test_ieee8021x.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. scan_freq="2412")
  23. hwsim_utils.test_connectivity(dev[0], hapd)
  24. def test_ieee8021x_wep40(dev, apdev):
  25. """IEEE 802.1X connection using dynamic WEP40"""
  26. params = hostapd.radius_params()
  27. params["ssid"] = "ieee8021x-wep"
  28. params["ieee8021x"] = "1"
  29. params["wep_key_len_broadcast"] = "5"
  30. params["wep_key_len_unicast"] = "5"
  31. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  32. dev[0].connect("ieee8021x-wep", key_mgmt="IEEE8021X", eap="PSK",
  33. identity="psk.user@example.com",
  34. password_hex="0123456789abcdef0123456789abcdef",
  35. scan_freq="2412")
  36. hwsim_utils.test_connectivity(dev[0], hapd)
  37. def test_ieee8021x_open(dev, apdev):
  38. """IEEE 802.1X connection using open network"""
  39. params = hostapd.radius_params()
  40. params["ssid"] = "ieee8021x-open"
  41. params["ieee8021x"] = "1"
  42. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  43. id = dev[0].connect("ieee8021x-open", key_mgmt="IEEE8021X", eapol_flags="0",
  44. eap="PSK", identity="psk.user@example.com",
  45. password_hex="0123456789abcdef0123456789abcdef",
  46. scan_freq="2412")
  47. hwsim_utils.test_connectivity(dev[0], hapd)
  48. logger.info("Test EAPOL-Logoff")
  49. dev[0].request("LOGOFF")
  50. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  51. if ev is None:
  52. raise Exception("Did not get disconnected")
  53. if "reason=23" not in ev:
  54. raise Exception("Unexpected disconnection reason")
  55. dev[0].request("LOGON")
  56. dev[0].connect_network(id)
  57. hwsim_utils.test_connectivity(dev[0], hapd)
  58. def test_ieee8021x_static_wep40(dev, apdev):
  59. """IEEE 802.1X connection using static WEP40"""
  60. params = hostapd.radius_params()
  61. params["ssid"] = "ieee8021x-wep"
  62. params["ieee8021x"] = "1"
  63. params["wep_key0"] = '"hello"'
  64. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  65. dev[0].connect("ieee8021x-wep", key_mgmt="IEEE8021X", eap="PSK",
  66. identity="psk.user@example.com",
  67. password_hex="0123456789abcdef0123456789abcdef",
  68. wep_key0='"hello"', eapol_flags="0",
  69. scan_freq="2412")
  70. hwsim_utils.test_connectivity(dev[0], hapd)
  71. def test_ieee8021x_proto(dev, apdev):
  72. """IEEE 802.1X and EAPOL supplicant protocol testing"""
  73. params = hostapd.radius_params()
  74. params["ssid"] = "ieee8021x-open"
  75. params["ieee8021x"] = "1"
  76. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  77. bssid = apdev[0]['bssid']
  78. dev[1].request("SET ext_eapol_frame_io 1")
  79. dev[1].connect("ieee8021x-open", key_mgmt="IEEE8021X", eapol_flags="0",
  80. eap="PSK", identity="psk.user@example.com",
  81. password_hex="0123456789abcdef0123456789abcdef",
  82. scan_freq="2412", wait_connect=False)
  83. id = dev[0].connect("ieee8021x-open", key_mgmt="IEEE8021X", eapol_flags="0",
  84. eap="PSK", identity="psk.user@example.com",
  85. password_hex="0123456789abcdef0123456789abcdef",
  86. scan_freq="2412")
  87. ev = dev[1].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  88. start = dev[0].get_mib()
  89. tests = [ "11",
  90. "11223344",
  91. "020000050a93000501",
  92. "020300050a93000501",
  93. "0203002c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  94. "0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  95. "0203002c0100050000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  96. "02aa00050a93000501" ]
  97. for frame in tests:
  98. res = dev[0].request("EAPOL_RX " + bssid + " " + frame)
  99. if "OK" not in res:
  100. raise Exception("EAPOL_RX to wpa_supplicant failed")
  101. dev[1].request("EAPOL_RX " + bssid + " " + frame)
  102. stop = dev[0].get_mib()
  103. logger.info("MIB before test frames: " + str(start))
  104. logger.info("MIB after test frames: " + str(stop))
  105. vals = [ 'dot1xSuppInvalidEapolFramesRx',
  106. 'dot1xSuppEapLengthErrorFramesRx' ]
  107. for val in vals:
  108. if int(stop[val]) <= int(start[val]):
  109. raise Exception(val + " did not increase")