test_ap_eap.py 254 KB

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