test_ap_eap.py 156 KB

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