test_ap_eap.py 282 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306
  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 struct
  17. import tempfile
  18. import hwsim_utils
  19. import hostapd
  20. from utils import HwsimSkip, alloc_fail, fail_test, skip_with_fips, wait_fail_trigger
  21. from wpasupplicant import WpaSupplicant
  22. from test_ap_psk import check_mib, find_wpas_process, read_process_memory, verify_not_present, get_key_locations, set_test_assoc_ie
  23. try:
  24. import OpenSSL
  25. openssl_imported = True
  26. except ImportError:
  27. openssl_imported = False
  28. def check_hlr_auc_gw_support():
  29. if not os.path.exists("/tmp/hlr_auc_gw.sock"):
  30. raise HwsimSkip("No hlr_auc_gw available")
  31. def check_eap_capa(dev, method):
  32. res = dev.get_capability("eap")
  33. if method not in res:
  34. raise HwsimSkip("EAP method %s not supported in the build" % method)
  35. def check_subject_match_support(dev):
  36. tls = dev.request("GET tls_library")
  37. if not tls.startswith("OpenSSL"):
  38. raise HwsimSkip("subject_match not supported with this TLS library: " + tls)
  39. def check_altsubject_match_support(dev):
  40. tls = dev.request("GET tls_library")
  41. if not tls.startswith("OpenSSL"):
  42. raise HwsimSkip("altsubject_match not supported with this TLS library: " + tls)
  43. def check_domain_match(dev):
  44. tls = dev.request("GET tls_library")
  45. if tls.startswith("internal"):
  46. raise HwsimSkip("domain_match not supported with this TLS library: " + tls)
  47. def check_domain_suffix_match(dev):
  48. tls = dev.request("GET tls_library")
  49. if tls.startswith("internal"):
  50. raise HwsimSkip("domain_suffix_match not supported with this TLS library: " + tls)
  51. def check_domain_match_full(dev):
  52. tls = dev.request("GET tls_library")
  53. if not tls.startswith("OpenSSL"):
  54. raise HwsimSkip("domain_suffix_match requires full match with this TLS library: " + tls)
  55. def check_cert_probe_support(dev):
  56. tls = dev.request("GET tls_library")
  57. if not tls.startswith("OpenSSL") and not tls.startswith("internal"):
  58. raise HwsimSkip("Certificate probing not supported with this TLS library: " + tls)
  59. def check_ext_cert_check_support(dev):
  60. tls = dev.request("GET tls_library")
  61. if not tls.startswith("OpenSSL"):
  62. raise HwsimSkip("ext_cert_check not supported with this TLS library: " + tls)
  63. def check_ocsp_support(dev):
  64. tls = dev.request("GET tls_library")
  65. #if tls.startswith("internal"):
  66. # raise HwsimSkip("OCSP not supported with this TLS library: " + tls)
  67. #if "BoringSSL" in tls:
  68. # raise HwsimSkip("OCSP not supported with this TLS library: " + tls)
  69. def check_pkcs5_v15_support(dev):
  70. tls = dev.request("GET tls_library")
  71. if "BoringSSL" in tls:
  72. raise HwsimSkip("PKCS#5 v1.5 not supported with this TLS library: " + tls)
  73. def check_ocsp_multi_support(dev):
  74. tls = dev.request("GET tls_library")
  75. if not tls.startswith("internal"):
  76. raise HwsimSkip("OCSP-multi not supported with this TLS library: " + tls)
  77. as_hapd = hostapd.Hostapd("as")
  78. res = as_hapd.request("GET tls_library")
  79. del as_hapd
  80. if not res.startswith("internal"):
  81. raise HwsimSkip("Authentication server does not support ocsp_multi")
  82. def check_pkcs12_support(dev):
  83. tls = dev.request("GET tls_library")
  84. #if tls.startswith("internal"):
  85. # raise HwsimSkip("PKCS#12 not supported with this TLS library: " + tls)
  86. def check_dh_dsa_support(dev):
  87. tls = dev.request("GET tls_library")
  88. if tls.startswith("internal"):
  89. raise HwsimSkip("DH DSA not supported with this TLS library: " + tls)
  90. def read_pem(fname):
  91. with open(fname, "r") as f:
  92. lines = f.readlines()
  93. copy = False
  94. cert = ""
  95. for l in lines:
  96. if "-----END" in l:
  97. break
  98. if copy:
  99. cert = cert + l
  100. if "-----BEGIN" in l:
  101. copy = True
  102. return base64.b64decode(cert)
  103. def eap_connect(dev, hapd, method, identity,
  104. sha256=False, expect_failure=False, local_error_report=False,
  105. maybe_local_error=False, **kwargs):
  106. id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  107. eap=method, identity=identity,
  108. wait_connect=False, scan_freq="2412", ieee80211w="1",
  109. **kwargs)
  110. eap_check_auth(dev, method, True, sha256=sha256,
  111. expect_failure=expect_failure,
  112. local_error_report=local_error_report,
  113. maybe_local_error=maybe_local_error)
  114. if expect_failure:
  115. return id
  116. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  117. if ev is None:
  118. raise Exception("No connection event received from hostapd")
  119. return id
  120. def eap_check_auth(dev, method, initial, rsn=True, sha256=False,
  121. expect_failure=False, local_error_report=False,
  122. maybe_local_error=False):
  123. ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  124. if ev is None:
  125. raise Exception("Association and EAP start timed out")
  126. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD",
  127. "CTRL-EVENT-EAP-FAILURE"], timeout=10)
  128. if ev is None:
  129. raise Exception("EAP method selection timed out")
  130. if "CTRL-EVENT-EAP-FAILURE" in ev:
  131. if maybe_local_error:
  132. return
  133. raise Exception("Could not select EAP method")
  134. if method not in ev:
  135. raise Exception("Unexpected EAP method")
  136. if expect_failure:
  137. ev = dev.wait_event(["CTRL-EVENT-EAP-FAILURE"])
  138. if ev is None:
  139. raise Exception("EAP failure timed out")
  140. ev = dev.wait_disconnected(timeout=10)
  141. if maybe_local_error and "locally_generated=1" in ev:
  142. return
  143. if not local_error_report:
  144. if "reason=23" not in ev:
  145. raise Exception("Proper reason code for disconnection not reported")
  146. return
  147. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  148. if ev is None:
  149. raise Exception("EAP success timed out")
  150. if initial:
  151. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
  152. else:
  153. ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=10)
  154. if ev is None:
  155. raise Exception("Association with the AP timed out")
  156. status = dev.get_status()
  157. if status["wpa_state"] != "COMPLETED":
  158. raise Exception("Connection not completed")
  159. if status["suppPortStatus"] != "Authorized":
  160. raise Exception("Port not authorized")
  161. if "selectedMethod" not in status:
  162. logger.info("Status: " + str(status))
  163. raise Exception("No selectedMethod in status")
  164. if method not in status["selectedMethod"]:
  165. raise Exception("Incorrect EAP method status")
  166. if sha256:
  167. e = "WPA2-EAP-SHA256"
  168. elif rsn:
  169. e = "WPA2/IEEE 802.1X/EAP"
  170. else:
  171. e = "WPA/IEEE 802.1X/EAP"
  172. if status["key_mgmt"] != e:
  173. raise Exception("Unexpected key_mgmt status: " + status["key_mgmt"])
  174. return status
  175. def eap_reauth(dev, method, rsn=True, sha256=False, expect_failure=False):
  176. dev.request("REAUTHENTICATE")
  177. return eap_check_auth(dev, method, False, rsn=rsn, sha256=sha256,
  178. expect_failure=expect_failure)
  179. def test_ap_wpa2_eap_sim(dev, apdev):
  180. """WPA2-Enterprise connection using EAP-SIM"""
  181. check_hlr_auc_gw_support()
  182. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  183. hapd = hostapd.add_ap(apdev[0], params)
  184. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  185. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  186. hwsim_utils.test_connectivity(dev[0], hapd)
  187. eap_reauth(dev[0], "SIM")
  188. eap_connect(dev[1], hapd, "SIM", "1232010000000001",
  189. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  190. eap_connect(dev[2], hapd, "SIM", "1232010000000002",
  191. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  192. expect_failure=True)
  193. logger.info("Negative test with incorrect key")
  194. dev[0].request("REMOVE_NETWORK all")
  195. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  196. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  197. expect_failure=True)
  198. logger.info("Invalid GSM-Milenage key")
  199. dev[0].request("REMOVE_NETWORK all")
  200. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  201. password="ffdca4eda45b53cf0f12d7c9c3bc6a",
  202. expect_failure=True)
  203. logger.info("Invalid GSM-Milenage key(2)")
  204. dev[0].request("REMOVE_NETWORK all")
  205. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  206. password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581",
  207. expect_failure=True)
  208. logger.info("Invalid GSM-Milenage key(3)")
  209. dev[0].request("REMOVE_NETWORK all")
  210. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  211. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q",
  212. expect_failure=True)
  213. logger.info("Invalid GSM-Milenage key(4)")
  214. dev[0].request("REMOVE_NETWORK all")
  215. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  216. password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581",
  217. expect_failure=True)
  218. logger.info("Missing key configuration")
  219. dev[0].request("REMOVE_NETWORK all")
  220. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  221. expect_failure=True)
  222. def test_ap_wpa2_eap_sim_sql(dev, apdev, params):
  223. """WPA2-Enterprise connection using EAP-SIM (SQL)"""
  224. check_hlr_auc_gw_support()
  225. try:
  226. import sqlite3
  227. except ImportError:
  228. raise HwsimSkip("No sqlite3 module available")
  229. con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db"))
  230. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  231. params['auth_server_port'] = "1814"
  232. hapd = hostapd.add_ap(apdev[0], params)
  233. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  234. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  235. logger.info("SIM fast re-authentication")
  236. eap_reauth(dev[0], "SIM")
  237. logger.info("SIM full auth with pseudonym")
  238. with con:
  239. cur = con.cursor()
  240. cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'")
  241. eap_reauth(dev[0], "SIM")
  242. logger.info("SIM full auth with permanent identity")
  243. with con:
  244. cur = con.cursor()
  245. cur.execute("DELETE FROM reauth WHERE permanent='1232010000000000'")
  246. cur.execute("DELETE FROM pseudonyms WHERE permanent='1232010000000000'")
  247. eap_reauth(dev[0], "SIM")
  248. logger.info("SIM reauth with mismatching MK")
  249. with con:
  250. cur = con.cursor()
  251. cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='1232010000000000'")
  252. eap_reauth(dev[0], "SIM", expect_failure=True)
  253. dev[0].request("REMOVE_NETWORK all")
  254. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  255. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  256. with con:
  257. cur = con.cursor()
  258. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'")
  259. eap_reauth(dev[0], "SIM")
  260. with con:
  261. cur = con.cursor()
  262. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='1232010000000000'")
  263. logger.info("SIM reauth with mismatching counter")
  264. eap_reauth(dev[0], "SIM")
  265. dev[0].request("REMOVE_NETWORK all")
  266. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  267. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  268. with con:
  269. cur = con.cursor()
  270. cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='1232010000000000'")
  271. logger.info("SIM reauth with max reauth count reached")
  272. eap_reauth(dev[0], "SIM")
  273. def test_ap_wpa2_eap_sim_config(dev, apdev):
  274. """EAP-SIM configuration options"""
  275. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  276. hapd = hostapd.add_ap(apdev[0], params)
  277. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
  278. identity="1232010000000000",
  279. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  280. phase1="sim_min_num_chal=1",
  281. wait_connect=False, scan_freq="2412")
  282. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10)
  283. if ev is None:
  284. raise Exception("No EAP error message seen")
  285. dev[0].request("REMOVE_NETWORK all")
  286. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
  287. identity="1232010000000000",
  288. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  289. phase1="sim_min_num_chal=4",
  290. wait_connect=False, scan_freq="2412")
  291. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 18 (SIM)"], timeout=10)
  292. if ev is None:
  293. raise Exception("No EAP error message seen (2)")
  294. dev[0].request("REMOVE_NETWORK all")
  295. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  296. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  297. phase1="sim_min_num_chal=2")
  298. eap_connect(dev[1], hapd, "SIM", "1232010000000000",
  299. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  300. anonymous_identity="345678")
  301. def test_ap_wpa2_eap_sim_ext(dev, apdev):
  302. """WPA2-Enterprise connection using EAP-SIM and external GSM auth"""
  303. try:
  304. _test_ap_wpa2_eap_sim_ext(dev, apdev)
  305. finally:
  306. dev[0].request("SET external_sim 0")
  307. def _test_ap_wpa2_eap_sim_ext(dev, apdev):
  308. check_hlr_auc_gw_support()
  309. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  310. hostapd.add_ap(apdev[0], params)
  311. dev[0].request("SET external_sim 1")
  312. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  313. identity="1232010000000000",
  314. wait_connect=False, scan_freq="2412")
  315. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  316. if ev is None:
  317. raise Exception("Network connected timed out")
  318. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  319. if ev is None:
  320. raise Exception("Wait for external SIM processing request timed out")
  321. p = ev.split(':', 2)
  322. if p[1] != "GSM-AUTH":
  323. raise Exception("Unexpected CTRL-REQ-SIM type")
  324. rid = p[0].split('-')[3]
  325. # IK:CK:RES
  326. resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344"
  327. # This will fail during processing, but the ctrl_iface command succeeds
  328. dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTH:" + resp)
  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:q"):
  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:34"):
  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"):
  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:q"):
  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"):
  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. dev[0].request("DISCONNECT")
  418. dev[0].wait_disconnected()
  419. time.sleep(0.1)
  420. dev[0].select_network(id, freq="2412")
  421. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  422. if ev is None:
  423. raise Exception("Wait for external SIM processing request timed out")
  424. p = ev.split(':', 2)
  425. if p[1] != "GSM-AUTH":
  426. raise Exception("Unexpected CTRL-REQ-SIM type")
  427. rid = p[0].split('-')[3]
  428. # This will fail during GSM auth validation
  429. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:0011223344556677:00112233:q"):
  430. raise Exception("CTRL-RSP-SIM failed")
  431. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  432. if ev is None:
  433. raise Exception("EAP failure not reported")
  434. def test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev):
  435. """EAP-SIM with external GSM auth and replacing SIM without clearing pseudonym id"""
  436. try:
  437. _test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev)
  438. finally:
  439. dev[0].request("SET external_sim 0")
  440. def _test_ap_wpa2_eap_sim_ext_replace_sim(dev, apdev):
  441. check_hlr_auc_gw_support()
  442. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  443. hostapd.add_ap(apdev[0], params)
  444. dev[0].request("SET external_sim 1")
  445. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  446. identity="1232010000000000",
  447. wait_connect=False, scan_freq="2412")
  448. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  449. if ev is None:
  450. raise Exception("Wait for external SIM processing request timed out")
  451. p = ev.split(':', 2)
  452. if p[1] != "GSM-AUTH":
  453. raise Exception("Unexpected CTRL-REQ-SIM type")
  454. rid = p[0].split('-')[3]
  455. rand = p[2].split(' ')[0]
  456. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  457. "-m",
  458. "auth_serv/hlr_auc_gw.milenage_db",
  459. "GSM-AUTH-REQ 232010000000000 " + rand])
  460. if "GSM-AUTH-RESP" not in res:
  461. raise Exception("Unexpected hlr_auc_gw response")
  462. resp = res.split(' ')[2].rstrip()
  463. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  464. dev[0].wait_connected(timeout=15)
  465. dev[0].request("DISCONNECT")
  466. dev[0].wait_disconnected()
  467. # Replace SIM, but forget to drop the previous pseudonym identity
  468. dev[0].set_network_quoted(id, "identity", "1232010000000009")
  469. dev[0].select_network(id, freq="2412")
  470. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  471. if ev is None:
  472. raise Exception("Wait for external SIM processing request timed out")
  473. p = ev.split(':', 2)
  474. if p[1] != "GSM-AUTH":
  475. raise Exception("Unexpected CTRL-REQ-SIM type")
  476. rid = p[0].split('-')[3]
  477. rand = p[2].split(' ')[0]
  478. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  479. "-m",
  480. "auth_serv/hlr_auc_gw.milenage_db",
  481. "GSM-AUTH-REQ 232010000000009 " + rand])
  482. if "GSM-AUTH-RESP" not in res:
  483. raise Exception("Unexpected hlr_auc_gw response")
  484. resp = res.split(' ')[2].rstrip()
  485. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  486. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  487. if ev is None:
  488. raise Exception("EAP-Failure not reported")
  489. dev[0].request("DISCONNECT")
  490. dev[0].wait_disconnected()
  491. def test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev):
  492. """EAP-SIM with external GSM auth and replacing SIM and clearing pseudonym identity"""
  493. try:
  494. _test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev)
  495. finally:
  496. dev[0].request("SET external_sim 0")
  497. def _test_ap_wpa2_eap_sim_ext_replace_sim2(dev, apdev):
  498. check_hlr_auc_gw_support()
  499. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  500. hostapd.add_ap(apdev[0], params)
  501. dev[0].request("SET external_sim 1")
  502. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  503. identity="1232010000000000",
  504. wait_connect=False, scan_freq="2412")
  505. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  506. if ev is None:
  507. raise Exception("Wait for external SIM processing request timed out")
  508. p = ev.split(':', 2)
  509. if p[1] != "GSM-AUTH":
  510. raise Exception("Unexpected CTRL-REQ-SIM type")
  511. rid = p[0].split('-')[3]
  512. rand = p[2].split(' ')[0]
  513. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  514. "-m",
  515. "auth_serv/hlr_auc_gw.milenage_db",
  516. "GSM-AUTH-REQ 232010000000000 " + rand])
  517. if "GSM-AUTH-RESP" not in res:
  518. raise Exception("Unexpected hlr_auc_gw response")
  519. resp = res.split(' ')[2].rstrip()
  520. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  521. dev[0].wait_connected(timeout=15)
  522. dev[0].request("DISCONNECT")
  523. dev[0].wait_disconnected()
  524. # Replace SIM and drop the previous pseudonym identity
  525. dev[0].set_network_quoted(id, "identity", "1232010000000009")
  526. dev[0].set_network(id, "anonymous_identity", "NULL")
  527. dev[0].select_network(id, freq="2412")
  528. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  529. if ev is None:
  530. raise Exception("Wait for external SIM processing request timed out")
  531. p = ev.split(':', 2)
  532. if p[1] != "GSM-AUTH":
  533. raise Exception("Unexpected CTRL-REQ-SIM type")
  534. rid = p[0].split('-')[3]
  535. rand = p[2].split(' ')[0]
  536. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  537. "-m",
  538. "auth_serv/hlr_auc_gw.milenage_db",
  539. "GSM-AUTH-REQ 232010000000009 " + rand])
  540. if "GSM-AUTH-RESP" not in res:
  541. raise Exception("Unexpected hlr_auc_gw response")
  542. resp = res.split(' ')[2].rstrip()
  543. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  544. dev[0].wait_connected()
  545. dev[0].request("DISCONNECT")
  546. dev[0].wait_disconnected()
  547. def test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev):
  548. """EAP-SIM with external GSM auth, replacing SIM, and no identity in config"""
  549. try:
  550. _test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev)
  551. finally:
  552. dev[0].request("SET external_sim 0")
  553. def _test_ap_wpa2_eap_sim_ext_replace_sim3(dev, apdev):
  554. check_hlr_auc_gw_support()
  555. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  556. hostapd.add_ap(apdev[0], params)
  557. dev[0].request("SET external_sim 1")
  558. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  559. wait_connect=False, scan_freq="2412")
  560. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  561. if ev is None:
  562. raise Exception("Request for identity timed out")
  563. rid = ev.split(':')[0].split('-')[-1]
  564. dev[0].request("CTRL-RSP-IDENTITY-" + rid + ":1232010000000000")
  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] != "GSM-AUTH":
  570. raise Exception("Unexpected CTRL-REQ-SIM type")
  571. rid = p[0].split('-')[3]
  572. rand = p[2].split(' ')[0]
  573. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  574. "-m",
  575. "auth_serv/hlr_auc_gw.milenage_db",
  576. "GSM-AUTH-REQ 232010000000000 " + rand])
  577. if "GSM-AUTH-RESP" not in res:
  578. raise Exception("Unexpected hlr_auc_gw response")
  579. resp = res.split(' ')[2].rstrip()
  580. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  581. dev[0].wait_connected(timeout=15)
  582. dev[0].request("DISCONNECT")
  583. dev[0].wait_disconnected()
  584. # Replace SIM and drop the previous permanent and pseudonym identities
  585. dev[0].set_network(id, "identity", "NULL")
  586. dev[0].set_network(id, "anonymous_identity", "NULL")
  587. dev[0].select_network(id, freq="2412")
  588. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  589. if ev is None:
  590. raise Exception("Request for identity timed out")
  591. rid = ev.split(':')[0].split('-')[-1]
  592. dev[0].request("CTRL-RSP-IDENTITY-" + rid + ":1232010000000009")
  593. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  594. if ev is None:
  595. raise Exception("Wait for external SIM processing request timed out")
  596. p = ev.split(':', 2)
  597. if p[1] != "GSM-AUTH":
  598. raise Exception("Unexpected CTRL-REQ-SIM type")
  599. rid = p[0].split('-')[3]
  600. rand = p[2].split(' ')[0]
  601. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  602. "-m",
  603. "auth_serv/hlr_auc_gw.milenage_db",
  604. "GSM-AUTH-REQ 232010000000009 " + rand])
  605. if "GSM-AUTH-RESP" not in res:
  606. raise Exception("Unexpected hlr_auc_gw response")
  607. resp = res.split(' ')[2].rstrip()
  608. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  609. dev[0].wait_connected()
  610. dev[0].request("DISCONNECT")
  611. dev[0].wait_disconnected()
  612. def test_ap_wpa2_eap_sim_ext_auth_fail(dev, apdev):
  613. """EAP-SIM with external GSM auth and auth failing"""
  614. try:
  615. _test_ap_wpa2_eap_sim_ext_auth_fail(dev, apdev)
  616. finally:
  617. dev[0].request("SET external_sim 0")
  618. def _test_ap_wpa2_eap_sim_ext_auth_fail(dev, apdev):
  619. check_hlr_auc_gw_support()
  620. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  621. hostapd.add_ap(apdev[0], params)
  622. dev[0].request("SET external_sim 1")
  623. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  624. identity="1232010000000000",
  625. wait_connect=False, scan_freq="2412")
  626. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  627. if ev is None:
  628. raise Exception("Wait for external SIM processing request timed out")
  629. p = ev.split(':', 2)
  630. rid = p[0].split('-')[3]
  631. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-FAIL")
  632. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  633. if ev is None:
  634. raise Exception("EAP failure not reported")
  635. dev[0].request("REMOVE_NETWORK all")
  636. dev[0].wait_disconnected()
  637. def test_ap_wpa2_eap_sim_change_bssid(dev, apdev):
  638. """EAP-SIM and external GSM auth to check fast reauth with bssid change"""
  639. try:
  640. _test_ap_wpa2_eap_sim_change_bssid(dev, apdev)
  641. finally:
  642. dev[0].request("SET external_sim 0")
  643. def _test_ap_wpa2_eap_sim_change_bssid(dev, apdev):
  644. check_hlr_auc_gw_support()
  645. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  646. hostapd.add_ap(apdev[0], params)
  647. dev[0].request("SET external_sim 1")
  648. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  649. identity="1232010000000000",
  650. wait_connect=False, scan_freq="2412")
  651. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  652. if ev is None:
  653. raise Exception("Wait for external SIM processing request timed out")
  654. p = ev.split(':', 2)
  655. if p[1] != "GSM-AUTH":
  656. raise Exception("Unexpected CTRL-REQ-SIM type")
  657. rid = p[0].split('-')[3]
  658. rand = p[2].split(' ')[0]
  659. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  660. "-m",
  661. "auth_serv/hlr_auc_gw.milenage_db",
  662. "GSM-AUTH-REQ 232010000000000 " + rand])
  663. if "GSM-AUTH-RESP" not in res:
  664. raise Exception("Unexpected hlr_auc_gw response")
  665. resp = res.split(' ')[2].rstrip()
  666. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  667. dev[0].wait_connected(timeout=15)
  668. # Verify that EAP-SIM Reauthentication can be used after a profile change
  669. # that does not affect EAP parameters.
  670. dev[0].set_network(id, "bssid", "any")
  671. eap_reauth(dev[0], "SIM")
  672. def test_ap_wpa2_eap_sim_no_change_set(dev, apdev):
  673. """EAP-SIM and external GSM auth to check fast reauth with no-change SET_NETWORK"""
  674. try:
  675. _test_ap_wpa2_eap_sim_no_change_set(dev, apdev)
  676. finally:
  677. dev[0].request("SET external_sim 0")
  678. def _test_ap_wpa2_eap_sim_no_change_set(dev, apdev):
  679. check_hlr_auc_gw_support()
  680. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  681. hostapd.add_ap(apdev[0], params)
  682. dev[0].request("SET external_sim 1")
  683. id = dev[0].connect("test-wpa2-eap", eap="SIM", key_mgmt="WPA-EAP",
  684. identity="1232010000000000",
  685. wait_connect=False, scan_freq="2412")
  686. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  687. if ev is None:
  688. raise Exception("Wait for external SIM processing request timed out")
  689. p = ev.split(':', 2)
  690. if p[1] != "GSM-AUTH":
  691. raise Exception("Unexpected CTRL-REQ-SIM type")
  692. rid = p[0].split('-')[3]
  693. rand = p[2].split(' ')[0]
  694. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  695. "-m",
  696. "auth_serv/hlr_auc_gw.milenage_db",
  697. "GSM-AUTH-REQ 232010000000000 " + rand])
  698. if "GSM-AUTH-RESP" not in res:
  699. raise Exception("Unexpected hlr_auc_gw response")
  700. resp = res.split(' ')[2].rstrip()
  701. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  702. dev[0].wait_connected(timeout=15)
  703. # Verify that EAP-SIM Reauthentication can be used after network profile
  704. # SET_NETWORK commands that do not actually change previously set
  705. # parameter values.
  706. dev[0].set_network(id, "key_mgmt", "WPA-EAP")
  707. dev[0].set_network(id, "eap", "SIM")
  708. dev[0].set_network_quoted(id, "identity", "1232010000000000")
  709. dev[0].set_network_quoted(id, "ssid", "test-wpa2-eap")
  710. eap_reauth(dev[0], "SIM")
  711. def test_ap_wpa2_eap_sim_oom(dev, apdev):
  712. """EAP-SIM and OOM"""
  713. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  714. hostapd.add_ap(apdev[0], params)
  715. tests = [ (1, "milenage_f2345"),
  716. (2, "milenage_f2345"),
  717. (3, "milenage_f2345"),
  718. (4, "milenage_f2345"),
  719. (5, "milenage_f2345"),
  720. (6, "milenage_f2345"),
  721. (7, "milenage_f2345"),
  722. (8, "milenage_f2345"),
  723. (9, "milenage_f2345"),
  724. (10, "milenage_f2345"),
  725. (11, "milenage_f2345"),
  726. (12, "milenage_f2345") ]
  727. for count, func in tests:
  728. with fail_test(dev[0], count, func):
  729. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
  730. identity="1232010000000000",
  731. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  732. wait_connect=False, scan_freq="2412")
  733. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  734. if ev is None:
  735. raise Exception("EAP method not selected")
  736. dev[0].wait_disconnected()
  737. dev[0].request("REMOVE_NETWORK all")
  738. def test_ap_wpa2_eap_aka(dev, apdev):
  739. """WPA2-Enterprise connection using EAP-AKA"""
  740. check_hlr_auc_gw_support()
  741. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  742. hapd = hostapd.add_ap(apdev[0], params)
  743. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  744. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  745. hwsim_utils.test_connectivity(dev[0], hapd)
  746. eap_reauth(dev[0], "AKA")
  747. logger.info("Negative test with incorrect key")
  748. dev[0].request("REMOVE_NETWORK all")
  749. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  750. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  751. expect_failure=True)
  752. logger.info("Invalid Milenage key")
  753. dev[0].request("REMOVE_NETWORK all")
  754. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  755. password="ffdca4eda45b53cf0f12d7c9c3bc6a",
  756. expect_failure=True)
  757. logger.info("Invalid Milenage key(2)")
  758. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  759. password="ffdca4eda45b53cf0f12d7c9c3bc6a8q:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  760. expect_failure=True)
  761. logger.info("Invalid Milenage key(3)")
  762. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  763. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb8258q:000000000123",
  764. expect_failure=True)
  765. logger.info("Invalid Milenage key(4)")
  766. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  767. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:00000000012q",
  768. expect_failure=True)
  769. logger.info("Invalid Milenage key(5)")
  770. dev[0].request("REMOVE_NETWORK all")
  771. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  772. password="ffdca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581q000000000123",
  773. expect_failure=True)
  774. logger.info("Invalid Milenage key(6)")
  775. dev[0].request("REMOVE_NETWORK all")
  776. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  777. password="ffdca4eda45b53cf0f12d7c9c3bc6a89qcb9cccc4b9258e6dca4760379fb82581q000000000123",
  778. expect_failure=True)
  779. logger.info("Missing key configuration")
  780. dev[0].request("REMOVE_NETWORK all")
  781. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  782. expect_failure=True)
  783. def test_ap_wpa2_eap_aka_sql(dev, apdev, params):
  784. """WPA2-Enterprise connection using EAP-AKA (SQL)"""
  785. check_hlr_auc_gw_support()
  786. try:
  787. import sqlite3
  788. except ImportError:
  789. raise HwsimSkip("No sqlite3 module available")
  790. con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db"))
  791. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  792. params['auth_server_port'] = "1814"
  793. hapd = hostapd.add_ap(apdev[0], params)
  794. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  795. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  796. logger.info("AKA fast re-authentication")
  797. eap_reauth(dev[0], "AKA")
  798. logger.info("AKA full auth with pseudonym")
  799. with con:
  800. cur = con.cursor()
  801. cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'")
  802. eap_reauth(dev[0], "AKA")
  803. logger.info("AKA full auth with permanent identity")
  804. with con:
  805. cur = con.cursor()
  806. cur.execute("DELETE FROM reauth WHERE permanent='0232010000000000'")
  807. cur.execute("DELETE FROM pseudonyms WHERE permanent='0232010000000000'")
  808. eap_reauth(dev[0], "AKA")
  809. logger.info("AKA reauth with mismatching MK")
  810. with con:
  811. cur = con.cursor()
  812. cur.execute("UPDATE reauth SET mk='0000000000000000000000000000000000000000' WHERE permanent='0232010000000000'")
  813. eap_reauth(dev[0], "AKA", expect_failure=True)
  814. dev[0].request("REMOVE_NETWORK all")
  815. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  816. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  817. with con:
  818. cur = con.cursor()
  819. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'")
  820. eap_reauth(dev[0], "AKA")
  821. with con:
  822. cur = con.cursor()
  823. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='0232010000000000'")
  824. logger.info("AKA reauth with mismatching counter")
  825. eap_reauth(dev[0], "AKA")
  826. dev[0].request("REMOVE_NETWORK all")
  827. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  828. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  829. with con:
  830. cur = con.cursor()
  831. cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='0232010000000000'")
  832. logger.info("AKA reauth with max reauth count reached")
  833. eap_reauth(dev[0], "AKA")
  834. def test_ap_wpa2_eap_aka_config(dev, apdev):
  835. """EAP-AKA configuration options"""
  836. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  837. hapd = hostapd.add_ap(apdev[0], params)
  838. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  839. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  840. anonymous_identity="2345678")
  841. def test_ap_wpa2_eap_aka_ext(dev, apdev):
  842. """WPA2-Enterprise connection using EAP-AKA and external UMTS auth"""
  843. try:
  844. _test_ap_wpa2_eap_aka_ext(dev, apdev)
  845. finally:
  846. dev[0].request("SET external_sim 0")
  847. def _test_ap_wpa2_eap_aka_ext(dev, apdev):
  848. check_hlr_auc_gw_support()
  849. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  850. hostapd.add_ap(apdev[0], params)
  851. dev[0].request("SET external_sim 1")
  852. id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP",
  853. identity="0232010000000000",
  854. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  855. wait_connect=False, scan_freq="2412")
  856. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  857. if ev is None:
  858. raise Exception("Network connected timed out")
  859. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  860. if ev is None:
  861. raise Exception("Wait for external SIM processing request timed out")
  862. p = ev.split(':', 2)
  863. if p[1] != "UMTS-AUTH":
  864. raise Exception("Unexpected CTRL-REQ-SIM type")
  865. rid = p[0].split('-')[3]
  866. # IK:CK:RES
  867. resp = "00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344"
  868. # This will fail during processing, but the ctrl_iface command succeeds
  869. dev[0].request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  870. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  871. if ev is None:
  872. raise Exception("EAP failure not reported")
  873. dev[0].request("DISCONNECT")
  874. dev[0].wait_disconnected()
  875. time.sleep(0.1)
  876. dev[0].dump_monitor()
  877. dev[0].select_network(id, freq="2412")
  878. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  879. if ev is None:
  880. raise Exception("Wait for external SIM processing request timed out")
  881. p = ev.split(':', 2)
  882. if p[1] != "UMTS-AUTH":
  883. raise Exception("Unexpected CTRL-REQ-SIM type")
  884. rid = p[0].split('-')[3]
  885. # This will fail during UMTS auth validation
  886. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"):
  887. raise Exception("CTRL-RSP-SIM failed")
  888. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  889. if ev is None:
  890. raise Exception("Wait for external SIM processing request timed out")
  891. p = ev.split(':', 2)
  892. if p[1] != "UMTS-AUTH":
  893. raise Exception("Unexpected CTRL-REQ-SIM type")
  894. rid = p[0].split('-')[3]
  895. # This will fail during UMTS auth validation
  896. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:12"):
  897. raise Exception("CTRL-RSP-SIM failed")
  898. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  899. if ev is None:
  900. raise Exception("EAP failure not reported")
  901. dev[0].request("DISCONNECT")
  902. dev[0].wait_disconnected()
  903. time.sleep(0.1)
  904. dev[0].dump_monitor()
  905. tests = [ ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:0011223344",
  906. ":UMTS-AUTH:34",
  907. ":UMTS-AUTH:00112233445566778899aabbccddeeff.00112233445566778899aabbccddeeff:0011223344",
  908. ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddee:0011223344",
  909. ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff.0011223344",
  910. ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff0011223344",
  911. ":UMTS-AUTH:00112233445566778899aabbccddeeff:00112233445566778899aabbccddeeff:001122334q" ]
  912. for t in tests:
  913. dev[0].select_network(id, freq="2412")
  914. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  915. if ev is None:
  916. raise Exception("Wait for external SIM processing request timed out")
  917. p = ev.split(':', 2)
  918. if p[1] != "UMTS-AUTH":
  919. raise Exception("Unexpected CTRL-REQ-SIM type")
  920. rid = p[0].split('-')[3]
  921. # This will fail during UMTS auth validation
  922. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + t):
  923. raise Exception("CTRL-RSP-SIM failed")
  924. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  925. if ev is None:
  926. raise Exception("EAP failure not reported")
  927. dev[0].request("DISCONNECT")
  928. dev[0].wait_disconnected()
  929. time.sleep(0.1)
  930. dev[0].dump_monitor()
  931. def test_ap_wpa2_eap_aka_ext_auth_fail(dev, apdev):
  932. """EAP-AKA with external UMTS auth and auth failing"""
  933. try:
  934. _test_ap_wpa2_eap_aka_ext_auth_fail(dev, apdev)
  935. finally:
  936. dev[0].request("SET external_sim 0")
  937. def _test_ap_wpa2_eap_aka_ext_auth_fail(dev, apdev):
  938. check_hlr_auc_gw_support()
  939. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  940. hostapd.add_ap(apdev[0], params)
  941. dev[0].request("SET external_sim 1")
  942. id = dev[0].connect("test-wpa2-eap", eap="AKA", key_mgmt="WPA-EAP",
  943. identity="0232010000000000",
  944. wait_connect=False, scan_freq="2412")
  945. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  946. if ev is None:
  947. raise Exception("Wait for external SIM processing request timed out")
  948. p = ev.split(':', 2)
  949. rid = p[0].split('-')[3]
  950. dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-FAIL")
  951. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  952. if ev is None:
  953. raise Exception("EAP failure not reported")
  954. dev[0].request("REMOVE_NETWORK all")
  955. dev[0].wait_disconnected()
  956. def test_ap_wpa2_eap_aka_prime(dev, apdev):
  957. """WPA2-Enterprise connection using EAP-AKA'"""
  958. check_hlr_auc_gw_support()
  959. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  960. hapd = hostapd.add_ap(apdev[0], params)
  961. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  962. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  963. hwsim_utils.test_connectivity(dev[0], hapd)
  964. eap_reauth(dev[0], "AKA'")
  965. logger.info("EAP-AKA' bidding protection when EAP-AKA enabled as well")
  966. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="AKA' AKA",
  967. identity="6555444333222111@both",
  968. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  969. wait_connect=False, scan_freq="2412")
  970. dev[1].wait_connected(timeout=15)
  971. logger.info("Negative test with incorrect key")
  972. dev[0].request("REMOVE_NETWORK all")
  973. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  974. password="ff22250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  975. expect_failure=True)
  976. def test_ap_wpa2_eap_aka_prime_sql(dev, apdev, params):
  977. """WPA2-Enterprise connection using EAP-AKA' (SQL)"""
  978. check_hlr_auc_gw_support()
  979. try:
  980. import sqlite3
  981. except ImportError:
  982. raise HwsimSkip("No sqlite3 module available")
  983. con = sqlite3.connect(os.path.join(params['logdir'], "hostapd.db"))
  984. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  985. params['auth_server_port'] = "1814"
  986. hapd = hostapd.add_ap(apdev[0], params)
  987. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  988. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  989. logger.info("AKA' fast re-authentication")
  990. eap_reauth(dev[0], "AKA'")
  991. logger.info("AKA' full auth with pseudonym")
  992. with con:
  993. cur = con.cursor()
  994. cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'")
  995. eap_reauth(dev[0], "AKA'")
  996. logger.info("AKA' full auth with permanent identity")
  997. with con:
  998. cur = con.cursor()
  999. cur.execute("DELETE FROM reauth WHERE permanent='6555444333222111'")
  1000. cur.execute("DELETE FROM pseudonyms WHERE permanent='6555444333222111'")
  1001. eap_reauth(dev[0], "AKA'")
  1002. logger.info("AKA' reauth with mismatching k_aut")
  1003. with con:
  1004. cur = con.cursor()
  1005. cur.execute("UPDATE reauth SET k_aut='0000000000000000000000000000000000000000000000000000000000000000' WHERE permanent='6555444333222111'")
  1006. eap_reauth(dev[0], "AKA'", expect_failure=True)
  1007. dev[0].request("REMOVE_NETWORK all")
  1008. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  1009. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  1010. with con:
  1011. cur = con.cursor()
  1012. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'")
  1013. eap_reauth(dev[0], "AKA'")
  1014. with con:
  1015. cur = con.cursor()
  1016. cur.execute("UPDATE reauth SET counter='10' WHERE permanent='6555444333222111'")
  1017. logger.info("AKA' reauth with mismatching counter")
  1018. eap_reauth(dev[0], "AKA'")
  1019. dev[0].request("REMOVE_NETWORK all")
  1020. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  1021. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  1022. with con:
  1023. cur = con.cursor()
  1024. cur.execute("UPDATE reauth SET counter='1001' WHERE permanent='6555444333222111'")
  1025. logger.info("AKA' reauth with max reauth count reached")
  1026. eap_reauth(dev[0], "AKA'")
  1027. def test_ap_wpa2_eap_aka_prime_ext_auth_fail(dev, apdev):
  1028. """EAP-AKA' with external UMTS auth and auth failing"""
  1029. try:
  1030. _test_ap_wpa2_eap_aka_prime_ext_auth_fail(dev, apdev)
  1031. finally:
  1032. dev[0].request("SET external_sim 0")
  1033. def _test_ap_wpa2_eap_aka_prime_ext_auth_fail(dev, apdev):
  1034. check_hlr_auc_gw_support()
  1035. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1036. hostapd.add_ap(apdev[0], params)
  1037. dev[0].request("SET external_sim 1")
  1038. id = dev[0].connect("test-wpa2-eap", eap="AKA'", key_mgmt="WPA-EAP",
  1039. identity="6555444333222111",
  1040. wait_connect=False, scan_freq="2412")
  1041. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  1042. if ev is None:
  1043. raise Exception("Wait for external SIM processing request timed out")
  1044. p = ev.split(':', 2)
  1045. rid = p[0].split('-')[3]
  1046. dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-FAIL")
  1047. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  1048. if ev is None:
  1049. raise Exception("EAP failure not reported")
  1050. dev[0].request("REMOVE_NETWORK all")
  1051. dev[0].wait_disconnected()
  1052. def test_ap_wpa2_eap_aka_prime_ext(dev, apdev):
  1053. """EAP-AKA' with external UMTS auth to hit Synchronization-Failure"""
  1054. try:
  1055. _test_ap_wpa2_eap_aka_prime_ext(dev, apdev)
  1056. finally:
  1057. dev[0].request("SET external_sim 0")
  1058. def _test_ap_wpa2_eap_aka_prime_ext(dev, apdev):
  1059. check_hlr_auc_gw_support()
  1060. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1061. hostapd.add_ap(apdev[0], params)
  1062. dev[0].request("SET external_sim 1")
  1063. id = dev[0].connect("test-wpa2-eap", eap="AKA'", key_mgmt="WPA-EAP",
  1064. identity="6555444333222111",
  1065. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1066. wait_connect=False, scan_freq="2412")
  1067. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  1068. if ev is None:
  1069. raise Exception("Network connected timed out")
  1070. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  1071. if ev is None:
  1072. raise Exception("Wait for external SIM processing request timed out")
  1073. p = ev.split(':', 2)
  1074. if p[1] != "UMTS-AUTH":
  1075. raise Exception("Unexpected CTRL-REQ-SIM type")
  1076. rid = p[0].split('-')[3]
  1077. # This will fail during UMTS auth validation
  1078. if "OK" not in dev[0].request("CTRL-RSP-SIM-" + rid + ":UMTS-AUTS:112233445566778899aabbccddee"):
  1079. raise Exception("CTRL-RSP-SIM failed")
  1080. ev = dev[0].wait_event(["CTRL-REQ-SIM"], timeout=15)
  1081. if ev is None:
  1082. raise Exception("Wait for external SIM processing request timed out")
  1083. def test_ap_wpa2_eap_ttls_pap(dev, apdev):
  1084. """WPA2-Enterprise connection using EAP-TTLS/PAP"""
  1085. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1086. hapd = hostapd.add_ap(apdev[0], params)
  1087. key_mgmt = hapd.get_config()['key_mgmt']
  1088. if key_mgmt.split(' ')[0] != "WPA-EAP":
  1089. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  1090. eap_connect(dev[0], hapd, "TTLS", "pap user",
  1091. anonymous_identity="ttls", password="password",
  1092. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  1093. hwsim_utils.test_connectivity(dev[0], hapd)
  1094. eap_reauth(dev[0], "TTLS")
  1095. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-1"),
  1096. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-1") ])
  1097. def test_ap_wpa2_eap_ttls_pap_subject_match(dev, apdev):
  1098. """WPA2-Enterprise connection using EAP-TTLS/PAP and (alt)subject_match"""
  1099. check_subject_match_support(dev[0])
  1100. check_altsubject_match_support(dev[0])
  1101. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1102. hapd = hostapd.add_ap(apdev[0], params)
  1103. eap_connect(dev[0], hapd, "TTLS", "pap user",
  1104. anonymous_identity="ttls", password="password",
  1105. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  1106. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  1107. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/")
  1108. eap_reauth(dev[0], "TTLS")
  1109. def test_ap_wpa2_eap_ttls_pap_incorrect_password(dev, apdev):
  1110. """WPA2-Enterprise connection using EAP-TTLS/PAP - incorrect password"""
  1111. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1112. hapd = hostapd.add_ap(apdev[0], params)
  1113. eap_connect(dev[0], hapd, "TTLS", "pap user",
  1114. anonymous_identity="ttls", password="wrong",
  1115. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  1116. expect_failure=True)
  1117. eap_connect(dev[1], hapd, "TTLS", "user",
  1118. anonymous_identity="ttls", password="password",
  1119. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  1120. expect_failure=True)
  1121. def test_ap_wpa2_eap_ttls_chap(dev, apdev):
  1122. """WPA2-Enterprise connection using EAP-TTLS/CHAP"""
  1123. skip_with_fips(dev[0])
  1124. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1125. hapd = hostapd.add_ap(apdev[0], params)
  1126. eap_connect(dev[0], hapd, "TTLS", "chap user",
  1127. anonymous_identity="ttls", password="password",
  1128. ca_cert="auth_serv/ca.der", phase2="auth=CHAP")
  1129. hwsim_utils.test_connectivity(dev[0], hapd)
  1130. eap_reauth(dev[0], "TTLS")
  1131. def test_ap_wpa2_eap_ttls_chap_altsubject_match(dev, apdev):
  1132. """WPA2-Enterprise connection using EAP-TTLS/CHAP"""
  1133. skip_with_fips(dev[0])
  1134. check_altsubject_match_support(dev[0])
  1135. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1136. hapd = hostapd.add_ap(apdev[0], params)
  1137. eap_connect(dev[0], hapd, "TTLS", "chap user",
  1138. anonymous_identity="ttls", password="password",
  1139. ca_cert="auth_serv/ca.der", phase2="auth=CHAP",
  1140. altsubject_match="EMAIL:noone@example.com;URI:http://example.com/;DNS:server.w1.fi")
  1141. eap_reauth(dev[0], "TTLS")
  1142. def test_ap_wpa2_eap_ttls_chap_incorrect_password(dev, apdev):
  1143. """WPA2-Enterprise connection using EAP-TTLS/CHAP - incorrect password"""
  1144. skip_with_fips(dev[0])
  1145. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1146. hapd = hostapd.add_ap(apdev[0], params)
  1147. eap_connect(dev[0], hapd, "TTLS", "chap user",
  1148. anonymous_identity="ttls", password="wrong",
  1149. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP",
  1150. expect_failure=True)
  1151. eap_connect(dev[1], hapd, "TTLS", "user",
  1152. anonymous_identity="ttls", password="password",
  1153. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP",
  1154. expect_failure=True)
  1155. def test_ap_wpa2_eap_ttls_mschap(dev, apdev):
  1156. """WPA2-Enterprise connection using EAP-TTLS/MSCHAP"""
  1157. skip_with_fips(dev[0])
  1158. check_domain_suffix_match(dev[0])
  1159. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1160. hapd = hostapd.add_ap(apdev[0], params)
  1161. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  1162. anonymous_identity="ttls", password="password",
  1163. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1164. domain_suffix_match="server.w1.fi")
  1165. hwsim_utils.test_connectivity(dev[0], hapd)
  1166. eap_reauth(dev[0], "TTLS")
  1167. dev[0].request("REMOVE_NETWORK all")
  1168. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  1169. anonymous_identity="ttls", password="password",
  1170. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1171. fragment_size="200")
  1172. dev[0].request("REMOVE_NETWORK all")
  1173. dev[0].wait_disconnected()
  1174. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  1175. anonymous_identity="ttls",
  1176. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1177. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  1178. def test_ap_wpa2_eap_ttls_mschap_incorrect_password(dev, apdev):
  1179. """WPA2-Enterprise connection using EAP-TTLS/MSCHAP - incorrect password"""
  1180. skip_with_fips(dev[0])
  1181. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1182. hapd = hostapd.add_ap(apdev[0], params)
  1183. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  1184. anonymous_identity="ttls", password="wrong",
  1185. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1186. expect_failure=True)
  1187. eap_connect(dev[1], hapd, "TTLS", "user",
  1188. anonymous_identity="ttls", password="password",
  1189. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1190. expect_failure=True)
  1191. eap_connect(dev[2], hapd, "TTLS", "no such user",
  1192. anonymous_identity="ttls", password="password",
  1193. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  1194. expect_failure=True)
  1195. def test_ap_wpa2_eap_ttls_mschapv2(dev, apdev):
  1196. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2"""
  1197. check_domain_suffix_match(dev[0])
  1198. check_eap_capa(dev[0], "MSCHAPV2")
  1199. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1200. hapd = hostapd.add_ap(apdev[0], params)
  1201. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  1202. anonymous_identity="ttls", password="password",
  1203. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1204. domain_suffix_match="server.w1.fi")
  1205. hwsim_utils.test_connectivity(dev[0], hapd)
  1206. sta1 = hapd.get_sta(dev[0].p2p_interface_addr())
  1207. eapol1 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol")
  1208. eap_reauth(dev[0], "TTLS")
  1209. sta2 = hapd.get_sta(dev[0].p2p_interface_addr())
  1210. eapol2 = hapd.get_sta(dev[0].p2p_interface_addr(), info="eapol")
  1211. if int(sta2['dot1xAuthEapolFramesRx']) <= int(sta1['dot1xAuthEapolFramesRx']):
  1212. raise Exception("dot1xAuthEapolFramesRx did not increase")
  1213. if int(eapol2['authAuthEapStartsWhileAuthenticated']) < 1:
  1214. raise Exception("authAuthEapStartsWhileAuthenticated did not increase")
  1215. if int(eapol2['backendAuthSuccesses']) <= int(eapol1['backendAuthSuccesses']):
  1216. raise Exception("backendAuthSuccesses did not increase")
  1217. logger.info("Password as hash value")
  1218. dev[0].request("REMOVE_NETWORK all")
  1219. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  1220. anonymous_identity="ttls",
  1221. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1222. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1223. def test_ap_wpa2_eap_ttls_invalid_phase2(dev, apdev):
  1224. """EAP-TTLS with invalid phase2 parameter values"""
  1225. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1226. hostapd.add_ap(apdev[0], params)
  1227. tests = [ "auth=MSCHAPv2", "auth=MSCHAPV2 autheap=MD5",
  1228. "autheap=MD5 auth=MSCHAPV2", "auth=PAP auth=CHAP",
  1229. "autheap=MD5 autheap=FOO autheap=MSCHAPV2" ]
  1230. for t in tests:
  1231. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1232. identity="DOMAIN\mschapv2 user",
  1233. anonymous_identity="ttls", password="password",
  1234. ca_cert="auth_serv/ca.pem", phase2=t,
  1235. wait_connect=False, scan_freq="2412")
  1236. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10)
  1237. if ev is None or "method=21" not in ev:
  1238. raise Exception("EAP-TTLS not started")
  1239. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method",
  1240. "CTRL-EVENT-CONNECTED"], timeout=5)
  1241. if ev is None or "CTRL-EVENT-CONNECTED" in ev:
  1242. raise Exception("No EAP-TTLS failure reported for phase2=" + t)
  1243. dev[0].request("REMOVE_NETWORK all")
  1244. dev[0].wait_disconnected()
  1245. dev[0].dump_monitor()
  1246. def test_ap_wpa2_eap_ttls_mschapv2_suffix_match(dev, apdev):
  1247. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2"""
  1248. check_domain_match_full(dev[0])
  1249. skip_with_fips(dev[0])
  1250. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1251. hapd = hostapd.add_ap(apdev[0], params)
  1252. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  1253. anonymous_identity="ttls", password="password",
  1254. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1255. domain_suffix_match="w1.fi")
  1256. hwsim_utils.test_connectivity(dev[0], hapd)
  1257. eap_reauth(dev[0], "TTLS")
  1258. def test_ap_wpa2_eap_ttls_mschapv2_domain_match(dev, apdev):
  1259. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 (domain_match)"""
  1260. check_domain_match(dev[0])
  1261. skip_with_fips(dev[0])
  1262. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1263. hapd = hostapd.add_ap(apdev[0], params)
  1264. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  1265. anonymous_identity="ttls", password="password",
  1266. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1267. domain_match="Server.w1.fi")
  1268. hwsim_utils.test_connectivity(dev[0], hapd)
  1269. eap_reauth(dev[0], "TTLS")
  1270. def test_ap_wpa2_eap_ttls_mschapv2_incorrect_password(dev, apdev):
  1271. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 - incorrect password"""
  1272. skip_with_fips(dev[0])
  1273. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1274. hapd = hostapd.add_ap(apdev[0], params)
  1275. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  1276. anonymous_identity="ttls", password="password1",
  1277. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1278. expect_failure=True)
  1279. eap_connect(dev[1], hapd, "TTLS", "user",
  1280. anonymous_identity="ttls", password="password",
  1281. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1282. expect_failure=True)
  1283. def test_ap_wpa2_eap_ttls_mschapv2_utf8(dev, apdev):
  1284. """WPA2-Enterprise connection using EAP-TTLS/MSCHAPv2 and UTF-8 password"""
  1285. skip_with_fips(dev[0])
  1286. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1287. hapd = hostapd.add_ap(apdev[0], params)
  1288. eap_connect(dev[0], hapd, "TTLS", "utf8-user-hash",
  1289. anonymous_identity="ttls", password="secret-åäö-€-password",
  1290. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1291. eap_connect(dev[1], hapd, "TTLS", "utf8-user",
  1292. anonymous_identity="ttls",
  1293. password_hex="hash:bd5844fad2489992da7fe8c5a01559cf",
  1294. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1295. for p in [ "80", "41c041e04141e041", 257*"41" ]:
  1296. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  1297. eap="TTLS", identity="utf8-user-hash",
  1298. anonymous_identity="ttls", password_hex=p,
  1299. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1300. wait_connect=False, scan_freq="2412")
  1301. ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=1)
  1302. if ev is None:
  1303. raise Exception("No failure reported")
  1304. dev[2].request("REMOVE_NETWORK all")
  1305. dev[2].wait_disconnected()
  1306. def test_ap_wpa2_eap_ttls_eap_gtc(dev, apdev):
  1307. """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC"""
  1308. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1309. hapd = hostapd.add_ap(apdev[0], params)
  1310. eap_connect(dev[0], hapd, "TTLS", "user",
  1311. anonymous_identity="ttls", password="password",
  1312. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC")
  1313. hwsim_utils.test_connectivity(dev[0], hapd)
  1314. eap_reauth(dev[0], "TTLS")
  1315. def test_ap_wpa2_eap_ttls_eap_gtc_incorrect_password(dev, apdev):
  1316. """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - incorrect password"""
  1317. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1318. hapd = hostapd.add_ap(apdev[0], params)
  1319. eap_connect(dev[0], hapd, "TTLS", "user",
  1320. anonymous_identity="ttls", password="wrong",
  1321. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  1322. expect_failure=True)
  1323. def test_ap_wpa2_eap_ttls_eap_gtc_no_password(dev, apdev):
  1324. """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - no password"""
  1325. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1326. hapd = hostapd.add_ap(apdev[0], params)
  1327. eap_connect(dev[0], hapd, "TTLS", "user-no-passwd",
  1328. anonymous_identity="ttls", password="password",
  1329. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  1330. expect_failure=True)
  1331. def test_ap_wpa2_eap_ttls_eap_gtc_server_oom(dev, apdev):
  1332. """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC - server OOM"""
  1333. params = int_eap_server_params()
  1334. hapd = hostapd.add_ap(apdev[0], params)
  1335. with alloc_fail(hapd, 1, "eap_gtc_init"):
  1336. eap_connect(dev[0], hapd, "TTLS", "user",
  1337. anonymous_identity="ttls", password="password",
  1338. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  1339. expect_failure=True)
  1340. dev[0].request("REMOVE_NETWORK all")
  1341. with alloc_fail(hapd, 1, "eap_gtc_buildReq"):
  1342. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1343. eap="TTLS", identity="user",
  1344. anonymous_identity="ttls", password="password",
  1345. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  1346. wait_connect=False, scan_freq="2412")
  1347. # This would eventually time out, but we can stop after having reached
  1348. # the allocation failure.
  1349. for i in range(20):
  1350. time.sleep(0.1)
  1351. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1352. break
  1353. def test_ap_wpa2_eap_ttls_eap_gtc_oom(dev, apdev):
  1354. """WPA2-Enterprise connection using EAP-TTLS/EAP-GTC (OOM)"""
  1355. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1356. hapd = hostapd.add_ap(apdev[0], params)
  1357. tests = [ "eap_gtc_init",
  1358. "eap_msg_alloc;eap_gtc_process" ]
  1359. for func in tests:
  1360. with alloc_fail(dev[0], 1, func):
  1361. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  1362. scan_freq="2412",
  1363. eap="TTLS", identity="user",
  1364. anonymous_identity="ttls", password="password",
  1365. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  1366. wait_connect=False)
  1367. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1368. dev[0].request("REMOVE_NETWORK all")
  1369. dev[0].wait_disconnected()
  1370. def test_ap_wpa2_eap_ttls_eap_md5(dev, apdev):
  1371. """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5"""
  1372. check_eap_capa(dev[0], "MD5")
  1373. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1374. hapd = hostapd.add_ap(apdev[0], params)
  1375. eap_connect(dev[0], hapd, "TTLS", "user",
  1376. anonymous_identity="ttls", password="password",
  1377. ca_cert="auth_serv/ca.pem", phase2="autheap=MD5")
  1378. hwsim_utils.test_connectivity(dev[0], hapd)
  1379. eap_reauth(dev[0], "TTLS")
  1380. def test_ap_wpa2_eap_ttls_eap_md5_incorrect_password(dev, apdev):
  1381. """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - incorrect password"""
  1382. check_eap_capa(dev[0], "MD5")
  1383. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1384. hapd = hostapd.add_ap(apdev[0], params)
  1385. eap_connect(dev[0], hapd, "TTLS", "user",
  1386. anonymous_identity="ttls", password="wrong",
  1387. ca_cert="auth_serv/ca.pem", phase2="autheap=MD5",
  1388. expect_failure=True)
  1389. def test_ap_wpa2_eap_ttls_eap_md5_no_password(dev, apdev):
  1390. """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - no password"""
  1391. check_eap_capa(dev[0], "MD5")
  1392. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1393. hapd = hostapd.add_ap(apdev[0], params)
  1394. eap_connect(dev[0], hapd, "TTLS", "user-no-passwd",
  1395. anonymous_identity="ttls", password="password",
  1396. ca_cert="auth_serv/ca.pem", phase2="autheap=MD5",
  1397. expect_failure=True)
  1398. def test_ap_wpa2_eap_ttls_eap_md5_server_oom(dev, apdev):
  1399. """WPA2-Enterprise connection using EAP-TTLS/EAP-MD5 - server OOM"""
  1400. check_eap_capa(dev[0], "MD5")
  1401. params = int_eap_server_params()
  1402. hapd = hostapd.add_ap(apdev[0], params)
  1403. with alloc_fail(hapd, 1, "eap_md5_init"):
  1404. eap_connect(dev[0], hapd, "TTLS", "user",
  1405. anonymous_identity="ttls", password="password",
  1406. ca_cert="auth_serv/ca.pem", phase2="autheap=MD5",
  1407. expect_failure=True)
  1408. dev[0].request("REMOVE_NETWORK all")
  1409. with alloc_fail(hapd, 1, "eap_md5_buildReq"):
  1410. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1411. eap="TTLS", identity="user",
  1412. anonymous_identity="ttls", password="password",
  1413. ca_cert="auth_serv/ca.pem", phase2="autheap=MD5",
  1414. wait_connect=False, scan_freq="2412")
  1415. # This would eventually time out, but we can stop after having reached
  1416. # the allocation failure.
  1417. for i in range(20):
  1418. time.sleep(0.1)
  1419. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1420. break
  1421. def test_ap_wpa2_eap_ttls_eap_mschapv2(dev, apdev):
  1422. """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2"""
  1423. check_eap_capa(dev[0], "MSCHAPV2")
  1424. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1425. hapd = hostapd.add_ap(apdev[0], params)
  1426. eap_connect(dev[0], hapd, "TTLS", "user",
  1427. anonymous_identity="ttls", password="password",
  1428. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2")
  1429. hwsim_utils.test_connectivity(dev[0], hapd)
  1430. eap_reauth(dev[0], "TTLS")
  1431. logger.info("Negative test with incorrect password")
  1432. dev[0].request("REMOVE_NETWORK all")
  1433. eap_connect(dev[0], hapd, "TTLS", "user",
  1434. anonymous_identity="ttls", password="password1",
  1435. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  1436. expect_failure=True)
  1437. def test_ap_wpa2_eap_ttls_eap_mschapv2_no_password(dev, apdev):
  1438. """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2 - no password"""
  1439. check_eap_capa(dev[0], "MSCHAPV2")
  1440. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1441. hapd = hostapd.add_ap(apdev[0], params)
  1442. eap_connect(dev[0], hapd, "TTLS", "user-no-passwd",
  1443. anonymous_identity="ttls", password="password",
  1444. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  1445. expect_failure=True)
  1446. def test_ap_wpa2_eap_ttls_eap_mschapv2_server_oom(dev, apdev):
  1447. """WPA2-Enterprise connection using EAP-TTLS/EAP-MSCHAPv2 - server OOM"""
  1448. check_eap_capa(dev[0], "MSCHAPV2")
  1449. params = int_eap_server_params()
  1450. hapd = hostapd.add_ap(apdev[0], params)
  1451. with alloc_fail(hapd, 1, "eap_mschapv2_init"):
  1452. eap_connect(dev[0], hapd, "TTLS", "user",
  1453. anonymous_identity="ttls", password="password",
  1454. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  1455. expect_failure=True)
  1456. dev[0].request("REMOVE_NETWORK all")
  1457. with alloc_fail(hapd, 1, "eap_mschapv2_build_challenge"):
  1458. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1459. eap="TTLS", identity="user",
  1460. anonymous_identity="ttls", password="password",
  1461. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  1462. wait_connect=False, scan_freq="2412")
  1463. # This would eventually time out, but we can stop after having reached
  1464. # the allocation failure.
  1465. for i in range(20):
  1466. time.sleep(0.1)
  1467. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1468. break
  1469. dev[0].request("REMOVE_NETWORK all")
  1470. with alloc_fail(hapd, 1, "eap_mschapv2_build_success_req"):
  1471. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1472. eap="TTLS", identity="user",
  1473. anonymous_identity="ttls", password="password",
  1474. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  1475. wait_connect=False, scan_freq="2412")
  1476. # This would eventually time out, but we can stop after having reached
  1477. # the allocation failure.
  1478. for i in range(20):
  1479. time.sleep(0.1)
  1480. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1481. break
  1482. dev[0].request("REMOVE_NETWORK all")
  1483. with alloc_fail(hapd, 1, "eap_mschapv2_build_failure_req"):
  1484. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1485. eap="TTLS", identity="user",
  1486. anonymous_identity="ttls", password="wrong",
  1487. ca_cert="auth_serv/ca.pem", phase2="autheap=MSCHAPV2",
  1488. wait_connect=False, scan_freq="2412")
  1489. # This would eventually time out, but we can stop after having reached
  1490. # the allocation failure.
  1491. for i in range(20):
  1492. time.sleep(0.1)
  1493. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1494. break
  1495. dev[0].request("REMOVE_NETWORK all")
  1496. def test_ap_wpa2_eap_ttls_eap_sim(dev, apdev):
  1497. """WPA2-Enterprise connection using EAP-TTLS/EAP-SIM"""
  1498. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1499. hapd = hostapd.add_ap(apdev[0], params)
  1500. eap_connect(dev[0], hapd, "TTLS", "1232010000000000",
  1501. anonymous_identity="1232010000000000@ttls",
  1502. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1503. ca_cert="auth_serv/ca.pem", phase2="autheap=SIM")
  1504. eap_reauth(dev[0], "TTLS")
  1505. def run_ext_sim_auth(dev):
  1506. ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15)
  1507. if ev is None:
  1508. raise Exception("Wait for external SIM processing request timed out")
  1509. p = ev.split(':', 2)
  1510. if p[1] != "GSM-AUTH":
  1511. raise Exception("Unexpected CTRL-REQ-SIM type")
  1512. rid = p[0].split('-')[3]
  1513. rand = p[2].split(' ')[0]
  1514. res = subprocess.check_output(["../../hostapd/hlr_auc_gw",
  1515. "-m",
  1516. "auth_serv/hlr_auc_gw.milenage_db",
  1517. "GSM-AUTH-REQ 232010000000000 " + rand])
  1518. if "GSM-AUTH-RESP" not in res:
  1519. raise Exception("Unexpected hlr_auc_gw response")
  1520. resp = res.split(' ')[2].rstrip()
  1521. dev.request("CTRL-RSP-SIM-" + rid + ":GSM-AUTH:" + resp)
  1522. dev.wait_connected(timeout=15)
  1523. dev.dump_monitor()
  1524. dev.request("REAUTHENTICATE")
  1525. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  1526. if ev is None:
  1527. raise Exception("EAP reauthentication did not succeed")
  1528. ev = dev.wait_event(["WPA: Key negotiation completed"], timeout=5)
  1529. if ev is None:
  1530. raise Exception("Key negotiation did not complete")
  1531. dev.dump_monitor()
  1532. def test_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev):
  1533. """WPA2-Enterprise connection using EAP-TTLS/EAP-SIM and external GSM auth"""
  1534. check_hlr_auc_gw_support()
  1535. try:
  1536. run_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev)
  1537. finally:
  1538. dev[0].request("SET external_sim 0")
  1539. def run_ap_wpa2_eap_ttls_eap_sim_ext(dev, apdev):
  1540. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1541. hapd = hostapd.add_ap(apdev[0], params)
  1542. dev[0].request("SET external_sim 1")
  1543. dev[0].connect("test-wpa2-eap", eap="TTLS", key_mgmt="WPA-EAP",
  1544. identity="1232010000000000",
  1545. anonymous_identity="1232010000000000@ttls",
  1546. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1547. ca_cert="auth_serv/ca.pem", phase2="autheap=SIM",
  1548. wait_connect=False, scan_freq="2412")
  1549. run_ext_sim_auth(dev[0])
  1550. def test_ap_wpa2_eap_peap_eap_sim(dev, apdev):
  1551. """WPA2-Enterprise connection using EAP-PEAP/EAP-SIM"""
  1552. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1553. hapd = hostapd.add_ap(apdev[0], params)
  1554. eap_connect(dev[0], hapd, "PEAP", "1232010000000000",
  1555. anonymous_identity="1232010000000000@peap",
  1556. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1557. ca_cert="auth_serv/ca.pem", phase2="auth=SIM")
  1558. eap_reauth(dev[0], "PEAP")
  1559. def test_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev):
  1560. """WPA2-Enterprise connection using EAP-PEAP/EAP-SIM and external GSM auth"""
  1561. check_hlr_auc_gw_support()
  1562. try:
  1563. run_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev)
  1564. finally:
  1565. dev[0].request("SET external_sim 0")
  1566. def run_ap_wpa2_eap_peap_eap_sim_ext(dev, apdev):
  1567. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1568. hapd = hostapd.add_ap(apdev[0], params)
  1569. dev[0].request("SET external_sim 1")
  1570. dev[0].connect("test-wpa2-eap", eap="PEAP", key_mgmt="WPA-EAP",
  1571. identity="1232010000000000",
  1572. anonymous_identity="1232010000000000@peap",
  1573. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1574. ca_cert="auth_serv/ca.pem", phase2="auth=SIM",
  1575. wait_connect=False, scan_freq="2412")
  1576. run_ext_sim_auth(dev[0])
  1577. def test_ap_wpa2_eap_fast_eap_sim(dev, apdev):
  1578. """WPA2-Enterprise connection using EAP-FAST/EAP-SIM"""
  1579. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1580. hapd = hostapd.add_ap(apdev[0], params)
  1581. eap_connect(dev[0], hapd, "FAST", "1232010000000000",
  1582. anonymous_identity="1232010000000000@fast",
  1583. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1584. phase1="fast_provisioning=2",
  1585. pac_file="blob://fast_pac_auth_sim",
  1586. ca_cert="auth_serv/ca.pem", phase2="auth=SIM")
  1587. eap_reauth(dev[0], "FAST")
  1588. def test_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev):
  1589. """WPA2-Enterprise connection using EAP-FAST/EAP-SIM and external GSM auth"""
  1590. check_hlr_auc_gw_support()
  1591. try:
  1592. run_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev)
  1593. finally:
  1594. dev[0].request("SET external_sim 0")
  1595. def run_ap_wpa2_eap_fast_eap_sim_ext(dev, apdev):
  1596. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1597. hapd = hostapd.add_ap(apdev[0], params)
  1598. dev[0].request("SET external_sim 1")
  1599. dev[0].connect("test-wpa2-eap", eap="PEAP", key_mgmt="WPA-EAP",
  1600. identity="1232010000000000",
  1601. anonymous_identity="1232010000000000@peap",
  1602. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  1603. phase1="fast_provisioning=2",
  1604. pac_file="blob://fast_pac_auth_sim",
  1605. ca_cert="auth_serv/ca.pem", phase2="auth=SIM",
  1606. wait_connect=False, scan_freq="2412")
  1607. run_ext_sim_auth(dev[0])
  1608. def test_ap_wpa2_eap_ttls_eap_aka(dev, apdev):
  1609. """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA"""
  1610. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1611. hapd = hostapd.add_ap(apdev[0], params)
  1612. eap_connect(dev[0], hapd, "TTLS", "0232010000000000",
  1613. anonymous_identity="0232010000000000@ttls",
  1614. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1615. ca_cert="auth_serv/ca.pem", phase2="autheap=AKA")
  1616. eap_reauth(dev[0], "TTLS")
  1617. def test_ap_wpa2_eap_peap_eap_aka(dev, apdev):
  1618. """WPA2-Enterprise connection using EAP-PEAP/EAP-AKA"""
  1619. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1620. hapd = hostapd.add_ap(apdev[0], params)
  1621. eap_connect(dev[0], hapd, "PEAP", "0232010000000000",
  1622. anonymous_identity="0232010000000000@peap",
  1623. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1624. ca_cert="auth_serv/ca.pem", phase2="auth=AKA")
  1625. eap_reauth(dev[0], "PEAP")
  1626. def test_ap_wpa2_eap_fast_eap_aka(dev, apdev):
  1627. """WPA2-Enterprise connection using EAP-FAST/EAP-AKA"""
  1628. check_eap_capa(dev[0], "FAST")
  1629. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1630. hapd = hostapd.add_ap(apdev[0], params)
  1631. eap_connect(dev[0], hapd, "FAST", "0232010000000000",
  1632. anonymous_identity="0232010000000000@fast",
  1633. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1634. phase1="fast_provisioning=2",
  1635. pac_file="blob://fast_pac_auth_aka",
  1636. ca_cert="auth_serv/ca.pem", phase2="auth=AKA")
  1637. eap_reauth(dev[0], "FAST")
  1638. def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev):
  1639. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  1640. check_eap_capa(dev[0], "MSCHAPV2")
  1641. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1642. hapd = hostapd.add_ap(apdev[0], params)
  1643. eap_connect(dev[0], hapd, "PEAP", "user",
  1644. anonymous_identity="peap", password="password",
  1645. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1646. hwsim_utils.test_connectivity(dev[0], hapd)
  1647. eap_reauth(dev[0], "PEAP")
  1648. dev[0].request("REMOVE_NETWORK all")
  1649. eap_connect(dev[0], hapd, "PEAP", "user",
  1650. anonymous_identity="peap", password="password",
  1651. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1652. fragment_size="200")
  1653. logger.info("Password as hash value")
  1654. dev[0].request("REMOVE_NETWORK all")
  1655. eap_connect(dev[0], hapd, "PEAP", "user",
  1656. anonymous_identity="peap",
  1657. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1658. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1659. logger.info("Negative test with incorrect password")
  1660. dev[0].request("REMOVE_NETWORK all")
  1661. eap_connect(dev[0], hapd, "PEAP", "user",
  1662. anonymous_identity="peap", password="password1",
  1663. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1664. expect_failure=True)
  1665. def test_ap_wpa2_eap_peap_eap_mschapv2_domain(dev, apdev):
  1666. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 with domain"""
  1667. check_eap_capa(dev[0], "MSCHAPV2")
  1668. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1669. hapd = hostapd.add_ap(apdev[0], params)
  1670. eap_connect(dev[0], hapd, "PEAP", "DOMAIN\user3",
  1671. anonymous_identity="peap", password="password",
  1672. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1673. hwsim_utils.test_connectivity(dev[0], hapd)
  1674. eap_reauth(dev[0], "PEAP")
  1675. def test_ap_wpa2_eap_peap_eap_mschapv2_incorrect_password(dev, apdev):
  1676. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 - incorrect password"""
  1677. check_eap_capa(dev[0], "MSCHAPV2")
  1678. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1679. hapd = hostapd.add_ap(apdev[0], params)
  1680. eap_connect(dev[0], hapd, "PEAP", "user",
  1681. anonymous_identity="peap", password="wrong",
  1682. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1683. expect_failure=True)
  1684. def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev):
  1685. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding"""
  1686. check_eap_capa(dev[0], "MSCHAPV2")
  1687. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1688. hapd = hostapd.add_ap(apdev[0], params)
  1689. eap_connect(dev[0], hapd, "PEAP", "user", password="password",
  1690. ca_cert="auth_serv/ca.pem",
  1691. phase1="peapver=0 crypto_binding=2",
  1692. phase2="auth=MSCHAPV2")
  1693. hwsim_utils.test_connectivity(dev[0], hapd)
  1694. eap_reauth(dev[0], "PEAP")
  1695. eap_connect(dev[1], hapd, "PEAP", "user", password="password",
  1696. ca_cert="auth_serv/ca.pem",
  1697. phase1="peapver=0 crypto_binding=1",
  1698. phase2="auth=MSCHAPV2")
  1699. eap_connect(dev[2], hapd, "PEAP", "user", password="password",
  1700. ca_cert="auth_serv/ca.pem",
  1701. phase1="peapver=0 crypto_binding=0",
  1702. phase2="auth=MSCHAPV2")
  1703. def test_ap_wpa2_eap_peap_crypto_binding_server_oom(dev, apdev):
  1704. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding with server OOM"""
  1705. check_eap_capa(dev[0], "MSCHAPV2")
  1706. params = int_eap_server_params()
  1707. hapd = hostapd.add_ap(apdev[0], params)
  1708. with alloc_fail(hapd, 1, "eap_mschapv2_getKey"):
  1709. eap_connect(dev[0], hapd, "PEAP", "user", password="password",
  1710. ca_cert="auth_serv/ca.pem",
  1711. phase1="peapver=0 crypto_binding=2",
  1712. phase2="auth=MSCHAPV2",
  1713. expect_failure=True, local_error_report=True)
  1714. def test_ap_wpa2_eap_peap_params(dev, apdev):
  1715. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and various parameters"""
  1716. check_eap_capa(dev[0], "MSCHAPV2")
  1717. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1718. hapd = hostapd.add_ap(apdev[0], params)
  1719. eap_connect(dev[0], hapd, "PEAP", "user",
  1720. anonymous_identity="peap", password="password",
  1721. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1722. phase1="peapver=0 peaplabel=1",
  1723. expect_failure=True)
  1724. dev[0].request("REMOVE_NETWORK all")
  1725. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1726. identity="user",
  1727. anonymous_identity="peap", password="password",
  1728. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1729. phase1="peap_outer_success=0",
  1730. wait_connect=False, scan_freq="2412")
  1731. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  1732. if ev is None:
  1733. raise Exception("No EAP success seen")
  1734. # This won't succeed to connect with peap_outer_success=0, so stop here.
  1735. dev[0].request("REMOVE_NETWORK all")
  1736. dev[0].wait_disconnected()
  1737. eap_connect(dev[1], hapd, "PEAP", "user", password="password",
  1738. ca_cert="auth_serv/ca.pem",
  1739. phase1="peap_outer_success=1",
  1740. phase2="auth=MSCHAPV2")
  1741. eap_connect(dev[2], hapd, "PEAP", "user", password="password",
  1742. ca_cert="auth_serv/ca.pem",
  1743. phase1="peap_outer_success=2",
  1744. phase2="auth=MSCHAPV2")
  1745. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1746. identity="user",
  1747. anonymous_identity="peap", password="password",
  1748. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1749. phase1="peapver=1 peaplabel=1",
  1750. wait_connect=False, scan_freq="2412")
  1751. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  1752. if ev is None:
  1753. raise Exception("No EAP success seen")
  1754. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1755. if ev is not None:
  1756. raise Exception("Unexpected connection")
  1757. tests = [ ("peap-ver0", ""),
  1758. ("peap-ver1", ""),
  1759. ("peap-ver0", "peapver=0"),
  1760. ("peap-ver1", "peapver=1") ]
  1761. for anon,phase1 in tests:
  1762. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1763. identity="user", anonymous_identity=anon,
  1764. password="password", phase1=phase1,
  1765. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1766. scan_freq="2412")
  1767. dev[0].request("REMOVE_NETWORK all")
  1768. dev[0].wait_disconnected()
  1769. tests = [ ("peap-ver0", "peapver=1"),
  1770. ("peap-ver1", "peapver=0") ]
  1771. for anon,phase1 in tests:
  1772. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1773. identity="user", anonymous_identity=anon,
  1774. password="password", phase1=phase1,
  1775. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1776. wait_connect=False, scan_freq="2412")
  1777. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  1778. if ev is None:
  1779. raise Exception("No EAP-Failure seen")
  1780. dev[0].request("REMOVE_NETWORK all")
  1781. dev[0].wait_disconnected()
  1782. eap_connect(dev[0], hapd, "PEAP", "user", password="password",
  1783. ca_cert="auth_serv/ca.pem",
  1784. phase1="tls_allow_md5=1 tls_disable_session_ticket=1 tls_disable_tlsv1_0=0 tls_disable_tlsv1_1=0 tls_disable_tlsv1_2=0 tls_ext_cert_check=0",
  1785. phase2="auth=MSCHAPV2")
  1786. def test_ap_wpa2_eap_peap_eap_tls(dev, apdev):
  1787. """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS"""
  1788. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1789. hapd = hostapd.add_ap(apdev[0], params)
  1790. eap_connect(dev[0], hapd, "PEAP", "cert user",
  1791. ca_cert="auth_serv/ca.pem", phase2="auth=TLS",
  1792. ca_cert2="auth_serv/ca.pem",
  1793. client_cert2="auth_serv/user.pem",
  1794. private_key2="auth_serv/user.key")
  1795. eap_reauth(dev[0], "PEAP")
  1796. def test_ap_wpa2_eap_tls(dev, apdev):
  1797. """WPA2-Enterprise connection using EAP-TLS"""
  1798. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1799. hapd = hostapd.add_ap(apdev[0], params)
  1800. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1801. client_cert="auth_serv/user.pem",
  1802. private_key="auth_serv/user.key")
  1803. eap_reauth(dev[0], "TLS")
  1804. def test_eap_tls_pkcs8_pkcs5_v2_des3(dev, apdev):
  1805. """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v2 DES3 key"""
  1806. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1807. hapd = hostapd.add_ap(apdev[0], params)
  1808. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1809. client_cert="auth_serv/user.pem",
  1810. private_key="auth_serv/user.key.pkcs8",
  1811. private_key_passwd="whatever")
  1812. def test_eap_tls_pkcs8_pkcs5_v15(dev, apdev):
  1813. """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v1.5 key"""
  1814. check_pkcs5_v15_support(dev[0])
  1815. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1816. hapd = hostapd.add_ap(apdev[0], params)
  1817. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1818. client_cert="auth_serv/user.pem",
  1819. private_key="auth_serv/user.key.pkcs8.pkcs5v15",
  1820. private_key_passwd="whatever")
  1821. def test_ap_wpa2_eap_tls_blob(dev, apdev):
  1822. """WPA2-Enterprise connection using EAP-TLS and config blobs"""
  1823. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1824. hapd = hostapd.add_ap(apdev[0], params)
  1825. cert = read_pem("auth_serv/ca.pem")
  1826. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1827. raise Exception("Could not set cacert blob")
  1828. cert = read_pem("auth_serv/user.pem")
  1829. if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")):
  1830. raise Exception("Could not set usercert blob")
  1831. key = read_pem("auth_serv/user.rsa-key")
  1832. if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")):
  1833. raise Exception("Could not set cacert blob")
  1834. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert",
  1835. client_cert="blob://usercert",
  1836. private_key="blob://userkey")
  1837. def test_ap_wpa2_eap_tls_blob_missing(dev, apdev):
  1838. """EAP-TLS and config blob missing"""
  1839. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1840. hostapd.add_ap(apdev[0], params)
  1841. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1842. identity="tls user",
  1843. ca_cert="blob://testing-blob-does-not-exist",
  1844. client_cert="blob://testing-blob-does-not-exist",
  1845. private_key="blob://testing-blob-does-not-exist",
  1846. wait_connect=False, scan_freq="2412")
  1847. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=10)
  1848. if ev is None:
  1849. raise Exception("EAP failure not reported")
  1850. dev[0].request("REMOVE_NETWORK all")
  1851. dev[0].wait_disconnected()
  1852. def test_ap_wpa2_eap_tls_with_tls_len(dev, apdev):
  1853. """EAP-TLS and TLS Message Length in unfragmented packets"""
  1854. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1855. hapd = hostapd.add_ap(apdev[0], params)
  1856. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1857. phase1="include_tls_length=1",
  1858. client_cert="auth_serv/user.pem",
  1859. private_key="auth_serv/user.key")
  1860. def test_ap_wpa2_eap_tls_pkcs12(dev, apdev):
  1861. """WPA2-Enterprise connection using EAP-TLS and PKCS#12"""
  1862. check_pkcs12_support(dev[0])
  1863. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1864. hapd = hostapd.add_ap(apdev[0], params)
  1865. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1866. private_key="auth_serv/user.pkcs12",
  1867. private_key_passwd="whatever")
  1868. dev[0].request("REMOVE_NETWORK all")
  1869. dev[0].wait_disconnected()
  1870. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1871. identity="tls user",
  1872. ca_cert="auth_serv/ca.pem",
  1873. private_key="auth_serv/user.pkcs12",
  1874. wait_connect=False, scan_freq="2412")
  1875. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"])
  1876. if ev is None:
  1877. raise Exception("Request for private key passphrase timed out")
  1878. id = ev.split(':')[0].split('-')[-1]
  1879. dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever")
  1880. dev[0].wait_connected(timeout=10)
  1881. dev[0].request("REMOVE_NETWORK all")
  1882. dev[0].wait_disconnected()
  1883. # Run this twice to verify certificate chain handling with OpenSSL. Use two
  1884. # different files to cover both cases of the extra certificate being the
  1885. # one that signed the client certificate and it being unrelated to the
  1886. # client certificate.
  1887. for pkcs12 in "auth_serv/user2.pkcs12", "auth_serv/user3.pkcs12":
  1888. for i in range(2):
  1889. eap_connect(dev[0], hapd, "TLS", "tls user",
  1890. ca_cert="auth_serv/ca.pem",
  1891. private_key=pkcs12,
  1892. private_key_passwd="whatever")
  1893. dev[0].request("REMOVE_NETWORK all")
  1894. dev[0].wait_disconnected()
  1895. def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev):
  1896. """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob"""
  1897. check_pkcs12_support(dev[0])
  1898. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1899. hapd = hostapd.add_ap(apdev[0], params)
  1900. cert = read_pem("auth_serv/ca.pem")
  1901. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1902. raise Exception("Could not set cacert blob")
  1903. with open("auth_serv/user.pkcs12", "rb") as f:
  1904. if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")):
  1905. raise Exception("Could not set pkcs12 blob")
  1906. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert",
  1907. private_key="blob://pkcs12",
  1908. private_key_passwd="whatever")
  1909. def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev):
  1910. """WPA2-Enterprise negative test - incorrect trust root"""
  1911. check_eap_capa(dev[0], "MSCHAPV2")
  1912. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1913. hostapd.add_ap(apdev[0], params)
  1914. cert = read_pem("auth_serv/ca-incorrect.pem")
  1915. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1916. raise Exception("Could not set cacert blob")
  1917. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1918. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1919. password="password", phase2="auth=MSCHAPV2",
  1920. ca_cert="blob://cacert",
  1921. wait_connect=False, scan_freq="2412")
  1922. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1923. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1924. password="password", phase2="auth=MSCHAPV2",
  1925. ca_cert="auth_serv/ca-incorrect.pem",
  1926. wait_connect=False, scan_freq="2412")
  1927. for dev in (dev[0], dev[1]):
  1928. ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  1929. if ev is None:
  1930. raise Exception("Association and EAP start timed out")
  1931. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1932. if ev is None:
  1933. raise Exception("EAP method selection timed out")
  1934. if "TTLS" not in ev:
  1935. raise Exception("Unexpected EAP method")
  1936. ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1937. "CTRL-EVENT-EAP-SUCCESS",
  1938. "CTRL-EVENT-EAP-FAILURE",
  1939. "CTRL-EVENT-CONNECTED",
  1940. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1941. if ev is None:
  1942. raise Exception("EAP result timed out")
  1943. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1944. raise Exception("TLS certificate error not reported")
  1945. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1946. "CTRL-EVENT-EAP-FAILURE",
  1947. "CTRL-EVENT-CONNECTED",
  1948. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1949. if ev is None:
  1950. raise Exception("EAP result(2) timed out")
  1951. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1952. raise Exception("EAP failure not reported")
  1953. ev = dev.wait_event(["CTRL-EVENT-CONNECTED",
  1954. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1955. if ev is None:
  1956. raise Exception("EAP result(3) timed out")
  1957. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1958. raise Exception("Disconnection not reported")
  1959. ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1960. if ev is None:
  1961. raise Exception("Network block disabling not reported")
  1962. def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev):
  1963. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1964. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1965. hapd = hostapd.add_ap(apdev[0], params)
  1966. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1967. identity="pap user", anonymous_identity="ttls",
  1968. password="password", phase2="auth=PAP",
  1969. ca_cert="auth_serv/ca.pem",
  1970. wait_connect=True, scan_freq="2412")
  1971. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1972. identity="pap user", anonymous_identity="ttls",
  1973. password="password", phase2="auth=PAP",
  1974. ca_cert="auth_serv/ca-incorrect.pem",
  1975. only_add_network=True, scan_freq="2412")
  1976. dev[0].request("DISCONNECT")
  1977. dev[0].wait_disconnected()
  1978. dev[0].dump_monitor()
  1979. dev[0].select_network(id, freq="2412")
  1980. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1981. if ev is None:
  1982. raise Exception("EAP-TTLS not re-started")
  1983. ev = dev[0].wait_disconnected(timeout=15)
  1984. if "reason=23" not in ev:
  1985. raise Exception("Proper reason code for disconnection not reported")
  1986. def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev):
  1987. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1988. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1989. hapd = hostapd.add_ap(apdev[0], params)
  1990. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1991. identity="pap user", anonymous_identity="ttls",
  1992. password="password", phase2="auth=PAP",
  1993. wait_connect=True, scan_freq="2412")
  1994. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1995. identity="pap user", anonymous_identity="ttls",
  1996. password="password", phase2="auth=PAP",
  1997. ca_cert="auth_serv/ca-incorrect.pem",
  1998. only_add_network=True, scan_freq="2412")
  1999. dev[0].request("DISCONNECT")
  2000. dev[0].wait_disconnected()
  2001. dev[0].dump_monitor()
  2002. dev[0].select_network(id, freq="2412")
  2003. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  2004. if ev is None:
  2005. raise Exception("EAP-TTLS not re-started")
  2006. ev = dev[0].wait_disconnected(timeout=15)
  2007. if "reason=23" not in ev:
  2008. raise Exception("Proper reason code for disconnection not reported")
  2009. def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev):
  2010. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  2011. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2012. hapd = hostapd.add_ap(apdev[0], params)
  2013. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2014. identity="pap user", anonymous_identity="ttls",
  2015. password="password", phase2="auth=PAP",
  2016. ca_cert="auth_serv/ca.pem",
  2017. wait_connect=True, scan_freq="2412")
  2018. dev[0].request("DISCONNECT")
  2019. dev[0].wait_disconnected()
  2020. dev[0].dump_monitor()
  2021. dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem")
  2022. dev[0].select_network(id, freq="2412")
  2023. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  2024. if ev is None:
  2025. raise Exception("EAP-TTLS not re-started")
  2026. ev = dev[0].wait_disconnected(timeout=15)
  2027. if "reason=23" not in ev:
  2028. raise Exception("Proper reason code for disconnection not reported")
  2029. def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev):
  2030. """WPA2-Enterprise negative test - domain suffix mismatch"""
  2031. check_domain_suffix_match(dev[0])
  2032. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2033. hostapd.add_ap(apdev[0], params)
  2034. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2035. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2036. password="password", phase2="auth=MSCHAPV2",
  2037. ca_cert="auth_serv/ca.pem",
  2038. domain_suffix_match="incorrect.example.com",
  2039. wait_connect=False, scan_freq="2412")
  2040. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2041. if ev is None:
  2042. raise Exception("Association and EAP start timed out")
  2043. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2044. if ev is None:
  2045. raise Exception("EAP method selection timed out")
  2046. if "TTLS" not in ev:
  2047. raise Exception("Unexpected EAP method")
  2048. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  2049. "CTRL-EVENT-EAP-SUCCESS",
  2050. "CTRL-EVENT-EAP-FAILURE",
  2051. "CTRL-EVENT-CONNECTED",
  2052. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2053. if ev is None:
  2054. raise Exception("EAP result timed out")
  2055. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  2056. raise Exception("TLS certificate error not reported")
  2057. if "Domain suffix mismatch" not in ev:
  2058. raise Exception("Domain suffix mismatch not reported")
  2059. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  2060. "CTRL-EVENT-EAP-FAILURE",
  2061. "CTRL-EVENT-CONNECTED",
  2062. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2063. if ev is None:
  2064. raise Exception("EAP result(2) timed out")
  2065. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  2066. raise Exception("EAP failure not reported")
  2067. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2068. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2069. if ev is None:
  2070. raise Exception("EAP result(3) timed out")
  2071. if "CTRL-EVENT-DISCONNECTED" not in ev:
  2072. raise Exception("Disconnection not reported")
  2073. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  2074. if ev is None:
  2075. raise Exception("Network block disabling not reported")
  2076. def test_ap_wpa2_eap_tls_neg_domain_match(dev, apdev):
  2077. """WPA2-Enterprise negative test - domain mismatch"""
  2078. check_domain_match(dev[0])
  2079. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2080. hostapd.add_ap(apdev[0], params)
  2081. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2082. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2083. password="password", phase2="auth=MSCHAPV2",
  2084. ca_cert="auth_serv/ca.pem",
  2085. domain_match="w1.fi",
  2086. wait_connect=False, scan_freq="2412")
  2087. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2088. if ev is None:
  2089. raise Exception("Association and EAP start timed out")
  2090. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2091. if ev is None:
  2092. raise Exception("EAP method selection timed out")
  2093. if "TTLS" not in ev:
  2094. raise Exception("Unexpected EAP method")
  2095. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  2096. "CTRL-EVENT-EAP-SUCCESS",
  2097. "CTRL-EVENT-EAP-FAILURE",
  2098. "CTRL-EVENT-CONNECTED",
  2099. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2100. if ev is None:
  2101. raise Exception("EAP result timed out")
  2102. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  2103. raise Exception("TLS certificate error not reported")
  2104. if "Domain mismatch" not in ev:
  2105. raise Exception("Domain mismatch not reported")
  2106. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  2107. "CTRL-EVENT-EAP-FAILURE",
  2108. "CTRL-EVENT-CONNECTED",
  2109. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2110. if ev is None:
  2111. raise Exception("EAP result(2) timed out")
  2112. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  2113. raise Exception("EAP failure not reported")
  2114. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2115. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2116. if ev is None:
  2117. raise Exception("EAP result(3) timed out")
  2118. if "CTRL-EVENT-DISCONNECTED" not in ev:
  2119. raise Exception("Disconnection not reported")
  2120. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  2121. if ev is None:
  2122. raise Exception("Network block disabling not reported")
  2123. def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev):
  2124. """WPA2-Enterprise negative test - subject mismatch"""
  2125. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2126. hostapd.add_ap(apdev[0], params)
  2127. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2128. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2129. password="password", phase2="auth=MSCHAPV2",
  2130. ca_cert="auth_serv/ca.pem",
  2131. subject_match="/C=FI/O=w1.fi/CN=example.com",
  2132. wait_connect=False, scan_freq="2412")
  2133. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2134. if ev is None:
  2135. raise Exception("Association and EAP start timed out")
  2136. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  2137. "EAP: Failed to initialize EAP method"], timeout=10)
  2138. if ev is None:
  2139. raise Exception("EAP method selection timed out")
  2140. if "EAP: Failed to initialize EAP method" in ev:
  2141. tls = dev[0].request("GET tls_library")
  2142. if tls.startswith("OpenSSL"):
  2143. raise Exception("Failed to select EAP method")
  2144. logger.info("subject_match not supported - connection failed, so test succeeded")
  2145. return
  2146. if "TTLS" not in ev:
  2147. raise Exception("Unexpected EAP method")
  2148. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  2149. "CTRL-EVENT-EAP-SUCCESS",
  2150. "CTRL-EVENT-EAP-FAILURE",
  2151. "CTRL-EVENT-CONNECTED",
  2152. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2153. if ev is None:
  2154. raise Exception("EAP result timed out")
  2155. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  2156. raise Exception("TLS certificate error not reported")
  2157. if "Subject mismatch" not in ev:
  2158. raise Exception("Subject mismatch not reported")
  2159. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  2160. "CTRL-EVENT-EAP-FAILURE",
  2161. "CTRL-EVENT-CONNECTED",
  2162. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2163. if ev is None:
  2164. raise Exception("EAP result(2) timed out")
  2165. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  2166. raise Exception("EAP failure not reported")
  2167. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2168. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2169. if ev is None:
  2170. raise Exception("EAP result(3) timed out")
  2171. if "CTRL-EVENT-DISCONNECTED" not in ev:
  2172. raise Exception("Disconnection not reported")
  2173. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  2174. if ev is None:
  2175. raise Exception("Network block disabling not reported")
  2176. def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev):
  2177. """WPA2-Enterprise negative test - altsubject mismatch"""
  2178. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2179. hostapd.add_ap(apdev[0], params)
  2180. tests = [ "incorrect.example.com",
  2181. "DNS:incorrect.example.com",
  2182. "DNS:w1.fi",
  2183. "DNS:erver.w1.fi" ]
  2184. for match in tests:
  2185. _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match)
  2186. def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match):
  2187. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2188. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2189. password="password", phase2="auth=MSCHAPV2",
  2190. ca_cert="auth_serv/ca.pem",
  2191. altsubject_match=match,
  2192. wait_connect=False, scan_freq="2412")
  2193. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2194. if ev is None:
  2195. raise Exception("Association and EAP start timed out")
  2196. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  2197. "EAP: Failed to initialize EAP method"], timeout=10)
  2198. if ev is None:
  2199. raise Exception("EAP method selection timed out")
  2200. if "EAP: Failed to initialize EAP method" in ev:
  2201. tls = dev[0].request("GET tls_library")
  2202. if tls.startswith("OpenSSL"):
  2203. raise Exception("Failed to select EAP method")
  2204. logger.info("altsubject_match not supported - connection failed, so test succeeded")
  2205. return
  2206. if "TTLS" not in ev:
  2207. raise Exception("Unexpected EAP method")
  2208. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  2209. "CTRL-EVENT-EAP-SUCCESS",
  2210. "CTRL-EVENT-EAP-FAILURE",
  2211. "CTRL-EVENT-CONNECTED",
  2212. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2213. if ev is None:
  2214. raise Exception("EAP result timed out")
  2215. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  2216. raise Exception("TLS certificate error not reported")
  2217. if "AltSubject mismatch" not in ev:
  2218. raise Exception("altsubject mismatch not reported")
  2219. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  2220. "CTRL-EVENT-EAP-FAILURE",
  2221. "CTRL-EVENT-CONNECTED",
  2222. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2223. if ev is None:
  2224. raise Exception("EAP result(2) timed out")
  2225. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  2226. raise Exception("EAP failure not reported")
  2227. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2228. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2229. if ev is None:
  2230. raise Exception("EAP result(3) timed out")
  2231. if "CTRL-EVENT-DISCONNECTED" not in ev:
  2232. raise Exception("Disconnection not reported")
  2233. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  2234. if ev is None:
  2235. raise Exception("Network block disabling not reported")
  2236. dev[0].request("REMOVE_NETWORK all")
  2237. def test_ap_wpa2_eap_unauth_tls(dev, apdev):
  2238. """WPA2-Enterprise connection using UNAUTH-TLS"""
  2239. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2240. hapd = hostapd.add_ap(apdev[0], params)
  2241. eap_connect(dev[0], hapd, "UNAUTH-TLS", "unauth-tls",
  2242. ca_cert="auth_serv/ca.pem")
  2243. eap_reauth(dev[0], "UNAUTH-TLS")
  2244. def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev):
  2245. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash"""
  2246. check_cert_probe_support(dev[0])
  2247. skip_with_fips(dev[0])
  2248. srv_cert_hash = "bdb9cb55d3df278e52a071abf58e7f0238fbec3ad8fb2c254742f63562628272"
  2249. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2250. hapd = hostapd.add_ap(apdev[0], params)
  2251. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2252. identity="probe", ca_cert="probe://",
  2253. wait_connect=False, scan_freq="2412")
  2254. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2255. if ev is None:
  2256. raise Exception("Association and EAP start timed out")
  2257. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10)
  2258. if ev is None:
  2259. raise Exception("No peer server certificate event seen")
  2260. if "hash=" + srv_cert_hash not in ev:
  2261. raise Exception("Expected server certificate hash not reported")
  2262. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  2263. if ev is None:
  2264. raise Exception("EAP result timed out")
  2265. if "Server certificate chain probe" not in ev:
  2266. raise Exception("Server certificate probe not reported")
  2267. dev[0].wait_disconnected(timeout=10)
  2268. dev[0].request("REMOVE_NETWORK all")
  2269. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2270. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2271. password="password", phase2="auth=MSCHAPV2",
  2272. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  2273. wait_connect=False, scan_freq="2412")
  2274. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2275. if ev is None:
  2276. raise Exception("Association and EAP start timed out")
  2277. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  2278. if ev is None:
  2279. raise Exception("EAP result timed out")
  2280. if "Server certificate mismatch" not in ev:
  2281. raise Exception("Server certificate mismatch not reported")
  2282. dev[0].wait_disconnected(timeout=10)
  2283. dev[0].request("REMOVE_NETWORK all")
  2284. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  2285. anonymous_identity="ttls", password="password",
  2286. ca_cert="hash://server/sha256/" + srv_cert_hash,
  2287. phase2="auth=MSCHAPV2")
  2288. def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev):
  2289. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)"""
  2290. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2291. hostapd.add_ap(apdev[0], params)
  2292. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2293. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2294. password="password", phase2="auth=MSCHAPV2",
  2295. ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  2296. wait_connect=False, scan_freq="2412")
  2297. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2298. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2299. password="password", phase2="auth=MSCHAPV2",
  2300. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca",
  2301. wait_connect=False, scan_freq="2412")
  2302. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2303. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2304. password="password", phase2="auth=MSCHAPV2",
  2305. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q",
  2306. wait_connect=False, scan_freq="2412")
  2307. for i in range(0, 3):
  2308. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2309. if ev is None:
  2310. raise Exception("Association and EAP start timed out")
  2311. ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5)
  2312. if ev is None:
  2313. raise Exception("Did not report EAP method initialization failure")
  2314. def test_ap_wpa2_eap_pwd(dev, apdev):
  2315. """WPA2-Enterprise connection using EAP-pwd"""
  2316. check_eap_capa(dev[0], "PWD")
  2317. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2318. hapd = hostapd.add_ap(apdev[0], params)
  2319. eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password")
  2320. eap_reauth(dev[0], "PWD")
  2321. dev[0].request("REMOVE_NETWORK all")
  2322. eap_connect(dev[1], hapd, "PWD",
  2323. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  2324. password="secret password",
  2325. fragment_size="90")
  2326. logger.info("Negative test with incorrect password")
  2327. eap_connect(dev[2], hapd, "PWD", "pwd user", password="secret-password",
  2328. expect_failure=True, local_error_report=True)
  2329. eap_connect(dev[0], hapd, "PWD",
  2330. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  2331. password="secret password",
  2332. fragment_size="31")
  2333. def test_ap_wpa2_eap_pwd_nthash(dev, apdev):
  2334. """WPA2-Enterprise connection using EAP-pwd and NTHash"""
  2335. check_eap_capa(dev[0], "PWD")
  2336. skip_with_fips(dev[0])
  2337. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2338. hapd = hostapd.add_ap(apdev[0], params)
  2339. eap_connect(dev[0], hapd, "PWD", "pwd-hash", password="secret password")
  2340. eap_connect(dev[1], hapd, "PWD", "pwd-hash",
  2341. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a")
  2342. eap_connect(dev[2], hapd, "PWD", "pwd user",
  2343. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a",
  2344. expect_failure=True, local_error_report=True)
  2345. def test_ap_wpa2_eap_pwd_groups(dev, apdev):
  2346. """WPA2-Enterprise connection using various EAP-pwd groups"""
  2347. check_eap_capa(dev[0], "PWD")
  2348. tls = dev[0].request("GET tls_library")
  2349. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2350. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2351. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  2352. groups = [ 19, 20, 21, 25, 26 ]
  2353. if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  2354. logger.info("Add Brainpool EC groups since OpenSSL is new enough")
  2355. groups += [ 27, 28, 29, 30 ]
  2356. for i in groups:
  2357. logger.info("Group %d" % i)
  2358. params['pwd_group'] = str(i)
  2359. hapd = hostapd.add_ap(apdev[0], params)
  2360. try:
  2361. eap_connect(dev[0], hapd, "PWD", "pwd user",
  2362. password="secret password")
  2363. dev[0].request("REMOVE_NETWORK all")
  2364. dev[0].wait_disconnected()
  2365. dev[0].dump_monitor()
  2366. except:
  2367. if "BoringSSL" in tls and i in [ 25 ]:
  2368. logger.info("Ignore connection failure with group %d with BoringSSL" % i)
  2369. dev[0].request("DISCONNECT")
  2370. time.sleep(0.1)
  2371. dev[0].request("REMOVE_NETWORK all")
  2372. dev[0].dump_monitor()
  2373. continue
  2374. raise
  2375. def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev):
  2376. """WPA2-Enterprise connection using invalid EAP-pwd group"""
  2377. check_eap_capa(dev[0], "PWD")
  2378. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2379. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2380. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  2381. params['pwd_group'] = "0"
  2382. hostapd.add_ap(apdev[0], params)
  2383. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
  2384. identity="pwd user", password="secret password",
  2385. scan_freq="2412", wait_connect=False)
  2386. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2387. if ev is None:
  2388. raise Exception("Timeout on EAP failure report")
  2389. def test_ap_wpa2_eap_pwd_as_frag(dev, apdev):
  2390. """WPA2-Enterprise connection using EAP-pwd with server fragmentation"""
  2391. check_eap_capa(dev[0], "PWD")
  2392. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2393. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2394. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2395. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  2396. "pwd_group": "19", "fragment_size": "40" }
  2397. hapd = hostapd.add_ap(apdev[0], params)
  2398. eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password")
  2399. def test_ap_wpa2_eap_gpsk(dev, apdev):
  2400. """WPA2-Enterprise connection using EAP-GPSK"""
  2401. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2402. hapd = hostapd.add_ap(apdev[0], params)
  2403. id = eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  2404. password="abcdefghijklmnop0123456789abcdef")
  2405. eap_reauth(dev[0], "GPSK")
  2406. logger.info("Test forced algorithm selection")
  2407. for phase1 in [ "cipher=1", "cipher=2" ]:
  2408. dev[0].set_network_quoted(id, "phase1", phase1)
  2409. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  2410. if ev is None:
  2411. raise Exception("EAP success timed out")
  2412. dev[0].wait_connected(timeout=10)
  2413. logger.info("Test failed algorithm negotiation")
  2414. dev[0].set_network_quoted(id, "phase1", "cipher=9")
  2415. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2416. if ev is None:
  2417. raise Exception("EAP failure timed out")
  2418. logger.info("Negative test with incorrect password")
  2419. dev[0].request("REMOVE_NETWORK all")
  2420. eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  2421. password="ffcdefghijklmnop0123456789abcdef",
  2422. expect_failure=True)
  2423. def test_ap_wpa2_eap_sake(dev, apdev):
  2424. """WPA2-Enterprise connection using EAP-SAKE"""
  2425. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2426. hapd = hostapd.add_ap(apdev[0], params)
  2427. eap_connect(dev[0], hapd, "SAKE", "sake user",
  2428. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  2429. eap_reauth(dev[0], "SAKE")
  2430. logger.info("Negative test with incorrect password")
  2431. dev[0].request("REMOVE_NETWORK all")
  2432. eap_connect(dev[0], hapd, "SAKE", "sake user",
  2433. password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  2434. expect_failure=True)
  2435. def test_ap_wpa2_eap_eke(dev, apdev):
  2436. """WPA2-Enterprise connection using EAP-EKE"""
  2437. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2438. hapd = hostapd.add_ap(apdev[0], params)
  2439. id = eap_connect(dev[0], hapd, "EKE", "eke user", password="hello")
  2440. eap_reauth(dev[0], "EKE")
  2441. logger.info("Test forced algorithm selection")
  2442. for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2",
  2443. "dhgroup=4 encr=1 prf=2 mac=2",
  2444. "dhgroup=3 encr=1 prf=2 mac=2",
  2445. "dhgroup=3 encr=1 prf=1 mac=1" ]:
  2446. dev[0].set_network_quoted(id, "phase1", phase1)
  2447. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  2448. if ev is None:
  2449. raise Exception("EAP success timed out")
  2450. dev[0].wait_connected(timeout=10)
  2451. logger.info("Test failed algorithm negotiation")
  2452. dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9")
  2453. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2454. if ev is None:
  2455. raise Exception("EAP failure timed out")
  2456. logger.info("Negative test with incorrect password")
  2457. dev[0].request("REMOVE_NETWORK all")
  2458. eap_connect(dev[0], hapd, "EKE", "eke user", password="hello1",
  2459. expect_failure=True)
  2460. def test_ap_wpa2_eap_eke_many(dev, apdev, params):
  2461. """WPA2-Enterprise connection using EAP-EKE (many connections) [long]"""
  2462. if not params['long']:
  2463. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  2464. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2465. hostapd.add_ap(apdev[0], params)
  2466. success = 0
  2467. fail = 0
  2468. for i in range(100):
  2469. for j in range(3):
  2470. dev[j].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="EKE",
  2471. identity="eke user", password="hello",
  2472. phase1="dhgroup=3 encr=1 prf=1 mac=1",
  2473. scan_freq="2412", wait_connect=False)
  2474. for j in range(3):
  2475. ev = dev[j].wait_event(["CTRL-EVENT-CONNECTED",
  2476. "CTRL-EVENT-DISCONNECTED"], timeout=15)
  2477. if ev is None:
  2478. raise Exception("No connected/disconnected event")
  2479. if "CTRL-EVENT-DISCONNECTED" in ev:
  2480. fail += 1
  2481. # The RADIUS server limits on active sessions can be hit when
  2482. # going through this test case, so try to give some more time
  2483. # for the server to remove sessions.
  2484. logger.info("Failed to connect i=%d j=%d" % (i, j))
  2485. dev[j].request("REMOVE_NETWORK all")
  2486. time.sleep(1)
  2487. else:
  2488. success += 1
  2489. dev[j].request("REMOVE_NETWORK all")
  2490. dev[j].wait_disconnected()
  2491. dev[j].dump_monitor()
  2492. logger.info("Total success=%d failure=%d" % (success, fail))
  2493. def test_ap_wpa2_eap_eke_serverid_nai(dev, apdev):
  2494. """WPA2-Enterprise connection using EAP-EKE with serverid NAI"""
  2495. params = int_eap_server_params()
  2496. params['server_id'] = 'example.server@w1.fi'
  2497. hapd = hostapd.add_ap(apdev[0], params)
  2498. eap_connect(dev[0], hapd, "EKE", "eke user", password="hello")
  2499. def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
  2500. """WPA2-Enterprise connection using EAP-EKE with server OOM"""
  2501. params = int_eap_server_params()
  2502. hapd = hostapd.add_ap(apdev[0], params)
  2503. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  2504. for count,func in [ (1, "eap_eke_build_commit"),
  2505. (2, "eap_eke_build_commit"),
  2506. (3, "eap_eke_build_commit"),
  2507. (1, "eap_eke_build_confirm"),
  2508. (2, "eap_eke_build_confirm"),
  2509. (1, "eap_eke_process_commit"),
  2510. (2, "eap_eke_process_commit"),
  2511. (1, "eap_eke_process_confirm"),
  2512. (1, "eap_eke_process_identity"),
  2513. (2, "eap_eke_process_identity"),
  2514. (3, "eap_eke_process_identity"),
  2515. (4, "eap_eke_process_identity") ]:
  2516. with alloc_fail(hapd, count, func):
  2517. eap_connect(dev[0], hapd, "EKE", "eke user", password="hello",
  2518. expect_failure=True)
  2519. dev[0].request("REMOVE_NETWORK all")
  2520. for count,func,pw in [ (1, "eap_eke_init", "hello"),
  2521. (1, "eap_eke_get_session_id", "hello"),
  2522. (1, "eap_eke_getKey", "hello"),
  2523. (1, "eap_eke_build_msg", "hello"),
  2524. (1, "eap_eke_build_failure", "wrong"),
  2525. (1, "eap_eke_build_identity", "hello"),
  2526. (2, "eap_eke_build_identity", "hello") ]:
  2527. with alloc_fail(hapd, count, func):
  2528. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2529. eap="EKE", identity="eke user", password=pw,
  2530. wait_connect=False, scan_freq="2412")
  2531. # This would eventually time out, but we can stop after having
  2532. # reached the allocation failure.
  2533. for i in range(20):
  2534. time.sleep(0.1)
  2535. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  2536. break
  2537. dev[0].request("REMOVE_NETWORK all")
  2538. for count in range(1, 1000):
  2539. try:
  2540. with alloc_fail(hapd, count, "eap_server_sm_step"):
  2541. dev[0].connect("test-wpa2-eap",
  2542. key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2543. eap="EKE", identity="eke user", password=pw,
  2544. wait_connect=False, scan_freq="2412")
  2545. # This would eventually time out, but we can stop after having
  2546. # reached the allocation failure.
  2547. for i in range(10):
  2548. time.sleep(0.1)
  2549. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  2550. break
  2551. dev[0].request("REMOVE_NETWORK all")
  2552. except Exception, e:
  2553. if str(e) == "Allocation failure did not trigger":
  2554. if count < 30:
  2555. raise Exception("Too few allocation failures")
  2556. logger.info("%d allocation failures tested" % (count - 1))
  2557. break
  2558. raise e
  2559. def test_ap_wpa2_eap_ikev2(dev, apdev):
  2560. """WPA2-Enterprise connection using EAP-IKEv2"""
  2561. check_eap_capa(dev[0], "IKEV2")
  2562. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2563. hapd = hostapd.add_ap(apdev[0], params)
  2564. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2565. password="ike password")
  2566. eap_reauth(dev[0], "IKEV2")
  2567. dev[0].request("REMOVE_NETWORK all")
  2568. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2569. password="ike password", fragment_size="50")
  2570. logger.info("Negative test with incorrect password")
  2571. dev[0].request("REMOVE_NETWORK all")
  2572. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2573. password="ike-password", expect_failure=True)
  2574. dev[0].request("REMOVE_NETWORK all")
  2575. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2576. password="ike password", fragment_size="0")
  2577. dev[0].request("REMOVE_NETWORK all")
  2578. dev[0].wait_disconnected()
  2579. def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev):
  2580. """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation"""
  2581. check_eap_capa(dev[0], "IKEV2")
  2582. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2583. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2584. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2585. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  2586. "fragment_size": "50" }
  2587. hapd = hostapd.add_ap(apdev[0], params)
  2588. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2589. password="ike password")
  2590. eap_reauth(dev[0], "IKEV2")
  2591. def test_ap_wpa2_eap_ikev2_oom(dev, apdev):
  2592. """WPA2-Enterprise connection using EAP-IKEv2 and OOM"""
  2593. check_eap_capa(dev[0], "IKEV2")
  2594. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2595. hostapd.add_ap(apdev[0], params)
  2596. tests = [ (1, "dh_init"),
  2597. (2, "dh_init"),
  2598. (1, "dh_derive_shared") ]
  2599. for count, func in tests:
  2600. with alloc_fail(dev[0], count, func):
  2601. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  2602. identity="ikev2 user", password="ike password",
  2603. wait_connect=False, scan_freq="2412")
  2604. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2605. if ev is None:
  2606. raise Exception("EAP method not selected")
  2607. for i in range(10):
  2608. if "0:" in dev[0].request("GET_ALLOC_FAIL"):
  2609. break
  2610. time.sleep(0.02)
  2611. dev[0].request("REMOVE_NETWORK all")
  2612. tests = [ (1, "os_get_random;dh_init") ]
  2613. for count, func in tests:
  2614. with fail_test(dev[0], count, func):
  2615. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  2616. identity="ikev2 user", password="ike password",
  2617. wait_connect=False, scan_freq="2412")
  2618. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2619. if ev is None:
  2620. raise Exception("EAP method not selected")
  2621. for i in range(10):
  2622. if "0:" in dev[0].request("GET_FAIL"):
  2623. break
  2624. time.sleep(0.02)
  2625. dev[0].request("REMOVE_NETWORK all")
  2626. def test_ap_wpa2_eap_pax(dev, apdev):
  2627. """WPA2-Enterprise connection using EAP-PAX"""
  2628. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2629. hapd = hostapd.add_ap(apdev[0], params)
  2630. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  2631. password_hex="0123456789abcdef0123456789abcdef")
  2632. eap_reauth(dev[0], "PAX")
  2633. logger.info("Negative test with incorrect password")
  2634. dev[0].request("REMOVE_NETWORK all")
  2635. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  2636. password_hex="ff23456789abcdef0123456789abcdef",
  2637. expect_failure=True)
  2638. def test_ap_wpa2_eap_psk(dev, apdev):
  2639. """WPA2-Enterprise connection using EAP-PSK"""
  2640. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2641. params["wpa_key_mgmt"] = "WPA-EAP-SHA256"
  2642. params["ieee80211w"] = "2"
  2643. hapd = hostapd.add_ap(apdev[0], params)
  2644. eap_connect(dev[0], hapd, "PSK", "psk.user@example.com",
  2645. password_hex="0123456789abcdef0123456789abcdef", sha256=True)
  2646. eap_reauth(dev[0], "PSK", sha256=True)
  2647. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
  2648. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ])
  2649. bss = dev[0].get_bss(apdev[0]['bssid'])
  2650. if 'flags' not in bss:
  2651. raise Exception("Could not get BSS flags from BSS table")
  2652. if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']:
  2653. raise Exception("Unexpected BSS flags: " + bss['flags'])
  2654. logger.info("Negative test with incorrect password")
  2655. dev[0].request("REMOVE_NETWORK all")
  2656. eap_connect(dev[0], hapd, "PSK", "psk.user@example.com",
  2657. password_hex="ff23456789abcdef0123456789abcdef", sha256=True,
  2658. expect_failure=True)
  2659. def test_ap_wpa2_eap_psk_oom(dev, apdev):
  2660. """WPA2-Enterprise connection using EAP-PSK and OOM"""
  2661. skip_with_fips(dev[0])
  2662. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2663. hostapd.add_ap(apdev[0], params)
  2664. tests = [ (1, "=aes_128_eax_encrypt"),
  2665. (1, "=aes_128_eax_decrypt") ]
  2666. for count, func in tests:
  2667. with alloc_fail(dev[0], count, func):
  2668. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2669. identity="psk.user@example.com",
  2670. password_hex="0123456789abcdef0123456789abcdef",
  2671. wait_connect=False, scan_freq="2412")
  2672. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2673. if ev is None:
  2674. raise Exception("EAP method not selected")
  2675. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
  2676. note="Failure not triggered: %d:%s" % (count, func))
  2677. dev[0].request("REMOVE_NETWORK all")
  2678. dev[0].wait_disconnected()
  2679. tests = [ (1, "aes_ctr_encrypt;aes_128_eax_encrypt"),
  2680. (1, "omac1_aes_128;aes_128_eax_encrypt"),
  2681. (2, "omac1_aes_128;aes_128_eax_encrypt"),
  2682. (3, "omac1_aes_128;aes_128_eax_encrypt"),
  2683. (1, "omac1_aes_vector"),
  2684. (1, "omac1_aes_128;aes_128_eax_decrypt"),
  2685. (2, "omac1_aes_128;aes_128_eax_decrypt"),
  2686. (3, "omac1_aes_128;aes_128_eax_decrypt"),
  2687. (1, "aes_ctr_encrypt;aes_128_eax_decrypt") ]
  2688. for count, func in tests:
  2689. with fail_test(dev[0], count, func):
  2690. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2691. identity="psk.user@example.com",
  2692. password_hex="0123456789abcdef0123456789abcdef",
  2693. wait_connect=False, scan_freq="2412")
  2694. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2695. if ev is None:
  2696. raise Exception("EAP method not selected")
  2697. wait_fail_trigger(dev[0], "GET_FAIL",
  2698. note="Failure not triggered: %d:%s" % (count, func))
  2699. dev[0].request("REMOVE_NETWORK all")
  2700. dev[0].wait_disconnected()
  2701. with fail_test(dev[0], 1, "aes_128_encrypt_block"):
  2702. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2703. identity="psk.user@example.com",
  2704. password_hex="0123456789abcdef0123456789abcdef",
  2705. wait_connect=False, scan_freq="2412")
  2706. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2707. if ev is None:
  2708. raise Exception("EAP method failure not reported")
  2709. dev[0].request("REMOVE_NETWORK all")
  2710. dev[0].wait_disconnected()
  2711. def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev):
  2712. """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  2713. check_eap_capa(dev[0], "MSCHAPV2")
  2714. params = hostapd.wpa_eap_params(ssid="test-wpa-eap")
  2715. hapd = hostapd.add_ap(apdev[0], params)
  2716. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP",
  2717. identity="user", password="password", phase2="auth=MSCHAPV2",
  2718. ca_cert="auth_serv/ca.pem", wait_connect=False,
  2719. scan_freq="2412")
  2720. eap_check_auth(dev[0], "PEAP", True, rsn=False)
  2721. hwsim_utils.test_connectivity(dev[0], hapd)
  2722. eap_reauth(dev[0], "PEAP", rsn=False)
  2723. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
  2724. ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ])
  2725. status = dev[0].get_status(extra="VERBOSE")
  2726. if 'portControl' not in status:
  2727. raise Exception("portControl missing from STATUS-VERBOSE")
  2728. if status['portControl'] != 'Auto':
  2729. raise Exception("Unexpected portControl value: " + status['portControl'])
  2730. if 'eap_session_id' not in status:
  2731. raise Exception("eap_session_id missing from STATUS-VERBOSE")
  2732. if not status['eap_session_id'].startswith("19"):
  2733. raise Exception("Unexpected eap_session_id value: " + status['eap_session_id'])
  2734. def test_ap_wpa2_eap_interactive(dev, apdev):
  2735. """WPA2-Enterprise connection using interactive identity/password entry"""
  2736. check_eap_capa(dev[0], "MSCHAPV2")
  2737. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2738. hapd = hostapd.add_ap(apdev[0], params)
  2739. tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
  2740. "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
  2741. None, "password"),
  2742. ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
  2743. "TTLS", "ttls", None, "auth=MSCHAPV2",
  2744. "DOMAIN\mschapv2 user", "password"),
  2745. ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
  2746. "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
  2747. ("Connection with dynamic TTLS/EAP-MD5 password entry",
  2748. "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
  2749. ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
  2750. "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
  2751. ("Connection with dynamic PEAP/EAP-GTC password entry",
  2752. "PEAP", None, "user", "auth=GTC", None, "password") ]
  2753. for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
  2754. logger.info(desc)
  2755. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
  2756. anonymous_identity=anon, identity=identity,
  2757. ca_cert="auth_serv/ca.pem", phase2=phase2,
  2758. wait_connect=False, scan_freq="2412")
  2759. if req_id:
  2760. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2761. if ev is None:
  2762. raise Exception("Request for identity timed out")
  2763. id = ev.split(':')[0].split('-')[-1]
  2764. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2765. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
  2766. if ev is None:
  2767. raise Exception("Request for password timed out")
  2768. id = ev.split(':')[0].split('-')[-1]
  2769. type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD"
  2770. dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw)
  2771. dev[0].wait_connected(timeout=10)
  2772. dev[0].request("REMOVE_NETWORK all")
  2773. def test_ap_wpa2_eap_ext_enable_network_while_connected(dev, apdev):
  2774. """WPA2-Enterprise interactive identity entry and ENABLE_NETWORK"""
  2775. check_eap_capa(dev[0], "MSCHAPV2")
  2776. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2777. hapd = hostapd.add_ap(apdev[0], params)
  2778. id_other = dev[0].connect("other", key_mgmt="NONE", scan_freq="2412",
  2779. only_add_network=True)
  2780. req_id = "DOMAIN\mschapv2 user"
  2781. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2782. anonymous_identity="ttls", identity=None,
  2783. password="password",
  2784. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2785. wait_connect=False, scan_freq="2412")
  2786. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2787. if ev is None:
  2788. raise Exception("Request for identity timed out")
  2789. id = ev.split(':')[0].split('-')[-1]
  2790. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2791. dev[0].wait_connected(timeout=10)
  2792. if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id_other)):
  2793. raise Exception("Failed to enable network")
  2794. ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=1)
  2795. if ev is not None:
  2796. raise Exception("Unexpected reconnection attempt on ENABLE_NETWORK")
  2797. dev[0].request("REMOVE_NETWORK all")
  2798. def test_ap_wpa2_eap_vendor_test(dev, apdev):
  2799. """WPA2-Enterprise connection using EAP vendor test"""
  2800. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2801. hapd = hostapd.add_ap(apdev[0], params)
  2802. eap_connect(dev[0], hapd, "VENDOR-TEST", "vendor-test")
  2803. eap_reauth(dev[0], "VENDOR-TEST")
  2804. eap_connect(dev[1], hapd, "VENDOR-TEST", "vendor-test",
  2805. password="pending")
  2806. def test_ap_wpa2_eap_vendor_test_oom(dev, apdev):
  2807. """WPA2-Enterprise connection using EAP vendor test (OOM)"""
  2808. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2809. hostapd.add_ap(apdev[0], params)
  2810. tests = [ "eap_vendor_test_init",
  2811. "eap_msg_alloc;eap_vendor_test_process",
  2812. "eap_vendor_test_getKey" ]
  2813. for func in tests:
  2814. with alloc_fail(dev[0], 1, func):
  2815. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  2816. scan_freq="2412",
  2817. eap="VENDOR-TEST", identity="vendor-test",
  2818. wait_connect=False)
  2819. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2820. dev[0].request("REMOVE_NETWORK all")
  2821. dev[0].wait_disconnected()
  2822. def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev):
  2823. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning"""
  2824. check_eap_capa(dev[0], "FAST")
  2825. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2826. hapd = hostapd.add_ap(apdev[0], params)
  2827. eap_connect(dev[0], hapd, "FAST", "user",
  2828. anonymous_identity="FAST", password="password",
  2829. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2830. phase1="fast_provisioning=1", pac_file="blob://fast_pac")
  2831. hwsim_utils.test_connectivity(dev[0], hapd)
  2832. res = eap_reauth(dev[0], "FAST")
  2833. if res['tls_session_reused'] != '1':
  2834. raise Exception("EAP-FAST could not use PAC session ticket")
  2835. def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params):
  2836. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file"""
  2837. check_eap_capa(dev[0], "FAST")
  2838. pac_file = os.path.join(params['logdir'], "fast.pac")
  2839. pac_file2 = os.path.join(params['logdir'], "fast-bin.pac")
  2840. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2841. hapd = hostapd.add_ap(apdev[0], params)
  2842. try:
  2843. eap_connect(dev[0], hapd, "FAST", "user",
  2844. anonymous_identity="FAST", password="password",
  2845. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2846. phase1="fast_provisioning=1", pac_file=pac_file)
  2847. with open(pac_file, "r") as f:
  2848. data = f.read()
  2849. if "wpa_supplicant EAP-FAST PAC file - version 1" not in data:
  2850. raise Exception("PAC file header missing")
  2851. if "PAC-Key=" not in data:
  2852. raise Exception("PAC-Key missing from PAC file")
  2853. dev[0].request("REMOVE_NETWORK all")
  2854. eap_connect(dev[0], hapd, "FAST", "user",
  2855. anonymous_identity="FAST", password="password",
  2856. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2857. pac_file=pac_file)
  2858. eap_connect(dev[1], hapd, "FAST", "user",
  2859. anonymous_identity="FAST", password="password",
  2860. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2861. phase1="fast_provisioning=1 fast_pac_format=binary",
  2862. pac_file=pac_file2)
  2863. dev[1].request("REMOVE_NETWORK all")
  2864. eap_connect(dev[1], hapd, "FAST", "user",
  2865. anonymous_identity="FAST", password="password",
  2866. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2867. phase1="fast_pac_format=binary",
  2868. pac_file=pac_file2)
  2869. finally:
  2870. try:
  2871. os.remove(pac_file)
  2872. except:
  2873. pass
  2874. try:
  2875. os.remove(pac_file2)
  2876. except:
  2877. pass
  2878. def test_ap_wpa2_eap_fast_binary_pac(dev, apdev):
  2879. """WPA2-Enterprise connection using EAP-FAST and binary PAC format"""
  2880. check_eap_capa(dev[0], "FAST")
  2881. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2882. hapd = hostapd.add_ap(apdev[0], params)
  2883. eap_connect(dev[0], hapd, "FAST", "user",
  2884. anonymous_identity="FAST", password="password",
  2885. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2886. phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary",
  2887. pac_file="blob://fast_pac_bin")
  2888. res = eap_reauth(dev[0], "FAST")
  2889. if res['tls_session_reused'] != '1':
  2890. raise Exception("EAP-FAST could not use PAC session ticket")
  2891. # Verify fast_max_pac_list_len=0 special case
  2892. dev[0].request("REMOVE_NETWORK all")
  2893. dev[0].wait_disconnected()
  2894. eap_connect(dev[0], hapd, "FAST", "user",
  2895. anonymous_identity="FAST", password="password",
  2896. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2897. phase1="fast_provisioning=1 fast_max_pac_list_len=0 fast_pac_format=binary",
  2898. pac_file="blob://fast_pac_bin")
  2899. def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev):
  2900. """WPA2-Enterprise connection using EAP-FAST and missing PAC config"""
  2901. check_eap_capa(dev[0], "FAST")
  2902. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2903. hostapd.add_ap(apdev[0], params)
  2904. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2905. identity="user", anonymous_identity="FAST",
  2906. password="password",
  2907. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2908. pac_file="blob://fast_pac_not_in_use",
  2909. wait_connect=False, scan_freq="2412")
  2910. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2911. if ev is None:
  2912. raise Exception("Timeout on EAP failure report")
  2913. dev[0].request("REMOVE_NETWORK all")
  2914. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2915. identity="user", anonymous_identity="FAST",
  2916. password="password",
  2917. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2918. wait_connect=False, scan_freq="2412")
  2919. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2920. if ev is None:
  2921. raise Exception("Timeout on EAP failure report")
  2922. def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
  2923. """EAP-FAST and binary PAC errors"""
  2924. check_eap_capa(dev[0], "FAST")
  2925. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2926. hapd = hostapd.add_ap(apdev[0], params)
  2927. tests = [ (1, "=eap_fast_save_pac_bin"),
  2928. (1, "eap_fast_write_pac"),
  2929. (2, "eap_fast_write_pac"), ]
  2930. for count, func in tests:
  2931. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors "):
  2932. raise Exception("Could not set blob")
  2933. with alloc_fail(dev[0], count, func):
  2934. eap_connect(dev[0], hapd, "FAST", "user",
  2935. anonymous_identity="FAST", password="password",
  2936. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2937. phase1="fast_provisioning=1 fast_pac_format=binary",
  2938. pac_file="blob://fast_pac_bin_errors")
  2939. dev[0].request("REMOVE_NETWORK all")
  2940. dev[0].wait_disconnected()
  2941. tests = [ "00", "000000000000", "6ae4920c0001",
  2942. "6ae4920c000000",
  2943. "6ae4920c0000" + "0000" + 32*"00" + "ffff" + "0000",
  2944. "6ae4920c0000" + "0000" + 32*"00" + "0001" + "0000",
  2945. "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0001",
  2946. "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0008" + "00040000" + "0007000100"]
  2947. for t in tests:
  2948. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + t):
  2949. raise Exception("Could not set blob")
  2950. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2951. identity="user", anonymous_identity="FAST",
  2952. password="password",
  2953. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2954. phase1="fast_provisioning=1 fast_pac_format=binary",
  2955. pac_file="blob://fast_pac_bin_errors",
  2956. scan_freq="2412", wait_connect=False)
  2957. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2958. timeout=5)
  2959. if ev is None:
  2960. raise Exception("Failure not reported")
  2961. dev[0].request("REMOVE_NETWORK all")
  2962. dev[0].wait_disconnected()
  2963. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0000"
  2964. tests = [ (1, "eap_fast_load_pac_bin"),
  2965. (2, "eap_fast_load_pac_bin"),
  2966. (3, "eap_fast_load_pac_bin") ]
  2967. for count, func in tests:
  2968. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2969. raise Exception("Could not set blob")
  2970. with alloc_fail(dev[0], count, func):
  2971. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2972. identity="user", anonymous_identity="FAST",
  2973. password="password",
  2974. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2975. phase1="fast_provisioning=1 fast_pac_format=binary",
  2976. pac_file="blob://fast_pac_bin_errors",
  2977. scan_freq="2412", wait_connect=False)
  2978. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2979. timeout=5)
  2980. if ev is None:
  2981. raise Exception("Failure not reported")
  2982. dev[0].request("REMOVE_NETWORK all")
  2983. dev[0].wait_disconnected()
  2984. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0005" + "0011223344"
  2985. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2986. raise Exception("Could not set blob")
  2987. eap_connect(dev[0], hapd, "FAST", "user",
  2988. anonymous_identity="FAST", password="password",
  2989. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2990. phase1="fast_provisioning=1 fast_pac_format=binary",
  2991. pac_file="blob://fast_pac_bin_errors")
  2992. dev[0].request("REMOVE_NETWORK all")
  2993. dev[0].wait_disconnected()
  2994. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0009" + "00040000" + "0007000100"
  2995. tests = [ (1, "eap_fast_pac_get_a_id"),
  2996. (2, "eap_fast_pac_get_a_id") ]
  2997. for count, func in tests:
  2998. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2999. raise Exception("Could not set blob")
  3000. with alloc_fail(dev[0], count, func):
  3001. eap_connect(dev[0], hapd, "FAST", "user",
  3002. anonymous_identity="FAST", password="password",
  3003. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3004. phase1="fast_provisioning=1 fast_pac_format=binary",
  3005. pac_file="blob://fast_pac_bin_errors")
  3006. dev[0].request("REMOVE_NETWORK all")
  3007. dev[0].wait_disconnected()
  3008. def test_ap_wpa2_eap_fast_text_pac_errors(dev, apdev):
  3009. """EAP-FAST and text PAC errors"""
  3010. check_eap_capa(dev[0], "FAST")
  3011. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3012. hostapd.add_ap(apdev[0], params)
  3013. tests = [ (1, "eap_fast_parse_hex;eap_fast_parse_pac_key"),
  3014. (1, "eap_fast_parse_hex;eap_fast_parse_pac_opaque"),
  3015. (1, "eap_fast_parse_hex;eap_fast_parse_a_id"),
  3016. (1, "eap_fast_parse_start"),
  3017. (1, "eap_fast_save_pac") ]
  3018. for count, func in tests:
  3019. dev[0].request("FLUSH")
  3020. if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
  3021. raise Exception("Could not set blob")
  3022. with alloc_fail(dev[0], count, func):
  3023. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3024. identity="user", anonymous_identity="FAST",
  3025. password="password",
  3026. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3027. phase1="fast_provisioning=1",
  3028. pac_file="blob://fast_pac_text_errors",
  3029. scan_freq="2412", wait_connect=False)
  3030. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  3031. dev[0].request("REMOVE_NETWORK all")
  3032. dev[0].wait_disconnected()
  3033. pac = "wpa_supplicant EAP-FAST PAC file - version 1\n"
  3034. pac += "START\n"
  3035. pac += "PAC-Type\n"
  3036. pac += "END\n"
  3037. if "OK" not in dev[0].request("SET blob fast_pac_text_errors " + pac.encode("hex")):
  3038. raise Exception("Could not set blob")
  3039. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3040. identity="user", anonymous_identity="FAST",
  3041. password="password",
  3042. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3043. phase1="fast_provisioning=1",
  3044. pac_file="blob://fast_pac_text_errors",
  3045. scan_freq="2412", wait_connect=False)
  3046. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=5)
  3047. if ev is None:
  3048. raise Exception("Failure not reported")
  3049. dev[0].request("REMOVE_NETWORK all")
  3050. dev[0].wait_disconnected()
  3051. dev[0].request("FLUSH")
  3052. if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
  3053. raise Exception("Could not set blob")
  3054. with alloc_fail(dev[0], 1, "eap_fast_add_pac_data"):
  3055. for i in range(3):
  3056. params = int_eap_server_params()
  3057. params['ssid'] = "test-wpa2-eap-2"
  3058. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3059. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3060. params['eap_fast_a_id_info'] = "test server %d" % i
  3061. hapd2 = hostapd.add_ap(apdev[1], params)
  3062. dev[0].connect("test-wpa2-eap-2", key_mgmt="WPA-EAP", eap="FAST",
  3063. identity="user", anonymous_identity="FAST",
  3064. password="password",
  3065. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3066. phase1="fast_provisioning=1",
  3067. pac_file="blob://fast_pac_text_errors",
  3068. scan_freq="2412", wait_connect=False)
  3069. dev[0].wait_connected()
  3070. dev[0].request("REMOVE_NETWORK all")
  3071. dev[0].wait_disconnected()
  3072. hapd2.disable()
  3073. def test_ap_wpa2_eap_fast_pac_truncate(dev, apdev):
  3074. """EAP-FAST and PAC list truncation"""
  3075. check_eap_capa(dev[0], "FAST")
  3076. if "OK" not in dev[0].request("SET blob fast_pac_truncate "):
  3077. raise Exception("Could not set blob")
  3078. for i in range(5):
  3079. params = int_eap_server_params()
  3080. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3081. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3082. params['eap_fast_a_id_info'] = "test server %d" % i
  3083. hapd = hostapd.add_ap(apdev[0], params)
  3084. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3085. identity="user", anonymous_identity="FAST",
  3086. password="password",
  3087. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3088. phase1="fast_provisioning=1 fast_max_pac_list_len=2",
  3089. pac_file="blob://fast_pac_truncate",
  3090. scan_freq="2412", wait_connect=False)
  3091. dev[0].wait_connected()
  3092. dev[0].request("REMOVE_NETWORK all")
  3093. dev[0].wait_disconnected()
  3094. hapd.disable()
  3095. def test_ap_wpa2_eap_fast_pac_refresh(dev, apdev):
  3096. """EAP-FAST and PAC refresh"""
  3097. check_eap_capa(dev[0], "FAST")
  3098. if "OK" not in dev[0].request("SET blob fast_pac_refresh "):
  3099. raise Exception("Could not set blob")
  3100. for i in range(2):
  3101. params = int_eap_server_params()
  3102. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3103. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3104. params['eap_fast_a_id_info'] = "test server %d" % i
  3105. params['pac_key_refresh_time'] = "1"
  3106. params['pac_key_lifetime'] = "10"
  3107. hapd = hostapd.add_ap(apdev[0], params)
  3108. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3109. identity="user", anonymous_identity="FAST",
  3110. password="password",
  3111. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3112. phase1="fast_provisioning=1",
  3113. pac_file="blob://fast_pac_refresh",
  3114. scan_freq="2412", wait_connect=False)
  3115. dev[0].wait_connected()
  3116. dev[0].request("REMOVE_NETWORK all")
  3117. dev[0].wait_disconnected()
  3118. hapd.disable()
  3119. for i in range(2):
  3120. params = int_eap_server_params()
  3121. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3122. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3123. params['eap_fast_a_id_info'] = "test server %d" % i
  3124. params['pac_key_refresh_time'] = "10"
  3125. params['pac_key_lifetime'] = "10"
  3126. hapd = hostapd.add_ap(apdev[0], params)
  3127. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3128. identity="user", anonymous_identity="FAST",
  3129. password="password",
  3130. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3131. phase1="fast_provisioning=1",
  3132. pac_file="blob://fast_pac_refresh",
  3133. scan_freq="2412", wait_connect=False)
  3134. dev[0].wait_connected()
  3135. dev[0].request("REMOVE_NETWORK all")
  3136. dev[0].wait_disconnected()
  3137. hapd.disable()
  3138. def test_ap_wpa2_eap_fast_pac_lifetime(dev, apdev):
  3139. """EAP-FAST and PAC lifetime"""
  3140. check_eap_capa(dev[0], "FAST")
  3141. if "OK" not in dev[0].request("SET blob fast_pac_refresh "):
  3142. raise Exception("Could not set blob")
  3143. i = 0
  3144. params = int_eap_server_params()
  3145. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3146. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3147. params['eap_fast_a_id_info'] = "test server %d" % i
  3148. params['pac_key_refresh_time'] = "0"
  3149. params['pac_key_lifetime'] = "2"
  3150. hapd = hostapd.add_ap(apdev[0], params)
  3151. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3152. identity="user", anonymous_identity="FAST",
  3153. password="password",
  3154. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3155. phase1="fast_provisioning=2",
  3156. pac_file="blob://fast_pac_refresh",
  3157. scan_freq="2412", wait_connect=False)
  3158. dev[0].wait_connected()
  3159. dev[0].request("DISCONNECT")
  3160. dev[0].wait_disconnected()
  3161. time.sleep(3)
  3162. dev[0].request("PMKSA_FLUSH")
  3163. dev[0].request("RECONNECT")
  3164. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3165. if ev is None:
  3166. raise Exception("No EAP-Failure seen after expired PAC")
  3167. dev[0].request("DISCONNECT")
  3168. dev[0].wait_disconnected()
  3169. dev[0].select_network(id)
  3170. dev[0].wait_connected()
  3171. dev[0].request("REMOVE_NETWORK all")
  3172. dev[0].wait_disconnected()
  3173. def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev):
  3174. """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning"""
  3175. check_eap_capa(dev[0], "FAST")
  3176. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3177. hapd = hostapd.add_ap(apdev[0], params)
  3178. eap_connect(dev[0], hapd, "FAST", "user",
  3179. anonymous_identity="FAST", password="password",
  3180. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3181. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth")
  3182. hwsim_utils.test_connectivity(dev[0], hapd)
  3183. res = eap_reauth(dev[0], "FAST")
  3184. if res['tls_session_reused'] != '1':
  3185. raise Exception("EAP-FAST could not use PAC session ticket")
  3186. def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev):
  3187. """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing"""
  3188. check_eap_capa(dev[0], "FAST")
  3189. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3190. hapd = hostapd.add_ap(apdev[0], params)
  3191. id = eap_connect(dev[0], hapd, "FAST", "user",
  3192. anonymous_identity="FAST", password="password",
  3193. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3194. phase1="fast_provisioning=2",
  3195. pac_file="blob://fast_pac_auth")
  3196. dev[0].set_network_quoted(id, "identity", "user2")
  3197. dev[0].wait_disconnected()
  3198. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  3199. if ev is None:
  3200. raise Exception("EAP-FAST not started")
  3201. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  3202. if ev is None:
  3203. raise Exception("EAP failure not reported")
  3204. dev[0].wait_disconnected()
  3205. def test_ap_wpa2_eap_fast_prf_oom(dev, apdev):
  3206. """WPA2-Enterprise connection using EAP-FAST and OOM in PRF"""
  3207. check_eap_capa(dev[0], "FAST")
  3208. tls = dev[0].request("GET tls_library")
  3209. if tls.startswith("OpenSSL"):
  3210. func = "tls_connection_get_eap_fast_key"
  3211. count = 2
  3212. elif tls.startswith("internal"):
  3213. func = "tls_connection_prf"
  3214. count = 1
  3215. else:
  3216. raise HwsimSkip("Unsupported TLS library")
  3217. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3218. hapd = hostapd.add_ap(apdev[0], params)
  3219. with alloc_fail(dev[0], count, func):
  3220. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3221. identity="user", anonymous_identity="FAST",
  3222. password="password", ca_cert="auth_serv/ca.pem",
  3223. phase2="auth=GTC",
  3224. phase1="fast_provisioning=2",
  3225. pac_file="blob://fast_pac_auth",
  3226. wait_connect=False, scan_freq="2412")
  3227. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  3228. if ev is None:
  3229. raise Exception("EAP failure not reported")
  3230. dev[0].request("DISCONNECT")
  3231. def test_ap_wpa2_eap_fast_server_oom(dev, apdev):
  3232. """EAP-FAST/MSCHAPv2 and server OOM"""
  3233. check_eap_capa(dev[0], "FAST")
  3234. params = int_eap_server_params()
  3235. params['dh_file'] = 'auth_serv/dh.conf'
  3236. params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f'
  3237. params['eap_fast_a_id'] = '1011'
  3238. params['eap_fast_a_id_info'] = 'another test server'
  3239. hapd = hostapd.add_ap(apdev[0], params)
  3240. with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"):
  3241. id = eap_connect(dev[0], hapd, "FAST", "user",
  3242. anonymous_identity="FAST", password="password",
  3243. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3244. phase1="fast_provisioning=1",
  3245. pac_file="blob://fast_pac",
  3246. expect_failure=True)
  3247. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3248. if ev is None:
  3249. raise Exception("No EAP failure reported")
  3250. dev[0].wait_disconnected()
  3251. dev[0].request("DISCONNECT")
  3252. dev[0].select_network(id, freq="2412")
  3253. def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev):
  3254. """EAP-FAST and different TLS cipher suites"""
  3255. check_eap_capa(dev[0], "FAST")
  3256. tls = dev[0].request("GET tls_library")
  3257. if not tls.startswith("OpenSSL"):
  3258. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  3259. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3260. hapd = hostapd.add_ap(apdev[0], params)
  3261. dev[0].request("SET blob fast_pac_ciphers ")
  3262. eap_connect(dev[0], hapd, "FAST", "user",
  3263. anonymous_identity="FAST", password="password",
  3264. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3265. phase1="fast_provisioning=2",
  3266. pac_file="blob://fast_pac_ciphers")
  3267. res = dev[0].get_status_field('EAP TLS cipher')
  3268. dev[0].request("REMOVE_NETWORK all")
  3269. dev[0].wait_disconnected()
  3270. if res != "DHE-RSA-AES256-SHA":
  3271. raise Exception("Unexpected cipher suite for provisioning: " + res)
  3272. tests = [ "DHE-RSA-AES128-SHA",
  3273. "RC4-SHA",
  3274. "AES128-SHA",
  3275. "AES256-SHA",
  3276. "DHE-RSA-AES256-SHA" ]
  3277. for cipher in tests:
  3278. dev[0].dump_monitor()
  3279. logger.info("Testing " + cipher)
  3280. try:
  3281. eap_connect(dev[0], hapd, "FAST", "user",
  3282. openssl_ciphers=cipher,
  3283. anonymous_identity="FAST", password="password",
  3284. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3285. pac_file="blob://fast_pac_ciphers")
  3286. except Exception, e:
  3287. if "Could not select EAP method" in str(e) and cipher == "RC4-SHA":
  3288. tls = dev[0].request("GET tls_library")
  3289. if "run=OpenSSL 1.1" in tls:
  3290. logger.info("Allow failure due to missing TLS library support")
  3291. dev[0].request("REMOVE_NETWORK all")
  3292. dev[0].wait_disconnected()
  3293. continue
  3294. raise
  3295. res = dev[0].get_status_field('EAP TLS cipher')
  3296. dev[0].request("REMOVE_NETWORK all")
  3297. dev[0].wait_disconnected()
  3298. if res != cipher:
  3299. raise Exception("Unexpected TLS cipher info (configured %s): %s" % (cipher, res))
  3300. def test_ap_wpa2_eap_fast_prov(dev, apdev):
  3301. """EAP-FAST and provisioning options"""
  3302. check_eap_capa(dev[0], "FAST")
  3303. if "OK" not in dev[0].request("SET blob fast_pac_prov "):
  3304. raise Exception("Could not set blob")
  3305. i = 100
  3306. params = int_eap_server_params()
  3307. params['disable_pmksa_caching'] = '1'
  3308. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3309. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3310. params['eap_fast_a_id_info'] = "test server %d" % i
  3311. params['eap_fast_prov'] = "0"
  3312. hapd = hostapd.add_ap(apdev[0], params)
  3313. logger.info("Provisioning attempt while server has provisioning disabled")
  3314. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3315. identity="user", anonymous_identity="FAST",
  3316. password="password",
  3317. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3318. phase1="fast_provisioning=2",
  3319. pac_file="blob://fast_pac_prov",
  3320. scan_freq="2412", wait_connect=False)
  3321. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3322. timeout=15)
  3323. if ev is None:
  3324. raise Exception("EAP result not reported")
  3325. if "parameter='failure'" not in ev:
  3326. raise Exception("Unexpected EAP result: " + ev)
  3327. dev[0].wait_disconnected()
  3328. dev[0].request("DISCONNECT")
  3329. dev[0].dump_monitor()
  3330. hapd.disable()
  3331. logger.info("Authenticated provisioning")
  3332. hapd.set("eap_fast_prov", "2")
  3333. hapd.enable()
  3334. dev[0].select_network(id, freq="2412")
  3335. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3336. timeout=15)
  3337. if ev is None:
  3338. raise Exception("EAP result not reported")
  3339. if "parameter='success'" not in ev:
  3340. raise Exception("Unexpected EAP result: " + ev)
  3341. dev[0].wait_connected()
  3342. dev[0].request("DISCONNECT")
  3343. dev[0].wait_disconnected()
  3344. dev[0].dump_monitor()
  3345. hapd.disable()
  3346. logger.info("Provisioning disabled - using previously provisioned PAC")
  3347. hapd.set("eap_fast_prov", "0")
  3348. hapd.enable()
  3349. dev[0].select_network(id, freq="2412")
  3350. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3351. timeout=15)
  3352. if ev is None:
  3353. raise Exception("EAP result not reported")
  3354. if "parameter='success'" not in ev:
  3355. raise Exception("Unexpected EAP result: " + ev)
  3356. dev[0].wait_connected()
  3357. dev[0].request("DISCONNECT")
  3358. dev[0].wait_disconnected()
  3359. dev[0].dump_monitor()
  3360. logger.info("Drop PAC and verify connection failure")
  3361. if "OK" not in dev[0].request("SET blob fast_pac_prov "):
  3362. raise Exception("Could not set blob")
  3363. dev[0].select_network(id, freq="2412")
  3364. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3365. timeout=15)
  3366. if ev is None:
  3367. raise Exception("EAP result not reported")
  3368. if "parameter='failure'" not in ev:
  3369. raise Exception("Unexpected EAP result: " + ev)
  3370. dev[0].wait_disconnected()
  3371. dev[0].request("DISCONNECT")
  3372. dev[0].dump_monitor()
  3373. hapd.disable()
  3374. logger.info("Anonymous provisioning")
  3375. hapd.set("eap_fast_prov", "1")
  3376. hapd.enable()
  3377. dev[0].set_network_quoted(id, "phase1", "fast_provisioning=1")
  3378. dev[0].select_network(id, freq="2412")
  3379. # Anonymous provisioning results in EAP-Failure first
  3380. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3381. timeout=15)
  3382. if ev is None:
  3383. raise Exception("EAP result not reported")
  3384. if "parameter='failure'" not in ev:
  3385. raise Exception("Unexpected EAP result: " + ev)
  3386. dev[0].wait_disconnected()
  3387. # And then the actual data connection
  3388. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3389. timeout=15)
  3390. if ev is None:
  3391. raise Exception("EAP result not reported")
  3392. if "parameter='success'" not in ev:
  3393. raise Exception("Unexpected EAP result: " + ev)
  3394. dev[0].wait_connected()
  3395. dev[0].request("DISCONNECT")
  3396. dev[0].wait_disconnected()
  3397. dev[0].dump_monitor()
  3398. hapd.disable()
  3399. logger.info("Provisioning disabled - using previously provisioned PAC")
  3400. hapd.set("eap_fast_prov", "0")
  3401. hapd.enable()
  3402. dev[0].select_network(id, freq="2412")
  3403. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS status='completion'"],
  3404. timeout=15)
  3405. if ev is None:
  3406. raise Exception("EAP result not reported")
  3407. if "parameter='success'" not in ev:
  3408. raise Exception("Unexpected EAP result: " + ev)
  3409. dev[0].wait_connected()
  3410. dev[0].request("DISCONNECT")
  3411. dev[0].wait_disconnected()
  3412. dev[0].dump_monitor()
  3413. def test_ap_wpa2_eap_tls_ocsp(dev, apdev):
  3414. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP"""
  3415. check_ocsp_support(dev[0])
  3416. check_pkcs12_support(dev[0])
  3417. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3418. hapd = hostapd.add_ap(apdev[0], params)
  3419. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3420. private_key="auth_serv/user.pkcs12",
  3421. private_key_passwd="whatever", ocsp=2)
  3422. def test_ap_wpa2_eap_tls_ocsp_multi(dev, apdev):
  3423. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP-multi"""
  3424. check_ocsp_multi_support(dev[0])
  3425. check_pkcs12_support(dev[0])
  3426. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3427. hapd = hostapd.add_ap(apdev[0], params)
  3428. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3429. private_key="auth_serv/user.pkcs12",
  3430. private_key_passwd="whatever", ocsp=2)
  3431. def int_eap_server_params():
  3432. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  3433. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  3434. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  3435. "ca_cert": "auth_serv/ca.pem",
  3436. "server_cert": "auth_serv/server.pem",
  3437. "private_key": "auth_serv/server.key",
  3438. "dh_file": "auth_serv/dh.conf" }
  3439. return params
  3440. def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params):
  3441. """EAP-TLS and OCSP certificate signed OCSP response using key ID"""
  3442. check_ocsp_support(dev[0])
  3443. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-key-id.der")
  3444. if not os.path.exists(ocsp):
  3445. raise HwsimSkip("No OCSP response available")
  3446. params = int_eap_server_params()
  3447. params["ocsp_stapling_response"] = ocsp
  3448. hostapd.add_ap(apdev[0], params)
  3449. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3450. identity="tls user", ca_cert="auth_serv/ca.pem",
  3451. private_key="auth_serv/user.pkcs12",
  3452. private_key_passwd="whatever", ocsp=2,
  3453. scan_freq="2412")
  3454. def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params):
  3455. """EAP-TLS and CA signed OCSP response (good)"""
  3456. check_ocsp_support(dev[0])
  3457. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der")
  3458. if not os.path.exists(ocsp):
  3459. raise HwsimSkip("No OCSP response available")
  3460. params = int_eap_server_params()
  3461. params["ocsp_stapling_response"] = ocsp
  3462. hostapd.add_ap(apdev[0], params)
  3463. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3464. identity="tls user", ca_cert="auth_serv/ca.pem",
  3465. private_key="auth_serv/user.pkcs12",
  3466. private_key_passwd="whatever", ocsp=2,
  3467. scan_freq="2412")
  3468. def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params):
  3469. """EAP-TLS and CA signed OCSP response (revoked)"""
  3470. check_ocsp_support(dev[0])
  3471. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der")
  3472. if not os.path.exists(ocsp):
  3473. raise HwsimSkip("No OCSP response available")
  3474. params = int_eap_server_params()
  3475. params["ocsp_stapling_response"] = ocsp
  3476. hostapd.add_ap(apdev[0], params)
  3477. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3478. identity="tls user", ca_cert="auth_serv/ca.pem",
  3479. private_key="auth_serv/user.pkcs12",
  3480. private_key_passwd="whatever", ocsp=2,
  3481. wait_connect=False, scan_freq="2412")
  3482. count = 0
  3483. while True:
  3484. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3485. if ev is None:
  3486. raise Exception("Timeout on EAP status")
  3487. if 'bad certificate status response' in ev:
  3488. break
  3489. if 'certificate revoked' in ev:
  3490. break
  3491. count = count + 1
  3492. if count > 10:
  3493. raise Exception("Unexpected number of EAP status messages")
  3494. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3495. if ev is None:
  3496. raise Exception("Timeout on EAP failure report")
  3497. def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params):
  3498. """EAP-TLS and CA signed OCSP response (unknown)"""
  3499. check_ocsp_support(dev[0])
  3500. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der")
  3501. if not os.path.exists(ocsp):
  3502. raise HwsimSkip("No OCSP response available")
  3503. params = int_eap_server_params()
  3504. params["ocsp_stapling_response"] = ocsp
  3505. hostapd.add_ap(apdev[0], params)
  3506. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3507. identity="tls user", ca_cert="auth_serv/ca.pem",
  3508. private_key="auth_serv/user.pkcs12",
  3509. private_key_passwd="whatever", ocsp=2,
  3510. wait_connect=False, scan_freq="2412")
  3511. count = 0
  3512. while True:
  3513. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3514. if ev is None:
  3515. raise Exception("Timeout on EAP status")
  3516. if 'bad certificate status response' in ev:
  3517. break
  3518. count = count + 1
  3519. if count > 10:
  3520. raise Exception("Unexpected number of EAP status messages")
  3521. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3522. if ev is None:
  3523. raise Exception("Timeout on EAP failure report")
  3524. def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params):
  3525. """EAP-TLS and server signed OCSP response"""
  3526. check_ocsp_support(dev[0])
  3527. ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der")
  3528. if not os.path.exists(ocsp):
  3529. raise HwsimSkip("No OCSP response available")
  3530. params = int_eap_server_params()
  3531. params["ocsp_stapling_response"] = ocsp
  3532. hostapd.add_ap(apdev[0], params)
  3533. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3534. identity="tls user", ca_cert="auth_serv/ca.pem",
  3535. private_key="auth_serv/user.pkcs12",
  3536. private_key_passwd="whatever", ocsp=2,
  3537. wait_connect=False, scan_freq="2412")
  3538. count = 0
  3539. while True:
  3540. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3541. if ev is None:
  3542. raise Exception("Timeout on EAP status")
  3543. if 'bad certificate status response' in ev:
  3544. break
  3545. count = count + 1
  3546. if count > 10:
  3547. raise Exception("Unexpected number of EAP status messages")
  3548. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3549. if ev is None:
  3550. raise Exception("Timeout on EAP failure report")
  3551. def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
  3552. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data"""
  3553. check_ocsp_support(dev[0])
  3554. params = int_eap_server_params()
  3555. params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der"
  3556. hostapd.add_ap(apdev[0], params)
  3557. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3558. identity="tls user", ca_cert="auth_serv/ca.pem",
  3559. private_key="auth_serv/user.pkcs12",
  3560. private_key_passwd="whatever", ocsp=2,
  3561. wait_connect=False, scan_freq="2412")
  3562. count = 0
  3563. while True:
  3564. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3565. if ev is None:
  3566. raise Exception("Timeout on EAP status")
  3567. if 'bad certificate status response' in ev:
  3568. break
  3569. count = count + 1
  3570. if count > 10:
  3571. raise Exception("Unexpected number of EAP status messages")
  3572. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3573. if ev is None:
  3574. raise Exception("Timeout on EAP failure report")
  3575. def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
  3576. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
  3577. check_ocsp_support(dev[0])
  3578. params = int_eap_server_params()
  3579. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
  3580. hostapd.add_ap(apdev[0], params)
  3581. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3582. identity="tls user", ca_cert="auth_serv/ca.pem",
  3583. private_key="auth_serv/user.pkcs12",
  3584. private_key_passwd="whatever", ocsp=2,
  3585. wait_connect=False, scan_freq="2412")
  3586. count = 0
  3587. while True:
  3588. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3589. if ev is None:
  3590. raise Exception("Timeout on EAP status")
  3591. if 'bad certificate status response' in ev:
  3592. break
  3593. count = count + 1
  3594. if count > 10:
  3595. raise Exception("Unexpected number of EAP status messages")
  3596. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3597. if ev is None:
  3598. raise Exception("Timeout on EAP failure report")
  3599. def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev):
  3600. """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer"""
  3601. check_ocsp_support(dev[0])
  3602. params = int_eap_server_params()
  3603. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign"
  3604. hostapd.add_ap(apdev[0], params)
  3605. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3606. identity="tls user", ca_cert="auth_serv/ca.pem",
  3607. private_key="auth_serv/user.pkcs12",
  3608. private_key_passwd="whatever", ocsp=2,
  3609. wait_connect=False, scan_freq="2412")
  3610. count = 0
  3611. while True:
  3612. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3613. if ev is None:
  3614. raise Exception("Timeout on EAP status")
  3615. if 'bad certificate status response' in ev:
  3616. break
  3617. count = count + 1
  3618. if count > 10:
  3619. raise Exception("Unexpected number of EAP status messages")
  3620. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3621. if ev is None:
  3622. raise Exception("Timeout on EAP failure report")
  3623. def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params):
  3624. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3625. check_ocsp_support(dev[0])
  3626. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der")
  3627. if not os.path.exists(ocsp):
  3628. raise HwsimSkip("No OCSP response available")
  3629. params = int_eap_server_params()
  3630. params["ocsp_stapling_response"] = ocsp
  3631. hostapd.add_ap(apdev[0], params)
  3632. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3633. identity="pap user", ca_cert="auth_serv/ca.pem",
  3634. anonymous_identity="ttls", password="password",
  3635. phase2="auth=PAP", ocsp=2,
  3636. wait_connect=False, scan_freq="2412")
  3637. count = 0
  3638. while True:
  3639. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3640. if ev is None:
  3641. raise Exception("Timeout on EAP status")
  3642. if 'bad certificate status response' in ev:
  3643. break
  3644. if 'certificate revoked' in ev:
  3645. break
  3646. count = count + 1
  3647. if count > 10:
  3648. raise Exception("Unexpected number of EAP status messages")
  3649. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3650. if ev is None:
  3651. raise Exception("Timeout on EAP failure report")
  3652. def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params):
  3653. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3654. check_ocsp_support(dev[0])
  3655. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  3656. if not os.path.exists(ocsp):
  3657. raise HwsimSkip("No OCSP response available")
  3658. params = int_eap_server_params()
  3659. params["ocsp_stapling_response"] = ocsp
  3660. hostapd.add_ap(apdev[0], params)
  3661. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3662. identity="pap user", ca_cert="auth_serv/ca.pem",
  3663. anonymous_identity="ttls", password="password",
  3664. phase2="auth=PAP", ocsp=2,
  3665. wait_connect=False, scan_freq="2412")
  3666. count = 0
  3667. while True:
  3668. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3669. if ev is None:
  3670. raise Exception("Timeout on EAP status")
  3671. if 'bad certificate status response' in ev:
  3672. break
  3673. count = count + 1
  3674. if count > 10:
  3675. raise Exception("Unexpected number of EAP status messages")
  3676. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3677. if ev is None:
  3678. raise Exception("Timeout on EAP failure report")
  3679. def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params):
  3680. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3681. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  3682. if not os.path.exists(ocsp):
  3683. raise HwsimSkip("No OCSP response available")
  3684. params = int_eap_server_params()
  3685. params["ocsp_stapling_response"] = ocsp
  3686. hostapd.add_ap(apdev[0], params)
  3687. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3688. identity="pap user", ca_cert="auth_serv/ca.pem",
  3689. anonymous_identity="ttls", password="password",
  3690. phase2="auth=PAP", ocsp=1, scan_freq="2412")
  3691. def test_ap_wpa2_eap_tls_intermediate_ca(dev, apdev, params):
  3692. """EAP-TLS with intermediate server/user CA"""
  3693. params = int_eap_server_params()
  3694. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3695. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3696. params["private_key"] = "auth_serv/iCA-server/server.key"
  3697. hostapd.add_ap(apdev[0], params)
  3698. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3699. identity="tls user",
  3700. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3701. client_cert="auth_serv/iCA-user/user.pem",
  3702. private_key="auth_serv/iCA-user/user.key",
  3703. scan_freq="2412")
  3704. def root_ocsp(cert):
  3705. ca = "auth_serv/ca.pem"
  3706. fd2, fn2 = tempfile.mkstemp()
  3707. os.close(fd2)
  3708. arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-sha256",
  3709. "-cert", cert, "-no_nonce", "-text" ]
  3710. logger.info(' '.join(arg))
  3711. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3712. stderr=subprocess.PIPE)
  3713. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3714. cmd.stdout.close()
  3715. cmd.stderr.close()
  3716. cmd.wait()
  3717. if cmd.returncode != 0:
  3718. raise Exception("bad return code from openssl ocsp\n\n" + res)
  3719. logger.info("OCSP request:\n" + res)
  3720. fd, fn = tempfile.mkstemp()
  3721. os.close(fd)
  3722. arg = [ "openssl", "ocsp", "-index", "auth_serv/rootCA/index.txt",
  3723. "-rsigner", ca, "-rkey", "auth_serv/ca-key.pem",
  3724. "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
  3725. "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
  3726. "-text" ]
  3727. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3728. stderr=subprocess.PIPE)
  3729. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3730. cmd.stdout.close()
  3731. cmd.stderr.close()
  3732. cmd.wait()
  3733. if cmd.returncode != 0:
  3734. raise Exception("bad return code from openssl ocsp\n\n" + res)
  3735. logger.info("OCSP response:\n" + res)
  3736. os.unlink(fn2)
  3737. return fn
  3738. def ica_ocsp(cert, md="-sha256"):
  3739. prefix = "auth_serv/iCA-server/"
  3740. ca = prefix + "cacert.pem"
  3741. cert = prefix + cert
  3742. fd2, fn2 = tempfile.mkstemp()
  3743. os.close(fd2)
  3744. arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, md,
  3745. "-cert", cert, "-no_nonce", "-text" ]
  3746. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3747. stderr=subprocess.PIPE)
  3748. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3749. cmd.stdout.close()
  3750. cmd.stderr.close()
  3751. cmd.wait()
  3752. if cmd.returncode != 0:
  3753. raise Exception("bad return code from openssl ocsp\n\n" + res)
  3754. logger.info("OCSP request:\n" + res)
  3755. fd, fn = tempfile.mkstemp()
  3756. os.close(fd)
  3757. arg = [ "openssl", "ocsp", "-index", prefix + "index.txt",
  3758. "-rsigner", ca, "-rkey", prefix + "private/cakey.pem",
  3759. "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
  3760. "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
  3761. "-text" ]
  3762. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3763. stderr=subprocess.PIPE)
  3764. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3765. cmd.stdout.close()
  3766. cmd.stderr.close()
  3767. cmd.wait()
  3768. if cmd.returncode != 0:
  3769. raise Exception("bad return code from openssl ocsp\n\n" + res)
  3770. logger.info("OCSP response:\n" + res)
  3771. os.unlink(fn2)
  3772. return fn
  3773. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params):
  3774. """EAP-TLS with intermediate server/user CA and OCSP on server certificate"""
  3775. run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, "-sha256")
  3776. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_sha1(dev, apdev, params):
  3777. """EAP-TLS with intermediate server/user CA and OCSP on server certificate )SHA1)"""
  3778. run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, "-sha1")
  3779. def run_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params, md):
  3780. params = int_eap_server_params()
  3781. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3782. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3783. params["private_key"] = "auth_serv/iCA-server/server.key"
  3784. fn = ica_ocsp("server.pem", md)
  3785. params["ocsp_stapling_response"] = fn
  3786. try:
  3787. hostapd.add_ap(apdev[0], params)
  3788. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3789. identity="tls user",
  3790. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3791. client_cert="auth_serv/iCA-user/user.pem",
  3792. private_key="auth_serv/iCA-user/user.key",
  3793. scan_freq="2412", ocsp=2)
  3794. finally:
  3795. os.unlink(fn)
  3796. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params):
  3797. """EAP-TLS with intermediate server/user CA and OCSP on revoked server certificate"""
  3798. run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params,
  3799. "-sha256")
  3800. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked_sha1(dev, apdev, params):
  3801. """EAP-TLS with intermediate server/user CA and OCSP on revoked server certificate (SHA1)"""
  3802. run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params,
  3803. "-sha1")
  3804. def run_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params, md):
  3805. params = int_eap_server_params()
  3806. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3807. params["server_cert"] = "auth_serv/iCA-server/server-revoked.pem"
  3808. params["private_key"] = "auth_serv/iCA-server/server-revoked.key"
  3809. fn = ica_ocsp("server-revoked.pem", md)
  3810. params["ocsp_stapling_response"] = fn
  3811. try:
  3812. hostapd.add_ap(apdev[0], params)
  3813. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3814. identity="tls user",
  3815. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3816. client_cert="auth_serv/iCA-user/user.pem",
  3817. private_key="auth_serv/iCA-user/user.key",
  3818. scan_freq="2412", ocsp=1, wait_connect=False)
  3819. count = 0
  3820. while True:
  3821. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3822. "CTRL-EVENT-EAP-SUCCESS"])
  3823. if ev is None:
  3824. raise Exception("Timeout on EAP status")
  3825. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3826. raise Exception("Unexpected EAP-Success")
  3827. if 'bad certificate status response' in ev:
  3828. break
  3829. if 'certificate revoked' in ev:
  3830. break
  3831. count = count + 1
  3832. if count > 10:
  3833. raise Exception("Unexpected number of EAP status messages")
  3834. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3835. if ev is None:
  3836. raise Exception("Timeout on EAP failure report")
  3837. dev[0].request("REMOVE_NETWORK all")
  3838. dev[0].wait_disconnected()
  3839. finally:
  3840. os.unlink(fn)
  3841. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi_missing_resp(dev, apdev, params):
  3842. """EAP-TLS with intermediate server/user CA and OCSP multi missing response"""
  3843. check_ocsp_support(dev[0])
  3844. check_ocsp_multi_support(dev[0])
  3845. params = int_eap_server_params()
  3846. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3847. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3848. params["private_key"] = "auth_serv/iCA-server/server.key"
  3849. fn = ica_ocsp("server.pem")
  3850. params["ocsp_stapling_response"] = fn
  3851. try:
  3852. hostapd.add_ap(apdev[0], params)
  3853. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3854. identity="tls user",
  3855. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3856. client_cert="auth_serv/iCA-user/user.pem",
  3857. private_key="auth_serv/iCA-user/user.key",
  3858. scan_freq="2412", ocsp=3, wait_connect=False)
  3859. count = 0
  3860. while True:
  3861. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3862. "CTRL-EVENT-EAP-SUCCESS"])
  3863. if ev is None:
  3864. raise Exception("Timeout on EAP status")
  3865. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3866. raise Exception("Unexpected EAP-Success")
  3867. if 'bad certificate status response' in ev:
  3868. break
  3869. if 'certificate revoked' in ev:
  3870. break
  3871. count = count + 1
  3872. if count > 10:
  3873. raise Exception("Unexpected number of EAP status messages")
  3874. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3875. if ev is None:
  3876. raise Exception("Timeout on EAP failure report")
  3877. dev[0].request("REMOVE_NETWORK all")
  3878. dev[0].wait_disconnected()
  3879. finally:
  3880. os.unlink(fn)
  3881. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi(dev, apdev, params):
  3882. """EAP-TLS with intermediate server/user CA and OCSP multi OK"""
  3883. check_ocsp_support(dev[0])
  3884. check_ocsp_multi_support(dev[0])
  3885. params = int_eap_server_params()
  3886. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3887. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3888. params["private_key"] = "auth_serv/iCA-server/server.key"
  3889. fn = ica_ocsp("server.pem")
  3890. fn2 = root_ocsp("auth_serv/iCA-server/cacert.pem")
  3891. params["ocsp_stapling_response"] = fn
  3892. with open(fn, "r") as f:
  3893. resp_server = f.read()
  3894. with open(fn2, "r") as f:
  3895. resp_ica = f.read()
  3896. fd3, fn3 = tempfile.mkstemp()
  3897. try:
  3898. f = os.fdopen(fd3, 'w')
  3899. f.write(struct.pack(">L", len(resp_server))[1:4])
  3900. f.write(resp_server)
  3901. f.write(struct.pack(">L", len(resp_ica))[1:4])
  3902. f.write(resp_ica)
  3903. f.close()
  3904. params["ocsp_stapling_response_multi"] = fn3
  3905. hostapd.add_ap(apdev[0], params)
  3906. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3907. identity="tls user",
  3908. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3909. client_cert="auth_serv/iCA-user/user.pem",
  3910. private_key="auth_serv/iCA-user/user.key",
  3911. scan_freq="2412", ocsp=3)
  3912. dev[0].request("REMOVE_NETWORK all")
  3913. dev[0].wait_disconnected()
  3914. finally:
  3915. os.unlink(fn)
  3916. os.unlink(fn2)
  3917. os.unlink(fn3)
  3918. def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
  3919. """EAP-TLS and CA signed OCSP multi response (revoked)"""
  3920. check_ocsp_support(dev[0])
  3921. check_ocsp_multi_support(dev[0])
  3922. ocsp_revoked = os.path.join(params['logdir'],
  3923. "ocsp-resp-ca-signed-revoked.der")
  3924. if not os.path.exists(ocsp_revoked):
  3925. raise HwsimSkip("No OCSP response (revoked) available")
  3926. ocsp_unknown = os.path.join(params['logdir'],
  3927. "ocsp-resp-ca-signed-unknown.der")
  3928. if not os.path.exists(ocsp_unknown):
  3929. raise HwsimSkip("No OCSP response(unknown) available")
  3930. with open(ocsp_revoked, "r") as f:
  3931. resp_revoked = f.read()
  3932. with open(ocsp_unknown, "r") as f:
  3933. resp_unknown = f.read()
  3934. fd, fn = tempfile.mkstemp()
  3935. try:
  3936. # This is not really a valid order of the OCSPResponse items in the
  3937. # list, but this works for now to verify parsing and processing of
  3938. # multiple responses.
  3939. f = os.fdopen(fd, 'w')
  3940. f.write(struct.pack(">L", len(resp_unknown))[1:4])
  3941. f.write(resp_unknown)
  3942. f.write(struct.pack(">L", len(resp_revoked))[1:4])
  3943. f.write(resp_revoked)
  3944. f.write(struct.pack(">L", 0)[1:4])
  3945. f.write(struct.pack(">L", len(resp_unknown))[1:4])
  3946. f.write(resp_unknown)
  3947. f.close()
  3948. params = int_eap_server_params()
  3949. params["ocsp_stapling_response_multi"] = fn
  3950. hostapd.add_ap(apdev[0], params)
  3951. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3952. identity="tls user", ca_cert="auth_serv/ca.pem",
  3953. private_key="auth_serv/user.pkcs12",
  3954. private_key_passwd="whatever", ocsp=1,
  3955. wait_connect=False, scan_freq="2412")
  3956. count = 0
  3957. while True:
  3958. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3959. "CTRL-EVENT-EAP-SUCCESS"])
  3960. if ev is None:
  3961. raise Exception("Timeout on EAP status")
  3962. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3963. raise Exception("Unexpected EAP-Success")
  3964. if 'bad certificate status response' in ev:
  3965. break
  3966. if 'certificate revoked' in ev:
  3967. break
  3968. count = count + 1
  3969. if count > 10:
  3970. raise Exception("Unexpected number of EAP status messages")
  3971. finally:
  3972. os.unlink(fn)
  3973. def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
  3974. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  3975. check_domain_match_full(dev[0])
  3976. params = int_eap_server_params()
  3977. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3978. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3979. hostapd.add_ap(apdev[0], params)
  3980. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3981. identity="tls user", ca_cert="auth_serv/ca.pem",
  3982. private_key="auth_serv/user.pkcs12",
  3983. private_key_passwd="whatever",
  3984. domain_suffix_match="server3.w1.fi",
  3985. scan_freq="2412")
  3986. def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
  3987. """WPA2-Enterprise using EAP-TLS and domainmatch (CN)"""
  3988. check_domain_match(dev[0])
  3989. params = int_eap_server_params()
  3990. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3991. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3992. hostapd.add_ap(apdev[0], params)
  3993. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3994. identity="tls user", ca_cert="auth_serv/ca.pem",
  3995. private_key="auth_serv/user.pkcs12",
  3996. private_key_passwd="whatever",
  3997. domain_match="server3.w1.fi",
  3998. scan_freq="2412")
  3999. def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
  4000. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  4001. check_domain_match_full(dev[0])
  4002. params = int_eap_server_params()
  4003. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  4004. params["private_key"] = "auth_serv/server-no-dnsname.key"
  4005. hostapd.add_ap(apdev[0], params)
  4006. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4007. identity="tls user", ca_cert="auth_serv/ca.pem",
  4008. private_key="auth_serv/user.pkcs12",
  4009. private_key_passwd="whatever",
  4010. domain_suffix_match="w1.fi",
  4011. scan_freq="2412")
  4012. def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
  4013. """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
  4014. check_domain_suffix_match(dev[0])
  4015. params = int_eap_server_params()
  4016. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  4017. params["private_key"] = "auth_serv/server-no-dnsname.key"
  4018. hostapd.add_ap(apdev[0], params)
  4019. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4020. identity="tls user", ca_cert="auth_serv/ca.pem",
  4021. private_key="auth_serv/user.pkcs12",
  4022. private_key_passwd="whatever",
  4023. domain_suffix_match="example.com",
  4024. wait_connect=False,
  4025. scan_freq="2412")
  4026. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4027. identity="tls user", ca_cert="auth_serv/ca.pem",
  4028. private_key="auth_serv/user.pkcs12",
  4029. private_key_passwd="whatever",
  4030. domain_suffix_match="erver3.w1.fi",
  4031. wait_connect=False,
  4032. scan_freq="2412")
  4033. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4034. if ev is None:
  4035. raise Exception("Timeout on EAP failure report")
  4036. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4037. if ev is None:
  4038. raise Exception("Timeout on EAP failure report (2)")
  4039. def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev):
  4040. """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)"""
  4041. check_domain_match(dev[0])
  4042. params = int_eap_server_params()
  4043. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  4044. params["private_key"] = "auth_serv/server-no-dnsname.key"
  4045. hostapd.add_ap(apdev[0], params)
  4046. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4047. identity="tls user", ca_cert="auth_serv/ca.pem",
  4048. private_key="auth_serv/user.pkcs12",
  4049. private_key_passwd="whatever",
  4050. domain_match="example.com",
  4051. wait_connect=False,
  4052. scan_freq="2412")
  4053. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4054. identity="tls user", ca_cert="auth_serv/ca.pem",
  4055. private_key="auth_serv/user.pkcs12",
  4056. private_key_passwd="whatever",
  4057. domain_match="w1.fi",
  4058. wait_connect=False,
  4059. scan_freq="2412")
  4060. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4061. if ev is None:
  4062. raise Exception("Timeout on EAP failure report")
  4063. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4064. if ev is None:
  4065. raise Exception("Timeout on EAP failure report (2)")
  4066. def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev):
  4067. """WPA2-Enterprise using EAP-TTLS and expired certificate"""
  4068. skip_with_fips(dev[0])
  4069. params = int_eap_server_params()
  4070. params["server_cert"] = "auth_serv/server-expired.pem"
  4071. params["private_key"] = "auth_serv/server-expired.key"
  4072. hostapd.add_ap(apdev[0], params)
  4073. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4074. identity="mschap user", password="password",
  4075. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4076. wait_connect=False,
  4077. scan_freq="2412")
  4078. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  4079. if ev is None:
  4080. raise Exception("Timeout on EAP certificate error report")
  4081. if "reason=4" not in ev or "certificate has expired" not in ev:
  4082. raise Exception("Unexpected failure reason: " + ev)
  4083. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4084. if ev is None:
  4085. raise Exception("Timeout on EAP failure report")
  4086. def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev):
  4087. """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration"""
  4088. skip_with_fips(dev[0])
  4089. params = int_eap_server_params()
  4090. params["server_cert"] = "auth_serv/server-expired.pem"
  4091. params["private_key"] = "auth_serv/server-expired.key"
  4092. hostapd.add_ap(apdev[0], params)
  4093. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4094. identity="mschap user", password="password",
  4095. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4096. phase1="tls_disable_time_checks=1",
  4097. scan_freq="2412")
  4098. def test_ap_wpa2_eap_ttls_long_duration(dev, apdev):
  4099. """WPA2-Enterprise using EAP-TTLS and long certificate duration"""
  4100. skip_with_fips(dev[0])
  4101. params = int_eap_server_params()
  4102. params["server_cert"] = "auth_serv/server-long-duration.pem"
  4103. params["private_key"] = "auth_serv/server-long-duration.key"
  4104. hostapd.add_ap(apdev[0], params)
  4105. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4106. identity="mschap user", password="password",
  4107. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4108. scan_freq="2412")
  4109. def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev):
  4110. """WPA2-Enterprise using EAP-TTLS and server cert with client EKU"""
  4111. skip_with_fips(dev[0])
  4112. params = int_eap_server_params()
  4113. params["server_cert"] = "auth_serv/server-eku-client.pem"
  4114. params["private_key"] = "auth_serv/server-eku-client.key"
  4115. hostapd.add_ap(apdev[0], params)
  4116. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4117. identity="mschap user", password="password",
  4118. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4119. wait_connect=False,
  4120. scan_freq="2412")
  4121. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4122. if ev is None:
  4123. raise Exception("Timeout on EAP failure report")
  4124. def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev):
  4125. """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU"""
  4126. skip_with_fips(dev[0])
  4127. params = int_eap_server_params()
  4128. params["server_cert"] = "auth_serv/server-eku-client-server.pem"
  4129. params["private_key"] = "auth_serv/server-eku-client-server.key"
  4130. hostapd.add_ap(apdev[0], params)
  4131. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4132. identity="mschap user", password="password",
  4133. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4134. scan_freq="2412")
  4135. def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev):
  4136. """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file"""
  4137. skip_with_fips(dev[0])
  4138. params = int_eap_server_params()
  4139. del params["server_cert"]
  4140. params["private_key"] = "auth_serv/server.pkcs12"
  4141. hostapd.add_ap(apdev[0], params)
  4142. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4143. identity="mschap user", password="password",
  4144. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4145. scan_freq="2412")
  4146. def test_ap_wpa2_eap_ttls_server_pkcs12_extra(dev, apdev):
  4147. """EAP-TTLS and server PKCS#12 file with extra certs"""
  4148. skip_with_fips(dev[0])
  4149. params = int_eap_server_params()
  4150. del params["server_cert"]
  4151. params["private_key"] = "auth_serv/server-extra.pkcs12"
  4152. params["private_key_passwd"] = "whatever"
  4153. hostapd.add_ap(apdev[0], params)
  4154. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4155. identity="mschap user", password="password",
  4156. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4157. scan_freq="2412")
  4158. def test_ap_wpa2_eap_ttls_dh_params(dev, apdev):
  4159. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params"""
  4160. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4161. hapd = hostapd.add_ap(apdev[0], params)
  4162. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4163. anonymous_identity="ttls", password="password",
  4164. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  4165. dh_file="auth_serv/dh.conf")
  4166. def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev):
  4167. """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)"""
  4168. check_dh_dsa_support(dev[0])
  4169. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4170. hapd = hostapd.add_ap(apdev[0], params)
  4171. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4172. anonymous_identity="ttls", password="password",
  4173. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  4174. dh_file="auth_serv/dsaparam.pem")
  4175. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  4176. """EAP-TTLS and DH params file not found"""
  4177. skip_with_fips(dev[0])
  4178. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4179. hostapd.add_ap(apdev[0], params)
  4180. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4181. identity="mschap user", password="password",
  4182. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4183. dh_file="auth_serv/dh-no-such-file.conf",
  4184. scan_freq="2412", wait_connect=False)
  4185. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4186. if ev is None:
  4187. raise Exception("EAP failure timed out")
  4188. dev[0].request("REMOVE_NETWORK all")
  4189. dev[0].wait_disconnected()
  4190. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  4191. """EAP-TTLS and invalid DH params file"""
  4192. skip_with_fips(dev[0])
  4193. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4194. hostapd.add_ap(apdev[0], params)
  4195. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4196. identity="mschap user", password="password",
  4197. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4198. dh_file="auth_serv/ca.pem",
  4199. scan_freq="2412", wait_connect=False)
  4200. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4201. if ev is None:
  4202. raise Exception("EAP failure timed out")
  4203. dev[0].request("REMOVE_NETWORK all")
  4204. dev[0].wait_disconnected()
  4205. def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
  4206. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob"""
  4207. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4208. hapd = hostapd.add_ap(apdev[0], params)
  4209. dh = read_pem("auth_serv/dh2.conf")
  4210. if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
  4211. raise Exception("Could not set dhparams blob")
  4212. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4213. anonymous_identity="ttls", password="password",
  4214. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  4215. dh_file="blob://dhparams")
  4216. def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev):
  4217. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams"""
  4218. params = int_eap_server_params()
  4219. params["dh_file"] = "auth_serv/dh2.conf"
  4220. hapd = hostapd.add_ap(apdev[0], params)
  4221. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4222. anonymous_identity="ttls", password="password",
  4223. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  4224. def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev):
  4225. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)"""
  4226. params = int_eap_server_params()
  4227. params["dh_file"] = "auth_serv/dsaparam.pem"
  4228. hapd = hostapd.add_ap(apdev[0], params)
  4229. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4230. anonymous_identity="ttls", password="password",
  4231. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  4232. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  4233. """EAP-TLS server and dhparams file not found"""
  4234. params = int_eap_server_params()
  4235. params["dh_file"] = "auth_serv/dh-no-such-file.conf"
  4236. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  4237. if "FAIL" not in hapd.request("ENABLE"):
  4238. raise Exception("Invalid configuration accepted")
  4239. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  4240. """EAP-TLS server and invalid dhparams file"""
  4241. params = int_eap_server_params()
  4242. params["dh_file"] = "auth_serv/ca.pem"
  4243. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  4244. if "FAIL" not in hapd.request("ENABLE"):
  4245. raise Exception("Invalid configuration accepted")
  4246. def test_ap_wpa2_eap_reauth(dev, apdev):
  4247. """WPA2-Enterprise and Authenticator forcing reauthentication"""
  4248. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4249. params['eap_reauth_period'] = '2'
  4250. hapd = hostapd.add_ap(apdev[0], params)
  4251. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  4252. password_hex="0123456789abcdef0123456789abcdef")
  4253. logger.info("Wait for reauthentication")
  4254. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  4255. if ev is None:
  4256. raise Exception("Timeout on reauthentication")
  4257. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4258. if ev is None:
  4259. raise Exception("Timeout on reauthentication")
  4260. for i in range(0, 20):
  4261. state = dev[0].get_status_field("wpa_state")
  4262. if state == "COMPLETED":
  4263. break
  4264. time.sleep(0.1)
  4265. if state != "COMPLETED":
  4266. raise Exception("Reauthentication did not complete")
  4267. def test_ap_wpa2_eap_request_identity_message(dev, apdev):
  4268. """Optional displayable message in EAP Request-Identity"""
  4269. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4270. params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com'
  4271. hapd = hostapd.add_ap(apdev[0], params)
  4272. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  4273. password_hex="0123456789abcdef0123456789abcdef")
  4274. def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev):
  4275. """WPA2-Enterprise using EAP-SIM/AKA and protected result indication"""
  4276. check_hlr_auc_gw_support()
  4277. params = int_eap_server_params()
  4278. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  4279. params['eap_sim_aka_result_ind'] = "1"
  4280. hapd = hostapd.add_ap(apdev[0], params)
  4281. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  4282. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4283. phase1="result_ind=1")
  4284. eap_reauth(dev[0], "SIM")
  4285. eap_connect(dev[1], hapd, "SIM", "1232010000000000",
  4286. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4287. dev[0].request("REMOVE_NETWORK all")
  4288. dev[1].request("REMOVE_NETWORK all")
  4289. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  4290. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  4291. phase1="result_ind=1")
  4292. eap_reauth(dev[0], "AKA")
  4293. eap_connect(dev[1], hapd, "AKA", "0232010000000000",
  4294. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  4295. dev[0].request("REMOVE_NETWORK all")
  4296. dev[1].request("REMOVE_NETWORK all")
  4297. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  4298. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  4299. phase1="result_ind=1")
  4300. eap_reauth(dev[0], "AKA'")
  4301. eap_connect(dev[1], hapd, "AKA'", "6555444333222111",
  4302. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  4303. def test_ap_wpa2_eap_sim_zero_db_timeout(dev, apdev):
  4304. """WPA2-Enterprise using EAP-SIM with zero database timeout"""
  4305. check_hlr_auc_gw_support()
  4306. params = int_eap_server_params()
  4307. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  4308. params['eap_sim_db_timeout'] = "0"
  4309. params['disable_pmksa_caching'] = '1'
  4310. hapd = hostapd.add_ap(apdev[0], params)
  4311. # Run multiple iterations to make it more likely to hit the case where the
  4312. # DB request times out and response is lost.
  4313. for i in range(20):
  4314. print i
  4315. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="SIM",
  4316. identity="1232010000000000",
  4317. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4318. wait_connect=False, scan_freq="2412")
  4319. ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED",
  4320. "CTRL-EVENT-DISCONNECTED" ],
  4321. timeout=15)
  4322. if ev is None:
  4323. raise Exception("No connection result")
  4324. dev[0].request("REMOVE_NETWORK all")
  4325. if "CTRL-EVENT-DISCONNECTED" in ev:
  4326. break
  4327. dev[0].wait_disconnected()
  4328. hapd.ping()
  4329. def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev):
  4330. """WPA2-Enterprise connection resulting in too many EAP roundtrips"""
  4331. skip_with_fips(dev[0])
  4332. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4333. hostapd.add_ap(apdev[0], params)
  4334. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4335. eap="TTLS", identity="mschap user",
  4336. wait_connect=False, scan_freq="2412", ieee80211w="1",
  4337. anonymous_identity="ttls", password="password",
  4338. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4339. fragment_size="8")
  4340. ev = dev[0].wait_event(["EAP: more than",
  4341. "CTRL-EVENT-EAP-SUCCESS"], timeout=20)
  4342. if ev is None or "EAP: more than" not in ev:
  4343. raise Exception("EAP roundtrip limit not reached")
  4344. def test_ap_wpa2_eap_expanded_nak(dev, apdev):
  4345. """WPA2-Enterprise connection with EAP resulting in expanded NAK"""
  4346. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4347. hostapd.add_ap(apdev[0], params)
  4348. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4349. eap="PSK", identity="vendor-test",
  4350. password_hex="ff23456789abcdef0123456789abcdef",
  4351. wait_connect=False)
  4352. found = False
  4353. for i in range(0, 5):
  4354. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=16)
  4355. if ev is None:
  4356. raise Exception("Association and EAP start timed out")
  4357. if "refuse proposed method" in ev:
  4358. found = True
  4359. break
  4360. if not found:
  4361. raise Exception("Unexpected EAP status: " + ev)
  4362. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4363. if ev is None:
  4364. raise Exception("EAP failure timed out")
  4365. def test_ap_wpa2_eap_sql(dev, apdev, params):
  4366. """WPA2-Enterprise connection using SQLite for user DB"""
  4367. skip_with_fips(dev[0])
  4368. try:
  4369. import sqlite3
  4370. except ImportError:
  4371. raise HwsimSkip("No sqlite3 module available")
  4372. dbfile = os.path.join(params['logdir'], "eap-user.db")
  4373. try:
  4374. os.remove(dbfile)
  4375. except:
  4376. pass
  4377. con = sqlite3.connect(dbfile)
  4378. with con:
  4379. cur = con.cursor()
  4380. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  4381. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  4382. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)")
  4383. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)")
  4384. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)")
  4385. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)")
  4386. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  4387. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  4388. try:
  4389. params = int_eap_server_params()
  4390. params["eap_user_file"] = "sqlite:" + dbfile
  4391. hapd = hostapd.add_ap(apdev[0], params)
  4392. eap_connect(dev[0], hapd, "TTLS", "user-mschapv2",
  4393. anonymous_identity="ttls", password="password",
  4394. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4395. dev[0].request("REMOVE_NETWORK all")
  4396. eap_connect(dev[1], hapd, "TTLS", "user-mschap",
  4397. anonymous_identity="ttls", password="password",
  4398. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  4399. dev[1].request("REMOVE_NETWORK all")
  4400. eap_connect(dev[0], hapd, "TTLS", "user-chap",
  4401. anonymous_identity="ttls", password="password",
  4402. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP")
  4403. eap_connect(dev[1], hapd, "TTLS", "user-pap",
  4404. anonymous_identity="ttls", password="password",
  4405. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4406. finally:
  4407. os.remove(dbfile)
  4408. def test_ap_wpa2_eap_non_ascii_identity(dev, apdev):
  4409. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  4410. params = int_eap_server_params()
  4411. hostapd.add_ap(apdev[0], params)
  4412. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4413. identity="\x80", password="password", wait_connect=False)
  4414. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4415. identity="a\x80", password="password", wait_connect=False)
  4416. for i in range(0, 2):
  4417. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  4418. if ev is None:
  4419. raise Exception("Association and EAP start timed out")
  4420. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  4421. if ev is None:
  4422. raise Exception("EAP method selection timed out")
  4423. def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev):
  4424. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  4425. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4426. hostapd.add_ap(apdev[0], params)
  4427. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4428. identity="\x80", password="password", wait_connect=False)
  4429. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4430. identity="a\x80", password="password", wait_connect=False)
  4431. for i in range(0, 2):
  4432. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  4433. if ev is None:
  4434. raise Exception("Association and EAP start timed out")
  4435. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  4436. if ev is None:
  4437. raise Exception("EAP method selection timed out")
  4438. def test_openssl_cipher_suite_config_wpas(dev, apdev):
  4439. """OpenSSL cipher suite configuration on wpa_supplicant"""
  4440. tls = dev[0].request("GET tls_library")
  4441. if not tls.startswith("OpenSSL"):
  4442. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  4443. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4444. hapd = hostapd.add_ap(apdev[0], params)
  4445. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4446. anonymous_identity="ttls", password="password",
  4447. openssl_ciphers="AES128",
  4448. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4449. eap_connect(dev[1], hapd, "TTLS", "pap user",
  4450. anonymous_identity="ttls", password="password",
  4451. openssl_ciphers="EXPORT",
  4452. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4453. expect_failure=True, maybe_local_error=True)
  4454. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4455. identity="pap user", anonymous_identity="ttls",
  4456. password="password",
  4457. openssl_ciphers="FOO",
  4458. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4459. wait_connect=False)
  4460. ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4461. if ev is None:
  4462. raise Exception("EAP failure after invalid openssl_ciphers not reported")
  4463. dev[2].request("DISCONNECT")
  4464. def test_openssl_cipher_suite_config_hapd(dev, apdev):
  4465. """OpenSSL cipher suite configuration on hostapd"""
  4466. tls = dev[0].request("GET tls_library")
  4467. if not tls.startswith("OpenSSL"):
  4468. raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls)
  4469. params = int_eap_server_params()
  4470. params['openssl_ciphers'] = "AES256"
  4471. hapd = hostapd.add_ap(apdev[0], params)
  4472. tls = hapd.request("GET tls_library")
  4473. if not tls.startswith("OpenSSL"):
  4474. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  4475. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4476. anonymous_identity="ttls", password="password",
  4477. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4478. eap_connect(dev[1], hapd, "TTLS", "pap user",
  4479. anonymous_identity="ttls", password="password",
  4480. openssl_ciphers="AES128",
  4481. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4482. expect_failure=True)
  4483. eap_connect(dev[2], hapd, "TTLS", "pap user",
  4484. anonymous_identity="ttls", password="password",
  4485. openssl_ciphers="HIGH:!ADH",
  4486. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4487. params['openssl_ciphers'] = "FOO"
  4488. hapd2 = hostapd.add_ap(apdev[1], params, no_enable=True)
  4489. if "FAIL" not in hapd2.request("ENABLE"):
  4490. raise Exception("Invalid openssl_ciphers value accepted")
  4491. def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
  4492. """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
  4493. p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4494. hapd = hostapd.add_ap(apdev[0], p)
  4495. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  4496. pid = find_wpas_process(dev[0])
  4497. id = eap_connect(dev[0], hapd, "TTLS", "pap-secret",
  4498. anonymous_identity="ttls", password=password,
  4499. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4500. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  4501. # event has been delivered, so verify that wpa_supplicant has returned to
  4502. # eloop before reading process memory.
  4503. time.sleep(1)
  4504. dev[0].ping()
  4505. buf = read_process_memory(pid, password)
  4506. dev[0].request("DISCONNECT")
  4507. dev[0].wait_disconnected()
  4508. dev[0].relog()
  4509. msk = None
  4510. emsk = None
  4511. pmk = None
  4512. ptk = None
  4513. gtk = None
  4514. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  4515. for l in f.readlines():
  4516. if "EAP-TTLS: Derived key - hexdump" in l:
  4517. val = l.strip().split(':')[3].replace(' ', '')
  4518. msk = binascii.unhexlify(val)
  4519. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  4520. val = l.strip().split(':')[3].replace(' ', '')
  4521. emsk = binascii.unhexlify(val)
  4522. if "WPA: PMK - hexdump" in l:
  4523. val = l.strip().split(':')[3].replace(' ', '')
  4524. pmk = binascii.unhexlify(val)
  4525. if "WPA: PTK - hexdump" in l:
  4526. val = l.strip().split(':')[3].replace(' ', '')
  4527. ptk = binascii.unhexlify(val)
  4528. if "WPA: Group Key - hexdump" in l:
  4529. val = l.strip().split(':')[3].replace(' ', '')
  4530. gtk = binascii.unhexlify(val)
  4531. if not msk or not emsk or not pmk or not ptk or not gtk:
  4532. raise Exception("Could not find keys from debug log")
  4533. if len(gtk) != 16:
  4534. raise Exception("Unexpected GTK length")
  4535. kck = ptk[0:16]
  4536. kek = ptk[16:32]
  4537. tk = ptk[32:48]
  4538. fname = os.path.join(params['logdir'],
  4539. 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-')
  4540. logger.info("Checking keys in memory while associated")
  4541. get_key_locations(buf, password, "Password")
  4542. get_key_locations(buf, pmk, "PMK")
  4543. get_key_locations(buf, msk, "MSK")
  4544. get_key_locations(buf, emsk, "EMSK")
  4545. if password not in buf:
  4546. raise HwsimSkip("Password not found while associated")
  4547. if pmk not in buf:
  4548. raise HwsimSkip("PMK not found while associated")
  4549. if kck not in buf:
  4550. raise Exception("KCK not found while associated")
  4551. if kek not in buf:
  4552. raise Exception("KEK not found while associated")
  4553. if tk in buf:
  4554. raise Exception("TK found from memory")
  4555. if gtk in buf:
  4556. get_key_locations(buf, gtk, "GTK")
  4557. raise Exception("GTK found from memory")
  4558. logger.info("Checking keys in memory after disassociation")
  4559. buf = read_process_memory(pid, password)
  4560. # Note: Password is still present in network configuration
  4561. # Note: PMK is in PMKSA cache and EAP fast re-auth data
  4562. get_key_locations(buf, password, "Password")
  4563. get_key_locations(buf, pmk, "PMK")
  4564. get_key_locations(buf, msk, "MSK")
  4565. get_key_locations(buf, emsk, "EMSK")
  4566. verify_not_present(buf, kck, fname, "KCK")
  4567. verify_not_present(buf, kek, fname, "KEK")
  4568. verify_not_present(buf, tk, fname, "TK")
  4569. verify_not_present(buf, gtk, fname, "GTK")
  4570. dev[0].request("PMKSA_FLUSH")
  4571. dev[0].set_network_quoted(id, "identity", "foo")
  4572. logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush")
  4573. buf = read_process_memory(pid, password)
  4574. get_key_locations(buf, password, "Password")
  4575. get_key_locations(buf, pmk, "PMK")
  4576. get_key_locations(buf, msk, "MSK")
  4577. get_key_locations(buf, emsk, "EMSK")
  4578. verify_not_present(buf, pmk, fname, "PMK")
  4579. dev[0].request("REMOVE_NETWORK all")
  4580. logger.info("Checking keys in memory after network profile removal")
  4581. buf = read_process_memory(pid, password)
  4582. get_key_locations(buf, password, "Password")
  4583. get_key_locations(buf, pmk, "PMK")
  4584. get_key_locations(buf, msk, "MSK")
  4585. get_key_locations(buf, emsk, "EMSK")
  4586. verify_not_present(buf, password, fname, "password")
  4587. verify_not_present(buf, pmk, fname, "PMK")
  4588. verify_not_present(buf, kck, fname, "KCK")
  4589. verify_not_present(buf, kek, fname, "KEK")
  4590. verify_not_present(buf, tk, fname, "TK")
  4591. verify_not_present(buf, gtk, fname, "GTK")
  4592. verify_not_present(buf, msk, fname, "MSK")
  4593. verify_not_present(buf, emsk, fname, "EMSK")
  4594. def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev):
  4595. """WPA2-Enterprise connection and unexpected WEP EAPOL-Key"""
  4596. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4597. hapd = hostapd.add_ap(apdev[0], params)
  4598. bssid = apdev[0]['bssid']
  4599. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4600. anonymous_identity="ttls", password="password",
  4601. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4602. # Send unexpected WEP EAPOL-Key; this gets dropped
  4603. res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
  4604. if "OK" not in res:
  4605. raise Exception("EAPOL_RX to wpa_supplicant failed")
  4606. def test_ap_wpa2_eap_in_bridge(dev, apdev):
  4607. """WPA2-EAP and wpas interface in a bridge"""
  4608. br_ifname='sta-br0'
  4609. ifname='wlan5'
  4610. try:
  4611. _test_ap_wpa2_eap_in_bridge(dev, apdev)
  4612. finally:
  4613. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  4614. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  4615. subprocess.call(['brctl', 'delbr', br_ifname])
  4616. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  4617. def _test_ap_wpa2_eap_in_bridge(dev, apdev):
  4618. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4619. hapd = hostapd.add_ap(apdev[0], params)
  4620. br_ifname='sta-br0'
  4621. ifname='wlan5'
  4622. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  4623. subprocess.call(['brctl', 'addbr', br_ifname])
  4624. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  4625. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  4626. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  4627. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  4628. wpas.interface_add(ifname, br_ifname=br_ifname)
  4629. wpas.dump_monitor()
  4630. id = eap_connect(wpas, hapd, "PAX", "pax.user@example.com",
  4631. password_hex="0123456789abcdef0123456789abcdef")
  4632. wpas.dump_monitor()
  4633. eap_reauth(wpas, "PAX")
  4634. wpas.dump_monitor()
  4635. # Try again as a regression test for packet socket workaround
  4636. eap_reauth(wpas, "PAX")
  4637. wpas.dump_monitor()
  4638. wpas.request("DISCONNECT")
  4639. wpas.wait_disconnected()
  4640. wpas.dump_monitor()
  4641. wpas.request("RECONNECT")
  4642. wpas.wait_connected()
  4643. wpas.dump_monitor()
  4644. def test_ap_wpa2_eap_session_ticket(dev, apdev):
  4645. """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled"""
  4646. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4647. hapd = hostapd.add_ap(apdev[0], params)
  4648. key_mgmt = hapd.get_config()['key_mgmt']
  4649. if key_mgmt.split(' ')[0] != "WPA-EAP":
  4650. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  4651. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4652. anonymous_identity="ttls", password="password",
  4653. ca_cert="auth_serv/ca.pem",
  4654. phase1="tls_disable_session_ticket=0", phase2="auth=PAP")
  4655. eap_reauth(dev[0], "TTLS")
  4656. def test_ap_wpa2_eap_no_workaround(dev, apdev):
  4657. """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0"""
  4658. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4659. hapd = hostapd.add_ap(apdev[0], params)
  4660. key_mgmt = hapd.get_config()['key_mgmt']
  4661. if key_mgmt.split(' ')[0] != "WPA-EAP":
  4662. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  4663. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4664. anonymous_identity="ttls", password="password",
  4665. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4666. phase2="auth=PAP")
  4667. eap_reauth(dev[0], "TTLS")
  4668. def test_ap_wpa2_eap_tls_check_crl(dev, apdev):
  4669. """EAP-TLS and server checking CRL"""
  4670. params = int_eap_server_params()
  4671. params['check_crl'] = '1'
  4672. hapd = hostapd.add_ap(apdev[0], params)
  4673. # check_crl=1 and no CRL available --> reject connection
  4674. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4675. client_cert="auth_serv/user.pem",
  4676. private_key="auth_serv/user.key", expect_failure=True)
  4677. dev[0].request("REMOVE_NETWORK all")
  4678. hapd.disable()
  4679. hapd.set("ca_cert", "auth_serv/ca-and-crl.pem")
  4680. hapd.enable()
  4681. # check_crl=1 and valid CRL --> accept
  4682. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4683. client_cert="auth_serv/user.pem",
  4684. private_key="auth_serv/user.key")
  4685. dev[0].request("REMOVE_NETWORK all")
  4686. hapd.disable()
  4687. hapd.set("check_crl", "2")
  4688. hapd.enable()
  4689. # check_crl=2 and valid CRL --> accept
  4690. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4691. client_cert="auth_serv/user.pem",
  4692. private_key="auth_serv/user.key")
  4693. dev[0].request("REMOVE_NETWORK all")
  4694. def test_ap_wpa2_eap_tls_oom(dev, apdev):
  4695. """EAP-TLS and OOM"""
  4696. check_subject_match_support(dev[0])
  4697. check_altsubject_match_support(dev[0])
  4698. check_domain_match(dev[0])
  4699. check_domain_match_full(dev[0])
  4700. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4701. hostapd.add_ap(apdev[0], params)
  4702. tests = [ (1, "tls_connection_set_subject_match"),
  4703. (2, "tls_connection_set_subject_match"),
  4704. (3, "tls_connection_set_subject_match"),
  4705. (4, "tls_connection_set_subject_match") ]
  4706. for count, func in tests:
  4707. with alloc_fail(dev[0], count, func):
  4708. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4709. identity="tls user", ca_cert="auth_serv/ca.pem",
  4710. client_cert="auth_serv/user.pem",
  4711. private_key="auth_serv/user.key",
  4712. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  4713. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/",
  4714. domain_suffix_match="server.w1.fi",
  4715. domain_match="server.w1.fi",
  4716. wait_connect=False, scan_freq="2412")
  4717. # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE
  4718. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5)
  4719. if ev is None:
  4720. raise Exception("No passphrase request")
  4721. dev[0].request("REMOVE_NETWORK all")
  4722. dev[0].wait_disconnected()
  4723. def test_ap_wpa2_eap_tls_macacl(dev, apdev):
  4724. """WPA2-Enterprise connection using MAC ACL"""
  4725. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4726. params["macaddr_acl"] = "2"
  4727. hapd = hostapd.add_ap(apdev[0], params)
  4728. eap_connect(dev[1], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4729. client_cert="auth_serv/user.pem",
  4730. private_key="auth_serv/user.key")
  4731. def test_ap_wpa2_eap_oom(dev, apdev):
  4732. """EAP server and OOM"""
  4733. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4734. hapd = hostapd.add_ap(apdev[0], params)
  4735. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  4736. with alloc_fail(hapd, 1, "eapol_auth_alloc"):
  4737. # The first attempt fails, but STA will send EAPOL-Start to retry and
  4738. # that succeeds.
  4739. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4740. identity="tls user", ca_cert="auth_serv/ca.pem",
  4741. client_cert="auth_serv/user.pem",
  4742. private_key="auth_serv/user.key",
  4743. scan_freq="2412")
  4744. def check_tls_ver(dev, hapd, phase1, expected):
  4745. eap_connect(dev, hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4746. client_cert="auth_serv/user.pem",
  4747. private_key="auth_serv/user.key",
  4748. phase1=phase1)
  4749. ver = dev.get_status_field("eap_tls_version")
  4750. if ver != expected:
  4751. raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver))
  4752. def test_ap_wpa2_eap_tls_versions(dev, apdev):
  4753. """EAP-TLS and TLS version configuration"""
  4754. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4755. hapd = hostapd.add_ap(apdev[0], params)
  4756. tls = dev[0].request("GET tls_library")
  4757. if tls.startswith("OpenSSL"):
  4758. if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  4759. check_tls_ver(dev[0], hapd,
  4760. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
  4761. "TLSv1.2")
  4762. elif tls.startswith("internal"):
  4763. check_tls_ver(dev[0], hapd,
  4764. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", "TLSv1.2")
  4765. check_tls_ver(dev[1], hapd,
  4766. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1")
  4767. check_tls_ver(dev[2], hapd,
  4768. "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1")
  4769. def test_rsn_ie_proto_eap_sta(dev, apdev):
  4770. """RSN element protocol testing for EAP cases on STA side"""
  4771. bssid = apdev[0]['bssid']
  4772. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4773. # This is the RSN element used normally by hostapd
  4774. params['own_ie_override'] = '30140100000fac040100000fac040100000fac010c00'
  4775. hapd = hostapd.add_ap(apdev[0], params)
  4776. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4777. identity="gpsk user",
  4778. password="abcdefghijklmnop0123456789abcdef",
  4779. scan_freq="2412")
  4780. tests = [ ('No RSN Capabilities field',
  4781. '30120100000fac040100000fac040100000fac01'),
  4782. ('No AKM Suite fields',
  4783. '300c0100000fac040100000fac04'),
  4784. ('No Pairwise Cipher Suite fields',
  4785. '30060100000fac04'),
  4786. ('No Group Data Cipher Suite field',
  4787. '30020100') ]
  4788. for txt,ie in tests:
  4789. dev[0].request("DISCONNECT")
  4790. dev[0].wait_disconnected()
  4791. logger.info(txt)
  4792. hapd.disable()
  4793. hapd.set('own_ie_override', ie)
  4794. hapd.enable()
  4795. dev[0].request("BSS_FLUSH 0")
  4796. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  4797. dev[0].select_network(id, freq=2412)
  4798. dev[0].wait_connected()
  4799. dev[0].request("DISCONNECT")
  4800. dev[0].wait_disconnected()
  4801. dev[0].flush_scan_cache()
  4802. def check_tls_session_resumption_capa(dev, hapd):
  4803. tls = hapd.request("GET tls_library")
  4804. if not tls.startswith("OpenSSL"):
  4805. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  4806. tls = dev.request("GET tls_library")
  4807. if not tls.startswith("OpenSSL"):
  4808. raise HwsimSkip("Session resumption not supported with this TLS library: " + tls)
  4809. def test_eap_ttls_pap_session_resumption(dev, apdev):
  4810. """EAP-TTLS/PAP session resumption"""
  4811. params = int_eap_server_params()
  4812. params['tls_session_lifetime'] = '60'
  4813. hapd = hostapd.add_ap(apdev[0], params)
  4814. check_tls_session_resumption_capa(dev[0], hapd)
  4815. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4816. anonymous_identity="ttls", password="password",
  4817. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4818. phase2="auth=PAP")
  4819. if dev[0].get_status_field("tls_session_reused") != '0':
  4820. raise Exception("Unexpected session resumption on the first connection")
  4821. dev[0].request("REAUTHENTICATE")
  4822. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4823. if ev is None:
  4824. raise Exception("EAP success timed out")
  4825. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4826. if ev is None:
  4827. raise Exception("Key handshake with the AP timed out")
  4828. if dev[0].get_status_field("tls_session_reused") != '1':
  4829. raise Exception("Session resumption not used on the second connection")
  4830. def test_eap_ttls_chap_session_resumption(dev, apdev):
  4831. """EAP-TTLS/CHAP session resumption"""
  4832. params = int_eap_server_params()
  4833. params['tls_session_lifetime'] = '60'
  4834. hapd = hostapd.add_ap(apdev[0], params)
  4835. check_tls_session_resumption_capa(dev[0], hapd)
  4836. eap_connect(dev[0], hapd, "TTLS", "chap user",
  4837. anonymous_identity="ttls", password="password",
  4838. ca_cert="auth_serv/ca.der", phase2="auth=CHAP")
  4839. if dev[0].get_status_field("tls_session_reused") != '0':
  4840. raise Exception("Unexpected session resumption on the first connection")
  4841. dev[0].request("REAUTHENTICATE")
  4842. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4843. if ev is None:
  4844. raise Exception("EAP success timed out")
  4845. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4846. if ev is None:
  4847. raise Exception("Key handshake with the AP timed out")
  4848. if dev[0].get_status_field("tls_session_reused") != '1':
  4849. raise Exception("Session resumption not used on the second connection")
  4850. def test_eap_ttls_mschap_session_resumption(dev, apdev):
  4851. """EAP-TTLS/MSCHAP session resumption"""
  4852. check_domain_suffix_match(dev[0])
  4853. params = int_eap_server_params()
  4854. params['tls_session_lifetime'] = '60'
  4855. hapd = hostapd.add_ap(apdev[0], params)
  4856. check_tls_session_resumption_capa(dev[0], hapd)
  4857. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  4858. anonymous_identity="ttls", password="password",
  4859. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4860. domain_suffix_match="server.w1.fi")
  4861. if dev[0].get_status_field("tls_session_reused") != '0':
  4862. raise Exception("Unexpected session resumption on the first connection")
  4863. dev[0].request("REAUTHENTICATE")
  4864. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4865. if ev is None:
  4866. raise Exception("EAP success timed out")
  4867. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4868. if ev is None:
  4869. raise Exception("Key handshake with the AP timed out")
  4870. if dev[0].get_status_field("tls_session_reused") != '1':
  4871. raise Exception("Session resumption not used on the second connection")
  4872. def test_eap_ttls_mschapv2_session_resumption(dev, apdev):
  4873. """EAP-TTLS/MSCHAPv2 session resumption"""
  4874. check_domain_suffix_match(dev[0])
  4875. check_eap_capa(dev[0], "MSCHAPV2")
  4876. params = int_eap_server_params()
  4877. params['tls_session_lifetime'] = '60'
  4878. hapd = hostapd.add_ap(apdev[0], params)
  4879. check_tls_session_resumption_capa(dev[0], hapd)
  4880. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  4881. anonymous_identity="ttls", password="password",
  4882. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4883. domain_suffix_match="server.w1.fi")
  4884. if dev[0].get_status_field("tls_session_reused") != '0':
  4885. raise Exception("Unexpected session resumption on the first connection")
  4886. dev[0].request("REAUTHENTICATE")
  4887. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4888. if ev is None:
  4889. raise Exception("EAP success timed out")
  4890. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4891. if ev is None:
  4892. raise Exception("Key handshake with the AP timed out")
  4893. if dev[0].get_status_field("tls_session_reused") != '1':
  4894. raise Exception("Session resumption not used on the second connection")
  4895. def test_eap_ttls_eap_gtc_session_resumption(dev, apdev):
  4896. """EAP-TTLS/EAP-GTC session resumption"""
  4897. params = int_eap_server_params()
  4898. params['tls_session_lifetime'] = '60'
  4899. hapd = hostapd.add_ap(apdev[0], params)
  4900. check_tls_session_resumption_capa(dev[0], hapd)
  4901. eap_connect(dev[0], hapd, "TTLS", "user",
  4902. anonymous_identity="ttls", password="password",
  4903. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC")
  4904. if dev[0].get_status_field("tls_session_reused") != '0':
  4905. raise Exception("Unexpected session resumption on the first connection")
  4906. dev[0].request("REAUTHENTICATE")
  4907. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4908. if ev is None:
  4909. raise Exception("EAP success timed out")
  4910. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4911. if ev is None:
  4912. raise Exception("Key handshake with the AP timed out")
  4913. if dev[0].get_status_field("tls_session_reused") != '1':
  4914. raise Exception("Session resumption not used on the second connection")
  4915. def test_eap_ttls_no_session_resumption(dev, apdev):
  4916. """EAP-TTLS session resumption disabled on server"""
  4917. params = int_eap_server_params()
  4918. params['tls_session_lifetime'] = '0'
  4919. hapd = hostapd.add_ap(apdev[0], params)
  4920. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4921. anonymous_identity="ttls", password="password",
  4922. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4923. phase2="auth=PAP")
  4924. if dev[0].get_status_field("tls_session_reused") != '0':
  4925. raise Exception("Unexpected session resumption on the first connection")
  4926. dev[0].request("REAUTHENTICATE")
  4927. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4928. if ev is None:
  4929. raise Exception("EAP success timed out")
  4930. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4931. if ev is None:
  4932. raise Exception("Key handshake with the AP timed out")
  4933. if dev[0].get_status_field("tls_session_reused") != '0':
  4934. raise Exception("Unexpected session resumption on the second connection")
  4935. def test_eap_peap_session_resumption(dev, apdev):
  4936. """EAP-PEAP session resumption"""
  4937. params = int_eap_server_params()
  4938. params['tls_session_lifetime'] = '60'
  4939. hapd = hostapd.add_ap(apdev[0], params)
  4940. check_tls_session_resumption_capa(dev[0], hapd)
  4941. eap_connect(dev[0], hapd, "PEAP", "user",
  4942. anonymous_identity="peap", password="password",
  4943. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4944. if dev[0].get_status_field("tls_session_reused") != '0':
  4945. raise Exception("Unexpected session resumption on the first connection")
  4946. dev[0].request("REAUTHENTICATE")
  4947. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4948. if ev is None:
  4949. raise Exception("EAP success timed out")
  4950. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4951. if ev is None:
  4952. raise Exception("Key handshake with the AP timed out")
  4953. if dev[0].get_status_field("tls_session_reused") != '1':
  4954. raise Exception("Session resumption not used on the second connection")
  4955. def test_eap_peap_session_resumption_crypto_binding(dev, apdev):
  4956. """EAP-PEAP session resumption with crypto binding"""
  4957. params = int_eap_server_params()
  4958. params['tls_session_lifetime'] = '60'
  4959. hapd = hostapd.add_ap(apdev[0], params)
  4960. check_tls_session_resumption_capa(dev[0], hapd)
  4961. eap_connect(dev[0], hapd, "PEAP", "user",
  4962. anonymous_identity="peap", password="password",
  4963. phase1="peapver=0 crypto_binding=2",
  4964. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4965. if dev[0].get_status_field("tls_session_reused") != '0':
  4966. raise Exception("Unexpected session resumption on the first connection")
  4967. dev[0].request("REAUTHENTICATE")
  4968. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4969. if ev is None:
  4970. raise Exception("EAP success timed out")
  4971. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4972. if ev is None:
  4973. raise Exception("Key handshake with the AP timed out")
  4974. if dev[0].get_status_field("tls_session_reused") != '1':
  4975. raise Exception("Session resumption not used on the second connection")
  4976. def test_eap_peap_no_session_resumption(dev, apdev):
  4977. """EAP-PEAP session resumption disabled on server"""
  4978. params = int_eap_server_params()
  4979. hapd = hostapd.add_ap(apdev[0], params)
  4980. eap_connect(dev[0], hapd, "PEAP", "user",
  4981. anonymous_identity="peap", password="password",
  4982. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4983. if dev[0].get_status_field("tls_session_reused") != '0':
  4984. raise Exception("Unexpected session resumption on the first connection")
  4985. dev[0].request("REAUTHENTICATE")
  4986. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4987. if ev is None:
  4988. raise Exception("EAP success timed out")
  4989. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4990. if ev is None:
  4991. raise Exception("Key handshake with the AP timed out")
  4992. if dev[0].get_status_field("tls_session_reused") != '0':
  4993. raise Exception("Unexpected session resumption on the second connection")
  4994. def test_eap_tls_session_resumption(dev, apdev):
  4995. """EAP-TLS session resumption"""
  4996. params = int_eap_server_params()
  4997. params['tls_session_lifetime'] = '60'
  4998. hapd = hostapd.add_ap(apdev[0], params)
  4999. check_tls_session_resumption_capa(dev[0], hapd)
  5000. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  5001. client_cert="auth_serv/user.pem",
  5002. private_key="auth_serv/user.key")
  5003. if dev[0].get_status_field("tls_session_reused") != '0':
  5004. raise Exception("Unexpected session resumption on the first connection")
  5005. dev[0].request("REAUTHENTICATE")
  5006. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5007. if ev is None:
  5008. raise Exception("EAP success timed out")
  5009. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  5010. if ev is None:
  5011. raise Exception("Key handshake with the AP timed out")
  5012. if dev[0].get_status_field("tls_session_reused") != '1':
  5013. raise Exception("Session resumption not used on the second connection")
  5014. dev[0].request("REAUTHENTICATE")
  5015. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5016. if ev is None:
  5017. raise Exception("EAP success timed out")
  5018. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  5019. if ev is None:
  5020. raise Exception("Key handshake with the AP timed out")
  5021. if dev[0].get_status_field("tls_session_reused") != '1':
  5022. raise Exception("Session resumption not used on the third connection")
  5023. def test_eap_tls_session_resumption_expiration(dev, apdev):
  5024. """EAP-TLS session resumption"""
  5025. params = int_eap_server_params()
  5026. params['tls_session_lifetime'] = '1'
  5027. hapd = hostapd.add_ap(apdev[0], params)
  5028. check_tls_session_resumption_capa(dev[0], hapd)
  5029. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  5030. client_cert="auth_serv/user.pem",
  5031. private_key="auth_serv/user.key")
  5032. if dev[0].get_status_field("tls_session_reused") != '0':
  5033. raise Exception("Unexpected session resumption on the first connection")
  5034. # Allow multiple attempts since OpenSSL may not expire the cached entry
  5035. # immediately.
  5036. for i in range(10):
  5037. time.sleep(1.2)
  5038. dev[0].request("REAUTHENTICATE")
  5039. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5040. if ev is None:
  5041. raise Exception("EAP success timed out")
  5042. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  5043. if ev is None:
  5044. raise Exception("Key handshake with the AP timed out")
  5045. if dev[0].get_status_field("tls_session_reused") == '0':
  5046. break
  5047. if dev[0].get_status_field("tls_session_reused") != '0':
  5048. raise Exception("Session resumption used after lifetime expiration")
  5049. def test_eap_tls_no_session_resumption(dev, apdev):
  5050. """EAP-TLS session resumption disabled on server"""
  5051. params = int_eap_server_params()
  5052. hapd = hostapd.add_ap(apdev[0], params)
  5053. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  5054. client_cert="auth_serv/user.pem",
  5055. private_key="auth_serv/user.key")
  5056. if dev[0].get_status_field("tls_session_reused") != '0':
  5057. raise Exception("Unexpected session resumption on the first connection")
  5058. dev[0].request("REAUTHENTICATE")
  5059. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5060. if ev is None:
  5061. raise Exception("EAP success timed out")
  5062. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  5063. if ev is None:
  5064. raise Exception("Key handshake with the AP timed out")
  5065. if dev[0].get_status_field("tls_session_reused") != '0':
  5066. raise Exception("Unexpected session resumption on the second connection")
  5067. def test_eap_tls_session_resumption_radius(dev, apdev):
  5068. """EAP-TLS session resumption (RADIUS)"""
  5069. params = { "ssid": "as", "beacon_int": "2000",
  5070. "radius_server_clients": "auth_serv/radius_clients.conf",
  5071. "radius_server_auth_port": '18128',
  5072. "eap_server": "1",
  5073. "eap_user_file": "auth_serv/eap_user.conf",
  5074. "ca_cert": "auth_serv/ca.pem",
  5075. "server_cert": "auth_serv/server.pem",
  5076. "private_key": "auth_serv/server.key",
  5077. "tls_session_lifetime": "60" }
  5078. authsrv = hostapd.add_ap(apdev[1], params)
  5079. check_tls_session_resumption_capa(dev[0], authsrv)
  5080. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5081. params['auth_server_port'] = "18128"
  5082. hapd = hostapd.add_ap(apdev[0], params)
  5083. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  5084. client_cert="auth_serv/user.pem",
  5085. private_key="auth_serv/user.key")
  5086. if dev[0].get_status_field("tls_session_reused") != '0':
  5087. raise Exception("Unexpected session resumption on the first connection")
  5088. dev[0].request("REAUTHENTICATE")
  5089. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5090. if ev is None:
  5091. raise Exception("EAP success timed out")
  5092. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  5093. if ev is None:
  5094. raise Exception("Key handshake with the AP timed out")
  5095. if dev[0].get_status_field("tls_session_reused") != '1':
  5096. raise Exception("Session resumption not used on the second connection")
  5097. def test_eap_tls_no_session_resumption_radius(dev, apdev):
  5098. """EAP-TLS session resumption disabled (RADIUS)"""
  5099. params = { "ssid": "as", "beacon_int": "2000",
  5100. "radius_server_clients": "auth_serv/radius_clients.conf",
  5101. "radius_server_auth_port": '18128',
  5102. "eap_server": "1",
  5103. "eap_user_file": "auth_serv/eap_user.conf",
  5104. "ca_cert": "auth_serv/ca.pem",
  5105. "server_cert": "auth_serv/server.pem",
  5106. "private_key": "auth_serv/server.key",
  5107. "tls_session_lifetime": "0" }
  5108. hostapd.add_ap(apdev[1], params)
  5109. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5110. params['auth_server_port'] = "18128"
  5111. hapd = hostapd.add_ap(apdev[0], params)
  5112. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  5113. client_cert="auth_serv/user.pem",
  5114. private_key="auth_serv/user.key")
  5115. if dev[0].get_status_field("tls_session_reused") != '0':
  5116. raise Exception("Unexpected session resumption on the first connection")
  5117. dev[0].request("REAUTHENTICATE")
  5118. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5119. if ev is None:
  5120. raise Exception("EAP success timed out")
  5121. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  5122. if ev is None:
  5123. raise Exception("Key handshake with the AP timed out")
  5124. if dev[0].get_status_field("tls_session_reused") != '0':
  5125. raise Exception("Unexpected session resumption on the second connection")
  5126. def test_eap_mschapv2_errors(dev, apdev):
  5127. """EAP-MSCHAPv2 error cases"""
  5128. check_eap_capa(dev[0], "MSCHAPV2")
  5129. check_eap_capa(dev[0], "FAST")
  5130. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  5131. hapd = hostapd.add_ap(apdev[0], params)
  5132. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  5133. identity="phase1-user", password="password",
  5134. scan_freq="2412")
  5135. dev[0].request("REMOVE_NETWORK all")
  5136. dev[0].wait_disconnected()
  5137. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  5138. (1, "nt_password_hash;mschapv2_derive_response"),
  5139. (1, "nt_password_hash;=mschapv2_derive_response"),
  5140. (1, "generate_nt_response;mschapv2_derive_response"),
  5141. (1, "generate_authenticator_response;mschapv2_derive_response"),
  5142. (1, "nt_password_hash;=mschapv2_derive_response"),
  5143. (1, "get_master_key;mschapv2_derive_response"),
  5144. (1, "os_get_random;eap_mschapv2_challenge_reply") ]
  5145. for count, func in tests:
  5146. with fail_test(dev[0], count, func):
  5147. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  5148. identity="phase1-user", password="password",
  5149. wait_connect=False, scan_freq="2412")
  5150. wait_fail_trigger(dev[0], "GET_FAIL")
  5151. dev[0].request("REMOVE_NETWORK all")
  5152. dev[0].wait_disconnected()
  5153. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  5154. (1, "hash_nt_password_hash;=mschapv2_derive_response"),
  5155. (1, "generate_nt_response_pwhash;mschapv2_derive_response"),
  5156. (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ]
  5157. for count, func in tests:
  5158. with fail_test(dev[0], count, func):
  5159. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  5160. identity="phase1-user",
  5161. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  5162. wait_connect=False, scan_freq="2412")
  5163. wait_fail_trigger(dev[0], "GET_FAIL")
  5164. dev[0].request("REMOVE_NETWORK all")
  5165. dev[0].wait_disconnected()
  5166. tests = [ (1, "eap_mschapv2_init"),
  5167. (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"),
  5168. (1, "eap_msg_alloc;eap_mschapv2_success"),
  5169. (1, "eap_mschapv2_getKey") ]
  5170. for count, func in tests:
  5171. with alloc_fail(dev[0], count, func):
  5172. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  5173. identity="phase1-user", password="password",
  5174. wait_connect=False, scan_freq="2412")
  5175. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5176. dev[0].request("REMOVE_NETWORK all")
  5177. dev[0].wait_disconnected()
  5178. tests = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ]
  5179. for count, func in tests:
  5180. with alloc_fail(dev[0], count, func):
  5181. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  5182. identity="phase1-user", password="wrong password",
  5183. wait_connect=False, scan_freq="2412")
  5184. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5185. dev[0].request("REMOVE_NETWORK all")
  5186. dev[0].wait_disconnected()
  5187. tests = [ (2, "eap_mschapv2_init"),
  5188. (3, "eap_mschapv2_init") ]
  5189. for count, func in tests:
  5190. with alloc_fail(dev[0], count, func):
  5191. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST",
  5192. anonymous_identity="FAST", identity="user",
  5193. password="password",
  5194. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  5195. phase1="fast_provisioning=1",
  5196. pac_file="blob://fast_pac",
  5197. wait_connect=False, scan_freq="2412")
  5198. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5199. dev[0].request("REMOVE_NETWORK all")
  5200. dev[0].wait_disconnected()
  5201. def test_eap_gpsk_errors(dev, apdev):
  5202. """EAP-GPSK error cases"""
  5203. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  5204. hapd = hostapd.add_ap(apdev[0], params)
  5205. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5206. identity="gpsk user",
  5207. password="abcdefghijklmnop0123456789abcdef",
  5208. scan_freq="2412")
  5209. dev[0].request("REMOVE_NETWORK all")
  5210. dev[0].wait_disconnected()
  5211. tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None),
  5212. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  5213. "cipher=1"),
  5214. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  5215. "cipher=2"),
  5216. (1, "eap_gpsk_derive_keys_helper", None),
  5217. (2, "eap_gpsk_derive_keys_helper", None),
  5218. (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  5219. "cipher=1"),
  5220. (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  5221. "cipher=2"),
  5222. (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None),
  5223. (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None),
  5224. (1, "eap_gpsk_derive_mid_helper", None) ]
  5225. for count, func, phase1 in tests:
  5226. with fail_test(dev[0], count, func):
  5227. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5228. identity="gpsk user",
  5229. password="abcdefghijklmnop0123456789abcdef",
  5230. phase1=phase1,
  5231. wait_connect=False, scan_freq="2412")
  5232. wait_fail_trigger(dev[0], "GET_FAIL")
  5233. dev[0].request("REMOVE_NETWORK all")
  5234. dev[0].wait_disconnected()
  5235. tests = [ (1, "eap_gpsk_init"),
  5236. (2, "eap_gpsk_init"),
  5237. (3, "eap_gpsk_init"),
  5238. (1, "eap_gpsk_process_id_server"),
  5239. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"),
  5240. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  5241. (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  5242. (1, "eap_gpsk_derive_keys"),
  5243. (1, "eap_gpsk_derive_keys_helper"),
  5244. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"),
  5245. (1, "eap_gpsk_getKey"),
  5246. (1, "eap_gpsk_get_emsk"),
  5247. (1, "eap_gpsk_get_session_id") ]
  5248. for count, func in tests:
  5249. with alloc_fail(dev[0], count, func):
  5250. dev[0].request("ERP_FLUSH")
  5251. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5252. identity="gpsk user@domain", erp="1",
  5253. password="abcdefghijklmnop0123456789abcdef",
  5254. wait_connect=False, scan_freq="2412")
  5255. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5256. dev[0].request("REMOVE_NETWORK all")
  5257. dev[0].wait_disconnected()
  5258. def test_ap_wpa2_eap_sim_db(dev, apdev, params):
  5259. """EAP-SIM DB error cases"""
  5260. sockpath = '/tmp/hlr_auc_gw.sock-test'
  5261. try:
  5262. os.remove(sockpath)
  5263. except:
  5264. pass
  5265. hparams = int_eap_server_params()
  5266. hparams['eap_sim_db'] = 'unix:' + sockpath
  5267. hapd = hostapd.add_ap(apdev[0], hparams)
  5268. # Initial test with hlr_auc_gw socket not available
  5269. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  5270. eap="SIM", identity="1232010000000000",
  5271. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  5272. scan_freq="2412", wait_connect=False)
  5273. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  5274. if ev is None:
  5275. raise Exception("EAP-Failure not reported")
  5276. dev[0].wait_disconnected()
  5277. dev[0].request("DISCONNECT")
  5278. # Test with invalid responses and response timeout
  5279. class test_handler(SocketServer.DatagramRequestHandler):
  5280. def handle(self):
  5281. data = self.request[0].strip()
  5282. socket = self.request[1]
  5283. logger.debug("Received hlr_auc_gw request: " + data)
  5284. # EAP-SIM DB: Failed to parse response string
  5285. socket.sendto("FOO", self.client_address)
  5286. # EAP-SIM DB: Failed to parse response string
  5287. socket.sendto("FOO 1", self.client_address)
  5288. # EAP-SIM DB: Unknown external response
  5289. socket.sendto("FOO 1 2", self.client_address)
  5290. logger.info("No proper response - wait for pending eap_sim_db request timeout")
  5291. server = SocketServer.UnixDatagramServer(sockpath, test_handler)
  5292. server.timeout = 1
  5293. dev[0].select_network(id)
  5294. server.handle_request()
  5295. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  5296. if ev is None:
  5297. raise Exception("EAP-Failure not reported")
  5298. dev[0].wait_disconnected()
  5299. dev[0].request("DISCONNECT")
  5300. # Test with a valid response
  5301. class test_handler2(SocketServer.DatagramRequestHandler):
  5302. def handle(self):
  5303. data = self.request[0].strip()
  5304. socket = self.request[1]
  5305. logger.debug("Received hlr_auc_gw request: " + data)
  5306. fname = os.path.join(params['logdir'],
  5307. 'hlr_auc_gw.milenage_db')
  5308. cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw',
  5309. '-m', fname, data],
  5310. stdout=subprocess.PIPE)
  5311. res = cmd.stdout.read().strip()
  5312. cmd.stdout.close()
  5313. logger.debug("hlr_auc_gw response: " + res)
  5314. socket.sendto(res, self.client_address)
  5315. server.RequestHandlerClass = test_handler2
  5316. dev[0].select_network(id)
  5317. server.handle_request()
  5318. dev[0].wait_connected()
  5319. dev[0].request("DISCONNECT")
  5320. dev[0].wait_disconnected()
  5321. def test_eap_tls_sha512(dev, apdev, params):
  5322. """EAP-TLS with SHA512 signature"""
  5323. params = int_eap_server_params()
  5324. params["ca_cert"] = "auth_serv/sha512-ca.pem"
  5325. params["server_cert"] = "auth_serv/sha512-server.pem"
  5326. params["private_key"] = "auth_serv/sha512-server.key"
  5327. hostapd.add_ap(apdev[0], params)
  5328. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5329. identity="tls user sha512",
  5330. ca_cert="auth_serv/sha512-ca.pem",
  5331. client_cert="auth_serv/sha512-user.pem",
  5332. private_key="auth_serv/sha512-user.key",
  5333. scan_freq="2412")
  5334. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5335. identity="tls user sha512",
  5336. ca_cert="auth_serv/sha512-ca.pem",
  5337. client_cert="auth_serv/sha384-user.pem",
  5338. private_key="auth_serv/sha384-user.key",
  5339. scan_freq="2412")
  5340. def test_eap_tls_sha384(dev, apdev, params):
  5341. """EAP-TLS with SHA384 signature"""
  5342. params = int_eap_server_params()
  5343. params["ca_cert"] = "auth_serv/sha512-ca.pem"
  5344. params["server_cert"] = "auth_serv/sha384-server.pem"
  5345. params["private_key"] = "auth_serv/sha384-server.key"
  5346. hostapd.add_ap(apdev[0], params)
  5347. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5348. identity="tls user sha512",
  5349. ca_cert="auth_serv/sha512-ca.pem",
  5350. client_cert="auth_serv/sha512-user.pem",
  5351. private_key="auth_serv/sha512-user.key",
  5352. scan_freq="2412")
  5353. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5354. identity="tls user sha512",
  5355. ca_cert="auth_serv/sha512-ca.pem",
  5356. client_cert="auth_serv/sha384-user.pem",
  5357. private_key="auth_serv/sha384-user.key",
  5358. scan_freq="2412")
  5359. def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
  5360. """WPA2-Enterprise AP and association request RSN IE differences"""
  5361. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5362. hostapd.add_ap(apdev[0], params)
  5363. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap-11w")
  5364. params["ieee80211w"] = "2"
  5365. hostapd.add_ap(apdev[1], params)
  5366. # Success cases with optional RSN IE fields removed one by one
  5367. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  5368. "30140100000fac040100000fac040100000fac010000"),
  5369. ("Extra PMKIDCount field in RSN IE",
  5370. "30160100000fac040100000fac040100000fac0100000000"),
  5371. ("Extra Group Management Cipher Suite in RSN IE",
  5372. "301a0100000fac040100000fac040100000fac0100000000000fac06"),
  5373. ("Extra undefined extension field in RSN IE",
  5374. "301c0100000fac040100000fac040100000fac0100000000000fac061122"),
  5375. ("RSN IE without RSN Capabilities",
  5376. "30120100000fac040100000fac040100000fac01"),
  5377. ("RSN IE without AKM", "300c0100000fac040100000fac04"),
  5378. ("RSN IE without pairwise", "30060100000fac04"),
  5379. ("RSN IE without group", "30020100") ]
  5380. for title, ie in tests:
  5381. logger.info(title)
  5382. set_test_assoc_ie(dev[0], ie)
  5383. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5384. identity="gpsk user",
  5385. password="abcdefghijklmnop0123456789abcdef",
  5386. scan_freq="2412")
  5387. dev[0].request("REMOVE_NETWORK all")
  5388. dev[0].wait_disconnected()
  5389. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  5390. "30140100000fac040100000fac040100000fac01cc00"),
  5391. ("Group management cipher included in assoc req RSN IE",
  5392. "301a0100000fac040100000fac040100000fac01cc000000000fac06") ]
  5393. for title, ie in tests:
  5394. logger.info(title)
  5395. set_test_assoc_ie(dev[0], ie)
  5396. dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1",
  5397. eap="GPSK", identity="gpsk user",
  5398. password="abcdefghijklmnop0123456789abcdef",
  5399. scan_freq="2412")
  5400. dev[0].request("REMOVE_NETWORK all")
  5401. dev[0].wait_disconnected()
  5402. tests = [ ("Invalid group cipher", "30060100000fac02", 41),
  5403. ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42) ]
  5404. for title, ie, status in tests:
  5405. logger.info(title)
  5406. set_test_assoc_ie(dev[0], ie)
  5407. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5408. identity="gpsk user",
  5409. password="abcdefghijklmnop0123456789abcdef",
  5410. scan_freq="2412", wait_connect=False)
  5411. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  5412. if ev is None:
  5413. raise Exception("Association rejection not reported")
  5414. if "status_code=" + str(status) not in ev:
  5415. raise Exception("Unexpected status code: " + ev)
  5416. dev[0].request("REMOVE_NETWORK all")
  5417. dev[0].dump_monitor()
  5418. tests = [ ("Management frame protection not enabled",
  5419. "30140100000fac040100000fac040100000fac010000", 31),
  5420. ("Unsupported management group cipher",
  5421. "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 31) ]
  5422. for title, ie, status in tests:
  5423. logger.info(title)
  5424. set_test_assoc_ie(dev[0], ie)
  5425. dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1",
  5426. eap="GPSK", identity="gpsk user",
  5427. password="abcdefghijklmnop0123456789abcdef",
  5428. scan_freq="2412", wait_connect=False)
  5429. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  5430. if ev is None:
  5431. raise Exception("Association rejection not reported")
  5432. if "status_code=" + str(status) not in ev:
  5433. raise Exception("Unexpected status code: " + ev)
  5434. dev[0].request("REMOVE_NETWORK all")
  5435. dev[0].dump_monitor()
  5436. def test_eap_tls_ext_cert_check(dev, apdev):
  5437. """EAP-TLS and external server certification validation"""
  5438. # With internal server certificate chain validation
  5439. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5440. identity="tls user",
  5441. ca_cert="auth_serv/ca.pem",
  5442. client_cert="auth_serv/user.pem",
  5443. private_key="auth_serv/user.key",
  5444. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5445. only_add_network=True)
  5446. run_ext_cert_check(dev, apdev, id)
  5447. def test_eap_ttls_ext_cert_check(dev, apdev):
  5448. """EAP-TTLS and external server certification validation"""
  5449. # Without internal server certificate chain validation
  5450. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  5451. identity="pap user", anonymous_identity="ttls",
  5452. password="password", phase2="auth=PAP",
  5453. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5454. only_add_network=True)
  5455. run_ext_cert_check(dev, apdev, id)
  5456. def test_eap_peap_ext_cert_check(dev, apdev):
  5457. """EAP-PEAP and external server certification validation"""
  5458. # With internal server certificate chain validation
  5459. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  5460. identity="user", anonymous_identity="peap",
  5461. ca_cert="auth_serv/ca.pem",
  5462. password="password", phase2="auth=MSCHAPV2",
  5463. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5464. only_add_network=True)
  5465. run_ext_cert_check(dev, apdev, id)
  5466. def test_eap_fast_ext_cert_check(dev, apdev):
  5467. """EAP-FAST and external server certification validation"""
  5468. check_eap_capa(dev[0], "FAST")
  5469. # With internal server certificate chain validation
  5470. dev[0].request("SET blob fast_pac_auth_ext ")
  5471. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  5472. identity="user", anonymous_identity="FAST",
  5473. ca_cert="auth_serv/ca.pem",
  5474. password="password", phase2="auth=GTC",
  5475. phase1="tls_ext_cert_check=1 fast_provisioning=2",
  5476. pac_file="blob://fast_pac_auth_ext",
  5477. scan_freq="2412",
  5478. only_add_network=True)
  5479. run_ext_cert_check(dev, apdev, id)
  5480. def run_ext_cert_check(dev, apdev, net_id):
  5481. check_ext_cert_check_support(dev[0])
  5482. if not openssl_imported:
  5483. raise HwsimSkip("OpenSSL python method not available")
  5484. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5485. hapd = hostapd.add_ap(apdev[0], params)
  5486. dev[0].select_network(net_id)
  5487. certs = {}
  5488. while True:
  5489. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT",
  5490. "CTRL-REQ-EXT_CERT_CHECK",
  5491. "CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5492. if ev is None:
  5493. raise Exception("No peer server certificate event seen")
  5494. if "CTRL-EVENT-EAP-PEER-CERT" in ev:
  5495. depth = None
  5496. cert = None
  5497. vals = ev.split(' ')
  5498. for v in vals:
  5499. if v.startswith("depth="):
  5500. depth = int(v.split('=')[1])
  5501. elif v.startswith("cert="):
  5502. cert = v.split('=')[1]
  5503. if depth is not None and cert:
  5504. certs[depth] = binascii.unhexlify(cert)
  5505. elif "CTRL-EVENT-EAP-SUCCESS" in ev:
  5506. raise Exception("Unexpected EAP-Success")
  5507. elif "CTRL-REQ-EXT_CERT_CHECK" in ev:
  5508. id = ev.split(':')[0].split('-')[-1]
  5509. break
  5510. if 0 not in certs:
  5511. raise Exception("Server certificate not received")
  5512. if 1 not in certs:
  5513. raise Exception("Server certificate issuer not received")
  5514. cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
  5515. certs[0])
  5516. cn = cert.get_subject().commonName
  5517. logger.info("Server certificate CN=" + cn)
  5518. issuer = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
  5519. certs[1])
  5520. icn = issuer.get_subject().commonName
  5521. logger.info("Issuer certificate CN=" + icn)
  5522. if cn != "server.w1.fi":
  5523. raise Exception("Unexpected server certificate CN: " + cn)
  5524. if icn != "Root CA":
  5525. raise Exception("Unexpected server certificate issuer CN: " + icn)
  5526. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1)
  5527. if ev:
  5528. raise Exception("Unexpected EAP-Success before external check result indication")
  5529. dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":good")
  5530. dev[0].wait_connected()
  5531. dev[0].request("DISCONNECT")
  5532. dev[0].wait_disconnected()
  5533. if "FAIL" in dev[0].request("PMKSA_FLUSH"):
  5534. raise Exception("PMKSA_FLUSH failed")
  5535. dev[0].request("SET blob fast_pac_auth_ext ")
  5536. dev[0].request("RECONNECT")
  5537. ev = dev[0].wait_event(["CTRL-REQ-EXT_CERT_CHECK"], timeout=10)
  5538. if ev is None:
  5539. raise Exception("No peer server certificate event seen (2)")
  5540. id = ev.split(':')[0].split('-')[-1]
  5541. dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":bad")
  5542. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  5543. if ev is None:
  5544. raise Exception("EAP-Failure not reported")
  5545. dev[0].request("REMOVE_NETWORK all")
  5546. dev[0].wait_disconnected()
  5547. def test_eap_tls_errors(dev, apdev):
  5548. """EAP-TLS error cases"""
  5549. params = int_eap_server_params()
  5550. params['fragment_size'] = '100'
  5551. hostapd.add_ap(apdev[0], params)
  5552. with alloc_fail(dev[0], 1,
  5553. "eap_peer_tls_reassemble_fragment"):
  5554. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5555. identity="tls user", ca_cert="auth_serv/ca.pem",
  5556. client_cert="auth_serv/user.pem",
  5557. private_key="auth_serv/user.key",
  5558. wait_connect=False, scan_freq="2412")
  5559. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5560. dev[0].request("REMOVE_NETWORK all")
  5561. dev[0].wait_disconnected()
  5562. with alloc_fail(dev[0], 1, "eap_tls_init"):
  5563. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5564. identity="tls user", ca_cert="auth_serv/ca.pem",
  5565. client_cert="auth_serv/user.pem",
  5566. private_key="auth_serv/user.key",
  5567. wait_connect=False, scan_freq="2412")
  5568. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5569. dev[0].request("REMOVE_NETWORK all")
  5570. dev[0].wait_disconnected()
  5571. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init"):
  5572. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5573. identity="tls user", ca_cert="auth_serv/ca.pem",
  5574. client_cert="auth_serv/user.pem",
  5575. private_key="auth_serv/user.key",
  5576. engine="1",
  5577. wait_connect=False, scan_freq="2412")
  5578. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5579. ev = dev[0].wait_event(["CTRL-REQ-PIN"], timeout=5)
  5580. if ev is None:
  5581. raise Exception("No CTRL-REQ-PIN seen")
  5582. dev[0].request("REMOVE_NETWORK all")
  5583. dev[0].wait_disconnected()
  5584. tests = [ "eap_peer_tls_derive_key;eap_tls_success",
  5585. "eap_peer_tls_derive_session_id;eap_tls_success",
  5586. "eap_tls_getKey",
  5587. "eap_tls_get_emsk",
  5588. "eap_tls_get_session_id" ]
  5589. for func in tests:
  5590. with alloc_fail(dev[0], 1, func):
  5591. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5592. identity="tls user@domain",
  5593. ca_cert="auth_serv/ca.pem",
  5594. client_cert="auth_serv/user.pem",
  5595. private_key="auth_serv/user.key",
  5596. erp="1",
  5597. wait_connect=False, scan_freq="2412")
  5598. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5599. dev[0].request("REMOVE_NETWORK all")
  5600. dev[0].wait_disconnected()
  5601. with alloc_fail(dev[0], 1, "eap_unauth_tls_init"):
  5602. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS",
  5603. identity="unauth-tls", ca_cert="auth_serv/ca.pem",
  5604. wait_connect=False, scan_freq="2412")
  5605. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5606. dev[0].request("REMOVE_NETWORK all")
  5607. dev[0].wait_disconnected()
  5608. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_unauth_tls_init"):
  5609. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS",
  5610. identity="unauth-tls", ca_cert="auth_serv/ca.pem",
  5611. wait_connect=False, scan_freq="2412")
  5612. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5613. dev[0].request("REMOVE_NETWORK all")
  5614. dev[0].wait_disconnected()
  5615. with alloc_fail(dev[0], 1, "eap_wfa_unauth_tls_init"):
  5616. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  5617. eap="WFA-UNAUTH-TLS",
  5618. identity="osen@example.com", ca_cert="auth_serv/ca.pem",
  5619. wait_connect=False, scan_freq="2412")
  5620. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5621. dev[0].request("REMOVE_NETWORK all")
  5622. dev[0].wait_disconnected()
  5623. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_wfa_unauth_tls_init"):
  5624. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  5625. eap="WFA-UNAUTH-TLS",
  5626. identity="osen@example.com", ca_cert="auth_serv/ca.pem",
  5627. wait_connect=False, scan_freq="2412")
  5628. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5629. dev[0].request("REMOVE_NETWORK all")
  5630. dev[0].wait_disconnected()
  5631. def test_ap_wpa2_eap_status(dev, apdev):
  5632. """EAP state machine status information"""
  5633. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5634. hostapd.add_ap(apdev[0], params)
  5635. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  5636. identity="cert user",
  5637. ca_cert="auth_serv/ca.pem", phase2="auth=TLS",
  5638. ca_cert2="auth_serv/ca.pem",
  5639. client_cert2="auth_serv/user.pem",
  5640. private_key2="auth_serv/user.key",
  5641. scan_freq="2412", wait_connect=False)
  5642. success = False
  5643. states = []
  5644. method_states = []
  5645. decisions = []
  5646. req_methods = []
  5647. selected_methods = []
  5648. for i in range(100000):
  5649. s = dev[0].get_status(extra="VERBOSE")
  5650. if 'EAP state' in s:
  5651. state = s['EAP state']
  5652. if state:
  5653. if state not in states:
  5654. states.append(state)
  5655. if state == "SUCCESS":
  5656. success = True
  5657. break
  5658. if 'methodState' in s:
  5659. val = s['methodState']
  5660. if val not in method_states:
  5661. method_states.append(val)
  5662. if 'decision' in s:
  5663. val = s['decision']
  5664. if val not in decisions:
  5665. decisions.append(val)
  5666. if 'reqMethod' in s:
  5667. val = s['reqMethod']
  5668. if val not in req_methods:
  5669. req_methods.append(val)
  5670. if 'selectedMethod' in s:
  5671. val = s['selectedMethod']
  5672. if val not in selected_methods:
  5673. selected_methods.append(val)
  5674. logger.info("Iterations: %d" % i)
  5675. logger.info("EAP states: " + str(states))
  5676. logger.info("methodStates: " + str(method_states))
  5677. logger.info("decisions: " + str(decisions))
  5678. logger.info("reqMethods: " + str(req_methods))
  5679. logger.info("selectedMethods: " + str(selected_methods))
  5680. if not success:
  5681. raise Exception("EAP did not succeed")
  5682. dev[0].wait_connected()
  5683. dev[0].request("REMOVE_NETWORK all")
  5684. dev[0].wait_disconnected()
  5685. def test_ap_wpa2_eap_gpsk_ptk_rekey_ap(dev, apdev):
  5686. """WPA2-Enterprise with EAP-GPSK and PTK rekey enforced by AP"""
  5687. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5688. params['wpa_ptk_rekey'] = '2'
  5689. hapd = hostapd.add_ap(apdev[0], params)
  5690. id = eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  5691. password="abcdefghijklmnop0123456789abcdef")
  5692. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  5693. if ev is None:
  5694. raise Exception("PTK rekey timed out")
  5695. hwsim_utils.test_connectivity(dev[0], hapd)
  5696. def test_ap_wpa2_eap_wildcard_ssid(dev, apdev):
  5697. """WPA2-Enterprise connection using EAP-GPSK and wildcard SSID"""
  5698. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5699. hapd = hostapd.add_ap(apdev[0], params)
  5700. dev[0].connect(bssid=apdev[0]['bssid'], key_mgmt="WPA-EAP", eap="GPSK",
  5701. identity="gpsk user",
  5702. password="abcdefghijklmnop0123456789abcdef",
  5703. scan_freq="2412")