test_ap_eap.py 284 KB

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