test_wep.py 3.6 KB

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