test_eap_proto.py 327 KB

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