test_ap_eap.py 194 KB

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