test_ap_ft.py 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. # Fast BSS Transition tests
  2. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import binascii
  8. import os
  9. import time
  10. import logging
  11. logger = logging.getLogger()
  12. import hwsim_utils
  13. import hostapd
  14. from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips
  15. from wlantest import Wlantest
  16. from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations
  17. def ft_base_rsn():
  18. params = { "wpa": "2",
  19. "wpa_key_mgmt": "FT-PSK",
  20. "rsn_pairwise": "CCMP" }
  21. return params
  22. def ft_base_mixed():
  23. params = { "wpa": "3",
  24. "wpa_key_mgmt": "WPA-PSK FT-PSK",
  25. "wpa_pairwise": "TKIP",
  26. "rsn_pairwise": "CCMP" }
  27. return params
  28. def ft_params(rsn=True, ssid=None, passphrase=None):
  29. if rsn:
  30. params = ft_base_rsn()
  31. else:
  32. params = ft_base_mixed()
  33. if ssid:
  34. params["ssid"] = ssid
  35. if passphrase:
  36. params["wpa_passphrase"] = passphrase
  37. params["mobility_domain"] = "a1b2"
  38. params["r0_key_lifetime"] = "10000"
  39. params["pmk_r1_push"] = "1"
  40. params["reassociation_deadline"] = "1000"
  41. return params
  42. def ft_params1a(rsn=True, ssid=None, passphrase=None):
  43. params = ft_params(rsn, ssid, passphrase)
  44. params['nas_identifier'] = "nas1.w1.fi"
  45. params['r1_key_holder'] = "000102030405"
  46. return params
  47. def ft_params1(rsn=True, ssid=None, passphrase=None):
  48. params = ft_params1a(rsn, ssid, passphrase)
  49. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
  50. "02:00:00:00:04:00 nas2.w1.fi 300102030405060708090a0b0c0d0e0f" ]
  51. params['r1kh'] = "02:00:00:00:04:00 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f"
  52. return params
  53. def ft_params2a(rsn=True, ssid=None, passphrase=None):
  54. params = ft_params(rsn, ssid, passphrase)
  55. params['nas_identifier'] = "nas2.w1.fi"
  56. params['r1_key_holder'] = "000102030406"
  57. return params
  58. def ft_params2(rsn=True, ssid=None, passphrase=None):
  59. params = ft_params2a(rsn, ssid, passphrase)
  60. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 200102030405060708090a0b0c0d0e0f",
  61. "02:00:00:00:04:00 nas2.w1.fi 000102030405060708090a0b0c0d0e0f" ]
  62. params['r1kh'] = "02:00:00:00:03:00 00:01:02:03:04:05 300102030405060708090a0b0c0d0e0f"
  63. return params
  64. def ft_params1_r0kh_mismatch(rsn=True, ssid=None, passphrase=None):
  65. params = ft_params(rsn, ssid, passphrase)
  66. params['nas_identifier'] = "nas1.w1.fi"
  67. params['r1_key_holder'] = "000102030405"
  68. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
  69. "12:00:00:00:04:00 nas2.w1.fi 300102030405060708090a0b0c0d0e0f" ]
  70. params['r1kh'] = "12:00:00:00:04:00 10:01:02:03:04:06 200102030405060708090a0b0c0d0e0f"
  71. return params
  72. def ft_params2_incorrect_rrb_key(rsn=True, ssid=None, passphrase=None):
  73. params = ft_params(rsn, ssid, passphrase)
  74. params['nas_identifier'] = "nas2.w1.fi"
  75. params['r1_key_holder'] = "000102030406"
  76. params['r0kh'] = [ "02:00:00:00:03:00 nas1.w1.fi 200102030405060708090a0b0c0d0ef1",
  77. "02:00:00:00:04:00 nas2.w1.fi 000102030405060708090a0b0c0d0ef2" ]
  78. params['r1kh'] = "02:00:00:00:03:00 00:01:02:03:04:05 300102030405060708090a0b0c0d0ef3"
  79. return params
  80. def ft_params2_r0kh_mismatch(rsn=True, ssid=None, passphrase=None):
  81. params = ft_params(rsn, ssid, passphrase)
  82. params['nas_identifier'] = "nas2.w1.fi"
  83. params['r1_key_holder'] = "000102030406"
  84. params['r0kh'] = [ "12:00:00:00:03:00 nas1.w1.fi 200102030405060708090a0b0c0d0e0f",
  85. "02:00:00:00:04:00 nas2.w1.fi 000102030405060708090a0b0c0d0e0f" ]
  86. params['r1kh'] = "12:00:00:00:03:00 10:01:02:03:04:05 300102030405060708090a0b0c0d0e0f"
  87. return params
  88. def run_roams(dev, apdev, hapd0, hapd1, ssid, passphrase, over_ds=False,
  89. sae=False, eap=False, fail_test=False, roams=1,
  90. pairwise_cipher="CCMP", group_cipher="TKIP CCMP", ptk_rekey="0"):
  91. logger.info("Connect to first AP")
  92. if eap:
  93. dev.connect(ssid, key_mgmt="FT-EAP", proto="WPA2", ieee80211w="1",
  94. eap="GPSK", identity="gpsk user",
  95. password="abcdefghijklmnop0123456789abcdef",
  96. scan_freq="2412",
  97. pairwise=pairwise_cipher, group=group_cipher,
  98. wpa_ptk_rekey=ptk_rekey)
  99. else:
  100. if sae:
  101. key_mgmt="FT-SAE"
  102. else:
  103. key_mgmt="FT-PSK"
  104. dev.connect(ssid, psk=passphrase, key_mgmt=key_mgmt, proto="WPA2",
  105. ieee80211w="1", scan_freq="2412",
  106. pairwise=pairwise_cipher, group=group_cipher,
  107. wpa_ptk_rekey=ptk_rekey)
  108. if dev.get_status_field('bssid') == apdev[0]['bssid']:
  109. ap1 = apdev[0]
  110. ap2 = apdev[1]
  111. hapd1ap = hapd0
  112. hapd2ap = hapd1
  113. else:
  114. ap1 = apdev[1]
  115. ap2 = apdev[0]
  116. hapd1ap = hapd1
  117. hapd2ap = hapd0
  118. hwsim_utils.test_connectivity(dev, hapd1ap)
  119. dev.scan_for_bss(ap2['bssid'], freq="2412")
  120. for i in range(0, roams):
  121. logger.info("Roam to the second AP")
  122. if over_ds:
  123. dev.roam_over_ds(ap2['bssid'], fail_test=fail_test)
  124. else:
  125. dev.roam(ap2['bssid'], fail_test=fail_test)
  126. if fail_test:
  127. return
  128. if dev.get_status_field('bssid') != ap2['bssid']:
  129. raise Exception("Did not connect to correct AP")
  130. if i == 0 or i == roams - 1:
  131. hwsim_utils.test_connectivity(dev, hapd2ap)
  132. logger.info("Roam back to the first AP")
  133. if over_ds:
  134. dev.roam_over_ds(ap1['bssid'])
  135. else:
  136. dev.roam(ap1['bssid'])
  137. if dev.get_status_field('bssid') != ap1['bssid']:
  138. raise Exception("Did not connect to correct AP")
  139. if i == 0 or i == roams - 1:
  140. hwsim_utils.test_connectivity(dev, hapd1ap)
  141. def test_ap_ft(dev, apdev):
  142. """WPA2-PSK-FT AP"""
  143. ssid = "test-ft"
  144. passphrase="12345678"
  145. params = ft_params1(ssid=ssid, passphrase=passphrase)
  146. hapd0 = hostapd.add_ap(apdev[0], params)
  147. params = ft_params2(ssid=ssid, passphrase=passphrase)
  148. hapd1 = hostapd.add_ap(apdev[1], params)
  149. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  150. if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  151. raise Exception("Scan results missing RSN element info")
  152. def test_ap_ft_local_key_gen(dev, apdev):
  153. """WPA2-PSK-FT AP with local key generation (without pull/push)"""
  154. ssid = "test-ft"
  155. passphrase="12345678"
  156. params = ft_params1a(ssid=ssid, passphrase=passphrase)
  157. params['ft_psk_generate_local'] = "1";
  158. del params['pmk_r1_push']
  159. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  160. params = ft_params2a(ssid=ssid, passphrase=passphrase)
  161. params['ft_psk_generate_local'] = "1";
  162. del params['pmk_r1_push']
  163. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  164. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  165. if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  166. raise Exception("Scan results missing RSN element info")
  167. def test_ap_ft_many(dev, apdev):
  168. """WPA2-PSK-FT AP multiple times"""
  169. ssid = "test-ft"
  170. passphrase="12345678"
  171. params = ft_params1(ssid=ssid, passphrase=passphrase)
  172. hapd0 = hostapd.add_ap(apdev[0], params)
  173. params = ft_params2(ssid=ssid, passphrase=passphrase)
  174. hapd1 = hostapd.add_ap(apdev[1], params)
  175. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, roams=50)
  176. def test_ap_ft_mixed(dev, apdev):
  177. """WPA2-PSK-FT mixed-mode AP"""
  178. ssid = "test-ft-mixed"
  179. passphrase="12345678"
  180. params = ft_params1(rsn=False, ssid=ssid, passphrase=passphrase)
  181. hapd = hostapd.add_ap(apdev[0], params)
  182. key_mgmt = hapd.get_config()['key_mgmt']
  183. vals = key_mgmt.split(' ')
  184. if vals[0] != "WPA-PSK" or vals[1] != "FT-PSK":
  185. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  186. params = ft_params2(rsn=False, ssid=ssid, passphrase=passphrase)
  187. hapd1 = hostapd.add_ap(apdev[1], params)
  188. run_roams(dev[0], apdev, hapd, hapd1, ssid, passphrase)
  189. def test_ap_ft_pmf(dev, apdev):
  190. """WPA2-PSK-FT AP with PMF"""
  191. ssid = "test-ft"
  192. passphrase="12345678"
  193. params = ft_params1(ssid=ssid, passphrase=passphrase)
  194. params["ieee80211w"] = "2"
  195. hapd0 = hostapd.add_ap(apdev[0], params)
  196. params = ft_params2(ssid=ssid, passphrase=passphrase)
  197. params["ieee80211w"] = "2"
  198. hapd1 = hostapd.add_ap(apdev[1], params)
  199. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  200. def test_ap_ft_over_ds(dev, apdev):
  201. """WPA2-PSK-FT AP over DS"""
  202. ssid = "test-ft"
  203. passphrase="12345678"
  204. params = ft_params1(ssid=ssid, passphrase=passphrase)
  205. hapd0 = hostapd.add_ap(apdev[0], params)
  206. params = ft_params2(ssid=ssid, passphrase=passphrase)
  207. hapd1 = hostapd.add_ap(apdev[1], params)
  208. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True)
  209. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-4"),
  210. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-4") ])
  211. def test_ap_ft_over_ds_disabled(dev, apdev):
  212. """WPA2-PSK-FT AP over DS disabled"""
  213. ssid = "test-ft"
  214. passphrase="12345678"
  215. params = ft_params1(ssid=ssid, passphrase=passphrase)
  216. params['ft_over_ds'] = '0'
  217. hapd0 = hostapd.add_ap(apdev[0], params)
  218. params = ft_params2(ssid=ssid, passphrase=passphrase)
  219. params['ft_over_ds'] = '0'
  220. hapd1 = hostapd.add_ap(apdev[1], params)
  221. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  222. fail_test=True)
  223. def test_ap_ft_over_ds_many(dev, apdev):
  224. """WPA2-PSK-FT AP over DS multiple times"""
  225. ssid = "test-ft"
  226. passphrase="12345678"
  227. params = ft_params1(ssid=ssid, passphrase=passphrase)
  228. hapd0 = hostapd.add_ap(apdev[0], params)
  229. params = ft_params2(ssid=ssid, passphrase=passphrase)
  230. hapd1 = hostapd.add_ap(apdev[1], params)
  231. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  232. roams=50)
  233. @remote_compatible
  234. def test_ap_ft_over_ds_unknown_target(dev, apdev):
  235. """WPA2-PSK-FT AP"""
  236. ssid = "test-ft"
  237. passphrase="12345678"
  238. params = ft_params1(ssid=ssid, passphrase=passphrase)
  239. hapd0 = hostapd.add_ap(apdev[0], params)
  240. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  241. scan_freq="2412")
  242. dev[0].roam_over_ds("02:11:22:33:44:55", fail_test=True)
  243. @remote_compatible
  244. def test_ap_ft_over_ds_unexpected(dev, apdev):
  245. """WPA2-PSK-FT AP over DS and unexpected response"""
  246. ssid = "test-ft"
  247. passphrase="12345678"
  248. params = ft_params1(ssid=ssid, passphrase=passphrase)
  249. hapd0 = hostapd.add_ap(apdev[0], params)
  250. params = ft_params2(ssid=ssid, passphrase=passphrase)
  251. hapd1 = hostapd.add_ap(apdev[1], params)
  252. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  253. scan_freq="2412")
  254. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  255. ap1 = apdev[0]
  256. ap2 = apdev[1]
  257. hapd1ap = hapd0
  258. hapd2ap = hapd1
  259. else:
  260. ap1 = apdev[1]
  261. ap2 = apdev[0]
  262. hapd1ap = hapd1
  263. hapd2ap = hapd0
  264. addr = dev[0].own_addr()
  265. hapd1ap.set("ext_mgmt_frame_handling", "1")
  266. logger.info("Foreign STA address")
  267. msg = {}
  268. msg['fc'] = 13 << 4
  269. msg['da'] = addr
  270. msg['sa'] = ap1['bssid']
  271. msg['bssid'] = ap1['bssid']
  272. msg['payload'] = binascii.unhexlify("06021122334455660102030405060000")
  273. hapd1ap.mgmt_tx(msg)
  274. logger.info("No over-the-DS in progress")
  275. msg['payload'] = binascii.unhexlify("0602" + addr.replace(':', '') + "0102030405060000")
  276. hapd1ap.mgmt_tx(msg)
  277. logger.info("Non-zero status code")
  278. msg['payload'] = binascii.unhexlify("0602" + addr.replace(':', '') + "0102030405060100")
  279. hapd1ap.mgmt_tx(msg)
  280. hapd1ap.dump_monitor()
  281. dev[0].scan_for_bss(ap2['bssid'], freq="2412")
  282. if "OK" not in dev[0].request("FT_DS " + ap2['bssid']):
  283. raise Exception("FT_DS failed")
  284. req = hapd1ap.mgmt_rx()
  285. logger.info("Foreign Target AP")
  286. msg['payload'] = binascii.unhexlify("0602" + addr.replace(':', '') + "0102030405060000")
  287. hapd1ap.mgmt_tx(msg)
  288. addrs = addr.replace(':', '') + ap2['bssid'].replace(':', '')
  289. logger.info("No IEs")
  290. msg['payload'] = binascii.unhexlify("0602" + addrs + "0000")
  291. hapd1ap.mgmt_tx(msg)
  292. logger.info("Invalid IEs (trigger parsing failure)")
  293. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003700")
  294. hapd1ap.mgmt_tx(msg)
  295. logger.info("Too short MDIE")
  296. msg['payload'] = binascii.unhexlify("0602" + addrs + "000036021122")
  297. hapd1ap.mgmt_tx(msg)
  298. logger.info("Mobility domain mismatch")
  299. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603112201")
  300. hapd1ap.mgmt_tx(msg)
  301. logger.info("No FTIE")
  302. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201")
  303. hapd1ap.mgmt_tx(msg)
  304. logger.info("FTIE SNonce mismatch")
  305. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201375e0000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "1000000000000000000000000000000000000000000000000000000000000001" + "030a6e6173322e77312e6669")
  306. hapd1ap.mgmt_tx(msg)
  307. logger.info("No R0KH-ID subelem in FTIE")
  308. snonce = binascii.hexlify(req['payload'][111:111+32])
  309. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b20137520000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce)
  310. hapd1ap.mgmt_tx(msg)
  311. logger.info("No R0KH-ID subelem mismatch in FTIE")
  312. snonce = binascii.hexlify(req['payload'][111:111+32])
  313. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201375e0000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce + "030a11223344556677889900")
  314. hapd1ap.mgmt_tx(msg)
  315. logger.info("No R1KH-ID subelem in FTIE")
  316. r0khid = binascii.hexlify(req['payload'][145:145+10])
  317. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201375e0000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce + "030a" + r0khid)
  318. hapd1ap.mgmt_tx(msg)
  319. logger.info("No RSNE")
  320. r0khid = binascii.hexlify(req['payload'][145:145+10])
  321. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b20137660000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce + "030a" + r0khid + "0106000102030405")
  322. hapd1ap.mgmt_tx(msg)
  323. def test_ap_ft_pmf_over_ds(dev, apdev):
  324. """WPA2-PSK-FT AP over DS with PMF"""
  325. ssid = "test-ft"
  326. passphrase="12345678"
  327. params = ft_params1(ssid=ssid, passphrase=passphrase)
  328. params["ieee80211w"] = "2"
  329. hapd0 = hostapd.add_ap(apdev[0], params)
  330. params = ft_params2(ssid=ssid, passphrase=passphrase)
  331. params["ieee80211w"] = "2"
  332. hapd1 = hostapd.add_ap(apdev[1], params)
  333. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True)
  334. def test_ap_ft_over_ds_pull(dev, apdev):
  335. """WPA2-PSK-FT AP over DS (pull PMK)"""
  336. ssid = "test-ft"
  337. passphrase="12345678"
  338. params = ft_params1(ssid=ssid, passphrase=passphrase)
  339. params["pmk_r1_push"] = "0"
  340. hapd0 = hostapd.add_ap(apdev[0], params)
  341. params = ft_params2(ssid=ssid, passphrase=passphrase)
  342. params["pmk_r1_push"] = "0"
  343. hapd1 = hostapd.add_ap(apdev[1], params)
  344. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True)
  345. def test_ap_ft_sae(dev, apdev):
  346. """WPA2-PSK-FT-SAE AP"""
  347. if "SAE" not in dev[0].get_capability("auth_alg"):
  348. raise HwsimSkip("SAE not supported")
  349. ssid = "test-ft"
  350. passphrase="12345678"
  351. params = ft_params1(ssid=ssid, passphrase=passphrase)
  352. params['wpa_key_mgmt'] = "FT-SAE"
  353. hapd0 = hostapd.add_ap(apdev[0], params)
  354. params = ft_params2(ssid=ssid, passphrase=passphrase)
  355. params['wpa_key_mgmt'] = "FT-SAE"
  356. hapd = hostapd.add_ap(apdev[1], params)
  357. key_mgmt = hapd.get_config()['key_mgmt']
  358. if key_mgmt.split(' ')[0] != "FT-SAE":
  359. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  360. dev[0].request("SET sae_groups ")
  361. run_roams(dev[0], apdev, hapd0, hapd, ssid, passphrase, sae=True)
  362. def test_ap_ft_sae_over_ds(dev, apdev):
  363. """WPA2-PSK-FT-SAE AP over DS"""
  364. if "SAE" not in dev[0].get_capability("auth_alg"):
  365. raise HwsimSkip("SAE not supported")
  366. ssid = "test-ft"
  367. passphrase="12345678"
  368. params = ft_params1(ssid=ssid, passphrase=passphrase)
  369. params['wpa_key_mgmt'] = "FT-SAE"
  370. hapd0 = hostapd.add_ap(apdev[0], params)
  371. params = ft_params2(ssid=ssid, passphrase=passphrase)
  372. params['wpa_key_mgmt'] = "FT-SAE"
  373. hapd1 = hostapd.add_ap(apdev[1], params)
  374. dev[0].request("SET sae_groups ")
  375. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, sae=True,
  376. over_ds=True)
  377. def test_ap_ft_eap(dev, apdev):
  378. """WPA2-EAP-FT AP"""
  379. ssid = "test-ft"
  380. passphrase="12345678"
  381. radius = hostapd.radius_params()
  382. params = ft_params1(ssid=ssid, passphrase=passphrase)
  383. params['wpa_key_mgmt'] = "FT-EAP"
  384. params["ieee8021x"] = "1"
  385. params = dict(radius.items() + params.items())
  386. hapd = hostapd.add_ap(apdev[0], params)
  387. key_mgmt = hapd.get_config()['key_mgmt']
  388. if key_mgmt.split(' ')[0] != "FT-EAP":
  389. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  390. params = ft_params2(ssid=ssid, passphrase=passphrase)
  391. params['wpa_key_mgmt'] = "FT-EAP"
  392. params["ieee8021x"] = "1"
  393. params = dict(radius.items() + params.items())
  394. hapd1 = hostapd.add_ap(apdev[1], params)
  395. run_roams(dev[0], apdev, hapd, hapd1, ssid, passphrase, eap=True)
  396. if "[WPA2-FT/EAP-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  397. raise Exception("Scan results missing RSN element info")
  398. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-3"),
  399. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-3") ])
  400. # Verify EAPOL reauthentication after FT protocol
  401. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  402. ap = hapd
  403. else:
  404. ap = hapd1
  405. ap.request("EAPOL_REAUTH " + dev[0].own_addr())
  406. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  407. if ev is None:
  408. raise Exception("EAP authentication did not start")
  409. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  410. if ev is None:
  411. raise Exception("EAP authentication did not succeed")
  412. time.sleep(0.1)
  413. hwsim_utils.test_connectivity(dev[0], ap)
  414. def test_ap_ft_eap_pull(dev, apdev):
  415. """WPA2-EAP-FT AP (pull PMK)"""
  416. ssid = "test-ft"
  417. passphrase="12345678"
  418. radius = hostapd.radius_params()
  419. params = ft_params1(ssid=ssid, passphrase=passphrase)
  420. params['wpa_key_mgmt'] = "FT-EAP"
  421. params["ieee8021x"] = "1"
  422. params["pmk_r1_push"] = "0"
  423. params = dict(radius.items() + params.items())
  424. hapd = hostapd.add_ap(apdev[0], params)
  425. key_mgmt = hapd.get_config()['key_mgmt']
  426. if key_mgmt.split(' ')[0] != "FT-EAP":
  427. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  428. params = ft_params2(ssid=ssid, passphrase=passphrase)
  429. params['wpa_key_mgmt'] = "FT-EAP"
  430. params["ieee8021x"] = "1"
  431. params["pmk_r1_push"] = "0"
  432. params = dict(radius.items() + params.items())
  433. hapd1 = hostapd.add_ap(apdev[1], params)
  434. run_roams(dev[0], apdev, hapd, hapd1, ssid, passphrase, eap=True)
  435. @remote_compatible
  436. def test_ap_ft_mismatching_rrb_key_push(dev, apdev):
  437. """WPA2-PSK-FT AP over DS with mismatching RRB key (push)"""
  438. ssid = "test-ft"
  439. passphrase="12345678"
  440. params = ft_params1(ssid=ssid, passphrase=passphrase)
  441. params["ieee80211w"] = "2"
  442. hapd0 = hostapd.add_ap(apdev[0], params)
  443. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  444. params["ieee80211w"] = "2"
  445. hapd1 = hostapd.add_ap(apdev[1], params)
  446. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  447. fail_test=True)
  448. @remote_compatible
  449. def test_ap_ft_mismatching_rrb_key_pull(dev, apdev):
  450. """WPA2-PSK-FT AP over DS with mismatching RRB key (pull)"""
  451. ssid = "test-ft"
  452. passphrase="12345678"
  453. params = ft_params1(ssid=ssid, passphrase=passphrase)
  454. params["pmk_r1_push"] = "0"
  455. hapd0 = hostapd.add_ap(apdev[0], params)
  456. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  457. params["pmk_r1_push"] = "0"
  458. hapd1 = hostapd.add_ap(apdev[1], params)
  459. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  460. fail_test=True)
  461. @remote_compatible
  462. def test_ap_ft_mismatching_r0kh_id_pull(dev, apdev):
  463. """WPA2-PSK-FT AP over DS with mismatching R0KH-ID (pull)"""
  464. ssid = "test-ft"
  465. passphrase="12345678"
  466. params = ft_params1(ssid=ssid, passphrase=passphrase)
  467. params["pmk_r1_push"] = "0"
  468. params["nas_identifier"] = "nas0.w1.fi"
  469. hostapd.add_ap(apdev[0], params)
  470. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  471. scan_freq="2412")
  472. params = ft_params2(ssid=ssid, passphrase=passphrase)
  473. params["pmk_r1_push"] = "0"
  474. hostapd.add_ap(apdev[1], params)
  475. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  476. dev[0].roam_over_ds(apdev[1]['bssid'], fail_test=True)
  477. @remote_compatible
  478. def test_ap_ft_mismatching_rrb_r0kh_push(dev, apdev):
  479. """WPA2-PSK-FT AP over DS with mismatching R0KH key (push)"""
  480. ssid = "test-ft"
  481. passphrase="12345678"
  482. params = ft_params1(ssid=ssid, passphrase=passphrase)
  483. params["ieee80211w"] = "2"
  484. hapd0 = hostapd.add_ap(apdev[0], params)
  485. params = ft_params2_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  486. params["ieee80211w"] = "2"
  487. hapd1 = hostapd.add_ap(apdev[1], params)
  488. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  489. fail_test=True)
  490. @remote_compatible
  491. def test_ap_ft_mismatching_rrb_r0kh_pull(dev, apdev):
  492. """WPA2-PSK-FT AP over DS with mismatching R0KH key (pull)"""
  493. ssid = "test-ft"
  494. passphrase="12345678"
  495. params = ft_params1_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  496. params["pmk_r1_push"] = "0"
  497. hapd0 = hostapd.add_ap(apdev[0], params)
  498. params = ft_params2(ssid=ssid, passphrase=passphrase)
  499. params["pmk_r1_push"] = "0"
  500. hapd1 = hostapd.add_ap(apdev[1], params)
  501. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  502. fail_test=True)
  503. def test_ap_ft_mismatching_rrb_key_push_eap(dev, apdev):
  504. """WPA2-EAP-FT AP over DS with mismatching RRB key (push)"""
  505. ssid = "test-ft"
  506. passphrase="12345678"
  507. radius = hostapd.radius_params()
  508. params = ft_params1(ssid=ssid, passphrase=passphrase)
  509. params["ieee80211w"] = "2";
  510. params['wpa_key_mgmt'] = "FT-EAP"
  511. params["ieee8021x"] = "1"
  512. params = dict(radius.items() + params.items())
  513. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  514. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  515. params["ieee80211w"] = "2";
  516. params['wpa_key_mgmt'] = "FT-EAP"
  517. params["ieee8021x"] = "1"
  518. params = dict(radius.items() + params.items())
  519. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  520. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  521. fail_test=True, eap=True)
  522. def test_ap_ft_mismatching_rrb_key_pull_eap(dev, apdev):
  523. """WPA2-EAP-FT AP over DS with mismatching RRB key (pull)"""
  524. ssid = "test-ft"
  525. passphrase="12345678"
  526. radius = hostapd.radius_params()
  527. params = ft_params1(ssid=ssid, passphrase=passphrase)
  528. params["pmk_r1_push"] = "0"
  529. params['wpa_key_mgmt'] = "FT-EAP"
  530. params["ieee8021x"] = "1"
  531. params = dict(radius.items() + params.items())
  532. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  533. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  534. params["pmk_r1_push"] = "0"
  535. params['wpa_key_mgmt'] = "FT-EAP"
  536. params["ieee8021x"] = "1"
  537. params = dict(radius.items() + params.items())
  538. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  539. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  540. fail_test=True, eap=True)
  541. def test_ap_ft_mismatching_r0kh_id_pull_eap(dev, apdev):
  542. """WPA2-EAP-FT AP over DS with mismatching R0KH-ID (pull)"""
  543. ssid = "test-ft"
  544. passphrase="12345678"
  545. radius = hostapd.radius_params()
  546. params = ft_params1(ssid=ssid, passphrase=passphrase)
  547. params["pmk_r1_push"] = "0"
  548. params["nas_identifier"] = "nas0.w1.fi"
  549. params['wpa_key_mgmt'] = "FT-EAP"
  550. params["ieee8021x"] = "1"
  551. params = dict(radius.items() + params.items())
  552. hostapd.add_ap(apdev[0]['ifname'], params)
  553. dev[0].connect(ssid, key_mgmt="FT-EAP", proto="WPA2", ieee80211w="1",
  554. eap="GPSK", identity="gpsk user",
  555. password="abcdefghijklmnop0123456789abcdef",
  556. scan_freq="2412")
  557. params = ft_params2(ssid=ssid, passphrase=passphrase)
  558. params["pmk_r1_push"] = "0"
  559. params['wpa_key_mgmt'] = "FT-EAP"
  560. params["ieee8021x"] = "1"
  561. params = dict(radius.items() + params.items())
  562. hostapd.add_ap(apdev[1]['ifname'], params)
  563. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  564. dev[0].roam_over_ds(apdev[1]['bssid'], fail_test=True)
  565. def test_ap_ft_mismatching_rrb_r0kh_push_eap(dev, apdev):
  566. """WPA2-EAP-FT AP over DS with mismatching R0KH key (push)"""
  567. ssid = "test-ft"
  568. passphrase="12345678"
  569. radius = hostapd.radius_params()
  570. params = ft_params1(ssid=ssid, passphrase=passphrase)
  571. params["ieee80211w"] = "2";
  572. params['wpa_key_mgmt'] = "FT-EAP"
  573. params["ieee8021x"] = "1"
  574. params = dict(radius.items() + params.items())
  575. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  576. params = ft_params2_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  577. params["ieee80211w"] = "2";
  578. params['wpa_key_mgmt'] = "FT-EAP"
  579. params["ieee8021x"] = "1"
  580. params = dict(radius.items() + params.items())
  581. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  582. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  583. fail_test=True, eap=True)
  584. def test_ap_ft_mismatching_rrb_r0kh_pull_eap(dev, apdev):
  585. """WPA2-EAP-FT AP over DS with mismatching R0KH key (pull)"""
  586. ssid = "test-ft"
  587. passphrase="12345678"
  588. radius = hostapd.radius_params()
  589. params = ft_params1_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  590. params["pmk_r1_push"] = "0"
  591. params['wpa_key_mgmt'] = "FT-EAP"
  592. params["ieee8021x"] = "1"
  593. params = dict(radius.items() + params.items())
  594. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  595. params = ft_params2(ssid=ssid, passphrase=passphrase)
  596. params["pmk_r1_push"] = "0"
  597. params['wpa_key_mgmt'] = "FT-EAP"
  598. params["ieee8021x"] = "1"
  599. params = dict(radius.items() + params.items())
  600. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  601. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  602. fail_test=True, eap=True)
  603. def test_ap_ft_gtk_rekey(dev, apdev):
  604. """WPA2-PSK-FT AP and GTK rekey"""
  605. ssid = "test-ft"
  606. passphrase="12345678"
  607. params = ft_params1(ssid=ssid, passphrase=passphrase)
  608. params['wpa_group_rekey'] = '1'
  609. hapd = hostapd.add_ap(apdev[0], params)
  610. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  611. ieee80211w="1", scan_freq="2412")
  612. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  613. if ev is None:
  614. raise Exception("GTK rekey timed out after initial association")
  615. hwsim_utils.test_connectivity(dev[0], hapd)
  616. params = ft_params2(ssid=ssid, passphrase=passphrase)
  617. params['wpa_group_rekey'] = '1'
  618. hapd1 = hostapd.add_ap(apdev[1], params)
  619. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  620. dev[0].roam(apdev[1]['bssid'])
  621. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  622. raise Exception("Did not connect to correct AP")
  623. hwsim_utils.test_connectivity(dev[0], hapd1)
  624. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  625. if ev is None:
  626. raise Exception("GTK rekey timed out after FT protocol")
  627. hwsim_utils.test_connectivity(dev[0], hapd1)
  628. def test_ft_psk_key_lifetime_in_memory(dev, apdev, params):
  629. """WPA2-PSK-FT and key lifetime in memory"""
  630. ssid = "test-ft"
  631. passphrase="04c2726b4b8d5f1b4db9c07aa4d9e9d8f765cb5d25ec817e6cc4fcdd5255db0"
  632. psk = '93c90846ff67af9037ed83fb72b63dbeddaa81d47f926c20909b5886f1d9358d'
  633. pmk = binascii.unhexlify(psk)
  634. p = ft_params1(ssid=ssid, passphrase=passphrase)
  635. hapd0 = hostapd.add_ap(apdev[0], p)
  636. p = ft_params2(ssid=ssid, passphrase=passphrase)
  637. hapd1 = hostapd.add_ap(apdev[1], p)
  638. pid = find_wpas_process(dev[0])
  639. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  640. scan_freq="2412")
  641. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  642. # event has been delivered, so verify that wpa_supplicant has returned to
  643. # eloop before reading process memory.
  644. time.sleep(1)
  645. dev[0].ping()
  646. buf = read_process_memory(pid, pmk)
  647. dev[0].request("DISCONNECT")
  648. dev[0].wait_disconnected()
  649. dev[0].relog()
  650. pmkr0 = None
  651. pmkr1 = None
  652. ptk = None
  653. gtk = None
  654. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  655. for l in f.readlines():
  656. if "FT: PMK-R0 - hexdump" in l:
  657. val = l.strip().split(':')[3].replace(' ', '')
  658. pmkr0 = binascii.unhexlify(val)
  659. if "FT: PMK-R1 - hexdump" in l:
  660. val = l.strip().split(':')[3].replace(' ', '')
  661. pmkr1 = binascii.unhexlify(val)
  662. if "FT: KCK - hexdump" in l:
  663. val = l.strip().split(':')[3].replace(' ', '')
  664. kck = binascii.unhexlify(val)
  665. if "FT: KEK - hexdump" in l:
  666. val = l.strip().split(':')[3].replace(' ', '')
  667. kek = binascii.unhexlify(val)
  668. if "FT: TK - hexdump" in l:
  669. val = l.strip().split(':')[3].replace(' ', '')
  670. tk = binascii.unhexlify(val)
  671. if "WPA: Group Key - hexdump" in l:
  672. val = l.strip().split(':')[3].replace(' ', '')
  673. gtk = binascii.unhexlify(val)
  674. if not pmkr0 or not pmkr1 or not kck or not kek or not tk or not gtk:
  675. raise Exception("Could not find keys from debug log")
  676. if len(gtk) != 16:
  677. raise Exception("Unexpected GTK length")
  678. logger.info("Checking keys in memory while associated")
  679. get_key_locations(buf, pmk, "PMK")
  680. get_key_locations(buf, pmkr0, "PMK-R0")
  681. get_key_locations(buf, pmkr1, "PMK-R1")
  682. if pmk not in buf:
  683. raise HwsimSkip("PMK not found while associated")
  684. if pmkr0 not in buf:
  685. raise HwsimSkip("PMK-R0 not found while associated")
  686. if pmkr1 not in buf:
  687. raise HwsimSkip("PMK-R1 not found while associated")
  688. if kck not in buf:
  689. raise Exception("KCK not found while associated")
  690. if kek not in buf:
  691. raise Exception("KEK not found while associated")
  692. if tk in buf:
  693. raise Exception("TK found from memory")
  694. if gtk in buf:
  695. get_key_locations(buf, gtk, "GTK")
  696. raise Exception("GTK found from memory")
  697. logger.info("Checking keys in memory after disassociation")
  698. buf = read_process_memory(pid, pmk)
  699. get_key_locations(buf, pmk, "PMK")
  700. get_key_locations(buf, pmkr0, "PMK-R0")
  701. get_key_locations(buf, pmkr1, "PMK-R1")
  702. # Note: PMK/PSK is still present in network configuration
  703. fname = os.path.join(params['logdir'],
  704. 'ft_psk_key_lifetime_in_memory.memctx-')
  705. verify_not_present(buf, pmkr0, fname, "PMK-R0")
  706. verify_not_present(buf, pmkr1, fname, "PMK-R1")
  707. verify_not_present(buf, kck, fname, "KCK")
  708. verify_not_present(buf, kek, fname, "KEK")
  709. verify_not_present(buf, tk, fname, "TK")
  710. verify_not_present(buf, gtk, fname, "GTK")
  711. dev[0].request("REMOVE_NETWORK all")
  712. logger.info("Checking keys in memory after network profile removal")
  713. buf = read_process_memory(pid, pmk)
  714. get_key_locations(buf, pmk, "PMK")
  715. get_key_locations(buf, pmkr0, "PMK-R0")
  716. get_key_locations(buf, pmkr1, "PMK-R1")
  717. verify_not_present(buf, pmk, fname, "PMK")
  718. verify_not_present(buf, pmkr0, fname, "PMK-R0")
  719. verify_not_present(buf, pmkr1, fname, "PMK-R1")
  720. verify_not_present(buf, kck, fname, "KCK")
  721. verify_not_present(buf, kek, fname, "KEK")
  722. verify_not_present(buf, tk, fname, "TK")
  723. verify_not_present(buf, gtk, fname, "GTK")
  724. @remote_compatible
  725. def test_ap_ft_invalid_resp(dev, apdev):
  726. """WPA2-PSK-FT AP and invalid response IEs"""
  727. ssid = "test-ft"
  728. passphrase="12345678"
  729. params = ft_params1(ssid=ssid, passphrase=passphrase)
  730. hapd0 = hostapd.add_ap(apdev[0], params)
  731. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  732. scan_freq="2412")
  733. params = ft_params2(ssid=ssid, passphrase=passphrase)
  734. hapd1 = hostapd.add_ap(apdev[1], params)
  735. tests = [
  736. # Various IEs for test coverage. The last one is FTIE with invalid
  737. # R1KH-ID subelement.
  738. "020002000000" + "3800" + "38051122334455" + "3754000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010100",
  739. # FTIE with invalid R0KH-ID subelement (len=0).
  740. "020002000000" + "3754000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010300",
  741. # FTIE with invalid R0KH-ID subelement (len=49).
  742. "020002000000" + "378500010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001033101020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849",
  743. # Invalid RSNE.
  744. "020002000000" + "3000",
  745. # Required IEs missing from protected IE count.
  746. "020002000000" + "3603a1b201" + "375200010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001" + "3900",
  747. # RIC missing from protected IE count.
  748. "020002000000" + "3603a1b201" + "375200020203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001" + "3900",
  749. # Protected IE missing.
  750. "020002000000" + "3603a1b201" + "375200ff0203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001" + "3900" + "0000" ]
  751. for t in tests:
  752. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  753. hapd1.set("ext_mgmt_frame_handling", "1")
  754. hapd1.dump_monitor()
  755. if "OK" not in dev[0].request("ROAM " + apdev[1]['bssid']):
  756. raise Exception("ROAM failed")
  757. auth = None
  758. for i in range(20):
  759. msg = hapd1.mgmt_rx()
  760. if msg['subtype'] == 11:
  761. auth = msg
  762. break
  763. if not auth:
  764. raise Exception("Authentication frame not seen")
  765. resp = {}
  766. resp['fc'] = auth['fc']
  767. resp['da'] = auth['sa']
  768. resp['sa'] = auth['da']
  769. resp['bssid'] = auth['bssid']
  770. resp['payload'] = binascii.unhexlify(t)
  771. hapd1.mgmt_tx(resp)
  772. hapd1.set("ext_mgmt_frame_handling", "0")
  773. dev[0].wait_disconnected()
  774. dev[0].request("RECONNECT")
  775. dev[0].wait_connected()
  776. def test_ap_ft_gcmp_256(dev, apdev):
  777. """WPA2-PSK-FT AP with GCMP-256 cipher"""
  778. if "GCMP-256" not in dev[0].get_capability("pairwise"):
  779. raise HwsimSkip("Cipher GCMP-256 not supported")
  780. ssid = "test-ft"
  781. passphrase="12345678"
  782. params = ft_params1(ssid=ssid, passphrase=passphrase)
  783. params['rsn_pairwise'] = "GCMP-256"
  784. hapd0 = hostapd.add_ap(apdev[0], params)
  785. params = ft_params2(ssid=ssid, passphrase=passphrase)
  786. params['rsn_pairwise'] = "GCMP-256"
  787. hapd1 = hostapd.add_ap(apdev[1], params)
  788. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase,
  789. pairwise_cipher="GCMP-256", group_cipher="GCMP-256")
  790. def test_ap_ft_oom(dev, apdev):
  791. """WPA2-PSK-FT and OOM"""
  792. skip_with_fips(dev[0])
  793. ssid = "test-ft"
  794. passphrase="12345678"
  795. params = ft_params1(ssid=ssid, passphrase=passphrase)
  796. hapd0 = hostapd.add_ap(apdev[0], params)
  797. params = ft_params2(ssid=ssid, passphrase=passphrase)
  798. hapd1 = hostapd.add_ap(apdev[1], params)
  799. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  800. scan_freq="2412")
  801. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  802. dst = apdev[1]['bssid']
  803. else:
  804. dst = apdev[0]['bssid']
  805. dev[0].scan_for_bss(dst, freq="2412")
  806. with alloc_fail(dev[0], 1, "wpa_ft_gen_req_ies"):
  807. dev[0].roam(dst)
  808. with fail_test(dev[0], 1, "wpa_ft_mic"):
  809. dev[0].roam(dst, fail_test=True)
  810. with fail_test(dev[0], 1, "os_get_random;wpa_ft_prepare_auth_request"):
  811. dev[0].roam(dst, fail_test=True)
  812. dev[0].request("REMOVE_NETWORK all")
  813. with alloc_fail(dev[0], 1, "=sme_update_ft_ies"):
  814. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  815. scan_freq="2412")
  816. def test_ap_ft_over_ds_proto(dev, apdev):
  817. """WPA2-PSK-FT AP over DS protocol testing"""
  818. ssid = "test-ft"
  819. passphrase="12345678"
  820. params = ft_params1(ssid=ssid, passphrase=passphrase)
  821. hapd0 = hostapd.add_ap(apdev[0], params)
  822. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  823. scan_freq="2412")
  824. # FT Action Response while no FT-over-DS in progress
  825. msg = {}
  826. msg['fc'] = 13 << 4
  827. msg['da'] = dev[0].own_addr()
  828. msg['sa'] = apdev[0]['bssid']
  829. msg['bssid'] = apdev[0]['bssid']
  830. msg['payload'] = binascii.unhexlify("06020200000000000200000004000000")
  831. hapd0.mgmt_tx(msg)
  832. params = ft_params2(ssid=ssid, passphrase=passphrase)
  833. hapd1 = hostapd.add_ap(apdev[1], params)
  834. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  835. hapd0.set("ext_mgmt_frame_handling", "1")
  836. hapd0.dump_monitor()
  837. dev[0].request("FT_DS " + apdev[1]['bssid'])
  838. for i in range(0, 10):
  839. req = hapd0.mgmt_rx()
  840. if req is None:
  841. raise Exception("MGMT RX wait timed out")
  842. if req['subtype'] == 13:
  843. break
  844. req = None
  845. if not req:
  846. raise Exception("FT Action frame not received")
  847. # FT Action Response for unexpected Target AP
  848. msg['payload'] = binascii.unhexlify("0602020000000000" + "f20000000400" + "0000")
  849. hapd0.mgmt_tx(msg)
  850. # FT Action Response without MDIE
  851. msg['payload'] = binascii.unhexlify("0602020000000000" + "020000000400" + "0000")
  852. hapd0.mgmt_tx(msg)
  853. # FT Action Response without FTIE
  854. msg['payload'] = binascii.unhexlify("0602020000000000" + "020000000400" + "0000" + "3603a1b201")
  855. hapd0.mgmt_tx(msg)
  856. # FT Action Response with FTIE SNonce mismatch
  857. msg['payload'] = binascii.unhexlify("0602020000000000" + "020000000400" + "0000" + "3603a1b201" + "3766000000000000000000000000000000000000c4e67ac1999bebd00ff4ae4d5dcaf87896bb060b469f7c78d49623fb395c3455ffffff6b693fe6f8d8c5dfac0a22344750775bd09437f98b238c9f87b97f790c0106000102030406030a6e6173312e77312e6669")
  858. hapd0.mgmt_tx(msg)
  859. @remote_compatible
  860. def test_ap_ft_rrb(dev, apdev):
  861. """WPA2-PSK-FT RRB protocol testing"""
  862. ssid = "test-ft"
  863. passphrase="12345678"
  864. params = ft_params1(ssid=ssid, passphrase=passphrase)
  865. hapd0 = hostapd.add_ap(apdev[0], params)
  866. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  867. scan_freq="2412")
  868. _dst_ll = binascii.unhexlify(apdev[0]['bssid'].replace(':',''))
  869. _src_ll = binascii.unhexlify(dev[0].own_addr().replace(':',''))
  870. proto = '\x89\x0d'
  871. ehdr = _dst_ll + _src_ll + proto
  872. # Too short RRB frame
  873. pkt = ehdr + '\x01'
  874. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  875. raise Exception("DATA_TEST_FRAME failed")
  876. # RRB discarded frame wikth unrecognized type
  877. pkt = ehdr + '\x02' + '\x02' + '\x01\x00' + _src_ll
  878. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  879. raise Exception("DATA_TEST_FRAME failed")
  880. # RRB frame too short for action frame
  881. pkt = ehdr + '\x01' + '\x02' + '\x01\x00' + _src_ll
  882. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  883. raise Exception("DATA_TEST_FRAME failed")
  884. # Too short RRB frame (not enough room for Action Frame body)
  885. pkt = ehdr + '\x01' + '\x02' + '\x00\x00' + _src_ll
  886. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  887. raise Exception("DATA_TEST_FRAME failed")
  888. # Unexpected Action frame category
  889. pkt = ehdr + '\x01' + '\x02' + '\x0e\x00' + _src_ll + '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  890. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  891. raise Exception("DATA_TEST_FRAME failed")
  892. # Unexpected Action in RRB Request
  893. pkt = ehdr + '\x01' + '\x00' + '\x0e\x00' + _src_ll + '\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  894. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  895. raise Exception("DATA_TEST_FRAME failed")
  896. # Target AP address in RRB Request does not match with own address
  897. pkt = ehdr + '\x01' + '\x00' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  898. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  899. raise Exception("DATA_TEST_FRAME failed")
  900. # Not enough room for status code in RRB Response
  901. pkt = ehdr + '\x01' + '\x01' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  902. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  903. raise Exception("DATA_TEST_FRAME failed")
  904. # RRB discarded frame with unknown packet_type
  905. pkt = ehdr + '\x01' + '\x02' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  906. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  907. raise Exception("DATA_TEST_FRAME failed")
  908. # RRB Response with non-zero status code; no STA match
  909. pkt = ehdr + '\x01' + '\x01' + '\x10\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + '\xff\xff'
  910. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  911. raise Exception("DATA_TEST_FRAME failed")
  912. # RRB Response with zero status code and extra data; STA match
  913. pkt = ehdr + '\x01' + '\x01' + '\x11\x00' + _src_ll + '\x06\x01' + _src_ll + '\x00\x00\x00\x00\x00\x00' + '\x00\x00' + '\x00'
  914. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  915. raise Exception("DATA_TEST_FRAME failed")
  916. # Too short PMK-R1 pull
  917. pkt = ehdr + '\x01' + '\xc8' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  918. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  919. raise Exception("DATA_TEST_FRAME failed")
  920. # Too short PMK-R1 resp
  921. pkt = ehdr + '\x01' + '\xc9' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  922. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  923. raise Exception("DATA_TEST_FRAME failed")
  924. # Too short PMK-R1 push
  925. pkt = ehdr + '\x01' + '\xca' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  926. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  927. raise Exception("DATA_TEST_FRAME failed")
  928. # No matching R0KH address found for PMK-R0 pull response
  929. pkt = ehdr + '\x01' + '\xc9' + '\x5a\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + 76*'\00'
  930. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  931. raise Exception("DATA_TEST_FRAME failed")
  932. @remote_compatible
  933. def test_rsn_ie_proto_ft_psk_sta(dev, apdev):
  934. """RSN element protocol testing for FT-PSK + PMF cases on STA side"""
  935. bssid = apdev[0]['bssid']
  936. ssid = "test-ft"
  937. passphrase="12345678"
  938. params = ft_params1(ssid=ssid, passphrase=passphrase)
  939. params["ieee80211w"] = "1"
  940. # This is the RSN element used normally by hostapd
  941. params['own_ie_override'] = '30140100000fac040100000fac040100000fac048c00' + '3603a1b201'
  942. hapd = hostapd.add_ap(apdev[0], params)
  943. id = dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  944. ieee80211w="1", scan_freq="2412",
  945. pairwise="CCMP", group="CCMP")
  946. tests = [ ('PMKIDCount field included',
  947. '30160100000fac040100000fac040100000fac048c000000' + '3603a1b201'),
  948. ('Extra IE before RSNE',
  949. 'dd0400000000' + '30140100000fac040100000fac040100000fac048c00' + '3603a1b201'),
  950. ('PMKIDCount and Group Management Cipher suite fields included',
  951. '301a0100000fac040100000fac040100000fac048c000000000fac06' + '3603a1b201'),
  952. ('Extra octet after defined fields (future extensibility)',
  953. '301b0100000fac040100000fac040100000fac048c000000000fac0600' + '3603a1b201'),
  954. ('No RSN Capabilities field (PMF disabled in practice)',
  955. '30120100000fac040100000fac040100000fac04' + '3603a1b201') ]
  956. for txt,ie in tests:
  957. dev[0].request("DISCONNECT")
  958. dev[0].wait_disconnected()
  959. logger.info(txt)
  960. hapd.disable()
  961. hapd.set('own_ie_override', ie)
  962. hapd.enable()
  963. dev[0].request("BSS_FLUSH 0")
  964. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  965. dev[0].select_network(id, freq=2412)
  966. dev[0].wait_connected()
  967. dev[0].request("DISCONNECT")
  968. dev[0].wait_disconnected()
  969. logger.info('Invalid RSNE causing internal hostapd error')
  970. hapd.disable()
  971. hapd.set('own_ie_override', '30130100000fac040100000fac040100000fac048c' + '3603a1b201')
  972. hapd.enable()
  973. dev[0].request("BSS_FLUSH 0")
  974. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  975. dev[0].select_network(id, freq=2412)
  976. # hostapd fails to generate EAPOL-Key msg 3/4, so this connection cannot
  977. # complete.
  978. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  979. if ev is not None:
  980. raise Exception("Unexpected connection")
  981. dev[0].request("DISCONNECT")
  982. logger.info('Unexpected PMKID causing internal hostapd error')
  983. hapd.disable()
  984. hapd.set('own_ie_override', '30260100000fac040100000fac040100000fac048c000100ffffffffffffffffffffffffffffffff' + '3603a1b201')
  985. hapd.enable()
  986. dev[0].request("BSS_FLUSH 0")
  987. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  988. dev[0].select_network(id, freq=2412)
  989. # hostapd fails to generate EAPOL-Key msg 3/4, so this connection cannot
  990. # complete.
  991. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  992. if ev is not None:
  993. raise Exception("Unexpected connection")
  994. dev[0].request("DISCONNECT")
  995. def test_ap_ft_ptk_rekey(dev, apdev):
  996. """WPA2-PSK-FT PTK rekeying triggered by station after roam"""
  997. ssid = "test-ft"
  998. passphrase="12345678"
  999. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1000. hapd0 = hostapd.add_ap(apdev[0], params)
  1001. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1002. hapd1 = hostapd.add_ap(apdev[1], params)
  1003. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, ptk_rekey="1")
  1004. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
  1005. "WPA: Key negotiation completed"], timeout=5)
  1006. if ev is None:
  1007. raise Exception("No event received after roam")
  1008. if "CTRL-EVENT-DISCONNECTED" in ev:
  1009. raise Exception("Unexpected disconnection after roam")
  1010. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  1011. hapd = hapd0
  1012. else:
  1013. hapd = hapd1
  1014. hwsim_utils.test_connectivity(dev[0], hapd)
  1015. def test_ap_ft_ptk_rekey_ap(dev, apdev):
  1016. """WPA2-PSK-FT PTK rekeying triggered by AP after roam"""
  1017. ssid = "test-ft"
  1018. passphrase="12345678"
  1019. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1020. params['wpa_ptk_rekey'] = '2'
  1021. hapd0 = hostapd.add_ap(apdev[0], params)
  1022. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1023. params['wpa_ptk_rekey'] = '2'
  1024. hapd1 = hostapd.add_ap(apdev[1], params)
  1025. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  1026. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
  1027. "WPA: Key negotiation completed"], timeout=5)
  1028. if ev is None:
  1029. raise Exception("No event received after roam")
  1030. if "CTRL-EVENT-DISCONNECTED" in ev:
  1031. raise Exception("Unexpected disconnection after roam")
  1032. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  1033. hapd = hapd0
  1034. else:
  1035. hapd = hapd1
  1036. hwsim_utils.test_connectivity(dev[0], hapd)
  1037. def test_ap_ft_internal_rrb_check(dev, apdev):
  1038. """RRB internal delivery only to WPA enabled BSS"""
  1039. ssid = "test-ft"
  1040. passphrase="12345678"
  1041. radius = hostapd.radius_params()
  1042. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1043. params['wpa_key_mgmt'] = "FT-EAP"
  1044. params["ieee8021x"] = "1"
  1045. params = dict(radius.items() + params.items())
  1046. hapd = hostapd.add_ap(apdev[0], params)
  1047. key_mgmt = hapd.get_config()['key_mgmt']
  1048. if key_mgmt.split(' ')[0] != "FT-EAP":
  1049. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  1050. hapd1 = hostapd.add_ap(apdev[1], { "ssid" : ssid })
  1051. # Connect to WPA enabled AP
  1052. dev[0].connect(ssid, key_mgmt="FT-EAP", proto="WPA2", ieee80211w="1",
  1053. eap="GPSK", identity="gpsk user",
  1054. password="abcdefghijklmnop0123456789abcdef",
  1055. scan_freq="2412")
  1056. # Try over_ds roaming to non-WPA-enabled AP.
  1057. # If hostapd does not check hapd->wpa_auth internally, it will crash now.
  1058. dev[0].roam_over_ds(apdev[1]['bssid'], fail_test=True)
  1059. def test_ap_ft_extra_ie(dev, apdev):
  1060. """WPA2-PSK-FT AP with WPA2-PSK enabled and unexpected MDE"""
  1061. ssid = "test-ft"
  1062. passphrase="12345678"
  1063. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1064. params["wpa_key_mgmt"] = "WPA-PSK FT-PSK"
  1065. hapd0 = hostapd.add_ap(apdev[0], params)
  1066. dev[1].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1067. scan_freq="2412")
  1068. dev[2].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK", proto="WPA2",
  1069. scan_freq="2412")
  1070. try:
  1071. # Add Mobility Domain element to test AP validation code.
  1072. dev[0].request("VENDOR_ELEM_ADD 13 3603a1b201")
  1073. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK", proto="WPA2",
  1074. scan_freq="2412", wait_connect=False)
  1075. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1076. "CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  1077. if ev is None:
  1078. raise Exception("No connection result")
  1079. if "CTRL-EVENT-CONNECTED" in ev:
  1080. raise Exception("Non-FT association accepted with MDE")
  1081. if "status_code=43" not in ev:
  1082. raise Exception("Unexpected status code: " + ev)
  1083. dev[0].request("DISCONNECT")
  1084. finally:
  1085. dev[0].request("VENDOR_ELEM_REMOVE 13 *")