test_fils.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. # Test cases for FILS
  2. # Copyright (c) 2015-2016, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import binascii
  7. import hashlib
  8. import logging
  9. logger = logging.getLogger()
  10. import time
  11. import hostapd
  12. from wpasupplicant import WpaSupplicant
  13. import hwsim_utils
  14. from utils import HwsimSkip
  15. from test_erp import check_erp_capa, start_erp_as
  16. def check_fils_capa(dev):
  17. capa = dev.get_capability("fils")
  18. if capa is None or "FILS" not in capa:
  19. raise HwsimSkip("FILS not supported")
  20. def test_fils_sk_full_auth(dev, apdev):
  21. """FILS SK full authentication"""
  22. check_fils_capa(dev[0])
  23. check_erp_capa(dev[0])
  24. start_erp_as(apdev[1])
  25. bssid = apdev[0]['bssid']
  26. params = hostapd.wpa2_eap_params(ssid="fils")
  27. params['wpa_key_mgmt'] = "FILS-SHA256"
  28. params['auth_server_port'] = "18128"
  29. params['erp_send_reauth_start'] = '1'
  30. params['erp_domain'] = 'example.com'
  31. params['fils_realm'] = 'example.com'
  32. params['wpa_group_rekey'] = '1'
  33. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  34. dev[0].scan_for_bss(bssid, freq=2412)
  35. bss = dev[0].get_bss(bssid)
  36. logger.debug("BSS: " + str(bss))
  37. if "[FILS]" not in bss['flags']:
  38. raise Exception("[FILS] flag not indicated")
  39. if "[WPA2-FILS-SHA256-CCMP]" not in bss['flags']:
  40. raise Exception("[WPA2-FILS-SHA256-CCMP] flag not indicated")
  41. res = dev[0].request("SCAN_RESULTS")
  42. logger.debug("SCAN_RESULTS: " + res)
  43. if "[FILS]" not in res:
  44. raise Exception("[FILS] flag not indicated")
  45. if "[WPA2-FILS-SHA256-CCMP]" not in res:
  46. raise Exception("[WPA2-FILS-SHA256-CCMP] flag not indicated")
  47. dev[0].request("ERP_FLUSH")
  48. dev[0].connect("fils", key_mgmt="FILS-SHA256",
  49. eap="PSK", identity="psk.user@example.com",
  50. password_hex="0123456789abcdef0123456789abcdef",
  51. erp="1", scan_freq="2412")
  52. hwsim_utils.test_connectivity(dev[0], hapd)
  53. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  54. if ev is None:
  55. raise Exception("GTK rekey timed out")
  56. hwsim_utils.test_connectivity(dev[0], hapd)
  57. conf = hapd.get_config()
  58. if conf['key_mgmt'] != 'FILS-SHA256':
  59. raise Exception("Unexpected config key_mgmt: " + conf['key_mgmt'])
  60. def test_fils_sk_sha384_full_auth(dev, apdev):
  61. """FILS SK full authentication (SHA384)"""
  62. check_fils_capa(dev[0])
  63. check_erp_capa(dev[0])
  64. start_erp_as(apdev[1])
  65. bssid = apdev[0]['bssid']
  66. params = hostapd.wpa2_eap_params(ssid="fils")
  67. params['wpa_key_mgmt'] = "FILS-SHA384"
  68. params['auth_server_port'] = "18128"
  69. params['erp_send_reauth_start'] = '1'
  70. params['erp_domain'] = 'example.com'
  71. params['fils_realm'] = 'example.com'
  72. params['wpa_group_rekey'] = '1'
  73. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  74. dev[0].scan_for_bss(bssid, freq=2412)
  75. bss = dev[0].get_bss(bssid)
  76. logger.debug("BSS: " + str(bss))
  77. if "[FILS]" not in bss['flags']:
  78. raise Exception("[FILS] flag not indicated")
  79. if "[WPA2-FILS-SHA384-CCMP]" not in bss['flags']:
  80. raise Exception("[WPA2-FILS-SHA384-CCMP] flag not indicated")
  81. res = dev[0].request("SCAN_RESULTS")
  82. logger.debug("SCAN_RESULTS: " + res)
  83. if "[FILS]" not in res:
  84. raise Exception("[FILS] flag not indicated")
  85. if "[WPA2-FILS-SHA384-CCMP]" not in res:
  86. raise Exception("[WPA2-FILS-SHA384-CCMP] flag not indicated")
  87. dev[0].request("ERP_FLUSH")
  88. dev[0].connect("fils", key_mgmt="FILS-SHA384",
  89. eap="PSK", identity="psk.user@example.com",
  90. password_hex="0123456789abcdef0123456789abcdef",
  91. erp="1", scan_freq="2412")
  92. hwsim_utils.test_connectivity(dev[0], hapd)
  93. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  94. if ev is None:
  95. raise Exception("GTK rekey timed out")
  96. hwsim_utils.test_connectivity(dev[0], hapd)
  97. conf = hapd.get_config()
  98. if conf['key_mgmt'] != 'FILS-SHA384':
  99. raise Exception("Unexpected config key_mgmt: " + conf['key_mgmt'])
  100. def test_fils_sk_pmksa_caching(dev, apdev):
  101. """FILS SK and PMKSA caching"""
  102. check_fils_capa(dev[0])
  103. check_erp_capa(dev[0])
  104. start_erp_as(apdev[1])
  105. bssid = apdev[0]['bssid']
  106. params = hostapd.wpa2_eap_params(ssid="fils")
  107. params['wpa_key_mgmt'] = "FILS-SHA256"
  108. params['auth_server_port'] = "18128"
  109. params['erp_domain'] = 'example.com'
  110. params['fils_realm'] = 'example.com'
  111. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  112. dev[0].scan_for_bss(bssid, freq=2412)
  113. dev[0].request("ERP_FLUSH")
  114. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  115. eap="PSK", identity="psk.user@example.com",
  116. password_hex="0123456789abcdef0123456789abcdef",
  117. erp="1", scan_freq="2412")
  118. pmksa = dev[0].get_pmksa(bssid)
  119. if pmksa is None:
  120. raise Exception("No PMKSA cache entry created")
  121. dev[0].request("DISCONNECT")
  122. dev[0].wait_disconnected()
  123. dev[0].dump_monitor()
  124. dev[0].select_network(id, freq=2412)
  125. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  126. "CTRL-EVENT-CONNECTED"], timeout=10)
  127. if ev is None:
  128. raise Exception("Connection using PMKSA caching timed out")
  129. if "CTRL-EVENT-EAP-STARTED" in ev:
  130. raise Exception("Unexpected EAP exchange")
  131. hwsim_utils.test_connectivity(dev[0], hapd)
  132. pmksa2 = dev[0].get_pmksa(bssid)
  133. if pmksa2 is None:
  134. raise Exception("No PMKSA cache entry found")
  135. if pmksa['pmkid'] != pmksa2['pmkid']:
  136. raise Exception("Unexpected PMKID change")
  137. # Verify EAPOL reauthentication after FILS authentication
  138. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  139. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  140. if ev is None:
  141. raise Exception("EAP authentication did not start")
  142. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  143. if ev is None:
  144. raise Exception("EAP authentication did not succeed")
  145. time.sleep(0.1)
  146. hwsim_utils.test_connectivity(dev[0], hapd)
  147. def test_fils_sk_erp(dev, apdev):
  148. """FILS SK using ERP"""
  149. run_fils_sk_erp(dev, apdev, "FILS-SHA256")
  150. def test_fils_sk_erp_sha384(dev, apdev):
  151. """FILS SK using ERP and SHA384"""
  152. run_fils_sk_erp(dev, apdev, "FILS-SHA384")
  153. def run_fils_sk_erp(dev, apdev, key_mgmt):
  154. check_fils_capa(dev[0])
  155. check_erp_capa(dev[0])
  156. start_erp_as(apdev[1])
  157. bssid = apdev[0]['bssid']
  158. params = hostapd.wpa2_eap_params(ssid="fils")
  159. params['wpa_key_mgmt'] = key_mgmt
  160. params['auth_server_port'] = "18128"
  161. params['erp_domain'] = 'example.com'
  162. params['fils_realm'] = 'example.com'
  163. params['disable_pmksa_caching'] = '1'
  164. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  165. dev[0].scan_for_bss(bssid, freq=2412)
  166. dev[0].request("ERP_FLUSH")
  167. id = dev[0].connect("fils", key_mgmt=key_mgmt,
  168. eap="PSK", identity="psk.user@example.com",
  169. password_hex="0123456789abcdef0123456789abcdef",
  170. erp="1", scan_freq="2412")
  171. dev[0].request("DISCONNECT")
  172. dev[0].wait_disconnected()
  173. dev[0].dump_monitor()
  174. dev[0].select_network(id, freq=2412)
  175. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  176. "EVENT-ASSOC-REJECT",
  177. "CTRL-EVENT-CONNECTED"], timeout=10)
  178. if ev is None:
  179. raise Exception("Connection using FILS/ERP timed out")
  180. if "CTRL-EVENT-EAP-STARTED" in ev:
  181. raise Exception("Unexpected EAP exchange")
  182. if "EVENT-ASSOC-REJECT" in ev:
  183. raise Exception("Association failed")
  184. hwsim_utils.test_connectivity(dev[0], hapd)
  185. def test_fils_sk_multiple_realms(dev, apdev):
  186. """FILS SK and multiple realms"""
  187. check_fils_capa(dev[0])
  188. check_erp_capa(dev[0])
  189. start_erp_as(apdev[1])
  190. bssid = apdev[0]['bssid']
  191. params = hostapd.wpa2_eap_params(ssid="fils")
  192. params['wpa_key_mgmt'] = "FILS-SHA256"
  193. params['auth_server_port'] = "18128"
  194. params['erp_domain'] = 'example.com'
  195. fils_realms = [ 'r1.example.org', 'r2.EXAMPLE.org', 'r3.example.org',
  196. 'r4.example.org', 'r5.example.org', 'r6.example.org',
  197. 'r7.example.org', 'r8.example.org',
  198. 'example.com',
  199. 'r9.example.org', 'r10.example.org', 'r11.example.org',
  200. 'r12.example.org', 'r13.example.org', 'r14.example.org',
  201. 'r15.example.org', 'r16.example.org' ]
  202. params['fils_realm'] = fils_realms
  203. params['fils_cache_id'] = "1234"
  204. params['hessid'] = bssid
  205. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  206. dev[0].scan_for_bss(bssid, freq=2412)
  207. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 275"):
  208. raise Exception("ANQP_GET command failed")
  209. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  210. if ev is None:
  211. raise Exception("GAS query timed out")
  212. bss = dev[0].get_bss(bssid)
  213. if 'fils_info' not in bss:
  214. raise Exception("FILS Indication element information missing")
  215. if bss['fils_info'] != '02b8':
  216. raise Exception("Unexpected FILS Information: " + bss['fils_info'])
  217. if 'fils_cache_id' not in bss:
  218. raise Exception("FILS Cache Identifier missing")
  219. if bss['fils_cache_id'] != '1234':
  220. raise Exception("Unexpected FILS Cache Identifier: " + bss['fils_cache_id'])
  221. if 'fils_realms' not in bss:
  222. raise Exception("FILS Realm Identifiers missing")
  223. expected = ''
  224. count = 0
  225. for realm in fils_realms:
  226. hash = hashlib.sha256(realm.lower()).digest()
  227. expected += binascii.hexlify(hash[0:2])
  228. count += 1
  229. if count == 7:
  230. break
  231. if bss['fils_realms'] != expected:
  232. raise Exception("Unexpected FILS Realm Identifiers: " + bss['fils_realms'])
  233. if 'anqp_fils_realm_info' not in bss:
  234. raise Exception("FILS Realm Information ANQP-element not seen")
  235. info = bss['anqp_fils_realm_info'];
  236. expected = ''
  237. for realm in fils_realms:
  238. hash = hashlib.sha256(realm.lower()).digest()
  239. expected += binascii.hexlify(hash[0:2])
  240. if info != expected:
  241. raise Exception("Unexpected FILS Realm Info ANQP-element: " + info)
  242. dev[0].request("ERP_FLUSH")
  243. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  244. eap="PSK", identity="psk.user@example.com",
  245. password_hex="0123456789abcdef0123456789abcdef",
  246. erp="1", scan_freq="2412")
  247. dev[0].request("DISCONNECT")
  248. dev[0].wait_disconnected()
  249. dev[0].dump_monitor()
  250. dev[0].select_network(id, freq=2412)
  251. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  252. "EVENT-ASSOC-REJECT",
  253. "CTRL-EVENT-CONNECTED"], timeout=10)
  254. if ev is None:
  255. raise Exception("Connection using FILS/ERP timed out")
  256. if "CTRL-EVENT-EAP-STARTED" in ev:
  257. raise Exception("Unexpected EAP exchange")
  258. if "EVENT-ASSOC-REJECT" in ev:
  259. raise Exception("Association failed")
  260. hwsim_utils.test_connectivity(dev[0], hapd)