test_owe.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_and_psk(dev, apdev):
  48. """Opportunistic Wireless Encryption and WPA2-PSK enabled"""
  49. if "OWE" not in dev[0].get_capability("key_mgmt"):
  50. raise HwsimSkip("OWE not supported")
  51. params = { "ssid": "owe+psk",
  52. "wpa": "2",
  53. "wpa_key_mgmt": "OWE WPA-PSK",
  54. "rsn_pairwise": "CCMP",
  55. "wpa_passphrase": "12345678" }
  56. hapd = hostapd.add_ap(apdev[0], params)
  57. bssid = hapd.own_addr()
  58. dev[0].scan_for_bss(bssid, freq="2412")
  59. dev[0].connect("owe+psk", psk="12345678")
  60. hwsim_utils.test_connectivity(dev[0], hapd)
  61. dev[1].scan_for_bss(bssid, freq="2412")
  62. dev[1].connect("owe+psk", key_mgmt="OWE")
  63. hwsim_utils.test_connectivity(dev[1], hapd)
  64. def test_owe_transition_mode(dev, apdev):
  65. """Opportunistic Wireless Encryption transition mode"""
  66. if "OWE" not in dev[0].get_capability("key_mgmt"):
  67. raise HwsimSkip("OWE not supported")
  68. params = { "ssid": "owe-random",
  69. "wpa": "2",
  70. "wpa_key_mgmt": "OWE",
  71. "rsn_pairwise": "CCMP",
  72. "owe_transition_bssid": apdev[1]['bssid'],
  73. "owe_transition_ssid": '"owe-test"',
  74. "ignore_broadcast_ssid": "1" }
  75. hapd = hostapd.add_ap(apdev[0], params)
  76. bssid = hapd.own_addr()
  77. params = { "ssid": "owe-test",
  78. "owe_transition_bssid": apdev[0]['bssid'],
  79. "owe_transition_ssid": '"owe-random"' }
  80. hapd2 = hostapd.add_ap(apdev[1], params)
  81. bssid2 = hapd2.own_addr()
  82. dev[0].scan_for_bss(bssid, freq="2412")
  83. dev[0].scan_for_bss(bssid2, freq="2412")
  84. bss = dev[0].get_bss(bssid)
  85. if "[WPA2-OWE-CCMP]" not in bss['flags']:
  86. raise Exception("OWE AKM not recognized: " + bss['flags'])
  87. if "[OWE-TRANS]" not in bss['flags']:
  88. raise Exception("OWE transition not recognized: " + bss['flags'])
  89. bss = dev[0].get_bss(bssid2)
  90. if "[OWE-TRANS-OPEN]" not in bss['flags']:
  91. raise Exception("OWE transition (open) not recognized: " + bss['flags'])
  92. id = dev[0].connect("owe-test", key_mgmt="OWE")
  93. hwsim_utils.test_connectivity(dev[0], hapd)
  94. val = dev[0].get_status_field("key_mgmt")
  95. if val != "OWE":
  96. raise Exception("Unexpected key_mgmt: " + val)
  97. logger.info("Move to OWE only mode (disable transition mode)")
  98. dev[0].request("DISCONNECT")
  99. dev[0].wait_disconnected()
  100. dev[0].dump_monitor()
  101. hapd2.disable()
  102. hapd.disable()
  103. dev[0].flush_scan_cache()
  104. hapd.set("owe_transition_bssid", "00:00:00:00:00:00")
  105. hapd.set("ignore_broadcast_ssid", '0')
  106. hapd.set("ssid", 'owe-test')
  107. hapd.enable()
  108. dev[0].scan_for_bss(bssid, freq="2412")
  109. dev[0].select_network(id, 2412)
  110. dev[0].wait_connected()
  111. hwsim_utils.test_connectivity(dev[0], hapd)