test_ap_eap.py 287 KB

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