test_ap_eap.py 193 KB

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