test_sae.py 4.4 KB

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