test_ap_eap.py 109 KB

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