test_ap_eap.py 212 KB

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