test_ap_mixed.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Mixed AP module parameters enabled
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  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. def test_ap_mixed_security(dev, apdev):
  11. """WPA/WPA2 with PSK, EAP, SAE, FT in a single BSS"""
  12. sae = "SAE" in dev[0].get_capability("auth_alg")
  13. ssid = "test-mixed"
  14. passphrase = 'qwertyuiop'
  15. params = hostapd.wpa_mixed_params(ssid=ssid, passphrase=passphrase)
  16. params['wpa_key_mgmt'] = "WPA-PSK WPA-PSK-SHA256 WPA-EAP WPA-EAP-SHA256 SAE FT-PSK FT-EAP FT-SAE"
  17. params["ieee8021x"] = "1"
  18. params["eap_server"] = "1"
  19. params["eap_user_file"] = "auth_serv/eap_user.conf"
  20. params['nas_identifier'] = "nas1.w1.fi"
  21. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  22. dev[0].connect(ssid, key_mgmt="WPA-PSK", proto="WPA", pairwise="TKIP",
  23. psk=passphrase, scan_freq="2412")
  24. dev[1].connect(ssid, key_mgmt="WPA-EAP-SHA256", proto="WPA2", eap="GPSK",
  25. identity="gpsk user",
  26. password="abcdefghijklmnop0123456789abcdef",
  27. scan_freq="2412")
  28. if sae:
  29. dev[2].connect(ssid, psk=passphrase, key_mgmt="SAE", scan_freq="2412")
  30. logger.debug(dev[0].request("SCAN_RESULTS"))
  31. bss = dev[0].get_bss(apdev[0]['bssid'])
  32. logger.debug(bss)
  33. if "[WPA-EAP+PSK-TKIP]" not in bss['flags']:
  34. raise Exception("Unexpected flags (WPA): " + bss['flags'])
  35. if sae and "[WPA2-EAP+PSK+SAE+FT/EAP+FT/PSK+FT/SAE+EAP-SHA256+PSK-SHA256-CCMP]" not in bss['flags']:
  36. raise Exception("Unexpected flags (WPA2): " + bss['flags'])
  37. if dev[0].get_status_field("key_mgmt") != "WPA-PSK":
  38. raise Exception("Unexpected key_mgmt(1)")
  39. if dev[0].get_status_field("pairwise_cipher") != "TKIP":
  40. raise Exception("Unexpected pairwise(1)")
  41. if dev[1].get_status_field("key_mgmt") != "WPA2-EAP-SHA256":
  42. raise Exception("Unexpected key_mgmt(2)")
  43. if sae and dev[2].get_status_field("key_mgmt") != "SAE":
  44. raise Exception("Unexpected key_mgmt(3)")
  45. hwsim_utils.test_connectivity(dev[0], dev[1])
  46. if sae:
  47. hwsim_utils.test_connectivity(dev[1], dev[2])
  48. hwsim_utils.test_connectivity(dev[0], dev[2])
  49. for i in range(3):
  50. if i < 2 or sae:
  51. hwsim_utils.test_connectivity(dev[i], hapd)
  52. dev[i].request("DISCONNECT")
  53. dev[0].connect(ssid, key_mgmt="WPA-PSK WPA-PSK-SHA256", psk=passphrase,
  54. scan_freq="2412")
  55. dev[1].connect(ssid, key_mgmt="WPA-EAP", proto="WPA", eap="GPSK",
  56. identity="gpsk user",
  57. password="abcdefghijklmnop0123456789abcdef",
  58. scan_freq="2412")
  59. if sae:
  60. dev[2].connect(ssid, key_mgmt="WPA-PSK WPA-PSK-SHA256 SAE",
  61. psk=passphrase, scan_freq="2412")
  62. if dev[0].get_status_field("key_mgmt") != "WPA2-PSK-SHA256":
  63. raise Exception("Unexpected key_mgmt(1b)")
  64. if dev[0].get_status_field("pairwise_cipher") != "CCMP":
  65. raise Exception("Unexpected pairwise(1b)")
  66. if dev[1].get_status_field("key_mgmt") != "WPA/IEEE 802.1X/EAP":
  67. raise Exception("Unexpected key_mgmt(2b)")
  68. if sae and dev[2].get_status_field("key_mgmt") != "SAE":
  69. raise Exception("Unexpected key_mgmt(3b)")
  70. for i in range(3):
  71. dev[i].request("DISCONNECT")
  72. dev[0].connect(ssid, key_mgmt="FT-PSK", psk=passphrase, scan_freq="2412")
  73. dev[1].connect(ssid, key_mgmt="FT-EAP", eap="GPSK", identity="gpsk user",
  74. password="abcdefghijklmnop0123456789abcdef",
  75. scan_freq="2412")
  76. if sae:
  77. dev[2].connect(ssid, psk=passphrase, key_mgmt="FT-SAE",
  78. scan_freq="2412")
  79. if dev[0].get_status_field("key_mgmt") != "FT-PSK":
  80. raise Exception("Unexpected key_mgmt(1c)")
  81. if dev[1].get_status_field("key_mgmt") != "FT-EAP":
  82. raise Exception("Unexpected key_mgmt(2c)")
  83. if sae and dev[2].get_status_field("key_mgmt") != "FT-SAE":
  84. raise Exception("Unexpected key_mgmt(3c)")