test_eap_proto.py 357 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325
  1. # EAP protocol tests
  2. # Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import binascii
  7. import hashlib
  8. import hmac
  9. import logging
  10. logger = logging.getLogger()
  11. import os
  12. import select
  13. import struct
  14. import threading
  15. import time
  16. import hostapd
  17. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  18. from test_ap_eap import check_eap_capa, check_hlr_auc_gw_support, int_eap_server_params
  19. from test_erp import check_erp_capa
  20. try:
  21. import OpenSSL
  22. openssl_imported = True
  23. except ImportError:
  24. openssl_imported = False
  25. EAP_CODE_REQUEST = 1
  26. EAP_CODE_RESPONSE = 2
  27. EAP_CODE_SUCCESS = 3
  28. EAP_CODE_FAILURE = 4
  29. EAP_CODE_INITIATE = 5
  30. EAP_CODE_FINISH = 6
  31. EAP_TYPE_IDENTITY = 1
  32. EAP_TYPE_NOTIFICATION = 2
  33. EAP_TYPE_NAK = 3
  34. EAP_TYPE_MD5 = 4
  35. EAP_TYPE_OTP = 5
  36. EAP_TYPE_GTC = 6
  37. EAP_TYPE_TLS = 13
  38. EAP_TYPE_LEAP = 17
  39. EAP_TYPE_SIM = 18
  40. EAP_TYPE_TTLS = 21
  41. EAP_TYPE_AKA = 23
  42. EAP_TYPE_PEAP = 25
  43. EAP_TYPE_MSCHAPV2 = 26
  44. EAP_TYPE_TLV = 33
  45. EAP_TYPE_TNC = 38
  46. EAP_TYPE_FAST = 43
  47. EAP_TYPE_PAX = 46
  48. EAP_TYPE_PSK = 47
  49. EAP_TYPE_SAKE = 48
  50. EAP_TYPE_IKEV2 = 49
  51. EAP_TYPE_AKA_PRIME = 50
  52. EAP_TYPE_GPSK = 51
  53. EAP_TYPE_PWD = 52
  54. EAP_TYPE_EKE = 53
  55. EAP_TYPE_EXPANDED = 254
  56. # Type field in EAP-Initiate and EAP-Finish messages
  57. EAP_ERP_TYPE_REAUTH_START = 1
  58. EAP_ERP_TYPE_REAUTH = 2
  59. EAP_ERP_TLV_KEYNAME_NAI = 1
  60. EAP_ERP_TV_RRK_LIFETIME = 2
  61. EAP_ERP_TV_RMSK_LIFETIME = 3
  62. EAP_ERP_TLV_DOMAIN_NAME = 4
  63. EAP_ERP_TLV_CRYPTOSUITES = 5
  64. EAP_ERP_TLV_AUTHORIZATION_INDICATION = 6
  65. EAP_ERP_TLV_CALLED_STATION_ID = 128
  66. EAP_ERP_TLV_CALLING_STATION_ID = 129
  67. EAP_ERP_TLV_NAS_IDENTIFIER = 130
  68. EAP_ERP_TLV_NAS_IP_ADDRESS = 131
  69. EAP_ERP_TLV_NAS_IPV6_ADDRESS = 132
  70. def run_pyrad_server(srv, t_stop, eap_handler):
  71. srv.RunWithStop(t_stop, eap_handler)
  72. def start_radius_server(eap_handler):
  73. try:
  74. import pyrad.server
  75. import pyrad.packet
  76. import pyrad.dictionary
  77. except ImportError:
  78. raise HwsimSkip("No pyrad modules available")
  79. class TestServer(pyrad.server.Server):
  80. def _HandleAuthPacket(self, pkt):
  81. pyrad.server.Server._HandleAuthPacket(self, pkt)
  82. eap = ""
  83. for p in pkt[79]:
  84. eap += p
  85. eap_req = self.eap_handler(self.ctx, eap)
  86. reply = self.CreateReplyPacket(pkt)
  87. if eap_req:
  88. while True:
  89. if len(eap_req) > 253:
  90. reply.AddAttribute("EAP-Message", eap_req[0:253])
  91. eap_req = eap_req[253:]
  92. else:
  93. reply.AddAttribute("EAP-Message", eap_req)
  94. break
  95. else:
  96. logger.info("No EAP request available")
  97. reply.code = pyrad.packet.AccessChallenge
  98. hmac_obj = hmac.new(reply.secret)
  99. hmac_obj.update(struct.pack("B", reply.code))
  100. hmac_obj.update(struct.pack("B", reply.id))
  101. # reply attributes
  102. reply.AddAttribute("Message-Authenticator",
  103. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
  104. attrs = reply._PktEncodeAttributes()
  105. # Length
  106. flen = 4 + 16 + len(attrs)
  107. hmac_obj.update(struct.pack(">H", flen))
  108. hmac_obj.update(pkt.authenticator)
  109. hmac_obj.update(attrs)
  110. del reply[80]
  111. reply.AddAttribute("Message-Authenticator", hmac_obj.digest())
  112. self.SendReplyPacket(pkt.fd, reply)
  113. def RunWithStop(self, t_stop, eap_handler):
  114. self._poll = select.poll()
  115. self._fdmap = {}
  116. self._PrepareSockets()
  117. self.t_stop = t_stop
  118. self.eap_handler = eap_handler
  119. self.ctx = {}
  120. while not t_stop.is_set():
  121. for (fd, event) in self._poll.poll(200):
  122. if event == select.POLLIN:
  123. try:
  124. fdo = self._fdmap[fd]
  125. self._ProcessInput(fdo)
  126. except pyrad.server.ServerPacketError as err:
  127. logger.info("pyrad server dropping packet: " + str(err))
  128. except pyrad.packet.PacketError as err:
  129. logger.info("pyrad server received invalid packet: " + str(err))
  130. else:
  131. logger.error("Unexpected event in pyrad server main loop")
  132. srv = TestServer(dict=pyrad.dictionary.Dictionary("dictionary.radius"),
  133. authport=18138, acctport=18139)
  134. srv.hosts["127.0.0.1"] = pyrad.server.RemoteHost("127.0.0.1",
  135. "radius",
  136. "localhost")
  137. srv.BindToAddress("")
  138. t_stop = threading.Event()
  139. t = threading.Thread(target=run_pyrad_server, args=(srv, t_stop, eap_handler))
  140. t.start()
  141. return { 'srv': srv, 'stop': t_stop, 'thread': t }
  142. def stop_radius_server(srv):
  143. srv['stop'].set()
  144. srv['thread'].join()
  145. def start_ap(ap):
  146. params = hostapd.wpa2_eap_params(ssid="eap-test")
  147. params['auth_server_port'] = "18138"
  148. hapd = hostapd.add_ap(ap, params)
  149. return hapd
  150. def test_eap_proto(dev, apdev):
  151. """EAP protocol tests"""
  152. check_eap_capa(dev[0], "MD5")
  153. def eap_handler(ctx, req):
  154. logger.info("eap_handler - RX " + req.encode("hex"))
  155. if 'num' not in ctx:
  156. ctx['num'] = 0
  157. ctx['num'] = ctx['num'] + 1
  158. if 'id' not in ctx:
  159. ctx['id'] = 1
  160. ctx['id'] = (ctx['id'] + 1) % 256
  161. idx = 0
  162. idx += 1
  163. if ctx['num'] == idx:
  164. logger.info("Test: MD5 challenge")
  165. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  166. 4 + 1 + 3,
  167. EAP_TYPE_MD5,
  168. 1, 0xaa, ord('n'))
  169. idx += 1
  170. if ctx['num'] == idx:
  171. logger.info("Test: EAP-Success - id off by 2")
  172. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] + 1, 4)
  173. idx += 1
  174. if ctx['num'] == idx:
  175. logger.info("Test: MD5 challenge")
  176. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  177. 4 + 1 + 3,
  178. EAP_TYPE_MD5,
  179. 1, 0xaa, ord('n'))
  180. idx += 1
  181. if ctx['num'] == idx:
  182. logger.info("Test: EAP-Success - id off by 3")
  183. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] + 2, 4)
  184. idx += 1
  185. if ctx['num'] == idx:
  186. logger.info("Test: MD5 challenge")
  187. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  188. 4 + 1 + 3,
  189. EAP_TYPE_MD5,
  190. 1, 0xaa, ord('n'))
  191. idx += 1
  192. if ctx['num'] == idx:
  193. logger.info("Test: EAP-Notification/Request")
  194. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  195. 4 + 1 + 1,
  196. EAP_TYPE_NOTIFICATION,
  197. ord('A'))
  198. idx += 1
  199. if ctx['num'] == idx:
  200. logger.info("Test: EAP-Success")
  201. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 1, 4)
  202. idx += 1
  203. if ctx['num'] == idx:
  204. logger.info("Test: EAP-Notification/Request")
  205. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  206. 4 + 1 + 1,
  207. EAP_TYPE_NOTIFICATION,
  208. ord('B'))
  209. idx += 1
  210. if ctx['num'] == idx:
  211. logger.info("Test: MD5 challenge")
  212. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  213. 4 + 1 + 3,
  214. EAP_TYPE_MD5,
  215. 1, 0xaa, ord('n'))
  216. idx += 1
  217. if ctx['num'] == idx:
  218. logger.info("Test: EAP-Success")
  219. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 1, 4)
  220. idx += 1
  221. if ctx['num'] == idx:
  222. logger.info("Test: EAP-Notification/Request")
  223. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  224. 4 + 1 + 1,
  225. EAP_TYPE_NOTIFICATION,
  226. ord('C'))
  227. idx += 1
  228. if ctx['num'] == idx:
  229. logger.info("Test: MD5 challenge")
  230. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  231. 4 + 1 + 3,
  232. EAP_TYPE_MD5,
  233. 1, 0xaa, ord('n'))
  234. idx += 1
  235. if ctx['num'] == idx:
  236. logger.info("Test: EAP-Notification/Request")
  237. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  238. 4 + 1 + 1,
  239. EAP_TYPE_NOTIFICATION,
  240. ord('D'))
  241. idx += 1
  242. if ctx['num'] == idx:
  243. logger.info("Test: EAP-Success")
  244. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 1, 4)
  245. idx += 1
  246. if ctx['num'] == idx:
  247. logger.info("Test: EAP-Notification/Request")
  248. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  249. 4 + 1 + 1,
  250. EAP_TYPE_NOTIFICATION,
  251. ord('E'))
  252. idx += 1
  253. if ctx['num'] == idx:
  254. logger.info("Test: EAP-Notification/Request (same id)")
  255. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'] - 1,
  256. 4 + 1 + 1,
  257. EAP_TYPE_NOTIFICATION,
  258. ord('F'))
  259. idx += 1
  260. if ctx['num'] == idx:
  261. logger.info("Test: Unexpected EAP-Success")
  262. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'] - 2, 4)
  263. return None
  264. srv = start_radius_server(eap_handler)
  265. try:
  266. hapd = start_ap(apdev[0])
  267. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  268. eap="MD5", identity="user", password="password",
  269. wait_connect=False)
  270. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  271. if ev is None:
  272. raise Exception("Timeout on EAP start")
  273. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  274. if ev is None:
  275. raise Exception("Timeout on EAP success")
  276. dev[0].request("REMOVE_NETWORK all")
  277. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  278. eap="MD5", identity="user", password="password",
  279. wait_connect=False)
  280. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  281. if ev is None:
  282. raise Exception("Timeout on EAP start")
  283. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=1)
  284. if ev is not None:
  285. raise Exception("Unexpected EAP success")
  286. dev[0].request("REMOVE_NETWORK all")
  287. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  288. eap="MD5", identity="user", password="password",
  289. wait_connect=False)
  290. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  291. if ev is None:
  292. raise Exception("Timeout on EAP start")
  293. ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
  294. if ev is None:
  295. raise Exception("Timeout on EAP notification")
  296. if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION A":
  297. raise Exception("Unexpected notification contents: " + ev)
  298. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  299. if ev is None:
  300. raise Exception("Timeout on EAP success")
  301. dev[0].request("REMOVE_NETWORK all")
  302. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  303. eap="MD5", identity="user", password="password",
  304. wait_connect=False)
  305. ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
  306. if ev is None:
  307. raise Exception("Timeout on EAP notification")
  308. if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION B":
  309. raise Exception("Unexpected notification contents: " + ev)
  310. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  311. if ev is None:
  312. raise Exception("Timeout on EAP start")
  313. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  314. if ev is None:
  315. raise Exception("Timeout on EAP success")
  316. dev[0].request("REMOVE_NETWORK all")
  317. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  318. eap="MD5", identity="user", password="password",
  319. wait_connect=False)
  320. ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
  321. if ev is None:
  322. raise Exception("Timeout on EAP notification")
  323. if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION C":
  324. raise Exception("Unexpected notification contents: " + ev)
  325. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  326. if ev is None:
  327. raise Exception("Timeout on EAP start")
  328. ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
  329. if ev is None:
  330. raise Exception("Timeout on EAP notification")
  331. if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION D":
  332. raise Exception("Unexpected notification contents: " + ev)
  333. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  334. if ev is None:
  335. raise Exception("Timeout on EAP success")
  336. dev[0].request("REMOVE_NETWORK all")
  337. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  338. eap="MD5", identity="user", password="password",
  339. wait_connect=False)
  340. ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
  341. if ev is None:
  342. raise Exception("Timeout on EAP notification")
  343. if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION E":
  344. raise Exception("Unexpected notification contents: " + ev)
  345. ev = dev[0].wait_event(["CTRL-EVENT-EAP-NOTIFICATION"], timeout=10)
  346. if ev is None:
  347. raise Exception("Timeout on EAP notification")
  348. if ev != "<3>CTRL-EVENT-EAP-NOTIFICATION F":
  349. raise Exception("Unexpected notification contents: " + ev)
  350. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  351. if ev is None:
  352. raise Exception("Timeout on EAP failure")
  353. dev[0].request("REMOVE_NETWORK all")
  354. finally:
  355. stop_radius_server(srv)
  356. def test_eap_proto_notification_errors(dev, apdev):
  357. """EAP Notification errors"""
  358. def eap_handler(ctx, req):
  359. logger.info("eap_handler - RX " + req.encode("hex"))
  360. if 'num' not in ctx:
  361. ctx['num'] = 0
  362. ctx['num'] = ctx['num'] + 1
  363. if 'id' not in ctx:
  364. ctx['id'] = 1
  365. ctx['id'] = (ctx['id'] + 1) % 256
  366. idx = 0
  367. idx += 1
  368. if ctx['num'] == idx:
  369. logger.info("Test: MD5 challenge")
  370. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  371. 4 + 1 + 3,
  372. EAP_TYPE_MD5,
  373. 1, 0xaa, ord('n'))
  374. idx += 1
  375. if ctx['num'] == idx:
  376. logger.info("Test: EAP-Notification/Request")
  377. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  378. 4 + 1 + 1,
  379. EAP_TYPE_NOTIFICATION,
  380. ord('A'))
  381. idx += 1
  382. if ctx['num'] == idx:
  383. logger.info("Test: MD5 challenge")
  384. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  385. 4 + 1 + 3,
  386. EAP_TYPE_MD5,
  387. 1, 0xaa, ord('n'))
  388. idx += 1
  389. if ctx['num'] == idx:
  390. logger.info("Test: EAP-Notification/Request")
  391. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  392. 4 + 1 + 1,
  393. EAP_TYPE_NOTIFICATION,
  394. ord('A'))
  395. return None
  396. srv = start_radius_server(eap_handler)
  397. try:
  398. hapd = start_ap(apdev[0])
  399. with alloc_fail(dev[0], 1, "eap_sm_processNotify"):
  400. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  401. eap="MD5", identity="user", password="password",
  402. wait_connect=False)
  403. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  404. dev[0].request("REMOVE_NETWORK all")
  405. dev[0].wait_disconnected()
  406. with alloc_fail(dev[0], 1, "eap_msg_alloc;sm_EAP_NOTIFICATION_Enter"):
  407. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  408. eap="MD5", identity="user", password="password",
  409. wait_connect=False)
  410. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  411. dev[0].request("REMOVE_NETWORK all")
  412. dev[0].wait_disconnected()
  413. finally:
  414. stop_radius_server(srv)
  415. EAP_SAKE_VERSION = 2
  416. EAP_SAKE_SUBTYPE_CHALLENGE = 1
  417. EAP_SAKE_SUBTYPE_CONFIRM = 2
  418. EAP_SAKE_SUBTYPE_AUTH_REJECT = 3
  419. EAP_SAKE_SUBTYPE_IDENTITY = 4
  420. EAP_SAKE_AT_RAND_S = 1
  421. EAP_SAKE_AT_RAND_P = 2
  422. EAP_SAKE_AT_MIC_S = 3
  423. EAP_SAKE_AT_MIC_P = 4
  424. EAP_SAKE_AT_SERVERID = 5
  425. EAP_SAKE_AT_PEERID = 6
  426. EAP_SAKE_AT_SPI_S = 7
  427. EAP_SAKE_AT_SPI_P = 8
  428. EAP_SAKE_AT_ANY_ID_REQ = 9
  429. EAP_SAKE_AT_PERM_ID_REQ = 10
  430. EAP_SAKE_AT_ENCR_DATA = 128
  431. EAP_SAKE_AT_IV = 129
  432. EAP_SAKE_AT_PADDING = 130
  433. EAP_SAKE_AT_NEXT_TMPID = 131
  434. EAP_SAKE_AT_MSK_LIFE = 132
  435. def test_eap_proto_sake(dev, apdev):
  436. """EAP-SAKE protocol tests"""
  437. global eap_proto_sake_test_done
  438. eap_proto_sake_test_done = False
  439. def sake_challenge(ctx):
  440. logger.info("Test: Challenge subtype")
  441. return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
  442. 4 + 1 + 3 + 18,
  443. EAP_TYPE_SAKE,
  444. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE,
  445. EAP_SAKE_AT_RAND_S, 18, 0, 0, 0, 0)
  446. def sake_handler(ctx, req):
  447. logger.info("sake_handler - RX " + req.encode("hex"))
  448. if 'num' not in ctx:
  449. ctx['num'] = 0
  450. ctx['num'] += 1
  451. if 'id' not in ctx:
  452. ctx['id'] = 1
  453. ctx['id'] = (ctx['id'] + 1) % 256
  454. idx = 0
  455. idx += 1
  456. if ctx['num'] == idx:
  457. logger.info("Test: Missing payload")
  458. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'], 4 + 1,
  459. EAP_TYPE_SAKE)
  460. idx += 1
  461. if ctx['num'] == idx:
  462. logger.info("Test: Identity subtype without any attributes")
  463. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  464. 4 + 1 + 3,
  465. EAP_TYPE_SAKE,
  466. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY)
  467. idx += 1
  468. if ctx['num'] == idx:
  469. logger.info("Test: Identity subtype")
  470. return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
  471. 4 + 1 + 3 + 4,
  472. EAP_TYPE_SAKE,
  473. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
  474. EAP_SAKE_AT_ANY_ID_REQ, 4, 0)
  475. idx += 1
  476. if ctx['num'] == idx:
  477. logger.info("Test: Identity subtype (different session id)")
  478. return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
  479. 4 + 1 + 3 + 4,
  480. EAP_TYPE_SAKE,
  481. EAP_SAKE_VERSION, 1, EAP_SAKE_SUBTYPE_IDENTITY,
  482. EAP_SAKE_AT_PERM_ID_REQ, 4, 0)
  483. idx += 1
  484. if ctx['num'] == idx:
  485. logger.info("Test: Identity subtype with too short attribute")
  486. return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
  487. 4 + 1 + 3 + 2,
  488. EAP_TYPE_SAKE,
  489. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
  490. EAP_SAKE_AT_ANY_ID_REQ, 2)
  491. idx += 1
  492. if ctx['num'] == idx:
  493. logger.info("Test: Identity subtype with truncated attribute")
  494. return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
  495. 4 + 1 + 3 + 2,
  496. EAP_TYPE_SAKE,
  497. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
  498. EAP_SAKE_AT_ANY_ID_REQ, 4)
  499. idx += 1
  500. if ctx['num'] == idx:
  501. logger.info("Test: Identity subtype with too short attribute header")
  502. payload = struct.pack("B", EAP_SAKE_AT_ANY_ID_REQ)
  503. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  504. 4 + 1 + 3 + len(payload),
  505. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  506. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  507. idx += 1
  508. if ctx['num'] == idx:
  509. logger.info("Test: Identity subtype with AT_IV but not AT_ENCR_DATA")
  510. payload = struct.pack("BB", EAP_SAKE_AT_IV, 2)
  511. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  512. 4 + 1 + 3 + len(payload),
  513. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  514. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  515. idx += 1
  516. if ctx['num'] == idx:
  517. logger.info("Test: Identity subtype with skippable and non-skippable unknown attribute")
  518. payload = struct.pack("BBBB", 255, 2, 127, 2)
  519. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  520. 4 + 1 + 3 + len(payload),
  521. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  522. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  523. idx += 1
  524. if ctx['num'] == idx:
  525. logger.info("Test: Identity subtype: AT_RAND_P with invalid payload length")
  526. payload = struct.pack("BB", EAP_SAKE_AT_RAND_P, 2)
  527. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  528. 4 + 1 + 3 + len(payload),
  529. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  530. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  531. idx += 1
  532. if ctx['num'] == idx:
  533. logger.info("Test: Identity subtype: AT_MIC_P with invalid payload length")
  534. payload = struct.pack("BB", EAP_SAKE_AT_MIC_P, 2)
  535. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  536. 4 + 1 + 3 + len(payload),
  537. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  538. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  539. idx += 1
  540. if ctx['num'] == idx:
  541. logger.info("Test: Identity subtype: AT_PERM_ID_REQ with invalid payload length")
  542. payload = struct.pack("BBBBBBBBBBBBBB",
  543. EAP_SAKE_AT_SPI_S, 2,
  544. EAP_SAKE_AT_SPI_P, 2,
  545. EAP_SAKE_AT_ENCR_DATA, 2,
  546. EAP_SAKE_AT_NEXT_TMPID, 2,
  547. EAP_SAKE_AT_PERM_ID_REQ, 4, 0, 0,
  548. EAP_SAKE_AT_PERM_ID_REQ, 2)
  549. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  550. 4 + 1 + 3 + len(payload),
  551. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  552. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  553. idx += 1
  554. if ctx['num'] == idx:
  555. logger.info("Test: Identity subtype: AT_PADDING")
  556. payload = struct.pack("BBBBBB",
  557. EAP_SAKE_AT_PADDING, 3, 0,
  558. EAP_SAKE_AT_PADDING, 3, 1)
  559. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  560. 4 + 1 + 3 + len(payload),
  561. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  562. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  563. idx += 1
  564. if ctx['num'] == idx:
  565. logger.info("Test: Identity subtype: AT_MSK_LIFE")
  566. payload = struct.pack(">BBLBBH",
  567. EAP_SAKE_AT_MSK_LIFE, 6, 0,
  568. EAP_SAKE_AT_MSK_LIFE, 4, 0)
  569. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  570. 4 + 1 + 3 + len(payload),
  571. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  572. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  573. idx += 1
  574. if ctx['num'] == idx:
  575. logger.info("Test: Identity subtype with invalid attribute length")
  576. payload = struct.pack("BB", EAP_SAKE_AT_ANY_ID_REQ, 0)
  577. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  578. 4 + 1 + 3 + len(payload),
  579. EAP_TYPE_SAKE, EAP_SAKE_VERSION, 0,
  580. EAP_SAKE_SUBTYPE_IDENTITY) + payload
  581. idx += 1
  582. if ctx['num'] == idx:
  583. logger.info("Test: Unknown subtype")
  584. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  585. 4 + 1 + 3,
  586. EAP_TYPE_SAKE,
  587. EAP_SAKE_VERSION, 0, 123)
  588. idx += 1
  589. if ctx['num'] == idx:
  590. logger.info("Test: Challenge subtype without any attributes")
  591. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  592. 4 + 1 + 3,
  593. EAP_TYPE_SAKE,
  594. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE)
  595. idx += 1
  596. if ctx['num'] == idx:
  597. logger.info("Test: Challenge subtype with too short AT_RAND_S")
  598. return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
  599. 4 + 1 + 3 + 2,
  600. EAP_TYPE_SAKE,
  601. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE,
  602. EAP_SAKE_AT_RAND_S, 2)
  603. idx += 1
  604. if ctx['num'] == idx:
  605. return sake_challenge(ctx)
  606. idx += 1
  607. if ctx['num'] == idx:
  608. logger.info("Test: Unexpected Identity subtype")
  609. return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
  610. 4 + 1 + 3 + 4,
  611. EAP_TYPE_SAKE,
  612. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
  613. EAP_SAKE_AT_ANY_ID_REQ, 4, 0)
  614. idx += 1
  615. if ctx['num'] == idx:
  616. return sake_challenge(ctx)
  617. idx += 1
  618. if ctx['num'] == idx:
  619. logger.info("Test: Unexpected Challenge subtype")
  620. return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
  621. 4 + 1 + 3 + 18,
  622. EAP_TYPE_SAKE,
  623. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CHALLENGE,
  624. EAP_SAKE_AT_RAND_S, 18, 0, 0, 0, 0)
  625. idx += 1
  626. if ctx['num'] == idx:
  627. return sake_challenge(ctx)
  628. idx += 1
  629. if ctx['num'] == idx:
  630. logger.info("Test: Confirm subtype without any attributes")
  631. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  632. 4 + 1 + 3,
  633. EAP_TYPE_SAKE,
  634. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM)
  635. idx += 1
  636. if ctx['num'] == idx:
  637. return sake_challenge(ctx)
  638. idx += 1
  639. if ctx['num'] == idx:
  640. logger.info("Test: Confirm subtype with too short AT_MIC_S")
  641. return struct.pack(">BBHBBBBBB", EAP_CODE_REQUEST, ctx['id'],
  642. 4 + 1 + 3 + 2,
  643. EAP_TYPE_SAKE,
  644. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM,
  645. EAP_SAKE_AT_MIC_S, 2)
  646. idx += 1
  647. if ctx['num'] == idx:
  648. logger.info("Test: Unexpected Confirm subtype")
  649. return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
  650. 4 + 1 + 3 + 18,
  651. EAP_TYPE_SAKE,
  652. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM,
  653. EAP_SAKE_AT_MIC_S, 18, 0, 0, 0, 0)
  654. idx += 1
  655. if ctx['num'] == idx:
  656. return sake_challenge(ctx)
  657. idx += 1
  658. if ctx['num'] == idx:
  659. logger.info("Test: Confirm subtype with incorrect AT_MIC_S")
  660. return struct.pack(">BBHBBBBBBLLLL", EAP_CODE_REQUEST, ctx['id'],
  661. 4 + 1 + 3 + 18,
  662. EAP_TYPE_SAKE,
  663. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_CONFIRM,
  664. EAP_SAKE_AT_MIC_S, 18, 0, 0, 0, 0)
  665. global eap_proto_sake_test_done
  666. if eap_proto_sake_test_done:
  667. return sake_challenge(ctx)
  668. logger.info("No more test responses available - test case completed")
  669. eap_proto_sake_test_done = True
  670. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  671. srv = start_radius_server(sake_handler)
  672. try:
  673. hapd = start_ap(apdev[0])
  674. while not eap_proto_sake_test_done:
  675. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  676. eap="SAKE", identity="sake user",
  677. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  678. wait_connect=False)
  679. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  680. if ev is None:
  681. raise Exception("Timeout on EAP start")
  682. time.sleep(0.1)
  683. dev[0].request("REMOVE_NETWORK all")
  684. logger.info("Too short password")
  685. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  686. eap="SAKE", identity="sake user",
  687. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd",
  688. wait_connect=False)
  689. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  690. if ev is None:
  691. raise Exception("Timeout on EAP start")
  692. time.sleep(0.1)
  693. finally:
  694. stop_radius_server(srv)
  695. def test_eap_proto_sake_errors(dev, apdev):
  696. """EAP-SAKE local error cases"""
  697. check_eap_capa(dev[0], "SAKE")
  698. params = hostapd.wpa2_eap_params(ssid="eap-test")
  699. hapd = hostapd.add_ap(apdev[0], params)
  700. for i in range(1, 3):
  701. with alloc_fail(dev[0], i, "eap_sake_init"):
  702. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  703. eap="SAKE", identity="sake user",
  704. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  705. wait_connect=False)
  706. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  707. timeout=15)
  708. if ev is None:
  709. raise Exception("Timeout on EAP start")
  710. dev[0].request("REMOVE_NETWORK all")
  711. dev[0].wait_disconnected()
  712. tests = [ ( 1, "eap_msg_alloc;eap_sake_build_msg;eap_sake_process_challenge" ),
  713. ( 1, "=eap_sake_process_challenge" ),
  714. ( 1, "eap_sake_compute_mic;eap_sake_process_challenge" ),
  715. ( 1, "eap_sake_build_msg;eap_sake_process_confirm" ),
  716. ( 1, "eap_sake_compute_mic;eap_sake_process_confirm" ),
  717. ( 2, "eap_sake_compute_mic;eap_sake_process_confirm" ),
  718. ( 1, "eap_sake_getKey" ),
  719. ( 1, "eap_sake_get_emsk" ),
  720. ( 1, "eap_sake_get_session_id" ) ]
  721. for count, func in tests:
  722. with alloc_fail(dev[0], count, func):
  723. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  724. eap="SAKE", identity="sake user@domain",
  725. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  726. erp="1",
  727. wait_connect=False)
  728. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  729. timeout=15)
  730. if ev is None:
  731. raise Exception("Timeout on EAP start")
  732. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  733. dev[0].request("REMOVE_NETWORK all")
  734. dev[0].wait_disconnected()
  735. with fail_test(dev[0], 1, "os_get_random;eap_sake_process_challenge"):
  736. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  737. eap="SAKE", identity="sake user",
  738. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  739. wait_connect=False)
  740. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  741. if ev is None:
  742. raise Exception("Timeout on EAP start")
  743. wait_fail_trigger(dev[0], "GET_FAIL")
  744. dev[0].request("REMOVE_NETWORK all")
  745. dev[0].wait_disconnected()
  746. def test_eap_proto_sake_errors2(dev, apdev):
  747. """EAP-SAKE protocol tests (2)"""
  748. def sake_handler(ctx, req):
  749. logger.info("sake_handler - RX " + req.encode("hex"))
  750. if 'num' not in ctx:
  751. ctx['num'] = 0
  752. ctx['num'] += 1
  753. if 'id' not in ctx:
  754. ctx['id'] = 1
  755. ctx['id'] = (ctx['id'] + 1) % 256
  756. idx = 0
  757. idx += 1
  758. if ctx['num'] == idx:
  759. logger.info("Test: Identity subtype")
  760. return struct.pack(">BBHBBBBBBH", EAP_CODE_REQUEST, ctx['id'],
  761. 4 + 1 + 3 + 4,
  762. EAP_TYPE_SAKE,
  763. EAP_SAKE_VERSION, 0, EAP_SAKE_SUBTYPE_IDENTITY,
  764. EAP_SAKE_AT_ANY_ID_REQ, 4, 0)
  765. srv = start_radius_server(sake_handler)
  766. try:
  767. hapd = start_ap(apdev[0])
  768. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_sake_build_msg;eap_sake_process_identity"):
  769. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  770. eap="SAKE", identity="sake user",
  771. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  772. wait_connect=False)
  773. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  774. timeout=15)
  775. if ev is None:
  776. raise Exception("Timeout on EAP start")
  777. dev[0].request("REMOVE_NETWORK all")
  778. dev[0].wait_disconnected()
  779. finally:
  780. stop_radius_server(srv)
  781. def test_eap_proto_leap(dev, apdev):
  782. """EAP-LEAP protocol tests"""
  783. check_eap_capa(dev[0], "LEAP")
  784. def leap_handler(ctx, req):
  785. logger.info("leap_handler - RX " + req.encode("hex"))
  786. if 'num' not in ctx:
  787. ctx['num'] = 0
  788. ctx['num'] = ctx['num'] + 1
  789. if 'id' not in ctx:
  790. ctx['id'] = 1
  791. ctx['id'] = (ctx['id'] + 1) % 256
  792. if ctx['num'] == 1:
  793. logger.info("Test: Missing payload")
  794. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  795. 4 + 1,
  796. EAP_TYPE_LEAP)
  797. if ctx['num'] == 2:
  798. logger.info("Test: Unexpected version")
  799. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  800. 4 + 1 + 3,
  801. EAP_TYPE_LEAP,
  802. 0, 0, 0)
  803. if ctx['num'] == 3:
  804. logger.info("Test: Invalid challenge length")
  805. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  806. 4 + 1 + 3,
  807. EAP_TYPE_LEAP,
  808. 1, 0, 0)
  809. if ctx['num'] == 4:
  810. logger.info("Test: Truncated challenge")
  811. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  812. 4 + 1 + 3,
  813. EAP_TYPE_LEAP,
  814. 1, 0, 8)
  815. if ctx['num'] == 5:
  816. logger.info("Test: Valid challenge")
  817. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  818. 4 + 1 + 3 + 8,
  819. EAP_TYPE_LEAP,
  820. 1, 0, 8, 0, 0)
  821. if ctx['num'] == 6:
  822. logger.info("Test: Missing payload in Response")
  823. return struct.pack(">BBHB", EAP_CODE_RESPONSE, ctx['id'],
  824. 4 + 1,
  825. EAP_TYPE_LEAP)
  826. if ctx['num'] == 7:
  827. logger.info("Test: Valid challenge")
  828. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  829. 4 + 1 + 3 + 8,
  830. EAP_TYPE_LEAP,
  831. 1, 0, 8, 0, 0)
  832. if ctx['num'] == 8:
  833. logger.info("Test: Unexpected version in Response")
  834. return struct.pack(">BBHBBBB", EAP_CODE_RESPONSE, ctx['id'],
  835. 4 + 1 + 3,
  836. EAP_TYPE_LEAP,
  837. 0, 0, 8)
  838. if ctx['num'] == 9:
  839. logger.info("Test: Valid challenge")
  840. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  841. 4 + 1 + 3 + 8,
  842. EAP_TYPE_LEAP,
  843. 1, 0, 8, 0, 0)
  844. if ctx['num'] == 10:
  845. logger.info("Test: Invalid challenge length in Response")
  846. return struct.pack(">BBHBBBB", EAP_CODE_RESPONSE, ctx['id'],
  847. 4 + 1 + 3,
  848. EAP_TYPE_LEAP,
  849. 1, 0, 0)
  850. if ctx['num'] == 11:
  851. logger.info("Test: Valid challenge")
  852. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  853. 4 + 1 + 3 + 8,
  854. EAP_TYPE_LEAP,
  855. 1, 0, 8, 0, 0)
  856. if ctx['num'] == 12:
  857. logger.info("Test: Truncated challenge in Response")
  858. return struct.pack(">BBHBBBB", EAP_CODE_RESPONSE, ctx['id'],
  859. 4 + 1 + 3,
  860. EAP_TYPE_LEAP,
  861. 1, 0, 24)
  862. if ctx['num'] == 13:
  863. logger.info("Test: Valid challenge")
  864. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  865. 4 + 1 + 3 + 8,
  866. EAP_TYPE_LEAP,
  867. 1, 0, 8, 0, 0)
  868. if ctx['num'] == 14:
  869. logger.info("Test: Invalid challange value in Response")
  870. return struct.pack(">BBHBBBB6L", EAP_CODE_RESPONSE, ctx['id'],
  871. 4 + 1 + 3 + 24,
  872. EAP_TYPE_LEAP,
  873. 1, 0, 24,
  874. 0, 0, 0, 0, 0, 0)
  875. if ctx['num'] == 15:
  876. logger.info("Test: Valid challenge")
  877. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  878. 4 + 1 + 3 + 8,
  879. EAP_TYPE_LEAP,
  880. 1, 0, 8, 0, 0)
  881. if ctx['num'] == 16:
  882. logger.info("Test: Valid challange value in Response")
  883. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  884. 4 + 1 + 3 + 24,
  885. EAP_TYPE_LEAP,
  886. 1, 0, 24,
  887. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  888. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  889. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  890. if ctx['num'] == 17:
  891. logger.info("Test: Valid challenge")
  892. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  893. 4 + 1 + 3 + 8,
  894. EAP_TYPE_LEAP,
  895. 1, 0, 8, 0, 0)
  896. if ctx['num'] == 18:
  897. logger.info("Test: Success")
  898. return struct.pack(">BBHB", EAP_CODE_SUCCESS, ctx['id'],
  899. 4 + 1,
  900. EAP_TYPE_LEAP)
  901. # hostapd will drop the next frame in the sequence
  902. if ctx['num'] == 19:
  903. logger.info("Test: Valid challenge")
  904. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  905. 4 + 1 + 3 + 8,
  906. EAP_TYPE_LEAP,
  907. 1, 0, 8, 0, 0)
  908. if ctx['num'] == 20:
  909. logger.info("Test: Failure")
  910. return struct.pack(">BBHB", EAP_CODE_FAILURE, ctx['id'],
  911. 4 + 1,
  912. EAP_TYPE_LEAP)
  913. return None
  914. srv = start_radius_server(leap_handler)
  915. try:
  916. hapd = start_ap(apdev[0])
  917. for i in range(0, 12):
  918. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  919. eap="LEAP", identity="user", password="password",
  920. wait_connect=False)
  921. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  922. if ev is None:
  923. raise Exception("Timeout on EAP start")
  924. time.sleep(0.1)
  925. if i == 10:
  926. logger.info("Wait for additional roundtrip")
  927. time.sleep(1)
  928. dev[0].request("REMOVE_NETWORK all")
  929. finally:
  930. stop_radius_server(srv)
  931. def test_eap_proto_leap_errors(dev, apdev):
  932. """EAP-LEAP protocol tests (error paths)"""
  933. check_eap_capa(dev[0], "LEAP")
  934. def leap_handler2(ctx, req):
  935. logger.info("leap_handler2 - RX " + req.encode("hex"))
  936. if 'num' not in ctx:
  937. ctx['num'] = 0
  938. ctx['num'] = ctx['num'] + 1
  939. if 'id' not in ctx:
  940. ctx['id'] = 1
  941. ctx['id'] = (ctx['id'] + 1) % 256
  942. idx = 0
  943. idx += 1
  944. if ctx['num'] == idx:
  945. logger.info("Test: Valid challenge")
  946. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  947. 4 + 1 + 3 + 8,
  948. EAP_TYPE_LEAP,
  949. 1, 0, 8, 0, 0)
  950. idx += 1
  951. if ctx['num'] == idx:
  952. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  953. idx += 1
  954. if ctx['num'] == idx:
  955. logger.info("Test: Valid challenge")
  956. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  957. 4 + 1 + 3 + 8,
  958. EAP_TYPE_LEAP,
  959. 1, 0, 8, 0, 0)
  960. idx += 1
  961. if ctx['num'] == idx:
  962. logger.info("Test: Valid challenge")
  963. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  964. 4 + 1 + 3 + 8,
  965. EAP_TYPE_LEAP,
  966. 1, 0, 8, 0, 0)
  967. idx += 1
  968. if ctx['num'] == idx:
  969. logger.info("Test: Success")
  970. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  971. idx += 1
  972. if ctx['num'] == idx:
  973. logger.info("Test: Valid challenge")
  974. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  975. 4 + 1 + 3 + 8,
  976. EAP_TYPE_LEAP,
  977. 1, 0, 8, 0, 0)
  978. idx += 1
  979. if ctx['num'] == idx:
  980. logger.info("Test: Success")
  981. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  982. idx += 1
  983. if ctx['num'] == idx:
  984. logger.info("Test: Valid challenge")
  985. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  986. 4 + 1 + 3 + 8,
  987. EAP_TYPE_LEAP,
  988. 1, 0, 8, 0, 0)
  989. idx += 1
  990. if ctx['num'] == idx:
  991. logger.info("Test: Valid challange value in Response")
  992. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  993. 4 + 1 + 3 + 24,
  994. EAP_TYPE_LEAP,
  995. 1, 0, 24,
  996. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  997. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  998. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  999. idx += 1
  1000. if ctx['num'] == idx:
  1001. logger.info("Test: Valid challenge")
  1002. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1003. 4 + 1 + 3 + 8,
  1004. EAP_TYPE_LEAP,
  1005. 1, 0, 8, 0, 0)
  1006. idx += 1
  1007. if ctx['num'] == idx:
  1008. logger.info("Test: Valid challange value in Response")
  1009. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  1010. 4 + 1 + 3 + 24,
  1011. EAP_TYPE_LEAP,
  1012. 1, 0, 24,
  1013. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  1014. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  1015. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  1016. idx += 1
  1017. if ctx['num'] == idx:
  1018. logger.info("Test: Valid challenge")
  1019. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1020. 4 + 1 + 3 + 8,
  1021. EAP_TYPE_LEAP,
  1022. 1, 0, 8, 0, 0)
  1023. idx += 1
  1024. if ctx['num'] == idx:
  1025. logger.info("Test: Valid challange value in Response")
  1026. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  1027. 4 + 1 + 3 + 24,
  1028. EAP_TYPE_LEAP,
  1029. 1, 0, 24,
  1030. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  1031. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  1032. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  1033. idx += 1
  1034. if ctx['num'] == idx:
  1035. logger.info("Test: Valid challenge")
  1036. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1037. 4 + 1 + 3 + 8,
  1038. EAP_TYPE_LEAP,
  1039. 1, 0, 8, 0, 0)
  1040. idx += 1
  1041. if ctx['num'] == idx:
  1042. logger.info("Test: Valid challange value in Response")
  1043. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  1044. 4 + 1 + 3 + 24,
  1045. EAP_TYPE_LEAP,
  1046. 1, 0, 24,
  1047. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  1048. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  1049. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  1050. idx += 1
  1051. if ctx['num'] == idx:
  1052. logger.info("Test: Valid challenge")
  1053. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1054. 4 + 1 + 3 + 8,
  1055. EAP_TYPE_LEAP,
  1056. 1, 0, 8, 0, 0)
  1057. idx += 1
  1058. if ctx['num'] == idx:
  1059. logger.info("Test: Valid challange value in Response")
  1060. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  1061. 4 + 1 + 3 + 24,
  1062. EAP_TYPE_LEAP,
  1063. 1, 0, 24,
  1064. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  1065. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  1066. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  1067. idx += 1
  1068. if ctx['num'] == idx:
  1069. logger.info("Test: Valid challenge")
  1070. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1071. 4 + 1 + 3 + 8,
  1072. EAP_TYPE_LEAP,
  1073. 1, 0, 8, 0, 0)
  1074. idx += 1
  1075. if ctx['num'] == idx:
  1076. logger.info("Test: Valid challange value in Response")
  1077. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  1078. 4 + 1 + 3 + 24,
  1079. EAP_TYPE_LEAP,
  1080. 1, 0, 24,
  1081. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  1082. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  1083. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  1084. idx += 1
  1085. if ctx['num'] == idx:
  1086. logger.info("Test: Valid challenge")
  1087. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1088. 4 + 1 + 3 + 8,
  1089. EAP_TYPE_LEAP,
  1090. 1, 0, 8, 0, 0)
  1091. idx += 1
  1092. if ctx['num'] == idx:
  1093. logger.info("Test: Valid challange value in Response")
  1094. return struct.pack(">BBHBBBB24B", EAP_CODE_RESPONSE, ctx['id'],
  1095. 4 + 1 + 3 + 24,
  1096. EAP_TYPE_LEAP,
  1097. 1, 0, 24,
  1098. 0x48, 0x4e, 0x46, 0xe3, 0x88, 0x49, 0x46, 0xbd,
  1099. 0x28, 0x48, 0xf8, 0x53, 0x82, 0x50, 0x00, 0x04,
  1100. 0x93, 0x50, 0x30, 0xd7, 0x25, 0xea, 0x5f, 0x66)
  1101. idx += 1
  1102. if ctx['num'] == idx:
  1103. logger.info("Test: Valid challenge")
  1104. return struct.pack(">BBHBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  1105. 4 + 1 + 3 + 8,
  1106. EAP_TYPE_LEAP,
  1107. 1, 0, 8, 0, 0)
  1108. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1109. srv = start_radius_server(leap_handler2)
  1110. try:
  1111. hapd = start_ap(apdev[0])
  1112. with alloc_fail(dev[0], 1, "eap_leap_init"):
  1113. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1114. eap="LEAP", identity="user", password="password",
  1115. wait_connect=False)
  1116. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1117. dev[0].request("REMOVE_NETWORK all")
  1118. dev[0].wait_disconnected()
  1119. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_leap_process_request"):
  1120. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1121. eap="LEAP", identity="user",
  1122. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1123. wait_connect=False)
  1124. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1125. dev[0].request("REMOVE_NETWORK all")
  1126. dev[0].wait_disconnected()
  1127. with alloc_fail(dev[0], 1, "eap_leap_process_success"):
  1128. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1129. eap="LEAP", identity="user", password="password",
  1130. wait_connect=False)
  1131. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1132. dev[0].request("REMOVE_NETWORK all")
  1133. dev[0].wait_disconnected()
  1134. with fail_test(dev[0], 1, "os_get_random;eap_leap_process_success"):
  1135. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1136. eap="LEAP", identity="user", password="password",
  1137. wait_connect=False)
  1138. wait_fail_trigger(dev[0], "GET_FAIL")
  1139. dev[0].request("REMOVE_NETWORK all")
  1140. dev[0].wait_disconnected()
  1141. with fail_test(dev[0], 1, "eap_leap_process_response"):
  1142. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1143. eap="LEAP", identity="user",
  1144. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1145. wait_connect=False)
  1146. wait_fail_trigger(dev[0], "GET_FAIL")
  1147. dev[0].request("REMOVE_NETWORK all")
  1148. dev[0].wait_disconnected()
  1149. with fail_test(dev[0], 1, "nt_password_hash;eap_leap_process_response"):
  1150. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1151. eap="LEAP", identity="user", password="password",
  1152. wait_connect=False)
  1153. wait_fail_trigger(dev[0], "GET_FAIL")
  1154. dev[0].request("REMOVE_NETWORK all")
  1155. dev[0].wait_disconnected()
  1156. with fail_test(dev[0], 1, "hash_nt_password_hash;eap_leap_process_response"):
  1157. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1158. eap="LEAP", identity="user", password="password",
  1159. wait_connect=False)
  1160. wait_fail_trigger(dev[0], "GET_FAIL")
  1161. dev[0].request("REMOVE_NETWORK all")
  1162. dev[0].wait_disconnected()
  1163. with alloc_fail(dev[0], 1, "eap_leap_getKey"):
  1164. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1165. eap="LEAP", identity="user",
  1166. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1167. wait_connect=False)
  1168. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1169. dev[0].request("REMOVE_NETWORK all")
  1170. dev[0].wait_disconnected()
  1171. with fail_test(dev[0], 1, "eap_leap_getKey"):
  1172. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1173. eap="LEAP", identity="user",
  1174. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1175. wait_connect=False)
  1176. wait_fail_trigger(dev[0], "GET_FAIL")
  1177. dev[0].request("REMOVE_NETWORK all")
  1178. dev[0].wait_disconnected()
  1179. with fail_test(dev[0], 1, "nt_password_hash;eap_leap_getKey"):
  1180. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1181. eap="LEAP", identity="user", password="password",
  1182. wait_connect=False)
  1183. wait_fail_trigger(dev[0], "GET_FAIL")
  1184. dev[0].request("REMOVE_NETWORK all")
  1185. dev[0].wait_disconnected()
  1186. with fail_test(dev[0], 1, "hash_nt_password_hash;eap_leap_getKey"):
  1187. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1188. eap="LEAP", identity="user", password="password",
  1189. wait_connect=False)
  1190. wait_fail_trigger(dev[0], "GET_FAIL")
  1191. dev[0].request("REMOVE_NETWORK all")
  1192. dev[0].wait_disconnected()
  1193. with fail_test(dev[0], 1,
  1194. "nt_challenge_response;eap_leap_process_request"):
  1195. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1196. eap="LEAP", identity="user", password="password",
  1197. wait_connect=False)
  1198. wait_fail_trigger(dev[0], "GET_FAIL")
  1199. dev[0].request("REMOVE_NETWORK all")
  1200. dev[0].wait_disconnected()
  1201. finally:
  1202. stop_radius_server(srv)
  1203. def test_eap_proto_md5(dev, apdev):
  1204. """EAP-MD5 protocol tests"""
  1205. check_eap_capa(dev[0], "MD5")
  1206. def md5_handler(ctx, req):
  1207. logger.info("md5_handler - RX " + req.encode("hex"))
  1208. if 'num' not in ctx:
  1209. ctx['num'] = 0
  1210. ctx['num'] = ctx['num'] + 1
  1211. if 'id' not in ctx:
  1212. ctx['id'] = 1
  1213. ctx['id'] = (ctx['id'] + 1) % 256
  1214. if ctx['num'] == 1:
  1215. logger.info("Test: Missing payload")
  1216. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  1217. 4 + 1,
  1218. EAP_TYPE_MD5)
  1219. if ctx['num'] == 2:
  1220. logger.info("Test: Zero-length challenge")
  1221. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1222. 4 + 1 + 1,
  1223. EAP_TYPE_MD5,
  1224. 0)
  1225. if ctx['num'] == 3:
  1226. logger.info("Test: Truncated challenge")
  1227. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1228. 4 + 1 + 1,
  1229. EAP_TYPE_MD5,
  1230. 1)
  1231. if ctx['num'] == 4:
  1232. logger.info("Test: Shortest possible challenge and name")
  1233. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  1234. 4 + 1 + 3,
  1235. EAP_TYPE_MD5,
  1236. 1, 0xaa, ord('n'))
  1237. return None
  1238. srv = start_radius_server(md5_handler)
  1239. try:
  1240. hapd = start_ap(apdev[0])
  1241. for i in range(0, 4):
  1242. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1243. eap="MD5", identity="user", password="password",
  1244. wait_connect=False)
  1245. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  1246. if ev is None:
  1247. raise Exception("Timeout on EAP start")
  1248. time.sleep(0.1)
  1249. dev[0].request("REMOVE_NETWORK all")
  1250. finally:
  1251. stop_radius_server(srv)
  1252. def test_eap_proto_md5_errors(dev, apdev):
  1253. """EAP-MD5 local error cases"""
  1254. check_eap_capa(dev[0], "MD5")
  1255. params = hostapd.wpa2_eap_params(ssid="eap-test")
  1256. hapd = hostapd.add_ap(apdev[0], params)
  1257. with fail_test(dev[0], 1, "chap_md5"):
  1258. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1259. eap="MD5", identity="phase1-user", password="password",
  1260. wait_connect=False)
  1261. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  1262. if ev is None:
  1263. raise Exception("Timeout on EAP start")
  1264. dev[0].request("REMOVE_NETWORK all")
  1265. dev[0].wait_disconnected()
  1266. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_md5_process"):
  1267. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1268. eap="MD5", identity="phase1-user", password="password",
  1269. wait_connect=False)
  1270. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  1271. if ev is None:
  1272. raise Exception("Timeout on EAP start")
  1273. time.sleep(0.1)
  1274. dev[0].request("REMOVE_NETWORK all")
  1275. def test_eap_proto_otp(dev, apdev):
  1276. """EAP-OTP protocol tests"""
  1277. def otp_handler(ctx, req):
  1278. logger.info("otp_handler - RX " + req.encode("hex"))
  1279. if 'num' not in ctx:
  1280. ctx['num'] = 0
  1281. ctx['num'] = ctx['num'] + 1
  1282. if 'id' not in ctx:
  1283. ctx['id'] = 1
  1284. ctx['id'] = (ctx['id'] + 1) % 256
  1285. if ctx['num'] == 1:
  1286. logger.info("Test: Empty payload")
  1287. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  1288. 4 + 1,
  1289. EAP_TYPE_OTP)
  1290. if ctx['num'] == 2:
  1291. logger.info("Test: Success")
  1292. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'],
  1293. 4)
  1294. if ctx['num'] == 3:
  1295. logger.info("Test: Challenge included")
  1296. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1297. 4 + 1 + 1,
  1298. EAP_TYPE_OTP,
  1299. ord('A'))
  1300. if ctx['num'] == 4:
  1301. logger.info("Test: Success")
  1302. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'],
  1303. 4)
  1304. return None
  1305. srv = start_radius_server(otp_handler)
  1306. try:
  1307. hapd = start_ap(apdev[0])
  1308. for i in range(0, 1):
  1309. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1310. eap="OTP", identity="user", password="password",
  1311. wait_connect=False)
  1312. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  1313. timeout=15)
  1314. if ev is None:
  1315. raise Exception("Timeout on EAP start")
  1316. time.sleep(0.1)
  1317. dev[0].request("REMOVE_NETWORK all")
  1318. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1319. eap="OTP", identity="user", wait_connect=False)
  1320. ev = dev[0].wait_event(["CTRL-REQ-OTP"])
  1321. if ev is None:
  1322. raise Exception("Request for password timed out")
  1323. id = ev.split(':')[0].split('-')[-1]
  1324. dev[0].request("CTRL-RSP-OTP-" + id + ":password")
  1325. ev = dev[0].wait_event("CTRL-EVENT-EAP-SUCCESS")
  1326. if ev is None:
  1327. raise Exception("Success not reported")
  1328. finally:
  1329. stop_radius_server(srv)
  1330. def test_eap_proto_otp_errors(dev, apdev):
  1331. """EAP-OTP local error cases"""
  1332. def otp_handler2(ctx, req):
  1333. logger.info("otp_handler2 - RX " + req.encode("hex"))
  1334. if 'num' not in ctx:
  1335. ctx['num'] = 0
  1336. ctx['num'] = ctx['num'] + 1
  1337. if 'id' not in ctx:
  1338. ctx['id'] = 1
  1339. ctx['id'] = (ctx['id'] + 1) % 256
  1340. idx = 0
  1341. idx += 1
  1342. if ctx['num'] == idx:
  1343. logger.info("Test: Challenge included")
  1344. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1345. 4 + 1 + 1,
  1346. EAP_TYPE_OTP,
  1347. ord('A'))
  1348. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1349. srv = start_radius_server(otp_handler2)
  1350. try:
  1351. hapd = start_ap(apdev[0])
  1352. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_otp_process"):
  1353. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1354. eap="OTP", identity="user", password="password",
  1355. wait_connect=False)
  1356. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1357. dev[0].request("REMOVE_NETWORK all")
  1358. dev[0].wait_disconnected()
  1359. finally:
  1360. stop_radius_server(srv)
  1361. EAP_GPSK_OPCODE_GPSK_1 = 1
  1362. EAP_GPSK_OPCODE_GPSK_2 = 2
  1363. EAP_GPSK_OPCODE_GPSK_3 = 3
  1364. EAP_GPSK_OPCODE_GPSK_4 = 4
  1365. EAP_GPSK_OPCODE_FAIL = 5
  1366. EAP_GPSK_OPCODE_PROTECTED_FAIL = 6
  1367. def test_eap_proto_gpsk(dev, apdev):
  1368. """EAP-GPSK protocol tests"""
  1369. def gpsk_handler(ctx, req):
  1370. logger.info("gpsk_handler - RX " + req.encode("hex"))
  1371. if 'num' not in ctx:
  1372. ctx['num'] = 0
  1373. ctx['num'] = ctx['num'] + 1
  1374. if 'id' not in ctx:
  1375. ctx['id'] = 1
  1376. ctx['id'] = (ctx['id'] + 1) % 256
  1377. idx = 0
  1378. idx += 1
  1379. if ctx['num'] == idx:
  1380. logger.info("Test: Missing payload")
  1381. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  1382. 4 + 1,
  1383. EAP_TYPE_GPSK)
  1384. idx += 1
  1385. if ctx['num'] == idx:
  1386. logger.info("Test: Unknown opcode")
  1387. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1388. 4 + 1 + 1,
  1389. EAP_TYPE_GPSK,
  1390. 255)
  1391. idx += 1
  1392. if ctx['num'] == idx:
  1393. logger.info("Test: Unexpected GPSK-3")
  1394. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1395. 4 + 1 + 1,
  1396. EAP_TYPE_GPSK,
  1397. EAP_GPSK_OPCODE_GPSK_3)
  1398. idx += 1
  1399. if ctx['num'] == idx:
  1400. logger.info("Test: GPSK-1 Too short GPSK-1")
  1401. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1402. 4 + 1 + 1,
  1403. EAP_TYPE_GPSK,
  1404. EAP_GPSK_OPCODE_GPSK_1)
  1405. idx += 1
  1406. if ctx['num'] == idx:
  1407. logger.info("Test: GPSK-1 Truncated ID_Server")
  1408. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  1409. 4 + 1 + 1 + 2,
  1410. EAP_TYPE_GPSK,
  1411. EAP_GPSK_OPCODE_GPSK_1, 1)
  1412. idx += 1
  1413. if ctx['num'] == idx:
  1414. logger.info("Test: GPSK-1 Missing RAND_Server")
  1415. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  1416. 4 + 1 + 1 + 2,
  1417. EAP_TYPE_GPSK,
  1418. EAP_GPSK_OPCODE_GPSK_1, 0)
  1419. idx += 1
  1420. if ctx['num'] == idx:
  1421. logger.info("Test: GPSK-1 Missing CSuite_List")
  1422. return struct.pack(">BBHBBH8L", EAP_CODE_REQUEST, ctx['id'],
  1423. 4 + 1 + 1 + 2 + 32,
  1424. EAP_TYPE_GPSK,
  1425. EAP_GPSK_OPCODE_GPSK_1, 0,
  1426. 0, 0, 0, 0, 0, 0, 0, 0)
  1427. idx += 1
  1428. if ctx['num'] == idx:
  1429. logger.info("Test: GPSK-1 Truncated CSuite_List")
  1430. return struct.pack(">BBHBBH8LH", EAP_CODE_REQUEST, ctx['id'],
  1431. 4 + 1 + 1 + 2 + 32 + 2,
  1432. EAP_TYPE_GPSK,
  1433. EAP_GPSK_OPCODE_GPSK_1, 0,
  1434. 0, 0, 0, 0, 0, 0, 0, 0,
  1435. 1)
  1436. idx += 1
  1437. if ctx['num'] == idx:
  1438. logger.info("Test: GPSK-1 Empty CSuite_List")
  1439. return struct.pack(">BBHBBH8LH", EAP_CODE_REQUEST, ctx['id'],
  1440. 4 + 1 + 1 + 2 + 32 + 2,
  1441. EAP_TYPE_GPSK,
  1442. EAP_GPSK_OPCODE_GPSK_1, 0,
  1443. 0, 0, 0, 0, 0, 0, 0, 0,
  1444. 0)
  1445. idx += 1
  1446. if ctx['num'] == idx:
  1447. logger.info("Test: GPSK-1 Invalid CSuite_List")
  1448. return struct.pack(">BBHBBH8LHB", EAP_CODE_REQUEST, ctx['id'],
  1449. 4 + 1 + 1 + 2 + 32 + 2 + 1,
  1450. EAP_TYPE_GPSK,
  1451. EAP_GPSK_OPCODE_GPSK_1, 0,
  1452. 0, 0, 0, 0, 0, 0, 0, 0,
  1453. 1, 0)
  1454. idx += 1
  1455. if ctx['num'] == idx:
  1456. logger.info("Test: GPSK-1 No supported CSuite")
  1457. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1458. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1459. EAP_TYPE_GPSK,
  1460. EAP_GPSK_OPCODE_GPSK_1, 0,
  1461. 0, 0, 0, 0, 0, 0, 0, 0,
  1462. 6, 0, 0)
  1463. idx += 1
  1464. if ctx['num'] == idx:
  1465. logger.info("Test: GPSK-1 Supported CSuite")
  1466. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1467. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1468. EAP_TYPE_GPSK,
  1469. EAP_GPSK_OPCODE_GPSK_1, 0,
  1470. 0, 0, 0, 0, 0, 0, 0, 0,
  1471. 6, 0, 1)
  1472. idx += 1
  1473. if ctx['num'] == idx:
  1474. logger.info("Test: Unexpected GPSK-1")
  1475. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1476. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1477. EAP_TYPE_GPSK,
  1478. EAP_GPSK_OPCODE_GPSK_1, 0,
  1479. 0, 0, 0, 0, 0, 0, 0, 0,
  1480. 6, 0, 1)
  1481. idx += 1
  1482. if ctx['num'] == idx:
  1483. logger.info("Test: GPSK-1 Supported CSuite but too short key")
  1484. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1485. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1486. EAP_TYPE_GPSK,
  1487. EAP_GPSK_OPCODE_GPSK_1, 0,
  1488. 0, 0, 0, 0, 0, 0, 0, 0,
  1489. 6, 0, 1)
  1490. idx += 1
  1491. if ctx['num'] == idx:
  1492. logger.info("Test: GPSK-1 Supported CSuite")
  1493. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1494. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1495. EAP_TYPE_GPSK,
  1496. EAP_GPSK_OPCODE_GPSK_1, 0,
  1497. 0, 0, 0, 0, 0, 0, 0, 0,
  1498. 6, 0, 1)
  1499. idx += 1
  1500. if ctx['num'] == idx:
  1501. logger.info("Test: Too short GPSK-3")
  1502. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1503. 4 + 1 + 1,
  1504. EAP_TYPE_GPSK,
  1505. EAP_GPSK_OPCODE_GPSK_3)
  1506. idx += 1
  1507. if ctx['num'] == idx:
  1508. logger.info("Test: GPSK-1 Supported CSuite")
  1509. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1510. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1511. EAP_TYPE_GPSK,
  1512. EAP_GPSK_OPCODE_GPSK_1, 0,
  1513. 0, 0, 0, 0, 0, 0, 0, 0,
  1514. 6, 0, 1)
  1515. idx += 1
  1516. if ctx['num'] == idx:
  1517. logger.info("Test: GPSK-3 Mismatch in RAND_Peer")
  1518. return struct.pack(">BBHBB8L", EAP_CODE_REQUEST, ctx['id'],
  1519. 4 + 1 + 1 + 32,
  1520. EAP_TYPE_GPSK,
  1521. EAP_GPSK_OPCODE_GPSK_3,
  1522. 0, 0, 0, 0, 0, 0, 0, 0)
  1523. idx += 1
  1524. if ctx['num'] == idx:
  1525. logger.info("Test: GPSK-1 Supported CSuite")
  1526. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1527. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1528. EAP_TYPE_GPSK,
  1529. EAP_GPSK_OPCODE_GPSK_1, 0,
  1530. 0, 0, 0, 0, 0, 0, 0, 0,
  1531. 6, 0, 1)
  1532. idx += 1
  1533. if ctx['num'] == idx:
  1534. logger.info("Test: GPSK-3 Missing RAND_Server")
  1535. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1536. 4 + 1 + 1 + 32,
  1537. EAP_TYPE_GPSK,
  1538. EAP_GPSK_OPCODE_GPSK_3)
  1539. msg += req[14:46]
  1540. return msg
  1541. idx += 1
  1542. if ctx['num'] == idx:
  1543. logger.info("Test: GPSK-1 Supported CSuite")
  1544. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1545. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1546. EAP_TYPE_GPSK,
  1547. EAP_GPSK_OPCODE_GPSK_1, 0,
  1548. 0, 0, 0, 0, 0, 0, 0, 0,
  1549. 6, 0, 1)
  1550. idx += 1
  1551. if ctx['num'] == idx:
  1552. logger.info("Test: GPSK-3 Mismatch in RAND_Server")
  1553. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1554. 4 + 1 + 1 + 32 + 32,
  1555. EAP_TYPE_GPSK,
  1556. EAP_GPSK_OPCODE_GPSK_3)
  1557. msg += req[14:46]
  1558. msg += struct.pack(">8L", 1, 1, 1, 1, 1, 1, 1, 1)
  1559. return msg
  1560. idx += 1
  1561. if ctx['num'] == idx:
  1562. logger.info("Test: GPSK-1 Supported CSuite")
  1563. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1564. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1565. EAP_TYPE_GPSK,
  1566. EAP_GPSK_OPCODE_GPSK_1, 0,
  1567. 0, 0, 0, 0, 0, 0, 0, 0,
  1568. 6, 0, 1)
  1569. idx += 1
  1570. if ctx['num'] == idx:
  1571. logger.info("Test: GPSK-3 Missing ID_Server")
  1572. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1573. 4 + 1 + 1 + 32 + 32,
  1574. EAP_TYPE_GPSK,
  1575. EAP_GPSK_OPCODE_GPSK_3)
  1576. msg += req[14:46]
  1577. msg += struct.pack(">8L", 0, 0, 0, 0, 0, 0, 0, 0)
  1578. return msg
  1579. idx += 1
  1580. if ctx['num'] == idx:
  1581. logger.info("Test: GPSK-1 Supported CSuite")
  1582. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1583. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1584. EAP_TYPE_GPSK,
  1585. EAP_GPSK_OPCODE_GPSK_1, 0,
  1586. 0, 0, 0, 0, 0, 0, 0, 0,
  1587. 6, 0, 1)
  1588. idx += 1
  1589. if ctx['num'] == idx:
  1590. logger.info("Test: GPSK-3 Truncated ID_Server")
  1591. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1592. 4 + 1 + 1 + 32 + 32 + 2,
  1593. EAP_TYPE_GPSK,
  1594. EAP_GPSK_OPCODE_GPSK_3)
  1595. msg += req[14:46]
  1596. msg += struct.pack(">8LH", 0, 0, 0, 0, 0, 0, 0, 0, 1)
  1597. return msg
  1598. idx += 1
  1599. if ctx['num'] == idx:
  1600. logger.info("Test: GPSK-1 Supported CSuite")
  1601. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1602. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1603. EAP_TYPE_GPSK,
  1604. EAP_GPSK_OPCODE_GPSK_1, 0,
  1605. 0, 0, 0, 0, 0, 0, 0, 0,
  1606. 6, 0, 1)
  1607. idx += 1
  1608. if ctx['num'] == idx:
  1609. logger.info("Test: GPSK-3 Mismatch in ID_Server")
  1610. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1611. 4 + 1 + 1 + 32 + 32 + 3,
  1612. EAP_TYPE_GPSK,
  1613. EAP_GPSK_OPCODE_GPSK_3)
  1614. msg += req[14:46]
  1615. msg += struct.pack(">8LHB", 0, 0, 0, 0, 0, 0, 0, 0, 1, ord('B'))
  1616. return msg
  1617. idx += 1
  1618. if ctx['num'] == idx:
  1619. logger.info("Test: GPSK-1 Supported CSuite")
  1620. return struct.pack(">BBHBBHB8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1621. 4 + 1 + 1 + 3 + 32 + 2 + 6,
  1622. EAP_TYPE_GPSK,
  1623. EAP_GPSK_OPCODE_GPSK_1, 1, ord('A'),
  1624. 0, 0, 0, 0, 0, 0, 0, 0,
  1625. 6, 0, 1)
  1626. idx += 1
  1627. if ctx['num'] == idx:
  1628. logger.info("Test: GPSK-3 Mismatch in ID_Server (same length)")
  1629. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1630. 4 + 1 + 1 + 32 + 32 + 3,
  1631. EAP_TYPE_GPSK,
  1632. EAP_GPSK_OPCODE_GPSK_3)
  1633. msg += req[15:47]
  1634. msg += struct.pack(">8LHB", 0, 0, 0, 0, 0, 0, 0, 0, 1, ord('B'))
  1635. return msg
  1636. idx += 1
  1637. if ctx['num'] == idx:
  1638. logger.info("Test: GPSK-1 Supported CSuite")
  1639. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1640. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1641. EAP_TYPE_GPSK,
  1642. EAP_GPSK_OPCODE_GPSK_1, 0,
  1643. 0, 0, 0, 0, 0, 0, 0, 0,
  1644. 6, 0, 1)
  1645. idx += 1
  1646. if ctx['num'] == idx:
  1647. logger.info("Test: GPSK-3 Missing CSuite_Sel")
  1648. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1649. 4 + 1 + 1 + 32 + 32 + 2,
  1650. EAP_TYPE_GPSK,
  1651. EAP_GPSK_OPCODE_GPSK_3)
  1652. msg += req[14:46]
  1653. msg += struct.pack(">8LH", 0, 0, 0, 0, 0, 0, 0, 0, 0)
  1654. return msg
  1655. idx += 1
  1656. if ctx['num'] == idx:
  1657. logger.info("Test: GPSK-1 Supported CSuite")
  1658. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1659. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1660. EAP_TYPE_GPSK,
  1661. EAP_GPSK_OPCODE_GPSK_1, 0,
  1662. 0, 0, 0, 0, 0, 0, 0, 0,
  1663. 6, 0, 1)
  1664. idx += 1
  1665. if ctx['num'] == idx:
  1666. logger.info("Test: GPSK-3 Mismatch in CSuite_Sel")
  1667. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1668. 4 + 1 + 1 + 32 + 32 + 2 + 6,
  1669. EAP_TYPE_GPSK,
  1670. EAP_GPSK_OPCODE_GPSK_3)
  1671. msg += req[14:46]
  1672. msg += struct.pack(">8LHLH", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2)
  1673. return msg
  1674. idx += 1
  1675. if ctx['num'] == idx:
  1676. logger.info("Test: GPSK-1 Supported CSuite")
  1677. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1678. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1679. EAP_TYPE_GPSK,
  1680. EAP_GPSK_OPCODE_GPSK_1, 0,
  1681. 0, 0, 0, 0, 0, 0, 0, 0,
  1682. 6, 0, 1)
  1683. idx += 1
  1684. if ctx['num'] == idx:
  1685. logger.info("Test: GPSK-3 Missing len(PD_Payload_Block)")
  1686. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1687. 4 + 1 + 1 + 32 + 32 + 2 + 6,
  1688. EAP_TYPE_GPSK,
  1689. EAP_GPSK_OPCODE_GPSK_3)
  1690. msg += req[14:46]
  1691. msg += struct.pack(">8LHLH", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
  1692. return msg
  1693. idx += 1
  1694. if ctx['num'] == idx:
  1695. logger.info("Test: GPSK-1 Supported CSuite")
  1696. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1697. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1698. EAP_TYPE_GPSK,
  1699. EAP_GPSK_OPCODE_GPSK_1, 0,
  1700. 0, 0, 0, 0, 0, 0, 0, 0,
  1701. 6, 0, 1)
  1702. idx += 1
  1703. if ctx['num'] == idx:
  1704. logger.info("Test: GPSK-3 Truncated PD_Payload_Block")
  1705. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1706. 4 + 1 + 1 + 32 + 32 + 2 + 6 + 2,
  1707. EAP_TYPE_GPSK,
  1708. EAP_GPSK_OPCODE_GPSK_3)
  1709. msg += req[14:46]
  1710. msg += struct.pack(">8LHLHH", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1)
  1711. return msg
  1712. idx += 1
  1713. if ctx['num'] == idx:
  1714. logger.info("Test: GPSK-1 Supported CSuite")
  1715. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1716. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1717. EAP_TYPE_GPSK,
  1718. EAP_GPSK_OPCODE_GPSK_1, 0,
  1719. 0, 0, 0, 0, 0, 0, 0, 0,
  1720. 6, 0, 1)
  1721. idx += 1
  1722. if ctx['num'] == idx:
  1723. logger.info("Test: GPSK-3 Missing MAC")
  1724. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1725. 4 + 1 + 1 + 32 + 32 + 2 + 6 + 3,
  1726. EAP_TYPE_GPSK,
  1727. EAP_GPSK_OPCODE_GPSK_3)
  1728. msg += req[14:46]
  1729. msg += struct.pack(">8LHLHHB",
  1730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 123)
  1731. return msg
  1732. idx += 1
  1733. if ctx['num'] == idx:
  1734. logger.info("Test: GPSK-1 Supported CSuite")
  1735. return struct.pack(">BBHBBH8LHLH", EAP_CODE_REQUEST, ctx['id'],
  1736. 4 + 1 + 1 + 2 + 32 + 2 + 6,
  1737. EAP_TYPE_GPSK,
  1738. EAP_GPSK_OPCODE_GPSK_1, 0,
  1739. 0, 0, 0, 0, 0, 0, 0, 0,
  1740. 6, 0, 1)
  1741. idx += 1
  1742. if ctx['num'] == idx:
  1743. logger.info("Test: GPSK-3 Incorrect MAC")
  1744. msg = struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1745. 4 + 1 + 1 + 32 + 32 + 2 + 6 + 3 + 16,
  1746. EAP_TYPE_GPSK,
  1747. EAP_GPSK_OPCODE_GPSK_3)
  1748. msg += req[14:46]
  1749. msg += struct.pack(">8LHLHHB4L",
  1750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 123,
  1751. 0, 0, 0, 0)
  1752. return msg
  1753. return None
  1754. srv = start_radius_server(gpsk_handler)
  1755. try:
  1756. hapd = start_ap(apdev[0])
  1757. for i in range(0, 27):
  1758. if i == 12:
  1759. pw = "short"
  1760. else:
  1761. pw = "abcdefghijklmnop0123456789abcdef"
  1762. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  1763. eap="GPSK", identity="user", password=pw,
  1764. wait_connect=False)
  1765. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  1766. timeout=15)
  1767. if ev is None:
  1768. raise Exception("Timeout on EAP start")
  1769. time.sleep(0.05)
  1770. dev[0].request("REMOVE_NETWORK all")
  1771. finally:
  1772. stop_radius_server(srv)
  1773. EAP_EKE_ID = 1
  1774. EAP_EKE_COMMIT = 2
  1775. EAP_EKE_CONFIRM = 3
  1776. EAP_EKE_FAILURE = 4
  1777. def test_eap_proto_eke(dev, apdev):
  1778. """EAP-EKE protocol tests"""
  1779. def eke_handler(ctx, req):
  1780. logger.info("eke_handler - RX " + req.encode("hex"))
  1781. if 'num' not in ctx:
  1782. ctx['num'] = 0
  1783. ctx['num'] = ctx['num'] + 1
  1784. if 'id' not in ctx:
  1785. ctx['id'] = 1
  1786. ctx['id'] = (ctx['id'] + 1) % 256
  1787. idx = 0
  1788. idx += 1
  1789. if ctx['num'] == idx:
  1790. logger.info("Test: Missing payload")
  1791. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  1792. 4 + 1,
  1793. EAP_TYPE_EKE)
  1794. idx += 1
  1795. if ctx['num'] == idx:
  1796. logger.info("Test: Unknown exchange")
  1797. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1798. 4 + 1 + 1,
  1799. EAP_TYPE_EKE,
  1800. 255)
  1801. idx += 1
  1802. if ctx['num'] == idx:
  1803. logger.info("Test: No NumProposals in EAP-EKE-ID/Request")
  1804. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  1805. 4 + 1 + 1,
  1806. EAP_TYPE_EKE,
  1807. EAP_EKE_ID)
  1808. idx += 1
  1809. if ctx['num'] == idx:
  1810. logger.info("Test: EAP-Failure")
  1811. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1812. idx += 1
  1813. if ctx['num'] == idx:
  1814. logger.info("Test: NumProposals=0 in EAP-EKE-ID/Request")
  1815. return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
  1816. 4 + 1 + 1 + 1,
  1817. EAP_TYPE_EKE,
  1818. EAP_EKE_ID,
  1819. 0)
  1820. idx += 1
  1821. if ctx['num'] == idx:
  1822. logger.info("Test: EAP-Failure")
  1823. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1824. idx += 1
  1825. if ctx['num'] == idx:
  1826. logger.info("Test: Truncated Proposals list in EAP-EKE-ID/Request")
  1827. return struct.pack(">BBHBBBB4B", EAP_CODE_REQUEST, ctx['id'],
  1828. 4 + 1 + 1 + 2 + 4,
  1829. EAP_TYPE_EKE,
  1830. EAP_EKE_ID,
  1831. 2, 0, 0, 0, 0, 0)
  1832. idx += 1
  1833. if ctx['num'] == idx:
  1834. logger.info("Test: EAP-Failure")
  1835. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1836. idx += 1
  1837. if ctx['num'] == idx:
  1838. logger.info("Test: Unsupported proposals in EAP-EKE-ID/Request")
  1839. return struct.pack(">BBHBBBB4B4B4B4B", EAP_CODE_REQUEST, ctx['id'],
  1840. 4 + 1 + 1 + 2 + 4 * 4,
  1841. EAP_TYPE_EKE,
  1842. EAP_EKE_ID,
  1843. 4, 0,
  1844. 0, 0, 0, 0,
  1845. 3, 0, 0, 0,
  1846. 3, 1, 0, 0,
  1847. 3, 1, 1, 0)
  1848. idx += 1
  1849. if ctx['num'] == idx:
  1850. logger.info("Test: EAP-Failure")
  1851. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1852. idx += 1
  1853. if ctx['num'] == idx:
  1854. logger.info("Test: Missing IDType/Identity in EAP-EKE-ID/Request")
  1855. return struct.pack(">BBHBBBB4B4B4B4B4B",
  1856. EAP_CODE_REQUEST, ctx['id'],
  1857. 4 + 1 + 1 + 2 + 5 * 4,
  1858. EAP_TYPE_EKE,
  1859. EAP_EKE_ID,
  1860. 5, 0,
  1861. 0, 0, 0, 0,
  1862. 3, 0, 0, 0,
  1863. 3, 1, 0, 0,
  1864. 3, 1, 1, 0,
  1865. 3, 1, 1, 1)
  1866. idx += 1
  1867. if ctx['num'] == idx:
  1868. logger.info("Test: EAP-Failure")
  1869. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1870. idx += 1
  1871. if ctx['num'] == idx:
  1872. logger.info("Test: Valid EAP-EKE-ID/Request")
  1873. return struct.pack(">BBHBBBB4BB",
  1874. EAP_CODE_REQUEST, ctx['id'],
  1875. 4 + 1 + 1 + 2 + 4 + 1,
  1876. EAP_TYPE_EKE,
  1877. EAP_EKE_ID,
  1878. 1, 0,
  1879. 3, 1, 1, 1,
  1880. 255)
  1881. idx += 1
  1882. if ctx['num'] == idx:
  1883. logger.info("Test: Unexpected EAP-EKE-ID/Request")
  1884. return struct.pack(">BBHBBBB4BB",
  1885. EAP_CODE_REQUEST, ctx['id'],
  1886. 4 + 1 + 1 + 2 + 4 + 1,
  1887. EAP_TYPE_EKE,
  1888. EAP_EKE_ID,
  1889. 1, 0,
  1890. 3, 1, 1, 1,
  1891. 255)
  1892. idx += 1
  1893. if ctx['num'] == idx:
  1894. logger.info("Test: EAP-Failure")
  1895. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1896. idx += 1
  1897. if ctx['num'] == idx:
  1898. logger.info("Test: Valid EAP-EKE-ID/Request")
  1899. return struct.pack(">BBHBBBB4BB",
  1900. EAP_CODE_REQUEST, ctx['id'],
  1901. 4 + 1 + 1 + 2 + 4 + 1,
  1902. EAP_TYPE_EKE,
  1903. EAP_EKE_ID,
  1904. 1, 0,
  1905. 3, 1, 1, 1,
  1906. 255)
  1907. idx += 1
  1908. if ctx['num'] == idx:
  1909. logger.info("Test: Unexpected EAP-EKE-Confirm/Request")
  1910. return struct.pack(">BBHBB",
  1911. EAP_CODE_REQUEST, ctx['id'],
  1912. 4 + 1 + 1,
  1913. EAP_TYPE_EKE,
  1914. EAP_EKE_CONFIRM)
  1915. idx += 1
  1916. if ctx['num'] == idx:
  1917. logger.info("Test: EAP-Failure")
  1918. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1919. idx += 1
  1920. if ctx['num'] == idx:
  1921. logger.info("Test: Too short EAP-EKE-Failure/Request")
  1922. return struct.pack(">BBHBB",
  1923. EAP_CODE_REQUEST, ctx['id'],
  1924. 4 + 1 + 1,
  1925. EAP_TYPE_EKE,
  1926. EAP_EKE_FAILURE)
  1927. idx += 1
  1928. if ctx['num'] == idx:
  1929. logger.info("Test: EAP-Failure")
  1930. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1931. idx += 1
  1932. if ctx['num'] == idx:
  1933. logger.info("Test: Unexpected EAP-EKE-Commit/Request")
  1934. return struct.pack(">BBHBB",
  1935. EAP_CODE_REQUEST, ctx['id'],
  1936. 4 + 1 + 1,
  1937. EAP_TYPE_EKE,
  1938. EAP_EKE_COMMIT)
  1939. idx += 1
  1940. if ctx['num'] == idx:
  1941. logger.info("Test: EAP-Failure")
  1942. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1943. idx += 1
  1944. if ctx['num'] == idx:
  1945. logger.info("Test: Valid EAP-EKE-ID/Request")
  1946. return struct.pack(">BBHBBBB4BB",
  1947. EAP_CODE_REQUEST, ctx['id'],
  1948. 4 + 1 + 1 + 2 + 4 + 1,
  1949. EAP_TYPE_EKE,
  1950. EAP_EKE_ID,
  1951. 1, 0,
  1952. 3, 1, 1, 1,
  1953. 255)
  1954. idx += 1
  1955. if ctx['num'] == idx:
  1956. logger.info("Test: Too short EAP-EKE-Commit/Request")
  1957. return struct.pack(">BBHBB",
  1958. EAP_CODE_REQUEST, ctx['id'],
  1959. 4 + 1 + 1,
  1960. EAP_TYPE_EKE,
  1961. EAP_EKE_COMMIT)
  1962. idx += 1
  1963. if ctx['num'] == idx:
  1964. logger.info("Test: EAP-Failure")
  1965. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  1966. idx += 1
  1967. if ctx['num'] == idx:
  1968. logger.info("Test: Valid EAP-EKE-ID/Request")
  1969. return struct.pack(">BBHBBBB4BB",
  1970. EAP_CODE_REQUEST, ctx['id'],
  1971. 4 + 1 + 1 + 2 + 4 + 1,
  1972. EAP_TYPE_EKE,
  1973. EAP_EKE_ID,
  1974. 1, 0,
  1975. 1, 1, 1, 1,
  1976. 255)
  1977. idx += 1
  1978. if ctx['num'] == idx:
  1979. logger.info("Test: All zeroes DHComponent_S and empty CBvalue in EAP-EKE-Commit/Request")
  1980. return struct.pack(">BBHBB4L32L",
  1981. EAP_CODE_REQUEST, ctx['id'],
  1982. 4 + 1 + 1 + 16 + 128,
  1983. EAP_TYPE_EKE,
  1984. EAP_EKE_COMMIT,
  1985. 0, 0, 0, 0,
  1986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  1988. idx += 1
  1989. if ctx['num'] == idx:
  1990. logger.info("Test: Too short EAP-EKE-Confirm/Request")
  1991. return struct.pack(">BBHBB",
  1992. EAP_CODE_REQUEST, ctx['id'],
  1993. 4 + 1 + 1,
  1994. EAP_TYPE_EKE,
  1995. EAP_EKE_CONFIRM)
  1996. idx += 1
  1997. if ctx['num'] == idx:
  1998. logger.info("Test: EAP-Failure")
  1999. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2000. idx += 1
  2001. if ctx['num'] == idx:
  2002. logger.info("Test: Valid EAP-EKE-ID/Request")
  2003. return struct.pack(">BBHBBBB4BB",
  2004. EAP_CODE_REQUEST, ctx['id'],
  2005. 4 + 1 + 1 + 2 + 4 + 1,
  2006. EAP_TYPE_EKE,
  2007. EAP_EKE_ID,
  2008. 1, 0,
  2009. 1, 1, 1, 1,
  2010. 255)
  2011. idx += 1
  2012. if ctx['num'] == idx:
  2013. logger.info("Test: All zeroes DHComponent_S and empty CBvalue in EAP-EKE-Commit/Request")
  2014. return struct.pack(">BBHBB4L32L",
  2015. EAP_CODE_REQUEST, ctx['id'],
  2016. 4 + 1 + 1 + 16 + 128,
  2017. EAP_TYPE_EKE,
  2018. EAP_EKE_COMMIT,
  2019. 0, 0, 0, 0,
  2020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  2022. idx += 1
  2023. if ctx['num'] == idx:
  2024. logger.info("Test: Invalid PNonce_PS and Auth_S values in EAP-EKE-Confirm/Request")
  2025. return struct.pack(">BBHBB4L8L5L5L",
  2026. EAP_CODE_REQUEST, ctx['id'],
  2027. 4 + 1 + 1 + 16 + 2 * 16 + 20 + 20,
  2028. EAP_TYPE_EKE,
  2029. EAP_EKE_CONFIRM,
  2030. 0, 0, 0, 0,
  2031. 0, 0, 0, 0, 0, 0, 0, 0,
  2032. 0, 0, 0, 0, 0,
  2033. 0, 0, 0, 0, 0)
  2034. idx += 1
  2035. if ctx['num'] == idx:
  2036. logger.info("Test: EAP-Failure")
  2037. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2038. return None
  2039. srv = start_radius_server(eke_handler)
  2040. try:
  2041. hapd = start_ap(apdev[0])
  2042. for i in range(0, 14):
  2043. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2044. eap="EKE", identity="user", password="password",
  2045. wait_connect=False)
  2046. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  2047. timeout=15)
  2048. if ev is None:
  2049. raise Exception("Timeout on EAP start")
  2050. if i in [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]:
  2051. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  2052. timeout=10)
  2053. if ev is None:
  2054. raise Exception("Timeout on EAP failure")
  2055. else:
  2056. time.sleep(0.05)
  2057. dev[0].request("REMOVE_NETWORK all")
  2058. dev[0].dump_monitor()
  2059. finally:
  2060. stop_radius_server(srv)
  2061. def eap_eke_test_fail(dev, phase1=None, success=False):
  2062. dev.connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2063. eap="EKE", identity="eke user@domain", password="hello",
  2064. phase1=phase1, erp="1", wait_connect=False)
  2065. ev = dev.wait_event([ "CTRL-EVENT-EAP-FAILURE",
  2066. "CTRL-EVENT-EAP-SUCCESS" ], timeout=5)
  2067. if ev is None:
  2068. raise Exception("Timeout on EAP failure")
  2069. if not success and "CTRL-EVENT-EAP-FAILURE" not in ev:
  2070. raise Exception("EAP did not fail during failure test")
  2071. dev.request("REMOVE_NETWORK all")
  2072. dev.wait_disconnected()
  2073. def test_eap_proto_eke_errors(dev, apdev):
  2074. """EAP-EKE local error cases"""
  2075. check_eap_capa(dev[0], "EKE")
  2076. params = hostapd.wpa2_eap_params(ssid="eap-test")
  2077. hapd = hostapd.add_ap(apdev[0], params)
  2078. for i in range(1, 3):
  2079. with alloc_fail(dev[0], i, "eap_eke_init"):
  2080. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2081. eap="EKE", identity="eke user", password="hello",
  2082. wait_connect=False)
  2083. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2084. timeout=15)
  2085. if ev is None:
  2086. raise Exception("Timeout on EAP start")
  2087. dev[0].request("REMOVE_NETWORK all")
  2088. dev[0].wait_disconnected()
  2089. tests = [ (1, "eap_eke_dh_init", None),
  2090. (1, "eap_eke_prf_hmac_sha1", "dhgroup=3 encr=1 prf=1 mac=1"),
  2091. (1, "eap_eke_prf_hmac_sha256", "dhgroup=5 encr=1 prf=2 mac=2"),
  2092. (1, "eap_eke_prf", None),
  2093. (1, "os_get_random;eap_eke_dhcomp", None),
  2094. (1, "aes_128_cbc_encrypt;eap_eke_dhcomp", None),
  2095. (1, "aes_128_cbc_decrypt;eap_eke_shared_secret", None),
  2096. (1, "eap_eke_prf;eap_eke_shared_secret", None),
  2097. (1, "eap_eke_prfplus;eap_eke_derive_ke_ki", None),
  2098. (1, "eap_eke_prfplus;eap_eke_derive_ka", None),
  2099. (1, "eap_eke_prfplus;eap_eke_derive_msk", None),
  2100. (1, "os_get_random;eap_eke_prot", None),
  2101. (1, "aes_128_cbc_decrypt;eap_eke_decrypt_prot", None),
  2102. (1, "eap_eke_derive_key;eap_eke_process_commit", None),
  2103. (1, "eap_eke_dh_init;eap_eke_process_commit", None),
  2104. (1, "eap_eke_shared_secret;eap_eke_process_commit", None),
  2105. (1, "eap_eke_derive_ke_ki;eap_eke_process_commit", None),
  2106. (1, "eap_eke_dhcomp;eap_eke_process_commit", None),
  2107. (1, "os_get_random;eap_eke_process_commit", None),
  2108. (1, "os_get_random;=eap_eke_process_commit", None),
  2109. (1, "eap_eke_prot;eap_eke_process_commit", None),
  2110. (1, "eap_eke_decrypt_prot;eap_eke_process_confirm", None),
  2111. (1, "eap_eke_derive_ka;eap_eke_process_confirm", None),
  2112. (1, "eap_eke_auth;eap_eke_process_confirm", None),
  2113. (2, "eap_eke_auth;eap_eke_process_confirm", None),
  2114. (1, "eap_eke_prot;eap_eke_process_confirm", None),
  2115. (1, "eap_eke_derive_msk;eap_eke_process_confirm", None) ]
  2116. for count, func, phase1 in tests:
  2117. with fail_test(dev[0], count, func):
  2118. eap_eke_test_fail(dev[0], phase1)
  2119. tests = [ (1, "=eap_eke_derive_ke_ki", None),
  2120. (1, "=eap_eke_derive_ka", None),
  2121. (1, "=eap_eke_derive_msk", None),
  2122. (1, "eap_eke_build_msg;eap_eke_process_id", None),
  2123. (1, "wpabuf_alloc;eap_eke_process_id", None),
  2124. (1, "=eap_eke_process_id", None),
  2125. (1, "wpabuf_alloc;=eap_eke_process_id", None),
  2126. (1, "wpabuf_alloc;eap_eke_process_id", None),
  2127. (1, "eap_eke_build_msg;eap_eke_process_commit", None),
  2128. (1, "wpabuf_resize;eap_eke_process_commit", None),
  2129. (1, "eap_eke_build_msg;eap_eke_process_confirm", None) ]
  2130. for count, func, phase1 in tests:
  2131. with alloc_fail(dev[0], count, func):
  2132. eap_eke_test_fail(dev[0], phase1)
  2133. tests = [ (1, "eap_eke_getKey", None),
  2134. (1, "eap_eke_get_emsk", None),
  2135. (1, "eap_eke_get_session_id", None) ]
  2136. for count, func, phase1 in tests:
  2137. with alloc_fail(dev[0], count, func):
  2138. eap_eke_test_fail(dev[0], phase1, success=True)
  2139. EAP_PAX_OP_STD_1 = 0x01
  2140. EAP_PAX_OP_STD_2 = 0x02
  2141. EAP_PAX_OP_STD_3 = 0x03
  2142. EAP_PAX_OP_SEC_1 = 0x11
  2143. EAP_PAX_OP_SEC_2 = 0x12
  2144. EAP_PAX_OP_SEC_3 = 0x13
  2145. EAP_PAX_OP_SEC_4 = 0x14
  2146. EAP_PAX_OP_SEC_5 = 0x15
  2147. EAP_PAX_OP_ACK = 0x21
  2148. EAP_PAX_FLAGS_MF = 0x01
  2149. EAP_PAX_FLAGS_CE = 0x02
  2150. EAP_PAX_FLAGS_AI = 0x04
  2151. EAP_PAX_MAC_HMAC_SHA1_128 = 0x01
  2152. EAP_PAX_HMAC_SHA256_128 = 0x02
  2153. EAP_PAX_DH_GROUP_NONE = 0x00
  2154. EAP_PAX_DH_GROUP_2048_MODP = 0x01
  2155. EAP_PAX_DH_GROUP_3072_MODP = 0x02
  2156. EAP_PAX_DH_GROUP_NIST_ECC_P_256 = 0x03
  2157. EAP_PAX_PUBLIC_KEY_NONE = 0x00
  2158. EAP_PAX_PUBLIC_KEY_RSAES_OAEP = 0x01
  2159. EAP_PAX_PUBLIC_KEY_RSA_PKCS1_V1_5 = 0x02
  2160. EAP_PAX_PUBLIC_KEY_EL_GAMAL_NIST_ECC = 0x03
  2161. EAP_PAX_ADE_VENDOR_SPECIFIC = 0x01
  2162. EAP_PAX_ADE_CLIENT_CHANNEL_BINDING = 0x02
  2163. EAP_PAX_ADE_SERVER_CHANNEL_BINDING = 0x03
  2164. def test_eap_proto_pax(dev, apdev):
  2165. """EAP-PAX protocol tests"""
  2166. def pax_std_1(ctx):
  2167. logger.info("Test: STD-1")
  2168. ctx['id'] = 10
  2169. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2170. 4 + 1 + 5 + 2 + 32 + 16,
  2171. EAP_TYPE_PAX,
  2172. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2173. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2174. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2175. 0x16, 0xc9, 0x08, 0x9d, 0x98, 0xa5, 0x6e, 0x1f,
  2176. 0xf0, 0xac, 0xcf, 0xc4, 0x66, 0xcd, 0x2d, 0xbf)
  2177. def pax_handler(ctx, req):
  2178. logger.info("pax_handler - RX " + req.encode("hex"))
  2179. if 'num' not in ctx:
  2180. ctx['num'] = 0
  2181. ctx['num'] = ctx['num'] + 1
  2182. if 'id' not in ctx:
  2183. ctx['id'] = 1
  2184. ctx['id'] = (ctx['id'] + 1) % 256
  2185. idx = 0
  2186. idx += 1
  2187. if ctx['num'] == idx:
  2188. logger.info("Test: Missing payload")
  2189. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  2190. 4 + 1,
  2191. EAP_TYPE_PAX)
  2192. idx += 1
  2193. if ctx['num'] == idx:
  2194. logger.info("Test: Minimum length payload")
  2195. return struct.pack(">BBHB4L", EAP_CODE_REQUEST, ctx['id'],
  2196. 4 + 1 + 16,
  2197. EAP_TYPE_PAX,
  2198. 0, 0, 0, 0)
  2199. idx += 1
  2200. if ctx['num'] == idx:
  2201. logger.info("Test: Unsupported MAC ID")
  2202. return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
  2203. 4 + 1 + 5 + 16,
  2204. EAP_TYPE_PAX,
  2205. EAP_PAX_OP_STD_1, 0, 255, EAP_PAX_DH_GROUP_NONE,
  2206. EAP_PAX_PUBLIC_KEY_NONE,
  2207. 0, 0, 0, 0)
  2208. idx += 1
  2209. if ctx['num'] == idx:
  2210. logger.info("Test: Unsupported DH Group ID")
  2211. return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
  2212. 4 + 1 + 5 + 16,
  2213. EAP_TYPE_PAX,
  2214. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2215. 255, EAP_PAX_PUBLIC_KEY_NONE,
  2216. 0, 0, 0, 0)
  2217. idx += 1
  2218. if ctx['num'] == idx:
  2219. logger.info("Test: Unsupported Public Key ID")
  2220. return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
  2221. 4 + 1 + 5 + 16,
  2222. EAP_TYPE_PAX,
  2223. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2224. EAP_PAX_DH_GROUP_NONE, 255,
  2225. 0, 0, 0, 0)
  2226. idx += 1
  2227. if ctx['num'] == idx:
  2228. logger.info("Test: More fragments")
  2229. return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
  2230. 4 + 1 + 5 + 16,
  2231. EAP_TYPE_PAX,
  2232. EAP_PAX_OP_STD_1, EAP_PAX_FLAGS_MF,
  2233. EAP_PAX_MAC_HMAC_SHA1_128,
  2234. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2235. 0, 0, 0, 0)
  2236. idx += 1
  2237. if ctx['num'] == idx:
  2238. logger.info("Test: Invalid ICV")
  2239. return struct.pack(">BBHBBBBBB4L", EAP_CODE_REQUEST, ctx['id'],
  2240. 4 + 1 + 5 + 16,
  2241. EAP_TYPE_PAX,
  2242. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2243. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2244. 0, 0, 0, 0)
  2245. idx += 1
  2246. if ctx['num'] == idx:
  2247. logger.info("Test: Invalid ICV in short frame")
  2248. return struct.pack(">BBHBBBBBB3L", EAP_CODE_REQUEST, ctx['id'],
  2249. 4 + 1 + 5 + 12,
  2250. EAP_TYPE_PAX,
  2251. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2252. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2253. 0, 0, 0)
  2254. idx += 1
  2255. if ctx['num'] == idx:
  2256. logger.info("Test: Correct ICV - unsupported op_code")
  2257. ctx['id'] = 10
  2258. return struct.pack(">BBHBBBBBB16B", EAP_CODE_REQUEST, ctx['id'],
  2259. 4 + 1 + 5 + 16,
  2260. EAP_TYPE_PAX,
  2261. 255, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2262. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2263. 0x90, 0x78, 0x97, 0x38, 0x29, 0x94, 0x32, 0xd4,
  2264. 0x81, 0x27, 0xe0, 0xf6, 0x3b, 0x0d, 0xb2, 0xb2)
  2265. idx += 1
  2266. if ctx['num'] == idx:
  2267. logger.info("Test: Correct ICV - CE flag in STD-1")
  2268. ctx['id'] = 10
  2269. return struct.pack(">BBHBBBBBB16B", EAP_CODE_REQUEST, ctx['id'],
  2270. 4 + 1 + 5 + 16,
  2271. EAP_TYPE_PAX,
  2272. EAP_PAX_OP_STD_1, EAP_PAX_FLAGS_CE,
  2273. EAP_PAX_MAC_HMAC_SHA1_128,
  2274. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2275. 0x9c, 0x98, 0xb4, 0x0b, 0x94, 0x90, 0xde, 0x88,
  2276. 0xb7, 0x72, 0x63, 0x44, 0x1d, 0xe3, 0x7c, 0x5c)
  2277. idx += 1
  2278. if ctx['num'] == idx:
  2279. logger.info("Test: Correct ICV - too short STD-1 payload")
  2280. ctx['id'] = 10
  2281. return struct.pack(">BBHBBBBBB16B", EAP_CODE_REQUEST, ctx['id'],
  2282. 4 + 1 + 5 + 16,
  2283. EAP_TYPE_PAX,
  2284. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2285. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2286. 0xda, 0xab, 0x2c, 0xe7, 0x84, 0x41, 0xb5, 0x5c,
  2287. 0xee, 0xcf, 0x62, 0x03, 0xc5, 0x69, 0xcb, 0xf4)
  2288. idx += 1
  2289. if ctx['num'] == idx:
  2290. logger.info("Test: Correct ICV - incorrect A length in STD-1")
  2291. ctx['id'] = 10
  2292. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2293. 4 + 1 + 5 + 2 + 32 + 16,
  2294. EAP_TYPE_PAX,
  2295. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2296. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2297. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2298. 0xc4, 0xb0, 0x81, 0xe4, 0x6c, 0x8c, 0x20, 0x23,
  2299. 0x60, 0x46, 0x89, 0xea, 0x94, 0x60, 0xf3, 0x2a)
  2300. idx += 1
  2301. if ctx['num'] == idx:
  2302. logger.info("Test: Correct ICV - extra data in STD-1")
  2303. ctx['id'] = 10
  2304. return struct.pack(">BBHBBBBBBH8LB16B", EAP_CODE_REQUEST, ctx['id'],
  2305. 4 + 1 + 5 + 2 + 32 + 1 + 16,
  2306. EAP_TYPE_PAX,
  2307. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2308. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2309. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2310. 1,
  2311. 0x61, 0x49, 0x65, 0x37, 0x21, 0xe8, 0xd8, 0xbf,
  2312. 0xf3, 0x02, 0x01, 0xe5, 0x42, 0x51, 0xd3, 0x34)
  2313. idx += 1
  2314. if ctx['num'] == idx:
  2315. logger.info("Test: Unexpected STD-1")
  2316. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2317. 4 + 1 + 5 + 2 + 32 + 16,
  2318. EAP_TYPE_PAX,
  2319. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2320. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2321. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2322. 0xe5, 0x1d, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
  2323. 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
  2324. idx += 1
  2325. if ctx['num'] == idx:
  2326. return pax_std_1(ctx)
  2327. idx += 1
  2328. if ctx['num'] == idx:
  2329. logger.info("Test: MAC ID changed during session")
  2330. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2331. 4 + 1 + 5 + 2 + 32 + 16,
  2332. EAP_TYPE_PAX,
  2333. EAP_PAX_OP_STD_1, 0, EAP_PAX_HMAC_SHA256_128,
  2334. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2335. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2336. 0xee, 0x00, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
  2337. 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
  2338. idx += 1
  2339. if ctx['num'] == idx:
  2340. return pax_std_1(ctx)
  2341. idx += 1
  2342. if ctx['num'] == idx:
  2343. logger.info("Test: DH Group ID changed during session")
  2344. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2345. 4 + 1 + 5 + 2 + 32 + 16,
  2346. EAP_TYPE_PAX,
  2347. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2348. EAP_PAX_DH_GROUP_2048_MODP,
  2349. EAP_PAX_PUBLIC_KEY_NONE,
  2350. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2351. 0xee, 0x01, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
  2352. 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
  2353. idx += 1
  2354. if ctx['num'] == idx:
  2355. return pax_std_1(ctx)
  2356. idx += 1
  2357. if ctx['num'] == idx:
  2358. logger.info("Test: Public Key ID changed during session")
  2359. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2360. 4 + 1 + 5 + 2 + 32 + 16,
  2361. EAP_TYPE_PAX,
  2362. EAP_PAX_OP_STD_1, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2363. EAP_PAX_DH_GROUP_NONE,
  2364. EAP_PAX_PUBLIC_KEY_RSAES_OAEP,
  2365. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2366. 0xee, 0x02, 0xbf, 0xb8, 0x70, 0x20, 0x5c, 0xba,
  2367. 0x41, 0xbb, 0x34, 0xda, 0x1a, 0x08, 0xe6, 0x8d)
  2368. idx += 1
  2369. if ctx['num'] == idx:
  2370. logger.info("Test: Unexpected STD-3")
  2371. ctx['id'] = 10
  2372. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2373. 4 + 1 + 5 + 2 + 32 + 16,
  2374. EAP_TYPE_PAX,
  2375. EAP_PAX_OP_STD_3, 0, EAP_PAX_MAC_HMAC_SHA1_128,
  2376. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2377. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2378. 0x47, 0xbb, 0xc0, 0xf9, 0xb9, 0x69, 0xf5, 0xcb,
  2379. 0x3a, 0xe8, 0xe7, 0xd6, 0x80, 0x28, 0xf2, 0x59)
  2380. idx += 1
  2381. if ctx['num'] == idx:
  2382. return pax_std_1(ctx)
  2383. idx += 1
  2384. if ctx['num'] == idx:
  2385. # TODO: MAC calculation; for now, this gets dropped due to incorrect
  2386. # ICV
  2387. logger.info("Test: STD-3 with CE flag")
  2388. return struct.pack(">BBHBBBBBBH8L16B", EAP_CODE_REQUEST, ctx['id'],
  2389. 4 + 1 + 5 + 2 + 32 + 16,
  2390. EAP_TYPE_PAX,
  2391. EAP_PAX_OP_STD_3, EAP_PAX_FLAGS_CE,
  2392. EAP_PAX_MAC_HMAC_SHA1_128,
  2393. EAP_PAX_DH_GROUP_NONE, EAP_PAX_PUBLIC_KEY_NONE,
  2394. 32, 0, 0, 0, 0, 0, 0, 0, 0,
  2395. 0x8a, 0xc2, 0xf9, 0xf4, 0x8b, 0x75, 0x72, 0xa2,
  2396. 0x4d, 0xd3, 0x1e, 0x54, 0x77, 0x04, 0x05, 0xe2)
  2397. idx += 1
  2398. if ctx['num'] & 0x1 == idx & 0x1:
  2399. logger.info("Test: Default request")
  2400. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  2401. 4 + 1,
  2402. EAP_TYPE_PAX)
  2403. else:
  2404. logger.info("Test: Default EAP-Failure")
  2405. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2406. srv = start_radius_server(pax_handler)
  2407. try:
  2408. hapd = start_ap(apdev[0])
  2409. for i in range(0, 18):
  2410. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2411. eap="PAX", identity="user",
  2412. password_hex="0123456789abcdef0123456789abcdef",
  2413. wait_connect=False)
  2414. logger.info("Waiting for EAP method to start")
  2415. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  2416. timeout=15)
  2417. if ev is None:
  2418. raise Exception("Timeout on EAP start")
  2419. time.sleep(0.05)
  2420. dev[0].request("REMOVE_NETWORK all")
  2421. dev[0].dump_monitor()
  2422. logger.info("Too short password")
  2423. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2424. eap="PAX", identity="user",
  2425. password_hex="0123456789abcdef0123456789abcd",
  2426. wait_connect=False)
  2427. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  2428. if ev is None:
  2429. raise Exception("Timeout on EAP start")
  2430. time.sleep(0.1)
  2431. dev[0].request("REMOVE_NETWORK all")
  2432. dev[0].dump_monitor()
  2433. logger.info("No password")
  2434. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2435. eap="PAX", identity="user",
  2436. wait_connect=False)
  2437. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  2438. if ev is None:
  2439. raise Exception("Timeout on EAP start")
  2440. time.sleep(0.1)
  2441. dev[0].request("REMOVE_NETWORK all")
  2442. dev[0].dump_monitor()
  2443. finally:
  2444. stop_radius_server(srv)
  2445. def test_eap_proto_pax_errors(dev, apdev):
  2446. """EAP-PAX local error cases"""
  2447. check_eap_capa(dev[0], "PAX")
  2448. params = hostapd.wpa2_eap_params(ssid="eap-test")
  2449. hapd = hostapd.add_ap(apdev[0], params)
  2450. for i in range(1, 3):
  2451. with alloc_fail(dev[0], i, "eap_pax_init"):
  2452. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2453. eap="PAX", identity="pax.user@example.com",
  2454. password_hex="0123456789abcdef0123456789abcdef",
  2455. wait_connect=False)
  2456. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2457. timeout=15)
  2458. if ev is None:
  2459. raise Exception("Timeout on EAP start")
  2460. dev[0].request("REMOVE_NETWORK all")
  2461. dev[0].wait_disconnected()
  2462. tests = [ "eap_msg_alloc;eap_pax_alloc_resp;eap_pax_process_std_1",
  2463. "eap_msg_alloc;eap_pax_alloc_resp;eap_pax_process_std_3",
  2464. "eap_pax_getKey",
  2465. "eap_pax_get_emsk",
  2466. "eap_pax_get_session_id" ]
  2467. for func in tests:
  2468. with alloc_fail(dev[0], 1, func):
  2469. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2470. eap="PAX", identity="pax.user@example.com",
  2471. password_hex="0123456789abcdef0123456789abcdef",
  2472. erp="1", wait_connect=False)
  2473. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2474. dev[0].request("REMOVE_NETWORK all")
  2475. dev[0].wait_disconnected()
  2476. tests = [ (1, "os_get_random;eap_pax_process_std_1"),
  2477. (1, "eap_pax_initial_key_derivation"),
  2478. (1, "eap_pax_mac;eap_pax_process_std_3"),
  2479. (2, "eap_pax_mac;eap_pax_process_std_3"),
  2480. (1, "eap_pax_kdf;eap_pax_getKey"),
  2481. (1, "eap_pax_kdf;eap_pax_get_emsk") ]
  2482. for count, func in tests:
  2483. with fail_test(dev[0], count, func):
  2484. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2485. eap="PAX", identity="pax.user@example.com",
  2486. password_hex="0123456789abcdef0123456789abcdef",
  2487. erp="1", wait_connect=False)
  2488. wait_fail_trigger(dev[0], "GET_FAIL")
  2489. dev[0].request("REMOVE_NETWORK all")
  2490. dev[0].wait_disconnected()
  2491. def test_eap_proto_psk(dev, apdev):
  2492. """EAP-PSK protocol tests"""
  2493. def psk_handler(ctx, req):
  2494. logger.info("psk_handler - RX " + req.encode("hex"))
  2495. if 'num' not in ctx:
  2496. ctx['num'] = 0
  2497. ctx['num'] = ctx['num'] + 1
  2498. if 'id' not in ctx:
  2499. ctx['id'] = 1
  2500. ctx['id'] = (ctx['id'] + 1) % 256
  2501. idx = 0
  2502. idx += 1
  2503. if ctx['num'] == idx:
  2504. logger.info("Test: Missing payload")
  2505. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  2506. 4 + 1,
  2507. EAP_TYPE_PSK)
  2508. idx += 1
  2509. if ctx['num'] == idx:
  2510. logger.info("Test: Non-zero T in first message")
  2511. return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
  2512. 4 + 1 + 1 + 16,
  2513. EAP_TYPE_PSK, 0xc0, 0, 0, 0, 0)
  2514. idx += 1
  2515. if ctx['num'] == idx:
  2516. logger.info("Test: Valid first message")
  2517. return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
  2518. 4 + 1 + 1 + 16,
  2519. EAP_TYPE_PSK, 0, 0, 0, 0, 0)
  2520. idx += 1
  2521. if ctx['num'] == idx:
  2522. logger.info("Test: Too short third message")
  2523. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  2524. 4 + 1,
  2525. EAP_TYPE_PSK)
  2526. idx += 1
  2527. if ctx['num'] == idx:
  2528. logger.info("Test: Valid first message")
  2529. return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
  2530. 4 + 1 + 1 + 16,
  2531. EAP_TYPE_PSK, 0, 0, 0, 0, 0)
  2532. idx += 1
  2533. if ctx['num'] == idx:
  2534. logger.info("Test: Incorrect T in third message")
  2535. return struct.pack(">BBHBB4L4L", EAP_CODE_REQUEST, ctx['id'],
  2536. 4 + 1 + 1 + 16 + 16,
  2537. EAP_TYPE_PSK, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  2538. idx += 1
  2539. if ctx['num'] == idx:
  2540. logger.info("Test: Valid first message")
  2541. return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
  2542. 4 + 1 + 1 + 16,
  2543. EAP_TYPE_PSK, 0, 0, 0, 0, 0)
  2544. idx += 1
  2545. if ctx['num'] == idx:
  2546. logger.info("Test: Missing PCHANNEL in third message")
  2547. return struct.pack(">BBHBB4L4L", EAP_CODE_REQUEST, ctx['id'],
  2548. 4 + 1 + 1 + 16 + 16,
  2549. EAP_TYPE_PSK, 0x80, 0, 0, 0, 0, 0, 0, 0, 0)
  2550. idx += 1
  2551. if ctx['num'] == idx:
  2552. logger.info("Test: Valid first message")
  2553. return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
  2554. 4 + 1 + 1 + 16,
  2555. EAP_TYPE_PSK, 0, 0, 0, 0, 0)
  2556. idx += 1
  2557. if ctx['num'] == idx:
  2558. logger.info("Test: Invalic MAC_S in third message")
  2559. return struct.pack(">BBHBB4L4L5LB", EAP_CODE_REQUEST, ctx['id'],
  2560. 4 + 1 + 1 + 16 + 16 + 21,
  2561. EAP_TYPE_PSK, 0x80, 0, 0, 0, 0, 0, 0, 0, 0,
  2562. 0, 0, 0, 0, 0, 0)
  2563. idx += 1
  2564. if ctx['num'] == idx:
  2565. logger.info("Test: Valid first message")
  2566. return struct.pack(">BBHBB4L", EAP_CODE_REQUEST, ctx['id'],
  2567. 4 + 1 + 1 + 16,
  2568. EAP_TYPE_PSK, 0, 0, 0, 0, 0)
  2569. idx += 1
  2570. if ctx['num'] == idx:
  2571. logger.info("Test: EAP-Failure")
  2572. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2573. return None
  2574. srv = start_radius_server(psk_handler)
  2575. try:
  2576. hapd = start_ap(apdev[0])
  2577. for i in range(0, 6):
  2578. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2579. eap="PSK", identity="user",
  2580. password_hex="0123456789abcdef0123456789abcdef",
  2581. wait_connect=False)
  2582. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  2583. timeout=15)
  2584. if ev is None:
  2585. raise Exception("Timeout on EAP start")
  2586. time.sleep(0.1)
  2587. dev[0].request("REMOVE_NETWORK all")
  2588. logger.info("Test: Invalid PSK length")
  2589. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2590. eap="PSK", identity="user",
  2591. password_hex="0123456789abcdef0123456789abcd",
  2592. wait_connect=False)
  2593. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  2594. timeout=15)
  2595. if ev is None:
  2596. raise Exception("Timeout on EAP start")
  2597. time.sleep(0.1)
  2598. dev[0].request("REMOVE_NETWORK all")
  2599. finally:
  2600. stop_radius_server(srv)
  2601. def test_eap_proto_psk_errors(dev, apdev):
  2602. """EAP-PSK local error cases"""
  2603. check_eap_capa(dev[0], "PSK")
  2604. params = hostapd.wpa2_eap_params(ssid="eap-test")
  2605. hapd = hostapd.add_ap(apdev[0], params)
  2606. for i in range(1, 3):
  2607. with alloc_fail(dev[0], i, "eap_psk_init"):
  2608. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2609. eap="PSK", identity="psk.user@example.com",
  2610. password_hex="0123456789abcdef0123456789abcdef",
  2611. wait_connect=False)
  2612. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2613. timeout=15)
  2614. if ev is None:
  2615. raise Exception("Timeout on EAP start")
  2616. dev[0].request("REMOVE_NETWORK all")
  2617. dev[0].wait_disconnected()
  2618. for i in range(1, 4):
  2619. with fail_test(dev[0], i, "eap_psk_key_setup;eap_psk_init"):
  2620. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2621. eap="PSK", identity="psk.user@example.com",
  2622. password_hex="0123456789abcdef0123456789abcdef",
  2623. wait_connect=False)
  2624. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2625. timeout=15)
  2626. if ev is None:
  2627. raise Exception("Timeout on EAP start")
  2628. dev[0].request("REMOVE_NETWORK all")
  2629. dev[0].wait_disconnected()
  2630. tests = [ (1, "=eap_psk_process_1"),
  2631. (2, "=eap_psk_process_1"),
  2632. (1, "eap_msg_alloc;eap_psk_process_1"),
  2633. (1, "=eap_psk_process_3"),
  2634. (2, "=eap_psk_process_3"),
  2635. (1, "eap_msg_alloc;eap_psk_process_3"),
  2636. (1, "eap_psk_getKey"),
  2637. (1, "eap_psk_get_session_id"),
  2638. (1, "eap_psk_get_emsk") ]
  2639. for count, func in tests:
  2640. with alloc_fail(dev[0], count, func):
  2641. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2642. eap="PSK", identity="psk.user@example.com",
  2643. password_hex="0123456789abcdef0123456789abcdef",
  2644. erp="1", wait_connect=False)
  2645. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  2646. timeout=15)
  2647. if ev is None:
  2648. raise Exception("Timeout on EAP start")
  2649. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
  2650. note="No allocation failure seen for %d:%s" % (count, func))
  2651. dev[0].request("REMOVE_NETWORK all")
  2652. dev[0].wait_disconnected()
  2653. tests = [ (1, "os_get_random;eap_psk_process_1"),
  2654. (1, "omac1_aes_128;eap_psk_process_3"),
  2655. (1, "aes_128_eax_decrypt;eap_psk_process_3"),
  2656. (2, "aes_128_eax_decrypt;eap_psk_process_3"),
  2657. (3, "aes_128_eax_decrypt;eap_psk_process_3"),
  2658. (1, "aes_128_eax_encrypt;eap_psk_process_3"),
  2659. (2, "aes_128_eax_encrypt;eap_psk_process_3"),
  2660. (3, "aes_128_eax_encrypt;eap_psk_process_3"),
  2661. (1, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2662. (2, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2663. (3, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2664. (4, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2665. (5, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2666. (6, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2667. (7, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2668. (8, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2669. (9, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2670. (10, "aes_128_encrypt_block;eap_psk_derive_keys;eap_psk_process_3"),
  2671. (1, "aes_ctr_encrypt;aes_128_eax_decrypt;eap_psk_process_3"),
  2672. (1, "aes_ctr_encrypt;aes_128_eax_encrypt;eap_psk_process_3") ]
  2673. for count, func in tests:
  2674. with fail_test(dev[0], count, func):
  2675. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  2676. eap="PSK", identity="psk.user@example.com",
  2677. password_hex="0123456789abcdef0123456789abcdef",
  2678. wait_connect=False)
  2679. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  2680. timeout=15)
  2681. if ev is None:
  2682. raise Exception("Timeout on EAP start")
  2683. wait_fail_trigger(dev[0], "GET_FAIL",
  2684. note="No failure seen for %d:%s" % (count, func))
  2685. dev[0].request("REMOVE_NETWORK all")
  2686. dev[0].wait_disconnected()
  2687. EAP_SIM_SUBTYPE_START = 10
  2688. EAP_SIM_SUBTYPE_CHALLENGE = 11
  2689. EAP_SIM_SUBTYPE_NOTIFICATION = 12
  2690. EAP_SIM_SUBTYPE_REAUTHENTICATION = 13
  2691. EAP_SIM_SUBTYPE_CLIENT_ERROR = 14
  2692. EAP_AKA_SUBTYPE_CHALLENGE = 1
  2693. EAP_AKA_SUBTYPE_AUTHENTICATION_REJECT = 2
  2694. EAP_AKA_SUBTYPE_SYNCHRONIZATION_FAILURE = 4
  2695. EAP_AKA_SUBTYPE_IDENTITY = 5
  2696. EAP_AKA_SUBTYPE_NOTIFICATION = 12
  2697. EAP_AKA_SUBTYPE_REAUTHENTICATION = 13
  2698. EAP_AKA_SUBTYPE_CLIENT_ERROR = 14
  2699. EAP_SIM_AT_RAND = 1
  2700. EAP_SIM_AT_AUTN = 2
  2701. EAP_SIM_AT_RES = 3
  2702. EAP_SIM_AT_AUTS = 4
  2703. EAP_SIM_AT_PADDING = 6
  2704. EAP_SIM_AT_NONCE_MT = 7
  2705. EAP_SIM_AT_PERMANENT_ID_REQ = 10
  2706. EAP_SIM_AT_MAC = 11
  2707. EAP_SIM_AT_NOTIFICATION = 12
  2708. EAP_SIM_AT_ANY_ID_REQ = 13
  2709. EAP_SIM_AT_IDENTITY = 14
  2710. EAP_SIM_AT_VERSION_LIST = 15
  2711. EAP_SIM_AT_SELECTED_VERSION = 16
  2712. EAP_SIM_AT_FULLAUTH_ID_REQ = 17
  2713. EAP_SIM_AT_COUNTER = 19
  2714. EAP_SIM_AT_COUNTER_TOO_SMALL = 20
  2715. EAP_SIM_AT_NONCE_S = 21
  2716. EAP_SIM_AT_CLIENT_ERROR_CODE = 22
  2717. EAP_SIM_AT_KDF_INPUT = 23
  2718. EAP_SIM_AT_KDF = 24
  2719. EAP_SIM_AT_IV = 129
  2720. EAP_SIM_AT_ENCR_DATA = 130
  2721. EAP_SIM_AT_NEXT_PSEUDONYM = 132
  2722. EAP_SIM_AT_NEXT_REAUTH_ID = 133
  2723. EAP_SIM_AT_CHECKCODE = 134
  2724. EAP_SIM_AT_RESULT_IND = 135
  2725. EAP_SIM_AT_BIDDING = 136
  2726. def test_eap_proto_aka(dev, apdev):
  2727. """EAP-AKA protocol tests"""
  2728. def aka_handler(ctx, req):
  2729. logger.info("aka_handler - RX " + req.encode("hex"))
  2730. if 'num' not in ctx:
  2731. ctx['num'] = 0
  2732. ctx['num'] = ctx['num'] + 1
  2733. if 'id' not in ctx:
  2734. ctx['id'] = 1
  2735. ctx['id'] = (ctx['id'] + 1) % 256
  2736. idx = 0
  2737. idx += 1
  2738. if ctx['num'] == idx:
  2739. logger.info("Test: Missing payload")
  2740. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  2741. 4 + 1,
  2742. EAP_TYPE_AKA)
  2743. idx += 1
  2744. if ctx['num'] == idx:
  2745. logger.info("Test: Unknown subtype")
  2746. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2747. 4 + 1 + 3,
  2748. EAP_TYPE_AKA, 255, 0)
  2749. idx += 1
  2750. if ctx['num'] == idx:
  2751. logger.info("Test: EAP-Failure")
  2752. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2753. idx += 1
  2754. if ctx['num'] == idx:
  2755. logger.info("Test: Client Error")
  2756. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2757. 4 + 1 + 3,
  2758. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CLIENT_ERROR, 0)
  2759. idx += 1
  2760. if ctx['num'] == idx:
  2761. logger.info("Test: EAP-Failure")
  2762. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2763. idx += 1
  2764. if ctx['num'] == idx:
  2765. logger.info("Test: Too short attribute header")
  2766. return struct.pack(">BBHBBHB", EAP_CODE_REQUEST, ctx['id'],
  2767. 4 + 1 + 1 + 3,
  2768. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0, 255)
  2769. idx += 1
  2770. if ctx['num'] == idx:
  2771. logger.info("Test: EAP-Failure")
  2772. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2773. idx += 1
  2774. if ctx['num'] == idx:
  2775. logger.info("Test: Truncated attribute")
  2776. return struct.pack(">BBHBBHBB", EAP_CODE_REQUEST, ctx['id'],
  2777. 4 + 1 + 1 + 4,
  2778. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0, 255,
  2779. 255)
  2780. idx += 1
  2781. if ctx['num'] == idx:
  2782. logger.info("Test: EAP-Failure")
  2783. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2784. idx += 1
  2785. if ctx['num'] == idx:
  2786. logger.info("Test: Too short attribute data")
  2787. return struct.pack(">BBHBBHBB", EAP_CODE_REQUEST, ctx['id'],
  2788. 4 + 1 + 1 + 4,
  2789. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0, 255,
  2790. 0)
  2791. idx += 1
  2792. if ctx['num'] == idx:
  2793. logger.info("Test: EAP-Failure")
  2794. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2795. idx += 1
  2796. if ctx['num'] == idx:
  2797. logger.info("Test: Skippable/non-skippable unrecognzized attribute")
  2798. return struct.pack(">BBHBBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2799. 4 + 1 + 1 + 10,
  2800. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2801. 255, 1, 0, 127, 1, 0)
  2802. idx += 1
  2803. if ctx['num'] == idx:
  2804. logger.info("Test: EAP-Failure")
  2805. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2806. idx += 1
  2807. if ctx['num'] == idx:
  2808. logger.info("Test: Identity request without ID type")
  2809. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2810. 4 + 1 + 3,
  2811. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0)
  2812. idx += 1
  2813. if ctx['num'] == idx:
  2814. logger.info("Test: Identity request ANY_ID")
  2815. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2816. 4 + 1 + 3 + 4,
  2817. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2818. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  2819. idx += 1
  2820. if ctx['num'] == idx:
  2821. logger.info("Test: Identity request ANY_ID (duplicate)")
  2822. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2823. 4 + 1 + 3 + 4,
  2824. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2825. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  2826. idx += 1
  2827. if ctx['num'] == idx:
  2828. logger.info("Test: EAP-Failure")
  2829. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2830. idx += 1
  2831. if ctx['num'] == idx:
  2832. logger.info("Test: Identity request ANY_ID")
  2833. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2834. 4 + 1 + 3 + 4,
  2835. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2836. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  2837. idx += 1
  2838. if ctx['num'] == idx:
  2839. logger.info("Test: Identity request FULLAUTH_ID")
  2840. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2841. 4 + 1 + 3 + 4,
  2842. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2843. EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
  2844. idx += 1
  2845. if ctx['num'] == idx:
  2846. logger.info("Test: Identity request FULLAUTH_ID (duplicate)")
  2847. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2848. 4 + 1 + 3 + 4,
  2849. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2850. EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
  2851. idx += 1
  2852. if ctx['num'] == idx:
  2853. logger.info("Test: EAP-Failure")
  2854. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2855. idx += 1
  2856. if ctx['num'] == idx:
  2857. logger.info("Test: Identity request ANY_ID")
  2858. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2859. 4 + 1 + 3 + 4,
  2860. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2861. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  2862. idx += 1
  2863. if ctx['num'] == idx:
  2864. logger.info("Test: Identity request FULLAUTH_ID")
  2865. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2866. 4 + 1 + 3 + 4,
  2867. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2868. EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
  2869. idx += 1
  2870. if ctx['num'] == idx:
  2871. logger.info("Test: Identity request PERMANENT_ID")
  2872. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2873. 4 + 1 + 3 + 4,
  2874. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2875. EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
  2876. idx += 1
  2877. if ctx['num'] == idx:
  2878. logger.info("Test: Identity request PERMANENT_ID (duplicate)")
  2879. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2880. 4 + 1 + 3 + 4,
  2881. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  2882. EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
  2883. idx += 1
  2884. if ctx['num'] == idx:
  2885. logger.info("Test: EAP-Failure")
  2886. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2887. idx += 1
  2888. if ctx['num'] == idx:
  2889. logger.info("Test: Challenge with no attributes")
  2890. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2891. 4 + 1 + 3,
  2892. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0)
  2893. idx += 1
  2894. if ctx['num'] == idx:
  2895. logger.info("Test: EAP-Failure")
  2896. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2897. idx += 1
  2898. if ctx['num'] == idx:
  2899. logger.info("Test: AKA Challenge with BIDDING")
  2900. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2901. 4 + 1 + 3 + 4,
  2902. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  2903. EAP_SIM_AT_BIDDING, 1, 0x8000)
  2904. idx += 1
  2905. if ctx['num'] == idx:
  2906. logger.info("Test: EAP-Failure")
  2907. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2908. idx += 1
  2909. if ctx['num'] == idx:
  2910. logger.info("Test: Notification with no attributes")
  2911. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2912. 4 + 1 + 3,
  2913. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0)
  2914. idx += 1
  2915. if ctx['num'] == idx:
  2916. logger.info("Test: EAP-Failure")
  2917. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2918. idx += 1
  2919. if ctx['num'] == idx:
  2920. logger.info("Test: Notification indicating success, but no MAC")
  2921. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2922. 4 + 1 + 3 + 4,
  2923. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2924. EAP_SIM_AT_NOTIFICATION, 1, 32768)
  2925. idx += 1
  2926. if ctx['num'] == idx:
  2927. logger.info("Test: EAP-Failure")
  2928. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2929. idx += 1
  2930. if ctx['num'] == idx:
  2931. logger.info("Test: Notification indicating success, but invalid MAC value")
  2932. return struct.pack(">BBHBBHBBHBBH4L", EAP_CODE_REQUEST, ctx['id'],
  2933. 4 + 1 + 3 + 4 + 20,
  2934. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2935. EAP_SIM_AT_NOTIFICATION, 1, 32768,
  2936. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
  2937. idx += 1
  2938. if ctx['num'] == idx:
  2939. logger.info("Test: EAP-Failure")
  2940. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2941. idx += 1
  2942. if ctx['num'] == idx:
  2943. logger.info("Test: Notification indicating success with zero-key MAC")
  2944. return struct.pack(">BBHBBHBBHBBH16B", EAP_CODE_REQUEST,
  2945. ctx['id'] - 2,
  2946. 4 + 1 + 3 + 4 + 20,
  2947. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2948. EAP_SIM_AT_NOTIFICATION, 1, 32768,
  2949. EAP_SIM_AT_MAC, 5, 0,
  2950. 0xbe, 0x2e, 0xbb, 0xa9, 0xfa, 0x2e, 0x82, 0x36,
  2951. 0x37, 0x8c, 0x32, 0x41, 0xb7, 0xc7, 0x58, 0xa3)
  2952. idx += 1
  2953. if ctx['num'] == idx:
  2954. logger.info("Test: EAP-Success")
  2955. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  2956. idx += 1
  2957. if ctx['num'] == idx:
  2958. logger.info("Test: Notification before auth")
  2959. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2960. 4 + 1 + 3 + 4,
  2961. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2962. EAP_SIM_AT_NOTIFICATION, 1, 16384)
  2963. idx += 1
  2964. if ctx['num'] == idx:
  2965. logger.info("Test: EAP-Failure")
  2966. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2967. idx += 1
  2968. if ctx['num'] == idx:
  2969. logger.info("Test: Notification before auth")
  2970. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2971. 4 + 1 + 3 + 4,
  2972. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2973. EAP_SIM_AT_NOTIFICATION, 1, 16385)
  2974. idx += 1
  2975. if ctx['num'] == idx:
  2976. logger.info("Test: EAP-Failure")
  2977. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2978. idx += 1
  2979. if ctx['num'] == idx:
  2980. logger.info("Test: Notification with unrecognized non-failure")
  2981. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2982. 4 + 1 + 3 + 4,
  2983. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2984. EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
  2985. idx += 1
  2986. if ctx['num'] == idx:
  2987. logger.info("Test: Notification before auth (duplicate)")
  2988. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  2989. 4 + 1 + 3 + 4,
  2990. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_NOTIFICATION, 0,
  2991. EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
  2992. idx += 1
  2993. if ctx['num'] == idx:
  2994. logger.info("Test: EAP-Failure")
  2995. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  2996. idx += 1
  2997. if ctx['num'] == idx:
  2998. logger.info("Test: Re-authentication (unexpected) with no attributes")
  2999. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3000. 4 + 1 + 3,
  3001. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_REAUTHENTICATION,
  3002. 0)
  3003. idx += 1
  3004. if ctx['num'] == idx:
  3005. logger.info("Test: EAP-Failure")
  3006. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3007. idx += 1
  3008. if ctx['num'] == idx:
  3009. logger.info("Test: AKA Challenge with Checkcode claiming identity round was used")
  3010. return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
  3011. 4 + 1 + 3 + 24,
  3012. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3013. EAP_SIM_AT_CHECKCODE, 6, 0, 0, 0, 0, 0, 0)
  3014. idx += 1
  3015. if ctx['num'] == idx:
  3016. logger.info("Test: EAP-Failure")
  3017. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3018. idx += 1
  3019. if ctx['num'] == idx:
  3020. logger.info("Test: Identity request ANY_ID")
  3021. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3022. 4 + 1 + 3 + 4,
  3023. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3024. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  3025. idx += 1
  3026. if ctx['num'] == idx:
  3027. logger.info("Test: AKA Challenge with Checkcode claiming no identity round was used")
  3028. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3029. 4 + 1 + 3 + 4,
  3030. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3031. EAP_SIM_AT_CHECKCODE, 1, 0)
  3032. idx += 1
  3033. if ctx['num'] == idx:
  3034. logger.info("Test: EAP-Failure")
  3035. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3036. idx += 1
  3037. if ctx['num'] == idx:
  3038. logger.info("Test: Identity request ANY_ID")
  3039. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3040. 4 + 1 + 3 + 4,
  3041. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3042. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  3043. idx += 1
  3044. if ctx['num'] == idx:
  3045. logger.info("Test: AKA Challenge with mismatching Checkcode value")
  3046. return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
  3047. 4 + 1 + 3 + 24,
  3048. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3049. EAP_SIM_AT_CHECKCODE, 6, 0, 0, 0, 0, 0, 0)
  3050. idx += 1
  3051. if ctx['num'] == idx:
  3052. logger.info("Test: EAP-Failure")
  3053. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3054. idx += 1
  3055. if ctx['num'] == idx:
  3056. logger.info("Test: Re-authentication (unexpected) with Checkcode claimin identity round was used")
  3057. return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
  3058. 4 + 1 + 3 + 24,
  3059. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_REAUTHENTICATION,
  3060. 0,
  3061. EAP_SIM_AT_CHECKCODE, 6, 0, 0, 0, 0, 0, 0)
  3062. idx += 1
  3063. if ctx['num'] == idx:
  3064. logger.info("Test: EAP-Failure")
  3065. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3066. idx += 1
  3067. if ctx['num'] == idx:
  3068. logger.info("Test: Invalid AT_RAND length")
  3069. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3070. 4 + 1 + 3 + 4,
  3071. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3072. EAP_SIM_AT_RAND, 1, 0)
  3073. idx += 1
  3074. if ctx['num'] == idx:
  3075. logger.info("Test: EAP-Failure")
  3076. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3077. idx += 1
  3078. if ctx['num'] == idx:
  3079. logger.info("Test: Invalid AT_AUTN length")
  3080. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3081. 4 + 1 + 3 + 4,
  3082. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3083. EAP_SIM_AT_AUTN, 1, 0)
  3084. idx += 1
  3085. if ctx['num'] == idx:
  3086. logger.info("Test: EAP-Failure")
  3087. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3088. idx += 1
  3089. if ctx['num'] == idx:
  3090. logger.info("Test: Unencrypted AT_PADDING")
  3091. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3092. 4 + 1 + 3 + 4,
  3093. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3094. EAP_SIM_AT_PADDING, 1, 0)
  3095. idx += 1
  3096. if ctx['num'] == idx:
  3097. logger.info("Test: EAP-Failure")
  3098. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3099. idx += 1
  3100. if ctx['num'] == idx:
  3101. logger.info("Test: Invalid AT_NONCE_MT length")
  3102. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3103. 4 + 1 + 3 + 4,
  3104. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3105. EAP_SIM_AT_NONCE_MT, 1, 0)
  3106. idx += 1
  3107. if ctx['num'] == idx:
  3108. logger.info("Test: EAP-Failure")
  3109. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3110. idx += 1
  3111. if ctx['num'] == idx:
  3112. logger.info("Test: Invalid AT_MAC length")
  3113. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3114. 4 + 1 + 3 + 4,
  3115. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3116. EAP_SIM_AT_MAC, 1, 0)
  3117. idx += 1
  3118. if ctx['num'] == idx:
  3119. logger.info("Test: EAP-Failure")
  3120. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3121. idx += 1
  3122. if ctx['num'] == idx:
  3123. logger.info("Test: Invalid AT_NOTIFICATION length")
  3124. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3125. 4 + 1 + 3 + 8,
  3126. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3127. EAP_SIM_AT_NOTIFICATION, 2, 0, 0)
  3128. idx += 1
  3129. if ctx['num'] == idx:
  3130. logger.info("Test: EAP-Failure")
  3131. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3132. idx += 1
  3133. if ctx['num'] == idx:
  3134. logger.info("Test: AT_IDENTITY overflow")
  3135. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3136. 4 + 1 + 3 + 4,
  3137. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3138. EAP_SIM_AT_IDENTITY, 1, 0xffff)
  3139. idx += 1
  3140. if ctx['num'] == idx:
  3141. logger.info("Test: EAP-Failure")
  3142. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3143. idx += 1
  3144. if ctx['num'] == idx:
  3145. logger.info("Test: Unexpected AT_VERSION_LIST")
  3146. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3147. 4 + 1 + 3 + 4,
  3148. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3149. EAP_SIM_AT_VERSION_LIST, 1, 0)
  3150. idx += 1
  3151. if ctx['num'] == idx:
  3152. logger.info("Test: EAP-Failure")
  3153. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3154. idx += 1
  3155. if ctx['num'] == idx:
  3156. logger.info("Test: Invalid AT_SELECTED_VERSION length")
  3157. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3158. 4 + 1 + 3 + 8,
  3159. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3160. EAP_SIM_AT_SELECTED_VERSION, 2, 0, 0)
  3161. idx += 1
  3162. if ctx['num'] == idx:
  3163. logger.info("Test: EAP-Failure")
  3164. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3165. idx += 1
  3166. if ctx['num'] == idx:
  3167. logger.info("Test: Unencrypted AT_COUNTER")
  3168. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3169. 4 + 1 + 3 + 4,
  3170. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3171. EAP_SIM_AT_COUNTER, 1, 0)
  3172. idx += 1
  3173. if ctx['num'] == idx:
  3174. logger.info("Test: EAP-Failure")
  3175. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3176. idx += 1
  3177. if ctx['num'] == idx:
  3178. logger.info("Test: Unencrypted AT_COUNTER_TOO_SMALL")
  3179. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3180. 4 + 1 + 3 + 4,
  3181. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3182. EAP_SIM_AT_COUNTER_TOO_SMALL, 1, 0)
  3183. idx += 1
  3184. if ctx['num'] == idx:
  3185. logger.info("Test: EAP-Failure")
  3186. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3187. idx += 1
  3188. if ctx['num'] == idx:
  3189. logger.info("Test: Unencrypted AT_NONCE_S")
  3190. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3191. 4 + 1 + 3 + 4,
  3192. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3193. EAP_SIM_AT_NONCE_S, 1, 0)
  3194. idx += 1
  3195. if ctx['num'] == idx:
  3196. logger.info("Test: EAP-Failure")
  3197. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3198. idx += 1
  3199. if ctx['num'] == idx:
  3200. logger.info("Test: Invalid AT_CLIENT_ERROR_CODE length")
  3201. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3202. 4 + 1 + 3 + 8,
  3203. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3204. EAP_SIM_AT_CLIENT_ERROR_CODE, 2, 0, 0)
  3205. idx += 1
  3206. if ctx['num'] == idx:
  3207. logger.info("Test: EAP-Failure")
  3208. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3209. idx += 1
  3210. if ctx['num'] == idx:
  3211. logger.info("Test: Invalid AT_IV length")
  3212. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3213. 4 + 1 + 3 + 4,
  3214. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3215. EAP_SIM_AT_IV, 1, 0)
  3216. idx += 1
  3217. if ctx['num'] == idx:
  3218. logger.info("Test: EAP-Failure")
  3219. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3220. idx += 1
  3221. if ctx['num'] == idx:
  3222. logger.info("Test: Invalid AT_ENCR_DATA length")
  3223. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3224. 4 + 1 + 3 + 8,
  3225. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3226. EAP_SIM_AT_ENCR_DATA, 2, 0, 0)
  3227. idx += 1
  3228. if ctx['num'] == idx:
  3229. logger.info("Test: EAP-Failure")
  3230. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3231. idx += 1
  3232. if ctx['num'] == idx:
  3233. logger.info("Test: Unencrypted AT_NEXT_PSEUDONYM")
  3234. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3235. 4 + 1 + 3 + 4,
  3236. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3237. EAP_SIM_AT_NEXT_PSEUDONYM, 1, 0)
  3238. idx += 1
  3239. if ctx['num'] == idx:
  3240. logger.info("Test: EAP-Failure")
  3241. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3242. idx += 1
  3243. if ctx['num'] == idx:
  3244. logger.info("Test: Unencrypted AT_NEXT_REAUTH_ID")
  3245. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3246. 4 + 1 + 3 + 4,
  3247. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3248. EAP_SIM_AT_NEXT_REAUTH_ID, 1, 0)
  3249. idx += 1
  3250. if ctx['num'] == idx:
  3251. logger.info("Test: EAP-Failure")
  3252. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3253. idx += 1
  3254. if ctx['num'] == idx:
  3255. logger.info("Test: Invalid AT_RES length")
  3256. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3257. 4 + 1 + 3 + 4,
  3258. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3259. EAP_SIM_AT_RES, 1, 0)
  3260. idx += 1
  3261. if ctx['num'] == idx:
  3262. logger.info("Test: EAP-Failure")
  3263. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3264. idx += 1
  3265. if ctx['num'] == idx:
  3266. logger.info("Test: Invalid AT_RES length")
  3267. return struct.pack(">BBHBBHBBH5L", EAP_CODE_REQUEST, ctx['id'],
  3268. 4 + 1 + 3 + 24,
  3269. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3270. EAP_SIM_AT_RES, 6, 0xffff, 0, 0, 0, 0, 0)
  3271. idx += 1
  3272. if ctx['num'] == idx:
  3273. logger.info("Test: EAP-Failure")
  3274. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3275. idx += 1
  3276. if ctx['num'] == idx:
  3277. logger.info("Test: Invalid AT_AUTS length")
  3278. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3279. 4 + 1 + 3 + 8,
  3280. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3281. EAP_SIM_AT_AUTS, 2, 0, 0)
  3282. idx += 1
  3283. if ctx['num'] == idx:
  3284. logger.info("Test: EAP-Failure")
  3285. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3286. idx += 1
  3287. if ctx['num'] == idx:
  3288. logger.info("Test: Invalid AT_CHECKCODE length")
  3289. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3290. 4 + 1 + 3 + 8,
  3291. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3292. EAP_SIM_AT_CHECKCODE, 2, 0, 0)
  3293. idx += 1
  3294. if ctx['num'] == idx:
  3295. logger.info("Test: EAP-Failure")
  3296. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3297. idx += 1
  3298. if ctx['num'] == idx:
  3299. logger.info("Test: Invalid AT_RESULT_IND length")
  3300. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3301. 4 + 1 + 3 + 8,
  3302. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3303. EAP_SIM_AT_RESULT_IND, 2, 0, 0)
  3304. idx += 1
  3305. if ctx['num'] == idx:
  3306. logger.info("Test: EAP-Failure")
  3307. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3308. idx += 1
  3309. if ctx['num'] == idx:
  3310. logger.info("Test: Unexpected AT_KDF_INPUT")
  3311. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3312. 4 + 1 + 3 + 8,
  3313. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3314. EAP_SIM_AT_KDF_INPUT, 2, 0, 0)
  3315. idx += 1
  3316. if ctx['num'] == idx:
  3317. logger.info("Test: EAP-Failure")
  3318. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3319. idx += 1
  3320. if ctx['num'] == idx:
  3321. logger.info("Test: Unexpected AT_KDF")
  3322. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3323. 4 + 1 + 3 + 8,
  3324. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3325. EAP_SIM_AT_KDF, 2, 0, 0)
  3326. idx += 1
  3327. if ctx['num'] == idx:
  3328. logger.info("Test: EAP-Failure")
  3329. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3330. idx += 1
  3331. if ctx['num'] == idx:
  3332. logger.info("Test: Invalid AT_BIDDING length")
  3333. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3334. 4 + 1 + 3 + 8,
  3335. EAP_TYPE_AKA, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3336. EAP_SIM_AT_BIDDING, 2, 0, 0)
  3337. idx += 1
  3338. if ctx['num'] == idx:
  3339. logger.info("Test: EAP-Failure")
  3340. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3341. return None
  3342. srv = start_radius_server(aka_handler)
  3343. try:
  3344. hapd = start_ap(apdev[0])
  3345. for i in range(0, 49):
  3346. eap = "AKA AKA'" if i == 11 else "AKA"
  3347. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  3348. eap=eap, identity="0232010000000000",
  3349. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  3350. wait_connect=False)
  3351. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  3352. timeout=15)
  3353. if ev is None:
  3354. raise Exception("Timeout on EAP start")
  3355. if i in [ 0, 15 ]:
  3356. time.sleep(0.1)
  3357. else:
  3358. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  3359. timeout=10)
  3360. if ev is None:
  3361. raise Exception("Timeout on EAP failure")
  3362. dev[0].request("REMOVE_NETWORK all")
  3363. dev[0].dump_monitor()
  3364. finally:
  3365. stop_radius_server(srv)
  3366. def test_eap_proto_aka_prime(dev, apdev):
  3367. """EAP-AKA' protocol tests"""
  3368. def aka_prime_handler(ctx, req):
  3369. logger.info("aka_prime_handler - RX " + req.encode("hex"))
  3370. if 'num' not in ctx:
  3371. ctx['num'] = 0
  3372. ctx['num'] = ctx['num'] + 1
  3373. if 'id' not in ctx:
  3374. ctx['id'] = 1
  3375. ctx['id'] = (ctx['id'] + 1) % 256
  3376. idx = 0
  3377. idx += 1
  3378. if ctx['num'] == idx:
  3379. logger.info("Test: Missing payload")
  3380. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  3381. 4 + 1,
  3382. EAP_TYPE_AKA_PRIME)
  3383. idx += 1
  3384. if ctx['num'] == idx:
  3385. logger.info("Test: Challenge with no attributes")
  3386. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3387. 4 + 1 + 3,
  3388. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0)
  3389. idx += 1
  3390. if ctx['num'] == idx:
  3391. logger.info("Test: EAP-Failure")
  3392. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3393. idx += 1
  3394. if ctx['num'] == idx:
  3395. logger.info("Test: Challenge with empty AT_KDF_INPUT")
  3396. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3397. 4 + 1 + 3 + 4,
  3398. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3399. EAP_SIM_AT_KDF_INPUT, 1, 0)
  3400. idx += 1
  3401. if ctx['num'] == idx:
  3402. logger.info("Test: EAP-Failure")
  3403. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3404. idx += 1
  3405. if ctx['num'] == idx:
  3406. logger.info("Test: Challenge with AT_KDF_INPUT")
  3407. return struct.pack(">BBHBBHBBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  3408. 4 + 1 + 3 + 8,
  3409. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3410. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3411. ord('c'), ord('d'))
  3412. idx += 1
  3413. if ctx['num'] == idx:
  3414. logger.info("Test: EAP-Failure")
  3415. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3416. idx += 1
  3417. if ctx['num'] == idx:
  3418. logger.info("Test: Challenge with duplicated KDF")
  3419. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
  3420. EAP_CODE_REQUEST, ctx['id'],
  3421. 4 + 1 + 3 + 8 + 3 * 4,
  3422. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3423. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3424. ord('c'), ord('d'),
  3425. EAP_SIM_AT_KDF, 1, 1,
  3426. EAP_SIM_AT_KDF, 1, 2,
  3427. EAP_SIM_AT_KDF, 1, 1)
  3428. idx += 1
  3429. if ctx['num'] == idx:
  3430. logger.info("Test: EAP-Failure")
  3431. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3432. idx += 1
  3433. if ctx['num'] == idx:
  3434. logger.info("Test: Challenge with multiple KDF proposals")
  3435. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
  3436. EAP_CODE_REQUEST, ctx['id'],
  3437. 4 + 1 + 3 + 8 + 3 * 4,
  3438. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3439. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3440. ord('c'), ord('d'),
  3441. EAP_SIM_AT_KDF, 1, 255,
  3442. EAP_SIM_AT_KDF, 1, 254,
  3443. EAP_SIM_AT_KDF, 1, 1)
  3444. idx += 1
  3445. if ctx['num'] == idx:
  3446. logger.info("Test: Challenge with incorrect KDF selected")
  3447. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBHBBH",
  3448. EAP_CODE_REQUEST, ctx['id'],
  3449. 4 + 1 + 3 + 8 + 4 * 4,
  3450. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3451. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3452. ord('c'), ord('d'),
  3453. EAP_SIM_AT_KDF, 1, 255,
  3454. EAP_SIM_AT_KDF, 1, 255,
  3455. EAP_SIM_AT_KDF, 1, 254,
  3456. EAP_SIM_AT_KDF, 1, 1)
  3457. idx += 1
  3458. if ctx['num'] == idx:
  3459. logger.info("Test: EAP-Failure")
  3460. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3461. idx += 1
  3462. if ctx['num'] == idx:
  3463. logger.info("Test: Challenge with multiple KDF proposals")
  3464. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
  3465. EAP_CODE_REQUEST, ctx['id'],
  3466. 4 + 1 + 3 + 8 + 3 * 4,
  3467. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3468. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3469. ord('c'), ord('d'),
  3470. EAP_SIM_AT_KDF, 1, 255,
  3471. EAP_SIM_AT_KDF, 1, 254,
  3472. EAP_SIM_AT_KDF, 1, 1)
  3473. idx += 1
  3474. if ctx['num'] == idx:
  3475. logger.info("Test: Challenge with selected KDF not duplicated")
  3476. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
  3477. EAP_CODE_REQUEST, ctx['id'],
  3478. 4 + 1 + 3 + 8 + 3 * 4,
  3479. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3480. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3481. ord('c'), ord('d'),
  3482. EAP_SIM_AT_KDF, 1, 1,
  3483. EAP_SIM_AT_KDF, 1, 255,
  3484. EAP_SIM_AT_KDF, 1, 254)
  3485. idx += 1
  3486. if ctx['num'] == idx:
  3487. logger.info("Test: EAP-Failure")
  3488. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3489. idx += 1
  3490. if ctx['num'] == idx:
  3491. logger.info("Test: Challenge with multiple KDF proposals")
  3492. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
  3493. EAP_CODE_REQUEST, ctx['id'],
  3494. 4 + 1 + 3 + 8 + 3 * 4,
  3495. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3496. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3497. ord('c'), ord('d'),
  3498. EAP_SIM_AT_KDF, 1, 255,
  3499. EAP_SIM_AT_KDF, 1, 254,
  3500. EAP_SIM_AT_KDF, 1, 1)
  3501. idx += 1
  3502. if ctx['num'] == idx:
  3503. logger.info("Test: Challenge with selected KDF duplicated (missing MAC, RAND, AUTN)")
  3504. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBHBBH",
  3505. EAP_CODE_REQUEST, ctx['id'],
  3506. 4 + 1 + 3 + 8 + 4 * 4,
  3507. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3508. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3509. ord('c'), ord('d'),
  3510. EAP_SIM_AT_KDF, 1, 1,
  3511. EAP_SIM_AT_KDF, 1, 255,
  3512. EAP_SIM_AT_KDF, 1, 254,
  3513. EAP_SIM_AT_KDF, 1, 1)
  3514. idx += 1
  3515. if ctx['num'] == idx:
  3516. logger.info("Test: EAP-Failure")
  3517. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3518. idx += 1
  3519. if ctx['num'] == idx:
  3520. logger.info("Test: Challenge with multiple unsupported KDF proposals")
  3521. return struct.pack(">BBHBBHBBHBBBBBBHBBH",
  3522. EAP_CODE_REQUEST, ctx['id'],
  3523. 4 + 1 + 3 + 8 + 2 * 4,
  3524. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3525. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3526. ord('c'), ord('d'),
  3527. EAP_SIM_AT_KDF, 1, 255,
  3528. EAP_SIM_AT_KDF, 1, 254)
  3529. idx += 1
  3530. if ctx['num'] == idx:
  3531. logger.info("Test: EAP-Failure")
  3532. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3533. idx += 1
  3534. if ctx['num'] == idx:
  3535. logger.info("Test: Challenge with multiple KDF proposals")
  3536. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBH",
  3537. EAP_CODE_REQUEST, ctx['id'],
  3538. 4 + 1 + 3 + 8 + 3 * 4,
  3539. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3540. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3541. ord('c'), ord('d'),
  3542. EAP_SIM_AT_KDF, 1, 255,
  3543. EAP_SIM_AT_KDF, 1, 254,
  3544. EAP_SIM_AT_KDF, 1, 1)
  3545. idx += 1
  3546. if ctx['num'] == idx:
  3547. logger.info("Test: Challenge with invalid MAC, RAND, AUTN values)")
  3548. return struct.pack(">BBHBBHBBHBBBBBBHBBHBBHBBHBBH4LBBH4LBBH4L",
  3549. EAP_CODE_REQUEST, ctx['id'],
  3550. 4 + 1 + 3 + 8 + 4 * 4 + 20 + 20 + 20,
  3551. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3552. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3553. ord('c'), ord('d'),
  3554. EAP_SIM_AT_KDF, 1, 1,
  3555. EAP_SIM_AT_KDF, 1, 255,
  3556. EAP_SIM_AT_KDF, 1, 254,
  3557. EAP_SIM_AT_KDF, 1, 1,
  3558. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0,
  3559. EAP_SIM_AT_RAND, 5, 0, 0, 0, 0, 0,
  3560. EAP_SIM_AT_AUTN, 5, 0, 0, 0, 0, 0)
  3561. idx += 1
  3562. if ctx['num'] == idx:
  3563. logger.info("Test: EAP-Failure")
  3564. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3565. idx += 1
  3566. if ctx['num'] == idx:
  3567. logger.info("Test: Challenge - AMF separation bit not set)")
  3568. return struct.pack(">BBHBBHBBHBBBBBBHBBH4LBBH4LBBH4L",
  3569. EAP_CODE_REQUEST, ctx['id'],
  3570. 4 + 1 + 3 + 8 + 4 + 20 + 20 + 20,
  3571. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3572. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3573. ord('c'), ord('d'),
  3574. EAP_SIM_AT_KDF, 1, 1,
  3575. EAP_SIM_AT_MAC, 5, 0, 1, 2, 3, 4,
  3576. EAP_SIM_AT_RAND, 5, 0, 5, 6, 7, 8,
  3577. EAP_SIM_AT_AUTN, 5, 0, 9, 10,
  3578. 0x2fda8ef7, 0xbba518cc)
  3579. idx += 1
  3580. if ctx['num'] == idx:
  3581. logger.info("Test: EAP-Failure")
  3582. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3583. idx += 1
  3584. if ctx['num'] == idx:
  3585. logger.info("Test: Challenge - Invalid MAC")
  3586. return struct.pack(">BBHBBHBBHBBBBBBHBBH4LBBH4LBBH4L",
  3587. EAP_CODE_REQUEST, ctx['id'],
  3588. 4 + 1 + 3 + 8 + 4 + 20 + 20 + 20,
  3589. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3590. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3591. ord('c'), ord('d'),
  3592. EAP_SIM_AT_KDF, 1, 1,
  3593. EAP_SIM_AT_MAC, 5, 0, 1, 2, 3, 4,
  3594. EAP_SIM_AT_RAND, 5, 0, 5, 6, 7, 8,
  3595. EAP_SIM_AT_AUTN, 5, 0, 0xffffffff, 0xffffffff,
  3596. 0xd1f90322, 0x40514cb4)
  3597. idx += 1
  3598. if ctx['num'] == idx:
  3599. logger.info("Test: EAP-Failure")
  3600. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3601. idx += 1
  3602. if ctx['num'] == idx:
  3603. logger.info("Test: Challenge - Valid MAC")
  3604. return struct.pack(">BBHBBHBBHBBBBBBHBBH4LBBH4LBBH4L",
  3605. EAP_CODE_REQUEST, ctx['id'],
  3606. 4 + 1 + 3 + 8 + 4 + 20 + 20 + 20,
  3607. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3608. EAP_SIM_AT_KDF_INPUT, 2, 1, ord('a'), ord('b'),
  3609. ord('c'), ord('d'),
  3610. EAP_SIM_AT_KDF, 1, 1,
  3611. EAP_SIM_AT_MAC, 5, 0,
  3612. 0xf4a3c1d3, 0x7c901401, 0x34bd8b01, 0x6f7fa32f,
  3613. EAP_SIM_AT_RAND, 5, 0, 5, 6, 7, 8,
  3614. EAP_SIM_AT_AUTN, 5, 0, 0xffffffff, 0xffffffff,
  3615. 0xd1f90322, 0x40514cb4)
  3616. idx += 1
  3617. if ctx['num'] == idx:
  3618. logger.info("Test: EAP-Failure")
  3619. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3620. idx += 1
  3621. if ctx['num'] == idx:
  3622. logger.info("Test: Invalid AT_KDF_INPUT length")
  3623. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3624. 4 + 1 + 3 + 8,
  3625. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3626. EAP_SIM_AT_KDF_INPUT, 2, 0xffff, 0)
  3627. idx += 1
  3628. if ctx['num'] == idx:
  3629. logger.info("Test: EAP-Failure")
  3630. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3631. idx += 1
  3632. if ctx['num'] == idx:
  3633. logger.info("Test: Invalid AT_KDF length")
  3634. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3635. 4 + 1 + 3 + 8,
  3636. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_IDENTITY, 0,
  3637. EAP_SIM_AT_KDF, 2, 0, 0)
  3638. idx += 1
  3639. if ctx['num'] == idx:
  3640. logger.info("Test: EAP-Failure")
  3641. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3642. idx += 1
  3643. if ctx['num'] == idx:
  3644. logger.info("Test: Challenge with large number of KDF proposals")
  3645. return struct.pack(">BBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBHBBH",
  3646. EAP_CODE_REQUEST, ctx['id'],
  3647. 4 + 1 + 3 + 12 * 4,
  3648. EAP_TYPE_AKA_PRIME, EAP_AKA_SUBTYPE_CHALLENGE, 0,
  3649. EAP_SIM_AT_KDF, 1, 255,
  3650. EAP_SIM_AT_KDF, 1, 254,
  3651. EAP_SIM_AT_KDF, 1, 253,
  3652. EAP_SIM_AT_KDF, 1, 252,
  3653. EAP_SIM_AT_KDF, 1, 251,
  3654. EAP_SIM_AT_KDF, 1, 250,
  3655. EAP_SIM_AT_KDF, 1, 249,
  3656. EAP_SIM_AT_KDF, 1, 248,
  3657. EAP_SIM_AT_KDF, 1, 247,
  3658. EAP_SIM_AT_KDF, 1, 246,
  3659. EAP_SIM_AT_KDF, 1, 245,
  3660. EAP_SIM_AT_KDF, 1, 244)
  3661. idx += 1
  3662. if ctx['num'] == idx:
  3663. logger.info("Test: EAP-Failure")
  3664. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3665. return None
  3666. srv = start_radius_server(aka_prime_handler)
  3667. try:
  3668. hapd = start_ap(apdev[0])
  3669. for i in range(0, 16):
  3670. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  3671. eap="AKA'", identity="6555444333222111",
  3672. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  3673. wait_connect=False)
  3674. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  3675. timeout=15)
  3676. if ev is None:
  3677. raise Exception("Timeout on EAP start")
  3678. if i in [ 0 ]:
  3679. time.sleep(0.1)
  3680. else:
  3681. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  3682. timeout=10)
  3683. if ev is None:
  3684. raise Exception("Timeout on EAP failure")
  3685. dev[0].request("REMOVE_NETWORK all")
  3686. dev[0].dump_monitor()
  3687. finally:
  3688. stop_radius_server(srv)
  3689. def test_eap_proto_sim(dev, apdev):
  3690. """EAP-SIM protocol tests"""
  3691. def sim_handler(ctx, req):
  3692. logger.info("sim_handler - RX " + req.encode("hex"))
  3693. if 'num' not in ctx:
  3694. ctx['num'] = 0
  3695. ctx['num'] = ctx['num'] + 1
  3696. if 'id' not in ctx:
  3697. ctx['id'] = 1
  3698. ctx['id'] = (ctx['id'] + 1) % 256
  3699. idx = 0
  3700. idx += 1
  3701. if ctx['num'] == idx:
  3702. logger.info("Test: Missing payload")
  3703. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  3704. 4 + 1,
  3705. EAP_TYPE_SIM)
  3706. idx += 1
  3707. if ctx['num'] == idx:
  3708. logger.info("Test: Unexpected AT_AUTN")
  3709. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3710. 4 + 1 + 3 + 8,
  3711. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3712. EAP_SIM_AT_AUTN, 2, 0, 0)
  3713. idx += 1
  3714. if ctx['num'] == idx:
  3715. logger.info("Test: EAP-Failure")
  3716. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3717. idx += 1
  3718. if ctx['num'] == idx:
  3719. logger.info("Test: Too short AT_VERSION_LIST")
  3720. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3721. 4 + 1 + 3 + 4,
  3722. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3723. EAP_SIM_AT_VERSION_LIST, 1, 0)
  3724. idx += 1
  3725. if ctx['num'] == idx:
  3726. logger.info("Test: EAP-Failure")
  3727. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3728. idx += 1
  3729. if ctx['num'] == idx:
  3730. logger.info("Test: AT_VERSION_LIST overflow")
  3731. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3732. 4 + 1 + 3 + 4,
  3733. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3734. EAP_SIM_AT_VERSION_LIST, 1, 0xffff)
  3735. idx += 1
  3736. if ctx['num'] == idx:
  3737. logger.info("Test: EAP-Failure")
  3738. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3739. idx += 1
  3740. if ctx['num'] == idx:
  3741. logger.info("Test: Unexpected AT_AUTS")
  3742. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3743. 4 + 1 + 3 + 8,
  3744. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3745. EAP_SIM_AT_AUTS, 2, 0, 0)
  3746. idx += 1
  3747. if ctx['num'] == idx:
  3748. logger.info("Test: EAP-Failure")
  3749. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3750. idx += 1
  3751. if ctx['num'] == idx:
  3752. logger.info("Test: Unexpected AT_CHECKCODE")
  3753. return struct.pack(">BBHBBHBBHL", EAP_CODE_REQUEST, ctx['id'],
  3754. 4 + 1 + 3 + 8,
  3755. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3756. EAP_SIM_AT_CHECKCODE, 2, 0, 0)
  3757. idx += 1
  3758. if ctx['num'] == idx:
  3759. logger.info("Test: EAP-Failure")
  3760. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3761. idx += 1
  3762. if ctx['num'] == idx:
  3763. logger.info("Test: No AT_VERSION_LIST in Start")
  3764. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3765. 4 + 1 + 3,
  3766. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0)
  3767. idx += 1
  3768. if ctx['num'] == idx:
  3769. logger.info("Test: EAP-Failure")
  3770. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3771. idx += 1
  3772. if ctx['num'] == idx:
  3773. logger.info("Test: No support version in AT_VERSION_LIST")
  3774. return struct.pack(">BBHBBHBBH4B", EAP_CODE_REQUEST, ctx['id'],
  3775. 4 + 1 + 3 + 8,
  3776. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3777. EAP_SIM_AT_VERSION_LIST, 2, 3, 2, 3, 4, 5)
  3778. idx += 1
  3779. if ctx['num'] == idx:
  3780. logger.info("Test: EAP-Failure")
  3781. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3782. idx += 1
  3783. if ctx['num'] == idx:
  3784. logger.info("Test: Identity request without ID type")
  3785. return struct.pack(">BBHBBHBBH2H", EAP_CODE_REQUEST, ctx['id'],
  3786. 4 + 1 + 3 + 8,
  3787. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3788. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0)
  3789. idx += 1
  3790. if ctx['num'] == idx:
  3791. logger.info("Test: Identity request ANY_ID")
  3792. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3793. 4 + 1 + 3 + 8 + 4,
  3794. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3795. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3796. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  3797. idx += 1
  3798. if ctx['num'] == idx:
  3799. logger.info("Test: Identity request ANY_ID (duplicate)")
  3800. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3801. 4 + 1 + 3 + 8 + 4,
  3802. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3803. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3804. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  3805. idx += 1
  3806. if ctx['num'] == idx:
  3807. logger.info("Test: EAP-Failure")
  3808. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3809. idx += 1
  3810. if ctx['num'] == idx:
  3811. logger.info("Test: Identity request ANY_ID")
  3812. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3813. 4 + 1 + 3 + 8 + 4,
  3814. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3815. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3816. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  3817. idx += 1
  3818. if ctx['num'] == idx:
  3819. logger.info("Test: Identity request FULLAUTH_ID")
  3820. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3821. 4 + 1 + 3 + 8 + 4,
  3822. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3823. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3824. EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
  3825. idx += 1
  3826. if ctx['num'] == idx:
  3827. logger.info("Test: Identity request FULLAUTH_ID (duplicate)")
  3828. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3829. 4 + 1 + 3 + 8 + 4,
  3830. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3831. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3832. EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
  3833. idx += 1
  3834. if ctx['num'] == idx:
  3835. logger.info("Test: EAP-Failure")
  3836. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3837. idx += 1
  3838. if ctx['num'] == idx:
  3839. logger.info("Test: Identity request ANY_ID")
  3840. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3841. 4 + 1 + 3 + 8 + 4,
  3842. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3843. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3844. EAP_SIM_AT_ANY_ID_REQ, 1, 0)
  3845. idx += 1
  3846. if ctx['num'] == idx:
  3847. logger.info("Test: Identity request FULLAUTH_ID")
  3848. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3849. 4 + 1 + 3 + 8 + 4,
  3850. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3851. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3852. EAP_SIM_AT_FULLAUTH_ID_REQ, 1, 0)
  3853. idx += 1
  3854. if ctx['num'] == idx:
  3855. logger.info("Test: Identity request PERMANENT_ID")
  3856. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3857. 4 + 1 + 3 + 8 + 4,
  3858. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3859. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3860. EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
  3861. idx += 1
  3862. if ctx['num'] == idx:
  3863. logger.info("Test: Identity request PERMANENT_ID (duplicate)")
  3864. return struct.pack(">BBHBBHBBH2HBBH", EAP_CODE_REQUEST, ctx['id'],
  3865. 4 + 1 + 3 + 8 + 4,
  3866. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_START, 0,
  3867. EAP_SIM_AT_VERSION_LIST, 2, 2, 1, 0,
  3868. EAP_SIM_AT_PERMANENT_ID_REQ, 1, 0)
  3869. idx += 1
  3870. if ctx['num'] == idx:
  3871. logger.info("Test: EAP-Failure")
  3872. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3873. idx += 1
  3874. if ctx['num'] == idx:
  3875. logger.info("Test: No AT_MAC and AT_RAND in Challenge")
  3876. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3877. 4 + 1 + 3,
  3878. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0)
  3879. idx += 1
  3880. if ctx['num'] == idx:
  3881. logger.info("Test: EAP-Failure")
  3882. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3883. idx += 1
  3884. if ctx['num'] == idx:
  3885. logger.info("Test: No AT_RAND in Challenge")
  3886. return struct.pack(">BBHBBHBBH4L", EAP_CODE_REQUEST, ctx['id'],
  3887. 4 + 1 + 3 + 20,
  3888. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
  3889. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
  3890. idx += 1
  3891. if ctx['num'] == idx:
  3892. logger.info("Test: EAP-Failure")
  3893. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3894. idx += 1
  3895. if ctx['num'] == idx:
  3896. logger.info("Test: Insufficient number of challenges in Challenge")
  3897. return struct.pack(">BBHBBHBBH4LBBH4L", EAP_CODE_REQUEST, ctx['id'],
  3898. 4 + 1 + 3 + 20 + 20,
  3899. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
  3900. EAP_SIM_AT_RAND, 5, 0, 0, 0, 0, 0,
  3901. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
  3902. idx += 1
  3903. if ctx['num'] == idx:
  3904. logger.info("Test: EAP-Failure")
  3905. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3906. idx += 1
  3907. if ctx['num'] == idx:
  3908. logger.info("Test: Too many challenges in Challenge")
  3909. return struct.pack(">BBHBBHBBH4L4L4L4LBBH4L", EAP_CODE_REQUEST,
  3910. ctx['id'],
  3911. 4 + 1 + 3 + 4 + 4 * 16 + 20,
  3912. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
  3913. EAP_SIM_AT_RAND, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3914. 0, 0, 0, 0, 0, 0, 0, 0,
  3915. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
  3916. idx += 1
  3917. if ctx['num'] == idx:
  3918. logger.info("Test: EAP-Failure")
  3919. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3920. idx += 1
  3921. if ctx['num'] == idx:
  3922. logger.info("Test: Same RAND multiple times in Challenge")
  3923. return struct.pack(">BBHBBHBBH4L4L4LBBH4L", EAP_CODE_REQUEST,
  3924. ctx['id'],
  3925. 4 + 1 + 3 + 4 + 3 * 16 + 20,
  3926. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CHALLENGE, 0,
  3927. EAP_SIM_AT_RAND, 13, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  3928. 0, 0, 0, 0,
  3929. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
  3930. idx += 1
  3931. if ctx['num'] == idx:
  3932. logger.info("Test: EAP-Failure")
  3933. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3934. idx += 1
  3935. if ctx['num'] == idx:
  3936. logger.info("Test: Notification with no attributes")
  3937. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3938. 4 + 1 + 3,
  3939. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0)
  3940. idx += 1
  3941. if ctx['num'] == idx:
  3942. logger.info("Test: EAP-Failure")
  3943. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3944. idx += 1
  3945. if ctx['num'] == idx:
  3946. logger.info("Test: Notification indicating success, but no MAC")
  3947. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3948. 4 + 1 + 3 + 4,
  3949. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
  3950. EAP_SIM_AT_NOTIFICATION, 1, 32768)
  3951. idx += 1
  3952. if ctx['num'] == idx:
  3953. logger.info("Test: EAP-Failure")
  3954. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3955. idx += 1
  3956. if ctx['num'] == idx:
  3957. logger.info("Test: Notification indicating success, but invalid MAC value")
  3958. return struct.pack(">BBHBBHBBHBBH4L", EAP_CODE_REQUEST, ctx['id'],
  3959. 4 + 1 + 3 + 4 + 20,
  3960. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
  3961. EAP_SIM_AT_NOTIFICATION, 1, 32768,
  3962. EAP_SIM_AT_MAC, 5, 0, 0, 0, 0, 0)
  3963. idx += 1
  3964. if ctx['num'] == idx:
  3965. logger.info("Test: EAP-Failure")
  3966. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3967. idx += 1
  3968. if ctx['num'] == idx:
  3969. logger.info("Test: Notification before auth")
  3970. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3971. 4 + 1 + 3 + 4,
  3972. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
  3973. EAP_SIM_AT_NOTIFICATION, 1, 16384)
  3974. idx += 1
  3975. if ctx['num'] == idx:
  3976. logger.info("Test: EAP-Failure")
  3977. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3978. idx += 1
  3979. if ctx['num'] == idx:
  3980. logger.info("Test: Notification before auth")
  3981. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3982. 4 + 1 + 3 + 4,
  3983. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
  3984. EAP_SIM_AT_NOTIFICATION, 1, 16385)
  3985. idx += 1
  3986. if ctx['num'] == idx:
  3987. logger.info("Test: EAP-Failure")
  3988. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  3989. idx += 1
  3990. if ctx['num'] == idx:
  3991. logger.info("Test: Notification with unrecognized non-failure")
  3992. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  3993. 4 + 1 + 3 + 4,
  3994. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
  3995. EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
  3996. idx += 1
  3997. if ctx['num'] == idx:
  3998. logger.info("Test: Notification before auth (duplicate)")
  3999. return struct.pack(">BBHBBHBBH", EAP_CODE_REQUEST, ctx['id'],
  4000. 4 + 1 + 3 + 4,
  4001. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_NOTIFICATION, 0,
  4002. EAP_SIM_AT_NOTIFICATION, 1, 0xc000)
  4003. idx += 1
  4004. if ctx['num'] == idx:
  4005. logger.info("Test: EAP-Failure")
  4006. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4007. idx += 1
  4008. if ctx['num'] == idx:
  4009. logger.info("Test: Re-authentication (unexpected) with no attributes")
  4010. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  4011. 4 + 1 + 3,
  4012. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_REAUTHENTICATION,
  4013. 0)
  4014. idx += 1
  4015. if ctx['num'] == idx:
  4016. logger.info("Test: EAP-Failure")
  4017. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4018. idx += 1
  4019. if ctx['num'] == idx:
  4020. logger.info("Test: Client Error")
  4021. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  4022. 4 + 1 + 3,
  4023. EAP_TYPE_SIM, EAP_SIM_SUBTYPE_CLIENT_ERROR, 0)
  4024. idx += 1
  4025. if ctx['num'] == idx:
  4026. logger.info("Test: EAP-Failure")
  4027. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4028. idx += 1
  4029. if ctx['num'] == idx:
  4030. logger.info("Test: Unknown subtype")
  4031. return struct.pack(">BBHBBH", EAP_CODE_REQUEST, ctx['id'],
  4032. 4 + 1 + 3,
  4033. EAP_TYPE_SIM, 255, 0)
  4034. idx += 1
  4035. if ctx['num'] == idx:
  4036. logger.info("Test: EAP-Failure")
  4037. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4038. return None
  4039. srv = start_radius_server(sim_handler)
  4040. try:
  4041. hapd = start_ap(apdev[0])
  4042. for i in range(0, 25):
  4043. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4044. eap="SIM", identity="1232010000000000",
  4045. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4046. wait_connect=False)
  4047. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  4048. timeout=15)
  4049. if ev is None:
  4050. raise Exception("Timeout on EAP start")
  4051. if i in [ 0 ]:
  4052. time.sleep(0.1)
  4053. else:
  4054. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  4055. timeout=10)
  4056. if ev is None:
  4057. raise Exception("Timeout on EAP failure")
  4058. dev[0].request("REMOVE_NETWORK all")
  4059. dev[0].dump_monitor()
  4060. finally:
  4061. stop_radius_server(srv)
  4062. def test_eap_proto_sim_errors(dev, apdev):
  4063. """EAP-SIM protocol tests (error paths)"""
  4064. check_hlr_auc_gw_support()
  4065. params = hostapd.wpa2_eap_params(ssid="eap-test")
  4066. hapd = hostapd.add_ap(apdev[0], params)
  4067. with alloc_fail(dev[0], 1, "eap_sim_init"):
  4068. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4069. eap="SIM", identity="1232010000000000",
  4070. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4071. wait_connect=False)
  4072. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  4073. timeout=15)
  4074. if ev is None:
  4075. raise Exception("Timeout on EAP start")
  4076. dev[0].request("REMOVE_NETWORK all")
  4077. dev[0].wait_disconnected()
  4078. with fail_test(dev[0], 1, "os_get_random;eap_sim_init"):
  4079. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4080. eap="SIM", identity="1232010000000000",
  4081. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4082. wait_connect=False)
  4083. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  4084. timeout=15)
  4085. if ev is None:
  4086. raise Exception("Timeout on EAP start")
  4087. dev[0].request("REMOVE_NETWORK all")
  4088. dev[0].wait_disconnected()
  4089. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4090. eap="SIM", identity="1232010000000000",
  4091. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4092. with fail_test(dev[0], 1, "aes_128_cbc_encrypt;eap_sim_response_reauth"):
  4093. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  4094. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  4095. if ev is None:
  4096. raise Exception("EAP re-authentication did not start")
  4097. wait_fail_trigger(dev[0], "GET_FAIL")
  4098. dev[0].request("REMOVE_NETWORK all")
  4099. dev[0].dump_monitor()
  4100. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4101. eap="SIM", identity="1232010000000000",
  4102. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4103. with fail_test(dev[0], 1, "os_get_random;eap_sim_msg_add_encr_start"):
  4104. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  4105. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  4106. if ev is None:
  4107. raise Exception("EAP re-authentication did not start")
  4108. wait_fail_trigger(dev[0], "GET_FAIL")
  4109. dev[0].request("REMOVE_NETWORK all")
  4110. dev[0].dump_monitor()
  4111. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4112. eap="SIM", identity="1232010000000000",
  4113. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4114. with fail_test(dev[0], 1, "os_get_random;eap_sim_init_for_reauth"):
  4115. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  4116. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  4117. if ev is None:
  4118. raise Exception("EAP re-authentication did not start")
  4119. wait_fail_trigger(dev[0], "GET_FAIL")
  4120. dev[0].request("REMOVE_NETWORK all")
  4121. dev[0].dump_monitor()
  4122. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4123. eap="SIM", identity="1232010000000000",
  4124. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4125. with alloc_fail(dev[0], 1, "eap_sim_parse_encr;eap_sim_process_reauthentication"):
  4126. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  4127. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  4128. if ev is None:
  4129. raise Exception("EAP re-authentication did not start")
  4130. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4131. dev[0].request("REMOVE_NETWORK all")
  4132. dev[0].dump_monitor()
  4133. tests = [ (1, "eap_sim_verify_mac;eap_sim_process_challenge"),
  4134. (1, "eap_sim_parse_encr;eap_sim_process_challenge"),
  4135. (1, "eap_sim_msg_init;eap_sim_response_start"),
  4136. (1, "wpabuf_alloc;eap_sim_msg_init;eap_sim_response_start"),
  4137. (1, "=eap_sim_learn_ids"),
  4138. (2, "=eap_sim_learn_ids"),
  4139. (2, "eap_sim_learn_ids"),
  4140. (3, "eap_sim_learn_ids"),
  4141. (1, "eap_sim_process_start"),
  4142. (1, "eap_sim_getKey"),
  4143. (1, "eap_sim_get_emsk"),
  4144. (1, "eap_sim_get_session_id") ]
  4145. for count, func in tests:
  4146. with alloc_fail(dev[0], count, func):
  4147. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4148. eap="SIM", identity="1232010000000000@domain",
  4149. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4150. erp="1", wait_connect=False)
  4151. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4152. dev[0].request("REMOVE_NETWORK all")
  4153. dev[0].dump_monitor()
  4154. tests = [ (1, "aes_128_cbc_decrypt;eap_sim_parse_encr") ]
  4155. for count, func in tests:
  4156. with fail_test(dev[0], count, func):
  4157. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4158. eap="SIM", identity="1232010000000000",
  4159. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4160. wait_connect=False)
  4161. wait_fail_trigger(dev[0], "GET_FAIL")
  4162. dev[0].request("REMOVE_NETWORK all")
  4163. dev[0].dump_monitor()
  4164. params = int_eap_server_params()
  4165. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  4166. params['eap_sim_aka_result_ind'] = "1"
  4167. hostapd.add_ap(apdev[1], params)
  4168. with alloc_fail(dev[0], 1,
  4169. "eap_sim_msg_init;eap_sim_response_notification"):
  4170. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  4171. scan_freq="2412",
  4172. eap="SIM", identity="1232010000000000",
  4173. phase1="result_ind=1",
  4174. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4175. wait_connect=False)
  4176. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4177. dev[0].request("REMOVE_NETWORK all")
  4178. dev[0].dump_monitor()
  4179. tests = [ "eap_sim_msg_add_encr_start;eap_sim_response_notification",
  4180. "aes_128_cbc_encrypt;eap_sim_response_notification" ]
  4181. for func in tests:
  4182. with fail_test(dev[0], 1, func):
  4183. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  4184. scan_freq="2412",
  4185. eap="SIM", identity="1232010000000000",
  4186. phase1="result_ind=1",
  4187. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4188. dev[0].request("REAUTHENTICATE")
  4189. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  4190. if ev is None:
  4191. raise Exception("EAP method not started on reauthentication")
  4192. time.sleep(0.1)
  4193. wait_fail_trigger(dev[0], "GET_FAIL")
  4194. dev[0].request("REMOVE_NETWORK all")
  4195. dev[0].dump_monitor()
  4196. tests = [ "eap_sim_parse_encr;eap_sim_process_notification_reauth" ]
  4197. for func in tests:
  4198. with alloc_fail(dev[0], 1, func):
  4199. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  4200. scan_freq="2412",
  4201. eap="SIM", identity="1232010000000000",
  4202. phase1="result_ind=1",
  4203. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4204. dev[0].request("REAUTHENTICATE")
  4205. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  4206. if ev is None:
  4207. raise Exception("EAP method not started on reauthentication")
  4208. time.sleep(0.1)
  4209. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4210. dev[0].request("REMOVE_NETWORK all")
  4211. dev[0].dump_monitor()
  4212. def test_eap_proto_aka_errors(dev, apdev):
  4213. """EAP-AKA protocol tests (error paths)"""
  4214. check_hlr_auc_gw_support()
  4215. params = hostapd.wpa2_eap_params(ssid="eap-test")
  4216. hapd = hostapd.add_ap(apdev[0], params)
  4217. with alloc_fail(dev[0], 1, "eap_aka_init"):
  4218. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4219. eap="AKA", identity="0232010000000000",
  4220. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  4221. wait_connect=False)
  4222. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  4223. timeout=15)
  4224. if ev is None:
  4225. raise Exception("Timeout on EAP start")
  4226. dev[0].request("REMOVE_NETWORK all")
  4227. dev[0].wait_disconnected()
  4228. tests = [ (1, "=eap_aka_learn_ids"),
  4229. (2, "=eap_aka_learn_ids"),
  4230. (1, "eap_sim_parse_encr;eap_aka_process_challenge"),
  4231. (1, "wpabuf_dup;eap_aka_add_id_msg"),
  4232. (1, "wpabuf_resize;eap_aka_add_id_msg"),
  4233. (1, "eap_aka_getKey"),
  4234. (1, "eap_aka_get_emsk"),
  4235. (1, "eap_aka_get_session_id") ]
  4236. for count, func in tests:
  4237. with alloc_fail(dev[0], count, func):
  4238. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4239. eap="AKA", identity="0232010000000000@domain",
  4240. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  4241. erp="1", wait_connect=False)
  4242. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4243. dev[0].request("REMOVE_NETWORK all")
  4244. dev[0].dump_monitor()
  4245. params = int_eap_server_params()
  4246. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  4247. params['eap_sim_aka_result_ind'] = "1"
  4248. hostapd.add_ap(apdev[1], params)
  4249. with alloc_fail(dev[0], 1,
  4250. "eap_sim_msg_init;eap_aka_response_notification"):
  4251. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412",
  4252. eap="AKA", identity="0232010000000000",
  4253. phase1="result_ind=1",
  4254. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  4255. wait_connect=False)
  4256. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4257. dev[0].request("REMOVE_NETWORK all")
  4258. dev[0].dump_monitor()
  4259. tests = [ "eap_sim_msg_add_encr_start;eap_aka_response_notification",
  4260. "aes_128_cbc_encrypt;eap_aka_response_notification" ]
  4261. for func in tests:
  4262. with fail_test(dev[0], 1, func):
  4263. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  4264. scan_freq="2412",
  4265. eap="AKA", identity="0232010000000000",
  4266. phase1="result_ind=1",
  4267. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  4268. dev[0].request("REAUTHENTICATE")
  4269. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  4270. if ev is None:
  4271. raise Exception("EAP method not started on reauthentication")
  4272. time.sleep(0.1)
  4273. wait_fail_trigger(dev[0], "GET_FAIL")
  4274. dev[0].request("REMOVE_NETWORK all")
  4275. dev[0].dump_monitor()
  4276. tests = [ "eap_sim_parse_encr;eap_aka_process_notification_reauth" ]
  4277. for func in tests:
  4278. with alloc_fail(dev[0], 1, func):
  4279. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  4280. scan_freq="2412",
  4281. eap="AKA", identity="0232010000000000",
  4282. phase1="result_ind=1",
  4283. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  4284. dev[0].request("REAUTHENTICATE")
  4285. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  4286. if ev is None:
  4287. raise Exception("EAP method not started on reauthentication")
  4288. time.sleep(0.1)
  4289. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4290. dev[0].request("REMOVE_NETWORK all")
  4291. dev[0].dump_monitor()
  4292. def test_eap_proto_aka_prime_errors(dev, apdev):
  4293. """EAP-AKA' protocol tests (error paths)"""
  4294. check_hlr_auc_gw_support()
  4295. params = hostapd.wpa2_eap_params(ssid="eap-test")
  4296. hapd = hostapd.add_ap(apdev[0], params)
  4297. with alloc_fail(dev[0], 1, "eap_aka_init"):
  4298. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4299. eap="AKA'", identity="6555444333222111",
  4300. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  4301. wait_connect=False)
  4302. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  4303. timeout=15)
  4304. if ev is None:
  4305. raise Exception("Timeout on EAP start")
  4306. dev[0].request("REMOVE_NETWORK all")
  4307. dev[0].wait_disconnected()
  4308. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4309. eap="AKA'", identity="6555444333222111",
  4310. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  4311. with fail_test(dev[0], 1, "aes_128_cbc_encrypt;eap_aka_response_reauth"):
  4312. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  4313. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  4314. if ev is None:
  4315. raise Exception("EAP re-authentication did not start")
  4316. wait_fail_trigger(dev[0], "GET_FAIL")
  4317. dev[0].request("REMOVE_NETWORK all")
  4318. dev[0].dump_monitor()
  4319. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4320. eap="AKA'", identity="6555444333222111",
  4321. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  4322. with alloc_fail(dev[0], 1, "eap_sim_parse_encr;eap_aka_process_reauthentication"):
  4323. hapd.request("EAPOL_REAUTH " + dev[0].own_addr())
  4324. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  4325. if ev is None:
  4326. raise Exception("EAP re-authentication did not start")
  4327. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4328. dev[0].request("REMOVE_NETWORK all")
  4329. dev[0].dump_monitor()
  4330. tests = [ (1, "eap_sim_verify_mac_sha256"),
  4331. (1, "=eap_aka_process_challenge") ]
  4332. for count, func in tests:
  4333. with alloc_fail(dev[0], count, func):
  4334. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4335. eap="AKA'", identity="6555444333222111",
  4336. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  4337. erp="1", wait_connect=False)
  4338. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4339. dev[0].request("REMOVE_NETWORK all")
  4340. dev[0].dump_monitor()
  4341. def test_eap_proto_ikev2(dev, apdev):
  4342. """EAP-IKEv2 protocol tests"""
  4343. check_eap_capa(dev[0], "IKEV2")
  4344. global eap_proto_ikev2_test_done
  4345. eap_proto_ikev2_test_done = False
  4346. def ikev2_handler(ctx, req):
  4347. logger.info("ikev2_handler - RX " + req.encode("hex"))
  4348. if 'num' not in ctx:
  4349. ctx['num'] = 0
  4350. ctx['num'] = ctx['num'] + 1
  4351. if 'id' not in ctx:
  4352. ctx['id'] = 1
  4353. ctx['id'] = (ctx['id'] + 1) % 256
  4354. idx = 0
  4355. idx += 1
  4356. if ctx['num'] == idx:
  4357. logger.info("Test: Missing payload")
  4358. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  4359. 4 + 1,
  4360. EAP_TYPE_IKEV2)
  4361. idx += 1
  4362. if ctx['num'] == idx:
  4363. logger.info("Test: Truncated Message Length field")
  4364. return struct.pack(">BBHBB3B", EAP_CODE_REQUEST, ctx['id'],
  4365. 4 + 1 + 1 + 3,
  4366. EAP_TYPE_IKEV2, 0x80, 0, 0, 0)
  4367. idx += 1
  4368. if ctx['num'] == idx:
  4369. logger.info("Test: Too short Message Length value")
  4370. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  4371. 4 + 1 + 1 + 4 + 1,
  4372. EAP_TYPE_IKEV2, 0x80, 0, 1)
  4373. idx += 1
  4374. if ctx['num'] == idx:
  4375. logger.info("Test: Truncated message")
  4376. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  4377. 4 + 1 + 1 + 4,
  4378. EAP_TYPE_IKEV2, 0x80, 1)
  4379. idx += 1
  4380. if ctx['num'] == idx:
  4381. logger.info("Test: Truncated message(2)")
  4382. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  4383. 4 + 1 + 1 + 4,
  4384. EAP_TYPE_IKEV2, 0x80, 0xffffffff)
  4385. idx += 1
  4386. if ctx['num'] == idx:
  4387. logger.info("Test: Truncated message(3)")
  4388. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  4389. 4 + 1 + 1 + 4,
  4390. EAP_TYPE_IKEV2, 0xc0, 0xffffffff)
  4391. idx += 1
  4392. if ctx['num'] == idx:
  4393. logger.info("Test: Truncated message(4)")
  4394. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  4395. 4 + 1 + 1 + 4,
  4396. EAP_TYPE_IKEV2, 0xc0, 10000000)
  4397. idx += 1
  4398. if ctx['num'] == idx:
  4399. logger.info("Test: Too long fragments (first fragment)")
  4400. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  4401. 4 + 1 + 1 + 4 + 1,
  4402. EAP_TYPE_IKEV2, 0xc0, 2, 1)
  4403. idx += 1
  4404. if ctx['num'] == idx:
  4405. logger.info("Test: Too long fragments (second fragment)")
  4406. return struct.pack(">BBHBB2B", EAP_CODE_REQUEST, ctx['id'],
  4407. 4 + 1 + 1 + 2,
  4408. EAP_TYPE_IKEV2, 0x00, 2, 3)
  4409. idx += 1
  4410. if ctx['num'] == idx:
  4411. logger.info("Test: No Message Length field in first fragment")
  4412. return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
  4413. 4 + 1 + 1 + 1,
  4414. EAP_TYPE_IKEV2, 0x40, 1)
  4415. idx += 1
  4416. if ctx['num'] == idx:
  4417. logger.info("Test: ICV before keys")
  4418. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  4419. 4 + 1 + 1,
  4420. EAP_TYPE_IKEV2, 0x20)
  4421. idx += 1
  4422. if ctx['num'] == idx:
  4423. logger.info("Test: Unsupported IKEv2 header version")
  4424. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4425. 4 + 1 + 1 + 28,
  4426. EAP_TYPE_IKEV2, 0x00,
  4427. 0, 0, 0, 0,
  4428. 0, 0, 0, 0, 0, 0)
  4429. idx += 1
  4430. if ctx['num'] == idx:
  4431. logger.info("Test: Incorrect IKEv2 header Length")
  4432. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4433. 4 + 1 + 1 + 28,
  4434. EAP_TYPE_IKEV2, 0x00,
  4435. 0, 0, 0, 0,
  4436. 0, 0x20, 0, 0, 0, 0)
  4437. idx += 1
  4438. if ctx['num'] == idx:
  4439. logger.info("Test: Unexpected IKEv2 Exchange Type in SA_INIT state")
  4440. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4441. 4 + 1 + 1 + 28,
  4442. EAP_TYPE_IKEV2, 0x00,
  4443. 0, 0, 0, 0,
  4444. 0, 0x20, 0, 0, 0, 28)
  4445. idx += 1
  4446. if ctx['num'] == idx:
  4447. logger.info("Test: Unexpected IKEv2 Message ID in SA_INIT state")
  4448. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4449. 4 + 1 + 1 + 28,
  4450. EAP_TYPE_IKEV2, 0x00,
  4451. 0, 0, 0, 0,
  4452. 0, 0x20, 34, 0, 1, 28)
  4453. idx += 1
  4454. if ctx['num'] == idx:
  4455. logger.info("Test: Unexpected IKEv2 Flags value")
  4456. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4457. 4 + 1 + 1 + 28,
  4458. EAP_TYPE_IKEV2, 0x00,
  4459. 0, 0, 0, 0,
  4460. 0, 0x20, 34, 0, 0, 28)
  4461. idx += 1
  4462. if ctx['num'] == idx:
  4463. logger.info("Test: Unexpected IKEv2 Flags value(2)")
  4464. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4465. 4 + 1 + 1 + 28,
  4466. EAP_TYPE_IKEV2, 0x00,
  4467. 0, 0, 0, 0,
  4468. 0, 0x20, 34, 0x20, 0, 28)
  4469. idx += 1
  4470. if ctx['num'] == idx:
  4471. logger.info("Test: No SAi1 in SA_INIT")
  4472. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, ctx['id'],
  4473. 4 + 1 + 1 + 28,
  4474. EAP_TYPE_IKEV2, 0x00,
  4475. 0, 0, 0, 0,
  4476. 0, 0x20, 34, 0x08, 0, 28)
  4477. def build_ike(id, next=0, exch_type=34, flags=0x00, ike=''):
  4478. return struct.pack(">BBHBB2L2LBBBBLL", EAP_CODE_REQUEST, id,
  4479. 4 + 1 + 1 + 28 + len(ike),
  4480. EAP_TYPE_IKEV2, flags,
  4481. 0, 0, 0, 0,
  4482. next, 0x20, exch_type, 0x08, 0,
  4483. 28 + len(ike)) + ike
  4484. idx += 1
  4485. if ctx['num'] == idx:
  4486. logger.info("Test: Unexpected extra data after payloads")
  4487. return build_ike(ctx['id'], ike=struct.pack(">B", 1))
  4488. idx += 1
  4489. if ctx['num'] == idx:
  4490. logger.info("Test: Truncated payload header")
  4491. return build_ike(ctx['id'], next=128, ike=struct.pack(">B", 1))
  4492. idx += 1
  4493. if ctx['num'] == idx:
  4494. logger.info("Test: Too small payload header length")
  4495. ike = struct.pack(">BBH", 0, 0, 3)
  4496. return build_ike(ctx['id'], next=128, ike=ike)
  4497. idx += 1
  4498. if ctx['num'] == idx:
  4499. logger.info("Test: Too large payload header length")
  4500. ike = struct.pack(">BBH", 0, 0, 5)
  4501. return build_ike(ctx['id'], next=128, ike=ike)
  4502. idx += 1
  4503. if ctx['num'] == idx:
  4504. logger.info("Test: Unsupported payload (non-critical and critical)")
  4505. ike = struct.pack(">BBHBBH", 129, 0, 4, 0, 0x01, 4)
  4506. return build_ike(ctx['id'], next=128, ike=ike)
  4507. idx += 1
  4508. if ctx['num'] == idx:
  4509. logger.info("Test: Certificate and empty SAi1")
  4510. ike = struct.pack(">BBHBBH", 33, 0, 4, 0, 0, 4)
  4511. return build_ike(ctx['id'], next=37, ike=ike)
  4512. idx += 1
  4513. if ctx['num'] == idx:
  4514. logger.info("Test: Too short proposal")
  4515. ike = struct.pack(">BBHBBHBBB", 0, 0, 4 + 7,
  4516. 0, 0, 7, 0, 0, 0)
  4517. return build_ike(ctx['id'], next=33, ike=ike)
  4518. idx += 1
  4519. if ctx['num'] == idx:
  4520. logger.info("Test: Too small proposal length in SAi1")
  4521. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4522. 0, 0, 7, 0, 0, 0, 0)
  4523. return build_ike(ctx['id'], next=33, ike=ike)
  4524. idx += 1
  4525. if ctx['num'] == idx:
  4526. logger.info("Test: Too large proposal length in SAi1")
  4527. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4528. 0, 0, 9, 0, 0, 0, 0)
  4529. return build_ike(ctx['id'], next=33, ike=ike)
  4530. idx += 1
  4531. if ctx['num'] == idx:
  4532. logger.info("Test: Unexpected proposal type in SAi1")
  4533. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4534. 1, 0, 8, 0, 0, 0, 0)
  4535. return build_ike(ctx['id'], next=33, ike=ike)
  4536. idx += 1
  4537. if ctx['num'] == idx:
  4538. logger.info("Test: Unexpected Protocol ID in SAi1")
  4539. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4540. 0, 0, 8, 0, 0, 0, 0)
  4541. return build_ike(ctx['id'], next=33, ike=ike)
  4542. idx += 1
  4543. if ctx['num'] == idx:
  4544. logger.info("Test: Unexpected proposal number in SAi1")
  4545. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4546. 0, 0, 8, 0, 1, 0, 0)
  4547. return build_ike(ctx['id'], next=33, ike=ike)
  4548. idx += 1
  4549. if ctx['num'] == idx:
  4550. logger.info("Test: Not enough room for SPI in SAi1")
  4551. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4552. 0, 0, 8, 1, 1, 1, 0)
  4553. return build_ike(ctx['id'], next=33, ike=ike)
  4554. idx += 1
  4555. if ctx['num'] == idx:
  4556. logger.info("Test: Unexpected SPI in SAi1")
  4557. ike = struct.pack(">BBHBBHBBBBB", 0, 0, 4 + 9,
  4558. 0, 0, 9, 1, 1, 1, 0, 1)
  4559. return build_ike(ctx['id'], next=33, ike=ike)
  4560. idx += 1
  4561. if ctx['num'] == idx:
  4562. logger.info("Test: No transforms in SAi1")
  4563. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4564. 0, 0, 8, 1, 1, 0, 0)
  4565. return build_ike(ctx['id'], next=33, ike=ike)
  4566. idx += 1
  4567. if ctx['num'] == idx:
  4568. logger.info("Test: Too short transform in SAi1")
  4569. ike = struct.pack(">BBHBBHBBBB", 0, 0, 4 + 8,
  4570. 0, 0, 8, 1, 1, 0, 1)
  4571. return build_ike(ctx['id'], next=33, ike=ike)
  4572. idx += 1
  4573. if ctx['num'] == idx:
  4574. logger.info("Test: Too small transform length in SAi1")
  4575. ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
  4576. 0, 0, 8 + 8, 1, 1, 0, 1,
  4577. 0, 0, 7, 0, 0, 0)
  4578. return build_ike(ctx['id'], next=33, ike=ike)
  4579. idx += 1
  4580. if ctx['num'] == idx:
  4581. logger.info("Test: Too large transform length in SAi1")
  4582. ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
  4583. 0, 0, 8 + 8, 1, 1, 0, 1,
  4584. 0, 0, 9, 0, 0, 0)
  4585. return build_ike(ctx['id'], next=33, ike=ike)
  4586. idx += 1
  4587. if ctx['num'] == idx:
  4588. logger.info("Test: Unexpected Transform type in SAi1")
  4589. ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
  4590. 0, 0, 8 + 8, 1, 1, 0, 1,
  4591. 1, 0, 8, 0, 0, 0)
  4592. return build_ike(ctx['id'], next=33, ike=ike)
  4593. idx += 1
  4594. if ctx['num'] == idx:
  4595. logger.info("Test: No transform attributes in SAi1")
  4596. ike = struct.pack(">BBHBBHBBBBBBHBBH", 0, 0, 4 + 8 + 8,
  4597. 0, 0, 8 + 8, 1, 1, 0, 1,
  4598. 0, 0, 8, 0, 0, 0)
  4599. return build_ike(ctx['id'], next=33, ike=ike)
  4600. idx += 1
  4601. if ctx['num'] == idx:
  4602. logger.info("Test: No transform attr for AES and unexpected data after transforms in SAi1")
  4603. tlen1 = 8 + 3
  4604. tlen2 = 8 + 4
  4605. tlen3 = 8 + 4
  4606. tlen = tlen1 + tlen2 + tlen3
  4607. ike = struct.pack(">BBHBBHBBBBBBHBBH3BBBHBBHHHBBHBBHHHB",
  4608. 0, 0, 4 + 8 + tlen + 1,
  4609. 0, 0, 8 + tlen + 1, 1, 1, 0, 3,
  4610. 3, 0, tlen1, 1, 0, 12, 1, 2, 3,
  4611. 3, 0, tlen2, 1, 0, 12, 0, 128,
  4612. 0, 0, tlen3, 1, 0, 12, 0x8000 | 14, 127,
  4613. 1)
  4614. return build_ike(ctx['id'], next=33, ike=ike)
  4615. def build_sa(next=0):
  4616. tlen = 5 * 8
  4617. return struct.pack(">BBHBBHBBBBBBHBBHBBHBBHBBHBBHBBHBBHBBHBBH",
  4618. next, 0, 4 + 8 + tlen,
  4619. 0, 0, 8 + tlen, 1, 1, 0, 5,
  4620. 3, 0, 8, 1, 0, 3,
  4621. 3, 0, 8, 2, 0, 1,
  4622. 3, 0, 8, 3, 0, 1,
  4623. 3, 0, 8, 4, 0, 5,
  4624. 0, 0, 8, 241, 0, 0)
  4625. idx += 1
  4626. if ctx['num'] == idx:
  4627. logger.info("Test: Valid proposal, but no KEi in SAi1")
  4628. ike = build_sa()
  4629. return build_ike(ctx['id'], next=33, ike=ike)
  4630. idx += 1
  4631. if ctx['num'] == idx:
  4632. logger.info("Test: Empty KEi in SAi1")
  4633. ike = build_sa(next=34) + struct.pack(">BBH", 0, 0, 4)
  4634. return build_ike(ctx['id'], next=33, ike=ike)
  4635. idx += 1
  4636. if ctx['num'] == idx:
  4637. logger.info("Test: Mismatch in DH Group in SAi1")
  4638. ike = build_sa(next=34)
  4639. ike += struct.pack(">BBHHH", 0, 0, 4 + 4 + 96, 12345, 0)
  4640. ike += 96*'\x00'
  4641. return build_ike(ctx['id'], next=33, ike=ike)
  4642. idx += 1
  4643. if ctx['num'] == idx:
  4644. logger.info("Test: EAP-Failure")
  4645. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4646. idx += 1
  4647. if ctx['num'] == idx:
  4648. logger.info("Test: Invalid DH public value length in SAi1")
  4649. ike = build_sa(next=34)
  4650. ike += struct.pack(">BBHHH", 0, 0, 4 + 4 + 96, 5, 0)
  4651. ike += 96*'\x00'
  4652. return build_ike(ctx['id'], next=33, ike=ike)
  4653. def build_ke(next=0):
  4654. ke = struct.pack(">BBHHH", next, 0, 4 + 4 + 192, 5, 0)
  4655. ke += 192*'\x00'
  4656. return ke
  4657. idx += 1
  4658. if ctx['num'] == idx:
  4659. logger.info("Test: Valid proposal and KEi, but no Ni in SAi1")
  4660. ike = build_sa(next=34)
  4661. ike += build_ke()
  4662. return build_ike(ctx['id'], next=33, ike=ike)
  4663. idx += 1
  4664. if ctx['num'] == idx:
  4665. logger.info("Test: Too short Ni in SAi1")
  4666. ike = build_sa(next=34)
  4667. ike += build_ke(next=40)
  4668. ike += struct.pack(">BBH", 0, 0, 4)
  4669. return build_ike(ctx['id'], next=33, ike=ike)
  4670. idx += 1
  4671. if ctx['num'] == idx:
  4672. logger.info("Test: Too long Ni in SAi1")
  4673. ike = build_sa(next=34)
  4674. ike += build_ke(next=40)
  4675. ike += struct.pack(">BBH", 0, 0, 4 + 257) + 257*'\x00'
  4676. return build_ike(ctx['id'], next=33, ike=ike)
  4677. def build_ni(next=0):
  4678. return struct.pack(">BBH", next, 0, 4 + 256) + 256*'\x00'
  4679. def build_sai1(id):
  4680. ike = build_sa(next=34)
  4681. ike += build_ke(next=40)
  4682. ike += build_ni()
  4683. return build_ike(ctx['id'], next=33, ike=ike)
  4684. idx += 1
  4685. if ctx['num'] == idx:
  4686. logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
  4687. return build_sai1(ctx['id'])
  4688. idx += 1
  4689. if ctx['num'] == idx:
  4690. logger.info("Test: EAP-Failure")
  4691. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4692. idx += 1
  4693. if ctx['num'] == idx:
  4694. logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
  4695. return build_sai1(ctx['id'])
  4696. idx += 1
  4697. if ctx['num'] == idx:
  4698. logger.info("Test: No integrity checksum")
  4699. ike = ''
  4700. return build_ike(ctx['id'], next=37, ike=ike)
  4701. idx += 1
  4702. if ctx['num'] == idx:
  4703. logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
  4704. return build_sai1(ctx['id'])
  4705. idx += 1
  4706. if ctx['num'] == idx:
  4707. logger.info("Test: Truncated integrity checksum")
  4708. return struct.pack(">BBHBB",
  4709. EAP_CODE_REQUEST, ctx['id'],
  4710. 4 + 1 + 1,
  4711. EAP_TYPE_IKEV2, 0x20)
  4712. idx += 1
  4713. if ctx['num'] == idx:
  4714. logger.info("Test: Valid proposal, KEi, and Ni in SAi1")
  4715. return build_sai1(ctx['id'])
  4716. idx += 1
  4717. if ctx['num'] == idx:
  4718. logger.info("Test: Invalid integrity checksum")
  4719. ike = ''
  4720. return build_ike(ctx['id'], next=37, flags=0x20, ike=ike)
  4721. idx += 1
  4722. if ctx['num'] == idx:
  4723. logger.info("No more test responses available - test case completed")
  4724. global eap_proto_ikev2_test_done
  4725. eap_proto_ikev2_test_done = True
  4726. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  4727. 4 + 1,
  4728. EAP_TYPE_IKEV2)
  4729. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4730. srv = start_radius_server(ikev2_handler)
  4731. try:
  4732. hapd = start_ap(apdev[0])
  4733. i = 0
  4734. while not eap_proto_ikev2_test_done:
  4735. i += 1
  4736. logger.info("Running connection iteration %d" % i)
  4737. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4738. eap="IKEV2", identity="user",
  4739. password="password",
  4740. wait_connect=False)
  4741. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=15)
  4742. if ev is None:
  4743. raise Exception("Timeout on EAP start")
  4744. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  4745. timeout=15)
  4746. if ev is None:
  4747. raise Exception("Timeout on EAP method start")
  4748. if i in [ 41, 46 ]:
  4749. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  4750. timeout=10)
  4751. if ev is None:
  4752. raise Exception("Timeout on EAP failure")
  4753. else:
  4754. time.sleep(0.05)
  4755. dev[0].request("REMOVE_NETWORK all")
  4756. dev[0].wait_disconnected()
  4757. dev[0].dump_monitor()
  4758. dev[1].dump_monitor()
  4759. dev[2].dump_monitor()
  4760. finally:
  4761. stop_radius_server(srv)
  4762. def NtPasswordHash(password):
  4763. pw = password.encode('utf_16_le')
  4764. return hashlib.new('md4', pw).digest()
  4765. def HashNtPasswordHash(password_hash):
  4766. return hashlib.new('md4', password_hash).digest()
  4767. def ChallengeHash(peer_challenge, auth_challenge, username):
  4768. data = peer_challenge + auth_challenge + username
  4769. return hashlib.sha1(data).digest()[0:8]
  4770. def GenerateAuthenticatorResponse(password, nt_response, peer_challenge,
  4771. auth_challenge, username):
  4772. magic1 = binascii.unhexlify("4D616769632073657276657220746F20636C69656E74207369676E696E6720636F6E7374616E74")
  4773. magic2 = binascii.unhexlify("50616420746F206D616B6520697420646F206D6F7265207468616E206F6E6520697465726174696F6E")
  4774. password_hash = NtPasswordHash(password)
  4775. password_hash_hash = HashNtPasswordHash(password_hash)
  4776. data = password_hash_hash + nt_response + magic1
  4777. digest = hashlib.sha1(data).digest()
  4778. challenge = ChallengeHash(peer_challenge, auth_challenge, username)
  4779. data = digest + challenge + magic2
  4780. resp = hashlib.sha1(data).digest()
  4781. return resp
  4782. def test_eap_proto_ikev2_errors(dev, apdev):
  4783. """EAP-IKEv2 local error cases"""
  4784. check_eap_capa(dev[0], "IKEV2")
  4785. params = hostapd.wpa2_eap_params(ssid="eap-test")
  4786. hapd = hostapd.add_ap(apdev[0], params)
  4787. for i in range(1, 5):
  4788. with alloc_fail(dev[0], i, "eap_ikev2_init"):
  4789. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4790. eap="IKEV2", identity="ikev2 user",
  4791. password="ike password",
  4792. wait_connect=False)
  4793. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  4794. timeout=15)
  4795. if ev is None:
  4796. raise Exception("Timeout on EAP start")
  4797. dev[0].request("REMOVE_NETWORK all")
  4798. dev[0].wait_disconnected()
  4799. tests = [ (1, "ikev2_encr_encrypt"),
  4800. (1, "ikev2_encr_decrypt"),
  4801. (1, "ikev2_derive_auth_data"),
  4802. (2, "ikev2_derive_auth_data"),
  4803. (1, "=ikev2_decrypt_payload"),
  4804. (1, "ikev2_encr_decrypt;ikev2_decrypt_payload"),
  4805. (1, "ikev2_encr_encrypt;ikev2_build_encrypted"),
  4806. (1, "ikev2_derive_sk_keys"),
  4807. (2, "ikev2_derive_sk_keys"),
  4808. (3, "ikev2_derive_sk_keys"),
  4809. (4, "ikev2_derive_sk_keys"),
  4810. (5, "ikev2_derive_sk_keys"),
  4811. (6, "ikev2_derive_sk_keys"),
  4812. (7, "ikev2_derive_sk_keys"),
  4813. (8, "ikev2_derive_sk_keys"),
  4814. (1, "eap_ikev2_derive_keymat;eap_ikev2_peer_keymat"),
  4815. (1, "eap_msg_alloc;eap_ikev2_build_msg"),
  4816. (1, "eap_ikev2_getKey"),
  4817. (1, "eap_ikev2_get_emsk"),
  4818. (1, "eap_ikev2_get_session_id"),
  4819. (1, "=ikev2_derive_keys"),
  4820. (2, "=ikev2_derive_keys"),
  4821. (1, "wpabuf_alloc;ikev2_process_kei"),
  4822. (1, "=ikev2_process_idi"),
  4823. (1, "ikev2_derive_auth_data;ikev2_build_auth"),
  4824. (1, "wpabuf_alloc;ikev2_build_sa_init"),
  4825. (2, "wpabuf_alloc;ikev2_build_sa_init"),
  4826. (3, "wpabuf_alloc;ikev2_build_sa_init"),
  4827. (4, "wpabuf_alloc;ikev2_build_sa_init"),
  4828. (5, "wpabuf_alloc;ikev2_build_sa_init"),
  4829. (6, "wpabuf_alloc;ikev2_build_sa_init"),
  4830. (1, "wpabuf_alloc;ikev2_build_sa_auth"),
  4831. (2, "wpabuf_alloc;ikev2_build_sa_auth"),
  4832. (1, "ikev2_build_auth;ikev2_build_sa_auth") ]
  4833. for count, func in tests:
  4834. with alloc_fail(dev[0], count, func):
  4835. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4836. eap="IKEV2", identity="ikev2 user@domain",
  4837. password="ike password", erp="1", wait_connect=False)
  4838. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  4839. timeout=15)
  4840. if ev is None:
  4841. raise Exception("Timeout on EAP start")
  4842. ok = False
  4843. for j in range(10):
  4844. state = dev[0].request('GET_ALLOC_FAIL')
  4845. if state.startswith('0:'):
  4846. ok = True
  4847. break
  4848. time.sleep(0.1)
  4849. if not ok:
  4850. raise Exception("No allocation failure seen for %d:%s" % (count, func))
  4851. dev[0].request("REMOVE_NETWORK all")
  4852. dev[0].wait_disconnected()
  4853. tests = [ (1, "wpabuf_alloc;ikev2_build_notify"),
  4854. (2, "wpabuf_alloc;ikev2_build_notify"),
  4855. (1, "ikev2_build_encrypted;ikev2_build_notify") ]
  4856. for count, func in tests:
  4857. with alloc_fail(dev[0], count, func):
  4858. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4859. eap="IKEV2", identity="ikev2 user",
  4860. password="wrong password", erp="1",
  4861. wait_connect=False)
  4862. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  4863. timeout=15)
  4864. if ev is None:
  4865. raise Exception("Timeout on EAP start")
  4866. ok = False
  4867. for j in range(10):
  4868. state = dev[0].request('GET_ALLOC_FAIL')
  4869. if state.startswith('0:'):
  4870. ok = True
  4871. break
  4872. time.sleep(0.1)
  4873. if not ok:
  4874. raise Exception("No allocation failure seen for %d:%s" % (count, func))
  4875. dev[0].request("REMOVE_NETWORK all")
  4876. dev[0].wait_disconnected()
  4877. tests = [ (1, "ikev2_integ_hash"),
  4878. (1, "ikev2_integ_hash;ikev2_decrypt_payload"),
  4879. (1, "os_get_random;ikev2_build_encrypted"),
  4880. (1, "ikev2_prf_plus;ikev2_derive_sk_keys"),
  4881. (1, "eap_ikev2_derive_keymat;eap_ikev2_peer_keymat"),
  4882. (1, "os_get_random;ikev2_build_sa_init"),
  4883. (2, "os_get_random;ikev2_build_sa_init"),
  4884. (1, "ikev2_integ_hash;eap_ikev2_validate_icv"),
  4885. (1, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_keys"),
  4886. (1, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_auth_data"),
  4887. (2, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_auth_data"),
  4888. (3, "hmac_sha1_vector;?ikev2_prf_hash;ikev2_derive_auth_data") ]
  4889. for count, func in tests:
  4890. with fail_test(dev[0], count, func):
  4891. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  4892. eap="IKEV2", identity="ikev2 user",
  4893. password="ike password", wait_connect=False)
  4894. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  4895. timeout=15)
  4896. if ev is None:
  4897. raise Exception("Timeout on EAP start")
  4898. ok = False
  4899. for j in range(10):
  4900. state = dev[0].request('GET_FAIL')
  4901. if state.startswith('0:'):
  4902. ok = True
  4903. break
  4904. time.sleep(0.1)
  4905. if not ok:
  4906. raise Exception("No failure seen for %d:%s" % (count, func))
  4907. dev[0].request("REMOVE_NETWORK all")
  4908. dev[0].wait_disconnected()
  4909. params = { "ssid": "eap-test2", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  4910. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  4911. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  4912. "fragment_size": "50" }
  4913. hostapd.add_ap(apdev[1], params)
  4914. tests = [ (1, "eap_ikev2_build_frag_ack"),
  4915. (1, "wpabuf_alloc;eap_ikev2_process_fragment") ]
  4916. for count, func in tests:
  4917. with alloc_fail(dev[0], count, func):
  4918. dev[0].connect("eap-test2", key_mgmt="WPA-EAP", scan_freq="2412",
  4919. eap="IKEV2", identity="ikev2 user",
  4920. password="ike password", erp="1", wait_connect=False)
  4921. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  4922. timeout=15)
  4923. if ev is None:
  4924. raise Exception("Timeout on EAP start")
  4925. ok = False
  4926. for j in range(10):
  4927. state = dev[0].request('GET_ALLOC_FAIL')
  4928. if state.startswith('0:'):
  4929. ok = True
  4930. break
  4931. time.sleep(0.1)
  4932. if not ok:
  4933. raise Exception("No allocation failure seen for %d:%s" % (count, func))
  4934. dev[0].request("REMOVE_NETWORK all")
  4935. dev[0].wait_disconnected()
  4936. def test_eap_proto_mschapv2(dev, apdev):
  4937. """EAP-MSCHAPv2 protocol tests"""
  4938. check_eap_capa(dev[0], "MSCHAPV2")
  4939. def mschapv2_handler(ctx, req):
  4940. logger.info("mschapv2_handler - RX " + req.encode("hex"))
  4941. if 'num' not in ctx:
  4942. ctx['num'] = 0
  4943. ctx['num'] = ctx['num'] + 1
  4944. if 'id' not in ctx:
  4945. ctx['id'] = 1
  4946. ctx['id'] = (ctx['id'] + 1) % 256
  4947. idx = 0
  4948. idx += 1
  4949. if ctx['num'] == idx:
  4950. logger.info("Test: Missing payload")
  4951. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  4952. 4 + 1,
  4953. EAP_TYPE_MSCHAPV2)
  4954. idx += 1
  4955. if ctx['num'] == idx:
  4956. logger.info("Test: Unknown MSCHAPv2 op_code")
  4957. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  4958. 4 + 1 + 4 + 1,
  4959. EAP_TYPE_MSCHAPV2,
  4960. 0, 0, 5, 0)
  4961. idx += 1
  4962. if ctx['num'] == idx:
  4963. logger.info("Test: Invalid ms_len and unknown MSCHAPv2 op_code")
  4964. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  4965. 4 + 1 + 4 + 1,
  4966. EAP_TYPE_MSCHAPV2,
  4967. 255, 0, 0, 0)
  4968. idx += 1
  4969. if ctx['num'] == idx:
  4970. logger.info("Test: Success before challenge")
  4971. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  4972. 4 + 1 + 4 + 1,
  4973. EAP_TYPE_MSCHAPV2,
  4974. 3, 0, 5, 0)
  4975. idx += 1
  4976. if ctx['num'] == idx:
  4977. logger.info("Test: Failure before challenge - required challenge field not present")
  4978. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  4979. 4 + 1 + 4 + 1,
  4980. EAP_TYPE_MSCHAPV2,
  4981. 4, 0, 5, 0)
  4982. idx += 1
  4983. if ctx['num'] == idx:
  4984. logger.info("Test: Failure")
  4985. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4986. idx += 1
  4987. if ctx['num'] == idx:
  4988. logger.info("Test: Failure before challenge - invalid failure challenge len")
  4989. payload = 'C=12'
  4990. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  4991. 4 + 1 + 4 + len(payload),
  4992. EAP_TYPE_MSCHAPV2,
  4993. 4, 0, 4 + len(payload)) + payload
  4994. idx += 1
  4995. if ctx['num'] == idx:
  4996. logger.info("Test: Failure")
  4997. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  4998. idx += 1
  4999. if ctx['num'] == idx:
  5000. logger.info("Test: Failure before challenge - invalid failure challenge len")
  5001. payload = 'C=12 V=3'
  5002. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5003. 4 + 1 + 4 + len(payload),
  5004. EAP_TYPE_MSCHAPV2,
  5005. 4, 0, 4 + len(payload)) + payload
  5006. idx += 1
  5007. if ctx['num'] == idx:
  5008. logger.info("Test: Failure")
  5009. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5010. idx += 1
  5011. if ctx['num'] == idx:
  5012. logger.info("Test: Failure before challenge - invalid failure challenge")
  5013. payload = 'C=00112233445566778899aabbccddeefQ '
  5014. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5015. 4 + 1 + 4 + len(payload),
  5016. EAP_TYPE_MSCHAPV2,
  5017. 4, 0, 4 + len(payload)) + payload
  5018. idx += 1
  5019. if ctx['num'] == idx:
  5020. logger.info("Test: Failure")
  5021. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5022. idx += 1
  5023. if ctx['num'] == idx:
  5024. logger.info("Test: Failure before challenge - password expired")
  5025. payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
  5026. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5027. 4 + 1 + 4 + len(payload),
  5028. EAP_TYPE_MSCHAPV2,
  5029. 4, 0, 4 + len(payload)) + payload
  5030. idx += 1
  5031. if ctx['num'] == idx:
  5032. logger.info("Test: Success after password change")
  5033. payload = "S=1122334455667788990011223344556677889900"
  5034. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5035. 4 + 1 + 4 + len(payload),
  5036. EAP_TYPE_MSCHAPV2,
  5037. 3, 0, 4 + len(payload)) + payload
  5038. idx += 1
  5039. if ctx['num'] == idx:
  5040. logger.info("Test: Invalid challenge length")
  5041. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  5042. 4 + 1 + 4 + 1,
  5043. EAP_TYPE_MSCHAPV2,
  5044. 1, 0, 4 + 1, 0)
  5045. idx += 1
  5046. if ctx['num'] == idx:
  5047. logger.info("Test: Too short challenge packet")
  5048. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  5049. 4 + 1 + 4 + 1,
  5050. EAP_TYPE_MSCHAPV2,
  5051. 1, 0, 4 + 1, 16)
  5052. idx += 1
  5053. if ctx['num'] == idx:
  5054. logger.info("Test: Challenge")
  5055. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  5056. 4 + 1 + 4 + 1 + 16 + 6,
  5057. EAP_TYPE_MSCHAPV2,
  5058. 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
  5059. idx += 1
  5060. if ctx['num'] == idx:
  5061. logger.info("Test: Failure - password expired")
  5062. payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
  5063. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5064. 4 + 1 + 4 + len(payload),
  5065. EAP_TYPE_MSCHAPV2,
  5066. 4, 0, 4 + len(payload)) + payload
  5067. idx += 1
  5068. if ctx['num'] == idx:
  5069. logger.info("Test: Success after password change")
  5070. if len(req) != 591:
  5071. logger.info("Unexpected Change-Password packet length: %s" % len(req))
  5072. return None
  5073. data = req[9:]
  5074. enc_pw = data[0:516]
  5075. data = data[516:]
  5076. enc_hash = data[0:16]
  5077. data = data[16:]
  5078. peer_challenge = data[0:16]
  5079. data = data[16:]
  5080. # Reserved
  5081. data = data[8:]
  5082. nt_response = data[0:24]
  5083. data = data[24:]
  5084. flags = data
  5085. logger.info("enc_hash: " + enc_hash.encode("hex"))
  5086. logger.info("peer_challenge: " + peer_challenge.encode("hex"))
  5087. logger.info("nt_response: " + nt_response.encode("hex"))
  5088. logger.info("flags: " + flags.encode("hex"))
  5089. auth_challenge = binascii.unhexlify("00112233445566778899aabbccddeeff")
  5090. logger.info("auth_challenge: " + auth_challenge.encode("hex"))
  5091. auth_resp = GenerateAuthenticatorResponse("new-pw", nt_response,
  5092. peer_challenge,
  5093. auth_challenge, "user")
  5094. payload = "S=" + auth_resp.encode('hex').upper()
  5095. logger.info("Success message payload: " + payload)
  5096. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5097. 4 + 1 + 4 + len(payload),
  5098. EAP_TYPE_MSCHAPV2,
  5099. 3, 0, 4 + len(payload)) + payload
  5100. idx += 1
  5101. if ctx['num'] == idx:
  5102. logger.info("Test: EAP-Success")
  5103. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  5104. idx += 1
  5105. if ctx['num'] == idx:
  5106. logger.info("Test: Failure - password expired")
  5107. payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
  5108. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5109. 4 + 1 + 4 + len(payload),
  5110. EAP_TYPE_MSCHAPV2,
  5111. 4, 0, 4 + len(payload)) + payload
  5112. idx += 1
  5113. if ctx['num'] == idx:
  5114. logger.info("Test: Success after password change")
  5115. if len(req) != 591:
  5116. logger.info("Unexpected Change-Password packet length: %s" % len(req))
  5117. return None
  5118. data = req[9:]
  5119. enc_pw = data[0:516]
  5120. data = data[516:]
  5121. enc_hash = data[0:16]
  5122. data = data[16:]
  5123. peer_challenge = data[0:16]
  5124. data = data[16:]
  5125. # Reserved
  5126. data = data[8:]
  5127. nt_response = data[0:24]
  5128. data = data[24:]
  5129. flags = data
  5130. logger.info("enc_hash: " + enc_hash.encode("hex"))
  5131. logger.info("peer_challenge: " + peer_challenge.encode("hex"))
  5132. logger.info("nt_response: " + nt_response.encode("hex"))
  5133. logger.info("flags: " + flags.encode("hex"))
  5134. auth_challenge = binascii.unhexlify("00112233445566778899aabbccddeeff")
  5135. logger.info("auth_challenge: " + auth_challenge.encode("hex"))
  5136. auth_resp = GenerateAuthenticatorResponse("new-pw", nt_response,
  5137. peer_challenge,
  5138. auth_challenge, "user")
  5139. payload = "S=" + auth_resp.encode('hex').upper()
  5140. logger.info("Success message payload: " + payload)
  5141. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5142. 4 + 1 + 4 + len(payload),
  5143. EAP_TYPE_MSCHAPV2,
  5144. 3, 0, 4 + len(payload)) + payload
  5145. idx += 1
  5146. if ctx['num'] == idx:
  5147. logger.info("Test: EAP-Success")
  5148. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  5149. idx += 1
  5150. if ctx['num'] == idx:
  5151. logger.info("Test: Challenge")
  5152. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  5153. 4 + 1 + 4 + 1 + 16 + 6,
  5154. EAP_TYPE_MSCHAPV2,
  5155. 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
  5156. idx += 1
  5157. if ctx['num'] == idx:
  5158. logger.info("Test: Failure - authentication failure")
  5159. payload = 'E=691 R=1 C=00112233445566778899aabbccddeeff V=3 M=Authentication failed'
  5160. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5161. 4 + 1 + 4 + len(payload),
  5162. EAP_TYPE_MSCHAPV2,
  5163. 4, 0, 4 + len(payload)) + payload
  5164. idx += 1
  5165. if ctx['num'] == idx:
  5166. logger.info("Test: Challenge")
  5167. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  5168. 4 + 1 + 4 + 1 + 16 + 6,
  5169. EAP_TYPE_MSCHAPV2,
  5170. 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
  5171. idx += 1
  5172. if ctx['num'] == idx:
  5173. logger.info("Test: Failure - authentication failure")
  5174. payload = 'E=691 R=1 C=00112233445566778899aabbccddeeff V=3 M=Authentication failed (2)'
  5175. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5176. 4 + 1 + 4 + len(payload),
  5177. EAP_TYPE_MSCHAPV2,
  5178. 4, 0, 4 + len(payload)) + payload
  5179. idx += 1
  5180. if ctx['num'] == idx:
  5181. logger.info("Test: Failure")
  5182. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5183. idx += 1
  5184. if ctx['num'] == idx:
  5185. logger.info("Test: Challenge - invalid ms_len and workaround disabled")
  5186. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  5187. 4 + 1 + 4 + 1 + 16 + 6,
  5188. EAP_TYPE_MSCHAPV2,
  5189. 1, 0, 4 + 1 + 16 + 6 + 1, 16) + 16*'A' + 'foobar'
  5190. return None
  5191. srv = start_radius_server(mschapv2_handler)
  5192. try:
  5193. hapd = start_ap(apdev[0])
  5194. for i in range(0, 16):
  5195. logger.info("RUN: %d" % i)
  5196. if i == 12:
  5197. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5198. eap="MSCHAPV2", identity="user",
  5199. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  5200. wait_connect=False)
  5201. elif i == 14:
  5202. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5203. eap="MSCHAPV2", identity="user",
  5204. phase2="mschapv2_retry=0",
  5205. password="password", wait_connect=False)
  5206. elif i == 15:
  5207. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5208. eap="MSCHAPV2", identity="user",
  5209. eap_workaround="0",
  5210. password="password", wait_connect=False)
  5211. else:
  5212. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5213. eap="MSCHAPV2", identity="user",
  5214. password="password", wait_connect=False)
  5215. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=15)
  5216. if ev is None:
  5217. raise Exception("Timeout on EAP start")
  5218. if i in [ 8, 11, 12 ]:
  5219. ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"],
  5220. timeout=10)
  5221. if ev is None:
  5222. raise Exception("Timeout on new password request")
  5223. id = ev.split(':')[0].split('-')[-1]
  5224. dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
  5225. if i in [ 11, 12 ]:
  5226. ev = dev[0].wait_event(["CTRL-EVENT-PASSWORD-CHANGED"],
  5227. timeout=10)
  5228. if ev is None:
  5229. raise Exception("Timeout on password change")
  5230. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"],
  5231. timeout=10)
  5232. if ev is None:
  5233. raise Exception("Timeout on EAP success")
  5234. else:
  5235. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  5236. timeout=10)
  5237. if ev is None:
  5238. raise Exception("Timeout on EAP failure")
  5239. if i in [ 13 ]:
  5240. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"],
  5241. timeout=10)
  5242. if ev is None:
  5243. raise Exception("Timeout on identity request")
  5244. id = ev.split(':')[0].split('-')[-1]
  5245. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":user")
  5246. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD"],
  5247. timeout=10)
  5248. if ev is None:
  5249. raise Exception("Timeout on password request")
  5250. id = ev.split(':')[0].split('-')[-1]
  5251. dev[0].request("CTRL-RSP-PASSWORD-" + id + ":password")
  5252. # TODO: Does this work correctly?
  5253. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  5254. timeout=10)
  5255. if ev is None:
  5256. raise Exception("Timeout on EAP failure")
  5257. if i in [ 4, 5, 6, 7, 14 ]:
  5258. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"],
  5259. timeout=10)
  5260. if ev is None:
  5261. raise Exception("Timeout on EAP failure")
  5262. else:
  5263. time.sleep(0.05)
  5264. dev[0].request("REMOVE_NETWORK all")
  5265. dev[0].wait_disconnected(timeout=1)
  5266. finally:
  5267. stop_radius_server(srv)
  5268. def test_eap_proto_mschapv2_errors(dev, apdev):
  5269. """EAP-MSCHAPv2 protocol tests (error paths)"""
  5270. check_eap_capa(dev[0], "MSCHAPV2")
  5271. def mschapv2_fail_password_expired(ctx):
  5272. logger.info("Test: Failure before challenge - password expired")
  5273. payload = 'E=648 R=1 C=00112233445566778899aabbccddeeff V=3 M=Password expired'
  5274. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5275. 4 + 1 + 4 + len(payload),
  5276. EAP_TYPE_MSCHAPV2,
  5277. 4, 0, 4 + len(payload)) + payload
  5278. def mschapv2_success_after_password_change(ctx, req=None):
  5279. logger.info("Test: Success after password change")
  5280. if req is None or len(req) != 591:
  5281. payload = "S=1122334455667788990011223344556677889900"
  5282. else:
  5283. data = req[9:]
  5284. enc_pw = data[0:516]
  5285. data = data[516:]
  5286. enc_hash = data[0:16]
  5287. data = data[16:]
  5288. peer_challenge = data[0:16]
  5289. data = data[16:]
  5290. # Reserved
  5291. data = data[8:]
  5292. nt_response = data[0:24]
  5293. data = data[24:]
  5294. flags = data
  5295. logger.info("enc_hash: " + enc_hash.encode("hex"))
  5296. logger.info("peer_challenge: " + peer_challenge.encode("hex"))
  5297. logger.info("nt_response: " + nt_response.encode("hex"))
  5298. logger.info("flags: " + flags.encode("hex"))
  5299. auth_challenge = binascii.unhexlify("00112233445566778899aabbccddeeff")
  5300. logger.info("auth_challenge: " + auth_challenge.encode("hex"))
  5301. auth_resp = GenerateAuthenticatorResponse("new-pw", nt_response,
  5302. peer_challenge,
  5303. auth_challenge, "user")
  5304. payload = "S=" + auth_resp.encode('hex').upper()
  5305. return struct.pack(">BBHBBBH", EAP_CODE_REQUEST, ctx['id'],
  5306. 4 + 1 + 4 + len(payload),
  5307. EAP_TYPE_MSCHAPV2,
  5308. 3, 0, 4 + len(payload)) + payload
  5309. def mschapv2_handler(ctx, req):
  5310. logger.info("mschapv2_handler - RX " + req.encode("hex"))
  5311. if 'num' not in ctx:
  5312. ctx['num'] = 0
  5313. ctx['num'] = ctx['num'] + 1
  5314. if 'id' not in ctx:
  5315. ctx['id'] = 1
  5316. ctx['id'] = (ctx['id'] + 1) % 256
  5317. idx = 0
  5318. idx += 1
  5319. if ctx['num'] == idx:
  5320. return mschapv2_fail_password_expired(ctx)
  5321. idx += 1
  5322. if ctx['num'] == idx:
  5323. return mschapv2_success_after_password_change(ctx, req)
  5324. idx += 1
  5325. if ctx['num'] == idx:
  5326. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5327. idx += 1
  5328. if ctx['num'] == idx:
  5329. return mschapv2_fail_password_expired(ctx)
  5330. idx += 1
  5331. if ctx['num'] == idx:
  5332. return mschapv2_success_after_password_change(ctx, req)
  5333. idx += 1
  5334. if ctx['num'] == idx:
  5335. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5336. idx += 1
  5337. if ctx['num'] == idx:
  5338. return mschapv2_fail_password_expired(ctx)
  5339. idx += 1
  5340. if ctx['num'] == idx:
  5341. return mschapv2_success_after_password_change(ctx, req)
  5342. idx += 1
  5343. if ctx['num'] == idx:
  5344. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5345. idx += 1
  5346. if ctx['num'] == idx:
  5347. return mschapv2_fail_password_expired(ctx)
  5348. idx += 1
  5349. if ctx['num'] == idx:
  5350. return mschapv2_success_after_password_change(ctx, req)
  5351. idx += 1
  5352. if ctx['num'] == idx:
  5353. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5354. idx += 1
  5355. if ctx['num'] == idx:
  5356. return mschapv2_fail_password_expired(ctx)
  5357. idx += 1
  5358. if ctx['num'] == idx:
  5359. return mschapv2_success_after_password_change(ctx, req)
  5360. idx += 1
  5361. if ctx['num'] == idx:
  5362. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5363. idx += 1
  5364. if ctx['num'] == idx:
  5365. return mschapv2_fail_password_expired(ctx)
  5366. idx += 1
  5367. if ctx['num'] == idx:
  5368. return mschapv2_success_after_password_change(ctx, req)
  5369. idx += 1
  5370. if ctx['num'] == idx:
  5371. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5372. idx += 1
  5373. if ctx['num'] == idx:
  5374. return mschapv2_fail_password_expired(ctx)
  5375. idx += 1
  5376. if ctx['num'] == idx:
  5377. return mschapv2_success_after_password_change(ctx, req)
  5378. idx += 1
  5379. if ctx['num'] == idx:
  5380. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5381. idx += 1
  5382. if ctx['num'] == idx:
  5383. return mschapv2_fail_password_expired(ctx)
  5384. idx += 1
  5385. if ctx['num'] == idx:
  5386. return mschapv2_success_after_password_change(ctx, req)
  5387. idx += 1
  5388. if ctx['num'] == idx:
  5389. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5390. idx += 1
  5391. if ctx['num'] == idx:
  5392. return mschapv2_fail_password_expired(ctx)
  5393. idx += 1
  5394. if ctx['num'] == idx:
  5395. return mschapv2_success_after_password_change(ctx, req)
  5396. idx += 1
  5397. if ctx['num'] == idx:
  5398. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5399. return None
  5400. srv = start_radius_server(mschapv2_handler)
  5401. try:
  5402. hapd = start_ap(apdev[0])
  5403. tests = [ "os_get_random;eap_mschapv2_change_password",
  5404. "generate_nt_response;eap_mschapv2_change_password",
  5405. "get_master_key;eap_mschapv2_change_password",
  5406. "nt_password_hash;eap_mschapv2_change_password",
  5407. "old_nt_password_hash_encrypted_with_new_nt_password_hash" ]
  5408. for func in tests:
  5409. with fail_test(dev[0], 1, func):
  5410. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5411. eap="MSCHAPV2", identity="user",
  5412. password="password", wait_connect=False)
  5413. ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"], timeout=10)
  5414. if ev is None:
  5415. raise Exception("Timeout on new password request")
  5416. id = ev.split(':')[0].split('-')[-1]
  5417. dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
  5418. time.sleep(0.1)
  5419. wait_fail_trigger(dev[0], "GET_FAIL")
  5420. dev[0].request("REMOVE_NETWORK all")
  5421. dev[0].wait_disconnected(timeout=1)
  5422. tests = [ "encrypt_pw_block_with_password_hash;eap_mschapv2_change_password",
  5423. "nt_password_hash;eap_mschapv2_change_password",
  5424. "nt_password_hash;eap_mschapv2_success" ]
  5425. for func in tests:
  5426. with fail_test(dev[0], 1, func):
  5427. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5428. eap="MSCHAPV2", identity="user",
  5429. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  5430. wait_connect=False)
  5431. ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"], timeout=10)
  5432. if ev is None:
  5433. raise Exception("Timeout on new password request")
  5434. id = ev.split(':')[0].split('-')[-1]
  5435. dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
  5436. time.sleep(0.1)
  5437. wait_fail_trigger(dev[0], "GET_FAIL")
  5438. dev[0].request("REMOVE_NETWORK all")
  5439. dev[0].wait_disconnected(timeout=1)
  5440. tests = [ "eap_msg_alloc;eap_mschapv2_change_password" ]
  5441. for func in tests:
  5442. with alloc_fail(dev[0], 1, func):
  5443. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5444. eap="MSCHAPV2", identity="user",
  5445. password="password", wait_connect=False)
  5446. ev = dev[0].wait_event(["CTRL-REQ-NEW_PASSWORD"], timeout=10)
  5447. if ev is None:
  5448. raise Exception("Timeout on new password request")
  5449. id = ev.split(':')[0].split('-')[-1]
  5450. dev[0].request("CTRL-RSP-NEW_PASSWORD-" + id + ":new-pw")
  5451. time.sleep(0.1)
  5452. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5453. dev[0].request("REMOVE_NETWORK all")
  5454. dev[0].wait_disconnected(timeout=1)
  5455. finally:
  5456. stop_radius_server(srv)
  5457. def test_eap_proto_pwd(dev, apdev):
  5458. """EAP-pwd protocol tests"""
  5459. check_eap_capa(dev[0], "PWD")
  5460. global eap_proto_pwd_test_done, eap_proto_pwd_test_wait
  5461. eap_proto_pwd_test_done = False
  5462. eap_proto_pwd_test_wait = False
  5463. def pwd_handler(ctx, req):
  5464. logger.info("pwd_handler - RX " + req.encode("hex"))
  5465. if 'num' not in ctx:
  5466. ctx['num'] = 0
  5467. ctx['num'] = ctx['num'] + 1
  5468. if 'id' not in ctx:
  5469. ctx['id'] = 1
  5470. ctx['id'] = (ctx['id'] + 1) % 256
  5471. idx = 0
  5472. global eap_proto_pwd_test_wait
  5473. eap_proto_pwd_test_wait = False
  5474. idx += 1
  5475. if ctx['num'] == idx:
  5476. logger.info("Test: Missing payload")
  5477. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'], 4 + 1,
  5478. EAP_TYPE_PWD)
  5479. idx += 1
  5480. if ctx['num'] == idx:
  5481. logger.info("Test: Missing Total-Length field")
  5482. payload = struct.pack("B", 0x80)
  5483. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5484. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5485. idx += 1
  5486. if ctx['num'] == idx:
  5487. logger.info("Test: Too large Total-Length")
  5488. payload = struct.pack(">BH", 0x80, 65535)
  5489. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5490. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5491. idx += 1
  5492. if ctx['num'] == idx:
  5493. eap_proto_pwd_test_wait = True
  5494. logger.info("Test: First fragment")
  5495. payload = struct.pack(">BH", 0xc0, 10)
  5496. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5497. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5498. idx += 1
  5499. if ctx['num'] == idx:
  5500. logger.info("Test: Unexpected Total-Length value in the second fragment")
  5501. payload = struct.pack(">BH", 0x80, 0)
  5502. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5503. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5504. idx += 1
  5505. if ctx['num'] == idx:
  5506. logger.info("Test: First and only fragment")
  5507. payload = struct.pack(">BH", 0x80, 0)
  5508. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5509. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5510. idx += 1
  5511. if ctx['num'] == idx:
  5512. logger.info("Test: First and only fragment with extra data")
  5513. payload = struct.pack(">BHB", 0x80, 0, 0)
  5514. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5515. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5516. idx += 1
  5517. if ctx['num'] == idx:
  5518. eap_proto_pwd_test_wait = True
  5519. logger.info("Test: First fragment")
  5520. payload = struct.pack(">BHB", 0xc0, 2, 1)
  5521. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5522. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5523. idx += 1
  5524. if ctx['num'] == idx:
  5525. logger.info("Test: Extra data in the second fragment")
  5526. payload = struct.pack(">BBB", 0x0, 2, 3)
  5527. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5528. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5529. idx += 1
  5530. if ctx['num'] == idx:
  5531. logger.info("Test: Too short id exchange")
  5532. payload = struct.pack(">B", 0x01)
  5533. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5534. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5535. idx += 1
  5536. if ctx['num'] == idx:
  5537. logger.info("Test: Unsupported rand func in id exchange")
  5538. payload = struct.pack(">BHBBLB", 0x01, 0, 0, 0, 0, 0)
  5539. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5540. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5541. idx += 1
  5542. if ctx['num'] == idx:
  5543. logger.info("Test: Unsupported prf in id exchange")
  5544. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 0, 0, 0)
  5545. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5546. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5547. idx += 1
  5548. if ctx['num'] == idx:
  5549. logger.info("Test: Unsupported password pre-processing technique in id exchange")
  5550. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 255)
  5551. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5552. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5553. idx += 1
  5554. if ctx['num'] == idx:
  5555. eap_proto_pwd_test_wait = True
  5556. logger.info("Test: Valid id exchange")
  5557. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
  5558. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5559. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5560. idx += 1
  5561. if ctx['num'] == idx:
  5562. logger.info("Test: Unexpected id exchange")
  5563. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
  5564. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5565. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5566. idx += 1
  5567. if ctx['num'] == idx:
  5568. logger.info("Test: Unexpected commit exchange")
  5569. payload = struct.pack(">B", 0x02)
  5570. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5571. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5572. idx += 1
  5573. if ctx['num'] == idx:
  5574. eap_proto_pwd_test_wait = True
  5575. logger.info("Test: Valid id exchange")
  5576. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
  5577. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5578. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5579. idx += 1
  5580. if ctx['num'] == idx:
  5581. logger.info("Test: Unexpected Commit payload length")
  5582. payload = struct.pack(">B", 0x02)
  5583. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5584. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5585. idx += 1
  5586. if ctx['num'] == idx:
  5587. eap_proto_pwd_test_wait = True
  5588. logger.info("Test: Valid id exchange")
  5589. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
  5590. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5591. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5592. idx += 1
  5593. if ctx['num'] == idx:
  5594. logger.info("Test: Commit payload with all zeros values --> Shared key at infinity")
  5595. payload = struct.pack(">B", 0x02) + 96*'\0'
  5596. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5597. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5598. idx += 1
  5599. if ctx['num'] == idx:
  5600. eap_proto_pwd_test_wait = True
  5601. logger.info("Test: Valid id exchange")
  5602. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
  5603. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5604. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5605. idx += 1
  5606. if ctx['num'] == idx:
  5607. eap_proto_pwd_test_wait = True
  5608. logger.info("Test: Commit payload with valid values")
  5609. element = binascii.unhexlify("8dcab2862c5396839a6bac0c689ff03d962863108e7c275bbf1d6eedf634ee832a214db99f0d0a1a6317733eecdd97f0fc4cda19f57e1bb9bb9c8dcf8c60ba6f")
  5610. scalar = binascii.unhexlify("450f31e058cf2ac2636a5d6e2b3c70b1fcc301957f0716e77f13aa69f9a2e5bd")
  5611. payload = struct.pack(">B", 0x02) + element + scalar
  5612. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5613. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5614. idx += 1
  5615. if ctx['num'] == idx:
  5616. logger.info("Test: Unexpected Confirm payload length 0")
  5617. payload = struct.pack(">B", 0x03)
  5618. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5619. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5620. idx += 1
  5621. if ctx['num'] == idx:
  5622. eap_proto_pwd_test_wait = True
  5623. logger.info("Test: Valid id exchange")
  5624. payload = struct.pack(">BHBBLB", 0x01, 19, 1, 1, 0, 0)
  5625. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5626. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5627. idx += 1
  5628. if ctx['num'] == idx:
  5629. eap_proto_pwd_test_wait = True
  5630. logger.info("Test: Commit payload with valid values")
  5631. element = binascii.unhexlify("8dcab2862c5396839a6bac0c689ff03d962863108e7c275bbf1d6eedf634ee832a214db99f0d0a1a6317733eecdd97f0fc4cda19f57e1bb9bb9c8dcf8c60ba6f")
  5632. scalar = binascii.unhexlify("450f31e058cf2ac2636a5d6e2b3c70b1fcc301957f0716e77f13aa69f9a2e5bd")
  5633. payload = struct.pack(">B", 0x02) + element + scalar
  5634. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5635. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5636. idx += 1
  5637. if ctx['num'] == idx:
  5638. logger.info("Test: Confirm payload with incorrect value")
  5639. payload = struct.pack(">B", 0x03) + 32*'\0'
  5640. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5641. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5642. idx += 1
  5643. if ctx['num'] == idx:
  5644. logger.info("Test: Unexpected confirm exchange")
  5645. payload = struct.pack(">B", 0x03)
  5646. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  5647. 4 + 1 + len(payload), EAP_TYPE_PWD) + payload
  5648. logger.info("No more test responses available - test case completed")
  5649. global eap_proto_pwd_test_done
  5650. eap_proto_pwd_test_done = True
  5651. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5652. srv = start_radius_server(pwd_handler)
  5653. try:
  5654. hapd = start_ap(apdev[0])
  5655. i = 0
  5656. while not eap_proto_pwd_test_done:
  5657. i += 1
  5658. logger.info("Running connection iteration %d" % i)
  5659. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5660. eap="PWD", identity="pwd user",
  5661. password="secret password",
  5662. wait_connect=False)
  5663. ok = False
  5664. for j in range(5):
  5665. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  5666. "CTRL-EVENT-EAP-PROPOSED-METHOD"],
  5667. timeout=5)
  5668. if ev is None:
  5669. raise Exception("Timeout on EAP start")
  5670. if "CTRL-EVENT-EAP-PROPOSED-METHOD" in ev:
  5671. ok = True
  5672. break
  5673. if "CTRL-EVENT-EAP-STATUS" in ev and "status='completion' parameter='failure'" in ev:
  5674. ok = True
  5675. break
  5676. if not ok:
  5677. raise Exception("Expected EAP event not seen")
  5678. if eap_proto_pwd_test_wait:
  5679. for k in range(10):
  5680. time.sleep(0.1)
  5681. if not eap_proto_pwd_test_wait:
  5682. break
  5683. dev[0].request("REMOVE_NETWORK all")
  5684. dev[0].wait_disconnected(timeout=1)
  5685. dev[0].dump_monitor()
  5686. finally:
  5687. stop_radius_server(srv)
  5688. def test_eap_proto_pwd_errors(dev, apdev):
  5689. """EAP-pwd local error cases"""
  5690. check_eap_capa(dev[0], "PWD")
  5691. params = hostapd.wpa2_eap_params(ssid="eap-test")
  5692. hapd = hostapd.add_ap(apdev[0], params)
  5693. for i in range(1, 4):
  5694. with alloc_fail(dev[0], i, "eap_pwd_init"):
  5695. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5696. eap="PWD", identity="pwd user",
  5697. password="secret password",
  5698. wait_connect=False)
  5699. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  5700. timeout=15)
  5701. if ev is None:
  5702. raise Exception("Timeout on EAP start")
  5703. dev[0].request("REMOVE_NETWORK all")
  5704. dev[0].wait_disconnected()
  5705. with alloc_fail(dev[0], 1, "eap_pwd_get_session_id"):
  5706. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5707. eap="PWD", identity="pwd user",
  5708. fragment_size="0",
  5709. password="secret password")
  5710. dev[0].request("REMOVE_NETWORK all")
  5711. dev[0].wait_disconnected()
  5712. funcs = [ "eap_pwd_getkey", "eap_pwd_get_emsk" ]
  5713. for func in funcs:
  5714. with alloc_fail(dev[0], 1, func):
  5715. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5716. eap="PWD", identity="pwd user@domain",
  5717. password="secret password", erp="1",
  5718. wait_connect=False)
  5719. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5720. dev[0].request("REMOVE_NETWORK all")
  5721. dev[0].wait_disconnected()
  5722. for i in range(1, 7):
  5723. with alloc_fail(dev[0], i, "eap_pwd_perform_id_exchange"):
  5724. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5725. eap="PWD", identity="pwd user",
  5726. password="secret password",
  5727. wait_connect=False)
  5728. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  5729. timeout=15)
  5730. if ev is None:
  5731. raise Exception("Timeout on EAP start")
  5732. ok = False
  5733. for j in range(10):
  5734. state = dev[0].request('GET_ALLOC_FAIL')
  5735. if state.startswith('0:'):
  5736. ok = True
  5737. break
  5738. time.sleep(0.1)
  5739. if not ok:
  5740. raise Exception("No allocation failure seen")
  5741. dev[0].request("REMOVE_NETWORK all")
  5742. dev[0].wait_disconnected()
  5743. with alloc_fail(dev[0], 1, "wpabuf_alloc;eap_pwd_perform_id_exchange"):
  5744. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5745. eap="PWD", identity="pwd user",
  5746. password="secret password",
  5747. wait_connect=False)
  5748. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  5749. timeout=15)
  5750. if ev is None:
  5751. raise Exception("Timeout on EAP start")
  5752. dev[0].request("REMOVE_NETWORK all")
  5753. dev[0].wait_disconnected()
  5754. for i in range(1, 4):
  5755. with alloc_fail(dev[0], i, "eap_pwd_perform_commit_exchange"):
  5756. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5757. eap="PWD", identity="pwd user",
  5758. password="secret password",
  5759. wait_connect=False)
  5760. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  5761. timeout=15)
  5762. if ev is None:
  5763. raise Exception("Timeout on EAP start")
  5764. ok = False
  5765. for j in range(10):
  5766. state = dev[0].request('GET_ALLOC_FAIL')
  5767. if state.startswith('0:'):
  5768. ok = True
  5769. break
  5770. time.sleep(0.1)
  5771. if not ok:
  5772. raise Exception("No allocation failure seen")
  5773. dev[0].request("REMOVE_NETWORK all")
  5774. dev[0].wait_disconnected()
  5775. for i in range(1, 12):
  5776. with alloc_fail(dev[0], i, "eap_pwd_perform_confirm_exchange"):
  5777. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5778. eap="PWD", identity="pwd user",
  5779. password="secret password",
  5780. wait_connect=False)
  5781. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  5782. timeout=15)
  5783. if ev is None:
  5784. raise Exception("Timeout on EAP start")
  5785. ok = False
  5786. for j in range(10):
  5787. state = dev[0].request('GET_ALLOC_FAIL')
  5788. if state.startswith('0:'):
  5789. ok = True
  5790. break
  5791. time.sleep(0.1)
  5792. if not ok:
  5793. raise Exception("No allocation failure seen")
  5794. dev[0].request("REMOVE_NETWORK all")
  5795. dev[0].wait_disconnected()
  5796. for i in range(1, 5):
  5797. with alloc_fail(dev[0], i, "eap_msg_alloc;=eap_pwd_process"):
  5798. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5799. eap="PWD", identity="pwd user",
  5800. password="secret password", fragment_size="50",
  5801. wait_connect=False)
  5802. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  5803. timeout=15)
  5804. if ev is None:
  5805. raise Exception("Timeout on EAP start")
  5806. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5807. dev[0].request("REMOVE_NETWORK all")
  5808. dev[0].wait_disconnected()
  5809. # No password configured
  5810. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5811. eap="PWD", identity="pwd user",
  5812. wait_connect=False)
  5813. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=52"],
  5814. timeout=15)
  5815. if ev is None:
  5816. raise Exception("EAP-pwd not started")
  5817. dev[0].request("REMOVE_NETWORK all")
  5818. dev[0].wait_disconnected()
  5819. with fail_test(dev[0], 1,
  5820. "hash_nt_password_hash;eap_pwd_perform_id_exchange"):
  5821. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5822. eap="PWD", identity="pwd-hash",
  5823. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a",
  5824. wait_connect=False)
  5825. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  5826. if ev is None:
  5827. raise Exception("No EAP-Failure reported")
  5828. dev[0].request("REMOVE_NETWORK all")
  5829. dev[0].wait_disconnected()
  5830. params = { "ssid": "eap-test2", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  5831. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  5832. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  5833. "pwd_group": "19", "fragment_size": "40" }
  5834. hostapd.add_ap(apdev[1], params)
  5835. with alloc_fail(dev[0], 1, "wpabuf_alloc;=eap_pwd_process"):
  5836. dev[0].connect("eap-test2", key_mgmt="WPA-EAP", scan_freq="2412",
  5837. eap="PWD", identity="pwd user",
  5838. password="secret password",
  5839. wait_connect=False)
  5840. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5841. dev[0].request("REMOVE_NETWORK all")
  5842. dev[0].wait_disconnected()
  5843. def test_eap_proto_erp(dev, apdev):
  5844. """ERP protocol tests"""
  5845. check_erp_capa(dev[0])
  5846. global eap_proto_erp_test_done
  5847. eap_proto_erp_test_done = False
  5848. def erp_handler(ctx, req):
  5849. logger.info("erp_handler - RX " + req.encode("hex"))
  5850. if 'num' not in ctx:
  5851. ctx['num'] = 0
  5852. ctx['num'] += 1
  5853. if 'id' not in ctx:
  5854. ctx['id'] = 1
  5855. ctx['id'] = (ctx['id'] + 1) % 256
  5856. idx = 0
  5857. idx += 1
  5858. if ctx['num'] == idx:
  5859. logger.info("Test: Missing type")
  5860. return struct.pack(">BBH", EAP_CODE_INITIATE, ctx['id'], 4)
  5861. idx += 1
  5862. if ctx['num'] == idx:
  5863. logger.info("Test: Unexpected type")
  5864. return struct.pack(">BBHB", EAP_CODE_INITIATE, ctx['id'], 4 + 1,
  5865. 255)
  5866. idx += 1
  5867. if ctx['num'] == idx:
  5868. logger.info("Test: Missing Reserved field")
  5869. return struct.pack(">BBHB", EAP_CODE_INITIATE, ctx['id'], 4 + 1,
  5870. EAP_ERP_TYPE_REAUTH_START)
  5871. idx += 1
  5872. if ctx['num'] == idx:
  5873. logger.info("Test: Zero-length TVs/TLVs")
  5874. payload = ""
  5875. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5876. 4 + 1 + 1 + len(payload),
  5877. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5878. idx += 1
  5879. if ctx['num'] == idx:
  5880. logger.info("Test: Too short TLV")
  5881. payload = struct.pack("B", 191)
  5882. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5883. 4 + 1 + 1 + len(payload),
  5884. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5885. idx += 1
  5886. if ctx['num'] == idx:
  5887. logger.info("Test: Truncated TLV")
  5888. payload = struct.pack("BB", 191, 1)
  5889. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5890. 4 + 1 + 1 + len(payload),
  5891. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5892. idx += 1
  5893. if ctx['num'] == idx:
  5894. logger.info("Test: Ignored unknown TLV and unknown TV/TLV terminating parsing")
  5895. payload = struct.pack("BBB", 191, 0, 192)
  5896. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5897. 4 + 1 + 1 + len(payload),
  5898. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5899. idx += 1
  5900. if ctx['num'] == idx:
  5901. logger.info("Test: More than one keyName-NAI")
  5902. payload = struct.pack("BBBB", EAP_ERP_TLV_KEYNAME_NAI, 0,
  5903. EAP_ERP_TLV_KEYNAME_NAI, 0)
  5904. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5905. 4 + 1 + 1 + len(payload),
  5906. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5907. idx += 1
  5908. if ctx['num'] == idx:
  5909. logger.info("Test: Too short TLV keyName-NAI")
  5910. payload = struct.pack("B", EAP_ERP_TLV_KEYNAME_NAI)
  5911. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5912. 4 + 1 + 1 + len(payload),
  5913. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5914. idx += 1
  5915. if ctx['num'] == idx:
  5916. logger.info("Test: Truncated TLV keyName-NAI")
  5917. payload = struct.pack("BB", EAP_ERP_TLV_KEYNAME_NAI, 1)
  5918. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5919. 4 + 1 + 1 + len(payload),
  5920. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5921. idx += 1
  5922. if ctx['num'] == idx:
  5923. logger.info("Test: Valid rRK lifetime TV followed by too short rMSK lifetime TV")
  5924. payload = struct.pack(">BLBH", EAP_ERP_TV_RRK_LIFETIME, 0,
  5925. EAP_ERP_TV_RMSK_LIFETIME, 0)
  5926. return struct.pack(">BBHBB", EAP_CODE_INITIATE, ctx['id'],
  5927. 4 + 1 + 1 + len(payload),
  5928. EAP_ERP_TYPE_REAUTH_START, 0) + payload
  5929. idx += 1
  5930. if ctx['num'] == idx:
  5931. logger.info("Test: Missing type (Finish)")
  5932. return struct.pack(">BBH", EAP_CODE_FINISH, ctx['id'], 4)
  5933. idx += 1
  5934. if ctx['num'] == idx:
  5935. logger.info("Test: Unexpected type (Finish)")
  5936. return struct.pack(">BBHB", EAP_CODE_FINISH, ctx['id'], 4 + 1,
  5937. 255)
  5938. idx += 1
  5939. if ctx['num'] == idx:
  5940. logger.info("Test: Missing fields (Finish)")
  5941. return struct.pack(">BBHB", EAP_CODE_FINISH, ctx['id'], 4 + 1,
  5942. EAP_ERP_TYPE_REAUTH)
  5943. idx += 1
  5944. if ctx['num'] == idx:
  5945. logger.info("Test: Unexpected SEQ (Finish)")
  5946. return struct.pack(">BBHBBHB", EAP_CODE_FINISH, ctx['id'],
  5947. 4 + 1 + 4,
  5948. EAP_ERP_TYPE_REAUTH, 0, 0xffff, 0)
  5949. logger.info("No more test responses available - test case completed")
  5950. global eap_proto_erp_test_done
  5951. eap_proto_erp_test_done = True
  5952. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  5953. srv = start_radius_server(erp_handler)
  5954. try:
  5955. hapd = start_ap(apdev[0])
  5956. i = 0
  5957. while not eap_proto_erp_test_done:
  5958. i += 1
  5959. logger.info("Running connection iteration %d" % i)
  5960. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5961. eap="PAX", identity="pax.user@example.com",
  5962. password_hex="0123456789abcdef0123456789abcdef",
  5963. wait_connect=False)
  5964. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  5965. if ev is None:
  5966. raise Exception("Timeout on EAP start")
  5967. time.sleep(0.1)
  5968. dev[0].request("REMOVE_NETWORK all")
  5969. dev[0].wait_disconnected(timeout=1)
  5970. dev[0].dump_monitor()
  5971. finally:
  5972. stop_radius_server(srv)
  5973. def test_eap_proto_fast_errors(dev, apdev):
  5974. """EAP-FAST local error cases"""
  5975. check_eap_capa(dev[0], "FAST")
  5976. params = hostapd.wpa2_eap_params(ssid="eap-test")
  5977. hapd = hostapd.add_ap(apdev[0], params)
  5978. for i in range(1, 5):
  5979. with alloc_fail(dev[0], i, "eap_fast_init"):
  5980. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  5981. eap="FAST", anonymous_identity="FAST",
  5982. identity="user", password="password",
  5983. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  5984. phase1="fast_provisioning=2",
  5985. pac_file="blob://fast_pac_auth",
  5986. wait_connect=False)
  5987. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  5988. timeout=5)
  5989. if ev is None:
  5990. raise Exception("Timeout on EAP start")
  5991. dev[0].request("REMOVE_NETWORK all")
  5992. dev[0].wait_disconnected()
  5993. tests = [ (1, "wpabuf_alloc;eap_fast_tlv_eap_payload"),
  5994. (1, "eap_fast_derive_key;eap_fast_derive_key_auth"),
  5995. (1, "eap_msg_alloc;eap_peer_tls_phase2_nak"),
  5996. (1, "wpabuf_alloc;eap_fast_tlv_result"),
  5997. (1, "wpabuf_alloc;eap_fast_tlv_pac_ack"),
  5998. (1, "=eap_peer_tls_derive_session_id;eap_fast_process_crypto_binding"),
  5999. (1, "eap_peer_tls_decrypt;eap_fast_decrypt"),
  6000. (1, "eap_fast_getKey"),
  6001. (1, "eap_fast_get_session_id"),
  6002. (1, "eap_fast_get_emsk") ]
  6003. for count, func in tests:
  6004. dev[0].request("SET blob fast_pac_auth_errors ")
  6005. with alloc_fail(dev[0], count, func):
  6006. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6007. eap="FAST", anonymous_identity="FAST",
  6008. identity="user@example.com", password="password",
  6009. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  6010. phase1="fast_provisioning=2",
  6011. pac_file="blob://fast_pac_auth_errors",
  6012. erp="1",
  6013. wait_connect=False)
  6014. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6015. timeout=15)
  6016. if ev is None:
  6017. raise Exception("Timeout on EAP start")
  6018. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  6019. dev[0].request("REMOVE_NETWORK all")
  6020. dev[0].wait_disconnected()
  6021. tests = [ (1, "eap_fast_derive_key;eap_fast_derive_key_provisioning"),
  6022. (1, "eap_mschapv2_getKey;eap_fast_get_phase2_key"),
  6023. (1, "=eap_fast_use_pac_opaque"),
  6024. (1, "eap_fast_copy_buf"),
  6025. (1, "=eap_fast_add_pac"),
  6026. (1, "=eap_fast_init_pac_data"),
  6027. (1, "=eap_fast_write_pac"),
  6028. (2, "=eap_fast_write_pac") ]
  6029. for count, func in tests:
  6030. dev[0].request("SET blob fast_pac_errors ")
  6031. with alloc_fail(dev[0], count, func):
  6032. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6033. eap="FAST", anonymous_identity="FAST",
  6034. identity="user", password="password",
  6035. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6036. phase1="fast_provisioning=1",
  6037. pac_file="blob://fast_pac_errors",
  6038. erp="1",
  6039. wait_connect=False)
  6040. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6041. timeout=15)
  6042. if ev is None:
  6043. raise Exception("Timeout on EAP start")
  6044. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  6045. dev[0].request("REMOVE_NETWORK all")
  6046. dev[0].wait_disconnected()
  6047. tests = [ (1, "eap_fast_get_cmk;eap_fast_process_crypto_binding"),
  6048. (1, "eap_fast_derive_eap_msk;eap_fast_process_crypto_binding"),
  6049. (1, "eap_fast_derive_eap_emsk;eap_fast_process_crypto_binding") ]
  6050. for count, func in tests:
  6051. dev[0].request("SET blob fast_pac_auth_errors ")
  6052. with fail_test(dev[0], count, func):
  6053. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6054. eap="FAST", anonymous_identity="FAST",
  6055. identity="user", password="password",
  6056. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  6057. phase1="fast_provisioning=2",
  6058. pac_file="blob://fast_pac_auth_errors",
  6059. erp="1",
  6060. wait_connect=False)
  6061. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6062. timeout=15)
  6063. if ev is None:
  6064. raise Exception("Timeout on EAP start")
  6065. wait_fail_trigger(dev[0], "GET_FAIL")
  6066. dev[0].request("REMOVE_NETWORK all")
  6067. dev[0].wait_disconnected()
  6068. dev[0].request("SET blob fast_pac_errors ")
  6069. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6070. eap="FAST", anonymous_identity="FAST",
  6071. identity="user", password="password",
  6072. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  6073. phase1="fast_provisioning=1",
  6074. pac_file="blob://fast_pac_errors",
  6075. wait_connect=False)
  6076. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  6077. if ev is None:
  6078. raise Exception("Timeout on EAP start")
  6079. # EAP-FAST: Only EAP-MSCHAPv2 is allowed during unauthenticated
  6080. # provisioning; reject phase2 type 6
  6081. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  6082. if ev is None:
  6083. raise Exception("Timeout on EAP failure")
  6084. dev[0].request("REMOVE_NETWORK all")
  6085. dev[0].wait_disconnected()
  6086. logger.info("Wrong password in Phase 2")
  6087. dev[0].request("SET blob fast_pac_errors ")
  6088. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6089. eap="FAST", anonymous_identity="FAST",
  6090. identity="user", password="wrong password",
  6091. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6092. phase1="fast_provisioning=1",
  6093. pac_file="blob://fast_pac_errors",
  6094. wait_connect=False)
  6095. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  6096. if ev is None:
  6097. raise Exception("Timeout on EAP start")
  6098. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  6099. if ev is None:
  6100. raise Exception("Timeout on EAP failure")
  6101. dev[0].request("REMOVE_NETWORK all")
  6102. dev[0].wait_disconnected()
  6103. tests = [ "FOOBAR\n",
  6104. "wpa_supplicant EAP-FAST PAC file - version 1\nFOOBAR\n",
  6105. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\n",
  6106. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nSTART\n",
  6107. "wpa_supplicant EAP-FAST PAC file - version 1\nEND\n",
  6108. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Type=12345\nEND\n"
  6109. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Key=12\nEND\n",
  6110. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Key=1\nEND\n",
  6111. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Key=1q\nEND\n",
  6112. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nPAC-Opaque=1\nEND\n",
  6113. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nA-ID=1\nEND\n",
  6114. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nI-ID=1\nEND\n",
  6115. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nA-ID-Info=1\nEND\n" ]
  6116. for pac in tests:
  6117. blob = binascii.hexlify(pac)
  6118. dev[0].request("SET blob fast_pac_errors " + blob)
  6119. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6120. eap="FAST", anonymous_identity="FAST",
  6121. identity="user", password="password",
  6122. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  6123. phase1="fast_provisioning=2",
  6124. pac_file="blob://fast_pac_errors",
  6125. wait_connect=False)
  6126. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  6127. timeout=5)
  6128. if ev is None:
  6129. raise Exception("Timeout on EAP start")
  6130. dev[0].request("REMOVE_NETWORK all")
  6131. dev[0].wait_disconnected()
  6132. tests = [ "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nEND\n",
  6133. "wpa_supplicant EAP-FAST PAC file - version 1\nSTART\nEND\nSTART\nEND\nSTART\nEND\n" ]
  6134. for pac in tests:
  6135. blob = binascii.hexlify(pac)
  6136. dev[0].request("SET blob fast_pac_errors " + blob)
  6137. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6138. eap="FAST", anonymous_identity="FAST",
  6139. identity="user", password="password",
  6140. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  6141. phase1="fast_provisioning=2",
  6142. pac_file="blob://fast_pac_errors")
  6143. dev[0].request("REMOVE_NETWORK all")
  6144. dev[0].wait_disconnected()
  6145. dev[0].request("SET blob fast_pac_errors ")
  6146. def test_eap_proto_peap_errors(dev, apdev):
  6147. """EAP-PEAP local error cases"""
  6148. check_eap_capa(dev[0], "PEAP")
  6149. check_eap_capa(dev[0], "MSCHAPV2")
  6150. params = hostapd.wpa2_eap_params(ssid="eap-test")
  6151. hapd = hostapd.add_ap(apdev[0], params)
  6152. for i in range(1, 5):
  6153. with alloc_fail(dev[0], i, "eap_peap_init"):
  6154. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6155. eap="PEAP", anonymous_identity="peap",
  6156. identity="user", password="password",
  6157. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6158. wait_connect=False)
  6159. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  6160. timeout=5)
  6161. if ev is None:
  6162. raise Exception("Timeout on EAP start")
  6163. dev[0].request("REMOVE_NETWORK all")
  6164. dev[0].wait_disconnected()
  6165. tests = [ (1, "eap_mschapv2_getKey;eap_peap_get_isk;eap_peap_derive_cmk"),
  6166. (1, "eap_msg_alloc;eap_tlv_build_result"),
  6167. (1, "eap_mschapv2_init;eap_peap_phase2_request"),
  6168. (1, "eap_peer_tls_decrypt;eap_peap_decrypt"),
  6169. (1, "wpabuf_alloc;=eap_peap_decrypt"),
  6170. (1, "eap_peer_tls_encrypt;eap_peap_decrypt"),
  6171. (1, "eap_peer_tls_process_helper;eap_peap_process"),
  6172. (1, "eap_peer_tls_derive_key;eap_peap_process"),
  6173. (1, "eap_peer_tls_derive_session_id;eap_peap_process"),
  6174. (1, "eap_peap_getKey"),
  6175. (1, "eap_peap_get_session_id") ]
  6176. for count, func in tests:
  6177. with alloc_fail(dev[0], count, func):
  6178. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6179. eap="PEAP", anonymous_identity="peap",
  6180. identity="user", password="password",
  6181. phase1="peapver=0 crypto_binding=2",
  6182. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6183. erp="1", wait_connect=False)
  6184. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6185. timeout=15)
  6186. if ev is None:
  6187. raise Exception("Timeout on EAP start")
  6188. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  6189. dev[0].request("REMOVE_NETWORK all")
  6190. dev[0].wait_disconnected()
  6191. tests = [ (1, "peap_prfplus;eap_peap_derive_cmk"),
  6192. (1, "eap_tlv_add_cryptobinding;eap_tlv_build_result"),
  6193. (1, "peap_prfplus;eap_peap_getKey") ]
  6194. for count, func in tests:
  6195. with fail_test(dev[0], count, func):
  6196. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6197. eap="PEAP", anonymous_identity="peap",
  6198. identity="user", password="password",
  6199. phase1="peapver=0 crypto_binding=2",
  6200. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6201. erp="1", wait_connect=False)
  6202. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6203. timeout=15)
  6204. if ev is None:
  6205. raise Exception("Timeout on EAP start")
  6206. wait_fail_trigger(dev[0], "GET_FAIL")
  6207. dev[0].request("REMOVE_NETWORK all")
  6208. dev[0].wait_disconnected()
  6209. with alloc_fail(dev[0], 1,
  6210. "eap_peer_tls_phase2_nak;eap_peap_phase2_request"):
  6211. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6212. eap="PEAP", anonymous_identity="peap",
  6213. identity="cert user", password="password",
  6214. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6215. wait_connect=False)
  6216. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  6217. dev[0].request("REMOVE_NETWORK all")
  6218. dev[0].wait_disconnected()
  6219. def test_eap_proto_ttls_errors(dev, apdev):
  6220. """EAP-TTLS local error cases"""
  6221. check_eap_capa(dev[0], "TTLS")
  6222. check_eap_capa(dev[0], "MSCHAPV2")
  6223. params = hostapd.wpa2_eap_params(ssid="eap-test")
  6224. hapd = hostapd.add_ap(apdev[0], params)
  6225. for i in range(1, 5):
  6226. with alloc_fail(dev[0], i, "eap_ttls_init"):
  6227. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6228. eap="TTLS", anonymous_identity="ttls",
  6229. identity="user", password="password",
  6230. ca_cert="auth_serv/ca.pem",
  6231. phase2="autheap=MSCHAPV2",
  6232. wait_connect=False)
  6233. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  6234. timeout=5)
  6235. if ev is None:
  6236. raise Exception("Timeout on EAP start")
  6237. dev[0].request("REMOVE_NETWORK all")
  6238. dev[0].wait_disconnected()
  6239. tests = [ (1, "eap_peer_tls_derive_key;eap_ttls_v0_derive_key",
  6240. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6241. (1, "eap_peer_tls_derive_session_id;eap_ttls_v0_derive_key",
  6242. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6243. (1, "wpabuf_alloc;eap_ttls_phase2_request_mschapv2",
  6244. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6245. (1, "eap_peer_tls_derive_key;eap_ttls_phase2_request_mschapv2",
  6246. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6247. (1, "eap_peer_tls_encrypt;eap_ttls_encrypt_response;eap_ttls_implicit_identity_request",
  6248. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6249. (1, "eap_peer_tls_decrypt;eap_ttls_decrypt",
  6250. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6251. (1, "eap_ttls_getKey",
  6252. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6253. (1, "eap_ttls_get_session_id",
  6254. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  6255. (1, "eap_ttls_get_emsk",
  6256. "mschapv2 user@domain", "auth=MSCHAPV2"),
  6257. (1, "wpabuf_alloc;eap_ttls_phase2_request_mschap",
  6258. "mschap user", "auth=MSCHAP"),
  6259. (1, "eap_peer_tls_derive_key;eap_ttls_phase2_request_mschap",
  6260. "mschap user", "auth=MSCHAP"),
  6261. (1, "wpabuf_alloc;eap_ttls_phase2_request_chap",
  6262. "chap user", "auth=CHAP"),
  6263. (1, "eap_peer_tls_derive_key;eap_ttls_phase2_request_chap",
  6264. "chap user", "auth=CHAP"),
  6265. (1, "wpabuf_alloc;eap_ttls_phase2_request_pap",
  6266. "pap user", "auth=PAP"),
  6267. (1, "wpabuf_alloc;eap_ttls_avp_encapsulate",
  6268. "user", "autheap=MSCHAPV2"),
  6269. (1, "eap_mschapv2_init;eap_ttls_phase2_request_eap_method",
  6270. "user", "autheap=MSCHAPV2"),
  6271. (1, "eap_sm_buildIdentity;eap_ttls_phase2_request_eap",
  6272. "user", "autheap=MSCHAPV2"),
  6273. (1, "eap_ttls_avp_encapsulate;eap_ttls_phase2_request_eap",
  6274. "user", "autheap=MSCHAPV2"),
  6275. (1, "eap_ttls_parse_attr_eap",
  6276. "user", "autheap=MSCHAPV2"),
  6277. (1, "eap_peer_tls_encrypt;eap_ttls_encrypt_response;eap_ttls_process_decrypted",
  6278. "user", "autheap=MSCHAPV2"),
  6279. (1, "eap_ttls_fake_identity_request",
  6280. "user", "autheap=MSCHAPV2"),
  6281. (1, "eap_msg_alloc;eap_tls_process_output",
  6282. "user", "autheap=MSCHAPV2"),
  6283. (1, "eap_msg_alloc;eap_peer_tls_build_ack",
  6284. "user", "autheap=MSCHAPV2"),
  6285. (1, "tls_connection_decrypt;eap_peer_tls_decrypt",
  6286. "user", "autheap=MSCHAPV2"),
  6287. (1, "eap_peer_tls_phase2_nak;eap_ttls_phase2_request_eap_method",
  6288. "cert user", "autheap=MSCHAPV2") ]
  6289. for count, func, identity, phase2 in tests:
  6290. with alloc_fail(dev[0], count, func):
  6291. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6292. eap="TTLS", anonymous_identity="ttls",
  6293. identity=identity, password="password",
  6294. ca_cert="auth_serv/ca.pem", phase2=phase2,
  6295. erp="1", wait_connect=False)
  6296. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6297. timeout=15)
  6298. if ev is None:
  6299. raise Exception("Timeout on EAP start")
  6300. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
  6301. note="Allocation failure not triggered for: %d:%s" % (count, func))
  6302. dev[0].request("REMOVE_NETWORK all")
  6303. dev[0].wait_disconnected()
  6304. tests = [ (1, "os_get_random;eap_ttls_phase2_request_mschapv2"),
  6305. (1, "mschapv2_derive_response;eap_ttls_phase2_request_mschapv2") ]
  6306. for count, func in tests:
  6307. with fail_test(dev[0], count, func):
  6308. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6309. eap="TTLS", anonymous_identity="ttls",
  6310. identity="DOMAIN\mschapv2 user", password="password",
  6311. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  6312. erp="1", wait_connect=False)
  6313. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6314. timeout=15)
  6315. if ev is None:
  6316. raise Exception("Timeout on EAP start")
  6317. wait_fail_trigger(dev[0], "GET_FAIL",
  6318. note="Test failure not triggered for: %d:%s" % (count, func))
  6319. dev[0].request("REMOVE_NETWORK all")
  6320. dev[0].wait_disconnected()
  6321. tests = [ (1, "nt_challenge_response;eap_ttls_phase2_request_mschap") ]
  6322. for count, func in tests:
  6323. with fail_test(dev[0], count, func):
  6324. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6325. eap="TTLS", anonymous_identity="ttls",
  6326. identity="mschap user", password="password",
  6327. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  6328. erp="1", wait_connect=False)
  6329. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6330. timeout=15)
  6331. if ev is None:
  6332. raise Exception("Timeout on EAP start")
  6333. wait_fail_trigger(dev[0], "GET_FAIL",
  6334. note="Test failure not triggered for: %d:%s" % (count, func))
  6335. dev[0].request("REMOVE_NETWORK all")
  6336. dev[0].wait_disconnected()
  6337. def test_eap_proto_expanded(dev, apdev):
  6338. """EAP protocol tests with expanded header"""
  6339. global eap_proto_expanded_test_done
  6340. eap_proto_expanded_test_done = False
  6341. def expanded_handler(ctx, req):
  6342. logger.info("expanded_handler - RX " + req.encode("hex"))
  6343. if 'num' not in ctx:
  6344. ctx['num'] = 0
  6345. ctx['num'] += 1
  6346. if 'id' not in ctx:
  6347. ctx['id'] = 1
  6348. ctx['id'] = (ctx['id'] + 1) % 256
  6349. idx = 0
  6350. idx += 1
  6351. if ctx['num'] == idx:
  6352. logger.info("Test: MD5 challenge in expanded header")
  6353. return struct.pack(">BBHB3BLBBB", EAP_CODE_REQUEST, ctx['id'],
  6354. 4 + 1 + 3 + 4 + 3,
  6355. EAP_TYPE_EXPANDED, 0, 0, 0, EAP_TYPE_MD5,
  6356. 1, 0xaa, ord('n'))
  6357. idx += 1
  6358. if ctx['num'] == idx:
  6359. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6360. idx += 1
  6361. if ctx['num'] == idx:
  6362. logger.info("Test: Invalid expanded EAP length")
  6363. return struct.pack(">BBHB3BH", EAP_CODE_REQUEST, ctx['id'],
  6364. 4 + 1 + 3 + 2,
  6365. EAP_TYPE_EXPANDED, 0, 0, 0, EAP_TYPE_MD5)
  6366. idx += 1
  6367. if ctx['num'] == idx:
  6368. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6369. idx += 1
  6370. if ctx['num'] == idx:
  6371. logger.info("Test: Invalid expanded frame type")
  6372. return struct.pack(">BBHB3BL", EAP_CODE_REQUEST, ctx['id'],
  6373. 4 + 1 + 3 + 4,
  6374. EAP_TYPE_EXPANDED, 0, 0, 1, EAP_TYPE_MD5)
  6375. idx += 1
  6376. if ctx['num'] == idx:
  6377. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6378. idx += 1
  6379. if ctx['num'] == idx:
  6380. logger.info("Test: MSCHAPv2 Challenge")
  6381. return struct.pack(">BBHBBBHB", EAP_CODE_REQUEST, ctx['id'],
  6382. 4 + 1 + 4 + 1 + 16 + 6,
  6383. EAP_TYPE_MSCHAPV2,
  6384. 1, 0, 4 + 1 + 16 + 6, 16) + 16*'A' + 'foobar'
  6385. idx += 1
  6386. if ctx['num'] == idx:
  6387. logger.info("Test: Invalid expanded frame type")
  6388. return struct.pack(">BBHB3BL", EAP_CODE_REQUEST, ctx['id'],
  6389. 4 + 1 + 3 + 4,
  6390. EAP_TYPE_EXPANDED, 0, 0, 1, EAP_TYPE_MSCHAPV2)
  6391. logger.info("No more test responses available - test case completed")
  6392. global eap_proto_expanded_test_done
  6393. eap_proto_expanded_test_done = True
  6394. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6395. srv = start_radius_server(expanded_handler)
  6396. try:
  6397. hapd = start_ap(apdev[0])
  6398. i = 0
  6399. while not eap_proto_expanded_test_done:
  6400. i += 1
  6401. logger.info("Running connection iteration %d" % i)
  6402. if i == 4:
  6403. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6404. eap="MSCHAPV2", identity="user",
  6405. password="password",
  6406. wait_connect=False)
  6407. else:
  6408. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6409. eap="MD5", identity="user", password="password",
  6410. wait_connect=False)
  6411. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  6412. if ev is None:
  6413. raise Exception("Timeout on EAP start")
  6414. if i in [ 1 ]:
  6415. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  6416. if ev is None:
  6417. raise Exception("Timeout on EAP method start")
  6418. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  6419. if ev is None:
  6420. raise Exception("Timeout on EAP failure")
  6421. elif i in [ 2, 3 ]:
  6422. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  6423. timeout=5)
  6424. if ev is None:
  6425. raise Exception("Timeout on EAP proposed method")
  6426. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  6427. if ev is None:
  6428. raise Exception("Timeout on EAP failure")
  6429. else:
  6430. time.sleep(0.1)
  6431. dev[0].request("REMOVE_NETWORK all")
  6432. dev[0].wait_disconnected(timeout=1)
  6433. dev[0].dump_monitor()
  6434. finally:
  6435. stop_radius_server(srv)
  6436. def test_eap_proto_tls(dev, apdev):
  6437. """EAP-TLS protocol tests"""
  6438. check_eap_capa(dev[0], "TLS")
  6439. global eap_proto_tls_test_done, eap_proto_tls_test_wait
  6440. eap_proto_tls_test_done = False
  6441. eap_proto_tls_test_wait = False
  6442. def tls_handler(ctx, req):
  6443. logger.info("tls_handler - RX " + req.encode("hex"))
  6444. if 'num' not in ctx:
  6445. ctx['num'] = 0
  6446. ctx['num'] += 1
  6447. if 'id' not in ctx:
  6448. ctx['id'] = 1
  6449. ctx['id'] = (ctx['id'] + 1) % 256
  6450. idx = 0
  6451. global eap_proto_tls_test_wait
  6452. idx += 1
  6453. if ctx['num'] == idx:
  6454. logger.info("Test: Too much payload in TLS/Start: TLS Message Length (0 bytes) smaller than this fragment (1 bytes)")
  6455. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  6456. 4 + 1 + 1 + 4 + 1,
  6457. EAP_TYPE_TLS, 0xa0, 0, 1)
  6458. idx += 1
  6459. if ctx['num'] == idx:
  6460. logger.info("Test: Fragmented TLS/Start")
  6461. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  6462. 4 + 1 + 1 + 4 + 1,
  6463. EAP_TYPE_TLS, 0xe0, 2, 1)
  6464. idx += 1
  6465. if ctx['num'] == idx:
  6466. logger.info("Test: Too long fragment of TLS/Start: Invalid reassembly state: tls_in_left=2 tls_in_len=0 in_len=0")
  6467. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  6468. 4 + 1 + 1 + 2,
  6469. EAP_TYPE_TLS, 0x00, 2, 3)
  6470. idx += 1
  6471. if ctx['num'] == idx:
  6472. logger.info("Test: EAP-Failure")
  6473. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6474. idx += 1
  6475. if ctx['num'] == idx:
  6476. logger.info("Test: TLS/Start")
  6477. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6478. 4 + 1 + 1,
  6479. EAP_TYPE_TLS, 0x20)
  6480. idx += 1
  6481. if ctx['num'] == idx:
  6482. logger.info("Test: Fragmented TLS message")
  6483. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  6484. 4 + 1 + 1 + 4 + 1,
  6485. EAP_TYPE_TLS, 0xc0, 2, 1)
  6486. idx += 1
  6487. if ctx['num'] == idx:
  6488. logger.info("Test: Invalid TLS message: no Flags octet included + workaround")
  6489. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  6490. 4 + 1,
  6491. EAP_TYPE_TLS)
  6492. idx += 1
  6493. if ctx['num'] == idx:
  6494. logger.info("Test: Too long fragment of TLS message: more data than TLS message length indicated")
  6495. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  6496. 4 + 1 + 1 + 2,
  6497. EAP_TYPE_TLS, 0x00, 2, 3)
  6498. idx += 1
  6499. if ctx['num'] == idx:
  6500. logger.info("Test: EAP-Failure")
  6501. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6502. idx += 1
  6503. if ctx['num'] == idx:
  6504. logger.info("Test: Fragmented TLS/Start and truncated Message Length field")
  6505. return struct.pack(">BBHBB3B", EAP_CODE_REQUEST, ctx['id'],
  6506. 4 + 1 + 1 + 3,
  6507. EAP_TYPE_TLS, 0xe0, 1, 2, 3)
  6508. idx += 1
  6509. if ctx['num'] == idx:
  6510. logger.info("Test: TLS/Start")
  6511. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6512. 4 + 1 + 1,
  6513. EAP_TYPE_TLS, 0x20)
  6514. idx += 1
  6515. if ctx['num'] == idx:
  6516. logger.info("Test: Fragmented TLS message")
  6517. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  6518. 4 + 1 + 1 + 4 + 1,
  6519. EAP_TYPE_TLS, 0xc0, 2, 1)
  6520. idx += 1
  6521. if ctx['num'] == idx:
  6522. logger.info("Test: Invalid TLS message: no Flags octet included + workaround disabled")
  6523. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  6524. 4 + 1,
  6525. EAP_TYPE_TLS)
  6526. idx += 1
  6527. if ctx['num'] == idx:
  6528. logger.info("Test: TLS/Start")
  6529. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6530. 4 + 1 + 1,
  6531. EAP_TYPE_TLS, 0x20)
  6532. idx += 1
  6533. if ctx['num'] == idx:
  6534. logger.info("Test: Fragmented TLS message (long; first)")
  6535. payload = 1450*'A'
  6536. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  6537. 4 + 1 + 1 + 4 + len(payload),
  6538. EAP_TYPE_TLS, 0xc0, 65536) + payload
  6539. # "Too long TLS fragment (size over 64 kB)" on the last one
  6540. for i in range(44):
  6541. idx += 1
  6542. if ctx['num'] == idx:
  6543. logger.info("Test: Fragmented TLS message (long; cont %d)" % i)
  6544. eap_proto_tls_test_wait = True
  6545. payload = 1470*'A'
  6546. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6547. 4 + 1 + 1 + len(payload),
  6548. EAP_TYPE_TLS, 0x40) + payload
  6549. eap_proto_tls_test_wait = False
  6550. idx += 1
  6551. if ctx['num'] == idx:
  6552. logger.info("Test: EAP-Failure")
  6553. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6554. idx += 1
  6555. if ctx['num'] == idx:
  6556. logger.info("Test: TLS/Start")
  6557. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6558. 4 + 1 + 1,
  6559. EAP_TYPE_TLS, 0x20)
  6560. idx += 1
  6561. if ctx['num'] == idx:
  6562. logger.info("Test: Non-ACK to more-fragment message")
  6563. return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
  6564. 4 + 1 + 1 + 1,
  6565. EAP_TYPE_TLS, 0x00, 255)
  6566. idx += 1
  6567. if ctx['num'] == idx:
  6568. logger.info("Test: EAP-Failure")
  6569. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6570. logger.info("No more test responses available - test case completed")
  6571. global eap_proto_tls_test_done
  6572. eap_proto_tls_test_done = True
  6573. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6574. srv = start_radius_server(tls_handler)
  6575. try:
  6576. hapd = start_ap(apdev[0])
  6577. i = 0
  6578. while not eap_proto_tls_test_done:
  6579. i += 1
  6580. logger.info("Running connection iteration %d" % i)
  6581. workaround = "0" if i == 6 else "1"
  6582. fragment_size = "100" if i == 8 else "1400"
  6583. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6584. eap="TLS", identity="tls user",
  6585. ca_cert="auth_serv/ca.pem",
  6586. client_cert="auth_serv/user.pem",
  6587. private_key="auth_serv/user.key",
  6588. eap_workaround=workaround,
  6589. fragment_size=fragment_size,
  6590. wait_connect=False)
  6591. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  6592. if ev is None:
  6593. raise Exception("Timeout on EAP start")
  6594. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  6595. "CTRL-EVENT-EAP-STATUS"], timeout=5)
  6596. if ev is None:
  6597. raise Exception("Timeout on EAP method start")
  6598. time.sleep(0.1)
  6599. start = os.times()[4]
  6600. while eap_proto_tls_test_wait:
  6601. now = os.times()[4]
  6602. if now - start > 10:
  6603. break
  6604. time.sleep(0.1)
  6605. dev[0].request("REMOVE_NETWORK all")
  6606. dev[0].wait_disconnected(timeout=1)
  6607. dev[0].dump_monitor()
  6608. finally:
  6609. stop_radius_server(srv)
  6610. def test_eap_proto_tnc(dev, apdev):
  6611. """EAP-TNC protocol tests"""
  6612. check_eap_capa(dev[0], "TNC")
  6613. global eap_proto_tnc_test_done
  6614. eap_proto_tnc_test_done = False
  6615. def tnc_handler(ctx, req):
  6616. logger.info("tnc_handler - RX " + req.encode("hex"))
  6617. if 'num' not in ctx:
  6618. ctx['num'] = 0
  6619. ctx['num'] += 1
  6620. if 'id' not in ctx:
  6621. ctx['id'] = 1
  6622. ctx['id'] = (ctx['id'] + 1) % 256
  6623. idx = 0
  6624. idx += 1
  6625. if ctx['num'] == idx:
  6626. logger.info("Test: TNC start with unsupported version")
  6627. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6628. 4 + 1 + 1,
  6629. EAP_TYPE_TNC, 0x20)
  6630. idx += 1
  6631. if ctx['num'] == idx:
  6632. logger.info("Test: TNC without Flags field")
  6633. return struct.pack(">BBHB", EAP_CODE_REQUEST, ctx['id'],
  6634. 4 + 1,
  6635. EAP_TYPE_TNC)
  6636. idx += 1
  6637. if ctx['num'] == idx:
  6638. logger.info("Test: Message underflow due to missing Message Length")
  6639. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6640. 4 + 1 + 1,
  6641. EAP_TYPE_TNC, 0xa1)
  6642. idx += 1
  6643. if ctx['num'] == idx:
  6644. logger.info("Test: Invalid Message Length")
  6645. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  6646. 4 + 1 + 1 + 4 + 1,
  6647. EAP_TYPE_TNC, 0xa1, 0, 0)
  6648. idx += 1
  6649. if ctx['num'] == idx:
  6650. logger.info("Test: Invalid Message Length")
  6651. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  6652. 4 + 1 + 1 + 4,
  6653. EAP_TYPE_TNC, 0xe1, 75001)
  6654. idx += 1
  6655. if ctx['num'] == idx:
  6656. logger.info("Test: Start with Message Length")
  6657. return struct.pack(">BBHBBL", EAP_CODE_REQUEST, ctx['id'],
  6658. 4 + 1 + 1 + 4,
  6659. EAP_TYPE_TNC, 0xa1, 1)
  6660. idx += 1
  6661. if ctx['num'] == idx:
  6662. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6663. idx += 1
  6664. if ctx['num'] == idx:
  6665. logger.info("Test: Server used start flag again")
  6666. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6667. 4 + 1 + 1,
  6668. EAP_TYPE_TNC, 0x21)
  6669. idx += 1
  6670. if ctx['num'] == idx:
  6671. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6672. 4 + 1 + 1,
  6673. EAP_TYPE_TNC, 0x21)
  6674. idx += 1
  6675. if ctx['num'] == idx:
  6676. logger.info("Test: Fragmentation and unexpected payload in ack")
  6677. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6678. 4 + 1 + 1,
  6679. EAP_TYPE_TNC, 0x21)
  6680. idx += 1
  6681. if ctx['num'] == idx:
  6682. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6683. 4 + 1 + 1,
  6684. EAP_TYPE_TNC, 0x01)
  6685. idx += 1
  6686. if ctx['num'] == idx:
  6687. return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
  6688. 4 + 1 + 1 + 1,
  6689. EAP_TYPE_TNC, 0x01, 0)
  6690. idx += 1
  6691. if ctx['num'] == idx:
  6692. logger.info("Test: Server fragmenting and fragment overflow")
  6693. return struct.pack(">BBHBBLB", EAP_CODE_REQUEST, ctx['id'],
  6694. 4 + 1 + 1 + 4 + 1,
  6695. EAP_TYPE_TNC, 0xe1, 2, 1)
  6696. idx += 1
  6697. if ctx['num'] == idx:
  6698. return struct.pack(">BBHBBBB", EAP_CODE_REQUEST, ctx['id'],
  6699. 4 + 1 + 1 + 2,
  6700. EAP_TYPE_TNC, 0x01, 2, 3)
  6701. idx += 1
  6702. if ctx['num'] == idx:
  6703. logger.info("Test: Server fragmenting and no message length in a fragment")
  6704. return struct.pack(">BBHBBB", EAP_CODE_REQUEST, ctx['id'],
  6705. 4 + 1 + 1 + 1,
  6706. EAP_TYPE_TNC, 0x61, 2)
  6707. idx += 1
  6708. if ctx['num'] == idx:
  6709. logger.info("Test: TNC start followed by invalid TNCCS-Batch")
  6710. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6711. 4 + 1 + 1,
  6712. EAP_TYPE_TNC, 0x21)
  6713. idx += 1
  6714. if ctx['num'] == idx:
  6715. logger.info("Received TNCCS-Batch: " + req[6:])
  6716. resp = "FOO"
  6717. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6718. 4 + 1 + 1 + len(resp),
  6719. EAP_TYPE_TNC, 0x01) + resp
  6720. idx += 1
  6721. if ctx['num'] == idx:
  6722. logger.info("Test: TNC start followed by invalid TNCCS-Batch (2)")
  6723. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6724. 4 + 1 + 1,
  6725. EAP_TYPE_TNC, 0x21)
  6726. idx += 1
  6727. if ctx['num'] == idx:
  6728. logger.info("Received TNCCS-Batch: " + req[6:])
  6729. resp = "</TNCCS-Batch><TNCCS-Batch>"
  6730. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6731. 4 + 1 + 1 + len(resp),
  6732. EAP_TYPE_TNC, 0x01) + resp
  6733. idx += 1
  6734. if ctx['num'] == idx:
  6735. logger.info("Test: TNCCS-Batch missing BatchId attribute")
  6736. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6737. 4 + 1 + 1,
  6738. EAP_TYPE_TNC, 0x21)
  6739. idx += 1
  6740. if ctx['num'] == idx:
  6741. logger.info("Received TNCCS-Batch: " + req[6:])
  6742. resp = "<TNCCS-Batch foo=3></TNCCS-Batch>"
  6743. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6744. 4 + 1 + 1 + len(resp),
  6745. EAP_TYPE_TNC, 0x01) + resp
  6746. idx += 1
  6747. if ctx['num'] == idx:
  6748. logger.info("Test: Unexpected IF-TNCCS BatchId")
  6749. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6750. 4 + 1 + 1,
  6751. EAP_TYPE_TNC, 0x21)
  6752. idx += 1
  6753. if ctx['num'] == idx:
  6754. logger.info("Received TNCCS-Batch: " + req[6:])
  6755. resp = "<TNCCS-Batch BatchId=123456789></TNCCS-Batch>"
  6756. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6757. 4 + 1 + 1 + len(resp),
  6758. EAP_TYPE_TNC, 0x01) + resp
  6759. idx += 1
  6760. if ctx['num'] == idx:
  6761. logger.info("Test: Missing IMC-IMV-Message and TNCC-TNCS-Message end tags")
  6762. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6763. 4 + 1 + 1,
  6764. EAP_TYPE_TNC, 0x21)
  6765. idx += 1
  6766. if ctx['num'] == idx:
  6767. logger.info("Received TNCCS-Batch: " + req[6:])
  6768. resp = "<TNCCS-Batch BatchId=2><IMC-IMV-Message><TNCC-TNCS-Message></TNCCS-Batch>"
  6769. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6770. 4 + 1 + 1 + len(resp),
  6771. EAP_TYPE_TNC, 0x01) + resp
  6772. idx += 1
  6773. if ctx['num'] == idx:
  6774. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6775. idx += 1
  6776. if ctx['num'] == idx:
  6777. logger.info("Test: Missing IMC-IMV-Message and TNCC-TNCS-Message Type")
  6778. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6779. 4 + 1 + 1,
  6780. EAP_TYPE_TNC, 0x21)
  6781. idx += 1
  6782. if ctx['num'] == idx:
  6783. logger.info("Received TNCCS-Batch: " + req[6:])
  6784. resp = "<TNCCS-Batch BatchId=2><IMC-IMV-Message></IMC-IMV-Message><TNCC-TNCS-Message></TNCC-TNCS-Message></TNCCS-Batch>"
  6785. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6786. 4 + 1 + 1 + len(resp),
  6787. EAP_TYPE_TNC, 0x01) + resp
  6788. idx += 1
  6789. if ctx['num'] == idx:
  6790. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6791. idx += 1
  6792. if ctx['num'] == idx:
  6793. logger.info("Test: Missing TNCC-TNCS-Message XML end tag")
  6794. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6795. 4 + 1 + 1,
  6796. EAP_TYPE_TNC, 0x21)
  6797. idx += 1
  6798. if ctx['num'] == idx:
  6799. logger.info("Received TNCCS-Batch: " + req[6:])
  6800. resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML></TNCC-TNCS-Message></TNCCS-Batch>"
  6801. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6802. 4 + 1 + 1 + len(resp),
  6803. EAP_TYPE_TNC, 0x01) + resp
  6804. idx += 1
  6805. if ctx['num'] == idx:
  6806. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6807. idx += 1
  6808. if ctx['num'] == idx:
  6809. logger.info("Test: Missing TNCC-TNCS-Message Base64 start tag")
  6810. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6811. 4 + 1 + 1,
  6812. EAP_TYPE_TNC, 0x21)
  6813. idx += 1
  6814. if ctx['num'] == idx:
  6815. logger.info("Received TNCCS-Batch: " + req[6:])
  6816. resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type></TNCC-TNCS-Message></TNCCS-Batch>"
  6817. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6818. 4 + 1 + 1 + len(resp),
  6819. EAP_TYPE_TNC, 0x01) + resp
  6820. idx += 1
  6821. if ctx['num'] == idx:
  6822. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6823. idx += 1
  6824. if ctx['num'] == idx:
  6825. logger.info("Test: Missing TNCC-TNCS-Message Base64 end tag")
  6826. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6827. 4 + 1 + 1,
  6828. EAP_TYPE_TNC, 0x21)
  6829. idx += 1
  6830. if ctx['num'] == idx:
  6831. logger.info("Received TNCCS-Batch: " + req[6:])
  6832. resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><Base64>abc</TNCC-TNCS-Message></TNCCS-Batch>"
  6833. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6834. 4 + 1 + 1 + len(resp),
  6835. EAP_TYPE_TNC, 0x01) + resp
  6836. idx += 1
  6837. if ctx['num'] == idx:
  6838. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6839. idx += 1
  6840. if ctx['num'] == idx:
  6841. logger.info("Test: TNCC-TNCS-Message Base64 message")
  6842. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6843. 4 + 1 + 1,
  6844. EAP_TYPE_TNC, 0x21)
  6845. idx += 1
  6846. if ctx['num'] == idx:
  6847. logger.info("Received TNCCS-Batch: " + req[6:])
  6848. resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><Base64>aGVsbG8=</Base64></TNCC-TNCS-Message></TNCCS-Batch>"
  6849. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6850. 4 + 1 + 1 + len(resp),
  6851. EAP_TYPE_TNC, 0x01) + resp
  6852. idx += 1
  6853. if ctx['num'] == idx:
  6854. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6855. idx += 1
  6856. if ctx['num'] == idx:
  6857. logger.info("Test: Invalid TNCC-TNCS-Message XML message")
  6858. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6859. 4 + 1 + 1,
  6860. EAP_TYPE_TNC, 0x21)
  6861. idx += 1
  6862. if ctx['num'] == idx:
  6863. logger.info("Received TNCCS-Batch: " + req[6:])
  6864. resp = "<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML>hello</XML></TNCC-TNCS-Message></TNCCS-Batch>"
  6865. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6866. 4 + 1 + 1 + len(resp),
  6867. EAP_TYPE_TNC, 0x01) + resp
  6868. idx += 1
  6869. if ctx['num'] == idx:
  6870. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6871. idx += 1
  6872. if ctx['num'] == idx:
  6873. logger.info("Test: Missing TNCCS-Recommendation type")
  6874. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6875. 4 + 1 + 1,
  6876. EAP_TYPE_TNC, 0x21)
  6877. idx += 1
  6878. if ctx['num'] == idx:
  6879. logger.info("Received TNCCS-Batch: " + req[6:])
  6880. resp = '<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML><TNCCS-Recommendation foo=1></TNCCS-Recommendation></XML></TNCC-TNCS-Message></TNCCS-Batch>'
  6881. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6882. 4 + 1 + 1 + len(resp),
  6883. EAP_TYPE_TNC, 0x01) + resp
  6884. idx += 1
  6885. if ctx['num'] == idx:
  6886. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6887. idx += 1
  6888. if ctx['num'] == idx:
  6889. logger.info("Test: TNCCS-Recommendation type=none")
  6890. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6891. 4 + 1 + 1,
  6892. EAP_TYPE_TNC, 0x21)
  6893. idx += 1
  6894. if ctx['num'] == idx:
  6895. logger.info("Received TNCCS-Batch: " + req[6:])
  6896. resp = '<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML><TNCCS-Recommendation type="none"></TNCCS-Recommendation></XML></TNCC-TNCS-Message></TNCCS-Batch>'
  6897. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6898. 4 + 1 + 1 + len(resp),
  6899. EAP_TYPE_TNC, 0x01) + resp
  6900. idx += 1
  6901. if ctx['num'] == idx:
  6902. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6903. idx += 1
  6904. if ctx['num'] == idx:
  6905. logger.info("Test: TNCCS-Recommendation type=isolate")
  6906. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6907. 4 + 1 + 1,
  6908. EAP_TYPE_TNC, 0x21)
  6909. idx += 1
  6910. if ctx['num'] == idx:
  6911. logger.info("Received TNCCS-Batch: " + req[6:])
  6912. resp = '<TNCCS-Batch BatchId=2><TNCC-TNCS-Message><Type>00000001</Type><XML><TNCCS-Recommendation type="isolate"></TNCCS-Recommendation></XML></TNCC-TNCS-Message></TNCCS-Batch>'
  6913. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  6914. 4 + 1 + 1 + len(resp),
  6915. EAP_TYPE_TNC, 0x01) + resp
  6916. idx += 1
  6917. if ctx['num'] == idx:
  6918. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6919. logger.info("No more test responses available - test case completed")
  6920. global eap_proto_tnc_test_done
  6921. eap_proto_tnc_test_done = True
  6922. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  6923. srv = start_radius_server(tnc_handler)
  6924. try:
  6925. hapd = start_ap(apdev[0])
  6926. i = 0
  6927. while not eap_proto_tnc_test_done:
  6928. i += 1
  6929. logger.info("Running connection iteration %d" % i)
  6930. frag = 1400
  6931. if i == 8:
  6932. frag = 150
  6933. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6934. eap="TNC", identity="tnc", fragment_size=str(frag),
  6935. wait_connect=False)
  6936. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  6937. if ev is None:
  6938. raise Exception("Timeout on EAP start")
  6939. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  6940. "CTRL-EVENT-EAP-STATUS"], timeout=5)
  6941. if ev is None:
  6942. raise Exception("Timeout on EAP method start")
  6943. time.sleep(0.1)
  6944. dev[0].request("REMOVE_NETWORK all")
  6945. dev[0].wait_disconnected(timeout=1)
  6946. dev[0].dump_monitor()
  6947. finally:
  6948. stop_radius_server(srv)
  6949. def test_eap_canned_success_after_identity(dev, apdev):
  6950. """EAP protocol tests for canned EAP-Success after identity"""
  6951. check_eap_capa(dev[0], "MD5")
  6952. def eap_canned_success_handler(ctx, req):
  6953. logger.info("eap_canned_success_handler - RX " + req.encode("hex"))
  6954. if 'num' not in ctx:
  6955. ctx['num'] = 0
  6956. ctx['num'] = ctx['num'] + 1
  6957. if 'id' not in ctx:
  6958. ctx['id'] = 1
  6959. ctx['id'] = (ctx['id'] + 1) % 256
  6960. idx = 0
  6961. idx += 1
  6962. if ctx['num'] == idx:
  6963. logger.info("Test: EAP-Success")
  6964. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  6965. idx += 1
  6966. if ctx['num'] == idx:
  6967. logger.info("Test: EAP-Success")
  6968. return struct.pack(">BBH", EAP_CODE_SUCCESS, ctx['id'], 4)
  6969. return None
  6970. srv = start_radius_server(eap_canned_success_handler)
  6971. try:
  6972. hapd = start_ap(apdev[0])
  6973. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6974. phase1="allow_canned_success=1",
  6975. eap="MD5", identity="user", password="password",
  6976. wait_connect=False)
  6977. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  6978. if ev is None:
  6979. raise Exception("Timeout on EAP success")
  6980. dev[0].request("REMOVE_NETWORK all")
  6981. dev[0].wait_disconnected()
  6982. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  6983. eap="MD5", identity="user", password="password",
  6984. wait_connect=False)
  6985. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=5)
  6986. if ev is None:
  6987. raise Exception("Timeout on EAP start")
  6988. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1)
  6989. if ev is not None:
  6990. raise Exception("Unexpected EAP success")
  6991. dev[0].request("REMOVE_NETWORK all")
  6992. dev[0].wait_disconnected()
  6993. finally:
  6994. stop_radius_server(srv)
  6995. def test_eap_proto_wsc(dev, apdev):
  6996. """EAP-WSC protocol tests"""
  6997. global eap_proto_wsc_test_done, eap_proto_wsc_wait_failure
  6998. eap_proto_wsc_test_done = False
  6999. def wsc_handler(ctx, req):
  7000. logger.info("wsc_handler - RX " + req.encode("hex"))
  7001. if 'num' not in ctx:
  7002. ctx['num'] = 0
  7003. ctx['num'] += 1
  7004. if 'id' not in ctx:
  7005. ctx['id'] = 1
  7006. ctx['id'] = (ctx['id'] + 1) % 256
  7007. idx = 0
  7008. global eap_proto_wsc_wait_failure
  7009. eap_proto_wsc_wait_failure = False
  7010. idx += 1
  7011. if ctx['num'] == idx:
  7012. logger.info("Test: Missing Flags field")
  7013. return struct.pack(">BBHB3BLB", EAP_CODE_REQUEST, ctx['id'],
  7014. 4 + 1 + 3 + 4 + 1,
  7015. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7016. 1)
  7017. idx += 1
  7018. if ctx['num'] == idx:
  7019. logger.info("Test: Message underflow (missing Message Length field)")
  7020. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7021. 4 + 1 + 3 + 4 + 2,
  7022. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7023. 1, 0x02)
  7024. idx += 1
  7025. if ctx['num'] == idx:
  7026. logger.info("Test: Invalid Message Length (> 50000)")
  7027. return struct.pack(">BBHB3BLBBH", EAP_CODE_REQUEST, ctx['id'],
  7028. 4 + 1 + 3 + 4 + 4,
  7029. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7030. 1, 0x02, 65535)
  7031. idx += 1
  7032. if ctx['num'] == idx:
  7033. logger.info("Test: Invalid Message Length (< current payload)")
  7034. return struct.pack(">BBHB3BLBBHB", EAP_CODE_REQUEST, ctx['id'],
  7035. 4 + 1 + 3 + 4 + 5,
  7036. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7037. 1, 0x02, 0, 0xff)
  7038. idx += 1
  7039. if ctx['num'] == idx:
  7040. logger.info("Test: Unexpected Op-Code 5 in WAIT_START state")
  7041. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7042. 4 + 1 + 3 + 4 + 2,
  7043. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7044. 5, 0x00)
  7045. idx += 1
  7046. if ctx['num'] == idx:
  7047. logger.info("Test: Valid WSC Start to start the sequence")
  7048. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7049. 4 + 1 + 3 + 4 + 2,
  7050. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7051. 1, 0x00)
  7052. idx += 1
  7053. if ctx['num'] == idx:
  7054. logger.info("Test: No Message Length field in a fragmented packet")
  7055. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7056. 4 + 1 + 3 + 4 + 2,
  7057. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7058. 4, 0x01)
  7059. idx += 1
  7060. if ctx['num'] == idx:
  7061. logger.info("Test: Valid WSC Start to start the sequence")
  7062. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7063. 4 + 1 + 3 + 4 + 2,
  7064. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7065. 1, 0x00)
  7066. idx += 1
  7067. if ctx['num'] == idx:
  7068. logger.info("Test: Valid first fragmented packet")
  7069. return struct.pack(">BBHB3BLBBHB", EAP_CODE_REQUEST, ctx['id'],
  7070. 4 + 1 + 3 + 4 + 5,
  7071. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7072. 4, 0x03, 10, 1)
  7073. idx += 1
  7074. if ctx['num'] == idx:
  7075. logger.info("Test: Unexpected Op-Code 5 in fragment (expected 4)")
  7076. return struct.pack(">BBHB3BLBBB", EAP_CODE_REQUEST, ctx['id'],
  7077. 4 + 1 + 3 + 4 + 3,
  7078. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7079. 5, 0x01, 2)
  7080. idx += 1
  7081. if ctx['num'] == idx:
  7082. logger.info("Test: Valid WSC Start to start the sequence")
  7083. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7084. 4 + 1 + 3 + 4 + 2,
  7085. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7086. 1, 0x00)
  7087. idx += 1
  7088. if ctx['num'] == idx:
  7089. logger.info("Test: Valid first fragmented packet")
  7090. return struct.pack(">BBHB3BLBBHB", EAP_CODE_REQUEST, ctx['id'],
  7091. 4 + 1 + 3 + 4 + 5,
  7092. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7093. 4, 0x03, 2, 1)
  7094. idx += 1
  7095. if ctx['num'] == idx:
  7096. logger.info("Test: Fragment overflow")
  7097. return struct.pack(">BBHB3BLBBBB", EAP_CODE_REQUEST, ctx['id'],
  7098. 4 + 1 + 3 + 4 + 4,
  7099. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7100. 4, 0x01, 2, 3)
  7101. idx += 1
  7102. if ctx['num'] == idx:
  7103. logger.info("Test: Valid WSC Start to start the sequence")
  7104. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7105. 4 + 1 + 3 + 4 + 2,
  7106. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7107. 1, 0x00)
  7108. idx += 1
  7109. if ctx['num'] == idx:
  7110. logger.info("Test: Unexpected Op-Code 5 in WAIT_FRAG_ACK state")
  7111. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7112. 4 + 1 + 3 + 4 + 2,
  7113. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7114. 5, 0x00)
  7115. idx += 1
  7116. if ctx['num'] == idx:
  7117. logger.info("Test: Valid WSC Start")
  7118. return struct.pack(">BBHB3BLBB", EAP_CODE_REQUEST, ctx['id'],
  7119. 4 + 1 + 3 + 4 + 2,
  7120. EAP_TYPE_EXPANDED, 0x00, 0x37, 0x2a, 1,
  7121. 1, 0x00)
  7122. idx += 1
  7123. if ctx['num'] == idx:
  7124. logger.info("No more test responses available - test case completed")
  7125. global eap_proto_wsc_test_done
  7126. eap_proto_wsc_test_done = True
  7127. eap_proto_wsc_wait_failure = True
  7128. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  7129. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  7130. srv = start_radius_server(wsc_handler)
  7131. try:
  7132. hapd = start_ap(apdev[0])
  7133. i = 0
  7134. while not eap_proto_wsc_test_done:
  7135. i += 1
  7136. logger.info("Running connection iteration %d" % i)
  7137. fragment_size = 1398 if i != 9 else 50
  7138. dev[0].connect("eap-test", key_mgmt="WPA-EAP", eap="WSC",
  7139. fragment_size=str(fragment_size),
  7140. identity="WFA-SimpleConfig-Enrollee-1-0",
  7141. phase1="pin=12345670",
  7142. scan_freq="2412", wait_connect=False)
  7143. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  7144. if ev is None:
  7145. raise Exception("Timeout on EAP method start")
  7146. if eap_proto_wsc_wait_failure:
  7147. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  7148. if ev is None:
  7149. raise Exception("Timeout on EAP failure")
  7150. else:
  7151. time.sleep(0.1)
  7152. dev[0].request("REMOVE_NETWORK all")
  7153. dev[0].wait_disconnected(timeout=1)
  7154. dev[0].dump_monitor()
  7155. finally:
  7156. stop_radius_server(srv)
  7157. def test_eap_canned_success_before_method(dev, apdev):
  7158. """EAP protocol tests for canned EAP-Success before any method"""
  7159. params = int_eap_server_params()
  7160. hapd = hostapd.add_ap(apdev[0], params)
  7161. bssid = apdev[0]['bssid']
  7162. hapd.request("SET ext_eapol_frame_io 1")
  7163. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412",
  7164. phase1="allow_canned_success=1",
  7165. eap="MD5", identity="user", password="password",
  7166. wait_connect=False)
  7167. ev = hapd.wait_event(["EAPOL-TX"], timeout=10)
  7168. if ev is None:
  7169. raise Exception("Timeout on EAPOL-TX from hostapd")
  7170. res = dev[0].request("EAPOL_RX " + bssid + " 0200000403020004")
  7171. if "OK" not in res:
  7172. raise Exception("EAPOL_RX to wpa_supplicant failed")
  7173. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=5)
  7174. if ev is None:
  7175. raise Exception("Timeout on EAP success")
  7176. dev[0].request("REMOVE_NETWORK all")
  7177. dev[0].wait_disconnected()
  7178. def test_eap_canned_failure_before_method(dev, apdev):
  7179. """EAP protocol tests for canned EAP-Failure before any method"""
  7180. params = int_eap_server_params()
  7181. hapd = hostapd.add_ap(apdev[0], params)
  7182. bssid = apdev[0]['bssid']
  7183. hapd.request("SET ext_eapol_frame_io 1")
  7184. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", scan_freq="2412",
  7185. phase1="allow_canned_success=1",
  7186. eap="MD5", identity="user", password="password",
  7187. wait_connect=False)
  7188. ev = hapd.wait_event(["EAPOL-TX"], timeout=10)
  7189. if ev is None:
  7190. raise Exception("Timeout on EAPOL-TX from hostapd")
  7191. res = dev[0].request("EAPOL_RX " + bssid + " 0200000404020004")
  7192. if "OK" not in res:
  7193. raise Exception("EAPOL_RX to wpa_supplicant failed")
  7194. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  7195. if ev is None:
  7196. raise Exception("Timeout on EAP failure")
  7197. dev[0].request("REMOVE_NETWORK all")
  7198. dev[0].wait_disconnected()
  7199. def test_eap_nak_oom(dev, apdev):
  7200. """EAP-Nak OOM"""
  7201. check_eap_capa(dev[0], "MD5")
  7202. params = hostapd.wpa2_eap_params(ssid="eap-test")
  7203. hapd = hostapd.add_ap(apdev[0], params)
  7204. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_sm_buildNak"):
  7205. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  7206. eap="MD5", identity="sake user", password="password",
  7207. wait_connect=False)
  7208. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  7209. dev[0].request("REMOVE_NETWORK all")
  7210. dev[0].wait_disconnected()
  7211. def test_eap_nak_expanded(dev, apdev):
  7212. """EAP-Nak with expanded method"""
  7213. check_eap_capa(dev[0], "MD5")
  7214. check_eap_capa(dev[0], "VENDOR-TEST")
  7215. params = hostapd.wpa2_eap_params(ssid="eap-test")
  7216. hapd = hostapd.add_ap(apdev[0], params)
  7217. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  7218. eap="VENDOR-TEST WSC",
  7219. identity="sake user", password="password",
  7220. wait_connect=False)
  7221. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"], timeout=10)
  7222. if ev is None or "NAK" not in ev:
  7223. raise Exception("No NAK event seen")
  7224. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  7225. if ev is None:
  7226. raise Exception("No EAP-Failure seen")
  7227. dev[0].request("REMOVE_NETWORK all")
  7228. dev[0].wait_disconnected()
  7229. EAP_TLV_RESULT_TLV = 3
  7230. EAP_TLV_NAK_TLV = 4
  7231. EAP_TLV_ERROR_CODE_TLV = 5
  7232. EAP_TLV_CONNECTION_BINDING_TLV = 6
  7233. EAP_TLV_VENDOR_SPECIFIC_TLV = 7
  7234. EAP_TLV_URI_TLV = 8
  7235. EAP_TLV_EAP_PAYLOAD_TLV = 9
  7236. EAP_TLV_INTERMEDIATE_RESULT_TLV = 10
  7237. EAP_TLV_PAC_TLV = 11
  7238. EAP_TLV_CRYPTO_BINDING_TLV = 12
  7239. EAP_TLV_CALLING_STATION_ID_TLV = 13
  7240. EAP_TLV_CALLED_STATION_ID_TLV = 14
  7241. EAP_TLV_NAS_PORT_TYPE_TLV = 15
  7242. EAP_TLV_SERVER_IDENTIFIER_TLV = 16
  7243. EAP_TLV_IDENTITY_TYPE_TLV = 17
  7244. EAP_TLV_SERVER_TRUSTED_ROOT_TLV = 18
  7245. EAP_TLV_REQUEST_ACTION_TLV = 19
  7246. EAP_TLV_PKCS7_TLV = 20
  7247. EAP_TLV_RESULT_SUCCESS = 1
  7248. EAP_TLV_RESULT_FAILURE = 2
  7249. EAP_TLV_TYPE_MANDATORY = 0x8000
  7250. EAP_TLV_TYPE_MASK = 0x3fff
  7251. PAC_TYPE_PAC_KEY = 1
  7252. PAC_TYPE_PAC_OPAQUE = 2
  7253. PAC_TYPE_CRED_LIFETIME = 3
  7254. PAC_TYPE_A_ID = 4
  7255. PAC_TYPE_I_ID = 5
  7256. PAC_TYPE_A_ID_INFO = 7
  7257. PAC_TYPE_PAC_ACKNOWLEDGEMENT = 8
  7258. PAC_TYPE_PAC_INFO = 9
  7259. PAC_TYPE_PAC_TYPE = 10
  7260. def eap_fast_start(ctx):
  7261. logger.info("Send EAP-FAST/Start")
  7262. return struct.pack(">BBHBBHH", EAP_CODE_REQUEST, ctx['id'],
  7263. 4 + 1 + 1 + 4 + 16,
  7264. EAP_TYPE_FAST, 0x21, 4, 16) + 16*'A'
  7265. def test_eap_fast_proto(dev, apdev):
  7266. """EAP-FAST Phase protocol testing"""
  7267. check_eap_capa(dev[0], "FAST")
  7268. global eap_fast_proto_ctx
  7269. eap_fast_proto_ctx = None
  7270. def eap_handler(ctx, req):
  7271. logger.info("eap_handler - RX " + req.encode("hex"))
  7272. if 'num' not in ctx:
  7273. ctx['num'] = 0
  7274. ctx['num'] = ctx['num'] + 1
  7275. if 'id' not in ctx:
  7276. ctx['id'] = 1
  7277. ctx['id'] = (ctx['id'] + 1) % 256
  7278. idx = 0
  7279. global eap_fast_proto_ctx
  7280. eap_fast_proto_ctx = ctx
  7281. ctx['test_done'] = False
  7282. idx += 1
  7283. if ctx['num'] == idx:
  7284. return eap_fast_start(ctx)
  7285. idx += 1
  7286. if ctx['num'] == idx:
  7287. logger.info("EAP-FAST: TLS processing failed")
  7288. data = 'ABCDEFGHIK'
  7289. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  7290. 4 + 1 + 1 + len(data),
  7291. EAP_TYPE_FAST, 0x01) + data
  7292. idx += 1
  7293. if ctx['num'] == idx:
  7294. ctx['test_done'] = True
  7295. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  7296. logger.info("Past last test case")
  7297. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  7298. srv = start_radius_server(eap_handler)
  7299. try:
  7300. hapd = start_ap(apdev[0])
  7301. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  7302. eap="FAST", anonymous_identity="FAST",
  7303. identity="user", password="password",
  7304. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  7305. phase1="fast_provisioning=1",
  7306. pac_file="blob://fast_pac_proto",
  7307. wait_connect=False)
  7308. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  7309. if ev is None:
  7310. raise Exception("Could not start EAP-FAST")
  7311. ok = False
  7312. for i in range(100):
  7313. if eap_fast_proto_ctx:
  7314. if eap_fast_proto_ctx['test_done']:
  7315. ok = True
  7316. break
  7317. time.sleep(0.05)
  7318. dev[0].request("REMOVE_NETWORK all")
  7319. dev[0].wait_disconnected()
  7320. finally:
  7321. stop_radius_server(srv)
  7322. def run_eap_fast_phase2(dev, test_payload, test_failure=True):
  7323. global eap_fast_proto_ctx
  7324. eap_fast_proto_ctx = None
  7325. def ssl_info_callback(conn, where, ret):
  7326. logger.debug("SSL: info where=%d ret=%d" % (where, ret))
  7327. def log_conn_state(conn):
  7328. try:
  7329. state = conn.state_string()
  7330. except AttributeError:
  7331. state = conn.get_state_string()
  7332. if state:
  7333. logger.info("State: " + state)
  7334. def process_clienthello(ctx, payload):
  7335. logger.info("Process ClientHello")
  7336. ctx['sslctx'] = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
  7337. ctx['sslctx'].set_info_callback(ssl_info_callback)
  7338. ctx['sslctx'].load_tmp_dh("auth_serv/dh.conf")
  7339. ctx['sslctx'].set_cipher_list("ADH-AES128-SHA")
  7340. ctx['conn'] = OpenSSL.SSL.Connection(ctx['sslctx'], None)
  7341. ctx['conn'].set_accept_state()
  7342. log_conn_state(ctx['conn'])
  7343. ctx['conn'].bio_write(payload)
  7344. try:
  7345. ctx['conn'].do_handshake()
  7346. except OpenSSL.SSL.WantReadError:
  7347. pass
  7348. log_conn_state(ctx['conn'])
  7349. data = ctx['conn'].bio_read(4096)
  7350. log_conn_state(ctx['conn'])
  7351. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  7352. 4 + 1 + 1 + len(data),
  7353. EAP_TYPE_FAST, 0x01) + data
  7354. def process_clientkeyexchange(ctx, payload, appl_data):
  7355. logger.info("Process ClientKeyExchange")
  7356. log_conn_state(ctx['conn'])
  7357. ctx['conn'].bio_write(payload)
  7358. try:
  7359. ctx['conn'].do_handshake()
  7360. except OpenSSL.SSL.WantReadError:
  7361. pass
  7362. ctx['conn'].send(appl_data)
  7363. log_conn_state(ctx['conn'])
  7364. data = ctx['conn'].bio_read(4096)
  7365. log_conn_state(ctx['conn'])
  7366. return struct.pack(">BBHBB", EAP_CODE_REQUEST, ctx['id'],
  7367. 4 + 1 + 1 + len(data),
  7368. EAP_TYPE_FAST, 0x01) + data
  7369. def eap_handler(ctx, req):
  7370. logger.info("eap_handler - RX " + req.encode("hex"))
  7371. if 'num' not in ctx:
  7372. ctx['num'] = 0
  7373. ctx['num'] = ctx['num'] + 1
  7374. if 'id' not in ctx:
  7375. ctx['id'] = 1
  7376. ctx['id'] = (ctx['id'] + 1) % 256
  7377. idx = 0
  7378. global eap_fast_proto_ctx
  7379. eap_fast_proto_ctx = ctx
  7380. ctx['test_done'] = False
  7381. logger.debug("ctx['num']=%d" % ctx['num'])
  7382. idx += 1
  7383. if ctx['num'] == idx:
  7384. return eap_fast_start(ctx)
  7385. idx += 1
  7386. if ctx['num'] == idx:
  7387. return process_clienthello(ctx, req[6:])
  7388. idx += 1
  7389. if ctx['num'] == idx:
  7390. if not test_failure:
  7391. ctx['test_done'] = True
  7392. return process_clientkeyexchange(ctx, req[6:], test_payload)
  7393. idx += 1
  7394. if ctx['num'] == idx:
  7395. ctx['test_done'] = True
  7396. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  7397. logger.info("Past last test case")
  7398. return struct.pack(">BBH", EAP_CODE_FAILURE, ctx['id'], 4)
  7399. srv = start_radius_server(eap_handler)
  7400. try:
  7401. dev[0].connect("eap-test", key_mgmt="WPA-EAP", scan_freq="2412",
  7402. eap="FAST", anonymous_identity="FAST",
  7403. identity="user", password="password",
  7404. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  7405. phase1="fast_provisioning=1",
  7406. pac_file="blob://fast_pac_proto",
  7407. wait_connect=False)
  7408. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  7409. if ev is None:
  7410. raise Exception("Could not start EAP-FAST")
  7411. dev[0].dump_monitor()
  7412. ok = False
  7413. for i in range(100):
  7414. if eap_fast_proto_ctx:
  7415. if eap_fast_proto_ctx['test_done']:
  7416. ok = True
  7417. break
  7418. time.sleep(0.05)
  7419. time.sleep(0.1)
  7420. dev[0].request("REMOVE_NETWORK all")
  7421. dev[0].wait_disconnected()
  7422. if not ok:
  7423. raise Exception("EAP-FAST TLS exchange did not complete")
  7424. for i in range(3):
  7425. dev[i].dump_monitor()
  7426. finally:
  7427. stop_radius_server(srv)
  7428. def test_eap_fast_proto_phase2(dev, apdev):
  7429. """EAP-FAST Phase 2 protocol testing"""
  7430. if not openssl_imported:
  7431. raise HwsimSkip("OpenSSL python method not available")
  7432. check_eap_capa(dev[0], "FAST")
  7433. hapd = start_ap(apdev[0])
  7434. tests = [ ("Too short Phase 2 TLV frame (len=3)",
  7435. "ABC",
  7436. False),
  7437. ("EAP-FAST: TLV overflow",
  7438. struct.pack(">HHB", 0, 2, 0xff),
  7439. False),
  7440. ("EAP-FAST: Unknown TLV (optional and mandatory)",
  7441. struct.pack(">HHB", 0, 1, 0xff) +
  7442. struct.pack(">HHB", EAP_TLV_TYPE_MANDATORY, 1, 0xff),
  7443. True),
  7444. ("EAP-FAST: More than one EAP-Payload TLV in the message",
  7445. struct.pack(">HHBHHB",
  7446. EAP_TLV_EAP_PAYLOAD_TLV, 1, 0xff,
  7447. EAP_TLV_EAP_PAYLOAD_TLV, 1, 0xff),
  7448. True),
  7449. ("EAP-FAST: Unknown Result 255 and More than one Result TLV in the message",
  7450. struct.pack(">HHHHHH",
  7451. EAP_TLV_RESULT_TLV, 2, 0xff,
  7452. EAP_TLV_RESULT_TLV, 2, 0xff),
  7453. True),
  7454. ("EAP-FAST: Too short Result TLV",
  7455. struct.pack(">HHB", EAP_TLV_RESULT_TLV, 1, 0xff),
  7456. True),
  7457. ("EAP-FAST: Unknown Intermediate Result 255 and More than one Intermediate-Result TLV in the message",
  7458. struct.pack(">HHHHHH",
  7459. EAP_TLV_INTERMEDIATE_RESULT_TLV, 2, 0xff,
  7460. EAP_TLV_INTERMEDIATE_RESULT_TLV, 2, 0xff),
  7461. True),
  7462. ("EAP-FAST: Too short Intermediate-Result TLV",
  7463. struct.pack(">HHB", EAP_TLV_INTERMEDIATE_RESULT_TLV, 1, 0xff),
  7464. True),
  7465. ("EAP-FAST: More than one Crypto-Binding TLV in the message",
  7466. struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A' +
  7467. struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A',
  7468. True),
  7469. ("EAP-FAST: Too short Crypto-Binding TLV",
  7470. struct.pack(">HHB", EAP_TLV_CRYPTO_BINDING_TLV, 1, 0xff),
  7471. True),
  7472. ("EAP-FAST: More than one Request-Action TLV in the message",
  7473. struct.pack(">HHBBHHBB",
  7474. EAP_TLV_REQUEST_ACTION_TLV, 2, 0xff, 0xff,
  7475. EAP_TLV_REQUEST_ACTION_TLV, 2, 0xff, 0xff),
  7476. True),
  7477. ("EAP-FAST: Too short Request-Action TLV",
  7478. struct.pack(">HHB", EAP_TLV_REQUEST_ACTION_TLV, 1, 0xff),
  7479. True),
  7480. ("EAP-FAST: More than one PAC TLV in the message",
  7481. struct.pack(">HHBHHB",
  7482. EAP_TLV_PAC_TLV, 1, 0xff,
  7483. EAP_TLV_PAC_TLV, 1, 0xff),
  7484. True),
  7485. ("EAP-FAST: Too short EAP Payload TLV (Len=3)",
  7486. struct.pack(">HH3B",
  7487. EAP_TLV_EAP_PAYLOAD_TLV, 3, 0, 0, 0),
  7488. False),
  7489. ("EAP-FAST: Too short Phase 2 request (Len=0)",
  7490. struct.pack(">HHBBH",
  7491. EAP_TLV_EAP_PAYLOAD_TLV, 4,
  7492. EAP_CODE_REQUEST, 0, 0),
  7493. False),
  7494. ("EAP-FAST: EAP packet overflow in EAP Payload TLV",
  7495. struct.pack(">HHBBH",
  7496. EAP_TLV_EAP_PAYLOAD_TLV, 4,
  7497. EAP_CODE_REQUEST, 0, 4 + 1),
  7498. False),
  7499. ("EAP-FAST: Unexpected code=0 in Phase 2 EAP header",
  7500. struct.pack(">HHBBH",
  7501. EAP_TLV_EAP_PAYLOAD_TLV, 4,
  7502. 0, 0, 0),
  7503. False),
  7504. ("EAP-FAST: PAC TLV without Result TLV acknowledging success",
  7505. struct.pack(">HHB", EAP_TLV_PAC_TLV, 1, 0xff),
  7506. True),
  7507. ("EAP-FAST: PAC TLV does not include all the required fields",
  7508. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7509. EAP_TLV_RESULT_SUCCESS) +
  7510. struct.pack(">HHB", EAP_TLV_PAC_TLV, 1, 0xff),
  7511. True),
  7512. ("EAP-FAST: Invalid PAC-Key length 0, Ignored unknown PAC type 0, and PAC TLV overrun (type=0 len=2 left=1)",
  7513. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7514. EAP_TLV_RESULT_SUCCESS) +
  7515. struct.pack(">HHHHHHHHB", EAP_TLV_PAC_TLV, 4 + 4 + 5,
  7516. PAC_TYPE_PAC_KEY, 0, 0, 0, 0, 2, 0),
  7517. True),
  7518. ("EAP-FAST: PAC-Info does not include all the required fields",
  7519. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7520. EAP_TLV_RESULT_SUCCESS) +
  7521. struct.pack(">HHHHHHHH", EAP_TLV_PAC_TLV, 4 + 4 + 4 + 32,
  7522. PAC_TYPE_PAC_OPAQUE, 0,
  7523. PAC_TYPE_PAC_INFO, 0,
  7524. PAC_TYPE_PAC_KEY, 32) + 32*'A',
  7525. True),
  7526. ("EAP-FAST: Invalid CRED_LIFETIME length, Ignored unknown PAC-Info type 0, and Invalid PAC-Type length 1",
  7527. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7528. EAP_TLV_RESULT_SUCCESS) +
  7529. struct.pack(">HHHHHHHHHHHHBHH", EAP_TLV_PAC_TLV, 4 + 4 + 13 + 4 + 32,
  7530. PAC_TYPE_PAC_OPAQUE, 0,
  7531. PAC_TYPE_PAC_INFO, 13, PAC_TYPE_CRED_LIFETIME, 0,
  7532. 0, 0, PAC_TYPE_PAC_TYPE, 1, 0,
  7533. PAC_TYPE_PAC_KEY, 32) + 32*'A',
  7534. True),
  7535. ("EAP-FAST: Unsupported PAC-Type 0",
  7536. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7537. EAP_TLV_RESULT_SUCCESS) +
  7538. struct.pack(">HHHHHHHHHHH", EAP_TLV_PAC_TLV, 4 + 4 + 6 + 4 + 32,
  7539. PAC_TYPE_PAC_OPAQUE, 0,
  7540. PAC_TYPE_PAC_INFO, 6, PAC_TYPE_PAC_TYPE, 2, 0,
  7541. PAC_TYPE_PAC_KEY, 32) + 32*'A',
  7542. True),
  7543. ("EAP-FAST: PAC-Info overrun (type=0 len=2 left=1)",
  7544. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7545. EAP_TLV_RESULT_SUCCESS) +
  7546. struct.pack(">HHHHHHHHBHH", EAP_TLV_PAC_TLV, 4 + 4 + 5 + 4 + 32,
  7547. PAC_TYPE_PAC_OPAQUE, 0,
  7548. PAC_TYPE_PAC_INFO, 5, 0, 2, 1,
  7549. PAC_TYPE_PAC_KEY, 32) + 32*'A',
  7550. True),
  7551. ("EAP-FAST: Valid PAC",
  7552. struct.pack(">HHH", EAP_TLV_RESULT_TLV, 2,
  7553. EAP_TLV_RESULT_SUCCESS) +
  7554. struct.pack(">HHHHHHHHBHHBHH", EAP_TLV_PAC_TLV,
  7555. 4 + 4 + 10 + 4 + 32,
  7556. PAC_TYPE_PAC_OPAQUE, 0,
  7557. PAC_TYPE_PAC_INFO, 10, PAC_TYPE_A_ID, 1, 0x41,
  7558. PAC_TYPE_A_ID_INFO, 1, 0x42,
  7559. PAC_TYPE_PAC_KEY, 32) + 32*'A',
  7560. True),
  7561. ("EAP-FAST: Invalid version/subtype in Crypto-Binding TLV",
  7562. struct.pack(">HH", EAP_TLV_CRYPTO_BINDING_TLV, 60) + 60*'A',
  7563. True) ]
  7564. for title, payload, failure in tests:
  7565. logger.info("Phase 2 test: " + title)
  7566. run_eap_fast_phase2(dev, payload, failure)
  7567. def test_eap_fast_tlv_nak_oom(dev, apdev):
  7568. """EAP-FAST Phase 2 TLV NAK OOM"""
  7569. if not openssl_imported:
  7570. raise HwsimSkip("OpenSSL python method not available")
  7571. check_eap_capa(dev[0], "FAST")
  7572. hapd = start_ap(apdev[0])
  7573. with alloc_fail(dev[0], 1, "eap_fast_tlv_nak"):
  7574. run_eap_fast_phase2(dev, struct.pack(">HHB", EAP_TLV_TYPE_MANDATORY,
  7575. 1, 0xff), False)