test_fils.py 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  1. # Test cases for FILS
  2. # Copyright (c) 2015-2017, 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 os
  11. import socket
  12. import struct
  13. import time
  14. import hostapd
  15. from tshark import run_tshark
  16. from wpasupplicant import WpaSupplicant
  17. import hwsim_utils
  18. from utils import HwsimSkip, alloc_fail
  19. from test_erp import check_erp_capa, start_erp_as
  20. from test_ap_hs20 import ip_checksum
  21. def check_fils_capa(dev):
  22. capa = dev.get_capability("fils")
  23. if capa is None or "FILS" not in capa:
  24. raise HwsimSkip("FILS not supported")
  25. def check_fils_sk_pfs_capa(dev):
  26. capa = dev.get_capability("fils")
  27. if capa is None or "FILS-SK-PFS" not in capa:
  28. raise HwsimSkip("FILS-SK-PFS not supported")
  29. def test_fils_sk_full_auth(dev, apdev, params):
  30. """FILS SK full authentication"""
  31. check_fils_capa(dev[0])
  32. check_erp_capa(dev[0])
  33. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  34. bssid = apdev[0]['bssid']
  35. params = hostapd.wpa2_eap_params(ssid="fils")
  36. params['wpa_key_mgmt'] = "FILS-SHA256"
  37. params['auth_server_port'] = "18128"
  38. params['erp_send_reauth_start'] = '1'
  39. params['erp_domain'] = 'example.com'
  40. params['fils_realm'] = 'example.com'
  41. params['wpa_group_rekey'] = '1'
  42. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  43. dev[0].scan_for_bss(bssid, freq=2412)
  44. bss = dev[0].get_bss(bssid)
  45. logger.debug("BSS: " + str(bss))
  46. if "[FILS]" not in bss['flags']:
  47. raise Exception("[FILS] flag not indicated")
  48. if "[WPA2-FILS-SHA256-CCMP]" not in bss['flags']:
  49. raise Exception("[WPA2-FILS-SHA256-CCMP] flag not indicated")
  50. res = dev[0].request("SCAN_RESULTS")
  51. logger.debug("SCAN_RESULTS: " + res)
  52. if "[FILS]" not in res:
  53. raise Exception("[FILS] flag not indicated")
  54. if "[WPA2-FILS-SHA256-CCMP]" not in res:
  55. raise Exception("[WPA2-FILS-SHA256-CCMP] flag not indicated")
  56. dev[0].request("ERP_FLUSH")
  57. dev[0].connect("fils", key_mgmt="FILS-SHA256",
  58. eap="PSK", identity="psk.user@example.com",
  59. password_hex="0123456789abcdef0123456789abcdef",
  60. erp="1", scan_freq="2412")
  61. hwsim_utils.test_connectivity(dev[0], hapd)
  62. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  63. if ev is None:
  64. raise Exception("GTK rekey timed out")
  65. hwsim_utils.test_connectivity(dev[0], hapd)
  66. conf = hapd.get_config()
  67. if conf['key_mgmt'] != 'FILS-SHA256':
  68. raise Exception("Unexpected config key_mgmt: " + conf['key_mgmt'])
  69. def test_fils_sk_sha384_full_auth(dev, apdev, params):
  70. """FILS SK full authentication (SHA384)"""
  71. check_fils_capa(dev[0])
  72. check_erp_capa(dev[0])
  73. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  74. bssid = apdev[0]['bssid']
  75. params = hostapd.wpa2_eap_params(ssid="fils")
  76. params['wpa_key_mgmt'] = "FILS-SHA384"
  77. params['auth_server_port'] = "18128"
  78. params['erp_send_reauth_start'] = '1'
  79. params['erp_domain'] = 'example.com'
  80. params['fils_realm'] = 'example.com'
  81. params['wpa_group_rekey'] = '1'
  82. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  83. dev[0].scan_for_bss(bssid, freq=2412)
  84. bss = dev[0].get_bss(bssid)
  85. logger.debug("BSS: " + str(bss))
  86. if "[FILS]" not in bss['flags']:
  87. raise Exception("[FILS] flag not indicated")
  88. if "[WPA2-FILS-SHA384-CCMP]" not in bss['flags']:
  89. raise Exception("[WPA2-FILS-SHA384-CCMP] flag not indicated")
  90. res = dev[0].request("SCAN_RESULTS")
  91. logger.debug("SCAN_RESULTS: " + res)
  92. if "[FILS]" not in res:
  93. raise Exception("[FILS] flag not indicated")
  94. if "[WPA2-FILS-SHA384-CCMP]" not in res:
  95. raise Exception("[WPA2-FILS-SHA384-CCMP] flag not indicated")
  96. dev[0].request("ERP_FLUSH")
  97. dev[0].connect("fils", key_mgmt="FILS-SHA384",
  98. eap="PSK", identity="psk.user@example.com",
  99. password_hex="0123456789abcdef0123456789abcdef",
  100. erp="1", scan_freq="2412")
  101. hwsim_utils.test_connectivity(dev[0], hapd)
  102. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  103. if ev is None:
  104. raise Exception("GTK rekey timed out")
  105. hwsim_utils.test_connectivity(dev[0], hapd)
  106. conf = hapd.get_config()
  107. if conf['key_mgmt'] != 'FILS-SHA384':
  108. raise Exception("Unexpected config key_mgmt: " + conf['key_mgmt'])
  109. def test_fils_sk_pmksa_caching(dev, apdev, params):
  110. """FILS SK and PMKSA caching"""
  111. check_fils_capa(dev[0])
  112. check_erp_capa(dev[0])
  113. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  114. bssid = apdev[0]['bssid']
  115. params = hostapd.wpa2_eap_params(ssid="fils")
  116. params['wpa_key_mgmt'] = "FILS-SHA256"
  117. params['auth_server_port'] = "18128"
  118. params['erp_domain'] = 'example.com'
  119. params['fils_realm'] = 'example.com'
  120. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  121. dev[0].scan_for_bss(bssid, freq=2412)
  122. dev[0].request("ERP_FLUSH")
  123. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  124. eap="PSK", identity="psk.user@example.com",
  125. password_hex="0123456789abcdef0123456789abcdef",
  126. erp="1", scan_freq="2412")
  127. pmksa = dev[0].get_pmksa(bssid)
  128. if pmksa is None:
  129. raise Exception("No PMKSA cache entry created")
  130. dev[0].request("DISCONNECT")
  131. dev[0].wait_disconnected()
  132. dev[0].dump_monitor()
  133. dev[0].select_network(id, freq=2412)
  134. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  135. "CTRL-EVENT-CONNECTED"], timeout=10)
  136. if ev is None:
  137. raise Exception("Connection using PMKSA caching timed out")
  138. if "CTRL-EVENT-EAP-STARTED" in ev:
  139. raise Exception("Unexpected EAP exchange")
  140. hwsim_utils.test_connectivity(dev[0], hapd)
  141. pmksa2 = dev[0].get_pmksa(bssid)
  142. if pmksa2 is None:
  143. raise Exception("No PMKSA cache entry found")
  144. if pmksa['pmkid'] != pmksa2['pmkid']:
  145. raise Exception("Unexpected PMKID change")
  146. # Verify EAPOL reauthentication after FILS authentication
  147. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  148. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  149. if ev is None:
  150. raise Exception("EAP authentication did not start")
  151. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  152. if ev is None:
  153. raise Exception("EAP authentication did not succeed")
  154. time.sleep(0.1)
  155. hwsim_utils.test_connectivity(dev[0], hapd)
  156. def test_fils_sk_pmksa_caching_and_cache_id(dev, apdev):
  157. """FILS SK and PMKSA caching with Cache Identifier"""
  158. check_fils_capa(dev[0])
  159. check_erp_capa(dev[0])
  160. bssid = apdev[0]['bssid']
  161. params = hostapd.wpa2_eap_params(ssid="fils")
  162. params['wpa_key_mgmt'] = "FILS-SHA256"
  163. params['auth_server_port'] = "18128"
  164. params['erp_domain'] = 'example.com'
  165. params['fils_realm'] = 'example.com'
  166. params['fils_cache_id'] = "abcd"
  167. params["radius_server_clients"] = "auth_serv/radius_clients.conf"
  168. params["radius_server_auth_port"] = '18128'
  169. params["eap_server"] = "1"
  170. params["eap_user_file"] = "auth_serv/eap_user.conf"
  171. params["ca_cert"] = "auth_serv/ca.pem"
  172. params["server_cert"] = "auth_serv/server.pem"
  173. params["private_key"] = "auth_serv/server.key"
  174. params["eap_sim_db"] = "unix:/tmp/hlr_auc_gw.sock"
  175. params["dh_file"] = "auth_serv/dh.conf"
  176. params["pac_opaque_encr_key"] = "000102030405060708090a0b0c0d0e0f"
  177. params["eap_fast_a_id"] = "101112131415161718191a1b1c1d1e1f"
  178. params["eap_fast_a_id_info"] = "test server"
  179. params["eap_server_erp"] = "1"
  180. params["erp_domain"] = "example.com"
  181. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  182. dev[0].scan_for_bss(bssid, freq=2412)
  183. dev[0].request("ERP_FLUSH")
  184. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  185. eap="PSK", identity="psk.user@example.com",
  186. password_hex="0123456789abcdef0123456789abcdef",
  187. erp="1", scan_freq="2412")
  188. res = dev[0].request("PMKSA")
  189. if "FILS Cache Identifier" not in res:
  190. raise Exception("PMKSA list does not include FILS Cache Identifier")
  191. pmksa = dev[0].get_pmksa(bssid)
  192. if pmksa is None:
  193. raise Exception("No PMKSA cache entry created")
  194. if "cache_id" not in pmksa:
  195. raise Exception("No FILS Cache Identifier listed")
  196. if pmksa["cache_id"] != "abcd":
  197. raise Exception("The configured FILS Cache Identifier not seen in PMKSA")
  198. bssid2 = apdev[1]['bssid']
  199. params = hostapd.wpa2_eap_params(ssid="fils")
  200. params['wpa_key_mgmt'] = "FILS-SHA256"
  201. params['auth_server_port'] = "18128"
  202. params['erp_domain'] = 'example.com'
  203. params['fils_realm'] = 'example.com'
  204. params['fils_cache_id'] = "abcd"
  205. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  206. dev[0].scan_for_bss(bssid2, freq=2412)
  207. dev[0].dump_monitor()
  208. if "OK" not in dev[0].request("ROAM " + bssid2):
  209. raise Exception("ROAM failed")
  210. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  211. "CTRL-EVENT-CONNECTED"], timeout=10)
  212. if ev is None:
  213. raise Exception("Connection using PMKSA caching timed out")
  214. if "CTRL-EVENT-EAP-STARTED" in ev:
  215. raise Exception("Unexpected EAP exchange")
  216. if bssid2 not in ev:
  217. raise Exception("Failed to connect to the second AP")
  218. hwsim_utils.test_connectivity(dev[0], hapd2)
  219. pmksa2 = dev[0].get_pmksa(bssid2)
  220. if pmksa2:
  221. raise Exception("Unexpected extra PMKSA cache added")
  222. pmksa2 = dev[0].get_pmksa(bssid)
  223. if not pmksa2:
  224. raise Exception("Original PMKSA cache entry removed")
  225. if pmksa['pmkid'] != pmksa2['pmkid']:
  226. raise Exception("Unexpected PMKID change")
  227. def test_fils_sk_pmksa_caching_ctrl_ext(dev, apdev, params):
  228. """FILS SK and PMKSA caching with Cache Identifier and external management"""
  229. check_fils_capa(dev[0])
  230. check_erp_capa(dev[0])
  231. hapd_as = start_erp_as(apdev[1],
  232. msk_dump=os.path.join(params['logdir'], "msk.lst"))
  233. bssid = apdev[0]['bssid']
  234. params = hostapd.wpa2_eap_params(ssid="fils")
  235. params['wpa_key_mgmt'] = "FILS-SHA384"
  236. params['auth_server_port'] = "18128"
  237. params['erp_send_reauth_start'] = '1'
  238. params['erp_domain'] = 'example.com'
  239. params['fils_realm'] = 'example.com'
  240. params['fils_cache_id'] = "ffee"
  241. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  242. dev[0].scan_for_bss(bssid, freq=2412)
  243. dev[0].request("ERP_FLUSH")
  244. id = dev[0].connect("fils", key_mgmt="FILS-SHA384",
  245. eap="PSK", identity="psk.user@example.com",
  246. password_hex="0123456789abcdef0123456789abcdef",
  247. erp="1", scan_freq="2412")
  248. res1 = dev[0].request("PMKSA_GET %d" % id)
  249. logger.info("PMKSA_GET: " + res1)
  250. if "UNKNOWN COMMAND" in res1:
  251. raise HwsimSkip("PMKSA_GET not supported in the build")
  252. if bssid not in res1:
  253. raise Exception("PMKSA cache entry missing")
  254. if "ffee" not in res1:
  255. raise Exception("FILS Cache Identifier not seen in PMKSA cache entry")
  256. dev[0].request("DISCONNECT")
  257. dev[0].wait_disconnected()
  258. hapd_as.disable()
  259. dev[0].scan_for_bss(bssid, freq=2412)
  260. dev[0].request("PMKSA_FLUSH")
  261. dev[0].request("ERP_FLUSH")
  262. for entry in res1.splitlines():
  263. if "OK" not in dev[0].request("PMKSA_ADD %d %s" % (id, entry)):
  264. raise Exception("Failed to add PMKSA entry")
  265. bssid2 = apdev[1]['bssid']
  266. params = hostapd.wpa2_eap_params(ssid="fils")
  267. params['wpa_key_mgmt'] = "FILS-SHA384"
  268. params['auth_server_port'] = "18128"
  269. params['erp_send_reauth_start'] = '1'
  270. params['erp_domain'] = 'example.com'
  271. params['fils_realm'] = 'example.com'
  272. params['fils_cache_id'] = "ffee"
  273. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  274. dev[0].scan_for_bss(bssid2, freq=2412)
  275. dev[0].set_network(id, "bssid", bssid2)
  276. dev[0].select_network(id, freq=2412)
  277. ev = dev[0].wait_connected()
  278. if bssid2 not in ev:
  279. raise Exception("Unexpected BSS selected")
  280. def test_fils_sk_erp(dev, apdev, params):
  281. """FILS SK using ERP"""
  282. run_fils_sk_erp(dev, apdev, "FILS-SHA256", params)
  283. def test_fils_sk_erp_sha384(dev, apdev, params):
  284. """FILS SK using ERP and SHA384"""
  285. run_fils_sk_erp(dev, apdev, "FILS-SHA384", params)
  286. def run_fils_sk_erp(dev, apdev, key_mgmt, params):
  287. check_fils_capa(dev[0])
  288. check_erp_capa(dev[0])
  289. start_erp_as(apdev[1],
  290. msk_dump=os.path.join(params['logdir'], "msk.lst"))
  291. bssid = apdev[0]['bssid']
  292. params = hostapd.wpa2_eap_params(ssid="fils")
  293. params['wpa_key_mgmt'] = key_mgmt
  294. params['auth_server_port'] = "18128"
  295. params['erp_domain'] = 'example.com'
  296. params['fils_realm'] = 'example.com'
  297. params['disable_pmksa_caching'] = '1'
  298. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  299. dev[0].scan_for_bss(bssid, freq=2412)
  300. dev[0].request("ERP_FLUSH")
  301. id = dev[0].connect("fils", key_mgmt=key_mgmt,
  302. eap="PSK", identity="psk.user@example.com",
  303. password_hex="0123456789abcdef0123456789abcdef",
  304. erp="1", scan_freq="2412")
  305. dev[0].request("DISCONNECT")
  306. dev[0].wait_disconnected()
  307. dev[0].dump_monitor()
  308. dev[0].select_network(id, freq=2412)
  309. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  310. "EVENT-ASSOC-REJECT",
  311. "CTRL-EVENT-CONNECTED"], timeout=10)
  312. if ev is None:
  313. raise Exception("Connection using FILS/ERP timed out")
  314. if "CTRL-EVENT-EAP-STARTED" in ev:
  315. raise Exception("Unexpected EAP exchange")
  316. if "EVENT-ASSOC-REJECT" in ev:
  317. raise Exception("Association failed")
  318. hwsim_utils.test_connectivity(dev[0], hapd)
  319. def test_fils_sk_erp_followed_by_pmksa_caching(dev, apdev, params):
  320. check_fils_capa(dev[0])
  321. check_erp_capa(dev[0])
  322. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  323. bssid = apdev[0]['bssid']
  324. params = hostapd.wpa2_eap_params(ssid="fils")
  325. params['wpa_key_mgmt'] = "FILS-SHA256"
  326. params['auth_server_port'] = "18128"
  327. params['erp_domain'] = 'example.com'
  328. params['fils_realm'] = 'example.com'
  329. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  330. dev[0].scan_for_bss(bssid, freq=2412)
  331. dev[0].request("ERP_FLUSH")
  332. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  333. eap="PSK", identity="psk.user@example.com",
  334. password_hex="0123456789abcdef0123456789abcdef",
  335. erp="1", scan_freq="2412")
  336. dev[0].request("DISCONNECT")
  337. dev[0].wait_disconnected()
  338. # Force the second connection to use ERP by deleting the PMKSA entry.
  339. dev[0].request("PMKSA_FLUSH")
  340. dev[0].dump_monitor()
  341. dev[0].select_network(id, freq=2412)
  342. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  343. "EVENT-ASSOC-REJECT",
  344. "CTRL-EVENT-CONNECTED"], timeout=10)
  345. if ev is None:
  346. raise Exception("Connection using FILS/ERP timed out")
  347. if "CTRL-EVENT-EAP-STARTED" in ev:
  348. raise Exception("Unexpected EAP exchange")
  349. if "EVENT-ASSOC-REJECT" in ev:
  350. raise Exception("Association failed")
  351. hwsim_utils.test_connectivity(dev[0], hapd)
  352. pmksa = dev[0].get_pmksa(bssid)
  353. if pmksa is None:
  354. raise Exception("No PMKSA cache entry created")
  355. dev[0].request("DISCONNECT")
  356. dev[0].wait_disconnected()
  357. # The third connection is expected to use PMKSA caching for FILS
  358. # authentication.
  359. dev[0].dump_monitor()
  360. dev[0].select_network(id, freq=2412)
  361. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  362. "EVENT-ASSOC-REJECT",
  363. "CTRL-EVENT-CONNECTED"], timeout=10)
  364. if ev is None:
  365. raise Exception("Connection using PMKSA caching timed out")
  366. if "CTRL-EVENT-EAP-STARTED" in ev:
  367. raise Exception("Unexpected EAP exchange")
  368. if "EVENT-ASSOC-REJECT" in ev:
  369. raise Exception("Association failed")
  370. hwsim_utils.test_connectivity(dev[0], hapd)
  371. pmksa2 = dev[0].get_pmksa(bssid)
  372. if pmksa2 is None:
  373. raise Exception("No PMKSA cache entry found")
  374. if pmksa['pmkid'] != pmksa2['pmkid']:
  375. raise Exception("Unexpected PMKID change")
  376. def test_fils_sk_erp_another_ssid(dev, apdev, params):
  377. """FILS SK using ERP and roam to another SSID"""
  378. check_fils_capa(dev[0])
  379. check_erp_capa(dev[0])
  380. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  381. bssid = apdev[0]['bssid']
  382. params = hostapd.wpa2_eap_params(ssid="fils")
  383. params['wpa_key_mgmt'] = "FILS-SHA256"
  384. params['auth_server_port'] = "18128"
  385. params['erp_domain'] = 'example.com'
  386. params['fils_realm'] = 'example.com'
  387. params['disable_pmksa_caching'] = '1'
  388. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  389. dev[0].scan_for_bss(bssid, freq=2412)
  390. dev[0].request("ERP_FLUSH")
  391. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  392. eap="PSK", identity="psk.user@example.com",
  393. password_hex="0123456789abcdef0123456789abcdef",
  394. erp="1", scan_freq="2412")
  395. dev[0].request("DISCONNECT")
  396. dev[0].wait_disconnected()
  397. hapd.disable()
  398. dev[0].flush_scan_cache()
  399. if "FAIL" in dev[0].request("PMKSA_FLUSH"):
  400. raise Exception("PMKSA_FLUSH failed")
  401. params = hostapd.wpa2_eap_params(ssid="fils2")
  402. params['wpa_key_mgmt'] = "FILS-SHA256"
  403. params['auth_server_port'] = "18128"
  404. params['erp_domain'] = 'example.com'
  405. params['fils_realm'] = 'example.com'
  406. params['disable_pmksa_caching'] = '1'
  407. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  408. dev[0].scan_for_bss(bssid, freq=2412)
  409. dev[0].dump_monitor()
  410. id = dev[0].connect("fils2", key_mgmt="FILS-SHA256",
  411. eap="PSK", identity="psk.user@example.com",
  412. password_hex="0123456789abcdef0123456789abcdef",
  413. erp="1", scan_freq="2412", wait_connect=False)
  414. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  415. "EVENT-ASSOC-REJECT",
  416. "CTRL-EVENT-CONNECTED"], timeout=10)
  417. if ev is None:
  418. raise Exception("Connection using FILS/ERP timed out")
  419. if "CTRL-EVENT-EAP-STARTED" in ev:
  420. raise Exception("Unexpected EAP exchange")
  421. if "EVENT-ASSOC-REJECT" in ev:
  422. raise Exception("Association failed")
  423. hwsim_utils.test_connectivity(dev[0], hapd)
  424. def test_fils_sk_multiple_realms(dev, apdev, params):
  425. """FILS SK and multiple realms"""
  426. check_fils_capa(dev[0])
  427. check_erp_capa(dev[0])
  428. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  429. bssid = apdev[0]['bssid']
  430. params = hostapd.wpa2_eap_params(ssid="fils")
  431. params['wpa_key_mgmt'] = "FILS-SHA256"
  432. params['auth_server_port'] = "18128"
  433. params['erp_domain'] = 'example.com'
  434. fils_realms = [ 'r1.example.org', 'r2.EXAMPLE.org', 'r3.example.org',
  435. 'r4.example.org', 'r5.example.org', 'r6.example.org',
  436. 'r7.example.org', 'r8.example.org',
  437. 'example.com',
  438. 'r9.example.org', 'r10.example.org', 'r11.example.org',
  439. 'r12.example.org', 'r13.example.org', 'r14.example.org',
  440. 'r15.example.org', 'r16.example.org' ]
  441. params['fils_realm'] = fils_realms
  442. params['fils_cache_id'] = "1234"
  443. params['hessid'] = bssid
  444. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  445. dev[0].scan_for_bss(bssid, freq=2412)
  446. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 275"):
  447. raise Exception("ANQP_GET command failed")
  448. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  449. if ev is None:
  450. raise Exception("GAS query timed out")
  451. bss = dev[0].get_bss(bssid)
  452. if 'fils_info' not in bss:
  453. raise Exception("FILS Indication element information missing")
  454. if bss['fils_info'] != '02b8':
  455. raise Exception("Unexpected FILS Information: " + bss['fils_info'])
  456. if 'fils_cache_id' not in bss:
  457. raise Exception("FILS Cache Identifier missing")
  458. if bss['fils_cache_id'] != '1234':
  459. raise Exception("Unexpected FILS Cache Identifier: " + bss['fils_cache_id'])
  460. if 'fils_realms' not in bss:
  461. raise Exception("FILS Realm Identifiers missing")
  462. expected = ''
  463. count = 0
  464. for realm in fils_realms:
  465. hash = hashlib.sha256(realm.lower()).digest()
  466. expected += binascii.hexlify(hash[0:2])
  467. count += 1
  468. if count == 7:
  469. break
  470. if bss['fils_realms'] != expected:
  471. raise Exception("Unexpected FILS Realm Identifiers: " + bss['fils_realms'])
  472. if 'anqp_fils_realm_info' not in bss:
  473. raise Exception("FILS Realm Information ANQP-element not seen")
  474. info = bss['anqp_fils_realm_info'];
  475. expected = ''
  476. for realm in fils_realms:
  477. hash = hashlib.sha256(realm.lower()).digest()
  478. expected += binascii.hexlify(hash[0:2])
  479. if info != expected:
  480. raise Exception("Unexpected FILS Realm Info ANQP-element: " + info)
  481. dev[0].request("ERP_FLUSH")
  482. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  483. eap="PSK", identity="psk.user@example.com",
  484. password_hex="0123456789abcdef0123456789abcdef",
  485. erp="1", scan_freq="2412")
  486. dev[0].request("DISCONNECT")
  487. dev[0].wait_disconnected()
  488. dev[0].dump_monitor()
  489. dev[0].select_network(id, freq=2412)
  490. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  491. "EVENT-ASSOC-REJECT",
  492. "CTRL-EVENT-CONNECTED"], timeout=10)
  493. if ev is None:
  494. raise Exception("Connection using FILS/ERP timed out")
  495. if "CTRL-EVENT-EAP-STARTED" in ev:
  496. raise Exception("Unexpected EAP exchange")
  497. if "EVENT-ASSOC-REJECT" in ev:
  498. raise Exception("Association failed")
  499. hwsim_utils.test_connectivity(dev[0], hapd)
  500. # DHCP message op codes
  501. BOOTREQUEST=1
  502. BOOTREPLY=2
  503. OPT_PAD=0
  504. OPT_DHCP_MESSAGE_TYPE=53
  505. OPT_RAPID_COMMIT=80
  506. OPT_END=255
  507. DHCPDISCOVER=1
  508. DHCPOFFER=2
  509. DHCPREQUEST=3
  510. DHCPDECLINE=4
  511. DHCPACK=5
  512. DHCPNAK=6
  513. DHCPRELEASE=7
  514. DHCPINFORM=8
  515. def build_dhcp(req, dhcp_msg, chaddr, giaddr="0.0.0.0",
  516. ip_src="0.0.0.0", ip_dst="255.255.255.255",
  517. rapid_commit=True, override_op=None, magic_override=None,
  518. opt_end=True, extra_op=None):
  519. proto = '\x08\x00' # IPv4
  520. _ip_src = socket.inet_pton(socket.AF_INET, ip_src)
  521. _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst)
  522. _ciaddr = '\x00\x00\x00\x00'
  523. _yiaddr = '\x00\x00\x00\x00'
  524. _siaddr = '\x00\x00\x00\x00'
  525. _giaddr = socket.inet_pton(socket.AF_INET, giaddr)
  526. _chaddr = binascii.unhexlify(chaddr.replace(':','')) + 10*'\x00'
  527. htype = 1 # Hardware address type; 1 = Ethernet
  528. hlen = 6 # Hardware address length
  529. hops = 0
  530. xid = 123456
  531. secs = 0
  532. flags = 0
  533. if req:
  534. op = BOOTREQUEST
  535. src_port = 68
  536. dst_port = 67
  537. else:
  538. op = BOOTREPLY
  539. src_port = 67
  540. dst_port = 68
  541. if override_op is not None:
  542. op = override_op
  543. payload = struct.pack('>BBBBLHH', op, htype, hlen, hops, xid, secs, flags)
  544. sname = 64*'\x00'
  545. file = 128*'\x00'
  546. payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + sname + file
  547. # magic - DHCP
  548. if magic_override is not None:
  549. payload += magic_override
  550. else:
  551. payload += '\x63\x82\x53\x63'
  552. # Option: DHCP Message Type
  553. if dhcp_msg is not None:
  554. payload += struct.pack('BBB', OPT_DHCP_MESSAGE_TYPE, 1, dhcp_msg)
  555. if rapid_commit:
  556. # Option: Rapid Commit
  557. payload += struct.pack('BB', OPT_RAPID_COMMIT, 0)
  558. if extra_op:
  559. payload += extra_op
  560. # End Option
  561. if opt_end:
  562. payload += struct.pack('B', OPT_END)
  563. udp = struct.pack('>HHHH', src_port, dst_port,
  564. 8 + len(payload), 0) + payload
  565. tot_len = 20 + len(udp)
  566. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  567. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  568. csum = ip_checksum(ipv4)
  569. ipv4 = start + csum + _ip_src + _ip_dst
  570. return proto + ipv4 + udp
  571. def fils_hlp_config(fils_hlp_wait_time=10000):
  572. params = hostapd.wpa2_eap_params(ssid="fils")
  573. params['wpa_key_mgmt'] = "FILS-SHA256"
  574. params['auth_server_port'] = "18128"
  575. params['erp_domain'] = 'example.com'
  576. params['fils_realm'] = 'example.com'
  577. params['disable_pmksa_caching'] = '1'
  578. params['own_ip_addr'] = '127.0.0.3'
  579. params['dhcp_server'] = '127.0.0.2'
  580. params['fils_hlp_wait_time'] = str(fils_hlp_wait_time)
  581. return params
  582. def test_fils_sk_hlp(dev, apdev, params):
  583. """FILS SK HLP (rapid commit server)"""
  584. run_fils_sk_hlp(dev, apdev, True, params)
  585. def test_fils_sk_hlp_no_rapid_commit(dev, apdev, params):
  586. """FILS SK HLP (no rapid commit server)"""
  587. run_fils_sk_hlp(dev, apdev, False, params)
  588. def run_fils_sk_hlp(dev, apdev, rapid_commit_server, params):
  589. check_fils_capa(dev[0])
  590. check_erp_capa(dev[0])
  591. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  592. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  593. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  594. sock.settimeout(5)
  595. sock.bind(("127.0.0.2", 67))
  596. bssid = apdev[0]['bssid']
  597. params = fils_hlp_config()
  598. params['fils_hlp_wait_time'] = '10000'
  599. if not rapid_commit_server:
  600. params['dhcp_rapid_commit_proxy'] = '1'
  601. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  602. dev[0].scan_for_bss(bssid, freq=2412)
  603. dev[0].request("ERP_FLUSH")
  604. if "OK" not in dev[0].request("FILS_HLP_REQ_FLUSH"):
  605. raise Exception("Failed to flush pending FILS HLP requests")
  606. tests = [ "",
  607. "q",
  608. "ff:ff:ff:ff:ff:ff",
  609. "ff:ff:ff:ff:ff:ff q" ]
  610. for t in tests:
  611. if "FAIL" not in dev[0].request("FILS_HLP_REQ_ADD " + t):
  612. raise Exception("Invalid FILS_HLP_REQ_ADD accepted: " + t)
  613. dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  614. chaddr=dev[0].own_addr())
  615. tests = [ "ff:ff:ff:ff:ff:ff aabb",
  616. "ff:ff:ff:ff:ff:ff " + 255*'cc',
  617. hapd.own_addr() + " ddee010203040506070809",
  618. "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc) ]
  619. for t in tests:
  620. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + t):
  621. raise Exception("FILS_HLP_REQ_ADD failed: " + t)
  622. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  623. eap="PSK", identity="psk.user@example.com",
  624. password_hex="0123456789abcdef0123456789abcdef",
  625. erp="1", scan_freq="2412")
  626. dev[0].request("DISCONNECT")
  627. dev[0].wait_disconnected()
  628. dev[0].dump_monitor()
  629. dev[0].select_network(id, freq=2412)
  630. (msg,addr) = sock.recvfrom(1000)
  631. logger.debug("Received DHCP message from %s" % str(addr))
  632. if rapid_commit_server:
  633. # TODO: Proper rapid commit response
  634. dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPACK,
  635. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  636. sock.sendto(dhcpdisc[2+20+8:], addr)
  637. else:
  638. dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  639. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  640. sock.sendto(dhcpdisc[2+20+8:], addr)
  641. (msg,addr) = sock.recvfrom(1000)
  642. logger.debug("Received DHCP message from %s" % str(addr))
  643. dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPACK, rapid_commit=False,
  644. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  645. sock.sendto(dhcpdisc[2+20+8:], addr)
  646. ev = dev[0].wait_event(["FILS-HLP-RX"], timeout=10)
  647. if ev is None:
  648. raise Exception("FILS HLP response not reported")
  649. vals = ev.split(' ')
  650. frame = binascii.unhexlify(vals[3].split('=')[1])
  651. proto, = struct.unpack('>H', frame[0:2])
  652. if proto != 0x0800:
  653. raise Exception("Unexpected ethertype in HLP response: %d" % proto)
  654. frame = frame[2:]
  655. ip = frame[0:20]
  656. if ip_checksum(ip) != '\x00\x00':
  657. raise Exception("IP header checksum mismatch in HLP response")
  658. frame = frame[20:]
  659. udp = frame[0:8]
  660. frame = frame[8:]
  661. sport, dport, ulen, ucheck = struct.unpack('>HHHH', udp)
  662. if sport != 67 or dport != 68:
  663. raise Exception("Unexpected UDP port in HLP response")
  664. dhcp = frame[0:28]
  665. frame = frame[28:]
  666. op,htype,hlen,hops,xid,secs,flags,ciaddr,yiaddr,siaddr,giaddr = struct.unpack('>4BL2H4L', dhcp)
  667. chaddr = frame[0:16]
  668. frame = frame[16:]
  669. sname = frame[0:64]
  670. frame = frame[64:]
  671. file = frame[0:128]
  672. frame = frame[128:]
  673. options = frame
  674. if options[0:4] != '\x63\x82\x53\x63':
  675. raise Exception("No DHCP magic seen in HLP response")
  676. options = options[4:]
  677. # TODO: fully parse and validate DHCPACK options
  678. if struct.pack('BBB', OPT_DHCP_MESSAGE_TYPE, 1, DHCPACK) not in options:
  679. raise Exception("DHCPACK not in HLP response")
  680. dev[0].wait_connected()
  681. dev[0].request("FILS_HLP_REQ_FLUSH")
  682. def test_fils_sk_hlp_timeout(dev, apdev, params):
  683. """FILS SK HLP (rapid commit server timeout)"""
  684. check_fils_capa(dev[0])
  685. check_erp_capa(dev[0])
  686. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  687. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  688. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  689. sock.settimeout(5)
  690. sock.bind(("127.0.0.2", 67))
  691. bssid = apdev[0]['bssid']
  692. params = fils_hlp_config(fils_hlp_wait_time=30)
  693. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  694. dev[0].scan_for_bss(bssid, freq=2412)
  695. dev[0].request("ERP_FLUSH")
  696. if "OK" not in dev[0].request("FILS_HLP_REQ_FLUSH"):
  697. raise Exception("Failed to flush pending FILS HLP requests")
  698. dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  699. chaddr=dev[0].own_addr())
  700. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc)):
  701. raise Exception("FILS_HLP_REQ_ADD failed")
  702. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  703. eap="PSK", identity="psk.user@example.com",
  704. password_hex="0123456789abcdef0123456789abcdef",
  705. erp="1", scan_freq="2412")
  706. dev[0].request("DISCONNECT")
  707. dev[0].wait_disconnected()
  708. dev[0].dump_monitor()
  709. dev[0].select_network(id, freq=2412)
  710. (msg,addr) = sock.recvfrom(1000)
  711. logger.debug("Received DHCP message from %s" % str(addr))
  712. # Wait for HLP wait timeout to hit
  713. # FILS: HLP response timeout - continue with association response
  714. dev[0].wait_connected()
  715. dev[0].request("FILS_HLP_REQ_FLUSH")
  716. def test_fils_sk_hlp_oom(dev, apdev, params):
  717. """FILS SK HLP and hostapd OOM"""
  718. check_fils_capa(dev[0])
  719. check_erp_capa(dev[0])
  720. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  721. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  722. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  723. sock.settimeout(5)
  724. sock.bind(("127.0.0.2", 67))
  725. bssid = apdev[0]['bssid']
  726. params = fils_hlp_config(fils_hlp_wait_time=500)
  727. params['dhcp_rapid_commit_proxy'] = '1'
  728. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  729. dev[0].scan_for_bss(bssid, freq=2412)
  730. dev[0].request("ERP_FLUSH")
  731. if "OK" not in dev[0].request("FILS_HLP_REQ_FLUSH"):
  732. raise Exception("Failed to flush pending FILS HLP requests")
  733. dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  734. chaddr=dev[0].own_addr())
  735. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc)):
  736. raise Exception("FILS_HLP_REQ_ADD failed")
  737. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  738. eap="PSK", identity="psk.user@example.com",
  739. password_hex="0123456789abcdef0123456789abcdef",
  740. erp="1", scan_freq="2412")
  741. dev[0].request("DISCONNECT")
  742. dev[0].wait_disconnected()
  743. dev[0].dump_monitor()
  744. with alloc_fail(hapd, 1, "fils_process_hlp"):
  745. dev[0].select_network(id, freq=2412)
  746. dev[0].wait_connected()
  747. dev[0].request("DISCONNECT")
  748. dev[0].wait_disconnected()
  749. dev[0].dump_monitor()
  750. with alloc_fail(hapd, 1, "fils_process_hlp_dhcp"):
  751. dev[0].select_network(id, freq=2412)
  752. dev[0].wait_connected()
  753. dev[0].request("DISCONNECT")
  754. dev[0].wait_disconnected()
  755. dev[0].dump_monitor()
  756. with alloc_fail(hapd, 1, "wpabuf_alloc;fils_process_hlp_dhcp"):
  757. dev[0].select_network(id, freq=2412)
  758. dev[0].wait_connected()
  759. dev[0].request("DISCONNECT")
  760. dev[0].wait_disconnected()
  761. dev[0].dump_monitor()
  762. with alloc_fail(hapd, 1, "wpabuf_alloc;fils_dhcp_handler"):
  763. dev[0].select_network(id, freq=2412)
  764. (msg,addr) = sock.recvfrom(1000)
  765. logger.debug("Received DHCP message from %s" % str(addr))
  766. dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPACK,
  767. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  768. sock.sendto(dhcpdisc[2+20+8:], addr)
  769. dev[0].wait_connected()
  770. dev[0].request("DISCONNECT")
  771. dev[0].wait_disconnected()
  772. dev[0].dump_monitor()
  773. with alloc_fail(hapd, 1, "wpabuf_resize;fils_dhcp_handler"):
  774. dev[0].select_network(id, freq=2412)
  775. (msg,addr) = sock.recvfrom(1000)
  776. logger.debug("Received DHCP message from %s" % str(addr))
  777. dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPACK,
  778. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  779. sock.sendto(dhcpdisc[2+20+8:], addr)
  780. dev[0].wait_connected()
  781. dev[0].request("DISCONNECT")
  782. dev[0].wait_disconnected()
  783. dev[0].dump_monitor()
  784. dev[0].select_network(id, freq=2412)
  785. (msg,addr) = sock.recvfrom(1000)
  786. logger.debug("Received DHCP message from %s" % str(addr))
  787. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  788. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  789. with alloc_fail(hapd, 1, "wpabuf_resize;fils_dhcp_request"):
  790. sock.sendto(dhcpoffer[2+20+8:], addr)
  791. dev[0].wait_connected()
  792. dev[0].request("DISCONNECT")
  793. dev[0].wait_disconnected()
  794. dev[0].request("FILS_HLP_REQ_FLUSH")
  795. def test_fils_sk_hlp_req_parsing(dev, apdev, params):
  796. """FILS SK HLP request parsing"""
  797. check_fils_capa(dev[0])
  798. check_erp_capa(dev[0])
  799. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  800. bssid = apdev[0]['bssid']
  801. params = fils_hlp_config(fils_hlp_wait_time=30)
  802. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  803. dev[0].scan_for_bss(bssid, freq=2412)
  804. dev[0].request("ERP_FLUSH")
  805. if "OK" not in dev[0].request("FILS_HLP_REQ_FLUSH"):
  806. raise Exception("Failed to flush pending FILS HLP requests")
  807. tot_len = 20 + 1
  808. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  809. _ip_src = '\x00\x00\x00\x00'
  810. _ip_dst = '\x00\x00\x00\x00'
  811. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  812. csum = ip_checksum(ipv4)
  813. ipv4_overflow = start + csum + _ip_src + _ip_dst
  814. tot_len = 20
  815. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 123)
  816. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  817. csum = ip_checksum(ipv4)
  818. ipv4_unknown_proto = start + csum + _ip_src + _ip_dst
  819. tot_len = 20
  820. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  821. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  822. csum = ip_checksum(ipv4)
  823. ipv4_missing_udp_hdr = start + csum + _ip_src + _ip_dst
  824. src_port = 68
  825. dst_port = 67
  826. udp = struct.pack('>HHHH', src_port, dst_port, 8 + 1, 0)
  827. tot_len = 20 + len(udp)
  828. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  829. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  830. csum = ip_checksum(ipv4)
  831. udp_overflow = start + csum + _ip_src + _ip_dst + udp
  832. udp = struct.pack('>HHHH', src_port, dst_port, 7, 0)
  833. tot_len = 20 + len(udp)
  834. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  835. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  836. csum = ip_checksum(ipv4)
  837. udp_underflow = start + csum + _ip_src + _ip_dst + udp
  838. src_port = 123
  839. dst_port = 456
  840. udp = struct.pack('>HHHH', src_port, dst_port, 8, 0)
  841. tot_len = 20 + len(udp)
  842. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  843. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  844. csum = ip_checksum(ipv4)
  845. udp_unknown_port = start + csum + _ip_src + _ip_dst + udp
  846. src_port = 68
  847. dst_port = 67
  848. udp = struct.pack('>HHHH', src_port, dst_port, 8, 0)
  849. tot_len = 20 + len(udp)
  850. start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17)
  851. ipv4 = start + '\x00\x00' + _ip_src + _ip_dst
  852. csum = ip_checksum(ipv4)
  853. dhcp_missing_data = start + csum + _ip_src + _ip_dst + udp
  854. dhcp_not_req = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  855. chaddr=dev[0].own_addr(), override_op=BOOTREPLY)
  856. dhcp_no_magic = build_dhcp(req=True, dhcp_msg=None,
  857. chaddr=dev[0].own_addr(), magic_override='',
  858. rapid_commit=False, opt_end=False)
  859. dhcp_unknown_magic = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  860. chaddr=dev[0].own_addr(),
  861. magic_override='\x00\x00\x00\x00')
  862. dhcp_opts = build_dhcp(req=True, dhcp_msg=DHCPNAK,
  863. chaddr=dev[0].own_addr(),
  864. extra_op='\x00\x11', opt_end=False)
  865. dhcp_opts2 = build_dhcp(req=True, dhcp_msg=DHCPNAK,
  866. chaddr=dev[0].own_addr(),
  867. extra_op='\x11\x01', opt_end=False)
  868. dhcp_valid = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  869. chaddr=dev[0].own_addr())
  870. tests = [ "ff",
  871. "0800",
  872. "0800" + 20*"00",
  873. "0800" + binascii.hexlify(ipv4_overflow),
  874. "0800" + binascii.hexlify(ipv4_unknown_proto),
  875. "0800" + binascii.hexlify(ipv4_missing_udp_hdr),
  876. "0800" + binascii.hexlify(udp_overflow),
  877. "0800" + binascii.hexlify(udp_underflow),
  878. "0800" + binascii.hexlify(udp_unknown_port),
  879. "0800" + binascii.hexlify(dhcp_missing_data),
  880. binascii.hexlify(dhcp_not_req),
  881. binascii.hexlify(dhcp_no_magic),
  882. binascii.hexlify(dhcp_unknown_magic) ]
  883. for t in tests:
  884. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " + t):
  885. raise Exception("FILS_HLP_REQ_ADD failed: " + t)
  886. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  887. eap="PSK", identity="psk.user@example.com",
  888. password_hex="0123456789abcdef0123456789abcdef",
  889. erp="1", scan_freq="2412")
  890. dev[0].request("DISCONNECT")
  891. dev[0].wait_disconnected()
  892. dev[0].dump_monitor()
  893. dev[0].select_network(id, freq=2412)
  894. dev[0].wait_connected()
  895. dev[0].request("DISCONNECT")
  896. dev[0].wait_disconnected()
  897. dev[0].request("FILS_HLP_REQ_FLUSH")
  898. tests = [ binascii.hexlify(dhcp_opts),
  899. binascii.hexlify(dhcp_opts2) ]
  900. for t in tests:
  901. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " + t):
  902. raise Exception("FILS_HLP_REQ_ADD failed: " + t)
  903. dev[0].dump_monitor()
  904. dev[0].select_network(id, freq=2412)
  905. dev[0].wait_connected()
  906. dev[0].request("DISCONNECT")
  907. dev[0].wait_disconnected()
  908. dev[0].request("FILS_HLP_REQ_FLUSH")
  909. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcp_valid)):
  910. raise Exception("FILS_HLP_REQ_ADD failed")
  911. hapd.set("own_ip_addr", "0.0.0.0")
  912. dev[0].select_network(id, freq=2412)
  913. dev[0].wait_connected()
  914. dev[0].request("DISCONNECT")
  915. dev[0].wait_disconnected()
  916. hapd.set("dhcp_server", "0.0.0.0")
  917. dev[0].select_network(id, freq=2412)
  918. dev[0].wait_connected()
  919. dev[0].request("DISCONNECT")
  920. dev[0].wait_disconnected()
  921. # FILS: Failed to bind DHCP socket: Address already in use
  922. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  923. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  924. sock.settimeout(5)
  925. sock.bind(("127.0.0.2", 67))
  926. hapd.set("own_ip_addr", "127.0.0.2")
  927. hapd.set("dhcp_server", "127.0.0.2")
  928. dev[0].select_network(id, freq=2412)
  929. dev[0].wait_connected()
  930. dev[0].request("DISCONNECT")
  931. dev[0].wait_disconnected()
  932. # FILS: DHCP sendto failed: Invalid argument
  933. hapd.set("own_ip_addr", "127.0.0.3")
  934. hapd.set("dhcp_server", "127.0.0.2")
  935. hapd.set("dhcp_relay_port", "0")
  936. hapd.set("dhcp_server_port", "0")
  937. dev[0].select_network(id, freq=2412)
  938. dev[0].wait_connected()
  939. dev[0].request("DISCONNECT")
  940. dev[0].wait_disconnected()
  941. dev[0].request("FILS_HLP_REQ_FLUSH")
  942. def test_fils_sk_hlp_dhcp_parsing(dev, apdev, params):
  943. """FILS SK HLP and DHCP response parsing"""
  944. check_fils_capa(dev[0])
  945. check_erp_capa(dev[0])
  946. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  947. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  948. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  949. sock.settimeout(5)
  950. sock.bind(("127.0.0.2", 67))
  951. bssid = apdev[0]['bssid']
  952. params = fils_hlp_config(fils_hlp_wait_time=30)
  953. params['dhcp_rapid_commit_proxy'] = '1'
  954. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  955. dev[0].scan_for_bss(bssid, freq=2412)
  956. dev[0].request("ERP_FLUSH")
  957. if "OK" not in dev[0].request("FILS_HLP_REQ_FLUSH"):
  958. raise Exception("Failed to flush pending FILS HLP requests")
  959. dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  960. chaddr=dev[0].own_addr())
  961. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc)):
  962. raise Exception("FILS_HLP_REQ_ADD failed")
  963. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  964. eap="PSK", identity="psk.user@example.com",
  965. password_hex="0123456789abcdef0123456789abcdef",
  966. erp="1", scan_freq="2412")
  967. dev[0].request("DISCONNECT")
  968. dev[0].wait_disconnected()
  969. dev[0].dump_monitor()
  970. with alloc_fail(hapd, 1, "fils_process_hlp"):
  971. dev[0].select_network(id, freq=2412)
  972. dev[0].wait_connected()
  973. dev[0].request("DISCONNECT")
  974. dev[0].wait_disconnected()
  975. dev[0].dump_monitor()
  976. dev[0].select_network(id, freq=2412)
  977. (msg,addr) = sock.recvfrom(1000)
  978. logger.debug("Received DHCP message from %s" % str(addr))
  979. dhcpdisc = build_dhcp(req=False, dhcp_msg=DHCPACK,
  980. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  981. #sock.sendto(dhcpdisc[2+20+8:], addr)
  982. chaddr = binascii.unhexlify(dev[0].own_addr().replace(':','')) + 10*'\x00'
  983. tests = [ "\x00",
  984. "\x02" + 500 * "\x00",
  985. "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 500 * "\x00",
  986. "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 16*"\x00" + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63",
  987. "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 16*"\x00" + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x00\x11",
  988. "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + 16*"\x00" + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x11\x01",
  989. "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + chaddr + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x35\x00\xff",
  990. "\x02\x00\x00\x00" + 20*"\x00" + "\x7f\x00\x00\x03" + chaddr + 64*"\x00" + 128*"\x00" + "\x63\x82\x53\x63" + "\x35\x01\x00\xff",
  991. 1501 * "\x00" ]
  992. for t in tests:
  993. sock.sendto(t, addr)
  994. dev[0].wait_connected()
  995. dev[0].request("DISCONNECT")
  996. dev[0].wait_disconnected()
  997. # FILS: DHCP sendto failed: Invalid argument for second DHCP TX in proxy
  998. dev[0].dump_monitor()
  999. dev[0].select_network(id, freq=2412)
  1000. (msg,addr) = sock.recvfrom(1000)
  1001. logger.debug("Received DHCP message from %s" % str(addr))
  1002. hapd.set("dhcp_server_port", "0")
  1003. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  1004. chaddr=dev[0].own_addr(), giaddr="127.0.0.3")
  1005. sock.sendto(dhcpoffer[2+20+8:], addr)
  1006. dev[0].wait_connected()
  1007. dev[0].request("DISCONNECT")
  1008. dev[0].wait_disconnected()
  1009. hapd.set("dhcp_server_port", "67")
  1010. # Options in DHCPOFFER
  1011. dev[0].dump_monitor()
  1012. dev[0].select_network(id, freq=2412)
  1013. (msg,addr) = sock.recvfrom(1000)
  1014. logger.debug("Received DHCP message from %s" % str(addr))
  1015. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  1016. chaddr=dev[0].own_addr(), giaddr="127.0.0.3",
  1017. extra_op="\x00\x11", opt_end=False)
  1018. sock.sendto(dhcpoffer[2+20+8:], addr)
  1019. (msg,addr) = sock.recvfrom(1000)
  1020. logger.debug("Received DHCP message from %s" % str(addr))
  1021. dev[0].wait_connected()
  1022. dev[0].request("DISCONNECT")
  1023. dev[0].wait_disconnected()
  1024. # Options in DHCPOFFER (2)
  1025. dev[0].dump_monitor()
  1026. dev[0].select_network(id, freq=2412)
  1027. (msg,addr) = sock.recvfrom(1000)
  1028. logger.debug("Received DHCP message from %s" % str(addr))
  1029. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  1030. chaddr=dev[0].own_addr(), giaddr="127.0.0.3",
  1031. extra_op="\x11\x01", opt_end=False)
  1032. sock.sendto(dhcpoffer[2+20+8:], addr)
  1033. (msg,addr) = sock.recvfrom(1000)
  1034. logger.debug("Received DHCP message from %s" % str(addr))
  1035. dev[0].wait_connected()
  1036. dev[0].request("DISCONNECT")
  1037. dev[0].wait_disconnected()
  1038. # Server ID in DHCPOFFER
  1039. dev[0].dump_monitor()
  1040. dev[0].select_network(id, freq=2412)
  1041. (msg,addr) = sock.recvfrom(1000)
  1042. logger.debug("Received DHCP message from %s" % str(addr))
  1043. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  1044. chaddr=dev[0].own_addr(), giaddr="127.0.0.3",
  1045. extra_op="\x36\x01\x30")
  1046. sock.sendto(dhcpoffer[2+20+8:], addr)
  1047. (msg,addr) = sock.recvfrom(1000)
  1048. logger.debug("Received DHCP message from %s" % str(addr))
  1049. dev[0].wait_connected()
  1050. dev[0].request("DISCONNECT")
  1051. dev[0].wait_disconnected()
  1052. # FILS: Could not update DHCPDISCOVER
  1053. dev[0].request("FILS_HLP_REQ_FLUSH")
  1054. dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  1055. chaddr=dev[0].own_addr(),
  1056. extra_op="\x00\x11", opt_end=False)
  1057. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc)):
  1058. raise Exception("FILS_HLP_REQ_ADD failed")
  1059. dev[0].dump_monitor()
  1060. dev[0].select_network(id, freq=2412)
  1061. (msg,addr) = sock.recvfrom(1000)
  1062. logger.debug("Received DHCP message from %s" % str(addr))
  1063. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  1064. chaddr=dev[0].own_addr(), giaddr="127.0.0.3",
  1065. extra_op="\x36\x01\x30")
  1066. sock.sendto(dhcpoffer[2+20+8:], addr)
  1067. dev[0].wait_connected()
  1068. dev[0].request("DISCONNECT")
  1069. dev[0].wait_disconnected()
  1070. # FILS: Could not update DHCPDISCOVER (2)
  1071. dev[0].request("FILS_HLP_REQ_FLUSH")
  1072. dhcpdisc = build_dhcp(req=True, dhcp_msg=DHCPDISCOVER,
  1073. chaddr=dev[0].own_addr(),
  1074. extra_op="\x11\x01", opt_end=False)
  1075. if "OK" not in dev[0].request("FILS_HLP_REQ_ADD " + "ff:ff:ff:ff:ff:ff " + binascii.hexlify(dhcpdisc)):
  1076. raise Exception("FILS_HLP_REQ_ADD failed")
  1077. dev[0].dump_monitor()
  1078. dev[0].select_network(id, freq=2412)
  1079. (msg,addr) = sock.recvfrom(1000)
  1080. logger.debug("Received DHCP message from %s" % str(addr))
  1081. dhcpoffer = build_dhcp(req=False, dhcp_msg=DHCPOFFER, rapid_commit=False,
  1082. chaddr=dev[0].own_addr(), giaddr="127.0.0.3",
  1083. extra_op="\x36\x01\x30")
  1084. sock.sendto(dhcpoffer[2+20+8:], addr)
  1085. dev[0].wait_connected()
  1086. dev[0].request("DISCONNECT")
  1087. dev[0].wait_disconnected()
  1088. dev[0].request("FILS_HLP_REQ_FLUSH")
  1089. def test_fils_sk_erp_and_reauth(dev, apdev, params):
  1090. """FILS SK using ERP and AP going away"""
  1091. check_fils_capa(dev[0])
  1092. check_erp_capa(dev[0])
  1093. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1094. bssid = apdev[0]['bssid']
  1095. params = hostapd.wpa2_eap_params(ssid="fils")
  1096. params['wpa_key_mgmt'] = "FILS-SHA256"
  1097. params['auth_server_port'] = "18128"
  1098. params['erp_domain'] = 'example.com'
  1099. params['fils_realm'] = 'example.com'
  1100. params['disable_pmksa_caching'] = '1'
  1101. params['broadcast_deauth'] = '0'
  1102. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1103. dev[0].scan_for_bss(bssid, freq=2412)
  1104. dev[0].request("ERP_FLUSH")
  1105. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1106. eap="PSK", identity="psk.user@example.com",
  1107. password_hex="0123456789abcdef0123456789abcdef",
  1108. erp="1", scan_freq="2412")
  1109. hapd.disable()
  1110. dev[0].wait_disconnected()
  1111. dev[0].dump_monitor()
  1112. hapd.enable()
  1113. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1114. "EVENT-ASSOC-REJECT",
  1115. "CTRL-EVENT-CONNECTED"], timeout=10)
  1116. if ev is None:
  1117. raise Exception("Reconnection using FILS/ERP timed out")
  1118. if "CTRL-EVENT-EAP-STARTED" in ev:
  1119. raise Exception("Unexpected EAP exchange")
  1120. if "EVENT-ASSOC-REJECT" in ev:
  1121. raise Exception("Association failed")
  1122. def test_fils_sk_erp_sim(dev, apdev, params):
  1123. """FILS SK using ERP with SIM"""
  1124. check_fils_capa(dev[0])
  1125. check_erp_capa(dev[0])
  1126. realm='wlan.mnc001.mcc232.3gppnetwork.org'
  1127. start_erp_as(apdev[1], erp_domain=realm,
  1128. msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1129. bssid = apdev[0]['bssid']
  1130. params = hostapd.wpa2_eap_params(ssid="fils")
  1131. params['wpa_key_mgmt'] = "FILS-SHA256"
  1132. params['auth_server_port'] = "18128"
  1133. params['fils_realm'] = realm
  1134. params['disable_pmksa_caching'] = '1'
  1135. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1136. dev[0].scan_for_bss(bssid, freq=2412)
  1137. dev[0].request("ERP_FLUSH")
  1138. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1139. eap="SIM", identity="1232010000000000@" + realm,
  1140. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1141. erp="1", scan_freq="2412")
  1142. hapd.disable()
  1143. dev[0].wait_disconnected()
  1144. dev[0].dump_monitor()
  1145. hapd.enable()
  1146. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1147. "EVENT-ASSOC-REJECT",
  1148. "CTRL-EVENT-CONNECTED"], timeout=10)
  1149. if ev is None:
  1150. raise Exception("Reconnection using FILS/ERP timed out")
  1151. if "CTRL-EVENT-EAP-STARTED" in ev:
  1152. raise Exception("Unexpected EAP exchange")
  1153. if "EVENT-ASSOC-REJECT" in ev:
  1154. raise Exception("Association failed")
  1155. def test_fils_sk_pfs_19(dev, apdev, params):
  1156. """FILS SK with PFS (DH group 19)"""
  1157. run_fils_sk_pfs(dev, apdev, "19", params)
  1158. def test_fils_sk_pfs_20(dev, apdev, params):
  1159. """FILS SK with PFS (DH group 20)"""
  1160. run_fils_sk_pfs(dev, apdev, "20", params)
  1161. def test_fils_sk_pfs_21(dev, apdev, params):
  1162. """FILS SK with PFS (DH group 21)"""
  1163. run_fils_sk_pfs(dev, apdev, "21", params)
  1164. def test_fils_sk_pfs_25(dev, apdev, params):
  1165. """FILS SK with PFS (DH group 25)"""
  1166. run_fils_sk_pfs(dev, apdev, "25", params)
  1167. def test_fils_sk_pfs_26(dev, apdev, params):
  1168. """FILS SK with PFS (DH group 26)"""
  1169. run_fils_sk_pfs(dev, apdev, "26", params)
  1170. def test_fils_sk_pfs_27(dev, apdev, params):
  1171. """FILS SK with PFS (DH group 27)"""
  1172. run_fils_sk_pfs(dev, apdev, "27", params)
  1173. def test_fils_sk_pfs_28(dev, apdev, params):
  1174. """FILS SK with PFS (DH group 28)"""
  1175. run_fils_sk_pfs(dev, apdev, "28", params)
  1176. def test_fils_sk_pfs_29(dev, apdev, params):
  1177. """FILS SK with PFS (DH group 29)"""
  1178. run_fils_sk_pfs(dev, apdev, "29", params)
  1179. def test_fils_sk_pfs_30(dev, apdev, params):
  1180. """FILS SK with PFS (DH group 30)"""
  1181. run_fils_sk_pfs(dev, apdev, "30", params)
  1182. def run_fils_sk_pfs(dev, apdev, group, params):
  1183. check_fils_sk_pfs_capa(dev[0])
  1184. check_erp_capa(dev[0])
  1185. tls = dev[0].request("GET tls_library")
  1186. if int(group) in [ 25 ]:
  1187. if not (tls.startswith("OpenSSL") and ("build=OpenSSL 1.0.2" in tls or "build=OpenSSL 1.1" in tls) and ("run=OpenSSL 1.0.2" in tls or "run=OpenSSL 1.1" in tls)):
  1188. raise HwsimSkip("EC group not supported")
  1189. if int(group) in [ 27, 28, 29, 30 ]:
  1190. if not (tls.startswith("OpenSSL") and ("build=OpenSSL 1.0.2" in tls or "build=OpenSSL 1.1" in tls) and ("run=OpenSSL 1.0.2" in tls or "run=OpenSSL 1.1" in tls)):
  1191. raise HwsimSkip("Brainpool EC group not supported")
  1192. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1193. bssid = apdev[0]['bssid']
  1194. params = hostapd.wpa2_eap_params(ssid="fils")
  1195. params['wpa_key_mgmt'] = "FILS-SHA256"
  1196. params['auth_server_port'] = "18128"
  1197. params['erp_domain'] = 'example.com'
  1198. params['fils_realm'] = 'example.com'
  1199. params['disable_pmksa_caching'] = '1'
  1200. params['fils_dh_group'] = group
  1201. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1202. dev[0].scan_for_bss(bssid, freq=2412)
  1203. dev[0].request("ERP_FLUSH")
  1204. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1205. eap="PSK", identity="psk.user@example.com",
  1206. password_hex="0123456789abcdef0123456789abcdef",
  1207. erp="1", fils_dh_group=group, scan_freq="2412")
  1208. dev[0].request("DISCONNECT")
  1209. dev[0].wait_disconnected()
  1210. dev[0].dump_monitor()
  1211. dev[0].select_network(id, freq=2412)
  1212. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1213. "EVENT-ASSOC-REJECT",
  1214. "CTRL-EVENT-CONNECTED"], timeout=10)
  1215. if ev is None:
  1216. raise Exception("Connection using FILS/ERP timed out")
  1217. if "CTRL-EVENT-EAP-STARTED" in ev:
  1218. raise Exception("Unexpected EAP exchange")
  1219. if "EVENT-ASSOC-REJECT" in ev:
  1220. raise Exception("Association failed")
  1221. hwsim_utils.test_connectivity(dev[0], hapd)
  1222. def test_fils_sk_pfs_group_mismatch(dev, apdev, params):
  1223. """FILS SK PFS DH group mismatch"""
  1224. check_fils_sk_pfs_capa(dev[0])
  1225. check_erp_capa(dev[0])
  1226. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1227. bssid = apdev[0]['bssid']
  1228. params = hostapd.wpa2_eap_params(ssid="fils")
  1229. params['wpa_key_mgmt'] = "FILS-SHA256"
  1230. params['auth_server_port'] = "18128"
  1231. params['erp_domain'] = 'example.com'
  1232. params['fils_realm'] = 'example.com'
  1233. params['disable_pmksa_caching'] = '1'
  1234. params['fils_dh_group'] = "20"
  1235. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1236. dev[0].scan_for_bss(bssid, freq=2412)
  1237. dev[0].request("ERP_FLUSH")
  1238. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1239. eap="PSK", identity="psk.user@example.com",
  1240. password_hex="0123456789abcdef0123456789abcdef",
  1241. erp="1", fils_dh_group="19", scan_freq="2412")
  1242. dev[0].request("DISCONNECT")
  1243. dev[0].wait_disconnected()
  1244. dev[0].dump_monitor()
  1245. dev[0].select_network(id, freq=2412)
  1246. ev = dev[0].wait_event(["CTRL-EVENT-AUTH-REJECT"], timeout=10)
  1247. dev[0].request("DISCONNECT")
  1248. if ev is None:
  1249. raise Exception("Authentication rejection not seen")
  1250. if "auth_type=5 auth_transaction=2 status_code=77" not in ev:
  1251. raise Exception("Unexpected auth reject value: " + ev)
  1252. def test_fils_sk_pfs_pmksa_caching(dev, apdev, params):
  1253. """FILS SK with PFS and PMKSA caching"""
  1254. check_fils_sk_pfs_capa(dev[0])
  1255. check_erp_capa(dev[0])
  1256. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1257. bssid = apdev[0]['bssid']
  1258. params = hostapd.wpa2_eap_params(ssid="fils")
  1259. params['wpa_key_mgmt'] = "FILS-SHA256"
  1260. params['auth_server_port'] = "18128"
  1261. params['erp_domain'] = 'example.com'
  1262. params['fils_realm'] = 'example.com'
  1263. params['fils_dh_group'] = "19"
  1264. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1265. dev[0].scan_for_bss(bssid, freq=2412)
  1266. dev[0].request("ERP_FLUSH")
  1267. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1268. eap="PSK", identity="psk.user@example.com",
  1269. password_hex="0123456789abcdef0123456789abcdef",
  1270. erp="1", fils_dh_group="19", scan_freq="2412")
  1271. pmksa = dev[0].get_pmksa(bssid)
  1272. if pmksa is None:
  1273. raise Exception("No PMKSA cache entry created")
  1274. dev[0].request("DISCONNECT")
  1275. dev[0].wait_disconnected()
  1276. # FILS authentication with PMKSA caching and PFS
  1277. dev[0].dump_monitor()
  1278. dev[0].select_network(id, freq=2412)
  1279. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1280. "CTRL-EVENT-CONNECTED"], timeout=10)
  1281. if ev is None:
  1282. raise Exception("Connection using PMKSA caching timed out")
  1283. if "CTRL-EVENT-EAP-STARTED" in ev:
  1284. raise Exception("Unexpected EAP exchange")
  1285. hwsim_utils.test_connectivity(dev[0], hapd)
  1286. pmksa2 = dev[0].get_pmksa(bssid)
  1287. if pmksa2 is None:
  1288. raise Exception("No PMKSA cache entry found")
  1289. if pmksa['pmkid'] != pmksa2['pmkid']:
  1290. raise Exception("Unexpected PMKID change")
  1291. # Verify EAPOL reauthentication after FILS authentication
  1292. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  1293. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  1294. if ev is None:
  1295. raise Exception("EAP authentication did not start")
  1296. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  1297. if ev is None:
  1298. raise Exception("EAP authentication did not succeed")
  1299. time.sleep(0.1)
  1300. hwsim_utils.test_connectivity(dev[0], hapd)
  1301. dev[0].request("DISCONNECT")
  1302. dev[0].wait_disconnected()
  1303. # FILS authentication with ERP and PFS
  1304. dev[0].request("PMKSA_FLUSH")
  1305. dev[0].dump_monitor()
  1306. dev[0].select_network(id, freq=2412)
  1307. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1308. "CTRL-EVENT-EAP-SUCCESS",
  1309. "CTRL-EVENT-CONNECTED"], timeout=10)
  1310. if ev is None:
  1311. raise Exception("Connection using ERP and PFS timed out")
  1312. if "CTRL-EVENT-EAP-STARTED" in ev:
  1313. raise Exception("Unexpected EAP exchange")
  1314. if "CTRL-EVENT-EAP-SUCCESS" not in ev:
  1315. raise Exception("ERP success not reported")
  1316. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1317. "SME: Trying to authenticate",
  1318. "CTRL-EVENT-CONNECTED"], timeout=10)
  1319. if ev is None:
  1320. raise Exception("Connection using ERP and PFS timed out")
  1321. if "CTRL-EVENT-EAP-STARTED" in ev:
  1322. raise Exception("Unexpected EAP exchange")
  1323. if "SME: Trying to authenticate" in ev:
  1324. raise Exception("Unexpected extra authentication round with ERP and PFS")
  1325. hwsim_utils.test_connectivity(dev[0], hapd)
  1326. pmksa3 = dev[0].get_pmksa(bssid)
  1327. if pmksa3 is None:
  1328. raise Exception("No PMKSA cache entry found")
  1329. if pmksa2['pmkid'] == pmksa3['pmkid']:
  1330. raise Exception("PMKID did not change")
  1331. dev[0].request("DISCONNECT")
  1332. dev[0].wait_disconnected()
  1333. # FILS authentication with PMKSA caching and PFS
  1334. dev[0].dump_monitor()
  1335. dev[0].select_network(id, freq=2412)
  1336. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1337. "CTRL-EVENT-CONNECTED"], timeout=10)
  1338. if ev is None:
  1339. raise Exception("Connection using PMKSA caching timed out")
  1340. if "CTRL-EVENT-EAP-STARTED" in ev:
  1341. raise Exception("Unexpected EAP exchange")
  1342. hwsim_utils.test_connectivity(dev[0], hapd)
  1343. pmksa4 = dev[0].get_pmksa(bssid)
  1344. if pmksa4 is None:
  1345. raise Exception("No PMKSA cache entry found")
  1346. if pmksa3['pmkid'] != pmksa4['pmkid']:
  1347. raise Exception("Unexpected PMKID change (2)")
  1348. def test_fils_sk_auth_mismatch(dev, apdev, params):
  1349. """FILS SK authentication type mismatch (PFS not supported)"""
  1350. check_fils_sk_pfs_capa(dev[0])
  1351. check_erp_capa(dev[0])
  1352. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1353. bssid = apdev[0]['bssid']
  1354. params = hostapd.wpa2_eap_params(ssid="fils")
  1355. params['wpa_key_mgmt'] = "FILS-SHA256"
  1356. params['auth_server_port'] = "18128"
  1357. params['erp_domain'] = 'example.com'
  1358. params['fils_realm'] = 'example.com'
  1359. params['disable_pmksa_caching'] = '1'
  1360. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1361. dev[0].scan_for_bss(bssid, freq=2412)
  1362. dev[0].request("ERP_FLUSH")
  1363. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1364. eap="PSK", identity="psk.user@example.com",
  1365. password_hex="0123456789abcdef0123456789abcdef",
  1366. erp="1", fils_dh_group="19", scan_freq="2412")
  1367. dev[0].request("DISCONNECT")
  1368. dev[0].wait_disconnected()
  1369. dev[0].dump_monitor()
  1370. dev[0].select_network(id, freq=2412)
  1371. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1372. "EVENT-ASSOC-REJECT",
  1373. "CTRL-EVENT-CONNECTED"], timeout=10)
  1374. if ev is None:
  1375. raise Exception("Connection using FILS/ERP timed out")
  1376. if "CTRL-EVENT-EAP-STARTED" not in ev:
  1377. raise Exception("No EAP exchange seen")
  1378. dev[0].wait_connected()
  1379. hwsim_utils.test_connectivity(dev[0], hapd)
  1380. def test_fils_auth_gtk_rekey(dev, apdev, params):
  1381. """GTK rekeying after FILS authentication"""
  1382. check_fils_capa(dev[0])
  1383. check_erp_capa(dev[0])
  1384. start_erp_as(apdev[1], msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1385. bssid = apdev[0]['bssid']
  1386. params = hostapd.wpa2_eap_params(ssid="fils")
  1387. params['wpa_key_mgmt'] = "FILS-SHA256"
  1388. params['auth_server_port'] = "18128"
  1389. params['erp_domain'] = 'example.com'
  1390. params['fils_realm'] = 'example.com'
  1391. params['wpa_group_rekey'] = '1'
  1392. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1393. dev[0].scan_for_bss(bssid, freq=2412)
  1394. dev[0].request("ERP_FLUSH")
  1395. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1396. eap="PSK", identity="psk.user@example.com",
  1397. password_hex="0123456789abcdef0123456789abcdef",
  1398. erp="1", scan_freq="2412")
  1399. dev[0].request("DISCONNECT")
  1400. dev[0].wait_disconnected()
  1401. dev[0].dump_monitor()
  1402. dev[0].select_network(id, freq=2412)
  1403. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1404. "CTRL-EVENT-CONNECTED"], timeout=10)
  1405. if ev is None:
  1406. raise Exception("Connection using PMKSA caching timed out")
  1407. if "CTRL-EVENT-EAP-STARTED" in ev:
  1408. raise Exception("Unexpected EAP exchange")
  1409. dev[0].dump_monitor()
  1410. hwsim_utils.test_connectivity(dev[0], hapd)
  1411. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  1412. if ev is None:
  1413. raise Exception("GTK rekey timed out")
  1414. hwsim_utils.test_connectivity(dev[0], hapd)
  1415. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  1416. if ev is not None:
  1417. raise Exception("Rekeying failed - disconnected")
  1418. hwsim_utils.test_connectivity(dev[0], hapd)
  1419. def test_fils_and_ft(dev, apdev, params):
  1420. """FILS SK using ERP and FT initial mobility domain association"""
  1421. check_fils_capa(dev[0])
  1422. check_erp_capa(dev[0])
  1423. er = start_erp_as(apdev[1],
  1424. msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1425. bssid = apdev[0]['bssid']
  1426. params = hostapd.wpa2_eap_params(ssid="fils")
  1427. params['wpa_key_mgmt'] = "FILS-SHA256"
  1428. params['auth_server_port'] = "18128"
  1429. params['erp_domain'] = 'example.com'
  1430. params['fils_realm'] = 'example.com'
  1431. params['disable_pmksa_caching'] = '1'
  1432. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1433. dev[0].scan_for_bss(bssid, freq=2412)
  1434. dev[0].request("ERP_FLUSH")
  1435. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1436. eap="PSK", identity="psk.user@example.com",
  1437. password_hex="0123456789abcdef0123456789abcdef",
  1438. erp="1", scan_freq="2412")
  1439. dev[0].request("DISCONNECT")
  1440. dev[0].wait_disconnected()
  1441. hapd.disable()
  1442. dev[0].flush_scan_cache()
  1443. if "FAIL" in dev[0].request("PMKSA_FLUSH"):
  1444. raise Exception("PMKSA_FLUSH failed")
  1445. params = hostapd.wpa2_eap_params(ssid="fils-ft")
  1446. params['wpa_key_mgmt'] = "FILS-SHA256 FT-FILS-SHA256 FT-EAP"
  1447. params['auth_server_port'] = "18128"
  1448. params['erp_domain'] = 'example.com'
  1449. params['fils_realm'] = 'example.com'
  1450. params['disable_pmksa_caching'] = '1'
  1451. params["mobility_domain"] = "a1b2"
  1452. params["r0_key_lifetime"] = "10000"
  1453. params["pmk_r1_push"] = "1"
  1454. params["reassociation_deadline"] = "1000"
  1455. params['nas_identifier'] = "nas1.w1.fi"
  1456. params['r1_key_holder'] = "000102030405"
  1457. params['r0kh'] = [ "02:00:00:00:04:00 nas2.w1.fi 300102030405060708090a0b0c0d0e0f" ]
  1458. params['r1kh'] = "02:00:00:00:04:00 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f"
  1459. params['ieee80211w'] = "1"
  1460. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1461. dev[0].scan_for_bss(bssid, freq=2412)
  1462. dev[0].dump_monitor()
  1463. id = dev[0].connect("fils-ft", key_mgmt="FILS-SHA256 FT-FILS-SHA256 FT-EAP",
  1464. ieee80211w="1",
  1465. eap="PSK", identity="psk.user@example.com",
  1466. password_hex="0123456789abcdef0123456789abcdef",
  1467. erp="1", scan_freq="2412", wait_connect=False)
  1468. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1469. "CTRL-EVENT-AUTH-REJECT",
  1470. "EVENT-ASSOC-REJECT",
  1471. "CTRL-EVENT-CONNECTED"], timeout=10)
  1472. if ev is None:
  1473. raise Exception("Connection using FILS/ERP timed out")
  1474. if "CTRL-EVENT-EAP-STARTED" in ev:
  1475. raise Exception("Unexpected EAP exchange")
  1476. if "CTRL-EVENT-AUTH-REJECT" in ev:
  1477. raise Exception("Authentication failed")
  1478. if "EVENT-ASSOC-REJECT" in ev:
  1479. raise Exception("Association failed")
  1480. hwsim_utils.test_connectivity(dev[0], hapd)
  1481. er.disable()
  1482. # FIX: FT-FILS-SHA256 does not currently work for FT protocol due to not
  1483. # fully defined FT Reassociation Request/Response frame MIC use in FTE.
  1484. # FT-EAP can be used to work around that in this test case to confirm the
  1485. # FT key hierarchy was properly formed in the previous step.
  1486. #params['wpa_key_mgmt'] = "FILS-SHA256 FT-FILS-SHA256"
  1487. params['wpa_key_mgmt'] = "FT-EAP"
  1488. params['nas_identifier'] = "nas2.w1.fi"
  1489. params['r1_key_holder'] = "000102030406"
  1490. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 200102030405060708090a0b0c0d0e0f" ]
  1491. params['r1kh'] = "02:00:00:00:03:00 00:01:02:03:04:05 300102030405060708090a0b0c0d0e0f"
  1492. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  1493. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412", force_scan=True)
  1494. # FIX: Cannot use FT-over-DS without the FTE MIC issue addressed
  1495. #dev[0].roam_over_ds(apdev[1]['bssid'])
  1496. dev[0].roam(apdev[1]['bssid'])
  1497. def test_fils_and_ft_over_air(dev, apdev, params):
  1498. """FILS SK using ERP and FT-over-air (SHA256)"""
  1499. run_fils_and_ft_over_air(dev, apdev, params, "FT-FILS-SHA256")
  1500. def run_fils_and_ft_over_air(dev, apdev, params, key_mgmt):
  1501. hapd = run_fils_and_ft_setup(dev, apdev, params, key_mgmt)
  1502. logger.info("FT protocol using FT key hierarchy established during FILS authentication")
  1503. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412", force_scan=True)
  1504. hapd.request("NOTE FT protocol to AP2 using FT keys established during FILS FILS authentication")
  1505. dev[0].roam(apdev[1]['bssid'])
  1506. logger.info("FT protocol using the previously established FT key hierarchy from FILS authentication")
  1507. hapd.request("NOTE FT protocol back to AP1 using FT keys established during FILS FILS authentication")
  1508. dev[0].roam(apdev[0]['bssid'])
  1509. hapd.request("NOTE FT protocol back to AP2 using FT keys established during FILS FILS authentication")
  1510. dev[0].roam(apdev[1]['bssid'])
  1511. hapd.request("NOTE FT protocol back to AP1 using FT keys established during FILS FILS authentication (2)")
  1512. dev[0].roam(apdev[0]['bssid'])
  1513. def test_fils_and_ft_over_ds(dev, apdev, params):
  1514. """FILS SK using ERP and FT-over-DS (SHA256)"""
  1515. run_fils_and_ft_over_ds(dev, apdev, params, "FT-FILS-SHA256")
  1516. def run_fils_and_ft_over_ds(dev, apdev, params, key_mgmt):
  1517. hapd = run_fils_and_ft_setup(dev, apdev, params, key_mgmt)
  1518. logger.info("FT protocol using FT key hierarchy established during FILS authentication")
  1519. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412", force_scan=True)
  1520. hapd.request("NOTE FT protocol to AP2 using FT keys established during FILS FILS authentication")
  1521. dev[0].roam_over_ds(apdev[1]['bssid'])
  1522. logger.info("FT protocol using the previously established FT key hierarchy from FILS authentication")
  1523. hapd.request("NOTE FT protocol back to AP1 using FT keys established during FILS FILS authentication")
  1524. dev[0].roam_over_ds(apdev[0]['bssid'])
  1525. hapd.request("NOTE FT protocol back to AP2 using FT keys established during FILS FILS authentication")
  1526. dev[0].roam_over_ds(apdev[1]['bssid'])
  1527. hapd.request("NOTE FT protocol back to AP1 using FT keys established during FILS FILS authentication (2)")
  1528. dev[0].roam_over_ds(apdev[0]['bssid'])
  1529. def run_fils_and_ft_setup(dev, apdev, params, key_mgmt):
  1530. check_fils_capa(dev[0])
  1531. check_erp_capa(dev[0])
  1532. er = start_erp_as(apdev[1],
  1533. msk_dump=os.path.join(params['logdir'], "msk.lst"))
  1534. logger.info("Set up ERP key hierarchy without FILS/FT authentication")
  1535. bssid = apdev[0]['bssid']
  1536. params = hostapd.wpa2_eap_params(ssid="fils")
  1537. params['wpa_key_mgmt'] = key_mgmt
  1538. params['auth_server_port'] = "18128"
  1539. params['erp_domain'] = 'example.com'
  1540. params['fils_realm'] = 'example.com'
  1541. params['disable_pmksa_caching'] = '1'
  1542. params['ieee80211w'] = "2"
  1543. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1544. dev[0].scan_for_bss(bssid, freq=2412)
  1545. dev[0].request("ERP_FLUSH")
  1546. hapd.request("NOTE Initial association to establish ERP keys")
  1547. id = dev[0].connect("fils", key_mgmt=key_mgmt, ieee80211w="2",
  1548. eap="PSK", identity="psk.user@example.com",
  1549. password_hex="0123456789abcdef0123456789abcdef",
  1550. erp="1", scan_freq="2412")
  1551. dev[0].request("DISCONNECT")
  1552. dev[0].wait_disconnected()
  1553. hapd.disable()
  1554. dev[0].flush_scan_cache()
  1555. if "FAIL" in dev[0].request("PMKSA_FLUSH"):
  1556. raise Exception("PMKSA_FLUSH failed")
  1557. logger.info("Initial mobility domain association using FILS authentication")
  1558. params = hostapd.wpa2_eap_params(ssid="fils-ft")
  1559. params['wpa_key_mgmt'] = key_mgmt
  1560. params['auth_server_port'] = "18128"
  1561. params['erp_domain'] = 'example.com'
  1562. params['fils_realm'] = 'example.com'
  1563. params['disable_pmksa_caching'] = '1'
  1564. params["mobility_domain"] = "a1b2"
  1565. params["r0_key_lifetime"] = "10000"
  1566. params["pmk_r1_push"] = "1"
  1567. params["reassociation_deadline"] = "1000"
  1568. params['nas_identifier'] = "nas1.w1.fi"
  1569. params['r1_key_holder'] = "000102030405"
  1570. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 100102030405060708090a0b0c0d0e0f100102030405060708090a0b0c0d0e0f",
  1571. "02:00:00:00:04:00 nas2.w1.fi 300102030405060708090a0b0c0d0e0f" ]
  1572. params['r1kh'] = "02:00:00:00:04:00 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f"
  1573. params['ieee80211w'] = "2"
  1574. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1575. dev[0].scan_for_bss(bssid, freq=2412)
  1576. dev[0].dump_monitor()
  1577. hapd.request("NOTE Initial FT mobility domain association using FILS authentication")
  1578. dev[0].set_network_quoted(id, "ssid", "fils-ft")
  1579. dev[0].select_network(id, freq=2412)
  1580. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
  1581. "CTRL-EVENT-AUTH-REJECT",
  1582. "EVENT-ASSOC-REJECT",
  1583. "CTRL-EVENT-CONNECTED"], timeout=10)
  1584. if ev is None:
  1585. raise Exception("Connection using FILS/ERP timed out")
  1586. if "CTRL-EVENT-EAP-STARTED" in ev:
  1587. raise Exception("Unexpected EAP exchange")
  1588. if "CTRL-EVENT-AUTH-REJECT" in ev:
  1589. raise Exception("Authentication failed")
  1590. if "EVENT-ASSOC-REJECT" in ev:
  1591. raise Exception("Association failed")
  1592. hwsim_utils.test_connectivity(dev[0], hapd)
  1593. er.disable()
  1594. params['wpa_key_mgmt'] = key_mgmt
  1595. params['nas_identifier'] = "nas2.w1.fi"
  1596. params['r1_key_holder'] = "000102030406"
  1597. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 200102030405060708090a0b0c0d0e0f",
  1598. "02:00:00:00:04:00 nas2.w1.fi 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f" ]
  1599. params['r1kh'] = "02:00:00:00:03:00 00:01:02:03:04:05 300102030405060708090a0b0c0d0e0f"
  1600. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  1601. return hapd
  1602. def test_fils_assoc_replay(dev, apdev, params):
  1603. """FILS AP and replayed Association Request frame"""
  1604. capfile = os.path.join(params['logdir'], "hwsim0.pcapng")
  1605. check_fils_capa(dev[0])
  1606. check_erp_capa(dev[0])
  1607. start_erp_as(apdev[1])
  1608. bssid = apdev[0]['bssid']
  1609. params = hostapd.wpa2_eap_params(ssid="fils")
  1610. params['wpa_key_mgmt'] = "FILS-SHA256"
  1611. params['auth_server_port'] = "18128"
  1612. params['erp_domain'] = 'example.com'
  1613. params['fils_realm'] = 'example.com'
  1614. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1615. dev[0].scan_for_bss(bssid, freq=2412)
  1616. dev[0].request("ERP_FLUSH")
  1617. id = dev[0].connect("fils", key_mgmt="FILS-SHA256",
  1618. eap="PSK", identity="psk.user@example.com",
  1619. password_hex="0123456789abcdef0123456789abcdef",
  1620. erp="1", scan_freq="2412")
  1621. dev[0].request("DISCONNECT")
  1622. dev[0].wait_disconnected()
  1623. hapd.set("ext_mgmt_frame_handling", "1")
  1624. dev[0].dump_monitor()
  1625. dev[0].select_network(id, freq=2412)
  1626. assocreq = None
  1627. count = 0
  1628. while count < 100:
  1629. req = hapd.mgmt_rx()
  1630. count += 1
  1631. hapd.dump_monitor()
  1632. hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + binascii.hexlify(req['frame']))
  1633. if req['subtype'] == 0:
  1634. assocreq = req
  1635. ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
  1636. if ev is None:
  1637. raise Exception("No TX status seen")
  1638. cmd = "MGMT_TX_STATUS_PROCESS %s" % (" ".join(ev.split(' ')[1:4]))
  1639. if "OK" not in hapd.request(cmd):
  1640. raise Exception("MGMT_TX_STATUS_PROCESS failed")
  1641. break
  1642. hapd.set("ext_mgmt_frame_handling", "0")
  1643. if assocreq is None:
  1644. raise Exception("No Association Request frame seen")
  1645. dev[0].wait_connected()
  1646. dev[0].dump_monitor()
  1647. hapd.dump_monitor()
  1648. hwsim_utils.test_connectivity(dev[0], hapd)
  1649. logger.info("Replay the last Association Request frame")
  1650. hapd.dump_monitor()
  1651. hapd.set("ext_mgmt_frame_handling", "1")
  1652. hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + binascii.hexlify(req['frame']))
  1653. ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
  1654. if ev is None:
  1655. raise Exception("No TX status seen")
  1656. cmd = "MGMT_TX_STATUS_PROCESS %s" % (" ".join(ev.split(' ')[1:4]))
  1657. if "OK" not in hapd.request(cmd):
  1658. raise Exception("MGMT_TX_STATUS_PROCESS failed")
  1659. hapd.set("ext_mgmt_frame_handling", "0")
  1660. try:
  1661. hwsim_utils.test_connectivity(dev[0], hapd)
  1662. ok = True
  1663. except:
  1664. ok = False
  1665. ap = hapd.own_addr()
  1666. sta = dev[0].own_addr()
  1667. filt = "wlan.fc.type == 2 && " + \
  1668. "wlan.da == " + sta + " && " + \
  1669. "wlan.sa == " + ap + " && wlan.ccmp.extiv"
  1670. fields = [ "wlan.ccmp.extiv" ]
  1671. res = run_tshark(capfile, filt, fields)
  1672. vals = res.splitlines()
  1673. logger.info("CCMP PN: " + str(vals))
  1674. if len(vals) < 2:
  1675. raise Exception("Could not find all CCMP protected frames from capture")
  1676. if len(set(vals)) < len(vals):
  1677. raise Exception("Duplicate CCMP PN used")
  1678. if not ok:
  1679. raise Exception("The second hwsim connectivity test failed")