test_ap_eap.py 159 KB

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