test_ap_eap.py 176 KB

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