test_wep.py 3.6 KB

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