test_dpp.py 169 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063
  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_test_vector_p_256(dev, apdev):
  1521. """DPP P-256 test vector (mutual auth)"""
  1522. check_dpp_capab(dev[0])
  1523. check_dpp_capab(dev[1])
  1524. # Responder bootstrapping key
  1525. priv = "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0"
  1526. addr = dev[0].own_addr().replace(':', '')
  1527. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr + " key=30310201010420" + priv + "a00a06082a8648ce3d030107"
  1528. res = dev[0].request(cmd)
  1529. if "FAIL" in res:
  1530. raise Exception("Failed to generate bootstrapping info")
  1531. id0 = int(res)
  1532. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1533. # Responder protocol keypair override
  1534. priv = "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5"
  1535. dev[0].set("dpp_protocol_key_override",
  1536. "30310201010420" + priv + "a00a06082a8648ce3d030107")
  1537. dev[0].set("dpp_nonce_override", "3d0cfb011ca916d796f7029ff0b43393")
  1538. # Initiator bootstrapping key
  1539. priv = "15b2a83c5a0a38b61f2aa8200ee4994b8afdc01c58507d10d0a38f7eedf051bb"
  1540. cmd = "DPP_BOOTSTRAP_GEN type=qrcode key=30310201010420" + priv + "a00a06082a8648ce3d030107"
  1541. res = dev[1].request(cmd)
  1542. if "FAIL" in res:
  1543. raise Exception("Failed to generate bootstrapping info")
  1544. id1 = int(res)
  1545. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1546. # Initiator protocol keypair override
  1547. priv = "a87de9afbb406c96e5f79a3df895ecac3ad406f95da66314c8cb3165e0c61783"
  1548. dev[1].set("dpp_protocol_key_override",
  1549. "30310201010420" + priv + "a00a06082a8648ce3d030107")
  1550. dev[1].set("dpp_nonce_override", "13f4602a16daeb69712263b9c46cba31")
  1551. res = dev[1].request("DPP_QR_CODE " + uri0)
  1552. if "FAIL" in res:
  1553. raise Exception("Failed to parse QR Code URI")
  1554. id1peer = int(res)
  1555. res = dev[0].request("DPP_QR_CODE " + uri1)
  1556. if "FAIL" in res:
  1557. raise Exception("Failed to parse QR Code URI")
  1558. id0peer = int(res)
  1559. cmd = "DPP_LISTEN 2462 qr=mutual"
  1560. if "OK" not in dev[0].request(cmd):
  1561. raise Exception("Failed to start listen operation")
  1562. cmd = "DPP_AUTH_INIT peer=%d own=%d neg_freq=2412" % (id1peer, id1)
  1563. if "OK" not in dev[1].request(cmd):
  1564. raise Exception("Failed to initiate operation")
  1565. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1566. if ev is None:
  1567. raise Exception("DPP authentication did not succeed (Initiator)")
  1568. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1569. if ev is None:
  1570. raise Exception("DPP authentication did not succeed (Responder)")
  1571. def test_dpp_test_vector_p_256_b(dev, apdev):
  1572. """DPP P-256 test vector (Responder-only auth)"""
  1573. check_dpp_capab(dev[0])
  1574. check_dpp_capab(dev[1])
  1575. # Responder bootstrapping key
  1576. priv = "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0"
  1577. addr = dev[0].own_addr().replace(':', '')
  1578. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr + " key=30310201010420" + priv + "a00a06082a8648ce3d030107"
  1579. res = dev[0].request(cmd)
  1580. if "FAIL" in res:
  1581. raise Exception("Failed to generate bootstrapping info")
  1582. id0 = int(res)
  1583. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1584. # Responder protocol keypair override
  1585. priv = "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5"
  1586. dev[0].set("dpp_protocol_key_override",
  1587. "30310201010420" + priv + "a00a06082a8648ce3d030107")
  1588. dev[0].set("dpp_nonce_override", "3d0cfb011ca916d796f7029ff0b43393")
  1589. # Initiator bootstrapping key
  1590. priv = "15b2a83c5a0a38b61f2aa8200ee4994b8afdc01c58507d10d0a38f7eedf051bb"
  1591. cmd = "DPP_BOOTSTRAP_GEN type=qrcode key=30310201010420" + priv + "a00a06082a8648ce3d030107"
  1592. res = dev[1].request(cmd)
  1593. if "FAIL" in res:
  1594. raise Exception("Failed to generate bootstrapping info")
  1595. id1 = int(res)
  1596. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1597. # Initiator protocol keypair override
  1598. priv = "a87de9afbb406c96e5f79a3df895ecac3ad406f95da66314c8cb3165e0c61783"
  1599. dev[1].set("dpp_protocol_key_override",
  1600. "30310201010420" + priv + "a00a06082a8648ce3d030107")
  1601. dev[1].set("dpp_nonce_override", "13f4602a16daeb69712263b9c46cba31")
  1602. res = dev[1].request("DPP_QR_CODE " + uri0)
  1603. if "FAIL" in res:
  1604. raise Exception("Failed to parse QR Code URI")
  1605. id1peer = int(res)
  1606. cmd = "DPP_LISTEN 2462"
  1607. if "OK" not in dev[0].request(cmd):
  1608. raise Exception("Failed to start listen operation")
  1609. cmd = "DPP_AUTH_INIT peer=%d own=%d neg_freq=2412" % (id1peer, id1)
  1610. if "OK" not in dev[1].request(cmd):
  1611. raise Exception("Failed to initiate operation")
  1612. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1613. if ev is None:
  1614. raise Exception("DPP authentication did not succeed (Initiator)")
  1615. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1616. if ev is None:
  1617. raise Exception("DPP authentication did not succeed (Responder)")
  1618. def der_priv_key_p_521(priv):
  1619. if len(priv) != 2 * 66:
  1620. raise Exception("Unexpected der_priv_key_p_521 parameter: " + priv)
  1621. der_prefix = "3081500201010442"
  1622. der_postfix = "a00706052b81040023"
  1623. return der_prefix + priv + der_postfix
  1624. def test_dpp_test_vector_p_521(dev, apdev):
  1625. """DPP P-521 test vector (mutual auth)"""
  1626. check_dpp_capab(dev[0])
  1627. check_dpp_capab(dev[1])
  1628. # Responder bootstrapping key
  1629. priv = "0061e54f518cdf859735da3dd64c6f72c2f086f41a6fd52915152ea2fe0f24ddaecd8883730c9c9fd82cf7c043a41021696388cf5190b731dd83638bcd56d8b6c743"
  1630. addr = dev[0].own_addr().replace(':', '')
  1631. #cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr + " key=" + der_prefix + priv + der_postfix
  1632. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr + " key=" + der_priv_key_p_521(priv)
  1633. res = dev[0].request(cmd)
  1634. if "FAIL" in res:
  1635. raise Exception("Failed to generate bootstrapping info")
  1636. id0 = int(res)
  1637. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1638. # Responder protocol keypair override
  1639. priv = "01d8b7b17cd1b0a33f7c66fb4220999329cdaf4f8b44b2ffadde8ab8ed8abffa9f5358c5b1caae26709ca4fb78e52a4d08f2e4f24111a36a6f440d20a0000ff51597"
  1640. dev[0].set("dpp_protocol_key_override", der_priv_key_p_521(priv))
  1641. dev[0].set("dpp_nonce_override",
  1642. "d749a782012eb0a8595af30b2dfc8d0880d004ebddb55ecc5afbdef18c400e01")
  1643. # Initiator bootstrapping key
  1644. priv = "0060c10df14af5ef27f6e362d31bdd9eeb44be77a323ba64b08f3f03d58b92cbfe05c182a91660caa081ca344243c47b5aa088bcdf738840eb35f0218b9f26881e02"
  1645. cmd = "DPP_BOOTSTRAP_GEN type=qrcode key=" + der_priv_key_p_521(priv)
  1646. res = dev[1].request(cmd)
  1647. if "FAIL" in res:
  1648. raise Exception("Failed to generate bootstrapping info")
  1649. id1 = int(res)
  1650. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1651. # Initiator protocol keypair override
  1652. priv = "019c1c08caaeec38fb931894699b095bc3ab8c1ec7ef0622d2e3eba821477c8c6fca41774f21166ad98aebda37c067d9aa08a8a2e1b5c44c61f2bae02a61f85d9661"
  1653. dev[1].set("dpp_protocol_key_override", der_priv_key_p_521(priv))
  1654. dev[1].set("dpp_nonce_override",
  1655. "de972af3847bec3ba2aedd9f5c21cfdec7bf0bc5fe8b276cbcd0267807fb15b0")
  1656. res = dev[1].request("DPP_QR_CODE " + uri0)
  1657. if "FAIL" in res:
  1658. raise Exception("Failed to parse QR Code URI")
  1659. id1peer = int(res)
  1660. res = dev[0].request("DPP_QR_CODE " + uri1)
  1661. if "FAIL" in res:
  1662. raise Exception("Failed to parse QR Code URI")
  1663. id0peer = int(res)
  1664. cmd = "DPP_LISTEN 2462 qr=mutual"
  1665. if "OK" not in dev[0].request(cmd):
  1666. raise Exception("Failed to start listen operation")
  1667. cmd = "DPP_AUTH_INIT peer=%d own=%d neg_freq=2412" % (id1peer, id1)
  1668. if "OK" not in dev[1].request(cmd):
  1669. raise Exception("Failed to initiate operation")
  1670. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1671. if ev is None:
  1672. raise Exception("DPP authentication did not succeed (Initiator)")
  1673. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1674. if ev is None:
  1675. raise Exception("DPP authentication did not succeed (Responder)")
  1676. def test_dpp_pkex(dev, apdev):
  1677. """DPP and PKEX"""
  1678. run_dpp_pkex(dev, apdev)
  1679. def test_dpp_pkex_p256(dev, apdev):
  1680. """DPP and PKEX (P-256)"""
  1681. run_dpp_pkex(dev, apdev, "P-256")
  1682. def test_dpp_pkex_p384(dev, apdev):
  1683. """DPP and PKEX (P-384)"""
  1684. run_dpp_pkex(dev, apdev, "P-384")
  1685. def test_dpp_pkex_p521(dev, apdev):
  1686. """DPP and PKEX (P-521)"""
  1687. run_dpp_pkex(dev, apdev, "P-521")
  1688. def test_dpp_pkex_bp256(dev, apdev):
  1689. """DPP and PKEX (BP-256)"""
  1690. run_dpp_pkex(dev, apdev, "brainpoolP256r1")
  1691. def test_dpp_pkex_bp384(dev, apdev):
  1692. """DPP and PKEX (BP-384)"""
  1693. run_dpp_pkex(dev, apdev, "brainpoolP384r1")
  1694. def test_dpp_pkex_bp512(dev, apdev):
  1695. """DPP and PKEX (BP-512)"""
  1696. run_dpp_pkex(dev, apdev, "brainpoolP512r1")
  1697. def test_dpp_pkex_config(dev, apdev):
  1698. """DPP and PKEX with initiator as the configurator"""
  1699. check_dpp_capab(dev[1])
  1700. cmd = "DPP_CONFIGURATOR_ADD"
  1701. res = dev[1].request(cmd);
  1702. if "FAIL" in res:
  1703. raise Exception("Failed to add configurator")
  1704. conf_id = int(res)
  1705. run_dpp_pkex(dev, apdev,
  1706. init_extra="conf=sta-dpp configurator=%d" % (conf_id),
  1707. check_config=True)
  1708. def run_dpp_pkex(dev, apdev, curve=None, init_extra="", check_config=False):
  1709. check_dpp_capab(dev[0], curve and "brainpool" in curve)
  1710. check_dpp_capab(dev[1], curve and "brainpool" in curve)
  1711. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1712. if curve:
  1713. cmd += " curve=" + curve
  1714. res = dev[0].request(cmd)
  1715. if "FAIL" in res:
  1716. raise Exception("Failed to generate bootstrapping info")
  1717. id0 = int(res)
  1718. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1719. if curve:
  1720. cmd += " curve=" + curve
  1721. res = dev[1].request(cmd)
  1722. if "FAIL" in res:
  1723. raise Exception("Failed to generate bootstrapping info")
  1724. id1 = int(res)
  1725. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1726. res = dev[0].request(cmd)
  1727. if "FAIL" in res:
  1728. raise Exception("Failed to set PKEX data (responder)")
  1729. cmd = "DPP_LISTEN 2437"
  1730. if "OK" not in dev[0].request(cmd):
  1731. raise Exception("Failed to start listen operation")
  1732. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 %s code=secret" % (id1, init_extra)
  1733. res = dev[1].request(cmd)
  1734. if "FAIL" in res:
  1735. raise Exception("Failed to set PKEX data (initiator)")
  1736. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1737. if ev is None:
  1738. raise Exception("DPP authentication did not succeed (Initiator)")
  1739. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1740. if ev is None:
  1741. raise Exception("DPP authentication did not succeed (Responder)")
  1742. if check_config:
  1743. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  1744. if ev is None:
  1745. raise Exception("DPP configuration not completed (Configurator)")
  1746. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1747. if ev is None:
  1748. raise Exception("DPP configuration not completed (Enrollee)")
  1749. def test_dpp_pkex_test_vector(dev, apdev):
  1750. """DPP and PKEX (P-256) test vector"""
  1751. check_dpp_capab(dev[0])
  1752. check_dpp_capab(dev[1])
  1753. dev[0].set("dpp_pkex_own_mac_override", "cd:9b:a8:f3:e5:36")
  1754. dev[0].set("dpp_pkex_peer_mac_override", "0c:c5:fc:af:f3:ec")
  1755. dev[1].set("dpp_pkex_own_mac_override", "0c:c5:fc:af:f3:ec")
  1756. dev[1].set("dpp_pkex_peer_mac_override", "cd:9b:a8:f3:e5:36")
  1757. identifier = "joes_key"
  1758. code = "thisisreallysecret"
  1759. # Responder bootstrapping key
  1760. priv = "2ae8956293f49986b6d0b8169a86805d9232babb5f6813fdfe96f19d59536c60"
  1761. cmd = "DPP_BOOTSTRAP_GEN type=pkex key=30310201010420" + priv + "a00a06082a8648ce3d030107"
  1762. res = dev[0].request(cmd)
  1763. if "FAIL" in res:
  1764. raise Exception("Failed to generate bootstrapping info")
  1765. id0 = int(res)
  1766. # Responder y/Y keypair override
  1767. priv = "cc6cf1b24f59370920df1633a818c6c777013a116a4e1e285c80ed1cc996f0f5"
  1768. dev[0].set("dpp_pkex_ephemeral_key_override",
  1769. "30310201010420" + priv + "a00a06082a8648ce3d030107")
  1770. # Initiator bootstrapping key
  1771. priv = "5941b51acfc702cdc1c347264beb2920db88eb1a0bf03a211868b1632233c269"
  1772. cmd = "DPP_BOOTSTRAP_GEN type=pkex key=30310201010420" + priv + "a00a06082a8648ce3d030107"
  1773. res = dev[1].request(cmd)
  1774. if "FAIL" in res:
  1775. raise Exception("Failed to generate bootstrapping info")
  1776. id1 = int(res)
  1777. # Initiator x/X keypair override
  1778. priv = "c18f91b88b2c8e12349b2f755c888c143bcfa8e42ce744ba24ef656cf893032f"
  1779. dev[1].set("dpp_pkex_ephemeral_key_override",
  1780. "30310201010420" + priv + "a00a06082a8648ce3d030107")
  1781. cmd = "DPP_PKEX_ADD own=%d identifier=%s code=%s" % (id0, identifier, code)
  1782. res = dev[0].request(cmd)
  1783. if "FAIL" in res:
  1784. raise Exception("Failed to set PKEX data (responder)")
  1785. cmd = "DPP_LISTEN 2437"
  1786. if "OK" not in dev[0].request(cmd):
  1787. raise Exception("Failed to start listen operation")
  1788. cmd = "DPP_PKEX_ADD own=%d identifier=%s init=1 code=%s" % (id1, identifier, code)
  1789. res = dev[1].request(cmd)
  1790. if "FAIL" in res:
  1791. raise Exception("Failed to set PKEX data (initiator)")
  1792. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1793. if ev is None:
  1794. raise Exception("DPP authentication did not succeed (Initiator)")
  1795. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1796. if ev is None:
  1797. raise Exception("DPP authentication did not succeed (Responder)")
  1798. def test_dpp_pkex_code_mismatch(dev, apdev):
  1799. """DPP and PKEX with mismatching code"""
  1800. check_dpp_capab(dev[0])
  1801. check_dpp_capab(dev[1])
  1802. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1803. res = dev[0].request(cmd)
  1804. if "FAIL" in res:
  1805. raise Exception("Failed to generate bootstrapping info")
  1806. id0 = int(res)
  1807. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1808. res = dev[1].request(cmd)
  1809. if "FAIL" in res:
  1810. raise Exception("Failed to generate bootstrapping info")
  1811. id1 = int(res)
  1812. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1813. res = dev[0].request(cmd)
  1814. if "FAIL" in res:
  1815. raise Exception("Failed to set PKEX data (responder)")
  1816. cmd = "DPP_LISTEN 2437"
  1817. if "OK" not in dev[0].request(cmd):
  1818. raise Exception("Failed to start listen operation")
  1819. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=unknown" % id1
  1820. res = dev[1].request(cmd)
  1821. if "FAIL" in res:
  1822. raise Exception("Failed to set PKEX data (initiator)")
  1823. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1824. if ev is None:
  1825. raise Exception("Failure not reported")
  1826. if "possible PKEX code mismatch" not in ev:
  1827. raise Exception("Unexpected result: " + ev)
  1828. dev[0].dump_monitor()
  1829. dev[1].dump_monitor()
  1830. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1831. res = dev[1].request(cmd)
  1832. if "FAIL" in res:
  1833. raise Exception("Failed to set PKEX data (initiator, retry)")
  1834. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1835. if ev is None:
  1836. raise Exception("DPP authentication did not succeed (Initiator, retry)")
  1837. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1838. if ev is None:
  1839. raise Exception("DPP authentication did not succeed (Responder, retry)")
  1840. def test_dpp_pkex_code_mismatch_limit(dev, apdev):
  1841. """DPP and PKEX with mismatching code limit"""
  1842. check_dpp_capab(dev[0])
  1843. check_dpp_capab(dev[1])
  1844. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1845. res = dev[0].request(cmd)
  1846. if "FAIL" in res:
  1847. raise Exception("Failed to generate bootstrapping info")
  1848. id0 = int(res)
  1849. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1850. res = dev[1].request(cmd)
  1851. if "FAIL" in res:
  1852. raise Exception("Failed to generate bootstrapping info")
  1853. id1 = int(res)
  1854. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1855. res = dev[0].request(cmd)
  1856. if "FAIL" in res:
  1857. raise Exception("Failed to set PKEX data (responder)")
  1858. cmd = "DPP_LISTEN 2437"
  1859. if "OK" not in dev[0].request(cmd):
  1860. raise Exception("Failed to start listen operation")
  1861. for i in range(5):
  1862. dev[0].dump_monitor()
  1863. dev[1].dump_monitor()
  1864. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=unknown" % id1
  1865. res = dev[1].request(cmd)
  1866. if "FAIL" in res:
  1867. raise Exception("Failed to set PKEX data (initiator)")
  1868. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1869. if ev is None:
  1870. raise Exception("Failure not reported")
  1871. if "possible PKEX code mismatch" not in ev:
  1872. raise Exception("Unexpected result: " + ev)
  1873. ev = dev[0].wait_event(["DPP-PKEX-T-LIMIT"], timeout=1)
  1874. if ev is None:
  1875. raise Exception("PKEX t limit not reported")
  1876. def test_dpp_pkex_curve_mismatch(dev, apdev):
  1877. """DPP and PKEX with mismatching curve"""
  1878. check_dpp_capab(dev[0])
  1879. check_dpp_capab(dev[1])
  1880. cmd = "DPP_BOOTSTRAP_GEN type=pkex curve=P-256"
  1881. res = dev[0].request(cmd)
  1882. if "FAIL" in res:
  1883. raise Exception("Failed to generate bootstrapping info")
  1884. id0 = int(res)
  1885. cmd = "DPP_BOOTSTRAP_GEN type=pkex curve=P-384"
  1886. res = dev[1].request(cmd)
  1887. if "FAIL" in res:
  1888. raise Exception("Failed to generate bootstrapping info")
  1889. id1 = int(res)
  1890. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1891. res = dev[0].request(cmd)
  1892. if "FAIL" in res:
  1893. raise Exception("Failed to set PKEX data (responder)")
  1894. cmd = "DPP_LISTEN 2437"
  1895. if "OK" not in dev[0].request(cmd):
  1896. raise Exception("Failed to start listen operation")
  1897. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  1898. res = dev[1].request(cmd)
  1899. if "FAIL" in res:
  1900. raise Exception("Failed to set PKEX data (initiator)")
  1901. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  1902. if ev is None:
  1903. raise Exception("Failure not reported (dev 0)")
  1904. if "Mismatching PKEX curve: peer=20 own=19" not in ev:
  1905. raise Exception("Unexpected result: " + ev)
  1906. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1907. if ev is None:
  1908. raise Exception("Failure not reported (dev 1)")
  1909. if "Peer indicated mismatching PKEX group - proposed 19" not in ev:
  1910. raise Exception("Unexpected result: " + ev)
  1911. def test_dpp_pkex_config2(dev, apdev):
  1912. """DPP and PKEX with responder as the configurator"""
  1913. check_dpp_capab(dev[0])
  1914. cmd = "DPP_CONFIGURATOR_ADD"
  1915. res = dev[0].request(cmd);
  1916. if "FAIL" in res:
  1917. raise Exception("Failed to add configurator")
  1918. conf_id = int(res)
  1919. dev[0].set("dpp_configurator_params",
  1920. " conf=sta-dpp configurator=%d" % conf_id);
  1921. run_dpp_pkex2(dev, apdev)
  1922. def run_dpp_pkex2(dev, apdev, curve=None, init_extra=""):
  1923. check_dpp_capab(dev[0])
  1924. check_dpp_capab(dev[1])
  1925. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1926. if curve:
  1927. cmd += " curve=" + curve
  1928. res = dev[0].request(cmd)
  1929. if "FAIL" in res:
  1930. raise Exception("Failed to generate bootstrapping info")
  1931. id0 = int(res)
  1932. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1933. if curve:
  1934. cmd += " curve=" + curve
  1935. res = dev[1].request(cmd)
  1936. if "FAIL" in res:
  1937. raise Exception("Failed to generate bootstrapping info")
  1938. id1 = int(res)
  1939. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  1940. res = dev[0].request(cmd)
  1941. if "FAIL" in res:
  1942. raise Exception("Failed to set PKEX data (responder)")
  1943. cmd = "DPP_LISTEN 2437 role=configurator"
  1944. if "OK" not in dev[0].request(cmd):
  1945. raise Exception("Failed to start listen operation")
  1946. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee %s code=secret" % (id1, init_extra)
  1947. res = dev[1].request(cmd)
  1948. if "FAIL" in res:
  1949. raise Exception("Failed to set PKEX data (initiator)")
  1950. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1951. if ev is None:
  1952. raise Exception("DPP authentication did not succeed (Initiator)")
  1953. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  1954. if ev is None:
  1955. raise Exception("DPP authentication did not succeed (Responder)")
  1956. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  1957. if ev is None:
  1958. raise Exception("DPP configuration not completed (Configurator)")
  1959. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  1960. if ev is None:
  1961. raise Exception("DPP configuration not completed (Enrollee)")
  1962. def test_dpp_pkex_no_responder(dev, apdev):
  1963. """DPP and PKEX with no responder (retry behavior)"""
  1964. check_dpp_capab(dev[0])
  1965. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1966. res = dev[0].request(cmd)
  1967. if "FAIL" in res:
  1968. raise Exception("Failed to generate bootstrapping info")
  1969. id0 = int(res)
  1970. cmd = "DPP_PKEX_ADD own=%d init=1 identifier=test code=secret" % (id0)
  1971. res = dev[0].request(cmd)
  1972. if "FAIL" in res:
  1973. raise Exception("Failed to set PKEX data (initiator)")
  1974. ev = dev[0].wait_event(["DPP-FAIL"], timeout=15)
  1975. if ev is None:
  1976. raise Exception("DPP PKEX failure not reported")
  1977. if "No response from PKEX peer" not in ev:
  1978. raise Exception("Unexpected failure reason: " + ev)
  1979. def test_dpp_pkex_after_retry(dev, apdev):
  1980. """DPP and PKEX completing after retry"""
  1981. check_dpp_capab(dev[0])
  1982. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1983. res = dev[0].request(cmd)
  1984. if "FAIL" in res:
  1985. raise Exception("Failed to generate bootstrapping info")
  1986. id0 = int(res)
  1987. cmd = "DPP_PKEX_ADD own=%d init=1 identifier=test code=secret" % (id0)
  1988. res = dev[0].request(cmd)
  1989. if "FAIL" in res:
  1990. raise Exception("Failed to set PKEX data (initiator)")
  1991. time.sleep(0.1)
  1992. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1993. res = dev[1].request(cmd)
  1994. if "FAIL" in res:
  1995. raise Exception("Failed to generate bootstrapping info")
  1996. id1 = int(res)
  1997. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
  1998. res = dev[1].request(cmd)
  1999. if "FAIL" in res:
  2000. raise Exception("Failed to set PKEX data (responder)")
  2001. cmd = "DPP_LISTEN 2437"
  2002. if "OK" not in dev[1].request(cmd):
  2003. raise Exception("Failed to start listen operation")
  2004. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=10)
  2005. if ev is None:
  2006. raise Exception("DPP authentication did not succeed (Responder)")
  2007. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2008. if ev is None:
  2009. raise Exception("DPP authentication did not succeed (Initiator)")
  2010. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  2011. if ev is None:
  2012. raise Exception("DPP configuration not completed (Configurator)")
  2013. # Ignore Enrollee result since configurator was not set here
  2014. def test_dpp_pkex_hostapd_responder(dev, apdev):
  2015. """DPP PKEX with hostapd as responder"""
  2016. check_dpp_capab(dev[0])
  2017. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  2018. "channel": "6" })
  2019. check_dpp_capab(hapd)
  2020. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2021. res = hapd.request(cmd)
  2022. if "FAIL" in res:
  2023. raise Exception("Failed to generate bootstrapping info (hostapd)")
  2024. id_h = int(res)
  2025. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id_h)
  2026. res = hapd.request(cmd)
  2027. if "FAIL" in res:
  2028. raise Exception("Failed to set PKEX data (responder/hostapd)")
  2029. cmd = "DPP_CONFIGURATOR_ADD"
  2030. res = dev[0].request(cmd);
  2031. if "FAIL" in res:
  2032. raise Exception("Failed to add configurator")
  2033. conf_id = int(res)
  2034. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2035. res = dev[0].request(cmd)
  2036. if "FAIL" in res:
  2037. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  2038. id0 = int(res)
  2039. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=ap-dpp configurator=%d code=secret" % (id0, conf_id)
  2040. res = dev[0].request(cmd)
  2041. if "FAIL" in res:
  2042. raise Exception("Failed to set PKEX data (initiator/wpa_supplicant)")
  2043. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2044. if ev is None:
  2045. raise Exception("DPP authentication did not succeed (Initiator)")
  2046. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2047. if ev is None:
  2048. raise Exception("DPP authentication did not succeed (Responder)")
  2049. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  2050. if ev is None:
  2051. raise Exception("DPP configuration not completed (Configurator)")
  2052. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2053. if ev is None:
  2054. raise Exception("DPP configuration not completed (Enrollee)")
  2055. dev[0].request("DPP_STOP_LISTEN")
  2056. dev[0].dump_monitor()
  2057. def test_dpp_pkex_hostapd_initiator(dev, apdev):
  2058. """DPP PKEX with hostapd as initiator"""
  2059. check_dpp_capab(dev[0])
  2060. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  2061. "channel": "6" })
  2062. check_dpp_capab(hapd)
  2063. cmd = "DPP_CONFIGURATOR_ADD"
  2064. res = dev[0].request(cmd);
  2065. if "FAIL" in res:
  2066. raise Exception("Failed to add configurator")
  2067. conf_id = int(res)
  2068. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2069. res = dev[0].request(cmd)
  2070. if "FAIL" in res:
  2071. raise Exception("Failed to generate bootstrapping info (wpa_supplicant)")
  2072. id0 = int(res)
  2073. dev[0].set("dpp_configurator_params",
  2074. " conf=ap-dpp configurator=%d" % conf_id);
  2075. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  2076. res = dev[0].request(cmd)
  2077. if "FAIL" in res:
  2078. raise Exception("Failed to set PKEX data (responder/wpa_supplicant)")
  2079. cmd = "DPP_LISTEN 2437 role=configurator"
  2080. if "OK" not in dev[0].request(cmd):
  2081. raise Exception("Failed to start listen operation")
  2082. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2083. res = hapd.request(cmd)
  2084. if "FAIL" in res:
  2085. raise Exception("Failed to generate bootstrapping info (hostapd)")
  2086. id_h = int(res)
  2087. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 role=enrollee code=secret" % (id_h)
  2088. res = hapd.request(cmd)
  2089. if "FAIL" in res:
  2090. raise Exception("Failed to set PKEX data (initiator/hostapd)")
  2091. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2092. if ev is None:
  2093. raise Exception("DPP authentication did not succeed (Initiator)")
  2094. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2095. if ev is None:
  2096. raise Exception("DPP authentication did not succeed (Responder)")
  2097. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  2098. if ev is None:
  2099. raise Exception("DPP configuration not completed (Configurator)")
  2100. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2101. if ev is None:
  2102. raise Exception("DPP configuration not completed (Enrollee)")
  2103. dev[0].request("DPP_STOP_LISTEN")
  2104. dev[0].dump_monitor()
  2105. def test_dpp_hostapd_configurator(dev, apdev):
  2106. """DPP with hostapd as configurator/initiator"""
  2107. check_dpp_capab(dev[0])
  2108. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  2109. "channel": "1" })
  2110. check_dpp_capab(hapd)
  2111. cmd = "DPP_CONFIGURATOR_ADD"
  2112. res = hapd.request(cmd);
  2113. if "FAIL" in res:
  2114. raise Exception("Failed to add configurator")
  2115. conf_id = int(res)
  2116. addr = dev[0].own_addr().replace(':', '')
  2117. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2118. res = dev[0].request(cmd)
  2119. if "FAIL" in res:
  2120. raise Exception("Failed to generate bootstrapping info")
  2121. id0 = int(res)
  2122. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2123. res = hapd.request("DPP_QR_CODE " + uri0)
  2124. if "FAIL" in res:
  2125. raise Exception("Failed to parse QR Code URI")
  2126. id1 = int(res)
  2127. res = hapd.request("DPP_BOOTSTRAP_INFO %d" % id0)
  2128. if "FAIL" in res:
  2129. raise Exception("DPP_BOOTSTRAP_INFO failed")
  2130. if "type=QRCODE" not in res:
  2131. raise Exception("DPP_BOOTSTRAP_INFO did not report correct type")
  2132. if "mac_addr=" + dev[0].own_addr() not in res:
  2133. raise Exception("DPP_BOOTSTRAP_INFO did not report correct mac_addr")
  2134. cmd = "DPP_LISTEN 2412"
  2135. if "OK" not in dev[0].request(cmd):
  2136. raise Exception("Failed to start listen operation")
  2137. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  2138. if "OK" not in hapd.request(cmd):
  2139. raise Exception("Failed to initiate DPP Authentication")
  2140. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2141. if ev is None:
  2142. raise Exception("DPP authentication did not succeed (Responder)")
  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"], timeout=5)
  2150. if ev is None:
  2151. raise Exception("DPP configuration not completed (Enrollee)")
  2152. dev[0].request("DPP_STOP_LISTEN")
  2153. dev[0].dump_monitor()
  2154. def test_dpp_hostapd_configurator_responder(dev, apdev):
  2155. """DPP with hostapd as configurator/responder"""
  2156. check_dpp_capab(dev[0])
  2157. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured",
  2158. "channel": "1" })
  2159. check_dpp_capab(hapd)
  2160. cmd = "DPP_CONFIGURATOR_ADD"
  2161. res = hapd.request(cmd);
  2162. if "FAIL" in res:
  2163. raise Exception("Failed to add configurator")
  2164. conf_id = int(res)
  2165. hapd.set("dpp_configurator_params",
  2166. " conf=sta-dpp configurator=%d" % conf_id);
  2167. addr = hapd.own_addr().replace(':', '')
  2168. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2169. res = hapd.request(cmd)
  2170. if "FAIL" in res:
  2171. raise Exception("Failed to generate bootstrapping info")
  2172. id0 = int(res)
  2173. uri0 = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2174. res = dev[0].request("DPP_QR_CODE " + uri0)
  2175. if "FAIL" in res:
  2176. raise Exception("Failed to parse QR Code URI")
  2177. id1 = int(res)
  2178. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  2179. if "OK" not in dev[0].request(cmd):
  2180. raise Exception("Failed to initiate DPP Authentication")
  2181. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2182. if ev is None:
  2183. raise Exception("DPP authentication did not succeed (Responder)")
  2184. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2185. if ev is None:
  2186. raise Exception("DPP authentication did not succeed (Initiator)")
  2187. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  2188. if ev is None:
  2189. raise Exception("DPP configuration not completed (Configurator)")
  2190. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2191. if ev is None:
  2192. raise Exception("DPP configuration not completed (Enrollee)")
  2193. dev[0].request("DPP_STOP_LISTEN")
  2194. dev[0].dump_monitor()
  2195. def test_dpp_own_config(dev, apdev):
  2196. """DPP configurator signing own connector"""
  2197. try:
  2198. run_dpp_own_config(dev, apdev)
  2199. finally:
  2200. dev[0].set("dpp_config_processing", "0")
  2201. def test_dpp_own_config_curve_mismatch(dev, apdev):
  2202. """DPP configurator signing own connector using mismatching curve"""
  2203. try:
  2204. run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
  2205. finally:
  2206. dev[0].set("dpp_config_processing", "0")
  2207. def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False):
  2208. check_dpp_capab(dev[0], own_curve and "BP" in own_curve)
  2209. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  2210. check_dpp_capab(hapd)
  2211. addr = hapd.own_addr().replace(':', '')
  2212. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2213. res = hapd.request(cmd)
  2214. if "FAIL" in res:
  2215. raise Exception("Failed to generate bootstrapping info")
  2216. id_h = int(res)
  2217. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  2218. cmd = "DPP_CONFIGURATOR_ADD"
  2219. res = dev[0].request(cmd);
  2220. if "FAIL" in res:
  2221. raise Exception("Failed to add configurator")
  2222. conf_id = int(res)
  2223. res = dev[0].request("DPP_QR_CODE " + uri)
  2224. if "FAIL" in res:
  2225. raise Exception("Failed to parse QR Code URI")
  2226. id = int(res)
  2227. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  2228. if "OK" not in dev[0].request(cmd):
  2229. raise Exception("Failed to initiate DPP Authentication")
  2230. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2231. if ev is None:
  2232. raise Exception("DPP authentication did not succeed (Responder)")
  2233. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2234. if ev is None:
  2235. raise Exception("DPP authentication did not succeed (Initiator)")
  2236. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  2237. if ev is None:
  2238. raise Exception("DPP configuration not completed (Configurator)")
  2239. ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2240. if ev is None:
  2241. raise Exception("DPP configuration not completed (Enrollee)")
  2242. update_hapd_config(hapd)
  2243. dev[0].set("dpp_config_processing", "1")
  2244. cmd = "DPP_CONFIGURATOR_SIGN conf=sta-dpp configurator=%d" % (conf_id)
  2245. if own_curve:
  2246. cmd += " curve=" + own_curve
  2247. res = dev[0].request(cmd)
  2248. if "FAIL" in res:
  2249. raise Exception("Failed to generate own configuration")
  2250. ev = dev[0].wait_event(["DPP-NETWORK-ID"], timeout=1)
  2251. if ev is None:
  2252. raise Exception("DPP network profile not generated")
  2253. id = ev.split(' ')[1]
  2254. dev[0].select_network(id, freq="2412")
  2255. if expect_failure:
  2256. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  2257. if ev is not None:
  2258. raise Exception("Unexpected connection");
  2259. dev[0].request("DISCONNECT")
  2260. else:
  2261. dev[0].wait_connected()
  2262. def test_dpp_own_config_ap(dev, apdev):
  2263. """DPP configurator (AP) signing own connector"""
  2264. try:
  2265. run_dpp_own_config_ap(dev, apdev)
  2266. finally:
  2267. dev[0].set("dpp_config_processing", "0")
  2268. def run_dpp_own_config_ap(dev, apdev):
  2269. check_dpp_capab(dev[0])
  2270. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  2271. check_dpp_capab(hapd)
  2272. cmd = "DPP_CONFIGURATOR_ADD"
  2273. res = hapd.request(cmd);
  2274. if "FAIL" in res:
  2275. raise Exception("Failed to add configurator")
  2276. conf_id = int(res)
  2277. cmd = "DPP_CONFIGURATOR_SIGN conf=ap-dpp configurator=%d" % (conf_id)
  2278. res = hapd.request(cmd)
  2279. if "FAIL" in res:
  2280. raise Exception("Failed to generate own configuration")
  2281. update_hapd_config(hapd)
  2282. addr = dev[0].own_addr().replace(':', '')
  2283. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2284. res = dev[0].request(cmd)
  2285. if "FAIL" in res:
  2286. raise Exception("Failed to generate bootstrapping info")
  2287. id = int(res)
  2288. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
  2289. res = hapd.request("DPP_QR_CODE " + uri)
  2290. if "FAIL" in res:
  2291. raise Exception("Failed to parse QR Code URI")
  2292. id = int(res)
  2293. dev[0].set("dpp_config_processing", "2")
  2294. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  2295. raise Exception("Failed to start listen operation")
  2296. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id, conf_id)
  2297. if "OK" not in hapd.request(cmd):
  2298. raise Exception("Failed to initiate DPP Authentication")
  2299. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  2300. if ev is None:
  2301. raise Exception("DPP authentication did not succeed (Initiator)")
  2302. ev = hapd.wait_event(["DPP-CONF-SENT"], timeout=5)
  2303. if ev is None:
  2304. raise Exception("DPP configuration not completed (Configurator)")
  2305. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  2306. if ev is None:
  2307. raise Exception("DPP configuration not completed (Enrollee)")
  2308. if "DPP-CONF-RECEIVED" not in ev:
  2309. raise Exception("DPP configuration failed (Enrollee)")
  2310. dev[0].wait_connected()
  2311. def test_dpp_intro_mismatch(dev, apdev):
  2312. """DPP network introduction mismatch cases"""
  2313. try:
  2314. wpas = None
  2315. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2316. wpas.interface_add("wlan5")
  2317. check_dpp_capab(wpas)
  2318. run_dpp_intro_mismatch(dev, apdev, wpas)
  2319. finally:
  2320. dev[0].set("dpp_config_processing", "0")
  2321. dev[2].set("dpp_config_processing", "0")
  2322. if wpas:
  2323. wpas.set("dpp_config_processing", "0")
  2324. def run_dpp_intro_mismatch(dev, apdev, wpas):
  2325. check_dpp_capab(dev[0])
  2326. check_dpp_capab(dev[1])
  2327. check_dpp_capab(dev[2])
  2328. logger.info("Start AP in unconfigured state")
  2329. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  2330. check_dpp_capab(hapd)
  2331. addr = hapd.own_addr().replace(':', '')
  2332. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2333. res = hapd.request(cmd)
  2334. if "FAIL" in res:
  2335. raise Exception("Failed to generate bootstrapping info")
  2336. id_h = int(res)
  2337. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  2338. logger.info("Provision AP with DPP configuration")
  2339. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  2340. if "FAIL" in res:
  2341. raise Exception("Failed to add configurator")
  2342. conf_id = int(res)
  2343. res = dev[1].request("DPP_QR_CODE " + uri)
  2344. if "FAIL" in res:
  2345. raise Exception("Failed to parse QR Code URI")
  2346. id = int(res)
  2347. dev[1].set("dpp_groups_override", '[{"groupId":"a","netRole":"ap"}]')
  2348. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  2349. if "OK" not in dev[1].request(cmd):
  2350. raise Exception("Failed to initiate DPP Authentication")
  2351. update_hapd_config(hapd)
  2352. logger.info("Provision STA0 with DPP Connector that has mismatching groupId")
  2353. dev[0].set("dpp_config_processing", "2")
  2354. addr = dev[0].own_addr().replace(':', '')
  2355. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2356. res = dev[0].request(cmd)
  2357. if "FAIL" in res:
  2358. raise Exception("Failed to generate bootstrapping info")
  2359. id0 = int(res)
  2360. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2361. res = dev[1].request("DPP_QR_CODE " + uri0)
  2362. if "FAIL" in res:
  2363. raise Exception("Failed to parse QR Code URI")
  2364. id1 = int(res)
  2365. cmd = "DPP_LISTEN 2412"
  2366. if "OK" not in dev[0].request(cmd):
  2367. raise Exception("Failed to start listen operation")
  2368. dev[1].set("dpp_groups_override", '[{"groupId":"b","netRole":"sta"}]')
  2369. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  2370. if "OK" not in dev[1].request(cmd):
  2371. raise Exception("Failed to initiate DPP Authentication")
  2372. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  2373. if ev is None:
  2374. raise Exception("DPP configuration not completed (Configurator for STA0)")
  2375. ev = dev[0].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2376. if ev is None:
  2377. raise Exception("DPP configuration not completed (Enrollee STA0)")
  2378. logger.info("Provision STA2 with DPP Connector that has mismatching C-sign-key")
  2379. dev[2].set("dpp_config_processing", "2")
  2380. addr = dev[2].own_addr().replace(':', '')
  2381. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2382. res = dev[2].request(cmd)
  2383. if "FAIL" in res:
  2384. raise Exception("Failed to generate bootstrapping info")
  2385. id2 = int(res)
  2386. uri2 = dev[2].request("DPP_BOOTSTRAP_GET_URI %d" % id2)
  2387. res = dev[1].request("DPP_QR_CODE " + uri2)
  2388. if "FAIL" in res:
  2389. raise Exception("Failed to parse QR Code URI")
  2390. id1 = int(res)
  2391. cmd = "DPP_LISTEN 2412"
  2392. if "OK" not in dev[2].request(cmd):
  2393. raise Exception("Failed to start listen operation")
  2394. res = dev[1].request("DPP_CONFIGURATOR_ADD");
  2395. if "FAIL" in res:
  2396. raise Exception("Failed to add configurator")
  2397. conf_id_2 = int(res)
  2398. dev[1].set("dpp_groups_override", '')
  2399. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id_2)
  2400. if "OK" not in dev[1].request(cmd):
  2401. raise Exception("Failed to initiate DPP Authentication")
  2402. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  2403. if ev is None:
  2404. raise Exception("DPP configuration not completed (Configurator for STA2)")
  2405. ev = dev[2].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2406. if ev is None:
  2407. raise Exception("DPP configuration not completed (Enrollee STA2)")
  2408. logger.info("Provision STA5 with DPP Connector that has mismatching netAccessKey EC group")
  2409. wpas.set("dpp_config_processing", "2")
  2410. addr = wpas.own_addr().replace(':', '')
  2411. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  2412. cmd += " curve=P-521"
  2413. res = wpas.request(cmd)
  2414. if "FAIL" in res:
  2415. raise Exception("Failed to generate bootstrapping info")
  2416. id5 = int(res)
  2417. uri5 = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % id5)
  2418. res = dev[1].request("DPP_QR_CODE " + uri5)
  2419. if "FAIL" in res:
  2420. raise Exception("Failed to parse QR Code URI")
  2421. id1 = int(res)
  2422. cmd = "DPP_LISTEN 2412"
  2423. if "OK" not in wpas.request(cmd):
  2424. raise Exception("Failed to start listen operation")
  2425. dev[1].set("dpp_groups_override", '')
  2426. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  2427. if "OK" not in dev[1].request(cmd):
  2428. raise Exception("Failed to initiate DPP Authentication")
  2429. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  2430. if ev is None:
  2431. raise Exception("DPP configuration not completed (Configurator for STA0)")
  2432. ev = wpas.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  2433. if ev is None:
  2434. raise Exception("DPP configuration not completed (Enrollee STA5)")
  2435. logger.info("Verify network introduction results")
  2436. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  2437. if ev is None:
  2438. raise Exception("DPP network introduction result not seen on STA0")
  2439. if "status=8" not in ev:
  2440. raise Exception("Unexpected network introduction result on STA0: " + ev)
  2441. ev = dev[2].wait_event(["DPP-INTRO"], timeout=5)
  2442. if ev is None:
  2443. raise Exception("DPP network introduction result not seen on STA2")
  2444. if "status=8" not in ev:
  2445. raise Exception("Unexpected network introduction result on STA2: " + ev)
  2446. ev = wpas.wait_event(["DPP-INTRO"], timeout=10)
  2447. if ev is None:
  2448. raise Exception("DPP network introduction result not seen on STA5")
  2449. if "status=7" not in ev:
  2450. raise Exception("Unexpected network introduction result on STA5: " + ev)
  2451. def run_dpp_proto_init(dev, test_dev, test, mutual=False, unicast=True,
  2452. listen=True, chan="81/1", init_enrollee=False):
  2453. check_dpp_capab(dev[0])
  2454. check_dpp_capab(dev[1])
  2455. dev[test_dev].set("dpp_test", str(test))
  2456. cmd = "DPP_CONFIGURATOR_ADD"
  2457. if init_enrollee:
  2458. res = dev[0].request(cmd)
  2459. else:
  2460. res = dev[1].request(cmd)
  2461. if "FAIL" in res:
  2462. raise Exception("Failed to add configurator")
  2463. conf_id = int(res)
  2464. addr = dev[0].own_addr().replace(':', '')
  2465. cmd = "DPP_BOOTSTRAP_GEN type=qrcode"
  2466. if chan:
  2467. cmd += " chan=" + chan
  2468. if unicast:
  2469. cmd += " mac=" + addr
  2470. res = dev[0].request(cmd)
  2471. if "FAIL" in res:
  2472. raise Exception("Failed to generate bootstrapping info")
  2473. id0 = int(res)
  2474. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  2475. res = dev[1].request("DPP_QR_CODE " + uri0)
  2476. if "FAIL" in res:
  2477. raise Exception("Failed to parse QR Code URI")
  2478. id1 = int(res)
  2479. if mutual:
  2480. addr = dev[1].own_addr().replace(':', '')
  2481. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  2482. if "FAIL" in res:
  2483. raise Exception("Failed to generate bootstrapping info")
  2484. id1b = int(res)
  2485. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  2486. res = dev[0].request("DPP_QR_CODE " + uri1b)
  2487. if "FAIL" in res:
  2488. raise Exception("Failed to parse QR Code URI")
  2489. id0b = int(res)
  2490. cmd = "DPP_LISTEN 2412 qr=mutual"
  2491. else:
  2492. cmd = "DPP_LISTEN 2412"
  2493. if init_enrollee:
  2494. cmd += " role=configurator"
  2495. dev[0].set("dpp_configurator_params",
  2496. " conf=sta-dpp configurator=%d" % conf_id);
  2497. if listen:
  2498. if "OK" not in dev[0].request(cmd):
  2499. raise Exception("Failed to start listen operation")
  2500. if init_enrollee:
  2501. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % (id1)
  2502. else:
  2503. cmd = "DPP_AUTH_INIT peer=%d configurator=%d conf=sta-dpp" % (id1, conf_id)
  2504. if mutual:
  2505. cmd += " own=%d" % id1b
  2506. if "OK" not in dev[1].request(cmd):
  2507. raise Exception("Failed to initiate DPP Authentication")
  2508. def test_dpp_proto_after_wrapped_data_auth_req(dev, apdev):
  2509. """DPP protocol testing - attribute after Wrapped Data in Auth Req"""
  2510. run_dpp_proto_init(dev, 1, 1)
  2511. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2512. if ev is None:
  2513. raise Exception("DPP Authentication Request not seen")
  2514. if "type=0" not in ev or "ignore=invalid-attributes" not in ev:
  2515. raise Exception("Unexpected RX info: " + ev)
  2516. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  2517. if ev is not None:
  2518. raise Exception("Unexpected DPP message seen")
  2519. def test_dpp_auth_req_stop_after_ack(dev, apdev):
  2520. """DPP initiator stopping after ACK, but no response"""
  2521. run_dpp_proto_init(dev, 1, 1, listen=True)
  2522. ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
  2523. if ev is None:
  2524. raise Exception("Authentication failure not reported")
  2525. def test_dpp_auth_req_retries(dev, apdev):
  2526. """DPP initiator retries with no ACK"""
  2527. check_dpp_capab(dev[1])
  2528. dev[1].set("dpp_init_max_tries", "3")
  2529. dev[1].set("dpp_init_retry_time", "1000")
  2530. dev[1].set("dpp_resp_wait_time", "100")
  2531. run_dpp_proto_init(dev, 1, 1, unicast=False, listen=False)
  2532. for i in range(3):
  2533. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  2534. if ev is None:
  2535. raise Exception("Auth Req not sent (%d)" % i)
  2536. ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
  2537. if ev is None:
  2538. raise Exception("Authentication failure not reported")
  2539. def test_dpp_auth_req_retries_multi_chan(dev, apdev):
  2540. """DPP initiator retries with no ACK and multiple channels"""
  2541. check_dpp_capab(dev[1])
  2542. dev[1].set("dpp_init_max_tries", "3")
  2543. dev[1].set("dpp_init_retry_time", "1000")
  2544. dev[1].set("dpp_resp_wait_time", "100")
  2545. run_dpp_proto_init(dev, 1, 1, unicast=False, listen=False,
  2546. chan="81/1,81/6,81/11")
  2547. for i in range(3 * 3):
  2548. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  2549. if ev is None:
  2550. raise Exception("Auth Req not sent (%d)" % i)
  2551. ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
  2552. if ev is None:
  2553. raise Exception("Authentication failure not reported")
  2554. def test_dpp_proto_after_wrapped_data_auth_resp(dev, apdev):
  2555. """DPP protocol testing - attribute after Wrapped Data in Auth Resp"""
  2556. run_dpp_proto_init(dev, 0, 2)
  2557. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2558. if ev is None:
  2559. raise Exception("DPP Authentication Response not seen")
  2560. if "type=1" not in ev or "ignore=invalid-attributes" not in ev:
  2561. raise Exception("Unexpected RX info: " + ev)
  2562. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2563. if ev is None or "type=0" not in ev:
  2564. raise Exception("DPP Authentication Request not seen")
  2565. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2566. if ev is not None:
  2567. raise Exception("Unexpected DPP message seen")
  2568. def test_dpp_proto_after_wrapped_data_auth_conf(dev, apdev):
  2569. """DPP protocol testing - attribute after Wrapped Data in Auth Conf"""
  2570. run_dpp_proto_init(dev, 1, 3)
  2571. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2572. if ev is None or "type=0" not in ev:
  2573. raise Exception("DPP Authentication Request not seen")
  2574. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2575. if ev is None:
  2576. raise Exception("DPP Authentication Confirm not seen")
  2577. if "type=2" not in ev or "ignore=invalid-attributes" not in ev:
  2578. raise Exception("Unexpected RX info: " + ev)
  2579. def test_dpp_proto_after_wrapped_data_conf_req(dev, apdev):
  2580. """DPP protocol testing - attribute after Wrapped Data in Conf Req"""
  2581. run_dpp_proto_init(dev, 0, 6)
  2582. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=10)
  2583. if ev is None:
  2584. raise Exception("DPP Configuration failure not seen")
  2585. def test_dpp_proto_after_wrapped_data_conf_resp(dev, apdev):
  2586. """DPP protocol testing - attribute after Wrapped Data in Conf Resp"""
  2587. run_dpp_proto_init(dev, 1, 7)
  2588. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=10)
  2589. if ev is None:
  2590. raise Exception("DPP Configuration failure not seen")
  2591. def test_dpp_proto_zero_i_capab(dev, apdev):
  2592. """DPP protocol testing - zero I-capability in Auth Req"""
  2593. run_dpp_proto_init(dev, 1, 8)
  2594. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2595. if ev is None:
  2596. raise Exception("DPP failure not seen")
  2597. if "Invalid role in I-capabilities 0x00" not in ev:
  2598. raise Exception("Unexpected failure: " + ev)
  2599. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  2600. if ev is not None:
  2601. raise Exception("Unexpected DPP message seen")
  2602. def test_dpp_proto_zero_r_capab(dev, apdev):
  2603. """DPP protocol testing - zero R-capability in Auth Resp"""
  2604. run_dpp_proto_init(dev, 0, 9)
  2605. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2606. if ev is None:
  2607. raise Exception("DPP failure not seen")
  2608. if "Unexpected role in R-capabilities 0x00" not in ev:
  2609. raise Exception("Unexpected failure: " + ev)
  2610. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2611. if ev is None or "type=0" not in ev:
  2612. raise Exception("DPP Authentication Request not seen")
  2613. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2614. if ev is not None:
  2615. raise Exception("Unexpected DPP message seen")
  2616. def run_dpp_proto_auth_req_missing(dev, test, reason, mutual=False):
  2617. run_dpp_proto_init(dev, 1, test, mutual=mutual)
  2618. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2619. if ev is None:
  2620. raise Exception("DPP failure not seen")
  2621. if reason not in ev:
  2622. raise Exception("Unexpected failure: " + ev)
  2623. ev = dev[1].wait_event(["DPP-RX"], timeout=0.1)
  2624. if ev is not None:
  2625. raise Exception("Unexpected DPP message seen")
  2626. def test_dpp_proto_auth_req_no_r_bootstrap_key(dev, apdev):
  2627. """DPP protocol testing - no R-bootstrap key in Auth Req"""
  2628. run_dpp_proto_auth_req_missing(dev, 10, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2629. def test_dpp_proto_auth_req_invalid_r_bootstrap_key(dev, apdev):
  2630. """DPP protocol testing - invalid R-bootstrap key in Auth Req"""
  2631. run_dpp_proto_auth_req_missing(dev, 68, "No matching own bootstrapping key found - ignore message")
  2632. def test_dpp_proto_auth_req_no_i_bootstrap_key(dev, apdev):
  2633. """DPP protocol testing - no I-bootstrap key in Auth Req"""
  2634. run_dpp_proto_auth_req_missing(dev, 11, "Missing or invalid required Initiator Bootstrapping Key Hash attribute")
  2635. def test_dpp_proto_auth_req_invalid_i_bootstrap_key(dev, apdev):
  2636. """DPP protocol testing - invalid I-bootstrap key in Auth Req"""
  2637. run_dpp_proto_init(dev, 1, 69, mutual=True)
  2638. ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  2639. if ev is None:
  2640. raise Exception("DPP scan request not seen")
  2641. ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  2642. if ev is None:
  2643. raise Exception("DPP response pending indivation not seen")
  2644. def test_dpp_proto_auth_req_no_i_proto_key(dev, apdev):
  2645. """DPP protocol testing - no I-proto key in Auth Req"""
  2646. run_dpp_proto_auth_req_missing(dev, 12, "Missing required Initiator Protocol Key attribute")
  2647. def test_dpp_proto_auth_req_invalid_i_proto_key(dev, apdev):
  2648. """DPP protocol testing - invalid I-proto key in Auth Req"""
  2649. run_dpp_proto_auth_req_missing(dev, 66, "Invalid Initiator Protocol Key")
  2650. def test_dpp_proto_auth_req_no_i_nonce(dev, apdev):
  2651. """DPP protocol testing - no I-nonce in Auth Req"""
  2652. run_dpp_proto_auth_req_missing(dev, 13, "Missing or invalid I-nonce")
  2653. def test_dpp_proto_auth_req_invalid_i_nonce(dev, apdev):
  2654. """DPP protocol testing - invalid I-nonce in Auth Req"""
  2655. run_dpp_proto_auth_req_missing(dev, 81, "Missing or invalid I-nonce")
  2656. def test_dpp_proto_auth_req_no_i_capab(dev, apdev):
  2657. """DPP protocol testing - no I-capab in Auth Req"""
  2658. run_dpp_proto_auth_req_missing(dev, 14, "Missing or invalid I-capab")
  2659. def test_dpp_proto_auth_req_no_wrapped_data(dev, apdev):
  2660. """DPP protocol testing - no Wrapped Data in Auth Req"""
  2661. run_dpp_proto_auth_req_missing(dev, 15, "Missing or invalid required Wrapped Data attribute")
  2662. def run_dpp_proto_auth_resp_missing(dev, test, reason):
  2663. run_dpp_proto_init(dev, 0, test, mutual=True)
  2664. if reason is None:
  2665. time.sleep(0.1)
  2666. return
  2667. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2668. if ev is None:
  2669. raise Exception("DPP failure not seen")
  2670. if reason not in ev:
  2671. raise Exception("Unexpected failure: " + ev)
  2672. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2673. if ev is None or "type=0" not in ev:
  2674. raise Exception("DPP Authentication Request not seen")
  2675. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2676. if ev is not None:
  2677. raise Exception("Unexpected DPP message seen")
  2678. def test_dpp_proto_auth_resp_no_status(dev, apdev):
  2679. """DPP protocol testing - no Status in Auth Resp"""
  2680. run_dpp_proto_auth_resp_missing(dev, 16, "Missing or invalid required DPP Status attribute")
  2681. def test_dpp_proto_auth_resp_invalid_status(dev, apdev):
  2682. """DPP protocol testing - invalid Status in Auth Resp"""
  2683. run_dpp_proto_auth_resp_missing(dev, 74, "Responder reported failure")
  2684. def test_dpp_proto_auth_resp_no_r_bootstrap_key(dev, apdev):
  2685. """DPP protocol testing - no R-bootstrap key in Auth Resp"""
  2686. run_dpp_proto_auth_resp_missing(dev, 17, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2687. def test_dpp_proto_auth_resp_invalid_r_bootstrap_key(dev, apdev):
  2688. """DPP protocol testing - invalid R-bootstrap key in Auth Resp"""
  2689. run_dpp_proto_auth_resp_missing(dev, 70, "Unexpected Responder Bootstrapping Key Hash value")
  2690. def test_dpp_proto_auth_resp_no_i_bootstrap_key(dev, apdev):
  2691. """DPP protocol testing - no I-bootstrap key in Auth Resp"""
  2692. run_dpp_proto_auth_resp_missing(dev, 18, None)
  2693. def test_dpp_proto_auth_resp_invalid_i_bootstrap_key(dev, apdev):
  2694. """DPP protocol testing - invalid I-bootstrap key in Auth Resp"""
  2695. run_dpp_proto_auth_resp_missing(dev, 71, "Initiator Bootstrapping Key Hash attribute did not match")
  2696. def test_dpp_proto_auth_resp_no_r_proto_key(dev, apdev):
  2697. """DPP protocol testing - no R-Proto Key in Auth Resp"""
  2698. run_dpp_proto_auth_resp_missing(dev, 19, "Missing required Responder Protocol Key attribute")
  2699. def test_dpp_proto_auth_resp_invalid_r_proto_key(dev, apdev):
  2700. """DPP protocol testing - invalid R-Proto Key in Auth Resp"""
  2701. run_dpp_proto_auth_resp_missing(dev, 67, "Invalid Responder Protocol Key")
  2702. def test_dpp_proto_auth_resp_no_r_nonce(dev, apdev):
  2703. """DPP protocol testing - no R-nonce in Auth Resp"""
  2704. run_dpp_proto_auth_resp_missing(dev, 20, "Missing or invalid R-nonce")
  2705. def test_dpp_proto_auth_resp_no_i_nonce(dev, apdev):
  2706. """DPP protocol testing - no I-nonce in Auth Resp"""
  2707. run_dpp_proto_auth_resp_missing(dev, 21, "Missing or invalid I-nonce")
  2708. def test_dpp_proto_auth_resp_no_r_capab(dev, apdev):
  2709. """DPP protocol testing - no R-capab in Auth Resp"""
  2710. run_dpp_proto_auth_resp_missing(dev, 22, "Missing or invalid R-capabilities")
  2711. def test_dpp_proto_auth_resp_no_r_auth(dev, apdev):
  2712. """DPP protocol testing - no R-auth in Auth Resp"""
  2713. run_dpp_proto_auth_resp_missing(dev, 23, "Missing or invalid Secondary Wrapped Data")
  2714. def test_dpp_proto_auth_resp_no_wrapped_data(dev, apdev):
  2715. """DPP protocol testing - no Wrapped Data in Auth Resp"""
  2716. run_dpp_proto_auth_resp_missing(dev, 24, "Missing or invalid required Wrapped Data attribute")
  2717. def test_dpp_proto_auth_resp_i_nonce_mismatch(dev, apdev):
  2718. """DPP protocol testing - I-nonce mismatch in Auth Resp"""
  2719. run_dpp_proto_init(dev, 0, 30, mutual=True)
  2720. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2721. if ev is None:
  2722. raise Exception("DPP failure not seen")
  2723. if "I-nonce mismatch" not in ev:
  2724. raise Exception("Unexpected failure: " + ev)
  2725. ev = dev[0].wait_event(["DPP-RX"], timeout=1)
  2726. if ev is None or "type=0" not in ev:
  2727. raise Exception("DPP Authentication Request not seen")
  2728. ev = dev[0].wait_event(["DPP-RX"], timeout=0.1)
  2729. if ev is not None:
  2730. raise Exception("Unexpected DPP message seen")
  2731. def test_dpp_proto_auth_resp_incompatible_r_capab(dev, apdev):
  2732. """DPP protocol testing - Incompatible R-capab in Auth Resp"""
  2733. run_dpp_proto_init(dev, 0, 31, mutual=True)
  2734. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2735. if ev is None:
  2736. raise Exception("DPP failure not seen")
  2737. if "Unexpected role in R-capabilities 0x02" not in ev:
  2738. raise Exception("Unexpected failure: " + ev)
  2739. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2740. if ev is None:
  2741. raise Exception("DPP failure not seen")
  2742. if "Peer reported incompatible R-capab role" not in ev:
  2743. raise Exception("Unexpected failure: " + ev)
  2744. def test_dpp_proto_auth_resp_r_auth_mismatch(dev, apdev):
  2745. """DPP protocol testing - R-auth mismatch in Auth Resp"""
  2746. run_dpp_proto_init(dev, 0, 32, mutual=True)
  2747. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2748. if ev is None:
  2749. raise Exception("DPP failure not seen")
  2750. if "Mismatching Responder Authenticating Tag" not in ev:
  2751. raise Exception("Unexpected failure: " + ev)
  2752. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2753. if ev is None:
  2754. raise Exception("DPP failure not seen")
  2755. if "Peer reported authentication failure" not in ev:
  2756. raise Exception("Unexpected failure: " + ev)
  2757. def run_dpp_proto_auth_conf_missing(dev, test, reason):
  2758. run_dpp_proto_init(dev, 1, test, mutual=True)
  2759. if reason is None:
  2760. time.sleep(0.1)
  2761. return
  2762. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2763. if ev is None:
  2764. raise Exception("DPP failure not seen")
  2765. if reason not in ev:
  2766. raise Exception("Unexpected failure: " + ev)
  2767. def test_dpp_proto_auth_conf_no_status(dev, apdev):
  2768. """DPP protocol testing - no Status in Auth Conf"""
  2769. run_dpp_proto_auth_conf_missing(dev, 25, "Missing or invalid required DPP Status attribute")
  2770. def test_dpp_proto_auth_conf_invalid_status(dev, apdev):
  2771. """DPP protocol testing - invalid Status in Auth Conf"""
  2772. run_dpp_proto_auth_conf_missing(dev, 75, "Authentication failed")
  2773. def test_dpp_proto_auth_conf_no_r_bootstrap_key(dev, apdev):
  2774. """DPP protocol testing - no R-bootstrap key in Auth Conf"""
  2775. run_dpp_proto_auth_conf_missing(dev, 26, "Missing or invalid required Responder Bootstrapping Key Hash attribute")
  2776. def test_dpp_proto_auth_conf_invalid_r_bootstrap_key(dev, apdev):
  2777. """DPP protocol testing - invalid R-bootstrap key in Auth Conf"""
  2778. run_dpp_proto_auth_conf_missing(dev, 72, "Responder Bootstrapping Key Hash mismatch")
  2779. def test_dpp_proto_auth_conf_no_i_bootstrap_key(dev, apdev):
  2780. """DPP protocol testing - no I-bootstrap key in Auth Conf"""
  2781. run_dpp_proto_auth_conf_missing(dev, 27, "Missing Initiator Bootstrapping Key Hash attribute")
  2782. def test_dpp_proto_auth_conf_invalid_i_bootstrap_key(dev, apdev):
  2783. """DPP protocol testing - invalid I-bootstrap key in Auth Conf"""
  2784. run_dpp_proto_auth_conf_missing(dev, 73, "Initiator Bootstrapping Key Hash mismatch")
  2785. def test_dpp_proto_auth_conf_no_i_auth(dev, apdev):
  2786. """DPP protocol testing - no I-Auth in Auth Conf"""
  2787. run_dpp_proto_auth_conf_missing(dev, 28, "Missing or invalid Initiator Authenticating Tag")
  2788. def test_dpp_proto_auth_conf_no_wrapped_data(dev, apdev):
  2789. """DPP protocol testing - no Wrapped Data in Auth Conf"""
  2790. run_dpp_proto_auth_conf_missing(dev, 29, "Missing or invalid required Wrapped Data attribute")
  2791. def test_dpp_proto_auth_conf_i_auth_mismatch(dev, apdev):
  2792. """DPP protocol testing - I-auth mismatch in Auth Conf"""
  2793. run_dpp_proto_init(dev, 1, 33, mutual=True)
  2794. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2795. if ev is None:
  2796. raise Exception("DPP failure not seen")
  2797. if "Mismatching Initiator Authenticating Tag" not in ev:
  2798. raise Excception("Unexpected failure: " + ev)
  2799. def test_dpp_proto_auth_conf_replaced_by_resp(dev, apdev):
  2800. """DPP protocol testing - Auth Conf replaced by Resp"""
  2801. run_dpp_proto_init(dev, 1, 65, mutual=True)
  2802. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2803. if ev is None:
  2804. raise Exception("DPP failure not seen")
  2805. if "Unexpected Authentication Response" not in ev:
  2806. raise Excception("Unexpected failure: " + ev)
  2807. def run_dpp_proto_conf_req_missing(dev, test, reason):
  2808. run_dpp_proto_init(dev, 0, test)
  2809. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2810. if ev is None:
  2811. raise Exception("DPP failure not seen")
  2812. if reason not in ev:
  2813. raise Exception("Unexpected failure: " + ev)
  2814. def test_dpp_proto_conf_req_no_e_nonce(dev, apdev):
  2815. """DPP protocol testing - no E-nonce in Conf Req"""
  2816. run_dpp_proto_conf_req_missing(dev, 51,
  2817. "Missing or invalid Enrollee Nonce attribute")
  2818. def test_dpp_proto_conf_req_invalid_e_nonce(dev, apdev):
  2819. """DPP protocol testing - invalid E-nonce in Conf Req"""
  2820. run_dpp_proto_conf_req_missing(dev, 83,
  2821. "Missing or invalid Enrollee Nonce attribute")
  2822. def test_dpp_proto_conf_req_no_config_attr_obj(dev, apdev):
  2823. """DPP protocol testing - no Config Attr Obj in Conf Req"""
  2824. run_dpp_proto_conf_req_missing(dev, 52,
  2825. "Missing or invalid Config Attributes attribute")
  2826. def test_dpp_proto_conf_req_invalid_config_attr_obj(dev, apdev):
  2827. """DPP protocol testing - invalid Config Attr Obj in Conf Req"""
  2828. run_dpp_proto_conf_req_missing(dev, 76,
  2829. "Unsupported wi-fi_tech")
  2830. def test_dpp_proto_conf_req_no_wrapped_data(dev, apdev):
  2831. """DPP protocol testing - no Wrapped Data in Conf Req"""
  2832. run_dpp_proto_conf_req_missing(dev, 53,
  2833. "Missing or invalid required Wrapped Data attribute")
  2834. def run_dpp_proto_conf_resp_missing(dev, test, reason):
  2835. run_dpp_proto_init(dev, 1, test)
  2836. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2837. if ev is None:
  2838. raise Exception("DPP failure not seen")
  2839. if reason not in ev:
  2840. raise Exception("Unexpected failure: " + ev)
  2841. def test_dpp_proto_conf_resp_no_e_nonce(dev, apdev):
  2842. """DPP protocol testing - no E-nonce in Conf Resp"""
  2843. run_dpp_proto_conf_resp_missing(dev, 54,
  2844. "Missing or invalid Enrollee Nonce attribute")
  2845. def test_dpp_proto_conf_resp_no_config_obj(dev, apdev):
  2846. """DPP protocol testing - no Config Object in Conf Resp"""
  2847. run_dpp_proto_conf_resp_missing(dev, 55,
  2848. "Missing required Configuration Object attribute")
  2849. def test_dpp_proto_conf_resp_no_status(dev, apdev):
  2850. """DPP protocol testing - no Status in Conf Resp"""
  2851. run_dpp_proto_conf_resp_missing(dev, 56,
  2852. "Missing or invalid required DPP Status attribute")
  2853. def test_dpp_proto_conf_resp_no_wrapped_data(dev, apdev):
  2854. """DPP protocol testing - no Wrapped Data in Conf Resp"""
  2855. run_dpp_proto_conf_resp_missing(dev, 57,
  2856. "Missing or invalid required Wrapped Data attribute")
  2857. def test_dpp_proto_conf_resp_invalid_status(dev, apdev):
  2858. """DPP protocol testing - invalid Status in Conf Resp"""
  2859. run_dpp_proto_conf_resp_missing(dev, 58,
  2860. "Configurator rejected configuration")
  2861. def test_dpp_proto_conf_resp_e_nonce_mismatch(dev, apdev):
  2862. """DPP protocol testing - E-nonce mismatch in Conf Resp"""
  2863. run_dpp_proto_conf_resp_missing(dev, 59,
  2864. "Enrollee Nonce mismatch")
  2865. def test_dpp_proto_stop_at_auth_req(dev, apdev):
  2866. """DPP protocol testing - stop when receiving Auth Req"""
  2867. run_dpp_proto_init(dev, 0, 87)
  2868. ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
  2869. if ev is None:
  2870. raise Exception("Authentication init failure not reported")
  2871. def test_dpp_proto_stop_at_auth_resp(dev, apdev):
  2872. """DPP protocol testing - stop when receiving Auth Resp"""
  2873. run_dpp_proto_init(dev, 1, 88)
  2874. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  2875. if ev is None:
  2876. raise Exception("Auth Req TX not seen")
  2877. ev = dev[0].wait_event(["DPP-TX "], timeout=5)
  2878. if ev is None:
  2879. raise Exception("Auth Resp TX not seen")
  2880. ev = dev[1].wait_event(["DPP-TX "], timeout=0.1)
  2881. if ev is not None:
  2882. raise Exception("Unexpected Auth Conf TX")
  2883. def test_dpp_proto_stop_at_auth_conf(dev, apdev):
  2884. """DPP protocol testing - stop when receiving Auth Conf"""
  2885. run_dpp_proto_init(dev, 0, 89, init_enrollee=True)
  2886. ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=10)
  2887. if ev is None:
  2888. raise Exception("Enrollee did not start GAS")
  2889. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=10)
  2890. if ev is None:
  2891. raise Exception("Enrollee did not time out GAS")
  2892. if "result=TIMEOUT" not in ev:
  2893. raise Exception("Unexpected GAS result: " + ev)
  2894. def test_dpp_proto_stop_at_conf_req(dev, apdev):
  2895. """DPP protocol testing - stop when receiving Auth Req"""
  2896. run_dpp_proto_init(dev, 1, 90)
  2897. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=10)
  2898. if ev is None:
  2899. raise Exception("Enrollee did not start GAS")
  2900. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  2901. if ev is None:
  2902. raise Exception("Enrollee did not time out GAS")
  2903. if "result=TIMEOUT" not in ev:
  2904. raise Exception("Unexpected GAS result: " + ev)
  2905. def run_dpp_proto_init_pkex(dev, test_dev, test):
  2906. check_dpp_capab(dev[0])
  2907. check_dpp_capab(dev[1])
  2908. dev[test_dev].set("dpp_test", str(test))
  2909. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2910. res = dev[0].request(cmd)
  2911. if "FAIL" in res:
  2912. raise Exception("Failed to generate bootstrapping info")
  2913. id0 = int(res)
  2914. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  2915. res = dev[1].request(cmd)
  2916. if "FAIL" in res:
  2917. raise Exception("Failed to generate bootstrapping info")
  2918. id1 = int(res)
  2919. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  2920. res = dev[0].request(cmd)
  2921. if "FAIL" in res:
  2922. raise Exception("Failed to set PKEX data (responder)")
  2923. cmd = "DPP_LISTEN 2437"
  2924. if "OK" not in dev[0].request(cmd):
  2925. raise Exception("Failed to start listen operation")
  2926. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 code=secret" % id1
  2927. res = dev[1].request(cmd)
  2928. if "FAIL" in res:
  2929. raise Exception("Failed to set PKEX data (initiator)")
  2930. def test_dpp_proto_after_wrapped_data_pkex_cr_req(dev, apdev):
  2931. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Req"""
  2932. run_dpp_proto_init_pkex(dev, 1, 4)
  2933. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2934. if ev is None or "type=7" not in ev:
  2935. raise Exception("PKEX Exchange Request not seen")
  2936. ev = dev[0].wait_event(["DPP-RX"], timeout=5)
  2937. if ev is None or "type=9" not in ev:
  2938. raise Exception("PKEX Commit-Reveal Request not seen")
  2939. if "ignore=invalid-attributes" not in ev:
  2940. raise Exception("Unexpected RX info: " + ev)
  2941. def test_dpp_proto_after_wrapped_data_pkex_cr_resp(dev, apdev):
  2942. """DPP protocol testing - attribute after Wrapped Data in PKEX CR Resp"""
  2943. run_dpp_proto_init_pkex(dev, 0, 5)
  2944. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2945. if ev is None or "type=8" not in ev:
  2946. raise Exception("PKEX Exchange Response not seen")
  2947. ev = dev[1].wait_event(["DPP-RX"], timeout=5)
  2948. if ev is None or "type=10" not in ev:
  2949. raise Exception("PKEX Commit-Reveal Response not seen")
  2950. if "ignore=invalid-attributes" not in ev:
  2951. raise Exception("Unexpected RX info: " + ev)
  2952. def run_dpp_proto_pkex_req_missing(dev, test, reason):
  2953. run_dpp_proto_init_pkex(dev, 1, test)
  2954. ev = dev[0].wait_event(["DPP-FAIL"], timeout=5)
  2955. if ev is None:
  2956. raise Exception("DPP failure not seen")
  2957. if reason not in ev:
  2958. raise Exception("Unexpected failure: " + ev)
  2959. def run_dpp_proto_pkex_resp_missing(dev, test, reason):
  2960. run_dpp_proto_init_pkex(dev, 0, test)
  2961. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  2962. if ev is None:
  2963. raise Exception("DPP failure not seen")
  2964. if reason not in ev:
  2965. raise Exception("Unexpected failure: " + ev)
  2966. def test_dpp_proto_pkex_exchange_req_no_finite_cyclic_group(dev, apdev):
  2967. """DPP protocol testing - no Finite Cyclic Group in PKEX Exchange Request"""
  2968. run_dpp_proto_pkex_req_missing(dev, 34,
  2969. "Missing or invalid Finite Cyclic Group attribute")
  2970. def test_dpp_proto_pkex_exchange_req_no_encrypted_key(dev, apdev):
  2971. """DPP protocol testing - no Encrypted Key in PKEX Exchange Request"""
  2972. run_dpp_proto_pkex_req_missing(dev, 35,
  2973. "Missing Encrypted Key attribute")
  2974. def test_dpp_proto_pkex_exchange_resp_no_status(dev, apdev):
  2975. """DPP protocol testing - no Status in PKEX Exchange Response"""
  2976. run_dpp_proto_pkex_resp_missing(dev, 36, "No DPP Status attribute")
  2977. def test_dpp_proto_pkex_exchange_resp_no_encrypted_key(dev, apdev):
  2978. """DPP protocol testing - no Encrypted Key in PKEX Exchange Response"""
  2979. run_dpp_proto_pkex_resp_missing(dev, 37, "Missing Encrypted Key attribute")
  2980. def test_dpp_proto_pkex_cr_req_no_bootstrap_key(dev, apdev):
  2981. """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Request"""
  2982. run_dpp_proto_pkex_req_missing(dev, 38,
  2983. "No valid peer bootstrapping key found")
  2984. def test_dpp_proto_pkex_cr_req_no_i_auth_tag(dev, apdev):
  2985. """DPP protocol testing - no I-Auth Tag in PKEX Commit-Reveal Request"""
  2986. run_dpp_proto_pkex_req_missing(dev, 39, "No valid u (I-Auth tag) found")
  2987. def test_dpp_proto_pkex_cr_req_no_wrapped_data(dev, apdev):
  2988. """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Request"""
  2989. run_dpp_proto_pkex_req_missing(dev, 40, "Missing or invalid required Wrapped Data attribute")
  2990. def test_dpp_proto_pkex_cr_resp_no_bootstrap_key(dev, apdev):
  2991. """DPP protocol testing - no Bootstrap Key in PKEX Commit-Reveal Response"""
  2992. run_dpp_proto_pkex_resp_missing(dev, 41,
  2993. "No valid peer bootstrapping key found")
  2994. def test_dpp_proto_pkex_cr_resp_no_r_auth_tag(dev, apdev):
  2995. """DPP protocol testing - no R-Auth Tag in PKEX Commit-Reveal Response"""
  2996. run_dpp_proto_pkex_resp_missing(dev, 42, "No valid v (R-Auth tag) found")
  2997. def test_dpp_proto_pkex_cr_resp_no_wrapped_data(dev, apdev):
  2998. """DPP protocol testing - no Wrapped Data in PKEX Commit-Reveal Response"""
  2999. run_dpp_proto_pkex_resp_missing(dev, 43, "Missing or invalid required Wrapped Data attribute")
  3000. def test_dpp_proto_pkex_exchange_req_invalid_encrypted_key(dev, apdev):
  3001. """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Request"""
  3002. run_dpp_proto_pkex_req_missing(dev, 44,
  3003. "Invalid Encrypted Key value")
  3004. def test_dpp_proto_pkex_exchange_resp_invalid_encrypted_key(dev, apdev):
  3005. """DPP protocol testing - invalid Encrypted Key in PKEX Exchange Response"""
  3006. run_dpp_proto_pkex_resp_missing(dev, 45,
  3007. "Invalid Encrypted Key value")
  3008. def test_dpp_proto_pkex_exchange_resp_invalid_status(dev, apdev):
  3009. """DPP protocol testing - invalid Status in PKEX Exchange Response"""
  3010. run_dpp_proto_pkex_resp_missing(dev, 46,
  3011. "PKEX failed (peer indicated failure)")
  3012. def test_dpp_proto_pkex_cr_req_invalid_bootstrap_key(dev, apdev):
  3013. """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Request"""
  3014. run_dpp_proto_pkex_req_missing(dev, 47,
  3015. "Peer bootstrapping key is invalid")
  3016. def test_dpp_proto_pkex_cr_resp_invalid_bootstrap_key(dev, apdev):
  3017. """DPP protocol testing - invalid Bootstrap Key in PKEX Commit-Reveal Response"""
  3018. run_dpp_proto_pkex_resp_missing(dev, 48,
  3019. "Peer bootstrapping key is invalid")
  3020. def test_dpp_proto_pkex_cr_req_i_auth_tag_mismatch(dev, apdev):
  3021. """DPP protocol testing - I-auth tag mismatch in PKEX Commit-Reveal Request"""
  3022. run_dpp_proto_pkex_req_missing(dev, 49, "No valid u (I-Auth tag) found")
  3023. def test_dpp_proto_pkex_cr_resp_r_auth_tag_mismatch(dev, apdev):
  3024. """DPP protocol testing - R-auth tag mismatch in PKEX Commit-Reveal Response"""
  3025. run_dpp_proto_pkex_resp_missing(dev, 50, "No valid v (R-Auth tag) found")
  3026. def test_dpp_proto_stop_at_pkex_exchange_resp(dev, apdev):
  3027. """DPP protocol testing - stop when receiving PKEX Exchange Response"""
  3028. run_dpp_proto_init_pkex(dev, 1, 84)
  3029. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  3030. if ev is None:
  3031. raise Exception("PKEX Exchange Req TX not seen")
  3032. ev = dev[0].wait_event(["DPP-TX "], timeout=5)
  3033. if ev is None:
  3034. raise Exception("PKEX Exchange Resp not seen")
  3035. ev = dev[1].wait_event(["DPP-TX "], timeout=0.1)
  3036. if ev is not None:
  3037. raise Exception("Unexpected PKEX CR Req TX")
  3038. def test_dpp_proto_stop_at_pkex_cr_req(dev, apdev):
  3039. """DPP protocol testing - stop when receiving PKEX CR Request"""
  3040. run_dpp_proto_init_pkex(dev, 0, 85)
  3041. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  3042. if ev is None:
  3043. raise Exception("PKEX Exchange Req TX not seen")
  3044. ev = dev[0].wait_event(["DPP-TX "], timeout=5)
  3045. if ev is None:
  3046. raise Exception("PKEX Exchange Resp not seen")
  3047. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  3048. if ev is None:
  3049. raise Exception("PKEX CR Req TX not seen")
  3050. ev = dev[0].wait_event(["DPP-TX "], timeout=0.1)
  3051. if ev is not None:
  3052. raise Exception("Unexpected PKEX CR Resp TX")
  3053. def test_dpp_proto_stop_at_pkex_cr_resp(dev, apdev):
  3054. """DPP protocol testing - stop when receiving PKEX CR Response"""
  3055. run_dpp_proto_init_pkex(dev, 1, 86)
  3056. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  3057. if ev is None:
  3058. raise Exception("PKEX Exchange Req TX not seen")
  3059. ev = dev[0].wait_event(["DPP-TX "], timeout=5)
  3060. if ev is None:
  3061. raise Exception("PKEX Exchange Resp not seen")
  3062. ev = dev[1].wait_event(["DPP-TX "], timeout=5)
  3063. if ev is None:
  3064. raise Exception("PKEX CR Req TX not seen")
  3065. ev = dev[0].wait_event(["DPP-TX "], timeout=5)
  3066. if ev is None:
  3067. raise Exception("PKEX CR Resp TX not seen")
  3068. ev = dev[1].wait_event(["DPP-TX "], timeout=0.1)
  3069. if ev is not None:
  3070. raise Exception("Unexpected Auth Req TX")
  3071. def test_dpp_proto_network_introduction(dev, apdev):
  3072. """DPP protocol testing - network introduction"""
  3073. check_dpp_capab(dev[0])
  3074. check_dpp_capab(dev[1])
  3075. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  3076. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  3077. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  3078. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  3079. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  3080. params = { "ssid": "dpp",
  3081. "wpa": "2",
  3082. "wpa_key_mgmt": "DPP",
  3083. "ieee80211w": "2",
  3084. "rsn_pairwise": "CCMP",
  3085. "dpp_connector": ap_connector,
  3086. "dpp_csign": csign,
  3087. "dpp_netaccesskey": ap_netaccesskey }
  3088. try:
  3089. hapd = hostapd.add_ap(apdev[0], params)
  3090. except:
  3091. raise HwsimSkip("DPP not supported")
  3092. for test in [ 60, 61, 80, 82 ]:
  3093. dev[0].set("dpp_test", str(test))
  3094. dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
  3095. dpp_csign=csign, dpp_connector=sta_connector,
  3096. dpp_netaccesskey=sta_netaccesskey, wait_connect=False)
  3097. ev = dev[0].wait_event(["DPP-TX"], timeout=10)
  3098. if ev is None or "type=5" not in ev:
  3099. raise Exception("Peer Discovery Request TX not reported")
  3100. ev = dev[0].wait_event(["DPP-TX-STATUS"], timeout=2)
  3101. if ev is None or "result=SUCCESS" not in ev:
  3102. raise Exception("Peer Discovery Request TX status not reported")
  3103. ev = hapd.wait_event(["DPP-RX"], timeout=10)
  3104. if ev is None or "type=5" not in ev:
  3105. raise Exception("Peer Discovery Request RX not reported")
  3106. if test == 80:
  3107. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  3108. if ev is None:
  3109. raise Exception("DPP-INTRO not reported for test 80")
  3110. if "status=7" not in ev:
  3111. raise Exception("Unexpected result in test 80: " + ev)
  3112. dev[0].request("REMOVE_NETWORK all")
  3113. dev[0].dump_monitor()
  3114. hapd.dump_monitor()
  3115. dev[0].set("dpp_test", "0")
  3116. for test in [ 62, 63, 64, 77, 78, 79 ]:
  3117. hapd.set("dpp_test", str(test))
  3118. dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
  3119. dpp_csign=csign, dpp_connector=sta_connector,
  3120. dpp_netaccesskey=sta_netaccesskey, wait_connect=False)
  3121. ev = dev[0].wait_event(["DPP-INTRO"], timeout=10)
  3122. if ev is None:
  3123. raise Exception("Peer introduction result not reported (test %d)" % test)
  3124. if test == 77:
  3125. if "fail=transaction_id_mismatch" not in ev:
  3126. raise Exception("Connector validation failure not reported")
  3127. elif test == 78:
  3128. if "status=254" not in ev:
  3129. raise Exception("Invalid status value not reported")
  3130. elif test == 79:
  3131. if "fail=peer_connector_validation_failed" not in ev:
  3132. raise Exception("Connector validation failure not reported")
  3133. elif "status=" in ev:
  3134. raise Exception("Unexpected peer introduction result (test %d): " % test + ev)
  3135. dev[0].request("REMOVE_NETWORK all")
  3136. dev[0].dump_monitor()
  3137. hapd.dump_monitor()
  3138. hapd.set("dpp_test", "0")
  3139. dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412", ieee80211w="2",
  3140. dpp_csign=csign, dpp_connector=sta_connector,
  3141. dpp_netaccesskey=sta_netaccesskey)
  3142. def test_dpp_qr_code_no_chan_list_unicast(dev, apdev):
  3143. """DPP QR Code and no channel list (unicast)"""
  3144. run_dpp_qr_code_chan_list(dev, apdev, True, 2417, None)
  3145. def test_dpp_qr_code_chan_list_unicast(dev, apdev):
  3146. """DPP QR Code and 2.4 GHz channels (unicast)"""
  3147. run_dpp_qr_code_chan_list(dev, apdev, True, 2417,
  3148. "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")
  3149. def test_dpp_qr_code_chan_list_no_peer_unicast(dev, apdev):
  3150. """DPP QR Code and channel list and no peer (unicast)"""
  3151. run_dpp_qr_code_chan_list(dev, apdev, True, 2417, "81/1,81/6,81/11",
  3152. no_wait=True)
  3153. ev = dev[1].wait_event(["DPP-AUTH-INIT-FAILED"], timeout=5)
  3154. if ev is None:
  3155. raise Exception("Initiation failure not reported")
  3156. def test_dpp_qr_code_no_chan_list_broadcast(dev, apdev):
  3157. """DPP QR Code and no channel list (broadcast)"""
  3158. run_dpp_qr_code_chan_list(dev, apdev, False, 2412, None)
  3159. def test_dpp_qr_code_chan_list_broadcast(dev, apdev):
  3160. """DPP QR Code and some 2.4 GHz channels (broadcast)"""
  3161. run_dpp_qr_code_chan_list(dev, apdev, False, 2412, "81/1,81/6,81/11",
  3162. timeout=10)
  3163. def run_dpp_qr_code_chan_list(dev, apdev, unicast, listen_freq, chanlist,
  3164. no_wait=False, timeout=5):
  3165. check_dpp_capab(dev[0])
  3166. check_dpp_capab(dev[1])
  3167. dev[1].set("dpp_init_max_tries", "3")
  3168. dev[1].set("dpp_init_retry_time", "100")
  3169. dev[1].set("dpp_resp_wait_time", "1000")
  3170. logger.info("dev0 displays QR Code")
  3171. cmd = "DPP_BOOTSTRAP_GEN type=qrcode"
  3172. if chanlist:
  3173. cmd += " chan=" + chanlist
  3174. if unicast:
  3175. addr = dev[0].own_addr().replace(':', '')
  3176. cmd += " mac=" + addr
  3177. res = dev[0].request(cmd)
  3178. if "FAIL" in res:
  3179. raise Exception("Failed to generate bootstrapping info")
  3180. id0 = int(res)
  3181. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  3182. logger.info("dev1 scans QR Code")
  3183. res = dev[1].request("DPP_QR_CODE " + uri0)
  3184. if "FAIL" in res:
  3185. raise Exception("Failed to parse QR Code URI")
  3186. id1 = int(res)
  3187. logger.info("dev1 initiates DPP Authentication")
  3188. cmd = "DPP_LISTEN %d" % listen_freq
  3189. if "OK" not in dev[0].request(cmd):
  3190. raise Exception("Failed to start listen operation")
  3191. cmd = "DPP_AUTH_INIT peer=%d" % id1
  3192. if "OK" not in dev[1].request(cmd):
  3193. raise Exception("Failed to initiate DPP Authentication")
  3194. if no_wait:
  3195. return
  3196. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=timeout)
  3197. if ev is None:
  3198. raise Exception("DPP authentication did not succeed (Responder)")
  3199. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  3200. if ev is None:
  3201. raise Exception("DPP authentication did not succeed (Initiator)")
  3202. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  3203. if ev is None:
  3204. raise Exception("DPP configuration not completed (Enrollee)")
  3205. dev[0].request("DPP_STOP_LISTEN")
  3206. dev[0].dump_monitor()
  3207. dev[1].dump_monitor()
  3208. def test_dpp_qr_code_chan_list_no_match(dev, apdev):
  3209. """DPP QR Code and no matching supported channel"""
  3210. check_dpp_capab(dev[0])
  3211. check_dpp_capab(dev[1])
  3212. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=123/123"
  3213. res = dev[0].request(cmd)
  3214. if "FAIL" in res:
  3215. raise Exception("Failed to generate bootstrapping info")
  3216. id0 = int(res)
  3217. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  3218. res = dev[1].request("DPP_QR_CODE " + uri0)
  3219. if "FAIL" in res:
  3220. raise Exception("Failed to parse QR Code URI")
  3221. id1 = int(res)
  3222. cmd = "DPP_AUTH_INIT peer=%d" % id1
  3223. if "FAIL" not in dev[1].request(cmd):
  3224. raise Exception("DPP Authentication started unexpectedly")
  3225. def test_dpp_pkex_alloc_fail(dev, apdev):
  3226. """DPP/PKEX and memory allocation failures"""
  3227. check_dpp_capab(dev[0])
  3228. check_dpp_capab(dev[1])
  3229. tests = [ (1, "=dpp_keygen_configurator"),
  3230. (1, "base64_gen_encode;dpp_keygen_configurator") ]
  3231. for count, func in tests:
  3232. with alloc_fail(dev[1], count, func):
  3233. cmd = "DPP_CONFIGURATOR_ADD"
  3234. res = dev[1].request(cmd);
  3235. if "FAIL" not in res:
  3236. raise Exception("Unexpected DPP_CONFIGURATOR_ADD success")
  3237. cmd = "DPP_CONFIGURATOR_ADD"
  3238. res = dev[1].request(cmd);
  3239. if "FAIL" in res:
  3240. raise Exception("Failed to add configurator")
  3241. conf_id = int(res)
  3242. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  3243. res = dev[0].request(cmd)
  3244. if "FAIL" in res:
  3245. raise Exception("Failed to generate bootstrapping info")
  3246. id0 = int(res)
  3247. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  3248. res = dev[1].request(cmd)
  3249. if "FAIL" in res:
  3250. raise Exception("Failed to generate bootstrapping info")
  3251. id1 = int(res)
  3252. # Local error cases on the Initiator
  3253. tests = [ (1, "dpp_get_pubkey_point"),
  3254. (1, "dpp_alloc_msg;dpp_pkex_build_exchange_req"),
  3255. (1, "dpp_alloc_msg;dpp_pkex_build_commit_reveal_req"),
  3256. (1, "dpp_alloc_msg;dpp_auth_build_req"),
  3257. (1, "dpp_alloc_msg;dpp_auth_build_conf"),
  3258. (1, "dpp_bootstrap_key_hash"),
  3259. (1, "dpp_auth_init"),
  3260. (1, "=dpp_auth_resp_rx"),
  3261. (2, "=dpp_auth_resp_rx"),
  3262. (1, "dpp_build_conf_start"),
  3263. (1, "dpp_build_conf_obj_dpp"),
  3264. (2, "dpp_build_conf_obj_dpp"),
  3265. (3, "dpp_build_conf_obj_dpp"),
  3266. (4, "dpp_build_conf_obj_dpp"),
  3267. (5, "dpp_build_conf_obj_dpp"),
  3268. (6, "dpp_build_conf_obj_dpp"),
  3269. (7, "dpp_build_conf_obj_dpp"),
  3270. (8, "dpp_build_conf_obj_dpp"),
  3271. (1, "dpp_conf_req_rx"),
  3272. (2, "dpp_conf_req_rx"),
  3273. (3, "dpp_conf_req_rx"),
  3274. (4, "dpp_conf_req_rx"),
  3275. (5, "dpp_conf_req_rx"),
  3276. (6, "dpp_conf_req_rx"),
  3277. (7, "dpp_conf_req_rx"),
  3278. (1, "dpp_pkex_init"),
  3279. (2, "dpp_pkex_init"),
  3280. (3, "dpp_pkex_init"),
  3281. (1, "dpp_pkex_derive_z"),
  3282. (1, "=dpp_pkex_rx_commit_reveal_resp"),
  3283. (1, "dpp_get_pubkey_point;dpp_build_jwk"),
  3284. (2, "dpp_get_pubkey_point;dpp_build_jwk"),
  3285. (1, "dpp_get_pubkey_point;dpp_auth_init") ]
  3286. for count, func in tests:
  3287. dev[0].request("DPP_STOP_LISTEN")
  3288. dev[1].request("DPP_STOP_LISTEN")
  3289. dev[0].dump_monitor()
  3290. dev[1].dump_monitor()
  3291. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  3292. res = dev[0].request(cmd)
  3293. if "FAIL" in res:
  3294. raise Exception("Failed to set PKEX data (responder)")
  3295. cmd = "DPP_LISTEN 2437"
  3296. if "OK" not in dev[0].request(cmd):
  3297. raise Exception("Failed to start listen operation")
  3298. with alloc_fail(dev[1], count, func):
  3299. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=sta-dpp configurator=%d code=secret" % (id1, conf_id)
  3300. dev[1].request(cmd)
  3301. wait_fail_trigger(dev[1], "GET_ALLOC_FAIL", max_iter=100)
  3302. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
  3303. if ev:
  3304. dev[0].request("DPP_STOP_LISTEN")
  3305. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
  3306. # Local error cases on the Responder
  3307. tests = [ (1, "dpp_get_pubkey_point"),
  3308. (1, "dpp_alloc_msg;dpp_pkex_build_exchange_resp"),
  3309. (1, "dpp_alloc_msg;dpp_pkex_build_commit_reveal_resp"),
  3310. (1, "dpp_alloc_msg;dpp_auth_build_resp"),
  3311. (1, "dpp_get_pubkey_point;dpp_auth_build_resp_ok"),
  3312. (1, "=dpp_auth_req_rx"),
  3313. (2, "=dpp_auth_req_rx"),
  3314. (1, "=dpp_auth_conf_rx"),
  3315. (1, "json_parse;dpp_parse_jws_prot_hdr"),
  3316. (1, "json_get_member_base64url;dpp_parse_jws_prot_hdr"),
  3317. (1, "json_get_member_base64url;dpp_parse_jwk"),
  3318. (2, "json_get_member_base64url;dpp_parse_jwk"),
  3319. (1, "json_parse;dpp_parse_connector"),
  3320. (1, "dpp_parse_jwk;dpp_parse_connector"),
  3321. (1, "dpp_parse_jwk;dpp_parse_cred_dpp"),
  3322. (1, "dpp_get_pubkey_point;dpp_check_pubkey_match"),
  3323. (1, "base64_gen_decode;dpp_process_signed_connector"),
  3324. (1, "dpp_parse_jws_prot_hdr;dpp_process_signed_connector"),
  3325. (2, "base64_gen_decode;dpp_process_signed_connector"),
  3326. (3, "base64_gen_decode;dpp_process_signed_connector"),
  3327. (4, "base64_gen_decode;dpp_process_signed_connector"),
  3328. (1, "json_parse;dpp_parse_conf_obj"),
  3329. (1, "dpp_conf_resp_rx"),
  3330. (1, "=dpp_pkex_derive_z"),
  3331. (1, "=dpp_pkex_rx_exchange_req"),
  3332. (2, "=dpp_pkex_rx_exchange_req"),
  3333. (3, "=dpp_pkex_rx_exchange_req"),
  3334. (1, "=dpp_pkex_rx_commit_reveal_req"),
  3335. (1, "dpp_get_pubkey_point;dpp_pkex_rx_commit_reveal_req"),
  3336. (1, "dpp_bootstrap_key_hash") ]
  3337. for count, func in tests:
  3338. dev[0].request("DPP_STOP_LISTEN")
  3339. dev[1].request("DPP_STOP_LISTEN")
  3340. dev[0].dump_monitor()
  3341. dev[1].dump_monitor()
  3342. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  3343. res = dev[0].request(cmd)
  3344. if "FAIL" in res:
  3345. raise Exception("Failed to set PKEX data (responder)")
  3346. cmd = "DPP_LISTEN 2437"
  3347. if "OK" not in dev[0].request(cmd):
  3348. raise Exception("Failed to start listen operation")
  3349. with alloc_fail(dev[0], count, func):
  3350. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=sta-dpp configurator=%d code=secret" % (id1, conf_id)
  3351. dev[1].request(cmd)
  3352. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL", max_iter=100)
  3353. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
  3354. if ev:
  3355. dev[0].request("DPP_STOP_LISTEN")
  3356. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
  3357. def test_dpp_pkex_test_fail(dev, apdev):
  3358. """DPP/PKEX and local failures"""
  3359. check_dpp_capab(dev[0])
  3360. check_dpp_capab(dev[1])
  3361. tests = [ (1, "dpp_keygen_configurator") ]
  3362. for count, func in tests:
  3363. with fail_test(dev[1], count, func):
  3364. cmd = "DPP_CONFIGURATOR_ADD"
  3365. res = dev[1].request(cmd);
  3366. if "FAIL" not in res:
  3367. raise Exception("Unexpected DPP_CONFIGURATOR_ADD success")
  3368. tests = [ (1, "dpp_keygen") ]
  3369. for count, func in tests:
  3370. with fail_test(dev[1], count, func):
  3371. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  3372. res = dev[1].request(cmd);
  3373. if "FAIL" not in res:
  3374. raise Exception("Unexpected DPP_BOOTSTRAP_GEN success")
  3375. cmd = "DPP_CONFIGURATOR_ADD"
  3376. res = dev[1].request(cmd);
  3377. if "FAIL" in res:
  3378. raise Exception("Failed to add configurator")
  3379. conf_id = int(res)
  3380. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  3381. res = dev[0].request(cmd)
  3382. if "FAIL" in res:
  3383. raise Exception("Failed to generate bootstrapping info")
  3384. id0 = int(res)
  3385. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  3386. res = dev[1].request(cmd)
  3387. if "FAIL" in res:
  3388. raise Exception("Failed to generate bootstrapping info")
  3389. id1 = int(res)
  3390. # Local error cases on the Initiator
  3391. tests = [ (1, "aes_siv_encrypt;dpp_auth_build_req"),
  3392. (1, "os_get_random;dpp_auth_init"),
  3393. (1, "dpp_derive_k1;dpp_auth_init"),
  3394. (1, "dpp_hkdf_expand;dpp_derive_k1;dpp_auth_init"),
  3395. (1, "dpp_gen_i_auth;dpp_auth_build_conf"),
  3396. (1, "aes_siv_encrypt;dpp_auth_build_conf"),
  3397. (1, "dpp_derive_k2;dpp_auth_resp_rx"),
  3398. (1, "dpp_hkdf_expand;dpp_derive_k2;dpp_auth_resp_rx"),
  3399. (1, "dpp_derive_ke;dpp_auth_resp_rx"),
  3400. (1, "dpp_hkdf_expand;dpp_derive_ke;dpp_auth_resp_rx"),
  3401. (1, "dpp_gen_r_auth;dpp_auth_resp_rx"),
  3402. (1, "aes_siv_encrypt;dpp_build_conf_resp"),
  3403. (1, "dpp_pkex_derive_Qi;dpp_pkex_build_exchange_req"),
  3404. (1, "aes_siv_encrypt;dpp_pkex_build_commit_reveal_req"),
  3405. (1, "hmac_sha256_vector;dpp_pkex_rx_exchange_resp"),
  3406. (1, "aes_siv_decrypt;dpp_pkex_rx_commit_reveal_resp"),
  3407. (1, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_resp") ]
  3408. for count, func in tests:
  3409. dev[0].request("DPP_STOP_LISTEN")
  3410. dev[1].request("DPP_STOP_LISTEN")
  3411. dev[0].dump_monitor()
  3412. dev[1].dump_monitor()
  3413. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  3414. res = dev[0].request(cmd)
  3415. if "FAIL" in res:
  3416. raise Exception("Failed to set PKEX data (responder)")
  3417. cmd = "DPP_LISTEN 2437"
  3418. if "OK" not in dev[0].request(cmd):
  3419. raise Exception("Failed to start listen operation")
  3420. with fail_test(dev[1], count, func):
  3421. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=sta-dpp configurator=%d code=secret" % (id1, conf_id)
  3422. dev[1].request(cmd)
  3423. wait_fail_trigger(dev[1], "GET_FAIL", max_iter=100)
  3424. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
  3425. if ev:
  3426. dev[0].request("DPP_STOP_LISTEN")
  3427. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)
  3428. # Local error cases on the Responder
  3429. tests = [ (1, "aes_siv_encrypt;dpp_auth_build_resp"),
  3430. (1, "os_get_random;dpp_build_conf_req"),
  3431. (1, "aes_siv_encrypt;dpp_build_conf_req"),
  3432. (1, "os_get_random;dpp_auth_build_resp_ok"),
  3433. (1, "dpp_derive_k2;dpp_auth_build_resp_ok"),
  3434. (1, "dpp_derive_ke;dpp_auth_build_resp_ok"),
  3435. (1, "dpp_gen_r_auth;dpp_auth_build_resp_ok"),
  3436. (1, "aes_siv_encrypt;dpp_auth_build_resp_ok"),
  3437. (1, "dpp_derive_k1;dpp_auth_req_rx"),
  3438. (1, "aes_siv_decrypt;dpp_auth_req_rx"),
  3439. (1, "aes_siv_decrypt;dpp_auth_conf_rx"),
  3440. (1, "dpp_gen_i_auth;dpp_auth_conf_rx"),
  3441. (1, "dpp_check_pubkey_match"),
  3442. (1, "aes_siv_decrypt;dpp_conf_resp_rx"),
  3443. (1, "hmac_sha256_kdf;dpp_pkex_derive_z"),
  3444. (1, "dpp_pkex_derive_Qi;dpp_pkex_rx_exchange_req"),
  3445. (1, "dpp_pkex_derive_Qr;dpp_pkex_rx_exchange_req"),
  3446. (1, "aes_siv_encrypt;dpp_pkex_build_commit_reveal_resp"),
  3447. (1, "aes_siv_decrypt;dpp_pkex_rx_commit_reveal_req"),
  3448. (1, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_req"),
  3449. (2, "hmac_sha256_vector;dpp_pkex_rx_commit_reveal_req") ]
  3450. for count, func in tests:
  3451. dev[0].request("DPP_STOP_LISTEN")
  3452. dev[1].request("DPP_STOP_LISTEN")
  3453. dev[0].dump_monitor()
  3454. dev[1].dump_monitor()
  3455. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id0)
  3456. res = dev[0].request(cmd)
  3457. if "FAIL" in res:
  3458. raise Exception("Failed to set PKEX data (responder)")
  3459. cmd = "DPP_LISTEN 2437"
  3460. if "OK" not in dev[0].request(cmd):
  3461. raise Exception("Failed to start listen operation")
  3462. with fail_test(dev[0], count, func):
  3463. cmd = "DPP_PKEX_ADD own=%d identifier=test init=1 conf=sta-dpp configurator=%d code=secret" % (id1, conf_id)
  3464. dev[1].request(cmd)
  3465. wait_fail_trigger(dev[0], "GET_FAIL", max_iter=100)
  3466. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=0.01)
  3467. if ev:
  3468. dev[0].request("DPP_STOP_LISTEN")
  3469. dev[0].wait_event(["GAS-QUERY-DONE"], timeout=3)