test_wep.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # WEP tests
  2. # Copyright (c) 2014, 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 hostapd
  7. import hwsim_utils
  8. def test_wep_open_auth(dev, apdev):
  9. """WEP Open System authentication"""
  10. hapd = hostapd.add_ap(apdev[0]['ifname'],
  11. { "ssid": "wep-open",
  12. "wep_key0": '"hello"' })
  13. dev[0].connect("wep-open", key_mgmt="NONE", wep_key0='"hello"',
  14. scan_freq="2412")
  15. hwsim_utils.test_connectivity(dev[0], hapd)
  16. if "[WEP]" not in dev[0].request("SCAN_RESULTS"):
  17. raise Exception("WEP flag not indicated in scan results")
  18. def test_wep_shared_key_auth(dev, apdev):
  19. """WEP Shared Key authentication"""
  20. hapd = hostapd.add_ap(apdev[0]['ifname'],
  21. { "ssid": "wep-shared-key",
  22. "wep_key0": '"hello12345678"',
  23. "auth_algs": "2" })
  24. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  25. wep_key0='"hello12345678"',
  26. scan_freq="2412")
  27. hwsim_utils.test_connectivity(dev[0], hapd)
  28. dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
  29. wep_key0='"hello12345678"',
  30. scan_freq="2412")
  31. def test_wep_shared_key_auth_not_allowed(dev, apdev):
  32. """WEP Shared Key authentication not allowed"""
  33. hostapd.add_ap(apdev[0]['ifname'],
  34. { "ssid": "wep-shared-key",
  35. "wep_key0": '"hello12345678"',
  36. "auth_algs": "1" })
  37. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  38. wep_key0='"hello12345678"',
  39. scan_freq="2412", wait_connect=False)
  40. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  41. if ev is not None:
  42. raise Exception("Unexpected association")
  43. def test_wep_shared_key_auth_multi_key(dev, apdev):
  44. """WEP Shared Key authentication with multiple keys"""
  45. hapd = hostapd.add_ap(apdev[0]['ifname'],
  46. { "ssid": "wep-shared-key",
  47. "wep_key0": '"hello12345678"',
  48. "wep_key1": '"other12345678"',
  49. "auth_algs": "2" })
  50. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  51. wep_key0='"hello12345678"',
  52. scan_freq="2412")
  53. dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  54. wep_key0='"hello12345678"',
  55. wep_key1='"other12345678"',
  56. wep_tx_keyidx="1",
  57. scan_freq="2412")
  58. id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  59. wep_key0='"hello12345678"',
  60. wep_key1='"other12345678"',
  61. wep_tx_keyidx="0",
  62. scan_freq="2412")
  63. hwsim_utils.test_connectivity(dev[0], hapd)
  64. hwsim_utils.test_connectivity(dev[1], hapd)
  65. hwsim_utils.test_connectivity(dev[2], hapd)
  66. dev[2].set_network(id, "wep_tx_keyidx", "1")
  67. dev[2].request("REASSOCIATE")
  68. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  69. if ev is None:
  70. raise Exception("Reassociation with the AP timed out")
  71. hwsim_utils.test_connectivity(dev[2], hapd)