test_dpp.py 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  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. try:
  765. hapd = hostapd.add_ap(apdev[0], params)
  766. except:
  767. raise HwsimSkip("DPP not supported")
  768. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  769. wait_connect=False)
  770. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  771. if not ev:
  772. raise Exception("Network mismatch not reported")
  773. dev[0].request("DISCONNECT")
  774. dev[0].dump_monitor()
  775. bssid = hapd.own_addr()
  776. pmkid = 16*'11'
  777. akmp = 2**23
  778. pmk = pmk_len*'22'
  779. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  780. if "OK" not in dev[0].request(cmd):
  781. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  782. dev[0].select_network(id, freq="2412")
  783. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  784. dev[0].request("DISCONNECT")
  785. dev[0].dump_monitor()
  786. if not ev:
  787. raise Exception("Association attempt was not rejected")
  788. if "status_code=53" not in ev:
  789. raise Exception("Unexpected status code: " + ev)
  790. addr = dev[0].own_addr()
  791. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  792. if "OK" not in hapd.request(cmd):
  793. raise Exception("PMKSA_ADD failed (hostapd)")
  794. dev[0].select_network(id, freq="2412")
  795. dev[0].wait_connected()
  796. val = dev[0].get_status_field("key_mgmt")
  797. if val != "DPP":
  798. raise Exception("Unexpected key_mgmt: " + val)
  799. def test_dpp_network_introduction(dev, apdev):
  800. """DPP network introduction"""
  801. check_dpp_capab(dev[0])
  802. check_dpp_capab(dev[1])
  803. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  804. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  805. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  806. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  807. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  808. params = { "ssid": "dpp",
  809. "wpa": "2",
  810. "wpa_key_mgmt": "DPP",
  811. "rsn_pairwise": "CCMP",
  812. "dpp_connector": ap_connector,
  813. "dpp_csign": csign,
  814. "dpp_netaccesskey": ap_netaccesskey }
  815. try:
  816. hapd = hostapd.add_ap(apdev[0], params)
  817. except:
  818. raise HwsimSkip("DPP not supported")
  819. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  820. dpp_csign=csign,
  821. dpp_connector=sta_connector,
  822. dpp_netaccesskey=sta_netaccesskey)
  823. val = dev[0].get_status_field("key_mgmt")
  824. if val != "DPP":
  825. raise Exception("Unexpected key_mgmt: " + val)
  826. def test_dpp_ap_config(dev, apdev):
  827. """DPP and AP configuration"""
  828. run_dpp_ap_config(dev, apdev)
  829. def test_dpp_ap_config_p256_p256(dev, apdev):
  830. """DPP and AP configuration (P-256 + P-256)"""
  831. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  832. def test_dpp_ap_config_p256_p384(dev, apdev):
  833. """DPP and AP configuration (P-256 + P-384)"""
  834. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  835. def test_dpp_ap_config_p256_p521(dev, apdev):
  836. """DPP and AP configuration (P-256 + P-521)"""
  837. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  838. def test_dpp_ap_config_p384_p256(dev, apdev):
  839. """DPP and AP configuration (P-384 + P-256)"""
  840. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  841. def test_dpp_ap_config_p384_p384(dev, apdev):
  842. """DPP and AP configuration (P-384 + P-384)"""
  843. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  844. def test_dpp_ap_config_p384_p521(dev, apdev):
  845. """DPP and AP configuration (P-384 + P-521)"""
  846. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  847. def test_dpp_ap_config_p521_p256(dev, apdev):
  848. """DPP and AP configuration (P-521 + P-256)"""
  849. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  850. def test_dpp_ap_config_p521_p384(dev, apdev):
  851. """DPP and AP configuration (P-521 + P-384)"""
  852. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  853. def test_dpp_ap_config_p521_p521(dev, apdev):
  854. """DPP and AP configuration (P-521 + P-521)"""
  855. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  856. def update_hapd_config(hapd):
  857. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  858. if ev is None:
  859. raise Exception("SSID not reported (AP)")
  860. ssid = ev.split(' ')[1]
  861. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  862. if ev is None:
  863. raise Exception("Connector not reported (AP)")
  864. connector = ev.split(' ')[1]
  865. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  866. if ev is None:
  867. raise Exception("C-sign-key not reported (AP)")
  868. p = ev.split(' ')
  869. csign = p[1]
  870. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  871. if ev is None:
  872. raise Exception("netAccessKey not reported (AP)")
  873. p = ev.split(' ')
  874. net_access_key = p[1]
  875. net_access_key_expiry = p[2] if len(p) > 2 else None
  876. logger.info("Update AP configuration to use key_mgmt=DPP")
  877. hapd.disable()
  878. hapd.set("ssid", ssid)
  879. hapd.set("wpa", "2")
  880. hapd.set("wpa_key_mgmt", "DPP")
  881. hapd.set("rsn_pairwise", "CCMP")
  882. hapd.set("dpp_connector", connector)
  883. hapd.set("dpp_csign", csign)
  884. hapd.set("dpp_netaccesskey", net_access_key)
  885. if net_access_key_expiry:
  886. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  887. hapd.enable()
  888. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  889. check_dpp_capab(dev[0])
  890. check_dpp_capab(dev[1])
  891. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  892. check_dpp_capab(hapd)
  893. addr = hapd.own_addr().replace(':', '')
  894. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  895. if curve:
  896. cmd += " curve=" + curve
  897. res = hapd.request(cmd)
  898. if "FAIL" in res:
  899. raise Exception("Failed to generate bootstrapping info")
  900. id_h = int(res)
  901. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  902. cmd = "DPP_CONFIGURATOR_ADD"
  903. if conf_curve:
  904. cmd += " curve=" + conf_curve
  905. res = dev[0].request(cmd);
  906. if "FAIL" in res:
  907. raise Exception("Failed to add configurator")
  908. conf_id = int(res)
  909. res = dev[0].request("DPP_QR_CODE " + uri)
  910. if "FAIL" in res:
  911. raise Exception("Failed to parse QR Code URI")
  912. id = int(res)
  913. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  914. if "OK" not in dev[0].request(cmd):
  915. raise Exception("Failed to initiate DPP Authentication")
  916. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  917. if ev is None:
  918. raise Exception("DPP authentication did not succeed (Responder)")
  919. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  920. if ev is None:
  921. raise Exception("DPP authentication did not succeed (Initiator)")
  922. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  923. if ev is None:
  924. raise Exception("DPP configuration not completed (Configurator)")
  925. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  926. if ev is None:
  927. raise Exception("DPP configuration not completed (Enrollee)")
  928. if "DPP-CONF-FAILED" in ev:
  929. raise Exception("DPP configuration failed")
  930. update_hapd_config(hapd)
  931. addr = dev[1].own_addr().replace(':', '')
  932. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  933. if curve:
  934. cmd += " curve=" + curve
  935. res = dev[1].request(cmd)
  936. if "FAIL" in res:
  937. raise Exception("Failed to generate bootstrapping info")
  938. id1 = int(res)
  939. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  940. res = dev[0].request("DPP_QR_CODE " + uri1)
  941. if "FAIL" in res:
  942. raise Exception("Failed to parse QR Code URI")
  943. id0b = int(res)
  944. cmd = "DPP_LISTEN 2412"
  945. if "OK" not in dev[1].request(cmd):
  946. raise Exception("Failed to start listen operation")
  947. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  948. if "OK" not in dev[0].request(cmd):
  949. raise Exception("Failed to initiate DPP Authentication")
  950. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  951. if ev is None:
  952. raise Exception("DPP authentication did not succeed (Responder)")
  953. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  954. if ev is None:
  955. raise Exception("DPP authentication did not succeed (Initiator)")
  956. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  957. if ev is None:
  958. raise Exception("DPP configuration not completed (Configurator)")
  959. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  960. if ev is None:
  961. raise Exception("DPP configuration not completed (Enrollee)")
  962. dev[1].request("DPP_STOP_LISTEN")
  963. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  964. if ev is None:
  965. raise Exception("SSID not reported")
  966. ssid = ev.split(' ')[1]
  967. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  968. if ev is None:
  969. raise Exception("Connector not reported")
  970. connector = ev.split(' ')[1]
  971. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  972. if ev is None:
  973. raise Exception("C-sign-key not reported")
  974. p = ev.split(' ')
  975. csign = p[1]
  976. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  977. if ev is None:
  978. raise Exception("netAccessKey not reported")
  979. p = ev.split(' ')
  980. net_access_key = p[1]
  981. net_access_key_expiry = p[2] if len(p) > 2 else None
  982. dev[1].dump_monitor()
  983. id = dev[1].connect(ssid, key_mgmt="DPP", scan_freq="2412",
  984. only_add_network=True)
  985. dev[1].set_network_quoted(id, "dpp_connector", connector)
  986. dev[1].set_network(id, "dpp_csign", csign)
  987. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  988. if net_access_key_expiry:
  989. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  990. logger.info("Check data connection")
  991. dev[1].select_network(id, freq="2412")
  992. dev[1].wait_connected()
  993. def test_dpp_auto_connect_1(dev, apdev):
  994. """DPP and auto connect (1)"""
  995. try:
  996. run_dpp_auto_connect(dev, apdev, 1)
  997. finally:
  998. dev[0].set("dpp_config_processing", "0")
  999. def test_dpp_auto_connect_2(dev, apdev):
  1000. """DPP and auto connect (2)"""
  1001. try:
  1002. run_dpp_auto_connect(dev, apdev, 2)
  1003. finally:
  1004. dev[0].set("dpp_config_processing", "0")
  1005. def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
  1006. """DPP and auto connect (2) using connect_cmd"""
  1007. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1008. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  1009. dev_new = [ wpas, dev[1] ]
  1010. try:
  1011. run_dpp_auto_connect(dev_new, apdev, 2)
  1012. finally:
  1013. wpas.set("dpp_config_processing", "0")
  1014. def run_dpp_auto_connect(dev, apdev, processing):
  1015. check_dpp_capab(dev[0])
  1016. check_dpp_capab(dev[1])
  1017. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1018. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1019. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1020. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1021. params = { "ssid": "test",
  1022. "wpa": "2",
  1023. "wpa_key_mgmt": "DPP",
  1024. "rsn_pairwise": "CCMP",
  1025. "dpp_connector": ap_connector,
  1026. "dpp_csign": csign_pub,
  1027. "dpp_netaccesskey": ap_netaccesskey }
  1028. try:
  1029. hapd = hostapd.add_ap(apdev[0], params)
  1030. except:
  1031. raise HwsimSkip("DPP not supported")
  1032. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1033. res = dev[1].request(cmd)
  1034. if "FAIL" in res:
  1035. raise Exception("DPP_CONFIGURATOR_ADD failed")
  1036. conf_id = int(res)
  1037. dev[0].set("dpp_config_processing", str(processing))
  1038. addr = dev[0].own_addr().replace(':', '')
  1039. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1040. res = dev[0].request(cmd)
  1041. if "FAIL" in res:
  1042. raise Exception("Failed to generate bootstrapping info")
  1043. id0 = int(res)
  1044. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1045. res = dev[1].request("DPP_QR_CODE " + uri0)
  1046. if "FAIL" in res:
  1047. raise Exception("Failed to parse QR Code URI")
  1048. id1 = int(res)
  1049. cmd = "DPP_LISTEN 2412"
  1050. if "OK" not in dev[0].request(cmd):
  1051. raise Exception("Failed to start listen operation")
  1052. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1053. if "OK" not in dev[1].request(cmd):
  1054. raise Exception("Failed to initiate DPP Authentication")
  1055. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1056. if ev is None:
  1057. raise Exception("DPP configuration not completed (Configurator)")
  1058. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1059. if ev is None:
  1060. raise Exception("DPP configuration not completed (Enrollee)")
  1061. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1062. if ev is None:
  1063. raise Exception("DPP network profile not generated")
  1064. id = ev.split(' ')[1]
  1065. if processing == 1:
  1066. dev[0].select_network(id, freq=2412)
  1067. dev[0].wait_connected()
  1068. hwsim_utils.test_connectivity(dev[0], hapd)
  1069. def test_dpp_auto_connect_legacy(dev, apdev):
  1070. """DPP and auto connect (legacy)"""
  1071. try:
  1072. run_dpp_auto_connect_legacy(dev, apdev)
  1073. finally:
  1074. dev[0].set("dpp_config_processing", "0")
  1075. def run_dpp_auto_connect_legacy(dev, apdev):
  1076. check_dpp_capab(dev[0])
  1077. check_dpp_capab(dev[1])
  1078. params = hostapd.wpa2_params(ssid="dpp-legacy",
  1079. passphrase="secret passphrase")
  1080. hapd = hostapd.add_ap(apdev[0], params)
  1081. dev[0].set("dpp_config_processing", "2")
  1082. addr = dev[0].own_addr().replace(':', '')
  1083. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1084. res = dev[0].request(cmd)
  1085. if "FAIL" in res:
  1086. raise Exception("Failed to generate bootstrapping info")
  1087. id0 = int(res)
  1088. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1089. res = dev[1].request("DPP_QR_CODE " + uri0)
  1090. if "FAIL" in res:
  1091. raise Exception("Failed to parse QR Code URI")
  1092. id1 = int(res)
  1093. cmd = "DPP_LISTEN 2412"
  1094. if "OK" not in dev[0].request(cmd):
  1095. raise Exception("Failed to start listen operation")
  1096. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  1097. if "OK" not in dev[1].request(cmd):
  1098. raise Exception("Failed to initiate DPP Authentication")
  1099. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1100. if ev is None:
  1101. raise Exception("DPP configuration not completed (Configurator)")
  1102. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1103. if ev is None:
  1104. raise Exception("DPP configuration not completed (Enrollee)")
  1105. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1106. if ev is None:
  1107. raise Exception("DPP network profile not generated")
  1108. id = ev.split(' ')[1]
  1109. dev[0].wait_connected()
  1110. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  1111. """DPP QR Code and responder as the configurator"""
  1112. check_dpp_capab(dev[0])
  1113. check_dpp_capab(dev[1])
  1114. cmd = "DPP_CONFIGURATOR_ADD"
  1115. res = dev[0].request(cmd);
  1116. if "FAIL" in res:
  1117. raise Exception("Failed to add configurator")
  1118. conf_id = int(res)
  1119. addr = dev[0].own_addr().replace(':', '')
  1120. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1121. res = dev[0].request(cmd)
  1122. if "FAIL" in res:
  1123. raise Exception("Failed to generate bootstrapping info")
  1124. id0 = int(res)
  1125. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1126. res = dev[1].request("DPP_QR_CODE " + uri0)
  1127. if "FAIL" in res:
  1128. raise Exception("Failed to parse QR Code URI")
  1129. id1 = int(res)
  1130. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  1131. cmd = "DPP_LISTEN 2412 role=configurator"
  1132. if "OK" not in dev[0].request(cmd):
  1133. raise Exception("Failed to start listen operation")
  1134. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1135. if "OK" not in dev[1].request(cmd):
  1136. raise Exception("Failed to initiate DPP Authentication")
  1137. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1138. if ev is None:
  1139. raise Exception("DPP authentication did not succeed (Responder)")
  1140. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1141. if ev is None:
  1142. raise Exception("DPP authentication did not succeed (Initiator)")
  1143. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1144. if ev is None:
  1145. raise Exception("DPP configuration not completed (Configurator)")
  1146. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1147. if ev is None:
  1148. raise Exception("DPP configuration not completed (Enrollee)")
  1149. dev[0].request("DPP_STOP_LISTEN")
  1150. dev[0].dump_monitor()
  1151. dev[1].dump_monitor()
  1152. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1153. """DPP QR Code and hostapd as initiator"""
  1154. check_dpp_capab(dev[0])
  1155. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1156. "channel": "6" })
  1157. check_dpp_capab(hapd)
  1158. cmd = "DPP_CONFIGURATOR_ADD"
  1159. res = dev[0].request(cmd);
  1160. if "FAIL" in res:
  1161. raise Exception("Failed to add configurator")
  1162. conf_id = int(res)
  1163. addr = dev[0].own_addr().replace(':', '')
  1164. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1165. res = dev[0].request(cmd)
  1166. if "FAIL" in res:
  1167. raise Exception("Failed to generate bootstrapping info")
  1168. id0 = int(res)
  1169. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1170. dev[0].set("dpp_configurator_params",
  1171. " conf=ap-dpp configurator=%d" % conf_id);
  1172. cmd = "DPP_LISTEN 2437 role=configurator"
  1173. if "OK" not in dev[0].request(cmd):
  1174. raise Exception("Failed to start listen operation")
  1175. res = hapd.request("DPP_QR_CODE " + uri0)
  1176. if "FAIL" in res:
  1177. raise Exception("Failed to parse QR Code URI")
  1178. id1 = int(res)
  1179. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1180. if "OK" not in hapd.request(cmd):
  1181. raise Exception("Failed to initiate DPP Authentication")
  1182. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1183. if ev is None:
  1184. raise Exception("DPP authentication did not succeed (Responder)")
  1185. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1186. if ev is None:
  1187. raise Exception("DPP authentication did not succeed (Initiator)")
  1188. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1189. if ev is None:
  1190. raise Exception("DPP configuration not completed (Configurator)")
  1191. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1192. if ev is None:
  1193. raise Exception("DPP configuration not completed (Enrollee)")
  1194. dev[0].request("DPP_STOP_LISTEN")
  1195. dev[0].dump_monitor()
  1196. def test_dpp_pkex(dev, apdev):
  1197. """DPP and PKEX"""
  1198. run_dpp_pkex(dev, apdev)
  1199. def test_dpp_pkex_p256(dev, apdev):
  1200. """DPP and PKEX (P-256)"""
  1201. run_dpp_pkex(dev, apdev, "P-256")
  1202. def test_dpp_pkex_p384(dev, apdev):
  1203. """DPP and PKEX (P-384)"""
  1204. run_dpp_pkex(dev, apdev, "P-384")
  1205. def test_dpp_pkex_p521(dev, apdev):
  1206. """DPP and PKEX (P-521)"""
  1207. run_dpp_pkex(dev, apdev, "P-521")
  1208. def test_dpp_pkex_bp256(dev, apdev):
  1209. """DPP and PKEX (BP-256)"""
  1210. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1211. def test_dpp_pkex_bp384(dev, apdev):
  1212. """DPP and PKEX (BP-384)"""
  1213. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1214. def test_dpp_pkex_bp512(dev, apdev):
  1215. """DPP and PKEX (BP-512)"""
  1216. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1217. def test_dpp_pkex_config(dev, apdev):
  1218. """DPP and PKEX with initiator as the configurator"""
  1219. check_dpp_capab(dev[1])
  1220. cmd = "DPP_CONFIGURATOR_ADD"
  1221. res = dev[1].request(cmd);
  1222. if "FAIL" in res:
  1223. raise Exception("Failed to add configurator")
  1224. conf_id = int(res)
  1225. run_dpp_pkex(dev, apdev,
  1226. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1227. check_config=True)
  1228. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1229. check_dpp_capab(dev[0])
  1230. check_dpp_capab(dev[1])
  1231. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1232. if curve:
  1233. cmd += " curve=" + curve
  1234. res = dev[0].request(cmd)
  1235. if "FAIL" in res:
  1236. raise Exception("Failed to generate bootstrapping info")
  1237. id0 = int(res)
  1238. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1239. if curve:
  1240. cmd += " curve=" + curve
  1241. res = dev[1].request(cmd)
  1242. if "FAIL" in res:
  1243. raise Exception("Failed to generate bootstrapping info")
  1244. id1 = int(res)
  1245. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1246. res = dev[0].request(cmd)
  1247. if "FAIL" in res:
  1248. raise Exception("Failed to set PKEX data (responder)")
  1249. cmd = "DPP_LISTEN 2437"
  1250. if "OK" not in dev[0].request(cmd):
  1251. raise Exception("Failed to start listen operation")
  1252. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1253. res = dev[1].request(cmd)
  1254. if "FAIL" in res:
  1255. raise Exception("Failed to set PKEX data (initiator)")
  1256. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1257. if ev is None:
  1258. raise Exception("DPP authentication did not succeed (Initiator)")
  1259. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1260. if ev is None:
  1261. raise Exception("DPP authentication did not succeed (Responder)")
  1262. if check_config:
  1263. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1264. if ev is None:
  1265. raise Exception("DPP configuration not completed (Configurator)")
  1266. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1267. if ev is None:
  1268. raise Exception("DPP configuration not completed (Enrollee)")
  1269. def test_dpp_pkex_config2(dev, apdev):
  1270. """DPP and PKEX with responder as the configurator"""
  1271. check_dpp_capab(dev[0])
  1272. cmd = "DPP_CONFIGURATOR_ADD"
  1273. res = dev[0].request(cmd);
  1274. if "FAIL" in res:
  1275. raise Exception("Failed to add configurator")
  1276. conf_id = int(res)
  1277. dev[0].set("dpp_configurator_params",
  1278. " conf=sta-dpp configurator=%d" % conf_id);
  1279. run_dpp_pkex2(dev, apdev)
  1280. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1281. check_dpp_capab(dev[0])
  1282. check_dpp_capab(dev[1])
  1283. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1284. if curve:
  1285. cmd += " curve=" + curve
  1286. res = dev[0].request(cmd)
  1287. if "FAIL" in res:
  1288. raise Exception("Failed to generate bootstrapping info")
  1289. id0 = int(res)
  1290. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1291. if curve:
  1292. cmd += " curve=" + curve
  1293. res = dev[1].request(cmd)
  1294. if "FAIL" in res:
  1295. raise Exception("Failed to generate bootstrapping info")
  1296. id1 = int(res)
  1297. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1298. res = dev[0].request(cmd)
  1299. if "FAIL" in res:
  1300. raise Exception("Failed to set PKEX data (responder)")
  1301. cmd = "DPP_LISTEN 2437 role=configurator"
  1302. if "OK" not in dev[0].request(cmd):
  1303. raise Exception("Failed to start listen operation")
  1304. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1305. res = dev[1].request(cmd)
  1306. if "FAIL" in res:
  1307. raise Exception("Failed to set PKEX data (initiator)")
  1308. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1309. if ev is None:
  1310. raise Exception("DPP authentication did not succeed (Initiator)")
  1311. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1312. if ev is None:
  1313. raise Exception("DPP authentication did not succeed (Responder)")
  1314. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1315. if ev is None:
  1316. raise Exception("DPP configuration not completed (Configurator)")
  1317. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1318. if ev is None:
  1319. raise Exception("DPP configuration not completed (Enrollee)")
  1320. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1321. """DPP PKEX with hostapd as responder"""
  1322. check_dpp_capab(dev[0])
  1323. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1324. "channel": "6" })
  1325. check_dpp_capab(hapd)
  1326. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1327. res = hapd.request(cmd)
  1328. if "FAIL" in res:
  1329. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1330. id_h = int(res)
  1331. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1332. res = hapd.request(cmd)
  1333. if "FAIL" in res:
  1334. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1335. cmd = "DPP_CONFIGURATOR_ADD"
  1336. res = dev[0].request(cmd);
  1337. if "FAIL" in res:
  1338. raise Exception("Failed to add configurator")
  1339. conf_id = int(res)
  1340. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1341. res = dev[0].request(cmd)
  1342. if "FAIL" in res:
  1343. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1344. id0 = int(res)
  1345. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1346. res = dev[0].request(cmd)
  1347. if "FAIL" in res:
  1348. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1349. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1350. if ev is None:
  1351. raise Exception("DPP authentication did not succeed (Initiator)")
  1352. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1353. if ev is None:
  1354. raise Exception("DPP authentication did not succeed (Responder)")
  1355. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1356. if ev is None:
  1357. raise Exception("DPP configuration not completed (Configurator)")
  1358. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1359. if ev is None:
  1360. raise Exception("DPP configuration not completed (Enrollee)")
  1361. dev[0].request("DPP_STOP_LISTEN")
  1362. dev[0].dump_monitor()
  1363. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1364. """DPP PKEX with hostapd as initiator"""
  1365. check_dpp_capab(dev[0])
  1366. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1367. "channel": "6" })
  1368. check_dpp_capab(hapd)
  1369. cmd = "DPP_CONFIGURATOR_ADD"
  1370. res = dev[0].request(cmd);
  1371. if "FAIL" in res:
  1372. raise Exception("Failed to add configurator")
  1373. conf_id = int(res)
  1374. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1375. res = dev[0].request(cmd)
  1376. if "FAIL" in res:
  1377. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1378. id0 = int(res)
  1379. dev[0].set("dpp_configurator_params",
  1380. " conf=ap-dpp configurator=%d" % conf_id);
  1381. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1382. res = dev[0].request(cmd)
  1383. if "FAIL" in res:
  1384. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1385. cmd = "DPP_LISTEN 2437 role=configurator"
  1386. if "OK" not in dev[0].request(cmd):
  1387. raise Exception("Failed to start listen operation")
  1388. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1389. res = hapd.request(cmd)
  1390. if "FAIL" in res:
  1391. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1392. id_h = int(res)
  1393. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1394. res = hapd.request(cmd)
  1395. if "FAIL" in res:
  1396. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1397. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1398. if ev is None:
  1399. raise Exception("DPP authentication did not succeed (Initiator)")
  1400. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1401. if ev is None:
  1402. raise Exception("DPP authentication did not succeed (Responder)")
  1403. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1404. if ev is None:
  1405. raise Exception("DPP configuration not completed (Configurator)")
  1406. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1407. if ev is None:
  1408. raise Exception("DPP configuration not completed (Enrollee)")
  1409. dev[0].request("DPP_STOP_LISTEN")
  1410. dev[0].dump_monitor()
  1411. def test_dpp_hostapd_configurator(dev, apdev):
  1412. """DPP with hostapd as configurator/initiator"""
  1413. check_dpp_capab(dev[0])
  1414. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1415. "channel": "1" })
  1416. check_dpp_capab(hapd)
  1417. cmd = "DPP_CONFIGURATOR_ADD"
  1418. res = hapd.request(cmd);
  1419. if "FAIL" in res:
  1420. raise Exception("Failed to add configurator")
  1421. conf_id = int(res)
  1422. addr = dev[0].own_addr().replace(':', '')
  1423. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1424. res = dev[0].request(cmd)
  1425. if "FAIL" in res:
  1426. raise Exception("Failed to generate bootstrapping info")
  1427. id0 = int(res)
  1428. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1429. res = hapd.request("DPP_QR_CODE " + uri0)
  1430. if "FAIL" in res:
  1431. raise Exception("Failed to parse QR Code URI")
  1432. id1 = int(res)
  1433. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1434. if "FAIL" in res:
  1435. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1436. if "type=QRCODE" not in res:
  1437. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1438. if "mac_addr=" + dev[0].own_addr() not in res:
  1439. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1440. cmd = "DPP_LISTEN 2412"
  1441. if "OK" not in dev[0].request(cmd):
  1442. raise Exception("Failed to start listen operation")
  1443. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1444. if "OK" not in hapd.request(cmd):
  1445. raise Exception("Failed to initiate DPP Authentication")
  1446. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1447. if ev is None:
  1448. raise Exception("DPP authentication did not succeed (Responder)")
  1449. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1450. if ev is None:
  1451. raise Exception("DPP authentication did not succeed (Initiator)")
  1452. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1453. if ev is None:
  1454. raise Exception("DPP configuration not completed (Configurator)")
  1455. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1456. if ev is None:
  1457. raise Exception("DPP configuration not completed (Enrollee)")
  1458. dev[0].request("DPP_STOP_LISTEN")
  1459. dev[0].dump_monitor()
  1460. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1461. """DPP with hostapd as configurator/responder"""
  1462. check_dpp_capab(dev[0])
  1463. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1464. "channel": "1" })
  1465. check_dpp_capab(hapd)
  1466. cmd = "DPP_CONFIGURATOR_ADD"
  1467. res = hapd.request(cmd);
  1468. if "FAIL" in res:
  1469. raise Exception("Failed to add configurator")
  1470. conf_id = int(res)
  1471. hapd.set("dpp_configurator_params",
  1472. " conf=sta-dpp configurator=%d" % conf_id);
  1473. addr = hapd.own_addr().replace(':', '')
  1474. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1475. res = hapd.request(cmd)
  1476. if "FAIL" in res:
  1477. raise Exception("Failed to generate bootstrapping info")
  1478. id0 = int(res)
  1479. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1480. res = dev[0].request("DPP_QR_CODE " + uri0)
  1481. if "FAIL" in res:
  1482. raise Exception("Failed to parse QR Code URI")
  1483. id1 = int(res)
  1484. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1485. if "OK" not in dev[0].request(cmd):
  1486. raise Exception("Failed to initiate DPP Authentication")
  1487. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1488. if ev is None:
  1489. raise Exception("DPP authentication did not succeed (Responder)")
  1490. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1491. if ev is None:
  1492. raise Exception("DPP authentication did not succeed (Initiator)")
  1493. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1494. if ev is None:
  1495. raise Exception("DPP configuration not completed (Configurator)")
  1496. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1497. if ev is None:
  1498. raise Exception("DPP configuration not completed (Enrollee)")
  1499. dev[0].request("DPP_STOP_LISTEN")
  1500. dev[0].dump_monitor()
  1501. def test_dpp_own_config(dev, apdev):
  1502. """DPP configurator signing own connector"""
  1503. try:
  1504. run_dpp_own_config(dev, apdev)
  1505. finally:
  1506. dev[0].set("dpp_config_processing", "0")
  1507. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1508. """DPP configurator signing own connector using mismatching curve"""
  1509. try:
  1510. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1511. finally:
  1512. dev[0].set("dpp_config_processing", "0")
  1513. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1514. check_dpp_capab(dev[0])
  1515. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1516. check_dpp_capab(hapd)
  1517. addr = hapd.own_addr().replace(':', '')
  1518. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1519. res = hapd.request(cmd)
  1520. if "FAIL" in res:
  1521. raise Exception("Failed to generate bootstrapping info")
  1522. id_h = int(res)
  1523. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1524. cmd = "DPP_CONFIGURATOR_ADD"
  1525. res = dev[0].request(cmd);
  1526. if "FAIL" in res:
  1527. raise Exception("Failed to add configurator")
  1528. conf_id = int(res)
  1529. res = dev[0].request("DPP_QR_CODE " + uri)
  1530. if "FAIL" in res:
  1531. raise Exception("Failed to parse QR Code URI")
  1532. id = int(res)
  1533. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1534. if "OK" not in dev[0].request(cmd):
  1535. raise Exception("Failed to initiate DPP Authentication")
  1536. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1537. if ev is None:
  1538. raise Exception("DPP authentication did not succeed (Responder)")
  1539. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1540. if ev is None:
  1541. raise Exception("DPP authentication did not succeed (Initiator)")
  1542. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1543. if ev is None:
  1544. raise Exception("DPP configuration not completed (Configurator)")
  1545. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1546. if ev is None:
  1547. raise Exception("DPP configuration not completed (Enrollee)")
  1548. update_hapd_config(hapd)
  1549. dev[0].set("dpp_config_processing", "1")
  1550. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1551. if own_curve:
  1552. cmd += " curve=" + own_curve
  1553. res = dev[0].request(cmd)
  1554. if "FAIL" in res:
  1555. raise Exception("Failed to generate own configuration")
  1556. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1557. if ev is None:
  1558. raise Exception("DPP network profile not generated")
  1559. id = ev.split(' ')[1]
  1560. dev[0].select_network(id, freq="2412")
  1561. if expect_failure:
  1562. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1563. if ev is not None:
  1564. raise Exception("Unexpected connection");
  1565. dev[0].request("DISCONNECT")
  1566. else:
  1567. dev[0].wait_connected()
  1568. def test_dpp_intro_mismatch(dev, apdev):
  1569. """DPP network introduction mismatch cases"""
  1570. try:
  1571. wpas = None
  1572. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1573. wpas.interface_add("wlan5")
  1574. check_dpp_capab(wpas)
  1575. run_dpp_intro_mismatch(dev, apdev, wpas)
  1576. finally:
  1577. dev[0].set("dpp_config_processing", "0")
  1578. dev[2].set("dpp_config_processing", "0")
  1579. if wpas:
  1580. wpas.set("dpp_config_processing", "0")
  1581. def run_dpp_intro_mismatch(dev, apdev, wpas):
  1582. check_dpp_capab(dev[0])
  1583. check_dpp_capab(dev[1])
  1584. check_dpp_capab(dev[2])
  1585. logger.info("Start AP in unconfigured state")
  1586. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1587. check_dpp_capab(hapd)
  1588. addr = hapd.own_addr().replace(':', '')
  1589. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1590. res = hapd.request(cmd)
  1591. if "FAIL" in res:
  1592. raise Exception("Failed to generate bootstrapping info")
  1593. id_h = int(res)
  1594. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1595. logger.info("Provision AP with DPP configuration")
  1596. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  1597. if "FAIL" in res:
  1598. raise Exception("Failed to add configurator")
  1599. conf_id = int(res)
  1600. res = dev[1].request("DPP_QR_CODE " + uri)
  1601. if "FAIL" in res:
  1602. raise Exception("Failed to parse QR Code URI")
  1603. id = int(res)
  1604. dev[1].set("dpp_groups_override", '[{"groupId":"a","netRole":"ap"}]')
  1605. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1606. if "OK" not in dev[1].request(cmd):
  1607. raise Exception("Failed to initiate DPP Authentication")
  1608. update_hapd_config(hapd)
  1609. logger.info("Provision STA0 with DPP Connector that has mismatching groupId")
  1610. dev[0].set("dpp_config_processing", "2")
  1611. addr = dev[0].own_addr().replace(':', '')
  1612. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1613. res = dev[0].request(cmd)
  1614. if "FAIL" in res:
  1615. raise Exception("Failed to generate bootstrapping info")
  1616. id0 = int(res)
  1617. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1618. res = dev[1].request("DPP_QR_CODE " + uri0)
  1619. if "FAIL" in res:
  1620. raise Exception("Failed to parse QR Code URI")
  1621. id1 = int(res)
  1622. cmd = "DPP_LISTEN 2412"
  1623. if "OK" not in dev[0].request(cmd):
  1624. raise Exception("Failed to start listen operation")
  1625. dev[1].set("dpp_groups_override", '[{"groupId":"b","netRole":"sta"}]')
  1626. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1627. if "OK" not in dev[1].request(cmd):
  1628. raise Exception("Failed to initiate DPP Authentication")
  1629. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1630. if ev is None:
  1631. raise Exception("DPP configuration not completed (Configurator for STA0)")
  1632. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1633. if ev is None:
  1634. raise Exception("DPP configuration not completed (Enrollee STA0)")
  1635. logger.info("Provision STA2 with DPP Connector that has mismatching C-sign-key")
  1636. dev[2].set("dpp_config_processing", "2")
  1637. addr = dev[2].own_addr().replace(':', '')
  1638. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1639. res = dev[2].request(cmd)
  1640. if "FAIL" in res:
  1641. raise Exception("Failed to generate bootstrapping info")
  1642. id2 = int(res)
  1643. uri2 = dev[2].request("DPP_BOOTSTRAP_GET_URI %d" % id2)
  1644. res = dev[1].request("DPP_QR_CODE " + uri2)
  1645. if "FAIL" in res:
  1646. raise Exception("Failed to parse QR Code URI")
  1647. id1 = int(res)
  1648. cmd = "DPP_LISTEN 2412"
  1649. if "OK" not in dev[2].request(cmd):
  1650. raise Exception("Failed to start listen operation")
  1651. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  1652. if "FAIL" in res:
  1653. raise Exception("Failed to add configurator")
  1654. conf_id_2 = int(res)
  1655. dev[1].set("dpp_groups_override", '')
  1656. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id_2)
  1657. if "OK" not in dev[1].request(cmd):
  1658. raise Exception("Failed to initiate DPP Authentication")
  1659. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1660. if ev is None:
  1661. raise Exception("DPP configuration not completed (Configurator for STA2)")
  1662. ev = dev[2].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1663. if ev is None:
  1664. raise Exception("DPP configuration not completed (Enrollee STA2)")
  1665. logger.info("Provision STA5 with DPP Connector that has mismatching netAccessKey EC group")
  1666. wpas.set("dpp_config_processing", "2")
  1667. addr = wpas.own_addr().replace(':', '')
  1668. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1669. cmd += " curve=P-521"
  1670. res = wpas.request(cmd)
  1671. if "FAIL" in res:
  1672. raise Exception("Failed to generate bootstrapping info")
  1673. id5 = int(res)
  1674. uri5 = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % id5)
  1675. res = dev[1].request("DPP_QR_CODE " + uri5)
  1676. if "FAIL" in res:
  1677. raise Exception("Failed to parse QR Code URI")
  1678. id1 = int(res)
  1679. cmd = "DPP_LISTEN 2412"
  1680. if "OK" not in wpas.request(cmd):
  1681. raise Exception("Failed to start listen operation")
  1682. dev[1].set("dpp_groups_override", '')
  1683. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1684. if "OK" not in dev[1].request(cmd):
  1685. raise Exception("Failed to initiate DPP Authentication")
  1686. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1687. if ev is None:
  1688. raise Exception("DPP configuration not completed (Configurator for STA0)")
  1689. ev = wpas.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1690. if ev is None:
  1691. raise Exception("DPP configuration not completed (Enrollee STA5)")
  1692. logger.info("Verify network introduction results")
  1693. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  1694. if ev is None:
  1695. raise Exception("DPP network introduction result not seen on STA0")
  1696. if "status=8" not in ev:
  1697. raise Exception("Unexpected network introduction result on STA0: " + ev)
  1698. ev = dev[2].wait_event(["DPP-INTRO"], timeout=5)
  1699. if ev is None:
  1700. raise Exception("DPP network introduction result not seen on STA2")
  1701. if "status=8" not in ev:
  1702. raise Exception("Unexpected network introduction result on STA2: " + ev)
  1703. ev = wpas.wait_event(["DPP-INTRO"], timeout=10)
  1704. if ev is None:
  1705. raise Exception("DPP network introduction result not seen on STA5")
  1706. if "status=7" not in ev:
  1707. raise Exception("Unexpected network introduction result on STA5: " + ev)
  1708. def run_dpp_proto_init(dev, test_dev, test, mutual=False):
  1709. check_dpp_capab(dev[0])
  1710. check_dpp_capab(dev[1])
  1711. dev[test_dev].set("dpp_test", str(test))
  1712. cmd = "DPP_CONFIGURATOR_ADD"
  1713. res = dev[1].request(cmd);
  1714. if "FAIL" in res:
  1715. raise Exception("Failed to add configurator")
  1716. conf_id = int(res)
  1717. addr = dev[0].own_addr().replace(':', '')
  1718. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1719. res = dev[0].request(cmd)
  1720. if "FAIL" in res:
  1721. raise Exception("Failed to generate bootstrapping info")
  1722. id0 = int(res)
  1723. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1724. res = dev[1].request("DPP_QR_CODE " + uri0)
  1725. if "FAIL" in res:
  1726. raise Exception("Failed to parse QR Code URI")
  1727. id1 = int(res)
  1728. if mutual:
  1729. addr = dev[1].own_addr().replace(':', '')
  1730. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  1731. if "FAIL" in res:
  1732. raise Exception("Failed to generate bootstrapping info")
  1733. id1b = int(res)
  1734. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  1735. res = dev[0].request("DPP_QR_CODE " + uri1b)
  1736. if "FAIL" in res:
  1737. raise Exception("Failed to parse QR Code URI")
  1738. id0b = int(res)
  1739. cmd = "DPP_LISTEN 2412"
  1740. if "OK" not in dev[0].request(cmd):
  1741. raise Exception("Failed to start listen operation")
  1742. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1743. if mutual:
  1744. cmd += " own=%d" % id1b
  1745. if "OK" not in dev[1].request(cmd):
  1746. raise Exception("Failed to initiate DPP Authentication")
  1747. def test_dpp_proto_after_wrapped_data_auth_req(dev, apdev):
  1748. """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
  1749. run_dpp_proto_init(dev, 1, 1)
  1750. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1751. if ev is None:
  1752. raise Exception("DPP Authentication Request not seen")
  1753. if "type=0" not in ev or "ignore=invalid-attributes" not in ev:
  1754. raise Exception("Unexpected RX info: " + ev)
  1755. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1756. if ev is not None:
  1757. raise Exception("Unexpected DPP message seen")
  1758. def test_dpp_proto_after_wrapped_data_auth_resp(dev, apdev):
  1759. """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
  1760. run_dpp_proto_init(dev, 0, 2)
  1761. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  1762. if ev is None:
  1763. raise Exception("DPP Authentication Response not seen")
  1764. if "type=1" not in ev or "ignore=invalid-attributes" not in ev:
  1765. raise Exception("Unexpected RX info: " + ev)
  1766. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1767. if ev is None or "type=0" not in ev:
  1768. raise Exception("DPP Authentication Request not seen")
  1769. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1770. if ev is not None:
  1771. raise Exception("Unexpected DPP message seen")
  1772. def test_dpp_proto_after_wrapped_data_auth_conf(dev, apdev):
  1773. """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
  1774. run_dpp_proto_init(dev, 1, 3)
  1775. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1776. if ev is None or "type=0" not in ev:
  1777. raise Exception("DPP Authentication Request not seen")
  1778. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1779. if ev is None:
  1780. raise Exception("DPP Authentication Confirm not seen")
  1781. if "type=2" not in ev or "ignore=invalid-attributes" not in ev:
  1782. raise Exception("Unexpected RX info: " + ev)
  1783. def test_dpp_proto_after_wrapped_data_conf_req(dev, apdev):
  1784. """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
  1785. run_dpp_proto_init(dev, 0, 6)
  1786. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=10)
  1787. if ev is None:
  1788. raise Exception("DPP Configuration failure not seen")
  1789. def test_dpp_proto_after_wrapped_data_conf_resp(dev, apdev):
  1790. """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
  1791. run_dpp_proto_init(dev, 1, 7)
  1792. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=10)
  1793. if ev is None:
  1794. raise Exception("DPP Configuration failure not seen")
  1795. def test_dpp_proto_zero_i_capab(dev, apdev):
  1796. """DPP protocol testing - zero I-capability in Auth Req"""
  1797. run_dpp_proto_init(dev, 1, 8)
  1798. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1799. if ev is None:
  1800. raise Exception("DPP failure not seen")
  1801. if "Invalid role in I-capabilities 0x00" not in ev:
  1802. raise Exception("Unexpected failure: " + ev)
  1803. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1804. if ev is not None:
  1805. raise Exception("Unexpected DPP message seen")
  1806. def test_dpp_proto_zero_r_capab(dev, apdev):
  1807. """DPP protocol testing - zero R-capability in Auth Resp"""
  1808. run_dpp_proto_init(dev, 0, 9)
  1809. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1810. if ev is None:
  1811. raise Exception("DPP failure not seen")
  1812. if "Unexpected role in R-capabilities 0x00" not in ev:
  1813. raise Exception("Unexpected failure: " + ev)
  1814. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1815. if ev is None or "type=0" not in ev:
  1816. raise Exception("DPP Authentication Request not seen")
  1817. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1818. if ev is not None:
  1819. raise Exception("Unexpected DPP message seen")
  1820. def run_dpp_proto_auth_req_missing(dev, test, reason):
  1821. run_dpp_proto_init(dev, 1, test)
  1822. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1823. if ev is None:
  1824. raise Exception("DPP failure not seen")
  1825. if reason not in ev:
  1826. raise Exception("Unexpected failure: " + ev)
  1827. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  1828. if ev is not None:
  1829. raise Exception("Unexpected DPP message seen")
  1830. def test_dpp_proto_auth_req_no_r_bootstrap_key(dev, apdev):
  1831. """DPP protocol testing - no R-bootstrap key in Auth Req"""
  1832. run_dpp_proto_auth_req_missing(dev, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1833. def test_dpp_proto_auth_req_no_i_bootstrap_key(dev, apdev):
  1834. """DPP protocol testing - no I-bootstrap key in Auth Req"""
  1835. run_dpp_proto_auth_req_missing(dev, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
  1836. def test_dpp_proto_auth_req_no_i_proto_key(dev, apdev):
  1837. """DPP protocol testing - no I-proto key in Auth Req"""
  1838. run_dpp_proto_auth_req_missing(dev, 12, "Missing required Initiator Protocol Key attribute")
  1839. def test_dpp_proto_auth_req_no_i_nonce(dev, apdev):
  1840. """DPP protocol testing - no I-nonce in Auth Req"""
  1841. run_dpp_proto_auth_req_missing(dev, 13, "Missing or invalid I-nonce")
  1842. def test_dpp_proto_auth_req_no_i_capab(dev, apdev):
  1843. """DPP protocol testing - no I-capab in Auth Req"""
  1844. run_dpp_proto_auth_req_missing(dev, 14, "Missing or invalid I-capab")
  1845. def test_dpp_proto_auth_req_no_wrapped_data(dev, apdev):
  1846. """DPP protocol testing - no Wrapped Data in Auth Req"""
  1847. run_dpp_proto_auth_req_missing(dev, 15, "Missing or invalid required Wrapped Data attribute")
  1848. def run_dpp_proto_auth_resp_missing(dev, test, reason):
  1849. run_dpp_proto_init(dev, 0, test, mutual=True)
  1850. if reason is None:
  1851. time.sleep(0.1)
  1852. return
  1853. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1854. if ev is None:
  1855. raise Exception("DPP failure not seen")
  1856. if reason not in ev:
  1857. raise Exception("Unexpected failure: " + ev)
  1858. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1859. if ev is None or "type=0" not in ev:
  1860. raise Exception("DPP Authentication Request not seen")
  1861. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1862. if ev is not None:
  1863. raise Exception("Unexpected DPP message seen")
  1864. def test_dpp_proto_auth_resp_no_status(dev, apdev):
  1865. """DPP protocol testing - no Status in Auth Resp"""
  1866. run_dpp_proto_auth_resp_missing(dev, 16, "Missing or invalid required DPP Status attribute")
  1867. def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev, apdev):
  1868. """DPP protocol testing - no R-bootstrap key in Auth Resp"""
  1869. run_dpp_proto_auth_resp_missing(dev, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1870. def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev, apdev):
  1871. """DPP protocol testing - no I-bootstrap key in Auth Resp"""
  1872. run_dpp_proto_auth_resp_missing(dev, 18, None)
  1873. def test_dpp_proto_auth_resp_no_r_proto_key(dev, apdev):
  1874. """DPP protocol testing - no R-Proto Key in Auth Resp"""
  1875. run_dpp_proto_auth_resp_missing(dev, 19, "Missing required Responder Protocol Key attribute")
  1876. def test_dpp_proto_auth_resp_no_r_nonce(dev, apdev):
  1877. """DPP protocol testing - no R-nonce in Auth Resp"""
  1878. run_dpp_proto_auth_resp_missing(dev, 20, "Missing or invalid R-nonce")
  1879. def test_dpp_proto_auth_resp_no_i_nonce(dev, apdev):
  1880. """DPP protocol testing - no I-nonce in Auth Resp"""
  1881. run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce")
  1882. def test_dpp_proto_auth_resp_no_r_capab(dev, apdev):
  1883. """DPP protocol testing - no R-capab in Auth Resp"""
  1884. run_dpp_proto_auth_resp_missing(dev, 22, "Missing or invalid R-capabilities")
  1885. def test_dpp_proto_auth_resp_no_r_auth(dev, apdev):
  1886. """DPP protocol testing - no R-auth in Auth Resp"""
  1887. run_dpp_proto_auth_resp_missing(dev, 23, "Missing or invalid Secondary Wrapped Data")
  1888. def test_dpp_proto_auth_resp_no_wrapped_data(dev, apdev):
  1889. """DPP protocol testing - no Wrapped Data in Auth Resp"""
  1890. run_dpp_proto_auth_resp_missing(dev, 24, "Missing or invalid required Wrapped Data attribute")
  1891. def test_dpp_proto_auth_resp_i_nonce_mismatch(dev, apdev):
  1892. """DPP protocol testing - I-nonce mismatch in Auth Resp"""
  1893. run_dpp_proto_init(dev, 0, 30, mutual=True)
  1894. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1895. if ev is None:
  1896. raise Exception("DPP failure not seen")
  1897. if "I-nonce mismatch" not in ev:
  1898. raise Exception("Unexpected failure: " + ev)
  1899. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  1900. if ev is None or "type=0" not in ev:
  1901. raise Exception("DPP Authentication Request not seen")
  1902. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  1903. if ev is not None:
  1904. raise Exception("Unexpected DPP message seen")
  1905. def test_dpp_proto_auth_resp_incompatible_r_capab(dev, apdev):
  1906. """DPP protocol testing - Incompatible R-capab in Auth Resp"""
  1907. run_dpp_proto_init(dev, 0, 31, mutual=True)
  1908. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1909. if ev is None:
  1910. raise Exception("DPP failure not seen")
  1911. if "Unexpected role in R-capabilities 0x02" not in ev:
  1912. raise Exception("Unexpected failure: " + ev)
  1913. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1914. if ev is None:
  1915. raise Exception("DPP failure not seen")
  1916. if "Peer reported incompatible R-capab role" not in ev:
  1917. raise Exception("Unexpected failure: " + ev)
  1918. def test_dpp_proto_auth_resp_r_auth_mismatch(dev, apdev):
  1919. """DPP protocol testing - R-auth mismatch in Auth Resp"""
  1920. run_dpp_proto_init(dev, 0, 32, mutual=True)
  1921. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1922. if ev is None:
  1923. raise Exception("DPP failure not seen")
  1924. if "Mismatching Responder Authenticating Tag" not in ev:
  1925. raise Exception("Unexpected failure: " + ev)
  1926. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1927. if ev is None:
  1928. raise Exception("DPP failure not seen")
  1929. if "Peer reported authentication failure" not in ev:
  1930. raise Exception("Unexpected failure: " + ev)
  1931. def run_dpp_proto_auth_conf_missing(dev, test, reason):
  1932. run_dpp_proto_init(dev, 1, test, mutual=True)
  1933. if reason is None:
  1934. time.sleep(0.1)
  1935. return
  1936. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1937. if ev is None:
  1938. raise Exception("DPP failure not seen")
  1939. if reason not in ev:
  1940. raise Exception("Unexpected failure: " + ev)
  1941. def test_dpp_proto_auth_conf_no_status(dev, apdev):
  1942. """DPP protocol testing - no Status in Auth Conf"""
  1943. run_dpp_proto_auth_conf_missing(dev, 25, "Missing or invalid required DPP Status attribute")
  1944. def test_dpp_proto_auth_conf_no_r_bootstrap_key(dev, apdev):
  1945. """DPP protocol testing - no R-bootstrap key in Auth Conf"""
  1946. run_dpp_proto_auth_conf_missing(dev, 26, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  1947. def test_dpp_proto_auth_conf_no_i_bootstrap_key(dev, apdev):
  1948. """DPP protocol testing - no I-bootstrap key in Auth Conf"""
  1949. run_dpp_proto_auth_conf_missing(dev, 27, "Missing Initiator Bootstrapping Key Hash attribute")
  1950. def test_dpp_proto_auth_conf_no_i_auth(dev, apdev):
  1951. """DPP protocol testing - no I-Auth in Auth Conf"""
  1952. run_dpp_proto_auth_conf_missing(dev, 28, "Missing or invalid Initiator Authenticating Tag")
  1953. def test_dpp_proto_auth_conf_no_wrapped_data(dev, apdev):
  1954. """DPP protocol testing - no Wrapped Data in Auth Conf"""
  1955. run_dpp_proto_auth_conf_missing(dev, 29, "Missing or invalid required Wrapped Data attribute")
  1956. def test_dpp_proto_auth_conf_i_auth_mismatch(dev, apdev):
  1957. """DPP protocol testing - I-auth mismatch in Auth Conf"""
  1958. run_dpp_proto_init(dev, 1, 33, mutual=True)
  1959. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1960. if ev is None:
  1961. raise Exception("DPP failure not seen")
  1962. if "Mismatching Initiator Authenticating Tag" not in ev:
  1963. raise Excception("Unexpected failure: " + ev)
  1964. def run_dpp_proto_init_pkex(dev, test_dev, test):
  1965. check_dpp_capab(dev[0])
  1966. check_dpp_capab(dev[1])
  1967. dev[test_dev].set("dpp_test", str(test))
  1968. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1969. res = dev[0].request(cmd)
  1970. if "FAIL" in res:
  1971. raise Exception("Failed to generate bootstrapping info")
  1972. id0 = int(res)
  1973. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1974. res = dev[1].request(cmd)
  1975. if "FAIL" in res:
  1976. raise Exception("Failed to generate bootstrapping info")
  1977. id1 = int(res)
  1978. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1979. res = dev[0].request(cmd)
  1980. if "FAIL" in res:
  1981. raise Exception("Failed to set PKEX data (responder)")
  1982. cmd = "DPP_LISTEN 2437"
  1983. if "OK" not in dev[0].request(cmd):
  1984. raise Exception("Failed to start listen operation")
  1985. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1986. res = dev[1].request(cmd)
  1987. if "FAIL" in res:
  1988. raise Exception("Failed to set PKEX data (initiator)")
  1989. def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev, apdev):
  1990. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
  1991. run_dpp_proto_init_pkex(dev, 1, 4)
  1992. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1993. if ev is None or "type=7" not in ev:
  1994. raise Exception("PKEX Exchange Request not seen")
  1995. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  1996. if ev is None or "type=9" not in ev:
  1997. raise Exception("PKEX Commit-Reveal Request not seen")
  1998. if "ignore=invalid-attributes" not in ev:
  1999. raise Exception("Unexpected RX info: " + ev)
  2000. def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev, apdev):
  2001. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
  2002. run_dpp_proto_init_pkex(dev, 0, 5)
  2003. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2004. if ev is None or "type=8" not in ev:
  2005. raise Exception("PKEX Exchange Response not seen")
  2006. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2007. if ev is None or "type=10" not in ev:
  2008. raise Exception("PKEX Commit-Reveal Response not seen")
  2009. if "ignore=invalid-attributes" not in ev:
  2010. raise Exception("Unexpected RX info: " + ev)