test_ap_eap.py 105 KB

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