123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325 |
- # EAP protocol tests
- # Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
- #
- # This software may be distributed under the terms of the BSD license.
- # See README for more details.
- import binascii
- import hashlib
- import hmac
- import logging
- logger = logging.getLogger()
- import os
- import select
- import struct
- import threading
- import time
- import hostapd
- from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
- from test_ap_eap import check_eap_capa, check_hlr_auc_gw_support, int_eap_server_params
- from test_erp import check_erp_capa
- try:
- import OpenSSL
- openssl_imported = True
- except ImportError:
- openssl_imported = False
- EAP_CODE_REQUEST = 1
- EAP_CODE_RESPONSE = 2
- EAP_CODE_SUCCESS = 3
- EAP_CODE_FAILURE = 4
- EAP_CODE_INITIATE = 5
- EAP_CODE_FINISH = 6
- EAP_TYPE_IDENTITY = 1
- EAP_TYPE_NOTIFICATION = 2
- EAP_TYPE_NAK = 3
- EAP_TYPE_MD5 = 4
- EAP_TYPE_OTP = 5
- EAP_TYPE_GTC = 6
- EAP_TYPE_TLS = 13
- EAP_TYPE_LEAP = 17
- EAP_TYPE_SIM = 18
- EAP_TYPE_TTLS = 21
- EAP_TYPE_AKA = 23
- EAP_TYPE_PEAP = 25
- EAP_TYPE_MSCHAPV2 = 26
- EAP_TYPE_TLV = 33
- EAP_TYPE_TNC = 38
- EAP_TYPE_FAST = 43
- EAP_TYPE_PAX = 46
- EAP_TYPE_PSK = 47
- EAP_TYPE_SAKE = 48
- EAP_TYPE_IKEV2 = 49
- EAP_TYPE_AKA_PRIME = 50
- EAP_TYPE_GPSK = 51
- EAP_TYPE_PWD = 52
- EAP_TYPE_EKE = 53
- EAP_TYPE_EXPANDED = 254
- # Type field in EAP-Initiate and EAP-Finish messages
- EAP_ERP_TYPE_REAUTH_START = 1
- EAP_ERP_TYPE_REAUTH = 2
- EAP_ERP_TLV_KEYNAME_NAI = 1
- EAP_ERP_TV_RRK_LIFETIME = 2
- EAP_ERP_TV_RMSK_LIFETIME = 3
- EAP_ERP_TLV_DOMAIN_NAME = 4
- EAP_ERP_TLV_CRYPTOSUITES = 5
- EAP_ERP_TLV_AUTHORIZATION_INDICATION = 6
- EAP_ERP_TLV_CALLED_STATION_ID = 128
- EAP_ERP_TLV_CALLING_STATION_ID = 129
- EAP_ERP_TLV_NAS_IDENTIFIER = 130
- EAP_ERP_TLV_NAS_IP_ADDRESS = 131
- EAP_ERP_TLV_NAS_IPV6_ADDRESS = 132
- def run_pyrad_server(srv, t_stop, eap_handler):
- srv.RunWithStop(t_stop, eap_handler)
- def start_radius_server(eap_handler):
- try:
- import pyrad.server
- import pyrad.packet
- import pyrad.dictionary
- except ImportError:
- raise HwsimSkip("No pyrad modules available")
- class TestServer(pyrad.server.Server):
- def _HandleAuthPacket(self, pkt):
- pyrad.server.Server._HandleAuthPacket(self, pkt)
- eap = ""
- for p in pkt[79]:
- eap += p
- eap_req = self.eap_handler(self.ctx, eap)
- reply = self.CreateReplyPacket(pkt)
- if eap_req:
- while True:
- if len(eap_req) > 253:
- reply.AddAttribute("EAP-Message", eap_req[0:253])
- eap_req = eap_req[253:]
- else:
- reply.AddAttribute("EAP-Message", eap_req)
- break
- else:
- logger.info("No EAP request available")
- reply.code = pyrad.packet.AccessChallenge
- hmac_obj = hmac.new(reply.secret)
- hmac_obj.update(struct.pack("B", reply.code))
- hmac_obj.update(struct.pack("B", reply.id))
- # reply attributes
- reply.AddAttribute("Message-Authenticator",
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
- attrs = reply._PktEncodeAttributes()
- # Length
- flen = 4 + 16 + len(attrs)
- hmac_obj.update(struct.pack(">H", flen))
- hmac_obj.update(pkt.authenticator)
- hmac_obj.update(attrs)
- del reply[80]
- reply.AddAttribute("Message-Authenticator", hmac_obj.digest())
- self.SendReplyPacket(pkt.fd, reply)
- def RunWithStop(self, t_stop, eap_handler):
- self._poll = select.poll()
- self._fdmap = {}
- self._PrepareSockets()
- self.t_stop = t_stop
- self.eap_handler = eap_handler
- self.ctx = {}
- while not t_stop.is_set():
- for (fd, event) in self._poll.poll(200):
- if event == select.POLLIN:
- try:
- fdo = self._fdmap[fd]
- self._ProcessInput(fdo)
- except pyrad.server.ServerPacketError as err:
- logger.info("pyrad server dropping packet: " + str(err))
- except pyrad.packet.PacketError as err:
- logger.info("pyrad server received invalid packet: " + str(err))
- else:
- logger.error("Unexpected event in pyrad server main loop")
- srv = TestServer(dict=pyrad.dictionary.Dictionary("dictionary.radius"),
- authport=18138, acctport=18139)
- srv.hosts["127.0.0.1"] = pyrad.server.RemoteHost("127.0.0.1",
- "radius",
- "localhost")
- srv.BindToAddress("")
- t_stop = threading.Event()
- t = threading.Thread(target=run_pyrad_server, args=(srv, t_stop, eap_handler))
- t.start()
- return { 'srv': srv, 'stop': t_stop, 'thread': t }
- def stop_radius_server(srv):
- srv['stop'].set()
- srv['thread'].join()
- def start_ap(ap):
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- params['auth_server_port'] = "18138"
- hapd = hostapd.add_ap(ap, params)
- return hapd
- def test_eap_proto(dev, apdev):
- """EAP protocol tests"""
- check_eap_capa(dev[0], "MD5")
- def eap_handler(ctx, req):
- logger.info("eap_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success - id off by 2")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] + 1, 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success - id off by 3")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] + 2, 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('A'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 1, 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('B'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 1, 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('C'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('D'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 1, 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('E'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request (same id)")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'] - 1,
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('F'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 2, 4)
- return None
- srv = start_radius_server(eap_handler)
- try:
- hapd = start_ap(apdev[0])
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=1)
- if ev is not None:
- raise Exception("Unexpected EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP notification")
- if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION A":
- raise Exception("Unexpected notification contents: " + ev)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP notification")
- if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION B":
- raise Exception("Unexpected notification contents: " + ev)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP notification")
- if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION C":
- raise Exception("Unexpected notification contents: " + ev)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP notification")
- if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION D":
- raise Exception("Unexpected notification contents: " + ev)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP notification")
- if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION E":
- raise Exception("Unexpected notification contents: " + ev)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP notification")
- if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION F":
- raise Exception("Unexpected notification contents: " + ev)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- finally:
- stop_radius_server(srv)
- def test_eap_proto_notification_errors(dev, apdev):
- """EAP Notification errors"""
- def eap_handler(ctx, req):
- logger.info("eap_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('A'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Notification/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_NOTIFICATION,
- ord('A'))
- return None
- srv = start_radius_server(eap_handler)
- try:
- hapd = start_ap(apdev[0])
- with alloc_fail(dev[0], 1, "eap_sm_processNotify"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "eap_msg_alloc;sm_EAP_NOTIFICATION_Enter"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- finally:
- stop_radius_server(srv)
- EAP_SAKE_VERSION = 2
- EAP_SAKE_SUBTYPE_CHALLENGE = 1
- EAP_SAKE_SUBTYPE_CONFIRM = 2
- EAP_SAKE_SUBTYPE_AUTH_REJECT = 3
- EAP_SAKE_SUBTYPE_IDENTITY = 4
- EAP_SAKE_AT_RAND_S = 1
- EAP_SAKE_AT_RAND_P = 2
- EAP_SAKE_AT_MIC_S = 3
- EAP_SAKE_AT_MIC_P = 4
- EAP_SAKE_AT_SERVERID = 5
- EAP_SAKE_AT_PEERID = 6
- EAP_SAKE_AT_SPI_S = 7
- EAP_SAKE_AT_SPI_P = 8
- EAP_SAKE_AT_ANY_ID_REQ = 9
- EAP_SAKE_AT_PERM_ID_REQ = 10
- EAP_SAKE_AT_ENCR_DATA = 128
- EAP_SAKE_AT_IV = 129
- EAP_SAKE_AT_PADDING = 130
- EAP_SAKE_AT_NEXT_TMPID = 131
- EAP_SAKE_AT_MSK_LIFE = 132
- def test_eap_proto_sake(dev, apdev):
- """EAP-SAKE protocol tests"""
- global eap_proto_sake_test_done
- eap_proto_sake_test_done = False
- def sake_challenge(ctx):
- logger.info("Test: Challenge subtype")
- return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 18,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE,
- EAP_SAKE_AT_RAND_S, 18, 0, 0, 0, 0)
- def sake_handler(ctx, req):
- logger.info("sake_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'], 4 + 1,
- EAP_TYPE_SAKE)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype without any attributes")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype")
- return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
- EAP_SAKE_AT_ANY_ID_REQ, 4, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype (different session id)")
- return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 1, EAP_SAKE_SUBTYPE_IDENTITY,
- EAP_SAKE_AT_PERM_ID_REQ, 4, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype with too short attribute")
- return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 2,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
- EAP_SAKE_AT_ANY_ID_REQ, 2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype with truncated attribute")
- return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 2,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
- EAP_SAKE_AT_ANY_ID_REQ, 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype with too short attribute header")
- payload = struct.pack("B", EAP_SAKE_AT_ANY_ID_REQ)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype with AT_IV but not AT_ENCR_DATA")
- payload = struct.pack("BB", EAP_SAKE_AT_IV, 2)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype with skippable and non-skippable unknown attribute")
- payload = struct.pack("BBBB", 255, 2, 127, 2)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype: AT_RAND_P with invalid payload length")
- payload = struct.pack("BB", EAP_SAKE_AT_RAND_P, 2)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype: AT_MIC_P with invalid payload length")
- payload = struct.pack("BB", EAP_SAKE_AT_MIC_P, 2)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype: AT_PERM_ID_REQ with invalid payload length")
- payload = struct.pack("BBBBBBBBBBBBBB",
- EAP_SAKE_AT_SPI_S, 2,
- EAP_SAKE_AT_SPI_P, 2,
- EAP_SAKE_AT_ENCR_DATA, 2,
- EAP_SAKE_AT_NEXT_TMPID, 2,
- EAP_SAKE_AT_PERM_ID_REQ, 4, 0, 0,
- EAP_SAKE_AT_PERM_ID_REQ, 2)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype: AT_PADDING")
- payload = struct.pack("BBBBBB",
- EAP_SAKE_AT_PADDING, 3, 0,
- EAP_SAKE_AT_PADDING, 3, 1)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype: AT_MSK_LIFE")
- payload = struct.pack(">BBLBBH",
- EAP_SAKE_AT_MSK_LIFE, 6, 0,
- EAP_SAKE_AT_MSK_LIFE, 4, 0)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype with invalid attribute length")
- payload = struct.pack("BB", EAP_SAKE_AT_ANY_ID_REQ, 0)
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + len(payload),
- EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
- EAP_SAKE_SUBTYPE_IDENTITY) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unknown subtype")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, 123)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge subtype without any attributes")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge subtype with too short AT_RAND_S")
- return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 2,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE,
- EAP_SAKE_AT_RAND_S, 2)
- idx += 1
- if ctx['num'] == idx:
- return sake_challenge(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Identity subtype")
- return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
- EAP_SAKE_AT_ANY_ID_REQ, 4, 0)
- idx += 1
- if ctx['num'] == idx:
- return sake_challenge(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Challenge subtype")
- return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 18,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE,
- EAP_SAKE_AT_RAND_S, 18, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- return sake_challenge(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Confirm subtype without any attributes")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM)
- idx += 1
- if ctx['num'] == idx:
- return sake_challenge(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Confirm subtype with too short AT_MIC_S")
- return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 2,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM,
- EAP_SAKE_AT_MIC_S, 2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Confirm subtype")
- return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 18,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM,
- EAP_SAKE_AT_MIC_S, 18, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- return sake_challenge(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Confirm subtype with incorrect AT_MIC_S")
- return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 18,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM,
- EAP_SAKE_AT_MIC_S, 18, 0, 0, 0, 0)
- global eap_proto_sake_test_done
- if eap_proto_sake_test_done:
- return sake_challenge(ctx)
- logger.info("No more test responses available - test case completed")
- eap_proto_sake_test_done = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(sake_handler)
- try:
- hapd = start_ap(apdev[0])
- while not eap_proto_sake_test_done:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SAKE", identity="sake user",
- password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- logger.info("Too short password")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SAKE", identity="sake user",
- password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- finally:
- stop_radius_server(srv)
- def test_eap_proto_sake_errors(dev, apdev):
- """EAP-SAKE local error cases"""
- check_eap_capa(dev[0], "SAKE")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 3):
- with alloc_fail(dev[0], i, "eap_sake_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SAKE", identity="sake user",
- password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ ( 1, "eap_msg_alloc;eap_sake_build_msg;eap_sake_process_challenge" ),
- ( 1, "=eap_sake_process_challenge" ),
- ( 1, "eap_sake_compute_mic;eap_sake_process_challenge" ),
- ( 1, "eap_sake_build_msg;eap_sake_process_confirm" ),
- ( 1, "eap_sake_compute_mic;eap_sake_process_confirm" ),
- ( 2, "eap_sake_compute_mic;eap_sake_process_confirm" ),
- ( 1, "eap_sake_getKey" ),
- ( 1, "eap_sake_get_emsk" ),
- ( 1, "eap_sake_get_session_id" ) ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SAKE", identity="sake user@domain",
- password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
- erp="1",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "os_get_random;eap_sake_process_challenge"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SAKE", identity="sake user",
- password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_proto_sake_errors2(dev, apdev):
- """EAP-SAKE protocol tests (2)"""
- def sake_handler(ctx, req):
- logger.info("sake_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity subtype")
- return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SAKE,
- EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
- EAP_SAKE_AT_ANY_ID_REQ, 4, 0)
- srv = start_radius_server(sake_handler)
- try:
- hapd = start_ap(apdev[0])
- with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_sake_build_msg;eap_sake_process_identity"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SAKE", identity="sake user",
- password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_leap(dev, apdev):
- """EAP-LEAP protocol tests"""
- check_eap_capa(dev[0], "LEAP")
- def leap_handler(ctx, req):
- logger.info("leap_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- if ctx['num'] == 1:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_LEAP)
- if ctx['num'] == 2:
- logger.info("Test: Unexpected version")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_LEAP,
- 0, 0, 0)
- if ctx['num'] == 3:
- logger.info("Test: Invalid challenge length")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_LEAP,
- 1, 0, 0)
- if ctx['num'] == 4:
- logger.info("Test: Truncated challenge")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_LEAP,
- 1, 0, 8)
- if ctx['num'] == 5:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 6:
- logger.info("Test: Missing payload in Response")
- return struct.pack(">BBHB", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1,
- EAP_TYPE_LEAP)
- if ctx['num'] == 7:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 8:
- logger.info("Test: Unexpected version in Response")
- return struct.pack(">BBHBBBB", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_LEAP,
- 0, 0, 8)
- if ctx['num'] == 9:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 10:
- logger.info("Test: Invalid challenge length in Response")
- return struct.pack(">BBHBBBB", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_LEAP,
- 1, 0, 0)
- if ctx['num'] == 11:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 12:
- logger.info("Test: Truncated challenge in Response")
- return struct.pack(">BBHBBBB", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_LEAP,
- 1, 0, 24)
- if ctx['num'] == 13:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 14:
- logger.info("Test: Invalid challange value in Response")
- return struct.pack(">BBHBBBB6L", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0, 0, 0, 0, 0, 0)
- if ctx['num'] == 15:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 16:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- if ctx['num'] == 17:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 18:
- logger.info("Test: Success")
- return struct.pack(">BBHB", EAP_CODE_SUCCESS, ctx['id'],
- 4 + 1,
- EAP_TYPE_LEAP)
- # hostapd will drop the next frame in the sequence
- if ctx['num'] == 19:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- if ctx['num'] == 20:
- logger.info("Test: Failure")
- return struct.pack(">BBHB", EAP_CODE_FAILURE, ctx['id'],
- 4 + 1,
- EAP_TYPE_LEAP)
- return None
- srv = start_radius_server(leap_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 12):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- if i == 10:
- logger.info("Wait for additional roundtrip")
- time.sleep(1)
- dev[0].request("REMOVE_NETWORK all")
- finally:
- stop_radius_server(srv)
- def test_eap_proto_leap_errors(dev, apdev):
- """EAP-LEAP protocol tests (error paths)"""
- check_eap_capa(dev[0], "LEAP")
- def leap_handler2(ctx, req):
- logger.info("leap_handler2 - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challange value in Response")
- return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_LEAP,
- 1, 0, 24,
- 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
- 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
- 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid challenge")
- return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_LEAP,
- 1, 0, 8, 0, 0)
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(leap_handler2)
- try:
- hapd = start_ap(apdev[0])
- with alloc_fail(dev[0], 1, "eap_leap_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_leap_process_request"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user",
- password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "eap_leap_process_success"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "os_get_random;eap_leap_process_success"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "eap_leap_process_response"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user",
- password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "nt_password_hash;eap_leap_process_response"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "hash_nt_password_hash;eap_leap_process_response"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "eap_leap_getKey"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user",
- password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "eap_leap_getKey"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user",
- password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "nt_password_hash;eap_leap_getKey"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "hash_nt_password_hash;eap_leap_getKey"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1,
- "nt_challenge_response;eap_leap_process_request"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="LEAP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_md5(dev, apdev):
- """EAP-MD5 protocol tests"""
- check_eap_capa(dev[0], "MD5")
- def md5_handler(ctx, req):
- logger.info("md5_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- if ctx['num'] == 1:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_MD5)
- if ctx['num'] == 2:
- logger.info("Test: Zero-length challenge")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_MD5,
- 0)
- if ctx['num'] == 3:
- logger.info("Test: Truncated challenge")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_MD5,
- 1)
- if ctx['num'] == 4:
- logger.info("Test: Shortest possible challenge and name")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- return None
- srv = start_radius_server(md5_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 4):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- finally:
- stop_radius_server(srv)
- def test_eap_proto_md5_errors(dev, apdev):
- """EAP-MD5 local error cases"""
- check_eap_capa(dev[0], "MD5")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- with fail_test(dev[0], 1, "chap_md5"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="phase1-user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_md5_process"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="phase1-user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- def test_eap_proto_otp(dev, apdev):
- """EAP-OTP protocol tests"""
- def otp_handler(ctx, req):
- logger.info("otp_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- if ctx['num'] == 1:
- logger.info("Test: Empty payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_OTP)
- if ctx['num'] == 2:
- logger.info("Test: Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'],
- 4)
- if ctx['num'] == 3:
- logger.info("Test: Challenge included")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_OTP,
- ord('A'))
- if ctx['num'] == 4:
- logger.info("Test: Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'],
- 4)
- return None
- srv = start_radius_server(otp_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 1):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="OTP", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="OTP", identity="user", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-REQ-OTP"])
- if ev is None:
- raise Exception("Request for password timed out")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-OTP-" + id + ":password")
- ev = dev[0].wait_event("CTRL-EVENT-EAP-SUCCESS")
- if ev is None:
- raise Exception("Success not reported")
- finally:
- stop_radius_server(srv)
- def test_eap_proto_otp_errors(dev, apdev):
- """EAP-OTP local error cases"""
- def otp_handler2(ctx, req):
- logger.info("otp_handler2 - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge included")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_OTP,
- ord('A'))
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(otp_handler2)
- try:
- hapd = start_ap(apdev[0])
- with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_otp_process"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="OTP", identity="user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- finally:
- stop_radius_server(srv)
- EAP_GPSK_OPCODE_GPSK_1 = 1
- EAP_GPSK_OPCODE_GPSK_2 = 2
- EAP_GPSK_OPCODE_GPSK_3 = 3
- EAP_GPSK_OPCODE_GPSK_4 = 4
- EAP_GPSK_OPCODE_FAIL = 5
- EAP_GPSK_OPCODE_PROTECTED_FAIL = 6
- def test_eap_proto_gpsk(dev, apdev):
- """EAP-GPSK protocol tests"""
- def gpsk_handler(ctx, req):
- logger.info("gpsk_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_GPSK)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unknown opcode")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_GPSK,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected GPSK-3")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Too short GPSK-1")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Truncated ID_Server")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Missing RAND_Server")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Missing CSuite_List")
- return struct.pack(">BBHBBH8L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Truncated CSuite_List")
- return struct.pack(">BBHBBH8LH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Empty CSuite_List")
- return struct.pack(">BBHBBH8LH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Invalid CSuite_List")
- return struct.pack(">BBHBBH8LHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 1,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 No supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected GPSK-1")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite but too short key")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short GPSK-3")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Mismatch in RAND_Peer")
- return struct.pack(">BBHBB8L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3,
- 0, 0, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Missing RAND_Server")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Mismatch in RAND_Server")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8L", 1, 1, 1, 1, 1, 1, 1, 1)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Missing ID_Server")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8L", 0, 0, 0, 0, 0, 0, 0, 0)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Truncated ID_Server")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LH", 0, 0, 0, 0, 0, 0, 0, 0, 1)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Mismatch in ID_Server")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 3,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LHB", 0, 0, 0, 0, 0, 0, 0, 0, 1, ord('B'))
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBHB8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 3 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 1, ord('A'),
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Mismatch in ID_Server (same length)")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 3,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[15:47]
- msg += struct.pack(">8LHB", 0, 0, 0, 0, 0, 0, 0, 0, 1, ord('B'))
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Missing CSuite_Sel")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LH", 0, 0, 0, 0, 0, 0, 0, 0, 0)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Mismatch in CSuite_Sel")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LHLH", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Missing len(PD_Payload_Block)")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LHLH", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Truncated PD_Payload_Block")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2 + 6 + 2,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LHLHH", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Missing MAC")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2 + 6 + 3,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LHLHHB",
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 123)
- return msg
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-1 Supported CSuite")
- return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 32 + 2 + 6,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 6, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: GPSK-3 Incorrect MAC")
- msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 32 + 32 + 2 + 6 + 3 + 16,
- EAP_TYPE_GPSK,
- EAP_GPSK_OPCODE_GPSK_3)
- msg += req[14:46]
- msg += struct.pack(">8LHLHHB4L",
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 123,
- 0, 0, 0, 0)
- return msg
- return None
- srv = start_radius_server(gpsk_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 27):
- if i == 12:
- pw = "short"
- else:
- pw = "abcdefghijklmnop0123456789abcdef"
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="GPSK", identity="user", password=pw,
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.05)
- dev[0].request("REMOVE_NETWORK all")
- finally:
- stop_radius_server(srv)
- EAP_EKE_ID = 1
- EAP_EKE_COMMIT = 2
- EAP_EKE_CONFIRM = 3
- EAP_EKE_FAILURE = 4
- def test_eap_proto_eke(dev, apdev):
- """EAP-EKE protocol tests"""
- def eke_handler(ctx, req):
- logger.info("eke_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_EKE)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unknown exchange")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No NumProposals in EAP-EKE-ID/Request")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: NumProposals=0 in EAP-EKE-ID/Request")
- return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated Proposals list in EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 2, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported proposals in EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4B4B4B4B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 * 4,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 4, 0,
- 0, 0, 0, 0,
- 3, 0, 0, 0,
- 3, 1, 0, 0,
- 3, 1, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing IDType/Identity in EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4B4B4B4B4B",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 5 * 4,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 5, 0,
- 0, 0, 0, 0,
- 3, 0, 0, 0,
- 3, 1, 0, 0,
- 3, 1, 1, 0,
- 3, 1, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4BB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 1, 0,
- 3, 1, 1, 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4BB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 1, 0,
- 3, 1, 1, 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4BB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 1, 0,
- 3, 1, 1, 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected EAP-EKE-Confirm/Request")
- return struct.pack(">BBHBB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_CONFIRM)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short EAP-EKE-Failure/Request")
- return struct.pack(">BBHBB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_FAILURE)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected EAP-EKE-Commit/Request")
- return struct.pack(">BBHBB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_COMMIT)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4BB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 1, 0,
- 3, 1, 1, 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short EAP-EKE-Commit/Request")
- return struct.pack(">BBHBB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_COMMIT)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4BB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 1, 0,
- 1, 1, 1, 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: All zeroes DHComponent_S and empty CBvalue in EAP-EKE-Commit/Request")
- return struct.pack(">BBHBB4L32L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16 + 128,
- EAP_TYPE_EKE,
- EAP_EKE_COMMIT,
- 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short EAP-EKE-Confirm/Request")
- return struct.pack(">BBHBB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_CONFIRM)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid EAP-EKE-ID/Request")
- return struct.pack(">BBHBBBB4BB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2 + 4 + 1,
- EAP_TYPE_EKE,
- EAP_EKE_ID,
- 1, 0,
- 1, 1, 1, 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: All zeroes DHComponent_S and empty CBvalue in EAP-EKE-Commit/Request")
- return struct.pack(">BBHBB4L32L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16 + 128,
- EAP_TYPE_EKE,
- EAP_EKE_COMMIT,
- 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid PNonce_PS and Auth_S values in EAP-EKE-Confirm/Request")
- return struct.pack(">BBHBB4L8L5L5L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16 + 2 * 16 + 20 + 20,
- EAP_TYPE_EKE,
- EAP_EKE_CONFIRM,
- 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return None
- srv = start_radius_server(eke_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 14):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="EKE", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if i in [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- else:
- time.sleep(0.05)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def eap_eke_test_fail(dev, phase1=None, success=False):
- dev.connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="EKE", identity="eke user@domain", password="hello",
- phase1=phase1, erp="1", wait_connect=False)
- ev = dev.wait_event([ "CTRL-EVENT-EAP-FAILURE",
- "CTRL-EVENT-EAP-SUCCESS" ], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- if not success and "CTRL-EVENT-EAP-FAILURE" not in ev:
- raise Exception("EAP did not fail during failure test")
- dev.request("REMOVE_NETWORK all")
- dev.wait_disconnected()
- def test_eap_proto_eke_errors(dev, apdev):
- """EAP-EKE local error cases"""
- check_eap_capa(dev[0], "EKE")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 3):
- with alloc_fail(dev[0], i, "eap_eke_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="EKE", identity="eke user", password="hello",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "eap_eke_dh_init", None),
- (1, "eap_eke_prf_hmac_sha1", "dhgroup=3 encr=1 prf=1 mac=1"),
- (1, "eap_eke_prf_hmac_sha256", "dhgroup=5 encr=1 prf=2 mac=2"),
- (1, "eap_eke_prf", None),
- (1, "os_get_random;eap_eke_dhcomp", None),
- (1, "aes_128_cbc_encrypt;eap_eke_dhcomp", None),
- (1, "aes_128_cbc_decrypt;eap_eke_shared_secret", None),
- (1, "eap_eke_prf;eap_eke_shared_secret", None),
- (1, "eap_eke_prfplus;eap_eke_derive_ke_ki", None),
- (1, "eap_eke_prfplus;eap_eke_derive_ka", None),
- (1, "eap_eke_prfplus;eap_eke_derive_msk", None),
- (1, "os_get_random;eap_eke_prot", None),
- (1, "aes_128_cbc_decrypt;eap_eke_decrypt_prot", None),
- (1, "eap_eke_derive_key;eap_eke_process_commit", None),
- (1, "eap_eke_dh_init;eap_eke_process_commit", None),
- (1, "eap_eke_shared_secret;eap_eke_process_commit", None),
- (1, "eap_eke_derive_ke_ki;eap_eke_process_commit", None),
- (1, "eap_eke_dhcomp;eap_eke_process_commit", None),
- (1, "os_get_random;eap_eke_process_commit", None),
- (1, "os_get_random;=eap_eke_process_commit", None),
- (1, "eap_eke_prot;eap_eke_process_commit", None),
- (1, "eap_eke_decrypt_prot;eap_eke_process_confirm", None),
- (1, "eap_eke_derive_ka;eap_eke_process_confirm", None),
- (1, "eap_eke_auth;eap_eke_process_confirm", None),
- (2, "eap_eke_auth;eap_eke_process_confirm", None),
- (1, "eap_eke_prot;eap_eke_process_confirm", None),
- (1, "eap_eke_derive_msk;eap_eke_process_confirm", None) ]
- for count, func, phase1 in tests:
- with fail_test(dev[0], count, func):
- eap_eke_test_fail(dev[0], phase1)
- tests = [ (1, "=eap_eke_derive_ke_ki", None),
- (1, "=eap_eke_derive_ka", None),
- (1, "=eap_eke_derive_msk", None),
- (1, "eap_eke_build_msg;eap_eke_process_id", None),
- (1, "wpabuf_alloc;eap_eke_process_id", None),
- (1, "=eap_eke_process_id", None),
- (1, "wpabuf_alloc;=eap_eke_process_id", None),
- (1, "wpabuf_alloc;eap_eke_process_id", None),
- (1, "eap_eke_build_msg;eap_eke_process_commit", None),
- (1, "wpabuf_resize;eap_eke_process_commit", None),
- (1, "eap_eke_build_msg;eap_eke_process_confirm", None) ]
- for count, func, phase1 in tests:
- with alloc_fail(dev[0], count, func):
- eap_eke_test_fail(dev[0], phase1)
- tests = [ (1, "eap_eke_getKey", None),
- (1, "eap_eke_get_emsk", None),
- (1, "eap_eke_get_session_id", None) ]
- for count, func, phase1 in tests:
- with alloc_fail(dev[0], count, func):
- eap_eke_test_fail(dev[0], phase1, success=True)
- EAP_PAX_OP_STD_1 = 0x01
- EAP_PAX_OP_STD_2 = 0x02
- EAP_PAX_OP_STD_3 = 0x03
- EAP_PAX_OP_SEC_1 = 0x11
- EAP_PAX_OP_SEC_2 = 0x12
- EAP_PAX_OP_SEC_3 = 0x13
- EAP_PAX_OP_SEC_4 = 0x14
- EAP_PAX_OP_SEC_5 = 0x15
- EAP_PAX_OP_ACK = 0x21
- EAP_PAX_FLAGS_MF = 0x01
- EAP_PAX_FLAGS_CE = 0x02
- EAP_PAX_FLAGS_AI = 0x04
- EAP_PAX_MAC_HMAC_SHA1_128 = 0x01
- EAP_PAX_HMAC_SHA256_128 = 0x02
- EAP_PAX_DH_GROUP_NONE = 0x00
- EAP_PAX_DH_GROUP_2048_MODP = 0x01
- EAP_PAX_DH_GROUP_3072_MODP = 0x02
- EAP_PAX_DH_GROUP_NIST_ECC_P_256 = 0x03
- EAP_PAX_PUBLIC_KEY_NONE = 0x00
- EAP_PAX_PUBLIC_KEY_RSAES_OAEP = 0x01
- EAP_PAX_PUBLIC_KEY_RSA_PKCS1_V1_5 = 0x02
- EAP_PAX_PUBLIC_KEY_EL_GAMAL_NIST_ECC = 0x03
- EAP_PAX_ADE_VENDOR_SPECIFIC = 0x01
- EAP_PAX_ADE_CLIENT_CHANNEL_BINDING = 0x02
- EAP_PAX_ADE_SERVER_CHANNEL_BINDING = 0x03
- def test_eap_proto_pax(dev, apdev):
- """EAP-PAX protocol tests"""
- def pax_std_1(ctx):
- logger.info("Test: STD-1")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0x16, 0xc9, 0x08, 0x9d, 0x98, 0xa5, 0x6e, 0x1f,
- 0xf0, 0xac, 0xcf, 0xc4, 0x66, 0xcd, 0x2d, 0xbf)
- def pax_handler(ctx, req):
- logger.info("pax_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_PAX)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Minimum length payload")
- return struct.pack(">BBHB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 16,
- EAP_TYPE_PAX,
- 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported MAC ID")
- return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, 255, EAP_PAX_DH_GROUP_NONE,
- EAP_PAX_PUBLIC_KEY_NONE,
- 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported DH Group ID")
- return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- 255, EAP_PAX_PUBLIC_KEY_NONE,
- 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported Public Key ID")
- return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, 255,
- 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: More fragments")
- return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, EAP_PAX_FLAGS_MF,
- EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid ICV")
- return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid ICV in short frame")
- return struct.pack(">BBHBBBBBB3L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 12,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Correct ICV - unsupported op_code")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBB16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- 255, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0x90, 0x78, 0x97, 0x38, 0x29, 0x94, 0x32, 0xd4,
- 0x81, 0x27, 0xe0, 0xf6, 0x3b, 0x0d, 0xb2, 0xb2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Correct ICV - CE flag in STD-1")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBB16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, EAP_PAX_FLAGS_CE,
- EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0x9c, 0x98, 0xb4, 0x0b, 0x94, 0x90, 0xde, 0x88,
- 0xb7, 0x72, 0x63, 0x44, 0x1d, 0xe3, 0x7c, 0x5c)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Correct ICV - too short STD-1 payload")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBB16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0xda, 0xab, 0x2c, 0xe7, 0x84, 0x41, 0xb5, 0x5c,
- 0xee, 0xcf, 0x62, 0x03, 0xc5, 0x69, 0xcb, 0xf4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Correct ICV - incorrect A length in STD-1")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0xc4, 0xb0, 0x81, 0xe4, 0x6c, 0x8c, 0x20, 0x23,
- 0x60, 0x46, 0x89, 0xea, 0x94, 0x60, 0xf3, 0x2a)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Correct ICV - extra data in STD-1")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBBH8LB16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 1 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 1,
- 0x61, 0x49, 0x65, 0x37, 0x21, 0xe8, 0xd8, 0xbf,
- 0xf3, 0x02, 0x01, 0xe5, 0x42, 0x51, 0xd3, 0x34)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected STD-1")
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0xe5, 0x1d, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
- 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
- idx += 1
- if ctx['num'] == idx:
- return pax_std_1(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MAC ID changed during session")
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_HMAC_SHA256_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0xee, 0x00, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
- 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
- idx += 1
- if ctx['num'] == idx:
- return pax_std_1(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: DH Group ID changed during session")
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_2048_MODP,
- EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0xee, 0x01, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
- 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
- idx += 1
- if ctx['num'] == idx:
- return pax_std_1(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Public Key ID changed during session")
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE,
- EAP_PAX_PUBLIC_KEY_RSAES_OAEP,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0xee, 0x02, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
- 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected STD-3")
- ctx['id'] = 10
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_3, 0, EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0x47, 0xbb, 0xc0, 0xf9, 0xb9, 0x69, 0xf5, 0xcb,
- 0x3a, 0xe8, 0xe7, 0xd6, 0x80, 0x28, 0xf2, 0x59)
- idx += 1
- if ctx['num'] == idx:
- return pax_std_1(ctx)
- idx += 1
- if ctx['num'] == idx:
- # TODO: MAC calculation; for now, this gets dropped due to incorrect
- # ICV
- logger.info("Test: STD-3 with CE flag")
- return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 5 + 2 + 32 + 16,
- EAP_TYPE_PAX,
- EAP_PAX_OP_STD_3, EAP_PAX_FLAGS_CE,
- EAP_PAX_MAC_HMAC_SHA1_128,
- EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
- 32, 0, 0, 0, 0, 0, 0, 0, 0,
- 0x8a, 0xc2, 0xf9, 0xf4, 0x8b, 0x75, 0x72, 0xa2,
- 0x4d, 0xd3, 0x1e, 0x54, 0x77, 0x04, 0x05, 0xe2)
- idx += 1
- if ctx['num'] & 0x1 == idx & 0x1:
- logger.info("Test: Default request")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_PAX)
- else:
- logger.info("Test: Default EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(pax_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 18):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="user",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- logger.info("Waiting for EAP method to start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.05)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- logger.info("Too short password")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="user",
- password_hex="0123456789abcdef0123456789abcd",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- logger.info("No password")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="user",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_pax_errors(dev, apdev):
- """EAP-PAX local error cases"""
- check_eap_capa(dev[0], "PAX")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 3):
- with alloc_fail(dev[0], i, "eap_pax_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="pax.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ "eap_msg_alloc;eap_pax_alloc_resp;eap_pax_process_std_1",
- "eap_msg_alloc;eap_pax_alloc_resp;eap_pax_process_std_3",
- "eap_pax_getKey",
- "eap_pax_get_emsk",
- "eap_pax_get_session_id" ]
- for func in tests:
- with alloc_fail(dev[0], 1, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="pax.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- erp="1", wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "os_get_random;eap_pax_process_std_1"),
- (1, "eap_pax_initial_key_derivation"),
- (1, "eap_pax_mac;eap_pax_process_std_3"),
- (2, "eap_pax_mac;eap_pax_process_std_3"),
- (1, "eap_pax_kdf;eap_pax_getKey"),
- (1, "eap_pax_kdf;eap_pax_get_emsk") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="pax.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- erp="1", wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_proto_psk(dev, apdev):
- """EAP-PSK protocol tests"""
- def psk_handler(ctx, req):
- logger.info("psk_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_PSK)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Non-zero T in first message")
- return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16,
- EAP_TYPE_PSK, 0xc0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first message")
- return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16,
- EAP_TYPE_PSK, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short third message")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_PSK)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first message")
- return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16,
- EAP_TYPE_PSK, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Incorrect T in third message")
- return struct.pack(">BBHBB4L4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16 + 16,
- EAP_TYPE_PSK, 0, 0, 0, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first message")
- return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16,
- EAP_TYPE_PSK, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing PCHANNEL in third message")
- return struct.pack(">BBHBB4L4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16 + 16,
- EAP_TYPE_PSK, 0x80, 0, 0, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first message")
- return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16,
- EAP_TYPE_PSK, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalic MAC_S in third message")
- return struct.pack(">BBHBB4L4L5LB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16 + 16 + 21,
- EAP_TYPE_PSK, 0x80, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first message")
- return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 16,
- EAP_TYPE_PSK, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return None
- srv = start_radius_server(psk_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 6):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PSK", identity="user",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- logger.info("Test: Invalid PSK length")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PSK", identity="user",
- password_hex="0123456789abcdef0123456789abcd",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- finally:
- stop_radius_server(srv)
- def test_eap_proto_psk_errors(dev, apdev):
- """EAP-PSK local error cases"""
- check_eap_capa(dev[0], "PSK")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 3):
- with alloc_fail(dev[0], i, "eap_psk_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PSK", identity="psk.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- for i in range(1, 4):
- with fail_test(dev[0], i, "eap_psk_key_setup;eap_psk_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PSK", identity="psk.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "=eap_psk_process_1"),
- (2, "=eap_psk_process_1"),
- (1, "eap_msg_alloc;eap_psk_process_1"),
- (1, "=eap_psk_process_3"),
- (2, "=eap_psk_process_3"),
- (1, "eap_msg_alloc;eap_psk_process_3"),
- (1, "eap_psk_getKey"),
- (1, "eap_psk_get_session_id"),
- (1, "eap_psk_get_emsk") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PSK", identity="psk.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
- note="No allocation failure seen for %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "os_get_random;eap_psk_process_1"),
- (1, "omac1_aes_128;eap_psk_process_3"),
- (1, "aes_128_eax_decrypt;eap_psk_process_3"),
- (2, "aes_128_eax_decrypt;eap_psk_process_3"),
- (3, "aes_128_eax_decrypt;eap_psk_process_3"),
- (1, "aes_128_eax_encrypt;eap_psk_process_3"),
- (2, "aes_128_eax_encrypt;eap_psk_process_3"),
- (3, "aes_128_eax_encrypt;eap_psk_process_3"),
- (1, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (2, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (3, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (4, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (5, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (6, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (7, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (8, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (9, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (10, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
- (1, "aes_ctr_encrypt;aes_128_eax_decrypt;eap_psk_process_3"),
- (1, "aes_ctr_encrypt;aes_128_eax_encrypt;eap_psk_process_3") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PSK", identity="psk.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_FAIL",
- note="No failure seen for %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- EAP_SIM_SUBTYPE_START = 10
- EAP_SIM_SUBTYPE_CHALLENGE = 11
- EAP_SIM_SUBTYPE_NOTIFICATION = 12
- EAP_SIM_SUBTYPE_REAUTHENTICATION = 13
- EAP_SIM_SUBTYPE_CLIENT_ERROR = 14
- EAP_AKA_SUBTYPE_CHALLENGE = 1
- EAP_AKA_SUBTYPE_AUTHENTICATION_REJECT = 2
- EAP_AKA_SUBTYPE_SYNCHRONIZATION_FAILURE = 4
- EAP_AKA_SUBTYPE_IDENTITY = 5
- EAP_AKA_SUBTYPE_NOTIFICATION = 12
- EAP_AKA_SUBTYPE_REAUTHENTICATION = 13
- EAP_AKA_SUBTYPE_CLIENT_ERROR = 14
- EAP_SIM_AT_RAND = 1
- EAP_SIM_AT_AUTN = 2
- EAP_SIM_AT_RES = 3
- EAP_SIM_AT_AUTS = 4
- EAP_SIM_AT_PADDING = 6
- EAP_SIM_AT_NONCE_MT = 7
- EAP_SIM_AT_PERMANENT_ID_REQ = 10
- EAP_SIM_AT_MAC = 11
- EAP_SIM_AT_NOTIFICATION = 12
- EAP_SIM_AT_ANY_ID_REQ = 13
- EAP_SIM_AT_IDENTITY = 14
- EAP_SIM_AT_VERSION_LIST = 15
- EAP_SIM_AT_SELECTED_VERSION = 16
- EAP_SIM_AT_FULLAUTH_ID_REQ = 17
- EAP_SIM_AT_COUNTER = 19
- EAP_SIM_AT_COUNTER_TOO_SMALL = 20
- EAP_SIM_AT_NONCE_S = 21
- EAP_SIM_AT_CLIENT_ERROR_CODE = 22
- EAP_SIM_AT_KDF_INPUT = 23
- EAP_SIM_AT_KDF = 24
- EAP_SIM_AT_IV = 129
- EAP_SIM_AT_ENCR_DATA = 130
- EAP_SIM_AT_NEXT_PSEUDONYM = 132
- EAP_SIM_AT_NEXT_REAUTH_ID = 133
- EAP_SIM_AT_CHECKCODE = 134
- EAP_SIM_AT_RESULT_IND = 135
- EAP_SIM_AT_BIDDING = 136
- def test_eap_proto_aka(dev, apdev):
- """EAP-AKA protocol tests"""
- def aka_handler(ctx, req):
- logger.info("aka_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_AKA)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unknown subtype")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA, 255, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Client Error")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CLIENT_ERROR, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short attribute header")
- return struct.pack(">BBHBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 3,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0, 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated attribute")
- return struct.pack(">BBHBBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0, 255,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short attribute data")
- return struct.pack(">BBHBBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0, 255,
- 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Skippable/non-skippable unrecognzized attribute")
- return struct.pack(">BBHBBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 10,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- 255, 1, 0, 127, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request without ID type")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID (duplicate)")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request FULLAUTH_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request FULLAUTH_ID (duplicate)")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request FULLAUTH_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request PERMANENT_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request PERMANENT_ID (duplicate)")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with no attributes")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: AKA Challenge with BIDDING")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_BIDDING, 1, 0x8000)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification with no attributes")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification indicating success, but no MAC")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 32768)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification indicating success, but invalid MAC value")
- return struct.pack(">BBHBBHBBHBBH4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 20,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 32768,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification indicating success with zero-key MAC")
- return struct.pack(">BBHBBHBBHBBH16B", EAP_CODE_REQUEST,
- ctx['id'] - 2,
- 4 + 1 + 3 + 4 + 20,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 32768,
- EAP_SIM_AT_MAC, 5, 0,
- 0xbe, 0x2e, 0xbb, 0xa9, 0xfa, 0x2e, 0x82, 0x36,
- 0x37, 0x8c, 0x32, 0x41, 0xb7, 0xc7, 0x58, 0xa3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification before auth")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 16384)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification before auth")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 16385)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification with unrecognized non-failure")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification before auth (duplicate)")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Re-authentication (unexpected) with no attributes")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_REAUTHENTICATION,
- 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: AKA Challenge with Checkcode claiming identity round was used")
- return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_CHECKCODE, 6, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: AKA Challenge with Checkcode claiming no identity round was used")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_CHECKCODE, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: AKA Challenge with mismatching Checkcode value")
- return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_CHECKCODE, 6, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Re-authentication (unexpected) with Checkcode claimin identity round was used")
- return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_REAUTHENTICATION,
- 0,
- EAP_SIM_AT_CHECKCODE, 6, 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_RAND length")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_RAND, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_AUTN length")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_AUTN, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unencrypted AT_PADDING")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_PADDING, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_NONCE_MT length")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_NONCE_MT, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_MAC length")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_MAC, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_NOTIFICATION length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_NOTIFICATION, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: AT_IDENTITY overflow")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_IDENTITY, 1, 0xffff)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected AT_VERSION_LIST")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_VERSION_LIST, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_SELECTED_VERSION length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_SELECTED_VERSION, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unencrypted AT_COUNTER")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_COUNTER, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unencrypted AT_COUNTER_TOO_SMALL")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_COUNTER_TOO_SMALL, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unencrypted AT_NONCE_S")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_NONCE_S, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_CLIENT_ERROR_CODE length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_CLIENT_ERROR_CODE, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_IV length")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_IV, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_ENCR_DATA length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_ENCR_DATA, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unencrypted AT_NEXT_PSEUDONYM")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_NEXT_PSEUDONYM, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unencrypted AT_NEXT_REAUTH_ID")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_NEXT_REAUTH_ID, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_RES length")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_RES, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_RES length")
- return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 24,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_RES, 6, 0xffff, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_AUTS length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_AUTS, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_CHECKCODE length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_CHECKCODE, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_RESULT_IND length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_RESULT_IND, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected AT_KDF_INPUT")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected AT_KDF")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_KDF, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_BIDDING length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_BIDDING, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return None
- srv = start_radius_server(aka_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 49):
- eap = "AKA AKA'" if i == 11 else "AKA"
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap=eap, identity="0232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if i in [ 0, 15 ]:
- time.sleep(0.1)
- else:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_aka_prime(dev, apdev):
- """EAP-AKA' protocol tests"""
- def aka_prime_handler(ctx, req):
- logger.info("aka_prime_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_AKA_PRIME)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with no attributes")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with empty AT_KDF_INPUT")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with AT_KDF_INPUT")
- return struct.pack(">BBHBBHBBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with duplicated KDF")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 3 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_KDF, 1, 2,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with multiple KDF proposals")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 3 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with incorrect KDF selected")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with multiple KDF proposals")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 3 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with selected KDF not duplicated")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 3 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with multiple KDF proposals")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 3 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with selected KDF duplicated (missing MAC, RAND, AUTN)")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with multiple unsupported KDF proposals")
- return struct.pack(">BBHBBHBBHBBBBBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 2 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with multiple KDF proposals")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 3 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with invalid MAC, RAND, AUTN values)")
- return struct.pack(">BBHBBHBBHBBBBBBHBBHBBHBBHBBH4LBBH4LBBH4L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4 * 4 + 20 + 20 + 20,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0,
- EAP_SIM_AT_RAND, 5, 0, 0, 0, 0, 0,
- EAP_SIM_AT_AUTN, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge - AMF separation bit not set)")
- return struct.pack(">BBHBBHBBHBBBBBBHBBH4LBBH4LBBH4L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4 + 20 + 20 + 20,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_MAC, 5, 0, 1, 2, 3, 4,
- EAP_SIM_AT_RAND, 5, 0, 5, 6, 7, 8,
- EAP_SIM_AT_AUTN, 5, 0, 9, 10,
- 0x2fda8ef7, 0xbba518cc)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge - Invalid MAC")
- return struct.pack(">BBHBBHBBHBBBBBBHBBH4LBBH4LBBH4L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4 + 20 + 20 + 20,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_MAC, 5, 0, 1, 2, 3, 4,
- EAP_SIM_AT_RAND, 5, 0, 5, 6, 7, 8,
- EAP_SIM_AT_AUTN, 5, 0, 0xffffffff, 0xffffffff,
- 0xd1f90322, 0x40514cb4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge - Valid MAC")
- return struct.pack(">BBHBBHBBHBBBBBBHBBH4LBBH4LBBH4L",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4 + 20 + 20 + 20,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
- ord('c'), ord('d'),
- EAP_SIM_AT_KDF, 1, 1,
- EAP_SIM_AT_MAC, 5, 0,
- 0xf4a3c1d3, 0x7c901401, 0x34bd8b01, 0x6f7fa32f,
- EAP_SIM_AT_RAND, 5, 0, 5, 6, 7, 8,
- EAP_SIM_AT_AUTN, 5, 0, 0xffffffff, 0xffffffff,
- 0xd1f90322, 0x40514cb4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_KDF_INPUT length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_KDF_INPUT, 2, 0xffff, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid AT_KDF length")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_IDENTITY, 0,
- EAP_SIM_AT_KDF, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge with large number of KDF proposals")
- return struct.pack(">BBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBH",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 12 * 4,
- EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_KDF, 1, 255,
- EAP_SIM_AT_KDF, 1, 254,
- EAP_SIM_AT_KDF, 1, 253,
- EAP_SIM_AT_KDF, 1, 252,
- EAP_SIM_AT_KDF, 1, 251,
- EAP_SIM_AT_KDF, 1, 250,
- EAP_SIM_AT_KDF, 1, 249,
- EAP_SIM_AT_KDF, 1, 248,
- EAP_SIM_AT_KDF, 1, 247,
- EAP_SIM_AT_KDF, 1, 246,
- EAP_SIM_AT_KDF, 1, 245,
- EAP_SIM_AT_KDF, 1, 244)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return None
- srv = start_radius_server(aka_prime_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 16):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA'", identity="6555444333222111",
- password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if i in [ 0 ]:
- time.sleep(0.1)
- else:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_sim(dev, apdev):
- """EAP-SIM protocol tests"""
- def sim_handler(ctx, req):
- logger.info("sim_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_SIM)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected AT_AUTN")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_AUTN, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short AT_VERSION_LIST")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: AT_VERSION_LIST overflow")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 1, 0xffff)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected AT_AUTS")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_AUTS, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected AT_CHECKCODE")
- return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_CHECKCODE, 2, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No AT_VERSION_LIST in Start")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No support version in AT_VERSION_LIST")
- return struct.pack(">BBHBBHBBH4B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 3, 2, 3, 4, 5)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request without ID type")
- return struct.pack(">BBHBBHBBH2H", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID (duplicate)")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request FULLAUTH_ID")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request FULLAUTH_ID (duplicate)")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request ANY_ID")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_ANY_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request FULLAUTH_ID")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request PERMANENT_ID")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Identity request PERMANENT_ID (duplicate)")
- return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 8 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
- EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
- EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No AT_MAC and AT_RAND in Challenge")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No AT_RAND in Challenge")
- return struct.pack(">BBHBBHBBH4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 20,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Insufficient number of challenges in Challenge")
- return struct.pack(">BBHBBHBBH4LBBH4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 20 + 20,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_RAND, 5, 0, 0, 0, 0, 0,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too many challenges in Challenge")
- return struct.pack(">BBHBBHBBH4L4L4L4LBBH4L", EAP_CODE_REQUEST,
- ctx['id'],
- 4 + 1 + 3 + 4 + 4 * 16 + 20,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_RAND, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Same RAND multiple times in Challenge")
- return struct.pack(">BBHBBHBBH4L4L4LBBH4L", EAP_CODE_REQUEST,
- ctx['id'],
- 4 + 1 + 3 + 4 + 3 * 16 + 20,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
- EAP_SIM_AT_RAND, 13, 0, 0, 0, 0, 0, 0, 0, 0, 1,
- 0, 0, 0, 0,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification with no attributes")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification indicating success, but no MAC")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 32768)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification indicating success, but invalid MAC value")
- return struct.pack(">BBHBBHBBHBBH4L", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 20,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 32768,
- EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification before auth")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 16384)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification before auth")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 16385)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification with unrecognized non-failure")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Notification before auth (duplicate)")
- return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
- EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Re-authentication (unexpected) with no attributes")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_REAUTHENTICATION,
- 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Client Error")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CLIENT_ERROR, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unknown subtype")
- return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3,
- EAP_TYPE_SIM, 255, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return None
- srv = start_radius_server(sim_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 25):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if i in [ 0 ]:
- time.sleep(0.1)
- else:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_sim_errors(dev, apdev):
- """EAP-SIM protocol tests (error paths)"""
- check_hlr_auc_gw_support()
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- with alloc_fail(dev[0], 1, "eap_sim_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1, "os_get_random;eap_sim_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
- with fail_test(dev[0], 1, "aes_128_cbc_encrypt;eap_sim_response_reauth"):
- hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("EAP re-authentication did not start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
- with fail_test(dev[0], 1, "os_get_random;eap_sim_msg_add_encr_start"):
- hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("EAP re-authentication did not start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
- with fail_test(dev[0], 1, "os_get_random;eap_sim_init_for_reauth"):
- hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("EAP re-authentication did not start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
- with alloc_fail(dev[0], 1, "eap_sim_parse_encr;eap_sim_process_reauthentication"):
- hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("EAP re-authentication did not start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ (1, "eap_sim_verify_mac;eap_sim_process_challenge"),
- (1, "eap_sim_parse_encr;eap_sim_process_challenge"),
- (1, "eap_sim_msg_init;eap_sim_response_start"),
- (1, "wpabuf_alloc;eap_sim_msg_init;eap_sim_response_start"),
- (1, "=eap_sim_learn_ids"),
- (2, "=eap_sim_learn_ids"),
- (2, "eap_sim_learn_ids"),
- (3, "eap_sim_learn_ids"),
- (1, "eap_sim_process_start"),
- (1, "eap_sim_getKey"),
- (1, "eap_sim_get_emsk"),
- (1, "eap_sim_get_session_id") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000@domain",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
- erp="1", wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ (1, "aes_128_cbc_decrypt;eap_sim_parse_encr") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- params = int_eap_server_params()
- params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
- params['eap_sim_aka_result_ind'] = "1"
- hostapd.add_ap(apdev[1], params)
- with alloc_fail(dev[0], 1,
- "eap_sim_msg_init;eap_sim_response_notification"):
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
- scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- phase1="result_ind=1",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ "eap_sim_msg_add_encr_start;eap_sim_response_notification",
- "aes_128_cbc_encrypt;eap_sim_response_notification" ]
- for func in tests:
- with fail_test(dev[0], 1, func):
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
- scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- phase1="result_ind=1",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
- dev[0].request("REAUTHENTICATE")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("EAP method not started on reauthentication")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ "eap_sim_parse_encr;eap_sim_process_notification_reauth" ]
- for func in tests:
- with alloc_fail(dev[0], 1, func):
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
- scan_freq="2412",
- eap="SIM", identity="1232010000000000",
- phase1="result_ind=1",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
- dev[0].request("REAUTHENTICATE")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("EAP method not started on reauthentication")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- def test_eap_proto_aka_errors(dev, apdev):
- """EAP-AKA protocol tests (error paths)"""
- check_hlr_auc_gw_support()
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- with alloc_fail(dev[0], 1, "eap_aka_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA", identity="0232010000000000",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "=eap_aka_learn_ids"),
- (2, "=eap_aka_learn_ids"),
- (1, "eap_sim_parse_encr;eap_aka_process_challenge"),
- (1, "wpabuf_dup;eap_aka_add_id_msg"),
- (1, "wpabuf_resize;eap_aka_add_id_msg"),
- (1, "eap_aka_getKey"),
- (1, "eap_aka_get_emsk"),
- (1, "eap_aka_get_session_id") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA", identity="0232010000000000@domain",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
- erp="1", wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- params = int_eap_server_params()
- params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
- params['eap_sim_aka_result_ind'] = "1"
- hostapd.add_ap(apdev[1], params)
- with alloc_fail(dev[0], 1,
- "eap_sim_msg_init;eap_aka_response_notification"):
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA", identity="0232010000000000",
- phase1="result_ind=1",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ "eap_sim_msg_add_encr_start;eap_aka_response_notification",
- "aes_128_cbc_encrypt;eap_aka_response_notification" ]
- for func in tests:
- with fail_test(dev[0], 1, func):
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
- scan_freq="2412",
- eap="AKA", identity="0232010000000000",
- phase1="result_ind=1",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
- dev[0].request("REAUTHENTICATE")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("EAP method not started on reauthentication")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ "eap_sim_parse_encr;eap_aka_process_notification_reauth" ]
- for func in tests:
- with alloc_fail(dev[0], 1, func):
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
- scan_freq="2412",
- eap="AKA", identity="0232010000000000",
- phase1="result_ind=1",
- password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
- dev[0].request("REAUTHENTICATE")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("EAP method not started on reauthentication")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- def test_eap_proto_aka_prime_errors(dev, apdev):
- """EAP-AKA' protocol tests (error paths)"""
- check_hlr_auc_gw_support()
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- with alloc_fail(dev[0], 1, "eap_aka_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA'", identity="6555444333222111",
- password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA'", identity="6555444333222111",
- password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
- with fail_test(dev[0], 1, "aes_128_cbc_encrypt;eap_aka_response_reauth"):
- hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("EAP re-authentication did not start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA'", identity="6555444333222111",
- password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
- with alloc_fail(dev[0], 1, "eap_sim_parse_encr;eap_aka_process_reauthentication"):
- hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("EAP re-authentication did not start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- tests = [ (1, "eap_sim_verify_mac_sha256"),
- (1, "=eap_aka_process_challenge") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="AKA'", identity="6555444333222111",
- password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
- erp="1", wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].dump_monitor()
- def test_eap_proto_ikev2(dev, apdev):
- """EAP-IKEv2 protocol tests"""
- check_eap_capa(dev[0], "IKEV2")
- global eap_proto_ikev2_test_done
- eap_proto_ikev2_test_done = False
- def ikev2_handler(ctx, req):
- logger.info("ikev2_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_IKEV2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated Message Length field")
- return struct.pack(">BBHBB3B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 3,
- EAP_TYPE_IKEV2, 0x80, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short Message Length value")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_IKEV2, 0x80, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated message")
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_IKEV2, 0x80, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated message(2)")
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_IKEV2, 0x80, 0xffffffff)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated message(3)")
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_IKEV2, 0xc0, 0xffffffff)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated message(4)")
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_IKEV2, 0xc0, 10000000)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too long fragments (first fragment)")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_IKEV2, 0xc0, 2, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too long fragments (second fragment)")
- return struct.pack(">BBHBB2B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2,
- EAP_TYPE_IKEV2, 0x00, 2, 3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No Message Length field in first fragment")
- return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 1,
- EAP_TYPE_IKEV2, 0x40, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: ICV before keys")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_IKEV2, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported IKEv2 header version")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Incorrect IKEv2 header Length")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0x20, 0, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected IKEv2 Exchange Type in SA_INIT state")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0x20, 0, 0, 0, 28)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected IKEv2 Message ID in SA_INIT state")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0x20, 34, 0, 1, 28)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected IKEv2 Flags value")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0x20, 34, 0, 0, 28)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected IKEv2 Flags value(2)")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0x20, 34, 0x20, 0, 28)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No SAi1 in SA_INIT")
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 28,
- EAP_TYPE_IKEV2, 0x00,
- 0, 0, 0, 0,
- 0, 0x20, 34, 0x08, 0, 28)
- def build_ike(id, next=0, exch_type=34, flags=0x00, ike=''):
- return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, id,
- 4 + 1 + 1 + 28 + len(ike),
- EAP_TYPE_IKEV2, flags,
- 0, 0, 0, 0,
- next, 0x20, exch_type, 0x08, 0,
- 28 + len(ike)) + ike
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected extra data after payloads")
- return build_ike(ctx['id'], ike=struct.pack(">B", 1))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated payload header")
- return build_ike(ctx['id'], next=128, ike=struct.pack(">B", 1))
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too small payload header length")
- ike = struct.pack(">BBH", 0, 0, 3)
- return build_ike(ctx['id'], next=128, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too large payload header length")
- ike = struct.pack(">BBH", 0, 0, 5)
- return build_ike(ctx['id'], next=128, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported payload (non-critical and critical)")
- ike = struct.pack(">BBHBBH", 129, 0, 4, 0, 0x01, 4)
- return build_ike(ctx['id'], next=128, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Certificate and empty SAi1")
- ike = struct.pack(">BBHBBH", 33, 0, 4, 0, 0, 4)
- return build_ike(ctx['id'], next=37, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short proposal")
- ike = struct.pack(">BBHBBHBBB", 0, 0, 4 + 7,
- 0, 0, 7, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too small proposal length in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 7, 0, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too large proposal length in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 9, 0, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected proposal type in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 1, 0, 8, 0, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Protocol ID in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 8, 0, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected proposal number in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 8, 0, 1, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Not enough room for SPI in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 8, 1, 1, 1, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected SPI in SAi1")
- ike = struct.pack(">BBHBBHBBBBB", 0, 0, 4 + 9,
- 0, 0, 9, 1, 1, 1, 0, 1)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No transforms in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 8, 1, 1, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short transform in SAi1")
- ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
- 0, 0, 8, 1, 1, 0, 1)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too small transform length in SAi1")
- ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
- 0, 0, 8 + 8, 1, 1, 0, 1,
- 0, 0, 7, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too large transform length in SAi1")
- ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
- 0, 0, 8 + 8, 1, 1, 0, 1,
- 0, 0, 9, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Transform type in SAi1")
- ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
- 0, 0, 8 + 8, 1, 1, 0, 1,
- 1, 0, 8, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No transform attributes in SAi1")
- ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
- 0, 0, 8 + 8, 1, 1, 0, 1,
- 0, 0, 8, 0, 0, 0)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No transform attr for AES and unexpected data after transforms in SAi1")
- tlen1 = 8 + 3
- tlen2 = 8 + 4
- tlen3 = 8 + 4
- tlen = tlen1 + tlen2 + tlen3
- ike = struct.pack(">BBHBBHBBBBBBHBBH3BBBHBBHHHBBHBBHHHB",
- 0, 0, 4 + 8 + tlen + 1,
- 0, 0, 8 + tlen + 1, 1, 1, 0, 3,
- 3, 0, tlen1, 1, 0, 12, 1, 2, 3,
- 3, 0, tlen2, 1, 0, 12, 0, 128,
- 0, 0, tlen3, 1, 0, 12, 0x8000 | 14, 127,
- 1)
- return build_ike(ctx['id'], next=33, ike=ike)
- def build_sa(next=0):
- tlen = 5 * 8
- return struct.pack(">BBHBBHBBBBBBHBBHBBHBBHBBHBBHBBHBBHBBHBBH",
- next, 0, 4 + 8 + tlen,
- 0, 0, 8 + tlen, 1, 1, 0, 5,
- 3, 0, 8, 1, 0, 3,
- 3, 0, 8, 2, 0, 1,
- 3, 0, 8, 3, 0, 1,
- 3, 0, 8, 4, 0, 5,
- 0, 0, 8, 241, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid proposal, but no KEi in SAi1")
- ike = build_sa()
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Empty KEi in SAi1")
- ike = build_sa(next=34) + struct.pack(">BBH", 0, 0, 4)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Mismatch in DH Group in SAi1")
- ike = build_sa(next=34)
- ike += struct.pack(">BBHHH", 0, 0, 4 + 4 + 96, 12345, 0)
- ike += 96*'\x00'
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid DH public value length in SAi1")
- ike = build_sa(next=34)
- ike += struct.pack(">BBHHH", 0, 0, 4 + 4 + 96, 5, 0)
- ike += 96*'\x00'
- return build_ike(ctx['id'], next=33, ike=ike)
- def build_ke(next=0):
- ke = struct.pack(">BBHHH", next, 0, 4 + 4 + 192, 5, 0)
- ke += 192*'\x00'
- return ke
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid proposal and KEi, but no Ni in SAi1")
- ike = build_sa(next=34)
- ike += build_ke()
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short Ni in SAi1")
- ike = build_sa(next=34)
- ike += build_ke(next=40)
- ike += struct.pack(">BBH", 0, 0, 4)
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too long Ni in SAi1")
- ike = build_sa(next=34)
- ike += build_ke(next=40)
- ike += struct.pack(">BBH", 0, 0, 4 + 257) + 257*'\x00'
- return build_ike(ctx['id'], next=33, ike=ike)
- def build_ni(next=0):
- return struct.pack(">BBH", next, 0, 4 + 256) + 256*'\x00'
- def build_sai1(id):
- ike = build_sa(next=34)
- ike += build_ke(next=40)
- ike += build_ni()
- return build_ike(ctx['id'], next=33, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
- return build_sai1(ctx['id'])
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
- return build_sai1(ctx['id'])
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No integrity checksum")
- ike = ''
- return build_ike(ctx['id'], next=37, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
- return build_sai1(ctx['id'])
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated integrity checksum")
- return struct.pack(">BBHBB",
- EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_IKEV2, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
- return build_sai1(ctx['id'])
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid integrity checksum")
- ike = ''
- return build_ike(ctx['id'], next=37, flags=0x20, ike=ike)
- idx += 1
- if ctx['num'] == idx:
- logger.info("No more test responses available - test case completed")
- global eap_proto_ikev2_test_done
- eap_proto_ikev2_test_done = True
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_IKEV2)
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(ikev2_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_ikev2_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="IKEV2", identity="user",
- password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP method start")
- if i in [ 41, 46 ]:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- else:
- time.sleep(0.05)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- dev[0].dump_monitor()
- dev[1].dump_monitor()
- dev[2].dump_monitor()
- finally:
- stop_radius_server(srv)
- def NtPasswordHash(password):
- pw = password.encode('utf_16_le')
- return hashlib.new('md4', pw).digest()
- def HashNtPasswordHash(password_hash):
- return hashlib.new('md4', password_hash).digest()
- def ChallengeHash(peer_challenge, auth_challenge, username):
- data = peer_challenge + auth_challenge + username
- return hashlib.sha1(data).digest()[0:8]
- def GenerateAuthenticatorResponse(password, nt_response, peer_challenge,
- auth_challenge, username):
- magic1 = binascii.unhexlify("4D616769632073657276657220746F20636C69656E74207369676E696E6720636F6E7374616E74")
- magic2 = binascii.unhexlify("50616420746F206D616B6520697420646F206D6F7265207468616E206F6E6520697465726174696F6E")
- password_hash = NtPasswordHash(password)
- password_hash_hash = HashNtPasswordHash(password_hash)
- data = password_hash_hash + nt_response + magic1
- digest = hashlib.sha1(data).digest()
- challenge = ChallengeHash(peer_challenge, auth_challenge, username)
- data = digest + challenge + magic2
- resp = hashlib.sha1(data).digest()
- return resp
- def test_eap_proto_ikev2_errors(dev, apdev):
- """EAP-IKEv2 local error cases"""
- check_eap_capa(dev[0], "IKEV2")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 5):
- with alloc_fail(dev[0], i, "eap_ikev2_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="IKEV2", identity="ikev2 user",
- password="ike password",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "ikev2_encr_encrypt"),
- (1, "ikev2_encr_decrypt"),
- (1, "ikev2_derive_auth_data"),
- (2, "ikev2_derive_auth_data"),
- (1, "=ikev2_decrypt_payload"),
- (1, "ikev2_encr_decrypt;ikev2_decrypt_payload"),
- (1, "ikev2_encr_encrypt;ikev2_build_encrypted"),
- (1, "ikev2_derive_sk_keys"),
- (2, "ikev2_derive_sk_keys"),
- (3, "ikev2_derive_sk_keys"),
- (4, "ikev2_derive_sk_keys"),
- (5, "ikev2_derive_sk_keys"),
- (6, "ikev2_derive_sk_keys"),
- (7, "ikev2_derive_sk_keys"),
- (8, "ikev2_derive_sk_keys"),
- (1, "eap_ikev2_derive_keymat;eap_ikev2_peer_keymat"),
- (1, "eap_msg_alloc;eap_ikev2_build_msg"),
- (1, "eap_ikev2_getKey"),
- (1, "eap_ikev2_get_emsk"),
- (1, "eap_ikev2_get_session_id"),
- (1, "=ikev2_derive_keys"),
- (2, "=ikev2_derive_keys"),
- (1, "wpabuf_alloc;ikev2_process_kei"),
- (1, "=ikev2_process_idi"),
- (1, "ikev2_derive_auth_data;ikev2_build_auth"),
- (1, "wpabuf_alloc;ikev2_build_sa_init"),
- (2, "wpabuf_alloc;ikev2_build_sa_init"),
- (3, "wpabuf_alloc;ikev2_build_sa_init"),
- (4, "wpabuf_alloc;ikev2_build_sa_init"),
- (5, "wpabuf_alloc;ikev2_build_sa_init"),
- (6, "wpabuf_alloc;ikev2_build_sa_init"),
- (1, "wpabuf_alloc;ikev2_build_sa_auth"),
- (2, "wpabuf_alloc;ikev2_build_sa_auth"),
- (1, "ikev2_build_auth;ikev2_build_sa_auth") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="IKEV2", identity="ikev2 user@domain",
- password="ike password", erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_ALLOC_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No allocation failure seen for %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "wpabuf_alloc;ikev2_build_notify"),
- (2, "wpabuf_alloc;ikev2_build_notify"),
- (1, "ikev2_build_encrypted;ikev2_build_notify") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="IKEV2", identity="ikev2 user",
- password="wrong password", erp="1",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_ALLOC_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No allocation failure seen for %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "ikev2_integ_hash"),
- (1, "ikev2_integ_hash;ikev2_decrypt_payload"),
- (1, "os_get_random;ikev2_build_encrypted"),
- (1, "ikev2_prf_plus;ikev2_derive_sk_keys"),
- (1, "eap_ikev2_derive_keymat;eap_ikev2_peer_keymat"),
- (1, "os_get_random;ikev2_build_sa_init"),
- (2, "os_get_random;ikev2_build_sa_init"),
- (1, "ikev2_integ_hash;eap_ikev2_validate_icv"),
- (1, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_keys"),
- (1, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_auth_data"),
- (2, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_auth_data"),
- (3, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_auth_data") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="IKEV2", identity="ikev2 user",
- password="ike password", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No failure seen for %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- params = { "ssid": "eap-test2", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
- "rsn_pairwise": "CCMP", "ieee8021x": "1",
- "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
- "fragment_size": "50" }
- hostapd.add_ap(apdev[1], params)
- tests = [ (1, "eap_ikev2_build_frag_ack"),
- (1, "wpabuf_alloc;eap_ikev2_process_fragment") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test2", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="IKEV2", identity="ikev2 user",
- password="ike password", erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_ALLOC_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No allocation failure seen for %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_proto_mschapv2(dev, apdev):
- """EAP-MSCHAPv2 protocol tests"""
- check_eap_capa(dev[0], "MSCHAPV2")
- def mschapv2_handler(ctx, req):
- logger.info("mschapv2_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_MSCHAPV2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unknown MSCHAPv2 op_code")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1,
- EAP_TYPE_MSCHAPV2,
- 0, 0, 5, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid ms_len and unknown MSCHAPv2 op_code")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1,
- EAP_TYPE_MSCHAPV2,
- 255, 0, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Success before challenge")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1,
- EAP_TYPE_MSCHAPV2,
- 3, 0, 5, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure before challenge - required challenge field not present")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1,
- EAP_TYPE_MSCHAPV2,
- 4, 0, 5, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure before challenge - invalid failure challenge len")
- payload = 'C=12'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure before challenge - invalid failure challenge len")
- payload = 'C=12 V=3'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure before challenge - invalid failure challenge")
- payload = 'C=00112233445566778899aabbccddeefQ '
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure before challenge - password expired")
- payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Success after password change")
- payload = "S=1122334455667788990011223344556677889900"
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 3, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid challenge length")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short challenge packet")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1, 16)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1 + 16 + 6,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure - password expired")
- payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Success after password change")
- if len(req) != 591:
- logger.info("Unexpected Change-Password packet length: %s" % len(req))
- return None
- data = req[9:]
- enc_pw = data[0:516]
- data = data[516:]
- enc_hash = data[0:16]
- data = data[16:]
- peer_challenge = data[0:16]
- data = data[16:]
- # Reserved
- data = data[8:]
- nt_response = data[0:24]
- data = data[24:]
- flags = data
- logger.info("enc_hash: " + enc_hash.encode("hex"))
- logger.info("peer_challenge: " + peer_challenge.encode("hex"))
- logger.info("nt_response: " + nt_response.encode("hex"))
- logger.info("flags: " + flags.encode("hex"))
- auth_challenge = binascii.unhexlify("00112233445566778899aabbccddeeff")
- logger.info("auth_challenge: " + auth_challenge.encode("hex"))
- auth_resp = GenerateAuthenticatorResponse("new-pw", nt_response,
- peer_challenge,
- auth_challenge, "user")
- payload = "S=" + auth_resp.encode('hex').upper()
- logger.info("Success message payload: " + payload)
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 3, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure - password expired")
- payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Success after password change")
- if len(req) != 591:
- logger.info("Unexpected Change-Password packet length: %s" % len(req))
- return None
- data = req[9:]
- enc_pw = data[0:516]
- data = data[516:]
- enc_hash = data[0:16]
- data = data[16:]
- peer_challenge = data[0:16]
- data = data[16:]
- # Reserved
- data = data[8:]
- nt_response = data[0:24]
- data = data[24:]
- flags = data
- logger.info("enc_hash: " + enc_hash.encode("hex"))
- logger.info("peer_challenge: " + peer_challenge.encode("hex"))
- logger.info("nt_response: " + nt_response.encode("hex"))
- logger.info("flags: " + flags.encode("hex"))
- auth_challenge = binascii.unhexlify("00112233445566778899aabbccddeeff")
- logger.info("auth_challenge: " + auth_challenge.encode("hex"))
- auth_resp = GenerateAuthenticatorResponse("new-pw", nt_response,
- peer_challenge,
- auth_challenge, "user")
- payload = "S=" + auth_resp.encode('hex').upper()
- logger.info("Success message payload: " + payload)
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 3, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1 + 16 + 6,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure - authentication failure")
- payload = 'E=691 R=1 C=00112233445566778899aabbccddeeff V=3 M=Authentication failed'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1 + 16 + 6,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure - authentication failure")
- payload = 'E=691 R=1 C=00112233445566778899aabbccddeeff V=3 M=Authentication failed (2)'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Challenge - invalid ms_len and workaround disabled")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1 + 16 + 6,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1 + 16 + 6 + 1, 16) + 16*'A' + 'foobar'
- return None
- srv = start_radius_server(mschapv2_handler)
- try:
- hapd = start_ap(apdev[0])
- for i in range(0, 16):
- logger.info("RUN: %d" % i)
- if i == 12:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
- wait_connect=False)
- elif i == 14:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- phase2="mschapv2_retry=0",
- password="password", wait_connect=False)
- elif i == 15:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- eap_workaround="0",
- password="password", wait_connect=False)
- else:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- password="password", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if i in [ 8, 11, 12 ]:
- ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on new password request")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
- if i in [ 11, 12 ]:
- ev = dev[0].wait_event(["CTRL-EVENT-PASSWORD-CHANGED"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on password change")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP success")
- else:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- if i in [ 13 ]:
- ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on identity request")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-IDENTITY-" + id + ":user")
- ev = dev[0].wait_event(["CTRL-REQ-PASSWORD"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on password request")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-PASSWORD-" + id + ":password")
- # TODO: Does this work correctly?
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- if i in [ 4, 5, 6, 7, 14 ]:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
- timeout=10)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- else:
- time.sleep(0.05)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- finally:
- stop_radius_server(srv)
- def test_eap_proto_mschapv2_errors(dev, apdev):
- """EAP-MSCHAPv2 protocol tests (error paths)"""
- check_eap_capa(dev[0], "MSCHAPV2")
- def mschapv2_fail_password_expired(ctx):
- logger.info("Test: Failure before challenge - password expired")
- payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 4, 0, 4 + len(payload)) + payload
- def mschapv2_success_after_password_change(ctx, req=None):
- logger.info("Test: Success after password change")
- if req is None or len(req) != 591:
- payload = "S=1122334455667788990011223344556677889900"
- else:
- data = req[9:]
- enc_pw = data[0:516]
- data = data[516:]
- enc_hash = data[0:16]
- data = data[16:]
- peer_challenge = data[0:16]
- data = data[16:]
- # Reserved
- data = data[8:]
- nt_response = data[0:24]
- data = data[24:]
- flags = data
- logger.info("enc_hash: " + enc_hash.encode("hex"))
- logger.info("peer_challenge: " + peer_challenge.encode("hex"))
- logger.info("nt_response: " + nt_response.encode("hex"))
- logger.info("flags: " + flags.encode("hex"))
- auth_challenge = binascii.unhexlify("00112233445566778899aabbccddeeff")
- logger.info("auth_challenge: " + auth_challenge.encode("hex"))
- auth_resp = GenerateAuthenticatorResponse("new-pw", nt_response,
- peer_challenge,
- auth_challenge, "user")
- payload = "S=" + auth_resp.encode('hex').upper()
- return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + len(payload),
- EAP_TYPE_MSCHAPV2,
- 3, 0, 4 + len(payload)) + payload
- def mschapv2_handler(ctx, req):
- logger.info("mschapv2_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_fail_password_expired(ctx)
- idx += 1
- if ctx['num'] == idx:
- return mschapv2_success_after_password_change(ctx, req)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return None
- srv = start_radius_server(mschapv2_handler)
- try:
- hapd = start_ap(apdev[0])
- tests = [ "os_get_random;eap_mschapv2_change_password",
- "generate_nt_response;eap_mschapv2_change_password",
- "get_master_key;eap_mschapv2_change_password",
- "nt_password_hash;eap_mschapv2_change_password",
- "old_nt_password_hash_encrypted_with_new_nt_password_hash" ]
- for func in tests:
- with fail_test(dev[0], 1, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- password="password", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"], timeout=10)
- if ev is None:
- raise Exception("Timeout on new password request")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- tests = [ "encrypt_pw_block_with_password_hash;eap_mschapv2_change_password",
- "nt_password_hash;eap_mschapv2_change_password",
- "nt_password_hash;eap_mschapv2_success" ]
- for func in tests:
- with fail_test(dev[0], 1, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"], timeout=10)
- if ev is None:
- raise Exception("Timeout on new password request")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- tests = [ "eap_msg_alloc;eap_mschapv2_change_password" ]
- for func in tests:
- with alloc_fail(dev[0], 1, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- password="password", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"], timeout=10)
- if ev is None:
- raise Exception("Timeout on new password request")
- id = ev.split(':')[0].split('-')[-1]
- dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
- time.sleep(0.1)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- finally:
- stop_radius_server(srv)
- def test_eap_proto_pwd(dev, apdev):
- """EAP-pwd protocol tests"""
- check_eap_capa(dev[0], "PWD")
- global eap_proto_pwd_test_done, eap_proto_pwd_test_wait
- eap_proto_pwd_test_done = False
- eap_proto_pwd_test_wait = False
- def pwd_handler(ctx, req):
- logger.info("pwd_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- global eap_proto_pwd_test_wait
- eap_proto_pwd_test_wait = False
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing payload")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'], 4 + 1,
- EAP_TYPE_PWD)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing Total-Length field")
- payload = struct.pack("B", 0x80)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too large Total-Length")
- payload = struct.pack(">BH", 0x80, 65535)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: First fragment")
- payload = struct.pack(">BH", 0xc0, 10)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Total-Length value in the second fragment")
- payload = struct.pack(">BH", 0x80, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: First and only fragment")
- payload = struct.pack(">BH", 0x80, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: First and only fragment with extra data")
- payload = struct.pack(">BHB", 0x80, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: First fragment")
- payload = struct.pack(">BHB", 0xc0, 2, 1)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Extra data in the second fragment")
- payload = struct.pack(">BBB", 0x0, 2, 3)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short id exchange")
- payload = struct.pack(">B", 0x01)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported rand func in id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 0, 0, 0, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported prf in id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 0, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unsupported password pre-processing technique in id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 255)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Valid id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected commit exchange")
- payload = struct.pack(">B", 0x02)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Valid id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Commit payload length")
- payload = struct.pack(">B", 0x02)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Valid id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Commit payload with all zeros values --> Shared key at infinity")
- payload = struct.pack(">B", 0x02) + 96*'\0'
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Valid id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Commit payload with valid values")
- element = binascii.unhexlify("8dcab2862c5396839a6bac0c689ff03d962863108e7c275bbf1d6eedf634ee832a214db99f0d0a1a6317733eecdd97f0fc4cda19f57e1bb9bb9c8dcf8c60ba6f")
- scalar = binascii.unhexlify("450f31e058cf2ac2636a5d6e2b3c70b1fcc301957f0716e77f13aa69f9a2e5bd")
- payload = struct.pack(">B", 0x02) + element + scalar
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Confirm payload length 0")
- payload = struct.pack(">B", 0x03)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Valid id exchange")
- payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- eap_proto_pwd_test_wait = True
- logger.info("Test: Commit payload with valid values")
- element = binascii.unhexlify("8dcab2862c5396839a6bac0c689ff03d962863108e7c275bbf1d6eedf634ee832a214db99f0d0a1a6317733eecdd97f0fc4cda19f57e1bb9bb9c8dcf8c60ba6f")
- scalar = binascii.unhexlify("450f31e058cf2ac2636a5d6e2b3c70b1fcc301957f0716e77f13aa69f9a2e5bd")
- payload = struct.pack(">B", 0x02) + element + scalar
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Confirm payload with incorrect value")
- payload = struct.pack(">B", 0x03) + 32*'\0'
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected confirm exchange")
- payload = struct.pack(">B", 0x03)
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
- logger.info("No more test responses available - test case completed")
- global eap_proto_pwd_test_done
- eap_proto_pwd_test_done = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(pwd_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_pwd_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- ok = False
- for j in range(5):
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
- "CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if "CTRL-EVENT-EAP-PROPOSED-METHOD" in ev:
- ok = True
- break
- if "CTRL-EVENT-EAP-STATUS" in ev and "status='completion' parameter='failure'" in ev:
- ok = True
- break
- if not ok:
- raise Exception("Expected EAP event not seen")
- if eap_proto_pwd_test_wait:
- for k in range(10):
- time.sleep(0.1)
- if not eap_proto_pwd_test_wait:
- break
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_pwd_errors(dev, apdev):
- """EAP-pwd local error cases"""
- check_eap_capa(dev[0], "PWD")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 4):
- with alloc_fail(dev[0], i, "eap_pwd_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "eap_pwd_get_session_id"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- fragment_size="0",
- password="secret password")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- funcs = [ "eap_pwd_getkey", "eap_pwd_get_emsk" ]
- for func in funcs:
- with alloc_fail(dev[0], 1, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user@domain",
- password="secret password", erp="1",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- for i in range(1, 7):
- with alloc_fail(dev[0], i, "eap_pwd_perform_id_exchange"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_ALLOC_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No allocation failure seen")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1, "wpabuf_alloc;eap_pwd_perform_id_exchange"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- for i in range(1, 4):
- with alloc_fail(dev[0], i, "eap_pwd_perform_commit_exchange"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_ALLOC_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No allocation failure seen")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- for i in range(1, 12):
- with alloc_fail(dev[0], i, "eap_pwd_perform_confirm_exchange"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ok = False
- for j in range(10):
- state = dev[0].request('GET_ALLOC_FAIL')
- if state.startswith('0:'):
- ok = True
- break
- time.sleep(0.1)
- if not ok:
- raise Exception("No allocation failure seen")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- for i in range(1, 5):
- with alloc_fail(dev[0], i, "eap_msg_alloc;=eap_pwd_process"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password", fragment_size="50",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- # No password configured
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=52"],
- timeout=15)
- if ev is None:
- raise Exception("EAP-pwd not started")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with fail_test(dev[0], 1,
- "hash_nt_password_hash;eap_pwd_perform_id_exchange"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd-hash",
- password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
- if ev is None:
- raise Exception("No EAP-Failure reported")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- params = { "ssid": "eap-test2", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
- "rsn_pairwise": "CCMP", "ieee8021x": "1",
- "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
- "pwd_group": "19", "fragment_size": "40" }
- hostapd.add_ap(apdev[1], params)
- with alloc_fail(dev[0], 1, "wpabuf_alloc;=eap_pwd_process"):
- dev[0].connect("eap-test2", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PWD", identity="pwd user",
- password="secret password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_proto_erp(dev, apdev):
- """ERP protocol tests"""
- check_erp_capa(dev[0])
- global eap_proto_erp_test_done
- eap_proto_erp_test_done = False
- def erp_handler(ctx, req):
- logger.info("erp_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing type")
- return struct.pack(">BBH", EAP_CODE_INITIATE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected type")
- return struct.pack(">BBHB", EAP_CODE_INITIATE, ctx['id'], 4 + 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing Reserved field")
- return struct.pack(">BBHB", EAP_CODE_INITIATE, ctx['id'], 4 + 1,
- EAP_ERP_TYPE_REAUTH_START)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Zero-length TVs/TLVs")
- payload = ""
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short TLV")
- payload = struct.pack("B", 191)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated TLV")
- payload = struct.pack("BB", 191, 1)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Ignored unknown TLV and unknown TV/TLV terminating parsing")
- payload = struct.pack("BBB", 191, 0, 192)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: More than one keyName-NAI")
- payload = struct.pack("BBBB", EAP_ERP_TLV_KEYNAME_NAI, 0,
- EAP_ERP_TLV_KEYNAME_NAI, 0)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too short TLV keyName-NAI")
- payload = struct.pack("B", EAP_ERP_TLV_KEYNAME_NAI)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Truncated TLV keyName-NAI")
- payload = struct.pack("BB", EAP_ERP_TLV_KEYNAME_NAI, 1)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid rRK lifetime TV followed by too short rMSK lifetime TV")
- payload = struct.pack(">BLBH", EAP_ERP_TV_RRK_LIFETIME, 0,
- EAP_ERP_TV_RMSK_LIFETIME, 0)
- return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_ERP_TYPE_REAUTH_START, 0) + payload
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing type (Finish)")
- return struct.pack(">BBH", EAP_CODE_FINISH, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected type (Finish)")
- return struct.pack(">BBHB", EAP_CODE_FINISH, ctx['id'], 4 + 1,
- 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing fields (Finish)")
- return struct.pack(">BBHB", EAP_CODE_FINISH, ctx['id'], 4 + 1,
- EAP_ERP_TYPE_REAUTH)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected SEQ (Finish)")
- return struct.pack(">BBHBBHB", EAP_CODE_FINISH, ctx['id'],
- 4 + 1 + 4,
- EAP_ERP_TYPE_REAUTH, 0, 0xffff, 0)
- logger.info("No more test responses available - test case completed")
- global eap_proto_erp_test_done
- eap_proto_erp_test_done = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(erp_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_erp_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PAX", identity="pax.user@example.com",
- password_hex="0123456789abcdef0123456789abcdef",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_fast_errors(dev, apdev):
- """EAP-FAST local error cases"""
- check_eap_capa(dev[0], "FAST")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 5):
- with alloc_fail(dev[0], i, "eap_fast_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
- phase1="fast_provisioning=2",
- pac_file="blob://fast_pac_auth",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "wpabuf_alloc;eap_fast_tlv_eap_payload"),
- (1, "eap_fast_derive_key;eap_fast_derive_key_auth"),
- (1, "eap_msg_alloc;eap_peer_tls_phase2_nak"),
- (1, "wpabuf_alloc;eap_fast_tlv_result"),
- (1, "wpabuf_alloc;eap_fast_tlv_pac_ack"),
- (1, "=eap_peer_tls_derive_session_id;eap_fast_process_crypto_binding"),
- (1, "eap_peer_tls_decrypt;eap_fast_decrypt"),
- (1, "eap_fast_getKey"),
- (1, "eap_fast_get_session_id"),
- (1, "eap_fast_get_emsk") ]
- for count, func in tests:
- dev[0].request("SET blob fast_pac_auth_errors ")
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user@example.com", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
- phase1="fast_provisioning=2",
- pac_file="blob://fast_pac_auth_errors",
- erp="1",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "eap_fast_derive_key;eap_fast_derive_key_provisioning"),
- (1, "eap_mschapv2_getKey;eap_fast_get_phase2_key"),
- (1, "=eap_fast_use_pac_opaque"),
- (1, "eap_fast_copy_buf"),
- (1, "=eap_fast_add_pac"),
- (1, "=eap_fast_init_pac_data"),
- (1, "=eap_fast_write_pac"),
- (2, "=eap_fast_write_pac") ]
- for count, func in tests:
- dev[0].request("SET blob fast_pac_errors ")
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- phase1="fast_provisioning=1",
- pac_file="blob://fast_pac_errors",
- erp="1",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "eap_fast_get_cmk;eap_fast_process_crypto_binding"),
- (1, "eap_fast_derive_eap_msk;eap_fast_process_crypto_binding"),
- (1, "eap_fast_derive_eap_emsk;eap_fast_process_crypto_binding") ]
- for count, func in tests:
- dev[0].request("SET blob fast_pac_auth_errors ")
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
- phase1="fast_provisioning=2",
- pac_file="blob://fast_pac_auth_errors",
- erp="1",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- dev[0].request("SET blob fast_pac_errors ")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
- phase1="fast_provisioning=1",
- pac_file="blob://fast_pac_errors",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- # EAP-FAST: Only EAP-MSCHAPv2 is allowed during unauthenticated
- # provisioning; reject phase2 type 6
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- logger.info("Wrong password in Phase 2")
- dev[0].request("SET blob fast_pac_errors ")
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="wrong password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- phase1="fast_provisioning=1",
- pac_file="blob://fast_pac_errors",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ "FOOBAR\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nFOOBAR\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nSTART\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Type=12345\nEND\n"
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Key=12\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Key=1\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Key=1q\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Opaque=1\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nA-ID=1\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nI-ID=1\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nA-ID-Info=1\nEND\n" ]
- for pac in tests:
- blob = binascii.hexlify(pac)
- dev[0].request("SET blob fast_pac_errors " + blob)
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
- phase1="fast_provisioning=2",
- pac_file="blob://fast_pac_errors",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nEND\n",
- "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nEND\nSTART\nEND\nSTART\nEND\n" ]
- for pac in tests:
- blob = binascii.hexlify(pac)
- dev[0].request("SET blob fast_pac_errors " + blob)
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
- phase1="fast_provisioning=2",
- pac_file="blob://fast_pac_errors")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- dev[0].request("SET blob fast_pac_errors ")
- def test_eap_proto_peap_errors(dev, apdev):
- """EAP-PEAP local error cases"""
- check_eap_capa(dev[0], "PEAP")
- check_eap_capa(dev[0], "MSCHAPV2")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 5):
- with alloc_fail(dev[0], i, "eap_peap_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PEAP", anonymous_identity="peap",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "eap_mschapv2_getKey;eap_peap_get_isk;eap_peap_derive_cmk"),
- (1, "eap_msg_alloc;eap_tlv_build_result"),
- (1, "eap_mschapv2_init;eap_peap_phase2_request"),
- (1, "eap_peer_tls_decrypt;eap_peap_decrypt"),
- (1, "wpabuf_alloc;=eap_peap_decrypt"),
- (1, "eap_peer_tls_encrypt;eap_peap_decrypt"),
- (1, "eap_peer_tls_process_helper;eap_peap_process"),
- (1, "eap_peer_tls_derive_key;eap_peap_process"),
- (1, "eap_peer_tls_derive_session_id;eap_peap_process"),
- (1, "eap_peap_getKey"),
- (1, "eap_peap_get_session_id") ]
- for count, func in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PEAP", anonymous_identity="peap",
- identity="user", password="password",
- phase1="peapver=0 crypto_binding=2",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "peap_prfplus;eap_peap_derive_cmk"),
- (1, "eap_tlv_add_cryptobinding;eap_tlv_build_result"),
- (1, "peap_prfplus;eap_peap_getKey") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PEAP", anonymous_identity="peap",
- identity="user", password="password",
- phase1="peapver=0 crypto_binding=2",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- with alloc_fail(dev[0], 1,
- "eap_peer_tls_phase2_nak;eap_peap_phase2_request"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="PEAP", anonymous_identity="peap",
- identity="cert user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_proto_ttls_errors(dev, apdev):
- """EAP-TTLS local error cases"""
- check_eap_capa(dev[0], "TTLS")
- check_eap_capa(dev[0], "MSCHAPV2")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- for i in range(1, 5):
- with alloc_fail(dev[0], i, "eap_ttls_init"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="TTLS", anonymous_identity="ttls",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem",
- phase2="autheap=MSCHAPV2",
- wait_connect=False)
- ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
- timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "eap_peer_tls_derive_key;eap_ttls_v0_derive_key",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_peer_tls_derive_session_id;eap_ttls_v0_derive_key",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "wpabuf_alloc;eap_ttls_phase2_request_mschapv2",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_peer_tls_derive_key;eap_ttls_phase2_request_mschapv2",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_peer_tls_encrypt;eap_ttls_encrypt_response;eap_ttls_implicit_identity_request",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_peer_tls_decrypt;eap_ttls_decrypt",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_ttls_getKey",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_ttls_get_session_id",
- "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
- (1, "eap_ttls_get_emsk",
- "mschapv2 user@domain", "auth=MSCHAPV2"),
- (1, "wpabuf_alloc;eap_ttls_phase2_request_mschap",
- "mschap user", "auth=MSCHAP"),
- (1, "eap_peer_tls_derive_key;eap_ttls_phase2_request_mschap",
- "mschap user", "auth=MSCHAP"),
- (1, "wpabuf_alloc;eap_ttls_phase2_request_chap",
- "chap user", "auth=CHAP"),
- (1, "eap_peer_tls_derive_key;eap_ttls_phase2_request_chap",
- "chap user", "auth=CHAP"),
- (1, "wpabuf_alloc;eap_ttls_phase2_request_pap",
- "pap user", "auth=PAP"),
- (1, "wpabuf_alloc;eap_ttls_avp_encapsulate",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_mschapv2_init;eap_ttls_phase2_request_eap_method",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_sm_buildIdentity;eap_ttls_phase2_request_eap",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_ttls_avp_encapsulate;eap_ttls_phase2_request_eap",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_ttls_parse_attr_eap",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_peer_tls_encrypt;eap_ttls_encrypt_response;eap_ttls_process_decrypted",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_ttls_fake_identity_request",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_msg_alloc;eap_tls_process_output",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_msg_alloc;eap_peer_tls_build_ack",
- "user", "autheap=MSCHAPV2"),
- (1, "tls_connection_decrypt;eap_peer_tls_decrypt",
- "user", "autheap=MSCHAPV2"),
- (1, "eap_peer_tls_phase2_nak;eap_ttls_phase2_request_eap_method",
- "cert user", "autheap=MSCHAPV2") ]
- for count, func, identity, phase2 in tests:
- with alloc_fail(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="TTLS", anonymous_identity="ttls",
- identity=identity, password="password",
- ca_cert="auth_serv/ca.pem", phase2=phase2,
- erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
- note="Allocation failure not triggered for: %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "os_get_random;eap_ttls_phase2_request_mschapv2"),
- (1, "mschapv2_derive_response;eap_ttls_phase2_request_mschapv2") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="TTLS", anonymous_identity="ttls",
- identity="DOMAIN\mschapv2 user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_FAIL",
- note="Test failure not triggered for: %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- tests = [ (1, "nt_challenge_response;eap_ttls_phase2_request_mschap") ]
- for count, func in tests:
- with fail_test(dev[0], count, func):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="TTLS", anonymous_identity="ttls",
- identity="mschap user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
- erp="1", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP start")
- wait_fail_trigger(dev[0], "GET_FAIL",
- note="Test failure not triggered for: %d:%s" % (count, func))
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_proto_expanded(dev, apdev):
- """EAP protocol tests with expanded header"""
- global eap_proto_expanded_test_done
- eap_proto_expanded_test_done = False
- def expanded_handler(ctx, req):
- logger.info("expanded_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MD5 challenge in expanded header")
- return struct.pack(">BBHB3BLBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 3,
- EAP_TYPE_EXPANDED, 0, 0, 0, EAP_TYPE_MD5,
- 1, 0xaa, ord('n'))
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid expanded EAP length")
- return struct.pack(">BBHB3BH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 2,
- EAP_TYPE_EXPANDED, 0, 0, 0, EAP_TYPE_MD5)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid expanded frame type")
- return struct.pack(">BBHB3BL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_EXPANDED, 0, 0, 1, EAP_TYPE_MD5)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: MSCHAPv2 Challenge")
- return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 4 + 1 + 16 + 6,
- EAP_TYPE_MSCHAPV2,
- 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid expanded frame type")
- return struct.pack(">BBHB3BL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4,
- EAP_TYPE_EXPANDED, 0, 0, 1, EAP_TYPE_MSCHAPV2)
- logger.info("No more test responses available - test case completed")
- global eap_proto_expanded_test_done
- eap_proto_expanded_test_done = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(expanded_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_expanded_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- if i == 4:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MSCHAPV2", identity="user",
- password="password",
- wait_connect=False)
- else:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- if i in [ 1 ]:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP method start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- elif i in [ 2, 3 ]:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
- timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP proposed method")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- else:
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_tls(dev, apdev):
- """EAP-TLS protocol tests"""
- check_eap_capa(dev[0], "TLS")
- global eap_proto_tls_test_done, eap_proto_tls_test_wait
- eap_proto_tls_test_done = False
- eap_proto_tls_test_wait = False
- def tls_handler(ctx, req):
- logger.info("tls_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- global eap_proto_tls_test_wait
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too much payload in TLS/Start: TLS Message Length (0 bytes) smaller than this fragment (1 bytes)")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_TLS, 0xa0, 0, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmented TLS/Start")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_TLS, 0xe0, 2, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too long fragment of TLS/Start: Invalid reassembly state: tls_in_left=2 tls_in_len=0 in_len=0")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2,
- EAP_TYPE_TLS, 0x00, 2, 3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TLS/Start")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TLS, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmented TLS message")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_TLS, 0xc0, 2, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid TLS message: no Flags octet included + workaround")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_TLS)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Too long fragment of TLS message: more data than TLS message length indicated")
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2,
- EAP_TYPE_TLS, 0x00, 2, 3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmented TLS/Start and truncated Message Length field")
- return struct.pack(">BBHBB3B", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 3,
- EAP_TYPE_TLS, 0xe0, 1, 2, 3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TLS/Start")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TLS, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmented TLS message")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_TLS, 0xc0, 2, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid TLS message: no Flags octet included + workaround disabled")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_TLS)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TLS/Start")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TLS, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmented TLS message (long; first)")
- payload = 1450*'A'
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + len(payload),
- EAP_TYPE_TLS, 0xc0, 65536) + payload
- # "Too long TLS fragment (size over 64 kB)" on the last one
- for i in range(44):
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmented TLS message (long; cont %d)" % i)
- eap_proto_tls_test_wait = True
- payload = 1470*'A'
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(payload),
- EAP_TYPE_TLS, 0x40) + payload
- eap_proto_tls_test_wait = False
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TLS/Start")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TLS, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Non-ACK to more-fragment message")
- return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 1,
- EAP_TYPE_TLS, 0x00, 255)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Failure")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- logger.info("No more test responses available - test case completed")
- global eap_proto_tls_test_done
- eap_proto_tls_test_done = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(tls_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_tls_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- workaround = "0" if i == 6 else "1"
- fragment_size = "100" if i == 8 else "1400"
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="TLS", identity="tls user",
- ca_cert="auth_serv/ca.pem",
- client_cert="auth_serv/user.pem",
- private_key="auth_serv/user.key",
- eap_workaround=workaround,
- fragment_size=fragment_size,
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
- "CTRL-EVENT-EAP-STATUS"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP method start")
- time.sleep(0.1)
- start = os.times()[4]
- while eap_proto_tls_test_wait:
- now = os.times()[4]
- if now - start > 10:
- break
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_tnc(dev, apdev):
- """EAP-TNC protocol tests"""
- check_eap_capa(dev[0], "TNC")
- global eap_proto_tnc_test_done
- eap_proto_tnc_test_done = False
- def tnc_handler(ctx, req):
- logger.info("tnc_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNC start with unsupported version")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x20)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNC without Flags field")
- return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1,
- EAP_TYPE_TNC)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Message underflow due to missing Message Length")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0xa1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid Message Length")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_TNC, 0xa1, 0, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid Message Length")
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_TNC, 0xe1, 75001)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Start with Message Length")
- return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4,
- EAP_TYPE_TNC, 0xa1, 1)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Server used start flag again")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragmentation and unexpected payload in ack")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x01)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 1,
- EAP_TYPE_TNC, 0x01, 0)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Server fragmenting and fragment overflow")
- return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 1,
- EAP_TYPE_TNC, 0xe1, 2, 1)
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 2,
- EAP_TYPE_TNC, 0x01, 2, 3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Server fragmenting and no message length in a fragment")
- return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 1,
- EAP_TYPE_TNC, 0x61, 2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNC start followed by invalid TNCCS-Batch")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "FOO"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNC start followed by invalid TNCCS-Batch (2)")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "</TNCCS-Batch><TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNCCS-Batch missing BatchId attribute")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch foo=3></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected IF-TNCCS BatchId")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=123456789></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing IMC-IMV-Message and TNCC-TNCS-Message end tags")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><IMC-IMV-Message><TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing IMC-IMV-Message and TNCC-TNCS-Message Type")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><IMC-IMV-Message></IMC-IMV-Message><TNCC-TNCS-Message></TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing TNCC-TNCS-Message XML end tag")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML></TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing TNCC-TNCS-Message Base64 start tag")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type></TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing TNCC-TNCS-Message Base64 end tag")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><Base64>abc</TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNCC-TNCS-Message Base64 message")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><Base64>aGVsbG8=</Base64></TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid TNCC-TNCS-Message XML message")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML>hello</XML></TNCC-TNCS-Message></TNCCS-Batch>"
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing TNCCS-Recommendation type")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = '<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML><TNCCS-Recommendation foo=1></TNCCS-Recommendation></XML></TNCC-TNCS-Message></TNCCS-Batch>'
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNCCS-Recommendation type=none")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = '<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML><TNCCS-Recommendation type="none"></TNCCS-Recommendation></XML></TNCC-TNCS-Message></TNCCS-Batch>'
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: TNCCS-Recommendation type=isolate")
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1,
- EAP_TYPE_TNC, 0x21)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Received TNCCS-Batch: " + req[6:])
- resp = '<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML><TNCCS-Recommendation type="isolate"></TNCCS-Recommendation></XML></TNCC-TNCS-Message></TNCCS-Batch>'
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(resp),
- EAP_TYPE_TNC, 0x01) + resp
- idx += 1
- if ctx['num'] == idx:
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- logger.info("No more test responses available - test case completed")
- global eap_proto_tnc_test_done
- eap_proto_tnc_test_done = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(tnc_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_tnc_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- frag = 1400
- if i == 8:
- frag = 150
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="TNC", identity="tnc", fragment_size=str(frag),
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
- "CTRL-EVENT-EAP-STATUS"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP method start")
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_canned_success_after_identity(dev, apdev):
- """EAP protocol tests for canned EAP-Success after identity"""
- check_eap_capa(dev[0], "MD5")
- def eap_canned_success_handler(ctx, req):
- logger.info("eap_canned_success_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: EAP-Success")
- return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
- return None
- srv = start_radius_server(eap_canned_success_handler)
- try:
- hapd = start_ap(apdev[0])
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- phase1="allow_canned_success=1",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
- if ev is None:
- raise Exception("Timeout on EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP start")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1)
- if ev is not None:
- raise Exception("Unexpected EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- finally:
- stop_radius_server(srv)
- def test_eap_proto_wsc(dev, apdev):
- """EAP-WSC protocol tests"""
- global eap_proto_wsc_test_done, eap_proto_wsc_wait_failure
- eap_proto_wsc_test_done = False
- def wsc_handler(ctx, req):
- logger.info("wsc_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] += 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- global eap_proto_wsc_wait_failure
- eap_proto_wsc_wait_failure = False
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Missing Flags field")
- return struct.pack(">BBHB3BLB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 1,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Message underflow (missing Message Length field)")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x02)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid Message Length (> 50000)")
- return struct.pack(">BBHB3BLBBH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 4,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x02, 65535)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Invalid Message Length (< current payload)")
- return struct.pack(">BBHB3BLBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 5,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x02, 0, 0xff)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Op-Code 5 in WAIT_START state")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 5, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid WSC Start to start the sequence")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: No Message Length field in a fragmented packet")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 4, 0x01)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid WSC Start to start the sequence")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first fragmented packet")
- return struct.pack(">BBHB3BLBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 5,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 4, 0x03, 10, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Op-Code 5 in fragment (expected 4)")
- return struct.pack(">BBHB3BLBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 3,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 5, 0x01, 2)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid WSC Start to start the sequence")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid first fragmented packet")
- return struct.pack(">BBHB3BLBBHB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 5,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 4, 0x03, 2, 1)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Fragment overflow")
- return struct.pack(">BBHB3BLBBBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 4,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 4, 0x01, 2, 3)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid WSC Start to start the sequence")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Unexpected Op-Code 5 in WAIT_FRAG_ACK state")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 5, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("Test: Valid WSC Start")
- return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 3 + 4 + 2,
- EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
- 1, 0x00)
- idx += 1
- if ctx['num'] == idx:
- logger.info("No more test responses available - test case completed")
- global eap_proto_wsc_test_done
- eap_proto_wsc_test_done = True
- eap_proto_wsc_wait_failure = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(wsc_handler)
- try:
- hapd = start_ap(apdev[0])
- i = 0
- while not eap_proto_wsc_test_done:
- i += 1
- logger.info("Running connection iteration %d" % i)
- fragment_size = 1398 if i != 9 else 50
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", eap="WSC",
- fragment_size=str(fragment_size),
- identity="WFA-SimpleConfig-Enrollee-1-0",
- phase1="pin=12345670",
- scan_freq="2412", wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP method start")
- if eap_proto_wsc_wait_failure:
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- else:
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected(timeout=1)
- dev[0].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_canned_success_before_method(dev, apdev):
- """EAP protocol tests for canned EAP-Success before any method"""
- params = int_eap_server_params()
- hapd = hostapd.add_ap(apdev[0], params)
- bssid = apdev[0]['bssid']
- hapd.request("SET ext_eapol_frame_io 1")
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412",
- phase1="allow_canned_success=1",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = hapd.wait_event(["EAPOL-TX"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAPOL-TX from hostapd")
- res = dev[0].request("EAPOL_RX " + bssid + " 0200000403020004")
- if "OK" not in res:
- raise Exception("EAPOL_RX to wpa_supplicant failed")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP success")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_canned_failure_before_method(dev, apdev):
- """EAP protocol tests for canned EAP-Failure before any method"""
- params = int_eap_server_params()
- hapd = hostapd.add_ap(apdev[0], params)
- bssid = apdev[0]['bssid']
- hapd.request("SET ext_eapol_frame_io 1")
- dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412",
- phase1="allow_canned_success=1",
- eap="MD5", identity="user", password="password",
- wait_connect=False)
- ev = hapd.wait_event(["EAPOL-TX"], timeout=10)
- if ev is None:
- raise Exception("Timeout on EAPOL-TX from hostapd")
- res = dev[0].request("EAPOL_RX " + bssid + " 0200000404020004")
- if "OK" not in res:
- raise Exception("EAPOL_RX to wpa_supplicant failed")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
- if ev is None:
- raise Exception("Timeout on EAP failure")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_nak_oom(dev, apdev):
- """EAP-Nak OOM"""
- check_eap_capa(dev[0], "MD5")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_sm_buildNak"):
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="MD5", identity="sake user", password="password",
- wait_connect=False)
- wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- def test_eap_nak_expanded(dev, apdev):
- """EAP-Nak with expanded method"""
- check_eap_capa(dev[0], "MD5")
- check_eap_capa(dev[0], "VENDOR-TEST")
- params = hostapd.wpa2_eap_params(ssid="eap-test")
- hapd = hostapd.add_ap(apdev[0], params)
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="VENDOR-TEST WSC",
- identity="sake user", password="password",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10)
- if ev is None or "NAK" not in ev:
- raise Exception("No NAK event seen")
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
- if ev is None:
- raise Exception("No EAP-Failure seen")
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- EAP_TLV_RESULT_TLV = 3
- EAP_TLV_NAK_TLV = 4
- EAP_TLV_ERROR_CODE_TLV = 5
- EAP_TLV_CONNECTION_BINDING_TLV = 6
- EAP_TLV_VENDOR_SPECIFIC_TLV = 7
- EAP_TLV_URI_TLV = 8
- EAP_TLV_EAP_PAYLOAD_TLV = 9
- EAP_TLV_INTERMEDIATE_RESULT_TLV = 10
- EAP_TLV_PAC_TLV = 11
- EAP_TLV_CRYPTO_BINDING_TLV = 12
- EAP_TLV_CALLING_STATION_ID_TLV = 13
- EAP_TLV_CALLED_STATION_ID_TLV = 14
- EAP_TLV_NAS_PORT_TYPE_TLV = 15
- EAP_TLV_SERVER_IDENTIFIER_TLV = 16
- EAP_TLV_IDENTITY_TYPE_TLV = 17
- EAP_TLV_SERVER_TRUSTED_ROOT_TLV = 18
- EAP_TLV_REQUEST_ACTION_TLV = 19
- EAP_TLV_PKCS7_TLV = 20
- EAP_TLV_RESULT_SUCCESS = 1
- EAP_TLV_RESULT_FAILURE = 2
- EAP_TLV_TYPE_MANDATORY = 0x8000
- EAP_TLV_TYPE_MASK = 0x3fff
- PAC_TYPE_PAC_KEY = 1
- PAC_TYPE_PAC_OPAQUE = 2
- PAC_TYPE_CRED_LIFETIME = 3
- PAC_TYPE_A_ID = 4
- PAC_TYPE_I_ID = 5
- PAC_TYPE_A_ID_INFO = 7
- PAC_TYPE_PAC_ACKNOWLEDGEMENT = 8
- PAC_TYPE_PAC_INFO = 9
- PAC_TYPE_PAC_TYPE = 10
- def eap_fast_start(ctx):
- logger.info("Send EAP-FAST/Start")
- return struct.pack(">BBHBBHH", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + 4 + 16,
- EAP_TYPE_FAST, 0x21, 4, 16) + 16*'A'
- def test_eap_fast_proto(dev, apdev):
- """EAP-FAST Phase protocol testing"""
- check_eap_capa(dev[0], "FAST")
- global eap_fast_proto_ctx
- eap_fast_proto_ctx = None
- def eap_handler(ctx, req):
- logger.info("eap_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- global eap_fast_proto_ctx
- eap_fast_proto_ctx = ctx
- ctx['test_done'] = False
- idx += 1
- if ctx['num'] == idx:
- return eap_fast_start(ctx)
- idx += 1
- if ctx['num'] == idx:
- logger.info("EAP-FAST: TLS processing failed")
- data = 'ABCDEFGHIK'
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(data),
- EAP_TYPE_FAST, 0x01) + data
- idx += 1
- if ctx['num'] == idx:
- ctx['test_done'] = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- logger.info("Past last test case")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(eap_handler)
- try:
- hapd = start_ap(apdev[0])
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- phase1="fast_provisioning=1",
- pac_file="blob://fast_pac_proto",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("Could not start EAP-FAST")
- ok = False
- for i in range(100):
- if eap_fast_proto_ctx:
- if eap_fast_proto_ctx['test_done']:
- ok = True
- break
- time.sleep(0.05)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- finally:
- stop_radius_server(srv)
- def run_eap_fast_phase2(dev, test_payload, test_failure=True):
- global eap_fast_proto_ctx
- eap_fast_proto_ctx = None
- def ssl_info_callback(conn, where, ret):
- logger.debug("SSL: info where=%d ret=%d" % (where, ret))
- def log_conn_state(conn):
- try:
- state = conn.state_string()
- except AttributeError:
- state = conn.get_state_string()
- if state:
- logger.info("State: " + state)
- def process_clienthello(ctx, payload):
- logger.info("Process ClientHello")
- ctx['sslctx'] = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
- ctx['sslctx'].set_info_callback(ssl_info_callback)
- ctx['sslctx'].load_tmp_dh("auth_serv/dh.conf")
- ctx['sslctx'].set_cipher_list("ADH-AES128-SHA")
- ctx['conn'] = OpenSSL.SSL.Connection(ctx['sslctx'], None)
- ctx['conn'].set_accept_state()
- log_conn_state(ctx['conn'])
- ctx['conn'].bio_write(payload)
- try:
- ctx['conn'].do_handshake()
- except OpenSSL.SSL.WantReadError:
- pass
- log_conn_state(ctx['conn'])
- data = ctx['conn'].bio_read(4096)
- log_conn_state(ctx['conn'])
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(data),
- EAP_TYPE_FAST, 0x01) + data
- def process_clientkeyexchange(ctx, payload, appl_data):
- logger.info("Process ClientKeyExchange")
- log_conn_state(ctx['conn'])
- ctx['conn'].bio_write(payload)
- try:
- ctx['conn'].do_handshake()
- except OpenSSL.SSL.WantReadError:
- pass
- ctx['conn'].send(appl_data)
- log_conn_state(ctx['conn'])
- data = ctx['conn'].bio_read(4096)
- log_conn_state(ctx['conn'])
- return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
- 4 + 1 + 1 + len(data),
- EAP_TYPE_FAST, 0x01) + data
- def eap_handler(ctx, req):
- logger.info("eap_handler - RX " + req.encode("hex"))
- if 'num' not in ctx:
- ctx['num'] = 0
- ctx['num'] = ctx['num'] + 1
- if 'id' not in ctx:
- ctx['id'] = 1
- ctx['id'] = (ctx['id'] + 1) % 256
- idx = 0
- global eap_fast_proto_ctx
- eap_fast_proto_ctx = ctx
- ctx['test_done'] = False
- logger.debug("ctx['num']=%d" % ctx['num'])
- idx += 1
- if ctx['num'] == idx:
- return eap_fast_start(ctx)
- idx += 1
- if ctx['num'] == idx:
- return process_clienthello(ctx, req[6:])
- idx += 1
- if ctx['num'] == idx:
- if not test_failure:
- ctx['test_done'] = True
- return process_clientkeyexchange(ctx, req[6:], test_payload)
- idx += 1
- if ctx['num'] == idx:
- ctx['test_done'] = True
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- logger.info("Past last test case")
- return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
- srv = start_radius_server(eap_handler)
- try:
- dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
- eap="FAST", anonymous_identity="FAST",
- identity="user", password="password",
- ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
- phase1="fast_provisioning=1",
- pac_file="blob://fast_pac_proto",
- wait_connect=False)
- ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
- if ev is None:
- raise Exception("Could not start EAP-FAST")
- dev[0].dump_monitor()
- ok = False
- for i in range(100):
- if eap_fast_proto_ctx:
- if eap_fast_proto_ctx['test_done']:
- ok = True
- break
- time.sleep(0.05)
- time.sleep(0.1)
- dev[0].request("REMOVE_NETWORK all")
- dev[0].wait_disconnected()
- if not ok:
- raise Exception("EAP-FAST TLS exchange did not complete")
- for i in range(3):
- dev[i].dump_monitor()
- finally:
- stop_radius_server(srv)
- def test_eap_fast_proto_phase2(dev, apdev):
- """EAP-FAST Phase 2 protocol testing"""
- if not openssl_imported:
- raise HwsimSkip("OpenSSL python method not available")
- check_eap_capa(dev[0], "FAST")
- hapd = start_ap(apdev[0])
- tests = [ ("Too short Phase 2 TLV frame (len=3)",
- "ABC",
- False),
- ("EAP-FAST: TLV overflow",
- struct.pack(">HHB", 0, 2, 0xff),
- False),
- ("EAP-FAST: Unknown TLV (optional and mandatory)",
- struct.pack(">HHB", 0, 1, 0xff) +
- struct.pack(">HHB", EAP_TLV_TYPE_MANDATORY, 1, 0xff),
- True),
- ("EAP-FAST: More than one EAP-Payload TLV in the message",
- struct.pack(">HHBHHB",
- EAP_TLV_EAP_PAYLOAD_TLV, 1, 0xff,
- EAP_TLV_EAP_PAYLOAD_TLV, 1, 0xff),
- True),
- ("EAP-FAST: Unknown Result 255 and More than one Result TLV in the message",
- struct.pack(">HHHHHH",
- EAP_TLV_RESULT_TLV, 2, 0xff,
- EAP_TLV_RESULT_TLV, 2, 0xff),
- True),
- ("EAP-FAST: Too short Result TLV",
- struct.pack(">HHB", EAP_TLV_RESULT_TLV, 1, 0xff),
- True),
- ("EAP-FAST: Unknown Intermediate Result 255 and More than one Intermediate-Result TLV in the message",
- struct.pack(">HHHHHH",
- EAP_TLV_INTERMEDIATE_RESULT_TLV, 2, 0xff,
- EAP_TLV_INTERMEDIATE_RESULT_TLV, 2, 0xff),
- True),
- ("EAP-FAST: Too short Intermediate-Result TLV",
- struct.pack(">HHB", EAP_TLV_INTERMEDIATE_RESULT_TLV, 1, 0xff),
- True),
- ("EAP-FAST: More than one Crypto-Binding TLV in the message",
- struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A' +
- struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A',
- True),
- ("EAP-FAST: Too short Crypto-Binding TLV",
- struct.pack(">HHB", EAP_TLV_CRYPTO_BINDING_TLV, 1, 0xff),
- True),
- ("EAP-FAST: More than one Request-Action TLV in the message",
- struct.pack(">HHBBHHBB",
- EAP_TLV_REQUEST_ACTION_TLV, 2, 0xff, 0xff,
- EAP_TLV_REQUEST_ACTION_TLV, 2, 0xff, 0xff),
- True),
- ("EAP-FAST: Too short Request-Action TLV",
- struct.pack(">HHB", EAP_TLV_REQUEST_ACTION_TLV, 1, 0xff),
- True),
- ("EAP-FAST: More than one PAC TLV in the message",
- struct.pack(">HHBHHB",
- EAP_TLV_PAC_TLV, 1, 0xff,
- EAP_TLV_PAC_TLV, 1, 0xff),
- True),
- ("EAP-FAST: Too short EAP Payload TLV (Len=3)",
- struct.pack(">HH3B",
- EAP_TLV_EAP_PAYLOAD_TLV, 3, 0, 0, 0),
- False),
- ("EAP-FAST: Too short Phase 2 request (Len=0)",
- struct.pack(">HHBBH",
- EAP_TLV_EAP_PAYLOAD_TLV, 4,
- EAP_CODE_REQUEST, 0, 0),
- False),
- ("EAP-FAST: EAP packet overflow in EAP Payload TLV",
- struct.pack(">HHBBH",
- EAP_TLV_EAP_PAYLOAD_TLV, 4,
- EAP_CODE_REQUEST, 0, 4 + 1),
- False),
- ("EAP-FAST: Unexpected code=0 in Phase 2 EAP header",
- struct.pack(">HHBBH",
- EAP_TLV_EAP_PAYLOAD_TLV, 4,
- 0, 0, 0),
- False),
- ("EAP-FAST: PAC TLV without Result TLV acknowledging success",
- struct.pack(">HHB", EAP_TLV_PAC_TLV, 1, 0xff),
- True),
- ("EAP-FAST: PAC TLV does not include all the required fields",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHB", EAP_TLV_PAC_TLV, 1, 0xff),
- True),
- ("EAP-FAST: Invalid PAC-Key length 0, Ignored unknown PAC type 0, and PAC TLV overrun (type=0 len=2 left=1)",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHHHHHHHB", EAP_TLV_PAC_TLV, 4 + 4 + 5,
- PAC_TYPE_PAC_KEY, 0, 0, 0, 0, 2, 0),
- True),
- ("EAP-FAST: PAC-Info does not include all the required fields",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHHHHHHH", EAP_TLV_PAC_TLV, 4 + 4 + 4 + 32,
- PAC_TYPE_PAC_OPAQUE, 0,
- PAC_TYPE_PAC_INFO, 0,
- PAC_TYPE_PAC_KEY, 32) + 32*'A',
- True),
- ("EAP-FAST: Invalid CRED_LIFETIME length, Ignored unknown PAC-Info type 0, and Invalid PAC-Type length 1",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHHHHHHHHHHHBHH", EAP_TLV_PAC_TLV, 4 + 4 + 13 + 4 + 32,
- PAC_TYPE_PAC_OPAQUE, 0,
- PAC_TYPE_PAC_INFO, 13, PAC_TYPE_CRED_LIFETIME, 0,
- 0, 0, PAC_TYPE_PAC_TYPE, 1, 0,
- PAC_TYPE_PAC_KEY, 32) + 32*'A',
- True),
- ("EAP-FAST: Unsupported PAC-Type 0",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHHHHHHHHHH", EAP_TLV_PAC_TLV, 4 + 4 + 6 + 4 + 32,
- PAC_TYPE_PAC_OPAQUE, 0,
- PAC_TYPE_PAC_INFO, 6, PAC_TYPE_PAC_TYPE, 2, 0,
- PAC_TYPE_PAC_KEY, 32) + 32*'A',
- True),
- ("EAP-FAST: PAC-Info overrun (type=0 len=2 left=1)",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHHHHHHHBHH", EAP_TLV_PAC_TLV, 4 + 4 + 5 + 4 + 32,
- PAC_TYPE_PAC_OPAQUE, 0,
- PAC_TYPE_PAC_INFO, 5, 0, 2, 1,
- PAC_TYPE_PAC_KEY, 32) + 32*'A',
- True),
- ("EAP-FAST: Valid PAC",
- struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
- EAP_TLV_RESULT_SUCCESS) +
- struct.pack(">HHHHHHHHBHHBHH", EAP_TLV_PAC_TLV,
- 4 + 4 + 10 + 4 + 32,
- PAC_TYPE_PAC_OPAQUE, 0,
- PAC_TYPE_PAC_INFO, 10, PAC_TYPE_A_ID, 1, 0x41,
- PAC_TYPE_A_ID_INFO, 1, 0x42,
- PAC_TYPE_PAC_KEY, 32) + 32*'A',
- True),
- ("EAP-FAST: Invalid version/subtype in Crypto-Binding TLV",
- struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A',
- True) ]
- for title, payload, failure in tests:
- logger.info("Phase 2 test: " + title)
- run_eap_fast_phase2(dev, payload, failure)
- def test_eap_fast_tlv_nak_oom(dev, apdev):
- """EAP-FAST Phase 2 TLV NAK OOM"""
- if not openssl_imported:
- raise HwsimSkip("OpenSSL python method not available")
- check_eap_capa(dev[0], "FAST")
- hapd = start_ap(apdev[0])
- with alloc_fail(dev[0], 1, "eap_fast_tlv_nak"):
- run_eap_fast_phase2(dev, struct.pack(">HHB", EAP_TLV_TYPE_MANDATORY,
- 1, 0xff), False)
|