test_ap_eap.py 266 KB

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