test_ap_ciphers.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # Cipher suite tests
  2. # Copyright (c) 2013-2015, 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. from remotehost import remote_compatible
  7. import time
  8. import logging
  9. logger = logging.getLogger()
  10. import os.path
  11. import hwsim_utils
  12. import hostapd
  13. from utils import HwsimSkip, skip_with_fips
  14. from wlantest import Wlantest
  15. def check_cipher(dev, ap, cipher):
  16. if cipher not in dev.get_capability("pairwise"):
  17. raise HwsimSkip("Cipher %s not supported" % cipher)
  18. params = { "ssid": "test-wpa2-psk",
  19. "wpa_passphrase": "12345678",
  20. "wpa": "2",
  21. "wpa_key_mgmt": "WPA-PSK",
  22. "rsn_pairwise": cipher }
  23. hapd = hostapd.add_ap(ap, params)
  24. dev.connect("test-wpa2-psk", psk="12345678",
  25. pairwise=cipher, group=cipher, scan_freq="2412")
  26. hwsim_utils.test_connectivity(dev, hapd)
  27. def check_group_mgmt_cipher(dev, ap, cipher):
  28. if cipher not in dev.get_capability("group_mgmt"):
  29. raise HwsimSkip("Cipher %s not supported" % cipher)
  30. params = { "ssid": "test-wpa2-psk-pmf",
  31. "wpa_passphrase": "12345678",
  32. "wpa": "2",
  33. "ieee80211w": "2",
  34. "wpa_key_mgmt": "WPA-PSK-SHA256",
  35. "rsn_pairwise": "CCMP",
  36. "group_mgmt_cipher": cipher }
  37. hapd = hostapd.add_ap(ap, params)
  38. Wlantest.setup(hapd)
  39. wt = Wlantest()
  40. wt.flush()
  41. wt.add_passphrase("12345678")
  42. dev.connect("test-wpa2-psk-pmf", psk="12345678", ieee80211w="2",
  43. key_mgmt="WPA-PSK-SHA256",
  44. pairwise="CCMP", group="CCMP", scan_freq="2412")
  45. hwsim_utils.test_connectivity(dev, hapd)
  46. hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff")
  47. dev.wait_disconnected()
  48. if wt.get_bss_counter('valid_bip_mmie', ap['bssid']) < 1:
  49. raise Exception("No valid BIP MMIE seen")
  50. if wt.get_bss_counter('bip_deauth', ap['bssid']) < 1:
  51. raise Exception("No valid BIP deauth seen")
  52. if cipher == "AES-128-CMAC":
  53. group_mgmt = "BIP"
  54. else:
  55. group_mgmt = cipher
  56. res = wt.info_bss('group_mgmt', ap['bssid']).strip()
  57. if res != group_mgmt:
  58. raise Exception("Unexpected group mgmt cipher: " + res)
  59. @remote_compatible
  60. def test_ap_cipher_tkip(dev, apdev):
  61. """WPA2-PSK/TKIP connection"""
  62. skip_with_fips(dev[0])
  63. check_cipher(dev[0], apdev[0], "TKIP")
  64. @remote_compatible
  65. def test_ap_cipher_tkip_countermeasures_ap(dev, apdev):
  66. """WPA-PSK/TKIP countermeasures (detected by AP)"""
  67. skip_with_fips(dev[0])
  68. testfile = "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (dev[0].get_driver_status_field("phyname"), dev[0].ifname)
  69. if dev[0].cmd_execute([ "ls", testfile ])[0] != 0:
  70. raise HwsimSkip("tkip_mic_test not supported in mac80211")
  71. params = { "ssid": "tkip-countermeasures",
  72. "wpa_passphrase": "12345678",
  73. "wpa": "1",
  74. "wpa_key_mgmt": "WPA-PSK",
  75. "wpa_pairwise": "TKIP" }
  76. hapd = hostapd.add_ap(apdev[0], params)
  77. dev[0].connect("tkip-countermeasures", psk="12345678",
  78. pairwise="TKIP", group="TKIP", scan_freq="2412")
  79. dev[0].dump_monitor()
  80. dev[0].cmd_execute([ "echo", "-n", apdev[0]['bssid'], ">", testfile ],
  81. shell=True)
  82. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  83. if ev is not None:
  84. raise Exception("Unexpected disconnection on first Michael MIC failure")
  85. dev[0].cmd_execute([ "echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile ],
  86. shell=True)
  87. ev = dev[0].wait_disconnected(timeout=10,
  88. error="No disconnection after two Michael MIC failures")
  89. if "reason=14" not in ev:
  90. raise Exception("Unexpected disconnection reason: " + ev)
  91. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  92. if ev is not None:
  93. raise Exception("Unexpected connection during TKIP countermeasures")
  94. @remote_compatible
  95. def test_ap_cipher_tkip_countermeasures_sta(dev, apdev):
  96. """WPA-PSK/TKIP countermeasures (detected by STA)"""
  97. skip_with_fips(dev[0])
  98. params = { "ssid": "tkip-countermeasures",
  99. "wpa_passphrase": "12345678",
  100. "wpa": "1",
  101. "wpa_key_mgmt": "WPA-PSK",
  102. "wpa_pairwise": "TKIP" }
  103. hapd = hostapd.add_ap(apdev[0], params)
  104. testfile = "/sys/kernel/debug/ieee80211/%s/netdev:%s/tkip_mic_test" % (hapd.get_driver_status_field("phyname"), apdev[0]['ifname'])
  105. if hapd.cmd_execute([ "ls", testfile ])[0] != 0:
  106. raise HwsimSkip("tkip_mic_test not supported in mac80211")
  107. dev[0].connect("tkip-countermeasures", psk="12345678",
  108. pairwise="TKIP", group="TKIP", scan_freq="2412")
  109. dev[0].dump_monitor()
  110. hapd.cmd_execute([ "echo", "-n", dev[0].own_addr(), ">", testfile ],
  111. shell=True)
  112. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
  113. if ev is not None:
  114. raise Exception("Unexpected disconnection on first Michael MIC failure")
  115. hapd.cmd_execute([ "echo", "-n", "ff:ff:ff:ff:ff:ff", ">", testfile ],
  116. shell=True)
  117. ev = dev[0].wait_disconnected(timeout=10,
  118. error="No disconnection after two Michael MIC failures")
  119. if "reason=14 locally_generated=1" not in ev:
  120. raise Exception("Unexpected disconnection reason: " + ev)
  121. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  122. if ev is not None:
  123. raise Exception("Unexpected connection during TKIP countermeasures")
  124. @remote_compatible
  125. def test_ap_cipher_ccmp(dev, apdev):
  126. """WPA2-PSK/CCMP connection"""
  127. check_cipher(dev[0], apdev[0], "CCMP")
  128. def test_ap_cipher_gcmp(dev, apdev):
  129. """WPA2-PSK/GCMP connection"""
  130. check_cipher(dev[0], apdev[0], "GCMP")
  131. def test_ap_cipher_ccmp_256(dev, apdev):
  132. """WPA2-PSK/CCMP-256 connection"""
  133. check_cipher(dev[0], apdev[0], "CCMP-256")
  134. def test_ap_cipher_gcmp_256(dev, apdev):
  135. """WPA2-PSK/GCMP-256 connection"""
  136. check_cipher(dev[0], apdev[0], "GCMP-256")
  137. @remote_compatible
  138. def test_ap_cipher_mixed_wpa_wpa2(dev, apdev):
  139. """WPA2-PSK/CCMP/ and WPA-PSK/TKIP mixed configuration"""
  140. skip_with_fips(dev[0])
  141. ssid = "test-wpa-wpa2-psk"
  142. passphrase = "12345678"
  143. params = { "ssid": ssid,
  144. "wpa_passphrase": passphrase,
  145. "wpa": "3",
  146. "wpa_key_mgmt": "WPA-PSK",
  147. "rsn_pairwise": "CCMP",
  148. "wpa_pairwise": "TKIP" }
  149. hapd = hostapd.add_ap(apdev[0], params)
  150. dev[0].connect(ssid, psk=passphrase, proto="WPA2",
  151. pairwise="CCMP", group="TKIP", scan_freq="2412")
  152. status = dev[0].get_status()
  153. if status['key_mgmt'] != 'WPA2-PSK':
  154. raise Exception("Incorrect key_mgmt reported")
  155. if status['pairwise_cipher'] != 'CCMP':
  156. raise Exception("Incorrect pairwise_cipher reported")
  157. if status['group_cipher'] != 'TKIP':
  158. raise Exception("Incorrect group_cipher reported")
  159. bss = dev[0].get_bss(apdev[0]['bssid'])
  160. if bss['ssid'] != ssid:
  161. raise Exception("Unexpected SSID in the BSS entry")
  162. if "[WPA-PSK-TKIP]" not in bss['flags']:
  163. raise Exception("Missing BSS flag WPA-PSK-TKIP")
  164. if "[WPA2-PSK-CCMP]" not in bss['flags']:
  165. raise Exception("Missing BSS flag WPA2-PSK-CCMP")
  166. hwsim_utils.test_connectivity(dev[0], hapd)
  167. dev[1].connect(ssid, psk=passphrase, proto="WPA",
  168. pairwise="TKIP", group="TKIP", scan_freq="2412")
  169. status = dev[1].get_status()
  170. if status['key_mgmt'] != 'WPA-PSK':
  171. raise Exception("Incorrect key_mgmt reported")
  172. if status['pairwise_cipher'] != 'TKIP':
  173. raise Exception("Incorrect pairwise_cipher reported")
  174. if status['group_cipher'] != 'TKIP':
  175. raise Exception("Incorrect group_cipher reported")
  176. hwsim_utils.test_connectivity(dev[1], hapd)
  177. hwsim_utils.test_connectivity(dev[0], dev[1])
  178. @remote_compatible
  179. def test_ap_cipher_bip(dev, apdev):
  180. """WPA2-PSK with BIP"""
  181. check_group_mgmt_cipher(dev[0], apdev[0], "AES-128-CMAC")
  182. def test_ap_cipher_bip_gmac_128(dev, apdev):
  183. """WPA2-PSK with BIP-GMAC-128"""
  184. check_group_mgmt_cipher(dev[0], apdev[0], "BIP-GMAC-128")
  185. def test_ap_cipher_bip_gmac_256(dev, apdev):
  186. """WPA2-PSK with BIP-GMAC-256"""
  187. check_group_mgmt_cipher(dev[0], apdev[0], "BIP-GMAC-256")
  188. def test_ap_cipher_bip_cmac_256(dev, apdev):
  189. """WPA2-PSK with BIP-CMAC-256"""
  190. check_group_mgmt_cipher(dev[0], apdev[0], "BIP-CMAC-256")