test_dpp.py 111 KB

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