test_ap_eap.py 283 KB

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