test_ieee8021x.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # IEEE 802.1X tests
  2. # Copyright (c) 2013, 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. import time
  8. import hostapd
  9. import hwsim_utils
  10. logger = logging.getLogger()
  11. def test_ieee8021x_wep104(dev, apdev):
  12. """IEEE 802.1X connection using dynamic WEP104"""
  13. params = hostapd.radius_params()
  14. params["ssid"] = "ieee8021x-wep"
  15. params["ieee8021x"] = "1"
  16. params["wep_key_len_broadcast"] = "13"
  17. params["wep_key_len_unicast"] = "13"
  18. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  19. dev[0].connect("ieee8021x-wep", key_mgmt="IEEE8021X", eap="PSK",
  20. identity="psk.user@example.com",
  21. password_hex="0123456789abcdef0123456789abcdef")
  22. hwsim_utils.test_connectivity(dev[0], hapd)
  23. def test_ieee8021x_wep40(dev, apdev):
  24. """IEEE 802.1X connection using dynamic WEP40"""
  25. params = hostapd.radius_params()
  26. params["ssid"] = "ieee8021x-wep"
  27. params["ieee8021x"] = "1"
  28. params["wep_key_len_broadcast"] = "5"
  29. params["wep_key_len_unicast"] = "5"
  30. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  31. dev[0].connect("ieee8021x-wep", key_mgmt="IEEE8021X", eap="PSK",
  32. identity="psk.user@example.com",
  33. password_hex="0123456789abcdef0123456789abcdef")
  34. hwsim_utils.test_connectivity(dev[0], hapd)
  35. def test_ieee8021x_open(dev, apdev):
  36. """IEEE 802.1X connection using open network"""
  37. params = hostapd.radius_params()
  38. params["ssid"] = "ieee8021x-open"
  39. params["ieee8021x"] = "1"
  40. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  41. id = dev[0].connect("ieee8021x-open", key_mgmt="IEEE8021X", eapol_flags="0",
  42. eap="PSK", identity="psk.user@example.com",
  43. password_hex="0123456789abcdef0123456789abcdef")
  44. hwsim_utils.test_connectivity(dev[0], hapd)
  45. logger.info("Test EAPOL-Logoff")
  46. dev[0].request("LOGOFF")
  47. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  48. if ev is None:
  49. raise Exception("Did not get disconnected")
  50. if "reason=23" not in ev:
  51. raise Exception("Unexpected disconnection reason")
  52. dev[0].request("LOGON")
  53. dev[0].connect_network(id)
  54. hwsim_utils.test_connectivity(dev[0], hapd)