test_ap_eap.py 109 KB

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