test_ap_eap.py 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456
  1. # -*- coding: utf-8 -*-
  2. # WPA2-Enterprise tests
  3. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  4. #
  5. # This software may be distributed under the terms of the BSD license.
  6. # See README for more details.
  7. import base64
  8. import binascii
  9. import time
  10. import subprocess
  11. import logging
  12. logger = logging.getLogger()
  13. import os
  14. import hwsim_utils
  15. import hostapd
  16. from utils import HwsimSkip
  17. from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations
  18. def check_hlr_auc_gw_support():
  19. if not os.path.exists("/tmp/hlr_auc_gw.sock"):
  20. raise HwsimSkip("No hlr_auc_gw available")
  21. def check_eap_capa(dev, method):
  22. res = dev.get_capability("eap")
  23. if method not in res:
  24. raise HwsimSkip("EAP method %s not supported in the build" % method)
  25. def check_subject_match_support(dev):
  26. tls = dev.request("GET tls_library")
  27. if not tls.startswith("OpenSSL"):
  28. raise HwsimSkip("subject_match not supported with this TLS library: " + tls)
  29. def check_altsubject_match_support(dev):
  30. tls = dev.request("GET tls_library")
  31. if not tls.startswith("OpenSSL"):
  32. raise HwsimSkip("altsubject_match not supported with this TLS library: " + tls)
  33. def check_domain_match_full(dev):
  34. tls = dev.request("GET tls_library")
  35. if not tls.startswith("OpenSSL"):
  36. raise HwsimSkip("domain_suffix_match requires full match with this TLS library: " + tls)
  37. def check_cert_probe_support(dev):
  38. tls = dev.request("GET tls_library")
  39. if not tls.startswith("OpenSSL"):
  40. raise HwsimSkip("Certificate probing not supported with this TLS library: " + tls)
  41. def read_pem(fname):
  42. with open(fname, "r") as f:
  43. lines = f.readlines()
  44. copy = False
  45. cert = ""
  46. for l in lines:
  47. if "-----END" in l:
  48. break
  49. if copy:
  50. cert = cert + l
  51. if "-----BEGIN" in l:
  52. copy = True
  53. return base64.b64decode(cert)
  54. def eap_connect(dev, ap, method, identity,
  55. sha256=False, expect_failure=False, local_error_report=False,
  56. **kwargs):
  57. hapd = hostapd.Hostapd(ap['ifname'])
  58. id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  59. eap=method, identity=identity,
  60. wait_connect=False, scan_freq="2412", ieee80211w="1",
  61. **kwargs)
  62. eap_check_auth(dev, method, True, sha256=sha256,
  63. expect_failure=expect_failure,
  64. local_error_report=local_error_report)
  65. if expect_failure:
  66. return id
  67. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  68. if ev is None:
  69. raise Exception("No connection event received from hostapd")
  70. return id
  71. def eap_check_auth(dev, method, initial, rsn=True, sha256=False,
  72. expect_failure=False, local_error_report=False):
  73. ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  74. if ev is None:
  75. raise Exception("Association and EAP start timed out")
  76. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  77. if ev is None:
  78. raise Exception("EAP method selection timed out")
  79. if method not in ev:
  80. raise Exception("Unexpected EAP method")
  81. if expect_failure:
  82. ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"])
  83. if ev is None:
  84. raise Exception("EAP failure timed out")
  85. ev = dev.wait_disconnected(timeout=10)
  86. if not local_error_report:
  87. if "reason=23" not in ev:
  88. raise Exception("Proper reason code for disconnection not reported")
  89. return
  90. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  91. if ev is None:
  92. raise Exception("EAP success timed out")
  93. if initial:
  94. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  95. else:
  96. ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=10)
  97. if ev is None:
  98. raise Exception("Association with the AP timed out")
  99. status = dev.get_status()
  100. if status["wpa_state"] != "COMPLETED":
  101. raise Exception("Connection not completed")
  102. if status["suppPortStatus"] != "Authorized":
  103. raise Exception("Port not authorized")
  104. if method not in status["selectedMethod"]:
  105. raise Exception("Incorrect EAP method status")
  106. if sha256:
  107. e = "WPA2-EAP-SHA256"
  108. elif rsn:
  109. e = "WPA2/IEEE 802.1X/EAP"
  110. else:
  111. e = "WPA/IEEE 802.1X/EAP"
  112. if status["key_mgmt"] != e:
  113. raise Exception("Unexpected key_mgmt status: " + status["key_mgmt"])
  114. return status
  115. def eap_reauth(dev, method, rsn=True, sha256=False, expect_failure=False):
  116. dev.request("REAUTHENTICATE")
  117. return eap_check_auth(dev, method, False, rsn=rsn, sha256=sha256,
  118. expect_failure=expect_failure)
  119. def test_ap_wpa2_eap_sim(dev, apdev):
  120. """WPA2-Enterprise connection using EAP-SIM"""
  121. check_hlr_auc_gw_support()
  122. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  123. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  124. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  125. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  126. hwsim_utils.test_connectivity(dev[0], hapd)
  127. eap_reauth(dev[0], "SIM")
  128. eap_connect(dev[1], apdev[0], "SIM", "1232010000000001",
  129. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  130. eap_connect(dev[2], apdev[0], "SIM", "1232010000000002",
  131. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  132. expect_failure=True)
  133. logger.info("Negative test with incorrect key")
  134. dev[0].request("REMOVE_NETWORK all")
  135. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  136. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  137. expect_failure=True)
  138. logger.info("Invalid GSM-Milenage key")
  139. dev[0].request("REMOVE_NETWORK all")
  140. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  141. password="ffdca4eda45b53cf0f12d7c9c3bc6a",
  142. expect_failure=True)
  143. logger.info("Invalid GSM-Milenage key(2)")
  144. dev[0].request("REMOVE_NETWORK all")
  145. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  146. password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581",
  147. expect_failure=True)
  148. logger.info("Invalid GSM-Milenage key(3)")
  149. dev[0].request("REMOVE_NETWORK all")
  150. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  151. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q",
  152. expect_failure=True)
  153. logger.info("Invalid GSM-Milenage key(4)")
  154. dev[0].request("REMOVE_NETWORK all")
  155. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  156. password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581",
  157. expect_failure=True)
  158. logger.info("Missing key configuration")
  159. dev[0].request("REMOVE_NETWORK all")
  160. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  161. expect_failure=True)
  162. def test_ap_wpa2_eap_sim_sql(dev, apdev, params):
  163. """WPA2-Enterprise connection using EAP-SIM (SQL)"""
  164. check_hlr_auc_gw_support()
  165. try:
  166. import sqlite3
  167. except ImportError:
  168. raise HwsimSkip("No sqlite3 module available")
  169. con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db"))
  170. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  171. params['auth_server_port'] = "1814"
  172. hostapd.add_ap(apdev[0]['ifname'], params)
  173. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  174. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  175. logger.info("SIM fast re-authentication")
  176. eap_reauth(dev[0], "SIM")
  177. logger.info("SIM full auth with pseudonym")
  178. with con:
  179. cur = con.cursor()
  180. cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'")
  181. eap_reauth(dev[0], "SIM")
  182. logger.info("SIM full auth with permanent identity")
  183. with con:
  184. cur = con.cursor()
  185. cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'")
  186. cur.execute("DELETE FROM pseudonyms WHERE permanent='1232010000000000'")
  187. eap_reauth(dev[0], "SIM")
  188. logger.info("SIM reauth with mismatching MK")
  189. with con:
  190. cur = con.cursor()
  191. cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='1232010000000000'")
  192. eap_reauth(dev[0], "SIM", expect_failure=True)
  193. dev[0].request("REMOVE_NETWORK all")
  194. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  195. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  196. with con:
  197. cur = con.cursor()
  198. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'")
  199. eap_reauth(dev[0], "SIM")
  200. with con:
  201. cur = con.cursor()
  202. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'")
  203. logger.info("SIM reauth with mismatching counter")
  204. eap_reauth(dev[0], "SIM")
  205. dev[0].request("REMOVE_NETWORK all")
  206. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  207. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  208. with con:
  209. cur = con.cursor()
  210. cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='1232010000000000'")
  211. logger.info("SIM reauth with max reauth count reached")
  212. eap_reauth(dev[0], "SIM")
  213. def test_ap_wpa2_eap_sim_config(dev, apdev):
  214. """EAP-SIM configuration options"""
  215. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  216. hostapd.add_ap(apdev[0]['ifname'], params)
  217. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
  218. identity="1232010000000000",
  219. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  220. phase1="sim_min_num_chal=1",
  221. wait_connect=False, scan_freq="2412")
  222. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10)
  223. if ev is None:
  224. raise Exception("No EAP error message seen")
  225. dev[0].request("REMOVE_NETWORK all")
  226. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
  227. identity="1232010000000000",
  228. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  229. phase1="sim_min_num_chal=4",
  230. wait_connect=False, scan_freq="2412")
  231. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10)
  232. if ev is None:
  233. raise Exception("No EAP error message seen (2)")
  234. dev[0].request("REMOVE_NETWORK all")
  235. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  236. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  237. phase1="sim_min_num_chal=2")
  238. eap_connect(dev[1], apdev[0], "SIM", "1232010000000000",
  239. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  240. anonymous_identity="345678")
  241. def test_ap_wpa2_eap_sim_ext(dev, apdev):
  242. """WPA2-Enterprise connection using EAP-SIM and external GSM auth"""
  243. try:
  244. _test_ap_wpa2_eap_sim_ext(dev, apdev)
  245. finally:
  246. dev[0].request("SET external_sim 0")
  247. def _test_ap_wpa2_eap_sim_ext(dev, apdev):
  248. check_hlr_auc_gw_support()
  249. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  250. hostapd.add_ap(apdev[0]['ifname'], params)
  251. dev[0].request("SET external_sim 1")
  252. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  253. identity="1232010000000000",
  254. wait_connect=False, scan_freq="2412")
  255. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  256. if ev is None:
  257. raise Exception("Network connected timed out")
  258. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  259. if ev is None:
  260. raise Exception("Wait for external SIM processing request timed out")
  261. p = ev.split(':', 2)
  262. if p[1] != "GSM-AUTH":
  263. raise Exception("Unexpected CTRL-REQ-SIM type")
  264. rid = p[0].split('-')[3]
  265. # IK:CK:RES
  266. resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344"
  267. # This will fail during processing, but the ctrl_iface command succeeds
  268. dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp)
  269. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  270. if ev is None:
  271. raise Exception("EAP failure not reported")
  272. dev[0].request("DISCONNECT")
  273. dev[0].select_network(id, freq="2412")
  274. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  275. if ev is None:
  276. raise Exception("Wait for external SIM processing request timed out")
  277. p = ev.split(':', 2)
  278. if p[1] != "GSM-AUTH":
  279. raise Exception("Unexpected CTRL-REQ-SIM type")
  280. rid = p[0].split('-')[3]
  281. # This will fail during GSM auth validation
  282. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:q"):
  283. raise Exception("CTRL-RSP-SIM failed")
  284. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  285. if ev is None:
  286. raise Exception("EAP failure not reported")
  287. dev[0].request("DISCONNECT")
  288. dev[0].select_network(id, freq="2412")
  289. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  290. if ev is None:
  291. raise Exception("Wait for external SIM processing request timed out")
  292. p = ev.split(':', 2)
  293. if p[1] != "GSM-AUTH":
  294. raise Exception("Unexpected CTRL-REQ-SIM type")
  295. rid = p[0].split('-')[3]
  296. # This will fail during GSM auth validation
  297. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:34"):
  298. raise Exception("CTRL-RSP-SIM failed")
  299. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  300. if ev is None:
  301. raise Exception("EAP failure not reported")
  302. dev[0].request("DISCONNECT")
  303. dev[0].select_network(id, freq="2412")
  304. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  305. if ev is None:
  306. raise Exception("Wait for external SIM processing request timed out")
  307. p = ev.split(':', 2)
  308. if p[1] != "GSM-AUTH":
  309. raise Exception("Unexpected CTRL-REQ-SIM type")
  310. rid = p[0].split('-')[3]
  311. # This will fail during GSM auth validation
  312. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677"):
  313. raise Exception("CTRL-RSP-SIM failed")
  314. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  315. if ev is None:
  316. raise Exception("EAP failure not reported")
  317. dev[0].request("DISCONNECT")
  318. dev[0].select_network(id, freq="2412")
  319. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  320. if ev is None:
  321. raise Exception("Wait for external SIM processing request timed out")
  322. p = ev.split(':', 2)
  323. if p[1] != "GSM-AUTH":
  324. raise Exception("Unexpected CTRL-REQ-SIM type")
  325. rid = p[0].split('-')[3]
  326. # This will fail during GSM auth validation
  327. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:q"):
  328. raise Exception("CTRL-RSP-SIM failed")
  329. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  330. if ev is None:
  331. raise Exception("EAP failure not reported")
  332. dev[0].request("DISCONNECT")
  333. dev[0].select_network(id, freq="2412")
  334. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  335. if ev is None:
  336. raise Exception("Wait for external SIM processing request timed out")
  337. p = ev.split(':', 2)
  338. if p[1] != "GSM-AUTH":
  339. raise Exception("Unexpected CTRL-REQ-SIM type")
  340. rid = p[0].split('-')[3]
  341. # This will fail during GSM auth validation
  342. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233"):
  343. raise Exception("CTRL-RSP-SIM failed")
  344. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  345. if ev is None:
  346. raise Exception("EAP failure not reported")
  347. dev[0].request("DISCONNECT")
  348. dev[0].select_network(id, freq="2412")
  349. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  350. if ev is None:
  351. raise Exception("Wait for external SIM processing request timed out")
  352. p = ev.split(':', 2)
  353. if p[1] != "GSM-AUTH":
  354. raise Exception("Unexpected CTRL-REQ-SIM type")
  355. rid = p[0].split('-')[3]
  356. # This will fail during GSM auth validation
  357. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233:q"):
  358. raise Exception("CTRL-RSP-SIM failed")
  359. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  360. if ev is None:
  361. raise Exception("EAP failure not reported")
  362. def test_ap_wpa2_eap_aka(dev, apdev):
  363. """WPA2-Enterprise connection using EAP-AKA"""
  364. check_hlr_auc_gw_support()
  365. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  366. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  367. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  368. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  369. hwsim_utils.test_connectivity(dev[0], hapd)
  370. eap_reauth(dev[0], "AKA")
  371. logger.info("Negative test with incorrect key")
  372. dev[0].request("REMOVE_NETWORK all")
  373. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  374. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  375. expect_failure=True)
  376. logger.info("Invalid Milenage key")
  377. dev[0].request("REMOVE_NETWORK all")
  378. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  379. password="ffdca4eda45b53cf0f12d7c9c3bc6a",
  380. expect_failure=True)
  381. logger.info("Invalid Milenage key(2)")
  382. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  383. password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  384. expect_failure=True)
  385. logger.info("Invalid Milenage key(3)")
  386. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  387. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q:000000000123",
  388. expect_failure=True)
  389. logger.info("Invalid Milenage key(4)")
  390. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  391. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:00000000012q",
  392. expect_failure=True)
  393. logger.info("Invalid Milenage key(5)")
  394. dev[0].request("REMOVE_NETWORK all")
  395. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  396. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581q000000000123",
  397. expect_failure=True)
  398. logger.info("Invalid Milenage key(6)")
  399. dev[0].request("REMOVE_NETWORK all")
  400. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  401. password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581q000000000123",
  402. expect_failure=True)
  403. logger.info("Missing key configuration")
  404. dev[0].request("REMOVE_NETWORK all")
  405. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  406. expect_failure=True)
  407. def test_ap_wpa2_eap_aka_sql(dev, apdev, params):
  408. """WPA2-Enterprise connection using EAP-AKA (SQL)"""
  409. check_hlr_auc_gw_support()
  410. try:
  411. import sqlite3
  412. except ImportError:
  413. raise HwsimSkip("No sqlite3 module available")
  414. con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db"))
  415. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  416. params['auth_server_port'] = "1814"
  417. hostapd.add_ap(apdev[0]['ifname'], params)
  418. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  419. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  420. logger.info("AKA fast re-authentication")
  421. eap_reauth(dev[0], "AKA")
  422. logger.info("AKA full auth with pseudonym")
  423. with con:
  424. cur = con.cursor()
  425. cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'")
  426. eap_reauth(dev[0], "AKA")
  427. logger.info("AKA full auth with permanent identity")
  428. with con:
  429. cur = con.cursor()
  430. cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'")
  431. cur.execute("DELETE FROM pseudonyms WHERE permanent='0232010000000000'")
  432. eap_reauth(dev[0], "AKA")
  433. logger.info("AKA reauth with mismatching MK")
  434. with con:
  435. cur = con.cursor()
  436. cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='0232010000000000'")
  437. eap_reauth(dev[0], "AKA", expect_failure=True)
  438. dev[0].request("REMOVE_NETWORK all")
  439. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  440. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  441. with con:
  442. cur = con.cursor()
  443. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'")
  444. eap_reauth(dev[0], "AKA")
  445. with con:
  446. cur = con.cursor()
  447. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'")
  448. logger.info("AKA reauth with mismatching counter")
  449. eap_reauth(dev[0], "AKA")
  450. dev[0].request("REMOVE_NETWORK all")
  451. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  452. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  453. with con:
  454. cur = con.cursor()
  455. cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='0232010000000000'")
  456. logger.info("AKA reauth with max reauth count reached")
  457. eap_reauth(dev[0], "AKA")
  458. def test_ap_wpa2_eap_aka_config(dev, apdev):
  459. """EAP-AKA configuration options"""
  460. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  461. hostapd.add_ap(apdev[0]['ifname'], params)
  462. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  463. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  464. anonymous_identity="2345678")
  465. def test_ap_wpa2_eap_aka_ext(dev, apdev):
  466. """WPA2-Enterprise connection using EAP-AKA and external UMTS auth"""
  467. try:
  468. _test_ap_wpa2_eap_aka_ext(dev, apdev)
  469. finally:
  470. dev[0].request("SET external_sim 0")
  471. def _test_ap_wpa2_eap_aka_ext(dev, apdev):
  472. check_hlr_auc_gw_support()
  473. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  474. hostapd.add_ap(apdev[0]['ifname'], params)
  475. dev[0].request("SET external_sim 1")
  476. id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP",
  477. identity="0232010000000000",
  478. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  479. wait_connect=False, scan_freq="2412")
  480. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  481. if ev is None:
  482. raise Exception("Network connected timed out")
  483. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  484. if ev is None:
  485. raise Exception("Wait for external SIM processing request timed out")
  486. p = ev.split(':', 2)
  487. if p[1] != "UMTS-AUTH":
  488. raise Exception("Unexpected CTRL-REQ-SIM type")
  489. rid = p[0].split('-')[3]
  490. # IK:CK:RES
  491. resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344"
  492. # This will fail during processing, but the ctrl_iface command succeeds
  493. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  494. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  495. if ev is None:
  496. raise Exception("EAP failure not reported")
  497. dev[0].request("DISCONNECT")
  498. dev[0].request("REASSOCIATE")
  499. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  500. if ev is None:
  501. raise Exception("Wait for external SIM processing request timed out")
  502. p = ev.split(':', 2)
  503. if p[1] != "UMTS-AUTH":
  504. raise Exception("Unexpected CTRL-REQ-SIM type")
  505. rid = p[0].split('-')[3]
  506. # This will fail during UMTS auth validation
  507. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp):
  508. raise Exception("CTRL-RSP-SIM failed")
  509. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  510. if ev is None:
  511. raise Exception("EAP failure not reported")
  512. dev[0].request("DISCONNECT")
  513. dev[0].select_network(id, freq="2412")
  514. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  515. if ev is None:
  516. raise Exception("Wait for external SIM processing request timed out")
  517. p = ev.split(':', 2)
  518. if p[1] != "UMTS-AUTH":
  519. raise Exception("Unexpected CTRL-REQ-SIM type")
  520. rid = p[0].split('-')[3]
  521. # This will fail during UMTS auth validation
  522. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"):
  523. raise Exception("CTRL-RSP-SIM failed")
  524. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  525. if ev is None:
  526. raise Exception("Wait for external SIM processing request timed out")
  527. p = ev.split(':', 2)
  528. if p[1] != "UMTS-AUTH":
  529. raise Exception("Unexpected CTRL-REQ-SIM type")
  530. rid = p[0].split('-')[3]
  531. # This will fail during UMTS auth validation
  532. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:12"):
  533. raise Exception("CTRL-RSP-SIM failed")
  534. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  535. if ev is None:
  536. raise Exception("EAP failure not reported")
  537. dev[0].request("DISCONNECT")
  538. dev[0].select_network(id, freq="2412")
  539. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  540. if ev is None:
  541. raise Exception("Wait for external SIM processing request timed out")
  542. p = ev.split(':', 2)
  543. if p[1] != "UMTS-AUTH":
  544. raise Exception("Unexpected CTRL-REQ-SIM type")
  545. rid = p[0].split('-')[3]
  546. # This will fail during UMTS auth validation
  547. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:34"):
  548. raise Exception("CTRL-RSP-SIM failed")
  549. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  550. if ev is None:
  551. raise Exception("EAP failure not reported")
  552. dev[0].request("DISCONNECT")
  553. dev[0].select_network(id, freq="2412")
  554. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  555. if ev is None:
  556. raise Exception("Wait for external SIM processing request timed out")
  557. p = ev.split(':', 2)
  558. if p[1] != "UMTS-AUTH":
  559. raise Exception("Unexpected CTRL-REQ-SIM type")
  560. rid = p[0].split('-')[3]
  561. # This will fail during UMTS auth validation
  562. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344"):
  563. raise Exception("CTRL-RSP-SIM failed")
  564. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  565. if ev is None:
  566. raise Exception("EAP failure not reported")
  567. dev[0].request("DISCONNECT")
  568. dev[0].select_network(id, freq="2412")
  569. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  570. if ev is None:
  571. raise Exception("Wait for external SIM processing request timed out")
  572. p = ev.split(':', 2)
  573. if p[1] != "UMTS-AUTH":
  574. raise Exception("Unexpected CTRL-REQ-SIM type")
  575. rid = p[0].split('-')[3]
  576. # This will fail during UMTS auth validation
  577. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344"):
  578. raise Exception("CTRL-RSP-SIM failed")
  579. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  580. if ev is None:
  581. raise Exception("EAP failure not reported")
  582. dev[0].request("DISCONNECT")
  583. dev[0].select_network(id, freq="2412")
  584. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  585. if ev is None:
  586. raise Exception("Wait for external SIM processing request timed out")
  587. p = ev.split(':', 2)
  588. if p[1] != "UMTS-AUTH":
  589. raise Exception("Unexpected CTRL-REQ-SIM type")
  590. rid = p[0].split('-')[3]
  591. # This will fail during UMTS auth validation
  592. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344"):
  593. raise Exception("CTRL-RSP-SIM failed")
  594. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  595. if ev is None:
  596. raise Exception("EAP failure not reported")
  597. dev[0].request("DISCONNECT")
  598. dev[0].select_network(id, freq="2412")
  599. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  600. if ev is None:
  601. raise Exception("Wait for external SIM processing request timed out")
  602. p = ev.split(':', 2)
  603. if p[1] != "UMTS-AUTH":
  604. raise Exception("Unexpected CTRL-REQ-SIM type")
  605. rid = p[0].split('-')[3]
  606. # This will fail during UMTS auth validation
  607. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344"):
  608. raise Exception("CTRL-RSP-SIM failed")
  609. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  610. if ev is None:
  611. raise Exception("EAP failure not reported")
  612. dev[0].request("DISCONNECT")
  613. dev[0].select_network(id, freq="2412")
  614. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  615. if ev is None:
  616. raise Exception("Wait for external SIM processing request timed out")
  617. p = ev.split(':', 2)
  618. if p[1] != "UMTS-AUTH":
  619. raise Exception("Unexpected CTRL-REQ-SIM type")
  620. rid = p[0].split('-')[3]
  621. # This will fail during UMTS auth validation
  622. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q"):
  623. raise Exception("CTRL-RSP-SIM failed")
  624. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  625. if ev is None:
  626. raise Exception("EAP failure not reported")
  627. def test_ap_wpa2_eap_aka_prime(dev, apdev):
  628. """WPA2-Enterprise connection using EAP-AKA'"""
  629. check_hlr_auc_gw_support()
  630. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  631. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  632. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  633. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  634. hwsim_utils.test_connectivity(dev[0], hapd)
  635. eap_reauth(dev[0], "AKA'")
  636. logger.info("EAP-AKA' bidding protection when EAP-AKA enabled as well")
  637. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="AKA' AKA",
  638. identity="6555444333222111@both",
  639. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  640. wait_connect=False, scan_freq="2412")
  641. dev[1].wait_connected(timeout=15)
  642. logger.info("Negative test with incorrect key")
  643. dev[0].request("REMOVE_NETWORK all")
  644. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  645. password="ff22250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  646. expect_failure=True)
  647. def test_ap_wpa2_eap_aka_prime_sql(dev, apdev, params):
  648. """WPA2-Enterprise connection using EAP-AKA' (SQL)"""
  649. check_hlr_auc_gw_support()
  650. try:
  651. import sqlite3
  652. except ImportError:
  653. raise HwsimSkip("No sqlite3 module available")
  654. con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db"))
  655. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  656. params['auth_server_port'] = "1814"
  657. hostapd.add_ap(apdev[0]['ifname'], params)
  658. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  659. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  660. logger.info("AKA' fast re-authentication")
  661. eap_reauth(dev[0], "AKA'")
  662. logger.info("AKA' full auth with pseudonym")
  663. with con:
  664. cur = con.cursor()
  665. cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'")
  666. eap_reauth(dev[0], "AKA'")
  667. logger.info("AKA' full auth with permanent identity")
  668. with con:
  669. cur = con.cursor()
  670. cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'")
  671. cur.execute("DELETE FROM pseudonyms WHERE permanent='6555444333222111'")
  672. eap_reauth(dev[0], "AKA'")
  673. logger.info("AKA' reauth with mismatching k_aut")
  674. with con:
  675. cur = con.cursor()
  676. cur.execute("UPDATE reauth SET k_aut='0000000000000000000000000000000000000000000000000000000000000000' WHERE permanent='6555444333222111'")
  677. eap_reauth(dev[0], "AKA'", expect_failure=True)
  678. dev[0].request("REMOVE_NETWORK all")
  679. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  680. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  681. with con:
  682. cur = con.cursor()
  683. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'")
  684. eap_reauth(dev[0], "AKA'")
  685. with con:
  686. cur = con.cursor()
  687. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'")
  688. logger.info("AKA' reauth with mismatching counter")
  689. eap_reauth(dev[0], "AKA'")
  690. dev[0].request("REMOVE_NETWORK all")
  691. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  692. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  693. with con:
  694. cur = con.cursor()
  695. cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='6555444333222111'")
  696. logger.info("AKA' reauth with max reauth count reached")
  697. eap_reauth(dev[0], "AKA'")
  698. def test_ap_wpa2_eap_ttls_pap(dev, apdev):
  699. """WPA2-Enterprise connection using EAP-TTLS/PAP"""
  700. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  701. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  702. key_mgmt = hapd.get_config()['key_mgmt']
  703. if key_mgmt.split(' ')[0] != "WPA-EAP":
  704. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  705. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  706. anonymous_identity="ttls", password="password",
  707. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  708. hwsim_utils.test_connectivity(dev[0], hapd)
  709. eap_reauth(dev[0], "TTLS")
  710. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"),
  711. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ])
  712. def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev):
  713. """WPA2-Enterprise connection using EAP-TTLS/PAP and (alt)subject_match"""
  714. check_subject_match_support(dev[0])
  715. check_altsubject_match_support(dev[0])
  716. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  717. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  718. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  719. anonymous_identity="ttls", password="password",
  720. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  721. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  722. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/")
  723. eap_reauth(dev[0], "TTLS")
  724. def test_ap_wpa2_eap_ttls_pap_incorrect_password(dev, apdev):
  725. """WPA2-Enterprise connection using EAP-TTLS/PAP - incorrect password"""
  726. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  727. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  728. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  729. anonymous_identity="ttls", password="wrong",
  730. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  731. expect_failure=True)
  732. eap_connect(dev[1], apdev[0], "TTLS", "user",
  733. anonymous_identity="ttls", password="password",
  734. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  735. expect_failure=True)
  736. def test_ap_wpa2_eap_ttls_chap(dev, apdev):
  737. """WPA2-Enterprise connection using EAP-TTLS/CHAP"""
  738. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  739. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  740. eap_connect(dev[0], apdev[0], "TTLS", "chap user",
  741. anonymous_identity="ttls", password="password",
  742. ca_cert="auth_serv/ca.der", phase2="auth=CHAP")
  743. hwsim_utils.test_connectivity(dev[0], hapd)
  744. eap_reauth(dev[0], "TTLS")
  745. def test_ap_wpa2_eap_ttls_chap_altsubject_match(dev, apdev):
  746. """WPA2-Enterprise connection using EAP-TTLS/CHAP"""
  747. check_altsubject_match_support(dev[0])
  748. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  749. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  750. eap_connect(dev[0], apdev[0], "TTLS", "chap user",
  751. anonymous_identity="ttls", password="password",
  752. ca_cert="auth_serv/ca.der", phase2="auth=CHAP",
  753. altsubject_match="EMAIL:noone@example.com;URI:http://example.com/;DNS:server.w1.fi")
  754. eap_reauth(dev[0], "TTLS")
  755. def test_ap_wpa2_eap_ttls_chap_incorrect_password(dev, apdev):
  756. """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password"""
  757. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  758. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  759. eap_connect(dev[0], apdev[0], "TTLS", "chap user",
  760. anonymous_identity="ttls", password="wrong",
  761. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP",
  762. expect_failure=True)
  763. eap_connect(dev[1], apdev[0], "TTLS", "user",
  764. anonymous_identity="ttls", password="password",
  765. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP",
  766. expect_failure=True)
  767. def test_ap_wpa2_eap_ttls_mschap(dev, apdev):
  768. """WPA2-Enterprise connection using EAP-TTLS/MSCHAP"""
  769. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  770. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  771. eap_connect(dev[0], apdev[0], "TTLS", "mschap user",
  772. anonymous_identity="ttls", password="password",
  773. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  774. domain_suffix_match="server.w1.fi")
  775. hwsim_utils.test_connectivity(dev[0], hapd)
  776. eap_reauth(dev[0], "TTLS")
  777. dev[0].request("REMOVE_NETWORK all")
  778. eap_connect(dev[0], apdev[0], "TTLS", "mschap user",
  779. anonymous_identity="ttls", password="password",
  780. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  781. fragment_size="200")
  782. def test_ap_wpa2_eap_ttls_mschap_incorrect_password(dev, apdev):
  783. """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password"""
  784. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  785. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  786. eap_connect(dev[0], apdev[0], "TTLS", "mschap user",
  787. anonymous_identity="ttls", password="wrong",
  788. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  789. expect_failure=True)
  790. eap_connect(dev[1], apdev[0], "TTLS", "user",
  791. anonymous_identity="ttls", password="password",
  792. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  793. expect_failure=True)
  794. eap_connect(dev[2], apdev[0], "TTLS", "no such user",
  795. anonymous_identity="ttls", password="password",
  796. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  797. expect_failure=True)
  798. def test_ap_wpa2_eap_ttls_mschapv2(dev, apdev):
  799. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2"""
  800. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  801. hostapd.add_ap(apdev[0]['ifname'], params)
  802. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  803. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  804. anonymous_identity="ttls", password="password",
  805. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  806. domain_suffix_match="server.w1.fi")
  807. hwsim_utils.test_connectivity(dev[0], hapd)
  808. sta1 = hapd.get_sta(dev[0].p2p_interface_addr())
  809. eapol1 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol")
  810. eap_reauth(dev[0], "TTLS")
  811. sta2 = hapd.get_sta(dev[0].p2p_interface_addr())
  812. eapol2 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol")
  813. if int(sta2['dot1xAuthEapolFramesRx']) <= int(sta1['dot1xAuthEapolFramesRx']):
  814. raise Exception("dot1xAuthEapolFramesRx did not increase")
  815. if int(eapol2['authAuthEapStartsWhileAuthenticated']) < 1:
  816. raise Exception("authAuthEapStartsWhileAuthenticated did not increase")
  817. if int(eapol2['backendAuthSuccesses']) <= int(eapol1['backendAuthSuccesses']):
  818. raise Exception("backendAuthSuccesses did not increase")
  819. logger.info("Password as hash value")
  820. dev[0].request("REMOVE_NETWORK all")
  821. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  822. anonymous_identity="ttls",
  823. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  824. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  825. def test_ap_wpa2_eap_ttls_mschapv2_suffix_match(dev, apdev):
  826. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2"""
  827. check_domain_match_full(dev[0])
  828. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  829. hostapd.add_ap(apdev[0]['ifname'], params)
  830. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  831. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  832. anonymous_identity="ttls", password="password",
  833. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  834. domain_suffix_match="w1.fi")
  835. hwsim_utils.test_connectivity(dev[0], hapd)
  836. eap_reauth(dev[0], "TTLS")
  837. def test_ap_wpa2_eap_ttls_mschapv2_incorrect_password(dev, apdev):
  838. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 - incorrect password"""
  839. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  840. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  841. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  842. anonymous_identity="ttls", password="password1",
  843. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  844. expect_failure=True)
  845. eap_connect(dev[1], apdev[0], "TTLS", "user",
  846. anonymous_identity="ttls", password="password",
  847. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  848. expect_failure=True)
  849. def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev):
  850. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 and UTF-8 password"""
  851. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  852. hostapd.add_ap(apdev[0]['ifname'], params)
  853. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  854. eap_connect(dev[0], apdev[0], "TTLS", "utf8-user-hash",
  855. anonymous_identity="ttls", password="secret-åäö-€-password",
  856. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  857. eap_connect(dev[1], apdev[0], "TTLS", "utf8-user",
  858. anonymous_identity="ttls",
  859. password_hex="hash:bd5844fad2489992da7fe8c5a01559cf",
  860. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  861. def test_ap_wpa2_eap_ttls_eap_gtc(dev, apdev):
  862. """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC"""
  863. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  864. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  865. eap_connect(dev[0], apdev[0], "TTLS", "user",
  866. anonymous_identity="ttls", password="password",
  867. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC")
  868. hwsim_utils.test_connectivity(dev[0], hapd)
  869. eap_reauth(dev[0], "TTLS")
  870. def test_ap_wpa2_eap_ttls_eap_md5(dev, apdev):
  871. """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5"""
  872. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  873. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  874. eap_connect(dev[0], apdev[0], "TTLS", "user",
  875. anonymous_identity="ttls", password="password",
  876. ca_cert="auth_serv/ca.pem", phase2="autheap=MD5")
  877. hwsim_utils.test_connectivity(dev[0], hapd)
  878. eap_reauth(dev[0], "TTLS")
  879. def test_ap_wpa2_eap_ttls_eap_mschapv2(dev, apdev):
  880. """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2"""
  881. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  882. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  883. eap_connect(dev[0], apdev[0], "TTLS", "user",
  884. anonymous_identity="ttls", password="password",
  885. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2")
  886. hwsim_utils.test_connectivity(dev[0], hapd)
  887. eap_reauth(dev[0], "TTLS")
  888. logger.info("Negative test with incorrect password")
  889. dev[0].request("REMOVE_NETWORK all")
  890. eap_connect(dev[0], apdev[0], "TTLS", "user",
  891. anonymous_identity="ttls", password="password1",
  892. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  893. expect_failure=True)
  894. def test_ap_wpa2_eap_ttls_eap_aka(dev, apdev):
  895. """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA"""
  896. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  897. hostapd.add_ap(apdev[0]['ifname'], params)
  898. eap_connect(dev[0], apdev[0], "TTLS", "0232010000000000",
  899. anonymous_identity="0232010000000000@ttls",
  900. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  901. ca_cert="auth_serv/ca.pem", phase2="autheap=AKA")
  902. def test_ap_wpa2_eap_peap_eap_aka(dev, apdev):
  903. """WPA2-Enterprise connection using EAP-PEAP/EAP-AKA"""
  904. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  905. hostapd.add_ap(apdev[0]['ifname'], params)
  906. eap_connect(dev[0], apdev[0], "PEAP", "0232010000000000",
  907. anonymous_identity="0232010000000000@peap",
  908. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  909. ca_cert="auth_serv/ca.pem", phase2="auth=AKA")
  910. def test_ap_wpa2_eap_fast_eap_aka(dev, apdev):
  911. """WPA2-Enterprise connection using EAP-FAST/EAP-AKA"""
  912. check_eap_capa(dev[0], "FAST")
  913. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  914. hostapd.add_ap(apdev[0]['ifname'], params)
  915. eap_connect(dev[0], apdev[0], "FAST", "0232010000000000",
  916. anonymous_identity="0232010000000000@fast",
  917. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  918. phase1="fast_provisioning=2",
  919. pac_file="blob://fast_pac_auth_aka",
  920. ca_cert="auth_serv/ca.pem", phase2="auth=AKA")
  921. def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev):
  922. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  923. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  924. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  925. eap_connect(dev[0], apdev[0], "PEAP", "user",
  926. anonymous_identity="peap", password="password",
  927. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  928. hwsim_utils.test_connectivity(dev[0], hapd)
  929. eap_reauth(dev[0], "PEAP")
  930. dev[0].request("REMOVE_NETWORK all")
  931. eap_connect(dev[0], apdev[0], "PEAP", "user",
  932. anonymous_identity="peap", password="password",
  933. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  934. fragment_size="200")
  935. logger.info("Password as hash value")
  936. dev[0].request("REMOVE_NETWORK all")
  937. eap_connect(dev[0], apdev[0], "PEAP", "user",
  938. anonymous_identity="peap",
  939. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  940. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  941. logger.info("Negative test with incorrect password")
  942. dev[0].request("REMOVE_NETWORK all")
  943. eap_connect(dev[0], apdev[0], "PEAP", "user",
  944. anonymous_identity="peap", password="password1",
  945. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  946. expect_failure=True)
  947. def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev):
  948. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding"""
  949. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  950. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  951. eap_connect(dev[0], apdev[0], "PEAP", "user", password="password",
  952. ca_cert="auth_serv/ca.pem",
  953. phase1="peapver=0 crypto_binding=2",
  954. phase2="auth=MSCHAPV2")
  955. hwsim_utils.test_connectivity(dev[0], hapd)
  956. eap_reauth(dev[0], "PEAP")
  957. eap_connect(dev[1], apdev[0], "PEAP", "user", password="password",
  958. ca_cert="auth_serv/ca.pem",
  959. phase1="peapver=0 crypto_binding=1",
  960. phase2="auth=MSCHAPV2")
  961. eap_connect(dev[2], apdev[0], "PEAP", "user", password="password",
  962. ca_cert="auth_serv/ca.pem",
  963. phase1="peapver=0 crypto_binding=0",
  964. phase2="auth=MSCHAPV2")
  965. def test_ap_wpa2_eap_peap_params(dev, apdev):
  966. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and various parameters"""
  967. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  968. hostapd.add_ap(apdev[0]['ifname'], params)
  969. eap_connect(dev[0], apdev[0], "PEAP", "user",
  970. anonymous_identity="peap", password="password",
  971. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  972. phase1="peapver=0 peaplabel=1",
  973. expect_failure=True)
  974. dev[0].request("REMOVE_NETWORK all")
  975. eap_connect(dev[1], apdev[0], "PEAP", "user", password="password",
  976. ca_cert="auth_serv/ca.pem",
  977. phase1="peap_outer_success=1",
  978. phase2="auth=MSCHAPV2")
  979. eap_connect(dev[2], apdev[0], "PEAP", "user", password="password",
  980. ca_cert="auth_serv/ca.pem",
  981. phase1="peap_outer_success=2",
  982. phase2="auth=MSCHAPV2")
  983. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  984. identity="user",
  985. anonymous_identity="peap", password="password",
  986. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  987. phase1="peapver=1 peaplabel=1",
  988. wait_connect=False, scan_freq="2412")
  989. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  990. if ev is None:
  991. raise Exception("No EAP success seen")
  992. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  993. if ev is not None:
  994. raise Exception("Unexpected connection")
  995. def test_ap_wpa2_eap_peap_eap_tls(dev, apdev):
  996. """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS"""
  997. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  998. hostapd.add_ap(apdev[0]['ifname'], params)
  999. eap_connect(dev[0], apdev[0], "PEAP", "cert user",
  1000. ca_cert="auth_serv/ca.pem", phase2="auth=TLS",
  1001. ca_cert2="auth_serv/ca.pem",
  1002. client_cert2="auth_serv/user.pem",
  1003. private_key2="auth_serv/user.key")
  1004. eap_reauth(dev[0], "PEAP")
  1005. def test_ap_wpa2_eap_tls(dev, apdev):
  1006. """WPA2-Enterprise connection using EAP-TLS"""
  1007. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1008. hostapd.add_ap(apdev[0]['ifname'], params)
  1009. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1010. client_cert="auth_serv/user.pem",
  1011. private_key="auth_serv/user.key")
  1012. eap_reauth(dev[0], "TLS")
  1013. def test_ap_wpa2_eap_tls_blob(dev, apdev):
  1014. """WPA2-Enterprise connection using EAP-TLS and config blobs"""
  1015. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1016. hostapd.add_ap(apdev[0]['ifname'], params)
  1017. cert = read_pem("auth_serv/ca.pem")
  1018. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1019. raise Exception("Could not set cacert blob")
  1020. cert = read_pem("auth_serv/user.pem")
  1021. if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")):
  1022. raise Exception("Could not set usercert blob")
  1023. key = read_pem("auth_serv/user.rsa-key")
  1024. if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")):
  1025. raise Exception("Could not set cacert blob")
  1026. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert",
  1027. client_cert="blob://usercert",
  1028. private_key="blob://userkey")
  1029. def test_ap_wpa2_eap_tls_pkcs12(dev, apdev):
  1030. """WPA2-Enterprise connection using EAP-TLS and PKCS#12"""
  1031. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1032. hostapd.add_ap(apdev[0]['ifname'], params)
  1033. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1034. private_key="auth_serv/user.pkcs12",
  1035. private_key_passwd="whatever")
  1036. dev[0].request("REMOVE_NETWORK all")
  1037. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1038. identity="tls user",
  1039. ca_cert="auth_serv/ca.pem",
  1040. private_key="auth_serv/user.pkcs12",
  1041. wait_connect=False, scan_freq="2412")
  1042. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"])
  1043. if ev is None:
  1044. raise Exception("Request for private key passphrase timed out")
  1045. id = ev.split(':')[0].split('-')[-1]
  1046. dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever")
  1047. dev[0].wait_connected(timeout=10)
  1048. def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev):
  1049. """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob"""
  1050. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1051. hostapd.add_ap(apdev[0]['ifname'], params)
  1052. cert = read_pem("auth_serv/ca.pem")
  1053. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1054. raise Exception("Could not set cacert blob")
  1055. with open("auth_serv/user.pkcs12", "rb") as f:
  1056. if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")):
  1057. raise Exception("Could not set pkcs12 blob")
  1058. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert",
  1059. private_key="blob://pkcs12",
  1060. private_key_passwd="whatever")
  1061. def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev):
  1062. """WPA2-Enterprise negative test - incorrect trust root"""
  1063. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1064. hostapd.add_ap(apdev[0]['ifname'], params)
  1065. cert = read_pem("auth_serv/ca-incorrect.pem")
  1066. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1067. raise Exception("Could not set cacert blob")
  1068. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1069. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1070. password="password", phase2="auth=MSCHAPV2",
  1071. ca_cert="blob://cacert",
  1072. wait_connect=False, scan_freq="2412")
  1073. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1074. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1075. password="password", phase2="auth=MSCHAPV2",
  1076. ca_cert="auth_serv/ca-incorrect.pem",
  1077. wait_connect=False, scan_freq="2412")
  1078. for dev in (dev[0], dev[1]):
  1079. ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1080. if ev is None:
  1081. raise Exception("Association and EAP start timed out")
  1082. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1083. if ev is None:
  1084. raise Exception("EAP method selection timed out")
  1085. if "TTLS" not in ev:
  1086. raise Exception("Unexpected EAP method")
  1087. ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1088. "CTRL-EVENT-EAP-SUCCESS",
  1089. "CTRL-EVENT-EAP-FAILURE",
  1090. "CTRL-EVENT-CONNECTED",
  1091. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1092. if ev is None:
  1093. raise Exception("EAP result timed out")
  1094. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1095. raise Exception("TLS certificate error not reported")
  1096. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1097. "CTRL-EVENT-EAP-FAILURE",
  1098. "CTRL-EVENT-CONNECTED",
  1099. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1100. if ev is None:
  1101. raise Exception("EAP result(2) timed out")
  1102. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1103. raise Exception("EAP failure not reported")
  1104. ev = dev.wait_event(["CTRL-EVENT-CONNECTED",
  1105. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1106. if ev is None:
  1107. raise Exception("EAP result(3) timed out")
  1108. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1109. raise Exception("Disconnection not reported")
  1110. ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1111. if ev is None:
  1112. raise Exception("Network block disabling not reported")
  1113. def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev):
  1114. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1115. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1116. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1117. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1118. identity="pap user", anonymous_identity="ttls",
  1119. password="password", phase2="auth=PAP",
  1120. ca_cert="auth_serv/ca.pem",
  1121. wait_connect=True, scan_freq="2412")
  1122. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1123. identity="pap user", anonymous_identity="ttls",
  1124. password="password", phase2="auth=PAP",
  1125. ca_cert="auth_serv/ca-incorrect.pem",
  1126. only_add_network=True, scan_freq="2412")
  1127. dev[0].request("DISCONNECT")
  1128. dev[0].dump_monitor()
  1129. dev[0].select_network(id, freq="2412")
  1130. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1131. if ev is None:
  1132. raise Exception("EAP-TTLS not re-started")
  1133. ev = dev[0].wait_disconnected(timeout=15)
  1134. if "reason=23" not in ev:
  1135. raise Exception("Proper reason code for disconnection not reported")
  1136. def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev):
  1137. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1138. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1139. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1140. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1141. identity="pap user", anonymous_identity="ttls",
  1142. password="password", phase2="auth=PAP",
  1143. wait_connect=True, scan_freq="2412")
  1144. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1145. identity="pap user", anonymous_identity="ttls",
  1146. password="password", phase2="auth=PAP",
  1147. ca_cert="auth_serv/ca-incorrect.pem",
  1148. only_add_network=True, scan_freq="2412")
  1149. dev[0].request("DISCONNECT")
  1150. dev[0].dump_monitor()
  1151. dev[0].select_network(id, freq="2412")
  1152. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1153. if ev is None:
  1154. raise Exception("EAP-TTLS not re-started")
  1155. ev = dev[0].wait_disconnected(timeout=15)
  1156. if "reason=23" not in ev:
  1157. raise Exception("Proper reason code for disconnection not reported")
  1158. def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev):
  1159. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1160. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1161. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1162. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1163. identity="pap user", anonymous_identity="ttls",
  1164. password="password", phase2="auth=PAP",
  1165. ca_cert="auth_serv/ca.pem",
  1166. wait_connect=True, scan_freq="2412")
  1167. dev[0].request("DISCONNECT")
  1168. dev[0].dump_monitor()
  1169. dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem")
  1170. dev[0].select_network(id, freq="2412")
  1171. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1172. if ev is None:
  1173. raise Exception("EAP-TTLS not re-started")
  1174. ev = dev[0].wait_disconnected(timeout=15)
  1175. if "reason=23" not in ev:
  1176. raise Exception("Proper reason code for disconnection not reported")
  1177. def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev):
  1178. """WPA2-Enterprise negative test - domain suffix mismatch"""
  1179. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1180. hostapd.add_ap(apdev[0]['ifname'], params)
  1181. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1182. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1183. password="password", phase2="auth=MSCHAPV2",
  1184. ca_cert="auth_serv/ca.pem",
  1185. domain_suffix_match="incorrect.example.com",
  1186. wait_connect=False, scan_freq="2412")
  1187. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1188. if ev is None:
  1189. raise Exception("Association and EAP start timed out")
  1190. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1191. if ev is None:
  1192. raise Exception("EAP method selection timed out")
  1193. if "TTLS" not in ev:
  1194. raise Exception("Unexpected EAP method")
  1195. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1196. "CTRL-EVENT-EAP-SUCCESS",
  1197. "CTRL-EVENT-EAP-FAILURE",
  1198. "CTRL-EVENT-CONNECTED",
  1199. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1200. if ev is None:
  1201. raise Exception("EAP result timed out")
  1202. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1203. raise Exception("TLS certificate error not reported")
  1204. if "Domain suffix mismatch" not in ev:
  1205. raise Exception("Domain suffix mismatch not reported")
  1206. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1207. "CTRL-EVENT-EAP-FAILURE",
  1208. "CTRL-EVENT-CONNECTED",
  1209. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1210. if ev is None:
  1211. raise Exception("EAP result(2) timed out")
  1212. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1213. raise Exception("EAP failure not reported")
  1214. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1215. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1216. if ev is None:
  1217. raise Exception("EAP result(3) timed out")
  1218. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1219. raise Exception("Disconnection not reported")
  1220. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1221. if ev is None:
  1222. raise Exception("Network block disabling not reported")
  1223. def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev):
  1224. """WPA2-Enterprise negative test - subject mismatch"""
  1225. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1226. hostapd.add_ap(apdev[0]['ifname'], params)
  1227. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1228. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1229. password="password", phase2="auth=MSCHAPV2",
  1230. ca_cert="auth_serv/ca.pem",
  1231. subject_match="/C=FI/O=w1.fi/CN=example.com",
  1232. wait_connect=False, scan_freq="2412")
  1233. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1234. if ev is None:
  1235. raise Exception("Association and EAP start timed out")
  1236. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  1237. "EAP: Failed to initialize EAP method"], timeout=10)
  1238. if ev is None:
  1239. raise Exception("EAP method selection timed out")
  1240. if "EAP: Failed to initialize EAP method" in ev:
  1241. tls = dev[0].request("GET tls_library")
  1242. if tls.startswith("OpenSSL"):
  1243. raise Exception("Failed to select EAP method")
  1244. logger.info("subject_match not supported - connection failed, so test succeeded")
  1245. return
  1246. if "TTLS" not in ev:
  1247. raise Exception("Unexpected EAP method")
  1248. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1249. "CTRL-EVENT-EAP-SUCCESS",
  1250. "CTRL-EVENT-EAP-FAILURE",
  1251. "CTRL-EVENT-CONNECTED",
  1252. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1253. if ev is None:
  1254. raise Exception("EAP result timed out")
  1255. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1256. raise Exception("TLS certificate error not reported")
  1257. if "Subject mismatch" not in ev:
  1258. raise Exception("Subject mismatch not reported")
  1259. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1260. "CTRL-EVENT-EAP-FAILURE",
  1261. "CTRL-EVENT-CONNECTED",
  1262. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1263. if ev is None:
  1264. raise Exception("EAP result(2) timed out")
  1265. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1266. raise Exception("EAP failure not reported")
  1267. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1268. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1269. if ev is None:
  1270. raise Exception("EAP result(3) timed out")
  1271. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1272. raise Exception("Disconnection not reported")
  1273. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1274. if ev is None:
  1275. raise Exception("Network block disabling not reported")
  1276. def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev):
  1277. """WPA2-Enterprise negative test - altsubject mismatch"""
  1278. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1279. hostapd.add_ap(apdev[0]['ifname'], params)
  1280. tests = [ "incorrect.example.com",
  1281. "DNS:incorrect.example.com",
  1282. "DNS:w1.fi",
  1283. "DNS:erver.w1.fi" ]
  1284. for match in tests:
  1285. _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match)
  1286. def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match):
  1287. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1288. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1289. password="password", phase2="auth=MSCHAPV2",
  1290. ca_cert="auth_serv/ca.pem",
  1291. altsubject_match=match,
  1292. wait_connect=False, scan_freq="2412")
  1293. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1294. if ev is None:
  1295. raise Exception("Association and EAP start timed out")
  1296. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  1297. "EAP: Failed to initialize EAP method"], timeout=10)
  1298. if ev is None:
  1299. raise Exception("EAP method selection timed out")
  1300. if "EAP: Failed to initialize EAP method" in ev:
  1301. tls = dev[0].request("GET tls_library")
  1302. if tls.startswith("OpenSSL"):
  1303. raise Exception("Failed to select EAP method")
  1304. logger.info("altsubject_match not supported - connection failed, so test succeeded")
  1305. return
  1306. if "TTLS" not in ev:
  1307. raise Exception("Unexpected EAP method")
  1308. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1309. "CTRL-EVENT-EAP-SUCCESS",
  1310. "CTRL-EVENT-EAP-FAILURE",
  1311. "CTRL-EVENT-CONNECTED",
  1312. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1313. if ev is None:
  1314. raise Exception("EAP result timed out")
  1315. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1316. raise Exception("TLS certificate error not reported")
  1317. if "AltSubject mismatch" not in ev:
  1318. raise Exception("altsubject mismatch not reported")
  1319. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1320. "CTRL-EVENT-EAP-FAILURE",
  1321. "CTRL-EVENT-CONNECTED",
  1322. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1323. if ev is None:
  1324. raise Exception("EAP result(2) timed out")
  1325. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1326. raise Exception("EAP failure not reported")
  1327. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1328. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1329. if ev is None:
  1330. raise Exception("EAP result(3) timed out")
  1331. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1332. raise Exception("Disconnection not reported")
  1333. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1334. if ev is None:
  1335. raise Exception("Network block disabling not reported")
  1336. dev[0].request("REMOVE_NETWORK all")
  1337. def test_ap_wpa2_eap_unauth_tls(dev, apdev):
  1338. """WPA2-Enterprise connection using UNAUTH-TLS"""
  1339. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1340. hostapd.add_ap(apdev[0]['ifname'], params)
  1341. eap_connect(dev[0], apdev[0], "UNAUTH-TLS", "unauth-tls",
  1342. ca_cert="auth_serv/ca.pem")
  1343. eap_reauth(dev[0], "UNAUTH-TLS")
  1344. def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev):
  1345. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash"""
  1346. check_cert_probe_support(dev[0])
  1347. srv_cert_hash = "1477c9cd88391609444b83eca45c4f9f324e3051c5c31fc233ac6aede30ce7cd"
  1348. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1349. hostapd.add_ap(apdev[0]['ifname'], params)
  1350. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1351. identity="probe", ca_cert="probe://",
  1352. wait_connect=False, scan_freq="2412")
  1353. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1354. if ev is None:
  1355. raise Exception("Association and EAP start timed out")
  1356. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10)
  1357. if ev is None:
  1358. raise Exception("No peer server certificate event seen")
  1359. if "hash=" + srv_cert_hash not in ev:
  1360. raise Exception("Expected server certificate hash not reported")
  1361. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  1362. if ev is None:
  1363. raise Exception("EAP result timed out")
  1364. if "Server certificate chain probe" not in ev:
  1365. raise Exception("Server certificate probe not reported")
  1366. dev[0].wait_disconnected(timeout=10)
  1367. dev[0].request("REMOVE_NETWORK all")
  1368. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1369. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1370. password="password", phase2="auth=MSCHAPV2",
  1371. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  1372. wait_connect=False, scan_freq="2412")
  1373. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1374. if ev is None:
  1375. raise Exception("Association and EAP start timed out")
  1376. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  1377. if ev is None:
  1378. raise Exception("EAP result timed out")
  1379. if "Server certificate mismatch" not in ev:
  1380. raise Exception("Server certificate mismatch not reported")
  1381. dev[0].wait_disconnected(timeout=10)
  1382. dev[0].request("REMOVE_NETWORK all")
  1383. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  1384. anonymous_identity="ttls", password="password",
  1385. ca_cert="hash://server/sha256/" + srv_cert_hash,
  1386. phase2="auth=MSCHAPV2")
  1387. def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev):
  1388. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)"""
  1389. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1390. hostapd.add_ap(apdev[0]['ifname'], params)
  1391. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1392. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1393. password="password", phase2="auth=MSCHAPV2",
  1394. ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  1395. wait_connect=False, scan_freq="2412")
  1396. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1397. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1398. password="password", phase2="auth=MSCHAPV2",
  1399. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca",
  1400. wait_connect=False, scan_freq="2412")
  1401. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1402. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1403. password="password", phase2="auth=MSCHAPV2",
  1404. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q",
  1405. wait_connect=False, scan_freq="2412")
  1406. for i in range(0, 3):
  1407. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1408. if ev is None:
  1409. raise Exception("Association and EAP start timed out")
  1410. ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5)
  1411. if ev is None:
  1412. raise Exception("Did not report EAP method initialization failure")
  1413. def test_ap_wpa2_eap_pwd(dev, apdev):
  1414. """WPA2-Enterprise connection using EAP-pwd"""
  1415. check_eap_capa(dev[0], "PWD")
  1416. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1417. hostapd.add_ap(apdev[0]['ifname'], params)
  1418. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1419. eap_reauth(dev[0], "PWD")
  1420. dev[0].request("REMOVE_NETWORK all")
  1421. eap_connect(dev[1], apdev[0], "PWD",
  1422. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  1423. password="secret password",
  1424. fragment_size="90")
  1425. logger.info("Negative test with incorrect password")
  1426. eap_connect(dev[2], apdev[0], "PWD", "pwd user", password="secret-password",
  1427. expect_failure=True, local_error_report=True)
  1428. eap_connect(dev[0], apdev[0], "PWD",
  1429. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  1430. password="secret password",
  1431. fragment_size="31")
  1432. def test_ap_wpa2_eap_pwd_groups(dev, apdev):
  1433. """WPA2-Enterprise connection using various EAP-pwd groups"""
  1434. check_eap_capa(dev[0], "PWD")
  1435. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1436. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1437. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  1438. for i in [ 19, 20, 21, 25, 26 ]:
  1439. params['pwd_group'] = str(i)
  1440. hostapd.add_ap(apdev[0]['ifname'], params)
  1441. dev[0].request("REMOVE_NETWORK all")
  1442. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1443. def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev):
  1444. """WPA2-Enterprise connection using invalid EAP-pwd group"""
  1445. check_eap_capa(dev[0], "PWD")
  1446. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1447. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1448. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  1449. params['pwd_group'] = "0"
  1450. hostapd.add_ap(apdev[0]['ifname'], params)
  1451. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
  1452. identity="pwd user", password="secret password",
  1453. scan_freq="2412", wait_connect=False)
  1454. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1455. if ev is None:
  1456. raise Exception("Timeout on EAP failure report")
  1457. def test_ap_wpa2_eap_pwd_as_frag(dev, apdev):
  1458. """WPA2-Enterprise connection using EAP-pwd with server fragmentation"""
  1459. check_eap_capa(dev[0], "PWD")
  1460. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1461. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1462. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1463. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1464. "pwd_group": "19", "fragment_size": "40" }
  1465. hostapd.add_ap(apdev[0]['ifname'], params)
  1466. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1467. def test_ap_wpa2_eap_gpsk(dev, apdev):
  1468. """WPA2-Enterprise connection using EAP-GPSK"""
  1469. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1470. hostapd.add_ap(apdev[0]['ifname'], params)
  1471. id = eap_connect(dev[0], apdev[0], "GPSK", "gpsk user",
  1472. password="abcdefghijklmnop0123456789abcdef")
  1473. eap_reauth(dev[0], "GPSK")
  1474. logger.info("Test forced algorithm selection")
  1475. for phase1 in [ "cipher=1", "cipher=2" ]:
  1476. dev[0].set_network_quoted(id, "phase1", phase1)
  1477. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1478. if ev is None:
  1479. raise Exception("EAP success timed out")
  1480. dev[0].wait_connected(timeout=10)
  1481. logger.info("Test failed algorithm negotiation")
  1482. dev[0].set_network_quoted(id, "phase1", "cipher=9")
  1483. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1484. if ev is None:
  1485. raise Exception("EAP failure timed out")
  1486. logger.info("Negative test with incorrect password")
  1487. dev[0].request("REMOVE_NETWORK all")
  1488. eap_connect(dev[0], apdev[0], "GPSK", "gpsk user",
  1489. password="ffcdefghijklmnop0123456789abcdef",
  1490. expect_failure=True)
  1491. def test_ap_wpa2_eap_sake(dev, apdev):
  1492. """WPA2-Enterprise connection using EAP-SAKE"""
  1493. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1494. hostapd.add_ap(apdev[0]['ifname'], params)
  1495. eap_connect(dev[0], apdev[0], "SAKE", "sake user",
  1496. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  1497. eap_reauth(dev[0], "SAKE")
  1498. logger.info("Negative test with incorrect password")
  1499. dev[0].request("REMOVE_NETWORK all")
  1500. eap_connect(dev[0], apdev[0], "SAKE", "sake user",
  1501. password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  1502. expect_failure=True)
  1503. def test_ap_wpa2_eap_eke(dev, apdev):
  1504. """WPA2-Enterprise connection using EAP-EKE"""
  1505. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1506. hostapd.add_ap(apdev[0]['ifname'], params)
  1507. id = eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello")
  1508. eap_reauth(dev[0], "EKE")
  1509. logger.info("Test forced algorithm selection")
  1510. for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2",
  1511. "dhgroup=4 encr=1 prf=2 mac=2",
  1512. "dhgroup=3 encr=1 prf=2 mac=2",
  1513. "dhgroup=3 encr=1 prf=1 mac=1" ]:
  1514. dev[0].set_network_quoted(id, "phase1", phase1)
  1515. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1516. if ev is None:
  1517. raise Exception("EAP success timed out")
  1518. dev[0].wait_connected(timeout=10)
  1519. logger.info("Test failed algorithm negotiation")
  1520. dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9")
  1521. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1522. if ev is None:
  1523. raise Exception("EAP failure timed out")
  1524. logger.info("Negative test with incorrect password")
  1525. dev[0].request("REMOVE_NETWORK all")
  1526. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello1",
  1527. expect_failure=True)
  1528. def test_ap_wpa2_eap_ikev2(dev, apdev):
  1529. """WPA2-Enterprise connection using EAP-IKEv2"""
  1530. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1531. hostapd.add_ap(apdev[0]['ifname'], params)
  1532. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1533. password="ike password")
  1534. eap_reauth(dev[0], "IKEV2")
  1535. dev[0].request("REMOVE_NETWORK all")
  1536. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1537. password="ike password", fragment_size="50")
  1538. logger.info("Negative test with incorrect password")
  1539. dev[0].request("REMOVE_NETWORK all")
  1540. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1541. password="ike-password", expect_failure=True)
  1542. def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev):
  1543. """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation"""
  1544. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1545. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1546. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1547. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1548. "fragment_size": "50" }
  1549. hostapd.add_ap(apdev[0]['ifname'], params)
  1550. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1551. password="ike password")
  1552. eap_reauth(dev[0], "IKEV2")
  1553. def test_ap_wpa2_eap_pax(dev, apdev):
  1554. """WPA2-Enterprise connection using EAP-PAX"""
  1555. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1556. hostapd.add_ap(apdev[0]['ifname'], params)
  1557. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1558. password_hex="0123456789abcdef0123456789abcdef")
  1559. eap_reauth(dev[0], "PAX")
  1560. logger.info("Negative test with incorrect password")
  1561. dev[0].request("REMOVE_NETWORK all")
  1562. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1563. password_hex="ff23456789abcdef0123456789abcdef",
  1564. expect_failure=True)
  1565. def test_ap_wpa2_eap_psk(dev, apdev):
  1566. """WPA2-Enterprise connection using EAP-PSK"""
  1567. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1568. params["wpa_key_mgmt"] = "WPA-EAP-SHA256"
  1569. params["ieee80211w"] = "2"
  1570. hostapd.add_ap(apdev[0]['ifname'], params)
  1571. eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com",
  1572. password_hex="0123456789abcdef0123456789abcdef", sha256=True)
  1573. eap_reauth(dev[0], "PSK", sha256=True)
  1574. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
  1575. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ])
  1576. bss = dev[0].get_bss(apdev[0]['bssid'])
  1577. if 'flags' not in bss:
  1578. raise Exception("Could not get BSS flags from BSS table")
  1579. if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']:
  1580. raise Exception("Unexpected BSS flags: " + bss['flags'])
  1581. logger.info("Negative test with incorrect password")
  1582. dev[0].request("REMOVE_NETWORK all")
  1583. eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com",
  1584. password_hex="ff23456789abcdef0123456789abcdef", sha256=True,
  1585. expect_failure=True)
  1586. def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev):
  1587. """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  1588. params = hostapd.wpa_eap_params(ssid="test-wpa-eap")
  1589. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1590. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1591. identity="user", password="password", phase2="auth=MSCHAPV2",
  1592. ca_cert="auth_serv/ca.pem", wait_connect=False,
  1593. scan_freq="2412")
  1594. eap_check_auth(dev[0], "PEAP", True, rsn=False)
  1595. hwsim_utils.test_connectivity(dev[0], hapd)
  1596. eap_reauth(dev[0], "PEAP", rsn=False)
  1597. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
  1598. ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ])
  1599. def test_ap_wpa2_eap_interactive(dev, apdev):
  1600. """WPA2-Enterprise connection using interactive identity/password entry"""
  1601. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1602. hostapd.add_ap(apdev[0]['ifname'], params)
  1603. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1604. tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
  1605. "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
  1606. None, "password"),
  1607. ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
  1608. "TTLS", "ttls", None, "auth=MSCHAPV2",
  1609. "DOMAIN\mschapv2 user", "password"),
  1610. ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
  1611. "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
  1612. ("Connection with dynamic TTLS/EAP-MD5 password entry",
  1613. "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
  1614. ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
  1615. "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
  1616. ("Connection with dynamic PEAP/EAP-GTC password entry",
  1617. "PEAP", None, "user", "auth=GTC", None, "password") ]
  1618. for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
  1619. logger.info(desc)
  1620. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
  1621. anonymous_identity=anon, identity=identity,
  1622. ca_cert="auth_serv/ca.pem", phase2=phase2,
  1623. wait_connect=False, scan_freq="2412")
  1624. if req_id:
  1625. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  1626. if ev is None:
  1627. raise Exception("Request for identity timed out")
  1628. id = ev.split(':')[0].split('-')[-1]
  1629. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  1630. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
  1631. if ev is None:
  1632. raise Exception("Request for password timed out")
  1633. id = ev.split(':')[0].split('-')[-1]
  1634. type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD"
  1635. dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw)
  1636. dev[0].wait_connected(timeout=10)
  1637. dev[0].request("REMOVE_NETWORK all")
  1638. def test_ap_wpa2_eap_vendor_test(dev, apdev):
  1639. """WPA2-Enterprise connection using EAP vendor test"""
  1640. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1641. hostapd.add_ap(apdev[0]['ifname'], params)
  1642. eap_connect(dev[0], apdev[0], "VENDOR-TEST", "vendor-test")
  1643. eap_reauth(dev[0], "VENDOR-TEST")
  1644. def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev):
  1645. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning"""
  1646. check_eap_capa(dev[0], "FAST")
  1647. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1648. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1649. eap_connect(dev[0], apdev[0], "FAST", "user",
  1650. anonymous_identity="FAST", password="password",
  1651. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1652. phase1="fast_provisioning=1", pac_file="blob://fast_pac")
  1653. hwsim_utils.test_connectivity(dev[0], hapd)
  1654. res = eap_reauth(dev[0], "FAST")
  1655. if res['tls_session_reused'] != '1':
  1656. raise Exception("EAP-FAST could not use PAC session ticket")
  1657. def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params):
  1658. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file"""
  1659. check_eap_capa(dev[0], "FAST")
  1660. pac_file = os.path.join(params['logdir'], "fast.pac")
  1661. pac_file2 = os.path.join(params['logdir'], "fast-bin.pac")
  1662. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1663. hostapd.add_ap(apdev[0]['ifname'], params)
  1664. try:
  1665. eap_connect(dev[0], apdev[0], "FAST", "user",
  1666. anonymous_identity="FAST", password="password",
  1667. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1668. phase1="fast_provisioning=1", pac_file=pac_file)
  1669. with open(pac_file, "r") as f:
  1670. data = f.read()
  1671. if "wpa_supplicant EAP-FAST PAC file - version 1" not in data:
  1672. raise Exception("PAC file header missing")
  1673. if "PAC-Key=" not in data:
  1674. raise Exception("PAC-Key missing from PAC file")
  1675. dev[0].request("REMOVE_NETWORK all")
  1676. eap_connect(dev[0], apdev[0], "FAST", "user",
  1677. anonymous_identity="FAST", password="password",
  1678. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1679. pac_file=pac_file)
  1680. eap_connect(dev[1], apdev[0], "FAST", "user",
  1681. anonymous_identity="FAST", password="password",
  1682. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1683. phase1="fast_provisioning=1 fast_pac_format=binary",
  1684. pac_file=pac_file2)
  1685. dev[1].request("REMOVE_NETWORK all")
  1686. eap_connect(dev[1], apdev[0], "FAST", "user",
  1687. anonymous_identity="FAST", password="password",
  1688. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1689. phase1="fast_pac_format=binary",
  1690. pac_file=pac_file2)
  1691. finally:
  1692. subprocess.call(['sudo', 'rm', pac_file])
  1693. subprocess.call(['sudo', 'rm', pac_file2])
  1694. def test_ap_wpa2_eap_fast_binary_pac(dev, apdev):
  1695. """WPA2-Enterprise connection using EAP-FAST and binary PAC format"""
  1696. check_eap_capa(dev[0], "FAST")
  1697. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1698. hostapd.add_ap(apdev[0]['ifname'], params)
  1699. eap_connect(dev[0], apdev[0], "FAST", "user",
  1700. anonymous_identity="FAST", password="password",
  1701. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1702. phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary",
  1703. pac_file="blob://fast_pac_bin")
  1704. res = eap_reauth(dev[0], "FAST")
  1705. if res['tls_session_reused'] != '1':
  1706. raise Exception("EAP-FAST could not use PAC session ticket")
  1707. def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev):
  1708. """WPA2-Enterprise connection using EAP-FAST and missing PAC config"""
  1709. check_eap_capa(dev[0], "FAST")
  1710. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1711. hostapd.add_ap(apdev[0]['ifname'], params)
  1712. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  1713. identity="user", anonymous_identity="FAST",
  1714. password="password",
  1715. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1716. pac_file="blob://fast_pac_not_in_use",
  1717. wait_connect=False, scan_freq="2412")
  1718. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1719. if ev is None:
  1720. raise Exception("Timeout on EAP failure report")
  1721. dev[0].request("REMOVE_NETWORK all")
  1722. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  1723. identity="user", anonymous_identity="FAST",
  1724. password="password",
  1725. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1726. wait_connect=False, scan_freq="2412")
  1727. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1728. if ev is None:
  1729. raise Exception("Timeout on EAP failure report")
  1730. def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev):
  1731. """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning"""
  1732. check_eap_capa(dev[0], "FAST")
  1733. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1734. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1735. eap_connect(dev[0], apdev[0], "FAST", "user",
  1736. anonymous_identity="FAST", password="password",
  1737. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  1738. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth")
  1739. hwsim_utils.test_connectivity(dev[0], hapd)
  1740. res = eap_reauth(dev[0], "FAST")
  1741. if res['tls_session_reused'] != '1':
  1742. raise Exception("EAP-FAST could not use PAC session ticket")
  1743. def test_ap_wpa2_eap_tls_ocsp(dev, apdev):
  1744. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP"""
  1745. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1746. hostapd.add_ap(apdev[0]['ifname'], params)
  1747. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1748. private_key="auth_serv/user.pkcs12",
  1749. private_key_passwd="whatever", ocsp=2)
  1750. def int_eap_server_params():
  1751. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1752. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1753. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1754. "ca_cert": "auth_serv/ca.pem",
  1755. "server_cert": "auth_serv/server.pem",
  1756. "private_key": "auth_serv/server.key" }
  1757. return params
  1758. def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
  1759. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
  1760. params = int_eap_server_params()
  1761. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
  1762. hostapd.add_ap(apdev[0]['ifname'], params)
  1763. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1764. identity="tls user", ca_cert="auth_serv/ca.pem",
  1765. private_key="auth_serv/user.pkcs12",
  1766. private_key_passwd="whatever", ocsp=2,
  1767. wait_connect=False, scan_freq="2412")
  1768. count = 0
  1769. while True:
  1770. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  1771. if ev is None:
  1772. raise Exception("Timeout on EAP status")
  1773. if 'bad certificate status response' in ev:
  1774. break
  1775. count = count + 1
  1776. if count > 10:
  1777. raise Exception("Unexpected number of EAP status messages")
  1778. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1779. if ev is None:
  1780. raise Exception("Timeout on EAP failure report")
  1781. def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
  1782. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  1783. params = int_eap_server_params()
  1784. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  1785. params["private_key"] = "auth_serv/server-no-dnsname.key"
  1786. hostapd.add_ap(apdev[0]['ifname'], params)
  1787. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1788. identity="tls user", ca_cert="auth_serv/ca.pem",
  1789. private_key="auth_serv/user.pkcs12",
  1790. private_key_passwd="whatever",
  1791. domain_suffix_match="server3.w1.fi",
  1792. scan_freq="2412")
  1793. def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
  1794. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  1795. check_domain_match_full(dev[0])
  1796. params = int_eap_server_params()
  1797. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  1798. params["private_key"] = "auth_serv/server-no-dnsname.key"
  1799. hostapd.add_ap(apdev[0]['ifname'], params)
  1800. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1801. identity="tls user", ca_cert="auth_serv/ca.pem",
  1802. private_key="auth_serv/user.pkcs12",
  1803. private_key_passwd="whatever",
  1804. domain_suffix_match="w1.fi",
  1805. scan_freq="2412")
  1806. def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
  1807. """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
  1808. params = int_eap_server_params()
  1809. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  1810. params["private_key"] = "auth_serv/server-no-dnsname.key"
  1811. hostapd.add_ap(apdev[0]['ifname'], params)
  1812. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1813. identity="tls user", ca_cert="auth_serv/ca.pem",
  1814. private_key="auth_serv/user.pkcs12",
  1815. private_key_passwd="whatever",
  1816. domain_suffix_match="example.com",
  1817. wait_connect=False,
  1818. scan_freq="2412")
  1819. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1820. identity="tls user", ca_cert="auth_serv/ca.pem",
  1821. private_key="auth_serv/user.pkcs12",
  1822. private_key_passwd="whatever",
  1823. domain_suffix_match="erver3.w1.fi",
  1824. wait_connect=False,
  1825. scan_freq="2412")
  1826. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1827. if ev is None:
  1828. raise Exception("Timeout on EAP failure report")
  1829. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1830. if ev is None:
  1831. raise Exception("Timeout on EAP failure report (2)")
  1832. def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev):
  1833. """WPA2-Enterprise using EAP-TTLS and expired certificate"""
  1834. params = int_eap_server_params()
  1835. params["server_cert"] = "auth_serv/server-expired.pem"
  1836. params["private_key"] = "auth_serv/server-expired.key"
  1837. hostapd.add_ap(apdev[0]['ifname'], params)
  1838. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1839. identity="mschap user", password="password",
  1840. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1841. wait_connect=False,
  1842. scan_freq="2412")
  1843. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  1844. if ev is None:
  1845. raise Exception("Timeout on EAP certificate error report")
  1846. if "reason=4" not in ev or "certificate has expired" not in ev:
  1847. raise Exception("Unexpected failure reason: " + ev)
  1848. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1849. if ev is None:
  1850. raise Exception("Timeout on EAP failure report")
  1851. def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev):
  1852. """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration"""
  1853. params = int_eap_server_params()
  1854. params["server_cert"] = "auth_serv/server-expired.pem"
  1855. params["private_key"] = "auth_serv/server-expired.key"
  1856. hostapd.add_ap(apdev[0]['ifname'], params)
  1857. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1858. identity="mschap user", password="password",
  1859. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1860. phase1="tls_disable_time_checks=1",
  1861. scan_freq="2412")
  1862. def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev):
  1863. """WPA2-Enterprise using EAP-TTLS and server cert with client EKU"""
  1864. params = int_eap_server_params()
  1865. params["server_cert"] = "auth_serv/server-eku-client.pem"
  1866. params["private_key"] = "auth_serv/server-eku-client.key"
  1867. hostapd.add_ap(apdev[0]['ifname'], params)
  1868. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1869. identity="mschap user", password="password",
  1870. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1871. wait_connect=False,
  1872. scan_freq="2412")
  1873. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1874. if ev is None:
  1875. raise Exception("Timeout on EAP failure report")
  1876. def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev):
  1877. """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU"""
  1878. params = int_eap_server_params()
  1879. params["server_cert"] = "auth_serv/server-eku-client-server.pem"
  1880. params["private_key"] = "auth_serv/server-eku-client-server.key"
  1881. hostapd.add_ap(apdev[0]['ifname'], params)
  1882. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1883. identity="mschap user", password="password",
  1884. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1885. scan_freq="2412")
  1886. def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev):
  1887. """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file"""
  1888. params = int_eap_server_params()
  1889. del params["server_cert"]
  1890. params["private_key"] = "auth_serv/server.pkcs12"
  1891. hostapd.add_ap(apdev[0]['ifname'], params)
  1892. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1893. identity="mschap user", password="password",
  1894. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1895. scan_freq="2412")
  1896. def test_ap_wpa2_eap_ttls_dh_params(dev, apdev):
  1897. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params"""
  1898. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1899. hostapd.add_ap(apdev[0]['ifname'], params)
  1900. eap_connect(dev[0], apdev[0], "TTLS", "chap user",
  1901. anonymous_identity="ttls", password="password",
  1902. ca_cert="auth_serv/ca.der", phase2="auth=CHAP",
  1903. dh_file="auth_serv/dh.conf")
  1904. def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
  1905. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob"""
  1906. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1907. hostapd.add_ap(apdev[0]['ifname'], params)
  1908. dh = read_pem("auth_serv/dh.conf")
  1909. if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
  1910. raise Exception("Could not set dhparams blob")
  1911. eap_connect(dev[0], apdev[0], "TTLS", "chap user",
  1912. anonymous_identity="ttls", password="password",
  1913. ca_cert="auth_serv/ca.der", phase2="auth=CHAP",
  1914. dh_file="blob://dhparams")
  1915. def test_ap_wpa2_eap_reauth(dev, apdev):
  1916. """WPA2-Enterprise and Authenticator forcing reauthentication"""
  1917. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1918. params['eap_reauth_period'] = '2'
  1919. hostapd.add_ap(apdev[0]['ifname'], params)
  1920. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1921. password_hex="0123456789abcdef0123456789abcdef")
  1922. logger.info("Wait for reauthentication")
  1923. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1924. if ev is None:
  1925. raise Exception("Timeout on reauthentication")
  1926. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1927. if ev is None:
  1928. raise Exception("Timeout on reauthentication")
  1929. for i in range(0, 20):
  1930. state = dev[0].get_status_field("wpa_state")
  1931. if state == "COMPLETED":
  1932. break
  1933. time.sleep(0.1)
  1934. if state != "COMPLETED":
  1935. raise Exception("Reauthentication did not complete")
  1936. def test_ap_wpa2_eap_request_identity_message(dev, apdev):
  1937. """Optional displayable message in EAP Request-Identity"""
  1938. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1939. params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com'
  1940. hostapd.add_ap(apdev[0]['ifname'], params)
  1941. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1942. password_hex="0123456789abcdef0123456789abcdef")
  1943. def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev):
  1944. """WPA2-Enterprise using EAP-SIM/AKA and protected result indication"""
  1945. check_hlr_auc_gw_support()
  1946. params = int_eap_server_params()
  1947. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  1948. params['eap_sim_aka_result_ind'] = "1"
  1949. hostapd.add_ap(apdev[0]['ifname'], params)
  1950. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  1951. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1952. phase1="result_ind=1")
  1953. eap_reauth(dev[0], "SIM")
  1954. eap_connect(dev[1], apdev[0], "SIM", "1232010000000000",
  1955. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  1956. dev[0].request("REMOVE_NETWORK all")
  1957. dev[1].request("REMOVE_NETWORK all")
  1958. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  1959. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1960. phase1="result_ind=1")
  1961. eap_reauth(dev[0], "AKA")
  1962. eap_connect(dev[1], apdev[0], "AKA", "0232010000000000",
  1963. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  1964. dev[0].request("REMOVE_NETWORK all")
  1965. dev[1].request("REMOVE_NETWORK all")
  1966. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  1967. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  1968. phase1="result_ind=1")
  1969. eap_reauth(dev[0], "AKA'")
  1970. eap_connect(dev[1], apdev[0], "AKA'", "6555444333222111",
  1971. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  1972. def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev):
  1973. """WPA2-Enterprise connection resulting in too many EAP roundtrips"""
  1974. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1975. hostapd.add_ap(apdev[0]['ifname'], params)
  1976. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1977. eap="TTLS", identity="mschap user",
  1978. wait_connect=False, scan_freq="2412", ieee80211w="1",
  1979. anonymous_identity="ttls", password="password",
  1980. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1981. fragment_size="10")
  1982. ev = dev[0].wait_event(["EAP: more than"], timeout=20)
  1983. if ev is None:
  1984. raise Exception("EAP roundtrip limit not reached")
  1985. def test_ap_wpa2_eap_expanded_nak(dev, apdev):
  1986. """WPA2-Enterprise connection with EAP resulting in expanded NAK"""
  1987. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1988. hostapd.add_ap(apdev[0]['ifname'], params)
  1989. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1990. eap="PSK", identity="vendor-test",
  1991. password_hex="ff23456789abcdef0123456789abcdef",
  1992. wait_connect=False)
  1993. found = False
  1994. for i in range(0, 5):
  1995. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=10)
  1996. if ev is None:
  1997. raise Exception("Association and EAP start timed out")
  1998. if "refuse proposed method" in ev:
  1999. found = True
  2000. break
  2001. if not found:
  2002. raise Exception("Unexpected EAP status: " + ev)
  2003. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2004. if ev is None:
  2005. raise Exception("EAP failure timed out")
  2006. def test_ap_wpa2_eap_sql(dev, apdev, params):
  2007. """WPA2-Enterprise connection using SQLite for user DB"""
  2008. try:
  2009. import sqlite3
  2010. except ImportError:
  2011. raise HwsimSkip("No sqlite3 module available")
  2012. dbfile = os.path.join(params['logdir'], "eap-user.db")
  2013. try:
  2014. os.remove(dbfile)
  2015. except:
  2016. pass
  2017. con = sqlite3.connect(dbfile)
  2018. with con:
  2019. cur = con.cursor()
  2020. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  2021. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  2022. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)")
  2023. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)")
  2024. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)")
  2025. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)")
  2026. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  2027. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  2028. try:
  2029. params = int_eap_server_params()
  2030. params["eap_user_file"] = "sqlite:" + dbfile
  2031. hostapd.add_ap(apdev[0]['ifname'], params)
  2032. eap_connect(dev[0], apdev[0], "TTLS", "user-mschapv2",
  2033. anonymous_identity="ttls", password="password",
  2034. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  2035. dev[0].request("REMOVE_NETWORK all")
  2036. eap_connect(dev[1], apdev[0], "TTLS", "user-mschap",
  2037. anonymous_identity="ttls", password="password",
  2038. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  2039. dev[1].request("REMOVE_NETWORK all")
  2040. eap_connect(dev[0], apdev[0], "TTLS", "user-chap",
  2041. anonymous_identity="ttls", password="password",
  2042. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP")
  2043. eap_connect(dev[1], apdev[0], "TTLS", "user-pap",
  2044. anonymous_identity="ttls", password="password",
  2045. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2046. finally:
  2047. os.remove(dbfile)
  2048. def test_ap_wpa2_eap_non_ascii_identity(dev, apdev):
  2049. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  2050. params = int_eap_server_params()
  2051. hostapd.add_ap(apdev[0]['ifname'], params)
  2052. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2053. identity="\x80", password="password", wait_connect=False)
  2054. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2055. identity="a\x80", password="password", wait_connect=False)
  2056. for i in range(0, 2):
  2057. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2058. if ev is None:
  2059. raise Exception("Association and EAP start timed out")
  2060. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2061. if ev is None:
  2062. raise Exception("EAP method selection timed out")
  2063. def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev):
  2064. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  2065. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2066. hostapd.add_ap(apdev[0]['ifname'], params)
  2067. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2068. identity="\x80", password="password", wait_connect=False)
  2069. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2070. identity="a\x80", password="password", wait_connect=False)
  2071. for i in range(0, 2):
  2072. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2073. if ev is None:
  2074. raise Exception("Association and EAP start timed out")
  2075. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2076. if ev is None:
  2077. raise Exception("EAP method selection timed out")
  2078. def test_openssl_cipher_suite_config_wpas(dev, apdev):
  2079. """OpenSSL cipher suite configuration on wpa_supplicant"""
  2080. tls = dev[0].request("GET tls_library")
  2081. if not tls.startswith("OpenSSL"):
  2082. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  2083. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2084. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2085. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2086. anonymous_identity="ttls", password="password",
  2087. openssl_ciphers="AES128",
  2088. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2089. eap_connect(dev[1], apdev[0], "TTLS", "pap user",
  2090. anonymous_identity="ttls", password="password",
  2091. openssl_ciphers="EXPORT",
  2092. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2093. expect_failure=True)
  2094. def test_openssl_cipher_suite_config_hapd(dev, apdev):
  2095. """OpenSSL cipher suite configuration on hostapd"""
  2096. tls = dev[0].request("GET tls_library")
  2097. if not tls.startswith("OpenSSL"):
  2098. raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls)
  2099. params = int_eap_server_params()
  2100. params['openssl_ciphers'] = "AES256"
  2101. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2102. tls = hapd.request("GET tls_library")
  2103. if not tls.startswith("OpenSSL"):
  2104. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  2105. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2106. anonymous_identity="ttls", password="password",
  2107. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2108. eap_connect(dev[1], apdev[0], "TTLS", "pap user",
  2109. anonymous_identity="ttls", password="password",
  2110. openssl_ciphers="AES128",
  2111. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2112. expect_failure=True)
  2113. eap_connect(dev[2], apdev[0], "TTLS", "pap user",
  2114. anonymous_identity="ttls", password="password",
  2115. openssl_ciphers="HIGH:!ADH",
  2116. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2117. def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
  2118. """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
  2119. p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2120. hapd = hostapd.add_ap(apdev[0]['ifname'], p)
  2121. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  2122. pid = find_wpas_process(dev[0])
  2123. id = eap_connect(dev[0], apdev[0], "TTLS", "pap-secret",
  2124. anonymous_identity="ttls", password=password,
  2125. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2126. time.sleep(0.1)
  2127. buf = read_process_memory(pid, password)
  2128. dev[0].request("DISCONNECT")
  2129. dev[0].wait_disconnected()
  2130. dev[0].relog()
  2131. msk = None
  2132. emsk = None
  2133. pmk = None
  2134. ptk = None
  2135. gtk = None
  2136. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  2137. for l in f.readlines():
  2138. if "EAP-TTLS: Derived key - hexdump" in l:
  2139. val = l.strip().split(':')[3].replace(' ', '')
  2140. msk = binascii.unhexlify(val)
  2141. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  2142. val = l.strip().split(':')[3].replace(' ', '')
  2143. emsk = binascii.unhexlify(val)
  2144. if "WPA: PMK - hexdump" in l:
  2145. val = l.strip().split(':')[3].replace(' ', '')
  2146. pmk = binascii.unhexlify(val)
  2147. if "WPA: PTK - hexdump" in l:
  2148. val = l.strip().split(':')[3].replace(' ', '')
  2149. ptk = binascii.unhexlify(val)
  2150. if "WPA: Group Key - hexdump" in l:
  2151. val = l.strip().split(':')[3].replace(' ', '')
  2152. gtk = binascii.unhexlify(val)
  2153. if not msk or not emsk or not pmk or not ptk or not gtk:
  2154. raise Exception("Could not find keys from debug log")
  2155. if len(gtk) != 16:
  2156. raise Exception("Unexpected GTK length")
  2157. kck = ptk[0:16]
  2158. kek = ptk[16:32]
  2159. tk = ptk[32:48]
  2160. fname = os.path.join(params['logdir'],
  2161. 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-')
  2162. logger.info("Checking keys in memory while associated")
  2163. get_key_locations(buf, password, "Password")
  2164. get_key_locations(buf, pmk, "PMK")
  2165. get_key_locations(buf, msk, "MSK")
  2166. get_key_locations(buf, emsk, "EMSK")
  2167. if password not in buf:
  2168. raise HwsimSkip("Password not found while associated")
  2169. if pmk not in buf:
  2170. raise HwsimSkip("PMK not found while associated")
  2171. if kck not in buf:
  2172. raise Exception("KCK not found while associated")
  2173. if kek not in buf:
  2174. raise Exception("KEK not found while associated")
  2175. if tk in buf:
  2176. raise Exception("TK found from memory")
  2177. if gtk in buf:
  2178. raise Exception("GTK found from memory")
  2179. logger.info("Checking keys in memory after disassociation")
  2180. buf = read_process_memory(pid, password)
  2181. # Note: Password is still present in network configuration
  2182. # Note: PMK is in PMKSA cache and EAP fast re-auth data
  2183. get_key_locations(buf, password, "Password")
  2184. get_key_locations(buf, pmk, "PMK")
  2185. get_key_locations(buf, msk, "MSK")
  2186. get_key_locations(buf, emsk, "EMSK")
  2187. verify_not_present(buf, kck, fname, "KCK")
  2188. verify_not_present(buf, kek, fname, "KEK")
  2189. verify_not_present(buf, tk, fname, "TK")
  2190. verify_not_present(buf, gtk, fname, "GTK")
  2191. dev[0].request("PMKSA_FLUSH")
  2192. dev[0].set_network_quoted(id, "identity", "foo")
  2193. logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush")
  2194. buf = read_process_memory(pid, password)
  2195. get_key_locations(buf, password, "Password")
  2196. get_key_locations(buf, pmk, "PMK")
  2197. get_key_locations(buf, msk, "MSK")
  2198. get_key_locations(buf, emsk, "EMSK")
  2199. verify_not_present(buf, pmk, fname, "PMK")
  2200. dev[0].request("REMOVE_NETWORK all")
  2201. logger.info("Checking keys in memory after network profile removal")
  2202. buf = read_process_memory(pid, password)
  2203. get_key_locations(buf, password, "Password")
  2204. get_key_locations(buf, pmk, "PMK")
  2205. get_key_locations(buf, msk, "MSK")
  2206. get_key_locations(buf, emsk, "EMSK")
  2207. verify_not_present(buf, password, fname, "password")
  2208. verify_not_present(buf, pmk, fname, "PMK")
  2209. verify_not_present(buf, kck, fname, "KCK")
  2210. verify_not_present(buf, kek, fname, "KEK")
  2211. verify_not_present(buf, tk, fname, "TK")
  2212. verify_not_present(buf, gtk, fname, "GTK")
  2213. verify_not_present(buf, msk, fname, "MSK")
  2214. verify_not_present(buf, emsk, fname, "EMSK")