test_fils.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. def test_fils_sk_sha384_full_auth(dev, apdev):
  58. """FILS SK full authentication (SHA384)"""
  59. check_fils_capa(dev[0])
  60. check_erp_capa(dev[0])
  61. start_erp_as(apdev[1])
  62. bssid = apdev[0]['bssid']
  63. params = hostapd.wpa2_eap_params(ssid="fils")
  64. params['wpa_key_mgmt'] = "FILS-SHA384"
  65. params['auth_server_port'] = "18128"
  66. params['erp_send_reauth_start'] = '1'
  67. params['erp_domain'] = 'example.com'
  68. params['fils_realm'] = 'example.com'
  69. params['wpa_group_rekey'] = '1'
  70. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  71. dev[0].scan_for_bss(bssid, freq=2412)
  72. bss = dev[0].get_bss(bssid)
  73. logger.debug("BSS: " + str(bss))
  74. if "[FILS]" not in bss['flags']:
  75. raise Exception("[FILS] flag not indicated")
  76. if "[WPA2-FILS-SHA384-CCMP]" not in bss['flags']:
  77. raise Exception("[WPA2-FILS-SHA384-CCMP] flag not indicated")
  78. res = dev[0].request("SCAN_RESULTS")
  79. logger.debug("SCAN_RESULTS: " + res)
  80. if "[FILS]" not in res:
  81. raise Exception("[FILS] flag not indicated")
  82. if "[WPA2-FILS-SHA384-CCMP]" not in res:
  83. raise Exception("[WPA2-FILS-SHA384-CCMP] flag not indicated")
  84. dev[0].request("ERP_FLUSH")
  85. dev[0].connect("fils", key_mgmt="FILS-SHA384",
  86. eap="PSK", identity="psk.user@example.com",
  87. password_hex="0123456789abcdef0123456789abcdef",
  88. erp="1", scan_freq="2412")
  89. hwsim_utils.test_connectivity(dev[0], hapd)
  90. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  91. if ev is None:
  92. raise Exception("GTK rekey timed out")
  93. hwsim_utils.test_connectivity(dev[0], hapd)
  94. def test_fils_sk_pmksa_caching(dev, apdev):
  95. """FILS SK and PMKSA caching"""
  96. check_fils_capa(dev[0])
  97. check_erp_capa(dev[0])
  98. start_erp_as(apdev[1])
  99. bssid = apdev[0]['bssid']
  100. params = hostapd.wpa2_eap_params(ssid="fils")
  101. params['wpa_key_mgmt'] = "FILS-SHA256"
  102. params['auth_server_port'] = "18128"
  103. params['erp_domain'] = 'example.com'
  104. params['fils_realm'] = 'example.com'
  105. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  106. dev[0].scan_for_bss(bssid, freq=2412)
  107. dev[0].request("ERP_FLUSH")
  108. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  109. eap="PSK", identity="psk.user@example.com",
  110. password_hex="0123456789abcdef0123456789abcdef",
  111. erp="1", scan_freq="2412")
  112. pmksa = dev[0].get_pmksa(bssid)
  113. if pmksa is None:
  114. raise Exception("No PMKSA cache entry created")
  115. dev[0].request("DISCONNECT")
  116. dev[0].wait_disconnected()
  117. dev[0].dump_monitor()
  118. dev[0].select_network(id, freq=2412)
  119. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  120. "CTRL-EVENT-CONNECTED"], timeout=10)
  121. if ev is None:
  122. raise Exception("Connection using PMKSA caching timed out")
  123. if "CTRL-EVENT-EAP-STARTED" in ev:
  124. raise Exception("Unexpected EAP exchange")
  125. hwsim_utils.test_connectivity(dev[0], hapd)
  126. pmksa2 = dev[0].get_pmksa(bssid)
  127. if pmksa2 is None:
  128. raise Exception("No PMKSA cache entry found")
  129. if pmksa['pmkid'] != pmksa2['pmkid']:
  130. raise Exception("Unexpected PMKID change")
  131. # Verify EAPOL reauthentication after FILS authentication
  132. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  133. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  134. if ev is None:
  135. raise Exception("EAP authentication did not start")
  136. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  137. if ev is None:
  138. raise Exception("EAP authentication did not succeed")
  139. time.sleep(0.1)
  140. hwsim_utils.test_connectivity(dev[0], hapd)
  141. def test_fils_sk_erp(dev, apdev):
  142. """FILS SK using ERP"""
  143. check_fils_capa(dev[0])
  144. check_erp_capa(dev[0])
  145. start_erp_as(apdev[1])
  146. bssid = apdev[0]['bssid']
  147. params = hostapd.wpa2_eap_params(ssid="fils")
  148. params['wpa_key_mgmt'] = "FILS-SHA256"
  149. params['auth_server_port'] = "18128"
  150. params['erp_domain'] = 'example.com'
  151. params['fils_realm'] = 'example.com'
  152. params['disable_pmksa_caching'] = '1'
  153. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  154. dev[0].scan_for_bss(bssid, freq=2412)
  155. dev[0].request("ERP_FLUSH")
  156. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  157. eap="PSK", identity="psk.user@example.com",
  158. password_hex="0123456789abcdef0123456789abcdef",
  159. erp="1", scan_freq="2412")
  160. dev[0].request("DISCONNECT")
  161. dev[0].wait_disconnected()
  162. dev[0].dump_monitor()
  163. dev[0].select_network(id, freq=2412)
  164. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  165. "EVENT-ASSOC-REJECT",
  166. "CTRL-EVENT-CONNECTED"], timeout=10)
  167. if ev is None:
  168. raise Exception("Connection using FILS/ERP timed out")
  169. if "CTRL-EVENT-EAP-STARTED" in ev:
  170. raise Exception("Unexpected EAP exchange")
  171. if "EVENT-ASSOC-REJECT" in ev:
  172. raise Exception("Association failed")
  173. hwsim_utils.test_connectivity(dev[0], hapd)
  174. def test_fils_sk_multiple_realms(dev, apdev):
  175. """FILS SK and multiple realms"""
  176. check_fils_capa(dev[0])
  177. check_erp_capa(dev[0])
  178. start_erp_as(apdev[1])
  179. bssid = apdev[0]['bssid']
  180. params = hostapd.wpa2_eap_params(ssid="fils")
  181. params['wpa_key_mgmt'] = "FILS-SHA256"
  182. params['auth_server_port'] = "18128"
  183. params['erp_domain'] = 'example.com'
  184. fils_realms = [ 'r1.example.org', 'r2.EXAMPLE.org', 'r3.example.org',
  185. 'r4.example.org', 'r5.example.org', 'r6.example.org',
  186. 'r7.example.org', 'r8.example.org',
  187. 'example.com',
  188. 'r9.example.org', 'r10.example.org', 'r11.example.org',
  189. 'r12.example.org', 'r13.example.org', 'r14.example.org',
  190. 'r15.example.org', 'r16.example.org' ]
  191. params['fils_realm'] = fils_realms
  192. params['fils_cache_id'] = "1234"
  193. params['hessid'] = bssid
  194. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  195. dev[0].scan_for_bss(bssid, freq=2412)
  196. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 275"):
  197. raise Exception("ANQP_GET command failed")
  198. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  199. if ev is None:
  200. raise Exception("GAS query timed out")
  201. bss = dev[0].get_bss(bssid)
  202. if 'fils_info' not in bss:
  203. raise Exception("FILS Indication element information missing")
  204. if bss['fils_info'] != '02b8':
  205. raise Exception("Unexpected FILS Information: " + bss['fils_info'])
  206. if 'fils_cache_id' not in bss:
  207. raise Exception("FILS Cache Identifier missing")
  208. if bss['fils_cache_id'] != '1234':
  209. raise Exception("Unexpected FILS Cache Identifier: " + bss['fils_cache_id'])
  210. if 'fils_realms' not in bss:
  211. raise Exception("FILS Realm Identifiers missing")
  212. expected = ''
  213. count = 0
  214. for realm in fils_realms:
  215. hash = hashlib.sha256(realm.lower()).digest()
  216. expected += binascii.hexlify(hash[0:2])
  217. count += 1
  218. if count == 7:
  219. break
  220. if bss['fils_realms'] != expected:
  221. raise Exception("Unexpected FILS Realm Identifiers: " + bss['fils_realms'])
  222. if 'anqp_fils_realm_info' not in bss:
  223. raise Exception("FILS Realm Information ANQP-element not seen")
  224. info = bss['anqp_fils_realm_info'];
  225. expected = ''
  226. for realm in fils_realms:
  227. hash = hashlib.sha256(realm.lower()).digest()
  228. expected += binascii.hexlify(hash[0:2])
  229. if info != expected:
  230. raise Exception("Unexpected FILS Realm Info ANQP-element: " + info)
  231. dev[0].request("ERP_FLUSH")
  232. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  233. eap="PSK", identity="psk.user@example.com",
  234. password_hex="0123456789abcdef0123456789abcdef",
  235. erp="1", scan_freq="2412")
  236. dev[0].request("DISCONNECT")
  237. dev[0].wait_disconnected()
  238. dev[0].dump_monitor()
  239. dev[0].select_network(id, freq=2412)
  240. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  241. "EVENT-ASSOC-REJECT",
  242. "CTRL-EVENT-CONNECTED"], timeout=10)
  243. if ev is None:
  244. raise Exception("Connection using FILS/ERP timed out")
  245. if "CTRL-EVENT-EAP-STARTED" in ev:
  246. raise Exception("Unexpected EAP exchange")
  247. if "EVENT-ASSOC-REJECT" in ev:
  248. raise Exception("Association failed")
  249. hwsim_utils.test_connectivity(dev[0], hapd)