test_dpp.py 178 KB

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