test_dpp.py 171 KB

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