test_ap_psk.py 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623
  1. # WPA2-Personal tests
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  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. from Crypto.Cipher import AES
  9. import hashlib
  10. import hmac
  11. import logging
  12. logger = logging.getLogger()
  13. import os
  14. import re
  15. import struct
  16. import subprocess
  17. import time
  18. import hostapd
  19. from utils import HwsimSkip, fail_test, skip_with_fips
  20. import hwsim_utils
  21. from wpasupplicant import WpaSupplicant
  22. def check_mib(dev, vals):
  23. mib = dev.get_mib()
  24. for v in vals:
  25. if mib[v[0]] != v[1]:
  26. raise Exception("Unexpected {} = {} (expected {})".format(v[0], mib[v[0]], v[1]))
  27. @remote_compatible
  28. def test_ap_wpa2_psk(dev, apdev):
  29. """WPA2-PSK AP with PSK instead of passphrase"""
  30. ssid = "test-wpa2-psk"
  31. passphrase = 'qwertyuiop'
  32. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  33. params = hostapd.wpa2_params(ssid=ssid)
  34. params['wpa_psk'] = psk
  35. hapd = hostapd.add_ap(apdev[0], params)
  36. key_mgmt = hapd.get_config()['key_mgmt']
  37. if key_mgmt.split(' ')[0] != "WPA-PSK":
  38. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  39. dev[0].connect(ssid, raw_psk=psk, scan_freq="2412")
  40. dev[1].connect(ssid, psk=passphrase, scan_freq="2412")
  41. sig = dev[0].request("SIGNAL_POLL").splitlines()
  42. pkt = dev[0].request("PKTCNT_POLL").splitlines()
  43. if "FREQUENCY=2412" not in sig:
  44. raise Exception("Unexpected SIGNAL_POLL value: " + str(sig))
  45. if "TXBAD=0" not in pkt:
  46. raise Exception("Unexpected TXBAD value: " + str(pkt))
  47. def test_ap_wpa2_psk_file(dev, apdev):
  48. """WPA2-PSK AP with PSK from a file"""
  49. ssid = "test-wpa2-psk"
  50. passphrase = 'qwertyuiop'
  51. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  52. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  53. params['wpa_psk_file'] = 'hostapd.wpa_psk'
  54. hostapd.add_ap(apdev[0], params)
  55. dev[1].connect(ssid, psk="very secret", scan_freq="2412", wait_connect=False)
  56. dev[2].connect(ssid, raw_psk=psk, scan_freq="2412")
  57. dev[2].request("REMOVE_NETWORK all")
  58. dev[0].connect(ssid, psk="very secret", scan_freq="2412")
  59. dev[0].request("REMOVE_NETWORK all")
  60. dev[2].connect(ssid, psk="another passphrase for all STAs", scan_freq="2412")
  61. dev[0].connect(ssid, psk="another passphrase for all STAs", scan_freq="2412")
  62. ev = dev[1].wait_event(["WPA: 4-Way Handshake failed"], timeout=10)
  63. if ev is None:
  64. raise Exception("Timed out while waiting for failure report")
  65. dev[1].request("REMOVE_NETWORK all")
  66. @remote_compatible
  67. def test_ap_wpa2_psk_mem(dev, apdev):
  68. """WPA2-PSK AP with passphrase only in memory"""
  69. try:
  70. _test_ap_wpa2_psk_mem(dev, apdev)
  71. finally:
  72. dev[0].request("SCAN_INTERVAL 5")
  73. dev[1].request("SCAN_INTERVAL 5")
  74. def _test_ap_wpa2_psk_mem(dev, apdev):
  75. ssid = "test-wpa2-psk"
  76. passphrase = 'qwertyuiop'
  77. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  78. params = hostapd.wpa2_params(ssid=ssid)
  79. params['wpa_psk'] = psk
  80. hapd = hostapd.add_ap(apdev[0], params)
  81. dev[0].connect(ssid, mem_only_psk="1", scan_freq="2412", wait_connect=False)
  82. dev[0].request("SCAN_INTERVAL 1")
  83. ev = dev[0].wait_event(["CTRL-REQ-PSK_PASSPHRASE"], timeout=10)
  84. if ev is None:
  85. raise Exception("Request for PSK/passphrase timed out")
  86. id = ev.split(':')[0].split('-')[-1]
  87. dev[0].request("CTRL-RSP-PSK_PASSPHRASE-" + id + ':"' + passphrase + '"')
  88. dev[0].wait_connected(timeout=10)
  89. dev[1].connect(ssid, mem_only_psk="1", scan_freq="2412", wait_connect=False)
  90. dev[1].request("SCAN_INTERVAL 1")
  91. ev = dev[1].wait_event(["CTRL-REQ-PSK_PASSPHRASE"], timeout=10)
  92. if ev is None:
  93. raise Exception("Request for PSK/passphrase timed out(2)")
  94. id = ev.split(':')[0].split('-')[-1]
  95. dev[1].request("CTRL-RSP-PSK_PASSPHRASE-" + id + ':' + psk)
  96. dev[1].wait_connected(timeout=10)
  97. @remote_compatible
  98. def test_ap_wpa2_ptk_rekey(dev, apdev):
  99. """WPA2-PSK AP and PTK rekey enforced by station"""
  100. ssid = "test-wpa2-psk"
  101. passphrase = 'qwertyuiop'
  102. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  103. hapd = hostapd.add_ap(apdev[0], params)
  104. dev[0].connect(ssid, psk=passphrase, wpa_ptk_rekey="1", scan_freq="2412")
  105. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  106. if ev is None:
  107. raise Exception("PTK rekey timed out")
  108. hwsim_utils.test_connectivity(dev[0], hapd)
  109. @remote_compatible
  110. def test_ap_wpa2_ptk_rekey_ap(dev, apdev):
  111. """WPA2-PSK AP and PTK rekey enforced by AP"""
  112. ssid = "test-wpa2-psk"
  113. passphrase = 'qwertyuiop'
  114. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  115. params['wpa_ptk_rekey'] = '2'
  116. hapd = hostapd.add_ap(apdev[0], params)
  117. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  118. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  119. if ev is None:
  120. raise Exception("PTK rekey timed out")
  121. hwsim_utils.test_connectivity(dev[0], hapd)
  122. @remote_compatible
  123. def test_ap_wpa2_sha256_ptk_rekey(dev, apdev):
  124. """WPA2-PSK/SHA256 AKM AP and PTK rekey enforced by station"""
  125. ssid = "test-wpa2-psk"
  126. passphrase = 'qwertyuiop'
  127. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  128. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  129. hapd = hostapd.add_ap(apdev[0], params)
  130. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK-SHA256",
  131. wpa_ptk_rekey="1", scan_freq="2412")
  132. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  133. if ev is None:
  134. raise Exception("PTK rekey timed out")
  135. hwsim_utils.test_connectivity(dev[0], hapd)
  136. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-6"),
  137. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-6") ])
  138. @remote_compatible
  139. def test_ap_wpa2_sha256_ptk_rekey_ap(dev, apdev):
  140. """WPA2-PSK/SHA256 AKM AP and PTK rekey enforced by AP"""
  141. ssid = "test-wpa2-psk"
  142. passphrase = 'qwertyuiop'
  143. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  144. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  145. params['wpa_ptk_rekey'] = '2'
  146. hapd = hostapd.add_ap(apdev[0], params)
  147. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK-SHA256",
  148. scan_freq="2412")
  149. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  150. if ev is None:
  151. raise Exception("PTK rekey timed out")
  152. hwsim_utils.test_connectivity(dev[0], hapd)
  153. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-6"),
  154. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-6") ])
  155. @remote_compatible
  156. def test_ap_wpa_ptk_rekey(dev, apdev):
  157. """WPA-PSK/TKIP AP and PTK rekey enforced by station"""
  158. skip_with_fips(dev[0])
  159. ssid = "test-wpa-psk"
  160. passphrase = 'qwertyuiop'
  161. params = hostapd.wpa_params(ssid=ssid, passphrase=passphrase)
  162. hapd = hostapd.add_ap(apdev[0], params)
  163. dev[0].connect(ssid, psk=passphrase, wpa_ptk_rekey="1", scan_freq="2412")
  164. if "[WPA-PSK-TKIP]" not in dev[0].request("SCAN_RESULTS"):
  165. raise Exception("Scan results missing WPA element info")
  166. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  167. if ev is None:
  168. raise Exception("PTK rekey timed out")
  169. hwsim_utils.test_connectivity(dev[0], hapd)
  170. @remote_compatible
  171. def test_ap_wpa_ptk_rekey_ap(dev, apdev):
  172. """WPA-PSK/TKIP AP and PTK rekey enforced by AP"""
  173. skip_with_fips(dev[0])
  174. ssid = "test-wpa-psk"
  175. passphrase = 'qwertyuiop'
  176. params = hostapd.wpa_params(ssid=ssid, passphrase=passphrase)
  177. params['wpa_ptk_rekey'] = '2'
  178. hapd = hostapd.add_ap(apdev[0], params)
  179. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  180. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  181. if ev is None:
  182. raise Exception("PTK rekey timed out")
  183. hwsim_utils.test_connectivity(dev[0], hapd)
  184. @remote_compatible
  185. def test_ap_wpa_ccmp(dev, apdev):
  186. """WPA-PSK/CCMP"""
  187. ssid = "test-wpa-psk"
  188. passphrase = 'qwertyuiop'
  189. params = hostapd.wpa_params(ssid=ssid, passphrase=passphrase)
  190. params['wpa_pairwise'] = "CCMP"
  191. hapd = hostapd.add_ap(apdev[0], params)
  192. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  193. hwsim_utils.test_connectivity(dev[0], hapd)
  194. check_mib(dev[0], [ ("dot11RSNAConfigGroupCipherSize", "128"),
  195. ("dot11RSNAGroupCipherRequested", "00-50-f2-4"),
  196. ("dot11RSNAPairwiseCipherRequested", "00-50-f2-4"),
  197. ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-2"),
  198. ("dot11RSNAGroupCipherSelected", "00-50-f2-4"),
  199. ("dot11RSNAPairwiseCipherSelected", "00-50-f2-4"),
  200. ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-2"),
  201. ("dot1xSuppSuppControlledPortStatus", "Authorized") ])
  202. def test_ap_wpa2_psk_file_errors(dev, apdev):
  203. """WPA2-PSK AP with various PSK file error and success cases"""
  204. addr0 = dev[0].own_addr()
  205. addr1 = dev[1].own_addr()
  206. addr2 = dev[2].own_addr()
  207. ssid = "psk"
  208. pskfile = "/tmp/ap_wpa2_psk_file_errors.psk_file"
  209. try:
  210. os.remove(pskfile)
  211. except:
  212. pass
  213. params = { "ssid": ssid, "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
  214. "rsn_pairwise": "CCMP", "wpa_psk_file": pskfile }
  215. try:
  216. # missing PSK file
  217. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  218. if "FAIL" not in hapd.request("ENABLE"):
  219. raise Exception("Unexpected ENABLE success")
  220. hapd.request("DISABLE")
  221. # invalid MAC address
  222. with open(pskfile, "w") as f:
  223. f.write("\n")
  224. f.write("foo\n")
  225. if "FAIL" not in hapd.request("ENABLE"):
  226. raise Exception("Unexpected ENABLE success")
  227. hapd.request("DISABLE")
  228. # no PSK on line
  229. with open(pskfile, "w") as f:
  230. f.write("00:11:22:33:44:55\n")
  231. if "FAIL" not in hapd.request("ENABLE"):
  232. raise Exception("Unexpected ENABLE success")
  233. hapd.request("DISABLE")
  234. # invalid PSK
  235. with open(pskfile, "w") as f:
  236. f.write("00:11:22:33:44:55 1234567\n")
  237. if "FAIL" not in hapd.request("ENABLE"):
  238. raise Exception("Unexpected ENABLE success")
  239. hapd.request("DISABLE")
  240. # valid PSK file
  241. with open(pskfile, "w") as f:
  242. f.write("00:11:22:33:44:55 12345678\n")
  243. f.write(addr0 + " 123456789\n")
  244. f.write(addr1 + " 123456789a\n")
  245. f.write(addr2 + " 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\n")
  246. if "FAIL" in hapd.request("ENABLE"):
  247. raise Exception("Unexpected ENABLE failure")
  248. dev[0].connect(ssid, psk="123456789", scan_freq="2412")
  249. dev[1].connect(ssid, psk="123456789a", scan_freq="2412")
  250. dev[2].connect(ssid, raw_psk="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", scan_freq="2412")
  251. finally:
  252. try:
  253. os.remove(pskfile)
  254. except:
  255. pass
  256. @remote_compatible
  257. def test_ap_wpa2_psk_wildcard_ssid(dev, apdev):
  258. """WPA2-PSK AP and wildcard SSID configuration"""
  259. ssid = "test-wpa2-psk"
  260. passphrase = 'qwertyuiop'
  261. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  262. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  263. hapd = hostapd.add_ap(apdev[0], params)
  264. dev[0].connect("", bssid=apdev[0]['bssid'], psk=passphrase,
  265. scan_freq="2412")
  266. dev[1].connect("", bssid=apdev[0]['bssid'], raw_psk=psk, scan_freq="2412")
  267. @remote_compatible
  268. def test_ap_wpa2_gtk_rekey(dev, apdev):
  269. """WPA2-PSK AP and GTK rekey enforced by AP"""
  270. ssid = "test-wpa2-psk"
  271. passphrase = 'qwertyuiop'
  272. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  273. params['wpa_group_rekey'] = '1'
  274. hapd = hostapd.add_ap(apdev[0], params)
  275. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  276. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  277. if ev is None:
  278. raise Exception("GTK rekey timed out")
  279. hwsim_utils.test_connectivity(dev[0], hapd)
  280. @remote_compatible
  281. def test_ap_wpa_gtk_rekey(dev, apdev):
  282. """WPA-PSK/TKIP AP and GTK rekey enforced by AP"""
  283. skip_with_fips(dev[0])
  284. ssid = "test-wpa-psk"
  285. passphrase = 'qwertyuiop'
  286. params = hostapd.wpa_params(ssid=ssid, passphrase=passphrase)
  287. params['wpa_group_rekey'] = '1'
  288. hapd = hostapd.add_ap(apdev[0], params)
  289. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  290. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  291. if ev is None:
  292. raise Exception("GTK rekey timed out")
  293. hwsim_utils.test_connectivity(dev[0], hapd)
  294. @remote_compatible
  295. def test_ap_wpa2_gmk_rekey(dev, apdev):
  296. """WPA2-PSK AP and GMK and GTK rekey enforced by AP"""
  297. ssid = "test-wpa2-psk"
  298. passphrase = 'qwertyuiop'
  299. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  300. params['wpa_group_rekey'] = '1'
  301. params['wpa_gmk_rekey'] = '2'
  302. hapd = hostapd.add_ap(apdev[0], params)
  303. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  304. for i in range(0, 3):
  305. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  306. if ev is None:
  307. raise Exception("GTK rekey timed out")
  308. hwsim_utils.test_connectivity(dev[0], hapd)
  309. @remote_compatible
  310. def test_ap_wpa2_strict_rekey(dev, apdev):
  311. """WPA2-PSK AP and strict GTK rekey enforced by AP"""
  312. ssid = "test-wpa2-psk"
  313. passphrase = 'qwertyuiop'
  314. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  315. params['wpa_strict_rekey'] = '1'
  316. hapd = hostapd.add_ap(apdev[0], params)
  317. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  318. dev[1].connect(ssid, psk=passphrase, scan_freq="2412")
  319. dev[1].request("DISCONNECT")
  320. ev = dev[0].wait_event(["WPA: Group rekeying completed"], timeout=2)
  321. if ev is None:
  322. raise Exception("GTK rekey timed out")
  323. hwsim_utils.test_connectivity(dev[0], hapd)
  324. @remote_compatible
  325. def test_ap_wpa2_bridge_fdb(dev, apdev):
  326. """Bridge FDB entry removal"""
  327. hapd = None
  328. try:
  329. ssid = "test-wpa2-psk"
  330. passphrase = "12345678"
  331. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  332. params['bridge'] = 'ap-br0'
  333. hapd = hostapd.add_ap(apdev[0], params)
  334. hapd.cmd_execute(['brctl', 'setfd', 'ap-br0', '0'])
  335. hapd.cmd_execute(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  336. dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  337. bssid=apdev[0]['bssid'])
  338. dev[1].connect(ssid, psk=passphrase, scan_freq="2412",
  339. bssid=apdev[0]['bssid'])
  340. addr0 = dev[0].p2p_interface_addr()
  341. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  342. err, macs1 = hapd.cmd_execute(['brctl', 'showmacs', 'ap-br0'])
  343. hapd.cmd_execute(['brctl', 'setageing', 'ap-br0', '1'])
  344. dev[0].request("DISCONNECT")
  345. dev[1].request("DISCONNECT")
  346. time.sleep(1)
  347. err, macs2 = hapd.cmd_execute(['brctl', 'showmacs', 'ap-br0'])
  348. addr1 = dev[1].p2p_interface_addr()
  349. if addr0 not in macs1 or addr1 not in macs1:
  350. raise Exception("Bridge FDB entry missing")
  351. if addr0 in macs2 or addr1 in macs2:
  352. raise Exception("Bridge FDB entry was not removed")
  353. finally:
  354. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0',
  355. 'down'])
  356. hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', 'ap-br0'])
  357. @remote_compatible
  358. def test_ap_wpa2_already_in_bridge(dev, apdev):
  359. """hostapd behavior with interface already in bridge"""
  360. ifname = apdev[0]['ifname']
  361. br_ifname = 'ext-ap-br0'
  362. try:
  363. ssid = "test-wpa2-psk"
  364. passphrase = "12345678"
  365. hostapd.cmd_execute(apdev[0], ['brctl', 'addbr', br_ifname])
  366. hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', br_ifname, '0'])
  367. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
  368. 'up'])
  369. hostapd.cmd_execute(apdev[0], ['iw', ifname, 'set', 'type', '__ap'])
  370. hostapd.cmd_execute(apdev[0], ['brctl', 'addif', br_ifname, ifname])
  371. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  372. hapd = hostapd.add_ap(apdev[0], params)
  373. if hapd.get_driver_status_field('brname') != br_ifname:
  374. raise Exception("Bridge name not identified correctly")
  375. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  376. finally:
  377. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
  378. 'down'])
  379. hostapd.cmd_execute(apdev[0], ['brctl', 'delif', br_ifname, ifname])
  380. hostapd.cmd_execute(apdev[0], ['iw', ifname, 'set', 'type', 'station'])
  381. hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', br_ifname])
  382. @remote_compatible
  383. def test_ap_wpa2_in_different_bridge(dev, apdev):
  384. """hostapd behavior with interface in different bridge"""
  385. ifname = apdev[0]['ifname']
  386. br_ifname = 'ext-ap-br0'
  387. try:
  388. ssid = "test-wpa2-psk"
  389. passphrase = "12345678"
  390. hostapd.cmd_execute(apdev[0], ['brctl', 'addbr', br_ifname])
  391. hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', br_ifname, '0'])
  392. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
  393. 'up'])
  394. hostapd.cmd_execute(apdev[0], ['iw', ifname, 'set', 'type', '__ap'])
  395. hostapd.cmd_execute(apdev[0], ['brctl', 'addif', br_ifname, ifname])
  396. time.sleep(0.5)
  397. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  398. params['bridge'] = 'ap-br0'
  399. hapd = hostapd.add_ap(apdev[0], params)
  400. hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', 'ap-br0', '0'])
  401. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', 'ap-br0',
  402. 'up'])
  403. brname = hapd.get_driver_status_field('brname')
  404. if brname != 'ap-br0':
  405. raise Exception("Incorrect bridge: " + brname)
  406. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  407. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  408. if hapd.get_driver_status_field("added_bridge") != "1":
  409. raise Exception("Unexpected added_bridge value")
  410. if hapd.get_driver_status_field("added_if_into_bridge") != "1":
  411. raise Exception("Unexpected added_if_into_bridge value")
  412. dev[0].request("DISCONNECT")
  413. hapd.disable()
  414. finally:
  415. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
  416. 'down'])
  417. hostapd.cmd_execute(apdev[0], ['brctl', 'delif', br_ifname, ifname,
  418. "2>", "/dev/null"], shell=True)
  419. hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', br_ifname])
  420. @remote_compatible
  421. def test_ap_wpa2_ext_add_to_bridge(dev, apdev):
  422. """hostapd behavior with interface added to bridge externally"""
  423. ifname = apdev[0]['ifname']
  424. br_ifname = 'ext-ap-br0'
  425. try:
  426. ssid = "test-wpa2-psk"
  427. passphrase = "12345678"
  428. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  429. hapd = hostapd.add_ap(apdev[0], params)
  430. hostapd.cmd_execute(apdev[0], ['brctl', 'addbr', br_ifname])
  431. hostapd.cmd_execute(apdev[0], ['brctl', 'setfd', br_ifname, '0'])
  432. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
  433. 'up'])
  434. hostapd.cmd_execute(apdev[0], ['brctl', 'addif', br_ifname, ifname])
  435. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  436. if hapd.get_driver_status_field('brname') != br_ifname:
  437. raise Exception("Bridge name not identified correctly")
  438. finally:
  439. hostapd.cmd_execute(apdev[0], ['ip', 'link', 'set', 'dev', br_ifname,
  440. 'down'])
  441. hostapd.cmd_execute(apdev[0], ['brctl', 'delif', br_ifname, ifname])
  442. hostapd.cmd_execute(apdev[0], ['brctl', 'delbr', br_ifname])
  443. def test_ap_wpa2_psk_ext(dev, apdev):
  444. """WPA2-PSK AP using external EAPOL I/O"""
  445. bssid = apdev[0]['bssid']
  446. ssid = "test-wpa2-psk"
  447. passphrase = 'qwertyuiop'
  448. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  449. params = hostapd.wpa2_params(ssid=ssid)
  450. params['wpa_psk'] = psk
  451. hapd = hostapd.add_ap(apdev[0], params)
  452. hapd.request("SET ext_eapol_frame_io 1")
  453. dev[0].request("SET ext_eapol_frame_io 1")
  454. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  455. addr = dev[0].p2p_interface_addr()
  456. while True:
  457. ev = hapd.wait_event(["EAPOL-TX", "AP-STA-CONNECTED"], timeout=15)
  458. if ev is None:
  459. raise Exception("Timeout on EAPOL-TX from hostapd")
  460. if "AP-STA-CONNECTED" in ev:
  461. dev[0].wait_connected(timeout=15)
  462. break
  463. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  464. if "OK" not in res:
  465. raise Exception("EAPOL_RX to wpa_supplicant failed")
  466. ev = dev[0].wait_event(["EAPOL-TX", "CTRL-EVENT-CONNECTED"], timeout=15)
  467. if ev is None:
  468. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  469. if "CTRL-EVENT-CONNECTED" in ev:
  470. break
  471. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  472. if "OK" not in res:
  473. raise Exception("EAPOL_RX to hostapd failed")
  474. def test_ap_wpa2_psk_ext_retry_msg_3(dev, apdev):
  475. """WPA2-PSK AP using external EAPOL I/O and retry for EAPOL-Key msg 3/4"""
  476. bssid = apdev[0]['bssid']
  477. ssid = "test-wpa2-psk"
  478. passphrase = 'qwertyuiop'
  479. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  480. params = hostapd.wpa2_params(ssid=ssid)
  481. params['wpa_psk'] = psk
  482. hapd = hostapd.add_ap(apdev[0], params)
  483. hapd.request("SET ext_eapol_frame_io 1")
  484. dev[0].request("SET ext_eapol_frame_io 1")
  485. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  486. addr = dev[0].p2p_interface_addr()
  487. # EAPOL-Key msg 1/4
  488. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  489. if ev is None:
  490. raise Exception("Timeout on EAPOL-TX from hostapd")
  491. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  492. if "OK" not in res:
  493. raise Exception("EAPOL_RX to wpa_supplicant failed")
  494. # EAPOL-Key msg 2/4
  495. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  496. if ev is None:
  497. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  498. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  499. if "OK" not in res:
  500. raise Exception("EAPOL_RX to hostapd failed")
  501. # EAPOL-Key msg 3/4
  502. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  503. if ev is None:
  504. raise Exception("Timeout on EAPOL-TX from hostapd")
  505. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  506. if "OK" not in res:
  507. raise Exception("EAPOL_RX to wpa_supplicant failed")
  508. # EAPOL-Key msg 4/4
  509. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  510. if ev is None:
  511. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  512. # Do not send to the AP
  513. dev[0].wait_connected(timeout=15)
  514. # EAPOL-Key msg 3/4 (retry)
  515. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  516. if ev is None:
  517. raise Exception("Timeout on EAPOL-TX from hostapd")
  518. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  519. if "OK" not in res:
  520. raise Exception("EAPOL_RX to wpa_supplicant failed")
  521. # EAPOL-Key msg 4/4
  522. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  523. if ev is None:
  524. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  525. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  526. if "OK" not in res:
  527. raise Exception("EAPOL_RX to hostapd failed")
  528. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  529. if ev is None:
  530. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  531. hwsim_utils.test_connectivity(dev[0], hapd)
  532. def test_ap_wpa2_psk_ext_retry_msg_3b(dev, apdev):
  533. """WPA2-PSK AP using external EAPOL I/O and retry for EAPOL-Key msg 3/4 (b)"""
  534. bssid = apdev[0]['bssid']
  535. ssid = "test-wpa2-psk"
  536. passphrase = 'qwertyuiop'
  537. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  538. params = hostapd.wpa2_params(ssid=ssid)
  539. params['wpa_psk'] = psk
  540. hapd = hostapd.add_ap(apdev[0], params)
  541. hapd.request("SET ext_eapol_frame_io 1")
  542. dev[0].request("SET ext_eapol_frame_io 1")
  543. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  544. addr = dev[0].p2p_interface_addr()
  545. # EAPOL-Key msg 1/4
  546. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  547. if ev is None:
  548. raise Exception("Timeout on EAPOL-TX from hostapd")
  549. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  550. if "OK" not in res:
  551. raise Exception("EAPOL_RX to wpa_supplicant failed")
  552. # EAPOL-Key msg 2/4
  553. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  554. if ev is None:
  555. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  556. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  557. if "OK" not in res:
  558. raise Exception("EAPOL_RX to hostapd failed")
  559. # EAPOL-Key msg 3/4
  560. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  561. if ev is None:
  562. raise Exception("Timeout on EAPOL-TX from hostapd")
  563. # Do not send the first msg 3/4 to the STA yet; wait for retransmission
  564. # from AP.
  565. msg3_1 = ev
  566. # EAPOL-Key msg 3/4 (retry)
  567. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  568. if ev is None:
  569. raise Exception("Timeout on EAPOL-TX from hostapd")
  570. msg3_2 = ev
  571. # Send the first msg 3/4 to STA
  572. res = dev[0].request("EAPOL_RX " + bssid + " " + msg3_1.split(' ')[2])
  573. if "OK" not in res:
  574. raise Exception("EAPOL_RX to wpa_supplicant failed")
  575. # EAPOL-Key msg 4/4
  576. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  577. if ev is None:
  578. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  579. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  580. if "OK" not in res:
  581. raise Exception("EAPOL_RX to hostapd failed")
  582. dev[0].wait_connected(timeout=15)
  583. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  584. if ev is None:
  585. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  586. hwsim_utils.test_connectivity(dev[0], hapd)
  587. # Send the second msg 3/4 to STA
  588. res = dev[0].request("EAPOL_RX " + bssid + " " + msg3_2.split(' ')[2])
  589. if "OK" not in res:
  590. raise Exception("EAPOL_RX to wpa_supplicant failed")
  591. # EAPOL-Key msg 4/4
  592. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  593. if ev is None:
  594. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  595. # Do not send the second msg 4/4 to the AP
  596. hwsim_utils.test_connectivity(dev[0], hapd)
  597. def test_ap_wpa2_psk_ext_retry_msg_3c(dev, apdev):
  598. """WPA2-PSK AP using external EAPOL I/O and retry for EAPOL-Key msg 3/4 (c)"""
  599. bssid = apdev[0]['bssid']
  600. ssid = "test-wpa2-psk"
  601. passphrase = 'qwertyuiop'
  602. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  603. params = hostapd.wpa2_params(ssid=ssid)
  604. params['wpa_psk'] = psk
  605. hapd = hostapd.add_ap(apdev[0], params)
  606. hapd.request("SET ext_eapol_frame_io 1")
  607. dev[0].request("SET ext_eapol_frame_io 1")
  608. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  609. addr = dev[0].p2p_interface_addr()
  610. # EAPOL-Key msg 1/4
  611. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  612. if ev is None:
  613. raise Exception("Timeout on EAPOL-TX from hostapd")
  614. msg1 = ev.split(' ')[2]
  615. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1)
  616. if "OK" not in res:
  617. raise Exception("EAPOL_RX to wpa_supplicant failed")
  618. # EAPOL-Key msg 2/4
  619. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  620. if ev is None:
  621. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  622. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  623. if "OK" not in res:
  624. raise Exception("EAPOL_RX to hostapd failed")
  625. # EAPOL-Key msg 3/4
  626. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  627. if ev is None:
  628. raise Exception("Timeout on EAPOL-TX from hostapd")
  629. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  630. if "OK" not in res:
  631. raise Exception("EAPOL_RX to wpa_supplicant failed")
  632. # EAPOL-Key msg 4/4
  633. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  634. if ev is None:
  635. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  636. msg4 = ev.split(' ')[2]
  637. # Do not send msg 4/4 to hostapd to trigger retry
  638. # STA believes everything is ready
  639. dev[0].wait_connected()
  640. # EAPOL-Key msg 3/4 (retry)
  641. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  642. if ev is None:
  643. raise Exception("Timeout on EAPOL-TX from hostapd")
  644. msg3 = ev.split(' ')[2]
  645. # Send a forged msg 1/4 to STA (update replay counter)
  646. msg1b = msg1[0:18] + msg3[18:34] + msg1[34:]
  647. # and replace nonce (this results in "WPA: ANonce from message 1 of
  648. # 4-Way Handshake differs from 3 of 4-Way Handshake - drop packet" when
  649. # wpa_supplicant processed msg 3/4 afterwards)
  650. #msg1b = msg1[0:18] + msg3[18:34] + 32*"ff" + msg1[98:]
  651. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1b)
  652. if "OK" not in res:
  653. raise Exception("EAPOL_RX to wpa_supplicant failed")
  654. # EAPOL-Key msg 2/4
  655. ev = dev[0].wait_event(["EAPOL-TX"], timeout=1)
  656. if ev is None:
  657. # wpa_supplicant seems to have ignored the forged message. This means
  658. # the attack would fail.
  659. logger.info("wpa_supplicant ignored forged EAPOL-Key msg 1/4")
  660. return
  661. # Do not send msg 2/4 to hostapd
  662. # Send previously received msg 3/4 to STA
  663. res = dev[0].request("EAPOL_RX " + bssid + " " + msg3)
  664. if "OK" not in res:
  665. raise Exception("EAPOL_RX to wpa_supplicant failed")
  666. # EAPOL-Key msg 4/4
  667. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  668. if ev is None:
  669. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  670. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  671. if "OK" not in res:
  672. raise Exception("EAPOL_RX to hostapd failed")
  673. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  674. if ev is None:
  675. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  676. hwsim_utils.test_connectivity(dev[0], hapd)
  677. def test_ap_wpa2_psk_ext_retry_msg_3d(dev, apdev):
  678. """WPA2-PSK AP using external EAPOL I/O and retry for EAPOL-Key msg 3/4 (d)"""
  679. bssid = apdev[0]['bssid']
  680. ssid = "test-wpa2-psk"
  681. passphrase = 'qwertyuiop'
  682. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  683. params = hostapd.wpa2_params(ssid=ssid)
  684. params['wpa_psk'] = psk
  685. hapd = hostapd.add_ap(apdev[0], params)
  686. hapd.request("SET ext_eapol_frame_io 1")
  687. dev[0].request("SET ext_eapol_frame_io 1")
  688. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  689. addr = dev[0].p2p_interface_addr()
  690. # EAPOL-Key msg 1/4
  691. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  692. if ev is None:
  693. raise Exception("Timeout on EAPOL-TX from hostapd")
  694. msg1 = ev.split(' ')[2]
  695. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1)
  696. if "OK" not in res:
  697. raise Exception("EAPOL_RX to wpa_supplicant failed")
  698. # EAPOL-Key msg 2/4
  699. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  700. if ev is None:
  701. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  702. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  703. if "OK" not in res:
  704. raise Exception("EAPOL_RX to hostapd failed")
  705. # EAPOL-Key msg 3/4
  706. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  707. if ev is None:
  708. raise Exception("Timeout on EAPOL-TX from hostapd")
  709. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  710. if "OK" not in res:
  711. raise Exception("EAPOL_RX to wpa_supplicant failed")
  712. # EAPOL-Key msg 4/4
  713. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  714. if ev is None:
  715. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  716. msg4 = ev.split(' ')[2]
  717. # Do not send msg 4/4 to hostapd to trigger retry
  718. # STA believes everything is ready
  719. dev[0].wait_connected()
  720. # EAPOL-Key msg 3/4 (retry)
  721. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  722. if ev is None:
  723. raise Exception("Timeout on EAPOL-TX from hostapd")
  724. msg3 = ev.split(' ')[2]
  725. # Send a forged msg 1/4 to STA (update replay counter)
  726. msg1b = msg1[0:18] + msg3[18:34] + msg1[34:]
  727. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1b)
  728. if "OK" not in res:
  729. raise Exception("EAPOL_RX to wpa_supplicant failed")
  730. # EAPOL-Key msg 2/4
  731. ev = dev[0].wait_event(["EAPOL-TX"], timeout=1)
  732. if ev is None:
  733. # wpa_supplicant seems to have ignored the forged message. This means
  734. # the attack would fail.
  735. logger.info("wpa_supplicant ignored forged EAPOL-Key msg 1/4")
  736. return
  737. # Do not send msg 2/4 to hostapd
  738. # EAPOL-Key msg 3/4 (retry 2)
  739. # New one needed to get the correct Replay Counter value
  740. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  741. if ev is None:
  742. raise Exception("Timeout on EAPOL-TX from hostapd")
  743. msg3 = ev.split(' ')[2]
  744. # Send msg 3/4 to STA
  745. res = dev[0].request("EAPOL_RX " + bssid + " " + msg3)
  746. if "OK" not in res:
  747. raise Exception("EAPOL_RX to wpa_supplicant failed")
  748. # EAPOL-Key msg 4/4
  749. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  750. if ev is None:
  751. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  752. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  753. if "OK" not in res:
  754. raise Exception("EAPOL_RX to hostapd failed")
  755. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  756. if ev is None:
  757. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  758. hwsim_utils.test_connectivity(dev[0], hapd)
  759. def test_ap_wpa2_psk_ext_retry_msg_3e(dev, apdev):
  760. """WPA2-PSK AP using external EAPOL I/O and retry for EAPOL-Key msg 3/4 (e)"""
  761. bssid = apdev[0]['bssid']
  762. ssid = "test-wpa2-psk"
  763. passphrase = 'qwertyuiop'
  764. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  765. params = hostapd.wpa2_params(ssid=ssid)
  766. params['wpa_psk'] = psk
  767. hapd = hostapd.add_ap(apdev[0], params)
  768. hapd.request("SET ext_eapol_frame_io 1")
  769. dev[0].request("SET ext_eapol_frame_io 1")
  770. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  771. addr = dev[0].p2p_interface_addr()
  772. # EAPOL-Key msg 1/4
  773. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  774. if ev is None:
  775. raise Exception("Timeout on EAPOL-TX from hostapd")
  776. msg1 = ev.split(' ')[2]
  777. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1)
  778. if "OK" not in res:
  779. raise Exception("EAPOL_RX to wpa_supplicant failed")
  780. # EAPOL-Key msg 2/4
  781. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  782. if ev is None:
  783. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  784. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  785. if "OK" not in res:
  786. raise Exception("EAPOL_RX to hostapd failed")
  787. # EAPOL-Key msg 3/4
  788. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  789. if ev is None:
  790. raise Exception("Timeout on EAPOL-TX from hostapd")
  791. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  792. if "OK" not in res:
  793. raise Exception("EAPOL_RX to wpa_supplicant failed")
  794. # EAPOL-Key msg 4/4
  795. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  796. if ev is None:
  797. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  798. msg4 = ev.split(' ')[2]
  799. # Do not send msg 4/4 to hostapd to trigger retry
  800. # STA believes everything is ready
  801. dev[0].wait_connected()
  802. # EAPOL-Key msg 3/4 (retry)
  803. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  804. if ev is None:
  805. raise Exception("Timeout on EAPOL-TX from hostapd")
  806. msg3 = ev.split(' ')[2]
  807. # Send a forged msg 1/4 to STA (update replay counter and replace ANonce)
  808. msg1b = msg1[0:18] + msg3[18:34] + 32*"ff" + msg1[98:]
  809. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1b)
  810. if "OK" not in res:
  811. raise Exception("EAPOL_RX to wpa_supplicant failed")
  812. # EAPOL-Key msg 2/4
  813. ev = dev[0].wait_event(["EAPOL-TX"], timeout=1)
  814. if ev is None:
  815. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  816. # Do not send msg 2/4 to hostapd
  817. # Send a forged msg 1/4 to STA (back to previously used ANonce)
  818. msg1b = msg1[0:18] + msg3[18:34] + msg1[34:]
  819. res = dev[0].request("EAPOL_RX " + bssid + " " + msg1b)
  820. if "OK" not in res:
  821. raise Exception("EAPOL_RX to wpa_supplicant failed")
  822. # EAPOL-Key msg 2/4
  823. ev = dev[0].wait_event(["EAPOL-TX"], timeout=1)
  824. if ev is None:
  825. # wpa_supplicant seems to have ignored the forged message. This means
  826. # the attack would fail.
  827. logger.info("wpa_supplicant ignored forged EAPOL-Key msg 1/4")
  828. return
  829. # Do not send msg 2/4 to hostapd
  830. # EAPOL-Key msg 3/4 (retry 2)
  831. # New one needed to get the correct Replay Counter value
  832. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  833. if ev is None:
  834. raise Exception("Timeout on EAPOL-TX from hostapd")
  835. msg3 = ev.split(' ')[2]
  836. # Send msg 3/4 to STA
  837. res = dev[0].request("EAPOL_RX " + bssid + " " + msg3)
  838. if "OK" not in res:
  839. raise Exception("EAPOL_RX to wpa_supplicant failed")
  840. # EAPOL-Key msg 4/4
  841. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  842. if ev is None:
  843. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  844. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  845. if "OK" not in res:
  846. raise Exception("EAPOL_RX to hostapd failed")
  847. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  848. if ev is None:
  849. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  850. hwsim_utils.test_connectivity(dev[0], hapd)
  851. def parse_eapol(data):
  852. (version, type, length) = struct.unpack('>BBH', data[0:4])
  853. payload = data[4:]
  854. if length > len(payload):
  855. raise Exception("Invalid EAPOL length")
  856. if length < len(payload):
  857. payload = payload[0:length]
  858. eapol = {}
  859. eapol['version'] = version
  860. eapol['type'] = type
  861. eapol['length'] = length
  862. eapol['payload'] = payload
  863. if type == 3:
  864. # EAPOL-Key
  865. (eapol['descr_type'],) = struct.unpack('B', payload[0:1])
  866. payload = payload[1:]
  867. if eapol['descr_type'] == 2 or eapol['descr_type'] == 254:
  868. # RSN EAPOL-Key
  869. (key_info, key_len) = struct.unpack('>HH', payload[0:4])
  870. eapol['rsn_key_info'] = key_info
  871. eapol['rsn_key_len'] = key_len
  872. eapol['rsn_replay_counter'] = payload[4:12]
  873. eapol['rsn_key_nonce'] = payload[12:44]
  874. eapol['rsn_key_iv'] = payload[44:60]
  875. eapol['rsn_key_rsc'] = payload[60:68]
  876. eapol['rsn_key_id'] = payload[68:76]
  877. eapol['rsn_key_mic'] = payload[76:92]
  878. payload = payload[92:]
  879. (eapol['rsn_key_data_len'],) = struct.unpack('>H', payload[0:2])
  880. payload = payload[2:]
  881. eapol['rsn_key_data'] = payload
  882. return eapol
  883. def build_eapol(msg):
  884. data = struct.pack(">BBH", msg['version'], msg['type'], msg['length'])
  885. if msg['type'] == 3:
  886. data += struct.pack('>BHH', msg['descr_type'], msg['rsn_key_info'],
  887. msg['rsn_key_len'])
  888. data += msg['rsn_replay_counter']
  889. data += msg['rsn_key_nonce']
  890. data += msg['rsn_key_iv']
  891. data += msg['rsn_key_rsc']
  892. data += msg['rsn_key_id']
  893. data += msg['rsn_key_mic']
  894. data += struct.pack('>H', msg['rsn_key_data_len'])
  895. data += msg['rsn_key_data']
  896. else:
  897. data += msg['payload']
  898. return data
  899. def sha1_prf(key, label, data, outlen):
  900. res = ''
  901. counter = 0
  902. while outlen > 0:
  903. m = hmac.new(key, label, hashlib.sha1)
  904. m.update(struct.pack('B', 0))
  905. m.update(data)
  906. m.update(struct.pack('B', counter))
  907. counter += 1
  908. hash = m.digest()
  909. if outlen > len(hash):
  910. res += hash
  911. outlen -= len(hash)
  912. else:
  913. res += hash[0:outlen]
  914. outlen = 0
  915. return res
  916. def pmk_to_ptk(pmk, addr1, addr2, nonce1, nonce2):
  917. if addr1 < addr2:
  918. data = binascii.unhexlify(addr1.replace(':','')) + binascii.unhexlify(addr2.replace(':',''))
  919. else:
  920. data = binascii.unhexlify(addr2.replace(':','')) + binascii.unhexlify(addr1.replace(':',''))
  921. if nonce1 < nonce2:
  922. data += nonce1 + nonce2
  923. else:
  924. data += nonce2 + nonce1
  925. label = "Pairwise key expansion"
  926. ptk = sha1_prf(pmk, label, data, 48)
  927. kck = ptk[0:16]
  928. kek = ptk[16:32]
  929. return (ptk, kck, kek)
  930. def eapol_key_mic(kck, msg):
  931. msg['rsn_key_mic'] = binascii.unhexlify('00000000000000000000000000000000')
  932. data = build_eapol(msg)
  933. m = hmac.new(kck, data, hashlib.sha1)
  934. msg['rsn_key_mic'] = m.digest()[0:16]
  935. def rsn_eapol_key_set(msg, key_info, key_len, nonce, data):
  936. msg['rsn_key_info'] = key_info
  937. msg['rsn_key_len'] = key_len
  938. if nonce:
  939. msg['rsn_key_nonce'] = nonce
  940. else:
  941. msg['rsn_key_nonce'] = binascii.unhexlify('0000000000000000000000000000000000000000000000000000000000000000')
  942. if data:
  943. msg['rsn_key_data_len'] = len(data)
  944. msg['rsn_key_data'] = data
  945. msg['length'] = 95 + len(data)
  946. else:
  947. msg['rsn_key_data_len'] = 0
  948. msg['rsn_key_data'] = ''
  949. msg['length'] = 95
  950. def recv_eapol(hapd):
  951. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  952. if ev is None:
  953. raise Exception("Timeout on EAPOL-TX from hostapd")
  954. eapol = binascii.unhexlify(ev.split(' ')[2])
  955. return parse_eapol(eapol)
  956. def send_eapol(hapd, addr, data):
  957. res = hapd.request("EAPOL_RX " + addr + " " + binascii.hexlify(data))
  958. if "OK" not in res:
  959. raise Exception("EAPOL_RX to hostapd failed")
  960. def reply_eapol(info, hapd, addr, msg, key_info, nonce, data, kck):
  961. logger.info("Send EAPOL-Key msg " + info)
  962. rsn_eapol_key_set(msg, key_info, 0, nonce, data)
  963. eapol_key_mic(kck, msg)
  964. send_eapol(hapd, addr, build_eapol(msg))
  965. def hapd_connected(hapd):
  966. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  967. if ev is None:
  968. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  969. def eapol_test(apdev, dev, wpa2=True):
  970. bssid = apdev['bssid']
  971. if wpa2:
  972. ssid = "test-wpa2-psk"
  973. else:
  974. ssid = "test-wpa-psk"
  975. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  976. pmk = binascii.unhexlify(psk)
  977. if wpa2:
  978. params = hostapd.wpa2_params(ssid=ssid)
  979. else:
  980. params = hostapd.wpa_params(ssid=ssid)
  981. params['wpa_psk'] = psk
  982. hapd = hostapd.add_ap(apdev, params)
  983. hapd.request("SET ext_eapol_frame_io 1")
  984. dev.request("SET ext_eapol_frame_io 1")
  985. dev.connect(ssid, raw_psk=psk, scan_freq="2412", wait_connect=False)
  986. addr = dev.p2p_interface_addr()
  987. if wpa2:
  988. rsne = binascii.unhexlify('30140100000fac040100000fac040100000fac020000')
  989. else:
  990. rsne = binascii.unhexlify('dd160050f20101000050f20201000050f20201000050f202')
  991. snonce = binascii.unhexlify('1111111111111111111111111111111111111111111111111111111111111111')
  992. return (bssid,ssid,hapd,snonce,pmk,addr,rsne)
  993. @remote_compatible
  994. def test_ap_wpa2_psk_ext_eapol(dev, apdev):
  995. """WPA2-PSK AP using external EAPOL supplicant"""
  996. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  997. msg = recv_eapol(hapd)
  998. anonce = msg['rsn_key_nonce']
  999. logger.info("Replay same data back")
  1000. send_eapol(hapd, addr, build_eapol(msg))
  1001. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1002. logger.info("Truncated Key Data in EAPOL-Key msg 2/4")
  1003. rsn_eapol_key_set(msg, 0x0101, 0, snonce, rsne)
  1004. msg['length'] = 95 + 22 - 1
  1005. send_eapol(hapd, addr, build_eapol(msg))
  1006. reply_eapol("2/4", hapd, addr, msg, 0x010a, snonce, rsne, kck)
  1007. msg = recv_eapol(hapd)
  1008. if anonce != msg['rsn_key_nonce']:
  1009. raise Exception("ANonce changed")
  1010. logger.info("Replay same data back")
  1011. send_eapol(hapd, addr, build_eapol(msg))
  1012. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1013. hapd_connected(hapd)
  1014. @remote_compatible
  1015. def test_ap_wpa2_psk_ext_eapol_retry1(dev, apdev):
  1016. """WPA2 4-way handshake with EAPOL-Key 1/4 retransmitted"""
  1017. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1018. msg1 = recv_eapol(hapd)
  1019. anonce = msg1['rsn_key_nonce']
  1020. msg2 = recv_eapol(hapd)
  1021. if anonce != msg2['rsn_key_nonce']:
  1022. raise Exception("ANonce changed")
  1023. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1024. logger.info("Send EAPOL-Key msg 2/4")
  1025. msg = msg2
  1026. rsn_eapol_key_set(msg, 0x010a, 0, snonce, rsne)
  1027. eapol_key_mic(kck, msg)
  1028. send_eapol(hapd, addr, build_eapol(msg))
  1029. msg = recv_eapol(hapd)
  1030. if anonce != msg['rsn_key_nonce']:
  1031. raise Exception("ANonce changed")
  1032. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1033. hapd_connected(hapd)
  1034. @remote_compatible
  1035. def test_ap_wpa2_psk_ext_eapol_retry1b(dev, apdev):
  1036. """WPA2 4-way handshake with EAPOL-Key 1/4 and 2/4 retransmitted"""
  1037. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1038. msg1 = recv_eapol(hapd)
  1039. anonce = msg1['rsn_key_nonce']
  1040. msg2 = recv_eapol(hapd)
  1041. if anonce != msg2['rsn_key_nonce']:
  1042. raise Exception("ANonce changed")
  1043. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1044. reply_eapol("2/4 (a)", hapd, addr, msg1, 0x010a, snonce, rsne, kck)
  1045. reply_eapol("2/4 (b)", hapd, addr, msg2, 0x010a, snonce, rsne, kck)
  1046. msg = recv_eapol(hapd)
  1047. if anonce != msg['rsn_key_nonce']:
  1048. raise Exception("ANonce changed")
  1049. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1050. hapd_connected(hapd)
  1051. @remote_compatible
  1052. def test_ap_wpa2_psk_ext_eapol_retry1c(dev, apdev):
  1053. """WPA2 4-way handshake with EAPOL-Key 1/4 and 2/4 retransmitted and SNonce changing"""
  1054. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1055. msg1 = recv_eapol(hapd)
  1056. anonce = msg1['rsn_key_nonce']
  1057. msg2 = recv_eapol(hapd)
  1058. if anonce != msg2['rsn_key_nonce']:
  1059. raise Exception("ANonce changed")
  1060. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1061. reply_eapol("2/4 (a)", hapd, addr, msg1, 0x010a, snonce, rsne, kck)
  1062. snonce2 = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1063. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce2, anonce)
  1064. reply_eapol("2/4 (b)", hapd, addr, msg2, 0x010a, snonce2, rsne, kck)
  1065. msg = recv_eapol(hapd)
  1066. if anonce != msg['rsn_key_nonce']:
  1067. raise Exception("ANonce changed")
  1068. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1069. hapd_connected(hapd)
  1070. @remote_compatible
  1071. def test_ap_wpa2_psk_ext_eapol_retry1d(dev, apdev):
  1072. """WPA2 4-way handshake with EAPOL-Key 1/4 and 2/4 retransmitted and SNonce changing and older used"""
  1073. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1074. msg1 = recv_eapol(hapd)
  1075. anonce = msg1['rsn_key_nonce']
  1076. msg2 = recv_eapol(hapd)
  1077. if anonce != msg2['rsn_key_nonce']:
  1078. raise Exception("ANonce changed")
  1079. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1080. reply_eapol("2/4 (a)", hapd, addr, msg1, 0x010a, snonce, rsne, kck)
  1081. snonce2 = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1082. (ptk2, kck2, kek2) = pmk_to_ptk(pmk, addr, bssid, snonce2, anonce)
  1083. reply_eapol("2/4 (b)", hapd, addr, msg2, 0x010a, snonce2, rsne, kck2)
  1084. msg = recv_eapol(hapd)
  1085. if anonce != msg['rsn_key_nonce']:
  1086. raise Exception("ANonce changed")
  1087. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1088. hapd_connected(hapd)
  1089. @remote_compatible
  1090. def test_ap_wpa2_psk_ext_eapol_type_diff(dev, apdev):
  1091. """WPA2 4-way handshake using external EAPOL supplicant"""
  1092. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1093. msg = recv_eapol(hapd)
  1094. anonce = msg['rsn_key_nonce']
  1095. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1096. # Incorrect descriptor type (frame dropped)
  1097. msg['descr_type'] = 253
  1098. rsn_eapol_key_set(msg, 0x010a, 0, snonce, rsne)
  1099. eapol_key_mic(kck, msg)
  1100. send_eapol(hapd, addr, build_eapol(msg))
  1101. # Incorrect descriptor type, but with a workaround (frame processed)
  1102. msg['descr_type'] = 254
  1103. rsn_eapol_key_set(msg, 0x010a, 0, snonce, rsne)
  1104. eapol_key_mic(kck, msg)
  1105. send_eapol(hapd, addr, build_eapol(msg))
  1106. msg = recv_eapol(hapd)
  1107. if anonce != msg['rsn_key_nonce']:
  1108. raise Exception("ANonce changed")
  1109. logger.info("Replay same data back")
  1110. send_eapol(hapd, addr, build_eapol(msg))
  1111. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1112. hapd_connected(hapd)
  1113. @remote_compatible
  1114. def test_ap_wpa_psk_ext_eapol(dev, apdev):
  1115. """WPA2-PSK AP using external EAPOL supplicant"""
  1116. (bssid,ssid,hapd,snonce,pmk,addr,wpae) = eapol_test(apdev[0], dev[0],
  1117. wpa2=False)
  1118. msg = recv_eapol(hapd)
  1119. anonce = msg['rsn_key_nonce']
  1120. logger.info("Replay same data back")
  1121. send_eapol(hapd, addr, build_eapol(msg))
  1122. logger.info("Too short data")
  1123. send_eapol(hapd, addr, build_eapol(msg)[0:98])
  1124. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1125. msg['descr_type'] = 2
  1126. reply_eapol("2/4(invalid type)", hapd, addr, msg, 0x010a, snonce, wpae, kck)
  1127. msg['descr_type'] = 254
  1128. reply_eapol("2/4", hapd, addr, msg, 0x010a, snonce, wpae, kck)
  1129. msg = recv_eapol(hapd)
  1130. if anonce != msg['rsn_key_nonce']:
  1131. raise Exception("ANonce changed")
  1132. logger.info("Replay same data back")
  1133. send_eapol(hapd, addr, build_eapol(msg))
  1134. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1135. hapd_connected(hapd)
  1136. @remote_compatible
  1137. def test_ap_wpa2_psk_ext_eapol_key_info(dev, apdev):
  1138. """WPA2-PSK 4-way handshake with strange key info values"""
  1139. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1140. msg = recv_eapol(hapd)
  1141. anonce = msg['rsn_key_nonce']
  1142. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1143. rsn_eapol_key_set(msg, 0x0000, 0, snonce, rsne)
  1144. send_eapol(hapd, addr, build_eapol(msg))
  1145. rsn_eapol_key_set(msg, 0xffff, 0, snonce, rsne)
  1146. send_eapol(hapd, addr, build_eapol(msg))
  1147. # SMK M1
  1148. rsn_eapol_key_set(msg, 0x2802, 0, snonce, rsne)
  1149. send_eapol(hapd, addr, build_eapol(msg))
  1150. # SMK M3
  1151. rsn_eapol_key_set(msg, 0x2002, 0, snonce, rsne)
  1152. send_eapol(hapd, addr, build_eapol(msg))
  1153. # Request
  1154. rsn_eapol_key_set(msg, 0x0902, 0, snonce, rsne)
  1155. send_eapol(hapd, addr, build_eapol(msg))
  1156. # Request
  1157. rsn_eapol_key_set(msg, 0x0902, 0, snonce, rsne)
  1158. tmp_kck = binascii.unhexlify('00000000000000000000000000000000')
  1159. eapol_key_mic(tmp_kck, msg)
  1160. send_eapol(hapd, addr, build_eapol(msg))
  1161. reply_eapol("2/4", hapd, addr, msg, 0x010a, snonce, rsne, kck)
  1162. msg = recv_eapol(hapd)
  1163. if anonce != msg['rsn_key_nonce']:
  1164. raise Exception("ANonce changed")
  1165. # Request (valic MIC)
  1166. rsn_eapol_key_set(msg, 0x0902, 0, snonce, rsne)
  1167. eapol_key_mic(kck, msg)
  1168. send_eapol(hapd, addr, build_eapol(msg))
  1169. # Request (valid MIC, replayed counter)
  1170. rsn_eapol_key_set(msg, 0x0902, 0, snonce, rsne)
  1171. eapol_key_mic(kck, msg)
  1172. send_eapol(hapd, addr, build_eapol(msg))
  1173. reply_eapol("4/4", hapd, addr, msg, 0x030a, None, None, kck)
  1174. hapd_connected(hapd)
  1175. def build_eapol_key_1_4(anonce, replay_counter=1, key_data='', key_len=16):
  1176. msg = {}
  1177. msg['version'] = 2
  1178. msg['type'] = 3
  1179. msg['length'] = 95 + len(key_data)
  1180. msg['descr_type'] = 2
  1181. msg['rsn_key_info'] = 0x8a
  1182. msg['rsn_key_len'] = key_len
  1183. msg['rsn_replay_counter'] = struct.pack('>Q', replay_counter)
  1184. msg['rsn_key_nonce'] = anonce
  1185. msg['rsn_key_iv'] = binascii.unhexlify('00000000000000000000000000000000')
  1186. msg['rsn_key_rsc'] = binascii.unhexlify('0000000000000000')
  1187. msg['rsn_key_id'] = binascii.unhexlify('0000000000000000')
  1188. msg['rsn_key_mic'] = binascii.unhexlify('00000000000000000000000000000000')
  1189. msg['rsn_key_data_len'] = len(key_data)
  1190. msg['rsn_key_data'] = key_data
  1191. return msg
  1192. def build_eapol_key_3_4(anonce, kck, key_data, replay_counter=2,
  1193. key_info=0x13ca, extra_len=0, descr_type=2, key_len=16):
  1194. msg = {}
  1195. msg['version'] = 2
  1196. msg['type'] = 3
  1197. msg['length'] = 95 + len(key_data) + extra_len
  1198. msg['descr_type'] = descr_type
  1199. msg['rsn_key_info'] = key_info
  1200. msg['rsn_key_len'] = key_len
  1201. msg['rsn_replay_counter'] = struct.pack('>Q', replay_counter)
  1202. msg['rsn_key_nonce'] = anonce
  1203. msg['rsn_key_iv'] = binascii.unhexlify('00000000000000000000000000000000')
  1204. msg['rsn_key_rsc'] = binascii.unhexlify('0000000000000000')
  1205. msg['rsn_key_id'] = binascii.unhexlify('0000000000000000')
  1206. msg['rsn_key_data_len'] = len(key_data)
  1207. msg['rsn_key_data'] = key_data
  1208. eapol_key_mic(kck, msg)
  1209. return msg
  1210. def aes_wrap(kek, plain):
  1211. n = len(plain) / 8
  1212. a = 0xa6a6a6a6a6a6a6a6
  1213. enc = AES.new(kek).encrypt
  1214. r = [plain[i * 8:(i + 1) * 8] for i in range(0, n)]
  1215. for j in range(6):
  1216. for i in range(1, n + 1):
  1217. b = enc(struct.pack('>Q', a) + r[i - 1])
  1218. a = struct.unpack('>Q', b[:8])[0] ^ (n * j + i)
  1219. r[i - 1] =b[8:]
  1220. return struct.pack('>Q', a) + ''.join(r)
  1221. def pad_key_data(plain):
  1222. pad_len = len(plain) % 8
  1223. if pad_len:
  1224. pad_len = 8 - pad_len
  1225. plain += '\xdd'
  1226. pad_len -= 1
  1227. plain += pad_len * '\0'
  1228. return plain
  1229. def test_ap_wpa2_psk_supp_proto(dev, apdev):
  1230. """WPA2-PSK 4-way handshake protocol testing for supplicant"""
  1231. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1232. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1233. msg = recv_eapol(hapd)
  1234. dev[0].dump_monitor()
  1235. # Build own EAPOL-Key msg 1/4
  1236. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1237. counter = 1
  1238. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1239. counter += 1
  1240. send_eapol(dev[0], bssid, build_eapol(msg))
  1241. msg = recv_eapol(dev[0])
  1242. snonce = msg['rsn_key_nonce']
  1243. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1244. logger.debug("Invalid AES wrap data length 0")
  1245. dev[0].dump_monitor()
  1246. msg = build_eapol_key_3_4(anonce, kck, '', replay_counter=counter)
  1247. counter += 1
  1248. send_eapol(dev[0], bssid, build_eapol(msg))
  1249. ev = dev[0].wait_event(["WPA: Unsupported AES-WRAP len 0"])
  1250. if ev is None:
  1251. raise Exception("Unsupported AES-WRAP len 0 not reported")
  1252. logger.debug("Invalid AES wrap data length 1")
  1253. dev[0].dump_monitor()
  1254. msg = build_eapol_key_3_4(anonce, kck, '1', replay_counter=counter)
  1255. counter += 1
  1256. send_eapol(dev[0], bssid, build_eapol(msg))
  1257. ev = dev[0].wait_event(["WPA: Unsupported AES-WRAP len 1"])
  1258. if ev is None:
  1259. raise Exception("Unsupported AES-WRAP len 1 not reported")
  1260. logger.debug("Invalid AES wrap data length 9")
  1261. dev[0].dump_monitor()
  1262. msg = build_eapol_key_3_4(anonce, kck, '123456789', replay_counter=counter)
  1263. counter += 1
  1264. send_eapol(dev[0], bssid, build_eapol(msg))
  1265. ev = dev[0].wait_event(["WPA: Unsupported AES-WRAP len 9"])
  1266. if ev is None:
  1267. raise Exception("Unsupported AES-WRAP len 9 not reported")
  1268. logger.debug("Invalid AES wrap data payload")
  1269. dev[0].dump_monitor()
  1270. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter)
  1271. # do not increment counter to test replay protection
  1272. send_eapol(dev[0], bssid, build_eapol(msg))
  1273. ev = dev[0].wait_event(["WPA: AES unwrap failed"])
  1274. if ev is None:
  1275. raise Exception("AES unwrap failure not reported")
  1276. logger.debug("Replay Count not increasing")
  1277. dev[0].dump_monitor()
  1278. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter)
  1279. counter += 1
  1280. send_eapol(dev[0], bssid, build_eapol(msg))
  1281. ev = dev[0].wait_event(["WPA: EAPOL-Key Replay Counter did not increase"])
  1282. if ev is None:
  1283. raise Exception("Replay Counter replay not reported")
  1284. logger.debug("Missing Ack bit in key info")
  1285. dev[0].dump_monitor()
  1286. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter,
  1287. key_info=0x134a)
  1288. counter += 1
  1289. send_eapol(dev[0], bssid, build_eapol(msg))
  1290. ev = dev[0].wait_event(["WPA: No Ack bit in key_info"])
  1291. if ev is None:
  1292. raise Exception("Missing Ack bit not reported")
  1293. logger.debug("Unexpected Request bit in key info")
  1294. dev[0].dump_monitor()
  1295. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter,
  1296. key_info=0x1bca)
  1297. counter += 1
  1298. send_eapol(dev[0], bssid, build_eapol(msg))
  1299. ev = dev[0].wait_event(["WPA: EAPOL-Key with Request bit"])
  1300. if ev is None:
  1301. raise Exception("Request bit not reported")
  1302. logger.debug("Unsupported key descriptor version 0")
  1303. dev[0].dump_monitor()
  1304. msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef',
  1305. replay_counter=counter, key_info=0x13c8)
  1306. counter += 1
  1307. send_eapol(dev[0], bssid, build_eapol(msg))
  1308. ev = dev[0].wait_event(["WPA: Unsupported EAPOL-Key descriptor version 0"])
  1309. if ev is None:
  1310. raise Exception("Unsupported EAPOL-Key descriptor version 0 not reported")
  1311. logger.debug("Key descriptor version 1 not allowed with CCMP")
  1312. dev[0].dump_monitor()
  1313. msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef',
  1314. replay_counter=counter, key_info=0x13c9)
  1315. counter += 1
  1316. send_eapol(dev[0], bssid, build_eapol(msg))
  1317. ev = dev[0].wait_event(["WPA: CCMP is used, but EAPOL-Key descriptor version (1) is not 2"])
  1318. if ev is None:
  1319. raise Exception("Not allowed EAPOL-Key descriptor version not reported")
  1320. logger.debug("Invalid AES wrap payload with key descriptor version 2")
  1321. dev[0].dump_monitor()
  1322. msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef',
  1323. replay_counter=counter, key_info=0x13ca)
  1324. counter += 1
  1325. send_eapol(dev[0], bssid, build_eapol(msg))
  1326. ev = dev[0].wait_event(["WPA: AES unwrap failed"])
  1327. if ev is None:
  1328. raise Exception("AES unwrap failure not reported")
  1329. logger.debug("Key descriptor version 3 workaround")
  1330. dev[0].dump_monitor()
  1331. msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef',
  1332. replay_counter=counter, key_info=0x13cb)
  1333. counter += 1
  1334. send_eapol(dev[0], bssid, build_eapol(msg))
  1335. ev = dev[0].wait_event(["WPA: CCMP is used, but EAPOL-Key descriptor version (3) is not 2"])
  1336. if ev is None:
  1337. raise Exception("CCMP key descriptor mismatch not reported")
  1338. ev = dev[0].wait_event(["WPA: Interoperability workaround"])
  1339. if ev is None:
  1340. raise Exception("AES-128-CMAC workaround not reported")
  1341. ev = dev[0].wait_event(["WPA: Invalid EAPOL-Key MIC - dropping packet"])
  1342. if ev is None:
  1343. raise Exception("MIC failure with AES-128-CMAC workaround not reported")
  1344. logger.debug("Unsupported key descriptor version 4")
  1345. dev[0].dump_monitor()
  1346. msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef',
  1347. replay_counter=counter, key_info=0x13cc)
  1348. counter += 1
  1349. send_eapol(dev[0], bssid, build_eapol(msg))
  1350. ev = dev[0].wait_event(["WPA: Unsupported EAPOL-Key descriptor version 4"])
  1351. if ev is None:
  1352. raise Exception("Unsupported EAPOL-Key descriptor version 4 not reported")
  1353. logger.debug("Unsupported key descriptor version 7")
  1354. dev[0].dump_monitor()
  1355. msg = build_eapol_key_3_4(anonce, kck, '0123456789abcdef',
  1356. replay_counter=counter, key_info=0x13cf)
  1357. counter += 1
  1358. send_eapol(dev[0], bssid, build_eapol(msg))
  1359. ev = dev[0].wait_event(["WPA: Unsupported EAPOL-Key descriptor version 7"])
  1360. if ev is None:
  1361. raise Exception("Unsupported EAPOL-Key descriptor version 7 not reported")
  1362. logger.debug("Too short EAPOL header length")
  1363. dev[0].dump_monitor()
  1364. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter,
  1365. extra_len=-1)
  1366. counter += 1
  1367. send_eapol(dev[0], bssid, build_eapol(msg))
  1368. ev = dev[0].wait_event(["WPA: Invalid EAPOL-Key frame - key_data overflow (8 > 7)"])
  1369. if ev is None:
  1370. raise Exception("Key data overflow not reported")
  1371. logger.debug("Too long EAPOL header length")
  1372. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter,
  1373. extra_len=1)
  1374. counter += 1
  1375. send_eapol(dev[0], bssid, build_eapol(msg))
  1376. logger.debug("Unsupported descriptor type 0")
  1377. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter,
  1378. descr_type=0)
  1379. counter += 1
  1380. send_eapol(dev[0], bssid, build_eapol(msg))
  1381. logger.debug("WPA descriptor type 0")
  1382. msg = build_eapol_key_3_4(anonce, kck, '12345678', replay_counter=counter,
  1383. descr_type=254)
  1384. counter += 1
  1385. send_eapol(dev[0], bssid, build_eapol(msg))
  1386. logger.debug("Non-zero key index for pairwise key")
  1387. dev[0].dump_monitor()
  1388. wrapped = aes_wrap(kek, 16*'z')
  1389. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter,
  1390. key_info=0x13ea)
  1391. counter += 1
  1392. send_eapol(dev[0], bssid, build_eapol(msg))
  1393. ev = dev[0].wait_event(["WPA: Ignored EAPOL-Key (Pairwise) with non-zero key index"])
  1394. if ev is None:
  1395. raise Exception("Non-zero key index not reported")
  1396. logger.debug("Invalid Key Data plaintext payload --> disconnect")
  1397. dev[0].dump_monitor()
  1398. wrapped = aes_wrap(kek, 16*'z')
  1399. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1400. counter += 1
  1401. send_eapol(dev[0], bssid, build_eapol(msg))
  1402. dev[0].wait_disconnected(timeout=1)
  1403. def test_ap_wpa2_psk_supp_proto_no_ie(dev, apdev):
  1404. """WPA2-PSK supplicant protocol testing: IE not included"""
  1405. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1406. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1407. msg = recv_eapol(hapd)
  1408. dev[0].dump_monitor()
  1409. # Build own EAPOL-Key msg 1/4
  1410. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1411. counter = 1
  1412. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1413. counter += 1
  1414. send_eapol(dev[0], bssid, build_eapol(msg))
  1415. msg = recv_eapol(dev[0])
  1416. snonce = msg['rsn_key_nonce']
  1417. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1418. logger.debug("No IEs in msg 3/4 --> disconnect")
  1419. dev[0].dump_monitor()
  1420. wrapped = aes_wrap(kek, 16*'\0')
  1421. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1422. counter += 1
  1423. send_eapol(dev[0], bssid, build_eapol(msg))
  1424. dev[0].wait_disconnected(timeout=1)
  1425. def test_ap_wpa2_psk_supp_proto_ie_mismatch(dev, apdev):
  1426. """WPA2-PSK supplicant protocol testing: IE mismatch"""
  1427. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1428. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1429. msg = recv_eapol(hapd)
  1430. dev[0].dump_monitor()
  1431. # Build own EAPOL-Key msg 1/4
  1432. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1433. counter = 1
  1434. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1435. counter += 1
  1436. send_eapol(dev[0], bssid, build_eapol(msg))
  1437. msg = recv_eapol(dev[0])
  1438. snonce = msg['rsn_key_nonce']
  1439. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1440. logger.debug("Msg 3/4 with mismatching IE")
  1441. dev[0].dump_monitor()
  1442. wrapped = aes_wrap(kek, pad_key_data(binascii.unhexlify('30060100000fac04dd16000fac010100dc11188831bf4aa4a8678d2b41498618')))
  1443. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1444. counter += 1
  1445. send_eapol(dev[0], bssid, build_eapol(msg))
  1446. dev[0].wait_disconnected(timeout=1)
  1447. def test_ap_wpa2_psk_supp_proto_ok(dev, apdev):
  1448. """WPA2-PSK supplicant protocol testing: success"""
  1449. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1450. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1451. msg = recv_eapol(hapd)
  1452. dev[0].dump_monitor()
  1453. # Build own EAPOL-Key msg 1/4
  1454. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1455. counter = 1
  1456. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1457. counter += 1
  1458. send_eapol(dev[0], bssid, build_eapol(msg))
  1459. msg = recv_eapol(dev[0])
  1460. snonce = msg['rsn_key_nonce']
  1461. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1462. logger.debug("Valid EAPOL-Key msg 3/4")
  1463. dev[0].dump_monitor()
  1464. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010100dc11188831bf4aa4a8678d2b41498618')
  1465. wrapped = aes_wrap(kek, pad_key_data(plain))
  1466. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1467. counter += 1
  1468. send_eapol(dev[0], bssid, build_eapol(msg))
  1469. dev[0].wait_connected(timeout=1)
  1470. def test_ap_wpa2_psk_supp_proto_no_gtk(dev, apdev):
  1471. """WPA2-PSK supplicant protocol testing: no GTK"""
  1472. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1473. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1474. msg = recv_eapol(hapd)
  1475. dev[0].dump_monitor()
  1476. # Build own EAPOL-Key msg 1/4
  1477. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1478. counter = 1
  1479. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1480. counter += 1
  1481. send_eapol(dev[0], bssid, build_eapol(msg))
  1482. msg = recv_eapol(dev[0])
  1483. snonce = msg['rsn_key_nonce']
  1484. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1485. logger.debug("EAPOL-Key msg 3/4 without GTK KDE")
  1486. dev[0].dump_monitor()
  1487. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00')
  1488. wrapped = aes_wrap(kek, pad_key_data(plain))
  1489. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1490. counter += 1
  1491. send_eapol(dev[0], bssid, build_eapol(msg))
  1492. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  1493. if ev is not None:
  1494. raise Exception("Unexpected connection completion reported")
  1495. def test_ap_wpa2_psk_supp_proto_anonce_change(dev, apdev):
  1496. """WPA2-PSK supplicant protocol testing: ANonce change"""
  1497. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1498. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1499. msg = recv_eapol(hapd)
  1500. dev[0].dump_monitor()
  1501. # Build own EAPOL-Key msg 1/4
  1502. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1503. counter = 1
  1504. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1505. counter += 1
  1506. send_eapol(dev[0], bssid, build_eapol(msg))
  1507. msg = recv_eapol(dev[0])
  1508. snonce = msg['rsn_key_nonce']
  1509. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1510. logger.debug("Valid EAPOL-Key msg 3/4")
  1511. dev[0].dump_monitor()
  1512. anonce2 = binascii.unhexlify('3333333333333333333333333333333333333333333333333333333333333333')
  1513. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010100dc11188831bf4aa4a8678d2b41498618')
  1514. wrapped = aes_wrap(kek, pad_key_data(plain))
  1515. msg = build_eapol_key_3_4(anonce2, kck, wrapped, replay_counter=counter)
  1516. counter += 1
  1517. send_eapol(dev[0], bssid, build_eapol(msg))
  1518. ev = dev[0].wait_event(["WPA: ANonce from message 1 of 4-Way Handshake differs from 3 of 4-Way Handshake"])
  1519. if ev is None:
  1520. raise Exception("ANonce change not reported")
  1521. def test_ap_wpa2_psk_supp_proto_unexpected_group_msg(dev, apdev):
  1522. """WPA2-PSK supplicant protocol testing: unexpected group message"""
  1523. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1524. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1525. msg = recv_eapol(hapd)
  1526. dev[0].dump_monitor()
  1527. # Build own EAPOL-Key msg 1/4
  1528. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1529. counter = 1
  1530. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1531. counter += 1
  1532. send_eapol(dev[0], bssid, build_eapol(msg))
  1533. msg = recv_eapol(dev[0])
  1534. snonce = msg['rsn_key_nonce']
  1535. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1536. logger.debug("Group key 1/2 instead of msg 3/4")
  1537. dev[0].dump_monitor()
  1538. wrapped = aes_wrap(kek, binascii.unhexlify('dd16000fac010100dc11188831bf4aa4a8678d2b41498618'))
  1539. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter,
  1540. key_info=0x13c2)
  1541. counter += 1
  1542. send_eapol(dev[0], bssid, build_eapol(msg))
  1543. ev = dev[0].wait_event(["WPA: Group Key Handshake started prior to completion of 4-way handshake"])
  1544. if ev is None:
  1545. raise Exception("Unexpected group key message not reported")
  1546. dev[0].wait_disconnected(timeout=1)
  1547. @remote_compatible
  1548. def test_ap_wpa2_psk_supp_proto_msg_1_invalid_kde(dev, apdev):
  1549. """WPA2-PSK supplicant protocol testing: invalid KDE in msg 1/4"""
  1550. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1551. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1552. msg = recv_eapol(hapd)
  1553. dev[0].dump_monitor()
  1554. # Build own EAPOL-Key msg 1/4 with invalid KDE
  1555. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1556. counter = 1
  1557. msg = build_eapol_key_1_4(anonce, replay_counter=counter,
  1558. key_data=binascii.unhexlify('5555'))
  1559. counter += 1
  1560. send_eapol(dev[0], bssid, build_eapol(msg))
  1561. dev[0].wait_disconnected(timeout=1)
  1562. def test_ap_wpa2_psk_supp_proto_wrong_pairwise_key_len(dev, apdev):
  1563. """WPA2-PSK supplicant protocol testing: wrong pairwise key length"""
  1564. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1565. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1566. msg = recv_eapol(hapd)
  1567. dev[0].dump_monitor()
  1568. # Build own EAPOL-Key msg 1/4
  1569. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1570. counter = 1
  1571. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1572. counter += 1
  1573. send_eapol(dev[0], bssid, build_eapol(msg))
  1574. msg = recv_eapol(dev[0])
  1575. snonce = msg['rsn_key_nonce']
  1576. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1577. logger.debug("Valid EAPOL-Key msg 3/4")
  1578. dev[0].dump_monitor()
  1579. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010100dc11188831bf4aa4a8678d2b41498618')
  1580. wrapped = aes_wrap(kek, pad_key_data(plain))
  1581. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter,
  1582. key_len=15)
  1583. counter += 1
  1584. send_eapol(dev[0], bssid, build_eapol(msg))
  1585. ev = dev[0].wait_event(["WPA: Invalid CCMP key length 15"])
  1586. if ev is None:
  1587. raise Exception("Invalid CCMP key length not reported")
  1588. dev[0].wait_disconnected(timeout=1)
  1589. def test_ap_wpa2_psk_supp_proto_wrong_group_key_len(dev, apdev):
  1590. """WPA2-PSK supplicant protocol testing: wrong group key length"""
  1591. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1592. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1593. msg = recv_eapol(hapd)
  1594. dev[0].dump_monitor()
  1595. # Build own EAPOL-Key msg 1/4
  1596. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1597. counter = 1
  1598. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1599. counter += 1
  1600. send_eapol(dev[0], bssid, build_eapol(msg))
  1601. msg = recv_eapol(dev[0])
  1602. snonce = msg['rsn_key_nonce']
  1603. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1604. logger.debug("Valid EAPOL-Key msg 3/4")
  1605. dev[0].dump_monitor()
  1606. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd15000fac010100dc11188831bf4aa4a8678d2b414986')
  1607. wrapped = aes_wrap(kek, pad_key_data(plain))
  1608. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1609. counter += 1
  1610. send_eapol(dev[0], bssid, build_eapol(msg))
  1611. ev = dev[0].wait_event(["WPA: Unsupported CCMP Group Cipher key length 15"])
  1612. if ev is None:
  1613. raise Exception("Invalid CCMP key length not reported")
  1614. dev[0].wait_disconnected(timeout=1)
  1615. def test_ap_wpa2_psk_supp_proto_gtk_tx_bit_workaround(dev, apdev):
  1616. """WPA2-PSK supplicant protocol testing: GTK TX bit workaround"""
  1617. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1618. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1619. msg = recv_eapol(hapd)
  1620. dev[0].dump_monitor()
  1621. # Build own EAPOL-Key msg 1/4
  1622. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1623. counter = 1
  1624. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1625. counter += 1
  1626. send_eapol(dev[0], bssid, build_eapol(msg))
  1627. msg = recv_eapol(dev[0])
  1628. snonce = msg['rsn_key_nonce']
  1629. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1630. logger.debug("Valid EAPOL-Key msg 3/4")
  1631. dev[0].dump_monitor()
  1632. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010500dc11188831bf4aa4a8678d2b41498618')
  1633. wrapped = aes_wrap(kek, pad_key_data(plain))
  1634. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1635. counter += 1
  1636. send_eapol(dev[0], bssid, build_eapol(msg))
  1637. ev = dev[0].wait_event(["WPA: Tx bit set for GTK, but pairwise keys are used - ignore Tx bit"])
  1638. if ev is None:
  1639. raise Exception("GTK Tx bit workaround not reported")
  1640. dev[0].wait_connected(timeout=1)
  1641. def test_ap_wpa2_psk_supp_proto_gtk_keyidx_0_and_3(dev, apdev):
  1642. """WPA2-PSK supplicant protocol testing: GTK key index 0 and 3"""
  1643. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1644. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1645. msg = recv_eapol(hapd)
  1646. dev[0].dump_monitor()
  1647. # Build own EAPOL-Key msg 1/4
  1648. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1649. counter = 1
  1650. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1651. counter += 1
  1652. send_eapol(dev[0], bssid, build_eapol(msg))
  1653. msg = recv_eapol(dev[0])
  1654. snonce = msg['rsn_key_nonce']
  1655. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1656. logger.debug("Valid EAPOL-Key msg 3/4 (GTK keyidx 0)")
  1657. dev[0].dump_monitor()
  1658. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010000dc11188831bf4aa4a8678d2b41498618')
  1659. wrapped = aes_wrap(kek, pad_key_data(plain))
  1660. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1661. counter += 1
  1662. send_eapol(dev[0], bssid, build_eapol(msg))
  1663. dev[0].wait_connected(timeout=1)
  1664. logger.debug("Valid EAPOL-Key group msg 1/2 (GTK keyidx 3)")
  1665. dev[0].dump_monitor()
  1666. plain = binascii.unhexlify('dd16000fac010300dc11188831bf4aa4a8678d2b41498618')
  1667. wrapped = aes_wrap(kek, pad_key_data(plain))
  1668. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter,
  1669. key_info=0x13c2)
  1670. counter += 1
  1671. send_eapol(dev[0], bssid, build_eapol(msg))
  1672. msg = recv_eapol(dev[0])
  1673. ev = dev[0].wait_event(["WPA: Group rekeying completed"])
  1674. if ev is None:
  1675. raise Exception("GTK rekeing not reported")
  1676. logger.debug("Unencrypted GTK KDE in group msg 1/2")
  1677. dev[0].dump_monitor()
  1678. plain = binascii.unhexlify('dd16000fac010300dc11188831bf4aa4a8678d2b41498618')
  1679. msg = build_eapol_key_3_4(anonce, kck, plain, replay_counter=counter,
  1680. key_info=0x03c2)
  1681. counter += 1
  1682. send_eapol(dev[0], bssid, build_eapol(msg))
  1683. ev = dev[0].wait_event(["WPA: GTK IE in unencrypted key data"])
  1684. if ev is None:
  1685. raise Exception("Unencrypted GTK KDE not reported")
  1686. dev[0].wait_disconnected(timeout=1)
  1687. def test_ap_wpa2_psk_supp_proto_no_gtk_in_group_msg(dev, apdev):
  1688. """WPA2-PSK supplicant protocol testing: GTK KDE missing from group msg"""
  1689. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1690. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1691. msg = recv_eapol(hapd)
  1692. dev[0].dump_monitor()
  1693. # Build own EAPOL-Key msg 1/4
  1694. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1695. counter = 1
  1696. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1697. counter += 1
  1698. send_eapol(dev[0], bssid, build_eapol(msg))
  1699. msg = recv_eapol(dev[0])
  1700. snonce = msg['rsn_key_nonce']
  1701. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1702. logger.debug("Valid EAPOL-Key msg 3/4 (GTK keyidx 0)")
  1703. dev[0].dump_monitor()
  1704. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010000dc11188831bf4aa4a8678d2b41498618')
  1705. wrapped = aes_wrap(kek, pad_key_data(plain))
  1706. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1707. counter += 1
  1708. send_eapol(dev[0], bssid, build_eapol(msg))
  1709. dev[0].wait_connected(timeout=1)
  1710. logger.debug("No GTK KDE in EAPOL-Key group msg 1/2")
  1711. dev[0].dump_monitor()
  1712. plain = binascii.unhexlify('dd00dd00dd00dd00dd00dd00dd00dd00')
  1713. wrapped = aes_wrap(kek, pad_key_data(plain))
  1714. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter,
  1715. key_info=0x13c2)
  1716. counter += 1
  1717. send_eapol(dev[0], bssid, build_eapol(msg))
  1718. ev = dev[0].wait_event(["WPA: No GTK IE in Group Key msg 1/2"])
  1719. if ev is None:
  1720. raise Exception("Missing GTK KDE not reported")
  1721. dev[0].wait_disconnected(timeout=1)
  1722. def test_ap_wpa2_psk_supp_proto_too_long_gtk_in_group_msg(dev, apdev):
  1723. """WPA2-PSK supplicant protocol testing: too long GTK KDE in group msg"""
  1724. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1725. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1726. msg = recv_eapol(hapd)
  1727. dev[0].dump_monitor()
  1728. # Build own EAPOL-Key msg 1/4
  1729. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1730. counter = 1
  1731. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1732. counter += 1
  1733. send_eapol(dev[0], bssid, build_eapol(msg))
  1734. msg = recv_eapol(dev[0])
  1735. snonce = msg['rsn_key_nonce']
  1736. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1737. logger.debug("Valid EAPOL-Key msg 3/4 (GTK keyidx 0)")
  1738. dev[0].dump_monitor()
  1739. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010000dc11188831bf4aa4a8678d2b41498618')
  1740. wrapped = aes_wrap(kek, pad_key_data(plain))
  1741. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1742. counter += 1
  1743. send_eapol(dev[0], bssid, build_eapol(msg))
  1744. dev[0].wait_connected(timeout=1)
  1745. logger.debug("EAPOL-Key group msg 1/2 with too long GTK KDE")
  1746. dev[0].dump_monitor()
  1747. plain = binascii.unhexlify('dd27000fac010100ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
  1748. wrapped = aes_wrap(kek, pad_key_data(plain))
  1749. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter,
  1750. key_info=0x13c2)
  1751. counter += 1
  1752. send_eapol(dev[0], bssid, build_eapol(msg))
  1753. ev = dev[0].wait_event(["WPA: Unsupported CCMP Group Cipher key length 33"])
  1754. if ev is None:
  1755. raise Exception("Too long GTK KDE not reported")
  1756. dev[0].wait_disconnected(timeout=1)
  1757. def test_ap_wpa2_psk_supp_proto_too_long_gtk_kde(dev, apdev):
  1758. """WPA2-PSK supplicant protocol testing: too long GTK KDE"""
  1759. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1760. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1761. msg = recv_eapol(hapd)
  1762. dev[0].dump_monitor()
  1763. # Build own EAPOL-Key msg 1/4
  1764. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1765. counter = 1
  1766. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1767. counter += 1
  1768. send_eapol(dev[0], bssid, build_eapol(msg))
  1769. msg = recv_eapol(dev[0])
  1770. snonce = msg['rsn_key_nonce']
  1771. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1772. logger.debug("EAPOL-Key msg 3/4 with too short GTK KDE")
  1773. dev[0].dump_monitor()
  1774. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd27000fac010100ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
  1775. wrapped = aes_wrap(kek, pad_key_data(plain))
  1776. msg = build_eapol_key_3_4(anonce, kck, wrapped, replay_counter=counter)
  1777. counter += 1
  1778. send_eapol(dev[0], bssid, build_eapol(msg))
  1779. dev[0].wait_disconnected(timeout=1)
  1780. def test_ap_wpa2_psk_supp_proto_gtk_not_encrypted(dev, apdev):
  1781. """WPA2-PSK supplicant protocol testing: GTK KDE not encrypted"""
  1782. (bssid,ssid,hapd,snonce,pmk,addr,rsne) = eapol_test(apdev[0], dev[0])
  1783. # Wait for EAPOL-Key msg 1/4 from hostapd to determine when associated
  1784. msg = recv_eapol(hapd)
  1785. dev[0].dump_monitor()
  1786. # Build own EAPOL-Key msg 1/4
  1787. anonce = binascii.unhexlify('2222222222222222222222222222222222222222222222222222222222222222')
  1788. counter = 1
  1789. msg = build_eapol_key_1_4(anonce, replay_counter=counter)
  1790. counter += 1
  1791. send_eapol(dev[0], bssid, build_eapol(msg))
  1792. msg = recv_eapol(dev[0])
  1793. snonce = msg['rsn_key_nonce']
  1794. (ptk, kck, kek) = pmk_to_ptk(pmk, addr, bssid, snonce, anonce)
  1795. logger.debug("Valid EAPOL-Key msg 3/4")
  1796. dev[0].dump_monitor()
  1797. plain = binascii.unhexlify('30140100000fac040100000fac040100000fac020c00dd16000fac010100dc11188831bf4aa4a8678d2b41498618')
  1798. msg = build_eapol_key_3_4(anonce, kck, plain, replay_counter=counter,
  1799. key_info=0x03ca)
  1800. counter += 1
  1801. send_eapol(dev[0], bssid, build_eapol(msg))
  1802. ev = dev[0].wait_event(["WPA: GTK IE in unencrypted key data"])
  1803. if ev is None:
  1804. raise Exception("Unencrypted GTK KDE not reported")
  1805. dev[0].wait_disconnected(timeout=1)
  1806. def find_wpas_process(dev):
  1807. ifname = dev.ifname
  1808. err, data = dev.cmd_execute(['ps', 'ax'])
  1809. for l in data.splitlines():
  1810. if "wpa_supplicant" not in l:
  1811. continue
  1812. if "-i" + ifname not in l:
  1813. continue
  1814. return int(l.strip().split(' ')[0])
  1815. raise Exception("Could not find wpa_supplicant process")
  1816. def read_process_memory(pid, key=None):
  1817. buf = bytes()
  1818. logger.info("Reading process memory (pid=%d)" % pid)
  1819. with open('/proc/%d/maps' % pid, 'r') as maps, \
  1820. open('/proc/%d/mem' % pid, 'r') as mem:
  1821. for l in maps.readlines():
  1822. m = re.match(r'([0-9a-f]+)-([0-9a-f]+) ([-r][-w][-x][-p])', l)
  1823. if not m:
  1824. continue
  1825. start = int(m.group(1), 16)
  1826. end = int(m.group(2), 16)
  1827. perm = m.group(3)
  1828. if start > 0xffffffffffff:
  1829. continue
  1830. if end < start:
  1831. continue
  1832. if not perm.startswith('rw'):
  1833. continue
  1834. for name in [ "[heap]", "[stack]" ]:
  1835. if name in l:
  1836. logger.info("%s 0x%x-0x%x is at %d-%d" % (name, start, end, len(buf), len(buf) + (end - start)))
  1837. mem.seek(start)
  1838. data = mem.read(end - start)
  1839. buf += data
  1840. if key and key in data:
  1841. logger.info("Key found in " + l)
  1842. logger.info("Total process memory read: %d bytes" % len(buf))
  1843. return buf
  1844. def verify_not_present(buf, key, fname, keyname):
  1845. pos = buf.find(key)
  1846. if pos < 0:
  1847. return
  1848. prefix = 2048 if pos > 2048 else pos
  1849. with open(fname + keyname, 'w') as f:
  1850. f.write(buf[pos - prefix:pos + 2048])
  1851. raise Exception(keyname + " found after disassociation")
  1852. def get_key_locations(buf, key, keyname):
  1853. count = 0
  1854. pos = 0
  1855. while True:
  1856. pos = buf.find(key, pos)
  1857. if pos < 0:
  1858. break
  1859. logger.info("Found %s at %d" % (keyname, pos))
  1860. context = 128
  1861. start = pos - context if pos > context else 0
  1862. before = binascii.hexlify(buf[start:pos])
  1863. context += len(key)
  1864. end = pos + context if pos < len(buf) - context else len(buf) - context
  1865. after = binascii.hexlify(buf[pos + len(key):end])
  1866. logger.debug("Memory context %d-%d: %s|%s|%s" % (start, end, before, binascii.hexlify(key), after))
  1867. count += 1
  1868. pos += len(key)
  1869. return count
  1870. def test_wpa2_psk_key_lifetime_in_memory(dev, apdev, params):
  1871. """WPA2-PSK and PSK/PTK lifetime in memory"""
  1872. ssid = "test-wpa2-psk"
  1873. passphrase = 'qwertyuiop'
  1874. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  1875. pmk = binascii.unhexlify(psk)
  1876. p = hostapd.wpa2_params(ssid=ssid)
  1877. p['wpa_psk'] = psk
  1878. hapd = hostapd.add_ap(apdev[0], p)
  1879. pid = find_wpas_process(dev[0])
  1880. id = dev[0].connect(ssid, raw_psk=psk, scan_freq="2412",
  1881. only_add_network=True)
  1882. logger.info("Checking keys in memory after network profile configuration")
  1883. buf = read_process_memory(pid, pmk)
  1884. get_key_locations(buf, pmk, "PMK")
  1885. dev[0].request("REMOVE_NETWORK all")
  1886. logger.info("Checking keys in memory after network profile removal")
  1887. buf = read_process_memory(pid, pmk)
  1888. get_key_locations(buf, pmk, "PMK")
  1889. id = dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  1890. only_add_network=True)
  1891. logger.info("Checking keys in memory before connection")
  1892. buf = read_process_memory(pid, pmk)
  1893. get_key_locations(buf, pmk, "PMK")
  1894. dev[0].connect_network(id, timeout=20)
  1895. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  1896. # event has been delivered, so verify that wpa_supplicant has returned to
  1897. # eloop before reading process memory.
  1898. time.sleep(1)
  1899. dev[0].ping()
  1900. buf = read_process_memory(pid, pmk)
  1901. dev[0].request("DISCONNECT")
  1902. dev[0].wait_disconnected()
  1903. dev[0].relog()
  1904. ptk = None
  1905. gtk = None
  1906. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  1907. for l in f.readlines():
  1908. if "WPA: PTK - hexdump" in l:
  1909. val = l.strip().split(':')[3].replace(' ', '')
  1910. ptk = binascii.unhexlify(val)
  1911. if "WPA: Group Key - hexdump" in l:
  1912. val = l.strip().split(':')[3].replace(' ', '')
  1913. gtk = binascii.unhexlify(val)
  1914. if not pmk or not ptk or not gtk:
  1915. raise Exception("Could not find keys from debug log")
  1916. if len(gtk) != 16:
  1917. raise Exception("Unexpected GTK length")
  1918. kck = ptk[0:16]
  1919. kek = ptk[16:32]
  1920. tk = ptk[32:48]
  1921. logger.info("Checking keys in memory while associated")
  1922. get_key_locations(buf, pmk, "PMK")
  1923. if pmk not in buf:
  1924. raise HwsimSkip("PMK not found while associated")
  1925. if kck not in buf:
  1926. raise Exception("KCK not found while associated")
  1927. if kek not in buf:
  1928. raise Exception("KEK not found while associated")
  1929. #if tk in buf:
  1930. # raise Exception("TK found from memory")
  1931. logger.info("Checking keys in memory after disassociation")
  1932. buf = read_process_memory(pid, pmk)
  1933. get_key_locations(buf, pmk, "PMK")
  1934. # Note: PMK/PSK is still present in network configuration
  1935. fname = os.path.join(params['logdir'],
  1936. 'wpa2_psk_key_lifetime_in_memory.memctx-')
  1937. verify_not_present(buf, kck, fname, "KCK")
  1938. verify_not_present(buf, kek, fname, "KEK")
  1939. verify_not_present(buf, tk, fname, "TK")
  1940. if gtk in buf:
  1941. get_key_locations(buf, gtk, "GTK")
  1942. verify_not_present(buf, gtk, fname, "GTK")
  1943. dev[0].request("REMOVE_NETWORK all")
  1944. logger.info("Checking keys in memory after network profile removal")
  1945. buf = read_process_memory(pid, pmk)
  1946. get_key_locations(buf, pmk, "PMK")
  1947. verify_not_present(buf, pmk, fname, "PMK")
  1948. verify_not_present(buf, kck, fname, "KCK")
  1949. verify_not_present(buf, kek, fname, "KEK")
  1950. verify_not_present(buf, tk, fname, "TK")
  1951. verify_not_present(buf, gtk, fname, "GTK")
  1952. @remote_compatible
  1953. def test_ap_wpa2_psk_wep(dev, apdev):
  1954. """WPA2-PSK AP and WEP enabled"""
  1955. ssid = "test-wpa2-psk"
  1956. passphrase = 'qwertyuiop'
  1957. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  1958. hapd = hostapd.add_ap(apdev[0], params)
  1959. try:
  1960. hapd.set('wep_key0', '"hello"')
  1961. raise Exception("WEP key accepted to WPA2 network")
  1962. except Exception:
  1963. pass
  1964. def test_ap_wpa2_psk_wpas_in_bridge(dev, apdev):
  1965. """WPA2-PSK AP and wpas interface in a bridge"""
  1966. br_ifname='sta-br0'
  1967. ifname='wlan5'
  1968. try:
  1969. _test_ap_wpa2_psk_wpas_in_bridge(dev, apdev)
  1970. finally:
  1971. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  1972. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  1973. subprocess.call(['brctl', 'delbr', br_ifname])
  1974. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  1975. def _test_ap_wpa2_psk_wpas_in_bridge(dev, apdev):
  1976. ssid = "test-wpa2-psk"
  1977. passphrase = 'qwertyuiop'
  1978. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  1979. hapd = hostapd.add_ap(apdev[0], params)
  1980. br_ifname='sta-br0'
  1981. ifname='wlan5'
  1982. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1983. subprocess.call(['brctl', 'addbr', br_ifname])
  1984. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  1985. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  1986. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  1987. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  1988. wpas.interface_add(ifname, br_ifname=br_ifname)
  1989. wpas.dump_monitor()
  1990. wpas.connect(ssid, psk=passphrase, scan_freq="2412")
  1991. wpas.dump_monitor()
  1992. @remote_compatible
  1993. def test_ap_wpa2_psk_ifdown(dev, apdev):
  1994. """AP with open mode and external ifconfig down"""
  1995. ssid = "test-wpa2-psk"
  1996. passphrase = 'qwertyuiop'
  1997. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  1998. hapd = hostapd.add_ap(apdev[0], params)
  1999. bssid = apdev[0]['bssid']
  2000. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  2001. hapd.cmd_execute(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'down'])
  2002. ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=10)
  2003. if ev is None:
  2004. raise Exception("No INTERFACE-DISABLED event")
  2005. # this wait tests beacon loss detection in mac80211
  2006. dev[0].wait_disconnected()
  2007. hapd.cmd_execute(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'up'])
  2008. ev = hapd.wait_event(["INTERFACE-ENABLED"], timeout=10)
  2009. if ev is None:
  2010. raise Exception("No INTERFACE-ENABLED event")
  2011. dev[0].wait_connected()
  2012. hwsim_utils.test_connectivity(dev[0], hapd)
  2013. def test_ap_wpa2_psk_drop_first_msg_4(dev, apdev):
  2014. """WPA2-PSK and first EAPOL-Key msg 4/4 dropped"""
  2015. bssid = apdev[0]['bssid']
  2016. ssid = "test-wpa2-psk"
  2017. passphrase = 'qwertyuiop'
  2018. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  2019. params = hostapd.wpa2_params(ssid=ssid)
  2020. params['wpa_psk'] = psk
  2021. hapd = hostapd.add_ap(apdev[0], params)
  2022. hapd.request("SET ext_eapol_frame_io 1")
  2023. dev[0].request("SET ext_eapol_frame_io 1")
  2024. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", wait_connect=False)
  2025. addr = dev[0].own_addr()
  2026. # EAPOL-Key msg 1/4
  2027. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  2028. if ev is None:
  2029. raise Exception("Timeout on EAPOL-TX from hostapd")
  2030. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  2031. if "OK" not in res:
  2032. raise Exception("EAPOL_RX to wpa_supplicant failed")
  2033. # EAPOL-Key msg 2/4
  2034. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  2035. if ev is None:
  2036. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  2037. res = hapd.request("EAPOL_RX " + addr + " " + ev.split(' ')[2])
  2038. if "OK" not in res:
  2039. raise Exception("EAPOL_RX to hostapd failed")
  2040. # EAPOL-Key msg 3/4
  2041. ev = hapd.wait_event(["EAPOL-TX"], timeout=15)
  2042. if ev is None:
  2043. raise Exception("Timeout on EAPOL-TX from hostapd")
  2044. res = dev[0].request("EAPOL_RX " + bssid + " " + ev.split(' ')[2])
  2045. if "OK" not in res:
  2046. raise Exception("EAPOL_RX to wpa_supplicant failed")
  2047. # EAPOL-Key msg 4/4
  2048. ev = dev[0].wait_event(["EAPOL-TX"], timeout=15)
  2049. if ev is None:
  2050. raise Exception("Timeout on EAPOL-TX from wpa_supplicant")
  2051. logger.info("Drop the first EAPOL-Key msg 4/4")
  2052. # wpa_supplicant believes now that 4-way handshake succeeded; hostapd
  2053. # doesn't. Use normal EAPOL TX/RX to handle retries.
  2054. hapd.request("SET ext_eapol_frame_io 0")
  2055. dev[0].request("SET ext_eapol_frame_io 0")
  2056. dev[0].wait_connected()
  2057. ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=15)
  2058. if ev is None:
  2059. raise Exception("Timeout on AP-STA-CONNECTED from hostapd")
  2060. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.1)
  2061. if ev is not None:
  2062. logger.info("Disconnection detected")
  2063. # The EAPOL-Key retries are supposed to allow the connection to be
  2064. # established without having to reassociate. However, this does not
  2065. # currently work since mac80211 ends up encrypting EAPOL-Key msg 4/4
  2066. # after the pairwise key has been configured and AP will drop those and
  2067. # disconnect the station after reaching retransmission limit. Connection
  2068. # is then established after reassociation. Once that behavior has been
  2069. # optimized to prevent EAPOL-Key frame encryption for retransmission
  2070. # case, this exception can be uncommented here.
  2071. #raise Exception("Unexpected disconnection")
  2072. @remote_compatible
  2073. def test_ap_wpa2_psk_disable_enable(dev, apdev):
  2074. """WPA2-PSK AP getting disabled and re-enabled"""
  2075. ssid = "test-wpa2-psk"
  2076. passphrase = 'qwertyuiop'
  2077. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  2078. params = hostapd.wpa2_params(ssid=ssid)
  2079. params['wpa_psk'] = psk
  2080. hapd = hostapd.add_ap(apdev[0], params)
  2081. dev[0].connect(ssid, raw_psk=psk, scan_freq="2412")
  2082. for i in range(2):
  2083. hapd.request("DISABLE")
  2084. dev[0].wait_disconnected()
  2085. hapd.request("ENABLE")
  2086. dev[0].wait_connected()
  2087. hwsim_utils.test_connectivity(dev[0], hapd)
  2088. @remote_compatible
  2089. def test_ap_wpa2_psk_incorrect_passphrase(dev, apdev):
  2090. """WPA2-PSK AP and station using incorrect passphrase"""
  2091. ssid = "test-wpa2-psk"
  2092. passphrase = 'qwertyuiop'
  2093. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  2094. hapd = hostapd.add_ap(apdev[0], params)
  2095. dev[0].connect(ssid, psk="incorrect passphrase", scan_freq="2412",
  2096. wait_connect=False)
  2097. ev = hapd.wait_event(["AP-STA-POSSIBLE-PSK-MISMATCH"], timeout=10)
  2098. if ev is None:
  2099. raise Exception("No AP-STA-POSSIBLE-PSK-MISMATCH reported")
  2100. dev[0].dump_monitor()
  2101. hapd.disable()
  2102. hapd.set("wpa_passphrase", "incorrect passphrase")
  2103. hapd.enable()
  2104. dev[0].wait_connected(timeout=20)
  2105. @remote_compatible
  2106. def test_ap_wpa_ie_parsing(dev, apdev):
  2107. """WPA IE parsing"""
  2108. skip_with_fips(dev[0])
  2109. ssid = "test-wpa-psk"
  2110. passphrase = 'qwertyuiop'
  2111. params = hostapd.wpa_params(ssid=ssid, passphrase=passphrase)
  2112. hapd = hostapd.add_ap(apdev[0], params)
  2113. id = dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  2114. only_add_network=True)
  2115. tests = [ "dd040050f201",
  2116. "dd050050f20101",
  2117. "dd060050f2010100",
  2118. "dd060050f2010001",
  2119. "dd070050f201010000",
  2120. "dd080050f20101000050",
  2121. "dd090050f20101000050f2",
  2122. "dd0a0050f20101000050f202",
  2123. "dd0b0050f20101000050f20201",
  2124. "dd0c0050f20101000050f2020100",
  2125. "dd0c0050f20101000050f2020000",
  2126. "dd0c0050f20101000050f202ffff",
  2127. "dd0d0050f20101000050f202010000",
  2128. "dd0e0050f20101000050f20201000050",
  2129. "dd0f0050f20101000050f20201000050f2",
  2130. "dd100050f20101000050f20201000050f202",
  2131. "dd110050f20101000050f20201000050f20201",
  2132. "dd120050f20101000050f20201000050f2020100",
  2133. "dd120050f20101000050f20201000050f2020000",
  2134. "dd120050f20101000050f20201000050f202ffff",
  2135. "dd130050f20101000050f20201000050f202010000",
  2136. "dd140050f20101000050f20201000050f20201000050",
  2137. "dd150050f20101000050f20201000050f20201000050f2" ]
  2138. for t in tests:
  2139. try:
  2140. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 " + t):
  2141. raise Exception("VENDOR_ELEM_ADD failed")
  2142. dev[0].select_network(id)
  2143. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  2144. if ev is None:
  2145. raise Exception("Association rejection not reported")
  2146. dev[0].request("DISCONNECT")
  2147. dev[0].dump_monitor()
  2148. finally:
  2149. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  2150. tests = [ "dd170050f20101000050f20201000050f20201000050f202ff",
  2151. "dd180050f20101000050f20201000050f20201000050f202ffff",
  2152. "dd190050f20101000050f20201000050f20201000050f202ffffff" ]
  2153. for t in tests:
  2154. try:
  2155. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 " + t):
  2156. raise Exception("VENDOR_ELEM_ADD failed")
  2157. dev[0].select_network(id)
  2158. dev[0].wait_connected()
  2159. dev[0].request("DISCONNECT")
  2160. dev[0].dump_monitor()
  2161. finally:
  2162. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  2163. @remote_compatible
  2164. def test_ap_wpa2_psk_no_random(dev, apdev):
  2165. """WPA2-PSK AP and no random numbers available"""
  2166. ssid = "test-wpa2-psk"
  2167. passphrase = 'qwertyuiop'
  2168. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  2169. params = hostapd.wpa2_params(ssid=ssid)
  2170. params['wpa_psk'] = psk
  2171. hapd = hostapd.add_ap(apdev[0], params)
  2172. with fail_test(hapd, 1, "wpa_gmk_to_gtk"):
  2173. id = dev[0].connect(ssid, raw_psk=psk, scan_freq="2412",
  2174. wait_connect=False)
  2175. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  2176. if ev is None:
  2177. raise Exception("Disconnection event not reported")
  2178. dev[0].request("DISCONNECT")
  2179. dev[0].select_network(id, freq=2412)
  2180. dev[0].wait_connected()
  2181. @remote_compatible
  2182. def test_rsn_ie_proto_psk_sta(dev, apdev):
  2183. """RSN element protocol testing for PSK cases on STA side"""
  2184. bssid = apdev[0]['bssid']
  2185. ssid = "test-wpa2-psk"
  2186. passphrase = 'qwertyuiop'
  2187. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  2188. # This is the RSN element used normally by hostapd
  2189. params['own_ie_override'] = '30140100000fac040100000fac040100000fac020c00'
  2190. hapd = hostapd.add_ap(apdev[0], params)
  2191. if "FAIL" not in hapd.request("SET own_ie_override qwerty"):
  2192. raise Exception("Invalid own_ie_override value accepted")
  2193. id = dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  2194. tests = [ ('No RSN Capabilities field',
  2195. '30120100000fac040100000fac040100000fac02'),
  2196. ('Reserved RSN Capabilities bits set',
  2197. '30140100000fac040100000fac040100000fac023cff'),
  2198. ('Extra pairwise cipher suite (unsupported)',
  2199. '30180100000fac040200ffffffff000fac040100000fac020c00'),
  2200. ('Extra AKM suite (unsupported)',
  2201. '30180100000fac040100000fac040200ffffffff000fac020c00'),
  2202. ('PMKIDCount field included',
  2203. '30160100000fac040100000fac040100000fac020c000000'),
  2204. ('Unexpected Group Management Cipher Suite with PMF disabled',
  2205. '301a0100000fac040100000fac040100000fac020c000000000fac06'),
  2206. ('Extra octet after defined fields (future extensibility)',
  2207. '301b0100000fac040100000fac040100000fac020c000000000fac0600') ]
  2208. for txt,ie in tests:
  2209. dev[0].request("DISCONNECT")
  2210. dev[0].wait_disconnected()
  2211. logger.info(txt)
  2212. hapd.disable()
  2213. hapd.set('own_ie_override', ie)
  2214. hapd.enable()
  2215. dev[0].request("BSS_FLUSH 0")
  2216. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  2217. dev[0].select_network(id, freq=2412)
  2218. dev[0].wait_connected()
  2219. @remote_compatible
  2220. def test_ap_cli_order(dev, apdev):
  2221. ssid = "test-rsn-setup"
  2222. passphrase = 'zzzzzzzz'
  2223. hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
  2224. hapd.set('ssid', ssid)
  2225. hapd.set('wpa_passphrase', passphrase)
  2226. hapd.set('rsn_pairwise', 'CCMP')
  2227. hapd.set('wpa_key_mgmt', 'WPA-PSK')
  2228. hapd.set('wpa', '2')
  2229. hapd.enable()
  2230. cfg = hapd.get_config()
  2231. if cfg['group_cipher'] != 'CCMP':
  2232. raise Exception("Unexpected group_cipher: " + cfg['group_cipher'])
  2233. if cfg['rsn_pairwise_cipher'] != 'CCMP':
  2234. raise Exception("Unexpected rsn_pairwise_cipher: " + cfg['rsn_pairwise_cipher'])
  2235. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=30)
  2236. if ev is None:
  2237. raise Exception("AP startup timed out")
  2238. if "AP-ENABLED" not in ev:
  2239. raise Exception("AP startup failed")
  2240. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  2241. def set_test_assoc_ie(dev, ie):
  2242. if "OK" not in dev.request("TEST_ASSOC_IE " + ie):
  2243. raise Exception("Could not set TEST_ASSOC_IE")
  2244. @remote_compatible
  2245. def test_ap_wpa2_psk_assoc_rsn(dev, apdev):
  2246. """WPA2-PSK AP and association request RSN IE differences"""
  2247. ssid = "test-wpa2-psk"
  2248. passphrase = 'qwertyuiop'
  2249. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  2250. hapd = hostapd.add_ap(apdev[0], params)
  2251. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  2252. "30140100000fac040100000fac040100000fac020000"),
  2253. ("RSN IE without RSN Capabilities",
  2254. "30120100000fac040100000fac040100000fac02") ]
  2255. for title, ie in tests:
  2256. logger.info(title)
  2257. set_test_assoc_ie(dev[0], ie)
  2258. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  2259. dev[0].request("REMOVE_NETWORK all")
  2260. dev[0].wait_disconnected()
  2261. tests = [ ("WPA IE instead of RSN IE and only RSN enabled on AP",
  2262. "dd160050f20101000050f20201000050f20201000050f202", 40),
  2263. ("Empty RSN IE", "3000", 40),
  2264. ("RSN IE with truncated Version", "300101", 40),
  2265. ("RSN IE with only Version", "30020100", 43) ]
  2266. for title, ie, status in tests:
  2267. logger.info(title)
  2268. set_test_assoc_ie(dev[0], ie)
  2269. dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  2270. wait_connect=False)
  2271. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  2272. if ev is None:
  2273. raise Exception("Association rejection not reported")
  2274. if "status_code=" + str(status) not in ev:
  2275. raise Exception("Unexpected status code: " + ev)
  2276. dev[0].request("REMOVE_NETWORK all")
  2277. dev[0].dump_monitor()
  2278. def test_ap_wpa_psk_rsn_pairwise(dev, apdev):
  2279. """WPA-PSK AP and only rsn_pairwise set"""
  2280. params = { "ssid": "wpapsk", "wpa": "1", "wpa_key_mgmt": "WPA-PSK",
  2281. "rsn_pairwise": "TKIP", "wpa_passphrase": "1234567890" }
  2282. hapd = hostapd.add_ap(apdev[0], params)
  2283. dev[0].connect("wpapsk", psk="1234567890", proto="WPA", pairwise="TKIP",
  2284. scan_freq="2412")
  2285. def test_ap_wpa2_eapol_retry_limit(dev, apdev):
  2286. """WPA2-PSK EAPOL-Key retry limit configuration"""
  2287. ssid = "test-wpa2-psk"
  2288. passphrase = 'qwertyuiop'
  2289. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  2290. params['wpa_ptk_rekey'] = '2'
  2291. params['wpa_group_update_count'] = '1'
  2292. params['wpa_pairwise_update_count'] = '1'
  2293. hapd = hostapd.add_ap(apdev[0], params)
  2294. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  2295. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  2296. if ev is None:
  2297. raise Exception("PTK rekey timed out")
  2298. if "FAIL" not in hapd.request("SET wpa_group_update_count 0"):
  2299. raise Exception("Invalid wpa_group_update_count value accepted")
  2300. if "FAIL" not in hapd.request("SET wpa_pairwise_update_count 0"):
  2301. raise Exception("Invalid wpa_pairwise_update_count value accepted")