test_ap_ft.py 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  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, wait_fail_trigger, 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. test_connectivity=True):
  92. logger.info("Connect to first AP")
  93. if eap:
  94. dev.connect(ssid, key_mgmt="FT-EAP", proto="WPA2", ieee80211w="1",
  95. eap="GPSK", identity="gpsk user",
  96. password="abcdefghijklmnop0123456789abcdef",
  97. scan_freq="2412",
  98. pairwise=pairwise_cipher, group=group_cipher,
  99. wpa_ptk_rekey=ptk_rekey)
  100. else:
  101. if sae:
  102. key_mgmt="FT-SAE"
  103. else:
  104. key_mgmt="FT-PSK"
  105. dev.connect(ssid, psk=passphrase, key_mgmt=key_mgmt, proto="WPA2",
  106. ieee80211w="1", scan_freq="2412",
  107. pairwise=pairwise_cipher, group=group_cipher,
  108. wpa_ptk_rekey=ptk_rekey)
  109. if dev.get_status_field('bssid') == apdev[0]['bssid']:
  110. ap1 = apdev[0]
  111. ap2 = apdev[1]
  112. hapd1ap = hapd0
  113. hapd2ap = hapd1
  114. else:
  115. ap1 = apdev[1]
  116. ap2 = apdev[0]
  117. hapd1ap = hapd1
  118. hapd2ap = hapd0
  119. if test_connectivity:
  120. hwsim_utils.test_connectivity(dev, hapd1ap)
  121. dev.scan_for_bss(ap2['bssid'], freq="2412")
  122. for i in range(0, roams):
  123. logger.info("Roam to the second AP")
  124. if over_ds:
  125. dev.roam_over_ds(ap2['bssid'], fail_test=fail_test)
  126. else:
  127. dev.roam(ap2['bssid'], fail_test=fail_test)
  128. if fail_test:
  129. return
  130. if dev.get_status_field('bssid') != ap2['bssid']:
  131. raise Exception("Did not connect to correct AP")
  132. if (i == 0 or i == roams - 1) and test_connectivity:
  133. hwsim_utils.test_connectivity(dev, hapd2ap)
  134. logger.info("Roam back to the first AP")
  135. if over_ds:
  136. dev.roam_over_ds(ap1['bssid'])
  137. else:
  138. dev.roam(ap1['bssid'])
  139. if dev.get_status_field('bssid') != ap1['bssid']:
  140. raise Exception("Did not connect to correct AP")
  141. if (i == 0 or i == roams - 1) and test_connectivity:
  142. hwsim_utils.test_connectivity(dev, hapd1ap)
  143. def test_ap_ft(dev, apdev):
  144. """WPA2-PSK-FT AP"""
  145. ssid = "test-ft"
  146. passphrase="12345678"
  147. params = ft_params1(ssid=ssid, passphrase=passphrase)
  148. hapd0 = hostapd.add_ap(apdev[0], params)
  149. params = ft_params2(ssid=ssid, passphrase=passphrase)
  150. hapd1 = hostapd.add_ap(apdev[1], params)
  151. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  152. if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  153. raise Exception("Scan results missing RSN element info")
  154. def test_ap_ft_local_key_gen(dev, apdev):
  155. """WPA2-PSK-FT AP with local key generation (without pull/push)"""
  156. ssid = "test-ft"
  157. passphrase="12345678"
  158. params = ft_params1a(ssid=ssid, passphrase=passphrase)
  159. params['ft_psk_generate_local'] = "1";
  160. del params['pmk_r1_push']
  161. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  162. params = ft_params2a(ssid=ssid, passphrase=passphrase)
  163. params['ft_psk_generate_local'] = "1";
  164. del params['pmk_r1_push']
  165. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  166. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  167. if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  168. raise Exception("Scan results missing RSN element info")
  169. def test_ap_ft_many(dev, apdev):
  170. """WPA2-PSK-FT AP multiple times"""
  171. ssid = "test-ft"
  172. passphrase="12345678"
  173. params = ft_params1(ssid=ssid, passphrase=passphrase)
  174. hapd0 = hostapd.add_ap(apdev[0], params)
  175. params = ft_params2(ssid=ssid, passphrase=passphrase)
  176. hapd1 = hostapd.add_ap(apdev[1], params)
  177. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, roams=50)
  178. def test_ap_ft_mixed(dev, apdev):
  179. """WPA2-PSK-FT mixed-mode AP"""
  180. ssid = "test-ft-mixed"
  181. passphrase="12345678"
  182. params = ft_params1(rsn=False, ssid=ssid, passphrase=passphrase)
  183. hapd = hostapd.add_ap(apdev[0], params)
  184. key_mgmt = hapd.get_config()['key_mgmt']
  185. vals = key_mgmt.split(' ')
  186. if vals[0] != "WPA-PSK" or vals[1] != "FT-PSK":
  187. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  188. params = ft_params2(rsn=False, ssid=ssid, passphrase=passphrase)
  189. hapd1 = hostapd.add_ap(apdev[1], params)
  190. run_roams(dev[0], apdev, hapd, hapd1, ssid, passphrase)
  191. def test_ap_ft_pmf(dev, apdev):
  192. """WPA2-PSK-FT AP with PMF"""
  193. ssid = "test-ft"
  194. passphrase="12345678"
  195. params = ft_params1(ssid=ssid, passphrase=passphrase)
  196. params["ieee80211w"] = "2"
  197. hapd0 = hostapd.add_ap(apdev[0], params)
  198. params = ft_params2(ssid=ssid, passphrase=passphrase)
  199. params["ieee80211w"] = "2"
  200. hapd1 = hostapd.add_ap(apdev[1], params)
  201. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  202. def test_ap_ft_over_ds(dev, apdev):
  203. """WPA2-PSK-FT AP over DS"""
  204. ssid = "test-ft"
  205. passphrase="12345678"
  206. params = ft_params1(ssid=ssid, passphrase=passphrase)
  207. hapd0 = hostapd.add_ap(apdev[0], params)
  208. params = ft_params2(ssid=ssid, passphrase=passphrase)
  209. hapd1 = hostapd.add_ap(apdev[1], params)
  210. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True)
  211. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-4"),
  212. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-4") ])
  213. def test_ap_ft_over_ds_disabled(dev, apdev):
  214. """WPA2-PSK-FT AP over DS disabled"""
  215. ssid = "test-ft"
  216. passphrase="12345678"
  217. params = ft_params1(ssid=ssid, passphrase=passphrase)
  218. params['ft_over_ds'] = '0'
  219. hapd0 = hostapd.add_ap(apdev[0], params)
  220. params = ft_params2(ssid=ssid, passphrase=passphrase)
  221. params['ft_over_ds'] = '0'
  222. hapd1 = hostapd.add_ap(apdev[1], params)
  223. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  224. fail_test=True)
  225. def test_ap_ft_over_ds_many(dev, apdev):
  226. """WPA2-PSK-FT AP over DS multiple times"""
  227. ssid = "test-ft"
  228. passphrase="12345678"
  229. params = ft_params1(ssid=ssid, passphrase=passphrase)
  230. hapd0 = hostapd.add_ap(apdev[0], params)
  231. params = ft_params2(ssid=ssid, passphrase=passphrase)
  232. hapd1 = hostapd.add_ap(apdev[1], params)
  233. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  234. roams=50)
  235. @remote_compatible
  236. def test_ap_ft_over_ds_unknown_target(dev, apdev):
  237. """WPA2-PSK-FT AP"""
  238. ssid = "test-ft"
  239. passphrase="12345678"
  240. params = ft_params1(ssid=ssid, passphrase=passphrase)
  241. hapd0 = hostapd.add_ap(apdev[0], params)
  242. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  243. scan_freq="2412")
  244. dev[0].roam_over_ds("02:11:22:33:44:55", fail_test=True)
  245. @remote_compatible
  246. def test_ap_ft_over_ds_unexpected(dev, apdev):
  247. """WPA2-PSK-FT AP over DS and unexpected response"""
  248. ssid = "test-ft"
  249. passphrase="12345678"
  250. params = ft_params1(ssid=ssid, passphrase=passphrase)
  251. hapd0 = hostapd.add_ap(apdev[0], params)
  252. params = ft_params2(ssid=ssid, passphrase=passphrase)
  253. hapd1 = hostapd.add_ap(apdev[1], params)
  254. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  255. scan_freq="2412")
  256. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  257. ap1 = apdev[0]
  258. ap2 = apdev[1]
  259. hapd1ap = hapd0
  260. hapd2ap = hapd1
  261. else:
  262. ap1 = apdev[1]
  263. ap2 = apdev[0]
  264. hapd1ap = hapd1
  265. hapd2ap = hapd0
  266. addr = dev[0].own_addr()
  267. hapd1ap.set("ext_mgmt_frame_handling", "1")
  268. logger.info("Foreign STA address")
  269. msg = {}
  270. msg['fc'] = 13 << 4
  271. msg['da'] = addr
  272. msg['sa'] = ap1['bssid']
  273. msg['bssid'] = ap1['bssid']
  274. msg['payload'] = binascii.unhexlify("06021122334455660102030405060000")
  275. hapd1ap.mgmt_tx(msg)
  276. logger.info("No over-the-DS in progress")
  277. msg['payload'] = binascii.unhexlify("0602" + addr.replace(':', '') + "0102030405060000")
  278. hapd1ap.mgmt_tx(msg)
  279. logger.info("Non-zero status code")
  280. msg['payload'] = binascii.unhexlify("0602" + addr.replace(':', '') + "0102030405060100")
  281. hapd1ap.mgmt_tx(msg)
  282. hapd1ap.dump_monitor()
  283. dev[0].scan_for_bss(ap2['bssid'], freq="2412")
  284. if "OK" not in dev[0].request("FT_DS " + ap2['bssid']):
  285. raise Exception("FT_DS failed")
  286. req = hapd1ap.mgmt_rx()
  287. logger.info("Foreign Target AP")
  288. msg['payload'] = binascii.unhexlify("0602" + addr.replace(':', '') + "0102030405060000")
  289. hapd1ap.mgmt_tx(msg)
  290. addrs = addr.replace(':', '') + ap2['bssid'].replace(':', '')
  291. logger.info("No IEs")
  292. msg['payload'] = binascii.unhexlify("0602" + addrs + "0000")
  293. hapd1ap.mgmt_tx(msg)
  294. logger.info("Invalid IEs (trigger parsing failure)")
  295. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003700")
  296. hapd1ap.mgmt_tx(msg)
  297. logger.info("Too short MDIE")
  298. msg['payload'] = binascii.unhexlify("0602" + addrs + "000036021122")
  299. hapd1ap.mgmt_tx(msg)
  300. logger.info("Mobility domain mismatch")
  301. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603112201")
  302. hapd1ap.mgmt_tx(msg)
  303. logger.info("No FTIE")
  304. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201")
  305. hapd1ap.mgmt_tx(msg)
  306. logger.info("FTIE SNonce mismatch")
  307. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201375e0000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "1000000000000000000000000000000000000000000000000000000000000001" + "030a6e6173322e77312e6669")
  308. hapd1ap.mgmt_tx(msg)
  309. logger.info("No R0KH-ID subelem in FTIE")
  310. snonce = binascii.hexlify(req['payload'][111:111+32])
  311. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b20137520000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce)
  312. hapd1ap.mgmt_tx(msg)
  313. logger.info("No R0KH-ID subelem mismatch in FTIE")
  314. snonce = binascii.hexlify(req['payload'][111:111+32])
  315. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201375e0000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce + "030a11223344556677889900")
  316. hapd1ap.mgmt_tx(msg)
  317. logger.info("No R1KH-ID subelem in FTIE")
  318. r0khid = binascii.hexlify(req['payload'][145:145+10])
  319. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b201375e0000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce + "030a" + r0khid)
  320. hapd1ap.mgmt_tx(msg)
  321. logger.info("No RSNE")
  322. r0khid = binascii.hexlify(req['payload'][145:145+10])
  323. msg['payload'] = binascii.unhexlify("0602" + addrs + "00003603a1b20137660000" + "00000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + snonce + "030a" + r0khid + "0106000102030405")
  324. hapd1ap.mgmt_tx(msg)
  325. def test_ap_ft_pmf_over_ds(dev, apdev):
  326. """WPA2-PSK-FT AP over DS with PMF"""
  327. ssid = "test-ft"
  328. passphrase="12345678"
  329. params = ft_params1(ssid=ssid, passphrase=passphrase)
  330. params["ieee80211w"] = "2"
  331. hapd0 = hostapd.add_ap(apdev[0], params)
  332. params = ft_params2(ssid=ssid, passphrase=passphrase)
  333. params["ieee80211w"] = "2"
  334. hapd1 = hostapd.add_ap(apdev[1], params)
  335. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True)
  336. def test_ap_ft_over_ds_pull(dev, apdev):
  337. """WPA2-PSK-FT AP over DS (pull PMK)"""
  338. ssid = "test-ft"
  339. passphrase="12345678"
  340. params = ft_params1(ssid=ssid, passphrase=passphrase)
  341. params["pmk_r1_push"] = "0"
  342. hapd0 = hostapd.add_ap(apdev[0], params)
  343. params = ft_params2(ssid=ssid, passphrase=passphrase)
  344. params["pmk_r1_push"] = "0"
  345. hapd1 = hostapd.add_ap(apdev[1], params)
  346. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True)
  347. def test_ap_ft_sae(dev, apdev):
  348. """WPA2-PSK-FT-SAE AP"""
  349. if "SAE" not in dev[0].get_capability("auth_alg"):
  350. raise HwsimSkip("SAE not supported")
  351. ssid = "test-ft"
  352. passphrase="12345678"
  353. params = ft_params1(ssid=ssid, passphrase=passphrase)
  354. params['wpa_key_mgmt'] = "FT-SAE"
  355. hapd0 = hostapd.add_ap(apdev[0], params)
  356. params = ft_params2(ssid=ssid, passphrase=passphrase)
  357. params['wpa_key_mgmt'] = "FT-SAE"
  358. hapd = hostapd.add_ap(apdev[1], params)
  359. key_mgmt = hapd.get_config()['key_mgmt']
  360. if key_mgmt.split(' ')[0] != "FT-SAE":
  361. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  362. dev[0].request("SET sae_groups ")
  363. run_roams(dev[0], apdev, hapd0, hapd, ssid, passphrase, sae=True)
  364. def test_ap_ft_sae_over_ds(dev, apdev):
  365. """WPA2-PSK-FT-SAE AP over DS"""
  366. if "SAE" not in dev[0].get_capability("auth_alg"):
  367. raise HwsimSkip("SAE not supported")
  368. ssid = "test-ft"
  369. passphrase="12345678"
  370. params = ft_params1(ssid=ssid, passphrase=passphrase)
  371. params['wpa_key_mgmt'] = "FT-SAE"
  372. hapd0 = hostapd.add_ap(apdev[0], params)
  373. params = ft_params2(ssid=ssid, passphrase=passphrase)
  374. params['wpa_key_mgmt'] = "FT-SAE"
  375. hapd1 = hostapd.add_ap(apdev[1], params)
  376. dev[0].request("SET sae_groups ")
  377. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, sae=True,
  378. over_ds=True)
  379. def test_ap_ft_eap(dev, apdev):
  380. """WPA2-EAP-FT AP"""
  381. ssid = "test-ft"
  382. passphrase="12345678"
  383. radius = hostapd.radius_params()
  384. params = ft_params1(ssid=ssid, passphrase=passphrase)
  385. params['wpa_key_mgmt'] = "FT-EAP"
  386. params["ieee8021x"] = "1"
  387. params = dict(radius.items() + params.items())
  388. hapd = hostapd.add_ap(apdev[0], params)
  389. key_mgmt = hapd.get_config()['key_mgmt']
  390. if key_mgmt.split(' ')[0] != "FT-EAP":
  391. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  392. params = ft_params2(ssid=ssid, passphrase=passphrase)
  393. params['wpa_key_mgmt'] = "FT-EAP"
  394. params["ieee8021x"] = "1"
  395. params = dict(radius.items() + params.items())
  396. hapd1 = hostapd.add_ap(apdev[1], params)
  397. run_roams(dev[0], apdev, hapd, hapd1, ssid, passphrase, eap=True)
  398. if "[WPA2-FT/EAP-CCMP]" not in dev[0].request("SCAN_RESULTS"):
  399. raise Exception("Scan results missing RSN element info")
  400. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-3"),
  401. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-3") ])
  402. # Verify EAPOL reauthentication after FT protocol
  403. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  404. ap = hapd
  405. else:
  406. ap = hapd1
  407. ap.request("EAPOL_REAUTH " + dev[0].own_addr())
  408. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  409. if ev is None:
  410. raise Exception("EAP authentication did not start")
  411. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  412. if ev is None:
  413. raise Exception("EAP authentication did not succeed")
  414. time.sleep(0.1)
  415. hwsim_utils.test_connectivity(dev[0], ap)
  416. def test_ap_ft_eap_pull(dev, apdev):
  417. """WPA2-EAP-FT AP (pull PMK)"""
  418. ssid = "test-ft"
  419. passphrase="12345678"
  420. radius = hostapd.radius_params()
  421. params = ft_params1(ssid=ssid, passphrase=passphrase)
  422. params['wpa_key_mgmt'] = "FT-EAP"
  423. params["ieee8021x"] = "1"
  424. params["pmk_r1_push"] = "0"
  425. params = dict(radius.items() + params.items())
  426. hapd = hostapd.add_ap(apdev[0], params)
  427. key_mgmt = hapd.get_config()['key_mgmt']
  428. if key_mgmt.split(' ')[0] != "FT-EAP":
  429. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  430. params = ft_params2(ssid=ssid, passphrase=passphrase)
  431. params['wpa_key_mgmt'] = "FT-EAP"
  432. params["ieee8021x"] = "1"
  433. params["pmk_r1_push"] = "0"
  434. params = dict(radius.items() + params.items())
  435. hapd1 = hostapd.add_ap(apdev[1], params)
  436. run_roams(dev[0], apdev, hapd, hapd1, ssid, passphrase, eap=True)
  437. @remote_compatible
  438. def test_ap_ft_mismatching_rrb_key_push(dev, apdev):
  439. """WPA2-PSK-FT AP over DS with mismatching RRB key (push)"""
  440. ssid = "test-ft"
  441. passphrase="12345678"
  442. params = ft_params1(ssid=ssid, passphrase=passphrase)
  443. params["ieee80211w"] = "2"
  444. hapd0 = hostapd.add_ap(apdev[0], params)
  445. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  446. params["ieee80211w"] = "2"
  447. hapd1 = hostapd.add_ap(apdev[1], params)
  448. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  449. fail_test=True)
  450. @remote_compatible
  451. def test_ap_ft_mismatching_rrb_key_pull(dev, apdev):
  452. """WPA2-PSK-FT AP over DS with mismatching RRB key (pull)"""
  453. ssid = "test-ft"
  454. passphrase="12345678"
  455. params = ft_params1(ssid=ssid, passphrase=passphrase)
  456. params["pmk_r1_push"] = "0"
  457. hapd0 = hostapd.add_ap(apdev[0], params)
  458. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  459. params["pmk_r1_push"] = "0"
  460. hapd1 = hostapd.add_ap(apdev[1], params)
  461. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  462. fail_test=True)
  463. @remote_compatible
  464. def test_ap_ft_mismatching_r0kh_id_pull(dev, apdev):
  465. """WPA2-PSK-FT AP over DS with mismatching R0KH-ID (pull)"""
  466. ssid = "test-ft"
  467. passphrase="12345678"
  468. params = ft_params1(ssid=ssid, passphrase=passphrase)
  469. params["pmk_r1_push"] = "0"
  470. params["nas_identifier"] = "nas0.w1.fi"
  471. hostapd.add_ap(apdev[0], params)
  472. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  473. scan_freq="2412")
  474. params = ft_params2(ssid=ssid, passphrase=passphrase)
  475. params["pmk_r1_push"] = "0"
  476. hostapd.add_ap(apdev[1], params)
  477. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  478. dev[0].roam_over_ds(apdev[1]['bssid'], fail_test=True)
  479. @remote_compatible
  480. def test_ap_ft_mismatching_rrb_r0kh_push(dev, apdev):
  481. """WPA2-PSK-FT AP over DS with mismatching R0KH key (push)"""
  482. ssid = "test-ft"
  483. passphrase="12345678"
  484. params = ft_params1(ssid=ssid, passphrase=passphrase)
  485. params["ieee80211w"] = "2"
  486. hapd0 = hostapd.add_ap(apdev[0], params)
  487. params = ft_params2_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  488. params["ieee80211w"] = "2"
  489. hapd1 = hostapd.add_ap(apdev[1], params)
  490. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  491. fail_test=True)
  492. @remote_compatible
  493. def test_ap_ft_mismatching_rrb_r0kh_pull(dev, apdev):
  494. """WPA2-PSK-FT AP over DS with mismatching R0KH key (pull)"""
  495. ssid = "test-ft"
  496. passphrase="12345678"
  497. params = ft_params1_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  498. params["pmk_r1_push"] = "0"
  499. hapd0 = hostapd.add_ap(apdev[0], params)
  500. params = ft_params2(ssid=ssid, passphrase=passphrase)
  501. params["pmk_r1_push"] = "0"
  502. hapd1 = hostapd.add_ap(apdev[1], params)
  503. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  504. fail_test=True)
  505. def test_ap_ft_mismatching_rrb_key_push_eap(dev, apdev):
  506. """WPA2-EAP-FT AP over DS with mismatching RRB key (push)"""
  507. ssid = "test-ft"
  508. passphrase="12345678"
  509. radius = hostapd.radius_params()
  510. params = ft_params1(ssid=ssid, passphrase=passphrase)
  511. params["ieee80211w"] = "2";
  512. params['wpa_key_mgmt'] = "FT-EAP"
  513. params["ieee8021x"] = "1"
  514. params = dict(radius.items() + params.items())
  515. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  516. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  517. params["ieee80211w"] = "2";
  518. params['wpa_key_mgmt'] = "FT-EAP"
  519. params["ieee8021x"] = "1"
  520. params = dict(radius.items() + params.items())
  521. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  522. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  523. fail_test=True, eap=True)
  524. def test_ap_ft_mismatching_rrb_key_pull_eap(dev, apdev):
  525. """WPA2-EAP-FT AP over DS with mismatching RRB key (pull)"""
  526. ssid = "test-ft"
  527. passphrase="12345678"
  528. radius = hostapd.radius_params()
  529. params = ft_params1(ssid=ssid, passphrase=passphrase)
  530. params["pmk_r1_push"] = "0"
  531. params['wpa_key_mgmt'] = "FT-EAP"
  532. params["ieee8021x"] = "1"
  533. params = dict(radius.items() + params.items())
  534. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  535. params = ft_params2_incorrect_rrb_key(ssid=ssid, passphrase=passphrase)
  536. params["pmk_r1_push"] = "0"
  537. params['wpa_key_mgmt'] = "FT-EAP"
  538. params["ieee8021x"] = "1"
  539. params = dict(radius.items() + params.items())
  540. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  541. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  542. fail_test=True, eap=True)
  543. def test_ap_ft_mismatching_r0kh_id_pull_eap(dev, apdev):
  544. """WPA2-EAP-FT AP over DS with mismatching R0KH-ID (pull)"""
  545. ssid = "test-ft"
  546. passphrase="12345678"
  547. radius = hostapd.radius_params()
  548. params = ft_params1(ssid=ssid, passphrase=passphrase)
  549. params["pmk_r1_push"] = "0"
  550. params["nas_identifier"] = "nas0.w1.fi"
  551. params['wpa_key_mgmt'] = "FT-EAP"
  552. params["ieee8021x"] = "1"
  553. params = dict(radius.items() + params.items())
  554. hostapd.add_ap(apdev[0]['ifname'], params)
  555. dev[0].connect(ssid, key_mgmt="FT-EAP", proto="WPA2", ieee80211w="1",
  556. eap="GPSK", identity="gpsk user",
  557. password="abcdefghijklmnop0123456789abcdef",
  558. scan_freq="2412")
  559. params = ft_params2(ssid=ssid, passphrase=passphrase)
  560. params["pmk_r1_push"] = "0"
  561. params['wpa_key_mgmt'] = "FT-EAP"
  562. params["ieee8021x"] = "1"
  563. params = dict(radius.items() + params.items())
  564. hostapd.add_ap(apdev[1]['ifname'], params)
  565. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  566. dev[0].roam_over_ds(apdev[1]['bssid'], fail_test=True)
  567. def test_ap_ft_mismatching_rrb_r0kh_push_eap(dev, apdev):
  568. """WPA2-EAP-FT AP over DS with mismatching R0KH key (push)"""
  569. ssid = "test-ft"
  570. passphrase="12345678"
  571. radius = hostapd.radius_params()
  572. params = ft_params1(ssid=ssid, passphrase=passphrase)
  573. params["ieee80211w"] = "2";
  574. params['wpa_key_mgmt'] = "FT-EAP"
  575. params["ieee8021x"] = "1"
  576. params = dict(radius.items() + params.items())
  577. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  578. params = ft_params2_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  579. params["ieee80211w"] = "2";
  580. params['wpa_key_mgmt'] = "FT-EAP"
  581. params["ieee8021x"] = "1"
  582. params = dict(radius.items() + params.items())
  583. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  584. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  585. fail_test=True, eap=True)
  586. def test_ap_ft_mismatching_rrb_r0kh_pull_eap(dev, apdev):
  587. """WPA2-EAP-FT AP over DS with mismatching R0KH key (pull)"""
  588. ssid = "test-ft"
  589. passphrase="12345678"
  590. radius = hostapd.radius_params()
  591. params = ft_params1_r0kh_mismatch(ssid=ssid, passphrase=passphrase)
  592. params["pmk_r1_push"] = "0"
  593. params['wpa_key_mgmt'] = "FT-EAP"
  594. params["ieee8021x"] = "1"
  595. params = dict(radius.items() + params.items())
  596. hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
  597. params = ft_params2(ssid=ssid, passphrase=passphrase)
  598. params["pmk_r1_push"] = "0"
  599. params['wpa_key_mgmt'] = "FT-EAP"
  600. params["ieee8021x"] = "1"
  601. params = dict(radius.items() + params.items())
  602. hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
  603. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
  604. fail_test=True, eap=True)
  605. def test_ap_ft_gtk_rekey(dev, apdev):
  606. """WPA2-PSK-FT AP and GTK rekey"""
  607. ssid = "test-ft"
  608. passphrase="12345678"
  609. params = ft_params1(ssid=ssid, passphrase=passphrase)
  610. params['wpa_group_rekey'] = '1'
  611. hapd = hostapd.add_ap(apdev[0], params)
  612. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  613. ieee80211w="1", scan_freq="2412")
  614. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  615. if ev is None:
  616. raise Exception("GTK rekey timed out after initial association")
  617. hwsim_utils.test_connectivity(dev[0], hapd)
  618. params = ft_params2(ssid=ssid, passphrase=passphrase)
  619. params['wpa_group_rekey'] = '1'
  620. hapd1 = hostapd.add_ap(apdev[1], params)
  621. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  622. dev[0].roam(apdev[1]['bssid'])
  623. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  624. raise Exception("Did not connect to correct AP")
  625. hwsim_utils.test_connectivity(dev[0], hapd1)
  626. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  627. if ev is None:
  628. raise Exception("GTK rekey timed out after FT protocol")
  629. hwsim_utils.test_connectivity(dev[0], hapd1)
  630. def test_ft_psk_key_lifetime_in_memory(dev, apdev, params):
  631. """WPA2-PSK-FT and key lifetime in memory"""
  632. ssid = "test-ft"
  633. passphrase="04c2726b4b8d5f1b4db9c07aa4d9e9d8f765cb5d25ec817e6cc4fcdd5255db0"
  634. psk = '93c90846ff67af9037ed83fb72b63dbeddaa81d47f926c20909b5886f1d9358d'
  635. pmk = binascii.unhexlify(psk)
  636. p = ft_params1(ssid=ssid, passphrase=passphrase)
  637. hapd0 = hostapd.add_ap(apdev[0], p)
  638. p = ft_params2(ssid=ssid, passphrase=passphrase)
  639. hapd1 = hostapd.add_ap(apdev[1], p)
  640. pid = find_wpas_process(dev[0])
  641. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  642. scan_freq="2412")
  643. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  644. # event has been delivered, so verify that wpa_supplicant has returned to
  645. # eloop before reading process memory.
  646. time.sleep(1)
  647. dev[0].ping()
  648. buf = read_process_memory(pid, pmk)
  649. dev[0].request("DISCONNECT")
  650. dev[0].wait_disconnected()
  651. dev[0].relog()
  652. pmkr0 = None
  653. pmkr1 = None
  654. ptk = None
  655. gtk = None
  656. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  657. for l in f.readlines():
  658. if "FT: PMK-R0 - hexdump" in l:
  659. val = l.strip().split(':')[3].replace(' ', '')
  660. pmkr0 = binascii.unhexlify(val)
  661. if "FT: PMK-R1 - hexdump" in l:
  662. val = l.strip().split(':')[3].replace(' ', '')
  663. pmkr1 = binascii.unhexlify(val)
  664. if "FT: KCK - hexdump" in l:
  665. val = l.strip().split(':')[3].replace(' ', '')
  666. kck = binascii.unhexlify(val)
  667. if "FT: KEK - hexdump" in l:
  668. val = l.strip().split(':')[3].replace(' ', '')
  669. kek = binascii.unhexlify(val)
  670. if "FT: TK - hexdump" in l:
  671. val = l.strip().split(':')[3].replace(' ', '')
  672. tk = binascii.unhexlify(val)
  673. if "WPA: Group Key - hexdump" in l:
  674. val = l.strip().split(':')[3].replace(' ', '')
  675. gtk = binascii.unhexlify(val)
  676. if not pmkr0 or not pmkr1 or not kck or not kek or not tk or not gtk:
  677. raise Exception("Could not find keys from debug log")
  678. if len(gtk) != 16:
  679. raise Exception("Unexpected GTK length")
  680. logger.info("Checking keys in memory while associated")
  681. get_key_locations(buf, pmk, "PMK")
  682. get_key_locations(buf, pmkr0, "PMK-R0")
  683. get_key_locations(buf, pmkr1, "PMK-R1")
  684. if pmk not in buf:
  685. raise HwsimSkip("PMK not found while associated")
  686. if pmkr0 not in buf:
  687. raise HwsimSkip("PMK-R0 not found while associated")
  688. if pmkr1 not in buf:
  689. raise HwsimSkip("PMK-R1 not found while associated")
  690. if kck not in buf:
  691. raise Exception("KCK not found while associated")
  692. if kek not in buf:
  693. raise Exception("KEK not found while associated")
  694. if tk in buf:
  695. raise Exception("TK found from memory")
  696. if gtk in buf:
  697. get_key_locations(buf, gtk, "GTK")
  698. raise Exception("GTK found from memory")
  699. logger.info("Checking keys in memory after disassociation")
  700. buf = read_process_memory(pid, pmk)
  701. get_key_locations(buf, pmk, "PMK")
  702. get_key_locations(buf, pmkr0, "PMK-R0")
  703. get_key_locations(buf, pmkr1, "PMK-R1")
  704. # Note: PMK/PSK is still present in network configuration
  705. fname = os.path.join(params['logdir'],
  706. 'ft_psk_key_lifetime_in_memory.memctx-')
  707. verify_not_present(buf, pmkr0, fname, "PMK-R0")
  708. verify_not_present(buf, pmkr1, fname, "PMK-R1")
  709. verify_not_present(buf, kck, fname, "KCK")
  710. verify_not_present(buf, kek, fname, "KEK")
  711. verify_not_present(buf, tk, fname, "TK")
  712. verify_not_present(buf, gtk, fname, "GTK")
  713. dev[0].request("REMOVE_NETWORK all")
  714. logger.info("Checking keys in memory after network profile removal")
  715. buf = read_process_memory(pid, pmk)
  716. get_key_locations(buf, pmk, "PMK")
  717. get_key_locations(buf, pmkr0, "PMK-R0")
  718. get_key_locations(buf, pmkr1, "PMK-R1")
  719. verify_not_present(buf, pmk, fname, "PMK")
  720. verify_not_present(buf, pmkr0, fname, "PMK-R0")
  721. verify_not_present(buf, pmkr1, fname, "PMK-R1")
  722. verify_not_present(buf, kck, fname, "KCK")
  723. verify_not_present(buf, kek, fname, "KEK")
  724. verify_not_present(buf, tk, fname, "TK")
  725. verify_not_present(buf, gtk, fname, "GTK")
  726. @remote_compatible
  727. def test_ap_ft_invalid_resp(dev, apdev):
  728. """WPA2-PSK-FT AP and invalid response IEs"""
  729. ssid = "test-ft"
  730. passphrase="12345678"
  731. params = ft_params1(ssid=ssid, passphrase=passphrase)
  732. hapd0 = hostapd.add_ap(apdev[0], params)
  733. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  734. scan_freq="2412")
  735. params = ft_params2(ssid=ssid, passphrase=passphrase)
  736. hapd1 = hostapd.add_ap(apdev[1], params)
  737. tests = [
  738. # Various IEs for test coverage. The last one is FTIE with invalid
  739. # R1KH-ID subelement.
  740. "020002000000" + "3800" + "38051122334455" + "3754000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010100",
  741. # FTIE with invalid R0KH-ID subelement (len=0).
  742. "020002000000" + "3754000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010300",
  743. # FTIE with invalid R0KH-ID subelement (len=49).
  744. "020002000000" + "378500010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001033101020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849",
  745. # Invalid RSNE.
  746. "020002000000" + "3000",
  747. # Required IEs missing from protected IE count.
  748. "020002000000" + "3603a1b201" + "375200010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001" + "3900",
  749. # RIC missing from protected IE count.
  750. "020002000000" + "3603a1b201" + "375200020203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001" + "3900",
  751. # Protected IE missing.
  752. "020002000000" + "3603a1b201" + "375200ff0203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001" + "3900" + "0000" ]
  753. for t in tests:
  754. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  755. hapd1.set("ext_mgmt_frame_handling", "1")
  756. hapd1.dump_monitor()
  757. if "OK" not in dev[0].request("ROAM " + apdev[1]['bssid']):
  758. raise Exception("ROAM failed")
  759. auth = None
  760. for i in range(20):
  761. msg = hapd1.mgmt_rx()
  762. if msg['subtype'] == 11:
  763. auth = msg
  764. break
  765. if not auth:
  766. raise Exception("Authentication frame not seen")
  767. resp = {}
  768. resp['fc'] = auth['fc']
  769. resp['da'] = auth['sa']
  770. resp['sa'] = auth['da']
  771. resp['bssid'] = auth['bssid']
  772. resp['payload'] = binascii.unhexlify(t)
  773. hapd1.mgmt_tx(resp)
  774. hapd1.set("ext_mgmt_frame_handling", "0")
  775. dev[0].wait_disconnected()
  776. dev[0].request("RECONNECT")
  777. dev[0].wait_connected()
  778. def test_ap_ft_gcmp_256(dev, apdev):
  779. """WPA2-PSK-FT AP with GCMP-256 cipher"""
  780. if "GCMP-256" not in dev[0].get_capability("pairwise"):
  781. raise HwsimSkip("Cipher GCMP-256 not supported")
  782. ssid = "test-ft"
  783. passphrase="12345678"
  784. params = ft_params1(ssid=ssid, passphrase=passphrase)
  785. params['rsn_pairwise'] = "GCMP-256"
  786. hapd0 = hostapd.add_ap(apdev[0], params)
  787. params = ft_params2(ssid=ssid, passphrase=passphrase)
  788. params['rsn_pairwise'] = "GCMP-256"
  789. hapd1 = hostapd.add_ap(apdev[1], params)
  790. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase,
  791. pairwise_cipher="GCMP-256", group_cipher="GCMP-256")
  792. def test_ap_ft_oom(dev, apdev):
  793. """WPA2-PSK-FT and OOM"""
  794. skip_with_fips(dev[0])
  795. ssid = "test-ft"
  796. passphrase="12345678"
  797. params = ft_params1(ssid=ssid, passphrase=passphrase)
  798. hapd0 = hostapd.add_ap(apdev[0], params)
  799. params = ft_params2(ssid=ssid, passphrase=passphrase)
  800. hapd1 = hostapd.add_ap(apdev[1], params)
  801. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  802. scan_freq="2412")
  803. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  804. dst = apdev[1]['bssid']
  805. else:
  806. dst = apdev[0]['bssid']
  807. dev[0].scan_for_bss(dst, freq="2412")
  808. with alloc_fail(dev[0], 1, "wpa_ft_gen_req_ies"):
  809. dev[0].roam(dst)
  810. with fail_test(dev[0], 1, "wpa_ft_mic"):
  811. dev[0].roam(dst, fail_test=True)
  812. with fail_test(dev[0], 1, "os_get_random;wpa_ft_prepare_auth_request"):
  813. dev[0].roam(dst, fail_test=True)
  814. dev[0].request("REMOVE_NETWORK all")
  815. with alloc_fail(dev[0], 1, "=sme_update_ft_ies"):
  816. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  817. scan_freq="2412")
  818. def test_ap_ft_ap_oom(dev, apdev):
  819. """WPA2-PSK-FT and AP OOM"""
  820. ssid = "test-ft"
  821. passphrase="12345678"
  822. params = ft_params1(ssid=ssid, passphrase=passphrase)
  823. hapd0 = hostapd.add_ap(apdev[0], params)
  824. bssid0 = hapd0.own_addr()
  825. dev[0].scan_for_bss(bssid0, freq="2412")
  826. with alloc_fail(hapd0, 1, "wpa_ft_store_pmk_r0"):
  827. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  828. scan_freq="2412")
  829. params = ft_params2(ssid=ssid, passphrase=passphrase)
  830. hapd1 = hostapd.add_ap(apdev[1], params)
  831. bssid1 = hapd1.own_addr()
  832. dev[0].scan_for_bss(bssid1, freq="2412")
  833. # This roam will fail due to missing PMK-R0 (OOM prevented storing it)
  834. dev[0].roam(bssid1)
  835. def test_ap_ft_ap_oom2(dev, apdev):
  836. """WPA2-PSK-FT and AP OOM 2"""
  837. ssid = "test-ft"
  838. passphrase="12345678"
  839. params = ft_params1(ssid=ssid, passphrase=passphrase)
  840. hapd0 = hostapd.add_ap(apdev[0], params)
  841. bssid0 = hapd0.own_addr()
  842. dev[0].scan_for_bss(bssid0, freq="2412")
  843. with alloc_fail(hapd0, 1, "wpa_ft_store_pmk_r1"):
  844. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  845. scan_freq="2412")
  846. params = ft_params2(ssid=ssid, passphrase=passphrase)
  847. hapd1 = hostapd.add_ap(apdev[1], params)
  848. bssid1 = hapd1.own_addr()
  849. dev[0].scan_for_bss(bssid1, freq="2412")
  850. dev[0].roam(bssid1)
  851. if dev[0].get_status_field('bssid') != bssid1:
  852. raise Exception("Did not roam to AP1")
  853. # This roam will fail due to missing PMK-R1 (OOM prevented storing it)
  854. dev[0].roam(bssid0)
  855. def test_ap_ft_ap_oom3(dev, apdev):
  856. """WPA2-PSK-FT and AP OOM 3"""
  857. ssid = "test-ft"
  858. passphrase="12345678"
  859. params = ft_params1(ssid=ssid, passphrase=passphrase)
  860. hapd0 = hostapd.add_ap(apdev[0], params)
  861. bssid0 = hapd0.own_addr()
  862. dev[0].scan_for_bss(bssid0, freq="2412")
  863. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  864. scan_freq="2412")
  865. params = ft_params2(ssid=ssid, passphrase=passphrase)
  866. hapd1 = hostapd.add_ap(apdev[1], params)
  867. bssid1 = hapd1.own_addr()
  868. dev[0].scan_for_bss(bssid1, freq="2412")
  869. with alloc_fail(hapd1, 1, "wpa_ft_pull_pmk_r1"):
  870. # This will fail due to not being able to send out PMK-R1 pull request
  871. dev[0].roam(bssid1)
  872. with fail_test(hapd1, 1, "os_get_random;wpa_ft_pull_pmk_r1"):
  873. # This will fail due to not being able to send out PMK-R1 pull request
  874. dev[0].roam(bssid1)
  875. with fail_test(hapd1, 1, "aes_wrap;wpa_ft_pull_pmk_r1"):
  876. # This will fail due to not being able to send out PMK-R1 pull request
  877. dev[0].roam(bssid1)
  878. def test_ap_ft_ap_oom4(dev, apdev):
  879. """WPA2-PSK-FT and AP OOM 4"""
  880. ssid = "test-ft"
  881. passphrase="12345678"
  882. params = ft_params1(ssid=ssid, passphrase=passphrase)
  883. hapd0 = hostapd.add_ap(apdev[0], params)
  884. bssid0 = hapd0.own_addr()
  885. dev[0].scan_for_bss(bssid0, freq="2412")
  886. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  887. scan_freq="2412")
  888. params = ft_params2(ssid=ssid, passphrase=passphrase)
  889. hapd1 = hostapd.add_ap(apdev[1], params)
  890. bssid1 = hapd1.own_addr()
  891. dev[0].scan_for_bss(bssid1, freq="2412")
  892. with alloc_fail(hapd1, 1, "wpa_ft_gtk_subelem"):
  893. dev[0].roam(bssid1)
  894. if dev[0].get_status_field('bssid') != bssid1:
  895. raise Exception("Did not roam to AP1")
  896. with fail_test(hapd0, 1, "wpa_auth_get_seqnum;wpa_ft_gtk_subelem"):
  897. dev[0].roam(bssid0)
  898. if dev[0].get_status_field('bssid') != bssid0:
  899. raise Exception("Did not roam to AP0")
  900. with fail_test(hapd0, 1, "aes_wrap;wpa_ft_gtk_subelem"):
  901. dev[0].roam(bssid1)
  902. if dev[0].get_status_field('bssid') != bssid1:
  903. raise Exception("Did not roam to AP1")
  904. def test_ap_ft_ap_oom5(dev, apdev):
  905. """WPA2-PSK-FT and AP OOM 5"""
  906. ssid = "test-ft"
  907. passphrase="12345678"
  908. params = ft_params1(ssid=ssid, passphrase=passphrase)
  909. hapd0 = hostapd.add_ap(apdev[0], params)
  910. bssid0 = hapd0.own_addr()
  911. dev[0].scan_for_bss(bssid0, freq="2412")
  912. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  913. scan_freq="2412")
  914. params = ft_params2(ssid=ssid, passphrase=passphrase)
  915. hapd1 = hostapd.add_ap(apdev[1], params)
  916. bssid1 = hapd1.own_addr()
  917. dev[0].scan_for_bss(bssid1, freq="2412")
  918. with alloc_fail(hapd1, 1, "=wpa_ft_process_auth_req"):
  919. # This will fail to roam
  920. dev[0].roam(bssid1)
  921. with fail_test(hapd1, 1, "os_get_random;wpa_ft_process_auth_req"):
  922. # This will fail to roam
  923. dev[0].roam(bssid1)
  924. with fail_test(hapd1, 1, "sha256_prf_bits;wpa_pmk_r1_to_ptk;wpa_ft_process_auth_req"):
  925. # This will fail to roam
  926. dev[0].roam(bssid1)
  927. with fail_test(hapd1, 3, "wpa_pmk_r1_to_ptk;wpa_ft_process_auth_req"):
  928. # This will fail to roam
  929. dev[0].roam(bssid1)
  930. with fail_test(hapd1, 1, "wpa_derive_pmk_r1_name;wpa_ft_process_auth_req"):
  931. # This will fail to roam
  932. dev[0].roam(bssid1)
  933. def test_ap_ft_ap_oom6(dev, apdev):
  934. """WPA2-PSK-FT and AP OOM 6"""
  935. ssid = "test-ft"
  936. passphrase="12345678"
  937. params = ft_params1(ssid=ssid, passphrase=passphrase)
  938. hapd0 = hostapd.add_ap(apdev[0], params)
  939. bssid0 = hapd0.own_addr()
  940. dev[0].scan_for_bss(bssid0, freq="2412")
  941. with fail_test(hapd0, 1, "wpa_derive_pmk_r0;wpa_auth_derive_ptk_ft"):
  942. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  943. scan_freq="2412")
  944. dev[0].request("REMOVE_NETWORK all")
  945. dev[0].wait_disconnected()
  946. with fail_test(hapd0, 1, "wpa_derive_pmk_r1;wpa_auth_derive_ptk_ft"):
  947. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  948. scan_freq="2412")
  949. dev[0].request("REMOVE_NETWORK all")
  950. dev[0].wait_disconnected()
  951. with fail_test(hapd0, 1, "wpa_pmk_r1_to_ptk;wpa_auth_derive_ptk_ft"):
  952. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  953. scan_freq="2412")
  954. def test_ap_ft_ap_oom7(dev, apdev):
  955. """WPA2-PSK-FT and AP OOM 7"""
  956. ssid = "test-ft"
  957. passphrase="12345678"
  958. params = ft_params1(ssid=ssid, passphrase=passphrase)
  959. params["ieee80211w"] = "2"
  960. hapd0 = hostapd.add_ap(apdev[0], params)
  961. bssid0 = hapd0.own_addr()
  962. dev[0].scan_for_bss(bssid0, freq="2412")
  963. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  964. ieee80211w="2", scan_freq="2412")
  965. params = ft_params2(ssid=ssid, passphrase=passphrase)
  966. params["ieee80211w"] = "2"
  967. hapd1 = hostapd.add_ap(apdev[1], params)
  968. bssid1 = hapd1.own_addr()
  969. dev[0].scan_for_bss(bssid1, freq="2412")
  970. with alloc_fail(hapd1, 1, "wpa_ft_igtk_subelem"):
  971. # This will fail to roam
  972. dev[0].roam(bssid1)
  973. with fail_test(hapd1, 1, "aes_wrap;wpa_ft_igtk_subelem"):
  974. # This will fail to roam
  975. dev[0].roam(bssid1)
  976. with alloc_fail(hapd1, 1, "=wpa_sm_write_assoc_resp_ies"):
  977. # This will fail to roam
  978. dev[0].roam(bssid1)
  979. with fail_test(hapd1, 1, "wpa_ft_mic;wpa_sm_write_assoc_resp_ies"):
  980. # This will fail to roam
  981. dev[0].roam(bssid1)
  982. def test_ap_ft_ap_oom8(dev, apdev):
  983. """WPA2-PSK-FT and AP OOM 8"""
  984. ssid = "test-ft"
  985. passphrase="12345678"
  986. params = ft_params1(ssid=ssid, passphrase=passphrase)
  987. params['ft_psk_generate_local'] = "1";
  988. hapd0 = hostapd.add_ap(apdev[0], params)
  989. bssid0 = hapd0.own_addr()
  990. dev[0].scan_for_bss(bssid0, freq="2412")
  991. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  992. scan_freq="2412")
  993. params = ft_params2(ssid=ssid, passphrase=passphrase)
  994. params['ft_psk_generate_local'] = "1";
  995. hapd1 = hostapd.add_ap(apdev[1], params)
  996. bssid1 = hapd1.own_addr()
  997. dev[0].scan_for_bss(bssid1, freq="2412")
  998. with fail_test(hapd1, 1, "wpa_derive_pmk_r0;wpa_ft_psk_pmk_r1"):
  999. # This will fail to roam
  1000. dev[0].roam(bssid1)
  1001. with fail_test(hapd1, 1, "wpa_derive_pmk_r1;wpa_ft_psk_pmk_r1"):
  1002. # This will fail to roam
  1003. dev[0].roam(bssid1)
  1004. def test_ap_ft_ap_oom9(dev, apdev):
  1005. """WPA2-PSK-FT and AP OOM 9"""
  1006. ssid = "test-ft"
  1007. passphrase="12345678"
  1008. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1009. hapd0 = hostapd.add_ap(apdev[0], params)
  1010. bssid0 = hapd0.own_addr()
  1011. dev[0].scan_for_bss(bssid0, freq="2412")
  1012. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1013. scan_freq="2412")
  1014. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1015. hapd1 = hostapd.add_ap(apdev[1], params)
  1016. bssid1 = hapd1.own_addr()
  1017. dev[0].scan_for_bss(bssid1, freq="2412")
  1018. with alloc_fail(hapd0, 1, "wpa_ft_action_rx"):
  1019. # This will fail to roam
  1020. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1021. raise Exception("FT_DS failed")
  1022. wait_fail_trigger(hapd0, "GET_ALLOC_FAIL")
  1023. with alloc_fail(hapd1, 1, "wpa_ft_rrb_rx_request"):
  1024. # This will fail to roam
  1025. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1026. raise Exception("FT_DS failed")
  1027. wait_fail_trigger(hapd1, "GET_ALLOC_FAIL")
  1028. with alloc_fail(hapd1, 1, "wpa_ft_send_rrb_auth_resp"):
  1029. # This will fail to roam
  1030. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1031. raise Exception("FT_DS failed")
  1032. wait_fail_trigger(hapd1, "GET_ALLOC_FAIL")
  1033. def test_ap_ft_ap_oom10(dev, apdev):
  1034. """WPA2-PSK-FT and AP OOM 10"""
  1035. ssid = "test-ft"
  1036. passphrase="12345678"
  1037. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1038. hapd0 = hostapd.add_ap(apdev[0], params)
  1039. bssid0 = hapd0.own_addr()
  1040. dev[0].scan_for_bss(bssid0, freq="2412")
  1041. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1042. scan_freq="2412")
  1043. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1044. hapd1 = hostapd.add_ap(apdev[1], params)
  1045. bssid1 = hapd1.own_addr()
  1046. dev[0].scan_for_bss(bssid1, freq="2412")
  1047. with fail_test(hapd0, 1, "aes_unwrap;wpa_ft_rrb_rx_pull"):
  1048. # This will fail to roam
  1049. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1050. raise Exception("FT_DS failed")
  1051. wait_fail_trigger(hapd0, "GET_FAIL")
  1052. with fail_test(hapd0, 1, "wpa_derive_pmk_r1;wpa_ft_rrb_rx_pull"):
  1053. # This will fail to roam
  1054. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1055. raise Exception("FT_DS failed")
  1056. wait_fail_trigger(hapd0, "GET_FAIL")
  1057. with fail_test(hapd0, 1, "aes_wrap;wpa_ft_rrb_rx_pull"):
  1058. # This will fail to roam
  1059. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1060. raise Exception("FT_DS failed")
  1061. wait_fail_trigger(hapd0, "GET_FAIL")
  1062. with fail_test(hapd1, 1, "aes_unwrap;wpa_ft_rrb_rx_resp"):
  1063. # This will fail to roam
  1064. if "OK" not in dev[0].request("FT_DS " + bssid1):
  1065. raise Exception("FT_DS failed")
  1066. wait_fail_trigger(hapd1, "GET_FAIL")
  1067. def test_ap_ft_ap_oom11(dev, apdev):
  1068. """WPA2-PSK-FT and AP OOM 11"""
  1069. ssid = "test-ft"
  1070. passphrase="12345678"
  1071. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1072. hapd0 = hostapd.add_ap(apdev[0], params)
  1073. bssid0 = hapd0.own_addr()
  1074. dev[0].scan_for_bss(bssid0, freq="2412")
  1075. with fail_test(hapd0, 1, "wpa_derive_pmk_r1;wpa_ft_generate_pmk_r1"):
  1076. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1077. scan_freq="2412")
  1078. wait_fail_trigger(hapd0, "GET_FAIL")
  1079. dev[1].scan_for_bss(bssid0, freq="2412")
  1080. with fail_test(hapd0, 1, "aes_wrap;wpa_ft_generate_pmk_r1"):
  1081. dev[1].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1082. scan_freq="2412")
  1083. wait_fail_trigger(hapd0, "GET_FAIL")
  1084. def test_ap_ft_over_ds_proto_ap(dev, apdev):
  1085. """WPA2-PSK-FT AP over DS protocol testing for AP processing"""
  1086. ssid = "test-ft"
  1087. passphrase="12345678"
  1088. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1089. hapd0 = hostapd.add_ap(apdev[0], params)
  1090. bssid0 = hapd0.own_addr()
  1091. _bssid0 = bssid0.replace(':', '')
  1092. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1093. scan_freq="2412")
  1094. addr = dev[0].own_addr()
  1095. _addr = addr.replace(':', '')
  1096. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1097. hapd1 = hostapd.add_ap(apdev[1], params)
  1098. bssid1 = hapd1.own_addr()
  1099. _bssid1 = bssid1.replace(':', '')
  1100. hapd0.set("ext_mgmt_frame_handling", "1")
  1101. hdr = "d0003a01" + _bssid0 + _addr + _bssid0 + "1000"
  1102. valid = "0601" + _addr + _bssid1
  1103. tests = [ "0601",
  1104. "0601" + _addr,
  1105. "0601" + _addr + _bssid0,
  1106. "0601" + _addr + "ffffffffffff",
  1107. "0601" + _bssid0 + _bssid0,
  1108. valid,
  1109. valid + "01",
  1110. valid + "3700",
  1111. valid + "3600",
  1112. valid + "3603ffffff",
  1113. valid + "3603a1b2ff",
  1114. valid + "3603a1b2ff" + "3700",
  1115. valid + "3603a1b2ff" + "37520000" + 16*"00" + 32*"00" + 32*"00",
  1116. valid + "3603a1b2ff" + "37520001" + 16*"00" + 32*"00" + 32*"00",
  1117. valid + "3603a1b2ff" + "37550000" + 16*"00" + 32*"00" + 32*"00" + "0301aa",
  1118. valid + "3603a1b2ff" + "37550000" + 16*"00" + 32*"00" + 32*"00" + "0301aa" + "3000",
  1119. valid + "3603a1b2ff" + "37550000" + 16*"00" + 32*"00" + 32*"00" + "0301aa" + "30260100000fac040100000fac040100000facff00000100a225368fe0983b5828a37a0acb37f253",
  1120. valid + "3603a1b2ff" + "37550000" + 16*"00" + 32*"00" + 32*"00" + "0301aa" + "30260100000fac040100000fac030100000fac0400000100a225368fe0983b5828a37a0acb37f253",
  1121. valid + "3603a1b2ff" + "37550000" + 16*"00" + 32*"00" + 32*"00" + "0301aa" + "30260100000fac040100000fac040100000fac0400000100a225368fe0983b5828a37a0acb37f253",
  1122. valid + "0001" ]
  1123. for t in tests:
  1124. hapd0.dump_monitor()
  1125. if "OK" not in hapd0.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1126. raise Exception("MGMT_RX_PROCESS failed")
  1127. hapd0.set("ext_mgmt_frame_handling", "0")
  1128. def test_ap_ft_over_ds_proto(dev, apdev):
  1129. """WPA2-PSK-FT AP over DS protocol testing"""
  1130. ssid = "test-ft"
  1131. passphrase="12345678"
  1132. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1133. hapd0 = hostapd.add_ap(apdev[0], params)
  1134. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1135. scan_freq="2412")
  1136. # FT Action Response while no FT-over-DS in progress
  1137. msg = {}
  1138. msg['fc'] = 13 << 4
  1139. msg['da'] = dev[0].own_addr()
  1140. msg['sa'] = apdev[0]['bssid']
  1141. msg['bssid'] = apdev[0]['bssid']
  1142. msg['payload'] = binascii.unhexlify("06020200000000000200000004000000")
  1143. hapd0.mgmt_tx(msg)
  1144. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1145. hapd1 = hostapd.add_ap(apdev[1], params)
  1146. dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412")
  1147. hapd0.set("ext_mgmt_frame_handling", "1")
  1148. hapd0.dump_monitor()
  1149. dev[0].request("FT_DS " + apdev[1]['bssid'])
  1150. for i in range(0, 10):
  1151. req = hapd0.mgmt_rx()
  1152. if req is None:
  1153. raise Exception("MGMT RX wait timed out")
  1154. if req['subtype'] == 13:
  1155. break
  1156. req = None
  1157. if not req:
  1158. raise Exception("FT Action frame not received")
  1159. # FT Action Response for unexpected Target AP
  1160. msg['payload'] = binascii.unhexlify("0602020000000000" + "f20000000400" + "0000")
  1161. hapd0.mgmt_tx(msg)
  1162. # FT Action Response without MDIE
  1163. msg['payload'] = binascii.unhexlify("0602020000000000" + "020000000400" + "0000")
  1164. hapd0.mgmt_tx(msg)
  1165. # FT Action Response without FTIE
  1166. msg['payload'] = binascii.unhexlify("0602020000000000" + "020000000400" + "0000" + "3603a1b201")
  1167. hapd0.mgmt_tx(msg)
  1168. # FT Action Response with FTIE SNonce mismatch
  1169. msg['payload'] = binascii.unhexlify("0602020000000000" + "020000000400" + "0000" + "3603a1b201" + "3766000000000000000000000000000000000000c4e67ac1999bebd00ff4ae4d5dcaf87896bb060b469f7c78d49623fb395c3455ffffff6b693fe6f8d8c5dfac0a22344750775bd09437f98b238c9f87b97f790c0106000102030406030a6e6173312e77312e6669")
  1170. hapd0.mgmt_tx(msg)
  1171. @remote_compatible
  1172. def test_ap_ft_rrb(dev, apdev):
  1173. """WPA2-PSK-FT RRB protocol testing"""
  1174. ssid = "test-ft"
  1175. passphrase="12345678"
  1176. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1177. hapd0 = hostapd.add_ap(apdev[0], params)
  1178. dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1179. scan_freq="2412")
  1180. _dst_ll = binascii.unhexlify(apdev[0]['bssid'].replace(':',''))
  1181. _src_ll = binascii.unhexlify(dev[0].own_addr().replace(':',''))
  1182. proto = '\x89\x0d'
  1183. ehdr = _dst_ll + _src_ll + proto
  1184. # Too short RRB frame
  1185. pkt = ehdr + '\x01'
  1186. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1187. raise Exception("DATA_TEST_FRAME failed")
  1188. # RRB discarded frame wikth unrecognized type
  1189. pkt = ehdr + '\x02' + '\x02' + '\x01\x00' + _src_ll
  1190. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1191. raise Exception("DATA_TEST_FRAME failed")
  1192. # RRB frame too short for action frame
  1193. pkt = ehdr + '\x01' + '\x02' + '\x01\x00' + _src_ll
  1194. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1195. raise Exception("DATA_TEST_FRAME failed")
  1196. # Too short RRB frame (not enough room for Action Frame body)
  1197. pkt = ehdr + '\x01' + '\x02' + '\x00\x00' + _src_ll
  1198. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1199. raise Exception("DATA_TEST_FRAME failed")
  1200. # Unexpected Action frame category
  1201. pkt = ehdr + '\x01' + '\x02' + '\x0e\x00' + _src_ll + '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1202. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1203. raise Exception("DATA_TEST_FRAME failed")
  1204. # Unexpected Action in RRB Request
  1205. pkt = ehdr + '\x01' + '\x00' + '\x0e\x00' + _src_ll + '\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1206. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1207. raise Exception("DATA_TEST_FRAME failed")
  1208. # Target AP address in RRB Request does not match with own address
  1209. pkt = ehdr + '\x01' + '\x00' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1210. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1211. raise Exception("DATA_TEST_FRAME failed")
  1212. # Not enough room for status code in RRB Response
  1213. pkt = ehdr + '\x01' + '\x01' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1214. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1215. raise Exception("DATA_TEST_FRAME failed")
  1216. # RRB discarded frame with unknown packet_type
  1217. pkt = ehdr + '\x01' + '\x02' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1218. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1219. raise Exception("DATA_TEST_FRAME failed")
  1220. # RRB Response with non-zero status code; no STA match
  1221. pkt = ehdr + '\x01' + '\x01' + '\x10\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + '\xff\xff'
  1222. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1223. raise Exception("DATA_TEST_FRAME failed")
  1224. # RRB Response with zero status code and extra data; STA match
  1225. pkt = ehdr + '\x01' + '\x01' + '\x11\x00' + _src_ll + '\x06\x01' + _src_ll + '\x00\x00\x00\x00\x00\x00' + '\x00\x00' + '\x00'
  1226. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1227. raise Exception("DATA_TEST_FRAME failed")
  1228. # Too short PMK-R1 pull
  1229. pkt = ehdr + '\x01' + '\xc8' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1230. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1231. raise Exception("DATA_TEST_FRAME failed")
  1232. # Too short PMK-R1 resp
  1233. pkt = ehdr + '\x01' + '\xc9' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1234. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1235. raise Exception("DATA_TEST_FRAME failed")
  1236. # Too short PMK-R1 push
  1237. pkt = ehdr + '\x01' + '\xca' + '\x0e\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  1238. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1239. raise Exception("DATA_TEST_FRAME failed")
  1240. # No matching R0KH address found for PMK-R0 pull response
  1241. pkt = ehdr + '\x01' + '\xc9' + '\x5a\x00' + _src_ll + '\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + 76*'\00'
  1242. if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)):
  1243. raise Exception("DATA_TEST_FRAME failed")
  1244. @remote_compatible
  1245. def test_rsn_ie_proto_ft_psk_sta(dev, apdev):
  1246. """RSN element protocol testing for FT-PSK + PMF cases on STA side"""
  1247. bssid = apdev[0]['bssid']
  1248. ssid = "test-ft"
  1249. passphrase="12345678"
  1250. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1251. params["ieee80211w"] = "1"
  1252. # This is the RSN element used normally by hostapd
  1253. params['own_ie_override'] = '30140100000fac040100000fac040100000fac048c00' + '3603a1b201'
  1254. hapd = hostapd.add_ap(apdev[0], params)
  1255. id = dev[0].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1256. ieee80211w="1", scan_freq="2412",
  1257. pairwise="CCMP", group="CCMP")
  1258. tests = [ ('PMKIDCount field included',
  1259. '30160100000fac040100000fac040100000fac048c000000' + '3603a1b201'),
  1260. ('Extra IE before RSNE',
  1261. 'dd0400000000' + '30140100000fac040100000fac040100000fac048c00' + '3603a1b201'),
  1262. ('PMKIDCount and Group Management Cipher suite fields included',
  1263. '301a0100000fac040100000fac040100000fac048c000000000fac06' + '3603a1b201'),
  1264. ('Extra octet after defined fields (future extensibility)',
  1265. '301b0100000fac040100000fac040100000fac048c000000000fac0600' + '3603a1b201'),
  1266. ('No RSN Capabilities field (PMF disabled in practice)',
  1267. '30120100000fac040100000fac040100000fac04' + '3603a1b201') ]
  1268. for txt,ie in tests:
  1269. dev[0].request("DISCONNECT")
  1270. dev[0].wait_disconnected()
  1271. logger.info(txt)
  1272. hapd.disable()
  1273. hapd.set('own_ie_override', ie)
  1274. hapd.enable()
  1275. dev[0].request("BSS_FLUSH 0")
  1276. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  1277. dev[0].select_network(id, freq=2412)
  1278. dev[0].wait_connected()
  1279. dev[0].request("DISCONNECT")
  1280. dev[0].wait_disconnected()
  1281. logger.info('Invalid RSNE causing internal hostapd error')
  1282. hapd.disable()
  1283. hapd.set('own_ie_override', '30130100000fac040100000fac040100000fac048c' + '3603a1b201')
  1284. hapd.enable()
  1285. dev[0].request("BSS_FLUSH 0")
  1286. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  1287. dev[0].select_network(id, freq=2412)
  1288. # hostapd fails to generate EAPOL-Key msg 3/4, so this connection cannot
  1289. # complete.
  1290. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1291. if ev is not None:
  1292. raise Exception("Unexpected connection")
  1293. dev[0].request("DISCONNECT")
  1294. logger.info('Unexpected PMKID causing internal hostapd error')
  1295. hapd.disable()
  1296. hapd.set('own_ie_override', '30260100000fac040100000fac040100000fac048c000100ffffffffffffffffffffffffffffffff' + '3603a1b201')
  1297. hapd.enable()
  1298. dev[0].request("BSS_FLUSH 0")
  1299. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  1300. dev[0].select_network(id, freq=2412)
  1301. # hostapd fails to generate EAPOL-Key msg 3/4, so this connection cannot
  1302. # complete.
  1303. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1304. if ev is not None:
  1305. raise Exception("Unexpected connection")
  1306. dev[0].request("DISCONNECT")
  1307. def test_ap_ft_ptk_rekey(dev, apdev):
  1308. """WPA2-PSK-FT PTK rekeying triggered by station after roam"""
  1309. ssid = "test-ft"
  1310. passphrase="12345678"
  1311. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1312. hapd0 = hostapd.add_ap(apdev[0], params)
  1313. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1314. hapd1 = hostapd.add_ap(apdev[1], params)
  1315. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, ptk_rekey="1")
  1316. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
  1317. "WPA: Key negotiation completed"], timeout=5)
  1318. if ev is None:
  1319. raise Exception("No event received after roam")
  1320. if "CTRL-EVENT-DISCONNECTED" in ev:
  1321. raise Exception("Unexpected disconnection after roam")
  1322. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  1323. hapd = hapd0
  1324. else:
  1325. hapd = hapd1
  1326. hwsim_utils.test_connectivity(dev[0], hapd)
  1327. def test_ap_ft_ptk_rekey_ap(dev, apdev):
  1328. """WPA2-PSK-FT PTK rekeying triggered by AP after roam"""
  1329. ssid = "test-ft"
  1330. passphrase="12345678"
  1331. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1332. params['wpa_ptk_rekey'] = '2'
  1333. hapd0 = hostapd.add_ap(apdev[0], params)
  1334. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1335. params['wpa_ptk_rekey'] = '2'
  1336. hapd1 = hostapd.add_ap(apdev[1], params)
  1337. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase)
  1338. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED",
  1339. "WPA: Key negotiation completed"], timeout=5)
  1340. if ev is None:
  1341. raise Exception("No event received after roam")
  1342. if "CTRL-EVENT-DISCONNECTED" in ev:
  1343. raise Exception("Unexpected disconnection after roam")
  1344. if dev[0].get_status_field('bssid') == apdev[0]['bssid']:
  1345. hapd = hapd0
  1346. else:
  1347. hapd = hapd1
  1348. hwsim_utils.test_connectivity(dev[0], hapd)
  1349. def test_ap_ft_internal_rrb_check(dev, apdev):
  1350. """RRB internal delivery only to WPA enabled BSS"""
  1351. ssid = "test-ft"
  1352. passphrase="12345678"
  1353. radius = hostapd.radius_params()
  1354. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1355. params['wpa_key_mgmt'] = "FT-EAP"
  1356. params["ieee8021x"] = "1"
  1357. params = dict(radius.items() + params.items())
  1358. hapd = hostapd.add_ap(apdev[0], params)
  1359. key_mgmt = hapd.get_config()['key_mgmt']
  1360. if key_mgmt.split(' ')[0] != "FT-EAP":
  1361. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  1362. hapd1 = hostapd.add_ap(apdev[1], { "ssid" : ssid })
  1363. # Connect to WPA enabled AP
  1364. dev[0].connect(ssid, key_mgmt="FT-EAP", proto="WPA2", ieee80211w="1",
  1365. eap="GPSK", identity="gpsk user",
  1366. password="abcdefghijklmnop0123456789abcdef",
  1367. scan_freq="2412")
  1368. # Try over_ds roaming to non-WPA-enabled AP.
  1369. # If hostapd does not check hapd->wpa_auth internally, it will crash now.
  1370. dev[0].roam_over_ds(apdev[1]['bssid'], fail_test=True)
  1371. def test_ap_ft_extra_ie(dev, apdev):
  1372. """WPA2-PSK-FT AP with WPA2-PSK enabled and unexpected MDE"""
  1373. ssid = "test-ft"
  1374. passphrase="12345678"
  1375. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1376. params["wpa_key_mgmt"] = "WPA-PSK FT-PSK"
  1377. hapd0 = hostapd.add_ap(apdev[0], params)
  1378. dev[1].connect(ssid, psk=passphrase, key_mgmt="FT-PSK", proto="WPA2",
  1379. scan_freq="2412")
  1380. dev[2].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK", proto="WPA2",
  1381. scan_freq="2412")
  1382. try:
  1383. # Add Mobility Domain element to test AP validation code.
  1384. dev[0].request("VENDOR_ELEM_ADD 13 3603a1b201")
  1385. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK", proto="WPA2",
  1386. scan_freq="2412", wait_connect=False)
  1387. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1388. "CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  1389. if ev is None:
  1390. raise Exception("No connection result")
  1391. if "CTRL-EVENT-CONNECTED" in ev:
  1392. raise Exception("Non-FT association accepted with MDE")
  1393. if "status_code=43" not in ev:
  1394. raise Exception("Unexpected status code: " + ev)
  1395. dev[0].request("DISCONNECT")
  1396. finally:
  1397. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  1398. def test_ap_ft_ric(dev, apdev):
  1399. """WPA2-PSK-FT AP and RIC"""
  1400. ssid = "test-ft"
  1401. passphrase="12345678"
  1402. params = ft_params1(ssid=ssid, passphrase=passphrase)
  1403. hapd0 = hostapd.add_ap(apdev[0], params)
  1404. params = ft_params2(ssid=ssid, passphrase=passphrase)
  1405. hapd1 = hostapd.add_ap(apdev[1], params)
  1406. dev[0].set("ric_ies", "")
  1407. dev[0].set("ric_ies", '""')
  1408. if "FAIL" not in dev[0].request("SET ric_ies q"):
  1409. raise Exception("Invalid ric_ies value accepted")
  1410. tests = [ "3900",
  1411. "3900ff04eeeeeeee",
  1412. "390400000000",
  1413. "390400000000" + "390400000000",
  1414. "390400000000" + "dd050050f20202",
  1415. "390400000000" + "dd3d0050f2020201" + 55*"00",
  1416. "390400000000" + "dd3d0050f2020201aa300010270000000000000000000000000000000000000000000000000000ffffff7f00000000000000000000000040420f00ffff0000",
  1417. "390401010000" + "dd3d0050f2020201aa3000dc050000000000000000000000000000000000000000000000000000dc050000000000000000000000000000808d5b0028230000" ]
  1418. for t in tests:
  1419. dev[0].set("ric_ies", t)
  1420. run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase,
  1421. test_connectivity=False)
  1422. dev[0].request("REMOVE_NETWORK all")
  1423. dev[0].wait_disconnected()
  1424. dev[0].dump_monitor()