test_ap_eap.py 131 KB

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