test_ap_eap.py 207 KB

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