test_owe.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. params = { "ssid": "owe-random",
  124. "wpa": "2",
  125. "wpa_key_mgmt": "OWE",
  126. "rsn_pairwise": "CCMP",
  127. "owe_transition_bssid": apdev[1]['bssid'],
  128. "owe_transition_ssid": '"owe-test"',
  129. "ignore_broadcast_ssid": "1" }
  130. hapd = hostapd.add_ap(apdev[0], params)
  131. bssid = hapd.own_addr()
  132. params = { "ssid": "owe-test",
  133. "owe_transition_bssid": apdev[0]['bssid'],
  134. "owe_transition_ssid": '"owe-random"' }
  135. hapd2 = hostapd.add_ap(apdev[1], params)
  136. bssid2 = hapd2.own_addr()
  137. dev[0].scan_for_bss(bssid, freq="2412")
  138. dev[0].scan_for_bss(bssid2, freq="2412")
  139. bss = dev[0].get_bss(bssid)
  140. if "[WPA2-OWE-CCMP]" not in bss['flags']:
  141. raise Exception("OWE AKM not recognized: " + bss['flags'])
  142. if "[OWE-TRANS]" not in bss['flags']:
  143. raise Exception("OWE transition not recognized: " + bss['flags'])
  144. bss = dev[0].get_bss(bssid2)
  145. if "[OWE-TRANS-OPEN]" not in bss['flags']:
  146. raise Exception("OWE transition (open) not recognized: " + bss['flags'])
  147. id = dev[0].connect("owe-test", key_mgmt="OWE")
  148. hwsim_utils.test_connectivity(dev[0], hapd)
  149. val = dev[0].get_status_field("key_mgmt")
  150. if val != "OWE":
  151. raise Exception("Unexpected key_mgmt: " + val)
  152. logger.info("Move to OWE only mode (disable transition mode)")
  153. dev[0].request("DISCONNECT")
  154. dev[0].wait_disconnected()
  155. dev[0].dump_monitor()
  156. hapd2.disable()
  157. hapd.disable()
  158. dev[0].flush_scan_cache()
  159. hapd.set("owe_transition_bssid", "00:00:00:00:00:00")
  160. hapd.set("ignore_broadcast_ssid", '0')
  161. hapd.set("ssid", 'owe-test')
  162. hapd.enable()
  163. dev[0].scan_for_bss(bssid, freq="2412")
  164. dev[0].select_network(id, 2412)
  165. dev[0].wait_connected()
  166. hwsim_utils.test_connectivity(dev[0], hapd)
  167. def test_owe_transition_mode_multi_bss(dev, apdev):
  168. """Opportunistic Wireless Encryption transition mode (multi BSS)"""
  169. try:
  170. run_owe_transition_mode_multi_bss(dev, apdev)
  171. finally:
  172. dev[0].request("SCAN_INTERVAL 5")
  173. def run_owe_transition_mode_multi_bss(dev, apdev):
  174. if "OWE" not in dev[0].get_capability("key_mgmt"):
  175. raise HwsimSkip("OWE not supported")
  176. ifname1 = apdev[0]['ifname']
  177. ifname2 = apdev[0]['ifname'] + '-2'
  178. hapd1 = hostapd.add_bss(apdev[0], ifname1, 'owe-bss-1.conf')
  179. hapd2 = hostapd.add_bss(apdev[0], ifname2, 'owe-bss-2.conf')
  180. bssid = hapd1.own_addr()
  181. bssid2 = hapd2.own_addr()
  182. # Beaconing with the OWE Transition Mode element can start only once both
  183. # BSSs are enabled, so the very first Beacon frame may go out without this
  184. # element. Wait a bit to avoid getting incomplete scan results.
  185. time.sleep(0.1)
  186. dev[0].request("SCAN_INTERVAL 1")
  187. dev[0].scan_for_bss(bssid2, freq="2412")
  188. dev[0].scan_for_bss(bssid, freq="2412")
  189. dev[0].connect("transition-mode-open", key_mgmt="OWE")
  190. hwsim_utils.test_connectivity(dev[0], hapd2)
  191. val = dev[0].get_status_field("key_mgmt")
  192. if val != "OWE":
  193. raise Exception("Unexpected key_mgmt: " + val)