test_dpp.py 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106
  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, brainpool=False):
  14. if "UNKNOWN COMMAND" in dev.request("DPP_BOOTSTRAP_GET_URI 0"):
  15. raise HwsimSkip("DPP not supported")
  16. if brainpool:
  17. tls = dev.request("GET tls_library")
  18. if not tls.startswith("OpenSSL") or "run=BoringSSL" in tls:
  19. raise HwsimSkip("Crypto library does not support Brainpool curves: " + tls)
  20. def test_dpp_qr_code_parsing(dev, apdev):
  21. """DPP QR Code parsing"""
  22. check_dpp_capab(dev[0])
  23. id = []
  24. tests = [ "DPP:C:81/1,115/36;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
  25. "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
  26. "DPP:I:;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" ]
  27. for uri in tests:
  28. res = dev[0].request("DPP_QR_CODE " + uri)
  29. if "FAIL" in res:
  30. raise Exception("Failed to parse QR Code")
  31. id.append(int(res))
  32. uri2 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id[-1])
  33. if uri != uri2:
  34. raise Exception("Returned URI does not match")
  35. tests = [ "foo",
  36. "DPP:",
  37. "DPP:;;",
  38. "DPP:C:1/2;M:;K;;",
  39. "DPP:I:;M:01020304050;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" ]
  40. for t in tests:
  41. res = dev[0].request("DPP_QR_CODE " + t)
  42. if "FAIL" not in res:
  43. raise Exception("Accepted invalid QR Code: " + t)
  44. logger.info("ID: " + str(id))
  45. if id[0] == id[1] or id[0] == id[2] or id[1] == id[2]:
  46. raise Exception("Duplicate ID returned")
  47. if "FAIL" not in dev[0].request("DPP_BOOTSTRAP_REMOVE 12345678"):
  48. raise Exception("DPP_BOOTSTRAP_REMOVE accepted unexpectedly")
  49. if "OK" not in dev[0].request("DPP_BOOTSTRAP_REMOVE %d" % id[1]):
  50. raise Exception("DPP_BOOTSTRAP_REMOVE failed")
  51. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode")
  52. if "FAIL" in res:
  53. raise Exception("Failed to generate bootstrapping info")
  54. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % int(res))
  55. logger.info("Generated URI: " + uri)
  56. res = dev[0].request("DPP_QR_CODE " + uri)
  57. if "FAIL" in res:
  58. raise Exception("Failed to parse self-generated QR Code URI")
  59. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1,115/36 mac=010203040506 info=foo")
  60. if "FAIL" in res:
  61. raise Exception("Failed to generate bootstrapping info")
  62. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % int(res))
  63. logger.info("Generated URI: " + uri)
  64. res = dev[0].request("DPP_QR_CODE " + uri)
  65. if "FAIL" in res:
  66. raise Exception("Failed to parse self-generated QR Code URI")
  67. def test_dpp_qr_code_auth_broadcast(dev, apdev):
  68. """DPP QR Code and authentication exchange (broadcast)"""
  69. check_dpp_capab(dev[0])
  70. check_dpp_capab(dev[1])
  71. logger.info("dev0 displays QR Code")
  72. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1")
  73. if "FAIL" in res:
  74. raise Exception("Failed to generate bootstrapping info")
  75. id0 = int(res)
  76. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  77. logger.info("dev1 scans QR Code")
  78. res = dev[1].request("DPP_QR_CODE " + uri0)
  79. if "FAIL" in res:
  80. raise Exception("Failed to parse QR Code URI")
  81. id1 = int(res)
  82. logger.info("dev1 initiates DPP Authentication")
  83. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  84. raise Exception("Failed to start listen operation")
  85. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  86. raise Exception("Failed to initiate DPP Authentication")
  87. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  88. if ev is None:
  89. raise Exception("DPP authentication did not succeed (Responder)")
  90. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  91. if ev is None:
  92. raise Exception("DPP authentication did not succeed (Initiator)")
  93. dev[0].request("DPP_STOP_LISTEN")
  94. def test_dpp_qr_code_auth_unicast(dev, apdev):
  95. """DPP QR Code and authentication exchange (unicast)"""
  96. run_dpp_qr_code_auth_unicast(dev, apdev, None)
  97. def test_dpp_qr_code_auth_unicast_ap_enrollee(dev, apdev):
  98. """DPP QR Code and authentication exchange (AP enrollee)"""
  99. run_dpp_qr_code_auth_unicast(dev, apdev, None, netrole="ap")
  100. def test_dpp_qr_code_curve_prime256v1(dev, apdev):
  101. """DPP QR Code and curve prime256v1"""
  102. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1")
  103. def test_dpp_qr_code_curve_secp384r1(dev, apdev):
  104. """DPP QR Code and curve secp384r1"""
  105. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1")
  106. def test_dpp_qr_code_curve_secp521r1(dev, apdev):
  107. """DPP QR Code and curve secp521r1"""
  108. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1")
  109. def test_dpp_qr_code_curve_brainpoolP256r1(dev, apdev):
  110. """DPP QR Code and curve brainpoolP256r1"""
  111. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP256r1")
  112. def test_dpp_qr_code_curve_brainpoolP384r1(dev, apdev):
  113. """DPP QR Code and curve brainpoolP384r1"""
  114. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP384r1")
  115. def test_dpp_qr_code_curve_brainpoolP512r1(dev, apdev):
  116. """DPP QR Code and curve brainpoolP512r1"""
  117. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP512r1")
  118. def test_dpp_qr_code_set_key(dev, apdev):
  119. """DPP QR Code and fixed bootstrapping key"""
  120. run_dpp_qr_code_auth_unicast(dev, apdev, None, key="30770201010420e5143ac74682cc6869a830e8f5301a5fa569130ac329b1d7dd6f2a7495dbcbe1a00a06082a8648ce3d030107a144034200045e13e167c33dbc7d85541e5509600aa8139bbb3e39e25898992c5d01be92039ee2850f17e71506ded0d6b25677441eae249f8e225c68dd15a6354dca54006383")
  121. def run_dpp_qr_code_auth_unicast(dev, apdev, curve, netrole=None, key=None,
  122. require_conf_success=False, init_extra=None,
  123. require_conf_failure=False,
  124. configurator=False, conf_curve=None):
  125. check_dpp_capab(dev[0], curve and "brainpool" in curve)
  126. check_dpp_capab(dev[1], curve and "brainpool" in curve)
  127. if configurator:
  128. logger.info("Create configurator on dev1")
  129. cmd = "DPP_CONFIGURATOR_ADD"
  130. if conf_curve:
  131. cmd += " curve=" + conf_curve
  132. res = dev[1].request(cmd);
  133. if "FAIL" in res:
  134. raise Exception("Failed to add configurator")
  135. conf_id = int(res)
  136. logger.info("dev0 displays QR Code")
  137. addr = dev[0].own_addr().replace(':', '')
  138. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  139. if curve:
  140. cmd += " curve=" + curve
  141. if key:
  142. cmd += " key=" + key
  143. res = dev[0].request(cmd)
  144. if "FAIL" in res:
  145. raise Exception("Failed to generate bootstrapping info")
  146. id0 = int(res)
  147. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  148. logger.info("dev1 scans QR Code")
  149. res = dev[1].request("DPP_QR_CODE " + uri0)
  150. if "FAIL" in res:
  151. raise Exception("Failed to parse QR Code URI")
  152. id1 = int(res)
  153. logger.info("dev1 initiates DPP Authentication")
  154. cmd = "DPP_LISTEN 2412"
  155. if netrole:
  156. cmd += " netrole=" + netrole
  157. if "OK" not in dev[0].request(cmd):
  158. raise Exception("Failed to start listen operation")
  159. cmd = "DPP_AUTH_INIT peer=%d" % id1
  160. if init_extra:
  161. cmd += " " + init_extra
  162. if configurator:
  163. cmd += " configurator=%d" % conf_id
  164. if "OK" not in dev[1].request(cmd):
  165. raise Exception("Failed to initiate DPP Authentication")
  166. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  167. if ev is None:
  168. raise Exception("DPP authentication did not succeed (Responder)")
  169. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  170. if ev is None:
  171. raise Exception("DPP authentication did not succeed (Initiator)")
  172. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  173. if ev is None:
  174. raise Exception("DPP configuration not completed (Configurator)")
  175. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  176. if ev is None:
  177. raise Exception("DPP configuration not completed (Enrollee)")
  178. if require_conf_success:
  179. if "DPP-CONF-FAILED" in ev:
  180. raise Exception("DPP configuration failed")
  181. if require_conf_failure:
  182. if "DPP-CONF-SUCCESS" in ev:
  183. raise Exception("DPP configuration succeeded unexpectedly")
  184. dev[0].request("DPP_STOP_LISTEN")
  185. dev[0].dump_monitor()
  186. dev[1].dump_monitor()
  187. def test_dpp_qr_code_auth_mutual(dev, apdev):
  188. """DPP QR Code and authentication exchange (mutual)"""
  189. check_dpp_capab(dev[0])
  190. check_dpp_capab(dev[1])
  191. logger.info("dev0 displays QR Code")
  192. addr = dev[0].own_addr().replace(':', '')
  193. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  194. if "FAIL" in res:
  195. raise Exception("Failed to generate bootstrapping info")
  196. id0 = int(res)
  197. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  198. logger.info("dev1 scans QR Code")
  199. res = dev[1].request("DPP_QR_CODE " + uri0)
  200. if "FAIL" in res:
  201. raise Exception("Failed to parse QR Code URI")
  202. id1 = int(res)
  203. logger.info("dev1 displays QR Code")
  204. addr = dev[1].own_addr().replace(':', '')
  205. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  206. if "FAIL" in res:
  207. raise Exception("Failed to generate bootstrapping info")
  208. id1b = int(res)
  209. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  210. logger.info("dev0 scans QR Code")
  211. res = dev[0].request("DPP_QR_CODE " + uri1b)
  212. if "FAIL" in res:
  213. raise Exception("Failed to parse QR Code URI")
  214. id0b = int(res)
  215. logger.info("dev1 initiates DPP Authentication")
  216. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  217. raise Exception("Failed to start listen operation")
  218. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  219. raise Exception("Failed to initiate DPP Authentication")
  220. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  221. if ev is None:
  222. raise Exception("DPP authentication did not succeed (Responder)")
  223. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  224. if ev is None:
  225. raise Exception("DPP authentication did not succeed (Initiator)")
  226. dev[0].request("DPP_STOP_LISTEN")
  227. def test_dpp_qr_code_auth_mutual2(dev, apdev):
  228. """DPP QR Code and authentication exchange (mutual2)"""
  229. check_dpp_capab(dev[0])
  230. check_dpp_capab(dev[1])
  231. logger.info("dev0 displays QR Code")
  232. addr = dev[0].own_addr().replace(':', '')
  233. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  234. if "FAIL" in res:
  235. raise Exception("Failed to generate bootstrapping info")
  236. id0 = int(res)
  237. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  238. logger.info("dev1 scans QR Code")
  239. res = dev[1].request("DPP_QR_CODE " + uri0)
  240. if "FAIL" in res:
  241. raise Exception("Failed to parse QR Code URI")
  242. id1 = int(res)
  243. logger.info("dev1 displays QR Code")
  244. addr = dev[1].own_addr().replace(':', '')
  245. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  246. if "FAIL" in res:
  247. raise Exception("Failed to generate bootstrapping info")
  248. id1b = int(res)
  249. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  250. logger.info("dev1 initiates DPP Authentication")
  251. if "OK" not in dev[0].request("DPP_LISTEN 2412 qr=mutual"):
  252. raise Exception("Failed to start listen operation")
  253. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  254. raise Exception("Failed to initiate DPP Authentication")
  255. ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  256. if ev is None:
  257. raise Exception("Pending response not reported")
  258. ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  259. if ev is None:
  260. raise Exception("QR Code scan for mutual authentication not requested")
  261. logger.info("dev0 scans QR Code")
  262. res = dev[0].request("DPP_QR_CODE " + uri1b)
  263. if "FAIL" in res:
  264. raise Exception("Failed to parse QR Code URI")
  265. id0b = int(res)
  266. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  267. if ev is None:
  268. raise Exception("DPP authentication did not succeed (Responder)")
  269. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  270. if ev is None:
  271. raise Exception("DPP authentication did not succeed (Initiator)")
  272. dev[0].request("DPP_STOP_LISTEN")
  273. def test_dpp_auth_resp_retries(dev, apdev):
  274. """DPP Authentication Response retries"""
  275. check_dpp_capab(dev[0])
  276. check_dpp_capab(dev[1])
  277. dev[0].set("dpp_resp_max_tries", "3")
  278. dev[0].set("dpp_resp_retry_time", "100")
  279. logger.info("dev0 displays QR Code")
  280. addr = dev[0].own_addr().replace(':', '')
  281. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  282. if "FAIL" in res:
  283. raise Exception("Failed to generate bootstrapping info")
  284. id0 = int(res)
  285. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  286. logger.info("dev1 scans QR Code")
  287. res = dev[1].request("DPP_QR_CODE " + uri0)
  288. if "FAIL" in res:
  289. raise Exception("Failed to parse QR Code URI")
  290. id1 = int(res)
  291. logger.info("dev1 displays QR Code")
  292. addr = dev[1].own_addr().replace(':', '')
  293. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  294. if "FAIL" in res:
  295. raise Exception("Failed to generate bootstrapping info")
  296. id1b = int(res)
  297. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  298. logger.info("dev1 initiates DPP Authentication")
  299. if "OK" not in dev[0].request("DPP_LISTEN 2412 qr=mutual"):
  300. raise Exception("Failed to start listen operation")
  301. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  302. raise Exception("Failed to initiate DPP Authentication")
  303. ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  304. if ev is None:
  305. raise Exception("Pending response not reported")
  306. ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  307. if ev is None:
  308. raise Exception("QR Code scan for mutual authentication not requested")
  309. # Stop Initiator from listening to frames to force retransmission of the
  310. # DPP Authentication Response frame with Status=0
  311. dev[1].request("DPP_STOP_LISTEN")
  312. dev[1].dump_monitor()
  313. dev[0].dump_monitor()
  314. logger.info("dev0 scans QR Code")
  315. res = dev[0].request("DPP_QR_CODE " + uri1b)
  316. if "FAIL" in res:
  317. raise Exception("Failed to parse QR Code URI")
  318. id0b = int(res)
  319. ev = dev[0].wait_event(["DPP-TX"], timeout=5)
  320. if ev is None or "type=1" not in ev:
  321. raise Exception("DPP Authentication Response not sent")
  322. ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=5)
  323. if ev is None:
  324. raise Exception("TX status for DPP Authentication Response not reported")
  325. if "result=no-ACK" not in ev:
  326. raise Exception("Unexpected TX status for Authentication Response: " + ev)
  327. ev = dev[0].wait_event(["DPP-TX"], timeout=15)
  328. if ev is None or "type=1" not in ev:
  329. raise Exception("DPP Authentication Response retransmission not sent")
  330. def test_dpp_qr_code_auth_mutual_not_used(dev, apdev):
  331. """DPP QR Code and authentication exchange (mutual not used)"""
  332. check_dpp_capab(dev[0])
  333. check_dpp_capab(dev[1])
  334. logger.info("dev0 displays QR Code")
  335. addr = dev[0].own_addr().replace(':', '')
  336. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  337. if "FAIL" in res:
  338. raise Exception("Failed to generate bootstrapping info")
  339. id0 = int(res)
  340. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  341. logger.info("dev1 scans QR Code")
  342. res = dev[1].request("DPP_QR_CODE " + uri0)
  343. if "FAIL" in res:
  344. raise Exception("Failed to parse QR Code URI")
  345. id1 = int(res)
  346. logger.info("dev1 displays QR Code")
  347. addr = dev[1].own_addr().replace(':', '')
  348. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  349. if "FAIL" in res:
  350. raise Exception("Failed to generate bootstrapping info")
  351. id1b = int(res)
  352. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  353. logger.info("dev0 does not scan QR Code")
  354. logger.info("dev1 initiates DPP Authentication")
  355. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  356. raise Exception("Failed to start listen operation")
  357. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  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_mutual_curve_mismatch(dev, apdev):
  367. """DPP QR Code and authentication exchange (mutual/mismatch)"""
  368. check_dpp_capab(dev[0])
  369. check_dpp_capab(dev[1])
  370. logger.info("dev0 displays QR Code")
  371. addr = dev[0].own_addr().replace(':', '')
  372. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  373. if "FAIL" in res:
  374. raise Exception("Failed to generate bootstrapping info")
  375. id0 = int(res)
  376. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  377. logger.info("dev1 scans QR Code")
  378. res = dev[1].request("DPP_QR_CODE " + uri0)
  379. if "FAIL" in res:
  380. raise Exception("Failed to parse QR Code URI")
  381. id1 = int(res)
  382. logger.info("dev1 displays QR Code")
  383. addr = dev[1].own_addr().replace(':', '')
  384. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr + " curve=secp384r1")
  385. if "FAIL" in res:
  386. raise Exception("Failed to generate bootstrapping info")
  387. id1b = int(res)
  388. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  389. logger.info("dev0 scans QR Code")
  390. res = dev[0].request("DPP_QR_CODE " + uri1b)
  391. if "FAIL" in res:
  392. raise Exception("Failed to parse QR Code URI")
  393. id0b = int(res)
  394. res = dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b))
  395. if "FAIL" not in res:
  396. raise Exception("DPP_AUTH_INIT accepted unexpectedly")
  397. def test_dpp_qr_code_auth_hostapd_mutual2(dev, apdev):
  398. """DPP QR Code and authentication exchange (hostapd mutual2)"""
  399. check_dpp_capab(dev[0])
  400. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  401. check_dpp_capab(hapd)
  402. logger.info("AP displays QR Code")
  403. addr = hapd.own_addr().replace(':', '')
  404. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  405. res = hapd.request(cmd)
  406. if "FAIL" in res:
  407. raise Exception("Failed to generate bootstrapping info")
  408. id_h = int(res)
  409. uri_h = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  410. logger.info("dev0 scans QR Code")
  411. res = dev[0].request("DPP_QR_CODE " + uri_h)
  412. if "FAIL" in res:
  413. raise Exception("Failed to parse QR Code URI")
  414. id0 = int(res)
  415. logger.info("dev0 displays QR Code")
  416. addr = dev[0].own_addr().replace(':', '')
  417. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  418. if "FAIL" in res:
  419. raise Exception("Failed to generate bootstrapping info")
  420. id0b = int(res)
  421. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0b)
  422. logger.info("dev0 initiates DPP Authentication")
  423. if "OK" not in hapd.request("DPP_LISTEN 2412 qr=mutual"):
  424. raise Exception("Failed to start listen operation")
  425. if "OK" not in dev[0].request("DPP_AUTH_INIT peer=%d own=%d" % (id0, id0b)):
  426. raise Exception("Failed to initiate DPP Authentication")
  427. ev = dev[0].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  428. if ev is None:
  429. raise Exception("Pending response not reported")
  430. ev = hapd.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  431. if ev is None:
  432. raise Exception("QR Code scan for mutual authentication not requested")
  433. logger.info("AP scans QR Code")
  434. res = hapd.request("DPP_QR_CODE " + uri0)
  435. if "FAIL" in res:
  436. raise Exception("Failed to parse QR Code URI")
  437. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  438. if ev is None:
  439. raise Exception("DPP authentication did not succeed (Responder)")
  440. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  441. if ev is None:
  442. raise Exception("DPP authentication did not succeed (Initiator)")
  443. hapd.request("DPP_STOP_LISTEN")
  444. def test_dpp_qr_code_listen_continue(dev, apdev):
  445. """DPP QR Code and listen operation needing continuation"""
  446. check_dpp_capab(dev[0])
  447. check_dpp_capab(dev[1])
  448. logger.info("dev0 displays QR Code")
  449. addr = dev[0].own_addr().replace(':', '')
  450. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  451. if "FAIL" in res:
  452. raise Exception("Failed to generate bootstrapping info")
  453. id0 = int(res)
  454. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  455. logger.info("dev1 scans QR Code")
  456. res = dev[1].request("DPP_QR_CODE " + uri0)
  457. if "FAIL" in res:
  458. raise Exception("Failed to parse QR Code URI")
  459. id1 = int(res)
  460. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  461. raise Exception("Failed to start listen operation")
  462. logger.info("Wait for listen to expire and get restarted")
  463. time.sleep(5.5)
  464. logger.info("dev1 initiates DPP Authentication")
  465. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  466. raise Exception("Failed to initiate DPP Authentication")
  467. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  468. if ev is None:
  469. raise Exception("DPP authentication did not succeed (Responder)")
  470. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  471. if ev is None:
  472. raise Exception("DPP authentication did not succeed (Initiator)")
  473. dev[0].request("DPP_STOP_LISTEN")
  474. def test_dpp_qr_code_auth_initiator_enrollee(dev, apdev):
  475. """DPP QR Code and authentication exchange (Initiator in Enrollee role)"""
  476. check_dpp_capab(dev[0])
  477. check_dpp_capab(dev[1])
  478. dev[0].request("SET gas_address3 1")
  479. dev[1].request("SET gas_address3 1")
  480. logger.info("dev0 displays QR Code")
  481. addr = dev[0].own_addr().replace(':', '')
  482. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  483. if "FAIL" in res:
  484. raise Exception("Failed to generate bootstrapping info")
  485. id0 = int(res)
  486. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  487. logger.info("dev1 scans QR Code")
  488. res = dev[1].request("DPP_QR_CODE " + uri0)
  489. if "FAIL" in res:
  490. raise Exception("Failed to parse QR Code URI")
  491. id1 = int(res)
  492. logger.info("dev1 initiates DPP Authentication")
  493. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  494. raise Exception("Failed to start listen operation")
  495. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  496. raise Exception("Failed to initiate DPP Authentication")
  497. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  498. if ev is None:
  499. raise Exception("DPP authentication did not succeed (Responder)")
  500. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  501. if ev is None:
  502. raise Exception("DPP authentication did not succeed (Initiator)")
  503. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  504. if ev is None:
  505. raise Exception("DPP configuration did not succeed (Configurator)")
  506. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=5)
  507. if ev is None:
  508. raise Exception("DPP configuration did not succeed (Enrollee)")
  509. dev[0].request("DPP_STOP_LISTEN")
  510. def test_dpp_qr_code_auth_initiator_either_1(dev, apdev):
  511. """DPP QR Code and authentication exchange (Initiator in either role)"""
  512. run_dpp_qr_code_auth_initiator_either(dev, apdev, None, dev[1], dev[0])
  513. def test_dpp_qr_code_auth_initiator_either_2(dev, apdev):
  514. """DPP QR Code and authentication exchange (Initiator in either role)"""
  515. run_dpp_qr_code_auth_initiator_either(dev, apdev, "enrollee",
  516. dev[1], dev[0])
  517. def test_dpp_qr_code_auth_initiator_either_3(dev, apdev):
  518. """DPP QR Code and authentication exchange (Initiator in either role)"""
  519. run_dpp_qr_code_auth_initiator_either(dev, apdev, "configurator",
  520. dev[0], dev[1])
  521. def run_dpp_qr_code_auth_initiator_either(dev, apdev, resp_role,
  522. conf_dev, enrollee_dev):
  523. check_dpp_capab(dev[0])
  524. check_dpp_capab(dev[1])
  525. logger.info("dev0 displays QR Code")
  526. addr = dev[0].own_addr().replace(':', '')
  527. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  528. if "FAIL" in res:
  529. raise Exception("Failed to generate bootstrapping info")
  530. id0 = int(res)
  531. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  532. logger.info("dev1 scans QR Code")
  533. res = dev[1].request("DPP_QR_CODE " + uri0)
  534. if "FAIL" in res:
  535. raise Exception("Failed to parse QR Code URI")
  536. id1 = int(res)
  537. logger.info("dev1 initiates DPP Authentication")
  538. cmd = "DPP_LISTEN 2412"
  539. if resp_role:
  540. cmd += " role=" + resp_role
  541. if "OK" not in dev[0].request(cmd):
  542. raise Exception("Failed to start listen operation")
  543. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=either" % id1):
  544. raise Exception("Failed to initiate DPP Authentication")
  545. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  546. if ev is None:
  547. raise Exception("DPP authentication did not succeed (Responder)")
  548. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  549. if ev is None:
  550. raise Exception("DPP authentication did not succeed (Initiator)")
  551. ev = conf_dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  552. if ev is None:
  553. raise Exception("DPP configuration did not succeed (Configurator)")
  554. ev = enrollee_dev.wait_event(["DPP-CONF-FAILED"], timeout=5)
  555. if ev is None:
  556. raise Exception("DPP configuration did not succeed (Enrollee)")
  557. dev[0].request("DPP_STOP_LISTEN")
  558. def test_dpp_qr_code_auth_incompatible_roles(dev, apdev):
  559. """DPP QR Code and authentication exchange (incompatible roles)"""
  560. check_dpp_capab(dev[0])
  561. check_dpp_capab(dev[1])
  562. logger.info("dev0 displays QR Code")
  563. addr = dev[0].own_addr().replace(':', '')
  564. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  565. if "FAIL" in res:
  566. raise Exception("Failed to generate bootstrapping info")
  567. id0 = int(res)
  568. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  569. logger.info("dev1 scans QR Code")
  570. res = dev[1].request("DPP_QR_CODE " + uri0)
  571. if "FAIL" in res:
  572. raise Exception("Failed to parse QR Code URI")
  573. id1 = int(res)
  574. logger.info("dev1 initiates DPP Authentication")
  575. if "OK" not in dev[0].request("DPP_LISTEN 2412 role=enrollee"):
  576. raise Exception("Failed to start listen operation")
  577. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  578. raise Exception("Failed to initiate DPP Authentication")
  579. ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
  580. if ev is None:
  581. raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
  582. ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
  583. if ev is None:
  584. raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
  585. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=configurator" % id1):
  586. raise Exception("Failed to initiate DPP Authentication")
  587. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  588. if ev is None:
  589. raise Exception("DPP authentication did not succeed (Responder)")
  590. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  591. if ev is None:
  592. raise Exception("DPP authentication did not succeed (Initiator)")
  593. dev[0].request("DPP_STOP_LISTEN")
  594. def test_dpp_qr_code_auth_neg_chan(dev, apdev):
  595. """DPP QR Code and authentication exchange with requested different channel"""
  596. check_dpp_capab(dev[0])
  597. check_dpp_capab(dev[1])
  598. logger.info("Create configurator on dev1")
  599. cmd = "DPP_CONFIGURATOR_ADD"
  600. res = dev[1].request(cmd);
  601. if "FAIL" in res:
  602. raise Exception("Failed to add configurator")
  603. conf_id = int(res)
  604. logger.info("dev0 displays QR Code")
  605. addr = dev[0].own_addr().replace(':', '')
  606. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  607. res = dev[0].request(cmd)
  608. if "FAIL" in res:
  609. raise Exception("Failed to generate bootstrapping info")
  610. id0 = int(res)
  611. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  612. logger.info("dev1 scans QR Code")
  613. res = dev[1].request("DPP_QR_CODE " + uri0)
  614. if "FAIL" in res:
  615. raise Exception("Failed to parse QR Code URI")
  616. id1 = int(res)
  617. logger.info("dev1 initiates DPP Authentication")
  618. cmd = "DPP_LISTEN 2412"
  619. if "OK" not in dev[0].request(cmd):
  620. raise Exception("Failed to start listen operation")
  621. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp neg_freq=2462" % (id1, conf_id)
  622. if "OK" not in dev[1].request(cmd):
  623. raise Exception("Failed to initiate DPP Authentication")
  624. ev = dev[1].wait_event(["DPP-TX"], timeout=5)
  625. if ev is None:
  626. raise Exception("DPP Authentication Request not sent")
  627. if "freq=2412 type=0" not in ev:
  628. raise Exception("Unexpected TX data for Authentication Request: " + ev)
  629. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  630. if ev is None:
  631. raise Exception("DPP Authentication Request not received")
  632. if "freq=2412 type=0" not in ev:
  633. raise Exception("Unexpected RX data for Authentication Request: " + ev)
  634. ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5)
  635. if ev is None:
  636. raise Exception("TX status for DPP Authentication Request not reported")
  637. if "freq=2412 result=SUCCESS" not in ev:
  638. raise Exception("Unexpected TX status for Authentication Request: " + ev)
  639. ev = dev[0].wait_event(["DPP-TX"], timeout=5)
  640. if ev is None:
  641. raise Exception("DPP Authentication Response not sent")
  642. if "freq=2462 type=1" not in ev:
  643. raise Exception("Unexpected TX data for Authentication Response: " + ev)
  644. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  645. if ev is None:
  646. raise Exception("DPP Authentication Response not received")
  647. if "freq=2462 type=1" not in ev:
  648. raise Exception("Unexpected RX data for Authentication Response: " + ev)
  649. ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=5)
  650. if ev is None:
  651. raise Exception("TX status for DPP Authentication Response not reported")
  652. if "freq=2462 result=SUCCESS" not in ev:
  653. raise Exception("Unexpected TX status for Authentication Response: " + ev)
  654. ev = dev[1].wait_event(["DPP-TX"], timeout=5)
  655. if ev is None:
  656. raise Exception("DPP Authentication Confirm not sent")
  657. if "freq=2462 type=2" not in ev:
  658. raise Exception("Unexpected TX data for Authentication Confirm: " + ev)
  659. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  660. if ev is None:
  661. raise Exception("DPP Authentication Confirm not received")
  662. if "freq=2462 type=2" not in ev:
  663. raise Exception("Unexpected RX data for Authentication Confirm: " + ev)
  664. ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5)
  665. if ev is None:
  666. raise Exception("TX status for DPP Authentication Confirm not reported")
  667. if "freq=2462 result=SUCCESS" not in ev:
  668. raise Exception("Unexpected TX status for Authentication Confirm: " + ev)
  669. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  670. if ev is None:
  671. raise Exception("DPP authentication did not succeed (Responder)")
  672. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  673. if ev is None:
  674. raise Exception("DPP authentication did not succeed (Initiator)")
  675. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  676. if ev is None:
  677. raise Exception("DPP configuration not completed (Configurator)")
  678. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  679. if ev is None:
  680. raise Exception("DPP configuration not completed (Enrollee)")
  681. if "DPP-CONF-FAILED" in ev:
  682. raise Exception("DPP configuration failed")
  683. dev[0].request("DPP_STOP_LISTEN")
  684. dev[0].dump_monitor()
  685. dev[1].dump_monitor()
  686. def test_dpp_config_legacy(dev, apdev):
  687. """DPP Config Object for legacy network using passphrase"""
  688. check_dpp_capab(dev[1])
  689. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
  690. dev[1].set("dpp_config_obj_override", conf)
  691. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  692. require_conf_success=True)
  693. def test_dpp_config_legacy_psk_hex(dev, apdev):
  694. """DPP Config Object for legacy network using PSK"""
  695. check_dpp_capab(dev[1])
  696. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
  697. dev[1].set("dpp_config_obj_override", conf)
  698. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  699. require_conf_success=True)
  700. def test_dpp_config_fragmentation(dev, apdev):
  701. """DPP Config Object for legacy network requiring fragmentation"""
  702. check_dpp_capab(dev[1])
  703. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  704. dev[1].set("dpp_config_obj_override", conf)
  705. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  706. require_conf_success=True)
  707. def test_dpp_config_legacy_gen(dev, apdev):
  708. """Generate DPP Config Object for legacy network"""
  709. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  710. init_extra="conf=sta-psk pass=%s" % "passphrase".encode("hex"),
  711. require_conf_success=True)
  712. def test_dpp_config_dpp_gen_prime256v1(dev, apdev):
  713. """Generate DPP Config Object for DPP network (P-256)"""
  714. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  715. init_extra="conf=sta-dpp",
  716. require_conf_success=True,
  717. configurator=True)
  718. def test_dpp_config_dpp_gen_secp384r1(dev, apdev):
  719. """Generate DPP Config Object for DPP network (P-384)"""
  720. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  721. init_extra="conf=sta-dpp",
  722. require_conf_success=True,
  723. configurator=True)
  724. def test_dpp_config_dpp_gen_secp521r1(dev, apdev):
  725. """Generate DPP Config Object for DPP network (P-521)"""
  726. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  727. init_extra="conf=sta-dpp",
  728. require_conf_success=True,
  729. configurator=True)
  730. def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev, apdev):
  731. """Generate DPP Config Object for DPP network (P-256 + P-256)"""
  732. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  733. init_extra="conf=sta-dpp",
  734. require_conf_success=True,
  735. configurator=True,
  736. conf_curve="prime256v1")
  737. def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev, apdev):
  738. """Generate DPP Config Object for DPP network (P-256 + P-384)"""
  739. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  740. init_extra="conf=sta-dpp",
  741. require_conf_success=True,
  742. configurator=True,
  743. conf_curve="secp384r1")
  744. def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev, apdev):
  745. """Generate DPP Config Object for DPP network (P-256 + P-521)"""
  746. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  747. init_extra="conf=sta-dpp",
  748. require_conf_success=True,
  749. configurator=True,
  750. conf_curve="secp521r1")
  751. def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev, apdev):
  752. """Generate DPP Config Object for DPP network (P-384 + P-256)"""
  753. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  754. init_extra="conf=sta-dpp",
  755. require_conf_success=True,
  756. configurator=True,
  757. conf_curve="prime256v1")
  758. def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev, apdev):
  759. """Generate DPP Config Object for DPP network (P-384 + P-384)"""
  760. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  761. init_extra="conf=sta-dpp",
  762. require_conf_success=True,
  763. configurator=True,
  764. conf_curve="secp384r1")
  765. def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev, apdev):
  766. """Generate DPP Config Object for DPP network (P-384 + P-521)"""
  767. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  768. init_extra="conf=sta-dpp",
  769. require_conf_success=True,
  770. configurator=True,
  771. conf_curve="secp521r1")
  772. def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev, apdev):
  773. """Generate DPP Config Object for DPP network (P-521 + P-256)"""
  774. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  775. init_extra="conf=sta-dpp",
  776. require_conf_success=True,
  777. configurator=True,
  778. conf_curve="prime256v1")
  779. def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev, apdev):
  780. """Generate DPP Config Object for DPP network (P-521 + P-384)"""
  781. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  782. init_extra="conf=sta-dpp",
  783. require_conf_success=True,
  784. configurator=True,
  785. conf_curve="secp384r1")
  786. def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev, apdev):
  787. """Generate DPP Config Object for DPP network (P-521 + P-521)"""
  788. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  789. init_extra="conf=sta-dpp",
  790. require_conf_success=True,
  791. configurator=True,
  792. conf_curve="secp521r1")
  793. def test_dpp_config_dpp_gen_expiry(dev, apdev):
  794. """Generate DPP Config Object for DPP network with expiry value"""
  795. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  796. init_extra="conf=sta-dpp expiry=%d" % (time.time() + 1000),
  797. require_conf_success=True,
  798. configurator=True)
  799. def test_dpp_config_dpp_gen_expired_key(dev, apdev):
  800. """Generate DPP Config Object for DPP network with expiry value"""
  801. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  802. init_extra="conf=sta-dpp expiry=%d" % (time.time() - 10),
  803. require_conf_failure=True,
  804. configurator=True)
  805. def test_dpp_config_dpp_override_prime256v1(dev, apdev):
  806. """DPP Config Object override (P-256)"""
  807. check_dpp_capab(dev[0])
  808. check_dpp_capab(dev[1])
  809. 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"}}}'
  810. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  811. dev[1].set("dpp_config_obj_override", conf)
  812. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  813. require_conf_success=True)
  814. def test_dpp_config_dpp_override_secp384r1(dev, apdev):
  815. """DPP Config Object override (P-384)"""
  816. check_dpp_capab(dev[0])
  817. check_dpp_capab(dev[1])
  818. 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"}}}'
  819. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  820. dev[1].set("dpp_config_obj_override", conf)
  821. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  822. require_conf_success=True)
  823. def test_dpp_config_dpp_override_secp521r1(dev, apdev):
  824. """DPP Config Object override (P-521)"""
  825. check_dpp_capab(dev[0])
  826. check_dpp_capab(dev[1])
  827. 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"}}}'
  828. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  829. dev[1].set("dpp_config_obj_override", conf)
  830. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  831. require_conf_success=True)
  832. def test_dpp_config_override_objects(dev, apdev):
  833. """Generate DPP Config Object and override objects)"""
  834. check_dpp_capab(dev[1])
  835. discovery = '{\n"ssid":"mywifi"\n}'
  836. groups = '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
  837. dev[1].set("dpp_discovery_override", discovery)
  838. dev[1].set("dpp_groups_override", groups)
  839. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  840. init_extra="conf=sta-dpp",
  841. require_conf_success=True,
  842. configurator=True)
  843. def test_dpp_gas_timeout(dev, apdev):
  844. """DPP and GAS server timeout for a query"""
  845. check_dpp_capab(dev[0])
  846. check_dpp_capab(dev[1])
  847. logger.info("dev0 displays QR Code")
  848. addr = dev[0].own_addr().replace(':', '')
  849. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  850. res = dev[0].request(cmd)
  851. if "FAIL" in res:
  852. raise Exception("Failed to generate bootstrapping info")
  853. id0 = int(res)
  854. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  855. logger.info("dev1 scans QR Code")
  856. res = dev[1].request("DPP_QR_CODE " + uri0)
  857. if "FAIL" in res:
  858. raise Exception("Failed to parse QR Code URI")
  859. id1 = int(res)
  860. logger.info("dev1 initiates DPP Authentication")
  861. dev[0].set("ext_mgmt_frame_handling", "1")
  862. cmd = "DPP_LISTEN 2412"
  863. if "OK" not in dev[0].request(cmd):
  864. raise Exception("Failed to start listen operation")
  865. # Force GAS fragmentation
  866. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  867. dev[1].set("dpp_config_obj_override", conf)
  868. cmd = "DPP_AUTH_INIT peer=%d" % id1
  869. if "OK" not in dev[1].request(cmd):
  870. raise Exception("Failed to initiate DPP Authentication")
  871. # DPP Authentication Request
  872. msg = dev[0].mgmt_rx()
  873. 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'))):
  874. raise Exception("MGMT_RX_PROCESS failed")
  875. # DPP Authentication Confirmation
  876. msg = dev[0].mgmt_rx()
  877. 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'))):
  878. raise Exception("MGMT_RX_PROCESS failed")
  879. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  880. if ev is None:
  881. raise Exception("DPP authentication did not succeed (Responder)")
  882. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  883. if ev is None:
  884. raise Exception("DPP authentication did not succeed (Initiator)")
  885. # DPP Configuration Response (GAS Initial Response frame)
  886. msg = dev[0].mgmt_rx()
  887. 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'))):
  888. raise Exception("MGMT_RX_PROCESS failed")
  889. # GAS Comeback Response frame
  890. msg = dev[0].mgmt_rx()
  891. # Do not continue to force timeout on GAS server
  892. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  893. if ev is None:
  894. raise Exception("GAS result not reported (Enrollee)")
  895. if "result=TIMEOUT" not in ev:
  896. raise Exception("Unexpected GAS result (Enrollee): " + ev)
  897. dev[0].set("ext_mgmt_frame_handling", "0")
  898. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
  899. if ev is None:
  900. raise Exception("DPP configuration failure not reported (Configurator)")
  901. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
  902. if ev is None:
  903. raise Exception("DPP configuration failure not reported (Enrollee)")
  904. def test_dpp_akm_sha256(dev, apdev):
  905. """DPP AKM (SHA256)"""
  906. run_dpp_akm(dev, apdev, 32)
  907. def test_dpp_akm_sha384(dev, apdev):
  908. """DPP AKM (SHA384)"""
  909. run_dpp_akm(dev, apdev, 48)
  910. def test_dpp_akm_sha512(dev, apdev):
  911. """DPP AKM (SHA512)"""
  912. run_dpp_akm(dev, apdev, 64)
  913. def run_dpp_akm(dev, apdev, pmk_len):
  914. check_dpp_capab(dev[0])
  915. check_dpp_capab(dev[1])
  916. params = { "ssid": "dpp",
  917. "wpa": "2",
  918. "wpa_key_mgmt": "DPP",
  919. "rsn_pairwise": "CCMP",
  920. "ieee80211w": "2" }
  921. try:
  922. hapd = hostapd.add_ap(apdev[0], params)
  923. except:
  924. raise HwsimSkip("DPP not supported")
  925. id = dev[0].connect("dpp", key_mgmt="DPP", ieee80211w="2", scan_freq="2412",
  926. wait_connect=False)
  927. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  928. if not ev:
  929. raise Exception("Network mismatch not reported")
  930. dev[0].request("DISCONNECT")
  931. dev[0].dump_monitor()
  932. bssid = hapd.own_addr()
  933. pmkid = 16*'11'
  934. akmp = 2**23
  935. pmk = pmk_len*'22'
  936. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  937. if "OK" not in dev[0].request(cmd):
  938. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  939. dev[0].select_network(id, freq="2412")
  940. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  941. dev[0].request("DISCONNECT")
  942. dev[0].dump_monitor()
  943. if not ev:
  944. raise Exception("Association attempt was not rejected")
  945. if "status_code=53" not in ev:
  946. raise Exception("Unexpected status code: " + ev)
  947. addr = dev[0].own_addr()
  948. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  949. if "OK" not in hapd.request(cmd):
  950. raise Exception("PMKSA_ADD failed (hostapd)")
  951. dev[0].select_network(id, freq="2412")
  952. dev[0].wait_connected()
  953. val = dev[0].get_status_field("key_mgmt")
  954. if val != "DPP":
  955. raise Exception("Unexpected key_mgmt: " + val)
  956. def test_dpp_network_introduction(dev, apdev):
  957. """DPP network introduction"""
  958. check_dpp_capab(dev[0])
  959. check_dpp_capab(dev[1])
  960. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  961. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  962. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  963. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  964. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  965. params = { "ssid": "dpp",
  966. "wpa": "2",
  967. "wpa_key_mgmt": "DPP",
  968. "ieee80211w": "2",
  969. "rsn_pairwise": "CCMP",
  970. "dpp_connector": ap_connector,
  971. "dpp_csign": csign,
  972. "dpp_netaccesskey": ap_netaccesskey }
  973. try:
  974. hapd = hostapd.add_ap(apdev[0], params)
  975. except:
  976. raise HwsimSkip("DPP not supported")
  977. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  978. ieee80211w="2",
  979. dpp_csign=csign,
  980. dpp_connector=sta_connector,
  981. dpp_netaccesskey=sta_netaccesskey)
  982. val = dev[0].get_status_field("key_mgmt")
  983. if val != "DPP":
  984. raise Exception("Unexpected key_mgmt: " + val)
  985. def test_dpp_ap_config(dev, apdev):
  986. """DPP and AP configuration"""
  987. run_dpp_ap_config(dev, apdev)
  988. def test_dpp_ap_config_p256_p256(dev, apdev):
  989. """DPP and AP configuration (P-256 + P-256)"""
  990. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  991. def test_dpp_ap_config_p256_p384(dev, apdev):
  992. """DPP and AP configuration (P-256 + P-384)"""
  993. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  994. def test_dpp_ap_config_p256_p521(dev, apdev):
  995. """DPP and AP configuration (P-256 + P-521)"""
  996. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  997. def test_dpp_ap_config_p384_p256(dev, apdev):
  998. """DPP and AP configuration (P-384 + P-256)"""
  999. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  1000. def test_dpp_ap_config_p384_p384(dev, apdev):
  1001. """DPP and AP configuration (P-384 + P-384)"""
  1002. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  1003. def test_dpp_ap_config_p384_p521(dev, apdev):
  1004. """DPP and AP configuration (P-384 + P-521)"""
  1005. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  1006. def test_dpp_ap_config_p521_p256(dev, apdev):
  1007. """DPP and AP configuration (P-521 + P-256)"""
  1008. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  1009. def test_dpp_ap_config_p521_p384(dev, apdev):
  1010. """DPP and AP configuration (P-521 + P-384)"""
  1011. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  1012. def test_dpp_ap_config_p521_p521(dev, apdev):
  1013. """DPP and AP configuration (P-521 + P-521)"""
  1014. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  1015. def update_hapd_config(hapd):
  1016. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  1017. if ev is None:
  1018. raise Exception("SSID not reported (AP)")
  1019. ssid = ev.split(' ')[1]
  1020. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  1021. if ev is None:
  1022. raise Exception("Connector not reported (AP)")
  1023. connector = ev.split(' ')[1]
  1024. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  1025. if ev is None:
  1026. raise Exception("C-sign-key not reported (AP)")
  1027. p = ev.split(' ')
  1028. csign = p[1]
  1029. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  1030. if ev is None:
  1031. raise Exception("netAccessKey not reported (AP)")
  1032. p = ev.split(' ')
  1033. net_access_key = p[1]
  1034. net_access_key_expiry = p[2] if len(p) > 2 else None
  1035. logger.info("Update AP configuration to use key_mgmt=DPP")
  1036. hapd.disable()
  1037. hapd.set("ssid", ssid)
  1038. hapd.set("wpa", "2")
  1039. hapd.set("wpa_key_mgmt", "DPP")
  1040. hapd.set("ieee80211w", "2")
  1041. hapd.set("rsn_pairwise", "CCMP")
  1042. hapd.set("dpp_connector", connector)
  1043. hapd.set("dpp_csign", csign)
  1044. hapd.set("dpp_netaccesskey", net_access_key)
  1045. if net_access_key_expiry:
  1046. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  1047. hapd.enable()
  1048. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  1049. check_dpp_capab(dev[0])
  1050. check_dpp_capab(dev[1])
  1051. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1052. check_dpp_capab(hapd)
  1053. addr = hapd.own_addr().replace(':', '')
  1054. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1055. if curve:
  1056. cmd += " curve=" + curve
  1057. res = hapd.request(cmd)
  1058. if "FAIL" in res:
  1059. raise Exception("Failed to generate bootstrapping info")
  1060. id_h = int(res)
  1061. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1062. cmd = "DPP_CONFIGURATOR_ADD"
  1063. if conf_curve:
  1064. cmd += " curve=" + conf_curve
  1065. res = dev[0].request(cmd);
  1066. if "FAIL" in res:
  1067. raise Exception("Failed to add configurator")
  1068. conf_id = int(res)
  1069. res = dev[0].request("DPP_QR_CODE " + uri)
  1070. if "FAIL" in res:
  1071. raise Exception("Failed to parse QR Code URI")
  1072. id = int(res)
  1073. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1074. if "OK" not in dev[0].request(cmd):
  1075. raise Exception("Failed to initiate DPP Authentication")
  1076. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1077. if ev is None:
  1078. raise Exception("DPP authentication did not succeed (Responder)")
  1079. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1080. if ev is None:
  1081. raise Exception("DPP authentication did not succeed (Initiator)")
  1082. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1083. if ev is None:
  1084. raise Exception("DPP configuration not completed (Configurator)")
  1085. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  1086. if ev is None:
  1087. raise Exception("DPP configuration not completed (Enrollee)")
  1088. if "DPP-CONF-FAILED" in ev:
  1089. raise Exception("DPP configuration failed")
  1090. update_hapd_config(hapd)
  1091. addr = dev[1].own_addr().replace(':', '')
  1092. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1093. if curve:
  1094. cmd += " curve=" + curve
  1095. res = dev[1].request(cmd)
  1096. if "FAIL" in res:
  1097. raise Exception("Failed to generate bootstrapping info")
  1098. id1 = int(res)
  1099. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1100. res = dev[0].request("DPP_QR_CODE " + uri1)
  1101. if "FAIL" in res:
  1102. raise Exception("Failed to parse QR Code URI")
  1103. id0b = int(res)
  1104. cmd = "DPP_LISTEN 2412"
  1105. if "OK" not in dev[1].request(cmd):
  1106. raise Exception("Failed to start listen operation")
  1107. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  1108. if "OK" not in dev[0].request(cmd):
  1109. raise Exception("Failed to initiate DPP Authentication")
  1110. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1111. if ev is None:
  1112. raise Exception("DPP authentication did not succeed (Responder)")
  1113. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1114. if ev is None:
  1115. raise Exception("DPP authentication did not succeed (Initiator)")
  1116. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1117. if ev is None:
  1118. raise Exception("DPP configuration not completed (Configurator)")
  1119. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1120. if ev is None:
  1121. raise Exception("DPP configuration not completed (Enrollee)")
  1122. dev[1].request("DPP_STOP_LISTEN")
  1123. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  1124. if ev is None:
  1125. raise Exception("SSID not reported")
  1126. ssid = ev.split(' ')[1]
  1127. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  1128. if ev is None:
  1129. raise Exception("Connector not reported")
  1130. connector = ev.split(' ')[1]
  1131. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  1132. if ev is None:
  1133. raise Exception("C-sign-key not reported")
  1134. p = ev.split(' ')
  1135. csign = p[1]
  1136. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  1137. if ev is None:
  1138. raise Exception("netAccessKey not reported")
  1139. p = ev.split(' ')
  1140. net_access_key = p[1]
  1141. net_access_key_expiry = p[2] if len(p) > 2 else None
  1142. dev[1].dump_monitor()
  1143. id = dev[1].connect(ssid, key_mgmt="DPP", ieee80211w="2", scan_freq="2412",
  1144. only_add_network=True)
  1145. dev[1].set_network_quoted(id, "dpp_connector", connector)
  1146. dev[1].set_network(id, "dpp_csign", csign)
  1147. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  1148. if net_access_key_expiry:
  1149. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  1150. logger.info("Check data connection")
  1151. dev[1].select_network(id, freq="2412")
  1152. dev[1].wait_connected()
  1153. def test_dpp_auto_connect_1(dev, apdev):
  1154. """DPP and auto connect (1)"""
  1155. try:
  1156. run_dpp_auto_connect(dev, apdev, 1)
  1157. finally:
  1158. dev[0].set("dpp_config_processing", "0")
  1159. def test_dpp_auto_connect_2(dev, apdev):
  1160. """DPP and auto connect (2)"""
  1161. try:
  1162. run_dpp_auto_connect(dev, apdev, 2)
  1163. finally:
  1164. dev[0].set("dpp_config_processing", "0")
  1165. def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
  1166. """DPP and auto connect (2) using connect_cmd"""
  1167. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1168. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  1169. dev_new = [ wpas, dev[1] ]
  1170. try:
  1171. run_dpp_auto_connect(dev_new, apdev, 2)
  1172. finally:
  1173. wpas.set("dpp_config_processing", "0")
  1174. def run_dpp_auto_connect(dev, apdev, processing):
  1175. check_dpp_capab(dev[0])
  1176. check_dpp_capab(dev[1])
  1177. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1178. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1179. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1180. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1181. params = { "ssid": "test",
  1182. "wpa": "2",
  1183. "wpa_key_mgmt": "DPP",
  1184. "ieee80211w": "2",
  1185. "rsn_pairwise": "CCMP",
  1186. "dpp_connector": ap_connector,
  1187. "dpp_csign": csign_pub,
  1188. "dpp_netaccesskey": ap_netaccesskey }
  1189. try:
  1190. hapd = hostapd.add_ap(apdev[0], params)
  1191. except:
  1192. raise HwsimSkip("DPP not supported")
  1193. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1194. res = dev[1].request(cmd)
  1195. if "FAIL" in res:
  1196. raise Exception("DPP_CONFIGURATOR_ADD failed")
  1197. conf_id = int(res)
  1198. dev[0].set("dpp_config_processing", str(processing))
  1199. addr = dev[0].own_addr().replace(':', '')
  1200. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1201. res = dev[0].request(cmd)
  1202. if "FAIL" in res:
  1203. raise Exception("Failed to generate bootstrapping info")
  1204. id0 = int(res)
  1205. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1206. res = dev[1].request("DPP_QR_CODE " + uri0)
  1207. if "FAIL" in res:
  1208. raise Exception("Failed to parse QR Code URI")
  1209. id1 = int(res)
  1210. cmd = "DPP_LISTEN 2412"
  1211. if "OK" not in dev[0].request(cmd):
  1212. raise Exception("Failed to start listen operation")
  1213. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1214. if "OK" not in dev[1].request(cmd):
  1215. raise Exception("Failed to initiate DPP Authentication")
  1216. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1217. if ev is None:
  1218. raise Exception("DPP configuration not completed (Configurator)")
  1219. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1220. if ev is None:
  1221. raise Exception("DPP configuration not completed (Enrollee)")
  1222. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1223. if ev is None:
  1224. raise Exception("DPP network profile not generated")
  1225. id = ev.split(' ')[1]
  1226. if processing == 1:
  1227. dev[0].select_network(id, freq=2412)
  1228. dev[0].wait_connected()
  1229. hwsim_utils.test_connectivity(dev[0], hapd)
  1230. def test_dpp_auto_connect_legacy(dev, apdev):
  1231. """DPP and auto connect (legacy)"""
  1232. try:
  1233. run_dpp_auto_connect_legacy(dev, apdev)
  1234. finally:
  1235. dev[0].set("dpp_config_processing", "0")
  1236. def run_dpp_auto_connect_legacy(dev, apdev):
  1237. check_dpp_capab(dev[0])
  1238. check_dpp_capab(dev[1])
  1239. params = hostapd.wpa2_params(ssid="dpp-legacy",
  1240. passphrase="secret passphrase")
  1241. hapd = hostapd.add_ap(apdev[0], params)
  1242. dev[0].set("dpp_config_processing", "2")
  1243. addr = dev[0].own_addr().replace(':', '')
  1244. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1245. res = dev[0].request(cmd)
  1246. if "FAIL" in res:
  1247. raise Exception("Failed to generate bootstrapping info")
  1248. id0 = int(res)
  1249. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1250. res = dev[1].request("DPP_QR_CODE " + uri0)
  1251. if "FAIL" in res:
  1252. raise Exception("Failed to parse QR Code URI")
  1253. id1 = int(res)
  1254. cmd = "DPP_LISTEN 2412"
  1255. if "OK" not in dev[0].request(cmd):
  1256. raise Exception("Failed to start listen operation")
  1257. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  1258. if "OK" not in dev[1].request(cmd):
  1259. raise Exception("Failed to initiate DPP Authentication")
  1260. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1261. if ev is None:
  1262. raise Exception("DPP configuration not completed (Configurator)")
  1263. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1264. if ev is None:
  1265. raise Exception("DPP configuration not completed (Enrollee)")
  1266. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1267. if ev is None:
  1268. raise Exception("DPP network profile not generated")
  1269. id = ev.split(' ')[1]
  1270. dev[0].wait_connected()
  1271. def test_dpp_auto_connect_legacy_pmf_required(dev, apdev):
  1272. """DPP and auto connect (legacy, PMF required)"""
  1273. try:
  1274. run_dpp_auto_connect_legacy_pmf_required(dev, apdev)
  1275. finally:
  1276. dev[0].set("dpp_config_processing", "0")
  1277. def run_dpp_auto_connect_legacy_pmf_required(dev, apdev):
  1278. check_dpp_capab(dev[0])
  1279. check_dpp_capab(dev[1])
  1280. params = hostapd.wpa2_params(ssid="dpp-legacy",
  1281. passphrase="secret passphrase")
  1282. params['wpa_key_mgmt'] = "WPA-PSK-SHA256"
  1283. params['ieee80211w'] = "2"
  1284. hapd = hostapd.add_ap(apdev[0], params)
  1285. dev[0].set("dpp_config_processing", "2")
  1286. addr = dev[0].own_addr().replace(':', '')
  1287. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1288. res = dev[0].request(cmd)
  1289. if "FAIL" in res:
  1290. raise Exception("Failed to generate bootstrapping info")
  1291. id0 = int(res)
  1292. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1293. res = dev[1].request("DPP_QR_CODE " + uri0)
  1294. if "FAIL" in res:
  1295. raise Exception("Failed to parse QR Code URI")
  1296. id1 = int(res)
  1297. cmd = "DPP_LISTEN 2412"
  1298. if "OK" not in dev[0].request(cmd):
  1299. raise Exception("Failed to start listen operation")
  1300. cmd = "DPP_AUTH_INIT peer=%d conf=sta-psk ssid=%s pass=%s" % (id1, "dpp-legacy".encode("hex"), "secret passphrase".encode("hex"))
  1301. if "OK" not in dev[1].request(cmd):
  1302. raise Exception("Failed to initiate DPP Authentication")
  1303. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=10)
  1304. if ev is None:
  1305. raise Exception("DPP configuration not completed (Configurator)")
  1306. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=2)
  1307. if ev is None:
  1308. raise Exception("DPP configuration not completed (Enrollee)")
  1309. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1310. if ev is None:
  1311. raise Exception("DPP network profile not generated")
  1312. id = ev.split(' ')[1]
  1313. dev[0].wait_connected()
  1314. def test_dpp_qr_code_auth_responder_configurator(dev, apdev):
  1315. """DPP QR Code and responder as the configurator"""
  1316. check_dpp_capab(dev[0])
  1317. check_dpp_capab(dev[1])
  1318. cmd = "DPP_CONFIGURATOR_ADD"
  1319. res = dev[0].request(cmd);
  1320. if "FAIL" in res:
  1321. raise Exception("Failed to add configurator")
  1322. conf_id = int(res)
  1323. addr = dev[0].own_addr().replace(':', '')
  1324. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1325. res = dev[0].request(cmd)
  1326. if "FAIL" in res:
  1327. raise Exception("Failed to generate bootstrapping info")
  1328. id0 = int(res)
  1329. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1330. res = dev[1].request("DPP_QR_CODE " + uri0)
  1331. if "FAIL" in res:
  1332. raise Exception("Failed to parse QR Code URI")
  1333. id1 = int(res)
  1334. dev[0].set("dpp_configurator_params", " conf=sta-dpp configurator=%d" % conf_id);
  1335. cmd = "DPP_LISTEN 2412 role=configurator"
  1336. if "OK" not in dev[0].request(cmd):
  1337. raise Exception("Failed to start listen operation")
  1338. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1339. if "OK" not in dev[1].request(cmd):
  1340. raise Exception("Failed to initiate DPP Authentication")
  1341. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1342. if ev is None:
  1343. raise Exception("DPP authentication did not succeed (Responder)")
  1344. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1345. if ev is None:
  1346. raise Exception("DPP authentication did not succeed (Initiator)")
  1347. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1348. if ev is None:
  1349. raise Exception("DPP configuration not completed (Configurator)")
  1350. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1351. if ev is None:
  1352. raise Exception("DPP configuration not completed (Enrollee)")
  1353. dev[0].request("DPP_STOP_LISTEN")
  1354. dev[0].dump_monitor()
  1355. dev[1].dump_monitor()
  1356. def test_dpp_qr_code_hostapd_init(dev, apdev):
  1357. """DPP QR Code and hostapd as initiator"""
  1358. check_dpp_capab(dev[0])
  1359. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1360. "channel": "6" })
  1361. check_dpp_capab(hapd)
  1362. cmd = "DPP_CONFIGURATOR_ADD"
  1363. res = dev[0].request(cmd);
  1364. if "FAIL" in res:
  1365. raise Exception("Failed to add configurator")
  1366. conf_id = int(res)
  1367. addr = dev[0].own_addr().replace(':', '')
  1368. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1369. res = dev[0].request(cmd)
  1370. if "FAIL" in res:
  1371. raise Exception("Failed to generate bootstrapping info")
  1372. id0 = int(res)
  1373. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1374. dev[0].set("dpp_configurator_params",
  1375. " conf=ap-dpp configurator=%d" % conf_id);
  1376. cmd = "DPP_LISTEN 2437 role=configurator"
  1377. if "OK" not in dev[0].request(cmd):
  1378. raise Exception("Failed to start listen operation")
  1379. res = hapd.request("DPP_QR_CODE " + uri0)
  1380. if "FAIL" in res:
  1381. raise Exception("Failed to parse QR Code URI")
  1382. id1 = int(res)
  1383. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  1384. if "OK" not in hapd.request(cmd):
  1385. raise Exception("Failed to initiate DPP Authentication")
  1386. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1387. if ev is None:
  1388. raise Exception("DPP authentication did not succeed (Responder)")
  1389. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1390. if ev is None:
  1391. raise Exception("DPP authentication did not succeed (Initiator)")
  1392. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1393. if ev is None:
  1394. raise Exception("DPP configuration not completed (Configurator)")
  1395. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1396. if ev is None:
  1397. raise Exception("DPP configuration not completed (Enrollee)")
  1398. dev[0].request("DPP_STOP_LISTEN")
  1399. dev[0].dump_monitor()
  1400. def test_dpp_pkex(dev, apdev):
  1401. """DPP and PKEX"""
  1402. run_dpp_pkex(dev, apdev)
  1403. def test_dpp_pkex_p256(dev, apdev):
  1404. """DPP and PKEX (P-256)"""
  1405. run_dpp_pkex(dev, apdev, "P-256")
  1406. def test_dpp_pkex_p384(dev, apdev):
  1407. """DPP and PKEX (P-384)"""
  1408. run_dpp_pkex(dev, apdev, "P-384")
  1409. def test_dpp_pkex_p521(dev, apdev):
  1410. """DPP and PKEX (P-521)"""
  1411. run_dpp_pkex(dev, apdev, "P-521")
  1412. def test_dpp_pkex_bp256(dev, apdev):
  1413. """DPP and PKEX (BP-256)"""
  1414. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1415. def test_dpp_pkex_bp384(dev, apdev):
  1416. """DPP and PKEX (BP-384)"""
  1417. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1418. def test_dpp_pkex_bp512(dev, apdev):
  1419. """DPP and PKEX (BP-512)"""
  1420. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1421. def test_dpp_pkex_config(dev, apdev):
  1422. """DPP and PKEX with initiator as the configurator"""
  1423. check_dpp_capab(dev[1])
  1424. cmd = "DPP_CONFIGURATOR_ADD"
  1425. res = dev[1].request(cmd);
  1426. if "FAIL" in res:
  1427. raise Exception("Failed to add configurator")
  1428. conf_id = int(res)
  1429. run_dpp_pkex(dev, apdev,
  1430. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1431. check_config=True)
  1432. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1433. check_dpp_capab(dev[0], curve and "brainpool" in curve)
  1434. check_dpp_capab(dev[1], curve and "brainpool" in curve)
  1435. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1436. if curve:
  1437. cmd += " curve=" + curve
  1438. res = dev[0].request(cmd)
  1439. if "FAIL" in res:
  1440. raise Exception("Failed to generate bootstrapping info")
  1441. id0 = int(res)
  1442. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1443. if curve:
  1444. cmd += " curve=" + curve
  1445. res = dev[1].request(cmd)
  1446. if "FAIL" in res:
  1447. raise Exception("Failed to generate bootstrapping info")
  1448. id1 = int(res)
  1449. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1450. res = dev[0].request(cmd)
  1451. if "FAIL" in res:
  1452. raise Exception("Failed to set PKEX data (responder)")
  1453. cmd = "DPP_LISTEN 2437"
  1454. if "OK" not in dev[0].request(cmd):
  1455. raise Exception("Failed to start listen operation")
  1456. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1457. res = dev[1].request(cmd)
  1458. if "FAIL" in res:
  1459. raise Exception("Failed to set PKEX data (initiator)")
  1460. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1461. if ev is None:
  1462. raise Exception("DPP authentication did not succeed (Initiator)")
  1463. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1464. if ev is None:
  1465. raise Exception("DPP authentication did not succeed (Responder)")
  1466. if check_config:
  1467. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1468. if ev is None:
  1469. raise Exception("DPP configuration not completed (Configurator)")
  1470. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1471. if ev is None:
  1472. raise Exception("DPP configuration not completed (Enrollee)")
  1473. def test_dpp_pkex_code_mismatch(dev, apdev):
  1474. """DPP and PKEX with mismatching code"""
  1475. check_dpp_capab(dev[0])
  1476. check_dpp_capab(dev[1])
  1477. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1478. res = dev[0].request(cmd)
  1479. if "FAIL" in res:
  1480. raise Exception("Failed to generate bootstrapping info")
  1481. id0 = int(res)
  1482. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1483. res = dev[1].request(cmd)
  1484. if "FAIL" in res:
  1485. raise Exception("Failed to generate bootstrapping info")
  1486. id1 = int(res)
  1487. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1488. res = dev[0].request(cmd)
  1489. if "FAIL" in res:
  1490. raise Exception("Failed to set PKEX data (responder)")
  1491. cmd = "DPP_LISTEN 2437"
  1492. if "OK" not in dev[0].request(cmd):
  1493. raise Exception("Failed to start listen operation")
  1494. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=unknown" % id1
  1495. res = dev[1].request(cmd)
  1496. if "FAIL" in res:
  1497. raise Exception("Failed to set PKEX data (initiator)")
  1498. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1499. if ev is None:
  1500. raise Exception("Failure not reported")
  1501. if "possible PKEX code mismatch" not in ev:
  1502. raise Exception("Unexpected result: " + ev)
  1503. dev[0].dump_monitor()
  1504. dev[1].dump_monitor()
  1505. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1506. res = dev[1].request(cmd)
  1507. if "FAIL" in res:
  1508. raise Exception("Failed to set PKEX data (initiator, retry)")
  1509. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1510. if ev is None:
  1511. raise Exception("DPP authentication did not succeed (Initiator, retry)")
  1512. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1513. if ev is None:
  1514. raise Exception("DPP authentication did not succeed (Responder, retry)")
  1515. def test_dpp_pkex_code_mismatch_limit(dev, apdev):
  1516. """DPP and PKEX with mismatching code limit"""
  1517. check_dpp_capab(dev[0])
  1518. check_dpp_capab(dev[1])
  1519. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1520. res = dev[0].request(cmd)
  1521. if "FAIL" in res:
  1522. raise Exception("Failed to generate bootstrapping info")
  1523. id0 = int(res)
  1524. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1525. res = dev[1].request(cmd)
  1526. if "FAIL" in res:
  1527. raise Exception("Failed to generate bootstrapping info")
  1528. id1 = int(res)
  1529. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1530. res = dev[0].request(cmd)
  1531. if "FAIL" in res:
  1532. raise Exception("Failed to set PKEX data (responder)")
  1533. cmd = "DPP_LISTEN 2437"
  1534. if "OK" not in dev[0].request(cmd):
  1535. raise Exception("Failed to start listen operation")
  1536. for i in range(5):
  1537. dev[0].dump_monitor()
  1538. dev[1].dump_monitor()
  1539. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=unknown" % id1
  1540. res = dev[1].request(cmd)
  1541. if "FAIL" in res:
  1542. raise Exception("Failed to set PKEX data (initiator)")
  1543. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1544. if ev is None:
  1545. raise Exception("Failure not reported")
  1546. if "possible PKEX code mismatch" not in ev:
  1547. raise Exception("Unexpected result: " + ev)
  1548. ev = dev[0].wait_event(["DPP-PKEX-T-LIMIT"], timeout=1)
  1549. if ev is None:
  1550. raise Exception("PKEX t limit not reported")
  1551. def test_dpp_pkex_curve_mismatch(dev, apdev):
  1552. """DPP and PKEX with mismatching curve"""
  1553. check_dpp_capab(dev[0])
  1554. check_dpp_capab(dev[1])
  1555. cmd = "DPP_BOOTSTRAP_GEN type=pkex curve=P-256"
  1556. res = dev[0].request(cmd)
  1557. if "FAIL" in res:
  1558. raise Exception("Failed to generate bootstrapping info")
  1559. id0 = int(res)
  1560. cmd = "DPP_BOOTSTRAP_GEN type=pkex curve=P-384"
  1561. res = dev[1].request(cmd)
  1562. if "FAIL" in res:
  1563. raise Exception("Failed to generate bootstrapping info")
  1564. id1 = int(res)
  1565. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1566. res = dev[0].request(cmd)
  1567. if "FAIL" in res:
  1568. raise Exception("Failed to set PKEX data (responder)")
  1569. cmd = "DPP_LISTEN 2437"
  1570. if "OK" not in dev[0].request(cmd):
  1571. raise Exception("Failed to start listen operation")
  1572. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1573. res = dev[1].request(cmd)
  1574. if "FAIL" in res:
  1575. raise Exception("Failed to set PKEX data (initiator)")
  1576. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1577. if ev is None:
  1578. raise Exception("Failure not reported (dev 0)")
  1579. if "Mismatching PKEX curve: peer=20 own=19" not in ev:
  1580. raise Exception("Unexpected result: " + ev)
  1581. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1582. if ev is None:
  1583. raise Exception("Failure not reported (dev 1)")
  1584. if "Peer indicated mismatching PKEX group - proposed 19" not in ev:
  1585. raise Exception("Unexpected result: " + ev)
  1586. def test_dpp_pkex_config2(dev, apdev):
  1587. """DPP and PKEX with responder as the configurator"""
  1588. check_dpp_capab(dev[0])
  1589. cmd = "DPP_CONFIGURATOR_ADD"
  1590. res = dev[0].request(cmd);
  1591. if "FAIL" in res:
  1592. raise Exception("Failed to add configurator")
  1593. conf_id = int(res)
  1594. dev[0].set("dpp_configurator_params",
  1595. " conf=sta-dpp configurator=%d" % conf_id);
  1596. run_dpp_pkex2(dev, apdev)
  1597. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1598. check_dpp_capab(dev[0])
  1599. check_dpp_capab(dev[1])
  1600. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1601. if curve:
  1602. cmd += " curve=" + curve
  1603. res = dev[0].request(cmd)
  1604. if "FAIL" in res:
  1605. raise Exception("Failed to generate bootstrapping info")
  1606. id0 = int(res)
  1607. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1608. if curve:
  1609. cmd += " curve=" + curve
  1610. res = dev[1].request(cmd)
  1611. if "FAIL" in res:
  1612. raise Exception("Failed to generate bootstrapping info")
  1613. id1 = int(res)
  1614. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1615. res = dev[0].request(cmd)
  1616. if "FAIL" in res:
  1617. raise Exception("Failed to set PKEX data (responder)")
  1618. cmd = "DPP_LISTEN 2437 role=configurator"
  1619. if "OK" not in dev[0].request(cmd):
  1620. raise Exception("Failed to start listen operation")
  1621. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1622. res = dev[1].request(cmd)
  1623. if "FAIL" in res:
  1624. raise Exception("Failed to set PKEX data (initiator)")
  1625. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1626. if ev is None:
  1627. raise Exception("DPP authentication did not succeed (Initiator)")
  1628. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1629. if ev is None:
  1630. raise Exception("DPP authentication did not succeed (Responder)")
  1631. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1632. if ev is None:
  1633. raise Exception("DPP configuration not completed (Configurator)")
  1634. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1635. if ev is None:
  1636. raise Exception("DPP configuration not completed (Enrollee)")
  1637. def test_dpp_pkex_hostapd_responder(dev, apdev):
  1638. """DPP PKEX with hostapd as responder"""
  1639. check_dpp_capab(dev[0])
  1640. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1641. "channel": "6" })
  1642. check_dpp_capab(hapd)
  1643. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1644. res = hapd.request(cmd)
  1645. if "FAIL" in res:
  1646. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1647. id_h = int(res)
  1648. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  1649. res = hapd.request(cmd)
  1650. if "FAIL" in res:
  1651. raise Exception("Failed to set PKEX data (responder/hostapd)")
  1652. cmd = "DPP_CONFIGURATOR_ADD"
  1653. res = dev[0].request(cmd);
  1654. if "FAIL" in res:
  1655. raise Exception("Failed to add configurator")
  1656. conf_id = int(res)
  1657. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1658. res = dev[0].request(cmd)
  1659. if "FAIL" in res:
  1660. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1661. id0 = int(res)
  1662. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  1663. res = dev[0].request(cmd)
  1664. if "FAIL" in res:
  1665. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  1666. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1667. if ev is None:
  1668. raise Exception("DPP authentication did not succeed (Initiator)")
  1669. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1670. if ev is None:
  1671. raise Exception("DPP authentication did not succeed (Responder)")
  1672. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1673. if ev is None:
  1674. raise Exception("DPP configuration not completed (Configurator)")
  1675. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1676. if ev is None:
  1677. raise Exception("DPP configuration not completed (Enrollee)")
  1678. dev[0].request("DPP_STOP_LISTEN")
  1679. dev[0].dump_monitor()
  1680. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  1681. """DPP PKEX with hostapd as initiator"""
  1682. check_dpp_capab(dev[0])
  1683. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1684. "channel": "6" })
  1685. check_dpp_capab(hapd)
  1686. cmd = "DPP_CONFIGURATOR_ADD"
  1687. res = dev[0].request(cmd);
  1688. if "FAIL" in res:
  1689. raise Exception("Failed to add configurator")
  1690. conf_id = int(res)
  1691. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1692. res = dev[0].request(cmd)
  1693. if "FAIL" in res:
  1694. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  1695. id0 = int(res)
  1696. dev[0].set("dpp_configurator_params",
  1697. " conf=ap-dpp configurator=%d" % conf_id);
  1698. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1699. res = dev[0].request(cmd)
  1700. if "FAIL" in res:
  1701. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  1702. cmd = "DPP_LISTEN 2437 role=configurator"
  1703. if "OK" not in dev[0].request(cmd):
  1704. raise Exception("Failed to start listen operation")
  1705. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1706. res = hapd.request(cmd)
  1707. if "FAIL" in res:
  1708. raise Exception("Failed to generate bootstrapping info (hostapd)")
  1709. id_h = int(res)
  1710. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  1711. res = hapd.request(cmd)
  1712. if "FAIL" in res:
  1713. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  1714. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1715. if ev is None:
  1716. raise Exception("DPP authentication did not succeed (Initiator)")
  1717. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1718. if ev is None:
  1719. raise Exception("DPP authentication did not succeed (Responder)")
  1720. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1721. if ev is None:
  1722. raise Exception("DPP configuration not completed (Configurator)")
  1723. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1724. if ev is None:
  1725. raise Exception("DPP configuration not completed (Enrollee)")
  1726. dev[0].request("DPP_STOP_LISTEN")
  1727. dev[0].dump_monitor()
  1728. def test_dpp_hostapd_configurator(dev, apdev):
  1729. """DPP with hostapd as configurator/initiator"""
  1730. check_dpp_capab(dev[0])
  1731. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1732. "channel": "1" })
  1733. check_dpp_capab(hapd)
  1734. cmd = "DPP_CONFIGURATOR_ADD"
  1735. res = hapd.request(cmd);
  1736. if "FAIL" in res:
  1737. raise Exception("Failed to add configurator")
  1738. conf_id = int(res)
  1739. addr = dev[0].own_addr().replace(':', '')
  1740. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1741. res = dev[0].request(cmd)
  1742. if "FAIL" in res:
  1743. raise Exception("Failed to generate bootstrapping info")
  1744. id0 = int(res)
  1745. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1746. res = hapd.request("DPP_QR_CODE " + uri0)
  1747. if "FAIL" in res:
  1748. raise Exception("Failed to parse QR Code URI")
  1749. id1 = int(res)
  1750. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  1751. if "FAIL" in res:
  1752. raise Exception("DPP_BOOTSTRAP_INFO failed")
  1753. if "type=QRCODE" not in res:
  1754. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  1755. if "mac_addr=" + dev[0].own_addr() not in res:
  1756. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  1757. cmd = "DPP_LISTEN 2412"
  1758. if "OK" not in dev[0].request(cmd):
  1759. raise Exception("Failed to start listen operation")
  1760. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  1761. if "OK" not in hapd.request(cmd):
  1762. raise Exception("Failed to initiate DPP Authentication")
  1763. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1764. if ev is None:
  1765. raise Exception("DPP authentication did not succeed (Responder)")
  1766. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1767. if ev is None:
  1768. raise Exception("DPP authentication did not succeed (Initiator)")
  1769. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1770. if ev is None:
  1771. raise Exception("DPP configuration not completed (Configurator)")
  1772. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1773. if ev is None:
  1774. raise Exception("DPP configuration not completed (Enrollee)")
  1775. dev[0].request("DPP_STOP_LISTEN")
  1776. dev[0].dump_monitor()
  1777. def test_dpp_hostapd_configurator_responder(dev, apdev):
  1778. """DPP with hostapd as configurator/responder"""
  1779. check_dpp_capab(dev[0])
  1780. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  1781. "channel": "1" })
  1782. check_dpp_capab(hapd)
  1783. cmd = "DPP_CONFIGURATOR_ADD"
  1784. res = hapd.request(cmd);
  1785. if "FAIL" in res:
  1786. raise Exception("Failed to add configurator")
  1787. conf_id = int(res)
  1788. hapd.set("dpp_configurator_params",
  1789. " conf=sta-dpp configurator=%d" % conf_id);
  1790. addr = hapd.own_addr().replace(':', '')
  1791. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1792. res = hapd.request(cmd)
  1793. if "FAIL" in res:
  1794. raise Exception("Failed to generate bootstrapping info")
  1795. id0 = int(res)
  1796. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1797. res = dev[0].request("DPP_QR_CODE " + uri0)
  1798. if "FAIL" in res:
  1799. raise Exception("Failed to parse QR Code URI")
  1800. id1 = int(res)
  1801. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  1802. if "OK" not in dev[0].request(cmd):
  1803. raise Exception("Failed to initiate DPP Authentication")
  1804. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1805. if ev is None:
  1806. raise Exception("DPP authentication did not succeed (Responder)")
  1807. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1808. if ev is None:
  1809. raise Exception("DPP authentication did not succeed (Initiator)")
  1810. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  1811. if ev is None:
  1812. raise Exception("DPP configuration not completed (Configurator)")
  1813. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1814. if ev is None:
  1815. raise Exception("DPP configuration not completed (Enrollee)")
  1816. dev[0].request("DPP_STOP_LISTEN")
  1817. dev[0].dump_monitor()
  1818. def test_dpp_own_config(dev, apdev):
  1819. """DPP configurator signing own connector"""
  1820. try:
  1821. run_dpp_own_config(dev, apdev)
  1822. finally:
  1823. dev[0].set("dpp_config_processing", "0")
  1824. def test_dpp_own_config_curve_mismatch(dev, apdev):
  1825. """DPP configurator signing own connector using mismatching curve"""
  1826. try:
  1827. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  1828. finally:
  1829. dev[0].set("dpp_config_processing", "0")
  1830. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  1831. check_dpp_capab(dev[0], own_curve and "BP" in own_curve)
  1832. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1833. check_dpp_capab(hapd)
  1834. addr = hapd.own_addr().replace(':', '')
  1835. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1836. res = hapd.request(cmd)
  1837. if "FAIL" in res:
  1838. raise Exception("Failed to generate bootstrapping info")
  1839. id_h = int(res)
  1840. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1841. cmd = "DPP_CONFIGURATOR_ADD"
  1842. res = dev[0].request(cmd);
  1843. if "FAIL" in res:
  1844. raise Exception("Failed to add configurator")
  1845. conf_id = int(res)
  1846. res = dev[0].request("DPP_QR_CODE " + uri)
  1847. if "FAIL" in res:
  1848. raise Exception("Failed to parse QR Code URI")
  1849. id = int(res)
  1850. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1851. if "OK" not in dev[0].request(cmd):
  1852. raise Exception("Failed to initiate DPP Authentication")
  1853. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1854. if ev is None:
  1855. raise Exception("DPP authentication did not succeed (Responder)")
  1856. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1857. if ev is None:
  1858. raise Exception("DPP authentication did not succeed (Initiator)")
  1859. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1860. if ev is None:
  1861. raise Exception("DPP configuration not completed (Configurator)")
  1862. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1863. if ev is None:
  1864. raise Exception("DPP configuration not completed (Enrollee)")
  1865. update_hapd_config(hapd)
  1866. dev[0].set("dpp_config_processing", "1")
  1867. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  1868. if own_curve:
  1869. cmd += " curve=" + own_curve
  1870. res = dev[0].request(cmd)
  1871. if "FAIL" in res:
  1872. raise Exception("Failed to generate own configuration")
  1873. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  1874. if ev is None:
  1875. raise Exception("DPP network profile not generated")
  1876. id = ev.split(' ')[1]
  1877. dev[0].select_network(id, freq="2412")
  1878. if expect_failure:
  1879. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1880. if ev is not None:
  1881. raise Exception("Unexpected connection");
  1882. dev[0].request("DISCONNECT")
  1883. else:
  1884. dev[0].wait_connected()
  1885. def test_dpp_intro_mismatch(dev, apdev):
  1886. """DPP network introduction mismatch cases"""
  1887. try:
  1888. wpas = None
  1889. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1890. wpas.interface_add("wlan5")
  1891. check_dpp_capab(wpas)
  1892. run_dpp_intro_mismatch(dev, apdev, wpas)
  1893. finally:
  1894. dev[0].set("dpp_config_processing", "0")
  1895. dev[2].set("dpp_config_processing", "0")
  1896. if wpas:
  1897. wpas.set("dpp_config_processing", "0")
  1898. def run_dpp_intro_mismatch(dev, apdev, wpas):
  1899. check_dpp_capab(dev[0])
  1900. check_dpp_capab(dev[1])
  1901. check_dpp_capab(dev[2])
  1902. logger.info("Start AP in unconfigured state")
  1903. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1904. check_dpp_capab(hapd)
  1905. addr = hapd.own_addr().replace(':', '')
  1906. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1907. res = hapd.request(cmd)
  1908. if "FAIL" in res:
  1909. raise Exception("Failed to generate bootstrapping info")
  1910. id_h = int(res)
  1911. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  1912. logger.info("Provision AP with DPP configuration")
  1913. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  1914. if "FAIL" in res:
  1915. raise Exception("Failed to add configurator")
  1916. conf_id = int(res)
  1917. res = dev[1].request("DPP_QR_CODE " + uri)
  1918. if "FAIL" in res:
  1919. raise Exception("Failed to parse QR Code URI")
  1920. id = int(res)
  1921. dev[1].set("dpp_groups_override", '[{"groupId":"a","netRole":"ap"}]')
  1922. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  1923. if "OK" not in dev[1].request(cmd):
  1924. raise Exception("Failed to initiate DPP Authentication")
  1925. update_hapd_config(hapd)
  1926. logger.info("Provision STA0 with DPP Connector that has mismatching groupId")
  1927. dev[0].set("dpp_config_processing", "2")
  1928. addr = dev[0].own_addr().replace(':', '')
  1929. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1930. res = dev[0].request(cmd)
  1931. if "FAIL" in res:
  1932. raise Exception("Failed to generate bootstrapping info")
  1933. id0 = int(res)
  1934. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1935. res = dev[1].request("DPP_QR_CODE " + uri0)
  1936. if "FAIL" in res:
  1937. raise Exception("Failed to parse QR Code URI")
  1938. id1 = int(res)
  1939. cmd = "DPP_LISTEN 2412"
  1940. if "OK" not in dev[0].request(cmd):
  1941. raise Exception("Failed to start listen operation")
  1942. dev[1].set("dpp_groups_override", '[{"groupId":"b","netRole":"sta"}]')
  1943. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1944. if "OK" not in dev[1].request(cmd):
  1945. raise Exception("Failed to initiate DPP Authentication")
  1946. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1947. if ev is None:
  1948. raise Exception("DPP configuration not completed (Configurator for STA0)")
  1949. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1950. if ev is None:
  1951. raise Exception("DPP configuration not completed (Enrollee STA0)")
  1952. logger.info("Provision STA2 with DPP Connector that has mismatching C-sign-key")
  1953. dev[2].set("dpp_config_processing", "2")
  1954. addr = dev[2].own_addr().replace(':', '')
  1955. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1956. res = dev[2].request(cmd)
  1957. if "FAIL" in res:
  1958. raise Exception("Failed to generate bootstrapping info")
  1959. id2 = int(res)
  1960. uri2 = dev[2].request("DPP_BOOTSTRAP_GET_URI %d" % id2)
  1961. res = dev[1].request("DPP_QR_CODE " + uri2)
  1962. if "FAIL" in res:
  1963. raise Exception("Failed to parse QR Code URI")
  1964. id1 = int(res)
  1965. cmd = "DPP_LISTEN 2412"
  1966. if "OK" not in dev[2].request(cmd):
  1967. raise Exception("Failed to start listen operation")
  1968. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  1969. if "FAIL" in res:
  1970. raise Exception("Failed to add configurator")
  1971. conf_id_2 = int(res)
  1972. dev[1].set("dpp_groups_override", '')
  1973. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id_2)
  1974. if "OK" not in dev[1].request(cmd):
  1975. raise Exception("Failed to initiate DPP Authentication")
  1976. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1977. if ev is None:
  1978. raise Exception("DPP configuration not completed (Configurator for STA2)")
  1979. ev = dev[2].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1980. if ev is None:
  1981. raise Exception("DPP configuration not completed (Enrollee STA2)")
  1982. logger.info("Provision STA5 with DPP Connector that has mismatching netAccessKey EC group")
  1983. wpas.set("dpp_config_processing", "2")
  1984. addr = wpas.own_addr().replace(':', '')
  1985. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1986. cmd += " curve=P-521"
  1987. res = wpas.request(cmd)
  1988. if "FAIL" in res:
  1989. raise Exception("Failed to generate bootstrapping info")
  1990. id5 = int(res)
  1991. uri5 = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % id5)
  1992. res = dev[1].request("DPP_QR_CODE " + uri5)
  1993. if "FAIL" in res:
  1994. raise Exception("Failed to parse QR Code URI")
  1995. id1 = int(res)
  1996. cmd = "DPP_LISTEN 2412"
  1997. if "OK" not in wpas.request(cmd):
  1998. raise Exception("Failed to start listen operation")
  1999. dev[1].set("dpp_groups_override", '')
  2000. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  2001. if "OK" not in dev[1].request(cmd):
  2002. raise Exception("Failed to initiate DPP Authentication")
  2003. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  2004. if ev is None:
  2005. raise Exception("DPP configuration not completed (Configurator for STA0)")
  2006. ev = wpas.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2007. if ev is None:
  2008. raise Exception("DPP configuration not completed (Enrollee STA5)")
  2009. logger.info("Verify network introduction results")
  2010. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  2011. if ev is None:
  2012. raise Exception("DPP network introduction result not seen on STA0")
  2013. if "status=8" not in ev:
  2014. raise Exception("Unexpected network introduction result on STA0: " + ev)
  2015. ev = dev[2].wait_event(["DPP-INTRO"], timeout=5)
  2016. if ev is None:
  2017. raise Exception("DPP network introduction result not seen on STA2")
  2018. if "status=8" not in ev:
  2019. raise Exception("Unexpected network introduction result on STA2: " + ev)
  2020. ev = wpas.wait_event(["DPP-INTRO"], timeout=10)
  2021. if ev is None:
  2022. raise Exception("DPP network introduction result not seen on STA5")
  2023. if "status=7" not in ev:
  2024. raise Exception("Unexpected network introduction result on STA5: " + ev)
  2025. def run_dpp_proto_init(dev, test_dev, test, mutual=False):
  2026. check_dpp_capab(dev[0])
  2027. check_dpp_capab(dev[1])
  2028. dev[test_dev].set("dpp_test", str(test))
  2029. cmd = "DPP_CONFIGURATOR_ADD"
  2030. res = dev[1].request(cmd);
  2031. if "FAIL" in res:
  2032. raise Exception("Failed to add configurator")
  2033. conf_id = int(res)
  2034. addr = dev[0].own_addr().replace(':', '')
  2035. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2036. res = dev[0].request(cmd)
  2037. if "FAIL" in res:
  2038. raise Exception("Failed to generate bootstrapping info")
  2039. id0 = int(res)
  2040. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2041. res = dev[1].request("DPP_QR_CODE " + uri0)
  2042. if "FAIL" in res:
  2043. raise Exception("Failed to parse QR Code URI")
  2044. id1 = int(res)
  2045. if mutual:
  2046. addr = dev[1].own_addr().replace(':', '')
  2047. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  2048. if "FAIL" in res:
  2049. raise Exception("Failed to generate bootstrapping info")
  2050. id1b = int(res)
  2051. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  2052. res = dev[0].request("DPP_QR_CODE " + uri1b)
  2053. if "FAIL" in res:
  2054. raise Exception("Failed to parse QR Code URI")
  2055. id0b = int(res)
  2056. cmd = "DPP_LISTEN 2412 qr=mutual"
  2057. else:
  2058. cmd = "DPP_LISTEN 2412"
  2059. if "OK" not in dev[0].request(cmd):
  2060. raise Exception("Failed to start listen operation")
  2061. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  2062. if mutual:
  2063. cmd += " own=%d" % id1b
  2064. if "OK" not in dev[1].request(cmd):
  2065. raise Exception("Failed to initiate DPP Authentication")
  2066. def test_dpp_proto_after_wrapped_data_auth_req(dev, apdev):
  2067. """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
  2068. run_dpp_proto_init(dev, 1, 1)
  2069. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2070. if ev is None:
  2071. raise Exception("DPP Authentication Request not seen")
  2072. if "type=0" not in ev or "ignore=invalid-attributes" not in ev:
  2073. raise Exception("Unexpected RX info: " + ev)
  2074. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  2075. if ev is not None:
  2076. raise Exception("Unexpected DPP message seen")
  2077. def test_dpp_proto_after_wrapped_data_auth_resp(dev, apdev):
  2078. """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
  2079. run_dpp_proto_init(dev, 0, 2)
  2080. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2081. if ev is None:
  2082. raise Exception("DPP Authentication Response not seen")
  2083. if "type=1" not in ev or "ignore=invalid-attributes" not in ev:
  2084. raise Exception("Unexpected RX info: " + ev)
  2085. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2086. if ev is None or "type=0" not in ev:
  2087. raise Exception("DPP Authentication Request not seen")
  2088. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2089. if ev is not None:
  2090. raise Exception("Unexpected DPP message seen")
  2091. def test_dpp_proto_after_wrapped_data_auth_conf(dev, apdev):
  2092. """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
  2093. run_dpp_proto_init(dev, 1, 3)
  2094. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2095. if ev is None or "type=0" not in ev:
  2096. raise Exception("DPP Authentication Request not seen")
  2097. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2098. if ev is None:
  2099. raise Exception("DPP Authentication Confirm not seen")
  2100. if "type=2" not in ev or "ignore=invalid-attributes" not in ev:
  2101. raise Exception("Unexpected RX info: " + ev)
  2102. def test_dpp_proto_after_wrapped_data_conf_req(dev, apdev):
  2103. """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
  2104. run_dpp_proto_init(dev, 0, 6)
  2105. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=10)
  2106. if ev is None:
  2107. raise Exception("DPP Configuration failure not seen")
  2108. def test_dpp_proto_after_wrapped_data_conf_resp(dev, apdev):
  2109. """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
  2110. run_dpp_proto_init(dev, 1, 7)
  2111. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=10)
  2112. if ev is None:
  2113. raise Exception("DPP Configuration failure not seen")
  2114. def test_dpp_proto_zero_i_capab(dev, apdev):
  2115. """DPP protocol testing - zero I-capability in Auth Req"""
  2116. run_dpp_proto_init(dev, 1, 8)
  2117. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2118. if ev is None:
  2119. raise Exception("DPP failure not seen")
  2120. if "Invalid role in I-capabilities 0x00" not in ev:
  2121. raise Exception("Unexpected failure: " + ev)
  2122. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  2123. if ev is not None:
  2124. raise Exception("Unexpected DPP message seen")
  2125. def test_dpp_proto_zero_r_capab(dev, apdev):
  2126. """DPP protocol testing - zero R-capability in Auth Resp"""
  2127. run_dpp_proto_init(dev, 0, 9)
  2128. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2129. if ev is None:
  2130. raise Exception("DPP failure not seen")
  2131. if "Unexpected role in R-capabilities 0x00" not in ev:
  2132. raise Exception("Unexpected failure: " + ev)
  2133. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2134. if ev is None or "type=0" not in ev:
  2135. raise Exception("DPP Authentication Request not seen")
  2136. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2137. if ev is not None:
  2138. raise Exception("Unexpected DPP message seen")
  2139. def run_dpp_proto_auth_req_missing(dev, test, reason, mutual=False):
  2140. run_dpp_proto_init(dev, 1, test, mutual=mutual)
  2141. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2142. if ev is None:
  2143. raise Exception("DPP failure not seen")
  2144. if reason not in ev:
  2145. raise Exception("Unexpected failure: " + ev)
  2146. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  2147. if ev is not None:
  2148. raise Exception("Unexpected DPP message seen")
  2149. def test_dpp_proto_auth_req_no_r_bootstrap_key(dev, apdev):
  2150. """DPP protocol testing - no R-bootstrap key in Auth Req"""
  2151. run_dpp_proto_auth_req_missing(dev, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2152. def test_dpp_proto_auth_req_invalid_r_bootstrap_key(dev, apdev):
  2153. """DPP protocol testing - invalid R-bootstrap key in Auth Req"""
  2154. run_dpp_proto_auth_req_missing(dev, 68, "No matching own bootstrapping key found - ignore message")
  2155. def test_dpp_proto_auth_req_no_i_bootstrap_key(dev, apdev):
  2156. """DPP protocol testing - no I-bootstrap key in Auth Req"""
  2157. run_dpp_proto_auth_req_missing(dev, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
  2158. def test_dpp_proto_auth_req_invalid_i_bootstrap_key(dev, apdev):
  2159. """DPP protocol testing - invalid I-bootstrap key in Auth Req"""
  2160. run_dpp_proto_init(dev, 1, 69, mutual=True)
  2161. ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  2162. if ev is None:
  2163. raise Exception("DPP scan request not seen")
  2164. ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  2165. if ev is None:
  2166. raise Exception("DPP response pending indivation not seen")
  2167. def test_dpp_proto_auth_req_no_i_proto_key(dev, apdev):
  2168. """DPP protocol testing - no I-proto key in Auth Req"""
  2169. run_dpp_proto_auth_req_missing(dev, 12, "Missing required Initiator Protocol Key attribute")
  2170. def test_dpp_proto_auth_req_invalid_i_proto_key(dev, apdev):
  2171. """DPP protocol testing - invalid I-proto key in Auth Req"""
  2172. run_dpp_proto_auth_req_missing(dev, 66, "Invalid Initiator Protocol Key")
  2173. def test_dpp_proto_auth_req_no_i_nonce(dev, apdev):
  2174. """DPP protocol testing - no I-nonce in Auth Req"""
  2175. run_dpp_proto_auth_req_missing(dev, 13, "Missing or invalid I-nonce")
  2176. def test_dpp_proto_auth_req_no_i_capab(dev, apdev):
  2177. """DPP protocol testing - no I-capab in Auth Req"""
  2178. run_dpp_proto_auth_req_missing(dev, 14, "Missing or invalid I-capab")
  2179. def test_dpp_proto_auth_req_no_wrapped_data(dev, apdev):
  2180. """DPP protocol testing - no Wrapped Data in Auth Req"""
  2181. run_dpp_proto_auth_req_missing(dev, 15, "Missing or invalid required Wrapped Data attribute")
  2182. def run_dpp_proto_auth_resp_missing(dev, test, reason):
  2183. run_dpp_proto_init(dev, 0, test, mutual=True)
  2184. if reason is None:
  2185. time.sleep(0.1)
  2186. return
  2187. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2188. if ev is None:
  2189. raise Exception("DPP failure not seen")
  2190. if reason not in ev:
  2191. raise Exception("Unexpected failure: " + ev)
  2192. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2193. if ev is None or "type=0" not in ev:
  2194. raise Exception("DPP Authentication Request not seen")
  2195. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2196. if ev is not None:
  2197. raise Exception("Unexpected DPP message seen")
  2198. def test_dpp_proto_auth_resp_no_status(dev, apdev):
  2199. """DPP protocol testing - no Status in Auth Resp"""
  2200. run_dpp_proto_auth_resp_missing(dev, 16, "Missing or invalid required DPP Status attribute")
  2201. def test_dpp_proto_auth_resp_invalid_status(dev, apdev):
  2202. """DPP protocol testing - invalid Status in Auth Resp"""
  2203. run_dpp_proto_auth_resp_missing(dev, 74, "Responder reported failure")
  2204. def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev, apdev):
  2205. """DPP protocol testing - no R-bootstrap key in Auth Resp"""
  2206. run_dpp_proto_auth_resp_missing(dev, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2207. def test_dpp_proto_auth_resp_invalid_r_bootstrap_key(dev, apdev):
  2208. """DPP protocol testing - invalid R-bootstrap key in Auth Resp"""
  2209. run_dpp_proto_auth_resp_missing(dev, 70, "Unexpected Responder Bootstrapping Key Hash value")
  2210. def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev, apdev):
  2211. """DPP protocol testing - no I-bootstrap key in Auth Resp"""
  2212. run_dpp_proto_auth_resp_missing(dev, 18, None)
  2213. def test_dpp_proto_auth_resp_invalid_i_bootstrap_key(dev, apdev):
  2214. """DPP protocol testing - invalid I-bootstrap key in Auth Resp"""
  2215. run_dpp_proto_auth_resp_missing(dev, 71, "Initiator Bootstrapping Key Hash attribute did not match")
  2216. def test_dpp_proto_auth_resp_no_r_proto_key(dev, apdev):
  2217. """DPP protocol testing - no R-Proto Key in Auth Resp"""
  2218. run_dpp_proto_auth_resp_missing(dev, 19, "Missing required Responder Protocol Key attribute")
  2219. def test_dpp_proto_auth_resp_invalid_r_proto_key(dev, apdev):
  2220. """DPP protocol testing - invalid R-Proto Key in Auth Resp"""
  2221. run_dpp_proto_auth_resp_missing(dev, 67, "Invalid Responder Protocol Key")
  2222. def test_dpp_proto_auth_resp_no_r_nonce(dev, apdev):
  2223. """DPP protocol testing - no R-nonce in Auth Resp"""
  2224. run_dpp_proto_auth_resp_missing(dev, 20, "Missing or invalid R-nonce")
  2225. def test_dpp_proto_auth_resp_no_i_nonce(dev, apdev):
  2226. """DPP protocol testing - no I-nonce in Auth Resp"""
  2227. run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce")
  2228. def test_dpp_proto_auth_resp_no_r_capab(dev, apdev):
  2229. """DPP protocol testing - no R-capab in Auth Resp"""
  2230. run_dpp_proto_auth_resp_missing(dev, 22, "Missing or invalid R-capabilities")
  2231. def test_dpp_proto_auth_resp_no_r_auth(dev, apdev):
  2232. """DPP protocol testing - no R-auth in Auth Resp"""
  2233. run_dpp_proto_auth_resp_missing(dev, 23, "Missing or invalid Secondary Wrapped Data")
  2234. def test_dpp_proto_auth_resp_no_wrapped_data(dev, apdev):
  2235. """DPP protocol testing - no Wrapped Data in Auth Resp"""
  2236. run_dpp_proto_auth_resp_missing(dev, 24, "Missing or invalid required Wrapped Data attribute")
  2237. def test_dpp_proto_auth_resp_i_nonce_mismatch(dev, apdev):
  2238. """DPP protocol testing - I-nonce mismatch in Auth Resp"""
  2239. run_dpp_proto_init(dev, 0, 30, mutual=True)
  2240. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2241. if ev is None:
  2242. raise Exception("DPP failure not seen")
  2243. if "I-nonce mismatch" not in ev:
  2244. raise Exception("Unexpected failure: " + ev)
  2245. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2246. if ev is None or "type=0" not in ev:
  2247. raise Exception("DPP Authentication Request not seen")
  2248. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2249. if ev is not None:
  2250. raise Exception("Unexpected DPP message seen")
  2251. def test_dpp_proto_auth_resp_incompatible_r_capab(dev, apdev):
  2252. """DPP protocol testing - Incompatible R-capab in Auth Resp"""
  2253. run_dpp_proto_init(dev, 0, 31, mutual=True)
  2254. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2255. if ev is None:
  2256. raise Exception("DPP failure not seen")
  2257. if "Unexpected role in R-capabilities 0x02" not in ev:
  2258. raise Exception("Unexpected failure: " + ev)
  2259. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2260. if ev is None:
  2261. raise Exception("DPP failure not seen")
  2262. if "Peer reported incompatible R-capab role" not in ev:
  2263. raise Exception("Unexpected failure: " + ev)
  2264. def test_dpp_proto_auth_resp_r_auth_mismatch(dev, apdev):
  2265. """DPP protocol testing - R-auth mismatch in Auth Resp"""
  2266. run_dpp_proto_init(dev, 0, 32, mutual=True)
  2267. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2268. if ev is None:
  2269. raise Exception("DPP failure not seen")
  2270. if "Mismatching Responder Authenticating Tag" not in ev:
  2271. raise Exception("Unexpected failure: " + ev)
  2272. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2273. if ev is None:
  2274. raise Exception("DPP failure not seen")
  2275. if "Peer reported authentication failure" not in ev:
  2276. raise Exception("Unexpected failure: " + ev)
  2277. def run_dpp_proto_auth_conf_missing(dev, test, reason):
  2278. run_dpp_proto_init(dev, 1, test, mutual=True)
  2279. if reason is None:
  2280. time.sleep(0.1)
  2281. return
  2282. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2283. if ev is None:
  2284. raise Exception("DPP failure not seen")
  2285. if reason not in ev:
  2286. raise Exception("Unexpected failure: " + ev)
  2287. def test_dpp_proto_auth_conf_no_status(dev, apdev):
  2288. """DPP protocol testing - no Status in Auth Conf"""
  2289. run_dpp_proto_auth_conf_missing(dev, 25, "Missing or invalid required DPP Status attribute")
  2290. def test_dpp_proto_auth_conf_invalid_status(dev, apdev):
  2291. """DPP protocol testing - invalid Status in Auth Conf"""
  2292. run_dpp_proto_auth_conf_missing(dev, 75, "Authentication failed")
  2293. def test_dpp_proto_auth_conf_no_r_bootstrap_key(dev, apdev):
  2294. """DPP protocol testing - no R-bootstrap key in Auth Conf"""
  2295. run_dpp_proto_auth_conf_missing(dev, 26, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2296. def test_dpp_proto_auth_conf_invalid_r_bootstrap_key(dev, apdev):
  2297. """DPP protocol testing - invalid R-bootstrap key in Auth Conf"""
  2298. run_dpp_proto_auth_conf_missing(dev, 72, "Responder Bootstrapping Key Hash mismatch")
  2299. def test_dpp_proto_auth_conf_no_i_bootstrap_key(dev, apdev):
  2300. """DPP protocol testing - no I-bootstrap key in Auth Conf"""
  2301. run_dpp_proto_auth_conf_missing(dev, 27, "Missing Initiator Bootstrapping Key Hash attribute")
  2302. def test_dpp_proto_auth_conf_invalid_i_bootstrap_key(dev, apdev):
  2303. """DPP protocol testing - invalid I-bootstrap key in Auth Conf"""
  2304. run_dpp_proto_auth_conf_missing(dev, 73, "Initiator Bootstrapping Key Hash mismatch")
  2305. def test_dpp_proto_auth_conf_no_i_auth(dev, apdev):
  2306. """DPP protocol testing - no I-Auth in Auth Conf"""
  2307. run_dpp_proto_auth_conf_missing(dev, 28, "Missing or invalid Initiator Authenticating Tag")
  2308. def test_dpp_proto_auth_conf_no_wrapped_data(dev, apdev):
  2309. """DPP protocol testing - no Wrapped Data in Auth Conf"""
  2310. run_dpp_proto_auth_conf_missing(dev, 29, "Missing or invalid required Wrapped Data attribute")
  2311. def test_dpp_proto_auth_conf_i_auth_mismatch(dev, apdev):
  2312. """DPP protocol testing - I-auth mismatch in Auth Conf"""
  2313. run_dpp_proto_init(dev, 1, 33, mutual=True)
  2314. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2315. if ev is None:
  2316. raise Exception("DPP failure not seen")
  2317. if "Mismatching Initiator Authenticating Tag" not in ev:
  2318. raise Excception("Unexpected failure: " + ev)
  2319. def test_dpp_proto_auth_conf_replaced_by_resp(dev, apdev):
  2320. """DPP protocol testing - Auth Conf replaced by Resp"""
  2321. run_dpp_proto_init(dev, 1, 65, mutual=True)
  2322. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2323. if ev is None:
  2324. raise Exception("DPP failure not seen")
  2325. if "Unexpected Authentication Response" not in ev:
  2326. raise Excception("Unexpected failure: " + ev)
  2327. def run_dpp_proto_conf_req_missing(dev, test, reason):
  2328. run_dpp_proto_init(dev, 0, test)
  2329. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2330. if ev is None:
  2331. raise Exception("DPP failure not seen")
  2332. if reason not in ev:
  2333. raise Exception("Unexpected failure: " + ev)
  2334. def test_dpp_proto_conf_req_no_e_nonce(dev, apdev):
  2335. """DPP protocol testing - no E-nonce in Conf Req"""
  2336. run_dpp_proto_conf_req_missing(dev, 51,
  2337. "Missing or invalid Enrollee Nonce attribute")
  2338. def test_dpp_proto_conf_req_no_config_attr_obj(dev, apdev):
  2339. """DPP protocol testing - no Config Attr Obj in Conf Req"""
  2340. run_dpp_proto_conf_req_missing(dev, 52,
  2341. "Missing or invalid Config Attributes attribute")
  2342. def test_dpp_proto_conf_req_invalid_config_attr_obj(dev, apdev):
  2343. """DPP protocol testing - invalid Config Attr Obj in Conf Req"""
  2344. run_dpp_proto_conf_req_missing(dev, 76,
  2345. "Unsupported wi-fi_tech")
  2346. def test_dpp_proto_conf_req_no_wrapped_data(dev, apdev):
  2347. """DPP protocol testing - no Wrapped Data in Conf Req"""
  2348. run_dpp_proto_conf_req_missing(dev, 53,
  2349. "Missing or invalid required Wrapped Data attribute")
  2350. def run_dpp_proto_conf_resp_missing(dev, test, reason):
  2351. run_dpp_proto_init(dev, 1, test)
  2352. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2353. if ev is None:
  2354. raise Exception("DPP failure not seen")
  2355. if reason not in ev:
  2356. raise Exception("Unexpected failure: " + ev)
  2357. def test_dpp_proto_conf_resp_no_e_nonce(dev, apdev):
  2358. """DPP protocol testing - no E-nonce in Conf Resp"""
  2359. run_dpp_proto_conf_resp_missing(dev, 54,
  2360. "Missing or invalid Enrollee Nonce attribute")
  2361. def test_dpp_proto_conf_resp_no_config_obj(dev, apdev):
  2362. """DPP protocol testing - no Config Object in Conf Resp"""
  2363. run_dpp_proto_conf_resp_missing(dev, 55,
  2364. "Missing required Configuration Object attribute")
  2365. def test_dpp_proto_conf_resp_no_status(dev, apdev):
  2366. """DPP protocol testing - no Status in Conf Resp"""
  2367. run_dpp_proto_conf_resp_missing(dev, 56,
  2368. "Missing or invalid required DPP Status attribute")
  2369. def test_dpp_proto_conf_resp_no_wrapped_data(dev, apdev):
  2370. """DPP protocol testing - no Wrapped Data in Conf Resp"""
  2371. run_dpp_proto_conf_resp_missing(dev, 57,
  2372. "Missing or invalid required Wrapped Data attribute")
  2373. def test_dpp_proto_conf_resp_invalid_status(dev, apdev):
  2374. """DPP protocol testing - invalid Status in Conf Resp"""
  2375. run_dpp_proto_conf_resp_missing(dev, 58,
  2376. "Configurator rejected configuration")
  2377. def test_dpp_proto_conf_resp_e_nonce_mismatch(dev, apdev):
  2378. """DPP protocol testing - E-nonce mismatch in Conf Resp"""
  2379. run_dpp_proto_conf_resp_missing(dev, 59,
  2380. "Enrollee Nonce mismatch")
  2381. def run_dpp_proto_init_pkex(dev, test_dev, test):
  2382. check_dpp_capab(dev[0])
  2383. check_dpp_capab(dev[1])
  2384. dev[test_dev].set("dpp_test", str(test))
  2385. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2386. res = dev[0].request(cmd)
  2387. if "FAIL" in res:
  2388. raise Exception("Failed to generate bootstrapping info")
  2389. id0 = int(res)
  2390. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2391. res = dev[1].request(cmd)
  2392. if "FAIL" in res:
  2393. raise Exception("Failed to generate bootstrapping info")
  2394. id1 = int(res)
  2395. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  2396. res = dev[0].request(cmd)
  2397. if "FAIL" in res:
  2398. raise Exception("Failed to set PKEX data (responder)")
  2399. cmd = "DPP_LISTEN 2437"
  2400. if "OK" not in dev[0].request(cmd):
  2401. raise Exception("Failed to start listen operation")
  2402. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  2403. res = dev[1].request(cmd)
  2404. if "FAIL" in res:
  2405. raise Exception("Failed to set PKEX data (initiator)")
  2406. def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev, apdev):
  2407. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
  2408. run_dpp_proto_init_pkex(dev, 1, 4)
  2409. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2410. if ev is None or "type=7" not in ev:
  2411. raise Exception("PKEX Exchange Request not seen")
  2412. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2413. if ev is None or "type=9" not in ev:
  2414. raise Exception("PKEX Commit-Reveal Request not seen")
  2415. if "ignore=invalid-attributes" not in ev:
  2416. raise Exception("Unexpected RX info: " + ev)
  2417. def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev, apdev):
  2418. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
  2419. run_dpp_proto_init_pkex(dev, 0, 5)
  2420. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2421. if ev is None or "type=8" not in ev:
  2422. raise Exception("PKEX Exchange Response not seen")
  2423. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2424. if ev is None or "type=10" not in ev:
  2425. raise Exception("PKEX Commit-Reveal Response not seen")
  2426. if "ignore=invalid-attributes" not in ev:
  2427. raise Exception("Unexpected RX info: " + ev)
  2428. def run_dpp_proto_pkex_req_missing(dev, test, reason):
  2429. run_dpp_proto_init_pkex(dev, 1, test)
  2430. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2431. if ev is None:
  2432. raise Exception("DPP failure not seen")
  2433. if reason not in ev:
  2434. raise Exception("Unexpected failure: " + ev)
  2435. def run_dpp_proto_pkex_resp_missing(dev, test, reason):
  2436. run_dpp_proto_init_pkex(dev, 0, test)
  2437. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2438. if ev is None:
  2439. raise Exception("DPP failure not seen")
  2440. if reason not in ev:
  2441. raise Exception("Unexpected failure: " + ev)
  2442. def test_dpp_proto_pkex_exchange_req_no_finite_cyclic_group(dev, apdev):
  2443. """DPP protocol testing - no Finite Cyclic Group in PKEX Exchange Request"""
  2444. run_dpp_proto_pkex_req_missing(dev, 34,
  2445. "Missing or invalid Finite Cyclic Group attribute")
  2446. def test_dpp_proto_pkex_exchange_req_no_encrypted_key(dev, apdev):
  2447. """DPP protocol testing - no Encrypted Key in PKEX Exchange Request"""
  2448. run_dpp_proto_pkex_req_missing(dev, 35,
  2449. "Missing Encrypted Key attribute")
  2450. def test_dpp_proto_pkex_exchange_resp_no_status(dev, apdev):
  2451. """DPP protocol testing - no Status in PKEX Exchange Response"""
  2452. run_dpp_proto_pkex_resp_missing(dev, 36, "No DPP Status attribute")
  2453. def test_dpp_proto_pkex_exchange_resp_no_encrypted_key(dev, apdev):
  2454. """DPP protocol testing - no Encrypted Key in PKEX Exchange Response"""
  2455. run_dpp_proto_pkex_resp_missing(dev, 37, "Missing Encrypted Key attribute")
  2456. def test_dpp_proto_pkex_cr_req_no_bootstrap_key(dev, apdev):
  2457. """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Request"""
  2458. run_dpp_proto_pkex_req_missing(dev, 38,
  2459. "No valid peer bootstrapping key found")
  2460. def test_dpp_proto_pkex_cr_req_no_i_auth_tag(dev, apdev):
  2461. """DPP protocol testing - no I-Auth Tag in PKEX Commit-Reveal Request"""
  2462. run_dpp_proto_pkex_req_missing(dev, 39, "No valid u (I-Auth tag) found")
  2463. def test_dpp_proto_pkex_cr_req_no_wrapped_data(dev, apdev):
  2464. """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Request"""
  2465. run_dpp_proto_pkex_req_missing(dev, 40, "Missing or invalid required Wrapped Data attribute")
  2466. def test_dpp_proto_pkex_cr_resp_no_bootstrap_key(dev, apdev):
  2467. """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Response"""
  2468. run_dpp_proto_pkex_resp_missing(dev, 41,
  2469. "No valid peer bootstrapping key found")
  2470. def test_dpp_proto_pkex_cr_resp_no_r_auth_tag(dev, apdev):
  2471. """DPP protocol testing - no R-Auth Tag in PKEX Commit-Reveal Response"""
  2472. run_dpp_proto_pkex_resp_missing(dev, 42, "No valid v (R-Auth tag) found")
  2473. def test_dpp_proto_pkex_cr_resp_no_wrapped_data(dev, apdev):
  2474. """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Response"""
  2475. run_dpp_proto_pkex_resp_missing(dev, 43, "Missing or invalid required Wrapped Data attribute")
  2476. def test_dpp_proto_pkex_exchange_req_invalid_encrypted_key(dev, apdev):
  2477. """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Request"""
  2478. run_dpp_proto_pkex_req_missing(dev, 44,
  2479. "Invalid Encrypted Key value")
  2480. def test_dpp_proto_pkex_exchange_resp_invalid_encrypted_key(dev, apdev):
  2481. """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Response"""
  2482. run_dpp_proto_pkex_resp_missing(dev, 45,
  2483. "Invalid Encrypted Key value")
  2484. def test_dpp_proto_pkex_exchange_resp_invalid_status(dev, apdev):
  2485. """DPP protocol testing - invalid Status in PKEX Exchange Response"""
  2486. run_dpp_proto_pkex_resp_missing(dev, 46,
  2487. "PKEX failed (peer indicated failure)")
  2488. def test_dpp_proto_pkex_cr_req_invalid_bootstrap_key(dev, apdev):
  2489. """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Request"""
  2490. run_dpp_proto_pkex_req_missing(dev, 47,
  2491. "Peer bootstrapping key is invalid")
  2492. def test_dpp_proto_pkex_cr_resp_invalid_bootstrap_key(dev, apdev):
  2493. """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Response"""
  2494. run_dpp_proto_pkex_resp_missing(dev, 48,
  2495. "Peer bootstrapping key is invalid")
  2496. def test_dpp_proto_pkex_cr_req_i_auth_tag_mismatch(dev, apdev):
  2497. """DPP protocol testing - I-auth tag mismatch in PKEX Commit-Reveal Request"""
  2498. run_dpp_proto_pkex_req_missing(dev, 49, "No valid u (I-Auth tag) found")
  2499. def test_dpp_proto_pkex_cr_resp_r_auth_tag_mismatch(dev, apdev):
  2500. """DPP protocol testing - R-auth tag mismatch in PKEX Commit-Reveal Response"""
  2501. run_dpp_proto_pkex_resp_missing(dev, 50, "No valid v (R-Auth tag) found")
  2502. def test_dpp_proto_network_introduction(dev, apdev):
  2503. """DPP protocol testing - network introduction"""
  2504. check_dpp_capab(dev[0])
  2505. check_dpp_capab(dev[1])
  2506. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  2507. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  2508. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  2509. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  2510. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  2511. params = { "ssid": "dpp",
  2512. "wpa": "2",
  2513. "wpa_key_mgmt": "DPP",
  2514. "ieee80211w": "2",
  2515. "rsn_pairwise": "CCMP",
  2516. "dpp_connector": ap_connector,
  2517. "dpp_csign": csign,
  2518. "dpp_netaccesskey": ap_netaccesskey }
  2519. try:
  2520. hapd = hostapd.add_ap(apdev[0], params)
  2521. except:
  2522. raise HwsimSkip("DPP not supported")
  2523. for test in [ 60, 61, 80 ]:
  2524. dev[0].set("dpp_test", str(test))
  2525. dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
  2526. dpp_csign=csign, dpp_connector=sta_connector,
  2527. dpp_netaccesskey=sta_netaccesskey, wait_connect=False)
  2528. ev = dev[0].wait_event(["DPP-TX"], timeout=10)
  2529. if ev is None or "type=5" not in ev:
  2530. raise Exception("Peer Discovery Request TX not reported")
  2531. ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=2)
  2532. if ev is None or "result=SUCCESS" not in ev:
  2533. raise Exception("Peer Discovery Request TX status not reported")
  2534. ev = hapd.wait_event(["DPP-RX"], timeout=10)
  2535. if ev is None or "type=5" not in ev:
  2536. raise Exception("Peer Discovery Request RX not reported")
  2537. if test == 80:
  2538. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  2539. if ev is None:
  2540. raise Exception("DPP-INTRO not reported for test 80")
  2541. if "status=7" not in ev:
  2542. raise Exception("Unexpected result in test 80: " + ev)
  2543. dev[0].request("REMOVE_NETWORK all")
  2544. dev[0].dump_monitor()
  2545. hapd.dump_monitor()
  2546. dev[0].set("dpp_test", "0")
  2547. for test in [ 62, 63, 64, 77, 78, 79 ]:
  2548. hapd.set("dpp_test", str(test))
  2549. dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
  2550. dpp_csign=csign, dpp_connector=sta_connector,
  2551. dpp_netaccesskey=sta_netaccesskey, wait_connect=False)
  2552. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  2553. if ev is None:
  2554. raise Exception("Peer introduction result not reported (test %d)" % test)
  2555. if test == 77:
  2556. if "fail=transaction_id_mismatch" not in ev:
  2557. raise Exception("Connector validation failure not reported")
  2558. elif test == 78:
  2559. if "status=254" not in ev:
  2560. raise Exception("Invalid status value not reported")
  2561. elif test == 79:
  2562. if "fail=peer_connector_validation_failed" not in ev:
  2563. raise Exception("Connector validation failure not reported")
  2564. elif "status=" in ev:
  2565. raise Exception("Unexpected peer introduction result (test %d): " % test + ev)
  2566. dev[0].request("REMOVE_NETWORK all")
  2567. dev[0].dump_monitor()
  2568. hapd.dump_monitor()
  2569. hapd.set("dpp_test", "0")
  2570. dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
  2571. dpp_csign=csign, dpp_connector=sta_connector,
  2572. dpp_netaccesskey=sta_netaccesskey)
  2573. def test_dpp_qr_code_no_chan_list_unicast(dev, apdev):
  2574. """DPP QR Code and no channel list (unicast)"""
  2575. run_dpp_qr_code_chan_list(dev, apdev, True, 2417, None)
  2576. def test_dpp_qr_code_chan_list_unicast(dev, apdev):
  2577. """DPP QR Code and 2.4 GHz channels (unicast)"""
  2578. run_dpp_qr_code_chan_list(dev, apdev, True, 2417,
  2579. "81/1,81/2,81/3,81/4,81/5,81/6,81/7,81/8,81/9,81/10,81/11,81/12,81/13")
  2580. def test_dpp_qr_code_chan_list_no_peer_unicast(dev, apdev):
  2581. """DPP QR Code and channel list and no peer (unicast)"""
  2582. run_dpp_qr_code_chan_list(dev, apdev, True, 2417, "81/1,81/6,81/11",
  2583. no_wait=True)
  2584. ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
  2585. if ev is None:
  2586. raise Exception("Initiation failure not reported")
  2587. def test_dpp_qr_code_no_chan_list_broadcast(dev, apdev):
  2588. """DPP QR Code and no channel list (broadcast)"""
  2589. run_dpp_qr_code_chan_list(dev, apdev, False, 2412, None)
  2590. def test_dpp_qr_code_chan_list_broadcast(dev, apdev):
  2591. """DPP QR Code and some 2.4 GHz channels (broadcast)"""
  2592. run_dpp_qr_code_chan_list(dev, apdev, False, 2412, "81/1,81/6,81/11",
  2593. timeout=10)
  2594. def run_dpp_qr_code_chan_list(dev, apdev, unicast, listen_freq, chanlist,
  2595. no_wait=False, timeout=5):
  2596. check_dpp_capab(dev[0])
  2597. check_dpp_capab(dev[1])
  2598. dev[1].set("dpp_init_max_tries", "3")
  2599. dev[1].set("dpp_init_retry_time", "100")
  2600. dev[1].set("dpp_resp_wait_time", "1")
  2601. logger.info("dev0 displays QR Code")
  2602. cmd = "DPP_BOOTSTRAP_GEN type=qrcode"
  2603. if chanlist:
  2604. cmd += " chan=" + chanlist
  2605. if unicast:
  2606. addr = dev[0].own_addr().replace(':', '')
  2607. cmd += " mac=" + addr
  2608. res = dev[0].request(cmd)
  2609. if "FAIL" in res:
  2610. raise Exception("Failed to generate bootstrapping info")
  2611. id0 = int(res)
  2612. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2613. logger.info("dev1 scans QR Code")
  2614. res = dev[1].request("DPP_QR_CODE " + uri0)
  2615. if "FAIL" in res:
  2616. raise Exception("Failed to parse QR Code URI")
  2617. id1 = int(res)
  2618. logger.info("dev1 initiates DPP Authentication")
  2619. cmd = "DPP_LISTEN %d" % listen_freq
  2620. if "OK" not in dev[0].request(cmd):
  2621. raise Exception("Failed to start listen operation")
  2622. cmd = "DPP_AUTH_INIT peer=%d" % id1
  2623. if "OK" not in dev[1].request(cmd):
  2624. raise Exception("Failed to initiate DPP Authentication")
  2625. if no_wait:
  2626. return
  2627. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=timeout)
  2628. if ev is None:
  2629. raise Exception("DPP authentication did not succeed (Responder)")
  2630. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2631. if ev is None:
  2632. raise Exception("DPP authentication did not succeed (Initiator)")
  2633. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  2634. if ev is None:
  2635. raise Exception("DPP configuration not completed (Enrollee)")
  2636. dev[0].request("DPP_STOP_LISTEN")
  2637. dev[0].dump_monitor()
  2638. dev[1].dump_monitor()
  2639. def test_dpp_qr_code_chan_list_no_match(dev, apdev):
  2640. """DPP QR Code and no matching supported channel"""
  2641. check_dpp_capab(dev[0])
  2642. check_dpp_capab(dev[1])
  2643. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=123/123"
  2644. res = dev[0].request(cmd)
  2645. if "FAIL" in res:
  2646. raise Exception("Failed to generate bootstrapping info")
  2647. id0 = int(res)
  2648. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2649. res = dev[1].request("DPP_QR_CODE " + uri0)
  2650. if "FAIL" in res:
  2651. raise Exception("Failed to parse QR Code URI")
  2652. id1 = int(res)
  2653. cmd = "DPP_AUTH_INIT peer=%d" % id1
  2654. if "FAIL" not in dev[1].request(cmd):
  2655. raise Exception("DPP Authentication started unexpectedly")