test_ap_eap.py 267 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961
  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_aka(dev, apdev):
  1466. """WPA2-Enterprise connection using EAP-TTLS/EAP-AKA"""
  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", "0232010000000000",
  1470. anonymous_identity="0232010000000000@ttls",
  1471. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1472. ca_cert="auth_serv/ca.pem", phase2="autheap=AKA")
  1473. def test_ap_wpa2_eap_peap_eap_aka(dev, apdev):
  1474. """WPA2-Enterprise connection using EAP-PEAP/EAP-AKA"""
  1475. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1476. hapd = hostapd.add_ap(apdev[0], params)
  1477. eap_connect(dev[0], hapd, "PEAP", "0232010000000000",
  1478. anonymous_identity="0232010000000000@peap",
  1479. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1480. ca_cert="auth_serv/ca.pem", phase2="auth=AKA")
  1481. def test_ap_wpa2_eap_fast_eap_aka(dev, apdev):
  1482. """WPA2-Enterprise connection using EAP-FAST/EAP-AKA"""
  1483. check_eap_capa(dev[0], "FAST")
  1484. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1485. hapd = hostapd.add_ap(apdev[0], params)
  1486. eap_connect(dev[0], hapd, "FAST", "0232010000000000",
  1487. anonymous_identity="0232010000000000@fast",
  1488. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  1489. phase1="fast_provisioning=2",
  1490. pac_file="blob://fast_pac_auth_aka",
  1491. ca_cert="auth_serv/ca.pem", phase2="auth=AKA")
  1492. def test_ap_wpa2_eap_peap_eap_mschapv2(dev, apdev):
  1493. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  1494. check_eap_capa(dev[0], "MSCHAPV2")
  1495. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1496. hapd = hostapd.add_ap(apdev[0], params)
  1497. eap_connect(dev[0], hapd, "PEAP", "user",
  1498. anonymous_identity="peap", password="password",
  1499. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1500. hwsim_utils.test_connectivity(dev[0], hapd)
  1501. eap_reauth(dev[0], "PEAP")
  1502. dev[0].request("REMOVE_NETWORK all")
  1503. eap_connect(dev[0], hapd, "PEAP", "user",
  1504. anonymous_identity="peap", password="password",
  1505. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1506. fragment_size="200")
  1507. logger.info("Password as hash value")
  1508. dev[0].request("REMOVE_NETWORK all")
  1509. eap_connect(dev[0], hapd, "PEAP", "user",
  1510. anonymous_identity="peap",
  1511. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  1512. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1513. logger.info("Negative test with incorrect password")
  1514. dev[0].request("REMOVE_NETWORK all")
  1515. eap_connect(dev[0], hapd, "PEAP", "user",
  1516. anonymous_identity="peap", password="password1",
  1517. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1518. expect_failure=True)
  1519. def test_ap_wpa2_eap_peap_eap_mschapv2_domain(dev, apdev):
  1520. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 with domain"""
  1521. check_eap_capa(dev[0], "MSCHAPV2")
  1522. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1523. hapd = hostapd.add_ap(apdev[0], params)
  1524. eap_connect(dev[0], hapd, "PEAP", "DOMAIN\user3",
  1525. anonymous_identity="peap", password="password",
  1526. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  1527. hwsim_utils.test_connectivity(dev[0], hapd)
  1528. eap_reauth(dev[0], "PEAP")
  1529. def test_ap_wpa2_eap_peap_eap_mschapv2_incorrect_password(dev, apdev):
  1530. """WPA2-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2 - incorrect password"""
  1531. check_eap_capa(dev[0], "MSCHAPV2")
  1532. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1533. hapd = hostapd.add_ap(apdev[0], params)
  1534. eap_connect(dev[0], hapd, "PEAP", "user",
  1535. anonymous_identity="peap", password="wrong",
  1536. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1537. expect_failure=True)
  1538. def test_ap_wpa2_eap_peap_crypto_binding(dev, apdev):
  1539. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding"""
  1540. check_eap_capa(dev[0], "MSCHAPV2")
  1541. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1542. hapd = hostapd.add_ap(apdev[0], params)
  1543. eap_connect(dev[0], hapd, "PEAP", "user", password="password",
  1544. ca_cert="auth_serv/ca.pem",
  1545. phase1="peapver=0 crypto_binding=2",
  1546. phase2="auth=MSCHAPV2")
  1547. hwsim_utils.test_connectivity(dev[0], hapd)
  1548. eap_reauth(dev[0], "PEAP")
  1549. eap_connect(dev[1], hapd, "PEAP", "user", password="password",
  1550. ca_cert="auth_serv/ca.pem",
  1551. phase1="peapver=0 crypto_binding=1",
  1552. phase2="auth=MSCHAPV2")
  1553. eap_connect(dev[2], hapd, "PEAP", "user", password="password",
  1554. ca_cert="auth_serv/ca.pem",
  1555. phase1="peapver=0 crypto_binding=0",
  1556. phase2="auth=MSCHAPV2")
  1557. def test_ap_wpa2_eap_peap_crypto_binding_server_oom(dev, apdev):
  1558. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and crypto binding with server OOM"""
  1559. check_eap_capa(dev[0], "MSCHAPV2")
  1560. params = int_eap_server_params()
  1561. hapd = hostapd.add_ap(apdev[0], params)
  1562. with alloc_fail(hapd, 1, "eap_mschapv2_getKey"):
  1563. eap_connect(dev[0], hapd, "PEAP", "user", password="password",
  1564. ca_cert="auth_serv/ca.pem",
  1565. phase1="peapver=0 crypto_binding=2",
  1566. phase2="auth=MSCHAPV2",
  1567. expect_failure=True, local_error_report=True)
  1568. def test_ap_wpa2_eap_peap_params(dev, apdev):
  1569. """WPA2-Enterprise connection using EAP-PEAPv0/EAP-MSCHAPv2 and various parameters"""
  1570. check_eap_capa(dev[0], "MSCHAPV2")
  1571. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1572. hapd = hostapd.add_ap(apdev[0], params)
  1573. eap_connect(dev[0], hapd, "PEAP", "user",
  1574. anonymous_identity="peap", password="password",
  1575. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1576. phase1="peapver=0 peaplabel=1",
  1577. expect_failure=True)
  1578. dev[0].request("REMOVE_NETWORK all")
  1579. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1580. identity="user",
  1581. anonymous_identity="peap", password="password",
  1582. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1583. phase1="peap_outer_success=0",
  1584. wait_connect=False, scan_freq="2412")
  1585. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  1586. if ev is None:
  1587. raise Exception("No EAP success seen")
  1588. # This won't succeed to connect with peap_outer_success=0, so stop here.
  1589. dev[0].request("REMOVE_NETWORK all")
  1590. dev[0].wait_disconnected()
  1591. eap_connect(dev[1], hapd, "PEAP", "user", password="password",
  1592. ca_cert="auth_serv/ca.pem",
  1593. phase1="peap_outer_success=1",
  1594. phase2="auth=MSCHAPV2")
  1595. eap_connect(dev[2], hapd, "PEAP", "user", password="password",
  1596. ca_cert="auth_serv/ca.pem",
  1597. phase1="peap_outer_success=2",
  1598. phase2="auth=MSCHAPV2")
  1599. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1600. identity="user",
  1601. anonymous_identity="peap", password="password",
  1602. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1603. phase1="peapver=1 peaplabel=1",
  1604. wait_connect=False, scan_freq="2412")
  1605. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  1606. if ev is None:
  1607. raise Exception("No EAP success seen")
  1608. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  1609. if ev is not None:
  1610. raise Exception("Unexpected connection")
  1611. tests = [ ("peap-ver0", ""),
  1612. ("peap-ver1", ""),
  1613. ("peap-ver0", "peapver=0"),
  1614. ("peap-ver1", "peapver=1") ]
  1615. for anon,phase1 in tests:
  1616. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1617. identity="user", anonymous_identity=anon,
  1618. password="password", phase1=phase1,
  1619. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1620. scan_freq="2412")
  1621. dev[0].request("REMOVE_NETWORK all")
  1622. dev[0].wait_disconnected()
  1623. tests = [ ("peap-ver0", "peapver=1"),
  1624. ("peap-ver1", "peapver=0") ]
  1625. for anon,phase1 in tests:
  1626. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1627. identity="user", anonymous_identity=anon,
  1628. password="password", phase1=phase1,
  1629. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  1630. wait_connect=False, scan_freq="2412")
  1631. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  1632. if ev is None:
  1633. raise Exception("No EAP-Failure seen")
  1634. dev[0].request("REMOVE_NETWORK all")
  1635. dev[0].wait_disconnected()
  1636. eap_connect(dev[0], hapd, "PEAP", "user", password="password",
  1637. ca_cert="auth_serv/ca.pem",
  1638. 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",
  1639. phase2="auth=MSCHAPV2")
  1640. def test_ap_wpa2_eap_peap_eap_tls(dev, apdev):
  1641. """WPA2-Enterprise connection using EAP-PEAP/EAP-TLS"""
  1642. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1643. hapd = hostapd.add_ap(apdev[0], params)
  1644. eap_connect(dev[0], hapd, "PEAP", "cert user",
  1645. ca_cert="auth_serv/ca.pem", phase2="auth=TLS",
  1646. ca_cert2="auth_serv/ca.pem",
  1647. client_cert2="auth_serv/user.pem",
  1648. private_key2="auth_serv/user.key")
  1649. eap_reauth(dev[0], "PEAP")
  1650. def test_ap_wpa2_eap_tls(dev, apdev):
  1651. """WPA2-Enterprise connection using EAP-TLS"""
  1652. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1653. hapd = hostapd.add_ap(apdev[0], params)
  1654. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1655. client_cert="auth_serv/user.pem",
  1656. private_key="auth_serv/user.key")
  1657. eap_reauth(dev[0], "TLS")
  1658. def test_eap_tls_pkcs8_pkcs5_v2_des3(dev, apdev):
  1659. """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v2 DES3 key"""
  1660. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1661. hapd = hostapd.add_ap(apdev[0], params)
  1662. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1663. client_cert="auth_serv/user.pem",
  1664. private_key="auth_serv/user.key.pkcs8",
  1665. private_key_passwd="whatever")
  1666. def test_eap_tls_pkcs8_pkcs5_v15(dev, apdev):
  1667. """WPA2-Enterprise connection using EAP-TLS and PKCS #8, PKCS #5 v1.5 key"""
  1668. check_pkcs5_v15_support(dev[0])
  1669. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1670. hapd = hostapd.add_ap(apdev[0], params)
  1671. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1672. client_cert="auth_serv/user.pem",
  1673. private_key="auth_serv/user.key.pkcs8.pkcs5v15",
  1674. private_key_passwd="whatever")
  1675. def test_ap_wpa2_eap_tls_blob(dev, apdev):
  1676. """WPA2-Enterprise connection using EAP-TLS and config blobs"""
  1677. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1678. hapd = hostapd.add_ap(apdev[0], params)
  1679. cert = read_pem("auth_serv/ca.pem")
  1680. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1681. raise Exception("Could not set cacert blob")
  1682. cert = read_pem("auth_serv/user.pem")
  1683. if "OK" not in dev[0].request("SET blob usercert " + cert.encode("hex")):
  1684. raise Exception("Could not set usercert blob")
  1685. key = read_pem("auth_serv/user.rsa-key")
  1686. if "OK" not in dev[0].request("SET blob userkey " + key.encode("hex")):
  1687. raise Exception("Could not set cacert blob")
  1688. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert",
  1689. client_cert="blob://usercert",
  1690. private_key="blob://userkey")
  1691. def test_ap_wpa2_eap_tls_blob_missing(dev, apdev):
  1692. """EAP-TLS and config blob missing"""
  1693. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1694. hostapd.add_ap(apdev[0], params)
  1695. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1696. identity="tls user",
  1697. ca_cert="blob://testing-blob-does-not-exist",
  1698. client_cert="blob://testing-blob-does-not-exist",
  1699. private_key="blob://testing-blob-does-not-exist",
  1700. wait_connect=False, scan_freq="2412")
  1701. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=10)
  1702. if ev is None:
  1703. raise Exception("EAP failure not reported")
  1704. dev[0].request("REMOVE_NETWORK all")
  1705. dev[0].wait_disconnected()
  1706. def test_ap_wpa2_eap_tls_with_tls_len(dev, apdev):
  1707. """EAP-TLS and TLS Message Length in unfragmented packets"""
  1708. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1709. hapd = hostapd.add_ap(apdev[0], params)
  1710. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1711. phase1="include_tls_length=1",
  1712. client_cert="auth_serv/user.pem",
  1713. private_key="auth_serv/user.key")
  1714. def test_ap_wpa2_eap_tls_pkcs12(dev, apdev):
  1715. """WPA2-Enterprise connection using EAP-TLS and PKCS#12"""
  1716. check_pkcs12_support(dev[0])
  1717. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1718. hapd = hostapd.add_ap(apdev[0], params)
  1719. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1720. private_key="auth_serv/user.pkcs12",
  1721. private_key_passwd="whatever")
  1722. dev[0].request("REMOVE_NETWORK all")
  1723. dev[0].wait_disconnected()
  1724. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  1725. identity="tls user",
  1726. ca_cert="auth_serv/ca.pem",
  1727. private_key="auth_serv/user.pkcs12",
  1728. wait_connect=False, scan_freq="2412")
  1729. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"])
  1730. if ev is None:
  1731. raise Exception("Request for private key passphrase timed out")
  1732. id = ev.split(':')[0].split('-')[-1]
  1733. dev[0].request("CTRL-RSP-PASSPHRASE-" + id + ":whatever")
  1734. dev[0].wait_connected(timeout=10)
  1735. dev[0].request("REMOVE_NETWORK all")
  1736. dev[0].wait_disconnected()
  1737. # Run this twice to verify certificate chain handling with OpenSSL. Use two
  1738. # different files to cover both cases of the extra certificate being the
  1739. # one that signed the client certificate and it being unrelated to the
  1740. # client certificate.
  1741. for pkcs12 in "auth_serv/user2.pkcs12", "auth_serv/user3.pkcs12":
  1742. for i in range(2):
  1743. eap_connect(dev[0], hapd, "TLS", "tls user",
  1744. ca_cert="auth_serv/ca.pem",
  1745. private_key=pkcs12,
  1746. private_key_passwd="whatever")
  1747. dev[0].request("REMOVE_NETWORK all")
  1748. dev[0].wait_disconnected()
  1749. def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev):
  1750. """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob"""
  1751. check_pkcs12_support(dev[0])
  1752. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1753. hapd = hostapd.add_ap(apdev[0], params)
  1754. cert = read_pem("auth_serv/ca.pem")
  1755. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1756. raise Exception("Could not set cacert blob")
  1757. with open("auth_serv/user.pkcs12", "rb") as f:
  1758. if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")):
  1759. raise Exception("Could not set pkcs12 blob")
  1760. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="blob://cacert",
  1761. private_key="blob://pkcs12",
  1762. private_key_passwd="whatever")
  1763. def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev):
  1764. """WPA2-Enterprise negative test - incorrect trust root"""
  1765. check_eap_capa(dev[0], "MSCHAPV2")
  1766. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1767. hostapd.add_ap(apdev[0], params)
  1768. cert = read_pem("auth_serv/ca-incorrect.pem")
  1769. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1770. raise Exception("Could not set cacert blob")
  1771. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1772. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1773. password="password", phase2="auth=MSCHAPV2",
  1774. ca_cert="blob://cacert",
  1775. wait_connect=False, scan_freq="2412")
  1776. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1777. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1778. password="password", phase2="auth=MSCHAPV2",
  1779. ca_cert="auth_serv/ca-incorrect.pem",
  1780. wait_connect=False, scan_freq="2412")
  1781. for dev in (dev[0], dev[1]):
  1782. ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  1783. if ev is None:
  1784. raise Exception("Association and EAP start timed out")
  1785. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1786. if ev is None:
  1787. raise Exception("EAP method selection timed out")
  1788. if "TTLS" not in ev:
  1789. raise Exception("Unexpected EAP method")
  1790. ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1791. "CTRL-EVENT-EAP-SUCCESS",
  1792. "CTRL-EVENT-EAP-FAILURE",
  1793. "CTRL-EVENT-CONNECTED",
  1794. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1795. if ev is None:
  1796. raise Exception("EAP result timed out")
  1797. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1798. raise Exception("TLS certificate error not reported")
  1799. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1800. "CTRL-EVENT-EAP-FAILURE",
  1801. "CTRL-EVENT-CONNECTED",
  1802. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1803. if ev is None:
  1804. raise Exception("EAP result(2) timed out")
  1805. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1806. raise Exception("EAP failure not reported")
  1807. ev = dev.wait_event(["CTRL-EVENT-CONNECTED",
  1808. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1809. if ev is None:
  1810. raise Exception("EAP result(3) timed out")
  1811. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1812. raise Exception("Disconnection not reported")
  1813. ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1814. if ev is None:
  1815. raise Exception("Network block disabling not reported")
  1816. def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev):
  1817. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1818. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1819. hapd = hostapd.add_ap(apdev[0], params)
  1820. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1821. identity="pap user", anonymous_identity="ttls",
  1822. password="password", phase2="auth=PAP",
  1823. ca_cert="auth_serv/ca.pem",
  1824. wait_connect=True, scan_freq="2412")
  1825. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1826. identity="pap user", anonymous_identity="ttls",
  1827. password="password", phase2="auth=PAP",
  1828. ca_cert="auth_serv/ca-incorrect.pem",
  1829. only_add_network=True, scan_freq="2412")
  1830. dev[0].request("DISCONNECT")
  1831. dev[0].wait_disconnected()
  1832. dev[0].dump_monitor()
  1833. dev[0].select_network(id, freq="2412")
  1834. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1835. if ev is None:
  1836. raise Exception("EAP-TTLS not re-started")
  1837. ev = dev[0].wait_disconnected(timeout=15)
  1838. if "reason=23" not in ev:
  1839. raise Exception("Proper reason code for disconnection not reported")
  1840. def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev):
  1841. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1842. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1843. hapd = hostapd.add_ap(apdev[0], params)
  1844. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1845. identity="pap user", anonymous_identity="ttls",
  1846. password="password", phase2="auth=PAP",
  1847. wait_connect=True, scan_freq="2412")
  1848. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1849. identity="pap user", anonymous_identity="ttls",
  1850. password="password", phase2="auth=PAP",
  1851. ca_cert="auth_serv/ca-incorrect.pem",
  1852. only_add_network=True, scan_freq="2412")
  1853. dev[0].request("DISCONNECT")
  1854. dev[0].wait_disconnected()
  1855. dev[0].dump_monitor()
  1856. dev[0].select_network(id, freq="2412")
  1857. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1858. if ev is None:
  1859. raise Exception("EAP-TTLS not re-started")
  1860. ev = dev[0].wait_disconnected(timeout=15)
  1861. if "reason=23" not in ev:
  1862. raise Exception("Proper reason code for disconnection not reported")
  1863. def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev):
  1864. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1865. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1866. hapd = hostapd.add_ap(apdev[0], params)
  1867. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1868. identity="pap user", anonymous_identity="ttls",
  1869. password="password", phase2="auth=PAP",
  1870. ca_cert="auth_serv/ca.pem",
  1871. wait_connect=True, scan_freq="2412")
  1872. dev[0].request("DISCONNECT")
  1873. dev[0].wait_disconnected()
  1874. dev[0].dump_monitor()
  1875. dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem")
  1876. dev[0].select_network(id, freq="2412")
  1877. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1878. if ev is None:
  1879. raise Exception("EAP-TTLS not re-started")
  1880. ev = dev[0].wait_disconnected(timeout=15)
  1881. if "reason=23" not in ev:
  1882. raise Exception("Proper reason code for disconnection not reported")
  1883. def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev):
  1884. """WPA2-Enterprise negative test - domain suffix mismatch"""
  1885. check_domain_suffix_match(dev[0])
  1886. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1887. hostapd.add_ap(apdev[0], params)
  1888. dev[0].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.pem",
  1892. domain_suffix_match="incorrect.example.com",
  1893. wait_connect=False, scan_freq="2412")
  1894. ev = dev[0].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[0].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[0].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. if "Domain suffix mismatch" not in ev:
  1912. raise Exception("Domain suffix mismatch not reported")
  1913. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1914. "CTRL-EVENT-EAP-FAILURE",
  1915. "CTRL-EVENT-CONNECTED",
  1916. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1917. if ev is None:
  1918. raise Exception("EAP result(2) timed out")
  1919. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1920. raise Exception("EAP failure not reported")
  1921. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1922. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1923. if ev is None:
  1924. raise Exception("EAP result(3) timed out")
  1925. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1926. raise Exception("Disconnection not reported")
  1927. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1928. if ev is None:
  1929. raise Exception("Network block disabling not reported")
  1930. def test_ap_wpa2_eap_tls_neg_domain_match(dev, apdev):
  1931. """WPA2-Enterprise negative test - domain mismatch"""
  1932. check_domain_match(dev[0])
  1933. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1934. hostapd.add_ap(apdev[0], params)
  1935. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1936. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1937. password="password", phase2="auth=MSCHAPV2",
  1938. ca_cert="auth_serv/ca.pem",
  1939. domain_match="w1.fi",
  1940. wait_connect=False, scan_freq="2412")
  1941. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  1942. if ev is None:
  1943. raise Exception("Association and EAP start timed out")
  1944. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1945. if ev is None:
  1946. raise Exception("EAP method selection timed out")
  1947. if "TTLS" not in ev:
  1948. raise Exception("Unexpected EAP method")
  1949. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1950. "CTRL-EVENT-EAP-SUCCESS",
  1951. "CTRL-EVENT-EAP-FAILURE",
  1952. "CTRL-EVENT-CONNECTED",
  1953. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1954. if ev is None:
  1955. raise Exception("EAP result timed out")
  1956. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1957. raise Exception("TLS certificate error not reported")
  1958. if "Domain mismatch" not in ev:
  1959. raise Exception("Domain mismatch not reported")
  1960. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1961. "CTRL-EVENT-EAP-FAILURE",
  1962. "CTRL-EVENT-CONNECTED",
  1963. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1964. if ev is None:
  1965. raise Exception("EAP result(2) timed out")
  1966. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1967. raise Exception("EAP failure not reported")
  1968. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1969. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1970. if ev is None:
  1971. raise Exception("EAP result(3) timed out")
  1972. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1973. raise Exception("Disconnection not reported")
  1974. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1975. if ev is None:
  1976. raise Exception("Network block disabling not reported")
  1977. def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev):
  1978. """WPA2-Enterprise negative test - subject mismatch"""
  1979. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1980. hostapd.add_ap(apdev[0], params)
  1981. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1982. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1983. password="password", phase2="auth=MSCHAPV2",
  1984. ca_cert="auth_serv/ca.pem",
  1985. subject_match="/C=FI/O=w1.fi/CN=example.com",
  1986. wait_connect=False, scan_freq="2412")
  1987. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  1988. if ev is None:
  1989. raise Exception("Association and EAP start timed out")
  1990. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  1991. "EAP: Failed to initialize EAP method"], timeout=10)
  1992. if ev is None:
  1993. raise Exception("EAP method selection timed out")
  1994. if "EAP: Failed to initialize EAP method" in ev:
  1995. tls = dev[0].request("GET tls_library")
  1996. if tls.startswith("OpenSSL"):
  1997. raise Exception("Failed to select EAP method")
  1998. logger.info("subject_match not supported - connection failed, so test succeeded")
  1999. return
  2000. if "TTLS" not in ev:
  2001. raise Exception("Unexpected EAP method")
  2002. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  2003. "CTRL-EVENT-EAP-SUCCESS",
  2004. "CTRL-EVENT-EAP-FAILURE",
  2005. "CTRL-EVENT-CONNECTED",
  2006. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2007. if ev is None:
  2008. raise Exception("EAP result timed out")
  2009. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  2010. raise Exception("TLS certificate error not reported")
  2011. if "Subject mismatch" not in ev:
  2012. raise Exception("Subject mismatch not reported")
  2013. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  2014. "CTRL-EVENT-EAP-FAILURE",
  2015. "CTRL-EVENT-CONNECTED",
  2016. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2017. if ev is None:
  2018. raise Exception("EAP result(2) timed out")
  2019. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  2020. raise Exception("EAP failure not reported")
  2021. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2022. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2023. if ev is None:
  2024. raise Exception("EAP result(3) timed out")
  2025. if "CTRL-EVENT-DISCONNECTED" not in ev:
  2026. raise Exception("Disconnection not reported")
  2027. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  2028. if ev is None:
  2029. raise Exception("Network block disabling not reported")
  2030. def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev):
  2031. """WPA2-Enterprise negative test - altsubject mismatch"""
  2032. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2033. hostapd.add_ap(apdev[0], params)
  2034. tests = [ "incorrect.example.com",
  2035. "DNS:incorrect.example.com",
  2036. "DNS:w1.fi",
  2037. "DNS:erver.w1.fi" ]
  2038. for match in tests:
  2039. _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match)
  2040. def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match):
  2041. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2042. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2043. password="password", phase2="auth=MSCHAPV2",
  2044. ca_cert="auth_serv/ca.pem",
  2045. altsubject_match=match,
  2046. wait_connect=False, scan_freq="2412")
  2047. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2048. if ev is None:
  2049. raise Exception("Association and EAP start timed out")
  2050. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  2051. "EAP: Failed to initialize EAP method"], timeout=10)
  2052. if ev is None:
  2053. raise Exception("EAP method selection timed out")
  2054. if "EAP: Failed to initialize EAP method" in ev:
  2055. tls = dev[0].request("GET tls_library")
  2056. if tls.startswith("OpenSSL"):
  2057. raise Exception("Failed to select EAP method")
  2058. logger.info("altsubject_match not supported - connection failed, so test succeeded")
  2059. return
  2060. if "TTLS" not in ev:
  2061. raise Exception("Unexpected EAP method")
  2062. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  2063. "CTRL-EVENT-EAP-SUCCESS",
  2064. "CTRL-EVENT-EAP-FAILURE",
  2065. "CTRL-EVENT-CONNECTED",
  2066. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2067. if ev is None:
  2068. raise Exception("EAP result timed out")
  2069. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  2070. raise Exception("TLS certificate error not reported")
  2071. if "AltSubject mismatch" not in ev:
  2072. raise Exception("altsubject mismatch not reported")
  2073. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  2074. "CTRL-EVENT-EAP-FAILURE",
  2075. "CTRL-EVENT-CONNECTED",
  2076. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2077. if ev is None:
  2078. raise Exception("EAP result(2) timed out")
  2079. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  2080. raise Exception("EAP failure not reported")
  2081. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  2082. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  2083. if ev is None:
  2084. raise Exception("EAP result(3) timed out")
  2085. if "CTRL-EVENT-DISCONNECTED" not in ev:
  2086. raise Exception("Disconnection not reported")
  2087. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  2088. if ev is None:
  2089. raise Exception("Network block disabling not reported")
  2090. dev[0].request("REMOVE_NETWORK all")
  2091. def test_ap_wpa2_eap_unauth_tls(dev, apdev):
  2092. """WPA2-Enterprise connection using UNAUTH-TLS"""
  2093. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2094. hapd = hostapd.add_ap(apdev[0], params)
  2095. eap_connect(dev[0], hapd, "UNAUTH-TLS", "unauth-tls",
  2096. ca_cert="auth_serv/ca.pem")
  2097. eap_reauth(dev[0], "UNAUTH-TLS")
  2098. def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev):
  2099. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash"""
  2100. check_cert_probe_support(dev[0])
  2101. skip_with_fips(dev[0])
  2102. srv_cert_hash = "bdb9cb55d3df278e52a071abf58e7f0238fbec3ad8fb2c254742f63562628272"
  2103. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2104. hapd = hostapd.add_ap(apdev[0], params)
  2105. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2106. identity="probe", ca_cert="probe://",
  2107. wait_connect=False, scan_freq="2412")
  2108. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2109. if ev is None:
  2110. raise Exception("Association and EAP start timed out")
  2111. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10)
  2112. if ev is None:
  2113. raise Exception("No peer server certificate event seen")
  2114. if "hash=" + srv_cert_hash not in ev:
  2115. raise Exception("Expected server certificate hash not reported")
  2116. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  2117. if ev is None:
  2118. raise Exception("EAP result timed out")
  2119. if "Server certificate chain probe" not in ev:
  2120. raise Exception("Server certificate probe not reported")
  2121. dev[0].wait_disconnected(timeout=10)
  2122. dev[0].request("REMOVE_NETWORK all")
  2123. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2124. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2125. password="password", phase2="auth=MSCHAPV2",
  2126. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  2127. wait_connect=False, scan_freq="2412")
  2128. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2129. if ev is None:
  2130. raise Exception("Association and EAP start timed out")
  2131. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  2132. if ev is None:
  2133. raise Exception("EAP result timed out")
  2134. if "Server certificate mismatch" not in ev:
  2135. raise Exception("Server certificate mismatch not reported")
  2136. dev[0].wait_disconnected(timeout=10)
  2137. dev[0].request("REMOVE_NETWORK all")
  2138. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  2139. anonymous_identity="ttls", password="password",
  2140. ca_cert="hash://server/sha256/" + srv_cert_hash,
  2141. phase2="auth=MSCHAPV2")
  2142. def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev):
  2143. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)"""
  2144. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2145. hostapd.add_ap(apdev[0], params)
  2146. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2147. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2148. password="password", phase2="auth=MSCHAPV2",
  2149. ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  2150. wait_connect=False, scan_freq="2412")
  2151. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2152. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2153. password="password", phase2="auth=MSCHAPV2",
  2154. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca",
  2155. wait_connect=False, scan_freq="2412")
  2156. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2157. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  2158. password="password", phase2="auth=MSCHAPV2",
  2159. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q",
  2160. wait_connect=False, scan_freq="2412")
  2161. for i in range(0, 3):
  2162. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  2163. if ev is None:
  2164. raise Exception("Association and EAP start timed out")
  2165. ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5)
  2166. if ev is None:
  2167. raise Exception("Did not report EAP method initialization failure")
  2168. def test_ap_wpa2_eap_pwd(dev, apdev):
  2169. """WPA2-Enterprise connection using EAP-pwd"""
  2170. check_eap_capa(dev[0], "PWD")
  2171. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2172. hapd = hostapd.add_ap(apdev[0], params)
  2173. eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password")
  2174. eap_reauth(dev[0], "PWD")
  2175. dev[0].request("REMOVE_NETWORK all")
  2176. eap_connect(dev[1], hapd, "PWD",
  2177. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  2178. password="secret password",
  2179. fragment_size="90")
  2180. logger.info("Negative test with incorrect password")
  2181. eap_connect(dev[2], hapd, "PWD", "pwd user", password="secret-password",
  2182. expect_failure=True, local_error_report=True)
  2183. eap_connect(dev[0], hapd, "PWD",
  2184. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  2185. password="secret password",
  2186. fragment_size="31")
  2187. def test_ap_wpa2_eap_pwd_nthash(dev, apdev):
  2188. """WPA2-Enterprise connection using EAP-pwd and NTHash"""
  2189. check_eap_capa(dev[0], "PWD")
  2190. skip_with_fips(dev[0])
  2191. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2192. hapd = hostapd.add_ap(apdev[0], params)
  2193. eap_connect(dev[0], hapd, "PWD", "pwd-hash", password="secret password")
  2194. eap_connect(dev[1], hapd, "PWD", "pwd-hash",
  2195. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a")
  2196. eap_connect(dev[2], hapd, "PWD", "pwd user",
  2197. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a",
  2198. expect_failure=True, local_error_report=True)
  2199. def test_ap_wpa2_eap_pwd_groups(dev, apdev):
  2200. """WPA2-Enterprise connection using various EAP-pwd groups"""
  2201. check_eap_capa(dev[0], "PWD")
  2202. tls = dev[0].request("GET tls_library")
  2203. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2204. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2205. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  2206. groups = [ 19, 20, 21, 25, 26 ]
  2207. if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  2208. logger.info("Add Brainpool EC groups since OpenSSL is new enough")
  2209. groups += [ 27, 28, 29, 30 ]
  2210. for i in groups:
  2211. logger.info("Group %d" % i)
  2212. params['pwd_group'] = str(i)
  2213. hapd = hostapd.add_ap(apdev[0], params)
  2214. try:
  2215. eap_connect(dev[0], hapd, "PWD", "pwd user",
  2216. password="secret password")
  2217. dev[0].request("REMOVE_NETWORK all")
  2218. dev[0].wait_disconnected()
  2219. dev[0].dump_monitor()
  2220. except:
  2221. if "BoringSSL" in tls and i in [ 25 ]:
  2222. logger.info("Ignore connection failure with group %d with BoringSSL" % i)
  2223. dev[0].request("DISCONNECT")
  2224. time.sleep(0.1)
  2225. dev[0].request("REMOVE_NETWORK all")
  2226. dev[0].dump_monitor()
  2227. continue
  2228. raise
  2229. def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev):
  2230. """WPA2-Enterprise connection using invalid EAP-pwd group"""
  2231. check_eap_capa(dev[0], "PWD")
  2232. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2233. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2234. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  2235. params['pwd_group'] = "0"
  2236. hostapd.add_ap(apdev[0], params)
  2237. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
  2238. identity="pwd user", password="secret password",
  2239. scan_freq="2412", wait_connect=False)
  2240. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2241. if ev is None:
  2242. raise Exception("Timeout on EAP failure report")
  2243. def test_ap_wpa2_eap_pwd_as_frag(dev, apdev):
  2244. """WPA2-Enterprise connection using EAP-pwd with server fragmentation"""
  2245. check_eap_capa(dev[0], "PWD")
  2246. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2247. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2248. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2249. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  2250. "pwd_group": "19", "fragment_size": "40" }
  2251. hapd = hostapd.add_ap(apdev[0], params)
  2252. eap_connect(dev[0], hapd, "PWD", "pwd user", password="secret password")
  2253. def test_ap_wpa2_eap_gpsk(dev, apdev):
  2254. """WPA2-Enterprise connection using EAP-GPSK"""
  2255. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2256. hapd = hostapd.add_ap(apdev[0], params)
  2257. id = eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  2258. password="abcdefghijklmnop0123456789abcdef")
  2259. eap_reauth(dev[0], "GPSK")
  2260. logger.info("Test forced algorithm selection")
  2261. for phase1 in [ "cipher=1", "cipher=2" ]:
  2262. dev[0].set_network_quoted(id, "phase1", phase1)
  2263. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  2264. if ev is None:
  2265. raise Exception("EAP success timed out")
  2266. dev[0].wait_connected(timeout=10)
  2267. logger.info("Test failed algorithm negotiation")
  2268. dev[0].set_network_quoted(id, "phase1", "cipher=9")
  2269. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2270. if ev is None:
  2271. raise Exception("EAP failure timed out")
  2272. logger.info("Negative test with incorrect password")
  2273. dev[0].request("REMOVE_NETWORK all")
  2274. eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  2275. password="ffcdefghijklmnop0123456789abcdef",
  2276. expect_failure=True)
  2277. def test_ap_wpa2_eap_sake(dev, apdev):
  2278. """WPA2-Enterprise connection using EAP-SAKE"""
  2279. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2280. hapd = hostapd.add_ap(apdev[0], params)
  2281. eap_connect(dev[0], hapd, "SAKE", "sake user",
  2282. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  2283. eap_reauth(dev[0], "SAKE")
  2284. logger.info("Negative test with incorrect password")
  2285. dev[0].request("REMOVE_NETWORK all")
  2286. eap_connect(dev[0], hapd, "SAKE", "sake user",
  2287. password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  2288. expect_failure=True)
  2289. def test_ap_wpa2_eap_eke(dev, apdev):
  2290. """WPA2-Enterprise connection using EAP-EKE"""
  2291. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2292. hapd = hostapd.add_ap(apdev[0], params)
  2293. id = eap_connect(dev[0], hapd, "EKE", "eke user", password="hello")
  2294. eap_reauth(dev[0], "EKE")
  2295. logger.info("Test forced algorithm selection")
  2296. for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2",
  2297. "dhgroup=4 encr=1 prf=2 mac=2",
  2298. "dhgroup=3 encr=1 prf=2 mac=2",
  2299. "dhgroup=3 encr=1 prf=1 mac=1" ]:
  2300. dev[0].set_network_quoted(id, "phase1", phase1)
  2301. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  2302. if ev is None:
  2303. raise Exception("EAP success timed out")
  2304. dev[0].wait_connected(timeout=10)
  2305. logger.info("Test failed algorithm negotiation")
  2306. dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9")
  2307. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2308. if ev is None:
  2309. raise Exception("EAP failure timed out")
  2310. logger.info("Negative test with incorrect password")
  2311. dev[0].request("REMOVE_NETWORK all")
  2312. eap_connect(dev[0], hapd, "EKE", "eke user", password="hello1",
  2313. expect_failure=True)
  2314. def test_ap_wpa2_eap_eke_many(dev, apdev, params):
  2315. """WPA2-Enterprise connection using EAP-EKE (many connections) [long]"""
  2316. if not params['long']:
  2317. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  2318. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2319. hostapd.add_ap(apdev[0], params)
  2320. success = 0
  2321. fail = 0
  2322. for i in range(100):
  2323. for j in range(3):
  2324. dev[j].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="EKE",
  2325. identity="eke user", password="hello",
  2326. phase1="dhgroup=3 encr=1 prf=1 mac=1",
  2327. scan_freq="2412", wait_connect=False)
  2328. for j in range(3):
  2329. ev = dev[j].wait_event(["CTRL-EVENT-CONNECTED",
  2330. "CTRL-EVENT-DISCONNECTED"], timeout=15)
  2331. if ev is None:
  2332. raise Exception("No connected/disconnected event")
  2333. if "CTRL-EVENT-DISCONNECTED" in ev:
  2334. fail += 1
  2335. # The RADIUS server limits on active sessions can be hit when
  2336. # going through this test case, so try to give some more time
  2337. # for the server to remove sessions.
  2338. logger.info("Failed to connect i=%d j=%d" % (i, j))
  2339. dev[j].request("REMOVE_NETWORK all")
  2340. time.sleep(1)
  2341. else:
  2342. success += 1
  2343. dev[j].request("REMOVE_NETWORK all")
  2344. dev[j].wait_disconnected()
  2345. dev[j].dump_monitor()
  2346. logger.info("Total success=%d failure=%d" % (success, fail))
  2347. def test_ap_wpa2_eap_eke_serverid_nai(dev, apdev):
  2348. """WPA2-Enterprise connection using EAP-EKE with serverid NAI"""
  2349. params = int_eap_server_params()
  2350. params['server_id'] = 'example.server@w1.fi'
  2351. hapd = hostapd.add_ap(apdev[0], params)
  2352. eap_connect(dev[0], hapd, "EKE", "eke user", password="hello")
  2353. def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
  2354. """WPA2-Enterprise connection using EAP-EKE with server OOM"""
  2355. params = int_eap_server_params()
  2356. hapd = hostapd.add_ap(apdev[0], params)
  2357. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  2358. for count,func in [ (1, "eap_eke_build_commit"),
  2359. (2, "eap_eke_build_commit"),
  2360. (3, "eap_eke_build_commit"),
  2361. (1, "eap_eke_build_confirm"),
  2362. (2, "eap_eke_build_confirm"),
  2363. (1, "eap_eke_process_commit"),
  2364. (2, "eap_eke_process_commit"),
  2365. (1, "eap_eke_process_confirm"),
  2366. (1, "eap_eke_process_identity"),
  2367. (2, "eap_eke_process_identity"),
  2368. (3, "eap_eke_process_identity"),
  2369. (4, "eap_eke_process_identity") ]:
  2370. with alloc_fail(hapd, count, func):
  2371. eap_connect(dev[0], hapd, "EKE", "eke user", password="hello",
  2372. expect_failure=True)
  2373. dev[0].request("REMOVE_NETWORK all")
  2374. for count,func,pw in [ (1, "eap_eke_init", "hello"),
  2375. (1, "eap_eke_get_session_id", "hello"),
  2376. (1, "eap_eke_getKey", "hello"),
  2377. (1, "eap_eke_build_msg", "hello"),
  2378. (1, "eap_eke_build_failure", "wrong"),
  2379. (1, "eap_eke_build_identity", "hello"),
  2380. (2, "eap_eke_build_identity", "hello") ]:
  2381. with alloc_fail(hapd, count, func):
  2382. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2383. eap="EKE", identity="eke user", password=pw,
  2384. wait_connect=False, scan_freq="2412")
  2385. # This would eventually time out, but we can stop after having
  2386. # reached the allocation failure.
  2387. for i in range(20):
  2388. time.sleep(0.1)
  2389. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  2390. break
  2391. dev[0].request("REMOVE_NETWORK all")
  2392. for count in range(1, 1000):
  2393. try:
  2394. with alloc_fail(hapd, count, "eap_server_sm_step"):
  2395. dev[0].connect("test-wpa2-eap",
  2396. key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2397. eap="EKE", identity="eke user", password=pw,
  2398. wait_connect=False, scan_freq="2412")
  2399. # This would eventually time out, but we can stop after having
  2400. # reached the allocation failure.
  2401. for i in range(10):
  2402. time.sleep(0.1)
  2403. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  2404. break
  2405. dev[0].request("REMOVE_NETWORK all")
  2406. except Exception, e:
  2407. if str(e) == "Allocation failure did not trigger":
  2408. if count < 30:
  2409. raise Exception("Too few allocation failures")
  2410. logger.info("%d allocation failures tested" % (count - 1))
  2411. break
  2412. raise e
  2413. def test_ap_wpa2_eap_ikev2(dev, apdev):
  2414. """WPA2-Enterprise connection using EAP-IKEv2"""
  2415. check_eap_capa(dev[0], "IKEV2")
  2416. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2417. hapd = hostapd.add_ap(apdev[0], params)
  2418. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2419. password="ike password")
  2420. eap_reauth(dev[0], "IKEV2")
  2421. dev[0].request("REMOVE_NETWORK all")
  2422. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2423. password="ike password", fragment_size="50")
  2424. logger.info("Negative test with incorrect password")
  2425. dev[0].request("REMOVE_NETWORK all")
  2426. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2427. password="ike-password", expect_failure=True)
  2428. dev[0].request("REMOVE_NETWORK all")
  2429. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2430. password="ike password", fragment_size="0")
  2431. dev[0].request("REMOVE_NETWORK all")
  2432. dev[0].wait_disconnected()
  2433. def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev):
  2434. """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation"""
  2435. check_eap_capa(dev[0], "IKEV2")
  2436. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2437. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2438. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2439. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  2440. "fragment_size": "50" }
  2441. hapd = hostapd.add_ap(apdev[0], params)
  2442. eap_connect(dev[0], hapd, "IKEV2", "ikev2 user",
  2443. password="ike password")
  2444. eap_reauth(dev[0], "IKEV2")
  2445. def test_ap_wpa2_eap_ikev2_oom(dev, apdev):
  2446. """WPA2-Enterprise connection using EAP-IKEv2 and OOM"""
  2447. check_eap_capa(dev[0], "IKEV2")
  2448. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2449. hostapd.add_ap(apdev[0], params)
  2450. tests = [ (1, "dh_init"),
  2451. (2, "dh_init"),
  2452. (1, "dh_derive_shared") ]
  2453. for count, func in tests:
  2454. with alloc_fail(dev[0], count, func):
  2455. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  2456. identity="ikev2 user", password="ike password",
  2457. wait_connect=False, scan_freq="2412")
  2458. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2459. if ev is None:
  2460. raise Exception("EAP method not selected")
  2461. for i in range(10):
  2462. if "0:" in dev[0].request("GET_ALLOC_FAIL"):
  2463. break
  2464. time.sleep(0.02)
  2465. dev[0].request("REMOVE_NETWORK all")
  2466. tests = [ (1, "os_get_random;dh_init") ]
  2467. for count, func in tests:
  2468. with fail_test(dev[0], count, func):
  2469. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  2470. identity="ikev2 user", password="ike password",
  2471. wait_connect=False, scan_freq="2412")
  2472. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2473. if ev is None:
  2474. raise Exception("EAP method not selected")
  2475. for i in range(10):
  2476. if "0:" in dev[0].request("GET_FAIL"):
  2477. break
  2478. time.sleep(0.02)
  2479. dev[0].request("REMOVE_NETWORK all")
  2480. def test_ap_wpa2_eap_pax(dev, apdev):
  2481. """WPA2-Enterprise connection using EAP-PAX"""
  2482. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2483. hapd = hostapd.add_ap(apdev[0], params)
  2484. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  2485. password_hex="0123456789abcdef0123456789abcdef")
  2486. eap_reauth(dev[0], "PAX")
  2487. logger.info("Negative test with incorrect password")
  2488. dev[0].request("REMOVE_NETWORK all")
  2489. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  2490. password_hex="ff23456789abcdef0123456789abcdef",
  2491. expect_failure=True)
  2492. def test_ap_wpa2_eap_psk(dev, apdev):
  2493. """WPA2-Enterprise connection using EAP-PSK"""
  2494. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2495. params["wpa_key_mgmt"] = "WPA-EAP-SHA256"
  2496. params["ieee80211w"] = "2"
  2497. hapd = hostapd.add_ap(apdev[0], params)
  2498. eap_connect(dev[0], hapd, "PSK", "psk.user@example.com",
  2499. password_hex="0123456789abcdef0123456789abcdef", sha256=True)
  2500. eap_reauth(dev[0], "PSK", sha256=True)
  2501. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
  2502. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ])
  2503. bss = dev[0].get_bss(apdev[0]['bssid'])
  2504. if 'flags' not in bss:
  2505. raise Exception("Could not get BSS flags from BSS table")
  2506. if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']:
  2507. raise Exception("Unexpected BSS flags: " + bss['flags'])
  2508. logger.info("Negative test with incorrect password")
  2509. dev[0].request("REMOVE_NETWORK all")
  2510. eap_connect(dev[0], hapd, "PSK", "psk.user@example.com",
  2511. password_hex="ff23456789abcdef0123456789abcdef", sha256=True,
  2512. expect_failure=True)
  2513. def test_ap_wpa2_eap_psk_oom(dev, apdev):
  2514. """WPA2-Enterprise connection using EAP-PSK and OOM"""
  2515. skip_with_fips(dev[0])
  2516. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2517. hostapd.add_ap(apdev[0], params)
  2518. tests = [ (1, "=aes_128_eax_encrypt"),
  2519. (1, "=aes_128_eax_decrypt") ]
  2520. for count, func in tests:
  2521. with alloc_fail(dev[0], count, func):
  2522. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2523. identity="psk.user@example.com",
  2524. password_hex="0123456789abcdef0123456789abcdef",
  2525. wait_connect=False, scan_freq="2412")
  2526. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2527. if ev is None:
  2528. raise Exception("EAP method not selected")
  2529. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
  2530. note="Failure not triggered: %d:%s" % (count, func))
  2531. dev[0].request("REMOVE_NETWORK all")
  2532. dev[0].wait_disconnected()
  2533. tests = [ (1, "aes_ctr_encrypt;aes_128_eax_encrypt"),
  2534. (1, "omac1_aes_128;aes_128_eax_encrypt"),
  2535. (2, "omac1_aes_128;aes_128_eax_encrypt"),
  2536. (3, "omac1_aes_128;aes_128_eax_encrypt"),
  2537. (1, "omac1_aes_vector"),
  2538. (1, "omac1_aes_128;aes_128_eax_decrypt"),
  2539. (2, "omac1_aes_128;aes_128_eax_decrypt"),
  2540. (3, "omac1_aes_128;aes_128_eax_decrypt"),
  2541. (1, "aes_ctr_encrypt;aes_128_eax_decrypt") ]
  2542. for count, func in tests:
  2543. with fail_test(dev[0], count, func):
  2544. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2545. identity="psk.user@example.com",
  2546. password_hex="0123456789abcdef0123456789abcdef",
  2547. wait_connect=False, scan_freq="2412")
  2548. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  2549. if ev is None:
  2550. raise Exception("EAP method not selected")
  2551. wait_fail_trigger(dev[0], "GET_FAIL",
  2552. note="Failure not triggered: %d:%s" % (count, func))
  2553. dev[0].request("REMOVE_NETWORK all")
  2554. dev[0].wait_disconnected()
  2555. with fail_test(dev[0], 1, "aes_128_encrypt_block"):
  2556. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2557. identity="psk.user@example.com",
  2558. password_hex="0123456789abcdef0123456789abcdef",
  2559. wait_connect=False, scan_freq="2412")
  2560. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2561. if ev is None:
  2562. raise Exception("EAP method failure not reported")
  2563. dev[0].request("REMOVE_NETWORK all")
  2564. dev[0].wait_disconnected()
  2565. def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev):
  2566. """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  2567. check_eap_capa(dev[0], "MSCHAPV2")
  2568. params = hostapd.wpa_eap_params(ssid="test-wpa-eap")
  2569. hapd = hostapd.add_ap(apdev[0], params)
  2570. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP",
  2571. identity="user", password="password", phase2="auth=MSCHAPV2",
  2572. ca_cert="auth_serv/ca.pem", wait_connect=False,
  2573. scan_freq="2412")
  2574. eap_check_auth(dev[0], "PEAP", True, rsn=False)
  2575. hwsim_utils.test_connectivity(dev[0], hapd)
  2576. eap_reauth(dev[0], "PEAP", rsn=False)
  2577. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
  2578. ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ])
  2579. status = dev[0].get_status(extra="VERBOSE")
  2580. if 'portControl' not in status:
  2581. raise Exception("portControl missing from STATUS-VERBOSE")
  2582. if status['portControl'] != 'Auto':
  2583. raise Exception("Unexpected portControl value: " + status['portControl'])
  2584. if 'eap_session_id' not in status:
  2585. raise Exception("eap_session_id missing from STATUS-VERBOSE")
  2586. if not status['eap_session_id'].startswith("19"):
  2587. raise Exception("Unexpected eap_session_id value: " + status['eap_session_id'])
  2588. def test_ap_wpa2_eap_interactive(dev, apdev):
  2589. """WPA2-Enterprise connection using interactive identity/password entry"""
  2590. check_eap_capa(dev[0], "MSCHAPV2")
  2591. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2592. hapd = hostapd.add_ap(apdev[0], params)
  2593. tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
  2594. "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
  2595. None, "password"),
  2596. ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
  2597. "TTLS", "ttls", None, "auth=MSCHAPV2",
  2598. "DOMAIN\mschapv2 user", "password"),
  2599. ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
  2600. "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
  2601. ("Connection with dynamic TTLS/EAP-MD5 password entry",
  2602. "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
  2603. ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
  2604. "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
  2605. ("Connection with dynamic PEAP/EAP-GTC password entry",
  2606. "PEAP", None, "user", "auth=GTC", None, "password") ]
  2607. for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
  2608. logger.info(desc)
  2609. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
  2610. anonymous_identity=anon, identity=identity,
  2611. ca_cert="auth_serv/ca.pem", phase2=phase2,
  2612. wait_connect=False, scan_freq="2412")
  2613. if req_id:
  2614. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2615. if ev is None:
  2616. raise Exception("Request for identity timed out")
  2617. id = ev.split(':')[0].split('-')[-1]
  2618. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2619. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
  2620. if ev is None:
  2621. raise Exception("Request for password timed out")
  2622. id = ev.split(':')[0].split('-')[-1]
  2623. type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD"
  2624. dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw)
  2625. dev[0].wait_connected(timeout=10)
  2626. dev[0].request("REMOVE_NETWORK all")
  2627. def test_ap_wpa2_eap_ext_enable_network_while_connected(dev, apdev):
  2628. """WPA2-Enterprise interactive identity entry and ENABLE_NETWORK"""
  2629. check_eap_capa(dev[0], "MSCHAPV2")
  2630. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2631. hapd = hostapd.add_ap(apdev[0], params)
  2632. id_other = dev[0].connect("other", key_mgmt="NONE", scan_freq="2412",
  2633. only_add_network=True)
  2634. req_id = "DOMAIN\mschapv2 user"
  2635. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2636. anonymous_identity="ttls", identity=None,
  2637. password="password",
  2638. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2639. wait_connect=False, scan_freq="2412")
  2640. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2641. if ev is None:
  2642. raise Exception("Request for identity timed out")
  2643. id = ev.split(':')[0].split('-')[-1]
  2644. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2645. dev[0].wait_connected(timeout=10)
  2646. if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id_other)):
  2647. raise Exception("Failed to enable network")
  2648. ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=1)
  2649. if ev is not None:
  2650. raise Exception("Unexpected reconnection attempt on ENABLE_NETWORK")
  2651. dev[0].request("REMOVE_NETWORK all")
  2652. def test_ap_wpa2_eap_vendor_test(dev, apdev):
  2653. """WPA2-Enterprise connection using EAP vendor test"""
  2654. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2655. hapd = hostapd.add_ap(apdev[0], params)
  2656. eap_connect(dev[0], hapd, "VENDOR-TEST", "vendor-test")
  2657. eap_reauth(dev[0], "VENDOR-TEST")
  2658. eap_connect(dev[1], hapd, "VENDOR-TEST", "vendor-test",
  2659. password="pending")
  2660. def test_ap_wpa2_eap_vendor_test_oom(dev, apdev):
  2661. """WPA2-Enterprise connection using EAP vendor test (OOM)"""
  2662. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2663. hostapd.add_ap(apdev[0], params)
  2664. tests = [ "eap_vendor_test_init",
  2665. "eap_msg_alloc;eap_vendor_test_process",
  2666. "eap_vendor_test_getKey" ]
  2667. for func in tests:
  2668. with alloc_fail(dev[0], 1, func):
  2669. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  2670. scan_freq="2412",
  2671. eap="VENDOR-TEST", identity="vendor-test",
  2672. wait_connect=False)
  2673. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2674. dev[0].request("REMOVE_NETWORK all")
  2675. dev[0].wait_disconnected()
  2676. def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev):
  2677. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning"""
  2678. check_eap_capa(dev[0], "FAST")
  2679. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2680. hapd = hostapd.add_ap(apdev[0], params)
  2681. eap_connect(dev[0], hapd, "FAST", "user",
  2682. anonymous_identity="FAST", password="password",
  2683. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2684. phase1="fast_provisioning=1", pac_file="blob://fast_pac")
  2685. hwsim_utils.test_connectivity(dev[0], hapd)
  2686. res = eap_reauth(dev[0], "FAST")
  2687. if res['tls_session_reused'] != '1':
  2688. raise Exception("EAP-FAST could not use PAC session ticket")
  2689. def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params):
  2690. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file"""
  2691. check_eap_capa(dev[0], "FAST")
  2692. pac_file = os.path.join(params['logdir'], "fast.pac")
  2693. pac_file2 = os.path.join(params['logdir'], "fast-bin.pac")
  2694. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2695. hapd = hostapd.add_ap(apdev[0], params)
  2696. try:
  2697. eap_connect(dev[0], hapd, "FAST", "user",
  2698. anonymous_identity="FAST", password="password",
  2699. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2700. phase1="fast_provisioning=1", pac_file=pac_file)
  2701. with open(pac_file, "r") as f:
  2702. data = f.read()
  2703. if "wpa_supplicant EAP-FAST PAC file - version 1" not in data:
  2704. raise Exception("PAC file header missing")
  2705. if "PAC-Key=" not in data:
  2706. raise Exception("PAC-Key missing from PAC file")
  2707. dev[0].request("REMOVE_NETWORK all")
  2708. eap_connect(dev[0], hapd, "FAST", "user",
  2709. anonymous_identity="FAST", password="password",
  2710. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2711. pac_file=pac_file)
  2712. eap_connect(dev[1], hapd, "FAST", "user",
  2713. anonymous_identity="FAST", password="password",
  2714. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2715. phase1="fast_provisioning=1 fast_pac_format=binary",
  2716. pac_file=pac_file2)
  2717. dev[1].request("REMOVE_NETWORK all")
  2718. eap_connect(dev[1], hapd, "FAST", "user",
  2719. anonymous_identity="FAST", password="password",
  2720. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2721. phase1="fast_pac_format=binary",
  2722. pac_file=pac_file2)
  2723. finally:
  2724. try:
  2725. os.remove(pac_file)
  2726. except:
  2727. pass
  2728. try:
  2729. os.remove(pac_file2)
  2730. except:
  2731. pass
  2732. def test_ap_wpa2_eap_fast_binary_pac(dev, apdev):
  2733. """WPA2-Enterprise connection using EAP-FAST and binary PAC format"""
  2734. check_eap_capa(dev[0], "FAST")
  2735. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2736. hapd = hostapd.add_ap(apdev[0], params)
  2737. eap_connect(dev[0], hapd, "FAST", "user",
  2738. anonymous_identity="FAST", password="password",
  2739. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2740. phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary",
  2741. pac_file="blob://fast_pac_bin")
  2742. res = eap_reauth(dev[0], "FAST")
  2743. if res['tls_session_reused'] != '1':
  2744. raise Exception("EAP-FAST could not use PAC session ticket")
  2745. # Verify fast_max_pac_list_len=0 special case
  2746. dev[0].request("REMOVE_NETWORK all")
  2747. dev[0].wait_disconnected()
  2748. eap_connect(dev[0], hapd, "FAST", "user",
  2749. anonymous_identity="FAST", password="password",
  2750. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2751. phase1="fast_provisioning=1 fast_max_pac_list_len=0 fast_pac_format=binary",
  2752. pac_file="blob://fast_pac_bin")
  2753. def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev):
  2754. """WPA2-Enterprise connection using EAP-FAST and missing PAC config"""
  2755. check_eap_capa(dev[0], "FAST")
  2756. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2757. hostapd.add_ap(apdev[0], params)
  2758. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2759. identity="user", anonymous_identity="FAST",
  2760. password="password",
  2761. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2762. pac_file="blob://fast_pac_not_in_use",
  2763. wait_connect=False, scan_freq="2412")
  2764. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2765. if ev is None:
  2766. raise Exception("Timeout on EAP failure report")
  2767. dev[0].request("REMOVE_NETWORK all")
  2768. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2769. identity="user", anonymous_identity="FAST",
  2770. password="password",
  2771. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2772. wait_connect=False, scan_freq="2412")
  2773. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2774. if ev is None:
  2775. raise Exception("Timeout on EAP failure report")
  2776. def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
  2777. """EAP-FAST and binary PAC errors"""
  2778. check_eap_capa(dev[0], "FAST")
  2779. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2780. hapd = hostapd.add_ap(apdev[0], params)
  2781. tests = [ (1, "=eap_fast_save_pac_bin"),
  2782. (1, "eap_fast_write_pac"),
  2783. (2, "eap_fast_write_pac"), ]
  2784. for count, func in tests:
  2785. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors "):
  2786. raise Exception("Could not set blob")
  2787. with alloc_fail(dev[0], count, func):
  2788. eap_connect(dev[0], hapd, "FAST", "user",
  2789. anonymous_identity="FAST", password="password",
  2790. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2791. phase1="fast_provisioning=1 fast_pac_format=binary",
  2792. pac_file="blob://fast_pac_bin_errors")
  2793. dev[0].request("REMOVE_NETWORK all")
  2794. dev[0].wait_disconnected()
  2795. tests = [ "00", "000000000000", "6ae4920c0001",
  2796. "6ae4920c000000",
  2797. "6ae4920c0000" + "0000" + 32*"00" + "ffff" + "0000",
  2798. "6ae4920c0000" + "0000" + 32*"00" + "0001" + "0000",
  2799. "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0001",
  2800. "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0008" + "00040000" + "0007000100"]
  2801. for t in tests:
  2802. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + t):
  2803. raise Exception("Could not set blob")
  2804. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2805. identity="user", anonymous_identity="FAST",
  2806. password="password",
  2807. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2808. phase1="fast_provisioning=1 fast_pac_format=binary",
  2809. pac_file="blob://fast_pac_bin_errors",
  2810. scan_freq="2412", wait_connect=False)
  2811. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2812. timeout=5)
  2813. if ev is None:
  2814. raise Exception("Failure not reported")
  2815. dev[0].request("REMOVE_NETWORK all")
  2816. dev[0].wait_disconnected()
  2817. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0000"
  2818. tests = [ (1, "eap_fast_load_pac_bin"),
  2819. (2, "eap_fast_load_pac_bin"),
  2820. (3, "eap_fast_load_pac_bin") ]
  2821. for count, func in tests:
  2822. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2823. raise Exception("Could not set blob")
  2824. with alloc_fail(dev[0], count, func):
  2825. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2826. identity="user", anonymous_identity="FAST",
  2827. password="password",
  2828. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2829. phase1="fast_provisioning=1 fast_pac_format=binary",
  2830. pac_file="blob://fast_pac_bin_errors",
  2831. scan_freq="2412", wait_connect=False)
  2832. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2833. timeout=5)
  2834. if ev is None:
  2835. raise Exception("Failure not reported")
  2836. dev[0].request("REMOVE_NETWORK all")
  2837. dev[0].wait_disconnected()
  2838. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0005" + "0011223344"
  2839. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2840. raise Exception("Could not set blob")
  2841. eap_connect(dev[0], hapd, "FAST", "user",
  2842. anonymous_identity="FAST", password="password",
  2843. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2844. phase1="fast_provisioning=1 fast_pac_format=binary",
  2845. pac_file="blob://fast_pac_bin_errors")
  2846. dev[0].request("REMOVE_NETWORK all")
  2847. dev[0].wait_disconnected()
  2848. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0009" + "00040000" + "0007000100"
  2849. tests = [ (1, "eap_fast_pac_get_a_id"),
  2850. (2, "eap_fast_pac_get_a_id") ]
  2851. for count, func in tests:
  2852. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2853. raise Exception("Could not set blob")
  2854. with alloc_fail(dev[0], count, func):
  2855. eap_connect(dev[0], hapd, "FAST", "user",
  2856. anonymous_identity="FAST", password="password",
  2857. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2858. phase1="fast_provisioning=1 fast_pac_format=binary",
  2859. pac_file="blob://fast_pac_bin_errors")
  2860. dev[0].request("REMOVE_NETWORK all")
  2861. dev[0].wait_disconnected()
  2862. def test_ap_wpa2_eap_fast_text_pac_errors(dev, apdev):
  2863. """EAP-FAST and text PAC errors"""
  2864. check_eap_capa(dev[0], "FAST")
  2865. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2866. hostapd.add_ap(apdev[0], params)
  2867. tests = [ (1, "eap_fast_parse_hex;eap_fast_parse_pac_key"),
  2868. (1, "eap_fast_parse_hex;eap_fast_parse_pac_opaque"),
  2869. (1, "eap_fast_parse_hex;eap_fast_parse_a_id"),
  2870. (1, "eap_fast_parse_start"),
  2871. (1, "eap_fast_save_pac") ]
  2872. for count, func in tests:
  2873. dev[0].request("FLUSH")
  2874. if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
  2875. raise Exception("Could not set blob")
  2876. with alloc_fail(dev[0], count, func):
  2877. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2878. identity="user", anonymous_identity="FAST",
  2879. password="password",
  2880. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2881. phase1="fast_provisioning=1",
  2882. pac_file="blob://fast_pac_text_errors",
  2883. scan_freq="2412", wait_connect=False)
  2884. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2885. dev[0].request("REMOVE_NETWORK all")
  2886. dev[0].wait_disconnected()
  2887. pac = "wpa_supplicant EAP-FAST PAC file - version 1\n"
  2888. pac += "START\n"
  2889. pac += "PAC-Type\n"
  2890. pac += "END\n"
  2891. if "OK" not in dev[0].request("SET blob fast_pac_text_errors " + pac.encode("hex")):
  2892. raise Exception("Could not set blob")
  2893. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2894. identity="user", anonymous_identity="FAST",
  2895. password="password",
  2896. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2897. phase1="fast_provisioning=1",
  2898. pac_file="blob://fast_pac_text_errors",
  2899. scan_freq="2412", wait_connect=False)
  2900. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=5)
  2901. if ev is None:
  2902. raise Exception("Failure not reported")
  2903. dev[0].request("REMOVE_NETWORK all")
  2904. dev[0].wait_disconnected()
  2905. dev[0].request("FLUSH")
  2906. if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
  2907. raise Exception("Could not set blob")
  2908. with alloc_fail(dev[0], 1, "eap_fast_add_pac_data"):
  2909. for i in range(3):
  2910. params = int_eap_server_params()
  2911. params['ssid'] = "test-wpa2-eap-2"
  2912. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2913. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2914. params['eap_fast_a_id_info'] = "test server %d" % i
  2915. hapd2 = hostapd.add_ap(apdev[1], params)
  2916. dev[0].connect("test-wpa2-eap-2", 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",
  2921. pac_file="blob://fast_pac_text_errors",
  2922. scan_freq="2412", wait_connect=False)
  2923. dev[0].wait_connected()
  2924. dev[0].request("REMOVE_NETWORK all")
  2925. dev[0].wait_disconnected()
  2926. hapd2.disable()
  2927. def test_ap_wpa2_eap_fast_pac_truncate(dev, apdev):
  2928. """EAP-FAST and PAC list truncation"""
  2929. check_eap_capa(dev[0], "FAST")
  2930. if "OK" not in dev[0].request("SET blob fast_pac_truncate "):
  2931. raise Exception("Could not set blob")
  2932. for i in range(5):
  2933. params = int_eap_server_params()
  2934. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2935. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2936. params['eap_fast_a_id_info'] = "test server %d" % i
  2937. hapd = hostapd.add_ap(apdev[0], params)
  2938. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2939. identity="user", anonymous_identity="FAST",
  2940. password="password",
  2941. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2942. phase1="fast_provisioning=1 fast_max_pac_list_len=2",
  2943. pac_file="blob://fast_pac_truncate",
  2944. scan_freq="2412", wait_connect=False)
  2945. dev[0].wait_connected()
  2946. dev[0].request("REMOVE_NETWORK all")
  2947. dev[0].wait_disconnected()
  2948. hapd.disable()
  2949. def test_ap_wpa2_eap_fast_pac_refresh(dev, apdev):
  2950. """EAP-FAST and PAC refresh"""
  2951. check_eap_capa(dev[0], "FAST")
  2952. if "OK" not in dev[0].request("SET blob fast_pac_refresh "):
  2953. raise Exception("Could not set blob")
  2954. for i in range(2):
  2955. params = int_eap_server_params()
  2956. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2957. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2958. params['eap_fast_a_id_info'] = "test server %d" % i
  2959. params['pac_key_refresh_time'] = "1"
  2960. params['pac_key_lifetime'] = "10"
  2961. hapd = hostapd.add_ap(apdev[0], params)
  2962. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2963. identity="user", anonymous_identity="FAST",
  2964. password="password",
  2965. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2966. phase1="fast_provisioning=1",
  2967. pac_file="blob://fast_pac_refresh",
  2968. scan_freq="2412", wait_connect=False)
  2969. dev[0].wait_connected()
  2970. dev[0].request("REMOVE_NETWORK all")
  2971. dev[0].wait_disconnected()
  2972. hapd.disable()
  2973. for i in range(2):
  2974. params = int_eap_server_params()
  2975. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2976. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2977. params['eap_fast_a_id_info'] = "test server %d" % i
  2978. params['pac_key_refresh_time'] = "10"
  2979. params['pac_key_lifetime'] = "10"
  2980. hapd = hostapd.add_ap(apdev[0], params)
  2981. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2982. identity="user", anonymous_identity="FAST",
  2983. password="password",
  2984. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2985. phase1="fast_provisioning=1",
  2986. pac_file="blob://fast_pac_refresh",
  2987. scan_freq="2412", wait_connect=False)
  2988. dev[0].wait_connected()
  2989. dev[0].request("REMOVE_NETWORK all")
  2990. dev[0].wait_disconnected()
  2991. hapd.disable()
  2992. def test_ap_wpa2_eap_fast_pac_lifetime(dev, apdev):
  2993. """EAP-FAST and PAC lifetime"""
  2994. check_eap_capa(dev[0], "FAST")
  2995. if "OK" not in dev[0].request("SET blob fast_pac_refresh "):
  2996. raise Exception("Could not set blob")
  2997. i = 0
  2998. params = int_eap_server_params()
  2999. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  3000. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  3001. params['eap_fast_a_id_info'] = "test server %d" % i
  3002. params['pac_key_refresh_time'] = "0"
  3003. params['pac_key_lifetime'] = "2"
  3004. hapd = hostapd.add_ap(apdev[0], params)
  3005. id = 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=2",
  3010. pac_file="blob://fast_pac_refresh",
  3011. scan_freq="2412", wait_connect=False)
  3012. dev[0].wait_connected()
  3013. dev[0].request("DISCONNECT")
  3014. dev[0].wait_disconnected()
  3015. time.sleep(3)
  3016. dev[0].request("PMKSA_FLUSH")
  3017. dev[0].request("RECONNECT")
  3018. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3019. if ev is None:
  3020. raise Exception("No EAP-Failure seen after expired PAC")
  3021. dev[0].request("DISCONNECT")
  3022. dev[0].wait_disconnected()
  3023. dev[0].select_network(id)
  3024. dev[0].wait_connected()
  3025. dev[0].request("REMOVE_NETWORK all")
  3026. dev[0].wait_disconnected()
  3027. def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev):
  3028. """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning"""
  3029. check_eap_capa(dev[0], "FAST")
  3030. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3031. hapd = hostapd.add_ap(apdev[0], params)
  3032. eap_connect(dev[0], hapd, "FAST", "user",
  3033. anonymous_identity="FAST", password="password",
  3034. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3035. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth")
  3036. hwsim_utils.test_connectivity(dev[0], hapd)
  3037. res = eap_reauth(dev[0], "FAST")
  3038. if res['tls_session_reused'] != '1':
  3039. raise Exception("EAP-FAST could not use PAC session ticket")
  3040. def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev):
  3041. """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing"""
  3042. check_eap_capa(dev[0], "FAST")
  3043. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3044. hapd = hostapd.add_ap(apdev[0], params)
  3045. id = eap_connect(dev[0], hapd, "FAST", "user",
  3046. anonymous_identity="FAST", password="password",
  3047. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3048. phase1="fast_provisioning=2",
  3049. pac_file="blob://fast_pac_auth")
  3050. dev[0].set_network_quoted(id, "identity", "user2")
  3051. dev[0].wait_disconnected()
  3052. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  3053. if ev is None:
  3054. raise Exception("EAP-FAST not started")
  3055. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  3056. if ev is None:
  3057. raise Exception("EAP failure not reported")
  3058. dev[0].wait_disconnected()
  3059. def test_ap_wpa2_eap_fast_prf_oom(dev, apdev):
  3060. """WPA2-Enterprise connection using EAP-FAST and OOM in PRF"""
  3061. check_eap_capa(dev[0], "FAST")
  3062. tls = dev[0].request("GET tls_library")
  3063. if tls.startswith("OpenSSL"):
  3064. func = "tls_connection_get_eap_fast_key"
  3065. count = 2
  3066. elif tls.startswith("internal"):
  3067. func = "tls_connection_prf"
  3068. count = 1
  3069. else:
  3070. raise HwsimSkip("Unsupported TLS library")
  3071. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3072. hapd = hostapd.add_ap(apdev[0], params)
  3073. with alloc_fail(dev[0], count, func):
  3074. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3075. identity="user", anonymous_identity="FAST",
  3076. password="password", ca_cert="auth_serv/ca.pem",
  3077. phase2="auth=GTC",
  3078. phase1="fast_provisioning=2",
  3079. pac_file="blob://fast_pac_auth",
  3080. wait_connect=False, scan_freq="2412")
  3081. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  3082. if ev is None:
  3083. raise Exception("EAP failure not reported")
  3084. dev[0].request("DISCONNECT")
  3085. def test_ap_wpa2_eap_fast_server_oom(dev, apdev):
  3086. """EAP-FAST/MSCHAPv2 and server OOM"""
  3087. check_eap_capa(dev[0], "FAST")
  3088. params = int_eap_server_params()
  3089. params['dh_file'] = 'auth_serv/dh.conf'
  3090. params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f'
  3091. params['eap_fast_a_id'] = '1011'
  3092. params['eap_fast_a_id_info'] = 'another test server'
  3093. hapd = hostapd.add_ap(apdev[0], params)
  3094. with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"):
  3095. id = eap_connect(dev[0], hapd, "FAST", "user",
  3096. anonymous_identity="FAST", password="password",
  3097. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3098. phase1="fast_provisioning=1",
  3099. pac_file="blob://fast_pac",
  3100. expect_failure=True)
  3101. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3102. if ev is None:
  3103. raise Exception("No EAP failure reported")
  3104. dev[0].wait_disconnected()
  3105. dev[0].request("DISCONNECT")
  3106. dev[0].select_network(id, freq="2412")
  3107. def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev):
  3108. """EAP-FAST and different TLS cipher suites"""
  3109. check_eap_capa(dev[0], "FAST")
  3110. tls = dev[0].request("GET tls_library")
  3111. if not tls.startswith("OpenSSL"):
  3112. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  3113. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3114. hapd = hostapd.add_ap(apdev[0], params)
  3115. dev[0].request("SET blob fast_pac_ciphers ")
  3116. eap_connect(dev[0], hapd, "FAST", "user",
  3117. anonymous_identity="FAST", password="password",
  3118. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3119. phase1="fast_provisioning=2",
  3120. pac_file="blob://fast_pac_ciphers")
  3121. res = dev[0].get_status_field('EAP TLS cipher')
  3122. dev[0].request("REMOVE_NETWORK all")
  3123. dev[0].wait_disconnected()
  3124. if res != "DHE-RSA-AES256-SHA":
  3125. raise Exception("Unexpected cipher suite for provisioning: " + res)
  3126. tests = [ "DHE-RSA-AES128-SHA",
  3127. "RC4-SHA",
  3128. "AES128-SHA",
  3129. "AES256-SHA",
  3130. "DHE-RSA-AES256-SHA" ]
  3131. for cipher in tests:
  3132. dev[0].dump_monitor()
  3133. logger.info("Testing " + cipher)
  3134. try:
  3135. eap_connect(dev[0], hapd, "FAST", "user",
  3136. openssl_ciphers=cipher,
  3137. anonymous_identity="FAST", password="password",
  3138. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3139. pac_file="blob://fast_pac_ciphers")
  3140. except Exception, e:
  3141. if "Could not select EAP method" in str(e) and cipher == "RC4-SHA":
  3142. tls = dev[0].request("GET tls_library")
  3143. if "run=OpenSSL 1.1" in tls:
  3144. logger.info("Allow failure due to missing TLS library support")
  3145. dev[0].request("REMOVE_NETWORK all")
  3146. dev[0].wait_disconnected()
  3147. continue
  3148. raise
  3149. res = dev[0].get_status_field('EAP TLS cipher')
  3150. dev[0].request("REMOVE_NETWORK all")
  3151. dev[0].wait_disconnected()
  3152. if res != cipher:
  3153. raise Exception("Unexpected TLS cipher info (configured %s): %s" % (cipher, res))
  3154. def test_ap_wpa2_eap_tls_ocsp(dev, apdev):
  3155. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP"""
  3156. check_ocsp_support(dev[0])
  3157. check_pkcs12_support(dev[0])
  3158. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3159. hapd = hostapd.add_ap(apdev[0], params)
  3160. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3161. private_key="auth_serv/user.pkcs12",
  3162. private_key_passwd="whatever", ocsp=2)
  3163. def test_ap_wpa2_eap_tls_ocsp_multi(dev, apdev):
  3164. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP-multi"""
  3165. check_ocsp_multi_support(dev[0])
  3166. check_pkcs12_support(dev[0])
  3167. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3168. hapd = hostapd.add_ap(apdev[0], params)
  3169. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3170. private_key="auth_serv/user.pkcs12",
  3171. private_key_passwd="whatever", ocsp=2)
  3172. def int_eap_server_params():
  3173. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  3174. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  3175. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  3176. "ca_cert": "auth_serv/ca.pem",
  3177. "server_cert": "auth_serv/server.pem",
  3178. "private_key": "auth_serv/server.key",
  3179. "dh_file": "auth_serv/dh.conf" }
  3180. return params
  3181. def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params):
  3182. """EAP-TLS and OCSP certificate signed OCSP response using key ID"""
  3183. check_ocsp_support(dev[0])
  3184. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-key-id.der")
  3185. if not os.path.exists(ocsp):
  3186. raise HwsimSkip("No OCSP response available")
  3187. params = int_eap_server_params()
  3188. params["ocsp_stapling_response"] = ocsp
  3189. hostapd.add_ap(apdev[0], params)
  3190. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3191. identity="tls user", ca_cert="auth_serv/ca.pem",
  3192. private_key="auth_serv/user.pkcs12",
  3193. private_key_passwd="whatever", ocsp=2,
  3194. scan_freq="2412")
  3195. def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params):
  3196. """EAP-TLS and CA signed OCSP response (good)"""
  3197. check_ocsp_support(dev[0])
  3198. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der")
  3199. if not os.path.exists(ocsp):
  3200. raise HwsimSkip("No OCSP response available")
  3201. params = int_eap_server_params()
  3202. params["ocsp_stapling_response"] = ocsp
  3203. hostapd.add_ap(apdev[0], params)
  3204. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3205. identity="tls user", ca_cert="auth_serv/ca.pem",
  3206. private_key="auth_serv/user.pkcs12",
  3207. private_key_passwd="whatever", ocsp=2,
  3208. scan_freq="2412")
  3209. def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params):
  3210. """EAP-TLS and CA signed OCSP response (revoked)"""
  3211. check_ocsp_support(dev[0])
  3212. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der")
  3213. if not os.path.exists(ocsp):
  3214. raise HwsimSkip("No OCSP response available")
  3215. params = int_eap_server_params()
  3216. params["ocsp_stapling_response"] = ocsp
  3217. hostapd.add_ap(apdev[0], params)
  3218. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3219. identity="tls user", ca_cert="auth_serv/ca.pem",
  3220. private_key="auth_serv/user.pkcs12",
  3221. private_key_passwd="whatever", ocsp=2,
  3222. wait_connect=False, scan_freq="2412")
  3223. count = 0
  3224. while True:
  3225. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3226. if ev is None:
  3227. raise Exception("Timeout on EAP status")
  3228. if 'bad certificate status response' in ev:
  3229. break
  3230. if 'certificate revoked' in ev:
  3231. break
  3232. count = count + 1
  3233. if count > 10:
  3234. raise Exception("Unexpected number of EAP status messages")
  3235. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3236. if ev is None:
  3237. raise Exception("Timeout on EAP failure report")
  3238. def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params):
  3239. """EAP-TLS and CA signed OCSP response (unknown)"""
  3240. check_ocsp_support(dev[0])
  3241. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der")
  3242. if not os.path.exists(ocsp):
  3243. raise HwsimSkip("No OCSP response available")
  3244. params = int_eap_server_params()
  3245. params["ocsp_stapling_response"] = ocsp
  3246. hostapd.add_ap(apdev[0], params)
  3247. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3248. identity="tls user", ca_cert="auth_serv/ca.pem",
  3249. private_key="auth_serv/user.pkcs12",
  3250. private_key_passwd="whatever", ocsp=2,
  3251. wait_connect=False, scan_freq="2412")
  3252. count = 0
  3253. while True:
  3254. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3255. if ev is None:
  3256. raise Exception("Timeout on EAP status")
  3257. if 'bad certificate status response' in ev:
  3258. break
  3259. count = count + 1
  3260. if count > 10:
  3261. raise Exception("Unexpected number of EAP status messages")
  3262. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3263. if ev is None:
  3264. raise Exception("Timeout on EAP failure report")
  3265. def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params):
  3266. """EAP-TLS and server signed OCSP response"""
  3267. check_ocsp_support(dev[0])
  3268. ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der")
  3269. if not os.path.exists(ocsp):
  3270. raise HwsimSkip("No OCSP response available")
  3271. params = int_eap_server_params()
  3272. params["ocsp_stapling_response"] = ocsp
  3273. hostapd.add_ap(apdev[0], params)
  3274. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3275. identity="tls user", ca_cert="auth_serv/ca.pem",
  3276. private_key="auth_serv/user.pkcs12",
  3277. private_key_passwd="whatever", ocsp=2,
  3278. wait_connect=False, scan_freq="2412")
  3279. count = 0
  3280. while True:
  3281. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3282. if ev is None:
  3283. raise Exception("Timeout on EAP status")
  3284. if 'bad certificate status response' in ev:
  3285. break
  3286. count = count + 1
  3287. if count > 10:
  3288. raise Exception("Unexpected number of EAP status messages")
  3289. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3290. if ev is None:
  3291. raise Exception("Timeout on EAP failure report")
  3292. def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
  3293. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data"""
  3294. check_ocsp_support(dev[0])
  3295. params = int_eap_server_params()
  3296. params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der"
  3297. hostapd.add_ap(apdev[0], params)
  3298. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3299. identity="tls user", ca_cert="auth_serv/ca.pem",
  3300. private_key="auth_serv/user.pkcs12",
  3301. private_key_passwd="whatever", ocsp=2,
  3302. wait_connect=False, scan_freq="2412")
  3303. count = 0
  3304. while True:
  3305. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3306. if ev is None:
  3307. raise Exception("Timeout on EAP status")
  3308. if 'bad certificate status response' in ev:
  3309. break
  3310. count = count + 1
  3311. if count > 10:
  3312. raise Exception("Unexpected number of EAP status messages")
  3313. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3314. if ev is None:
  3315. raise Exception("Timeout on EAP failure report")
  3316. def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
  3317. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
  3318. check_ocsp_support(dev[0])
  3319. params = int_eap_server_params()
  3320. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
  3321. hostapd.add_ap(apdev[0], params)
  3322. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3323. identity="tls user", ca_cert="auth_serv/ca.pem",
  3324. private_key="auth_serv/user.pkcs12",
  3325. private_key_passwd="whatever", ocsp=2,
  3326. wait_connect=False, scan_freq="2412")
  3327. count = 0
  3328. while True:
  3329. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3330. if ev is None:
  3331. raise Exception("Timeout on EAP status")
  3332. if 'bad certificate status response' in ev:
  3333. break
  3334. count = count + 1
  3335. if count > 10:
  3336. raise Exception("Unexpected number of EAP status messages")
  3337. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3338. if ev is None:
  3339. raise Exception("Timeout on EAP failure report")
  3340. def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev):
  3341. """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer"""
  3342. check_ocsp_support(dev[0])
  3343. params = int_eap_server_params()
  3344. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign"
  3345. hostapd.add_ap(apdev[0], params)
  3346. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3347. identity="tls user", ca_cert="auth_serv/ca.pem",
  3348. private_key="auth_serv/user.pkcs12",
  3349. private_key_passwd="whatever", ocsp=2,
  3350. wait_connect=False, scan_freq="2412")
  3351. count = 0
  3352. while True:
  3353. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3354. if ev is None:
  3355. raise Exception("Timeout on EAP status")
  3356. if 'bad certificate status response' in ev:
  3357. break
  3358. count = count + 1
  3359. if count > 10:
  3360. raise Exception("Unexpected number of EAP status messages")
  3361. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3362. if ev is None:
  3363. raise Exception("Timeout on EAP failure report")
  3364. def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params):
  3365. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3366. check_ocsp_support(dev[0])
  3367. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der")
  3368. if not os.path.exists(ocsp):
  3369. raise HwsimSkip("No OCSP response available")
  3370. params = int_eap_server_params()
  3371. params["ocsp_stapling_response"] = ocsp
  3372. hostapd.add_ap(apdev[0], params)
  3373. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3374. identity="pap user", ca_cert="auth_serv/ca.pem",
  3375. anonymous_identity="ttls", password="password",
  3376. phase2="auth=PAP", ocsp=2,
  3377. wait_connect=False, scan_freq="2412")
  3378. count = 0
  3379. while True:
  3380. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3381. if ev is None:
  3382. raise Exception("Timeout on EAP status")
  3383. if 'bad certificate status response' in ev:
  3384. break
  3385. if 'certificate revoked' in ev:
  3386. break
  3387. count = count + 1
  3388. if count > 10:
  3389. raise Exception("Unexpected number of EAP status messages")
  3390. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3391. if ev is None:
  3392. raise Exception("Timeout on EAP failure report")
  3393. def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params):
  3394. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3395. check_ocsp_support(dev[0])
  3396. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  3397. if not os.path.exists(ocsp):
  3398. raise HwsimSkip("No OCSP response available")
  3399. params = int_eap_server_params()
  3400. params["ocsp_stapling_response"] = ocsp
  3401. hostapd.add_ap(apdev[0], params)
  3402. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3403. identity="pap user", ca_cert="auth_serv/ca.pem",
  3404. anonymous_identity="ttls", password="password",
  3405. phase2="auth=PAP", ocsp=2,
  3406. wait_connect=False, scan_freq="2412")
  3407. count = 0
  3408. while True:
  3409. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3410. if ev is None:
  3411. raise Exception("Timeout on EAP status")
  3412. if 'bad certificate status response' in ev:
  3413. break
  3414. count = count + 1
  3415. if count > 10:
  3416. raise Exception("Unexpected number of EAP status messages")
  3417. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3418. if ev is None:
  3419. raise Exception("Timeout on EAP failure report")
  3420. def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params):
  3421. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3422. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  3423. if not os.path.exists(ocsp):
  3424. raise HwsimSkip("No OCSP response available")
  3425. params = int_eap_server_params()
  3426. params["ocsp_stapling_response"] = ocsp
  3427. hostapd.add_ap(apdev[0], params)
  3428. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3429. identity="pap user", ca_cert="auth_serv/ca.pem",
  3430. anonymous_identity="ttls", password="password",
  3431. phase2="auth=PAP", ocsp=1, scan_freq="2412")
  3432. def test_ap_wpa2_eap_tls_intermediate_ca(dev, apdev, params):
  3433. """EAP-TLS with intermediate server/user CA"""
  3434. params = int_eap_server_params()
  3435. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3436. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3437. params["private_key"] = "auth_serv/iCA-server/server.key"
  3438. hostapd.add_ap(apdev[0], params)
  3439. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3440. identity="tls user",
  3441. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3442. client_cert="auth_serv/iCA-user/user.pem",
  3443. private_key="auth_serv/iCA-user/user.key",
  3444. scan_freq="2412")
  3445. def root_ocsp(cert):
  3446. ca = "auth_serv/ca.pem"
  3447. fd2, fn2 = tempfile.mkstemp()
  3448. os.close(fd2)
  3449. arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-cert", cert,
  3450. "-no_nonce", "-sha256", "-text" ]
  3451. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3452. stderr=subprocess.PIPE)
  3453. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3454. cmd.stdout.close()
  3455. cmd.stderr.close()
  3456. logger.info("OCSP request:\n" + res)
  3457. fd, fn = tempfile.mkstemp()
  3458. os.close(fd)
  3459. arg = [ "openssl", "ocsp", "-index", "auth_serv/rootCA/index.txt",
  3460. "-rsigner", ca, "-rkey", "auth_serv/ca-key.pem",
  3461. "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
  3462. "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
  3463. "-text" ]
  3464. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3465. stderr=subprocess.PIPE)
  3466. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3467. cmd.stdout.close()
  3468. cmd.stderr.close()
  3469. logger.info("OCSP response:\n" + res)
  3470. os.unlink(fn2)
  3471. return fn
  3472. def ica_ocsp(cert):
  3473. prefix = "auth_serv/iCA-server/"
  3474. ca = prefix + "cacert.pem"
  3475. cert = prefix + cert
  3476. fd2, fn2 = tempfile.mkstemp()
  3477. os.close(fd2)
  3478. arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-cert", cert,
  3479. "-no_nonce", "-sha256", "-text" ]
  3480. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3481. stderr=subprocess.PIPE)
  3482. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3483. cmd.stdout.close()
  3484. cmd.stderr.close()
  3485. logger.info("OCSP request:\n" + res)
  3486. fd, fn = tempfile.mkstemp()
  3487. os.close(fd)
  3488. arg = [ "openssl", "ocsp", "-index", prefix + "index.txt",
  3489. "-rsigner", ca, "-rkey", prefix + "private/cakey.pem",
  3490. "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
  3491. "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
  3492. "-text" ]
  3493. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3494. stderr=subprocess.PIPE)
  3495. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3496. cmd.stdout.close()
  3497. cmd.stderr.close()
  3498. logger.info("OCSP response:\n" + res)
  3499. os.unlink(fn2)
  3500. return fn
  3501. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params):
  3502. """EAP-TLS with intermediate server/user CA and OCSP on server certificate"""
  3503. params = int_eap_server_params()
  3504. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3505. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3506. params["private_key"] = "auth_serv/iCA-server/server.key"
  3507. fn = ica_ocsp("server.pem")
  3508. params["ocsp_stapling_response"] = fn
  3509. try:
  3510. hostapd.add_ap(apdev[0], params)
  3511. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3512. identity="tls user",
  3513. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3514. client_cert="auth_serv/iCA-user/user.pem",
  3515. private_key="auth_serv/iCA-user/user.key",
  3516. scan_freq="2412", ocsp=2)
  3517. finally:
  3518. os.unlink(fn)
  3519. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params):
  3520. """EAP-TLS with intermediate server/user CA and OCSP on revoked server certificate"""
  3521. params = int_eap_server_params()
  3522. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3523. params["server_cert"] = "auth_serv/iCA-server/server-revoked.pem"
  3524. params["private_key"] = "auth_serv/iCA-server/server-revoked.key"
  3525. fn = ica_ocsp("server-revoked.pem")
  3526. params["ocsp_stapling_response"] = fn
  3527. try:
  3528. hostapd.add_ap(apdev[0], params)
  3529. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3530. identity="tls user",
  3531. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3532. client_cert="auth_serv/iCA-user/user.pem",
  3533. private_key="auth_serv/iCA-user/user.key",
  3534. scan_freq="2412", ocsp=1, wait_connect=False)
  3535. count = 0
  3536. while True:
  3537. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3538. "CTRL-EVENT-EAP-SUCCESS"])
  3539. if ev is None:
  3540. raise Exception("Timeout on EAP status")
  3541. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3542. raise Exception("Unexpected EAP-Success")
  3543. if 'bad certificate status response' in ev:
  3544. break
  3545. if 'certificate revoked' in ev:
  3546. break
  3547. count = count + 1
  3548. if count > 10:
  3549. raise Exception("Unexpected number of EAP status messages")
  3550. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3551. if ev is None:
  3552. raise Exception("Timeout on EAP failure report")
  3553. dev[0].request("REMOVE_NETWORK all")
  3554. dev[0].wait_disconnected()
  3555. finally:
  3556. os.unlink(fn)
  3557. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi_missing_resp(dev, apdev, params):
  3558. """EAP-TLS with intermediate server/user CA and OCSP multi missing response"""
  3559. check_ocsp_support(dev[0])
  3560. check_ocsp_multi_support(dev[0])
  3561. params = int_eap_server_params()
  3562. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3563. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3564. params["private_key"] = "auth_serv/iCA-server/server.key"
  3565. fn = ica_ocsp("server.pem")
  3566. params["ocsp_stapling_response"] = fn
  3567. try:
  3568. hostapd.add_ap(apdev[0], params)
  3569. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3570. identity="tls user",
  3571. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3572. client_cert="auth_serv/iCA-user/user.pem",
  3573. private_key="auth_serv/iCA-user/user.key",
  3574. scan_freq="2412", ocsp=3, wait_connect=False)
  3575. count = 0
  3576. while True:
  3577. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3578. "CTRL-EVENT-EAP-SUCCESS"])
  3579. if ev is None:
  3580. raise Exception("Timeout on EAP status")
  3581. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3582. raise Exception("Unexpected EAP-Success")
  3583. if 'bad certificate status response' in ev:
  3584. break
  3585. if 'certificate revoked' in ev:
  3586. break
  3587. count = count + 1
  3588. if count > 10:
  3589. raise Exception("Unexpected number of EAP status messages")
  3590. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3591. if ev is None:
  3592. raise Exception("Timeout on EAP failure report")
  3593. dev[0].request("REMOVE_NETWORK all")
  3594. dev[0].wait_disconnected()
  3595. finally:
  3596. os.unlink(fn)
  3597. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi(dev, apdev, params):
  3598. """EAP-TLS with intermediate server/user CA and OCSP multi OK"""
  3599. check_ocsp_support(dev[0])
  3600. check_ocsp_multi_support(dev[0])
  3601. params = int_eap_server_params()
  3602. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3603. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3604. params["private_key"] = "auth_serv/iCA-server/server.key"
  3605. fn = ica_ocsp("server.pem")
  3606. fn2 = root_ocsp("auth_serv/iCA-server/cacert.pem")
  3607. params["ocsp_stapling_response"] = fn
  3608. with open(fn, "r") as f:
  3609. resp_server = f.read()
  3610. with open(fn2, "r") as f:
  3611. resp_ica = f.read()
  3612. fd3, fn3 = tempfile.mkstemp()
  3613. try:
  3614. f = os.fdopen(fd3, 'w')
  3615. f.write(struct.pack(">L", len(resp_server))[1:4])
  3616. f.write(resp_server)
  3617. f.write(struct.pack(">L", len(resp_ica))[1:4])
  3618. f.write(resp_ica)
  3619. f.close()
  3620. params["ocsp_stapling_response_multi"] = fn3
  3621. hostapd.add_ap(apdev[0], params)
  3622. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3623. identity="tls user",
  3624. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3625. client_cert="auth_serv/iCA-user/user.pem",
  3626. private_key="auth_serv/iCA-user/user.key",
  3627. scan_freq="2412", ocsp=3)
  3628. dev[0].request("REMOVE_NETWORK all")
  3629. dev[0].wait_disconnected()
  3630. finally:
  3631. os.unlink(fn)
  3632. os.unlink(fn2)
  3633. os.unlink(fn3)
  3634. def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
  3635. """EAP-TLS and CA signed OCSP multi response (revoked)"""
  3636. check_ocsp_support(dev[0])
  3637. check_ocsp_multi_support(dev[0])
  3638. ocsp_revoked = os.path.join(params['logdir'],
  3639. "ocsp-resp-ca-signed-revoked.der")
  3640. if not os.path.exists(ocsp_revoked):
  3641. raise HwsimSkip("No OCSP response (revoked) available")
  3642. ocsp_unknown = os.path.join(params['logdir'],
  3643. "ocsp-resp-ca-signed-unknown.der")
  3644. if not os.path.exists(ocsp_unknown):
  3645. raise HwsimSkip("No OCSP response(unknown) available")
  3646. with open(ocsp_revoked, "r") as f:
  3647. resp_revoked = f.read()
  3648. with open(ocsp_unknown, "r") as f:
  3649. resp_unknown = f.read()
  3650. fd, fn = tempfile.mkstemp()
  3651. try:
  3652. # This is not really a valid order of the OCSPResponse items in the
  3653. # list, but this works for now to verify parsing and processing of
  3654. # multiple responses.
  3655. f = os.fdopen(fd, 'w')
  3656. f.write(struct.pack(">L", len(resp_unknown))[1:4])
  3657. f.write(resp_unknown)
  3658. f.write(struct.pack(">L", len(resp_revoked))[1:4])
  3659. f.write(resp_revoked)
  3660. f.write(struct.pack(">L", 0)[1:4])
  3661. f.write(struct.pack(">L", len(resp_unknown))[1:4])
  3662. f.write(resp_unknown)
  3663. f.close()
  3664. params = int_eap_server_params()
  3665. params["ocsp_stapling_response_multi"] = fn
  3666. hostapd.add_ap(apdev[0], params)
  3667. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3668. identity="tls user", ca_cert="auth_serv/ca.pem",
  3669. private_key="auth_serv/user.pkcs12",
  3670. private_key_passwd="whatever", ocsp=1,
  3671. wait_connect=False, scan_freq="2412")
  3672. count = 0
  3673. while True:
  3674. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3675. "CTRL-EVENT-EAP-SUCCESS"])
  3676. if ev is None:
  3677. raise Exception("Timeout on EAP status")
  3678. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3679. raise Exception("Unexpected EAP-Success")
  3680. if 'bad certificate status response' in ev:
  3681. break
  3682. if 'certificate revoked' in ev:
  3683. break
  3684. count = count + 1
  3685. if count > 10:
  3686. raise Exception("Unexpected number of EAP status messages")
  3687. finally:
  3688. os.unlink(fn)
  3689. def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
  3690. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  3691. check_domain_match_full(dev[0])
  3692. params = int_eap_server_params()
  3693. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3694. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3695. hostapd.add_ap(apdev[0], params)
  3696. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3697. identity="tls user", ca_cert="auth_serv/ca.pem",
  3698. private_key="auth_serv/user.pkcs12",
  3699. private_key_passwd="whatever",
  3700. domain_suffix_match="server3.w1.fi",
  3701. scan_freq="2412")
  3702. def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
  3703. """WPA2-Enterprise using EAP-TLS and domainmatch (CN)"""
  3704. check_domain_match(dev[0])
  3705. params = int_eap_server_params()
  3706. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3707. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3708. hostapd.add_ap(apdev[0], params)
  3709. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3710. identity="tls user", ca_cert="auth_serv/ca.pem",
  3711. private_key="auth_serv/user.pkcs12",
  3712. private_key_passwd="whatever",
  3713. domain_match="server3.w1.fi",
  3714. scan_freq="2412")
  3715. def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
  3716. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  3717. check_domain_match_full(dev[0])
  3718. params = int_eap_server_params()
  3719. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3720. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3721. hostapd.add_ap(apdev[0], params)
  3722. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3723. identity="tls user", ca_cert="auth_serv/ca.pem",
  3724. private_key="auth_serv/user.pkcs12",
  3725. private_key_passwd="whatever",
  3726. domain_suffix_match="w1.fi",
  3727. scan_freq="2412")
  3728. def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
  3729. """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
  3730. check_domain_suffix_match(dev[0])
  3731. params = int_eap_server_params()
  3732. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3733. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3734. hostapd.add_ap(apdev[0], params)
  3735. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3736. identity="tls user", ca_cert="auth_serv/ca.pem",
  3737. private_key="auth_serv/user.pkcs12",
  3738. private_key_passwd="whatever",
  3739. domain_suffix_match="example.com",
  3740. wait_connect=False,
  3741. scan_freq="2412")
  3742. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3743. identity="tls user", ca_cert="auth_serv/ca.pem",
  3744. private_key="auth_serv/user.pkcs12",
  3745. private_key_passwd="whatever",
  3746. domain_suffix_match="erver3.w1.fi",
  3747. wait_connect=False,
  3748. scan_freq="2412")
  3749. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3750. if ev is None:
  3751. raise Exception("Timeout on EAP failure report")
  3752. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3753. if ev is None:
  3754. raise Exception("Timeout on EAP failure report (2)")
  3755. def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev):
  3756. """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)"""
  3757. check_domain_match(dev[0])
  3758. params = int_eap_server_params()
  3759. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3760. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3761. hostapd.add_ap(apdev[0], params)
  3762. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3763. identity="tls user", ca_cert="auth_serv/ca.pem",
  3764. private_key="auth_serv/user.pkcs12",
  3765. private_key_passwd="whatever",
  3766. domain_match="example.com",
  3767. wait_connect=False,
  3768. scan_freq="2412")
  3769. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3770. identity="tls user", ca_cert="auth_serv/ca.pem",
  3771. private_key="auth_serv/user.pkcs12",
  3772. private_key_passwd="whatever",
  3773. domain_match="w1.fi",
  3774. wait_connect=False,
  3775. scan_freq="2412")
  3776. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3777. if ev is None:
  3778. raise Exception("Timeout on EAP failure report")
  3779. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3780. if ev is None:
  3781. raise Exception("Timeout on EAP failure report (2)")
  3782. def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev):
  3783. """WPA2-Enterprise using EAP-TTLS and expired certificate"""
  3784. skip_with_fips(dev[0])
  3785. params = int_eap_server_params()
  3786. params["server_cert"] = "auth_serv/server-expired.pem"
  3787. params["private_key"] = "auth_serv/server-expired.key"
  3788. hostapd.add_ap(apdev[0], params)
  3789. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3790. identity="mschap user", password="password",
  3791. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3792. wait_connect=False,
  3793. scan_freq="2412")
  3794. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  3795. if ev is None:
  3796. raise Exception("Timeout on EAP certificate error report")
  3797. if "reason=4" not in ev or "certificate has expired" not in ev:
  3798. raise Exception("Unexpected failure reason: " + ev)
  3799. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3800. if ev is None:
  3801. raise Exception("Timeout on EAP failure report")
  3802. def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev):
  3803. """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration"""
  3804. skip_with_fips(dev[0])
  3805. params = int_eap_server_params()
  3806. params["server_cert"] = "auth_serv/server-expired.pem"
  3807. params["private_key"] = "auth_serv/server-expired.key"
  3808. hostapd.add_ap(apdev[0], params)
  3809. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3810. identity="mschap user", password="password",
  3811. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3812. phase1="tls_disable_time_checks=1",
  3813. scan_freq="2412")
  3814. def test_ap_wpa2_eap_ttls_long_duration(dev, apdev):
  3815. """WPA2-Enterprise using EAP-TTLS and long certificate duration"""
  3816. skip_with_fips(dev[0])
  3817. params = int_eap_server_params()
  3818. params["server_cert"] = "auth_serv/server-long-duration.pem"
  3819. params["private_key"] = "auth_serv/server-long-duration.key"
  3820. hostapd.add_ap(apdev[0], params)
  3821. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3822. identity="mschap user", password="password",
  3823. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3824. scan_freq="2412")
  3825. def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev):
  3826. """WPA2-Enterprise using EAP-TTLS and server cert with client EKU"""
  3827. skip_with_fips(dev[0])
  3828. params = int_eap_server_params()
  3829. params["server_cert"] = "auth_serv/server-eku-client.pem"
  3830. params["private_key"] = "auth_serv/server-eku-client.key"
  3831. hostapd.add_ap(apdev[0], params)
  3832. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3833. identity="mschap user", password="password",
  3834. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3835. wait_connect=False,
  3836. scan_freq="2412")
  3837. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3838. if ev is None:
  3839. raise Exception("Timeout on EAP failure report")
  3840. def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev):
  3841. """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU"""
  3842. skip_with_fips(dev[0])
  3843. params = int_eap_server_params()
  3844. params["server_cert"] = "auth_serv/server-eku-client-server.pem"
  3845. params["private_key"] = "auth_serv/server-eku-client-server.key"
  3846. hostapd.add_ap(apdev[0], params)
  3847. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3848. identity="mschap user", password="password",
  3849. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3850. scan_freq="2412")
  3851. def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev):
  3852. """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file"""
  3853. skip_with_fips(dev[0])
  3854. params = int_eap_server_params()
  3855. del params["server_cert"]
  3856. params["private_key"] = "auth_serv/server.pkcs12"
  3857. hostapd.add_ap(apdev[0], params)
  3858. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3859. identity="mschap user", password="password",
  3860. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3861. scan_freq="2412")
  3862. def test_ap_wpa2_eap_ttls_server_pkcs12_extra(dev, apdev):
  3863. """EAP-TTLS and server PKCS#12 file with extra certs"""
  3864. skip_with_fips(dev[0])
  3865. params = int_eap_server_params()
  3866. del params["server_cert"]
  3867. params["private_key"] = "auth_serv/server-extra.pkcs12"
  3868. params["private_key_passwd"] = "whatever"
  3869. hostapd.add_ap(apdev[0], params)
  3870. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3871. identity="mschap user", password="password",
  3872. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3873. scan_freq="2412")
  3874. def test_ap_wpa2_eap_ttls_dh_params(dev, apdev):
  3875. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params"""
  3876. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3877. hapd = hostapd.add_ap(apdev[0], params)
  3878. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3879. anonymous_identity="ttls", password="password",
  3880. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  3881. dh_file="auth_serv/dh.conf")
  3882. def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev):
  3883. """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)"""
  3884. check_dh_dsa_support(dev[0])
  3885. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3886. hapd = hostapd.add_ap(apdev[0], params)
  3887. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3888. anonymous_identity="ttls", password="password",
  3889. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  3890. dh_file="auth_serv/dsaparam.pem")
  3891. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  3892. """EAP-TTLS and DH params file not found"""
  3893. skip_with_fips(dev[0])
  3894. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3895. hostapd.add_ap(apdev[0], params)
  3896. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3897. identity="mschap user", password="password",
  3898. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3899. dh_file="auth_serv/dh-no-such-file.conf",
  3900. scan_freq="2412", wait_connect=False)
  3901. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3902. if ev is None:
  3903. raise Exception("EAP failure timed out")
  3904. dev[0].request("REMOVE_NETWORK all")
  3905. dev[0].wait_disconnected()
  3906. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  3907. """EAP-TTLS and invalid DH params file"""
  3908. skip_with_fips(dev[0])
  3909. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3910. hostapd.add_ap(apdev[0], params)
  3911. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3912. identity="mschap user", password="password",
  3913. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3914. dh_file="auth_serv/ca.pem",
  3915. scan_freq="2412", wait_connect=False)
  3916. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3917. if ev is None:
  3918. raise Exception("EAP failure timed out")
  3919. dev[0].request("REMOVE_NETWORK all")
  3920. dev[0].wait_disconnected()
  3921. def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
  3922. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob"""
  3923. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3924. hapd = hostapd.add_ap(apdev[0], params)
  3925. dh = read_pem("auth_serv/dh2.conf")
  3926. if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
  3927. raise Exception("Could not set dhparams blob")
  3928. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3929. anonymous_identity="ttls", password="password",
  3930. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  3931. dh_file="blob://dhparams")
  3932. def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev):
  3933. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams"""
  3934. params = int_eap_server_params()
  3935. params["dh_file"] = "auth_serv/dh2.conf"
  3936. hapd = hostapd.add_ap(apdev[0], params)
  3937. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3938. anonymous_identity="ttls", password="password",
  3939. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  3940. def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev):
  3941. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)"""
  3942. params = int_eap_server_params()
  3943. params["dh_file"] = "auth_serv/dsaparam.pem"
  3944. hapd = hostapd.add_ap(apdev[0], params)
  3945. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3946. anonymous_identity="ttls", password="password",
  3947. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  3948. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  3949. """EAP-TLS server and dhparams file not found"""
  3950. params = int_eap_server_params()
  3951. params["dh_file"] = "auth_serv/dh-no-such-file.conf"
  3952. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3953. if "FAIL" not in hapd.request("ENABLE"):
  3954. raise Exception("Invalid configuration accepted")
  3955. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  3956. """EAP-TLS server and invalid dhparams file"""
  3957. params = int_eap_server_params()
  3958. params["dh_file"] = "auth_serv/ca.pem"
  3959. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3960. if "FAIL" not in hapd.request("ENABLE"):
  3961. raise Exception("Invalid configuration accepted")
  3962. def test_ap_wpa2_eap_reauth(dev, apdev):
  3963. """WPA2-Enterprise and Authenticator forcing reauthentication"""
  3964. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3965. params['eap_reauth_period'] = '2'
  3966. hapd = hostapd.add_ap(apdev[0], params)
  3967. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  3968. password_hex="0123456789abcdef0123456789abcdef")
  3969. logger.info("Wait for reauthentication")
  3970. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  3971. if ev is None:
  3972. raise Exception("Timeout on reauthentication")
  3973. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3974. if ev is None:
  3975. raise Exception("Timeout on reauthentication")
  3976. for i in range(0, 20):
  3977. state = dev[0].get_status_field("wpa_state")
  3978. if state == "COMPLETED":
  3979. break
  3980. time.sleep(0.1)
  3981. if state != "COMPLETED":
  3982. raise Exception("Reauthentication did not complete")
  3983. def test_ap_wpa2_eap_request_identity_message(dev, apdev):
  3984. """Optional displayable message in EAP Request-Identity"""
  3985. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3986. params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com'
  3987. hapd = hostapd.add_ap(apdev[0], params)
  3988. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  3989. password_hex="0123456789abcdef0123456789abcdef")
  3990. def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev):
  3991. """WPA2-Enterprise using EAP-SIM/AKA and protected result indication"""
  3992. check_hlr_auc_gw_support()
  3993. params = int_eap_server_params()
  3994. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  3995. params['eap_sim_aka_result_ind'] = "1"
  3996. hapd = hostapd.add_ap(apdev[0], params)
  3997. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  3998. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  3999. phase1="result_ind=1")
  4000. eap_reauth(dev[0], "SIM")
  4001. eap_connect(dev[1], hapd, "SIM", "1232010000000000",
  4002. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  4003. dev[0].request("REMOVE_NETWORK all")
  4004. dev[1].request("REMOVE_NETWORK all")
  4005. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  4006. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  4007. phase1="result_ind=1")
  4008. eap_reauth(dev[0], "AKA")
  4009. eap_connect(dev[1], hapd, "AKA", "0232010000000000",
  4010. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  4011. dev[0].request("REMOVE_NETWORK all")
  4012. dev[1].request("REMOVE_NETWORK all")
  4013. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  4014. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  4015. phase1="result_ind=1")
  4016. eap_reauth(dev[0], "AKA'")
  4017. eap_connect(dev[1], hapd, "AKA'", "6555444333222111",
  4018. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  4019. def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev):
  4020. """WPA2-Enterprise connection resulting in too many EAP roundtrips"""
  4021. skip_with_fips(dev[0])
  4022. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4023. hostapd.add_ap(apdev[0], params)
  4024. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4025. eap="TTLS", identity="mschap user",
  4026. wait_connect=False, scan_freq="2412", ieee80211w="1",
  4027. anonymous_identity="ttls", password="password",
  4028. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4029. fragment_size="8")
  4030. ev = dev[0].wait_event(["EAP: more than",
  4031. "CTRL-EVENT-EAP-SUCCESS"], timeout=20)
  4032. if ev is None or "EAP: more than" not in ev:
  4033. raise Exception("EAP roundtrip limit not reached")
  4034. def test_ap_wpa2_eap_expanded_nak(dev, apdev):
  4035. """WPA2-Enterprise connection with EAP resulting in expanded NAK"""
  4036. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4037. hostapd.add_ap(apdev[0], params)
  4038. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4039. eap="PSK", identity="vendor-test",
  4040. password_hex="ff23456789abcdef0123456789abcdef",
  4041. wait_connect=False)
  4042. found = False
  4043. for i in range(0, 5):
  4044. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=16)
  4045. if ev is None:
  4046. raise Exception("Association and EAP start timed out")
  4047. if "refuse proposed method" in ev:
  4048. found = True
  4049. break
  4050. if not found:
  4051. raise Exception("Unexpected EAP status: " + ev)
  4052. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4053. if ev is None:
  4054. raise Exception("EAP failure timed out")
  4055. def test_ap_wpa2_eap_sql(dev, apdev, params):
  4056. """WPA2-Enterprise connection using SQLite for user DB"""
  4057. skip_with_fips(dev[0])
  4058. try:
  4059. import sqlite3
  4060. except ImportError:
  4061. raise HwsimSkip("No sqlite3 module available")
  4062. dbfile = os.path.join(params['logdir'], "eap-user.db")
  4063. try:
  4064. os.remove(dbfile)
  4065. except:
  4066. pass
  4067. con = sqlite3.connect(dbfile)
  4068. with con:
  4069. cur = con.cursor()
  4070. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  4071. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  4072. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)")
  4073. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)")
  4074. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)")
  4075. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)")
  4076. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  4077. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  4078. try:
  4079. params = int_eap_server_params()
  4080. params["eap_user_file"] = "sqlite:" + dbfile
  4081. hapd = hostapd.add_ap(apdev[0], params)
  4082. eap_connect(dev[0], hapd, "TTLS", "user-mschapv2",
  4083. anonymous_identity="ttls", password="password",
  4084. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4085. dev[0].request("REMOVE_NETWORK all")
  4086. eap_connect(dev[1], hapd, "TTLS", "user-mschap",
  4087. anonymous_identity="ttls", password="password",
  4088. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  4089. dev[1].request("REMOVE_NETWORK all")
  4090. eap_connect(dev[0], hapd, "TTLS", "user-chap",
  4091. anonymous_identity="ttls", password="password",
  4092. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP")
  4093. eap_connect(dev[1], hapd, "TTLS", "user-pap",
  4094. anonymous_identity="ttls", password="password",
  4095. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4096. finally:
  4097. os.remove(dbfile)
  4098. def test_ap_wpa2_eap_non_ascii_identity(dev, apdev):
  4099. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  4100. params = int_eap_server_params()
  4101. hostapd.add_ap(apdev[0], params)
  4102. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4103. identity="\x80", password="password", wait_connect=False)
  4104. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4105. identity="a\x80", password="password", wait_connect=False)
  4106. for i in range(0, 2):
  4107. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  4108. if ev is None:
  4109. raise Exception("Association and EAP start timed out")
  4110. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  4111. if ev is None:
  4112. raise Exception("EAP method selection timed out")
  4113. def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev):
  4114. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  4115. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4116. hostapd.add_ap(apdev[0], params)
  4117. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4118. identity="\x80", password="password", wait_connect=False)
  4119. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4120. identity="a\x80", password="password", wait_connect=False)
  4121. for i in range(0, 2):
  4122. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  4123. if ev is None:
  4124. raise Exception("Association and EAP start timed out")
  4125. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  4126. if ev is None:
  4127. raise Exception("EAP method selection timed out")
  4128. def test_openssl_cipher_suite_config_wpas(dev, apdev):
  4129. """OpenSSL cipher suite configuration on wpa_supplicant"""
  4130. tls = dev[0].request("GET tls_library")
  4131. if not tls.startswith("OpenSSL"):
  4132. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  4133. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4134. hapd = hostapd.add_ap(apdev[0], params)
  4135. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4136. anonymous_identity="ttls", password="password",
  4137. openssl_ciphers="AES128",
  4138. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4139. eap_connect(dev[1], hapd, "TTLS", "pap user",
  4140. anonymous_identity="ttls", password="password",
  4141. openssl_ciphers="EXPORT",
  4142. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4143. expect_failure=True, maybe_local_error=True)
  4144. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4145. identity="pap user", anonymous_identity="ttls",
  4146. password="password",
  4147. openssl_ciphers="FOO",
  4148. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4149. wait_connect=False)
  4150. ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4151. if ev is None:
  4152. raise Exception("EAP failure after invalid openssl_ciphers not reported")
  4153. dev[2].request("DISCONNECT")
  4154. def test_openssl_cipher_suite_config_hapd(dev, apdev):
  4155. """OpenSSL cipher suite configuration on hostapd"""
  4156. tls = dev[0].request("GET tls_library")
  4157. if not tls.startswith("OpenSSL"):
  4158. raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls)
  4159. params = int_eap_server_params()
  4160. params['openssl_ciphers'] = "AES256"
  4161. hapd = hostapd.add_ap(apdev[0], params)
  4162. tls = hapd.request("GET tls_library")
  4163. if not tls.startswith("OpenSSL"):
  4164. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  4165. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4166. anonymous_identity="ttls", password="password",
  4167. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4168. eap_connect(dev[1], hapd, "TTLS", "pap user",
  4169. anonymous_identity="ttls", password="password",
  4170. openssl_ciphers="AES128",
  4171. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4172. expect_failure=True)
  4173. eap_connect(dev[2], hapd, "TTLS", "pap user",
  4174. anonymous_identity="ttls", password="password",
  4175. openssl_ciphers="HIGH:!ADH",
  4176. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4177. params['openssl_ciphers'] = "FOO"
  4178. hapd2 = hostapd.add_ap(apdev[1], params, no_enable=True)
  4179. if "FAIL" not in hapd2.request("ENABLE"):
  4180. raise Exception("Invalid openssl_ciphers value accepted")
  4181. def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
  4182. """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
  4183. p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4184. hapd = hostapd.add_ap(apdev[0], p)
  4185. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  4186. pid = find_wpas_process(dev[0])
  4187. id = eap_connect(dev[0], hapd, "TTLS", "pap-secret",
  4188. anonymous_identity="ttls", password=password,
  4189. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4190. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  4191. # event has been delivered, so verify that wpa_supplicant has returned to
  4192. # eloop before reading process memory.
  4193. time.sleep(1)
  4194. dev[0].ping()
  4195. buf = read_process_memory(pid, password)
  4196. dev[0].request("DISCONNECT")
  4197. dev[0].wait_disconnected()
  4198. dev[0].relog()
  4199. msk = None
  4200. emsk = None
  4201. pmk = None
  4202. ptk = None
  4203. gtk = None
  4204. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  4205. for l in f.readlines():
  4206. if "EAP-TTLS: Derived key - hexdump" in l:
  4207. val = l.strip().split(':')[3].replace(' ', '')
  4208. msk = binascii.unhexlify(val)
  4209. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  4210. val = l.strip().split(':')[3].replace(' ', '')
  4211. emsk = binascii.unhexlify(val)
  4212. if "WPA: PMK - hexdump" in l:
  4213. val = l.strip().split(':')[3].replace(' ', '')
  4214. pmk = binascii.unhexlify(val)
  4215. if "WPA: PTK - hexdump" in l:
  4216. val = l.strip().split(':')[3].replace(' ', '')
  4217. ptk = binascii.unhexlify(val)
  4218. if "WPA: Group Key - hexdump" in l:
  4219. val = l.strip().split(':')[3].replace(' ', '')
  4220. gtk = binascii.unhexlify(val)
  4221. if not msk or not emsk or not pmk or not ptk or not gtk:
  4222. raise Exception("Could not find keys from debug log")
  4223. if len(gtk) != 16:
  4224. raise Exception("Unexpected GTK length")
  4225. kck = ptk[0:16]
  4226. kek = ptk[16:32]
  4227. tk = ptk[32:48]
  4228. fname = os.path.join(params['logdir'],
  4229. 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-')
  4230. logger.info("Checking keys in memory while associated")
  4231. get_key_locations(buf, password, "Password")
  4232. get_key_locations(buf, pmk, "PMK")
  4233. get_key_locations(buf, msk, "MSK")
  4234. get_key_locations(buf, emsk, "EMSK")
  4235. if password not in buf:
  4236. raise HwsimSkip("Password not found while associated")
  4237. if pmk not in buf:
  4238. raise HwsimSkip("PMK not found while associated")
  4239. if kck not in buf:
  4240. raise Exception("KCK not found while associated")
  4241. if kek not in buf:
  4242. raise Exception("KEK not found while associated")
  4243. if tk in buf:
  4244. raise Exception("TK found from memory")
  4245. if gtk in buf:
  4246. get_key_locations(buf, gtk, "GTK")
  4247. raise Exception("GTK found from memory")
  4248. logger.info("Checking keys in memory after disassociation")
  4249. buf = read_process_memory(pid, password)
  4250. # Note: Password is still present in network configuration
  4251. # Note: PMK is in PMKSA cache and EAP fast re-auth data
  4252. get_key_locations(buf, password, "Password")
  4253. get_key_locations(buf, pmk, "PMK")
  4254. get_key_locations(buf, msk, "MSK")
  4255. get_key_locations(buf, emsk, "EMSK")
  4256. verify_not_present(buf, kck, fname, "KCK")
  4257. verify_not_present(buf, kek, fname, "KEK")
  4258. verify_not_present(buf, tk, fname, "TK")
  4259. verify_not_present(buf, gtk, fname, "GTK")
  4260. dev[0].request("PMKSA_FLUSH")
  4261. dev[0].set_network_quoted(id, "identity", "foo")
  4262. logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush")
  4263. buf = read_process_memory(pid, password)
  4264. get_key_locations(buf, password, "Password")
  4265. get_key_locations(buf, pmk, "PMK")
  4266. get_key_locations(buf, msk, "MSK")
  4267. get_key_locations(buf, emsk, "EMSK")
  4268. verify_not_present(buf, pmk, fname, "PMK")
  4269. dev[0].request("REMOVE_NETWORK all")
  4270. logger.info("Checking keys in memory after network profile removal")
  4271. buf = read_process_memory(pid, password)
  4272. get_key_locations(buf, password, "Password")
  4273. get_key_locations(buf, pmk, "PMK")
  4274. get_key_locations(buf, msk, "MSK")
  4275. get_key_locations(buf, emsk, "EMSK")
  4276. verify_not_present(buf, password, fname, "password")
  4277. verify_not_present(buf, pmk, fname, "PMK")
  4278. verify_not_present(buf, kck, fname, "KCK")
  4279. verify_not_present(buf, kek, fname, "KEK")
  4280. verify_not_present(buf, tk, fname, "TK")
  4281. verify_not_present(buf, gtk, fname, "GTK")
  4282. verify_not_present(buf, msk, fname, "MSK")
  4283. verify_not_present(buf, emsk, fname, "EMSK")
  4284. def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev):
  4285. """WPA2-Enterprise connection and unexpected WEP EAPOL-Key"""
  4286. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4287. hapd = hostapd.add_ap(apdev[0], params)
  4288. bssid = apdev[0]['bssid']
  4289. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4290. anonymous_identity="ttls", password="password",
  4291. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4292. # Send unexpected WEP EAPOL-Key; this gets dropped
  4293. res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
  4294. if "OK" not in res:
  4295. raise Exception("EAPOL_RX to wpa_supplicant failed")
  4296. def test_ap_wpa2_eap_in_bridge(dev, apdev):
  4297. """WPA2-EAP and wpas interface in a bridge"""
  4298. br_ifname='sta-br0'
  4299. ifname='wlan5'
  4300. try:
  4301. _test_ap_wpa2_eap_in_bridge(dev, apdev)
  4302. finally:
  4303. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  4304. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  4305. subprocess.call(['brctl', 'delbr', br_ifname])
  4306. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  4307. def _test_ap_wpa2_eap_in_bridge(dev, apdev):
  4308. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4309. hapd = hostapd.add_ap(apdev[0], params)
  4310. br_ifname='sta-br0'
  4311. ifname='wlan5'
  4312. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  4313. subprocess.call(['brctl', 'addbr', br_ifname])
  4314. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  4315. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  4316. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  4317. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  4318. wpas.interface_add(ifname, br_ifname=br_ifname)
  4319. wpas.dump_monitor()
  4320. id = eap_connect(wpas, hapd, "PAX", "pax.user@example.com",
  4321. password_hex="0123456789abcdef0123456789abcdef")
  4322. wpas.dump_monitor()
  4323. eap_reauth(wpas, "PAX")
  4324. wpas.dump_monitor()
  4325. # Try again as a regression test for packet socket workaround
  4326. eap_reauth(wpas, "PAX")
  4327. wpas.dump_monitor()
  4328. wpas.request("DISCONNECT")
  4329. wpas.wait_disconnected()
  4330. wpas.dump_monitor()
  4331. wpas.request("RECONNECT")
  4332. wpas.wait_connected()
  4333. wpas.dump_monitor()
  4334. def test_ap_wpa2_eap_session_ticket(dev, apdev):
  4335. """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled"""
  4336. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4337. hapd = hostapd.add_ap(apdev[0], params)
  4338. key_mgmt = hapd.get_config()['key_mgmt']
  4339. if key_mgmt.split(' ')[0] != "WPA-EAP":
  4340. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  4341. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4342. anonymous_identity="ttls", password="password",
  4343. ca_cert="auth_serv/ca.pem",
  4344. phase1="tls_disable_session_ticket=0", phase2="auth=PAP")
  4345. eap_reauth(dev[0], "TTLS")
  4346. def test_ap_wpa2_eap_no_workaround(dev, apdev):
  4347. """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0"""
  4348. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4349. hapd = hostapd.add_ap(apdev[0], params)
  4350. key_mgmt = hapd.get_config()['key_mgmt']
  4351. if key_mgmt.split(' ')[0] != "WPA-EAP":
  4352. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  4353. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4354. anonymous_identity="ttls", password="password",
  4355. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4356. phase2="auth=PAP")
  4357. eap_reauth(dev[0], "TTLS")
  4358. def test_ap_wpa2_eap_tls_check_crl(dev, apdev):
  4359. """EAP-TLS and server checking CRL"""
  4360. params = int_eap_server_params()
  4361. params['check_crl'] = '1'
  4362. hapd = hostapd.add_ap(apdev[0], params)
  4363. # check_crl=1 and no CRL available --> reject connection
  4364. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4365. client_cert="auth_serv/user.pem",
  4366. private_key="auth_serv/user.key", expect_failure=True)
  4367. dev[0].request("REMOVE_NETWORK all")
  4368. hapd.disable()
  4369. hapd.set("ca_cert", "auth_serv/ca-and-crl.pem")
  4370. hapd.enable()
  4371. # check_crl=1 and valid CRL --> accept
  4372. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4373. client_cert="auth_serv/user.pem",
  4374. private_key="auth_serv/user.key")
  4375. dev[0].request("REMOVE_NETWORK all")
  4376. hapd.disable()
  4377. hapd.set("check_crl", "2")
  4378. hapd.enable()
  4379. # check_crl=2 and valid CRL --> accept
  4380. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4381. client_cert="auth_serv/user.pem",
  4382. private_key="auth_serv/user.key")
  4383. dev[0].request("REMOVE_NETWORK all")
  4384. def test_ap_wpa2_eap_tls_oom(dev, apdev):
  4385. """EAP-TLS and OOM"""
  4386. check_subject_match_support(dev[0])
  4387. check_altsubject_match_support(dev[0])
  4388. check_domain_match(dev[0])
  4389. check_domain_match_full(dev[0])
  4390. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4391. hostapd.add_ap(apdev[0], params)
  4392. tests = [ (1, "tls_connection_set_subject_match"),
  4393. (2, "tls_connection_set_subject_match"),
  4394. (3, "tls_connection_set_subject_match"),
  4395. (4, "tls_connection_set_subject_match") ]
  4396. for count, func in tests:
  4397. with alloc_fail(dev[0], count, func):
  4398. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4399. identity="tls user", ca_cert="auth_serv/ca.pem",
  4400. client_cert="auth_serv/user.pem",
  4401. private_key="auth_serv/user.key",
  4402. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  4403. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/",
  4404. domain_suffix_match="server.w1.fi",
  4405. domain_match="server.w1.fi",
  4406. wait_connect=False, scan_freq="2412")
  4407. # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE
  4408. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5)
  4409. if ev is None:
  4410. raise Exception("No passphrase request")
  4411. dev[0].request("REMOVE_NETWORK all")
  4412. dev[0].wait_disconnected()
  4413. def test_ap_wpa2_eap_tls_macacl(dev, apdev):
  4414. """WPA2-Enterprise connection using MAC ACL"""
  4415. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4416. params["macaddr_acl"] = "2"
  4417. hapd = hostapd.add_ap(apdev[0], params)
  4418. eap_connect(dev[1], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4419. client_cert="auth_serv/user.pem",
  4420. private_key="auth_serv/user.key")
  4421. def test_ap_wpa2_eap_oom(dev, apdev):
  4422. """EAP server and OOM"""
  4423. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4424. hapd = hostapd.add_ap(apdev[0], params)
  4425. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  4426. with alloc_fail(hapd, 1, "eapol_auth_alloc"):
  4427. # The first attempt fails, but STA will send EAPOL-Start to retry and
  4428. # that succeeds.
  4429. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4430. identity="tls user", ca_cert="auth_serv/ca.pem",
  4431. client_cert="auth_serv/user.pem",
  4432. private_key="auth_serv/user.key",
  4433. scan_freq="2412")
  4434. def check_tls_ver(dev, hapd, phase1, expected):
  4435. eap_connect(dev, hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4436. client_cert="auth_serv/user.pem",
  4437. private_key="auth_serv/user.key",
  4438. phase1=phase1)
  4439. ver = dev.get_status_field("eap_tls_version")
  4440. if ver != expected:
  4441. raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver))
  4442. def test_ap_wpa2_eap_tls_versions(dev, apdev):
  4443. """EAP-TLS and TLS version configuration"""
  4444. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4445. hapd = hostapd.add_ap(apdev[0], params)
  4446. tls = dev[0].request("GET tls_library")
  4447. if tls.startswith("OpenSSL"):
  4448. if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  4449. check_tls_ver(dev[0], hapd,
  4450. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
  4451. "TLSv1.2")
  4452. elif tls.startswith("internal"):
  4453. check_tls_ver(dev[0], hapd,
  4454. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", "TLSv1.2")
  4455. check_tls_ver(dev[1], hapd,
  4456. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1")
  4457. check_tls_ver(dev[2], hapd,
  4458. "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1")
  4459. def test_rsn_ie_proto_eap_sta(dev, apdev):
  4460. """RSN element protocol testing for EAP cases on STA side"""
  4461. bssid = apdev[0]['bssid']
  4462. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4463. # This is the RSN element used normally by hostapd
  4464. params['own_ie_override'] = '30140100000fac040100000fac040100000fac010c00'
  4465. hapd = hostapd.add_ap(apdev[0], params)
  4466. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4467. identity="gpsk user",
  4468. password="abcdefghijklmnop0123456789abcdef",
  4469. scan_freq="2412")
  4470. tests = [ ('No RSN Capabilities field',
  4471. '30120100000fac040100000fac040100000fac01'),
  4472. ('No AKM Suite fields',
  4473. '300c0100000fac040100000fac04'),
  4474. ('No Pairwise Cipher Suite fields',
  4475. '30060100000fac04'),
  4476. ('No Group Data Cipher Suite field',
  4477. '30020100') ]
  4478. for txt,ie in tests:
  4479. dev[0].request("DISCONNECT")
  4480. dev[0].wait_disconnected()
  4481. logger.info(txt)
  4482. hapd.disable()
  4483. hapd.set('own_ie_override', ie)
  4484. hapd.enable()
  4485. dev[0].request("BSS_FLUSH 0")
  4486. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  4487. dev[0].select_network(id, freq=2412)
  4488. dev[0].wait_connected()
  4489. dev[0].request("DISCONNECT")
  4490. dev[0].wait_disconnected()
  4491. dev[0].flush_scan_cache()
  4492. def check_tls_session_resumption_capa(dev, hapd):
  4493. tls = hapd.request("GET tls_library")
  4494. if not tls.startswith("OpenSSL"):
  4495. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  4496. tls = dev.request("GET tls_library")
  4497. if not tls.startswith("OpenSSL"):
  4498. raise HwsimSkip("Session resumption not supported with this TLS library: " + tls)
  4499. def test_eap_ttls_pap_session_resumption(dev, apdev):
  4500. """EAP-TTLS/PAP session resumption"""
  4501. params = int_eap_server_params()
  4502. params['tls_session_lifetime'] = '60'
  4503. hapd = hostapd.add_ap(apdev[0], params)
  4504. check_tls_session_resumption_capa(dev[0], hapd)
  4505. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4506. anonymous_identity="ttls", password="password",
  4507. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4508. phase2="auth=PAP")
  4509. if dev[0].get_status_field("tls_session_reused") != '0':
  4510. raise Exception("Unexpected session resumption on the first connection")
  4511. dev[0].request("REAUTHENTICATE")
  4512. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4513. if ev is None:
  4514. raise Exception("EAP success timed out")
  4515. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4516. if ev is None:
  4517. raise Exception("Key handshake with the AP timed out")
  4518. if dev[0].get_status_field("tls_session_reused") != '1':
  4519. raise Exception("Session resumption not used on the second connection")
  4520. def test_eap_ttls_chap_session_resumption(dev, apdev):
  4521. """EAP-TTLS/CHAP session resumption"""
  4522. params = int_eap_server_params()
  4523. params['tls_session_lifetime'] = '60'
  4524. hapd = hostapd.add_ap(apdev[0], params)
  4525. check_tls_session_resumption_capa(dev[0], hapd)
  4526. eap_connect(dev[0], hapd, "TTLS", "chap user",
  4527. anonymous_identity="ttls", password="password",
  4528. ca_cert="auth_serv/ca.der", phase2="auth=CHAP")
  4529. if dev[0].get_status_field("tls_session_reused") != '0':
  4530. raise Exception("Unexpected session resumption on the first connection")
  4531. dev[0].request("REAUTHENTICATE")
  4532. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4533. if ev is None:
  4534. raise Exception("EAP success timed out")
  4535. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4536. if ev is None:
  4537. raise Exception("Key handshake with the AP timed out")
  4538. if dev[0].get_status_field("tls_session_reused") != '1':
  4539. raise Exception("Session resumption not used on the second connection")
  4540. def test_eap_ttls_mschap_session_resumption(dev, apdev):
  4541. """EAP-TTLS/MSCHAP session resumption"""
  4542. check_domain_suffix_match(dev[0])
  4543. params = int_eap_server_params()
  4544. params['tls_session_lifetime'] = '60'
  4545. hapd = hostapd.add_ap(apdev[0], params)
  4546. check_tls_session_resumption_capa(dev[0], hapd)
  4547. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  4548. anonymous_identity="ttls", password="password",
  4549. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4550. domain_suffix_match="server.w1.fi")
  4551. if dev[0].get_status_field("tls_session_reused") != '0':
  4552. raise Exception("Unexpected session resumption on the first connection")
  4553. dev[0].request("REAUTHENTICATE")
  4554. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4555. if ev is None:
  4556. raise Exception("EAP success timed out")
  4557. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4558. if ev is None:
  4559. raise Exception("Key handshake with the AP timed out")
  4560. if dev[0].get_status_field("tls_session_reused") != '1':
  4561. raise Exception("Session resumption not used on the second connection")
  4562. def test_eap_ttls_mschapv2_session_resumption(dev, apdev):
  4563. """EAP-TTLS/MSCHAPv2 session resumption"""
  4564. check_domain_suffix_match(dev[0])
  4565. check_eap_capa(dev[0], "MSCHAPV2")
  4566. params = int_eap_server_params()
  4567. params['tls_session_lifetime'] = '60'
  4568. hapd = hostapd.add_ap(apdev[0], params)
  4569. check_tls_session_resumption_capa(dev[0], hapd)
  4570. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  4571. anonymous_identity="ttls", password="password",
  4572. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4573. domain_suffix_match="server.w1.fi")
  4574. if dev[0].get_status_field("tls_session_reused") != '0':
  4575. raise Exception("Unexpected session resumption on the first connection")
  4576. dev[0].request("REAUTHENTICATE")
  4577. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4578. if ev is None:
  4579. raise Exception("EAP success timed out")
  4580. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4581. if ev is None:
  4582. raise Exception("Key handshake with the AP timed out")
  4583. if dev[0].get_status_field("tls_session_reused") != '1':
  4584. raise Exception("Session resumption not used on the second connection")
  4585. def test_eap_ttls_eap_gtc_session_resumption(dev, apdev):
  4586. """EAP-TTLS/EAP-GTC session resumption"""
  4587. params = int_eap_server_params()
  4588. params['tls_session_lifetime'] = '60'
  4589. hapd = hostapd.add_ap(apdev[0], params)
  4590. check_tls_session_resumption_capa(dev[0], hapd)
  4591. eap_connect(dev[0], hapd, "TTLS", "user",
  4592. anonymous_identity="ttls", password="password",
  4593. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC")
  4594. if dev[0].get_status_field("tls_session_reused") != '0':
  4595. raise Exception("Unexpected session resumption on the first connection")
  4596. dev[0].request("REAUTHENTICATE")
  4597. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4598. if ev is None:
  4599. raise Exception("EAP success timed out")
  4600. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4601. if ev is None:
  4602. raise Exception("Key handshake with the AP timed out")
  4603. if dev[0].get_status_field("tls_session_reused") != '1':
  4604. raise Exception("Session resumption not used on the second connection")
  4605. def test_eap_ttls_no_session_resumption(dev, apdev):
  4606. """EAP-TTLS session resumption disabled on server"""
  4607. params = int_eap_server_params()
  4608. params['tls_session_lifetime'] = '0'
  4609. hapd = hostapd.add_ap(apdev[0], params)
  4610. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4611. anonymous_identity="ttls", password="password",
  4612. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4613. phase2="auth=PAP")
  4614. if dev[0].get_status_field("tls_session_reused") != '0':
  4615. raise Exception("Unexpected session resumption on the first connection")
  4616. dev[0].request("REAUTHENTICATE")
  4617. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4618. if ev is None:
  4619. raise Exception("EAP success timed out")
  4620. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4621. if ev is None:
  4622. raise Exception("Key handshake with the AP timed out")
  4623. if dev[0].get_status_field("tls_session_reused") != '0':
  4624. raise Exception("Unexpected session resumption on the second connection")
  4625. def test_eap_peap_session_resumption(dev, apdev):
  4626. """EAP-PEAP session resumption"""
  4627. params = int_eap_server_params()
  4628. params['tls_session_lifetime'] = '60'
  4629. hapd = hostapd.add_ap(apdev[0], params)
  4630. check_tls_session_resumption_capa(dev[0], hapd)
  4631. eap_connect(dev[0], hapd, "PEAP", "user",
  4632. anonymous_identity="peap", password="password",
  4633. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4634. if dev[0].get_status_field("tls_session_reused") != '0':
  4635. raise Exception("Unexpected session resumption on the first connection")
  4636. dev[0].request("REAUTHENTICATE")
  4637. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4638. if ev is None:
  4639. raise Exception("EAP success timed out")
  4640. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4641. if ev is None:
  4642. raise Exception("Key handshake with the AP timed out")
  4643. if dev[0].get_status_field("tls_session_reused") != '1':
  4644. raise Exception("Session resumption not used on the second connection")
  4645. def test_eap_peap_session_resumption_crypto_binding(dev, apdev):
  4646. """EAP-PEAP session resumption with crypto binding"""
  4647. params = int_eap_server_params()
  4648. params['tls_session_lifetime'] = '60'
  4649. hapd = hostapd.add_ap(apdev[0], params)
  4650. check_tls_session_resumption_capa(dev[0], hapd)
  4651. eap_connect(dev[0], hapd, "PEAP", "user",
  4652. anonymous_identity="peap", password="password",
  4653. phase1="peapver=0 crypto_binding=2",
  4654. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4655. if dev[0].get_status_field("tls_session_reused") != '0':
  4656. raise Exception("Unexpected session resumption on the first connection")
  4657. dev[0].request("REAUTHENTICATE")
  4658. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4659. if ev is None:
  4660. raise Exception("EAP success timed out")
  4661. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4662. if ev is None:
  4663. raise Exception("Key handshake with the AP timed out")
  4664. if dev[0].get_status_field("tls_session_reused") != '1':
  4665. raise Exception("Session resumption not used on the second connection")
  4666. def test_eap_peap_no_session_resumption(dev, apdev):
  4667. """EAP-PEAP session resumption disabled on server"""
  4668. params = int_eap_server_params()
  4669. hapd = hostapd.add_ap(apdev[0], params)
  4670. eap_connect(dev[0], hapd, "PEAP", "user",
  4671. anonymous_identity="peap", password="password",
  4672. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4673. if dev[0].get_status_field("tls_session_reused") != '0':
  4674. raise Exception("Unexpected session resumption on the first connection")
  4675. dev[0].request("REAUTHENTICATE")
  4676. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4677. if ev is None:
  4678. raise Exception("EAP success timed out")
  4679. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4680. if ev is None:
  4681. raise Exception("Key handshake with the AP timed out")
  4682. if dev[0].get_status_field("tls_session_reused") != '0':
  4683. raise Exception("Unexpected session resumption on the second connection")
  4684. def test_eap_tls_session_resumption(dev, apdev):
  4685. """EAP-TLS session resumption"""
  4686. params = int_eap_server_params()
  4687. params['tls_session_lifetime'] = '60'
  4688. hapd = hostapd.add_ap(apdev[0], params)
  4689. check_tls_session_resumption_capa(dev[0], hapd)
  4690. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4691. client_cert="auth_serv/user.pem",
  4692. private_key="auth_serv/user.key")
  4693. if dev[0].get_status_field("tls_session_reused") != '0':
  4694. raise Exception("Unexpected session resumption on the first connection")
  4695. dev[0].request("REAUTHENTICATE")
  4696. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4697. if ev is None:
  4698. raise Exception("EAP success timed out")
  4699. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4700. if ev is None:
  4701. raise Exception("Key handshake with the AP timed out")
  4702. if dev[0].get_status_field("tls_session_reused") != '1':
  4703. raise Exception("Session resumption not used on the second connection")
  4704. dev[0].request("REAUTHENTICATE")
  4705. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4706. if ev is None:
  4707. raise Exception("EAP success timed out")
  4708. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4709. if ev is None:
  4710. raise Exception("Key handshake with the AP timed out")
  4711. if dev[0].get_status_field("tls_session_reused") != '1':
  4712. raise Exception("Session resumption not used on the third connection")
  4713. def test_eap_tls_session_resumption_expiration(dev, apdev):
  4714. """EAP-TLS session resumption"""
  4715. params = int_eap_server_params()
  4716. params['tls_session_lifetime'] = '1'
  4717. hapd = hostapd.add_ap(apdev[0], params)
  4718. check_tls_session_resumption_capa(dev[0], hapd)
  4719. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4720. client_cert="auth_serv/user.pem",
  4721. private_key="auth_serv/user.key")
  4722. if dev[0].get_status_field("tls_session_reused") != '0':
  4723. raise Exception("Unexpected session resumption on the first connection")
  4724. # Allow multiple attempts since OpenSSL may not expire the cached entry
  4725. # immediately.
  4726. for i in range(10):
  4727. time.sleep(1.2)
  4728. dev[0].request("REAUTHENTICATE")
  4729. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4730. if ev is None:
  4731. raise Exception("EAP success timed out")
  4732. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4733. if ev is None:
  4734. raise Exception("Key handshake with the AP timed out")
  4735. if dev[0].get_status_field("tls_session_reused") == '0':
  4736. break
  4737. if dev[0].get_status_field("tls_session_reused") != '0':
  4738. raise Exception("Session resumption used after lifetime expiration")
  4739. def test_eap_tls_no_session_resumption(dev, apdev):
  4740. """EAP-TLS session resumption disabled on server"""
  4741. params = int_eap_server_params()
  4742. hapd = hostapd.add_ap(apdev[0], params)
  4743. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4744. client_cert="auth_serv/user.pem",
  4745. private_key="auth_serv/user.key")
  4746. if dev[0].get_status_field("tls_session_reused") != '0':
  4747. raise Exception("Unexpected session resumption on the first connection")
  4748. dev[0].request("REAUTHENTICATE")
  4749. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4750. if ev is None:
  4751. raise Exception("EAP success timed out")
  4752. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4753. if ev is None:
  4754. raise Exception("Key handshake with the AP timed out")
  4755. if dev[0].get_status_field("tls_session_reused") != '0':
  4756. raise Exception("Unexpected session resumption on the second connection")
  4757. def test_eap_tls_session_resumption_radius(dev, apdev):
  4758. """EAP-TLS session resumption (RADIUS)"""
  4759. params = { "ssid": "as", "beacon_int": "2000",
  4760. "radius_server_clients": "auth_serv/radius_clients.conf",
  4761. "radius_server_auth_port": '18128',
  4762. "eap_server": "1",
  4763. "eap_user_file": "auth_serv/eap_user.conf",
  4764. "ca_cert": "auth_serv/ca.pem",
  4765. "server_cert": "auth_serv/server.pem",
  4766. "private_key": "auth_serv/server.key",
  4767. "tls_session_lifetime": "60" }
  4768. authsrv = hostapd.add_ap(apdev[1], params)
  4769. check_tls_session_resumption_capa(dev[0], authsrv)
  4770. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4771. params['auth_server_port'] = "18128"
  4772. hapd = hostapd.add_ap(apdev[0], params)
  4773. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4774. client_cert="auth_serv/user.pem",
  4775. private_key="auth_serv/user.key")
  4776. if dev[0].get_status_field("tls_session_reused") != '0':
  4777. raise Exception("Unexpected session resumption on the first connection")
  4778. dev[0].request("REAUTHENTICATE")
  4779. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4780. if ev is None:
  4781. raise Exception("EAP success timed out")
  4782. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4783. if ev is None:
  4784. raise Exception("Key handshake with the AP timed out")
  4785. if dev[0].get_status_field("tls_session_reused") != '1':
  4786. raise Exception("Session resumption not used on the second connection")
  4787. def test_eap_tls_no_session_resumption_radius(dev, apdev):
  4788. """EAP-TLS session resumption disabled (RADIUS)"""
  4789. params = { "ssid": "as", "beacon_int": "2000",
  4790. "radius_server_clients": "auth_serv/radius_clients.conf",
  4791. "radius_server_auth_port": '18128',
  4792. "eap_server": "1",
  4793. "eap_user_file": "auth_serv/eap_user.conf",
  4794. "ca_cert": "auth_serv/ca.pem",
  4795. "server_cert": "auth_serv/server.pem",
  4796. "private_key": "auth_serv/server.key",
  4797. "tls_session_lifetime": "0" }
  4798. hostapd.add_ap(apdev[1], params)
  4799. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4800. params['auth_server_port'] = "18128"
  4801. hapd = hostapd.add_ap(apdev[0], params)
  4802. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4803. client_cert="auth_serv/user.pem",
  4804. private_key="auth_serv/user.key")
  4805. if dev[0].get_status_field("tls_session_reused") != '0':
  4806. raise Exception("Unexpected session resumption on the first connection")
  4807. dev[0].request("REAUTHENTICATE")
  4808. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4809. if ev is None:
  4810. raise Exception("EAP success timed out")
  4811. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4812. if ev is None:
  4813. raise Exception("Key handshake with the AP timed out")
  4814. if dev[0].get_status_field("tls_session_reused") != '0':
  4815. raise Exception("Unexpected session resumption on the second connection")
  4816. def test_eap_mschapv2_errors(dev, apdev):
  4817. """EAP-MSCHAPv2 error cases"""
  4818. check_eap_capa(dev[0], "MSCHAPV2")
  4819. check_eap_capa(dev[0], "FAST")
  4820. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  4821. hapd = hostapd.add_ap(apdev[0], params)
  4822. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4823. identity="phase1-user", password="password",
  4824. scan_freq="2412")
  4825. dev[0].request("REMOVE_NETWORK all")
  4826. dev[0].wait_disconnected()
  4827. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  4828. (1, "nt_password_hash;mschapv2_derive_response"),
  4829. (1, "nt_password_hash;=mschapv2_derive_response"),
  4830. (1, "generate_nt_response;mschapv2_derive_response"),
  4831. (1, "generate_authenticator_response;mschapv2_derive_response"),
  4832. (1, "nt_password_hash;=mschapv2_derive_response"),
  4833. (1, "get_master_key;mschapv2_derive_response"),
  4834. (1, "os_get_random;eap_mschapv2_challenge_reply") ]
  4835. for count, func in tests:
  4836. with fail_test(dev[0], count, func):
  4837. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4838. identity="phase1-user", password="password",
  4839. wait_connect=False, scan_freq="2412")
  4840. wait_fail_trigger(dev[0], "GET_FAIL")
  4841. dev[0].request("REMOVE_NETWORK all")
  4842. dev[0].wait_disconnected()
  4843. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  4844. (1, "hash_nt_password_hash;=mschapv2_derive_response"),
  4845. (1, "generate_nt_response_pwhash;mschapv2_derive_response"),
  4846. (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ]
  4847. for count, func in tests:
  4848. with fail_test(dev[0], count, func):
  4849. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4850. identity="phase1-user",
  4851. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  4852. wait_connect=False, scan_freq="2412")
  4853. wait_fail_trigger(dev[0], "GET_FAIL")
  4854. dev[0].request("REMOVE_NETWORK all")
  4855. dev[0].wait_disconnected()
  4856. tests = [ (1, "eap_mschapv2_init"),
  4857. (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"),
  4858. (1, "eap_msg_alloc;eap_mschapv2_success"),
  4859. (1, "eap_mschapv2_getKey") ]
  4860. for count, func in tests:
  4861. with alloc_fail(dev[0], count, func):
  4862. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4863. identity="phase1-user", password="password",
  4864. wait_connect=False, scan_freq="2412")
  4865. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4866. dev[0].request("REMOVE_NETWORK all")
  4867. dev[0].wait_disconnected()
  4868. tests = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ]
  4869. for count, func in tests:
  4870. with alloc_fail(dev[0], count, func):
  4871. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4872. identity="phase1-user", password="wrong password",
  4873. wait_connect=False, scan_freq="2412")
  4874. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4875. dev[0].request("REMOVE_NETWORK all")
  4876. dev[0].wait_disconnected()
  4877. tests = [ (2, "eap_mschapv2_init"),
  4878. (3, "eap_mschapv2_init") ]
  4879. for count, func in tests:
  4880. with alloc_fail(dev[0], count, func):
  4881. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST",
  4882. anonymous_identity="FAST", identity="user",
  4883. password="password",
  4884. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4885. phase1="fast_provisioning=1",
  4886. pac_file="blob://fast_pac",
  4887. wait_connect=False, scan_freq="2412")
  4888. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4889. dev[0].request("REMOVE_NETWORK all")
  4890. dev[0].wait_disconnected()
  4891. def test_eap_gpsk_errors(dev, apdev):
  4892. """EAP-GPSK error cases"""
  4893. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  4894. hapd = hostapd.add_ap(apdev[0], params)
  4895. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4896. identity="gpsk user",
  4897. password="abcdefghijklmnop0123456789abcdef",
  4898. scan_freq="2412")
  4899. dev[0].request("REMOVE_NETWORK all")
  4900. dev[0].wait_disconnected()
  4901. tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None),
  4902. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  4903. "cipher=1"),
  4904. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  4905. "cipher=2"),
  4906. (1, "eap_gpsk_derive_keys_helper", None),
  4907. (2, "eap_gpsk_derive_keys_helper", None),
  4908. (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  4909. "cipher=1"),
  4910. (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  4911. "cipher=2"),
  4912. (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None),
  4913. (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None),
  4914. (1, "eap_gpsk_derive_mid_helper", None) ]
  4915. for count, func, phase1 in tests:
  4916. with fail_test(dev[0], count, func):
  4917. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4918. identity="gpsk user",
  4919. password="abcdefghijklmnop0123456789abcdef",
  4920. phase1=phase1,
  4921. wait_connect=False, scan_freq="2412")
  4922. wait_fail_trigger(dev[0], "GET_FAIL")
  4923. dev[0].request("REMOVE_NETWORK all")
  4924. dev[0].wait_disconnected()
  4925. tests = [ (1, "eap_gpsk_init"),
  4926. (2, "eap_gpsk_init"),
  4927. (3, "eap_gpsk_init"),
  4928. (1, "eap_gpsk_process_id_server"),
  4929. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"),
  4930. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  4931. (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  4932. (1, "eap_gpsk_derive_keys"),
  4933. (1, "eap_gpsk_derive_keys_helper"),
  4934. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"),
  4935. (1, "eap_gpsk_getKey"),
  4936. (1, "eap_gpsk_get_emsk"),
  4937. (1, "eap_gpsk_get_session_id") ]
  4938. for count, func in tests:
  4939. with alloc_fail(dev[0], count, func):
  4940. dev[0].request("ERP_FLUSH")
  4941. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4942. identity="gpsk user", erp="1",
  4943. password="abcdefghijklmnop0123456789abcdef",
  4944. wait_connect=False, scan_freq="2412")
  4945. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4946. dev[0].request("REMOVE_NETWORK all")
  4947. dev[0].wait_disconnected()
  4948. def test_ap_wpa2_eap_sim_db(dev, apdev, params):
  4949. """EAP-SIM DB error cases"""
  4950. sockpath = '/tmp/hlr_auc_gw.sock-test'
  4951. try:
  4952. os.remove(sockpath)
  4953. except:
  4954. pass
  4955. hparams = int_eap_server_params()
  4956. hparams['eap_sim_db'] = 'unix:' + sockpath
  4957. hapd = hostapd.add_ap(apdev[0], hparams)
  4958. # Initial test with hlr_auc_gw socket not available
  4959. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4960. eap="SIM", identity="1232010000000000",
  4961. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4962. scan_freq="2412", wait_connect=False)
  4963. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4964. if ev is None:
  4965. raise Exception("EAP-Failure not reported")
  4966. dev[0].wait_disconnected()
  4967. dev[0].request("DISCONNECT")
  4968. # Test with invalid responses and response timeout
  4969. class test_handler(SocketServer.DatagramRequestHandler):
  4970. def handle(self):
  4971. data = self.request[0].strip()
  4972. socket = self.request[1]
  4973. logger.debug("Received hlr_auc_gw request: " + data)
  4974. # EAP-SIM DB: Failed to parse response string
  4975. socket.sendto("FOO", self.client_address)
  4976. # EAP-SIM DB: Failed to parse response string
  4977. socket.sendto("FOO 1", self.client_address)
  4978. # EAP-SIM DB: Unknown external response
  4979. socket.sendto("FOO 1 2", self.client_address)
  4980. logger.info("No proper response - wait for pending eap_sim_db request timeout")
  4981. server = SocketServer.UnixDatagramServer(sockpath, test_handler)
  4982. server.timeout = 1
  4983. dev[0].select_network(id)
  4984. server.handle_request()
  4985. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4986. if ev is None:
  4987. raise Exception("EAP-Failure not reported")
  4988. dev[0].wait_disconnected()
  4989. dev[0].request("DISCONNECT")
  4990. # Test with a valid response
  4991. class test_handler2(SocketServer.DatagramRequestHandler):
  4992. def handle(self):
  4993. data = self.request[0].strip()
  4994. socket = self.request[1]
  4995. logger.debug("Received hlr_auc_gw request: " + data)
  4996. fname = os.path.join(params['logdir'],
  4997. 'hlr_auc_gw.milenage_db')
  4998. cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw',
  4999. '-m', fname, data],
  5000. stdout=subprocess.PIPE)
  5001. res = cmd.stdout.read().strip()
  5002. cmd.stdout.close()
  5003. logger.debug("hlr_auc_gw response: " + res)
  5004. socket.sendto(res, self.client_address)
  5005. server.RequestHandlerClass = test_handler2
  5006. dev[0].select_network(id)
  5007. server.handle_request()
  5008. dev[0].wait_connected()
  5009. dev[0].request("DISCONNECT")
  5010. dev[0].wait_disconnected()
  5011. def test_eap_tls_sha512(dev, apdev, params):
  5012. """EAP-TLS with SHA512 signature"""
  5013. params = int_eap_server_params()
  5014. params["ca_cert"] = "auth_serv/sha512-ca.pem"
  5015. params["server_cert"] = "auth_serv/sha512-server.pem"
  5016. params["private_key"] = "auth_serv/sha512-server.key"
  5017. hostapd.add_ap(apdev[0], params)
  5018. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5019. identity="tls user sha512",
  5020. ca_cert="auth_serv/sha512-ca.pem",
  5021. client_cert="auth_serv/sha512-user.pem",
  5022. private_key="auth_serv/sha512-user.key",
  5023. scan_freq="2412")
  5024. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5025. identity="tls user sha512",
  5026. ca_cert="auth_serv/sha512-ca.pem",
  5027. client_cert="auth_serv/sha384-user.pem",
  5028. private_key="auth_serv/sha384-user.key",
  5029. scan_freq="2412")
  5030. def test_eap_tls_sha384(dev, apdev, params):
  5031. """EAP-TLS with SHA384 signature"""
  5032. params = int_eap_server_params()
  5033. params["ca_cert"] = "auth_serv/sha512-ca.pem"
  5034. params["server_cert"] = "auth_serv/sha384-server.pem"
  5035. params["private_key"] = "auth_serv/sha384-server.key"
  5036. hostapd.add_ap(apdev[0], params)
  5037. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5038. identity="tls user sha512",
  5039. ca_cert="auth_serv/sha512-ca.pem",
  5040. client_cert="auth_serv/sha512-user.pem",
  5041. private_key="auth_serv/sha512-user.key",
  5042. scan_freq="2412")
  5043. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5044. identity="tls user sha512",
  5045. ca_cert="auth_serv/sha512-ca.pem",
  5046. client_cert="auth_serv/sha384-user.pem",
  5047. private_key="auth_serv/sha384-user.key",
  5048. scan_freq="2412")
  5049. def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
  5050. """WPA2-Enterprise AP and association request RSN IE differences"""
  5051. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5052. hostapd.add_ap(apdev[0], params)
  5053. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap-11w")
  5054. params["ieee80211w"] = "2"
  5055. hostapd.add_ap(apdev[1], params)
  5056. # Success cases with optional RSN IE fields removed one by one
  5057. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  5058. "30140100000fac040100000fac040100000fac010000"),
  5059. ("Extra PMKIDCount field in RSN IE",
  5060. "30160100000fac040100000fac040100000fac0100000000"),
  5061. ("Extra Group Management Cipher Suite in RSN IE",
  5062. "301a0100000fac040100000fac040100000fac0100000000000fac06"),
  5063. ("Extra undefined extension field in RSN IE",
  5064. "301c0100000fac040100000fac040100000fac0100000000000fac061122"),
  5065. ("RSN IE without RSN Capabilities",
  5066. "30120100000fac040100000fac040100000fac01"),
  5067. ("RSN IE without AKM", "300c0100000fac040100000fac04"),
  5068. ("RSN IE without pairwise", "30060100000fac04"),
  5069. ("RSN IE without group", "30020100") ]
  5070. for title, ie in tests:
  5071. logger.info(title)
  5072. set_test_assoc_ie(dev[0], ie)
  5073. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5074. identity="gpsk user",
  5075. password="abcdefghijklmnop0123456789abcdef",
  5076. scan_freq="2412")
  5077. dev[0].request("REMOVE_NETWORK all")
  5078. dev[0].wait_disconnected()
  5079. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  5080. "30140100000fac040100000fac040100000fac01cc00"),
  5081. ("Group management cipher included in assoc req RSN IE",
  5082. "301a0100000fac040100000fac040100000fac01cc000000000fac06") ]
  5083. for title, ie in tests:
  5084. logger.info(title)
  5085. set_test_assoc_ie(dev[0], ie)
  5086. dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1",
  5087. eap="GPSK", identity="gpsk user",
  5088. password="abcdefghijklmnop0123456789abcdef",
  5089. scan_freq="2412")
  5090. dev[0].request("REMOVE_NETWORK all")
  5091. dev[0].wait_disconnected()
  5092. tests = [ ("Invalid group cipher", "30060100000fac02", 41),
  5093. ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42) ]
  5094. for title, ie, status in tests:
  5095. logger.info(title)
  5096. set_test_assoc_ie(dev[0], ie)
  5097. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5098. identity="gpsk user",
  5099. password="abcdefghijklmnop0123456789abcdef",
  5100. scan_freq="2412", wait_connect=False)
  5101. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  5102. if ev is None:
  5103. raise Exception("Association rejection not reported")
  5104. if "status_code=" + str(status) not in ev:
  5105. raise Exception("Unexpected status code: " + ev)
  5106. dev[0].request("REMOVE_NETWORK all")
  5107. dev[0].dump_monitor()
  5108. tests = [ ("Management frame protection not enabled",
  5109. "30140100000fac040100000fac040100000fac010000", 31),
  5110. ("Unsupported management group cipher",
  5111. "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 31) ]
  5112. for title, ie, status in tests:
  5113. logger.info(title)
  5114. set_test_assoc_ie(dev[0], ie)
  5115. dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1",
  5116. eap="GPSK", identity="gpsk user",
  5117. password="abcdefghijklmnop0123456789abcdef",
  5118. scan_freq="2412", wait_connect=False)
  5119. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  5120. if ev is None:
  5121. raise Exception("Association rejection not reported")
  5122. if "status_code=" + str(status) not in ev:
  5123. raise Exception("Unexpected status code: " + ev)
  5124. dev[0].request("REMOVE_NETWORK all")
  5125. dev[0].dump_monitor()
  5126. def test_eap_tls_ext_cert_check(dev, apdev):
  5127. """EAP-TLS and external server certification validation"""
  5128. # With internal server certificate chain validation
  5129. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5130. identity="tls user",
  5131. ca_cert="auth_serv/ca.pem",
  5132. client_cert="auth_serv/user.pem",
  5133. private_key="auth_serv/user.key",
  5134. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5135. only_add_network=True)
  5136. run_ext_cert_check(dev, apdev, id)
  5137. def test_eap_ttls_ext_cert_check(dev, apdev):
  5138. """EAP-TTLS and external server certification validation"""
  5139. # Without internal server certificate chain validation
  5140. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  5141. identity="pap user", anonymous_identity="ttls",
  5142. password="password", phase2="auth=PAP",
  5143. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5144. only_add_network=True)
  5145. run_ext_cert_check(dev, apdev, id)
  5146. def test_eap_peap_ext_cert_check(dev, apdev):
  5147. """EAP-PEAP and external server certification validation"""
  5148. # With internal server certificate chain validation
  5149. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  5150. identity="user", anonymous_identity="peap",
  5151. ca_cert="auth_serv/ca.pem",
  5152. password="password", phase2="auth=MSCHAPV2",
  5153. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5154. only_add_network=True)
  5155. run_ext_cert_check(dev, apdev, id)
  5156. def test_eap_fast_ext_cert_check(dev, apdev):
  5157. """EAP-FAST and external server certification validation"""
  5158. check_eap_capa(dev[0], "FAST")
  5159. # With internal server certificate chain validation
  5160. dev[0].request("SET blob fast_pac_auth_ext ")
  5161. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  5162. identity="user", anonymous_identity="FAST",
  5163. ca_cert="auth_serv/ca.pem",
  5164. password="password", phase2="auth=GTC",
  5165. phase1="tls_ext_cert_check=1 fast_provisioning=2",
  5166. pac_file="blob://fast_pac_auth_ext",
  5167. scan_freq="2412",
  5168. only_add_network=True)
  5169. run_ext_cert_check(dev, apdev, id)
  5170. def run_ext_cert_check(dev, apdev, net_id):
  5171. check_ext_cert_check_support(dev[0])
  5172. if not openssl_imported:
  5173. raise HwsimSkip("OpenSSL python method not available")
  5174. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5175. hapd = hostapd.add_ap(apdev[0], params)
  5176. dev[0].select_network(net_id)
  5177. certs = {}
  5178. while True:
  5179. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT",
  5180. "CTRL-REQ-EXT_CERT_CHECK",
  5181. "CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5182. if ev is None:
  5183. raise Exception("No peer server certificate event seen")
  5184. if "CTRL-EVENT-EAP-PEER-CERT" in ev:
  5185. depth = None
  5186. cert = None
  5187. vals = ev.split(' ')
  5188. for v in vals:
  5189. if v.startswith("depth="):
  5190. depth = int(v.split('=')[1])
  5191. elif v.startswith("cert="):
  5192. cert = v.split('=')[1]
  5193. if depth is not None and cert:
  5194. certs[depth] = binascii.unhexlify(cert)
  5195. elif "CTRL-EVENT-EAP-SUCCESS" in ev:
  5196. raise Exception("Unexpected EAP-Success")
  5197. elif "CTRL-REQ-EXT_CERT_CHECK" in ev:
  5198. id = ev.split(':')[0].split('-')[-1]
  5199. break
  5200. if 0 not in certs:
  5201. raise Exception("Server certificate not received")
  5202. if 1 not in certs:
  5203. raise Exception("Server certificate issuer not received")
  5204. cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
  5205. certs[0])
  5206. cn = cert.get_subject().commonName
  5207. logger.info("Server certificate CN=" + cn)
  5208. issuer = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
  5209. certs[1])
  5210. icn = issuer.get_subject().commonName
  5211. logger.info("Issuer certificate CN=" + icn)
  5212. if cn != "server.w1.fi":
  5213. raise Exception("Unexpected server certificate CN: " + cn)
  5214. if icn != "Root CA":
  5215. raise Exception("Unexpected server certificate issuer CN: " + icn)
  5216. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1)
  5217. if ev:
  5218. raise Exception("Unexpected EAP-Success before external check result indication")
  5219. dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":good")
  5220. dev[0].wait_connected()
  5221. dev[0].request("DISCONNECT")
  5222. dev[0].wait_disconnected()
  5223. if "FAIL" in dev[0].request("PMKSA_FLUSH"):
  5224. raise Exception("PMKSA_FLUSH failed")
  5225. dev[0].request("SET blob fast_pac_auth_ext ")
  5226. dev[0].request("RECONNECT")
  5227. ev = dev[0].wait_event(["CTRL-REQ-EXT_CERT_CHECK"], timeout=10)
  5228. if ev is None:
  5229. raise Exception("No peer server certificate event seen (2)")
  5230. id = ev.split(':')[0].split('-')[-1]
  5231. dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":bad")
  5232. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  5233. if ev is None:
  5234. raise Exception("EAP-Failure not reported")
  5235. dev[0].request("REMOVE_NETWORK all")
  5236. dev[0].wait_disconnected()
  5237. def test_eap_tls_errors(dev, apdev):
  5238. """EAP-TLS error cases"""
  5239. params = int_eap_server_params()
  5240. params['fragment_size'] = '100'
  5241. hostapd.add_ap(apdev[0], params)
  5242. with alloc_fail(dev[0], 1,
  5243. "eap_peer_tls_reassemble_fragment"):
  5244. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5245. identity="tls user", ca_cert="auth_serv/ca.pem",
  5246. client_cert="auth_serv/user.pem",
  5247. private_key="auth_serv/user.key",
  5248. wait_connect=False, scan_freq="2412")
  5249. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5250. dev[0].request("REMOVE_NETWORK all")
  5251. dev[0].wait_disconnected()
  5252. with alloc_fail(dev[0], 1, "eap_tls_init"):
  5253. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5254. identity="tls user", ca_cert="auth_serv/ca.pem",
  5255. client_cert="auth_serv/user.pem",
  5256. private_key="auth_serv/user.key",
  5257. wait_connect=False, scan_freq="2412")
  5258. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5259. dev[0].request("REMOVE_NETWORK all")
  5260. dev[0].wait_disconnected()
  5261. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init"):
  5262. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5263. identity="tls user", ca_cert="auth_serv/ca.pem",
  5264. client_cert="auth_serv/user.pem",
  5265. private_key="auth_serv/user.key",
  5266. engine="1",
  5267. wait_connect=False, scan_freq="2412")
  5268. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5269. ev = dev[0].wait_event(["CTRL-REQ-PIN"], timeout=5)
  5270. if ev is None:
  5271. raise Exception("No CTRL-REQ-PIN seen")
  5272. dev[0].request("REMOVE_NETWORK all")
  5273. dev[0].wait_disconnected()
  5274. tests = [ "eap_peer_tls_derive_key;eap_tls_success",
  5275. "eap_peer_tls_derive_session_id;eap_tls_success",
  5276. "eap_tls_getKey",
  5277. "eap_tls_get_emsk",
  5278. "eap_tls_get_session_id" ]
  5279. for func in tests:
  5280. with alloc_fail(dev[0], 1, func):
  5281. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5282. identity="tls user", ca_cert="auth_serv/ca.pem",
  5283. client_cert="auth_serv/user.pem",
  5284. private_key="auth_serv/user.key",
  5285. erp="1",
  5286. wait_connect=False, scan_freq="2412")
  5287. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5288. dev[0].request("REMOVE_NETWORK all")
  5289. dev[0].wait_disconnected()
  5290. with alloc_fail(dev[0], 1, "eap_unauth_tls_init"):
  5291. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS",
  5292. identity="unauth-tls", ca_cert="auth_serv/ca.pem",
  5293. wait_connect=False, scan_freq="2412")
  5294. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5295. dev[0].request("REMOVE_NETWORK all")
  5296. dev[0].wait_disconnected()
  5297. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_unauth_tls_init"):
  5298. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS",
  5299. identity="unauth-tls", ca_cert="auth_serv/ca.pem",
  5300. wait_connect=False, scan_freq="2412")
  5301. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5302. dev[0].request("REMOVE_NETWORK all")
  5303. dev[0].wait_disconnected()
  5304. with alloc_fail(dev[0], 1, "eap_wfa_unauth_tls_init"):
  5305. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  5306. eap="WFA-UNAUTH-TLS",
  5307. identity="osen@example.com", ca_cert="auth_serv/ca.pem",
  5308. wait_connect=False, scan_freq="2412")
  5309. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5310. dev[0].request("REMOVE_NETWORK all")
  5311. dev[0].wait_disconnected()
  5312. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_wfa_unauth_tls_init"):
  5313. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  5314. eap="WFA-UNAUTH-TLS",
  5315. identity="osen@example.com", ca_cert="auth_serv/ca.pem",
  5316. wait_connect=False, scan_freq="2412")
  5317. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5318. dev[0].request("REMOVE_NETWORK all")
  5319. dev[0].wait_disconnected()
  5320. def test_ap_wpa2_eap_status(dev, apdev):
  5321. """EAP state machine status information"""
  5322. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5323. hostapd.add_ap(apdev[0], params)
  5324. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  5325. identity="cert user",
  5326. ca_cert="auth_serv/ca.pem", phase2="auth=TLS",
  5327. ca_cert2="auth_serv/ca.pem",
  5328. client_cert2="auth_serv/user.pem",
  5329. private_key2="auth_serv/user.key",
  5330. scan_freq="2412", wait_connect=False)
  5331. success = False
  5332. states = []
  5333. method_states = []
  5334. decisions = []
  5335. req_methods = []
  5336. selected_methods = []
  5337. for i in range(100000):
  5338. s = dev[0].get_status(extra="VERBOSE")
  5339. if 'EAP state' in s:
  5340. state = s['EAP state']
  5341. if state:
  5342. if state not in states:
  5343. states.append(state)
  5344. if state == "SUCCESS":
  5345. success = True
  5346. break
  5347. if 'methodState' in s:
  5348. val = s['methodState']
  5349. if val not in method_states:
  5350. method_states.append(val)
  5351. if 'decision' in s:
  5352. val = s['decision']
  5353. if val not in decisions:
  5354. decisions.append(val)
  5355. if 'reqMethod' in s:
  5356. val = s['reqMethod']
  5357. if val not in req_methods:
  5358. req_methods.append(val)
  5359. if 'selectedMethod' in s:
  5360. val = s['selectedMethod']
  5361. if val not in selected_methods:
  5362. selected_methods.append(val)
  5363. logger.info("Iterations: %d" % i)
  5364. logger.info("EAP states: " + str(states))
  5365. logger.info("methodStates: " + str(method_states))
  5366. logger.info("decisions: " + str(decisions))
  5367. logger.info("reqMethods: " + str(req_methods))
  5368. logger.info("selectedMethods: " + str(selected_methods))
  5369. if not success:
  5370. raise Exception("EAP did not succeed")
  5371. dev[0].wait_connected()
  5372. dev[0].request("REMOVE_NETWORK all")
  5373. dev[0].wait_disconnected()
  5374. def test_ap_wpa2_eap_gpsk_ptk_rekey_ap(dev, apdev):
  5375. """WPA2-Enterprise with EAP-GPSK and PTK rekey enforced by AP"""
  5376. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5377. params['wpa_ptk_rekey'] = '2'
  5378. hapd = hostapd.add_ap(apdev[0], params)
  5379. id = eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  5380. password="abcdefghijklmnop0123456789abcdef")
  5381. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  5382. if ev is None:
  5383. raise Exception("PTK rekey timed out")
  5384. hwsim_utils.test_connectivity(dev[0], hapd)
  5385. def test_ap_wpa2_eap_wildcard_ssid(dev, apdev):
  5386. """WPA2-Enterprise connection using EAP-GPSK and wildcard SSID"""
  5387. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5388. hapd = hostapd.add_ap(apdev[0], params)
  5389. dev[0].connect(bssid=apdev[0]['bssid'], key_mgmt="WPA-EAP", eap="GPSK",
  5390. identity="gpsk user",
  5391. password="abcdefghijklmnop0123456789abcdef",
  5392. scan_freq="2412")