test_ap_eap.py 106 KB

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