test_sae.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. bss = dev[0].get_bss(apdev[0]['bssid'])
  27. if 'flags' not in bss:
  28. raise Exception("Could not get BSS flags from BSS table")
  29. if "[WPA2-SAE-CCMP]" not in bss['flags']:
  30. raise Exception("Unexpected BSS flags: " + bss['flags'])
  31. def test_sae_pmksa_caching(dev, apdev):
  32. """SAE and PMKSA caching"""
  33. params = hostapd.wpa2_params(ssid="test-sae",
  34. passphrase="12345678")
  35. params['wpa_key_mgmt'] = 'SAE'
  36. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  37. dev[0].request("SET sae_groups ")
  38. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  39. scan_freq="2412")
  40. dev[0].request("DISCONNECT")
  41. dev[0].request("RECONNECT")
  42. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  43. if ev is None:
  44. raise Exception("Reconnect timed out")
  45. if dev[0].get_status_field('sae_group') is not None:
  46. raise Exception("SAE group claimed to have been used")
  47. def test_sae_pmksa_caching_disabled(dev, apdev):
  48. """SAE and PMKSA caching disabled"""
  49. params = hostapd.wpa2_params(ssid="test-sae",
  50. passphrase="12345678")
  51. params['wpa_key_mgmt'] = 'SAE'
  52. params['disable_pmksa_caching'] = '1'
  53. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  54. dev[0].request("SET sae_groups ")
  55. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  56. scan_freq="2412")
  57. dev[0].request("DISCONNECT")
  58. dev[0].request("RECONNECT")
  59. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  60. if ev is None:
  61. raise Exception("Reconnect timed out")
  62. if dev[0].get_status_field('sae_group') != '19':
  63. raise Exception("Expected default SAE group not used")
  64. def test_sae_groups(dev, apdev):
  65. """SAE with all supported groups"""
  66. # This would be the full list of supported groups, but groups 14-16
  67. # (2048-4096 bit MODP) are a bit too slow on some VMs and can result in
  68. # hitting mac80211 authentication timeout, so skip them for now.
  69. #sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 14, 15, 16, 22, 23, 24 ]
  70. sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 22, 23, 24 ]
  71. groups = [str(g) for g in sae_groups]
  72. params = hostapd.wpa2_params(ssid="test-sae-groups",
  73. passphrase="12345678")
  74. params['wpa_key_mgmt'] = 'SAE'
  75. params['sae_groups'] = ' '.join(groups)
  76. hostapd.add_ap(apdev[0]['ifname'], params)
  77. for g in groups:
  78. logger.info("Testing SAE group " + g)
  79. dev[0].request("SET sae_groups " + g)
  80. id = dev[0].connect("test-sae-groups", psk="12345678", key_mgmt="SAE",
  81. scan_freq="2412")
  82. if dev[0].get_status_field('sae_group') != g:
  83. raise Exception("Expected SAE group not used")
  84. dev[0].remove_network(id)
  85. def test_sae_group_nego(dev, apdev):
  86. """SAE group negotiation"""
  87. params = hostapd.wpa2_params(ssid="test-sae-group-nego",
  88. passphrase="12345678")
  89. params['wpa_key_mgmt'] = 'SAE'
  90. params['sae_groups'] = '19'
  91. hostapd.add_ap(apdev[0]['ifname'], params)
  92. dev[0].request("SET sae_groups 25 26 20 19")
  93. dev[0].connect("test-sae-group-nego", psk="12345678", key_mgmt="SAE",
  94. scan_freq="2412")
  95. if dev[0].get_status_field('sae_group') != '19':
  96. raise Exception("Expected SAE group not used")
  97. def test_sae_anti_clogging(dev, apdev):
  98. """SAE anti clogging"""
  99. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  100. params['wpa_key_mgmt'] = 'SAE'
  101. params['sae_anti_clogging_threshold'] = '1'
  102. hostapd.add_ap(apdev[0]['ifname'], params)
  103. dev[0].request("SET sae_groups ")
  104. dev[1].request("SET sae_groups ")
  105. id = {}
  106. for i in range(0, 2):
  107. dev[i].scan(freq="2412")
  108. id[i] = dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  109. scan_freq="2412", only_add_network=True)
  110. for i in range(0, 2):
  111. dev[i].select_network(id[i])
  112. for i in range(0, 2):
  113. ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  114. if ev is None:
  115. raise Exception("Association with the AP timed out")
  116. def test_sae_forced_anti_clogging(dev, apdev):
  117. """SAE anti clogging (forced)"""
  118. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  119. params['wpa_key_mgmt'] = 'SAE WPA-PSK'
  120. params['sae_anti_clogging_threshold'] = '0'
  121. hostapd.add_ap(apdev[0]['ifname'], params)
  122. dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
  123. for i in range(0, 2):
  124. dev[i].request("SET sae_groups ")
  125. dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  126. scan_freq="2412")
  127. def test_sae_mixed(dev, apdev):
  128. """Mixed SAE and non-SAE network"""
  129. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  130. params['wpa_key_mgmt'] = 'SAE WPA-PSK'
  131. params['sae_anti_clogging_threshold'] = '0'
  132. hostapd.add_ap(apdev[0]['ifname'], params)
  133. dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
  134. for i in range(0, 2):
  135. dev[i].request("SET sae_groups ")
  136. dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  137. scan_freq="2412")
  138. def test_sae_missing_password(dev, apdev):
  139. """SAE and missing password"""
  140. params = hostapd.wpa2_params(ssid="test-sae",
  141. passphrase="12345678")
  142. params['wpa_key_mgmt'] = 'SAE'
  143. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  144. dev[0].request("SET sae_groups ")
  145. id = dev[0].connect("test-sae",
  146. raw_psk="46b4a73b8a951ad53ebd2e0afdb9c5483257edd4c21d12b7710759da70945858",
  147. key_mgmt="SAE", scan_freq="2412", wait_connect=False)
  148. ev = dev[0].wait_event(['CTRL-EVENT-SSID-TEMP-DISABLED'], timeout=10)
  149. if ev is None:
  150. raise Exception("Invalid network not temporarily disabled")