test_ap_ciphers.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/python
  2. #
  3. # Cipher suite tests
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger()
  12. import hwsim_utils
  13. import hostapd
  14. def check_cipher(dev, ap, cipher):
  15. if cipher not in dev.get_capability("pairwise"):
  16. return "skip"
  17. params = { "ssid": "test-wpa2-psk",
  18. "wpa_passphrase": "12345678",
  19. "wpa": "2",
  20. "wpa_key_mgmt": "WPA-PSK",
  21. "rsn_pairwise": cipher }
  22. hostapd.add_ap(ap['ifname'], params)
  23. dev.connect("test-wpa2-psk", psk="12345678",
  24. pairwise=cipher, group=cipher, scan_freq="2412")
  25. hwsim_utils.test_connectivity(dev.ifname, ap['ifname'])
  26. def test_ap_cipher_tkip(dev, apdev):
  27. """WPA2-PSK/TKIP connection"""
  28. check_cipher(dev[0], apdev[0], "TKIP")
  29. def test_ap_cipher_ccmp(dev, apdev):
  30. """WPA2-PSK/CCMP connection"""
  31. check_cipher(dev[0], apdev[0], "CCMP")
  32. def test_ap_cipher_gcmp(dev, apdev):
  33. """WPA2-PSK/GCMP connection"""
  34. check_cipher(dev[0], apdev[0], "GCMP")
  35. def test_ap_cipher_ccmp_256(dev, apdev):
  36. """WPA2-PSK/CCMP-256 connection"""
  37. check_cipher(dev[0], apdev[0], "CCMP-256")
  38. def test_ap_cipher_gcmp_256(dev, apdev):
  39. """WPA2-PSK/GCMP-256 connection"""
  40. check_cipher(dev[0], apdev[0], "GCMP-256")
  41. def test_ap_cipher_mixed_wpa_wpa2(dev, apdev):
  42. """WPA2-PSK/CCMP/ and WPA-PSK/TKIP mixed configuration"""
  43. ssid = "test-wpa-wpa2-psk"
  44. passphrase = "12345678"
  45. params = { "ssid": ssid,
  46. "wpa_passphrase": passphrase,
  47. "wpa": "3",
  48. "wpa_key_mgmt": "WPA-PSK",
  49. "rsn_pairwise": "CCMP",
  50. "wpa_pairwise": "TKIP" }
  51. hostapd.add_ap(apdev[0]['ifname'], params)
  52. dev[0].connect(ssid, psk=passphrase, proto="WPA2",
  53. pairwise="CCMP", group="TKIP", scan_freq="2412")
  54. status = dev[0].get_status()
  55. if status['key_mgmt'] != 'WPA2-PSK':
  56. raise Exception("Incorrect key_mgmt reported")
  57. if status['pairwise_cipher'] != 'CCMP':
  58. raise Exception("Incorrect pairwise_cipher reported")
  59. if status['group_cipher'] != 'TKIP':
  60. raise Exception("Incorrect group_cipher reported")
  61. bss = dev[0].get_bss(apdev[0]['bssid'])
  62. if bss['ssid'] != ssid:
  63. raise Exception("Unexpected SSID in the BSS entry")
  64. if "[WPA-PSK-TKIP]" not in bss['flags']:
  65. raise Exception("Missing BSS flag WPA-PSK-TKIP")
  66. if "[WPA2-PSK-CCMP]" not in bss['flags']:
  67. raise Exception("Missing BSS flag WPA2-PSK-CCMP")
  68. hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
  69. dev[1].connect(ssid, psk=passphrase, proto="WPA",
  70. pairwise="TKIP", group="TKIP", scan_freq="2412")
  71. status = dev[1].get_status()
  72. if status['key_mgmt'] != 'WPA-PSK':
  73. raise Exception("Incorrect key_mgmt reported")
  74. if status['pairwise_cipher'] != 'TKIP':
  75. raise Exception("Incorrect pairwise_cipher reported")
  76. if status['group_cipher'] != 'TKIP':
  77. raise Exception("Incorrect group_cipher reported")
  78. hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
  79. hwsim_utils.test_connectivity(dev[0].ifname, dev[1].ifname)