test_sae.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Test cases for SAE
  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 test_sae(dev, apdev):
  13. """SAE with default group"""
  14. params = hostapd.wpa2_params(ssid="test-sae",
  15. passphrase="12345678")
  16. params['wpa_key_mgmt'] = 'SAE'
  17. hostapd.add_ap(apdev[0]['ifname'], params)
  18. dev[0].request("SET sae_groups ")
  19. id = dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  20. scan_freq="2412")
  21. if dev[0].get_status_field('sae_group') != '19':
  22. raise Exception("Expected default SAE group not used")
  23. def test_sae_groups(dev, apdev):
  24. """SAE with all supported groups"""
  25. # This would be the full list of supported groups, but groups 14-16
  26. # (2048-4096 bit MODP) are a bit too slow on some VMs and can result in
  27. # hitting mac80211 authentication timeout, so skip them for now.
  28. #sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 14, 15, 16, 22, 23, 24 ]
  29. sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 22, 23, 24 ]
  30. groups = [str(g) for g in sae_groups]
  31. params = hostapd.wpa2_params(ssid="test-sae-groups",
  32. passphrase="12345678")
  33. params['wpa_key_mgmt'] = 'SAE'
  34. params['sae_groups'] = ' '.join(groups)
  35. hostapd.add_ap(apdev[0]['ifname'], params)
  36. for g in groups:
  37. logger.info("Testing SAE group " + g)
  38. dev[0].request("SET sae_groups " + g)
  39. id = dev[0].connect("test-sae-groups", psk="12345678", key_mgmt="SAE",
  40. scan_freq="2412")
  41. if dev[0].get_status_field('sae_group') != g:
  42. raise Exception("Expected SAE group not used")
  43. dev[0].remove_network(id)
  44. def test_sae_group_nego(dev, apdev):
  45. """SAE group negotiation"""
  46. params = hostapd.wpa2_params(ssid="test-sae-group-nego",
  47. passphrase="12345678")
  48. params['wpa_key_mgmt'] = 'SAE'
  49. params['sae_groups'] = '19'
  50. hostapd.add_ap(apdev[0]['ifname'], params)
  51. dev[0].request("SET sae_groups 25 26 20 19")
  52. dev[0].connect("test-sae-group-nego", psk="12345678", key_mgmt="SAE",
  53. scan_freq="2412")
  54. if dev[0].get_status_field('sae_group') != '19':
  55. raise Exception("Expected SAE group not used")
  56. def test_sae_anti_clogging(dev, apdev):
  57. """SAE anti clogging"""
  58. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  59. params['wpa_key_mgmt'] = 'SAE'
  60. params['sae_anti_clogging_threshold'] = '1'
  61. hostapd.add_ap(apdev[0]['ifname'], params)
  62. dev[0].request("SET sae_groups ")
  63. dev[1].request("SET sae_groups ")
  64. id = {}
  65. for i in range(0, 2):
  66. dev[i].scan(freq="2412")
  67. id[i] = dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  68. scan_freq="2412", only_add_network=True)
  69. for i in range(0, 2):
  70. dev[i].select_network(id[i])
  71. for i in range(0, 2):
  72. ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  73. if ev is None:
  74. raise Exception("Association with the AP timed out")