test_owe.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 hostapd
  9. import hwsim_utils
  10. from utils import HwsimSkip
  11. def test_owe(dev, apdev):
  12. """Opportunistic Wireless Encryption"""
  13. if "OWE" not in dev[0].get_capability("key_mgmt"):
  14. raise HwsimSkip("OWE not supported")
  15. params = { "ssid": "owe",
  16. "wpa": "2",
  17. "wpa_key_mgmt": "OWE",
  18. "rsn_pairwise": "CCMP" }
  19. hapd = hostapd.add_ap(apdev[0], params)
  20. bssid = hapd.own_addr()
  21. dev[0].scan_for_bss(bssid, freq="2412")
  22. bss = dev[0].get_bss(bssid)
  23. if "[WPA2-OWE-CCMP]" not in bss['flags']:
  24. raise Exception("OWE AKM not recognized: " + bss['flags'])
  25. dev[0].connect("owe", key_mgmt="OWE")
  26. hwsim_utils.test_connectivity(dev[0], hapd)
  27. val = dev[0].get_status_field("key_mgmt")
  28. if val != "OWE":
  29. raise Exception("Unexpected key_mgmt: " + val)
  30. def test_owe_groups(dev, apdev):
  31. """Opportunistic Wireless Encryption - DH groups"""
  32. if "OWE" not in dev[0].get_capability("key_mgmt"):
  33. raise HwsimSkip("OWE not supported")
  34. params = { "ssid": "owe",
  35. "wpa": "2",
  36. "wpa_key_mgmt": "OWE",
  37. "rsn_pairwise": "CCMP" }
  38. hapd = hostapd.add_ap(apdev[0], params)
  39. bssid = hapd.own_addr()
  40. dev[0].scan_for_bss(bssid, freq="2412")
  41. for group in [ 19, 20, 21 ]:
  42. dev[0].connect("owe", key_mgmt="OWE", owe_group=str(group))
  43. hwsim_utils.test_connectivity(dev[0], hapd)
  44. dev[0].request("REMOVE_NETWORK all")
  45. dev[0].wait_disconnected()
  46. dev[0].dump_monitor()
  47. def test_owe_pmksa_caching(dev, apdev):
  48. """Opportunistic Wireless Encryption and PMKSA caching"""
  49. if "OWE" not in dev[0].get_capability("key_mgmt"):
  50. raise HwsimSkip("OWE not supported")
  51. params = { "ssid": "owe",
  52. "wpa": "2",
  53. "wpa_key_mgmt": "OWE",
  54. "rsn_pairwise": "CCMP" }
  55. hapd = hostapd.add_ap(apdev[0], params)
  56. bssid = hapd.own_addr()
  57. dev[0].scan_for_bss(bssid, freq="2412")
  58. id = dev[0].connect("owe", key_mgmt="OWE")
  59. hwsim_utils.test_connectivity(dev[0], hapd)
  60. pmksa = dev[0].get_pmksa(bssid)
  61. dev[0].request("DISCONNECT")
  62. dev[0].wait_disconnected()
  63. dev[0].dump_monitor()
  64. dev[0].select_network(id, 2412)
  65. dev[0].wait_connected()
  66. hwsim_utils.test_connectivity(dev[0], hapd)
  67. pmksa2 = dev[0].get_pmksa(bssid)
  68. dev[0].request("DISCONNECT")
  69. dev[0].wait_disconnected()
  70. dev[0].dump_monitor()
  71. if "OK" not in hapd.request("PMKSA_FLUSH"):
  72. raise Exception("PMKSA_FLUSH failed")
  73. dev[0].select_network(id, 2412)
  74. dev[0].wait_connected()
  75. hwsim_utils.test_connectivity(dev[0], hapd)
  76. pmksa3 = dev[0].get_pmksa(bssid)
  77. dev[0].request("DISCONNECT")
  78. dev[0].wait_disconnected()
  79. dev[0].dump_monitor()
  80. if pmksa is None or pmksa2 is None or pmksa3 is None:
  81. raise Exception("PMKSA entry missing")
  82. if pmksa['pmkid'] != pmksa2['pmkid']:
  83. raise Exception("Unexpected PMKID change when using PMKSA caching")
  84. if pmksa['pmkid'] == pmksa3['pmkid']:
  85. raise Exception("PMKID did not change after PMKSA cache flush")
  86. def test_owe_and_psk(dev, apdev):
  87. """Opportunistic Wireless Encryption and WPA2-PSK enabled"""
  88. if "OWE" not in dev[0].get_capability("key_mgmt"):
  89. raise HwsimSkip("OWE not supported")
  90. params = { "ssid": "owe+psk",
  91. "wpa": "2",
  92. "wpa_key_mgmt": "OWE WPA-PSK",
  93. "rsn_pairwise": "CCMP",
  94. "wpa_passphrase": "12345678" }
  95. hapd = hostapd.add_ap(apdev[0], params)
  96. bssid = hapd.own_addr()
  97. dev[0].scan_for_bss(bssid, freq="2412")
  98. dev[0].connect("owe+psk", psk="12345678")
  99. hwsim_utils.test_connectivity(dev[0], hapd)
  100. dev[1].scan_for_bss(bssid, freq="2412")
  101. dev[1].connect("owe+psk", key_mgmt="OWE")
  102. hwsim_utils.test_connectivity(dev[1], hapd)
  103. def test_owe_transition_mode(dev, apdev):
  104. """Opportunistic Wireless Encryption transition mode"""
  105. if "OWE" not in dev[0].get_capability("key_mgmt"):
  106. raise HwsimSkip("OWE not supported")
  107. params = { "ssid": "owe-random",
  108. "wpa": "2",
  109. "wpa_key_mgmt": "OWE",
  110. "rsn_pairwise": "CCMP",
  111. "owe_transition_bssid": apdev[1]['bssid'],
  112. "owe_transition_ssid": '"owe-test"',
  113. "ignore_broadcast_ssid": "1" }
  114. hapd = hostapd.add_ap(apdev[0], params)
  115. bssid = hapd.own_addr()
  116. params = { "ssid": "owe-test",
  117. "owe_transition_bssid": apdev[0]['bssid'],
  118. "owe_transition_ssid": '"owe-random"' }
  119. hapd2 = hostapd.add_ap(apdev[1], params)
  120. bssid2 = hapd2.own_addr()
  121. dev[0].scan_for_bss(bssid, freq="2412")
  122. dev[0].scan_for_bss(bssid2, freq="2412")
  123. bss = dev[0].get_bss(bssid)
  124. if "[WPA2-OWE-CCMP]" not in bss['flags']:
  125. raise Exception("OWE AKM not recognized: " + bss['flags'])
  126. if "[OWE-TRANS]" not in bss['flags']:
  127. raise Exception("OWE transition not recognized: " + bss['flags'])
  128. bss = dev[0].get_bss(bssid2)
  129. if "[OWE-TRANS-OPEN]" not in bss['flags']:
  130. raise Exception("OWE transition (open) not recognized: " + bss['flags'])
  131. id = dev[0].connect("owe-test", key_mgmt="OWE")
  132. hwsim_utils.test_connectivity(dev[0], hapd)
  133. val = dev[0].get_status_field("key_mgmt")
  134. if val != "OWE":
  135. raise Exception("Unexpected key_mgmt: " + val)
  136. logger.info("Move to OWE only mode (disable transition mode)")
  137. dev[0].request("DISCONNECT")
  138. dev[0].wait_disconnected()
  139. dev[0].dump_monitor()
  140. hapd2.disable()
  141. hapd.disable()
  142. dev[0].flush_scan_cache()
  143. hapd.set("owe_transition_bssid", "00:00:00:00:00:00")
  144. hapd.set("ignore_broadcast_ssid", '0')
  145. hapd.set("ssid", 'owe-test')
  146. hapd.enable()
  147. dev[0].scan_for_bss(bssid, freq="2412")
  148. dev[0].select_network(id, 2412)
  149. dev[0].wait_connected()
  150. hwsim_utils.test_connectivity(dev[0], hapd)