test_ap_pmf.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. # Protected management frames tests
  2. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import time
  8. import logging
  9. logger = logging.getLogger()
  10. import hwsim_utils
  11. import hostapd
  12. from utils import alloc_fail, fail_test, wait_fail_trigger
  13. from wlantest import Wlantest
  14. from wpasupplicant import WpaSupplicant
  15. @remote_compatible
  16. def test_ap_pmf_required(dev, apdev):
  17. """WPA2-PSK AP with PMF required"""
  18. ssid = "test-pmf-required"
  19. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  20. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  21. params["ieee80211w"] = "2"
  22. hapd = hostapd.add_ap(apdev[0], params)
  23. Wlantest.setup(hapd)
  24. wt = Wlantest()
  25. wt.flush()
  26. wt.add_passphrase("12345678")
  27. key_mgmt = hapd.get_config()['key_mgmt']
  28. if key_mgmt.split(' ')[0] != "WPA-PSK-SHA256":
  29. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  30. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  31. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  32. scan_freq="2412")
  33. if "[WPA2-PSK-SHA256-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  34. raise Exception("Scan results missing RSN element info")
  35. hwsim_utils.test_connectivity(dev[0], hapd)
  36. dev[1].connect(ssid, psk="12345678", ieee80211w="2",
  37. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  38. scan_freq="2412")
  39. hwsim_utils.test_connectivity(dev[1], hapd)
  40. if "OK" not in hapd.request("SA_QUERY " + dev[0].own_addr()):
  41. raise Exception("SA_QUERY failed")
  42. if "OK" not in hapd.request("SA_QUERY " + dev[1].own_addr()):
  43. raise Exception("SA_QUERY failed")
  44. if "FAIL" not in hapd.request("SA_QUERY foo"):
  45. raise Exception("Invalid SA_QUERY accepted")
  46. wt.require_ap_pmf_mandatory(apdev[0]['bssid'])
  47. wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
  48. wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
  49. time.sleep(0.1)
  50. if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
  51. dev[0].p2p_interface_addr()) < 1:
  52. raise Exception("STA did not reply to SA Query")
  53. if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
  54. dev[1].p2p_interface_addr()) < 1:
  55. raise Exception("STA did not reply to SA Query")
  56. @remote_compatible
  57. def test_ap_pmf_optional(dev, apdev):
  58. """WPA2-PSK AP with PMF optional"""
  59. ssid = "test-pmf-optional"
  60. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  61. params["wpa_key_mgmt"] = "WPA-PSK"
  62. params["ieee80211w"] = "1"
  63. hapd = hostapd.add_ap(apdev[0], params)
  64. Wlantest.setup(hapd)
  65. wt = Wlantest()
  66. wt.flush()
  67. wt.add_passphrase("12345678")
  68. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  69. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  70. scan_freq="2412")
  71. hwsim_utils.test_connectivity(dev[0], hapd)
  72. dev[1].connect(ssid, psk="12345678", ieee80211w="2",
  73. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  74. scan_freq="2412")
  75. hwsim_utils.test_connectivity(dev[1], hapd)
  76. wt.require_ap_pmf_optional(apdev[0]['bssid'])
  77. wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
  78. wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
  79. @remote_compatible
  80. def test_ap_pmf_optional_2akm(dev, apdev):
  81. """WPA2-PSK AP with PMF optional (2 AKMs)"""
  82. ssid = "test-pmf-optional-2akm"
  83. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  84. params["wpa_key_mgmt"] = "WPA-PSK WPA-PSK-SHA256"
  85. params["ieee80211w"] = "1"
  86. hapd = hostapd.add_ap(apdev[0], params)
  87. Wlantest.setup(hapd)
  88. wt = Wlantest()
  89. wt.flush()
  90. wt.add_passphrase("12345678")
  91. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  92. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  93. scan_freq="2412")
  94. hwsim_utils.test_connectivity(dev[0], hapd)
  95. dev[1].connect(ssid, psk="12345678", ieee80211w="2",
  96. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  97. scan_freq="2412")
  98. hwsim_utils.test_connectivity(dev[1], hapd)
  99. wt.require_ap_pmf_optional(apdev[0]['bssid'])
  100. wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
  101. wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[0].p2p_interface_addr(),
  102. "PSK-SHA256")
  103. wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
  104. wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[1].p2p_interface_addr(),
  105. "PSK-SHA256")
  106. @remote_compatible
  107. def test_ap_pmf_negative(dev, apdev):
  108. """WPA2-PSK AP without PMF (negative test)"""
  109. ssid = "test-pmf-negative"
  110. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  111. hapd = hostapd.add_ap(apdev[0], params)
  112. Wlantest.setup(hapd)
  113. wt = Wlantest()
  114. wt.flush()
  115. wt.add_passphrase("12345678")
  116. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  117. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  118. scan_freq="2412")
  119. hwsim_utils.test_connectivity(dev[0], hapd)
  120. try:
  121. dev[1].connect(ssid, psk="12345678", ieee80211w="2",
  122. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  123. scan_freq="2412")
  124. hwsim_utils.test_connectivity(dev[1], hapd)
  125. raise Exception("PMF required STA connected to no PMF AP")
  126. except Exception, e:
  127. logger.debug("Ignore expected exception: " + str(e))
  128. wt.require_ap_no_pmf(apdev[0]['bssid'])
  129. @remote_compatible
  130. def test_ap_pmf_assoc_comeback(dev, apdev):
  131. """WPA2-PSK AP with PMF association comeback"""
  132. ssid = "assoc-comeback"
  133. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  134. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  135. params["ieee80211w"] = "2"
  136. hapd = hostapd.add_ap(apdev[0], params)
  137. Wlantest.setup(hapd)
  138. wt = Wlantest()
  139. wt.flush()
  140. wt.add_passphrase("12345678")
  141. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  142. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  143. scan_freq="2412")
  144. hapd.set("ext_mgmt_frame_handling", "1")
  145. dev[0].request("DISCONNECT")
  146. dev[0].wait_disconnected(timeout=10)
  147. hapd.set("ext_mgmt_frame_handling", "0")
  148. dev[0].request("REASSOCIATE")
  149. dev[0].wait_connected(timeout=10, error="Timeout on re-connection")
  150. if wt.get_sta_counter("assocresp_comeback", apdev[0]['bssid'],
  151. dev[0].p2p_interface_addr()) < 1:
  152. raise Exception("AP did not use association comeback request")
  153. @remote_compatible
  154. def test_ap_pmf_assoc_comeback2(dev, apdev):
  155. """WPA2-PSK AP with PMF association comeback (using DROP_SA)"""
  156. ssid = "assoc-comeback"
  157. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  158. params["wpa_key_mgmt"] = "WPA-PSK"
  159. params["ieee80211w"] = "1"
  160. hapd = hostapd.add_ap(apdev[0], params)
  161. Wlantest.setup(hapd)
  162. wt = Wlantest()
  163. wt.flush()
  164. wt.add_passphrase("12345678")
  165. dev[0].connect(ssid, psk="12345678", ieee80211w="2",
  166. key_mgmt="WPA-PSK", proto="WPA2", scan_freq="2412")
  167. if "OK" not in dev[0].request("DROP_SA"):
  168. raise Exception("DROP_SA failed")
  169. dev[0].request("REASSOCIATE")
  170. dev[0].wait_connected(timeout=10, error="Timeout on re-connection")
  171. if wt.get_sta_counter("reassocresp_comeback", apdev[0]['bssid'],
  172. dev[0].p2p_interface_addr()) < 1:
  173. raise Exception("AP did not use reassociation comeback request")
  174. def start_wpas_ap(ssid):
  175. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  176. wpas.interface_add("wlan5", drv_params="use_monitor=1")
  177. id = wpas.add_network()
  178. wpas.set_network(id, "mode", "2")
  179. wpas.set_network_quoted(id, "ssid", ssid)
  180. wpas.set_network(id, "proto", "WPA2")
  181. wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256")
  182. wpas.set_network(id, "ieee80211w", "2")
  183. wpas.set_network_quoted(id, "psk", "12345678")
  184. wpas.set_network(id, "pairwise", "CCMP")
  185. wpas.set_network(id, "group", "CCMP")
  186. wpas.set_network(id, "frequency", "2412")
  187. wpas.set_network(id, "scan_freq", "2412")
  188. wpas.connect_network(id)
  189. wpas.dump_monitor()
  190. return wpas
  191. def test_ap_pmf_sta_sa_query(dev, apdev):
  192. """WPA2-PSK AP with station using SA Query"""
  193. ssid = "assoc-comeback"
  194. addr = dev[0].own_addr()
  195. wpas = start_wpas_ap(ssid)
  196. bssid = wpas.own_addr()
  197. Wlantest.setup(wpas)
  198. wt = Wlantest()
  199. wt.flush()
  200. wt.add_passphrase("12345678")
  201. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  202. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  203. scan_freq="2412")
  204. wpas.dump_monitor()
  205. wpas.request("DEAUTHENTICATE " + addr + " test=0")
  206. wpas.dump_monitor()
  207. wpas.request("DISASSOCIATE " + addr + " test=0")
  208. wpas.dump_monitor()
  209. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  210. if ev is not None:
  211. raise Exception("Unexpected disconnection")
  212. wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
  213. wpas.dump_monitor()
  214. wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
  215. wpas.dump_monitor()
  216. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  217. if ev is not None:
  218. raise Exception("Unexpected disconnection")
  219. if wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) < 1:
  220. raise Exception("STA did not send SA Query")
  221. if wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) < 1:
  222. raise Exception("AP did not reply to SA Query")
  223. wpas.dump_monitor()
  224. def test_ap_pmf_sta_sa_query_no_response(dev, apdev):
  225. """WPA2-PSK AP with station using SA Query and getting no response"""
  226. ssid = "assoc-comeback"
  227. addr = dev[0].own_addr()
  228. wpas = start_wpas_ap(ssid)
  229. bssid = wpas.own_addr()
  230. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  231. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  232. scan_freq="2412")
  233. wpas.dump_monitor()
  234. wpas.request("DEAUTHENTICATE " + addr + " test=0")
  235. wpas.dump_monitor()
  236. wpas.request("DISASSOCIATE " + addr + " test=0")
  237. wpas.dump_monitor()
  238. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  239. if ev is not None:
  240. raise Exception("Unexpected disconnection")
  241. wpas.request("SET ext_mgmt_frame_handling 1")
  242. wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
  243. wpas.dump_monitor()
  244. wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
  245. wpas.dump_monitor()
  246. dev[0].wait_disconnected()
  247. wpas.dump_monitor()
  248. wpas.request("SET ext_mgmt_frame_handling 0")
  249. dev[0].wait_connected()
  250. wpas.dump_monitor()
  251. def test_ap_pmf_sta_unprot_deauth_burst(dev, apdev):
  252. """WPA2-PSK AP with station receiving burst of unprotected Deauthentication frames"""
  253. ssid = "deauth-attack"
  254. addr = dev[0].own_addr()
  255. wpas = start_wpas_ap(ssid)
  256. bssid = wpas.own_addr()
  257. Wlantest.setup(wpas)
  258. wt = Wlantest()
  259. wt.flush()
  260. wt.add_passphrase("12345678")
  261. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  262. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  263. scan_freq="2412")
  264. for i in range(0, 10):
  265. wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
  266. wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
  267. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  268. if ev is not None:
  269. raise Exception("Unexpected disconnection")
  270. num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr)
  271. num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr)
  272. if num_req < 1:
  273. raise Exception("STA did not send SA Query")
  274. if num_resp < 1:
  275. raise Exception("AP did not reply to SA Query")
  276. if num_req > 1:
  277. raise Exception("STA initiated too many SA Query procedures (%d)" % num_req)
  278. time.sleep(10)
  279. for i in range(0, 5):
  280. wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
  281. wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
  282. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  283. if ev is not None:
  284. raise Exception("Unexpected disconnection")
  285. num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr)
  286. num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr)
  287. if num_req != 2 or num_resp != 2:
  288. raise Exception("Unexpected number of SA Query procedures (req=%d resp=%d)" % (num_req, num_resp))
  289. def test_ap_pmf_sta_sa_query_oom(dev, apdev):
  290. """WPA2-PSK AP with station using SA Query (OOM)"""
  291. ssid = "assoc-comeback"
  292. addr = dev[0].own_addr()
  293. wpas = start_wpas_ap(ssid)
  294. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  295. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  296. scan_freq="2412")
  297. with alloc_fail(dev[0], 1, "=sme_sa_query_timer"):
  298. wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
  299. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  300. dev[0].request("DISCONNECT")
  301. wpas.request("DISCONNECT")
  302. dev[0].wait_disconnected()
  303. def test_ap_pmf_sta_sa_query_local_failure(dev, apdev):
  304. """WPA2-PSK AP with station using SA Query (local failure)"""
  305. ssid = "assoc-comeback"
  306. addr = dev[0].own_addr()
  307. wpas = start_wpas_ap(ssid)
  308. dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  309. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  310. scan_freq="2412")
  311. with fail_test(dev[0], 1, "os_get_random;sme_sa_query_timer"):
  312. wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
  313. wait_fail_trigger(dev[0], "GET_FAIL")
  314. dev[0].request("DISCONNECT")
  315. wpas.request("DISCONNECT")
  316. dev[0].wait_disconnected()
  317. def test_ap_pmf_required_eap(dev, apdev):
  318. """WPA2-EAP AP with PMF required"""
  319. ssid = "test-pmf-required-eap"
  320. params = hostapd.wpa2_eap_params(ssid=ssid)
  321. params["wpa_key_mgmt"] = "WPA-EAP-SHA256"
  322. params["ieee80211w"] = "2"
  323. hapd = hostapd.add_ap(apdev[0], params)
  324. key_mgmt = hapd.get_config()['key_mgmt']
  325. if key_mgmt.split(' ')[0] != "WPA-EAP-SHA256":
  326. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  327. dev[0].connect("test-pmf-required-eap", key_mgmt="WPA-EAP-SHA256",
  328. ieee80211w="2", eap="PSK", identity="psk.user@example.com",
  329. password_hex="0123456789abcdef0123456789abcdef",
  330. scan_freq="2412")
  331. dev[1].connect("test-pmf-required-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  332. ieee80211w="1", eap="PSK", identity="psk.user@example.com",
  333. password_hex="0123456789abcdef0123456789abcdef",
  334. scan_freq="2412")
  335. def test_ap_pmf_optional_eap(dev, apdev):
  336. """WPA2EAP AP with PMF optional"""
  337. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  338. params["ieee80211w"] = "1"
  339. hapd = hostapd.add_ap(apdev[0], params)
  340. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  341. identity="pap user", anonymous_identity="ttls",
  342. password="password",
  343. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  344. ieee80211w="1", scan_freq="2412")
  345. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  346. eap="TTLS", identity="pap user", anonymous_identity="ttls",
  347. password="password",
  348. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  349. ieee80211w="2", scan_freq="2412")
  350. @remote_compatible
  351. def test_ap_pmf_required_sha1(dev, apdev):
  352. """WPA2-PSK AP with PMF required with SHA1 AKM"""
  353. ssid = "test-pmf-required-sha1"
  354. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  355. params["wpa_key_mgmt"] = "WPA-PSK"
  356. params["ieee80211w"] = "2"
  357. hapd = hostapd.add_ap(apdev[0], params)
  358. Wlantest.setup(hapd)
  359. wt = Wlantest()
  360. wt.flush()
  361. wt.add_passphrase("12345678")
  362. key_mgmt = hapd.get_config()['key_mgmt']
  363. if key_mgmt.split(' ')[0] != "WPA-PSK":
  364. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  365. dev[0].connect(ssid, psk="12345678", ieee80211w="2",
  366. key_mgmt="WPA-PSK", proto="WPA2", scan_freq="2412")
  367. if "[WPA2-PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  368. raise Exception("Scan results missing RSN element info")
  369. hwsim_utils.test_connectivity(dev[0], hapd)
  370. @remote_compatible
  371. def test_ap_pmf_toggle(dev, apdev):
  372. """WPA2-PSK AP with PMF optional and changing PMF on reassociation"""
  373. try:
  374. _test_ap_pmf_toggle(dev, apdev)
  375. finally:
  376. dev[0].request("SET reassoc_same_bss_optim 0")
  377. def _test_ap_pmf_toggle(dev, apdev):
  378. ssid = "test-pmf-optional"
  379. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  380. params["wpa_key_mgmt"] = "WPA-PSK"
  381. params["ieee80211w"] = "1"
  382. params["assoc_sa_query_max_timeout"] = "1"
  383. params["assoc_sa_query_retry_timeout"] = "1"
  384. hapd = hostapd.add_ap(apdev[0], params)
  385. Wlantest.setup(hapd)
  386. wt = Wlantest()
  387. wt.flush()
  388. wt.add_passphrase("12345678")
  389. bssid = apdev[0]['bssid']
  390. addr = dev[0].own_addr()
  391. dev[0].request("SET reassoc_same_bss_optim 1")
  392. id = dev[0].connect(ssid, psk="12345678", ieee80211w="1",
  393. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  394. scan_freq="2412")
  395. wt.require_ap_pmf_optional(bssid)
  396. wt.require_sta_pmf(bssid, addr)
  397. sta = hapd.get_sta(addr)
  398. if '[MFP]' not in sta['flags']:
  399. raise Exception("MFP flag not present for STA")
  400. dev[0].set_network(id, "ieee80211w", "0")
  401. dev[0].request("REASSOCIATE")
  402. dev[0].wait_connected()
  403. wt.require_sta_no_pmf(bssid, addr)
  404. sta = hapd.get_sta(addr)
  405. if '[MFP]' in sta['flags']:
  406. raise Exception("MFP flag unexpectedly present for STA")
  407. err, data = hapd.cmd_execute(['iw', 'dev', apdev[0]['ifname'], 'station',
  408. 'get', addr])
  409. if "yes" in [l for l in data.splitlines() if "MFP" in l][0]:
  410. raise Exception("Kernel STA entry had MFP enabled")
  411. dev[0].set_network(id, "ieee80211w", "1")
  412. dev[0].request("REASSOCIATE")
  413. dev[0].wait_connected()
  414. wt.require_sta_pmf(bssid, addr)
  415. sta = hapd.get_sta(addr)
  416. if '[MFP]' not in sta['flags']:
  417. raise Exception("MFP flag not present for STA")
  418. err, data = hapd.cmd_execute(['iw', 'dev', apdev[0]['ifname'], 'station',
  419. 'get', addr])
  420. if "yes" not in [l for l in data.splitlines() if "MFP" in l][0]:
  421. raise Exception("Kernel STA entry did not have MFP enabled")
  422. @remote_compatible
  423. def test_ap_pmf_required_sta_no_pmf(dev, apdev):
  424. """WPA2-PSK AP with PMF required and PMF disabled on STA"""
  425. ssid = "test-pmf-required"
  426. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  427. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  428. params["ieee80211w"] = "2"
  429. hapd = hostapd.add_ap(apdev[0], params)
  430. # Disable PMF on the station and try to connect
  431. dev[0].connect(ssid, psk="12345678", ieee80211w="0",
  432. key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
  433. scan_freq="2412", wait_connect=False)
  434. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
  435. "CTRL-EVENT-ASSOC-REJECT"], timeout=2)
  436. if ev is None:
  437. raise Exception("No connection result")
  438. if "CTRL-EVENT-ASSOC-REJECT" in ev:
  439. raise Exception("Tried to connect to PMF required AP without PMF enabled")
  440. dev[0].request("REMOVE_NETWORK all")
  441. def test_ap_pmf_inject_auth(dev, apdev):
  442. """WPA2-PSK AP with PMF and Authentication frame injection"""
  443. ssid = "test-pmf"
  444. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  445. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  446. params["ieee80211w"] = "2"
  447. hapd = hostapd.add_ap(apdev[0], params)
  448. dev[0].connect(ssid, psk="12345678", ieee80211w="2",
  449. key_mgmt="WPA-PSK-SHA256", proto="WPA2",
  450. scan_freq="2412")
  451. hwsim_utils.test_connectivity(dev[0], hapd)
  452. bssid = hapd.own_addr().replace(':', '')
  453. addr = dev[0].own_addr().replace(':', '')
  454. # Inject an unprotected Authentication frame claiming to be from the
  455. # associated STA.
  456. auth = "b0003a01" + bssid + addr + bssid + '1000000001000000'
  457. hapd.request("SET ext_mgmt_frame_handling 1")
  458. res = hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % auth)
  459. hapd.request("SET ext_mgmt_frame_handling 0")
  460. if "OK" not in res:
  461. raise Exception("MGMT_RX_PROCESS failed")
  462. # Verify that original association is still functional.
  463. hwsim_utils.test_connectivity(dev[0], hapd)
  464. def test_ap_pmf_tkip_reject(dev, apdev):
  465. """Mixed mode BSS and MFP-enabled AP rejecting TKIP"""
  466. params = hostapd.wpa2_params(ssid="test-pmf", passphrase="12345678")
  467. params['wpa'] = '3'
  468. params["ieee80211w"] = "1"
  469. params["wpa_pairwise"] = "TKIP CCMP"
  470. params["rsn_pairwise"] = "TKIP CCMP"
  471. hostapd.add_ap(apdev[0], params)
  472. dev[0].connect("test-pmf", psk="12345678", pairwise="CCMP", ieee80211w="2",
  473. scan_freq="2412")
  474. dev[0].dump_monitor()
  475. dev[1].connect("test-pmf", psk="12345678", proto="WPA", pairwise="TKIP",
  476. ieee80211w="0", scan_freq="2412")
  477. dev[1].dump_monitor()
  478. dev[2].connect("test-pmf", psk="12345678", pairwise="TKIP",
  479. ieee80211w="2", scan_freq="2412", wait_connect=False)
  480. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED",
  481. "CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  482. if ev is None:
  483. raise Exception("No connection result reported")
  484. if "CTRL-EVENT-ASSOC-REJECT" not in ev:
  485. raise Exception("MFP + TKIP connection was not rejected")
  486. if "status_code=31" not in ev:
  487. raise Exception("Unexpected status code in rejection: " + ev)
  488. dev[2].request("DISCONNECT")
  489. dev[2].dump_monitor()