test_dpp.py 182 KB

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