test_ap_eap.py 212 KB

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