test_ap_eap.py 201 KB

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