test_dpp.py 156 KB

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