test_ap_eap.py 266 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945
  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. hapd = hostapd.add_ap(apdev[0], params)
  2588. tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
  2589. "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
  2590. None, "password"),
  2591. ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
  2592. "TTLS", "ttls", None, "auth=MSCHAPV2",
  2593. "DOMAIN\mschapv2 user", "password"),
  2594. ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
  2595. "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
  2596. ("Connection with dynamic TTLS/EAP-MD5 password entry",
  2597. "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
  2598. ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
  2599. "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
  2600. ("Connection with dynamic PEAP/EAP-GTC password entry",
  2601. "PEAP", None, "user", "auth=GTC", None, "password") ]
  2602. for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
  2603. logger.info(desc)
  2604. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
  2605. anonymous_identity=anon, identity=identity,
  2606. ca_cert="auth_serv/ca.pem", phase2=phase2,
  2607. wait_connect=False, scan_freq="2412")
  2608. if req_id:
  2609. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2610. if ev is None:
  2611. raise Exception("Request for identity timed out")
  2612. id = ev.split(':')[0].split('-')[-1]
  2613. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2614. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
  2615. if ev is None:
  2616. raise Exception("Request for password timed out")
  2617. id = ev.split(':')[0].split('-')[-1]
  2618. type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD"
  2619. dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw)
  2620. dev[0].wait_connected(timeout=10)
  2621. dev[0].request("REMOVE_NETWORK all")
  2622. def test_ap_wpa2_eap_ext_enable_network_while_connected(dev, apdev):
  2623. """WPA2-Enterprise interactive identity entry and ENABLE_NETWORK"""
  2624. check_eap_capa(dev[0], "MSCHAPV2")
  2625. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2626. hapd = hostapd.add_ap(apdev[0], params)
  2627. id_other = dev[0].connect("other", key_mgmt="NONE", scan_freq="2412",
  2628. only_add_network=True)
  2629. req_id = "DOMAIN\mschapv2 user"
  2630. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2631. anonymous_identity="ttls", identity=None,
  2632. password="password",
  2633. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2634. wait_connect=False, scan_freq="2412")
  2635. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2636. if ev is None:
  2637. raise Exception("Request for identity timed out")
  2638. id = ev.split(':')[0].split('-')[-1]
  2639. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2640. dev[0].wait_connected(timeout=10)
  2641. if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id_other)):
  2642. raise Exception("Failed to enable network")
  2643. ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=1)
  2644. if ev is not None:
  2645. raise Exception("Unexpected reconnection attempt on ENABLE_NETWORK")
  2646. dev[0].request("REMOVE_NETWORK all")
  2647. def test_ap_wpa2_eap_vendor_test(dev, apdev):
  2648. """WPA2-Enterprise connection using EAP vendor test"""
  2649. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2650. hapd = hostapd.add_ap(apdev[0], params)
  2651. eap_connect(dev[0], hapd, "VENDOR-TEST", "vendor-test")
  2652. eap_reauth(dev[0], "VENDOR-TEST")
  2653. eap_connect(dev[1], hapd, "VENDOR-TEST", "vendor-test",
  2654. password="pending")
  2655. def test_ap_wpa2_eap_vendor_test_oom(dev, apdev):
  2656. """WPA2-Enterprise connection using EAP vendor test (OOM)"""
  2657. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2658. hostapd.add_ap(apdev[0], params)
  2659. tests = [ "eap_vendor_test_init",
  2660. "eap_msg_alloc;eap_vendor_test_process",
  2661. "eap_vendor_test_getKey" ]
  2662. for func in tests:
  2663. with alloc_fail(dev[0], 1, func):
  2664. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  2665. scan_freq="2412",
  2666. eap="VENDOR-TEST", identity="vendor-test",
  2667. wait_connect=False)
  2668. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2669. dev[0].request("REMOVE_NETWORK all")
  2670. dev[0].wait_disconnected()
  2671. def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev):
  2672. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning"""
  2673. check_eap_capa(dev[0], "FAST")
  2674. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2675. hapd = hostapd.add_ap(apdev[0], params)
  2676. eap_connect(dev[0], hapd, "FAST", "user",
  2677. anonymous_identity="FAST", password="password",
  2678. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2679. phase1="fast_provisioning=1", pac_file="blob://fast_pac")
  2680. hwsim_utils.test_connectivity(dev[0], hapd)
  2681. res = eap_reauth(dev[0], "FAST")
  2682. if res['tls_session_reused'] != '1':
  2683. raise Exception("EAP-FAST could not use PAC session ticket")
  2684. def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params):
  2685. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file"""
  2686. check_eap_capa(dev[0], "FAST")
  2687. pac_file = os.path.join(params['logdir'], "fast.pac")
  2688. pac_file2 = os.path.join(params['logdir'], "fast-bin.pac")
  2689. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2690. hapd = hostapd.add_ap(apdev[0], params)
  2691. try:
  2692. eap_connect(dev[0], hapd, "FAST", "user",
  2693. anonymous_identity="FAST", password="password",
  2694. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2695. phase1="fast_provisioning=1", pac_file=pac_file)
  2696. with open(pac_file, "r") as f:
  2697. data = f.read()
  2698. if "wpa_supplicant EAP-FAST PAC file - version 1" not in data:
  2699. raise Exception("PAC file header missing")
  2700. if "PAC-Key=" not in data:
  2701. raise Exception("PAC-Key missing from PAC file")
  2702. dev[0].request("REMOVE_NETWORK all")
  2703. eap_connect(dev[0], hapd, "FAST", "user",
  2704. anonymous_identity="FAST", password="password",
  2705. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2706. pac_file=pac_file)
  2707. eap_connect(dev[1], hapd, "FAST", "user",
  2708. anonymous_identity="FAST", password="password",
  2709. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2710. phase1="fast_provisioning=1 fast_pac_format=binary",
  2711. pac_file=pac_file2)
  2712. dev[1].request("REMOVE_NETWORK all")
  2713. eap_connect(dev[1], hapd, "FAST", "user",
  2714. anonymous_identity="FAST", password="password",
  2715. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2716. phase1="fast_pac_format=binary",
  2717. pac_file=pac_file2)
  2718. finally:
  2719. try:
  2720. os.remove(pac_file)
  2721. except:
  2722. pass
  2723. try:
  2724. os.remove(pac_file2)
  2725. except:
  2726. pass
  2727. def test_ap_wpa2_eap_fast_binary_pac(dev, apdev):
  2728. """WPA2-Enterprise connection using EAP-FAST and binary PAC format"""
  2729. check_eap_capa(dev[0], "FAST")
  2730. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2731. hapd = hostapd.add_ap(apdev[0], params)
  2732. eap_connect(dev[0], hapd, "FAST", "user",
  2733. anonymous_identity="FAST", password="password",
  2734. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2735. phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary",
  2736. pac_file="blob://fast_pac_bin")
  2737. res = eap_reauth(dev[0], "FAST")
  2738. if res['tls_session_reused'] != '1':
  2739. raise Exception("EAP-FAST could not use PAC session ticket")
  2740. # Verify fast_max_pac_list_len=0 special case
  2741. dev[0].request("REMOVE_NETWORK all")
  2742. dev[0].wait_disconnected()
  2743. eap_connect(dev[0], hapd, "FAST", "user",
  2744. anonymous_identity="FAST", password="password",
  2745. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2746. phase1="fast_provisioning=1 fast_max_pac_list_len=0 fast_pac_format=binary",
  2747. pac_file="blob://fast_pac_bin")
  2748. def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev):
  2749. """WPA2-Enterprise connection using EAP-FAST and missing PAC config"""
  2750. check_eap_capa(dev[0], "FAST")
  2751. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2752. hostapd.add_ap(apdev[0], params)
  2753. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2754. identity="user", anonymous_identity="FAST",
  2755. password="password",
  2756. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2757. pac_file="blob://fast_pac_not_in_use",
  2758. wait_connect=False, scan_freq="2412")
  2759. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2760. if ev is None:
  2761. raise Exception("Timeout on EAP failure report")
  2762. dev[0].request("REMOVE_NETWORK all")
  2763. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2764. identity="user", anonymous_identity="FAST",
  2765. password="password",
  2766. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2767. wait_connect=False, scan_freq="2412")
  2768. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2769. if ev is None:
  2770. raise Exception("Timeout on EAP failure report")
  2771. def test_ap_wpa2_eap_fast_binary_pac_errors(dev, apdev):
  2772. """EAP-FAST and binary PAC errors"""
  2773. check_eap_capa(dev[0], "FAST")
  2774. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2775. hapd = hostapd.add_ap(apdev[0], params)
  2776. tests = [ (1, "=eap_fast_save_pac_bin"),
  2777. (1, "eap_fast_write_pac"),
  2778. (2, "eap_fast_write_pac"), ]
  2779. for count, func in tests:
  2780. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors "):
  2781. raise Exception("Could not set blob")
  2782. with alloc_fail(dev[0], count, func):
  2783. eap_connect(dev[0], hapd, "FAST", "user",
  2784. anonymous_identity="FAST", password="password",
  2785. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2786. phase1="fast_provisioning=1 fast_pac_format=binary",
  2787. pac_file="blob://fast_pac_bin_errors")
  2788. dev[0].request("REMOVE_NETWORK all")
  2789. dev[0].wait_disconnected()
  2790. tests = [ "00", "000000000000", "6ae4920c0001",
  2791. "6ae4920c000000",
  2792. "6ae4920c0000" + "0000" + 32*"00" + "ffff" + "0000",
  2793. "6ae4920c0000" + "0000" + 32*"00" + "0001" + "0000",
  2794. "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0001",
  2795. "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0008" + "00040000" + "0007000100"]
  2796. for t in tests:
  2797. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + t):
  2798. raise Exception("Could not set blob")
  2799. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2800. identity="user", anonymous_identity="FAST",
  2801. password="password",
  2802. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2803. phase1="fast_provisioning=1 fast_pac_format=binary",
  2804. pac_file="blob://fast_pac_bin_errors",
  2805. scan_freq="2412", wait_connect=False)
  2806. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2807. timeout=5)
  2808. if ev is None:
  2809. raise Exception("Failure not reported")
  2810. dev[0].request("REMOVE_NETWORK all")
  2811. dev[0].wait_disconnected()
  2812. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0000"
  2813. tests = [ (1, "eap_fast_load_pac_bin"),
  2814. (2, "eap_fast_load_pac_bin"),
  2815. (3, "eap_fast_load_pac_bin") ]
  2816. for count, func in tests:
  2817. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2818. raise Exception("Could not set blob")
  2819. with alloc_fail(dev[0], count, func):
  2820. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2821. identity="user", anonymous_identity="FAST",
  2822. password="password",
  2823. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2824. phase1="fast_provisioning=1 fast_pac_format=binary",
  2825. pac_file="blob://fast_pac_bin_errors",
  2826. scan_freq="2412", wait_connect=False)
  2827. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"],
  2828. timeout=5)
  2829. if ev is None:
  2830. raise Exception("Failure not reported")
  2831. dev[0].request("REMOVE_NETWORK all")
  2832. dev[0].wait_disconnected()
  2833. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0005" + "0011223344"
  2834. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2835. raise Exception("Could not set blob")
  2836. eap_connect(dev[0], hapd, "FAST", "user",
  2837. anonymous_identity="FAST", password="password",
  2838. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2839. phase1="fast_provisioning=1 fast_pac_format=binary",
  2840. pac_file="blob://fast_pac_bin_errors")
  2841. dev[0].request("REMOVE_NETWORK all")
  2842. dev[0].wait_disconnected()
  2843. pac = "6ae4920c0000" + "0000" + 32*"00" + "0000" + "0009" + "00040000" + "0007000100"
  2844. tests = [ (1, "eap_fast_pac_get_a_id"),
  2845. (2, "eap_fast_pac_get_a_id") ]
  2846. for count, func in tests:
  2847. if "OK" not in dev[0].request("SET blob fast_pac_bin_errors " + pac):
  2848. raise Exception("Could not set blob")
  2849. with alloc_fail(dev[0], count, func):
  2850. eap_connect(dev[0], hapd, "FAST", "user",
  2851. anonymous_identity="FAST", password="password",
  2852. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2853. phase1="fast_provisioning=1 fast_pac_format=binary",
  2854. pac_file="blob://fast_pac_bin_errors")
  2855. dev[0].request("REMOVE_NETWORK all")
  2856. dev[0].wait_disconnected()
  2857. def test_ap_wpa2_eap_fast_text_pac_errors(dev, apdev):
  2858. """EAP-FAST and text PAC errors"""
  2859. check_eap_capa(dev[0], "FAST")
  2860. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2861. hostapd.add_ap(apdev[0], params)
  2862. tests = [ (1, "eap_fast_parse_hex;eap_fast_parse_pac_key"),
  2863. (1, "eap_fast_parse_hex;eap_fast_parse_pac_opaque"),
  2864. (1, "eap_fast_parse_hex;eap_fast_parse_a_id"),
  2865. (1, "eap_fast_parse_start"),
  2866. (1, "eap_fast_save_pac") ]
  2867. for count, func in tests:
  2868. dev[0].request("FLUSH")
  2869. if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
  2870. raise Exception("Could not set blob")
  2871. with alloc_fail(dev[0], count, func):
  2872. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2873. identity="user", anonymous_identity="FAST",
  2874. password="password",
  2875. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2876. phase1="fast_provisioning=1",
  2877. pac_file="blob://fast_pac_text_errors",
  2878. scan_freq="2412", wait_connect=False)
  2879. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  2880. dev[0].request("REMOVE_NETWORK all")
  2881. dev[0].wait_disconnected()
  2882. pac = "wpa_supplicant EAP-FAST PAC file - version 1\n"
  2883. pac += "START\n"
  2884. pac += "PAC-Type\n"
  2885. pac += "END\n"
  2886. if "OK" not in dev[0].request("SET blob fast_pac_text_errors " + pac.encode("hex")):
  2887. raise Exception("Could not set blob")
  2888. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2889. identity="user", anonymous_identity="FAST",
  2890. password="password",
  2891. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2892. phase1="fast_provisioning=1",
  2893. pac_file="blob://fast_pac_text_errors",
  2894. scan_freq="2412", wait_connect=False)
  2895. ev = dev[0].wait_event(["EAP: Failed to initialize EAP method"], timeout=5)
  2896. if ev is None:
  2897. raise Exception("Failure not reported")
  2898. dev[0].request("REMOVE_NETWORK all")
  2899. dev[0].wait_disconnected()
  2900. dev[0].request("FLUSH")
  2901. if "OK" not in dev[0].request("SET blob fast_pac_text_errors "):
  2902. raise Exception("Could not set blob")
  2903. with alloc_fail(dev[0], 1, "eap_fast_add_pac_data"):
  2904. for i in range(3):
  2905. params = int_eap_server_params()
  2906. params['ssid'] = "test-wpa2-eap-2"
  2907. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2908. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2909. params['eap_fast_a_id_info'] = "test server %d" % i
  2910. hapd2 = hostapd.add_ap(apdev[1], params)
  2911. dev[0].connect("test-wpa2-eap-2", key_mgmt="WPA-EAP", eap="FAST",
  2912. identity="user", anonymous_identity="FAST",
  2913. password="password",
  2914. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2915. phase1="fast_provisioning=1",
  2916. pac_file="blob://fast_pac_text_errors",
  2917. scan_freq="2412", wait_connect=False)
  2918. dev[0].wait_connected()
  2919. dev[0].request("REMOVE_NETWORK all")
  2920. dev[0].wait_disconnected()
  2921. hapd2.disable()
  2922. def test_ap_wpa2_eap_fast_pac_truncate(dev, apdev):
  2923. """EAP-FAST and PAC list truncation"""
  2924. check_eap_capa(dev[0], "FAST")
  2925. if "OK" not in dev[0].request("SET blob fast_pac_truncate "):
  2926. raise Exception("Could not set blob")
  2927. for i in range(5):
  2928. params = int_eap_server_params()
  2929. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2930. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2931. params['eap_fast_a_id_info'] = "test server %d" % i
  2932. hapd = hostapd.add_ap(apdev[0], params)
  2933. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2934. identity="user", anonymous_identity="FAST",
  2935. password="password",
  2936. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2937. phase1="fast_provisioning=1 fast_max_pac_list_len=2",
  2938. pac_file="blob://fast_pac_truncate",
  2939. scan_freq="2412", wait_connect=False)
  2940. dev[0].wait_connected()
  2941. dev[0].request("REMOVE_NETWORK all")
  2942. dev[0].wait_disconnected()
  2943. hapd.disable()
  2944. def test_ap_wpa2_eap_fast_pac_refresh(dev, apdev):
  2945. """EAP-FAST and PAC refresh"""
  2946. check_eap_capa(dev[0], "FAST")
  2947. if "OK" not in dev[0].request("SET blob fast_pac_refresh "):
  2948. raise Exception("Could not set blob")
  2949. for i in range(2):
  2950. params = int_eap_server_params()
  2951. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2952. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2953. params['eap_fast_a_id_info'] = "test server %d" % i
  2954. params['pac_key_refresh_time'] = "1"
  2955. params['pac_key_lifetime'] = "10"
  2956. hapd = hostapd.add_ap(apdev[0], params)
  2957. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2958. identity="user", anonymous_identity="FAST",
  2959. password="password",
  2960. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2961. phase1="fast_provisioning=1",
  2962. pac_file="blob://fast_pac_refresh",
  2963. scan_freq="2412", wait_connect=False)
  2964. dev[0].wait_connected()
  2965. dev[0].request("REMOVE_NETWORK all")
  2966. dev[0].wait_disconnected()
  2967. hapd.disable()
  2968. for i in range(2):
  2969. params = int_eap_server_params()
  2970. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2971. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2972. params['eap_fast_a_id_info'] = "test server %d" % i
  2973. params['pac_key_refresh_time'] = "10"
  2974. params['pac_key_lifetime'] = "10"
  2975. hapd = hostapd.add_ap(apdev[0], params)
  2976. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2977. identity="user", anonymous_identity="FAST",
  2978. password="password",
  2979. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2980. phase1="fast_provisioning=1",
  2981. pac_file="blob://fast_pac_refresh",
  2982. scan_freq="2412", wait_connect=False)
  2983. dev[0].wait_connected()
  2984. dev[0].request("REMOVE_NETWORK all")
  2985. dev[0].wait_disconnected()
  2986. hapd.disable()
  2987. def test_ap_wpa2_eap_fast_pac_lifetime(dev, apdev):
  2988. """EAP-FAST and PAC lifetime"""
  2989. check_eap_capa(dev[0], "FAST")
  2990. if "OK" not in dev[0].request("SET blob fast_pac_refresh "):
  2991. raise Exception("Could not set blob")
  2992. i = 0
  2993. params = int_eap_server_params()
  2994. params['pac_opaque_encr_key'] = "000102030405060708090a0b0c0dff%02x" % i
  2995. params['eap_fast_a_id'] = "101112131415161718191a1b1c1dff%02x" % i
  2996. params['eap_fast_a_id_info'] = "test server %d" % i
  2997. params['pac_key_refresh_time'] = "0"
  2998. params['pac_key_lifetime'] = "2"
  2999. hapd = hostapd.add_ap(apdev[0], params)
  3000. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3001. identity="user", anonymous_identity="FAST",
  3002. password="password",
  3003. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3004. phase1="fast_provisioning=2",
  3005. pac_file="blob://fast_pac_refresh",
  3006. scan_freq="2412", wait_connect=False)
  3007. dev[0].wait_connected()
  3008. dev[0].request("DISCONNECT")
  3009. dev[0].wait_disconnected()
  3010. time.sleep(3)
  3011. dev[0].request("PMKSA_FLUSH")
  3012. dev[0].request("RECONNECT")
  3013. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3014. if ev is None:
  3015. raise Exception("No EAP-Failure seen after expired PAC")
  3016. dev[0].request("DISCONNECT")
  3017. dev[0].wait_disconnected()
  3018. dev[0].select_network(id)
  3019. dev[0].wait_connected()
  3020. dev[0].request("REMOVE_NETWORK all")
  3021. dev[0].wait_disconnected()
  3022. def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev):
  3023. """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning"""
  3024. check_eap_capa(dev[0], "FAST")
  3025. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3026. hapd = hostapd.add_ap(apdev[0], params)
  3027. eap_connect(dev[0], hapd, "FAST", "user",
  3028. anonymous_identity="FAST", password="password",
  3029. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3030. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth")
  3031. hwsim_utils.test_connectivity(dev[0], hapd)
  3032. res = eap_reauth(dev[0], "FAST")
  3033. if res['tls_session_reused'] != '1':
  3034. raise Exception("EAP-FAST could not use PAC session ticket")
  3035. def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev):
  3036. """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing"""
  3037. check_eap_capa(dev[0], "FAST")
  3038. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3039. hapd = hostapd.add_ap(apdev[0], params)
  3040. id = eap_connect(dev[0], hapd, "FAST", "user",
  3041. anonymous_identity="FAST", password="password",
  3042. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3043. phase1="fast_provisioning=2",
  3044. pac_file="blob://fast_pac_auth")
  3045. dev[0].set_network_quoted(id, "identity", "user2")
  3046. dev[0].wait_disconnected()
  3047. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  3048. if ev is None:
  3049. raise Exception("EAP-FAST not started")
  3050. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  3051. if ev is None:
  3052. raise Exception("EAP failure not reported")
  3053. dev[0].wait_disconnected()
  3054. def test_ap_wpa2_eap_fast_prf_oom(dev, apdev):
  3055. """WPA2-Enterprise connection using EAP-FAST and OOM in PRF"""
  3056. check_eap_capa(dev[0], "FAST")
  3057. tls = dev[0].request("GET tls_library")
  3058. if tls.startswith("OpenSSL"):
  3059. func = "openssl_tls_prf"
  3060. count = 2
  3061. elif tls.startswith("internal"):
  3062. func = "tls_connection_prf"
  3063. count = 1
  3064. else:
  3065. raise HwsimSkip("Unsupported TLS library")
  3066. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3067. hapd = hostapd.add_ap(apdev[0], params)
  3068. with alloc_fail(dev[0], count, func):
  3069. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  3070. identity="user", anonymous_identity="FAST",
  3071. password="password", ca_cert="auth_serv/ca.pem",
  3072. phase2="auth=GTC",
  3073. phase1="fast_provisioning=2",
  3074. pac_file="blob://fast_pac_auth",
  3075. wait_connect=False, scan_freq="2412")
  3076. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  3077. if ev is None:
  3078. raise Exception("EAP failure not reported")
  3079. dev[0].request("DISCONNECT")
  3080. def test_ap_wpa2_eap_fast_server_oom(dev, apdev):
  3081. """EAP-FAST/MSCHAPv2 and server OOM"""
  3082. check_eap_capa(dev[0], "FAST")
  3083. params = int_eap_server_params()
  3084. params['dh_file'] = 'auth_serv/dh.conf'
  3085. params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f'
  3086. params['eap_fast_a_id'] = '1011'
  3087. params['eap_fast_a_id_info'] = 'another test server'
  3088. hapd = hostapd.add_ap(apdev[0], params)
  3089. with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"):
  3090. id = eap_connect(dev[0], hapd, "FAST", "user",
  3091. anonymous_identity="FAST", password="password",
  3092. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3093. phase1="fast_provisioning=1",
  3094. pac_file="blob://fast_pac",
  3095. expect_failure=True)
  3096. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3097. if ev is None:
  3098. raise Exception("No EAP failure reported")
  3099. dev[0].wait_disconnected()
  3100. dev[0].request("DISCONNECT")
  3101. dev[0].select_network(id, freq="2412")
  3102. def test_ap_wpa2_eap_fast_cipher_suites(dev, apdev):
  3103. """EAP-FAST and different TLS cipher suites"""
  3104. check_eap_capa(dev[0], "FAST")
  3105. tls = dev[0].request("GET tls_library")
  3106. if not tls.startswith("OpenSSL"):
  3107. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  3108. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3109. hapd = hostapd.add_ap(apdev[0], params)
  3110. dev[0].request("SET blob fast_pac_ciphers ")
  3111. eap_connect(dev[0], hapd, "FAST", "user",
  3112. anonymous_identity="FAST", password="password",
  3113. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3114. phase1="fast_provisioning=2",
  3115. pac_file="blob://fast_pac_ciphers")
  3116. res = dev[0].get_status_field('EAP TLS cipher')
  3117. dev[0].request("REMOVE_NETWORK all")
  3118. dev[0].wait_disconnected()
  3119. if res != "DHE-RSA-AES256-SHA":
  3120. raise Exception("Unexpected cipher suite for provisioning: " + res)
  3121. tests = [ "DHE-RSA-AES128-SHA",
  3122. "RC4-SHA",
  3123. "AES128-SHA",
  3124. "AES256-SHA",
  3125. "DHE-RSA-AES256-SHA" ]
  3126. for cipher in tests:
  3127. dev[0].dump_monitor()
  3128. logger.info("Testing " + cipher)
  3129. try:
  3130. eap_connect(dev[0], hapd, "FAST", "user",
  3131. openssl_ciphers=cipher,
  3132. anonymous_identity="FAST", password="password",
  3133. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  3134. pac_file="blob://fast_pac_ciphers")
  3135. except Exception, e:
  3136. if "Could not select EAP method" in str(e) and cipher == "RC4-SHA":
  3137. tls = dev[0].request("GET tls_library")
  3138. if "run=OpenSSL 1.1" in tls:
  3139. logger.info("Allow failure due to missing TLS library support")
  3140. dev[0].request("REMOVE_NETWORK all")
  3141. dev[0].wait_disconnected()
  3142. continue
  3143. raise
  3144. res = dev[0].get_status_field('EAP TLS cipher')
  3145. dev[0].request("REMOVE_NETWORK all")
  3146. dev[0].wait_disconnected()
  3147. if res != cipher:
  3148. raise Exception("Unexpected TLS cipher info (configured %s): %s" % (cipher, res))
  3149. def test_ap_wpa2_eap_tls_ocsp(dev, apdev):
  3150. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP"""
  3151. check_ocsp_support(dev[0])
  3152. check_pkcs12_support(dev[0])
  3153. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3154. hapd = hostapd.add_ap(apdev[0], params)
  3155. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3156. private_key="auth_serv/user.pkcs12",
  3157. private_key_passwd="whatever", ocsp=2)
  3158. def test_ap_wpa2_eap_tls_ocsp_multi(dev, apdev):
  3159. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP-multi"""
  3160. check_ocsp_multi_support(dev[0])
  3161. check_pkcs12_support(dev[0])
  3162. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3163. hapd = hostapd.add_ap(apdev[0], params)
  3164. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3165. private_key="auth_serv/user.pkcs12",
  3166. private_key_passwd="whatever", ocsp=2)
  3167. def int_eap_server_params():
  3168. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  3169. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  3170. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  3171. "ca_cert": "auth_serv/ca.pem",
  3172. "server_cert": "auth_serv/server.pem",
  3173. "private_key": "auth_serv/server.key",
  3174. "dh_file": "auth_serv/dh.conf" }
  3175. return params
  3176. def test_ap_wpa2_eap_tls_ocsp_key_id(dev, apdev, params):
  3177. """EAP-TLS and OCSP certificate signed OCSP response using key ID"""
  3178. check_ocsp_support(dev[0])
  3179. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-key-id.der")
  3180. if not os.path.exists(ocsp):
  3181. raise HwsimSkip("No OCSP response available")
  3182. params = int_eap_server_params()
  3183. params["ocsp_stapling_response"] = ocsp
  3184. hostapd.add_ap(apdev[0], params)
  3185. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3186. identity="tls user", ca_cert="auth_serv/ca.pem",
  3187. private_key="auth_serv/user.pkcs12",
  3188. private_key_passwd="whatever", ocsp=2,
  3189. scan_freq="2412")
  3190. def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params):
  3191. """EAP-TLS and CA signed OCSP response (good)"""
  3192. check_ocsp_support(dev[0])
  3193. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der")
  3194. if not os.path.exists(ocsp):
  3195. raise HwsimSkip("No OCSP response available")
  3196. params = int_eap_server_params()
  3197. params["ocsp_stapling_response"] = ocsp
  3198. hostapd.add_ap(apdev[0], params)
  3199. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3200. identity="tls user", ca_cert="auth_serv/ca.pem",
  3201. private_key="auth_serv/user.pkcs12",
  3202. private_key_passwd="whatever", ocsp=2,
  3203. scan_freq="2412")
  3204. def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params):
  3205. """EAP-TLS and CA signed OCSP response (revoked)"""
  3206. check_ocsp_support(dev[0])
  3207. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der")
  3208. if not os.path.exists(ocsp):
  3209. raise HwsimSkip("No OCSP response available")
  3210. params = int_eap_server_params()
  3211. params["ocsp_stapling_response"] = ocsp
  3212. hostapd.add_ap(apdev[0], params)
  3213. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3214. identity="tls user", ca_cert="auth_serv/ca.pem",
  3215. private_key="auth_serv/user.pkcs12",
  3216. private_key_passwd="whatever", ocsp=2,
  3217. wait_connect=False, scan_freq="2412")
  3218. count = 0
  3219. while True:
  3220. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3221. if ev is None:
  3222. raise Exception("Timeout on EAP status")
  3223. if 'bad certificate status response' in ev:
  3224. break
  3225. if 'certificate revoked' in ev:
  3226. break
  3227. count = count + 1
  3228. if count > 10:
  3229. raise Exception("Unexpected number of EAP status messages")
  3230. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3231. if ev is None:
  3232. raise Exception("Timeout on EAP failure report")
  3233. def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params):
  3234. """EAP-TLS and CA signed OCSP response (unknown)"""
  3235. check_ocsp_support(dev[0])
  3236. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der")
  3237. if not os.path.exists(ocsp):
  3238. raise HwsimSkip("No OCSP response available")
  3239. params = int_eap_server_params()
  3240. params["ocsp_stapling_response"] = ocsp
  3241. hostapd.add_ap(apdev[0], params)
  3242. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3243. identity="tls user", ca_cert="auth_serv/ca.pem",
  3244. private_key="auth_serv/user.pkcs12",
  3245. private_key_passwd="whatever", ocsp=2,
  3246. wait_connect=False, scan_freq="2412")
  3247. count = 0
  3248. while True:
  3249. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3250. if ev is None:
  3251. raise Exception("Timeout on EAP status")
  3252. if 'bad certificate status response' in ev:
  3253. break
  3254. count = count + 1
  3255. if count > 10:
  3256. raise Exception("Unexpected number of EAP status messages")
  3257. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3258. if ev is None:
  3259. raise Exception("Timeout on EAP failure report")
  3260. def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params):
  3261. """EAP-TLS and server signed OCSP response"""
  3262. check_ocsp_support(dev[0])
  3263. ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der")
  3264. if not os.path.exists(ocsp):
  3265. raise HwsimSkip("No OCSP response available")
  3266. params = int_eap_server_params()
  3267. params["ocsp_stapling_response"] = ocsp
  3268. hostapd.add_ap(apdev[0], params)
  3269. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3270. identity="tls user", ca_cert="auth_serv/ca.pem",
  3271. private_key="auth_serv/user.pkcs12",
  3272. private_key_passwd="whatever", ocsp=2,
  3273. wait_connect=False, scan_freq="2412")
  3274. count = 0
  3275. while True:
  3276. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3277. if ev is None:
  3278. raise Exception("Timeout on EAP status")
  3279. if 'bad certificate status response' in ev:
  3280. break
  3281. count = count + 1
  3282. if count > 10:
  3283. raise Exception("Unexpected number of EAP status messages")
  3284. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3285. if ev is None:
  3286. raise Exception("Timeout on EAP failure report")
  3287. def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
  3288. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data"""
  3289. check_ocsp_support(dev[0])
  3290. params = int_eap_server_params()
  3291. params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der"
  3292. hostapd.add_ap(apdev[0], params)
  3293. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3294. identity="tls user", ca_cert="auth_serv/ca.pem",
  3295. private_key="auth_serv/user.pkcs12",
  3296. private_key_passwd="whatever", ocsp=2,
  3297. wait_connect=False, scan_freq="2412")
  3298. count = 0
  3299. while True:
  3300. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3301. if ev is None:
  3302. raise Exception("Timeout on EAP status")
  3303. if 'bad certificate status response' in ev:
  3304. break
  3305. count = count + 1
  3306. if count > 10:
  3307. raise Exception("Unexpected number of EAP status messages")
  3308. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3309. if ev is None:
  3310. raise Exception("Timeout on EAP failure report")
  3311. def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
  3312. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
  3313. check_ocsp_support(dev[0])
  3314. params = int_eap_server_params()
  3315. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
  3316. hostapd.add_ap(apdev[0], params)
  3317. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3318. identity="tls user", ca_cert="auth_serv/ca.pem",
  3319. private_key="auth_serv/user.pkcs12",
  3320. private_key_passwd="whatever", ocsp=2,
  3321. wait_connect=False, scan_freq="2412")
  3322. count = 0
  3323. while True:
  3324. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3325. if ev is None:
  3326. raise Exception("Timeout on EAP status")
  3327. if 'bad certificate status response' in ev:
  3328. break
  3329. count = count + 1
  3330. if count > 10:
  3331. raise Exception("Unexpected number of EAP status messages")
  3332. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3333. if ev is None:
  3334. raise Exception("Timeout on EAP failure report")
  3335. def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev):
  3336. """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer"""
  3337. check_ocsp_support(dev[0])
  3338. params = int_eap_server_params()
  3339. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign"
  3340. hostapd.add_ap(apdev[0], params)
  3341. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3342. identity="tls user", ca_cert="auth_serv/ca.pem",
  3343. private_key="auth_serv/user.pkcs12",
  3344. private_key_passwd="whatever", ocsp=2,
  3345. wait_connect=False, scan_freq="2412")
  3346. count = 0
  3347. while True:
  3348. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3349. if ev is None:
  3350. raise Exception("Timeout on EAP status")
  3351. if 'bad certificate status response' in ev:
  3352. break
  3353. count = count + 1
  3354. if count > 10:
  3355. raise Exception("Unexpected number of EAP status messages")
  3356. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3357. if ev is None:
  3358. raise Exception("Timeout on EAP failure report")
  3359. def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params):
  3360. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3361. check_ocsp_support(dev[0])
  3362. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der")
  3363. if not os.path.exists(ocsp):
  3364. raise HwsimSkip("No OCSP response available")
  3365. params = int_eap_server_params()
  3366. params["ocsp_stapling_response"] = ocsp
  3367. hostapd.add_ap(apdev[0], params)
  3368. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3369. identity="pap user", ca_cert="auth_serv/ca.pem",
  3370. anonymous_identity="ttls", password="password",
  3371. phase2="auth=PAP", ocsp=2,
  3372. wait_connect=False, scan_freq="2412")
  3373. count = 0
  3374. while True:
  3375. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3376. if ev is None:
  3377. raise Exception("Timeout on EAP status")
  3378. if 'bad certificate status response' in ev:
  3379. break
  3380. if 'certificate revoked' in ev:
  3381. break
  3382. count = count + 1
  3383. if count > 10:
  3384. raise Exception("Unexpected number of EAP status messages")
  3385. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3386. if ev is None:
  3387. raise Exception("Timeout on EAP failure report")
  3388. def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params):
  3389. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3390. check_ocsp_support(dev[0])
  3391. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  3392. if not os.path.exists(ocsp):
  3393. raise HwsimSkip("No OCSP response available")
  3394. params = int_eap_server_params()
  3395. params["ocsp_stapling_response"] = ocsp
  3396. hostapd.add_ap(apdev[0], params)
  3397. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3398. identity="pap user", ca_cert="auth_serv/ca.pem",
  3399. anonymous_identity="ttls", password="password",
  3400. phase2="auth=PAP", ocsp=2,
  3401. wait_connect=False, scan_freq="2412")
  3402. count = 0
  3403. while True:
  3404. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  3405. if ev is None:
  3406. raise Exception("Timeout on EAP status")
  3407. if 'bad certificate status response' in ev:
  3408. break
  3409. count = count + 1
  3410. if count > 10:
  3411. raise Exception("Unexpected number of EAP status messages")
  3412. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3413. if ev is None:
  3414. raise Exception("Timeout on EAP failure report")
  3415. def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params):
  3416. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  3417. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  3418. if not os.path.exists(ocsp):
  3419. raise HwsimSkip("No OCSP response available")
  3420. params = int_eap_server_params()
  3421. params["ocsp_stapling_response"] = ocsp
  3422. hostapd.add_ap(apdev[0], params)
  3423. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3424. identity="pap user", ca_cert="auth_serv/ca.pem",
  3425. anonymous_identity="ttls", password="password",
  3426. phase2="auth=PAP", ocsp=1, scan_freq="2412")
  3427. def test_ap_wpa2_eap_tls_intermediate_ca(dev, apdev, params):
  3428. """EAP-TLS with intermediate server/user CA"""
  3429. params = int_eap_server_params()
  3430. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3431. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3432. params["private_key"] = "auth_serv/iCA-server/server.key"
  3433. hostapd.add_ap(apdev[0], params)
  3434. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3435. identity="tls user",
  3436. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3437. client_cert="auth_serv/iCA-user/user.pem",
  3438. private_key="auth_serv/iCA-user/user.key",
  3439. scan_freq="2412")
  3440. def root_ocsp(cert):
  3441. ca = "auth_serv/ca.pem"
  3442. fd2, fn2 = tempfile.mkstemp()
  3443. os.close(fd2)
  3444. arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-cert", cert,
  3445. "-no_nonce", "-sha256", "-text" ]
  3446. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3447. stderr=subprocess.PIPE)
  3448. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3449. cmd.stdout.close()
  3450. cmd.stderr.close()
  3451. logger.info("OCSP request:\n" + res)
  3452. fd, fn = tempfile.mkstemp()
  3453. os.close(fd)
  3454. arg = [ "openssl", "ocsp", "-index", "auth_serv/rootCA/index.txt",
  3455. "-rsigner", ca, "-rkey", "auth_serv/ca-key.pem",
  3456. "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
  3457. "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
  3458. "-text" ]
  3459. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3460. stderr=subprocess.PIPE)
  3461. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3462. cmd.stdout.close()
  3463. cmd.stderr.close()
  3464. logger.info("OCSP response:\n" + res)
  3465. os.unlink(fn2)
  3466. return fn
  3467. def ica_ocsp(cert):
  3468. prefix = "auth_serv/iCA-server/"
  3469. ca = prefix + "cacert.pem"
  3470. cert = prefix + cert
  3471. fd2, fn2 = tempfile.mkstemp()
  3472. os.close(fd2)
  3473. arg = [ "openssl", "ocsp", "-reqout", fn2, "-issuer", ca, "-cert", cert,
  3474. "-no_nonce", "-sha256", "-text" ]
  3475. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3476. stderr=subprocess.PIPE)
  3477. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3478. cmd.stdout.close()
  3479. cmd.stderr.close()
  3480. logger.info("OCSP request:\n" + res)
  3481. fd, fn = tempfile.mkstemp()
  3482. os.close(fd)
  3483. arg = [ "openssl", "ocsp", "-index", prefix + "index.txt",
  3484. "-rsigner", ca, "-rkey", prefix + "private/cakey.pem",
  3485. "-CA", ca, "-issuer", ca, "-verify_other", ca, "-trust_other",
  3486. "-ndays", "7", "-reqin", fn2, "-resp_no_certs", "-respout", fn,
  3487. "-text" ]
  3488. cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
  3489. stderr=subprocess.PIPE)
  3490. res = cmd.stdout.read() + "\n" + cmd.stderr.read()
  3491. cmd.stdout.close()
  3492. cmd.stderr.close()
  3493. logger.info("OCSP response:\n" + res)
  3494. os.unlink(fn2)
  3495. return fn
  3496. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp(dev, apdev, params):
  3497. """EAP-TLS with intermediate server/user CA and OCSP on server certificate"""
  3498. params = int_eap_server_params()
  3499. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3500. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3501. params["private_key"] = "auth_serv/iCA-server/server.key"
  3502. fn = ica_ocsp("server.pem")
  3503. params["ocsp_stapling_response"] = fn
  3504. try:
  3505. hostapd.add_ap(apdev[0], params)
  3506. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3507. identity="tls user",
  3508. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3509. client_cert="auth_serv/iCA-user/user.pem",
  3510. private_key="auth_serv/iCA-user/user.key",
  3511. scan_freq="2412", ocsp=2)
  3512. finally:
  3513. os.unlink(fn)
  3514. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_revoked(dev, apdev, params):
  3515. """EAP-TLS with intermediate server/user CA and OCSP on revoked server certificate"""
  3516. params = int_eap_server_params()
  3517. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3518. params["server_cert"] = "auth_serv/iCA-server/server-revoked.pem"
  3519. params["private_key"] = "auth_serv/iCA-server/server-revoked.key"
  3520. fn = ica_ocsp("server-revoked.pem")
  3521. params["ocsp_stapling_response"] = fn
  3522. try:
  3523. hostapd.add_ap(apdev[0], params)
  3524. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3525. identity="tls user",
  3526. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3527. client_cert="auth_serv/iCA-user/user.pem",
  3528. private_key="auth_serv/iCA-user/user.key",
  3529. scan_freq="2412", ocsp=1, wait_connect=False)
  3530. count = 0
  3531. while True:
  3532. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3533. "CTRL-EVENT-EAP-SUCCESS"])
  3534. if ev is None:
  3535. raise Exception("Timeout on EAP status")
  3536. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3537. raise Exception("Unexpected EAP-Success")
  3538. if 'bad certificate status response' in ev:
  3539. break
  3540. if 'certificate revoked' in ev:
  3541. break
  3542. count = count + 1
  3543. if count > 10:
  3544. raise Exception("Unexpected number of EAP status messages")
  3545. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3546. if ev is None:
  3547. raise Exception("Timeout on EAP failure report")
  3548. dev[0].request("REMOVE_NETWORK all")
  3549. dev[0].wait_disconnected()
  3550. finally:
  3551. os.unlink(fn)
  3552. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi_missing_resp(dev, apdev, params):
  3553. """EAP-TLS with intermediate server/user CA and OCSP multi missing response"""
  3554. check_ocsp_support(dev[0])
  3555. check_ocsp_multi_support(dev[0])
  3556. params = int_eap_server_params()
  3557. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3558. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3559. params["private_key"] = "auth_serv/iCA-server/server.key"
  3560. fn = ica_ocsp("server.pem")
  3561. params["ocsp_stapling_response"] = fn
  3562. try:
  3563. hostapd.add_ap(apdev[0], params)
  3564. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3565. identity="tls user",
  3566. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3567. client_cert="auth_serv/iCA-user/user.pem",
  3568. private_key="auth_serv/iCA-user/user.key",
  3569. scan_freq="2412", ocsp=3, wait_connect=False)
  3570. count = 0
  3571. while True:
  3572. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3573. "CTRL-EVENT-EAP-SUCCESS"])
  3574. if ev is None:
  3575. raise Exception("Timeout on EAP status")
  3576. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3577. raise Exception("Unexpected EAP-Success")
  3578. if 'bad certificate status response' in ev:
  3579. break
  3580. if 'certificate revoked' in ev:
  3581. break
  3582. count = count + 1
  3583. if count > 10:
  3584. raise Exception("Unexpected number of EAP status messages")
  3585. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3586. if ev is None:
  3587. raise Exception("Timeout on EAP failure report")
  3588. dev[0].request("REMOVE_NETWORK all")
  3589. dev[0].wait_disconnected()
  3590. finally:
  3591. os.unlink(fn)
  3592. def test_ap_wpa2_eap_tls_intermediate_ca_ocsp_multi(dev, apdev, params):
  3593. """EAP-TLS with intermediate server/user CA and OCSP multi OK"""
  3594. check_ocsp_support(dev[0])
  3595. check_ocsp_multi_support(dev[0])
  3596. params = int_eap_server_params()
  3597. params["ca_cert"] = "auth_serv/iCA-server/ca-and-root.pem"
  3598. params["server_cert"] = "auth_serv/iCA-server/server.pem"
  3599. params["private_key"] = "auth_serv/iCA-server/server.key"
  3600. fn = ica_ocsp("server.pem")
  3601. fn2 = root_ocsp("auth_serv/iCA-server/cacert.pem")
  3602. params["ocsp_stapling_response"] = fn
  3603. with open(fn, "r") as f:
  3604. resp_server = f.read()
  3605. with open(fn2, "r") as f:
  3606. resp_ica = f.read()
  3607. fd3, fn3 = tempfile.mkstemp()
  3608. try:
  3609. f = os.fdopen(fd3, 'w')
  3610. f.write(struct.pack(">L", len(resp_server))[1:4])
  3611. f.write(resp_server)
  3612. f.write(struct.pack(">L", len(resp_ica))[1:4])
  3613. f.write(resp_ica)
  3614. f.close()
  3615. params["ocsp_stapling_response_multi"] = fn3
  3616. hostapd.add_ap(apdev[0], params)
  3617. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3618. identity="tls user",
  3619. ca_cert="auth_serv/iCA-user/ca-and-root.pem",
  3620. client_cert="auth_serv/iCA-user/user.pem",
  3621. private_key="auth_serv/iCA-user/user.key",
  3622. scan_freq="2412", ocsp=3)
  3623. dev[0].request("REMOVE_NETWORK all")
  3624. dev[0].wait_disconnected()
  3625. finally:
  3626. os.unlink(fn)
  3627. os.unlink(fn2)
  3628. os.unlink(fn3)
  3629. def test_ap_wpa2_eap_tls_ocsp_multi_revoked(dev, apdev, params):
  3630. """EAP-TLS and CA signed OCSP multi response (revoked)"""
  3631. check_ocsp_support(dev[0])
  3632. check_ocsp_multi_support(dev[0])
  3633. ocsp_revoked = os.path.join(params['logdir'],
  3634. "ocsp-resp-ca-signed-revoked.der")
  3635. if not os.path.exists(ocsp_revoked):
  3636. raise HwsimSkip("No OCSP response (revoked) available")
  3637. ocsp_unknown = os.path.join(params['logdir'],
  3638. "ocsp-resp-ca-signed-unknown.der")
  3639. if not os.path.exists(ocsp_unknown):
  3640. raise HwsimSkip("No OCSP response(unknown) available")
  3641. with open(ocsp_revoked, "r") as f:
  3642. resp_revoked = f.read()
  3643. with open(ocsp_unknown, "r") as f:
  3644. resp_unknown = f.read()
  3645. fd, fn = tempfile.mkstemp()
  3646. try:
  3647. # This is not really a valid order of the OCSPResponse items in the
  3648. # list, but this works for now to verify parsing and processing of
  3649. # multiple responses.
  3650. f = os.fdopen(fd, 'w')
  3651. f.write(struct.pack(">L", len(resp_unknown))[1:4])
  3652. f.write(resp_unknown)
  3653. f.write(struct.pack(">L", len(resp_revoked))[1:4])
  3654. f.write(resp_revoked)
  3655. f.write(struct.pack(">L", 0)[1:4])
  3656. f.write(struct.pack(">L", len(resp_unknown))[1:4])
  3657. f.write(resp_unknown)
  3658. f.close()
  3659. params = int_eap_server_params()
  3660. params["ocsp_stapling_response_multi"] = fn
  3661. hostapd.add_ap(apdev[0], params)
  3662. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3663. identity="tls user", ca_cert="auth_serv/ca.pem",
  3664. private_key="auth_serv/user.pkcs12",
  3665. private_key_passwd="whatever", ocsp=1,
  3666. wait_connect=False, scan_freq="2412")
  3667. count = 0
  3668. while True:
  3669. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS",
  3670. "CTRL-EVENT-EAP-SUCCESS"])
  3671. if ev is None:
  3672. raise Exception("Timeout on EAP status")
  3673. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  3674. raise Exception("Unexpected EAP-Success")
  3675. if 'bad certificate status response' in ev:
  3676. break
  3677. if 'certificate revoked' in ev:
  3678. break
  3679. count = count + 1
  3680. if count > 10:
  3681. raise Exception("Unexpected number of EAP status messages")
  3682. finally:
  3683. os.unlink(fn)
  3684. def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
  3685. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  3686. check_domain_match_full(dev[0])
  3687. params = int_eap_server_params()
  3688. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3689. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3690. hostapd.add_ap(apdev[0], params)
  3691. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3692. identity="tls user", ca_cert="auth_serv/ca.pem",
  3693. private_key="auth_serv/user.pkcs12",
  3694. private_key_passwd="whatever",
  3695. domain_suffix_match="server3.w1.fi",
  3696. scan_freq="2412")
  3697. def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
  3698. """WPA2-Enterprise using EAP-TLS and domainmatch (CN)"""
  3699. check_domain_match(dev[0])
  3700. params = int_eap_server_params()
  3701. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3702. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3703. hostapd.add_ap(apdev[0], params)
  3704. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3705. identity="tls user", ca_cert="auth_serv/ca.pem",
  3706. private_key="auth_serv/user.pkcs12",
  3707. private_key_passwd="whatever",
  3708. domain_match="server3.w1.fi",
  3709. scan_freq="2412")
  3710. def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
  3711. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  3712. check_domain_match_full(dev[0])
  3713. params = int_eap_server_params()
  3714. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3715. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3716. hostapd.add_ap(apdev[0], params)
  3717. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3718. identity="tls user", ca_cert="auth_serv/ca.pem",
  3719. private_key="auth_serv/user.pkcs12",
  3720. private_key_passwd="whatever",
  3721. domain_suffix_match="w1.fi",
  3722. scan_freq="2412")
  3723. def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
  3724. """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
  3725. check_domain_suffix_match(dev[0])
  3726. params = int_eap_server_params()
  3727. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3728. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3729. hostapd.add_ap(apdev[0], params)
  3730. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3731. identity="tls user", ca_cert="auth_serv/ca.pem",
  3732. private_key="auth_serv/user.pkcs12",
  3733. private_key_passwd="whatever",
  3734. domain_suffix_match="example.com",
  3735. wait_connect=False,
  3736. scan_freq="2412")
  3737. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3738. identity="tls user", ca_cert="auth_serv/ca.pem",
  3739. private_key="auth_serv/user.pkcs12",
  3740. private_key_passwd="whatever",
  3741. domain_suffix_match="erver3.w1.fi",
  3742. wait_connect=False,
  3743. scan_freq="2412")
  3744. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3745. if ev is None:
  3746. raise Exception("Timeout on EAP failure report")
  3747. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3748. if ev is None:
  3749. raise Exception("Timeout on EAP failure report (2)")
  3750. def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev):
  3751. """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)"""
  3752. check_domain_match(dev[0])
  3753. params = int_eap_server_params()
  3754. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  3755. params["private_key"] = "auth_serv/server-no-dnsname.key"
  3756. hostapd.add_ap(apdev[0], params)
  3757. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3758. identity="tls user", ca_cert="auth_serv/ca.pem",
  3759. private_key="auth_serv/user.pkcs12",
  3760. private_key_passwd="whatever",
  3761. domain_match="example.com",
  3762. wait_connect=False,
  3763. scan_freq="2412")
  3764. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3765. identity="tls user", ca_cert="auth_serv/ca.pem",
  3766. private_key="auth_serv/user.pkcs12",
  3767. private_key_passwd="whatever",
  3768. domain_match="w1.fi",
  3769. wait_connect=False,
  3770. scan_freq="2412")
  3771. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3772. if ev is None:
  3773. raise Exception("Timeout on EAP failure report")
  3774. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3775. if ev is None:
  3776. raise Exception("Timeout on EAP failure report (2)")
  3777. def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev):
  3778. """WPA2-Enterprise using EAP-TTLS and expired certificate"""
  3779. skip_with_fips(dev[0])
  3780. params = int_eap_server_params()
  3781. params["server_cert"] = "auth_serv/server-expired.pem"
  3782. params["private_key"] = "auth_serv/server-expired.key"
  3783. hostapd.add_ap(apdev[0], params)
  3784. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3785. identity="mschap user", password="password",
  3786. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3787. wait_connect=False,
  3788. scan_freq="2412")
  3789. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  3790. if ev is None:
  3791. raise Exception("Timeout on EAP certificate error report")
  3792. if "reason=4" not in ev or "certificate has expired" not in ev:
  3793. raise Exception("Unexpected failure reason: " + ev)
  3794. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3795. if ev is None:
  3796. raise Exception("Timeout on EAP failure report")
  3797. def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev):
  3798. """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration"""
  3799. skip_with_fips(dev[0])
  3800. params = int_eap_server_params()
  3801. params["server_cert"] = "auth_serv/server-expired.pem"
  3802. params["private_key"] = "auth_serv/server-expired.key"
  3803. hostapd.add_ap(apdev[0], params)
  3804. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3805. identity="mschap user", password="password",
  3806. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3807. phase1="tls_disable_time_checks=1",
  3808. scan_freq="2412")
  3809. def test_ap_wpa2_eap_ttls_long_duration(dev, apdev):
  3810. """WPA2-Enterprise using EAP-TTLS and long certificate duration"""
  3811. skip_with_fips(dev[0])
  3812. params = int_eap_server_params()
  3813. params["server_cert"] = "auth_serv/server-long-duration.pem"
  3814. params["private_key"] = "auth_serv/server-long-duration.key"
  3815. hostapd.add_ap(apdev[0], params)
  3816. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3817. identity="mschap user", password="password",
  3818. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3819. scan_freq="2412")
  3820. def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev):
  3821. """WPA2-Enterprise using EAP-TTLS and server cert with client EKU"""
  3822. skip_with_fips(dev[0])
  3823. params = int_eap_server_params()
  3824. params["server_cert"] = "auth_serv/server-eku-client.pem"
  3825. params["private_key"] = "auth_serv/server-eku-client.key"
  3826. hostapd.add_ap(apdev[0], params)
  3827. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3828. identity="mschap user", password="password",
  3829. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3830. wait_connect=False,
  3831. scan_freq="2412")
  3832. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3833. if ev is None:
  3834. raise Exception("Timeout on EAP failure report")
  3835. def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev):
  3836. """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU"""
  3837. skip_with_fips(dev[0])
  3838. params = int_eap_server_params()
  3839. params["server_cert"] = "auth_serv/server-eku-client-server.pem"
  3840. params["private_key"] = "auth_serv/server-eku-client-server.key"
  3841. hostapd.add_ap(apdev[0], params)
  3842. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3843. identity="mschap user", password="password",
  3844. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3845. scan_freq="2412")
  3846. def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev):
  3847. """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file"""
  3848. skip_with_fips(dev[0])
  3849. params = int_eap_server_params()
  3850. del params["server_cert"]
  3851. params["private_key"] = "auth_serv/server.pkcs12"
  3852. hostapd.add_ap(apdev[0], params)
  3853. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3854. identity="mschap user", password="password",
  3855. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3856. scan_freq="2412")
  3857. def test_ap_wpa2_eap_ttls_server_pkcs12_extra(dev, apdev):
  3858. """EAP-TTLS and server PKCS#12 file with extra certs"""
  3859. skip_with_fips(dev[0])
  3860. params = int_eap_server_params()
  3861. del params["server_cert"]
  3862. params["private_key"] = "auth_serv/server-extra.pkcs12"
  3863. params["private_key_passwd"] = "whatever"
  3864. hostapd.add_ap(apdev[0], params)
  3865. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3866. identity="mschap user", password="password",
  3867. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3868. scan_freq="2412")
  3869. def test_ap_wpa2_eap_ttls_dh_params(dev, apdev):
  3870. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params"""
  3871. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3872. hapd = hostapd.add_ap(apdev[0], params)
  3873. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3874. anonymous_identity="ttls", password="password",
  3875. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  3876. dh_file="auth_serv/dh.conf")
  3877. def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev):
  3878. """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)"""
  3879. check_dh_dsa_support(dev[0])
  3880. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3881. hapd = hostapd.add_ap(apdev[0], params)
  3882. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3883. anonymous_identity="ttls", password="password",
  3884. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  3885. dh_file="auth_serv/dsaparam.pem")
  3886. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  3887. """EAP-TTLS and DH params file not found"""
  3888. skip_with_fips(dev[0])
  3889. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3890. hostapd.add_ap(apdev[0], params)
  3891. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3892. identity="mschap user", password="password",
  3893. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3894. dh_file="auth_serv/dh-no-such-file.conf",
  3895. scan_freq="2412", wait_connect=False)
  3896. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3897. if ev is None:
  3898. raise Exception("EAP failure timed out")
  3899. dev[0].request("REMOVE_NETWORK all")
  3900. dev[0].wait_disconnected()
  3901. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  3902. """EAP-TTLS and invalid DH params file"""
  3903. skip_with_fips(dev[0])
  3904. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3905. hostapd.add_ap(apdev[0], params)
  3906. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  3907. identity="mschap user", password="password",
  3908. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3909. dh_file="auth_serv/ca.pem",
  3910. scan_freq="2412", wait_connect=False)
  3911. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  3912. if ev is None:
  3913. raise Exception("EAP failure timed out")
  3914. dev[0].request("REMOVE_NETWORK all")
  3915. dev[0].wait_disconnected()
  3916. def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
  3917. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob"""
  3918. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3919. hapd = hostapd.add_ap(apdev[0], params)
  3920. dh = read_pem("auth_serv/dh2.conf")
  3921. if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
  3922. raise Exception("Could not set dhparams blob")
  3923. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3924. anonymous_identity="ttls", password="password",
  3925. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  3926. dh_file="blob://dhparams")
  3927. def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev):
  3928. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams"""
  3929. params = int_eap_server_params()
  3930. params["dh_file"] = "auth_serv/dh2.conf"
  3931. hapd = hostapd.add_ap(apdev[0], params)
  3932. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3933. anonymous_identity="ttls", password="password",
  3934. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  3935. def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev):
  3936. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)"""
  3937. params = int_eap_server_params()
  3938. params["dh_file"] = "auth_serv/dsaparam.pem"
  3939. hapd = hostapd.add_ap(apdev[0], params)
  3940. eap_connect(dev[0], hapd, "TTLS", "pap user",
  3941. anonymous_identity="ttls", password="password",
  3942. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  3943. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  3944. """EAP-TLS server and dhparams file not found"""
  3945. params = int_eap_server_params()
  3946. params["dh_file"] = "auth_serv/dh-no-such-file.conf"
  3947. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3948. if "FAIL" not in hapd.request("ENABLE"):
  3949. raise Exception("Invalid configuration accepted")
  3950. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  3951. """EAP-TLS server and invalid dhparams file"""
  3952. params = int_eap_server_params()
  3953. params["dh_file"] = "auth_serv/ca.pem"
  3954. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  3955. if "FAIL" not in hapd.request("ENABLE"):
  3956. raise Exception("Invalid configuration accepted")
  3957. def test_ap_wpa2_eap_reauth(dev, apdev):
  3958. """WPA2-Enterprise and Authenticator forcing reauthentication"""
  3959. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3960. params['eap_reauth_period'] = '2'
  3961. hapd = hostapd.add_ap(apdev[0], params)
  3962. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  3963. password_hex="0123456789abcdef0123456789abcdef")
  3964. logger.info("Wait for reauthentication")
  3965. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  3966. if ev is None:
  3967. raise Exception("Timeout on reauthentication")
  3968. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3969. if ev is None:
  3970. raise Exception("Timeout on reauthentication")
  3971. for i in range(0, 20):
  3972. state = dev[0].get_status_field("wpa_state")
  3973. if state == "COMPLETED":
  3974. break
  3975. time.sleep(0.1)
  3976. if state != "COMPLETED":
  3977. raise Exception("Reauthentication did not complete")
  3978. def test_ap_wpa2_eap_request_identity_message(dev, apdev):
  3979. """Optional displayable message in EAP Request-Identity"""
  3980. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3981. params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com'
  3982. hapd = hostapd.add_ap(apdev[0], params)
  3983. eap_connect(dev[0], hapd, "PAX", "pax.user@example.com",
  3984. password_hex="0123456789abcdef0123456789abcdef")
  3985. def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev):
  3986. """WPA2-Enterprise using EAP-SIM/AKA and protected result indication"""
  3987. check_hlr_auc_gw_support()
  3988. params = int_eap_server_params()
  3989. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  3990. params['eap_sim_aka_result_ind'] = "1"
  3991. hapd = hostapd.add_ap(apdev[0], params)
  3992. eap_connect(dev[0], hapd, "SIM", "1232010000000000",
  3993. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  3994. phase1="result_ind=1")
  3995. eap_reauth(dev[0], "SIM")
  3996. eap_connect(dev[1], hapd, "SIM", "1232010000000000",
  3997. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  3998. dev[0].request("REMOVE_NETWORK all")
  3999. dev[1].request("REMOVE_NETWORK all")
  4000. eap_connect(dev[0], hapd, "AKA", "0232010000000000",
  4001. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  4002. phase1="result_ind=1")
  4003. eap_reauth(dev[0], "AKA")
  4004. eap_connect(dev[1], hapd, "AKA", "0232010000000000",
  4005. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  4006. dev[0].request("REMOVE_NETWORK all")
  4007. dev[1].request("REMOVE_NETWORK all")
  4008. eap_connect(dev[0], hapd, "AKA'", "6555444333222111",
  4009. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  4010. phase1="result_ind=1")
  4011. eap_reauth(dev[0], "AKA'")
  4012. eap_connect(dev[1], hapd, "AKA'", "6555444333222111",
  4013. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  4014. def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev):
  4015. """WPA2-Enterprise connection resulting in too many EAP roundtrips"""
  4016. skip_with_fips(dev[0])
  4017. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4018. hostapd.add_ap(apdev[0], params)
  4019. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4020. eap="TTLS", identity="mschap user",
  4021. wait_connect=False, scan_freq="2412", ieee80211w="1",
  4022. anonymous_identity="ttls", password="password",
  4023. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4024. fragment_size="10")
  4025. ev = dev[0].wait_event(["EAP: more than"], timeout=20)
  4026. if ev is None:
  4027. raise Exception("EAP roundtrip limit not reached")
  4028. def test_ap_wpa2_eap_expanded_nak(dev, apdev):
  4029. """WPA2-Enterprise connection with EAP resulting in expanded NAK"""
  4030. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4031. hostapd.add_ap(apdev[0], params)
  4032. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4033. eap="PSK", identity="vendor-test",
  4034. password_hex="ff23456789abcdef0123456789abcdef",
  4035. wait_connect=False)
  4036. found = False
  4037. for i in range(0, 5):
  4038. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=16)
  4039. if ev is None:
  4040. raise Exception("Association and EAP start timed out")
  4041. if "refuse proposed method" in ev:
  4042. found = True
  4043. break
  4044. if not found:
  4045. raise Exception("Unexpected EAP status: " + ev)
  4046. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  4047. if ev is None:
  4048. raise Exception("EAP failure timed out")
  4049. def test_ap_wpa2_eap_sql(dev, apdev, params):
  4050. """WPA2-Enterprise connection using SQLite for user DB"""
  4051. skip_with_fips(dev[0])
  4052. try:
  4053. import sqlite3
  4054. except ImportError:
  4055. raise HwsimSkip("No sqlite3 module available")
  4056. dbfile = os.path.join(params['logdir'], "eap-user.db")
  4057. try:
  4058. os.remove(dbfile)
  4059. except:
  4060. pass
  4061. con = sqlite3.connect(dbfile)
  4062. with con:
  4063. cur = con.cursor()
  4064. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  4065. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  4066. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)")
  4067. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)")
  4068. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)")
  4069. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)")
  4070. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  4071. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  4072. try:
  4073. params = int_eap_server_params()
  4074. params["eap_user_file"] = "sqlite:" + dbfile
  4075. hapd = hostapd.add_ap(apdev[0], params)
  4076. eap_connect(dev[0], hapd, "TTLS", "user-mschapv2",
  4077. anonymous_identity="ttls", password="password",
  4078. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4079. dev[0].request("REMOVE_NETWORK all")
  4080. eap_connect(dev[1], hapd, "TTLS", "user-mschap",
  4081. anonymous_identity="ttls", password="password",
  4082. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  4083. dev[1].request("REMOVE_NETWORK all")
  4084. eap_connect(dev[0], hapd, "TTLS", "user-chap",
  4085. anonymous_identity="ttls", password="password",
  4086. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP")
  4087. eap_connect(dev[1], hapd, "TTLS", "user-pap",
  4088. anonymous_identity="ttls", password="password",
  4089. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4090. finally:
  4091. os.remove(dbfile)
  4092. def test_ap_wpa2_eap_non_ascii_identity(dev, apdev):
  4093. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  4094. params = int_eap_server_params()
  4095. hostapd.add_ap(apdev[0], params)
  4096. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4097. identity="\x80", password="password", wait_connect=False)
  4098. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4099. identity="a\x80", password="password", wait_connect=False)
  4100. for i in range(0, 2):
  4101. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  4102. if ev is None:
  4103. raise Exception("Association and EAP start timed out")
  4104. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  4105. if ev is None:
  4106. raise Exception("EAP method selection timed out")
  4107. def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev):
  4108. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  4109. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4110. hostapd.add_ap(apdev[0], params)
  4111. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4112. identity="\x80", password="password", wait_connect=False)
  4113. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4114. identity="a\x80", password="password", wait_connect=False)
  4115. for i in range(0, 2):
  4116. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=16)
  4117. if ev is None:
  4118. raise Exception("Association and EAP start timed out")
  4119. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  4120. if ev is None:
  4121. raise Exception("EAP method selection timed out")
  4122. def test_openssl_cipher_suite_config_wpas(dev, apdev):
  4123. """OpenSSL cipher suite configuration on wpa_supplicant"""
  4124. tls = dev[0].request("GET tls_library")
  4125. if not tls.startswith("OpenSSL"):
  4126. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  4127. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4128. hapd = hostapd.add_ap(apdev[0], params)
  4129. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4130. anonymous_identity="ttls", password="password",
  4131. openssl_ciphers="AES128",
  4132. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4133. eap_connect(dev[1], hapd, "TTLS", "pap user",
  4134. anonymous_identity="ttls", password="password",
  4135. openssl_ciphers="EXPORT",
  4136. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4137. expect_failure=True, maybe_local_error=True)
  4138. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  4139. identity="pap user", anonymous_identity="ttls",
  4140. password="password",
  4141. openssl_ciphers="FOO",
  4142. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4143. wait_connect=False)
  4144. ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4145. if ev is None:
  4146. raise Exception("EAP failure after invalid openssl_ciphers not reported")
  4147. dev[2].request("DISCONNECT")
  4148. def test_openssl_cipher_suite_config_hapd(dev, apdev):
  4149. """OpenSSL cipher suite configuration on hostapd"""
  4150. tls = dev[0].request("GET tls_library")
  4151. if not tls.startswith("OpenSSL"):
  4152. raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls)
  4153. params = int_eap_server_params()
  4154. params['openssl_ciphers'] = "AES256"
  4155. hapd = hostapd.add_ap(apdev[0], params)
  4156. tls = hapd.request("GET tls_library")
  4157. if not tls.startswith("OpenSSL"):
  4158. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  4159. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4160. anonymous_identity="ttls", password="password",
  4161. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4162. eap_connect(dev[1], hapd, "TTLS", "pap user",
  4163. anonymous_identity="ttls", password="password",
  4164. openssl_ciphers="AES128",
  4165. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  4166. expect_failure=True)
  4167. eap_connect(dev[2], hapd, "TTLS", "pap user",
  4168. anonymous_identity="ttls", password="password",
  4169. openssl_ciphers="HIGH:!ADH",
  4170. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4171. params['openssl_ciphers'] = "FOO"
  4172. hapd2 = hostapd.add_ap(apdev[1], params, no_enable=True)
  4173. if "FAIL" not in hapd2.request("ENABLE"):
  4174. raise Exception("Invalid openssl_ciphers value accepted")
  4175. def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
  4176. """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
  4177. p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4178. hapd = hostapd.add_ap(apdev[0], p)
  4179. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  4180. pid = find_wpas_process(dev[0])
  4181. id = eap_connect(dev[0], hapd, "TTLS", "pap-secret",
  4182. anonymous_identity="ttls", password=password,
  4183. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4184. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  4185. # event has been delivered, so verify that wpa_supplicant has returned to
  4186. # eloop before reading process memory.
  4187. time.sleep(1)
  4188. dev[0].ping()
  4189. buf = read_process_memory(pid, password)
  4190. dev[0].request("DISCONNECT")
  4191. dev[0].wait_disconnected()
  4192. dev[0].relog()
  4193. msk = None
  4194. emsk = None
  4195. pmk = None
  4196. ptk = None
  4197. gtk = None
  4198. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  4199. for l in f.readlines():
  4200. if "EAP-TTLS: Derived key - hexdump" in l:
  4201. val = l.strip().split(':')[3].replace(' ', '')
  4202. msk = binascii.unhexlify(val)
  4203. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  4204. val = l.strip().split(':')[3].replace(' ', '')
  4205. emsk = binascii.unhexlify(val)
  4206. if "WPA: PMK - hexdump" in l:
  4207. val = l.strip().split(':')[3].replace(' ', '')
  4208. pmk = binascii.unhexlify(val)
  4209. if "WPA: PTK - hexdump" in l:
  4210. val = l.strip().split(':')[3].replace(' ', '')
  4211. ptk = binascii.unhexlify(val)
  4212. if "WPA: Group Key - hexdump" in l:
  4213. val = l.strip().split(':')[3].replace(' ', '')
  4214. gtk = binascii.unhexlify(val)
  4215. if not msk or not emsk or not pmk or not ptk or not gtk:
  4216. raise Exception("Could not find keys from debug log")
  4217. if len(gtk) != 16:
  4218. raise Exception("Unexpected GTK length")
  4219. kck = ptk[0:16]
  4220. kek = ptk[16:32]
  4221. tk = ptk[32:48]
  4222. fname = os.path.join(params['logdir'],
  4223. 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-')
  4224. logger.info("Checking keys in memory while associated")
  4225. get_key_locations(buf, password, "Password")
  4226. get_key_locations(buf, pmk, "PMK")
  4227. get_key_locations(buf, msk, "MSK")
  4228. get_key_locations(buf, emsk, "EMSK")
  4229. if password not in buf:
  4230. raise HwsimSkip("Password not found while associated")
  4231. if pmk not in buf:
  4232. raise HwsimSkip("PMK not found while associated")
  4233. if kck not in buf:
  4234. raise Exception("KCK not found while associated")
  4235. if kek not in buf:
  4236. raise Exception("KEK not found while associated")
  4237. if tk in buf:
  4238. raise Exception("TK found from memory")
  4239. if gtk in buf:
  4240. get_key_locations(buf, gtk, "GTK")
  4241. raise Exception("GTK found from memory")
  4242. logger.info("Checking keys in memory after disassociation")
  4243. buf = read_process_memory(pid, password)
  4244. # Note: Password is still present in network configuration
  4245. # Note: PMK is in PMKSA cache and EAP fast re-auth data
  4246. get_key_locations(buf, password, "Password")
  4247. get_key_locations(buf, pmk, "PMK")
  4248. get_key_locations(buf, msk, "MSK")
  4249. get_key_locations(buf, emsk, "EMSK")
  4250. verify_not_present(buf, kck, fname, "KCK")
  4251. verify_not_present(buf, kek, fname, "KEK")
  4252. verify_not_present(buf, tk, fname, "TK")
  4253. verify_not_present(buf, gtk, fname, "GTK")
  4254. dev[0].request("PMKSA_FLUSH")
  4255. dev[0].set_network_quoted(id, "identity", "foo")
  4256. logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush")
  4257. buf = read_process_memory(pid, password)
  4258. get_key_locations(buf, password, "Password")
  4259. get_key_locations(buf, pmk, "PMK")
  4260. get_key_locations(buf, msk, "MSK")
  4261. get_key_locations(buf, emsk, "EMSK")
  4262. verify_not_present(buf, pmk, fname, "PMK")
  4263. dev[0].request("REMOVE_NETWORK all")
  4264. logger.info("Checking keys in memory after network profile removal")
  4265. buf = read_process_memory(pid, password)
  4266. get_key_locations(buf, password, "Password")
  4267. get_key_locations(buf, pmk, "PMK")
  4268. get_key_locations(buf, msk, "MSK")
  4269. get_key_locations(buf, emsk, "EMSK")
  4270. verify_not_present(buf, password, fname, "password")
  4271. verify_not_present(buf, pmk, fname, "PMK")
  4272. verify_not_present(buf, kck, fname, "KCK")
  4273. verify_not_present(buf, kek, fname, "KEK")
  4274. verify_not_present(buf, tk, fname, "TK")
  4275. verify_not_present(buf, gtk, fname, "GTK")
  4276. verify_not_present(buf, msk, fname, "MSK")
  4277. verify_not_present(buf, emsk, fname, "EMSK")
  4278. def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev):
  4279. """WPA2-Enterprise connection and unexpected WEP EAPOL-Key"""
  4280. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4281. hapd = hostapd.add_ap(apdev[0], params)
  4282. bssid = apdev[0]['bssid']
  4283. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4284. anonymous_identity="ttls", password="password",
  4285. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  4286. # Send unexpected WEP EAPOL-Key; this gets dropped
  4287. res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
  4288. if "OK" not in res:
  4289. raise Exception("EAPOL_RX to wpa_supplicant failed")
  4290. def test_ap_wpa2_eap_in_bridge(dev, apdev):
  4291. """WPA2-EAP and wpas interface in a bridge"""
  4292. br_ifname='sta-br0'
  4293. ifname='wlan5'
  4294. try:
  4295. _test_ap_wpa2_eap_in_bridge(dev, apdev)
  4296. finally:
  4297. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  4298. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  4299. subprocess.call(['brctl', 'delbr', br_ifname])
  4300. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  4301. def _test_ap_wpa2_eap_in_bridge(dev, apdev):
  4302. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4303. hapd = hostapd.add_ap(apdev[0], params)
  4304. br_ifname='sta-br0'
  4305. ifname='wlan5'
  4306. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  4307. subprocess.call(['brctl', 'addbr', br_ifname])
  4308. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  4309. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  4310. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  4311. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  4312. wpas.interface_add(ifname, br_ifname=br_ifname)
  4313. wpas.dump_monitor()
  4314. id = eap_connect(wpas, hapd, "PAX", "pax.user@example.com",
  4315. password_hex="0123456789abcdef0123456789abcdef")
  4316. wpas.dump_monitor()
  4317. eap_reauth(wpas, "PAX")
  4318. wpas.dump_monitor()
  4319. # Try again as a regression test for packet socket workaround
  4320. eap_reauth(wpas, "PAX")
  4321. wpas.dump_monitor()
  4322. wpas.request("DISCONNECT")
  4323. wpas.wait_disconnected()
  4324. wpas.dump_monitor()
  4325. wpas.request("RECONNECT")
  4326. wpas.wait_connected()
  4327. wpas.dump_monitor()
  4328. def test_ap_wpa2_eap_session_ticket(dev, apdev):
  4329. """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled"""
  4330. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4331. hapd = hostapd.add_ap(apdev[0], params)
  4332. key_mgmt = hapd.get_config()['key_mgmt']
  4333. if key_mgmt.split(' ')[0] != "WPA-EAP":
  4334. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  4335. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4336. anonymous_identity="ttls", password="password",
  4337. ca_cert="auth_serv/ca.pem",
  4338. phase1="tls_disable_session_ticket=0", phase2="auth=PAP")
  4339. eap_reauth(dev[0], "TTLS")
  4340. def test_ap_wpa2_eap_no_workaround(dev, apdev):
  4341. """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0"""
  4342. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4343. hapd = hostapd.add_ap(apdev[0], params)
  4344. key_mgmt = hapd.get_config()['key_mgmt']
  4345. if key_mgmt.split(' ')[0] != "WPA-EAP":
  4346. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  4347. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4348. anonymous_identity="ttls", password="password",
  4349. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4350. phase2="auth=PAP")
  4351. eap_reauth(dev[0], "TTLS")
  4352. def test_ap_wpa2_eap_tls_check_crl(dev, apdev):
  4353. """EAP-TLS and server checking CRL"""
  4354. params = int_eap_server_params()
  4355. params['check_crl'] = '1'
  4356. hapd = hostapd.add_ap(apdev[0], params)
  4357. # check_crl=1 and no CRL available --> reject connection
  4358. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4359. client_cert="auth_serv/user.pem",
  4360. private_key="auth_serv/user.key", expect_failure=True)
  4361. dev[0].request("REMOVE_NETWORK all")
  4362. hapd.disable()
  4363. hapd.set("ca_cert", "auth_serv/ca-and-crl.pem")
  4364. hapd.enable()
  4365. # check_crl=1 and valid CRL --> accept
  4366. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4367. client_cert="auth_serv/user.pem",
  4368. private_key="auth_serv/user.key")
  4369. dev[0].request("REMOVE_NETWORK all")
  4370. hapd.disable()
  4371. hapd.set("check_crl", "2")
  4372. hapd.enable()
  4373. # check_crl=2 and valid CRL --> accept
  4374. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4375. client_cert="auth_serv/user.pem",
  4376. private_key="auth_serv/user.key")
  4377. dev[0].request("REMOVE_NETWORK all")
  4378. def test_ap_wpa2_eap_tls_oom(dev, apdev):
  4379. """EAP-TLS and OOM"""
  4380. check_subject_match_support(dev[0])
  4381. check_altsubject_match_support(dev[0])
  4382. check_domain_match(dev[0])
  4383. check_domain_match_full(dev[0])
  4384. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4385. hostapd.add_ap(apdev[0], params)
  4386. tests = [ (1, "tls_connection_set_subject_match"),
  4387. (2, "tls_connection_set_subject_match"),
  4388. (3, "tls_connection_set_subject_match"),
  4389. (4, "tls_connection_set_subject_match") ]
  4390. for count, func in tests:
  4391. with alloc_fail(dev[0], count, func):
  4392. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4393. identity="tls user", ca_cert="auth_serv/ca.pem",
  4394. client_cert="auth_serv/user.pem",
  4395. private_key="auth_serv/user.key",
  4396. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  4397. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/",
  4398. domain_suffix_match="server.w1.fi",
  4399. domain_match="server.w1.fi",
  4400. wait_connect=False, scan_freq="2412")
  4401. # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE
  4402. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5)
  4403. if ev is None:
  4404. raise Exception("No passphrase request")
  4405. dev[0].request("REMOVE_NETWORK all")
  4406. dev[0].wait_disconnected()
  4407. def test_ap_wpa2_eap_tls_macacl(dev, apdev):
  4408. """WPA2-Enterprise connection using MAC ACL"""
  4409. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4410. params["macaddr_acl"] = "2"
  4411. hapd = hostapd.add_ap(apdev[0], params)
  4412. eap_connect(dev[1], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4413. client_cert="auth_serv/user.pem",
  4414. private_key="auth_serv/user.key")
  4415. def test_ap_wpa2_eap_oom(dev, apdev):
  4416. """EAP server and OOM"""
  4417. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4418. hapd = hostapd.add_ap(apdev[0], params)
  4419. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  4420. with alloc_fail(hapd, 1, "eapol_auth_alloc"):
  4421. # The first attempt fails, but STA will send EAPOL-Start to retry and
  4422. # that succeeds.
  4423. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  4424. identity="tls user", ca_cert="auth_serv/ca.pem",
  4425. client_cert="auth_serv/user.pem",
  4426. private_key="auth_serv/user.key",
  4427. scan_freq="2412")
  4428. def check_tls_ver(dev, hapd, phase1, expected):
  4429. eap_connect(dev, hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4430. client_cert="auth_serv/user.pem",
  4431. private_key="auth_serv/user.key",
  4432. phase1=phase1)
  4433. ver = dev.get_status_field("eap_tls_version")
  4434. if ver != expected:
  4435. raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver))
  4436. def test_ap_wpa2_eap_tls_versions(dev, apdev):
  4437. """EAP-TLS and TLS version configuration"""
  4438. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4439. hapd = hostapd.add_ap(apdev[0], params)
  4440. tls = dev[0].request("GET tls_library")
  4441. if tls.startswith("OpenSSL"):
  4442. if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  4443. check_tls_ver(dev[0], hapd,
  4444. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
  4445. "TLSv1.2")
  4446. elif tls.startswith("internal"):
  4447. check_tls_ver(dev[0], hapd,
  4448. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1", "TLSv1.2")
  4449. check_tls_ver(dev[1], hapd,
  4450. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1")
  4451. check_tls_ver(dev[2], hapd,
  4452. "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1")
  4453. def test_rsn_ie_proto_eap_sta(dev, apdev):
  4454. """RSN element protocol testing for EAP cases on STA side"""
  4455. bssid = apdev[0]['bssid']
  4456. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4457. # This is the RSN element used normally by hostapd
  4458. params['own_ie_override'] = '30140100000fac040100000fac040100000fac010c00'
  4459. hapd = hostapd.add_ap(apdev[0], params)
  4460. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4461. identity="gpsk user",
  4462. password="abcdefghijklmnop0123456789abcdef",
  4463. scan_freq="2412")
  4464. tests = [ ('No RSN Capabilities field',
  4465. '30120100000fac040100000fac040100000fac01'),
  4466. ('No AKM Suite fields',
  4467. '300c0100000fac040100000fac04'),
  4468. ('No Pairwise Cipher Suite fields',
  4469. '30060100000fac04'),
  4470. ('No Group Data Cipher Suite field',
  4471. '30020100') ]
  4472. for txt,ie in tests:
  4473. dev[0].request("DISCONNECT")
  4474. dev[0].wait_disconnected()
  4475. logger.info(txt)
  4476. hapd.disable()
  4477. hapd.set('own_ie_override', ie)
  4478. hapd.enable()
  4479. dev[0].request("BSS_FLUSH 0")
  4480. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  4481. dev[0].select_network(id, freq=2412)
  4482. dev[0].wait_connected()
  4483. dev[0].request("DISCONNECT")
  4484. dev[0].wait_disconnected()
  4485. dev[0].flush_scan_cache()
  4486. def check_tls_session_resumption_capa(dev, hapd):
  4487. tls = hapd.request("GET tls_library")
  4488. if not tls.startswith("OpenSSL"):
  4489. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  4490. tls = dev.request("GET tls_library")
  4491. if not tls.startswith("OpenSSL"):
  4492. raise HwsimSkip("Session resumption not supported with this TLS library: " + tls)
  4493. def test_eap_ttls_pap_session_resumption(dev, apdev):
  4494. """EAP-TTLS/PAP session resumption"""
  4495. params = int_eap_server_params()
  4496. params['tls_session_lifetime'] = '60'
  4497. hapd = hostapd.add_ap(apdev[0], params)
  4498. check_tls_session_resumption_capa(dev[0], hapd)
  4499. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4500. anonymous_identity="ttls", password="password",
  4501. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4502. phase2="auth=PAP")
  4503. if dev[0].get_status_field("tls_session_reused") != '0':
  4504. raise Exception("Unexpected session resumption on the first connection")
  4505. dev[0].request("REAUTHENTICATE")
  4506. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4507. if ev is None:
  4508. raise Exception("EAP success timed out")
  4509. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4510. if ev is None:
  4511. raise Exception("Key handshake with the AP timed out")
  4512. if dev[0].get_status_field("tls_session_reused") != '1':
  4513. raise Exception("Session resumption not used on the second connection")
  4514. def test_eap_ttls_chap_session_resumption(dev, apdev):
  4515. """EAP-TTLS/CHAP session resumption"""
  4516. params = int_eap_server_params()
  4517. params['tls_session_lifetime'] = '60'
  4518. hapd = hostapd.add_ap(apdev[0], params)
  4519. check_tls_session_resumption_capa(dev[0], hapd)
  4520. eap_connect(dev[0], hapd, "TTLS", "chap user",
  4521. anonymous_identity="ttls", password="password",
  4522. ca_cert="auth_serv/ca.der", phase2="auth=CHAP")
  4523. if dev[0].get_status_field("tls_session_reused") != '0':
  4524. raise Exception("Unexpected session resumption on the first connection")
  4525. dev[0].request("REAUTHENTICATE")
  4526. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4527. if ev is None:
  4528. raise Exception("EAP success timed out")
  4529. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4530. if ev is None:
  4531. raise Exception("Key handshake with the AP timed out")
  4532. if dev[0].get_status_field("tls_session_reused") != '1':
  4533. raise Exception("Session resumption not used on the second connection")
  4534. def test_eap_ttls_mschap_session_resumption(dev, apdev):
  4535. """EAP-TTLS/MSCHAP session resumption"""
  4536. check_domain_suffix_match(dev[0])
  4537. params = int_eap_server_params()
  4538. params['tls_session_lifetime'] = '60'
  4539. hapd = hostapd.add_ap(apdev[0], params)
  4540. check_tls_session_resumption_capa(dev[0], hapd)
  4541. eap_connect(dev[0], hapd, "TTLS", "mschap user",
  4542. anonymous_identity="ttls", password="password",
  4543. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  4544. domain_suffix_match="server.w1.fi")
  4545. if dev[0].get_status_field("tls_session_reused") != '0':
  4546. raise Exception("Unexpected session resumption on the first connection")
  4547. dev[0].request("REAUTHENTICATE")
  4548. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4549. if ev is None:
  4550. raise Exception("EAP success timed out")
  4551. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4552. if ev is None:
  4553. raise Exception("Key handshake with the AP timed out")
  4554. if dev[0].get_status_field("tls_session_reused") != '1':
  4555. raise Exception("Session resumption not used on the second connection")
  4556. def test_eap_ttls_mschapv2_session_resumption(dev, apdev):
  4557. """EAP-TTLS/MSCHAPv2 session resumption"""
  4558. check_domain_suffix_match(dev[0])
  4559. check_eap_capa(dev[0], "MSCHAPV2")
  4560. params = int_eap_server_params()
  4561. params['tls_session_lifetime'] = '60'
  4562. hapd = hostapd.add_ap(apdev[0], params)
  4563. check_tls_session_resumption_capa(dev[0], hapd)
  4564. eap_connect(dev[0], hapd, "TTLS", "DOMAIN\mschapv2 user",
  4565. anonymous_identity="ttls", password="password",
  4566. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4567. domain_suffix_match="server.w1.fi")
  4568. if dev[0].get_status_field("tls_session_reused") != '0':
  4569. raise Exception("Unexpected session resumption on the first connection")
  4570. dev[0].request("REAUTHENTICATE")
  4571. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4572. if ev is None:
  4573. raise Exception("EAP success timed out")
  4574. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4575. if ev is None:
  4576. raise Exception("Key handshake with the AP timed out")
  4577. if dev[0].get_status_field("tls_session_reused") != '1':
  4578. raise Exception("Session resumption not used on the second connection")
  4579. def test_eap_ttls_eap_gtc_session_resumption(dev, apdev):
  4580. """EAP-TTLS/EAP-GTC session resumption"""
  4581. params = int_eap_server_params()
  4582. params['tls_session_lifetime'] = '60'
  4583. hapd = hostapd.add_ap(apdev[0], params)
  4584. check_tls_session_resumption_capa(dev[0], hapd)
  4585. eap_connect(dev[0], hapd, "TTLS", "user",
  4586. anonymous_identity="ttls", password="password",
  4587. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC")
  4588. if dev[0].get_status_field("tls_session_reused") != '0':
  4589. raise Exception("Unexpected session resumption on the first connection")
  4590. dev[0].request("REAUTHENTICATE")
  4591. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4592. if ev is None:
  4593. raise Exception("EAP success timed out")
  4594. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4595. if ev is None:
  4596. raise Exception("Key handshake with the AP timed out")
  4597. if dev[0].get_status_field("tls_session_reused") != '1':
  4598. raise Exception("Session resumption not used on the second connection")
  4599. def test_eap_ttls_no_session_resumption(dev, apdev):
  4600. """EAP-TTLS session resumption disabled on server"""
  4601. params = int_eap_server_params()
  4602. params['tls_session_lifetime'] = '0'
  4603. hapd = hostapd.add_ap(apdev[0], params)
  4604. eap_connect(dev[0], hapd, "TTLS", "pap user",
  4605. anonymous_identity="ttls", password="password",
  4606. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  4607. phase2="auth=PAP")
  4608. if dev[0].get_status_field("tls_session_reused") != '0':
  4609. raise Exception("Unexpected session resumption on the first connection")
  4610. dev[0].request("REAUTHENTICATE")
  4611. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4612. if ev is None:
  4613. raise Exception("EAP success timed out")
  4614. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4615. if ev is None:
  4616. raise Exception("Key handshake with the AP timed out")
  4617. if dev[0].get_status_field("tls_session_reused") != '0':
  4618. raise Exception("Unexpected session resumption on the second connection")
  4619. def test_eap_peap_session_resumption(dev, apdev):
  4620. """EAP-PEAP session resumption"""
  4621. params = int_eap_server_params()
  4622. params['tls_session_lifetime'] = '60'
  4623. hapd = hostapd.add_ap(apdev[0], params)
  4624. check_tls_session_resumption_capa(dev[0], hapd)
  4625. eap_connect(dev[0], hapd, "PEAP", "user",
  4626. anonymous_identity="peap", password="password",
  4627. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4628. if dev[0].get_status_field("tls_session_reused") != '0':
  4629. raise Exception("Unexpected session resumption on the first connection")
  4630. dev[0].request("REAUTHENTICATE")
  4631. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4632. if ev is None:
  4633. raise Exception("EAP success timed out")
  4634. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4635. if ev is None:
  4636. raise Exception("Key handshake with the AP timed out")
  4637. if dev[0].get_status_field("tls_session_reused") != '1':
  4638. raise Exception("Session resumption not used on the second connection")
  4639. def test_eap_peap_session_resumption_crypto_binding(dev, apdev):
  4640. """EAP-PEAP session resumption with crypto binding"""
  4641. params = int_eap_server_params()
  4642. params['tls_session_lifetime'] = '60'
  4643. hapd = hostapd.add_ap(apdev[0], params)
  4644. check_tls_session_resumption_capa(dev[0], hapd)
  4645. eap_connect(dev[0], hapd, "PEAP", "user",
  4646. anonymous_identity="peap", password="password",
  4647. phase1="peapver=0 crypto_binding=2",
  4648. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4649. if dev[0].get_status_field("tls_session_reused") != '0':
  4650. raise Exception("Unexpected session resumption on the first connection")
  4651. dev[0].request("REAUTHENTICATE")
  4652. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4653. if ev is None:
  4654. raise Exception("EAP success timed out")
  4655. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4656. if ev is None:
  4657. raise Exception("Key handshake with the AP timed out")
  4658. if dev[0].get_status_field("tls_session_reused") != '1':
  4659. raise Exception("Session resumption not used on the second connection")
  4660. def test_eap_peap_no_session_resumption(dev, apdev):
  4661. """EAP-PEAP session resumption disabled on server"""
  4662. params = int_eap_server_params()
  4663. hapd = hostapd.add_ap(apdev[0], params)
  4664. eap_connect(dev[0], hapd, "PEAP", "user",
  4665. anonymous_identity="peap", password="password",
  4666. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  4667. if dev[0].get_status_field("tls_session_reused") != '0':
  4668. raise Exception("Unexpected session resumption on the first connection")
  4669. dev[0].request("REAUTHENTICATE")
  4670. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4671. if ev is None:
  4672. raise Exception("EAP success timed out")
  4673. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4674. if ev is None:
  4675. raise Exception("Key handshake with the AP timed out")
  4676. if dev[0].get_status_field("tls_session_reused") != '0':
  4677. raise Exception("Unexpected session resumption on the second connection")
  4678. def test_eap_tls_session_resumption(dev, apdev):
  4679. """EAP-TLS session resumption"""
  4680. params = int_eap_server_params()
  4681. params['tls_session_lifetime'] = '60'
  4682. hapd = hostapd.add_ap(apdev[0], params)
  4683. check_tls_session_resumption_capa(dev[0], hapd)
  4684. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4685. client_cert="auth_serv/user.pem",
  4686. private_key="auth_serv/user.key")
  4687. if dev[0].get_status_field("tls_session_reused") != '0':
  4688. raise Exception("Unexpected session resumption on the first connection")
  4689. dev[0].request("REAUTHENTICATE")
  4690. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4691. if ev is None:
  4692. raise Exception("EAP success timed out")
  4693. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4694. if ev is None:
  4695. raise Exception("Key handshake with the AP timed out")
  4696. if dev[0].get_status_field("tls_session_reused") != '1':
  4697. raise Exception("Session resumption not used on the second connection")
  4698. dev[0].request("REAUTHENTICATE")
  4699. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4700. if ev is None:
  4701. raise Exception("EAP success timed out")
  4702. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4703. if ev is None:
  4704. raise Exception("Key handshake with the AP timed out")
  4705. if dev[0].get_status_field("tls_session_reused") != '1':
  4706. raise Exception("Session resumption not used on the third connection")
  4707. def test_eap_tls_session_resumption_expiration(dev, apdev):
  4708. """EAP-TLS session resumption"""
  4709. params = int_eap_server_params()
  4710. params['tls_session_lifetime'] = '1'
  4711. hapd = hostapd.add_ap(apdev[0], params)
  4712. check_tls_session_resumption_capa(dev[0], hapd)
  4713. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4714. client_cert="auth_serv/user.pem",
  4715. private_key="auth_serv/user.key")
  4716. if dev[0].get_status_field("tls_session_reused") != '0':
  4717. raise Exception("Unexpected session resumption on the first connection")
  4718. # Allow multiple attempts since OpenSSL may not expire the cached entry
  4719. # immediately.
  4720. for i in range(10):
  4721. time.sleep(1.2)
  4722. dev[0].request("REAUTHENTICATE")
  4723. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4724. if ev is None:
  4725. raise Exception("EAP success timed out")
  4726. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4727. if ev is None:
  4728. raise Exception("Key handshake with the AP timed out")
  4729. if dev[0].get_status_field("tls_session_reused") == '0':
  4730. break
  4731. if dev[0].get_status_field("tls_session_reused") != '0':
  4732. raise Exception("Session resumption used after lifetime expiration")
  4733. def test_eap_tls_no_session_resumption(dev, apdev):
  4734. """EAP-TLS session resumption disabled on server"""
  4735. params = int_eap_server_params()
  4736. hapd = hostapd.add_ap(apdev[0], params)
  4737. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4738. client_cert="auth_serv/user.pem",
  4739. private_key="auth_serv/user.key")
  4740. if dev[0].get_status_field("tls_session_reused") != '0':
  4741. raise Exception("Unexpected session resumption on the first connection")
  4742. dev[0].request("REAUTHENTICATE")
  4743. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4744. if ev is None:
  4745. raise Exception("EAP success timed out")
  4746. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4747. if ev is None:
  4748. raise Exception("Key handshake with the AP timed out")
  4749. if dev[0].get_status_field("tls_session_reused") != '0':
  4750. raise Exception("Unexpected session resumption on the second connection")
  4751. def test_eap_tls_session_resumption_radius(dev, apdev):
  4752. """EAP-TLS session resumption (RADIUS)"""
  4753. params = { "ssid": "as", "beacon_int": "2000",
  4754. "radius_server_clients": "auth_serv/radius_clients.conf",
  4755. "radius_server_auth_port": '18128',
  4756. "eap_server": "1",
  4757. "eap_user_file": "auth_serv/eap_user.conf",
  4758. "ca_cert": "auth_serv/ca.pem",
  4759. "server_cert": "auth_serv/server.pem",
  4760. "private_key": "auth_serv/server.key",
  4761. "tls_session_lifetime": "60" }
  4762. authsrv = hostapd.add_ap(apdev[1], params)
  4763. check_tls_session_resumption_capa(dev[0], authsrv)
  4764. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4765. params['auth_server_port'] = "18128"
  4766. hapd = hostapd.add_ap(apdev[0], params)
  4767. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4768. client_cert="auth_serv/user.pem",
  4769. private_key="auth_serv/user.key")
  4770. if dev[0].get_status_field("tls_session_reused") != '0':
  4771. raise Exception("Unexpected session resumption on the first connection")
  4772. dev[0].request("REAUTHENTICATE")
  4773. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4774. if ev is None:
  4775. raise Exception("EAP success timed out")
  4776. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4777. if ev is None:
  4778. raise Exception("Key handshake with the AP timed out")
  4779. if dev[0].get_status_field("tls_session_reused") != '1':
  4780. raise Exception("Session resumption not used on the second connection")
  4781. def test_eap_tls_no_session_resumption_radius(dev, apdev):
  4782. """EAP-TLS session resumption disabled (RADIUS)"""
  4783. params = { "ssid": "as", "beacon_int": "2000",
  4784. "radius_server_clients": "auth_serv/radius_clients.conf",
  4785. "radius_server_auth_port": '18128',
  4786. "eap_server": "1",
  4787. "eap_user_file": "auth_serv/eap_user.conf",
  4788. "ca_cert": "auth_serv/ca.pem",
  4789. "server_cert": "auth_serv/server.pem",
  4790. "private_key": "auth_serv/server.key",
  4791. "tls_session_lifetime": "0" }
  4792. hostapd.add_ap(apdev[1], params)
  4793. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  4794. params['auth_server_port'] = "18128"
  4795. hapd = hostapd.add_ap(apdev[0], params)
  4796. eap_connect(dev[0], hapd, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  4797. client_cert="auth_serv/user.pem",
  4798. private_key="auth_serv/user.key")
  4799. if dev[0].get_status_field("tls_session_reused") != '0':
  4800. raise Exception("Unexpected session resumption on the first connection")
  4801. dev[0].request("REAUTHENTICATE")
  4802. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  4803. if ev is None:
  4804. raise Exception("EAP success timed out")
  4805. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  4806. if ev is None:
  4807. raise Exception("Key handshake with the AP timed out")
  4808. if dev[0].get_status_field("tls_session_reused") != '0':
  4809. raise Exception("Unexpected session resumption on the second connection")
  4810. def test_eap_mschapv2_errors(dev, apdev):
  4811. """EAP-MSCHAPv2 error cases"""
  4812. check_eap_capa(dev[0], "MSCHAPV2")
  4813. check_eap_capa(dev[0], "FAST")
  4814. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  4815. hapd = hostapd.add_ap(apdev[0], params)
  4816. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4817. identity="phase1-user", password="password",
  4818. scan_freq="2412")
  4819. dev[0].request("REMOVE_NETWORK all")
  4820. dev[0].wait_disconnected()
  4821. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  4822. (1, "nt_password_hash;mschapv2_derive_response"),
  4823. (1, "nt_password_hash;=mschapv2_derive_response"),
  4824. (1, "generate_nt_response;mschapv2_derive_response"),
  4825. (1, "generate_authenticator_response;mschapv2_derive_response"),
  4826. (1, "nt_password_hash;=mschapv2_derive_response"),
  4827. (1, "get_master_key;mschapv2_derive_response"),
  4828. (1, "os_get_random;eap_mschapv2_challenge_reply") ]
  4829. for count, func in tests:
  4830. with fail_test(dev[0], count, func):
  4831. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4832. identity="phase1-user", password="password",
  4833. wait_connect=False, scan_freq="2412")
  4834. wait_fail_trigger(dev[0], "GET_FAIL")
  4835. dev[0].request("REMOVE_NETWORK all")
  4836. dev[0].wait_disconnected()
  4837. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  4838. (1, "hash_nt_password_hash;=mschapv2_derive_response"),
  4839. (1, "generate_nt_response_pwhash;mschapv2_derive_response"),
  4840. (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ]
  4841. for count, func in tests:
  4842. with fail_test(dev[0], count, func):
  4843. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4844. identity="phase1-user",
  4845. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  4846. wait_connect=False, scan_freq="2412")
  4847. wait_fail_trigger(dev[0], "GET_FAIL")
  4848. dev[0].request("REMOVE_NETWORK all")
  4849. dev[0].wait_disconnected()
  4850. tests = [ (1, "eap_mschapv2_init"),
  4851. (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"),
  4852. (1, "eap_msg_alloc;eap_mschapv2_success"),
  4853. (1, "eap_mschapv2_getKey") ]
  4854. for count, func in tests:
  4855. with alloc_fail(dev[0], count, func):
  4856. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4857. identity="phase1-user", password="password",
  4858. wait_connect=False, scan_freq="2412")
  4859. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4860. dev[0].request("REMOVE_NETWORK all")
  4861. dev[0].wait_disconnected()
  4862. tests = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ]
  4863. for count, func in tests:
  4864. with alloc_fail(dev[0], count, func):
  4865. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  4866. identity="phase1-user", password="wrong password",
  4867. wait_connect=False, scan_freq="2412")
  4868. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4869. dev[0].request("REMOVE_NETWORK all")
  4870. dev[0].wait_disconnected()
  4871. tests = [ (2, "eap_mschapv2_init"),
  4872. (3, "eap_mschapv2_init") ]
  4873. for count, func in tests:
  4874. with alloc_fail(dev[0], count, func):
  4875. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST",
  4876. anonymous_identity="FAST", identity="user",
  4877. password="password",
  4878. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  4879. phase1="fast_provisioning=1",
  4880. pac_file="blob://fast_pac",
  4881. wait_connect=False, scan_freq="2412")
  4882. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4883. dev[0].request("REMOVE_NETWORK all")
  4884. dev[0].wait_disconnected()
  4885. def test_eap_gpsk_errors(dev, apdev):
  4886. """EAP-GPSK error cases"""
  4887. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  4888. hapd = hostapd.add_ap(apdev[0], params)
  4889. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4890. identity="gpsk user",
  4891. password="abcdefghijklmnop0123456789abcdef",
  4892. scan_freq="2412")
  4893. dev[0].request("REMOVE_NETWORK all")
  4894. dev[0].wait_disconnected()
  4895. tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None),
  4896. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  4897. "cipher=1"),
  4898. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  4899. "cipher=2"),
  4900. (1, "eap_gpsk_derive_keys_helper", None),
  4901. (2, "eap_gpsk_derive_keys_helper", None),
  4902. (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  4903. "cipher=1"),
  4904. (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  4905. "cipher=2"),
  4906. (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None),
  4907. (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None),
  4908. (1, "eap_gpsk_derive_mid_helper", None) ]
  4909. for count, func, phase1 in tests:
  4910. with fail_test(dev[0], count, func):
  4911. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4912. identity="gpsk user",
  4913. password="abcdefghijklmnop0123456789abcdef",
  4914. phase1=phase1,
  4915. wait_connect=False, scan_freq="2412")
  4916. wait_fail_trigger(dev[0], "GET_FAIL")
  4917. dev[0].request("REMOVE_NETWORK all")
  4918. dev[0].wait_disconnected()
  4919. tests = [ (1, "eap_gpsk_init"),
  4920. (2, "eap_gpsk_init"),
  4921. (3, "eap_gpsk_init"),
  4922. (1, "eap_gpsk_process_id_server"),
  4923. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"),
  4924. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  4925. (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  4926. (1, "eap_gpsk_derive_keys"),
  4927. (1, "eap_gpsk_derive_keys_helper"),
  4928. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"),
  4929. (1, "eap_gpsk_getKey"),
  4930. (1, "eap_gpsk_get_emsk"),
  4931. (1, "eap_gpsk_get_session_id") ]
  4932. for count, func in tests:
  4933. with alloc_fail(dev[0], count, func):
  4934. dev[0].request("ERP_FLUSH")
  4935. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  4936. identity="gpsk user", erp="1",
  4937. password="abcdefghijklmnop0123456789abcdef",
  4938. wait_connect=False, scan_freq="2412")
  4939. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  4940. dev[0].request("REMOVE_NETWORK all")
  4941. dev[0].wait_disconnected()
  4942. def test_ap_wpa2_eap_sim_db(dev, apdev, params):
  4943. """EAP-SIM DB error cases"""
  4944. sockpath = '/tmp/hlr_auc_gw.sock-test'
  4945. try:
  4946. os.remove(sockpath)
  4947. except:
  4948. pass
  4949. hparams = int_eap_server_params()
  4950. hparams['eap_sim_db'] = 'unix:' + sockpath
  4951. hapd = hostapd.add_ap(apdev[0], hparams)
  4952. # Initial test with hlr_auc_gw socket not available
  4953. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  4954. eap="SIM", identity="1232010000000000",
  4955. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  4956. scan_freq="2412", wait_connect=False)
  4957. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4958. if ev is None:
  4959. raise Exception("EAP-Failure not reported")
  4960. dev[0].wait_disconnected()
  4961. dev[0].request("DISCONNECT")
  4962. # Test with invalid responses and response timeout
  4963. class test_handler(SocketServer.DatagramRequestHandler):
  4964. def handle(self):
  4965. data = self.request[0].strip()
  4966. socket = self.request[1]
  4967. logger.debug("Received hlr_auc_gw request: " + data)
  4968. # EAP-SIM DB: Failed to parse response string
  4969. socket.sendto("FOO", self.client_address)
  4970. # EAP-SIM DB: Failed to parse response string
  4971. socket.sendto("FOO 1", self.client_address)
  4972. # EAP-SIM DB: Unknown external response
  4973. socket.sendto("FOO 1 2", self.client_address)
  4974. logger.info("No proper response - wait for pending eap_sim_db request timeout")
  4975. server = SocketServer.UnixDatagramServer(sockpath, test_handler)
  4976. server.timeout = 1
  4977. dev[0].select_network(id)
  4978. server.handle_request()
  4979. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  4980. if ev is None:
  4981. raise Exception("EAP-Failure not reported")
  4982. dev[0].wait_disconnected()
  4983. dev[0].request("DISCONNECT")
  4984. # Test with a valid response
  4985. class test_handler2(SocketServer.DatagramRequestHandler):
  4986. def handle(self):
  4987. data = self.request[0].strip()
  4988. socket = self.request[1]
  4989. logger.debug("Received hlr_auc_gw request: " + data)
  4990. fname = os.path.join(params['logdir'],
  4991. 'hlr_auc_gw.milenage_db')
  4992. cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw',
  4993. '-m', fname, data],
  4994. stdout=subprocess.PIPE)
  4995. res = cmd.stdout.read().strip()
  4996. cmd.stdout.close()
  4997. logger.debug("hlr_auc_gw response: " + res)
  4998. socket.sendto(res, self.client_address)
  4999. server.RequestHandlerClass = test_handler2
  5000. dev[0].select_network(id)
  5001. server.handle_request()
  5002. dev[0].wait_connected()
  5003. dev[0].request("DISCONNECT")
  5004. dev[0].wait_disconnected()
  5005. def test_eap_tls_sha512(dev, apdev, params):
  5006. """EAP-TLS with SHA512 signature"""
  5007. params = int_eap_server_params()
  5008. params["ca_cert"] = "auth_serv/sha512-ca.pem"
  5009. params["server_cert"] = "auth_serv/sha512-server.pem"
  5010. params["private_key"] = "auth_serv/sha512-server.key"
  5011. hostapd.add_ap(apdev[0], params)
  5012. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5013. identity="tls user sha512",
  5014. ca_cert="auth_serv/sha512-ca.pem",
  5015. client_cert="auth_serv/sha512-user.pem",
  5016. private_key="auth_serv/sha512-user.key",
  5017. scan_freq="2412")
  5018. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5019. identity="tls user sha512",
  5020. ca_cert="auth_serv/sha512-ca.pem",
  5021. client_cert="auth_serv/sha384-user.pem",
  5022. private_key="auth_serv/sha384-user.key",
  5023. scan_freq="2412")
  5024. def test_eap_tls_sha384(dev, apdev, params):
  5025. """EAP-TLS with SHA384 signature"""
  5026. params = int_eap_server_params()
  5027. params["ca_cert"] = "auth_serv/sha512-ca.pem"
  5028. params["server_cert"] = "auth_serv/sha384-server.pem"
  5029. params["private_key"] = "auth_serv/sha384-server.key"
  5030. hostapd.add_ap(apdev[0], params)
  5031. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5032. identity="tls user sha512",
  5033. ca_cert="auth_serv/sha512-ca.pem",
  5034. client_cert="auth_serv/sha512-user.pem",
  5035. private_key="auth_serv/sha512-user.key",
  5036. scan_freq="2412")
  5037. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5038. identity="tls user sha512",
  5039. ca_cert="auth_serv/sha512-ca.pem",
  5040. client_cert="auth_serv/sha384-user.pem",
  5041. private_key="auth_serv/sha384-user.key",
  5042. scan_freq="2412")
  5043. def test_ap_wpa2_eap_assoc_rsn(dev, apdev):
  5044. """WPA2-Enterprise AP and association request RSN IE differences"""
  5045. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5046. hostapd.add_ap(apdev[0], params)
  5047. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap-11w")
  5048. params["ieee80211w"] = "2"
  5049. hostapd.add_ap(apdev[1], params)
  5050. # Success cases with optional RSN IE fields removed one by one
  5051. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  5052. "30140100000fac040100000fac040100000fac010000"),
  5053. ("Extra PMKIDCount field in RSN IE",
  5054. "30160100000fac040100000fac040100000fac0100000000"),
  5055. ("Extra Group Management Cipher Suite in RSN IE",
  5056. "301a0100000fac040100000fac040100000fac0100000000000fac06"),
  5057. ("Extra undefined extension field in RSN IE",
  5058. "301c0100000fac040100000fac040100000fac0100000000000fac061122"),
  5059. ("RSN IE without RSN Capabilities",
  5060. "30120100000fac040100000fac040100000fac01"),
  5061. ("RSN IE without AKM", "300c0100000fac040100000fac04"),
  5062. ("RSN IE without pairwise", "30060100000fac04"),
  5063. ("RSN IE without group", "30020100") ]
  5064. for title, ie in tests:
  5065. logger.info(title)
  5066. set_test_assoc_ie(dev[0], ie)
  5067. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5068. identity="gpsk user",
  5069. password="abcdefghijklmnop0123456789abcdef",
  5070. scan_freq="2412")
  5071. dev[0].request("REMOVE_NETWORK all")
  5072. dev[0].wait_disconnected()
  5073. tests = [ ("Normal wpa_supplicant assoc req RSN IE",
  5074. "30140100000fac040100000fac040100000fac01cc00"),
  5075. ("Group management cipher included in assoc req RSN IE",
  5076. "301a0100000fac040100000fac040100000fac01cc000000000fac06") ]
  5077. for title, ie in tests:
  5078. logger.info(title)
  5079. set_test_assoc_ie(dev[0], ie)
  5080. dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1",
  5081. eap="GPSK", identity="gpsk user",
  5082. password="abcdefghijklmnop0123456789abcdef",
  5083. scan_freq="2412")
  5084. dev[0].request("REMOVE_NETWORK all")
  5085. dev[0].wait_disconnected()
  5086. tests = [ ("Invalid group cipher", "30060100000fac02", 41),
  5087. ("Invalid pairwise cipher", "300c0100000fac040100000fac02", 42) ]
  5088. for title, ie, status in tests:
  5089. logger.info(title)
  5090. set_test_assoc_ie(dev[0], ie)
  5091. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  5092. identity="gpsk user",
  5093. password="abcdefghijklmnop0123456789abcdef",
  5094. scan_freq="2412", wait_connect=False)
  5095. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  5096. if ev is None:
  5097. raise Exception("Association rejection not reported")
  5098. if "status_code=" + str(status) not in ev:
  5099. raise Exception("Unexpected status code: " + ev)
  5100. dev[0].request("REMOVE_NETWORK all")
  5101. dev[0].dump_monitor()
  5102. tests = [ ("Management frame protection not enabled",
  5103. "30140100000fac040100000fac040100000fac010000", 31),
  5104. ("Unsupported management group cipher",
  5105. "301a0100000fac040100000fac040100000fac01cc000000000fac0b", 31) ]
  5106. for title, ie, status in tests:
  5107. logger.info(title)
  5108. set_test_assoc_ie(dev[0], ie)
  5109. dev[0].connect("test-wpa2-eap-11w", key_mgmt="WPA-EAP", ieee80211w="1",
  5110. eap="GPSK", identity="gpsk user",
  5111. password="abcdefghijklmnop0123456789abcdef",
  5112. scan_freq="2412", wait_connect=False)
  5113. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  5114. if ev is None:
  5115. raise Exception("Association rejection not reported")
  5116. if "status_code=" + str(status) not in ev:
  5117. raise Exception("Unexpected status code: " + ev)
  5118. dev[0].request("REMOVE_NETWORK all")
  5119. dev[0].dump_monitor()
  5120. def test_eap_tls_ext_cert_check(dev, apdev):
  5121. """EAP-TLS and external server certification validation"""
  5122. # With internal server certificate chain validation
  5123. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5124. identity="tls user",
  5125. ca_cert="auth_serv/ca.pem",
  5126. client_cert="auth_serv/user.pem",
  5127. private_key="auth_serv/user.key",
  5128. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5129. only_add_network=True)
  5130. run_ext_cert_check(dev, apdev, id)
  5131. def test_eap_ttls_ext_cert_check(dev, apdev):
  5132. """EAP-TTLS and external server certification validation"""
  5133. # Without internal server certificate chain validation
  5134. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  5135. identity="pap user", anonymous_identity="ttls",
  5136. password="password", phase2="auth=PAP",
  5137. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5138. only_add_network=True)
  5139. run_ext_cert_check(dev, apdev, id)
  5140. def test_eap_peap_ext_cert_check(dev, apdev):
  5141. """EAP-PEAP and external server certification validation"""
  5142. # With internal server certificate chain validation
  5143. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  5144. identity="user", anonymous_identity="peap",
  5145. ca_cert="auth_serv/ca.pem",
  5146. password="password", phase2="auth=MSCHAPV2",
  5147. phase1="tls_ext_cert_check=1", scan_freq="2412",
  5148. only_add_network=True)
  5149. run_ext_cert_check(dev, apdev, id)
  5150. def test_eap_fast_ext_cert_check(dev, apdev):
  5151. """EAP-FAST and external server certification validation"""
  5152. check_eap_capa(dev[0], "FAST")
  5153. # With internal server certificate chain validation
  5154. dev[0].request("SET blob fast_pac_auth_ext ")
  5155. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  5156. identity="user", anonymous_identity="FAST",
  5157. ca_cert="auth_serv/ca.pem",
  5158. password="password", phase2="auth=GTC",
  5159. phase1="tls_ext_cert_check=1 fast_provisioning=2",
  5160. pac_file="blob://fast_pac_auth_ext",
  5161. scan_freq="2412",
  5162. only_add_network=True)
  5163. run_ext_cert_check(dev, apdev, id)
  5164. def run_ext_cert_check(dev, apdev, net_id):
  5165. check_ext_cert_check_support(dev[0])
  5166. if not openssl_imported:
  5167. raise HwsimSkip("OpenSSL python method not available")
  5168. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5169. hapd = hostapd.add_ap(apdev[0], params)
  5170. dev[0].select_network(net_id)
  5171. certs = {}
  5172. while True:
  5173. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT",
  5174. "CTRL-REQ-EXT_CERT_CHECK",
  5175. "CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  5176. if ev is None:
  5177. raise Exception("No peer server certificate event seen")
  5178. if "CTRL-EVENT-EAP-PEER-CERT" in ev:
  5179. depth = None
  5180. cert = None
  5181. vals = ev.split(' ')
  5182. for v in vals:
  5183. if v.startswith("depth="):
  5184. depth = int(v.split('=')[1])
  5185. elif v.startswith("cert="):
  5186. cert = v.split('=')[1]
  5187. if depth is not None and cert:
  5188. certs[depth] = binascii.unhexlify(cert)
  5189. elif "CTRL-EVENT-EAP-SUCCESS" in ev:
  5190. raise Exception("Unexpected EAP-Success")
  5191. elif "CTRL-REQ-EXT_CERT_CHECK" in ev:
  5192. id = ev.split(':')[0].split('-')[-1]
  5193. break
  5194. if 0 not in certs:
  5195. raise Exception("Server certificate not received")
  5196. if 1 not in certs:
  5197. raise Exception("Server certificate issuer not received")
  5198. cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
  5199. certs[0])
  5200. cn = cert.get_subject().commonName
  5201. logger.info("Server certificate CN=" + cn)
  5202. issuer = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1,
  5203. certs[1])
  5204. icn = issuer.get_subject().commonName
  5205. logger.info("Issuer certificate CN=" + icn)
  5206. if cn != "server.w1.fi":
  5207. raise Exception("Unexpected server certificate CN: " + cn)
  5208. if icn != "Root CA":
  5209. raise Exception("Unexpected server certificate issuer CN: " + icn)
  5210. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=0.1)
  5211. if ev:
  5212. raise Exception("Unexpected EAP-Success before external check result indication")
  5213. dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":good")
  5214. dev[0].wait_connected()
  5215. dev[0].request("DISCONNECT")
  5216. dev[0].wait_disconnected()
  5217. if "FAIL" in dev[0].request("PMKSA_FLUSH"):
  5218. raise Exception("PMKSA_FLUSH failed")
  5219. dev[0].request("SET blob fast_pac_auth_ext ")
  5220. dev[0].request("RECONNECT")
  5221. ev = dev[0].wait_event(["CTRL-REQ-EXT_CERT_CHECK"], timeout=10)
  5222. if ev is None:
  5223. raise Exception("No peer server certificate event seen (2)")
  5224. id = ev.split(':')[0].split('-')[-1]
  5225. dev[0].request("CTRL-RSP-EXT_CERT_CHECK-" + id + ":bad")
  5226. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  5227. if ev is None:
  5228. raise Exception("EAP-Failure not reported")
  5229. dev[0].request("REMOVE_NETWORK all")
  5230. dev[0].wait_disconnected()
  5231. def test_eap_tls_errors(dev, apdev):
  5232. """EAP-TLS error cases"""
  5233. params = int_eap_server_params()
  5234. params['fragment_size'] = '100'
  5235. hostapd.add_ap(apdev[0], params)
  5236. with alloc_fail(dev[0], 1,
  5237. "eap_peer_tls_reassemble_fragment"):
  5238. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5239. identity="tls user", ca_cert="auth_serv/ca.pem",
  5240. client_cert="auth_serv/user.pem",
  5241. private_key="auth_serv/user.key",
  5242. wait_connect=False, scan_freq="2412")
  5243. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5244. dev[0].request("REMOVE_NETWORK all")
  5245. dev[0].wait_disconnected()
  5246. with alloc_fail(dev[0], 1, "eap_tls_init"):
  5247. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5248. identity="tls user", ca_cert="auth_serv/ca.pem",
  5249. client_cert="auth_serv/user.pem",
  5250. private_key="auth_serv/user.key",
  5251. wait_connect=False, scan_freq="2412")
  5252. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5253. dev[0].request("REMOVE_NETWORK all")
  5254. dev[0].wait_disconnected()
  5255. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init"):
  5256. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5257. identity="tls user", ca_cert="auth_serv/ca.pem",
  5258. client_cert="auth_serv/user.pem",
  5259. private_key="auth_serv/user.key",
  5260. engine="1",
  5261. wait_connect=False, scan_freq="2412")
  5262. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5263. ev = dev[0].wait_event(["CTRL-REQ-PIN"], timeout=5)
  5264. if ev is None:
  5265. raise Exception("No CTRL-REQ-PIN seen")
  5266. dev[0].request("REMOVE_NETWORK all")
  5267. dev[0].wait_disconnected()
  5268. tests = [ "eap_peer_tls_derive_key;eap_tls_success",
  5269. "eap_peer_tls_derive_session_id;eap_tls_success",
  5270. "eap_tls_getKey",
  5271. "eap_tls_get_emsk",
  5272. "eap_tls_get_session_id" ]
  5273. for func in tests:
  5274. with alloc_fail(dev[0], 1, func):
  5275. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  5276. identity="tls user", ca_cert="auth_serv/ca.pem",
  5277. client_cert="auth_serv/user.pem",
  5278. private_key="auth_serv/user.key",
  5279. erp="1",
  5280. wait_connect=False, scan_freq="2412")
  5281. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5282. dev[0].request("REMOVE_NETWORK all")
  5283. dev[0].wait_disconnected()
  5284. with alloc_fail(dev[0], 1, "eap_unauth_tls_init"):
  5285. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS",
  5286. identity="unauth-tls", ca_cert="auth_serv/ca.pem",
  5287. wait_connect=False, scan_freq="2412")
  5288. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5289. dev[0].request("REMOVE_NETWORK all")
  5290. dev[0].wait_disconnected()
  5291. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_unauth_tls_init"):
  5292. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="UNAUTH-TLS",
  5293. identity="unauth-tls", ca_cert="auth_serv/ca.pem",
  5294. wait_connect=False, scan_freq="2412")
  5295. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5296. dev[0].request("REMOVE_NETWORK all")
  5297. dev[0].wait_disconnected()
  5298. with alloc_fail(dev[0], 1, "eap_wfa_unauth_tls_init"):
  5299. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  5300. eap="WFA-UNAUTH-TLS",
  5301. identity="osen@example.com", ca_cert="auth_serv/ca.pem",
  5302. wait_connect=False, scan_freq="2412")
  5303. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5304. dev[0].request("REMOVE_NETWORK all")
  5305. dev[0].wait_disconnected()
  5306. with alloc_fail(dev[0], 1, "eap_peer_tls_ssl_init;eap_wfa_unauth_tls_init"):
  5307. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  5308. eap="WFA-UNAUTH-TLS",
  5309. identity="osen@example.com", ca_cert="auth_serv/ca.pem",
  5310. wait_connect=False, scan_freq="2412")
  5311. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  5312. dev[0].request("REMOVE_NETWORK all")
  5313. dev[0].wait_disconnected()
  5314. def test_ap_wpa2_eap_status(dev, apdev):
  5315. """EAP state machine status information"""
  5316. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5317. hostapd.add_ap(apdev[0], params)
  5318. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PEAP",
  5319. identity="cert user",
  5320. ca_cert="auth_serv/ca.pem", phase2="auth=TLS",
  5321. ca_cert2="auth_serv/ca.pem",
  5322. client_cert2="auth_serv/user.pem",
  5323. private_key2="auth_serv/user.key",
  5324. scan_freq="2412", wait_connect=False)
  5325. success = False
  5326. states = []
  5327. method_states = []
  5328. decisions = []
  5329. req_methods = []
  5330. selected_methods = []
  5331. for i in range(100000):
  5332. s = dev[0].get_status(extra="VERBOSE")
  5333. if 'EAP state' in s:
  5334. state = s['EAP state']
  5335. if state:
  5336. if state not in states:
  5337. states.append(state)
  5338. if state == "SUCCESS":
  5339. success = True
  5340. break
  5341. if 'methodState' in s:
  5342. val = s['methodState']
  5343. if val not in method_states:
  5344. method_states.append(val)
  5345. if 'decision' in s:
  5346. val = s['decision']
  5347. if val not in decisions:
  5348. decisions.append(val)
  5349. if 'reqMethod' in s:
  5350. val = s['reqMethod']
  5351. if val not in req_methods:
  5352. req_methods.append(val)
  5353. if 'selectedMethod' in s:
  5354. val = s['selectedMethod']
  5355. if val not in selected_methods:
  5356. selected_methods.append(val)
  5357. logger.info("Iterations: %d" % i)
  5358. logger.info("EAP states: " + str(states))
  5359. logger.info("methodStates: " + str(method_states))
  5360. logger.info("decisions: " + str(decisions))
  5361. logger.info("reqMethods: " + str(req_methods))
  5362. logger.info("selectedMethods: " + str(selected_methods))
  5363. if not success:
  5364. raise Exception("EAP did not succeed")
  5365. dev[0].wait_connected()
  5366. dev[0].request("REMOVE_NETWORK all")
  5367. dev[0].wait_disconnected()
  5368. def test_ap_wpa2_eap_gpsk_ptk_rekey_ap(dev, apdev):
  5369. """WPA2-Enterprise with EAP-GPSK and PTK rekey enforced by AP"""
  5370. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  5371. params['wpa_ptk_rekey'] = '2'
  5372. hapd = hostapd.add_ap(apdev[0], params)
  5373. id = eap_connect(dev[0], hapd, "GPSK", "gpsk user",
  5374. password="abcdefghijklmnop0123456789abcdef")
  5375. ev = dev[0].wait_event(["WPA: Key negotiation completed"])
  5376. if ev is None:
  5377. raise Exception("PTK rekey timed out")
  5378. hwsim_utils.test_connectivity(dev[0], hapd)