test_dpp.py 124 KB

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