test_dpp.py 176 KB

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