test_suite_b.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. # Suite B tests
  2. # Copyright (c) 2014-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. import time
  7. import logging
  8. logger = logging.getLogger()
  9. import hostapd
  10. from utils import HwsimSkip, fail_test
  11. def check_suite_b_capa(dev):
  12. if "GCMP" not in dev[0].get_capability("pairwise"):
  13. raise HwsimSkip("GCMP not supported")
  14. if "BIP-GMAC-128" not in dev[0].get_capability("group_mgmt"):
  15. raise HwsimSkip("BIP-GMAC-128 not supported")
  16. if "WPA-EAP-SUITE-B" not in dev[0].get_capability("key_mgmt"):
  17. raise HwsimSkip("WPA-EAP-SUITE-B not supported")
  18. check_suite_b_tls_lib(dev)
  19. def check_suite_b_tls_lib(dev):
  20. tls = dev[0].request("GET tls_library")
  21. if not tls.startswith("OpenSSL"):
  22. raise HwsimSkip("TLS library not supported for Suite B: " + tls)
  23. supported = False
  24. for ver in [ '1.0.2', '1.1.0' ]:
  25. if "build=OpenSSL " + ver in tls and "run=OpenSSL " + ver in tls:
  26. supported = True
  27. break
  28. if not supported:
  29. raise HwsimSkip("OpenSSL version not supported for Suite B: " + tls)
  30. def suite_b_ap_params():
  31. params = { "ssid": "test-suite-b",
  32. "wpa": "2",
  33. "wpa_key_mgmt": "WPA-EAP-SUITE-B",
  34. "rsn_pairwise": "GCMP",
  35. "group_mgmt_cipher": "BIP-GMAC-128",
  36. "ieee80211w": "2",
  37. "ieee8021x": "1",
  38. "openssl_ciphers": "SUITEB128",
  39. #"dh_file": "auth_serv/dh.conf",
  40. "eap_server": "1",
  41. "eap_user_file": "auth_serv/eap_user.conf",
  42. "ca_cert": "auth_serv/ec-ca.pem",
  43. "server_cert": "auth_serv/ec-server.pem",
  44. "private_key": "auth_serv/ec-server.key" }
  45. return params
  46. def test_suite_b(dev, apdev):
  47. """WPA2/GCMP connection at Suite B 128-bit level"""
  48. check_suite_b_capa(dev)
  49. dev[0].flush_scan_cache()
  50. params = suite_b_ap_params()
  51. hapd = hostapd.add_ap(apdev[0], params)
  52. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B", ieee80211w="2",
  53. openssl_ciphers="SUITEB128",
  54. eap="TLS", identity="tls user",
  55. ca_cert="auth_serv/ec-ca.pem",
  56. client_cert="auth_serv/ec-user.pem",
  57. private_key="auth_serv/ec-user.key",
  58. pairwise="GCMP", group="GCMP", scan_freq="2412")
  59. tls_cipher = dev[0].get_status_field("EAP TLS cipher")
  60. if tls_cipher != "ECDHE-ECDSA-AES128-GCM-SHA256":
  61. raise Exception("Unexpected TLS cipher: " + tls_cipher)
  62. bss = dev[0].get_bss(apdev[0]['bssid'])
  63. if 'flags' not in bss:
  64. raise Exception("Could not get BSS flags from BSS table")
  65. if "[WPA2-EAP-SUITE-B-GCMP]" not in bss['flags']:
  66. raise Exception("Unexpected BSS flags: " + bss['flags'])
  67. dev[0].request("DISCONNECT")
  68. dev[0].wait_disconnected(timeout=20)
  69. dev[0].dump_monitor()
  70. dev[0].request("RECONNECT")
  71. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  72. "CTRL-EVENT-CONNECTED"], timeout=20)
  73. if ev is None:
  74. raise Exception("Roaming with the AP timed out")
  75. if "CTRL-EVENT-EAP-STARTED" in ev:
  76. raise Exception("Unexpected EAP exchange")
  77. def suite_b_as_params():
  78. params = {}
  79. params['ssid'] = 'as'
  80. params['beacon_int'] = '2000'
  81. params['radius_server_clients'] = 'auth_serv/radius_clients.conf'
  82. params['radius_server_auth_port'] = '18129'
  83. params['eap_server'] = '1'
  84. params['eap_user_file'] = 'auth_serv/eap_user.conf'
  85. params['ca_cert'] = 'auth_serv/ec-ca.pem'
  86. params['server_cert'] = 'auth_serv/ec-server.pem'
  87. params['private_key'] = 'auth_serv/ec-server.key'
  88. params['openssl_ciphers'] = 'SUITEB128'
  89. return params
  90. def test_suite_b_radius(dev, apdev):
  91. """WPA2/GCMP (RADIUS) connection at Suite B 128-bit level"""
  92. check_suite_b_capa(dev)
  93. dev[0].flush_scan_cache()
  94. params = suite_b_as_params()
  95. hostapd.add_ap(apdev[1], params)
  96. params = { "ssid": "test-suite-b",
  97. "wpa": "2",
  98. "wpa_key_mgmt": "WPA-EAP-SUITE-B",
  99. "rsn_pairwise": "GCMP",
  100. "group_mgmt_cipher": "BIP-GMAC-128",
  101. "ieee80211w": "2",
  102. "ieee8021x": "1",
  103. 'auth_server_addr': "127.0.0.1",
  104. 'auth_server_port': "18129",
  105. 'auth_server_shared_secret': "radius",
  106. 'nas_identifier': "nas.w1.fi" }
  107. hapd = hostapd.add_ap(apdev[0], params)
  108. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B", ieee80211w="2",
  109. openssl_ciphers="SUITEB128",
  110. eap="TLS", identity="tls user",
  111. ca_cert="auth_serv/ec-ca.pem",
  112. client_cert="auth_serv/ec-user.pem",
  113. private_key="auth_serv/ec-user.key",
  114. pairwise="GCMP", group="GCMP", scan_freq="2412")
  115. def check_suite_b_192_capa(dev):
  116. if "GCMP-256" not in dev[0].get_capability("pairwise"):
  117. raise HwsimSkip("GCMP-256 not supported")
  118. if "BIP-GMAC-256" not in dev[0].get_capability("group_mgmt"):
  119. raise HwsimSkip("BIP-GMAC-256 not supported")
  120. if "WPA-EAP-SUITE-B-192" not in dev[0].get_capability("key_mgmt"):
  121. raise HwsimSkip("WPA-EAP-SUITE-B-192 not supported")
  122. check_suite_b_tls_lib(dev)
  123. def suite_b_192_ap_params():
  124. params = { "ssid": "test-suite-b",
  125. "wpa": "2",
  126. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  127. "rsn_pairwise": "GCMP-256",
  128. "group_mgmt_cipher": "BIP-GMAC-256",
  129. "ieee80211w": "2",
  130. "ieee8021x": "1",
  131. "openssl_ciphers": "SUITEB192",
  132. "eap_server": "1",
  133. "eap_user_file": "auth_serv/eap_user.conf",
  134. "ca_cert": "auth_serv/ec2-ca.pem",
  135. "server_cert": "auth_serv/ec2-server.pem",
  136. "private_key": "auth_serv/ec2-server.key" }
  137. return params
  138. def test_suite_b_192(dev, apdev):
  139. """WPA2/GCMP-256 connection at Suite B 192-bit level"""
  140. check_suite_b_192_capa(dev)
  141. dev[0].flush_scan_cache()
  142. params = suite_b_192_ap_params()
  143. hapd = hostapd.add_ap(apdev[0], params)
  144. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  145. ieee80211w="2",
  146. openssl_ciphers="SUITEB192",
  147. eap="TLS", identity="tls user",
  148. ca_cert="auth_serv/ec2-ca.pem",
  149. client_cert="auth_serv/ec2-user.pem",
  150. private_key="auth_serv/ec2-user.key",
  151. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412")
  152. tls_cipher = dev[0].get_status_field("EAP TLS cipher")
  153. if tls_cipher != "ECDHE-ECDSA-AES256-GCM-SHA384":
  154. raise Exception("Unexpected TLS cipher: " + tls_cipher)
  155. bss = dev[0].get_bss(apdev[0]['bssid'])
  156. if 'flags' not in bss:
  157. raise Exception("Could not get BSS flags from BSS table")
  158. if "[WPA2-EAP-SUITE-B-192-GCMP-256]" not in bss['flags']:
  159. raise Exception("Unexpected BSS flags: " + bss['flags'])
  160. dev[0].request("DISCONNECT")
  161. dev[0].wait_disconnected(timeout=20)
  162. dev[0].dump_monitor()
  163. dev[0].request("RECONNECT")
  164. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  165. "CTRL-EVENT-CONNECTED"], timeout=20)
  166. if ev is None:
  167. raise Exception("Roaming with the AP timed out")
  168. if "CTRL-EVENT-EAP-STARTED" in ev:
  169. raise Exception("Unexpected EAP exchange")
  170. def test_suite_b_192_radius(dev, apdev):
  171. """WPA2/GCMP-256 (RADIUS) connection at Suite B 192-bit level"""
  172. check_suite_b_192_capa(dev)
  173. dev[0].flush_scan_cache()
  174. params = suite_b_as_params()
  175. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  176. params['server_cert'] = 'auth_serv/ec2-server.pem'
  177. params['private_key'] = 'auth_serv/ec2-server.key'
  178. params['openssl_ciphers'] = 'SUITEB192'
  179. hostapd.add_ap(apdev[1], params)
  180. params = { "ssid": "test-suite-b",
  181. "wpa": "2",
  182. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  183. "rsn_pairwise": "GCMP-256",
  184. "group_mgmt_cipher": "BIP-GMAC-256",
  185. "ieee80211w": "2",
  186. "ieee8021x": "1",
  187. 'auth_server_addr': "127.0.0.1",
  188. 'auth_server_port': "18129",
  189. 'auth_server_shared_secret': "radius",
  190. 'nas_identifier': "nas.w1.fi" }
  191. hapd = hostapd.add_ap(apdev[0], params)
  192. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  193. ieee80211w="2",
  194. openssl_ciphers="SUITEB192",
  195. eap="TLS", identity="tls user",
  196. ca_cert="auth_serv/ec2-ca.pem",
  197. client_cert="auth_serv/ec2-user.pem",
  198. private_key="auth_serv/ec2-user.key",
  199. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412")
  200. def test_suite_b_pmkid_failure(dev, apdev):
  201. """WPA2/GCMP connection at Suite B 128-bit level and PMKID derivation failure"""
  202. check_suite_b_capa(dev)
  203. dev[0].flush_scan_cache()
  204. params = suite_b_ap_params()
  205. hapd = hostapd.add_ap(apdev[0], params)
  206. with fail_test(dev[0], 1, "rsn_pmkid_suite_b"):
  207. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B",
  208. ieee80211w="2",
  209. openssl_ciphers="SUITEB128",
  210. eap="TLS", identity="tls user",
  211. ca_cert="auth_serv/ec-ca.pem",
  212. client_cert="auth_serv/ec-user.pem",
  213. private_key="auth_serv/ec-user.key",
  214. pairwise="GCMP", group="GCMP", scan_freq="2412")
  215. def test_suite_b_192_pmkid_failure(dev, apdev):
  216. """WPA2/GCMP-256 connection at Suite B 192-bit level and PMKID derivation failure"""
  217. check_suite_b_192_capa(dev)
  218. dev[0].flush_scan_cache()
  219. params = suite_b_192_ap_params()
  220. hapd = hostapd.add_ap(apdev[0], params)
  221. with fail_test(dev[0], 1, "rsn_pmkid_suite_b"):
  222. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  223. ieee80211w="2",
  224. openssl_ciphers="SUITEB192",
  225. eap="TLS", identity="tls user",
  226. ca_cert="auth_serv/ec2-ca.pem",
  227. client_cert="auth_serv/ec2-user.pem",
  228. private_key="auth_serv/ec2-user.key",
  229. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412")
  230. def test_suite_b_mic_failure(dev, apdev):
  231. """WPA2/GCMP connection at Suite B 128-bit level and MIC derivation failure"""
  232. check_suite_b_capa(dev)
  233. dev[0].flush_scan_cache()
  234. params = suite_b_ap_params()
  235. hapd = hostapd.add_ap(apdev[0], params)
  236. with fail_test(dev[0], 1, "wpa_eapol_key_mic"):
  237. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B",
  238. ieee80211w="2",
  239. openssl_ciphers="SUITEB128",
  240. eap="TLS", identity="tls user",
  241. ca_cert="auth_serv/ec-ca.pem",
  242. client_cert="auth_serv/ec-user.pem",
  243. private_key="auth_serv/ec-user.key",
  244. pairwise="GCMP", group="GCMP", scan_freq="2412",
  245. wait_connect=False)
  246. dev[0].wait_disconnected()
  247. def test_suite_b_192_mic_failure(dev, apdev):
  248. """WPA2/GCMP connection at Suite B 192-bit level and MIC derivation failure"""
  249. check_suite_b_capa(dev)
  250. dev[0].flush_scan_cache()
  251. params = suite_b_192_ap_params()
  252. hapd = hostapd.add_ap(apdev[0], params)
  253. with fail_test(dev[0], 1, "wpa_eapol_key_mic"):
  254. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  255. ieee80211w="2",
  256. openssl_ciphers="SUITEB192",
  257. eap="TLS", identity="tls user",
  258. ca_cert="auth_serv/ec2-ca.pem",
  259. client_cert="auth_serv/ec2-user.pem",
  260. private_key="auth_serv/ec2-user.key",
  261. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412",
  262. wait_connect=False)
  263. dev[0].wait_disconnected()