test_dpp.py 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  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}'
  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. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  743. if ev is None:
  744. raise Exception("netAccessKey not reported (AP)")
  745. p = ev.split(' ')
  746. net_access_key = p[1]
  747. net_access_key_expiry = p[2] if len(p) > 2 else None
  748. logger.info("Update AP configuration to use key_mgmt=DPP")
  749. hapd.disable()
  750. hapd.set("ssid", ssid)
  751. hapd.set("wpa", "2")
  752. hapd.set("wpa_key_mgmt", "DPP")
  753. hapd.set("rsn_pairwise", "CCMP")
  754. hapd.set("dpp_connector", connector)
  755. hapd.set("dpp_csign", csign)
  756. hapd.set("dpp_netaccesskey", net_access_key)
  757. if net_access_key_expiry:
  758. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  759. hapd.enable()
  760. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  761. check_dpp_capab(dev[0])
  762. check_dpp_capab(dev[1])
  763. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  764. check_dpp_capab(hapd)
  765. addr = hapd.own_addr().replace(':', '')
  766. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  767. if curve:
  768. cmd += " curve=" + curve
  769. res = hapd.request(cmd)
  770. if "FAIL" in res:
  771. raise Exception("Failed to generate bootstrapping info")
  772. id_h = int(res)
  773. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  774. cmd = "DPP_CONFIGURATOR_ADD"
  775. if conf_curve:
  776. cmd += " curve=" + conf_curve
  777. res = dev[0].request(cmd);
  778. if "FAIL" in res:
  779. raise Exception("Failed to add configurator")
  780. conf_id = int(res)
  781. res = dev[0].request("DPP_QR_CODE " + uri)
  782. if "FAIL" in res:
  783. raise Exception("Failed to parse QR Code URI")
  784. id = int(res)
  785. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  786. if "OK" not in dev[0].request(cmd):
  787. raise Exception("Failed to initiate DPP Authentication")
  788. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  789. if ev is None:
  790. raise Exception("DPP authentication did not succeed (Responder)")
  791. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  792. if ev is None:
  793. raise Exception("DPP authentication did not succeed (Initiator)")
  794. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  795. if ev is None:
  796. raise Exception("DPP configuration not completed (Configurator)")
  797. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  798. if ev is None:
  799. raise Exception("DPP configuration not completed (Enrollee)")
  800. if "DPP-CONF-FAILED" in ev:
  801. raise Exception("DPP configuration failed")
  802. update_hapd_config(hapd)
  803. addr = dev[1].own_addr().replace(':', '')
  804. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  805. if curve:
  806. cmd += " curve=" + curve
  807. res = dev[1].request(cmd)
  808. if "FAIL" in res:
  809. raise Exception("Failed to generate bootstrapping info")
  810. id1 = int(res)
  811. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  812. res = dev[0].request("DPP_QR_CODE " + uri1)
  813. if "FAIL" in res:
  814. raise Exception("Failed to parse QR Code URI")
  815. id0b = int(res)
  816. cmd = "DPP_LISTEN 2412"
  817. if "OK" not in dev[1].request(cmd):
  818. raise Exception("Failed to start listen operation")
  819. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  820. if "OK" not in dev[0].request(cmd):
  821. raise Exception("Failed to initiate DPP Authentication")
  822. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  823. if ev is None:
  824. raise Exception("DPP authentication did not succeed (Responder)")
  825. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  826. if ev is None:
  827. raise Exception("DPP authentication did not succeed (Initiator)")
  828. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  829. if ev is None:
  830. raise Exception("DPP configuration not completed (Configurator)")
  831. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  832. if ev is None:
  833. raise Exception("DPP configuration not completed (Enrollee)")
  834. dev[1].request("DPP_STOP_LISTEN")
  835. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  836. if ev is None:
  837. raise Exception("SSID not reported")
  838. ssid = ev.split(' ')[1]
  839. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  840. if ev is None:
  841. raise Exception("Connector not reported")
  842. connector = ev.split(' ')[1]
  843. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  844. if ev is None:
  845. raise Exception("C-sign-key not reported")
  846. p = ev.split(' ')
  847. csign = p[1]
  848. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  849. if ev is None:
  850. raise Exception("netAccessKey not reported")
  851. p = ev.split(' ')
  852. net_access_key = p[1]
  853. net_access_key_expiry = p[2] if len(p) > 2 else None
  854. dev[1].dump_monitor()
  855. id = dev[1].connect(ssid, key_mgmt="DPP", scan_freq="2412",
  856. only_add_network=True)
  857. dev[1].set_network_quoted(id, "dpp_connector", connector)
  858. dev[1].set_network(id, "dpp_csign", csign)
  859. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  860. if net_access_key_expiry:
  861. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  862. logger.info("Check data connection")
  863. dev[1].select_network(id, freq="2412")
  864. dev[1].wait_connected()
  865. def test_dpp_auto_connect_1(dev, apdev):
  866. """DPP and auto connect (1)"""
  867. try:
  868. run_dpp_auto_connect(dev, apdev, 1)
  869. finally:
  870. dev[0].set("dpp_config_processing", "0")
  871. def test_dpp_auto_connect_2(dev, apdev):
  872. """DPP and auto connect (2)"""
  873. try:
  874. run_dpp_auto_connect(dev, apdev, 2)
  875. finally:
  876. dev[0].set("dpp_config_processing", "0")
  877. def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
  878. """DPP and auto connect (2) using connect_cmd"""
  879. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  880. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  881. dev_new = [ wpas, dev[1] ]
  882. try:
  883. run_dpp_auto_connect(dev_new, apdev, 2)
  884. finally:
  885. wpas.set("dpp_config_processing", "0")
  886. def run_dpp_auto_connect(dev, apdev, processing):
  887. check_dpp_capab(dev[0])
  888. check_dpp_capab(dev[1])
  889. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  890. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  891. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  892. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  893. params = { "ssid": "test",
  894. "wpa": "2",
  895. "wpa_key_mgmt": "DPP",
  896. "rsn_pairwise": "CCMP",
  897. "dpp_connector": ap_connector,
  898. "dpp_csign": csign_pub,
  899. "dpp_netaccesskey": ap_netaccesskey }
  900. try:
  901. hapd = hostapd.add_ap(apdev[0], params)
  902. except:
  903. raise HwsimSkip("DPP not supported")
  904. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  905. res = dev[1].request(cmd)
  906. if "FAIL" in res:
  907. raise Exception("DPP_CONFIGURATOR_ADD failed")
  908. conf_id = int(res)
  909. dev[0].set("dpp_config_processing", str(processing))
  910. addr = dev[0].own_addr().replace(':', '')
  911. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  912. res = dev[0].request(cmd)
  913. if "FAIL" in res:
  914. raise Exception("Failed to generate bootstrapping info")
  915. id0 = int(res)
  916. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  917. res = dev[1].request("DPP_QR_CODE " + uri0)
  918. if "FAIL" in res:
  919. raise Exception("Failed to parse QR Code URI")
  920. id1 = int(res)
  921. cmd = "DPP_LISTEN 2412"
  922. if "OK" not in dev[0].request(cmd):
  923. raise Exception("Failed to start listen operation")
  924. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  925. if "OK" not in dev[1].request(cmd):
  926. raise Exception("Failed to initiate DPP Authentication")
  927. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  928. if ev is None:
  929. raise Exception("DPP configuration not completed (Configurator)")
  930. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  931. if ev is None:
  932. raise Exception("DPP configuration not completed (Enrollee)")
  933. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  934. if ev is None:
  935. raise Exception("DPP network profile not generated")
  936. id = ev.split(' ')[1]
  937. if processing == 1:
  938. dev[0].select_network(id, freq=2412)
  939. dev[0].wait_connected()
  940. hwsim_utils.test_connectivity(dev[0], hapd)
  941. def test_dpp_auto_connect_legacy(dev, apdev):
  942. """DPP and auto connect (legacy)"""
  943. try:
  944. run_dpp_auto_connect_legacy(dev, apdev)
  945. finally:
  946. dev[0].set("dpp_config_processing", "0")
  947. def run_dpp_auto_connect_legacy(dev, apdev):
  948. check_dpp_capab(dev[0])
  949. check_dpp_capab(dev[1])
  950. params = hostapd.wpa2_params(ssid="dpp-legacy",
  951. passphrase="secret passphrase")
  952. hapd = hostapd.add_ap(apdev[0], params)
  953. dev[0].set("dpp_config_processing", "2")
  954. addr = dev[0].own_addr().replace(':', '')
  955. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  956. res = dev[0].request(cmd)
  957. if "FAIL" in res:
  958. raise Exception("Failed to generate bootstrapping info")
  959. id0 = int(res)
  960. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  961. res = dev[1].request("DPP_QR_CODE " + uri0)
  962. if "FAIL" in res:
  963. raise Exception("Failed to parse QR Code URI")
  964. id1 = int(res)
  965. cmd = "DPP_LISTEN 2412"
  966. if "OK" not in dev[0].request(cmd):
  967. raise Exception("Failed to start listen operation")
  968. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  969. if "OK" not in dev[1].request(cmd):
  970. raise Exception("Failed to initiate DPP Authentication")
  971. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  972. if ev is None:
  973. raise Exception("DPP configuration not completed (Configurator)")
  974. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  975. if ev is None:
  976. raise Exception("DPP configuration not completed (Enrollee)")
  977. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  978. if ev is None:
  979. raise Exception("DPP network profile not generated")
  980. id = ev.split(' ')[1]
  981. dev[0].wait_connected()
  982. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  983. """DPP QR Code and responder as the configurator"""
  984. check_dpp_capab(dev[0])
  985. check_dpp_capab(dev[1])
  986. cmd = "DPP_CONFIGURATOR_ADD"
  987. res = dev[0].request(cmd);
  988. if "FAIL" in res:
  989. raise Exception("Failed to add configurator")
  990. conf_id = int(res)
  991. addr = dev[0].own_addr().replace(':', '')
  992. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  993. res = dev[0].request(cmd)
  994. if "FAIL" in res:
  995. raise Exception("Failed to generate bootstrapping info")
  996. id0 = int(res)
  997. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  998. res = dev[1].request("DPP_QR_CODE " + uri0)
  999. if "FAIL" in res:
  1000. raise Exception("Failed to parse QR Code URI")
  1001. id1 = int(res)
  1002. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  1003. cmd = "DPP_LISTEN 2412 role=configurator"
  1004. if "OK" not in dev[0].request(cmd):
  1005. raise Exception("Failed to start listen operation")
  1006. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1007. if "OK" not in dev[1].request(cmd):
  1008. raise Exception("Failed to initiate DPP Authentication")
  1009. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1010. if ev is None:
  1011. raise Exception("DPP authentication did not succeed (Responder)")
  1012. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1013. if ev is None:
  1014. raise Exception("DPP authentication did not succeed (Initiator)")
  1015. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1016. if ev is None:
  1017. raise Exception("DPP configuration not completed (Configurator)")
  1018. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1019. if ev is None:
  1020. raise Exception("DPP configuration not completed (Enrollee)")
  1021. dev[0].request("DPP_STOP_LISTEN")
  1022. dev[0].dump_monitor()
  1023. dev[1].dump_monitor()
  1024. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1025. """DPP QR Code and hostapd as initiator"""
  1026. check_dpp_capab(dev[0])
  1027. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1028. "channel": "6" })
  1029. check_dpp_capab(hapd)
  1030. cmd = "DPP_CONFIGURATOR_ADD"
  1031. res = dev[0].request(cmd);
  1032. if "FAIL" in res:
  1033. raise Exception("Failed to add configurator")
  1034. conf_id = int(res)
  1035. addr = dev[0].own_addr().replace(':', '')
  1036. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1037. res = dev[0].request(cmd)
  1038. if "FAIL" in res:
  1039. raise Exception("Failed to generate bootstrapping info")
  1040. id0 = int(res)
  1041. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1042. dev[0].set("dpp_configurator_params",
  1043. " conf=ap-dpp configurator=%d" % conf_id);
  1044. cmd = "DPP_LISTEN 2437 role=configurator"
  1045. if "OK" not in dev[0].request(cmd):
  1046. raise Exception("Failed to start listen operation")
  1047. res = hapd.request("DPP_QR_CODE " + uri0)
  1048. if "FAIL" in res:
  1049. raise Exception("Failed to parse QR Code URI")
  1050. id1 = int(res)
  1051. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1052. if "OK" not in hapd.request(cmd):
  1053. raise Exception("Failed to initiate DPP Authentication")
  1054. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1055. if ev is None:
  1056. raise Exception("DPP authentication did not succeed (Responder)")
  1057. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1058. if ev is None:
  1059. raise Exception("DPP authentication did not succeed (Initiator)")
  1060. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1061. if ev is None:
  1062. raise Exception("DPP configuration not completed (Configurator)")
  1063. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1064. if ev is None:
  1065. raise Exception("DPP configuration not completed (Enrollee)")
  1066. dev[0].request("DPP_STOP_LISTEN")
  1067. dev[0].dump_monitor()
  1068. def test_dpp_pkex(dev, apdev):
  1069. """DPP and PKEX"""
  1070. run_dpp_pkex(dev, apdev)
  1071. def test_dpp_pkex_p256(dev, apdev):
  1072. """DPP and PKEX (P-256)"""
  1073. run_dpp_pkex(dev, apdev, "P-256")
  1074. def test_dpp_pkex_p384(dev, apdev):
  1075. """DPP and PKEX (P-384)"""
  1076. run_dpp_pkex(dev, apdev, "P-384")
  1077. def test_dpp_pkex_p521(dev, apdev):
  1078. """DPP and PKEX (P-521)"""
  1079. run_dpp_pkex(dev, apdev, "P-521")
  1080. def test_dpp_pkex_bp256(dev, apdev):
  1081. """DPP and PKEX (BP-256)"""
  1082. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1083. def test_dpp_pkex_bp384(dev, apdev):
  1084. """DPP and PKEX (BP-384)"""
  1085. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1086. def test_dpp_pkex_bp512(dev, apdev):
  1087. """DPP and PKEX (BP-512)"""
  1088. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1089. def test_dpp_pkex_config(dev, apdev):
  1090. """DPP and PKEX with initiator as the configurator"""
  1091. check_dpp_capab(dev[1])
  1092. cmd = "DPP_CONFIGURATOR_ADD"
  1093. res = dev[1].request(cmd);
  1094. if "FAIL" in res:
  1095. raise Exception("Failed to add configurator")
  1096. conf_id = int(res)
  1097. run_dpp_pkex(dev, apdev,
  1098. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1099. check_config=True)
  1100. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1101. check_dpp_capab(dev[0])
  1102. check_dpp_capab(dev[1])
  1103. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1104. if curve:
  1105. cmd += " curve=" + curve
  1106. res = dev[0].request(cmd)
  1107. if "FAIL" in res:
  1108. raise Exception("Failed to generate bootstrapping info")
  1109. id0 = int(res)
  1110. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1111. if curve:
  1112. cmd += " curve=" + curve
  1113. res = dev[1].request(cmd)
  1114. if "FAIL" in res:
  1115. raise Exception("Failed to generate bootstrapping info")
  1116. id1 = int(res)
  1117. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1118. res = dev[0].request(cmd)
  1119. if "FAIL" in res:
  1120. raise Exception("Failed to set PKEX data (responder)")
  1121. cmd = "DPP_LISTEN 2437"
  1122. if "OK" not in dev[0].request(cmd):
  1123. raise Exception("Failed to start listen operation")
  1124. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1125. res = dev[1].request(cmd)
  1126. if "FAIL" in res:
  1127. raise Exception("Failed to set PKEX data (initiator)")
  1128. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1129. if ev is None:
  1130. raise Exception("DPP authentication did not succeed (Initiator)")
  1131. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1132. if ev is None:
  1133. raise Exception("DPP authentication did not succeed (Responder)")
  1134. if check_config:
  1135. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1136. if ev is None:
  1137. raise Exception("DPP configuration not completed (Configurator)")
  1138. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1139. if ev is None:
  1140. raise Exception("DPP configuration not completed (Enrollee)")
  1141. def test_dpp_pkex_config2(dev, apdev):
  1142. """DPP and PKEX with responder as the configurator"""
  1143. check_dpp_capab(dev[0])
  1144. cmd = "DPP_CONFIGURATOR_ADD"
  1145. res = dev[0].request(cmd);
  1146. if "FAIL" in res:
  1147. raise Exception("Failed to add configurator")
  1148. conf_id = int(res)
  1149. dev[0].set("dpp_configurator_params",
  1150. " conf=sta-dpp configurator=%d" % conf_id);
  1151. run_dpp_pkex2(dev, apdev)
  1152. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1153. check_dpp_capab(dev[0])
  1154. check_dpp_capab(dev[1])
  1155. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1156. if curve:
  1157. cmd += " curve=" + curve
  1158. res = dev[0].request(cmd)
  1159. if "FAIL" in res:
  1160. raise Exception("Failed to generate bootstrapping info")
  1161. id0 = int(res)
  1162. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1163. if curve:
  1164. cmd += " curve=" + curve
  1165. res = dev[1].request(cmd)
  1166. if "FAIL" in res:
  1167. raise Exception("Failed to generate bootstrapping info")
  1168. id1 = int(res)
  1169. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1170. res = dev[0].request(cmd)
  1171. if "FAIL" in res:
  1172. raise Exception("Failed to set PKEX data (responder)")
  1173. cmd = "DPP_LISTEN 2437 role=configurator"
  1174. if "OK" not in dev[0].request(cmd):
  1175. raise Exception("Failed to start listen operation")
  1176. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1177. res = dev[1].request(cmd)
  1178. if "FAIL" in res:
  1179. raise Exception("Failed to set PKEX data (initiator)")
  1180. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1181. if ev is None:
  1182. raise Exception("DPP authentication did not succeed (Initiator)")
  1183. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1184. if ev is None:
  1185. raise Exception("DPP authentication did not succeed (Responder)")
  1186. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1187. if ev is None:
  1188. raise Exception("DPP configuration not completed (Configurator)")
  1189. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1190. if ev is None:
  1191. raise Exception("DPP configuration not completed (Enrollee)")
  1192. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1193. """DPP PKEX with hostapd as responder"""
  1194. check_dpp_capab(dev[0])
  1195. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1196. "channel": "6" })
  1197. check_dpp_capab(hapd)
  1198. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1199. res = hapd.request(cmd)
  1200. if "FAIL" in res:
  1201. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1202. id_h = int(res)
  1203. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1204. res = hapd.request(cmd)
  1205. if "FAIL" in res:
  1206. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1207. cmd = "DPP_CONFIGURATOR_ADD"
  1208. res = dev[0].request(cmd);
  1209. if "FAIL" in res:
  1210. raise Exception("Failed to add configurator")
  1211. conf_id = int(res)
  1212. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1213. res = dev[0].request(cmd)
  1214. if "FAIL" in res:
  1215. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1216. id0 = int(res)
  1217. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1218. res = dev[0].request(cmd)
  1219. if "FAIL" in res:
  1220. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1221. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1222. if ev is None:
  1223. raise Exception("DPP authentication did not succeed (Initiator)")
  1224. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1225. if ev is None:
  1226. raise Exception("DPP authentication did not succeed (Responder)")
  1227. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1228. if ev is None:
  1229. raise Exception("DPP configuration not completed (Configurator)")
  1230. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1231. if ev is None:
  1232. raise Exception("DPP configuration not completed (Enrollee)")
  1233. dev[0].request("DPP_STOP_LISTEN")
  1234. dev[0].dump_monitor()
  1235. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1236. """DPP PKEX with hostapd as initiator"""
  1237. check_dpp_capab(dev[0])
  1238. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1239. "channel": "6" })
  1240. check_dpp_capab(hapd)
  1241. cmd = "DPP_CONFIGURATOR_ADD"
  1242. res = dev[0].request(cmd);
  1243. if "FAIL" in res:
  1244. raise Exception("Failed to add configurator")
  1245. conf_id = int(res)
  1246. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1247. res = dev[0].request(cmd)
  1248. if "FAIL" in res:
  1249. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1250. id0 = int(res)
  1251. dev[0].set("dpp_configurator_params",
  1252. " conf=ap-dpp configurator=%d" % conf_id);
  1253. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1254. res = dev[0].request(cmd)
  1255. if "FAIL" in res:
  1256. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1257. cmd = "DPP_LISTEN 2437 role=configurator"
  1258. if "OK" not in dev[0].request(cmd):
  1259. raise Exception("Failed to start listen operation")
  1260. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1261. res = hapd.request(cmd)
  1262. if "FAIL" in res:
  1263. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1264. id_h = int(res)
  1265. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1266. res = hapd.request(cmd)
  1267. if "FAIL" in res:
  1268. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1269. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1270. if ev is None:
  1271. raise Exception("DPP authentication did not succeed (Initiator)")
  1272. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1273. if ev is None:
  1274. raise Exception("DPP authentication did not succeed (Responder)")
  1275. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1276. if ev is None:
  1277. raise Exception("DPP configuration not completed (Configurator)")
  1278. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1279. if ev is None:
  1280. raise Exception("DPP configuration not completed (Enrollee)")
  1281. dev[0].request("DPP_STOP_LISTEN")
  1282. dev[0].dump_monitor()
  1283. def test_dpp_hostapd_configurator(dev, apdev):
  1284. """DPP with hostapd as configurator/initiator"""
  1285. check_dpp_capab(dev[0])
  1286. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1287. "channel": "1" })
  1288. check_dpp_capab(hapd)
  1289. cmd = "DPP_CONFIGURATOR_ADD"
  1290. res = hapd.request(cmd);
  1291. if "FAIL" in res:
  1292. raise Exception("Failed to add configurator")
  1293. conf_id = int(res)
  1294. addr = dev[0].own_addr().replace(':', '')
  1295. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1296. res = dev[0].request(cmd)
  1297. if "FAIL" in res:
  1298. raise Exception("Failed to generate bootstrapping info")
  1299. id0 = int(res)
  1300. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1301. res = hapd.request("DPP_QR_CODE " + uri0)
  1302. if "FAIL" in res:
  1303. raise Exception("Failed to parse QR Code URI")
  1304. id1 = int(res)
  1305. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1306. if "FAIL" in res:
  1307. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1308. if "type=QRCODE" not in res:
  1309. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1310. if "mac_addr=" + dev[0].own_addr() not in res:
  1311. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1312. cmd = "DPP_LISTEN 2412"
  1313. if "OK" not in dev[0].request(cmd):
  1314. raise Exception("Failed to start listen operation")
  1315. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1316. if "OK" not in hapd.request(cmd):
  1317. raise Exception("Failed to initiate DPP Authentication")
  1318. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1319. if ev is None:
  1320. raise Exception("DPP authentication did not succeed (Responder)")
  1321. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1322. if ev is None:
  1323. raise Exception("DPP authentication did not succeed (Initiator)")
  1324. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1325. if ev is None:
  1326. raise Exception("DPP configuration not completed (Configurator)")
  1327. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1328. if ev is None:
  1329. raise Exception("DPP configuration not completed (Enrollee)")
  1330. dev[0].request("DPP_STOP_LISTEN")
  1331. dev[0].dump_monitor()
  1332. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1333. """DPP with hostapd as configurator/responder"""
  1334. check_dpp_capab(dev[0])
  1335. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1336. "channel": "1" })
  1337. check_dpp_capab(hapd)
  1338. cmd = "DPP_CONFIGURATOR_ADD"
  1339. res = hapd.request(cmd);
  1340. if "FAIL" in res:
  1341. raise Exception("Failed to add configurator")
  1342. conf_id = int(res)
  1343. hapd.set("dpp_configurator_params",
  1344. " conf=sta-dpp configurator=%d" % conf_id);
  1345. addr = hapd.own_addr().replace(':', '')
  1346. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1347. res = hapd.request(cmd)
  1348. if "FAIL" in res:
  1349. raise Exception("Failed to generate bootstrapping info")
  1350. id0 = int(res)
  1351. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1352. res = dev[0].request("DPP_QR_CODE " + uri0)
  1353. if "FAIL" in res:
  1354. raise Exception("Failed to parse QR Code URI")
  1355. id1 = int(res)
  1356. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1357. if "OK" not in dev[0].request(cmd):
  1358. raise Exception("Failed to initiate DPP Authentication")
  1359. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1360. if ev is None:
  1361. raise Exception("DPP authentication did not succeed (Responder)")
  1362. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1363. if ev is None:
  1364. raise Exception("DPP authentication did not succeed (Initiator)")
  1365. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1366. if ev is None:
  1367. raise Exception("DPP configuration not completed (Configurator)")
  1368. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1369. if ev is None:
  1370. raise Exception("DPP configuration not completed (Enrollee)")
  1371. dev[0].request("DPP_STOP_LISTEN")
  1372. dev[0].dump_monitor()
  1373. def test_dpp_own_config(dev, apdev):
  1374. """DPP configurator signing own connector"""
  1375. try:
  1376. run_dpp_own_config(dev, apdev)
  1377. finally:
  1378. dev[0].set("dpp_config_processing", "0")
  1379. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1380. """DPP configurator signing own connector using mismatching curve"""
  1381. try:
  1382. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1383. finally:
  1384. dev[0].set("dpp_config_processing", "0")
  1385. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1386. check_dpp_capab(dev[0])
  1387. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1388. check_dpp_capab(hapd)
  1389. addr = hapd.own_addr().replace(':', '')
  1390. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1391. res = hapd.request(cmd)
  1392. if "FAIL" in res:
  1393. raise Exception("Failed to generate bootstrapping info")
  1394. id_h = int(res)
  1395. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1396. cmd = "DPP_CONFIGURATOR_ADD"
  1397. res = dev[0].request(cmd);
  1398. if "FAIL" in res:
  1399. raise Exception("Failed to add configurator")
  1400. conf_id = int(res)
  1401. res = dev[0].request("DPP_QR_CODE " + uri)
  1402. if "FAIL" in res:
  1403. raise Exception("Failed to parse QR Code URI")
  1404. id = int(res)
  1405. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1406. if "OK" not in dev[0].request(cmd):
  1407. raise Exception("Failed to initiate DPP Authentication")
  1408. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1409. if ev is None:
  1410. raise Exception("DPP authentication did not succeed (Responder)")
  1411. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1412. if ev is None:
  1413. raise Exception("DPP authentication did not succeed (Initiator)")
  1414. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1415. if ev is None:
  1416. raise Exception("DPP configuration not completed (Configurator)")
  1417. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1418. if ev is None:
  1419. raise Exception("DPP configuration not completed (Enrollee)")
  1420. update_hapd_config(hapd)
  1421. dev[0].set("dpp_config_processing", "1")
  1422. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1423. if own_curve:
  1424. cmd += " curve=" + own_curve
  1425. res = dev[0].request(cmd)
  1426. if "FAIL" in res:
  1427. raise Exception("Failed to generate own configuration")
  1428. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1429. if ev is None:
  1430. raise Exception("DPP network profile not generated")
  1431. id = ev.split(' ')[1]
  1432. dev[0].select_network(id, freq="2412")
  1433. if expect_failure:
  1434. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1435. if ev is not None:
  1436. raise Exception("Unexpected connection");
  1437. dev[0].request("DISCONNECT")
  1438. else:
  1439. dev[0].wait_connected()
  1440. def run_dpp_proto_init(dev, test_dev, test, mutual=False):
  1441. check_dpp_capab(dev[0])
  1442. check_dpp_capab(dev[1])
  1443. dev[test_dev].set("dpp_test", str(test))
  1444. cmd = "DPP_CONFIGURATOR_ADD"
  1445. res = dev[1].request(cmd);
  1446. if "FAIL" in res:
  1447. raise Exception("Failed to add configurator")
  1448. conf_id = int(res)
  1449. addr = dev[0].own_addr().replace(':', '')
  1450. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1451. res = dev[0].request(cmd)
  1452. if "FAIL" in res:
  1453. raise Exception("Failed to generate bootstrapping info")
  1454. id0 = int(res)
  1455. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1456. res = dev[1].request("DPP_QR_CODE " + uri0)
  1457. if "FAIL" in res:
  1458. raise Exception("Failed to parse QR Code URI")
  1459. id1 = int(res)
  1460. if mutual:
  1461. addr = dev[1].own_addr().replace(':', '')
  1462. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  1463. if "FAIL" in res:
  1464. raise Exception("Failed to generate bootstrapping info")
  1465. id1b = int(res)
  1466. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  1467. res = dev[0].request("DPP_QR_CODE " + uri1b)
  1468. if "FAIL" in res:
  1469. raise Exception("Failed to parse QR Code URI")
  1470. id0b = int(res)
  1471. cmd = "DPP_LISTEN 2412"
  1472. if "OK" not in dev[0].request(cmd):
  1473. raise Exception("Failed to start listen operation")
  1474. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1475. if mutual:
  1476. cmd += " own=%d" % id1b
  1477. if "OK" not in dev[1].request(cmd):
  1478. raise Exception("Failed to initiate DPP Authentication")
  1479. def test_dpp_proto_after_wrapped_data_auth_req(dev, apdev):
  1480. """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
  1481. run_dpp_proto_init(dev, 1, 1)
  1482. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1483. if ev is None:
  1484. raise Exception("DPP Authentication Request not seen")
  1485. if "type=0" not in ev or "ignore=invalid-attributes" not in ev:
  1486. raise Exception("Unexpected RX info: " + ev)
  1487. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1488. if ev is not None:
  1489. raise Exception("Unexpected DPP message seen")
  1490. def test_dpp_proto_after_wrapped_data_auth_resp(dev, apdev):
  1491. """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
  1492. run_dpp_proto_init(dev, 0, 2)
  1493. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  1494. if ev is None:
  1495. raise Exception("DPP Authentication Response not seen")
  1496. if "type=1" not in ev or "ignore=invalid-attributes" not in ev:
  1497. raise Exception("Unexpected RX info: " + ev)
  1498. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1499. if ev is None or "type=0" not in ev:
  1500. raise Exception("DPP Authentication Request not seen")
  1501. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1502. if ev is not None:
  1503. raise Exception("Unexpected DPP message seen")
  1504. def test_dpp_proto_after_wrapped_data_auth_conf(dev, apdev):
  1505. """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
  1506. run_dpp_proto_init(dev, 1, 3)
  1507. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1508. if ev is None or "type=0" not in ev:
  1509. raise Exception("DPP Authentication Request not seen")
  1510. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1511. if ev is None:
  1512. raise Exception("DPP Authentication Confirm not seen")
  1513. if "type=2" not in ev or "ignore=invalid-attributes" not in ev:
  1514. raise Exception("Unexpected RX info: " + ev)
  1515. def test_dpp_proto_after_wrapped_data_conf_req(dev, apdev):
  1516. """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
  1517. run_dpp_proto_init(dev, 0, 6)
  1518. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=10)
  1519. if ev is None:
  1520. raise Exception("DPP Configuration failure not seen")
  1521. def test_dpp_proto_after_wrapped_data_conf_resp(dev, apdev):
  1522. """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
  1523. run_dpp_proto_init(dev, 1, 7)
  1524. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=10)
  1525. if ev is None:
  1526. raise Exception("DPP Configuration failure not seen")
  1527. def test_dpp_proto_zero_i_capab(dev, apdev):
  1528. """DPP protocol testing - zero I-capability in Auth Req"""
  1529. run_dpp_proto_init(dev, 1, 8)
  1530. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1531. if ev is None:
  1532. raise Exception("DPP failure not seen")
  1533. if "Invalid role in I-capabilities 0x00" not in ev:
  1534. raise Exception("Unexpected failure: " + ev)
  1535. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1536. if ev is not None:
  1537. raise Exception("Unexpected DPP message seen")
  1538. def test_dpp_proto_zero_r_capab(dev, apdev):
  1539. """DPP protocol testing - zero R-capability in Auth Resp"""
  1540. run_dpp_proto_init(dev, 0, 9)
  1541. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1542. if ev is None:
  1543. raise Exception("DPP failure not seen")
  1544. if "Unexpected role in R-capabilities 0x00" not in ev:
  1545. raise Exception("Unexpected failure: " + ev)
  1546. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1547. if ev is None or "type=0" not in ev:
  1548. raise Exception("DPP Authentication Request not seen")
  1549. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1550. if ev is not None:
  1551. raise Exception("Unexpected DPP message seen")
  1552. def run_dpp_proto_auth_req_missing(dev, test, reason):
  1553. run_dpp_proto_init(dev, 1, test)
  1554. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1555. if ev is None:
  1556. raise Exception("DPP failure not seen")
  1557. if reason not in ev:
  1558. raise Exception("Unexpected failure: " + ev)
  1559. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1560. if ev is not None:
  1561. raise Exception("Unexpected DPP message seen")
  1562. def test_dpp_proto_auth_req_no_r_bootstrap_key(dev, apdev):
  1563. """DPP protocol testing - no R-bootstrap key in Auth Req"""
  1564. run_dpp_proto_auth_req_missing(dev, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1565. def test_dpp_proto_auth_req_no_i_bootstrap_key(dev, apdev):
  1566. """DPP protocol testing - no I-bootstrap key in Auth Req"""
  1567. run_dpp_proto_auth_req_missing(dev, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
  1568. def test_dpp_proto_auth_req_no_i_proto_key(dev, apdev):
  1569. """DPP protocol testing - no I-proto key in Auth Req"""
  1570. run_dpp_proto_auth_req_missing(dev, 12, "Missing required Initiator Protocol Key attribute")
  1571. def test_dpp_proto_auth_req_no_i_nonce(dev, apdev):
  1572. """DPP protocol testing - no I-nonce in Auth Req"""
  1573. run_dpp_proto_auth_req_missing(dev, 13, "Missing or invalid I-nonce")
  1574. def test_dpp_proto_auth_req_no_i_capab(dev, apdev):
  1575. """DPP protocol testing - no I-capab in Auth Req"""
  1576. run_dpp_proto_auth_req_missing(dev, 14, "Missing or invalid I-capab")
  1577. def test_dpp_proto_auth_req_no_wrapped_data(dev, apdev):
  1578. """DPP protocol testing - no Wrapped Data in Auth Req"""
  1579. run_dpp_proto_auth_req_missing(dev, 15, "Missing or invalid required Wrapped Data attribute")
  1580. def run_dpp_proto_auth_resp_missing(dev, test, reason):
  1581. run_dpp_proto_init(dev, 0, test, mutual=True)
  1582. if reason is None:
  1583. time.sleep(0.1)
  1584. return
  1585. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1586. if ev is None:
  1587. raise Exception("DPP failure not seen")
  1588. if reason not in ev:
  1589. raise Exception("Unexpected failure: " + ev)
  1590. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1591. if ev is None or "type=0" not in ev:
  1592. raise Exception("DPP Authentication Request not seen")
  1593. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1594. if ev is not None:
  1595. raise Exception("Unexpected DPP message seen")
  1596. def test_dpp_proto_auth_resp_no_status(dev, apdev):
  1597. """DPP protocol testing - no Status in Auth Resp"""
  1598. run_dpp_proto_auth_resp_missing(dev, 16, "Missing or invalid required DPP Status attribute")
  1599. def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev, apdev):
  1600. """DPP protocol testing - no R-bootstrap key in Auth Resp"""
  1601. run_dpp_proto_auth_resp_missing(dev, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1602. def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev, apdev):
  1603. """DPP protocol testing - no I-bootstrap key in Auth Resp"""
  1604. run_dpp_proto_auth_resp_missing(dev, 18, None)
  1605. def test_dpp_proto_auth_resp_no_r_proto_key(dev, apdev):
  1606. """DPP protocol testing - no R-Proto Key in Auth Resp"""
  1607. run_dpp_proto_auth_resp_missing(dev, 19, "Missing required Responder Protocol Key attribute")
  1608. def test_dpp_proto_auth_resp_no_r_nonce(dev, apdev):
  1609. """DPP protocol testing - no R-nonce in Auth Resp"""
  1610. run_dpp_proto_auth_resp_missing(dev, 20, "Missing or invalid R-nonce")
  1611. def test_dpp_proto_auth_resp_no_i_nonce(dev, apdev):
  1612. """DPP protocol testing - no I-nonce in Auth Resp"""
  1613. run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce")
  1614. def test_dpp_proto_auth_resp_no_r_capab(dev, apdev):
  1615. """DPP protocol testing - no R-capab in Auth Resp"""
  1616. run_dpp_proto_auth_resp_missing(dev, 22, "Missing or invalid R-capabilities")
  1617. def test_dpp_proto_auth_resp_no_r_auth(dev, apdev):
  1618. """DPP protocol testing - no R-auth in Auth Resp"""
  1619. run_dpp_proto_auth_resp_missing(dev, 23, "Missing or invalid Secondary Wrapped Data")
  1620. def test_dpp_proto_auth_resp_no_wrapped_data(dev, apdev):
  1621. """DPP protocol testing - no Wrapped Data in Auth Resp"""
  1622. run_dpp_proto_auth_resp_missing(dev, 24, "Missing or invalid required Wrapped Data attribute")
  1623. def run_dpp_proto_init_pkex(dev, test_dev, test):
  1624. check_dpp_capab(dev[0])
  1625. check_dpp_capab(dev[1])
  1626. dev[test_dev].set("dpp_test", str(test))
  1627. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1628. res = dev[0].request(cmd)
  1629. if "FAIL" in res:
  1630. raise Exception("Failed to generate bootstrapping info")
  1631. id0 = int(res)
  1632. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1633. res = dev[1].request(cmd)
  1634. if "FAIL" in res:
  1635. raise Exception("Failed to generate bootstrapping info")
  1636. id1 = int(res)
  1637. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1638. res = dev[0].request(cmd)
  1639. if "FAIL" in res:
  1640. raise Exception("Failed to set PKEX data (responder)")
  1641. cmd = "DPP_LISTEN 2437"
  1642. if "OK" not in dev[0].request(cmd):
  1643. raise Exception("Failed to start listen operation")
  1644. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1645. res = dev[1].request(cmd)
  1646. if "FAIL" in res:
  1647. raise Exception("Failed to set PKEX data (initiator)")
  1648. def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev, apdev):
  1649. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
  1650. run_dpp_proto_init_pkex(dev, 1, 4)
  1651. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1652. if ev is None or "type=7" not in ev:
  1653. raise Exception("PKEX Exchange Request not seen")
  1654. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1655. if ev is None or "type=9" not in ev:
  1656. raise Exception("PKEX Commit-Reveal Request not seen")
  1657. if "ignore=invalid-attributes" not in ev:
  1658. raise Exception("Unexpected RX info: " + ev)
  1659. def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev, apdev):
  1660. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
  1661. run_dpp_proto_init_pkex(dev, 0, 5)
  1662. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  1663. if ev is None or "type=8" not in ev:
  1664. raise Exception("PKEX Exchange Response not seen")
  1665. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  1666. if ev is None or "type=10" not in ev:
  1667. raise Exception("PKEX Commit-Reveal Response not seen")
  1668. if "ignore=invalid-attributes" not in ev:
  1669. raise Exception("Unexpected RX info: " + ev)