test_dpp.py 127 KB

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