test_eap_proto.py 341 KB

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