test_ap_eap.py 122 KB

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