test_dpp.py 144 KB

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