test_wep.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. bss = dev[0].get_bss(apdev[0]['bssid'])
  19. if 'flags' not in bss:
  20. raise Exception("Could not get BSS flags from BSS table")
  21. if "[WEP]" not in bss['flags']:
  22. raise Exception("Unexpected BSS flags: " + bss['flags'])
  23. def test_wep_shared_key_auth(dev, apdev):
  24. """WEP Shared Key authentication"""
  25. hapd = hostapd.add_ap(apdev[0]['ifname'],
  26. { "ssid": "wep-shared-key",
  27. "wep_key0": '"hello12345678"',
  28. "auth_algs": "2" })
  29. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  30. wep_key0='"hello12345678"',
  31. scan_freq="2412")
  32. hwsim_utils.test_connectivity(dev[0], hapd)
  33. dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="OPEN SHARED",
  34. wep_key0='"hello12345678"',
  35. scan_freq="2412")
  36. def test_wep_shared_key_auth_not_allowed(dev, apdev):
  37. """WEP Shared Key authentication not allowed"""
  38. hostapd.add_ap(apdev[0]['ifname'],
  39. { "ssid": "wep-shared-key",
  40. "wep_key0": '"hello12345678"',
  41. "auth_algs": "1" })
  42. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  43. wep_key0='"hello12345678"',
  44. scan_freq="2412", wait_connect=False)
  45. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  46. if ev is not None:
  47. raise Exception("Unexpected association")
  48. def test_wep_shared_key_auth_multi_key(dev, apdev):
  49. """WEP Shared Key authentication with multiple keys"""
  50. hapd = hostapd.add_ap(apdev[0]['ifname'],
  51. { "ssid": "wep-shared-key",
  52. "wep_key0": '"hello12345678"',
  53. "wep_key1": '"other12345678"',
  54. "auth_algs": "2" })
  55. dev[0].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  56. wep_key0='"hello12345678"',
  57. scan_freq="2412")
  58. dev[1].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  59. wep_key0='"hello12345678"',
  60. wep_key1='"other12345678"',
  61. wep_tx_keyidx="1",
  62. scan_freq="2412")
  63. id = dev[2].connect("wep-shared-key", key_mgmt="NONE", auth_alg="SHARED",
  64. wep_key0='"hello12345678"',
  65. wep_key1='"other12345678"',
  66. wep_tx_keyidx="0",
  67. scan_freq="2412")
  68. hwsim_utils.test_connectivity(dev[0], hapd)
  69. hwsim_utils.test_connectivity(dev[1], hapd)
  70. hwsim_utils.test_connectivity(dev[2], hapd)
  71. dev[2].set_network(id, "wep_tx_keyidx", "1")
  72. dev[2].request("REASSOCIATE")
  73. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  74. if ev is None:
  75. raise Exception("Reassociation with the AP timed out")
  76. hwsim_utils.test_connectivity(dev[2], hapd)