test_dpp.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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. from utils import HwsimSkip
  11. def check_dpp_capab(dev):
  12. if "UNKNOWN COMMAND" in dev.request("DPP_BOOTSTRAP_GET_URI 0"):
  13. raise HwsimSkip("DPP not supported")
  14. def test_dpp_qr_code_parsing(dev, apdev):
  15. """DPP QR Code parsing"""
  16. check_dpp_capab(dev[0])
  17. id = []
  18. tests = [ "DPP:C:81/1,115/36;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADM2206avxHJaHXgLMkq/24e0rsrfMP9K1Tm8gx+ovP0I=;;",
  19. "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;",
  20. "DPP:I:;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" ]
  21. for uri in tests:
  22. res = dev[0].request("DPP_QR_CODE " + uri)
  23. if "FAIL" in res:
  24. raise Exception("Failed to parse QR Code")
  25. id.append(int(res))
  26. uri2 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id[-1])
  27. if uri != uri2:
  28. raise Exception("Returned URI does not match")
  29. tests = [ "foo",
  30. "DPP:",
  31. "DPP:;;",
  32. "DPP:C:1/2;M:;K;;",
  33. "DPP:I:;M:01020304050;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" ]
  34. for t in tests:
  35. res = dev[0].request("DPP_QR_CODE " + t)
  36. if "FAIL" not in res:
  37. raise Exception("Accepted invalid QR Code: " + t)
  38. logger.info("ID: " + str(id))
  39. if id[0] == id[1] or id[0] == id[2] or id[1] == id[2]:
  40. raise Exception("Duplicate ID returned")
  41. if "FAIL" not in dev[0].request("DPP_BOOTSTRAP_REMOVE 12345678"):
  42. raise Exception("DPP_BOOTSTRAP_REMOVE accepted unexpectedly")
  43. if "OK" not in dev[0].request("DPP_BOOTSTRAP_REMOVE %d" % id[1]):
  44. raise Exception("DPP_BOOTSTRAP_REMOVE failed")
  45. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode")
  46. if "FAIL" in res:
  47. raise Exception("Failed to generate bootstrapping info")
  48. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % int(res))
  49. logger.info("Generated URI: " + uri)
  50. res = dev[0].request("DPP_QR_CODE " + uri)
  51. if "FAIL" in res:
  52. raise Exception("Failed to parse self-generated QR Code URI")
  53. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1,115/36 mac=010203040506 info=foo")
  54. if "FAIL" in res:
  55. raise Exception("Failed to generate bootstrapping info")
  56. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % int(res))
  57. logger.info("Generated URI: " + uri)
  58. res = dev[0].request("DPP_QR_CODE " + uri)
  59. if "FAIL" in res:
  60. raise Exception("Failed to parse self-generated QR Code URI")
  61. def test_dpp_qr_code_auth_broadcast(dev, apdev):
  62. """DPP QR Code and authentication exchange (broadcast)"""
  63. check_dpp_capab(dev[0])
  64. check_dpp_capab(dev[1])
  65. logger.info("dev0 displays QR Code")
  66. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1")
  67. if "FAIL" in res:
  68. raise Exception("Failed to generate bootstrapping info")
  69. id0 = int(res)
  70. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  71. logger.info("dev1 scans QR Code")
  72. res = dev[1].request("DPP_QR_CODE " + uri0)
  73. if "FAIL" in res:
  74. raise Exception("Failed to parse QR Code URI")
  75. id1 = int(res)
  76. logger.info("dev1 initiates DPP Authentication")
  77. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  78. raise Exception("Failed to start listen operation")
  79. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  80. raise Exception("Failed to initiate DPP Authentication")
  81. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  82. if ev is None:
  83. raise Exception("DPP authentication did not succeed (Responder)")
  84. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  85. if ev is None:
  86. raise Exception("DPP authentication did not succeed (Initiator)")
  87. dev[0].request("DPP_STOP_LISTEN")
  88. def test_dpp_qr_code_auth_unicast(dev, apdev):
  89. """DPP QR Code and authentication exchange (unicast)"""
  90. run_dpp_qr_code_auth_unicast(dev, apdev, None)
  91. def test_dpp_qr_code_auth_unicast_ap_enrollee(dev, apdev):
  92. """DPP QR Code and authentication exchange (AP enrollee)"""
  93. run_dpp_qr_code_auth_unicast(dev, apdev, None, netrole="ap")
  94. def test_dpp_qr_code_curve_prime256v1(dev, apdev):
  95. """DPP QR Code and curve prime256v1"""
  96. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1")
  97. def test_dpp_qr_code_curve_secp384r1(dev, apdev):
  98. """DPP QR Code and curve secp384r1"""
  99. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1")
  100. def test_dpp_qr_code_curve_secp521r1(dev, apdev):
  101. """DPP QR Code and curve secp521r1"""
  102. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1")
  103. def test_dpp_qr_code_curve_brainpoolP256r1(dev, apdev):
  104. """DPP QR Code and curve brainpoolP256r1"""
  105. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP256r1")
  106. def test_dpp_qr_code_curve_brainpoolP384r1(dev, apdev):
  107. """DPP QR Code and curve brainpoolP384r1"""
  108. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP384r1")
  109. def test_dpp_qr_code_curve_brainpoolP512r1(dev, apdev):
  110. """DPP QR Code and curve brainpoolP512r1"""
  111. run_dpp_qr_code_auth_unicast(dev, apdev, "brainpoolP512r1")
  112. def test_dpp_qr_code_set_key(dev, apdev):
  113. """DPP QR Code and fixed bootstrapping key"""
  114. run_dpp_qr_code_auth_unicast(dev, apdev, None, key="30770201010420e5143ac74682cc6869a830e8f5301a5fa569130ac329b1d7dd6f2a7495dbcbe1a00a06082a8648ce3d030107a144034200045e13e167c33dbc7d85541e5509600aa8139bbb3e39e25898992c5d01be92039ee2850f17e71506ded0d6b25677441eae249f8e225c68dd15a6354dca54006383")
  115. def run_dpp_qr_code_auth_unicast(dev, apdev, curve, netrole=None, key=None,
  116. require_conf_success=False, init_extra=None,
  117. require_conf_failure=False,
  118. configurator=False, conf_curve=None):
  119. check_dpp_capab(dev[0])
  120. check_dpp_capab(dev[1])
  121. if configurator:
  122. logger.info("Create configurator on dev1")
  123. cmd = "DPP_CONFIGURATOR_ADD"
  124. if conf_curve:
  125. cmd += " curve=" + conf_curve
  126. res = dev[1].request(cmd);
  127. if "FAIL" in res:
  128. raise Exception("Failed to add configurator")
  129. conf_id = int(res)
  130. logger.info("dev0 displays QR Code")
  131. addr = dev[0].own_addr().replace(':', '')
  132. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  133. if curve:
  134. cmd += " curve=" + curve
  135. if key:
  136. cmd += " key=" + key
  137. res = dev[0].request(cmd)
  138. if "FAIL" in res:
  139. raise Exception("Failed to generate bootstrapping info")
  140. id0 = int(res)
  141. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  142. logger.info("dev1 scans QR Code")
  143. res = dev[1].request("DPP_QR_CODE " + uri0)
  144. if "FAIL" in res:
  145. raise Exception("Failed to parse QR Code URI")
  146. id1 = int(res)
  147. logger.info("dev1 initiates DPP Authentication")
  148. cmd = "DPP_LISTEN 2412"
  149. if netrole:
  150. cmd += " netrole=" + netrole
  151. if "OK" not in dev[0].request(cmd):
  152. raise Exception("Failed to start listen operation")
  153. cmd = "DPP_AUTH_INIT peer=%d" % id1
  154. if init_extra:
  155. cmd += " " + init_extra
  156. if configurator:
  157. cmd += " configurator=%d" % conf_id
  158. if "OK" not in dev[1].request(cmd):
  159. raise Exception("Failed to initiate DPP Authentication")
  160. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  161. if ev is None:
  162. raise Exception("DPP authentication did not succeed (Responder)")
  163. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  164. if ev is None:
  165. raise Exception("DPP authentication did not succeed (Initiator)")
  166. ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=5)
  167. if ev is None:
  168. raise Exception("DPP configuration not completed (Configurator)")
  169. ev = dev[0].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  170. if ev is None:
  171. raise Exception("DPP configuration not completed (Enrollee)")
  172. if require_conf_success:
  173. if "DPP-CONF-FAILED" in ev:
  174. raise Exception("DPP configuration failed")
  175. if require_conf_failure:
  176. if "DPP-CONF-SUCCESS" in ev:
  177. raise Exception("DPP configuration succeeded unexpectedly")
  178. dev[0].request("DPP_STOP_LISTEN")
  179. dev[0].dump_monitor()
  180. dev[1].dump_monitor()
  181. def test_dpp_qr_code_auth_mutual(dev, apdev):
  182. """DPP QR Code and authentication exchange (mutual)"""
  183. check_dpp_capab(dev[0])
  184. check_dpp_capab(dev[1])
  185. logger.info("dev0 displays QR Code")
  186. addr = dev[0].own_addr().replace(':', '')
  187. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  188. if "FAIL" in res:
  189. raise Exception("Failed to generate bootstrapping info")
  190. id0 = int(res)
  191. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  192. logger.info("dev1 scans QR Code")
  193. res = dev[1].request("DPP_QR_CODE " + uri0)
  194. if "FAIL" in res:
  195. raise Exception("Failed to parse QR Code URI")
  196. id1 = int(res)
  197. logger.info("dev1 displays QR Code")
  198. addr = dev[1].own_addr().replace(':', '')
  199. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  200. if "FAIL" in res:
  201. raise Exception("Failed to generate bootstrapping info")
  202. id1b = int(res)
  203. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  204. logger.info("dev0 scans QR Code")
  205. res = dev[0].request("DPP_QR_CODE " + uri1b)
  206. if "FAIL" in res:
  207. raise Exception("Failed to parse QR Code URI")
  208. id0b = int(res)
  209. logger.info("dev1 initiates DPP Authentication")
  210. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  211. raise Exception("Failed to start listen operation")
  212. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  213. raise Exception("Failed to initiate DPP Authentication")
  214. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  215. if ev is None:
  216. raise Exception("DPP authentication did not succeed (Responder)")
  217. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  218. if ev is None:
  219. raise Exception("DPP authentication did not succeed (Initiator)")
  220. dev[0].request("DPP_STOP_LISTEN")
  221. def test_dpp_qr_code_auth_mutual2(dev, apdev):
  222. """DPP QR Code and authentication exchange (mutual2)"""
  223. check_dpp_capab(dev[0])
  224. check_dpp_capab(dev[1])
  225. logger.info("dev0 displays QR Code")
  226. addr = dev[0].own_addr().replace(':', '')
  227. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  228. if "FAIL" in res:
  229. raise Exception("Failed to generate bootstrapping info")
  230. id0 = int(res)
  231. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  232. logger.info("dev1 scans QR Code")
  233. res = dev[1].request("DPP_QR_CODE " + uri0)
  234. if "FAIL" in res:
  235. raise Exception("Failed to parse QR Code URI")
  236. id1 = int(res)
  237. logger.info("dev1 displays QR Code")
  238. addr = dev[1].own_addr().replace(':', '')
  239. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  240. if "FAIL" in res:
  241. raise Exception("Failed to generate bootstrapping info")
  242. id1b = int(res)
  243. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  244. logger.info("dev1 initiates DPP Authentication")
  245. if "OK" not in dev[0].request("DPP_LISTEN 2412 qr=mutual"):
  246. raise Exception("Failed to start listen operation")
  247. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b)):
  248. raise Exception("Failed to initiate DPP Authentication")
  249. ev = dev[1].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
  250. if ev is None:
  251. raise Exception("Pending response not reported")
  252. ev = dev[0].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
  253. if ev is None:
  254. raise Exception("QR Code scan for mutual authentication not requested")
  255. logger.info("dev0 scans QR Code")
  256. res = dev[0].request("DPP_QR_CODE " + uri1b)
  257. if "FAIL" in res:
  258. raise Exception("Failed to parse QR Code URI")
  259. id0b = int(res)
  260. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  261. if ev is None:
  262. raise Exception("DPP authentication did not succeed (Responder)")
  263. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  264. if ev is None:
  265. raise Exception("DPP authentication did not succeed (Initiator)")
  266. dev[0].request("DPP_STOP_LISTEN")
  267. def test_dpp_qr_code_auth_mutual_curve_mismatch(dev, apdev):
  268. """DPP QR Code and authentication exchange (mutual/mismatch)"""
  269. check_dpp_capab(dev[0])
  270. check_dpp_capab(dev[1])
  271. logger.info("dev0 displays QR Code")
  272. addr = dev[0].own_addr().replace(':', '')
  273. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  274. if "FAIL" in res:
  275. raise Exception("Failed to generate bootstrapping info")
  276. id0 = int(res)
  277. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  278. logger.info("dev1 scans QR Code")
  279. res = dev[1].request("DPP_QR_CODE " + uri0)
  280. if "FAIL" in res:
  281. raise Exception("Failed to parse QR Code URI")
  282. id1 = int(res)
  283. logger.info("dev1 displays QR Code")
  284. addr = dev[1].own_addr().replace(':', '')
  285. res = dev[1].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr + " curve=secp384r1")
  286. if "FAIL" in res:
  287. raise Exception("Failed to generate bootstrapping info")
  288. id1b = int(res)
  289. uri1b = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1b)
  290. logger.info("dev0 scans QR Code")
  291. res = dev[0].request("DPP_QR_CODE " + uri1b)
  292. if "FAIL" in res:
  293. raise Exception("Failed to parse QR Code URI")
  294. id0b = int(res)
  295. res = dev[1].request("DPP_AUTH_INIT peer=%d own=%d" % (id1, id1b))
  296. if "FAIL" not in res:
  297. raise Exception("DPP_AUTH_INIT accepted unexpectedly")
  298. def test_dpp_qr_code_listen_continue(dev, apdev):
  299. """DPP QR Code and listen operation needing continuation"""
  300. check_dpp_capab(dev[0])
  301. check_dpp_capab(dev[1])
  302. logger.info("dev0 displays QR Code")
  303. addr = dev[0].own_addr().replace(':', '')
  304. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  305. if "FAIL" in res:
  306. raise Exception("Failed to generate bootstrapping info")
  307. id0 = int(res)
  308. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  309. logger.info("dev1 scans QR Code")
  310. res = dev[1].request("DPP_QR_CODE " + uri0)
  311. if "FAIL" in res:
  312. raise Exception("Failed to parse QR Code URI")
  313. id1 = int(res)
  314. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  315. raise Exception("Failed to start listen operation")
  316. logger.info("Wait for listen to expire and get restarted")
  317. time.sleep(5.5)
  318. logger.info("dev1 initiates DPP Authentication")
  319. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d" % id1):
  320. raise Exception("Failed to initiate DPP Authentication")
  321. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  322. if ev is None:
  323. raise Exception("DPP authentication did not succeed (Responder)")
  324. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  325. if ev is None:
  326. raise Exception("DPP authentication did not succeed (Initiator)")
  327. dev[0].request("DPP_STOP_LISTEN")
  328. def test_dpp_qr_code_auth_initiator_enrollee(dev, apdev):
  329. """DPP QR Code and authentication exchange (Initiator in Enrollee role)"""
  330. check_dpp_capab(dev[0])
  331. check_dpp_capab(dev[1])
  332. dev[0].request("SET gas_address3 1")
  333. dev[1].request("SET gas_address3 1")
  334. logger.info("dev0 displays QR Code")
  335. addr = dev[0].own_addr().replace(':', '')
  336. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  337. if "FAIL" in res:
  338. raise Exception("Failed to generate bootstrapping info")
  339. id0 = int(res)
  340. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  341. logger.info("dev1 scans QR Code")
  342. res = dev[1].request("DPP_QR_CODE " + uri0)
  343. if "FAIL" in res:
  344. raise Exception("Failed to parse QR Code URI")
  345. id1 = int(res)
  346. logger.info("dev1 initiates DPP Authentication")
  347. if "OK" not in dev[0].request("DPP_LISTEN 2412"):
  348. raise Exception("Failed to start listen operation")
  349. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  350. raise Exception("Failed to initiate DPP Authentication")
  351. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  352. if ev is None:
  353. raise Exception("DPP authentication did not succeed (Responder)")
  354. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  355. if ev is None:
  356. raise Exception("DPP authentication did not succeed (Initiator)")
  357. dev[0].request("DPP_STOP_LISTEN")
  358. def test_dpp_qr_code_auth_incompatible_roles(dev, apdev):
  359. """DPP QR Code and authentication exchange (incompatible roles)"""
  360. check_dpp_capab(dev[0])
  361. check_dpp_capab(dev[1])
  362. logger.info("dev0 displays QR Code")
  363. addr = dev[0].own_addr().replace(':', '')
  364. res = dev[0].request("DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr)
  365. if "FAIL" in res:
  366. raise Exception("Failed to generate bootstrapping info")
  367. id0 = int(res)
  368. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  369. logger.info("dev1 scans QR Code")
  370. res = dev[1].request("DPP_QR_CODE " + uri0)
  371. if "FAIL" in res:
  372. raise Exception("Failed to parse QR Code URI")
  373. id1 = int(res)
  374. logger.info("dev1 initiates DPP Authentication")
  375. if "OK" not in dev[0].request("DPP_LISTEN 2412 role=enrollee"):
  376. raise Exception("Failed to start listen operation")
  377. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=enrollee" % id1):
  378. raise Exception("Failed to initiate DPP Authentication")
  379. ev = dev[1].wait_event(["DPP-NOT-COMPATIBLE"], timeout=5)
  380. if ev is None:
  381. raise Exception("DPP-NOT-COMPATIBLE event on initiator timed out")
  382. ev = dev[0].wait_event(["DPP-NOT-COMPATIBLE"], timeout=1)
  383. if ev is None:
  384. raise Exception("DPP-NOT-COMPATIBLE event on responder timed out")
  385. if "OK" not in dev[1].request("DPP_AUTH_INIT peer=%d role=configurator" % id1):
  386. raise Exception("Failed to initiate DPP Authentication")
  387. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  388. if ev is None:
  389. raise Exception("DPP authentication did not succeed (Responder)")
  390. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  391. if ev is None:
  392. raise Exception("DPP authentication did not succeed (Initiator)")
  393. dev[0].request("DPP_STOP_LISTEN")
  394. def test_dpp_config_legacy(dev, apdev):
  395. """DPP Config Object for legacy network using passphrase"""
  396. check_dpp_capab(dev[1])
  397. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}'
  398. dev[1].set("dpp_config_obj_override", conf)
  399. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  400. require_conf_success=True)
  401. def test_dpp_config_legacy_psk_hex(dev, apdev):
  402. """DPP Config Object for legacy network using PSK"""
  403. check_dpp_capab(dev[1])
  404. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","psk_hex":"' + 32*"12" + '"}}'
  405. dev[1].set("dpp_config_obj_override", conf)
  406. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  407. require_conf_success=True)
  408. def test_dpp_config_fragmentation(dev, apdev):
  409. """DPP Config Object for legacy network requiring fragmentation"""
  410. check_dpp_capab(dev[1])
  411. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  412. dev[1].set("dpp_config_obj_override", conf)
  413. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  414. require_conf_success=True)
  415. def test_dpp_config_legacy_gen(dev, apdev):
  416. """Generate DPP Config Object for legacy network"""
  417. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  418. init_extra="conf=sta-psk",
  419. require_conf_success=True)
  420. def test_dpp_config_dpp_gen_prime256v1(dev, apdev):
  421. """Generate DPP Config Object for DPP network (P-256)"""
  422. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  423. init_extra="conf=sta-dpp",
  424. require_conf_success=True,
  425. configurator=True)
  426. def test_dpp_config_dpp_gen_secp384r1(dev, apdev):
  427. """Generate DPP Config Object for DPP network (P-384)"""
  428. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  429. init_extra="conf=sta-dpp",
  430. require_conf_success=True,
  431. configurator=True)
  432. def test_dpp_config_dpp_gen_secp521r1(dev, apdev):
  433. """Generate DPP Config Object for DPP network (P-521)"""
  434. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  435. init_extra="conf=sta-dpp",
  436. require_conf_success=True,
  437. configurator=True)
  438. def test_dpp_config_dpp_gen_prime256v1_prime256v1(dev, apdev):
  439. """Generate DPP Config Object for DPP network (P-256 + P-256)"""
  440. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  441. init_extra="conf=sta-dpp",
  442. require_conf_success=True,
  443. configurator=True,
  444. conf_curve="prime256v1")
  445. def test_dpp_config_dpp_gen_prime256v1_secp384r1(dev, apdev):
  446. """Generate DPP Config Object for DPP network (P-256 + P-384)"""
  447. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  448. init_extra="conf=sta-dpp",
  449. require_conf_success=True,
  450. configurator=True,
  451. conf_curve="secp384r1")
  452. def test_dpp_config_dpp_gen_prime256v1_secp521r1(dev, apdev):
  453. """Generate DPP Config Object for DPP network (P-256 + P-521)"""
  454. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  455. init_extra="conf=sta-dpp",
  456. require_conf_success=True,
  457. configurator=True,
  458. conf_curve="secp521r1")
  459. def test_dpp_config_dpp_gen_secp384r1_prime256v1(dev, apdev):
  460. """Generate DPP Config Object for DPP network (P-384 + P-256)"""
  461. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  462. init_extra="conf=sta-dpp",
  463. require_conf_success=True,
  464. configurator=True,
  465. conf_curve="prime256v1")
  466. def test_dpp_config_dpp_gen_secp384r1_secp384r1(dev, apdev):
  467. """Generate DPP Config Object for DPP network (P-384 + P-384)"""
  468. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  469. init_extra="conf=sta-dpp",
  470. require_conf_success=True,
  471. configurator=True,
  472. conf_curve="secp384r1")
  473. def test_dpp_config_dpp_gen_secp384r1_secp521r1(dev, apdev):
  474. """Generate DPP Config Object for DPP network (P-384 + P-521)"""
  475. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  476. init_extra="conf=sta-dpp",
  477. require_conf_success=True,
  478. configurator=True,
  479. conf_curve="secp521r1")
  480. def test_dpp_config_dpp_gen_secp521r1_prime256v1(dev, apdev):
  481. """Generate DPP Config Object for DPP network (P-521 + P-256)"""
  482. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  483. init_extra="conf=sta-dpp",
  484. require_conf_success=True,
  485. configurator=True,
  486. conf_curve="prime256v1")
  487. def test_dpp_config_dpp_gen_secp521r1_secp384r1(dev, apdev):
  488. """Generate DPP Config Object for DPP network (P-521 + P-384)"""
  489. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  490. init_extra="conf=sta-dpp",
  491. require_conf_success=True,
  492. configurator=True,
  493. conf_curve="secp384r1")
  494. def test_dpp_config_dpp_gen_secp521r1_secp521r1(dev, apdev):
  495. """Generate DPP Config Object for DPP network (P-521 + P-521)"""
  496. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  497. init_extra="conf=sta-dpp",
  498. require_conf_success=True,
  499. configurator=True,
  500. conf_curve="secp521r1")
  501. def test_dpp_config_dpp_gen_expiry(dev, apdev):
  502. """Generate DPP Config Object for DPP network with expiry value"""
  503. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  504. init_extra="conf=sta-dpp expiry=%d" % (time.time() + 1000),
  505. require_conf_success=True,
  506. configurator=True)
  507. def test_dpp_config_dpp_gen_expired_key(dev, apdev):
  508. """Generate DPP Config Object for DPP network with expiry value"""
  509. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  510. init_extra="conf=sta-dpp expiry=%d" % (time.time() - 10),
  511. require_conf_failure=True,
  512. configurator=True)
  513. def test_dpp_config_dpp_override_prime256v1(dev, apdev):
  514. """DPP Config Object override (P-256)"""
  515. check_dpp_capab(dev[0])
  516. check_dpp_capab(dev[1])
  517. 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"}}}'
  518. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  519. dev[1].set("dpp_config_obj_override", conf)
  520. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  521. require_conf_success=True)
  522. def test_dpp_config_dpp_override_secp384r1(dev, apdev):
  523. """DPP Config Object override (P-384)"""
  524. check_dpp_capab(dev[0])
  525. check_dpp_capab(dev[1])
  526. 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"}}}'
  527. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  528. dev[1].set("dpp_config_obj_override", conf)
  529. run_dpp_qr_code_auth_unicast(dev, apdev, "secp384r1",
  530. require_conf_success=True)
  531. def test_dpp_config_dpp_override_secp521r1(dev, apdev):
  532. """DPP Config Object override (P-521)"""
  533. check_dpp_capab(dev[0])
  534. check_dpp_capab(dev[1])
  535. 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"}}}'
  536. dev[0].set("dpp_ignore_netaccesskey_mismatch", "1")
  537. dev[1].set("dpp_config_obj_override", conf)
  538. run_dpp_qr_code_auth_unicast(dev, apdev, "secp521r1",
  539. require_conf_success=True)
  540. def test_dpp_config_override_objects(dev, apdev):
  541. """Generate DPP Config Object and override objects)"""
  542. check_dpp_capab(dev[1])
  543. discovery = '{\n"ssid":"mywifi",\n"op_cl":81,\n"ch_list":\n[\n{"ch":1},\n{"ch":6},\n{"ch":11}\n]\n}'
  544. groups = '[\n {"groupId":"home","netRole":"sta"},\n {"groupId":"cottage","netRole":"sta"}\n]'
  545. devices = '[\n{"deviceId":"G1YaJYMbA9029ocP3BVCg5kj3yGHWYi3M2hJqyOmcxQ","netRole":"sta"},\n{"deviceId":"Azs-ksefien1CA8EYIliu6N6vGrTa3qowqCHKK8Iu0Y","netRole":"sta"}\n]'
  546. dev[1].set("dpp_discovery_override", discovery)
  547. dev[1].set("dpp_groups_override", groups)
  548. dev[1].set("dpp_devices_override", devices)
  549. run_dpp_qr_code_auth_unicast(dev, apdev, "prime256v1",
  550. init_extra="conf=sta-dpp",
  551. require_conf_success=True,
  552. configurator=True)
  553. def test_dpp_gas_timeout(dev, apdev):
  554. """DPP and GAS server timeout for a query"""
  555. check_dpp_capab(dev[0])
  556. check_dpp_capab(dev[1])
  557. logger.info("dev0 displays QR Code")
  558. addr = dev[0].own_addr().replace(':', '')
  559. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  560. res = dev[0].request(cmd)
  561. if "FAIL" in res:
  562. raise Exception("Failed to generate bootstrapping info")
  563. id0 = int(res)
  564. uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  565. logger.info("dev1 scans QR Code")
  566. res = dev[1].request("DPP_QR_CODE " + uri0)
  567. if "FAIL" in res:
  568. raise Exception("Failed to parse QR Code URI")
  569. id1 = int(res)
  570. logger.info("dev1 initiates DPP Authentication")
  571. dev[0].set("ext_mgmt_frame_handling", "1")
  572. cmd = "DPP_LISTEN 2412"
  573. if "OK" not in dev[0].request(cmd):
  574. raise Exception("Failed to start listen operation")
  575. # Force GAS fragmentation
  576. conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' '
  577. dev[1].set("dpp_config_obj_override", conf)
  578. cmd = "DPP_AUTH_INIT peer=%d" % id1
  579. if "OK" not in dev[1].request(cmd):
  580. raise Exception("Failed to initiate DPP Authentication")
  581. # DPP Authentication Request
  582. msg = dev[0].mgmt_rx()
  583. 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'))):
  584. raise Exception("MGMT_RX_PROCESS failed")
  585. # DPP Authentication Confirmation
  586. msg = dev[0].mgmt_rx()
  587. 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'))):
  588. raise Exception("MGMT_RX_PROCESS failed")
  589. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  590. if ev is None:
  591. raise Exception("DPP authentication did not succeed (Responder)")
  592. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  593. if ev is None:
  594. raise Exception("DPP authentication did not succeed (Initiator)")
  595. # DPP Configuration Response (GAS Initial Response frame)
  596. msg = dev[0].mgmt_rx()
  597. 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'))):
  598. raise Exception("MGMT_RX_PROCESS failed")
  599. # GAS Comeback Response frame
  600. msg = dev[0].mgmt_rx()
  601. # Do not continue to force timeout on GAS server
  602. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  603. if ev is None:
  604. raise Exception("GAS result not reported (Enrollee)")
  605. if "result=TIMEOUT" not in ev:
  606. raise Exception("Unexpected GAS result (Enrollee): " + ev)
  607. dev[0].set("ext_mgmt_frame_handling", "0")
  608. ev = dev[1].wait_event(["DPP-CONF-FAILED"], timeout=15)
  609. if ev is None:
  610. raise Exception("DPP configuration failure not reported (Configurator)")
  611. ev = dev[0].wait_event(["DPP-CONF-FAILED"], timeout=1)
  612. if ev is None:
  613. raise Exception("DPP configuration failure not reported (Enrollee)")
  614. def test_dpp_akm_sha256(dev, apdev):
  615. """DPP AKM (SHA256)"""
  616. run_dpp_akm(dev, apdev, 32)
  617. def test_dpp_akm_sha384(dev, apdev):
  618. """DPP AKM (SHA384)"""
  619. run_dpp_akm(dev, apdev, 48)
  620. def test_dpp_akm_sha512(dev, apdev):
  621. """DPP AKM (SHA512)"""
  622. run_dpp_akm(dev, apdev, 64)
  623. def run_dpp_akm(dev, apdev, pmk_len):
  624. check_dpp_capab(dev[0])
  625. check_dpp_capab(dev[1])
  626. params = { "ssid": "dpp",
  627. "wpa": "2",
  628. "wpa_key_mgmt": "DPP",
  629. "rsn_pairwise": "CCMP" }
  630. try:
  631. hapd = hostapd.add_ap(apdev[0], params)
  632. except:
  633. raise HwsimSkip("DPP not supported")
  634. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  635. wait_connect=False)
  636. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=2)
  637. if not ev:
  638. raise Exception("Network mismatch not reported")
  639. dev[0].request("DISCONNECT")
  640. dev[0].dump_monitor()
  641. bssid = hapd.own_addr()
  642. pmkid = 16*'11'
  643. akmp = 2**23
  644. pmk = pmk_len*'22'
  645. cmd = "PMKSA_ADD %d %s %s %s 30240 43200 %d 0" % (id, bssid, pmkid, pmk, akmp)
  646. if "OK" not in dev[0].request(cmd):
  647. raise Exception("PMKSA_ADD failed (wpa_supplicant)")
  648. dev[0].select_network(id, freq="2412")
  649. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  650. dev[0].request("DISCONNECT")
  651. dev[0].dump_monitor()
  652. if not ev:
  653. raise Exception("Association attempt was not rejected")
  654. if "status_code=53" not in ev:
  655. raise Exception("Unexpected status code: " + ev)
  656. addr = dev[0].own_addr()
  657. cmd = "PMKSA_ADD %s %s %s 0 %d" % (addr, pmkid, pmk, akmp)
  658. if "OK" not in hapd.request(cmd):
  659. raise Exception("PMKSA_ADD failed (hostapd)")
  660. dev[0].select_network(id, freq="2412")
  661. dev[0].wait_connected()
  662. def test_dpp_network_introduction(dev, apdev):
  663. """DPP network introduction"""
  664. check_dpp_capab(dev[0])
  665. check_dpp_capab(dev[1])
  666. csign = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d02e5bd81a120762b5f0f2994777f5d40297238a6c294fd575cdf35fabec44c050a6421c401d98d659fd2ed13c961cc8287944dd3202f516977800d3ab2f39ee"
  667. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIwOHF4TlNYRzRWemdCV3BjVUdNSmc1czNvbElOVFJsRVQ1aERpNkRKY3ZjIiwieSI6IlVhaGFYQXpKRVpRQk1YaHRUQnlZZVlrOWtJYjk5UDA3UV9NcW9TVVZTVEkifX0.a5_nfMVr7Qe1SW0ZL3u6oQRm5NUCYUSfixDAJOUFN3XUfECBZ6E8fm8xjeSfdOytgRidTz0CTlIRjzPQo82dmQ"
  668. ap_netaccesskey = "30770201010420f6531d17f29dfab655b7c9e923478d5a345164c489aadd44a3519c3e9dcc792da00a06082a8648ce3d030107a14403420004d3cab13525c6e15ce0056a5c506309839b37a2520d4d19444f98438ba0c972f751a85a5c0cc911940131786d4c1c9879893d9086fdf4fd3b43f32aa125154932"
  669. sta_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJzOEFrYjg5bTV4UGhoYk5UbTVmVVo0eVBzNU5VMkdxYXNRY3hXUWhtQVFRIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6InN0YSJ9XSwibmV0QWNjZXNzS2V5Ijp7Imt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiZWMzR3NqQ3lQMzVBUUZOQUJJdEltQnN4WXVyMGJZX1dES1lfSE9zUGdjNCIsInkiOiJTRS1HVllkdWVnTFhLMU1TQXZNMEx2QWdLREpTNWoyQVhCbE9PMTdUSTRBIn19.PDK9zsGlK-e1pEOmNxVeJfCS8pNeay6ckIS1TXCQsR64AR-9wFPCNVjqOxWvVKltehyMFqVAtOcv0IrjtMJFqQ"
  670. sta_netaccesskey = "30770201010420bc33380c26fd2168b69cd8242ed1df07ba89aa4813f8d4e8523de6ca3f8dd28ba00a06082a8648ce3d030107a1440342000479cdc6b230b23f7e40405340048b48981b3162eaf46d8fd60ca63f1ceb0f81ce484f8655876e7a02d72b531202f3342ef020283252e63d805c194e3b5ed32380"
  671. params = { "ssid": "dpp",
  672. "wpa": "2",
  673. "wpa_key_mgmt": "DPP",
  674. "rsn_pairwise": "CCMP",
  675. "dpp_connector": ap_connector,
  676. "dpp_csign": csign,
  677. "dpp_netaccesskey": ap_netaccesskey }
  678. try:
  679. hapd = hostapd.add_ap(apdev[0], params)
  680. except:
  681. raise HwsimSkip("DPP not supported")
  682. id = dev[0].connect("dpp", key_mgmt="DPP", scan_freq="2412",
  683. dpp_csign=csign,
  684. dpp_connector=sta_connector,
  685. dpp_netaccesskey=sta_netaccesskey)
  686. def test_dpp_ap_config(dev, apdev):
  687. """DPP and AP configuration"""
  688. run_dpp_ap_config(dev, apdev)
  689. def test_dpp_ap_config_p256_p256(dev, apdev):
  690. """DPP and AP configuration (P-256 + P-256)"""
  691. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-256")
  692. def test_dpp_ap_config_p256_p384(dev, apdev):
  693. """DPP and AP configuration (P-256 + P-384)"""
  694. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-384")
  695. def test_dpp_ap_config_p256_p521(dev, apdev):
  696. """DPP and AP configuration (P-256 + P-521)"""
  697. run_dpp_ap_config(dev, apdev, curve="P-256", conf_curve="P-521")
  698. def test_dpp_ap_config_p384_p256(dev, apdev):
  699. """DPP and AP configuration (P-384 + P-256)"""
  700. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-256")
  701. def test_dpp_ap_config_p384_p384(dev, apdev):
  702. """DPP and AP configuration (P-384 + P-384)"""
  703. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-384")
  704. def test_dpp_ap_config_p384_p521(dev, apdev):
  705. """DPP and AP configuration (P-384 + P-521)"""
  706. run_dpp_ap_config(dev, apdev, curve="P-384", conf_curve="P-521")
  707. def test_dpp_ap_config_p521_p256(dev, apdev):
  708. """DPP and AP configuration (P-521 + P-256)"""
  709. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-256")
  710. def test_dpp_ap_config_p521_p384(dev, apdev):
  711. """DPP and AP configuration (P-521 + P-384)"""
  712. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-384")
  713. def test_dpp_ap_config_p521_p521(dev, apdev):
  714. """DPP and AP configuration (P-521 + P-521)"""
  715. run_dpp_ap_config(dev, apdev, curve="P-521", conf_curve="P-521")
  716. def run_dpp_ap_config(dev, apdev, curve=None, conf_curve=None):
  717. check_dpp_capab(dev[0])
  718. check_dpp_capab(dev[1])
  719. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  720. check_dpp_capab(hapd)
  721. addr = hapd.own_addr().replace(':', '')
  722. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  723. if curve:
  724. cmd += " curve=" + curve
  725. res = hapd.request(cmd)
  726. if "FAIL" in res:
  727. raise Exception("Failed to generate bootstrapping info")
  728. id_h = int(res)
  729. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id_h)
  730. cmd = "DPP_CONFIGURATOR_ADD expiry=%d" % (time.time() + 100000)
  731. if conf_curve:
  732. cmd += " curve=" + conf_curve
  733. res = dev[0].request(cmd);
  734. if "FAIL" in res:
  735. raise Exception("Failed to add configurator")
  736. conf_id = int(res)
  737. res = dev[0].request("DPP_QR_CODE " + uri)
  738. if "FAIL" in res:
  739. raise Exception("Failed to parse QR Code URI")
  740. id = int(res)
  741. cmd = "DPP_AUTH_INIT peer=%d conf=ap-dpp configurator=%d" % (id, conf_id)
  742. if "OK" not in dev[0].request(cmd):
  743. raise Exception("Failed to initiate DPP Authentication")
  744. ev = hapd.wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  745. if ev is None:
  746. raise Exception("DPP authentication did not succeed (Responder)")
  747. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  748. if ev is None:
  749. raise Exception("DPP authentication did not succeed (Initiator)")
  750. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  751. if ev is None:
  752. raise Exception("DPP configuration not completed (Configurator)")
  753. ev = hapd.wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"], timeout=5)
  754. if ev is None:
  755. raise Exception("DPP configuration not completed (Enrollee)")
  756. if "DPP-CONF-FAILED" in ev:
  757. raise Exception("DPP configuration failed")
  758. ev = hapd.wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  759. if ev is None:
  760. raise Exception("SSID not reported (AP)")
  761. ssid = ev.split(' ')[1]
  762. ev = hapd.wait_event(["DPP-CONNECTOR"], timeout=1)
  763. if ev is None:
  764. raise Exception("Connector not reported (AP)")
  765. connector = ev.split(' ')[1]
  766. ev = hapd.wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  767. if ev is None:
  768. raise Exception("C-sign-key not reported (AP)")
  769. p = ev.split(' ')
  770. csign = p[1]
  771. csign_expiry = p[2] if len(p) > 2 else None
  772. ev = hapd.wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  773. if ev is None:
  774. raise Exception("netAccessKey not reported (AP)")
  775. p = ev.split(' ')
  776. net_access_key = p[1]
  777. net_access_key_expiry = p[2] if len(p) > 2 else None
  778. logger.info("Update AP configuration to use key_mgmt=DPP")
  779. hapd.disable()
  780. hapd.set("ssid", ssid)
  781. hapd.set("wpa", "2")
  782. hapd.set("wpa_key_mgmt", "DPP")
  783. hapd.set("rsn_pairwise", "CCMP")
  784. hapd.set("dpp_connector", connector)
  785. hapd.set("dpp_csign", csign)
  786. if csign_expiry:
  787. hapd.set("dpp_csign_expiry", csign_expiry)
  788. hapd.set("dpp_netaccesskey", net_access_key)
  789. if net_access_key_expiry:
  790. hapd.set("dpp_netaccesskey_expiry", net_access_key_expiry)
  791. hapd.enable()
  792. addr = dev[1].own_addr().replace(':', '')
  793. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  794. if curve:
  795. cmd += " curve=" + curve
  796. res = dev[1].request(cmd)
  797. if "FAIL" in res:
  798. raise Exception("Failed to generate bootstrapping info")
  799. id1 = int(res)
  800. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  801. res = dev[0].request("DPP_QR_CODE " + uri1)
  802. if "FAIL" in res:
  803. raise Exception("Failed to parse QR Code URI")
  804. id0b = int(res)
  805. cmd = "DPP_LISTEN 2412"
  806. if "OK" not in dev[1].request(cmd):
  807. raise Exception("Failed to start listen operation")
  808. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id0b, conf_id)
  809. if "OK" not in dev[0].request(cmd):
  810. raise Exception("Failed to initiate DPP Authentication")
  811. ev = dev[1].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  812. if ev is None:
  813. raise Exception("DPP authentication did not succeed (Responder)")
  814. ev = dev[0].wait_event(["DPP-AUTH-SUCCESS"], timeout=5)
  815. if ev is None:
  816. raise Exception("DPP authentication did not succeed (Initiator)")
  817. ev = dev[0].wait_event(["DPP-CONF-SENT"], timeout=5)
  818. if ev is None:
  819. raise Exception("DPP configuration not completed (Configurator)")
  820. ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  821. if ev is None:
  822. raise Exception("DPP configuration not completed (Enrollee)")
  823. dev[1].request("DPP_STOP_LISTEN")
  824. ev = dev[1].wait_event(["DPP-CONFOBJ-SSID"], timeout=1)
  825. if ev is None:
  826. raise Exception("SSID not reported")
  827. ssid = ev.split(' ')[1]
  828. ev = dev[1].wait_event(["DPP-CONNECTOR"], timeout=1)
  829. if ev is None:
  830. raise Exception("Connector not reported")
  831. connector = ev.split(' ')[1]
  832. ev = dev[1].wait_event(["DPP-C-SIGN-KEY"], timeout=1)
  833. if ev is None:
  834. raise Exception("C-sign-key not reported")
  835. p = ev.split(' ')
  836. csign = p[1]
  837. csign_expiry = p[2] if len(p) > 2 else None
  838. ev = dev[1].wait_event(["DPP-NET-ACCESS-KEY"], timeout=1)
  839. if ev is None:
  840. raise Exception("netAccessKey not reported")
  841. p = ev.split(' ')
  842. net_access_key = p[1]
  843. net_access_key_expiry = p[2] if len(p) > 2 else None
  844. dev[1].dump_monitor()
  845. id = dev[1].connect(ssid, key_mgmt="DPP", scan_freq="2412",
  846. only_add_network=True)
  847. dev[1].set_network_quoted(id, "dpp_connector", connector)
  848. dev[1].set_network(id, "dpp_csign", csign)
  849. if csign_expiry:
  850. dev[1].set_network(id, "dpp_csign_expiry", csign_expiry)
  851. dev[1].set_network(id, "dpp_netaccesskey", net_access_key)
  852. if net_access_key_expiry:
  853. dev[1].set_network(id, "dpp_netaccess_expiry", net_access_key_expiry)
  854. logger.info("Check data connection")
  855. dev[1].select_network(id, freq="2412")
  856. dev[1].wait_connected()