test_suite_b.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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
  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. tls = dev[0].request("GET tls_library")
  19. if not tls.startswith("OpenSSL"):
  20. raise HwsimSkip("TLS library not supported for Suite B: " + tls);
  21. if "build=OpenSSL 1.0.2" not in tls or "run=OpenSSL 1.0.2" not in tls:
  22. raise HwsimSkip("OpenSSL version not supported for Suite B: " + tls)
  23. def test_suite_b(dev, apdev):
  24. """WPA2/GCMP connection at Suite B 128-bit level"""
  25. check_suite_b_capa(dev)
  26. dev[0].flush_scan_cache()
  27. params = { "ssid": "test-suite-b",
  28. "wpa": "2",
  29. "wpa_key_mgmt": "WPA-EAP-SUITE-B",
  30. "rsn_pairwise": "GCMP",
  31. "group_mgmt_cipher": "BIP-GMAC-128",
  32. "ieee80211w": "2",
  33. "ieee8021x": "1",
  34. "openssl_ciphers": "SUITEB128",
  35. #"dh_file": "auth_serv/dh.conf",
  36. "eap_server": "1",
  37. "eap_user_file": "auth_serv/eap_user.conf",
  38. "ca_cert": "auth_serv/ec-ca.pem",
  39. "server_cert": "auth_serv/ec-server.pem",
  40. "private_key": "auth_serv/ec-server.key" }
  41. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  42. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B", ieee80211w="2",
  43. openssl_ciphers="SUITEB128",
  44. eap="TLS", identity="tls user",
  45. ca_cert="auth_serv/ec-ca.pem",
  46. client_cert="auth_serv/ec-user.pem",
  47. private_key="auth_serv/ec-user.key",
  48. pairwise="GCMP", group="GCMP", scan_freq="2412")
  49. tls_cipher = dev[0].get_status_field("EAP TLS cipher")
  50. if tls_cipher != "ECDHE-ECDSA-AES128-GCM-SHA256":
  51. raise Exception("Unexpected TLS cipher: " + tls_cipher)
  52. bss = dev[0].get_bss(apdev[0]['bssid'])
  53. if 'flags' not in bss:
  54. raise Exception("Could not get BSS flags from BSS table")
  55. if "[WPA2-EAP-SUITE-B-GCMP]" not in bss['flags']:
  56. raise Exception("Unexpected BSS flags: " + bss['flags'])
  57. dev[0].request("DISCONNECT")
  58. dev[0].wait_disconnected(timeout=20)
  59. dev[0].dump_monitor()
  60. dev[0].request("RECONNECT")
  61. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  62. "CTRL-EVENT-CONNECTED"], timeout=20)
  63. if ev is None:
  64. raise Exception("Roaming with the AP timed out")
  65. if "CTRL-EVENT-EAP-STARTED" in ev:
  66. raise Exception("Unexpected EAP exchange")
  67. def suite_b_as_params():
  68. params = {}
  69. params['ssid'] = 'as'
  70. params['beacon_int'] = '2000'
  71. params['radius_server_clients'] = 'auth_serv/radius_clients.conf'
  72. params['radius_server_auth_port'] = '18129'
  73. params['eap_server'] = '1'
  74. params['eap_user_file'] = 'auth_serv/eap_user.conf'
  75. params['ca_cert'] = 'auth_serv/ec-ca.pem'
  76. params['server_cert'] = 'auth_serv/ec-server.pem'
  77. params['private_key'] = 'auth_serv/ec-server.key'
  78. params['openssl_ciphers'] = 'SUITEB128'
  79. return params
  80. def test_suite_b_radius(dev, apdev):
  81. """WPA2/GCMP (RADIUS) connection at Suite B 128-bit level"""
  82. check_suite_b_capa(dev)
  83. dev[0].flush_scan_cache()
  84. params = suite_b_as_params()
  85. hostapd.add_ap(apdev[1]['ifname'], params)
  86. params = { "ssid": "test-suite-b",
  87. "wpa": "2",
  88. "wpa_key_mgmt": "WPA-EAP-SUITE-B",
  89. "rsn_pairwise": "GCMP",
  90. "group_mgmt_cipher": "BIP-GMAC-128",
  91. "ieee80211w": "2",
  92. "ieee8021x": "1",
  93. 'auth_server_addr': "127.0.0.1",
  94. 'auth_server_port': "18129",
  95. 'auth_server_shared_secret': "radius",
  96. 'nas_identifier': "nas.w1.fi" }
  97. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  98. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B", ieee80211w="2",
  99. openssl_ciphers="SUITEB128",
  100. eap="TLS", identity="tls user",
  101. ca_cert="auth_serv/ec-ca.pem",
  102. client_cert="auth_serv/ec-user.pem",
  103. private_key="auth_serv/ec-user.key",
  104. pairwise="GCMP", group="GCMP", scan_freq="2412")
  105. def check_suite_b_192_capa(dev):
  106. if "GCMP-256" not in dev[0].get_capability("pairwise"):
  107. raise HwsimSkip("GCMP-256 not supported")
  108. if "BIP-GMAC-256" not in dev[0].get_capability("group_mgmt"):
  109. raise HwsimSkip("BIP-GMAC-256 not supported")
  110. if "WPA-EAP-SUITE-B-192" not in dev[0].get_capability("key_mgmt"):
  111. raise HwsimSkip("WPA-EAP-SUITE-B-192 not supported")
  112. tls = dev[0].request("GET tls_library")
  113. if not tls.startswith("OpenSSL"):
  114. raise HwsimSkip("TLS library not supported for Suite B: " + tls);
  115. if "build=OpenSSL 1.0.2" not in tls or "run=OpenSSL 1.0.2" not in tls:
  116. raise HwsimSkip("OpenSSL version not supported for Suite B: " + tls)
  117. def test_suite_b_192(dev, apdev):
  118. """WPA2/GCMP-256 connection at Suite B 192-bit level"""
  119. check_suite_b_192_capa(dev)
  120. dev[0].flush_scan_cache()
  121. params = { "ssid": "test-suite-b",
  122. "wpa": "2",
  123. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  124. "rsn_pairwise": "GCMP-256",
  125. "group_mgmt_cipher": "BIP-GMAC-256",
  126. "ieee80211w": "2",
  127. "ieee8021x": "1",
  128. "openssl_ciphers": "SUITEB192",
  129. "eap_server": "1",
  130. "eap_user_file": "auth_serv/eap_user.conf",
  131. "ca_cert": "auth_serv/ec2-ca.pem",
  132. "server_cert": "auth_serv/ec2-server.pem",
  133. "private_key": "auth_serv/ec2-server.key" }
  134. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  135. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  136. ieee80211w="2",
  137. openssl_ciphers="SUITEB192",
  138. eap="TLS", identity="tls user",
  139. ca_cert="auth_serv/ec2-ca.pem",
  140. client_cert="auth_serv/ec2-user.pem",
  141. private_key="auth_serv/ec2-user.key",
  142. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412")
  143. tls_cipher = dev[0].get_status_field("EAP TLS cipher")
  144. if tls_cipher != "ECDHE-ECDSA-AES256-GCM-SHA384":
  145. raise Exception("Unexpected TLS cipher: " + tls_cipher)
  146. bss = dev[0].get_bss(apdev[0]['bssid'])
  147. if 'flags' not in bss:
  148. raise Exception("Could not get BSS flags from BSS table")
  149. if "[WPA2-EAP-SUITE-B-192-GCMP-256]" not in bss['flags']:
  150. raise Exception("Unexpected BSS flags: " + bss['flags'])
  151. dev[0].request("DISCONNECT")
  152. dev[0].wait_disconnected(timeout=20)
  153. dev[0].dump_monitor()
  154. dev[0].request("RECONNECT")
  155. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  156. "CTRL-EVENT-CONNECTED"], timeout=20)
  157. if ev is None:
  158. raise Exception("Roaming with the AP timed out")
  159. if "CTRL-EVENT-EAP-STARTED" in ev:
  160. raise Exception("Unexpected EAP exchange")
  161. def test_suite_b_192_radius(dev, apdev):
  162. """WPA2/GCMP-256 (RADIUS) connection at Suite B 192-bit level"""
  163. check_suite_b_192_capa(dev)
  164. dev[0].flush_scan_cache()
  165. params = suite_b_as_params()
  166. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  167. params['server_cert'] = 'auth_serv/ec2-server.pem'
  168. params['private_key'] = 'auth_serv/ec2-server.key'
  169. params['openssl_ciphers'] = 'SUITEB192'
  170. hostapd.add_ap(apdev[1]['ifname'], params)
  171. params = { "ssid": "test-suite-b",
  172. "wpa": "2",
  173. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  174. "rsn_pairwise": "GCMP-256",
  175. "group_mgmt_cipher": "BIP-GMAC-256",
  176. "ieee80211w": "2",
  177. "ieee8021x": "1",
  178. 'auth_server_addr': "127.0.0.1",
  179. 'auth_server_port': "18129",
  180. 'auth_server_shared_secret': "radius",
  181. 'nas_identifier': "nas.w1.fi" }
  182. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  183. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  184. ieee80211w="2",
  185. openssl_ciphers="SUITEB192",
  186. eap="TLS", identity="tls user",
  187. ca_cert="auth_serv/ec2-ca.pem",
  188. client_cert="auth_serv/ec2-user.pem",
  189. private_key="auth_serv/ec2-user.key",
  190. pairwise="GCMP-256", group="GCMP-256", scan_freq="2412")