test_dpp.py 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539
  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_not_used(dev, apdev):
  270. """DPP QR Code and authentication exchange (mutual not used)"""
  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)
  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 does not scan QR Code")
  293. logger.info("dev1 initiates DPP Authentication")
  294. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  295. raise Exception("Failed to start listen operation")
  296. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  297. raise Exception("Failed to initiate DPP Authentication")
  298. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  299. if ev is None:
  300. raise Exception("DPP authentication did not succeed (Responder)")
  301. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  302. if ev is None:
  303. raise Exception("DPP authentication did not succeed (Initiator)")
  304. dev[0].request("DPP_STOP_LISTEN")
  305. def test_dpp_qr_code_auth_mutual_curve_mismatch(dev, apdev):
  306. """DPP QR Code and authentication exchange (mutual/mismatch)"""
  307. check_dpp_capab(dev[0])
  308. check_dpp_capab(dev[1])
  309. logger.info("dev0 displays QR Code")
  310. addr = dev[0].own_addr().replace(':', '')
  311. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  312. if "FAIL" in res:
  313. raise Exception("Failed to generate bootstrapping info")
  314. id0 = int(res)
  315. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  316. logger.info("dev1 scans QR Code")
  317. res = dev[1].request("DPP_QR_CODE " + uri0)
  318. if "FAIL" in res:
  319. raise Exception("Failed to parse QR Code URI")
  320. id1 = int(res)
  321. logger.info("dev1 displays QR Code")
  322. addr = dev[1].own_addr().replace(':', '')
  323. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr + " curve=secp384r1")
  324. if "FAIL" in res:
  325. raise Exception("Failed to generate bootstrapping info")
  326. id1b = int(res)
  327. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  328. logger.info("dev0 scans QR Code")
  329. res = dev[0].request("DPP_QR_CODE " + uri1b)
  330. if "FAIL" in res:
  331. raise Exception("Failed to parse QR Code URI")
  332. id0b = int(res)
  333. res = dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b))
  334. if "FAIL" not in res:
  335. raise Exception("DPP_AUTH_INIT accepted unexpectedly")
  336. def test_dpp_qr_code_listen_continue(dev, apdev):
  337. """DPP QR Code and listen operation needing continuation"""
  338. check_dpp_capab(dev[0])
  339. check_dpp_capab(dev[1])
  340. logger.info("dev0 displays QR Code")
  341. addr = dev[0].own_addr().replace(':', '')
  342. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  343. if "FAIL" in res:
  344. raise Exception("Failed to generate bootstrapping info")
  345. id0 = int(res)
  346. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  347. logger.info("dev1 scans QR Code")
  348. res = dev[1].request("DPP_QR_CODE " + uri0)
  349. if "FAIL" in res:
  350. raise Exception("Failed to parse QR Code URI")
  351. id1 = int(res)
  352. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  353. raise Exception("Failed to start listen operation")
  354. logger.info("Wait for listen to expire and get restarted")
  355. time.sleep(5.5)
  356. logger.info("dev1 initiates DPP Authentication")
  357. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  358. raise Exception("Failed to initiate DPP Authentication")
  359. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  360. if ev is None:
  361. raise Exception("DPP authentication did not succeed (Responder)")
  362. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  363. if ev is None:
  364. raise Exception("DPP authentication did not succeed (Initiator)")
  365. dev[0].request("DPP_STOP_LISTEN")
  366. def test_dpp_qr_code_auth_initiator_enrollee(dev, apdev):
  367. """DPP QR Code and authentication exchange (Initiator in Enrollee role)"""
  368. check_dpp_capab(dev[0])
  369. check_dpp_capab(dev[1])
  370. dev[0].request("SET gas_address3 1")
  371. dev[1].request("SET gas_address3 1")
  372. logger.info("dev0 displays QR Code")
  373. addr = dev[0].own_addr().replace(':', '')
  374. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  375. if "FAIL" in res:
  376. raise Exception("Failed to generate bootstrapping info")
  377. id0 = int(res)
  378. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  379. logger.info("dev1 scans QR Code")
  380. res = dev[1].request("DPP_QR_CODE " + uri0)
  381. if "FAIL" in res:
  382. raise Exception("Failed to parse QR Code URI")
  383. id1 = int(res)
  384. logger.info("dev1 initiates DPP Authentication")
  385. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  386. raise Exception("Failed to start listen operation")
  387. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  388. raise Exception("Failed to initiate DPP Authentication")
  389. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  390. if ev is None:
  391. raise Exception("DPP authentication did not succeed (Responder)")
  392. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  393. if ev is None:
  394. raise Exception("DPP authentication did not succeed (Initiator)")
  395. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  396. if ev is None:
  397. raise Exception("DPP configuration did not succeed (Configurator)")
  398. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=5)
  399. if ev is None:
  400. raise Exception("DPP configuration did not succeed (Enrollee)")
  401. dev[0].request("DPP_STOP_LISTEN")
  402. def test_dpp_qr_code_auth_incompatible_roles(dev, apdev):
  403. """DPP QR Code and authentication exchange (incompatible roles)"""
  404. check_dpp_capab(dev[0])
  405. check_dpp_capab(dev[1])
  406. logger.info("dev0 displays QR Code")
  407. addr = dev[0].own_addr().replace(':', '')
  408. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  409. if "FAIL" in res:
  410. raise Exception("Failed to generate bootstrapping info")
  411. id0 = int(res)
  412. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  413. logger.info("dev1 scans QR Code")
  414. res = dev[1].request("DPP_QR_CODE " + uri0)
  415. if "FAIL" in res:
  416. raise Exception("Failed to parse QR Code URI")
  417. id1 = int(res)
  418. logger.info("dev1 initiates DPP Authentication")
  419. if "OK" not in dev[0].request("DPP_LISTEN 2412 role=enrollee"):
  420. raise Exception("Failed to start listen operation")
  421. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  422. raise Exception("Failed to initiate DPP Authentication")
  423. ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
  424. if ev is None:
  425. raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
  426. ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
  427. if ev is None:
  428. raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
  429. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=configurator" % id1):
  430. raise Exception("Failed to initiate DPP Authentication")
  431. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  432. if ev is None:
  433. raise Exception("DPP authentication did not succeed (Responder)")
  434. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  435. if ev is None:
  436. raise Exception("DPP authentication did not succeed (Initiator)")
  437. dev[0].request("DPP_STOP_LISTEN")
  438. def test_dpp_qr_code_auth_neg_chan(dev, apdev):
  439. """DPP QR Code and authentication exchange with requested different channel"""
  440. check_dpp_capab(dev[0])
  441. check_dpp_capab(dev[1])
  442. logger.info("Create configurator on dev1")
  443. cmd = "DPP_CONFIGURATOR_ADD"
  444. res = dev[1].request(cmd);
  445. if "FAIL" in res:
  446. raise Exception("Failed to add configurator")
  447. conf_id = int(res)
  448. logger.info("dev0 displays QR Code")
  449. addr = dev[0].own_addr().replace(':', '')
  450. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  451. res = dev[0].request(cmd)
  452. if "FAIL" in res:
  453. raise Exception("Failed to generate bootstrapping info")
  454. id0 = int(res)
  455. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  456. logger.info("dev1 scans QR Code")
  457. res = dev[1].request("DPP_QR_CODE " + uri0)
  458. if "FAIL" in res:
  459. raise Exception("Failed to parse QR Code URI")
  460. id1 = int(res)
  461. logger.info("dev1 initiates DPP Authentication")
  462. cmd = "DPP_LISTEN 2412"
  463. if "OK" not in dev[0].request(cmd):
  464. raise Exception("Failed to start listen operation")
  465. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp neg_freq=2462" % (id1, conf_id)
  466. if "OK" not in dev[1].request(cmd):
  467. raise Exception("Failed to initiate DPP Authentication")
  468. ev = dev[1].wait_event(["DPP-TX"], timeout=5)
  469. if ev is None:
  470. raise Exception("DPP Authentication Request not sent")
  471. if "freq=2412 type=0" not in ev:
  472. raise Exception("Unexpected TX data for Authentication Request: " + ev)
  473. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  474. if ev is None:
  475. raise Exception("DPP Authentication Request not received")
  476. if "freq=2412 type=0" not in ev:
  477. raise Exception("Unexpected RX data for Authentication Request: " + ev)
  478. ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5)
  479. if ev is None:
  480. raise Exception("TX status for DPP Authentication Request not reported")
  481. if "freq=2412 result=SUCCESS" not in ev:
  482. raise Exception("Unexpected TX status for Authentication Request: " + ev)
  483. ev = dev[0].wait_event(["DPP-TX"], timeout=5)
  484. if ev is None:
  485. raise Exception("DPP Authentication Response not sent")
  486. if "freq=2462 type=1" not in ev:
  487. raise Exception("Unexpected TX data for Authentication Response: " + ev)
  488. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  489. if ev is None:
  490. raise Exception("DPP Authentication Response not received")
  491. if "freq=2462 type=1" not in ev:
  492. raise Exception("Unexpected RX data for Authentication Response: " + ev)
  493. ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=5)
  494. if ev is None:
  495. raise Exception("TX status for DPP Authentication Response not reported")
  496. if "freq=2462 result=SUCCESS" not in ev:
  497. raise Exception("Unexpected TX status for Authentication Response: " + ev)
  498. ev = dev[1].wait_event(["DPP-TX"], timeout=5)
  499. if ev is None:
  500. raise Exception("DPP Authentication Confirm not sent")
  501. if "freq=2462 type=2" not in ev:
  502. raise Exception("Unexpected TX data for Authentication Confirm: " + ev)
  503. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  504. if ev is None:
  505. raise Exception("DPP Authentication Confirm not received")
  506. if "freq=2462 type=2" not in ev:
  507. raise Exception("Unexpected RX data for Authentication Confirm: " + ev)
  508. ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5)
  509. if ev is None:
  510. raise Exception("TX status for DPP Authentication Confirm not reported")
  511. if "freq=2462 result=SUCCESS" not in ev:
  512. raise Exception("Unexpected TX status for Authentication Confirm: " + ev)
  513. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  514. if ev is None:
  515. raise Exception("DPP authentication did not succeed (Responder)")
  516. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  517. if ev is None:
  518. raise Exception("DPP authentication did not succeed (Initiator)")
  519. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  520. if ev is None:
  521. raise Exception("DPP configuration not completed (Configurator)")
  522. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  523. if ev is None:
  524. raise Exception("DPP configuration not completed (Enrollee)")
  525. if "DPP-CONF-FAILED" in ev:
  526. raise Exception("DPP configuration failed")
  527. dev[0].request("DPP_STOP_LISTEN")
  528. dev[0].dump_monitor()
  529. dev[1].dump_monitor()
  530. def test_dpp_config_legacy(dev, apdev):
  531. """DPP Config Object for legacy network using passphrase"""
  532. check_dpp_capab(dev[1])
  533. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
  534. dev[1].set("dpp_config_obj_override", conf)
  535. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  536. require_conf_success=True)
  537. def test_dpp_config_legacy_psk_hex(dev, apdev):
  538. """DPP Config Object for legacy network using PSK"""
  539. check_dpp_capab(dev[1])
  540. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
  541. dev[1].set("dpp_config_obj_override", conf)
  542. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  543. require_conf_success=True)
  544. def test_dpp_config_fragmentation(dev, apdev):
  545. """DPP Config Object for legacy network requiring fragmentation"""
  546. check_dpp_capab(dev[1])
  547. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  548. dev[1].set("dpp_config_obj_override", conf)
  549. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  550. require_conf_success=True)
  551. def test_dpp_config_legacy_gen(dev, apdev):
  552. """Generate DPP Config Object for legacy network"""
  553. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  554. init_extra="conf=sta-psk pass=%s" % "passphrase".encode("hex"),
  555. require_conf_success=True)
  556. def test_dpp_config_dpp_gen_prime256v1(dev, apdev):
  557. """Generate DPP Config Object for DPP network (P-256)"""
  558. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  559. init_extra="conf=sta-dpp",
  560. require_conf_success=True,
  561. configurator=True)
  562. def test_dpp_config_dpp_gen_secp384r1(dev, apdev):
  563. """Generate DPP Config Object for DPP network (P-384)"""
  564. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  565. init_extra="conf=sta-dpp",
  566. require_conf_success=True,
  567. configurator=True)
  568. def test_dpp_config_dpp_gen_secp521r1(dev, apdev):
  569. """Generate DPP Config Object for DPP network (P-521)"""
  570. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  571. init_extra="conf=sta-dpp",
  572. require_conf_success=True,
  573. configurator=True)
  574. def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev, apdev):
  575. """Generate DPP Config Object for DPP network (P-256 + P-256)"""
  576. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  577. init_extra="conf=sta-dpp",
  578. require_conf_success=True,
  579. configurator=True,
  580. conf_curve="prime256v1")
  581. def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev, apdev):
  582. """Generate DPP Config Object for DPP network (P-256 + P-384)"""
  583. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  584. init_extra="conf=sta-dpp",
  585. require_conf_success=True,
  586. configurator=True,
  587. conf_curve="secp384r1")
  588. def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev, apdev):
  589. """Generate DPP Config Object for DPP network (P-256 + P-521)"""
  590. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  591. init_extra="conf=sta-dpp",
  592. require_conf_success=True,
  593. configurator=True,
  594. conf_curve="secp521r1")
  595. def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev, apdev):
  596. """Generate DPP Config Object for DPP network (P-384 + P-256)"""
  597. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  598. init_extra="conf=sta-dpp",
  599. require_conf_success=True,
  600. configurator=True,
  601. conf_curve="prime256v1")
  602. def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev, apdev):
  603. """Generate DPP Config Object for DPP network (P-384 + P-384)"""
  604. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  605. init_extra="conf=sta-dpp",
  606. require_conf_success=True,
  607. configurator=True,
  608. conf_curve="secp384r1")
  609. def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev, apdev):
  610. """Generate DPP Config Object for DPP network (P-384 + P-521)"""
  611. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  612. init_extra="conf=sta-dpp",
  613. require_conf_success=True,
  614. configurator=True,
  615. conf_curve="secp521r1")
  616. def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev, apdev):
  617. """Generate DPP Config Object for DPP network (P-521 + P-256)"""
  618. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  619. init_extra="conf=sta-dpp",
  620. require_conf_success=True,
  621. configurator=True,
  622. conf_curve="prime256v1")
  623. def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev, apdev):
  624. """Generate DPP Config Object for DPP network (P-521 + P-384)"""
  625. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  626. init_extra="conf=sta-dpp",
  627. require_conf_success=True,
  628. configurator=True,
  629. conf_curve="secp384r1")
  630. def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev, apdev):
  631. """Generate DPP Config Object for DPP network (P-521 + P-521)"""
  632. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  633. init_extra="conf=sta-dpp",
  634. require_conf_success=True,
  635. configurator=True,
  636. conf_curve="secp521r1")
  637. def test_dpp_config_dpp_gen_expiry(dev, apdev):
  638. """Generate DPP Config Object for DPP network with expiry value"""
  639. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  640. init_extra="conf=sta-dpp expiry=%d" % (time.time() + 1000),
  641. require_conf_success=True,
  642. configurator=True)
  643. def test_dpp_config_dpp_gen_expired_key(dev, apdev):
  644. """Generate DPP Config Object for DPP network with expiry value"""
  645. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  646. init_extra="conf=sta-dpp expiry=%d" % (time.time() - 10),
  647. require_conf_failure=True,
  648. configurator=True)
  649. def test_dpp_config_dpp_override_prime256v1(dev, apdev):
  650. """DPP Config Object override (P-256)"""
  651. check_dpp_capab(dev[0])
  652. check_dpp_capab(dev[1])
  653. 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"}}}'
  654. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  655. dev[1].set("dpp_config_obj_override", conf)
  656. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  657. require_conf_success=True)
  658. def test_dpp_config_dpp_override_secp384r1(dev, apdev):
  659. """DPP Config Object override (P-384)"""
  660. check_dpp_capab(dev[0])
  661. check_dpp_capab(dev[1])
  662. 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"}}}'
  663. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  664. dev[1].set("dpp_config_obj_override", conf)
  665. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  666. require_conf_success=True)
  667. def test_dpp_config_dpp_override_secp521r1(dev, apdev):
  668. """DPP Config Object override (P-521)"""
  669. check_dpp_capab(dev[0])
  670. check_dpp_capab(dev[1])
  671. 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"}}}'
  672. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  673. dev[1].set("dpp_config_obj_override", conf)
  674. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  675. require_conf_success=True)
  676. def test_dpp_config_override_objects(dev, apdev):
  677. """Generate DPP Config Object and override objects)"""
  678. check_dpp_capab(dev[1])
  679. discovery = '{\n"ssid":"mywifi"\n}'
  680. groups = '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
  681. dev[1].set("dpp_discovery_override", discovery)
  682. dev[1].set("dpp_groups_override", groups)
  683. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  684. init_extra="conf=sta-dpp",
  685. require_conf_success=True,
  686. configurator=True)
  687. def test_dpp_gas_timeout(dev, apdev):
  688. """DPP and GAS server timeout for a query"""
  689. check_dpp_capab(dev[0])
  690. check_dpp_capab(dev[1])
  691. logger.info("dev0 displays QR Code")
  692. addr = dev[0].own_addr().replace(':', '')
  693. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  694. res = dev[0].request(cmd)
  695. if "FAIL" in res:
  696. raise Exception("Failed to generate bootstrapping info")
  697. id0 = int(res)
  698. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  699. logger.info("dev1 scans QR Code")
  700. res = dev[1].request("DPP_QR_CODE " + uri0)
  701. if "FAIL" in res:
  702. raise Exception("Failed to parse QR Code URI")
  703. id1 = int(res)
  704. logger.info("dev1 initiates DPP Authentication")
  705. dev[0].set("ext_mgmt_frame_handling", "1")
  706. cmd = "DPP_LISTEN 2412"
  707. if "OK" not in dev[0].request(cmd):
  708. raise Exception("Failed to start listen operation")
  709. # Force GAS fragmentation
  710. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  711. dev[1].set("dpp_config_obj_override", conf)
  712. cmd = "DPP_AUTH_INIT peer=%d" % id1
  713. if "OK" not in dev[1].request(cmd):
  714. raise Exception("Failed to initiate DPP Authentication")
  715. # DPP Authentication Request
  716. msg = dev[0].mgmt_rx()
  717. 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'))):
  718. raise Exception("MGMT_RX_PROCESS failed")
  719. # DPP Authentication Confirmation
  720. msg = dev[0].mgmt_rx()
  721. 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'))):
  722. raise Exception("MGMT_RX_PROCESS failed")
  723. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  724. if ev is None:
  725. raise Exception("DPP authentication did not succeed (Responder)")
  726. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  727. if ev is None:
  728. raise Exception("DPP authentication did not succeed (Initiator)")
  729. # DPP Configuration Response (GAS Initial Response frame)
  730. msg = dev[0].mgmt_rx()
  731. 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'))):
  732. raise Exception("MGMT_RX_PROCESS failed")
  733. # GAS Comeback Response frame
  734. msg = dev[0].mgmt_rx()
  735. # Do not continue to force timeout on GAS server
  736. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  737. if ev is None:
  738. raise Exception("GAS result not reported (Enrollee)")
  739. if "result=TIMEOUT" not in ev:
  740. raise Exception("Unexpected GAS result (Enrollee): " + ev)
  741. dev[0].set("ext_mgmt_frame_handling", "0")
  742. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
  743. if ev is None:
  744. raise Exception("DPP configuration failure not reported (Configurator)")
  745. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
  746. if ev is None:
  747. raise Exception("DPP configuration failure not reported (Enrollee)")
  748. def test_dpp_akm_sha256(dev, apdev):
  749. """DPP AKM (SHA256)"""
  750. run_dpp_akm(dev, apdev, 32)
  751. def test_dpp_akm_sha384(dev, apdev):
  752. """DPP AKM (SHA384)"""
  753. run_dpp_akm(dev, apdev, 48)
  754. def test_dpp_akm_sha512(dev, apdev):
  755. """DPP AKM (SHA512)"""
  756. run_dpp_akm(dev, apdev, 64)
  757. def run_dpp_akm(dev, apdev, pmk_len):
  758. check_dpp_capab(dev[0])
  759. check_dpp_capab(dev[1])
  760. params = { "ssid": "dpp",
  761. "wpa": "2",
  762. "wpa_key_mgmt": "DPP",
  763. "rsn_pairwise": "CCMP",
  764. "ieee80211w": "2" }
  765. try:
  766. hapd = hostapd.add_ap(apdev[0], params)
  767. except:
  768. raise HwsimSkip("DPP not supported")
  769. id = dev[0].connect("dpp", key_mgmt="DPP", ieee80211w="2", scan_freq="2412",
  770. wait_connect=False)
  771. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  772. if not ev:
  773. raise Exception("Network mismatch not reported")
  774. dev[0].request("DISCONNECT")
  775. dev[0].dump_monitor()
  776. bssid = hapd.own_addr()
  777. pmkid = 16*'11'
  778. akmp = 2**23
  779. pmk = pmk_len*'22'
  780. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  781. if "OK" not in dev[0].request(cmd):
  782. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  783. dev[0].select_network(id, freq="2412")
  784. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  785. dev[0].request("DISCONNECT")
  786. dev[0].dump_monitor()
  787. if not ev:
  788. raise Exception("Association attempt was not rejected")
  789. if "status_code=53" not in ev:
  790. raise Exception("Unexpected status code: " + ev)
  791. addr = dev[0].own_addr()
  792. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  793. if "OK" not in hapd.request(cmd):
  794. raise Exception("PMKSA_ADD failed (hostapd)")
  795. dev[0].select_network(id, freq="2412")
  796. dev[0].wait_connected()
  797. val = dev[0].get_status_field("key_mgmt")
  798. if val != "DPP":
  799. raise Exception("Unexpected key_mgmt: " + val)
  800. def test_dpp_network_introduction(dev, apdev):
  801. """DPP network introduction"""
  802. check_dpp_capab(dev[0])
  803. check_dpp_capab(dev[1])
  804. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  805. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  806. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  807. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  808. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  809. params = { "ssid": "dpp",
  810. "wpa": "2",
  811. "wpa_key_mgmt": "DPP",
  812. "ieee80211w": "2",
  813. "rsn_pairwise": "CCMP",
  814. "dpp_connector": ap_connector,
  815. "dpp_csign": csign,
  816. "dpp_netaccesskey": ap_netaccesskey }
  817. try:
  818. hapd = hostapd.add_ap(apdev[0], params)
  819. except:
  820. raise HwsimSkip("DPP not supported")
  821. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  822. ieee80211w="2",
  823. dpp_csign=csign,
  824. dpp_connector=sta_connector,
  825. dpp_netaccesskey=sta_netaccesskey)
  826. val = dev[0].get_status_field("key_mgmt")
  827. if val != "DPP":
  828. raise Exception("Unexpected key_mgmt: " + val)
  829. def test_dpp_ap_config(dev, apdev):
  830. """DPP and AP configuration"""
  831. run_dpp_ap_config(dev, apdev)
  832. def test_dpp_ap_config_p256_p256(dev, apdev):
  833. """DPP and AP configuration (P-256 + P-256)"""
  834. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  835. def test_dpp_ap_config_p256_p384(dev, apdev):
  836. """DPP and AP configuration (P-256 + P-384)"""
  837. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  838. def test_dpp_ap_config_p256_p521(dev, apdev):
  839. """DPP and AP configuration (P-256 + P-521)"""
  840. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  841. def test_dpp_ap_config_p384_p256(dev, apdev):
  842. """DPP and AP configuration (P-384 + P-256)"""
  843. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  844. def test_dpp_ap_config_p384_p384(dev, apdev):
  845. """DPP and AP configuration (P-384 + P-384)"""
  846. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  847. def test_dpp_ap_config_p384_p521(dev, apdev):
  848. """DPP and AP configuration (P-384 + P-521)"""
  849. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  850. def test_dpp_ap_config_p521_p256(dev, apdev):
  851. """DPP and AP configuration (P-521 + P-256)"""
  852. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  853. def test_dpp_ap_config_p521_p384(dev, apdev):
  854. """DPP and AP configuration (P-521 + P-384)"""
  855. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  856. def test_dpp_ap_config_p521_p521(dev, apdev):
  857. """DPP and AP configuration (P-521 + P-521)"""
  858. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  859. def update_hapd_config(hapd):
  860. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  861. if ev is None:
  862. raise Exception("SSID not reported (AP)")
  863. ssid = ev.split(' ')[1]
  864. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  865. if ev is None:
  866. raise Exception("Connector not reported (AP)")
  867. connector = ev.split(' ')[1]
  868. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  869. if ev is None:
  870. raise Exception("C-sign-key not reported (AP)")
  871. p = ev.split(' ')
  872. csign = p[1]
  873. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  874. if ev is None:
  875. raise Exception("netAccessKey not reported (AP)")
  876. p = ev.split(' ')
  877. net_access_key = p[1]
  878. net_access_key_expiry = p[2] if len(p) > 2 else None
  879. logger.info("Update AP configuration to use key_mgmt=DPP")
  880. hapd.disable()
  881. hapd.set("ssid", ssid)
  882. hapd.set("wpa", "2")
  883. hapd.set("wpa_key_mgmt", "DPP")
  884. hapd.set("ieee80211w", "2")
  885. hapd.set("rsn_pairwise", "CCMP")
  886. hapd.set("dpp_connector", connector)
  887. hapd.set("dpp_csign", csign)
  888. hapd.set("dpp_netaccesskey", net_access_key)
  889. if net_access_key_expiry:
  890. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  891. hapd.enable()
  892. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  893. check_dpp_capab(dev[0])
  894. check_dpp_capab(dev[1])
  895. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  896. check_dpp_capab(hapd)
  897. addr = hapd.own_addr().replace(':', '')
  898. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  899. if curve:
  900. cmd += " curve=" + curve
  901. res = hapd.request(cmd)
  902. if "FAIL" in res:
  903. raise Exception("Failed to generate bootstrapping info")
  904. id_h = int(res)
  905. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  906. cmd = "DPP_CONFIGURATOR_ADD"
  907. if conf_curve:
  908. cmd += " curve=" + conf_curve
  909. res = dev[0].request(cmd);
  910. if "FAIL" in res:
  911. raise Exception("Failed to add configurator")
  912. conf_id = int(res)
  913. res = dev[0].request("DPP_QR_CODE " + uri)
  914. if "FAIL" in res:
  915. raise Exception("Failed to parse QR Code URI")
  916. id = int(res)
  917. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  918. if "OK" not in dev[0].request(cmd):
  919. raise Exception("Failed to initiate DPP Authentication")
  920. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  921. if ev is None:
  922. raise Exception("DPP authentication did not succeed (Responder)")
  923. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  924. if ev is None:
  925. raise Exception("DPP authentication did not succeed (Initiator)")
  926. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  927. if ev is None:
  928. raise Exception("DPP configuration not completed (Configurator)")
  929. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  930. if ev is None:
  931. raise Exception("DPP configuration not completed (Enrollee)")
  932. if "DPP-CONF-FAILED" in ev:
  933. raise Exception("DPP configuration failed")
  934. update_hapd_config(hapd)
  935. addr = dev[1].own_addr().replace(':', '')
  936. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  937. if curve:
  938. cmd += " curve=" + curve
  939. res = dev[1].request(cmd)
  940. if "FAIL" in res:
  941. raise Exception("Failed to generate bootstrapping info")
  942. id1 = int(res)
  943. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  944. res = dev[0].request("DPP_QR_CODE " + uri1)
  945. if "FAIL" in res:
  946. raise Exception("Failed to parse QR Code URI")
  947. id0b = int(res)
  948. cmd = "DPP_LISTEN 2412"
  949. if "OK" not in dev[1].request(cmd):
  950. raise Exception("Failed to start listen operation")
  951. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  952. if "OK" not in dev[0].request(cmd):
  953. raise Exception("Failed to initiate DPP Authentication")
  954. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  955. if ev is None:
  956. raise Exception("DPP authentication did not succeed (Responder)")
  957. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  958. if ev is None:
  959. raise Exception("DPP authentication did not succeed (Initiator)")
  960. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  961. if ev is None:
  962. raise Exception("DPP configuration not completed (Configurator)")
  963. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  964. if ev is None:
  965. raise Exception("DPP configuration not completed (Enrollee)")
  966. dev[1].request("DPP_STOP_LISTEN")
  967. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  968. if ev is None:
  969. raise Exception("SSID not reported")
  970. ssid = ev.split(' ')[1]
  971. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  972. if ev is None:
  973. raise Exception("Connector not reported")
  974. connector = ev.split(' ')[1]
  975. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  976. if ev is None:
  977. raise Exception("C-sign-key not reported")
  978. p = ev.split(' ')
  979. csign = p[1]
  980. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  981. if ev is None:
  982. raise Exception("netAccessKey not reported")
  983. p = ev.split(' ')
  984. net_access_key = p[1]
  985. net_access_key_expiry = p[2] if len(p) > 2 else None
  986. dev[1].dump_monitor()
  987. id = dev[1].connect(ssid, key_mgmt="DPP", ieee80211w="2", scan_freq="2412",
  988. only_add_network=True)
  989. dev[1].set_network_quoted(id, "dpp_connector", connector)
  990. dev[1].set_network(id, "dpp_csign", csign)
  991. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  992. if net_access_key_expiry:
  993. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  994. logger.info("Check data connection")
  995. dev[1].select_network(id, freq="2412")
  996. dev[1].wait_connected()
  997. def test_dpp_auto_connect_1(dev, apdev):
  998. """DPP and auto connect (1)"""
  999. try:
  1000. run_dpp_auto_connect(dev, apdev, 1)
  1001. finally:
  1002. dev[0].set("dpp_config_processing", "0")
  1003. def test_dpp_auto_connect_2(dev, apdev):
  1004. """DPP and auto connect (2)"""
  1005. try:
  1006. run_dpp_auto_connect(dev, apdev, 2)
  1007. finally:
  1008. dev[0].set("dpp_config_processing", "0")
  1009. def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
  1010. """DPP and auto connect (2) using connect_cmd"""
  1011. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1012. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  1013. dev_new = [ wpas, dev[1] ]
  1014. try:
  1015. run_dpp_auto_connect(dev_new, apdev, 2)
  1016. finally:
  1017. wpas.set("dpp_config_processing", "0")
  1018. def run_dpp_auto_connect(dev, apdev, processing):
  1019. check_dpp_capab(dev[0])
  1020. check_dpp_capab(dev[1])
  1021. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1022. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1023. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1024. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1025. params = { "ssid": "test",
  1026. "wpa": "2",
  1027. "wpa_key_mgmt": "DPP",
  1028. "ieee80211w": "2",
  1029. "rsn_pairwise": "CCMP",
  1030. "dpp_connector": ap_connector,
  1031. "dpp_csign": csign_pub,
  1032. "dpp_netaccesskey": ap_netaccesskey }
  1033. try:
  1034. hapd = hostapd.add_ap(apdev[0], params)
  1035. except:
  1036. raise HwsimSkip("DPP not supported")
  1037. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1038. res = dev[1].request(cmd)
  1039. if "FAIL" in res:
  1040. raise Exception("DPP_CONFIGURATOR_ADD failed")
  1041. conf_id = int(res)
  1042. dev[0].set("dpp_config_processing", str(processing))
  1043. addr = dev[0].own_addr().replace(':', '')
  1044. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1045. res = dev[0].request(cmd)
  1046. if "FAIL" in res:
  1047. raise Exception("Failed to generate bootstrapping info")
  1048. id0 = int(res)
  1049. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1050. res = dev[1].request("DPP_QR_CODE " + uri0)
  1051. if "FAIL" in res:
  1052. raise Exception("Failed to parse QR Code URI")
  1053. id1 = int(res)
  1054. cmd = "DPP_LISTEN 2412"
  1055. if "OK" not in dev[0].request(cmd):
  1056. raise Exception("Failed to start listen operation")
  1057. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1058. if "OK" not in dev[1].request(cmd):
  1059. raise Exception("Failed to initiate DPP Authentication")
  1060. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1061. if ev is None:
  1062. raise Exception("DPP configuration not completed (Configurator)")
  1063. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1064. if ev is None:
  1065. raise Exception("DPP configuration not completed (Enrollee)")
  1066. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1067. if ev is None:
  1068. raise Exception("DPP network profile not generated")
  1069. id = ev.split(' ')[1]
  1070. if processing == 1:
  1071. dev[0].select_network(id, freq=2412)
  1072. dev[0].wait_connected()
  1073. hwsim_utils.test_connectivity(dev[0], hapd)
  1074. def test_dpp_auto_connect_legacy(dev, apdev):
  1075. """DPP and auto connect (legacy)"""
  1076. try:
  1077. run_dpp_auto_connect_legacy(dev, apdev)
  1078. finally:
  1079. dev[0].set("dpp_config_processing", "0")
  1080. def run_dpp_auto_connect_legacy(dev, apdev):
  1081. check_dpp_capab(dev[0])
  1082. check_dpp_capab(dev[1])
  1083. params = hostapd.wpa2_params(ssid="dpp-legacy",
  1084. passphrase="secret passphrase")
  1085. hapd = hostapd.add_ap(apdev[0], params)
  1086. dev[0].set("dpp_config_processing", "2")
  1087. addr = dev[0].own_addr().replace(':', '')
  1088. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1089. res = dev[0].request(cmd)
  1090. if "FAIL" in res:
  1091. raise Exception("Failed to generate bootstrapping info")
  1092. id0 = int(res)
  1093. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1094. res = dev[1].request("DPP_QR_CODE " + uri0)
  1095. if "FAIL" in res:
  1096. raise Exception("Failed to parse QR Code URI")
  1097. id1 = int(res)
  1098. cmd = "DPP_LISTEN 2412"
  1099. if "OK" not in dev[0].request(cmd):
  1100. raise Exception("Failed to start listen operation")
  1101. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  1102. if "OK" not in dev[1].request(cmd):
  1103. raise Exception("Failed to initiate DPP Authentication")
  1104. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1105. if ev is None:
  1106. raise Exception("DPP configuration not completed (Configurator)")
  1107. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1108. if ev is None:
  1109. raise Exception("DPP configuration not completed (Enrollee)")
  1110. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1111. if ev is None:
  1112. raise Exception("DPP network profile not generated")
  1113. id = ev.split(' ')[1]
  1114. dev[0].wait_connected()
  1115. def test_dpp_auto_connect_legacy_pmf_required(dev, apdev):
  1116. """DPP and auto connect (legacy, PMF required)"""
  1117. try:
  1118. run_dpp_auto_connect_legacy_pmf_required(dev, apdev)
  1119. finally:
  1120. dev[0].set("dpp_config_processing", "0")
  1121. def run_dpp_auto_connect_legacy_pmf_required(dev, apdev):
  1122. check_dpp_capab(dev[0])
  1123. check_dpp_capab(dev[1])
  1124. params = hostapd.wpa2_params(ssid="dpp-legacy",
  1125. passphrase="secret passphrase")
  1126. params['wpa_key_mgmt'] = "WPA-PSK-SHA256"
  1127. params['ieee80211w'] = "2"
  1128. hapd = hostapd.add_ap(apdev[0], params)
  1129. dev[0].set("dpp_config_processing", "2")
  1130. addr = dev[0].own_addr().replace(':', '')
  1131. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1132. res = dev[0].request(cmd)
  1133. if "FAIL" in res:
  1134. raise Exception("Failed to generate bootstrapping info")
  1135. id0 = int(res)
  1136. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1137. res = dev[1].request("DPP_QR_CODE " + uri0)
  1138. if "FAIL" in res:
  1139. raise Exception("Failed to parse QR Code URI")
  1140. id1 = int(res)
  1141. cmd = "DPP_LISTEN 2412"
  1142. if "OK" not in dev[0].request(cmd):
  1143. raise Exception("Failed to start listen operation")
  1144. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  1145. if "OK" not in dev[1].request(cmd):
  1146. raise Exception("Failed to initiate DPP Authentication")
  1147. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1148. if ev is None:
  1149. raise Exception("DPP configuration not completed (Configurator)")
  1150. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1151. if ev is None:
  1152. raise Exception("DPP configuration not completed (Enrollee)")
  1153. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1154. if ev is None:
  1155. raise Exception("DPP network profile not generated")
  1156. id = ev.split(' ')[1]
  1157. dev[0].wait_connected()
  1158. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  1159. """DPP QR Code and responder as the configurator"""
  1160. check_dpp_capab(dev[0])
  1161. check_dpp_capab(dev[1])
  1162. cmd = "DPP_CONFIGURATOR_ADD"
  1163. res = dev[0].request(cmd);
  1164. if "FAIL" in res:
  1165. raise Exception("Failed to add configurator")
  1166. conf_id = int(res)
  1167. addr = dev[0].own_addr().replace(':', '')
  1168. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1169. res = dev[0].request(cmd)
  1170. if "FAIL" in res:
  1171. raise Exception("Failed to generate bootstrapping info")
  1172. id0 = int(res)
  1173. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1174. res = dev[1].request("DPP_QR_CODE " + uri0)
  1175. if "FAIL" in res:
  1176. raise Exception("Failed to parse QR Code URI")
  1177. id1 = int(res)
  1178. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  1179. cmd = "DPP_LISTEN 2412 role=configurator"
  1180. if "OK" not in dev[0].request(cmd):
  1181. raise Exception("Failed to start listen operation")
  1182. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1183. if "OK" not in dev[1].request(cmd):
  1184. raise Exception("Failed to initiate DPP Authentication")
  1185. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1186. if ev is None:
  1187. raise Exception("DPP authentication did not succeed (Responder)")
  1188. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1189. if ev is None:
  1190. raise Exception("DPP authentication did not succeed (Initiator)")
  1191. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1192. if ev is None:
  1193. raise Exception("DPP configuration not completed (Configurator)")
  1194. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1195. if ev is None:
  1196. raise Exception("DPP configuration not completed (Enrollee)")
  1197. dev[0].request("DPP_STOP_LISTEN")
  1198. dev[0].dump_monitor()
  1199. dev[1].dump_monitor()
  1200. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1201. """DPP QR Code and hostapd as initiator"""
  1202. check_dpp_capab(dev[0])
  1203. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1204. "channel": "6" })
  1205. check_dpp_capab(hapd)
  1206. cmd = "DPP_CONFIGURATOR_ADD"
  1207. res = dev[0].request(cmd);
  1208. if "FAIL" in res:
  1209. raise Exception("Failed to add configurator")
  1210. conf_id = int(res)
  1211. addr = dev[0].own_addr().replace(':', '')
  1212. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1213. res = dev[0].request(cmd)
  1214. if "FAIL" in res:
  1215. raise Exception("Failed to generate bootstrapping info")
  1216. id0 = int(res)
  1217. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1218. dev[0].set("dpp_configurator_params",
  1219. " conf=ap-dpp configurator=%d" % conf_id);
  1220. cmd = "DPP_LISTEN 2437 role=configurator"
  1221. if "OK" not in dev[0].request(cmd):
  1222. raise Exception("Failed to start listen operation")
  1223. res = hapd.request("DPP_QR_CODE " + uri0)
  1224. if "FAIL" in res:
  1225. raise Exception("Failed to parse QR Code URI")
  1226. id1 = int(res)
  1227. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1228. if "OK" not in hapd.request(cmd):
  1229. raise Exception("Failed to initiate DPP Authentication")
  1230. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1231. if ev is None:
  1232. raise Exception("DPP authentication did not succeed (Responder)")
  1233. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1234. if ev is None:
  1235. raise Exception("DPP authentication did not succeed (Initiator)")
  1236. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1237. if ev is None:
  1238. raise Exception("DPP configuration not completed (Configurator)")
  1239. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1240. if ev is None:
  1241. raise Exception("DPP configuration not completed (Enrollee)")
  1242. dev[0].request("DPP_STOP_LISTEN")
  1243. dev[0].dump_monitor()
  1244. def test_dpp_pkex(dev, apdev):
  1245. """DPP and PKEX"""
  1246. run_dpp_pkex(dev, apdev)
  1247. def test_dpp_pkex_p256(dev, apdev):
  1248. """DPP and PKEX (P-256)"""
  1249. run_dpp_pkex(dev, apdev, "P-256")
  1250. def test_dpp_pkex_p384(dev, apdev):
  1251. """DPP and PKEX (P-384)"""
  1252. run_dpp_pkex(dev, apdev, "P-384")
  1253. def test_dpp_pkex_p521(dev, apdev):
  1254. """DPP and PKEX (P-521)"""
  1255. run_dpp_pkex(dev, apdev, "P-521")
  1256. def test_dpp_pkex_bp256(dev, apdev):
  1257. """DPP and PKEX (BP-256)"""
  1258. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1259. def test_dpp_pkex_bp384(dev, apdev):
  1260. """DPP and PKEX (BP-384)"""
  1261. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1262. def test_dpp_pkex_bp512(dev, apdev):
  1263. """DPP and PKEX (BP-512)"""
  1264. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1265. def test_dpp_pkex_config(dev, apdev):
  1266. """DPP and PKEX with initiator as the configurator"""
  1267. check_dpp_capab(dev[1])
  1268. cmd = "DPP_CONFIGURATOR_ADD"
  1269. res = dev[1].request(cmd);
  1270. if "FAIL" in res:
  1271. raise Exception("Failed to add configurator")
  1272. conf_id = int(res)
  1273. run_dpp_pkex(dev, apdev,
  1274. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1275. check_config=True)
  1276. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1277. check_dpp_capab(dev[0])
  1278. check_dpp_capab(dev[1])
  1279. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1280. if curve:
  1281. cmd += " curve=" + curve
  1282. res = dev[0].request(cmd)
  1283. if "FAIL" in res:
  1284. raise Exception("Failed to generate bootstrapping info")
  1285. id0 = int(res)
  1286. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1287. if curve:
  1288. cmd += " curve=" + curve
  1289. res = dev[1].request(cmd)
  1290. if "FAIL" in res:
  1291. raise Exception("Failed to generate bootstrapping info")
  1292. id1 = int(res)
  1293. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1294. res = dev[0].request(cmd)
  1295. if "FAIL" in res:
  1296. raise Exception("Failed to set PKEX data (responder)")
  1297. cmd = "DPP_LISTEN 2437"
  1298. if "OK" not in dev[0].request(cmd):
  1299. raise Exception("Failed to start listen operation")
  1300. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1301. res = dev[1].request(cmd)
  1302. if "FAIL" in res:
  1303. raise Exception("Failed to set PKEX data (initiator)")
  1304. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1305. if ev is None:
  1306. raise Exception("DPP authentication did not succeed (Initiator)")
  1307. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1308. if ev is None:
  1309. raise Exception("DPP authentication did not succeed (Responder)")
  1310. if check_config:
  1311. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1312. if ev is None:
  1313. raise Exception("DPP configuration not completed (Configurator)")
  1314. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1315. if ev is None:
  1316. raise Exception("DPP configuration not completed (Enrollee)")
  1317. def test_dpp_pkex_code_mismatch(dev, apdev):
  1318. """DPP and PKEX with mismatching code"""
  1319. check_dpp_capab(dev[0])
  1320. check_dpp_capab(dev[1])
  1321. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1322. res = dev[0].request(cmd)
  1323. if "FAIL" in res:
  1324. raise Exception("Failed to generate bootstrapping info")
  1325. id0 = int(res)
  1326. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1327. res = dev[1].request(cmd)
  1328. if "FAIL" in res:
  1329. raise Exception("Failed to generate bootstrapping info")
  1330. id1 = int(res)
  1331. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1332. res = dev[0].request(cmd)
  1333. if "FAIL" in res:
  1334. raise Exception("Failed to set PKEX data (responder)")
  1335. cmd = "DPP_LISTEN 2437"
  1336. if "OK" not in dev[0].request(cmd):
  1337. raise Exception("Failed to start listen operation")
  1338. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=unknown" % id1
  1339. res = dev[1].request(cmd)
  1340. if "FAIL" in res:
  1341. raise Exception("Failed to set PKEX data (initiator)")
  1342. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1343. if ev is None:
  1344. raise Exception("Failure not reported")
  1345. if "possible PKEX code mismatch" not in ev:
  1346. raise Exception("Unexpected result: " + ev)
  1347. def test_dpp_pkex_curve_mismatch(dev, apdev):
  1348. """DPP and PKEX with mismatching curve"""
  1349. check_dpp_capab(dev[0])
  1350. check_dpp_capab(dev[1])
  1351. cmd = "DPP_BOOTSTRAP_GEN type=pkex curve=P-256"
  1352. res = dev[0].request(cmd)
  1353. if "FAIL" in res:
  1354. raise Exception("Failed to generate bootstrapping info")
  1355. id0 = int(res)
  1356. cmd = "DPP_BOOTSTRAP_GEN type=pkex curve=P-384"
  1357. res = dev[1].request(cmd)
  1358. if "FAIL" in res:
  1359. raise Exception("Failed to generate bootstrapping info")
  1360. id1 = int(res)
  1361. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1362. res = dev[0].request(cmd)
  1363. if "FAIL" in res:
  1364. raise Exception("Failed to set PKEX data (responder)")
  1365. cmd = "DPP_LISTEN 2437"
  1366. if "OK" not in dev[0].request(cmd):
  1367. raise Exception("Failed to start listen operation")
  1368. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1369. res = dev[1].request(cmd)
  1370. if "FAIL" in res:
  1371. raise Exception("Failed to set PKEX data (initiator)")
  1372. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1373. if ev is None:
  1374. raise Exception("Failure not reported (dev 0)")
  1375. if "Mismatching PKEX curve: peer=20 own=19" not in ev:
  1376. raise Exception("Unexpected result: " + ev)
  1377. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1378. if ev is None:
  1379. raise Exception("Failure not reported (dev 1)")
  1380. if "Peer indicated mismatching PKEX group - proposed 19" not in ev:
  1381. raise Exception("Unexpected result: " + ev)
  1382. def test_dpp_pkex_config2(dev, apdev):
  1383. """DPP and PKEX with responder as the configurator"""
  1384. check_dpp_capab(dev[0])
  1385. cmd = "DPP_CONFIGURATOR_ADD"
  1386. res = dev[0].request(cmd);
  1387. if "FAIL" in res:
  1388. raise Exception("Failed to add configurator")
  1389. conf_id = int(res)
  1390. dev[0].set("dpp_configurator_params",
  1391. " conf=sta-dpp configurator=%d" % conf_id);
  1392. run_dpp_pkex2(dev, apdev)
  1393. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1394. check_dpp_capab(dev[0])
  1395. check_dpp_capab(dev[1])
  1396. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1397. if curve:
  1398. cmd += " curve=" + curve
  1399. res = dev[0].request(cmd)
  1400. if "FAIL" in res:
  1401. raise Exception("Failed to generate bootstrapping info")
  1402. id0 = int(res)
  1403. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1404. if curve:
  1405. cmd += " curve=" + curve
  1406. res = dev[1].request(cmd)
  1407. if "FAIL" in res:
  1408. raise Exception("Failed to generate bootstrapping info")
  1409. id1 = int(res)
  1410. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1411. res = dev[0].request(cmd)
  1412. if "FAIL" in res:
  1413. raise Exception("Failed to set PKEX data (responder)")
  1414. cmd = "DPP_LISTEN 2437 role=configurator"
  1415. if "OK" not in dev[0].request(cmd):
  1416. raise Exception("Failed to start listen operation")
  1417. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1418. res = dev[1].request(cmd)
  1419. if "FAIL" in res:
  1420. raise Exception("Failed to set PKEX data (initiator)")
  1421. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1422. if ev is None:
  1423. raise Exception("DPP authentication did not succeed (Initiator)")
  1424. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1425. if ev is None:
  1426. raise Exception("DPP authentication did not succeed (Responder)")
  1427. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1428. if ev is None:
  1429. raise Exception("DPP configuration not completed (Configurator)")
  1430. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1431. if ev is None:
  1432. raise Exception("DPP configuration not completed (Enrollee)")
  1433. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1434. """DPP PKEX with hostapd as responder"""
  1435. check_dpp_capab(dev[0])
  1436. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1437. "channel": "6" })
  1438. check_dpp_capab(hapd)
  1439. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1440. res = hapd.request(cmd)
  1441. if "FAIL" in res:
  1442. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1443. id_h = int(res)
  1444. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1445. res = hapd.request(cmd)
  1446. if "FAIL" in res:
  1447. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1448. cmd = "DPP_CONFIGURATOR_ADD"
  1449. res = dev[0].request(cmd);
  1450. if "FAIL" in res:
  1451. raise Exception("Failed to add configurator")
  1452. conf_id = int(res)
  1453. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1454. res = dev[0].request(cmd)
  1455. if "FAIL" in res:
  1456. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1457. id0 = int(res)
  1458. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1459. res = dev[0].request(cmd)
  1460. if "FAIL" in res:
  1461. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1462. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1463. if ev is None:
  1464. raise Exception("DPP authentication did not succeed (Initiator)")
  1465. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1466. if ev is None:
  1467. raise Exception("DPP authentication did not succeed (Responder)")
  1468. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1469. if ev is None:
  1470. raise Exception("DPP configuration not completed (Configurator)")
  1471. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1472. if ev is None:
  1473. raise Exception("DPP configuration not completed (Enrollee)")
  1474. dev[0].request("DPP_STOP_LISTEN")
  1475. dev[0].dump_monitor()
  1476. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1477. """DPP PKEX with hostapd as initiator"""
  1478. check_dpp_capab(dev[0])
  1479. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1480. "channel": "6" })
  1481. check_dpp_capab(hapd)
  1482. cmd = "DPP_CONFIGURATOR_ADD"
  1483. res = dev[0].request(cmd);
  1484. if "FAIL" in res:
  1485. raise Exception("Failed to add configurator")
  1486. conf_id = int(res)
  1487. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1488. res = dev[0].request(cmd)
  1489. if "FAIL" in res:
  1490. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1491. id0 = int(res)
  1492. dev[0].set("dpp_configurator_params",
  1493. " conf=ap-dpp configurator=%d" % conf_id);
  1494. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1495. res = dev[0].request(cmd)
  1496. if "FAIL" in res:
  1497. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1498. cmd = "DPP_LISTEN 2437 role=configurator"
  1499. if "OK" not in dev[0].request(cmd):
  1500. raise Exception("Failed to start listen operation")
  1501. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1502. res = hapd.request(cmd)
  1503. if "FAIL" in res:
  1504. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1505. id_h = int(res)
  1506. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1507. res = hapd.request(cmd)
  1508. if "FAIL" in res:
  1509. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1510. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1511. if ev is None:
  1512. raise Exception("DPP authentication did not succeed (Initiator)")
  1513. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1514. if ev is None:
  1515. raise Exception("DPP authentication did not succeed (Responder)")
  1516. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1517. if ev is None:
  1518. raise Exception("DPP configuration not completed (Configurator)")
  1519. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1520. if ev is None:
  1521. raise Exception("DPP configuration not completed (Enrollee)")
  1522. dev[0].request("DPP_STOP_LISTEN")
  1523. dev[0].dump_monitor()
  1524. def test_dpp_hostapd_configurator(dev, apdev):
  1525. """DPP with hostapd as configurator/initiator"""
  1526. check_dpp_capab(dev[0])
  1527. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1528. "channel": "1" })
  1529. check_dpp_capab(hapd)
  1530. cmd = "DPP_CONFIGURATOR_ADD"
  1531. res = hapd.request(cmd);
  1532. if "FAIL" in res:
  1533. raise Exception("Failed to add configurator")
  1534. conf_id = int(res)
  1535. addr = dev[0].own_addr().replace(':', '')
  1536. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1537. res = dev[0].request(cmd)
  1538. if "FAIL" in res:
  1539. raise Exception("Failed to generate bootstrapping info")
  1540. id0 = int(res)
  1541. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1542. res = hapd.request("DPP_QR_CODE " + uri0)
  1543. if "FAIL" in res:
  1544. raise Exception("Failed to parse QR Code URI")
  1545. id1 = int(res)
  1546. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1547. if "FAIL" in res:
  1548. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1549. if "type=QRCODE" not in res:
  1550. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1551. if "mac_addr=" + dev[0].own_addr() not in res:
  1552. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1553. cmd = "DPP_LISTEN 2412"
  1554. if "OK" not in dev[0].request(cmd):
  1555. raise Exception("Failed to start listen operation")
  1556. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1557. if "OK" not in hapd.request(cmd):
  1558. raise Exception("Failed to initiate DPP Authentication")
  1559. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1560. if ev is None:
  1561. raise Exception("DPP authentication did not succeed (Responder)")
  1562. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1563. if ev is None:
  1564. raise Exception("DPP authentication did not succeed (Initiator)")
  1565. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1566. if ev is None:
  1567. raise Exception("DPP configuration not completed (Configurator)")
  1568. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1569. if ev is None:
  1570. raise Exception("DPP configuration not completed (Enrollee)")
  1571. dev[0].request("DPP_STOP_LISTEN")
  1572. dev[0].dump_monitor()
  1573. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1574. """DPP with hostapd as configurator/responder"""
  1575. check_dpp_capab(dev[0])
  1576. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1577. "channel": "1" })
  1578. check_dpp_capab(hapd)
  1579. cmd = "DPP_CONFIGURATOR_ADD"
  1580. res = hapd.request(cmd);
  1581. if "FAIL" in res:
  1582. raise Exception("Failed to add configurator")
  1583. conf_id = int(res)
  1584. hapd.set("dpp_configurator_params",
  1585. " conf=sta-dpp configurator=%d" % conf_id);
  1586. addr = hapd.own_addr().replace(':', '')
  1587. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1588. res = hapd.request(cmd)
  1589. if "FAIL" in res:
  1590. raise Exception("Failed to generate bootstrapping info")
  1591. id0 = int(res)
  1592. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1593. res = dev[0].request("DPP_QR_CODE " + uri0)
  1594. if "FAIL" in res:
  1595. raise Exception("Failed to parse QR Code URI")
  1596. id1 = int(res)
  1597. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1598. if "OK" not in dev[0].request(cmd):
  1599. raise Exception("Failed to initiate DPP Authentication")
  1600. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1601. if ev is None:
  1602. raise Exception("DPP authentication did not succeed (Responder)")
  1603. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1604. if ev is None:
  1605. raise Exception("DPP authentication did not succeed (Initiator)")
  1606. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1607. if ev is None:
  1608. raise Exception("DPP configuration not completed (Configurator)")
  1609. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1610. if ev is None:
  1611. raise Exception("DPP configuration not completed (Enrollee)")
  1612. dev[0].request("DPP_STOP_LISTEN")
  1613. dev[0].dump_monitor()
  1614. def test_dpp_own_config(dev, apdev):
  1615. """DPP configurator signing own connector"""
  1616. try:
  1617. run_dpp_own_config(dev, apdev)
  1618. finally:
  1619. dev[0].set("dpp_config_processing", "0")
  1620. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1621. """DPP configurator signing own connector using mismatching curve"""
  1622. try:
  1623. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1624. finally:
  1625. dev[0].set("dpp_config_processing", "0")
  1626. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1627. check_dpp_capab(dev[0])
  1628. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1629. check_dpp_capab(hapd)
  1630. addr = hapd.own_addr().replace(':', '')
  1631. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1632. res = hapd.request(cmd)
  1633. if "FAIL" in res:
  1634. raise Exception("Failed to generate bootstrapping info")
  1635. id_h = int(res)
  1636. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1637. cmd = "DPP_CONFIGURATOR_ADD"
  1638. res = dev[0].request(cmd);
  1639. if "FAIL" in res:
  1640. raise Exception("Failed to add configurator")
  1641. conf_id = int(res)
  1642. res = dev[0].request("DPP_QR_CODE " + uri)
  1643. if "FAIL" in res:
  1644. raise Exception("Failed to parse QR Code URI")
  1645. id = int(res)
  1646. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1647. if "OK" not in dev[0].request(cmd):
  1648. raise Exception("Failed to initiate DPP Authentication")
  1649. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1650. if ev is None:
  1651. raise Exception("DPP authentication did not succeed (Responder)")
  1652. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1653. if ev is None:
  1654. raise Exception("DPP authentication did not succeed (Initiator)")
  1655. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1656. if ev is None:
  1657. raise Exception("DPP configuration not completed (Configurator)")
  1658. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1659. if ev is None:
  1660. raise Exception("DPP configuration not completed (Enrollee)")
  1661. update_hapd_config(hapd)
  1662. dev[0].set("dpp_config_processing", "1")
  1663. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1664. if own_curve:
  1665. cmd += " curve=" + own_curve
  1666. res = dev[0].request(cmd)
  1667. if "FAIL" in res:
  1668. raise Exception("Failed to generate own configuration")
  1669. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1670. if ev is None:
  1671. raise Exception("DPP network profile not generated")
  1672. id = ev.split(' ')[1]
  1673. dev[0].select_network(id, freq="2412")
  1674. if expect_failure:
  1675. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1676. if ev is not None:
  1677. raise Exception("Unexpected connection");
  1678. dev[0].request("DISCONNECT")
  1679. else:
  1680. dev[0].wait_connected()
  1681. def test_dpp_intro_mismatch(dev, apdev):
  1682. """DPP network introduction mismatch cases"""
  1683. try:
  1684. wpas = None
  1685. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1686. wpas.interface_add("wlan5")
  1687. check_dpp_capab(wpas)
  1688. run_dpp_intro_mismatch(dev, apdev, wpas)
  1689. finally:
  1690. dev[0].set("dpp_config_processing", "0")
  1691. dev[2].set("dpp_config_processing", "0")
  1692. if wpas:
  1693. wpas.set("dpp_config_processing", "0")
  1694. def run_dpp_intro_mismatch(dev, apdev, wpas):
  1695. check_dpp_capab(dev[0])
  1696. check_dpp_capab(dev[1])
  1697. check_dpp_capab(dev[2])
  1698. logger.info("Start AP in unconfigured state")
  1699. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1700. check_dpp_capab(hapd)
  1701. addr = hapd.own_addr().replace(':', '')
  1702. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1703. res = hapd.request(cmd)
  1704. if "FAIL" in res:
  1705. raise Exception("Failed to generate bootstrapping info")
  1706. id_h = int(res)
  1707. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1708. logger.info("Provision AP with DPP configuration")
  1709. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  1710. if "FAIL" in res:
  1711. raise Exception("Failed to add configurator")
  1712. conf_id = int(res)
  1713. res = dev[1].request("DPP_QR_CODE " + uri)
  1714. if "FAIL" in res:
  1715. raise Exception("Failed to parse QR Code URI")
  1716. id = int(res)
  1717. dev[1].set("dpp_groups_override", '[{"groupId":"a","netRole":"ap"}]')
  1718. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1719. if "OK" not in dev[1].request(cmd):
  1720. raise Exception("Failed to initiate DPP Authentication")
  1721. update_hapd_config(hapd)
  1722. logger.info("Provision STA0 with DPP Connector that has mismatching groupId")
  1723. dev[0].set("dpp_config_processing", "2")
  1724. addr = dev[0].own_addr().replace(':', '')
  1725. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1726. res = dev[0].request(cmd)
  1727. if "FAIL" in res:
  1728. raise Exception("Failed to generate bootstrapping info")
  1729. id0 = int(res)
  1730. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1731. res = dev[1].request("DPP_QR_CODE " + uri0)
  1732. if "FAIL" in res:
  1733. raise Exception("Failed to parse QR Code URI")
  1734. id1 = int(res)
  1735. cmd = "DPP_LISTEN 2412"
  1736. if "OK" not in dev[0].request(cmd):
  1737. raise Exception("Failed to start listen operation")
  1738. dev[1].set("dpp_groups_override", '[{"groupId":"b","netRole":"sta"}]')
  1739. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1740. if "OK" not in dev[1].request(cmd):
  1741. raise Exception("Failed to initiate DPP Authentication")
  1742. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1743. if ev is None:
  1744. raise Exception("DPP configuration not completed (Configurator for STA0)")
  1745. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1746. if ev is None:
  1747. raise Exception("DPP configuration not completed (Enrollee STA0)")
  1748. logger.info("Provision STA2 with DPP Connector that has mismatching C-sign-key")
  1749. dev[2].set("dpp_config_processing", "2")
  1750. addr = dev[2].own_addr().replace(':', '')
  1751. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1752. res = dev[2].request(cmd)
  1753. if "FAIL" in res:
  1754. raise Exception("Failed to generate bootstrapping info")
  1755. id2 = int(res)
  1756. uri2 = dev[2].request("DPP_BOOTSTRAP_GET_URI %d" % id2)
  1757. res = dev[1].request("DPP_QR_CODE " + uri2)
  1758. if "FAIL" in res:
  1759. raise Exception("Failed to parse QR Code URI")
  1760. id1 = int(res)
  1761. cmd = "DPP_LISTEN 2412"
  1762. if "OK" not in dev[2].request(cmd):
  1763. raise Exception("Failed to start listen operation")
  1764. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  1765. if "FAIL" in res:
  1766. raise Exception("Failed to add configurator")
  1767. conf_id_2 = int(res)
  1768. dev[1].set("dpp_groups_override", '')
  1769. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id_2)
  1770. if "OK" not in dev[1].request(cmd):
  1771. raise Exception("Failed to initiate DPP Authentication")
  1772. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1773. if ev is None:
  1774. raise Exception("DPP configuration not completed (Configurator for STA2)")
  1775. ev = dev[2].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1776. if ev is None:
  1777. raise Exception("DPP configuration not completed (Enrollee STA2)")
  1778. logger.info("Provision STA5 with DPP Connector that has mismatching netAccessKey EC group")
  1779. wpas.set("dpp_config_processing", "2")
  1780. addr = wpas.own_addr().replace(':', '')
  1781. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1782. cmd += " curve=P-521"
  1783. res = wpas.request(cmd)
  1784. if "FAIL" in res:
  1785. raise Exception("Failed to generate bootstrapping info")
  1786. id5 = int(res)
  1787. uri5 = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % id5)
  1788. res = dev[1].request("DPP_QR_CODE " + uri5)
  1789. if "FAIL" in res:
  1790. raise Exception("Failed to parse QR Code URI")
  1791. id1 = int(res)
  1792. cmd = "DPP_LISTEN 2412"
  1793. if "OK" not in wpas.request(cmd):
  1794. raise Exception("Failed to start listen operation")
  1795. dev[1].set("dpp_groups_override", '')
  1796. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1797. if "OK" not in dev[1].request(cmd):
  1798. raise Exception("Failed to initiate DPP Authentication")
  1799. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1800. if ev is None:
  1801. raise Exception("DPP configuration not completed (Configurator for STA0)")
  1802. ev = wpas.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1803. if ev is None:
  1804. raise Exception("DPP configuration not completed (Enrollee STA5)")
  1805. logger.info("Verify network introduction results")
  1806. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  1807. if ev is None:
  1808. raise Exception("DPP network introduction result not seen on STA0")
  1809. if "status=8" not in ev:
  1810. raise Exception("Unexpected network introduction result on STA0: " + ev)
  1811. ev = dev[2].wait_event(["DPP-INTRO"], timeout=5)
  1812. if ev is None:
  1813. raise Exception("DPP network introduction result not seen on STA2")
  1814. if "status=8" not in ev:
  1815. raise Exception("Unexpected network introduction result on STA2: " + ev)
  1816. ev = wpas.wait_event(["DPP-INTRO"], timeout=10)
  1817. if ev is None:
  1818. raise Exception("DPP network introduction result not seen on STA5")
  1819. if "status=7" not in ev:
  1820. raise Exception("Unexpected network introduction result on STA5: " + ev)
  1821. def run_dpp_proto_init(dev, test_dev, test, mutual=False):
  1822. check_dpp_capab(dev[0])
  1823. check_dpp_capab(dev[1])
  1824. dev[test_dev].set("dpp_test", str(test))
  1825. cmd = "DPP_CONFIGURATOR_ADD"
  1826. res = dev[1].request(cmd);
  1827. if "FAIL" in res:
  1828. raise Exception("Failed to add configurator")
  1829. conf_id = int(res)
  1830. addr = dev[0].own_addr().replace(':', '')
  1831. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1832. res = dev[0].request(cmd)
  1833. if "FAIL" in res:
  1834. raise Exception("Failed to generate bootstrapping info")
  1835. id0 = int(res)
  1836. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1837. res = dev[1].request("DPP_QR_CODE " + uri0)
  1838. if "FAIL" in res:
  1839. raise Exception("Failed to parse QR Code URI")
  1840. id1 = int(res)
  1841. if mutual:
  1842. addr = dev[1].own_addr().replace(':', '')
  1843. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  1844. if "FAIL" in res:
  1845. raise Exception("Failed to generate bootstrapping info")
  1846. id1b = int(res)
  1847. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  1848. res = dev[0].request("DPP_QR_CODE " + uri1b)
  1849. if "FAIL" in res:
  1850. raise Exception("Failed to parse QR Code URI")
  1851. id0b = int(res)
  1852. cmd = "DPP_LISTEN 2412"
  1853. if "OK" not in dev[0].request(cmd):
  1854. raise Exception("Failed to start listen operation")
  1855. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1856. if mutual:
  1857. cmd += " own=%d" % id1b
  1858. if "OK" not in dev[1].request(cmd):
  1859. raise Exception("Failed to initiate DPP Authentication")
  1860. def test_dpp_proto_after_wrapped_data_auth_req(dev, apdev):
  1861. """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
  1862. run_dpp_proto_init(dev, 1, 1)
  1863. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1864. if ev is None:
  1865. raise Exception("DPP Authentication Request not seen")
  1866. if "type=0" not in ev or "ignore=invalid-attributes" not in ev:
  1867. raise Exception("Unexpected RX info: " + ev)
  1868. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1869. if ev is not None:
  1870. raise Exception("Unexpected DPP message seen")
  1871. def test_dpp_proto_after_wrapped_data_auth_resp(dev, apdev):
  1872. """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
  1873. run_dpp_proto_init(dev, 0, 2)
  1874. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  1875. if ev is None:
  1876. raise Exception("DPP Authentication Response not seen")
  1877. if "type=1" not in ev or "ignore=invalid-attributes" not in ev:
  1878. raise Exception("Unexpected RX info: " + ev)
  1879. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1880. if ev is None or "type=0" not in ev:
  1881. raise Exception("DPP Authentication Request not seen")
  1882. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1883. if ev is not None:
  1884. raise Exception("Unexpected DPP message seen")
  1885. def test_dpp_proto_after_wrapped_data_auth_conf(dev, apdev):
  1886. """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
  1887. run_dpp_proto_init(dev, 1, 3)
  1888. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1889. if ev is None or "type=0" not in ev:
  1890. raise Exception("DPP Authentication Request not seen")
  1891. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1892. if ev is None:
  1893. raise Exception("DPP Authentication Confirm not seen")
  1894. if "type=2" not in ev or "ignore=invalid-attributes" not in ev:
  1895. raise Exception("Unexpected RX info: " + ev)
  1896. def test_dpp_proto_after_wrapped_data_conf_req(dev, apdev):
  1897. """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
  1898. run_dpp_proto_init(dev, 0, 6)
  1899. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=10)
  1900. if ev is None:
  1901. raise Exception("DPP Configuration failure not seen")
  1902. def test_dpp_proto_after_wrapped_data_conf_resp(dev, apdev):
  1903. """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
  1904. run_dpp_proto_init(dev, 1, 7)
  1905. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=10)
  1906. if ev is None:
  1907. raise Exception("DPP Configuration failure not seen")
  1908. def test_dpp_proto_zero_i_capab(dev, apdev):
  1909. """DPP protocol testing - zero I-capability in Auth Req"""
  1910. run_dpp_proto_init(dev, 1, 8)
  1911. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1912. if ev is None:
  1913. raise Exception("DPP failure not seen")
  1914. if "Invalid role in I-capabilities 0x00" not in ev:
  1915. raise Exception("Unexpected failure: " + ev)
  1916. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1917. if ev is not None:
  1918. raise Exception("Unexpected DPP message seen")
  1919. def test_dpp_proto_zero_r_capab(dev, apdev):
  1920. """DPP protocol testing - zero R-capability in Auth Resp"""
  1921. run_dpp_proto_init(dev, 0, 9)
  1922. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1923. if ev is None:
  1924. raise Exception("DPP failure not seen")
  1925. if "Unexpected role in R-capabilities 0x00" not in ev:
  1926. raise Exception("Unexpected failure: " + ev)
  1927. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1928. if ev is None or "type=0" not in ev:
  1929. raise Exception("DPP Authentication Request not seen")
  1930. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1931. if ev is not None:
  1932. raise Exception("Unexpected DPP message seen")
  1933. def run_dpp_proto_auth_req_missing(dev, test, reason):
  1934. run_dpp_proto_init(dev, 1, test)
  1935. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1936. if ev is None:
  1937. raise Exception("DPP failure not seen")
  1938. if reason not in ev:
  1939. raise Exception("Unexpected failure: " + ev)
  1940. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1941. if ev is not None:
  1942. raise Exception("Unexpected DPP message seen")
  1943. def test_dpp_proto_auth_req_no_r_bootstrap_key(dev, apdev):
  1944. """DPP protocol testing - no R-bootstrap key in Auth Req"""
  1945. run_dpp_proto_auth_req_missing(dev, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1946. def test_dpp_proto_auth_req_no_i_bootstrap_key(dev, apdev):
  1947. """DPP protocol testing - no I-bootstrap key in Auth Req"""
  1948. run_dpp_proto_auth_req_missing(dev, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
  1949. def test_dpp_proto_auth_req_no_i_proto_key(dev, apdev):
  1950. """DPP protocol testing - no I-proto key in Auth Req"""
  1951. run_dpp_proto_auth_req_missing(dev, 12, "Missing required Initiator Protocol Key attribute")
  1952. def test_dpp_proto_auth_req_no_i_nonce(dev, apdev):
  1953. """DPP protocol testing - no I-nonce in Auth Req"""
  1954. run_dpp_proto_auth_req_missing(dev, 13, "Missing or invalid I-nonce")
  1955. def test_dpp_proto_auth_req_no_i_capab(dev, apdev):
  1956. """DPP protocol testing - no I-capab in Auth Req"""
  1957. run_dpp_proto_auth_req_missing(dev, 14, "Missing or invalid I-capab")
  1958. def test_dpp_proto_auth_req_no_wrapped_data(dev, apdev):
  1959. """DPP protocol testing - no Wrapped Data in Auth Req"""
  1960. run_dpp_proto_auth_req_missing(dev, 15, "Missing or invalid required Wrapped Data attribute")
  1961. def run_dpp_proto_auth_resp_missing(dev, test, reason):
  1962. run_dpp_proto_init(dev, 0, test, mutual=True)
  1963. if reason is None:
  1964. time.sleep(0.1)
  1965. return
  1966. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1967. if ev is None:
  1968. raise Exception("DPP failure not seen")
  1969. if reason not in ev:
  1970. raise Exception("Unexpected failure: " + ev)
  1971. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1972. if ev is None or "type=0" not in ev:
  1973. raise Exception("DPP Authentication Request not seen")
  1974. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1975. if ev is not None:
  1976. raise Exception("Unexpected DPP message seen")
  1977. def test_dpp_proto_auth_resp_no_status(dev, apdev):
  1978. """DPP protocol testing - no Status in Auth Resp"""
  1979. run_dpp_proto_auth_resp_missing(dev, 16, "Missing or invalid required DPP Status attribute")
  1980. def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev, apdev):
  1981. """DPP protocol testing - no R-bootstrap key in Auth Resp"""
  1982. run_dpp_proto_auth_resp_missing(dev, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1983. def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev, apdev):
  1984. """DPP protocol testing - no I-bootstrap key in Auth Resp"""
  1985. run_dpp_proto_auth_resp_missing(dev, 18, None)
  1986. def test_dpp_proto_auth_resp_no_r_proto_key(dev, apdev):
  1987. """DPP protocol testing - no R-Proto Key in Auth Resp"""
  1988. run_dpp_proto_auth_resp_missing(dev, 19, "Missing required Responder Protocol Key attribute")
  1989. def test_dpp_proto_auth_resp_no_r_nonce(dev, apdev):
  1990. """DPP protocol testing - no R-nonce in Auth Resp"""
  1991. run_dpp_proto_auth_resp_missing(dev, 20, "Missing or invalid R-nonce")
  1992. def test_dpp_proto_auth_resp_no_i_nonce(dev, apdev):
  1993. """DPP protocol testing - no I-nonce in Auth Resp"""
  1994. run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce")
  1995. def test_dpp_proto_auth_resp_no_r_capab(dev, apdev):
  1996. """DPP protocol testing - no R-capab in Auth Resp"""
  1997. run_dpp_proto_auth_resp_missing(dev, 22, "Missing or invalid R-capabilities")
  1998. def test_dpp_proto_auth_resp_no_r_auth(dev, apdev):
  1999. """DPP protocol testing - no R-auth in Auth Resp"""
  2000. run_dpp_proto_auth_resp_missing(dev, 23, "Missing or invalid Secondary Wrapped Data")
  2001. def test_dpp_proto_auth_resp_no_wrapped_data(dev, apdev):
  2002. """DPP protocol testing - no Wrapped Data in Auth Resp"""
  2003. run_dpp_proto_auth_resp_missing(dev, 24, "Missing or invalid required Wrapped Data attribute")
  2004. def test_dpp_proto_auth_resp_i_nonce_mismatch(dev, apdev):
  2005. """DPP protocol testing - I-nonce mismatch in Auth Resp"""
  2006. run_dpp_proto_init(dev, 0, 30, mutual=True)
  2007. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2008. if ev is None:
  2009. raise Exception("DPP failure not seen")
  2010. if "I-nonce mismatch" not in ev:
  2011. raise Exception("Unexpected failure: " + ev)
  2012. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2013. if ev is None or "type=0" not in ev:
  2014. raise Exception("DPP Authentication Request not seen")
  2015. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2016. if ev is not None:
  2017. raise Exception("Unexpected DPP message seen")
  2018. def test_dpp_proto_auth_resp_incompatible_r_capab(dev, apdev):
  2019. """DPP protocol testing - Incompatible R-capab in Auth Resp"""
  2020. run_dpp_proto_init(dev, 0, 31, mutual=True)
  2021. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2022. if ev is None:
  2023. raise Exception("DPP failure not seen")
  2024. if "Unexpected role in R-capabilities 0x02" not in ev:
  2025. raise Exception("Unexpected failure: " + ev)
  2026. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2027. if ev is None:
  2028. raise Exception("DPP failure not seen")
  2029. if "Peer reported incompatible R-capab role" not in ev:
  2030. raise Exception("Unexpected failure: " + ev)
  2031. def test_dpp_proto_auth_resp_r_auth_mismatch(dev, apdev):
  2032. """DPP protocol testing - R-auth mismatch in Auth Resp"""
  2033. run_dpp_proto_init(dev, 0, 32, mutual=True)
  2034. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2035. if ev is None:
  2036. raise Exception("DPP failure not seen")
  2037. if "Mismatching Responder Authenticating Tag" not in ev:
  2038. raise Exception("Unexpected failure: " + ev)
  2039. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2040. if ev is None:
  2041. raise Exception("DPP failure not seen")
  2042. if "Peer reported authentication failure" not in ev:
  2043. raise Exception("Unexpected failure: " + ev)
  2044. def run_dpp_proto_auth_conf_missing(dev, test, reason):
  2045. run_dpp_proto_init(dev, 1, test, mutual=True)
  2046. if reason is None:
  2047. time.sleep(0.1)
  2048. return
  2049. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2050. if ev is None:
  2051. raise Exception("DPP failure not seen")
  2052. if reason not in ev:
  2053. raise Exception("Unexpected failure: " + ev)
  2054. def test_dpp_proto_auth_conf_no_status(dev, apdev):
  2055. """DPP protocol testing - no Status in Auth Conf"""
  2056. run_dpp_proto_auth_conf_missing(dev, 25, "Missing or invalid required DPP Status attribute")
  2057. def test_dpp_proto_auth_conf_no_r_bootstrap_key(dev, apdev):
  2058. """DPP protocol testing - no R-bootstrap key in Auth Conf"""
  2059. run_dpp_proto_auth_conf_missing(dev, 26, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2060. def test_dpp_proto_auth_conf_no_i_bootstrap_key(dev, apdev):
  2061. """DPP protocol testing - no I-bootstrap key in Auth Conf"""
  2062. run_dpp_proto_auth_conf_missing(dev, 27, "Missing Initiator Bootstrapping Key Hash attribute")
  2063. def test_dpp_proto_auth_conf_no_i_auth(dev, apdev):
  2064. """DPP protocol testing - no I-Auth in Auth Conf"""
  2065. run_dpp_proto_auth_conf_missing(dev, 28, "Missing or invalid Initiator Authenticating Tag")
  2066. def test_dpp_proto_auth_conf_no_wrapped_data(dev, apdev):
  2067. """DPP protocol testing - no Wrapped Data in Auth Conf"""
  2068. run_dpp_proto_auth_conf_missing(dev, 29, "Missing or invalid required Wrapped Data attribute")
  2069. def test_dpp_proto_auth_conf_i_auth_mismatch(dev, apdev):
  2070. """DPP protocol testing - I-auth mismatch in Auth Conf"""
  2071. run_dpp_proto_init(dev, 1, 33, mutual=True)
  2072. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2073. if ev is None:
  2074. raise Exception("DPP failure not seen")
  2075. if "Mismatching Initiator Authenticating Tag" not in ev:
  2076. raise Excception("Unexpected failure: " + ev)
  2077. def run_dpp_proto_init_pkex(dev, test_dev, test):
  2078. check_dpp_capab(dev[0])
  2079. check_dpp_capab(dev[1])
  2080. dev[test_dev].set("dpp_test", str(test))
  2081. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2082. res = dev[0].request(cmd)
  2083. if "FAIL" in res:
  2084. raise Exception("Failed to generate bootstrapping info")
  2085. id0 = int(res)
  2086. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2087. res = dev[1].request(cmd)
  2088. if "FAIL" in res:
  2089. raise Exception("Failed to generate bootstrapping info")
  2090. id1 = int(res)
  2091. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  2092. res = dev[0].request(cmd)
  2093. if "FAIL" in res:
  2094. raise Exception("Failed to set PKEX data (responder)")
  2095. cmd = "DPP_LISTEN 2437"
  2096. if "OK" not in dev[0].request(cmd):
  2097. raise Exception("Failed to start listen operation")
  2098. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  2099. res = dev[1].request(cmd)
  2100. if "FAIL" in res:
  2101. raise Exception("Failed to set PKEX data (initiator)")
  2102. def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev, apdev):
  2103. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
  2104. run_dpp_proto_init_pkex(dev, 1, 4)
  2105. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2106. if ev is None or "type=7" not in ev:
  2107. raise Exception("PKEX Exchange Request not seen")
  2108. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2109. if ev is None or "type=9" not in ev:
  2110. raise Exception("PKEX Commit-Reveal Request not seen")
  2111. if "ignore=invalid-attributes" not in ev:
  2112. raise Exception("Unexpected RX info: " + ev)
  2113. def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev, apdev):
  2114. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
  2115. run_dpp_proto_init_pkex(dev, 0, 5)
  2116. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2117. if ev is None or "type=8" not in ev:
  2118. raise Exception("PKEX Exchange Response not seen")
  2119. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2120. if ev is None or "type=10" not in ev:
  2121. raise Exception("PKEX Commit-Reveal Response not seen")
  2122. if "ignore=invalid-attributes" not in ev:
  2123. raise Exception("Unexpected RX info: " + ev)
  2124. def run_dpp_proto_pkex_req_missing(dev, test, reason):
  2125. run_dpp_proto_init_pkex(dev, 1, test)
  2126. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2127. if ev is None:
  2128. raise Exception("DPP failure not seen")
  2129. if reason not in ev:
  2130. raise Exception("Unexpected failure: " + ev)
  2131. def run_dpp_proto_pkex_resp_missing(dev, test, reason):
  2132. run_dpp_proto_init_pkex(dev, 0, test)
  2133. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2134. if ev is None:
  2135. raise Exception("DPP failure not seen")
  2136. if reason not in ev:
  2137. raise Exception("Unexpected failure: " + ev)
  2138. def test_dpp_proto_pkex_exchange_req_no_finite_cyclic_group(dev, apdev):
  2139. """DPP protocol testing - no Finite Cyclic Group in PKEX Exchange Request"""
  2140. run_dpp_proto_pkex_req_missing(dev, 34,
  2141. "Missing or invalid Finite Cyclic Group attribute")
  2142. def test_dpp_proto_pkex_exchange_req_no_encrypted_key(dev, apdev):
  2143. """DPP protocol testing - no Encrypted Key in PKEX Exchange Request"""
  2144. run_dpp_proto_pkex_req_missing(dev, 35,
  2145. "Missing Encrypted Key attribute")
  2146. def test_dpp_proto_pkex_exchange_resp_no_status(dev, apdev):
  2147. """DPP protocol testing - no Status in PKEX Exchange Response"""
  2148. run_dpp_proto_pkex_resp_missing(dev, 36, "No DPP Status attribute")
  2149. def test_dpp_proto_pkex_exchange_resp_no_encrypted_key(dev, apdev):
  2150. """DPP protocol testing - no Encrypted Key in PKEX Exchange Response"""
  2151. run_dpp_proto_pkex_resp_missing(dev, 37, "Missing Encrypted Key attribute")
  2152. def test_dpp_proto_pkex_cr_req_no_bootstrap_key(dev, apdev):
  2153. """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Request"""
  2154. run_dpp_proto_pkex_req_missing(dev, 38,
  2155. "No valid peer bootstrapping key found")
  2156. def test_dpp_proto_pkex_cr_req_no_i_auth_tag(dev, apdev):
  2157. """DPP protocol testing - no I-Auth Tag in PKEX Commit-Reveal Request"""
  2158. run_dpp_proto_pkex_req_missing(dev, 39, "No valid u (I-Auth tag) found")
  2159. def test_dpp_proto_pkex_cr_req_no_wrapped_data(dev, apdev):
  2160. """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Request"""
  2161. run_dpp_proto_pkex_req_missing(dev, 40, "Missing or invalid required Wrapped Data attribute")
  2162. def test_dpp_proto_pkex_cr_resp_no_bootstrap_key(dev, apdev):
  2163. """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Response"""
  2164. run_dpp_proto_pkex_resp_missing(dev, 41,
  2165. "No valid peer bootstrapping key found")
  2166. def test_dpp_proto_pkex_cr_resp_no_r_auth_tag(dev, apdev):
  2167. """DPP protocol testing - no R-Auth Tag in PKEX Commit-Reveal Response"""
  2168. run_dpp_proto_pkex_resp_missing(dev, 42, "No valid v (R-Auth tag) found")
  2169. def test_dpp_proto_pkex_cr_resp_no_wrapped_data(dev, apdev):
  2170. """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Response"""
  2171. run_dpp_proto_pkex_resp_missing(dev, 43, "Missing or invalid required Wrapped Data attribute")
  2172. def test_dpp_proto_pkex_exchange_req_invalid_encrypted_key(dev, apdev):
  2173. """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Request"""
  2174. run_dpp_proto_pkex_req_missing(dev, 44,
  2175. "Invalid Encrypted Key value")
  2176. def test_dpp_proto_pkex_exchange_resp_invalid_encrypted_key(dev, apdev):
  2177. """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Response"""
  2178. run_dpp_proto_pkex_resp_missing(dev, 45,
  2179. "Invalid Encrypted Key value")