test_ap_ciphers.py 3.2 KB

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