test_ap_eap.py 231 KB

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