test_dpp.py 161 KB

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