test_ap_eap.py 279 KB

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