test_dpp.py 166 KB

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