test_ap_eap.py 267 KB

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