test_owe.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. # Test cases for Opportunistic Wireless Encryption (OWE)
  2. # Copyright (c) 2017, 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. import logging
  7. logger = logging.getLogger()
  8. import time
  9. import hostapd
  10. from wpasupplicant import WpaSupplicant
  11. import hwsim_utils
  12. from utils import HwsimSkip
  13. def test_owe(dev, apdev):
  14. """Opportunistic Wireless Encryption"""
  15. if "OWE" not in dev[0].get_capability("key_mgmt"):
  16. raise HwsimSkip("OWE not supported")
  17. params = { "ssid": "owe",
  18. "wpa": "2",
  19. "wpa_key_mgmt": "OWE",
  20. "rsn_pairwise": "CCMP" }
  21. hapd = hostapd.add_ap(apdev[0], params)
  22. bssid = hapd.own_addr()
  23. dev[0].scan_for_bss(bssid, freq="2412")
  24. bss = dev[0].get_bss(bssid)
  25. if "[WPA2-OWE-CCMP]" not in bss['flags']:
  26. raise Exception("OWE AKM not recognized: " + bss['flags'])
  27. dev[0].connect("owe", key_mgmt="OWE")
  28. hwsim_utils.test_connectivity(dev[0], hapd)
  29. val = dev[0].get_status_field("key_mgmt")
  30. if val != "OWE":
  31. raise Exception("Unexpected key_mgmt: " + val)
  32. def test_owe_groups(dev, apdev):
  33. """Opportunistic Wireless Encryption - DH groups"""
  34. if "OWE" not in dev[0].get_capability("key_mgmt"):
  35. raise HwsimSkip("OWE not supported")
  36. params = { "ssid": "owe",
  37. "wpa": "2",
  38. "wpa_key_mgmt": "OWE",
  39. "rsn_pairwise": "CCMP" }
  40. hapd = hostapd.add_ap(apdev[0], params)
  41. bssid = hapd.own_addr()
  42. dev[0].scan_for_bss(bssid, freq="2412")
  43. for group in [ 19, 20, 21 ]:
  44. dev[0].connect("owe", key_mgmt="OWE", owe_group=str(group))
  45. hwsim_utils.test_connectivity(dev[0], hapd)
  46. dev[0].request("REMOVE_NETWORK all")
  47. dev[0].wait_disconnected()
  48. dev[0].dump_monitor()
  49. def test_owe_pmksa_caching(dev, apdev):
  50. """Opportunistic Wireless Encryption and PMKSA caching"""
  51. run_owe_pmksa_caching(dev, apdev)
  52. def test_owe_pmksa_caching_connect_cmd(dev, apdev):
  53. """Opportunistic Wireless Encryption and PMKSA caching using cfg80211 connect command"""
  54. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  55. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  56. run_owe_pmksa_caching([ wpas ], apdev)
  57. def run_owe_pmksa_caching(dev, apdev):
  58. if "OWE" not in dev[0].get_capability("key_mgmt"):
  59. raise HwsimSkip("OWE not supported")
  60. params = { "ssid": "owe",
  61. "wpa": "2",
  62. "wpa_key_mgmt": "OWE",
  63. "rsn_pairwise": "CCMP" }
  64. hapd = hostapd.add_ap(apdev[0], params)
  65. bssid = hapd.own_addr()
  66. dev[0].scan_for_bss(bssid, freq="2412")
  67. id = dev[0].connect("owe", key_mgmt="OWE")
  68. hwsim_utils.test_connectivity(dev[0], hapd)
  69. pmksa = dev[0].get_pmksa(bssid)
  70. dev[0].request("DISCONNECT")
  71. dev[0].wait_disconnected()
  72. dev[0].dump_monitor()
  73. dev[0].select_network(id, 2412)
  74. dev[0].wait_connected()
  75. hwsim_utils.test_connectivity(dev[0], hapd)
  76. pmksa2 = dev[0].get_pmksa(bssid)
  77. dev[0].request("DISCONNECT")
  78. dev[0].wait_disconnected()
  79. dev[0].dump_monitor()
  80. if "OK" not in hapd.request("PMKSA_FLUSH"):
  81. raise Exception("PMKSA_FLUSH failed")
  82. dev[0].select_network(id, 2412)
  83. dev[0].wait_connected()
  84. hwsim_utils.test_connectivity(dev[0], hapd)
  85. pmksa3 = dev[0].get_pmksa(bssid)
  86. dev[0].request("DISCONNECT")
  87. dev[0].wait_disconnected()
  88. dev[0].dump_monitor()
  89. if pmksa is None or pmksa2 is None or pmksa3 is None:
  90. raise Exception("PMKSA entry missing")
  91. if pmksa['pmkid'] != pmksa2['pmkid']:
  92. raise Exception("Unexpected PMKID change when using PMKSA caching")
  93. if pmksa['pmkid'] == pmksa3['pmkid']:
  94. raise Exception("PMKID did not change after PMKSA cache flush")
  95. def test_owe_and_psk(dev, apdev):
  96. """Opportunistic Wireless Encryption and WPA2-PSK enabled"""
  97. if "OWE" not in dev[0].get_capability("key_mgmt"):
  98. raise HwsimSkip("OWE not supported")
  99. params = { "ssid": "owe+psk",
  100. "wpa": "2",
  101. "wpa_key_mgmt": "OWE WPA-PSK",
  102. "rsn_pairwise": "CCMP",
  103. "wpa_passphrase": "12345678" }
  104. hapd = hostapd.add_ap(apdev[0], params)
  105. bssid = hapd.own_addr()
  106. dev[0].scan_for_bss(bssid, freq="2412")
  107. dev[0].connect("owe+psk", psk="12345678")
  108. hwsim_utils.test_connectivity(dev[0], hapd)
  109. dev[1].scan_for_bss(bssid, freq="2412")
  110. dev[1].connect("owe+psk", key_mgmt="OWE")
  111. hwsim_utils.test_connectivity(dev[1], hapd)
  112. def test_owe_transition_mode(dev, apdev):
  113. """Opportunistic Wireless Encryption transition mode"""
  114. run_owe_transition_mode(dev, apdev)
  115. def test_owe_transition_mode_connect_cmd(dev, apdev):
  116. """Opportunistic Wireless Encryption transition mode using cfg80211 connect command"""
  117. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  118. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  119. run_owe_transition_mode([ wpas ], apdev)
  120. def run_owe_transition_mode(dev, apdev):
  121. if "OWE" not in dev[0].get_capability("key_mgmt"):
  122. raise HwsimSkip("OWE not supported")
  123. dev[0].flush_scan_cache()
  124. params = { "ssid": "owe-random",
  125. "wpa": "2",
  126. "wpa_key_mgmt": "OWE",
  127. "rsn_pairwise": "CCMP",
  128. "ieee80211w": "2",
  129. "owe_transition_bssid": apdev[1]['bssid'],
  130. "owe_transition_ssid": '"owe-test"',
  131. "ignore_broadcast_ssid": "1" }
  132. hapd = hostapd.add_ap(apdev[0], params)
  133. bssid = hapd.own_addr()
  134. params = { "ssid": "owe-test",
  135. "owe_transition_bssid": apdev[0]['bssid'],
  136. "owe_transition_ssid": '"owe-random"' }
  137. hapd2 = hostapd.add_ap(apdev[1], params)
  138. bssid2 = hapd2.own_addr()
  139. dev[0].scan_for_bss(bssid, freq="2412")
  140. dev[0].scan_for_bss(bssid2, freq="2412")
  141. bss = dev[0].get_bss(bssid)
  142. if "[WPA2-OWE-CCMP]" not in bss['flags']:
  143. raise Exception("OWE AKM not recognized: " + bss['flags'])
  144. if "[OWE-TRANS]" not in bss['flags']:
  145. raise Exception("OWE transition not recognized: " + bss['flags'])
  146. bss = dev[0].get_bss(bssid2)
  147. if "[OWE-TRANS-OPEN]" not in bss['flags']:
  148. raise Exception("OWE transition (open) not recognized: " + bss['flags'])
  149. id = dev[0].connect("owe-test", key_mgmt="OWE", ieee80211w="2",
  150. scan_freq="2412")
  151. hwsim_utils.test_connectivity(dev[0], hapd)
  152. val = dev[0].get_status_field("key_mgmt")
  153. if val != "OWE":
  154. raise Exception("Unexpected key_mgmt: " + val)
  155. logger.info("Move to OWE only mode (disable transition mode)")
  156. dev[0].request("DISCONNECT")
  157. dev[0].wait_disconnected()
  158. dev[0].dump_monitor()
  159. hapd2.disable()
  160. hapd.disable()
  161. dev[0].flush_scan_cache()
  162. hapd.set("owe_transition_bssid", "00:00:00:00:00:00")
  163. hapd.set("ignore_broadcast_ssid", '0')
  164. hapd.set("ssid", 'owe-test')
  165. hapd.enable()
  166. dev[0].scan_for_bss(bssid, freq="2412")
  167. dev[0].select_network(id, 2412)
  168. dev[0].wait_connected()
  169. hwsim_utils.test_connectivity(dev[0], hapd)
  170. def test_owe_transition_mode_open_only_ap(dev, apdev):
  171. """Opportunistic Wireless Encryption transition mode connect to open-only AP"""
  172. if "OWE" not in dev[0].get_capability("key_mgmt"):
  173. raise HwsimSkip("OWE not supported")
  174. dev[0].flush_scan_cache()
  175. params = { "ssid": "owe-test-open" }
  176. hapd = hostapd.add_ap(apdev[0], params)
  177. bssid = hapd.own_addr()
  178. dev[0].scan_for_bss(bssid, freq="2412")
  179. bss = dev[0].get_bss(bssid)
  180. id = dev[0].connect("owe-test-open", key_mgmt="OWE", ieee80211w="2",
  181. scan_freq="2412")
  182. hwsim_utils.test_connectivity(dev[0], hapd)
  183. val = dev[0].get_status_field("key_mgmt")
  184. if val != "NONE":
  185. raise Exception("Unexpected key_mgmt: " + val)
  186. def test_owe_transition_mode_multi_bss(dev, apdev):
  187. """Opportunistic Wireless Encryption transition mode (multi BSS)"""
  188. try:
  189. run_owe_transition_mode_multi_bss(dev, apdev)
  190. finally:
  191. dev[0].request("SCAN_INTERVAL 5")
  192. def run_owe_transition_mode_multi_bss(dev, apdev):
  193. if "OWE" not in dev[0].get_capability("key_mgmt"):
  194. raise HwsimSkip("OWE not supported")
  195. ifname1 = apdev[0]['ifname']
  196. ifname2 = apdev[0]['ifname'] + '-2'
  197. hapd1 = hostapd.add_bss(apdev[0], ifname1, 'owe-bss-1.conf')
  198. hapd2 = hostapd.add_bss(apdev[0], ifname2, 'owe-bss-2.conf')
  199. bssid = hapd1.own_addr()
  200. bssid2 = hapd2.own_addr()
  201. # Beaconing with the OWE Transition Mode element can start only once both
  202. # BSSs are enabled, so the very first Beacon frame may go out without this
  203. # element. Wait a bit to avoid getting incomplete scan results.
  204. time.sleep(0.1)
  205. dev[0].request("SCAN_INTERVAL 1")
  206. dev[0].scan_for_bss(bssid2, freq="2412")
  207. dev[0].scan_for_bss(bssid, freq="2412")
  208. dev[0].connect("transition-mode-open", key_mgmt="OWE")
  209. hwsim_utils.test_connectivity(dev[0], hapd2)
  210. val = dev[0].get_status_field("key_mgmt")
  211. if val != "OWE":
  212. raise Exception("Unexpected key_mgmt: " + val)
  213. def test_owe_unsupported_group(dev, apdev):
  214. """Opportunistic Wireless Encryption and unsupported group"""
  215. try:
  216. run_owe_unsupported_group(dev, apdev)
  217. finally:
  218. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  219. def test_owe_unsupported_group_connect_cmd(dev, apdev):
  220. """Opportunistic Wireless Encryption and unsupported group using cfg80211 connect command"""
  221. try:
  222. wpas = None
  223. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  224. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  225. run_owe_unsupported_group([ wpas ], apdev)
  226. finally:
  227. if wpas:
  228. wpas.request("VENDOR_ELEM_REMOVE 13 *")
  229. def run_owe_unsupported_group(dev, apdev):
  230. if "OWE" not in dev[0].get_capability("key_mgmt"):
  231. raise HwsimSkip("OWE not supported")
  232. # Override OWE Dh Parameters element with a payload that uses invalid group
  233. # 0 (and actual group 19 data) to make the AP reject this with the specific
  234. # status code 77.
  235. dev[0].request("VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd")
  236. params = { "ssid": "owe",
  237. "wpa": "2",
  238. "wpa_key_mgmt": "OWE",
  239. "rsn_pairwise": "CCMP" }
  240. hapd = hostapd.add_ap(apdev[0], params)
  241. bssid = hapd.own_addr()
  242. dev[0].scan_for_bss(bssid, freq="2412")
  243. dev[0].connect("owe", key_mgmt="OWE", wait_connect=False)
  244. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  245. dev[0].request("DISCONNECT")
  246. if ev is None:
  247. raise Exception("Association not rejected")
  248. if "status_code=77" not in ev:
  249. raise Exception("Unexpected rejection reason: " + ev)
  250. def test_owe_limited_group_set(dev, apdev):
  251. """Opportunistic Wireless Encryption and limited group set"""
  252. if "OWE" not in dev[0].get_capability("key_mgmt"):
  253. raise HwsimSkip("OWE not supported")
  254. params = { "ssid": "owe",
  255. "wpa": "2",
  256. "wpa_key_mgmt": "OWE",
  257. "rsn_pairwise": "CCMP",
  258. "owe_groups": "20 21" }
  259. hapd = hostapd.add_ap(apdev[0], params)
  260. bssid = hapd.own_addr()
  261. dev[0].scan_for_bss(bssid, freq="2412")
  262. dev[0].connect("owe", key_mgmt="OWE", owe_group="19", wait_connect=False)
  263. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  264. dev[0].request("DISCONNECT")
  265. if ev is None:
  266. raise Exception("Association not rejected")
  267. if "status_code=77" not in ev:
  268. raise Exception("Unexpected rejection reason: " + ev)
  269. dev[0].dump_monitor()
  270. for group in [ 20, 21 ]:
  271. dev[0].connect("owe", key_mgmt="OWE", owe_group=str(group))
  272. dev[0].request("REMOVE_NETWORK all")
  273. dev[0].wait_disconnected()
  274. dev[0].dump_monitor()
  275. def test_owe_group_negotiation(dev, apdev):
  276. """Opportunistic Wireless Encryption and group negotiation"""
  277. run_owe_group_negotiation(dev[0], apdev)
  278. def test_owe_group_negotiation_connect_cmd(dev, apdev):
  279. """Opportunistic Wireless Encryption and group negotiation (connect command)"""
  280. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  281. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  282. run_owe_group_negotiation(wpas, apdev)
  283. def run_owe_group_negotiation(dev, apdev):
  284. if "OWE" not in dev.get_capability("key_mgmt"):
  285. raise HwsimSkip("OWE not supported")
  286. params = { "ssid": "owe",
  287. "wpa": "2",
  288. "wpa_key_mgmt": "OWE",
  289. "rsn_pairwise": "CCMP",
  290. "owe_groups": "21" }
  291. hapd = hostapd.add_ap(apdev[0], params)
  292. bssid = hapd.own_addr()
  293. dev.scan_for_bss(bssid, freq="2412")
  294. dev.connect("owe", key_mgmt="OWE")