test_dpp.py 135 KB

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