test_dpp.py 176 KB

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