test_ap_eap.py 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409
  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. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  1220. private_key="auth_serv/user2.pkcs12",
  1221. private_key_passwd="whatever")
  1222. dev[0].request("REMOVE_NETWORK all")
  1223. dev[0].wait_disconnected()
  1224. def test_ap_wpa2_eap_tls_pkcs12_blob(dev, apdev):
  1225. """WPA2-Enterprise connection using EAP-TLS and PKCS#12 from configuration blob"""
  1226. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1227. hostapd.add_ap(apdev[0]['ifname'], params)
  1228. cert = read_pem("auth_serv/ca.pem")
  1229. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1230. raise Exception("Could not set cacert blob")
  1231. with open("auth_serv/user.pkcs12", "rb") as f:
  1232. if "OK" not in dev[0].request("SET blob pkcs12 " + f.read().encode("hex")):
  1233. raise Exception("Could not set pkcs12 blob")
  1234. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="blob://cacert",
  1235. private_key="blob://pkcs12",
  1236. private_key_passwd="whatever")
  1237. def test_ap_wpa2_eap_tls_neg_incorrect_trust_root(dev, apdev):
  1238. """WPA2-Enterprise negative test - incorrect trust root"""
  1239. check_eap_capa(dev[0], "MSCHAPV2")
  1240. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1241. hostapd.add_ap(apdev[0]['ifname'], params)
  1242. cert = read_pem("auth_serv/ca-incorrect.pem")
  1243. if "OK" not in dev[0].request("SET blob cacert " + cert.encode("hex")):
  1244. raise Exception("Could not set cacert blob")
  1245. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1246. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1247. password="password", phase2="auth=MSCHAPV2",
  1248. ca_cert="blob://cacert",
  1249. wait_connect=False, scan_freq="2412")
  1250. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1251. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1252. password="password", phase2="auth=MSCHAPV2",
  1253. ca_cert="auth_serv/ca-incorrect.pem",
  1254. wait_connect=False, scan_freq="2412")
  1255. for dev in (dev[0], dev[1]):
  1256. ev = dev.wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1257. if ev is None:
  1258. raise Exception("Association and EAP start timed out")
  1259. ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1260. if ev is None:
  1261. raise Exception("EAP method selection timed out")
  1262. if "TTLS" not in ev:
  1263. raise Exception("Unexpected EAP method")
  1264. ev = dev.wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1265. "CTRL-EVENT-EAP-SUCCESS",
  1266. "CTRL-EVENT-EAP-FAILURE",
  1267. "CTRL-EVENT-CONNECTED",
  1268. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1269. if ev is None:
  1270. raise Exception("EAP result timed out")
  1271. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1272. raise Exception("TLS certificate error not reported")
  1273. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1274. "CTRL-EVENT-EAP-FAILURE",
  1275. "CTRL-EVENT-CONNECTED",
  1276. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1277. if ev is None:
  1278. raise Exception("EAP result(2) timed out")
  1279. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1280. raise Exception("EAP failure not reported")
  1281. ev = dev.wait_event(["CTRL-EVENT-CONNECTED",
  1282. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1283. if ev is None:
  1284. raise Exception("EAP result(3) timed out")
  1285. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1286. raise Exception("Disconnection not reported")
  1287. ev = dev.wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1288. if ev is None:
  1289. raise Exception("Network block disabling not reported")
  1290. def test_ap_wpa2_eap_tls_diff_ca_trust(dev, apdev):
  1291. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1292. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1293. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1294. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1295. identity="pap user", anonymous_identity="ttls",
  1296. password="password", phase2="auth=PAP",
  1297. ca_cert="auth_serv/ca.pem",
  1298. wait_connect=True, scan_freq="2412")
  1299. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1300. identity="pap user", anonymous_identity="ttls",
  1301. password="password", phase2="auth=PAP",
  1302. ca_cert="auth_serv/ca-incorrect.pem",
  1303. only_add_network=True, scan_freq="2412")
  1304. dev[0].request("DISCONNECT")
  1305. dev[0].wait_disconnected()
  1306. dev[0].dump_monitor()
  1307. dev[0].select_network(id, freq="2412")
  1308. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1309. if ev is None:
  1310. raise Exception("EAP-TTLS not re-started")
  1311. ev = dev[0].wait_disconnected(timeout=15)
  1312. if "reason=23" not in ev:
  1313. raise Exception("Proper reason code for disconnection not reported")
  1314. def test_ap_wpa2_eap_tls_diff_ca_trust2(dev, apdev):
  1315. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1316. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1317. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1318. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1319. identity="pap user", anonymous_identity="ttls",
  1320. password="password", phase2="auth=PAP",
  1321. wait_connect=True, scan_freq="2412")
  1322. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1323. identity="pap user", anonymous_identity="ttls",
  1324. password="password", phase2="auth=PAP",
  1325. ca_cert="auth_serv/ca-incorrect.pem",
  1326. only_add_network=True, scan_freq="2412")
  1327. dev[0].request("DISCONNECT")
  1328. dev[0].wait_disconnected()
  1329. dev[0].dump_monitor()
  1330. dev[0].select_network(id, freq="2412")
  1331. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1332. if ev is None:
  1333. raise Exception("EAP-TTLS not re-started")
  1334. ev = dev[0].wait_disconnected(timeout=15)
  1335. if "reason=23" not in ev:
  1336. raise Exception("Proper reason code for disconnection not reported")
  1337. def test_ap_wpa2_eap_tls_diff_ca_trust3(dev, apdev):
  1338. """WPA2-Enterprise connection using EAP-TTLS/PAP and different CA trust"""
  1339. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1340. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1341. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1342. identity="pap user", anonymous_identity="ttls",
  1343. password="password", phase2="auth=PAP",
  1344. ca_cert="auth_serv/ca.pem",
  1345. wait_connect=True, scan_freq="2412")
  1346. dev[0].request("DISCONNECT")
  1347. dev[0].wait_disconnected()
  1348. dev[0].dump_monitor()
  1349. dev[0].set_network_quoted(id, "ca_cert", "auth_serv/ca-incorrect.pem")
  1350. dev[0].select_network(id, freq="2412")
  1351. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=21"], timeout=15)
  1352. if ev is None:
  1353. raise Exception("EAP-TTLS not re-started")
  1354. ev = dev[0].wait_disconnected(timeout=15)
  1355. if "reason=23" not in ev:
  1356. raise Exception("Proper reason code for disconnection not reported")
  1357. def test_ap_wpa2_eap_tls_neg_suffix_match(dev, apdev):
  1358. """WPA2-Enterprise negative test - domain suffix mismatch"""
  1359. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1360. hostapd.add_ap(apdev[0]['ifname'], params)
  1361. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1362. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1363. password="password", phase2="auth=MSCHAPV2",
  1364. ca_cert="auth_serv/ca.pem",
  1365. domain_suffix_match="incorrect.example.com",
  1366. wait_connect=False, scan_freq="2412")
  1367. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1368. if ev is None:
  1369. raise Exception("Association and EAP start timed out")
  1370. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1371. if ev is None:
  1372. raise Exception("EAP method selection timed out")
  1373. if "TTLS" not in ev:
  1374. raise Exception("Unexpected EAP method")
  1375. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1376. "CTRL-EVENT-EAP-SUCCESS",
  1377. "CTRL-EVENT-EAP-FAILURE",
  1378. "CTRL-EVENT-CONNECTED",
  1379. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1380. if ev is None:
  1381. raise Exception("EAP result timed out")
  1382. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1383. raise Exception("TLS certificate error not reported")
  1384. if "Domain suffix mismatch" not in ev:
  1385. raise Exception("Domain suffix mismatch not reported")
  1386. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1387. "CTRL-EVENT-EAP-FAILURE",
  1388. "CTRL-EVENT-CONNECTED",
  1389. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1390. if ev is None:
  1391. raise Exception("EAP result(2) timed out")
  1392. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1393. raise Exception("EAP failure not reported")
  1394. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1395. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1396. if ev is None:
  1397. raise Exception("EAP result(3) timed out")
  1398. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1399. raise Exception("Disconnection not reported")
  1400. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1401. if ev is None:
  1402. raise Exception("Network block disabling not reported")
  1403. def test_ap_wpa2_eap_tls_neg_domain_match(dev, apdev):
  1404. """WPA2-Enterprise negative test - domain mismatch"""
  1405. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1406. hostapd.add_ap(apdev[0]['ifname'], params)
  1407. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1408. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1409. password="password", phase2="auth=MSCHAPV2",
  1410. ca_cert="auth_serv/ca.pem",
  1411. domain_match="w1.fi",
  1412. wait_connect=False, scan_freq="2412")
  1413. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1414. if ev is None:
  1415. raise Exception("Association and EAP start timed out")
  1416. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  1417. if ev is None:
  1418. raise Exception("EAP method selection timed out")
  1419. if "TTLS" not in ev:
  1420. raise Exception("Unexpected EAP method")
  1421. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1422. "CTRL-EVENT-EAP-SUCCESS",
  1423. "CTRL-EVENT-EAP-FAILURE",
  1424. "CTRL-EVENT-CONNECTED",
  1425. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1426. if ev is None:
  1427. raise Exception("EAP result timed out")
  1428. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1429. raise Exception("TLS certificate error not reported")
  1430. if "Domain mismatch" not in ev:
  1431. raise Exception("Domain mismatch not reported")
  1432. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1433. "CTRL-EVENT-EAP-FAILURE",
  1434. "CTRL-EVENT-CONNECTED",
  1435. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1436. if ev is None:
  1437. raise Exception("EAP result(2) timed out")
  1438. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1439. raise Exception("EAP failure not reported")
  1440. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1441. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1442. if ev is None:
  1443. raise Exception("EAP result(3) timed out")
  1444. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1445. raise Exception("Disconnection not reported")
  1446. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1447. if ev is None:
  1448. raise Exception("Network block disabling not reported")
  1449. def test_ap_wpa2_eap_tls_neg_subject_match(dev, apdev):
  1450. """WPA2-Enterprise negative test - subject mismatch"""
  1451. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1452. hostapd.add_ap(apdev[0]['ifname'], params)
  1453. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1454. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1455. password="password", phase2="auth=MSCHAPV2",
  1456. ca_cert="auth_serv/ca.pem",
  1457. subject_match="/C=FI/O=w1.fi/CN=example.com",
  1458. wait_connect=False, scan_freq="2412")
  1459. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1460. if ev is None:
  1461. raise Exception("Association and EAP start timed out")
  1462. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  1463. "EAP: Failed to initialize EAP method"], timeout=10)
  1464. if ev is None:
  1465. raise Exception("EAP method selection timed out")
  1466. if "EAP: Failed to initialize EAP method" in ev:
  1467. tls = dev[0].request("GET tls_library")
  1468. if tls.startswith("OpenSSL"):
  1469. raise Exception("Failed to select EAP method")
  1470. logger.info("subject_match not supported - connection failed, so test succeeded")
  1471. return
  1472. if "TTLS" not in ev:
  1473. raise Exception("Unexpected EAP method")
  1474. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1475. "CTRL-EVENT-EAP-SUCCESS",
  1476. "CTRL-EVENT-EAP-FAILURE",
  1477. "CTRL-EVENT-CONNECTED",
  1478. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1479. if ev is None:
  1480. raise Exception("EAP result timed out")
  1481. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1482. raise Exception("TLS certificate error not reported")
  1483. if "Subject mismatch" not in ev:
  1484. raise Exception("Subject mismatch not reported")
  1485. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1486. "CTRL-EVENT-EAP-FAILURE",
  1487. "CTRL-EVENT-CONNECTED",
  1488. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1489. if ev is None:
  1490. raise Exception("EAP result(2) timed out")
  1491. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1492. raise Exception("EAP failure not reported")
  1493. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1494. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1495. if ev is None:
  1496. raise Exception("EAP result(3) timed out")
  1497. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1498. raise Exception("Disconnection not reported")
  1499. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1500. if ev is None:
  1501. raise Exception("Network block disabling not reported")
  1502. def test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev):
  1503. """WPA2-Enterprise negative test - altsubject mismatch"""
  1504. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1505. hostapd.add_ap(apdev[0]['ifname'], params)
  1506. tests = [ "incorrect.example.com",
  1507. "DNS:incorrect.example.com",
  1508. "DNS:w1.fi",
  1509. "DNS:erver.w1.fi" ]
  1510. for match in tests:
  1511. _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match)
  1512. def _test_ap_wpa2_eap_tls_neg_altsubject_match(dev, apdev, match):
  1513. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1514. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1515. password="password", phase2="auth=MSCHAPV2",
  1516. ca_cert="auth_serv/ca.pem",
  1517. altsubject_match=match,
  1518. wait_connect=False, scan_freq="2412")
  1519. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1520. if ev is None:
  1521. raise Exception("Association and EAP start timed out")
  1522. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD",
  1523. "EAP: Failed to initialize EAP method"], timeout=10)
  1524. if ev is None:
  1525. raise Exception("EAP method selection timed out")
  1526. if "EAP: Failed to initialize EAP method" in ev:
  1527. tls = dev[0].request("GET tls_library")
  1528. if tls.startswith("OpenSSL"):
  1529. raise Exception("Failed to select EAP method")
  1530. logger.info("altsubject_match not supported - connection failed, so test succeeded")
  1531. return
  1532. if "TTLS" not in ev:
  1533. raise Exception("Unexpected EAP method")
  1534. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR",
  1535. "CTRL-EVENT-EAP-SUCCESS",
  1536. "CTRL-EVENT-EAP-FAILURE",
  1537. "CTRL-EVENT-CONNECTED",
  1538. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1539. if ev is None:
  1540. raise Exception("EAP result timed out")
  1541. if "CTRL-EVENT-EAP-TLS-CERT-ERROR" not in ev:
  1542. raise Exception("TLS certificate error not reported")
  1543. if "AltSubject mismatch" not in ev:
  1544. raise Exception("altsubject mismatch not reported")
  1545. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  1546. "CTRL-EVENT-EAP-FAILURE",
  1547. "CTRL-EVENT-CONNECTED",
  1548. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1549. if ev is None:
  1550. raise Exception("EAP result(2) timed out")
  1551. if "CTRL-EVENT-EAP-FAILURE" not in ev:
  1552. raise Exception("EAP failure not reported")
  1553. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  1554. "CTRL-EVENT-DISCONNECTED"], timeout=10)
  1555. if ev is None:
  1556. raise Exception("EAP result(3) timed out")
  1557. if "CTRL-EVENT-DISCONNECTED" not in ev:
  1558. raise Exception("Disconnection not reported")
  1559. ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=10)
  1560. if ev is None:
  1561. raise Exception("Network block disabling not reported")
  1562. dev[0].request("REMOVE_NETWORK all")
  1563. def test_ap_wpa2_eap_unauth_tls(dev, apdev):
  1564. """WPA2-Enterprise connection using UNAUTH-TLS"""
  1565. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1566. hostapd.add_ap(apdev[0]['ifname'], params)
  1567. eap_connect(dev[0], apdev[0], "UNAUTH-TLS", "unauth-tls",
  1568. ca_cert="auth_serv/ca.pem")
  1569. eap_reauth(dev[0], "UNAUTH-TLS")
  1570. def test_ap_wpa2_eap_ttls_server_cert_hash(dev, apdev):
  1571. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash"""
  1572. check_cert_probe_support(dev[0])
  1573. skip_with_fips(dev[0])
  1574. srv_cert_hash = "1477c9cd88391609444b83eca45c4f9f324e3051c5c31fc233ac6aede30ce7cd"
  1575. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1576. hostapd.add_ap(apdev[0]['ifname'], params)
  1577. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1578. identity="probe", ca_cert="probe://",
  1579. wait_connect=False, scan_freq="2412")
  1580. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1581. if ev is None:
  1582. raise Exception("Association and EAP start timed out")
  1583. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PEER-CERT depth=0"], timeout=10)
  1584. if ev is None:
  1585. raise Exception("No peer server certificate event seen")
  1586. if "hash=" + srv_cert_hash not in ev:
  1587. raise Exception("Expected server certificate hash not reported")
  1588. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  1589. if ev is None:
  1590. raise Exception("EAP result timed out")
  1591. if "Server certificate chain probe" not in ev:
  1592. raise Exception("Server certificate probe not reported")
  1593. dev[0].wait_disconnected(timeout=10)
  1594. dev[0].request("REMOVE_NETWORK all")
  1595. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1596. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1597. password="password", phase2="auth=MSCHAPV2",
  1598. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  1599. wait_connect=False, scan_freq="2412")
  1600. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1601. if ev is None:
  1602. raise Exception("Association and EAP start timed out")
  1603. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
  1604. if ev is None:
  1605. raise Exception("EAP result timed out")
  1606. if "Server certificate mismatch" not in ev:
  1607. raise Exception("Server certificate mismatch not reported")
  1608. dev[0].wait_disconnected(timeout=10)
  1609. dev[0].request("REMOVE_NETWORK all")
  1610. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  1611. anonymous_identity="ttls", password="password",
  1612. ca_cert="hash://server/sha256/" + srv_cert_hash,
  1613. phase2="auth=MSCHAPV2")
  1614. def test_ap_wpa2_eap_ttls_server_cert_hash_invalid(dev, apdev):
  1615. """WPA2-Enterprise connection using EAP-TTLS and server certificate hash (invalid config)"""
  1616. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1617. hostapd.add_ap(apdev[0]['ifname'], params)
  1618. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1619. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1620. password="password", phase2="auth=MSCHAPV2",
  1621. ca_cert="hash://server/md5/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6a",
  1622. wait_connect=False, scan_freq="2412")
  1623. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1624. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1625. password="password", phase2="auth=MSCHAPV2",
  1626. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca",
  1627. wait_connect=False, scan_freq="2412")
  1628. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  1629. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1630. password="password", phase2="auth=MSCHAPV2",
  1631. ca_cert="hash://server/sha256/5a1bc1296205e6fdbe3979728efe3920798885c1c4590b5f90f43222d239ca6Q",
  1632. wait_connect=False, scan_freq="2412")
  1633. for i in range(0, 3):
  1634. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  1635. if ev is None:
  1636. raise Exception("Association and EAP start timed out")
  1637. ev = dev[i].wait_event(["EAP: Failed to initialize EAP method: vendor 0 method 21 (TTLS)"], timeout=5)
  1638. if ev is None:
  1639. raise Exception("Did not report EAP method initialization failure")
  1640. def test_ap_wpa2_eap_pwd(dev, apdev):
  1641. """WPA2-Enterprise connection using EAP-pwd"""
  1642. check_eap_capa(dev[0], "PWD")
  1643. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1644. hostapd.add_ap(apdev[0]['ifname'], params)
  1645. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1646. eap_reauth(dev[0], "PWD")
  1647. dev[0].request("REMOVE_NETWORK all")
  1648. eap_connect(dev[1], apdev[0], "PWD",
  1649. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  1650. password="secret password",
  1651. fragment_size="90")
  1652. logger.info("Negative test with incorrect password")
  1653. eap_connect(dev[2], apdev[0], "PWD", "pwd user", password="secret-password",
  1654. expect_failure=True, local_error_report=True)
  1655. eap_connect(dev[0], apdev[0], "PWD",
  1656. "pwd.user@test123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.example.com",
  1657. password="secret password",
  1658. fragment_size="31")
  1659. def test_ap_wpa2_eap_pwd_nthash(dev, apdev):
  1660. """WPA2-Enterprise connection using EAP-pwd and NTHash"""
  1661. check_eap_capa(dev[0], "PWD")
  1662. skip_with_fips(dev[0])
  1663. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1664. hostapd.add_ap(apdev[0]['ifname'], params)
  1665. eap_connect(dev[0], apdev[0], "PWD", "pwd-hash", password="secret password")
  1666. eap_connect(dev[1], apdev[0], "PWD", "pwd-hash",
  1667. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a")
  1668. eap_connect(dev[2], apdev[0], "PWD", "pwd user",
  1669. password_hex="hash:e3718ece8ab74792cbbfffd316d2d19a",
  1670. expect_failure=True, local_error_report=True)
  1671. def test_ap_wpa2_eap_pwd_groups(dev, apdev):
  1672. """WPA2-Enterprise connection using various EAP-pwd groups"""
  1673. check_eap_capa(dev[0], "PWD")
  1674. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1675. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1676. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  1677. for i in [ 19, 20, 21, 25, 26 ]:
  1678. params['pwd_group'] = str(i)
  1679. hostapd.add_ap(apdev[0]['ifname'], params)
  1680. dev[0].request("REMOVE_NETWORK all")
  1681. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1682. def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev):
  1683. """WPA2-Enterprise connection using invalid EAP-pwd group"""
  1684. check_eap_capa(dev[0], "PWD")
  1685. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1686. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1687. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  1688. params['pwd_group'] = "0"
  1689. hostapd.add_ap(apdev[0]['ifname'], params)
  1690. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
  1691. identity="pwd user", password="secret password",
  1692. scan_freq="2412", wait_connect=False)
  1693. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1694. if ev is None:
  1695. raise Exception("Timeout on EAP failure report")
  1696. def test_ap_wpa2_eap_pwd_as_frag(dev, apdev):
  1697. """WPA2-Enterprise connection using EAP-pwd with server fragmentation"""
  1698. check_eap_capa(dev[0], "PWD")
  1699. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1700. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1701. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1702. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1703. "pwd_group": "19", "fragment_size": "40" }
  1704. hostapd.add_ap(apdev[0]['ifname'], params)
  1705. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1706. def test_ap_wpa2_eap_gpsk(dev, apdev):
  1707. """WPA2-Enterprise connection using EAP-GPSK"""
  1708. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1709. hostapd.add_ap(apdev[0]['ifname'], params)
  1710. id = eap_connect(dev[0], apdev[0], "GPSK", "gpsk user",
  1711. password="abcdefghijklmnop0123456789abcdef")
  1712. eap_reauth(dev[0], "GPSK")
  1713. logger.info("Test forced algorithm selection")
  1714. for phase1 in [ "cipher=1", "cipher=2" ]:
  1715. dev[0].set_network_quoted(id, "phase1", phase1)
  1716. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1717. if ev is None:
  1718. raise Exception("EAP success timed out")
  1719. dev[0].wait_connected(timeout=10)
  1720. logger.info("Test failed algorithm negotiation")
  1721. dev[0].set_network_quoted(id, "phase1", "cipher=9")
  1722. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1723. if ev is None:
  1724. raise Exception("EAP failure timed out")
  1725. logger.info("Negative test with incorrect password")
  1726. dev[0].request("REMOVE_NETWORK all")
  1727. eap_connect(dev[0], apdev[0], "GPSK", "gpsk user",
  1728. password="ffcdefghijklmnop0123456789abcdef",
  1729. expect_failure=True)
  1730. def test_ap_wpa2_eap_sake(dev, apdev):
  1731. """WPA2-Enterprise connection using EAP-SAKE"""
  1732. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1733. hostapd.add_ap(apdev[0]['ifname'], params)
  1734. eap_connect(dev[0], apdev[0], "SAKE", "sake user",
  1735. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  1736. eap_reauth(dev[0], "SAKE")
  1737. logger.info("Negative test with incorrect password")
  1738. dev[0].request("REMOVE_NETWORK all")
  1739. eap_connect(dev[0], apdev[0], "SAKE", "sake user",
  1740. password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  1741. expect_failure=True)
  1742. def test_ap_wpa2_eap_eke(dev, apdev):
  1743. """WPA2-Enterprise connection using EAP-EKE"""
  1744. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1745. hostapd.add_ap(apdev[0]['ifname'], params)
  1746. id = eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello")
  1747. eap_reauth(dev[0], "EKE")
  1748. logger.info("Test forced algorithm selection")
  1749. for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2",
  1750. "dhgroup=4 encr=1 prf=2 mac=2",
  1751. "dhgroup=3 encr=1 prf=2 mac=2",
  1752. "dhgroup=3 encr=1 prf=1 mac=1" ]:
  1753. dev[0].set_network_quoted(id, "phase1", phase1)
  1754. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1755. if ev is None:
  1756. raise Exception("EAP success timed out")
  1757. dev[0].wait_connected(timeout=10)
  1758. logger.info("Test failed algorithm negotiation")
  1759. dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9")
  1760. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1761. if ev is None:
  1762. raise Exception("EAP failure timed out")
  1763. logger.info("Negative test with incorrect password")
  1764. dev[0].request("REMOVE_NETWORK all")
  1765. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello1",
  1766. expect_failure=True)
  1767. def test_ap_wpa2_eap_eke_serverid_nai(dev, apdev):
  1768. """WPA2-Enterprise connection using EAP-EKE with serverid NAI"""
  1769. params = int_eap_server_params()
  1770. params['server_id'] = 'example.server@w1.fi'
  1771. hostapd.add_ap(apdev[0]['ifname'], params)
  1772. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello")
  1773. def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
  1774. """WPA2-Enterprise connection using EAP-EKE with server OOM"""
  1775. params = int_eap_server_params()
  1776. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1777. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  1778. for count,func in [ (1, "eap_eke_build_commit"),
  1779. (2, "eap_eke_build_commit"),
  1780. (3, "eap_eke_build_commit"),
  1781. (1, "eap_eke_build_confirm"),
  1782. (2, "eap_eke_build_confirm"),
  1783. (1, "eap_eke_process_commit"),
  1784. (2, "eap_eke_process_commit"),
  1785. (1, "eap_eke_process_confirm"),
  1786. (1, "eap_eke_process_identity"),
  1787. (2, "eap_eke_process_identity"),
  1788. (3, "eap_eke_process_identity"),
  1789. (4, "eap_eke_process_identity") ]:
  1790. with alloc_fail(hapd, count, func):
  1791. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello",
  1792. expect_failure=True)
  1793. dev[0].request("REMOVE_NETWORK all")
  1794. for count,func,pw in [ (1, "eap_eke_init", "hello"),
  1795. (1, "eap_eke_get_session_id", "hello"),
  1796. (1, "eap_eke_getKey", "hello"),
  1797. (1, "eap_eke_build_msg", "hello"),
  1798. (1, "eap_eke_build_failure", "wrong"),
  1799. (1, "eap_eke_build_identity", "hello"),
  1800. (2, "eap_eke_build_identity", "hello") ]:
  1801. with alloc_fail(hapd, count, func):
  1802. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1803. eap="EKE", identity="eke user", password=pw,
  1804. wait_connect=False, scan_freq="2412")
  1805. # This would eventually time out, but we can stop after having
  1806. # reached the allocation failure.
  1807. for i in range(20):
  1808. time.sleep(0.1)
  1809. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1810. break
  1811. dev[0].request("REMOVE_NETWORK all")
  1812. for count in range(1, 1000):
  1813. try:
  1814. with alloc_fail(hapd, count, "eap_server_sm_step"):
  1815. dev[0].connect("test-wpa2-eap",
  1816. key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1817. eap="EKE", identity="eke user", password=pw,
  1818. wait_connect=False, scan_freq="2412")
  1819. # This would eventually time out, but we can stop after having
  1820. # reached the allocation failure.
  1821. for i in range(10):
  1822. time.sleep(0.1)
  1823. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1824. break
  1825. dev[0].request("REMOVE_NETWORK all")
  1826. except Exception, e:
  1827. if str(e) == "Allocation failure did not trigger":
  1828. if count < 30:
  1829. raise Exception("Too few allocation failures")
  1830. logger.info("%d allocation failures tested" % (count - 1))
  1831. break
  1832. raise e
  1833. def test_ap_wpa2_eap_ikev2(dev, apdev):
  1834. """WPA2-Enterprise connection using EAP-IKEv2"""
  1835. check_eap_capa(dev[0], "IKEV2")
  1836. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1837. hostapd.add_ap(apdev[0]['ifname'], params)
  1838. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1839. password="ike password")
  1840. eap_reauth(dev[0], "IKEV2")
  1841. dev[0].request("REMOVE_NETWORK all")
  1842. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1843. password="ike password", fragment_size="50")
  1844. logger.info("Negative test with incorrect password")
  1845. dev[0].request("REMOVE_NETWORK all")
  1846. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1847. password="ike-password", expect_failure=True)
  1848. def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev):
  1849. """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation"""
  1850. check_eap_capa(dev[0], "IKEV2")
  1851. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1852. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1853. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1854. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1855. "fragment_size": "50" }
  1856. hostapd.add_ap(apdev[0]['ifname'], params)
  1857. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1858. password="ike password")
  1859. eap_reauth(dev[0], "IKEV2")
  1860. def test_ap_wpa2_eap_ikev2_oom(dev, apdev):
  1861. """WPA2-Enterprise connection using EAP-IKEv2 and OOM"""
  1862. check_eap_capa(dev[0], "IKEV2")
  1863. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1864. hostapd.add_ap(apdev[0]['ifname'], params)
  1865. tests = [ (1, "dh_init"),
  1866. (2, "dh_init"),
  1867. (1, "dh_derive_shared") ]
  1868. for count, func in tests:
  1869. with alloc_fail(dev[0], count, func):
  1870. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  1871. identity="ikev2 user", password="ike password",
  1872. wait_connect=False, scan_freq="2412")
  1873. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  1874. if ev is None:
  1875. raise Exception("EAP method not selected")
  1876. for i in range(10):
  1877. if "0:" in dev[0].request("GET_ALLOC_FAIL"):
  1878. break
  1879. time.sleep(0.02)
  1880. dev[0].request("REMOVE_NETWORK all")
  1881. tests = [ (1, "os_get_random;dh_init") ]
  1882. for count, func in tests:
  1883. with fail_test(dev[0], count, func):
  1884. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  1885. identity="ikev2 user", password="ike password",
  1886. wait_connect=False, scan_freq="2412")
  1887. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  1888. if ev is None:
  1889. raise Exception("EAP method not selected")
  1890. for i in range(10):
  1891. if "0:" in dev[0].request("GET_FAIL"):
  1892. break
  1893. time.sleep(0.02)
  1894. dev[0].request("REMOVE_NETWORK all")
  1895. def test_ap_wpa2_eap_pax(dev, apdev):
  1896. """WPA2-Enterprise connection using EAP-PAX"""
  1897. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1898. hostapd.add_ap(apdev[0]['ifname'], params)
  1899. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1900. password_hex="0123456789abcdef0123456789abcdef")
  1901. eap_reauth(dev[0], "PAX")
  1902. logger.info("Negative test with incorrect password")
  1903. dev[0].request("REMOVE_NETWORK all")
  1904. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1905. password_hex="ff23456789abcdef0123456789abcdef",
  1906. expect_failure=True)
  1907. def test_ap_wpa2_eap_psk(dev, apdev):
  1908. """WPA2-Enterprise connection using EAP-PSK"""
  1909. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1910. params["wpa_key_mgmt"] = "WPA-EAP-SHA256"
  1911. params["ieee80211w"] = "2"
  1912. hostapd.add_ap(apdev[0]['ifname'], params)
  1913. eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com",
  1914. password_hex="0123456789abcdef0123456789abcdef", sha256=True)
  1915. eap_reauth(dev[0], "PSK", sha256=True)
  1916. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
  1917. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ])
  1918. bss = dev[0].get_bss(apdev[0]['bssid'])
  1919. if 'flags' not in bss:
  1920. raise Exception("Could not get BSS flags from BSS table")
  1921. if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']:
  1922. raise Exception("Unexpected BSS flags: " + bss['flags'])
  1923. logger.info("Negative test with incorrect password")
  1924. dev[0].request("REMOVE_NETWORK all")
  1925. eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com",
  1926. password_hex="ff23456789abcdef0123456789abcdef", sha256=True,
  1927. expect_failure=True)
  1928. def test_ap_wpa2_eap_psk_oom(dev, apdev):
  1929. """WPA2-Enterprise connection using EAP-PSK and OOM"""
  1930. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1931. hostapd.add_ap(apdev[0]['ifname'], params)
  1932. tests = [ (1, "aes_128_ctr_encrypt;aes_128_eax_encrypt"),
  1933. (1, "omac1_aes_128;aes_128_eax_encrypt"),
  1934. (2, "omac1_aes_128;aes_128_eax_encrypt"),
  1935. (3, "omac1_aes_128;aes_128_eax_encrypt"),
  1936. (1, "=aes_128_eax_encrypt"),
  1937. (1, "omac1_aes_vector"),
  1938. (1, "aes_128_ctr_encrypt;aes_128_eax_decrypt"),
  1939. (1, "omac1_aes_128;aes_128_eax_decrypt"),
  1940. (2, "omac1_aes_128;aes_128_eax_decrypt"),
  1941. (3, "omac1_aes_128;aes_128_eax_decrypt"),
  1942. (1, "=aes_128_eax_decrypt") ]
  1943. for count, func in tests:
  1944. with alloc_fail(dev[0], count, func):
  1945. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  1946. identity="psk.user@example.com",
  1947. password_hex="0123456789abcdef0123456789abcdef",
  1948. wait_connect=False, scan_freq="2412")
  1949. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  1950. if ev is None:
  1951. raise Exception("EAP method not selected")
  1952. for i in range(10):
  1953. if "0:" in dev[0].request("GET_ALLOC_FAIL"):
  1954. break
  1955. time.sleep(0.02)
  1956. dev[0].request("REMOVE_NETWORK all")
  1957. with alloc_fail(dev[0], 1, "aes_128_encrypt_block"):
  1958. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  1959. identity="psk.user@example.com",
  1960. password_hex="0123456789abcdef0123456789abcdef",
  1961. wait_connect=False, scan_freq="2412")
  1962. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1963. if ev is None:
  1964. raise Exception("EAP method failure not reported")
  1965. dev[0].request("REMOVE_NETWORK all")
  1966. def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev):
  1967. """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  1968. check_eap_capa(dev[0], "MSCHAPV2")
  1969. params = hostapd.wpa_eap_params(ssid="test-wpa-eap")
  1970. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1971. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP",
  1972. identity="user", password="password", phase2="auth=MSCHAPV2",
  1973. ca_cert="auth_serv/ca.pem", wait_connect=False,
  1974. scan_freq="2412")
  1975. eap_check_auth(dev[0], "PEAP", True, rsn=False)
  1976. hwsim_utils.test_connectivity(dev[0], hapd)
  1977. eap_reauth(dev[0], "PEAP", rsn=False)
  1978. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
  1979. ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ])
  1980. status = dev[0].get_status(extra="VERBOSE")
  1981. if 'portControl' not in status:
  1982. raise Exception("portControl missing from STATUS-VERBOSE")
  1983. if status['portControl'] != 'Auto':
  1984. raise Exception("Unexpected portControl value: " + status['portControl'])
  1985. if 'eap_session_id' not in status:
  1986. raise Exception("eap_session_id missing from STATUS-VERBOSE")
  1987. if not status['eap_session_id'].startswith("19"):
  1988. raise Exception("Unexpected eap_session_id value: " + status['eap_session_id'])
  1989. def test_ap_wpa2_eap_interactive(dev, apdev):
  1990. """WPA2-Enterprise connection using interactive identity/password entry"""
  1991. check_eap_capa(dev[0], "MSCHAPV2")
  1992. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1993. hostapd.add_ap(apdev[0]['ifname'], params)
  1994. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1995. tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
  1996. "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
  1997. None, "password"),
  1998. ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
  1999. "TTLS", "ttls", None, "auth=MSCHAPV2",
  2000. "DOMAIN\mschapv2 user", "password"),
  2001. ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
  2002. "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
  2003. ("Connection with dynamic TTLS/EAP-MD5 password entry",
  2004. "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
  2005. ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
  2006. "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
  2007. ("Connection with dynamic PEAP/EAP-GTC password entry",
  2008. "PEAP", None, "user", "auth=GTC", None, "password") ]
  2009. for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
  2010. logger.info(desc)
  2011. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
  2012. anonymous_identity=anon, identity=identity,
  2013. ca_cert="auth_serv/ca.pem", phase2=phase2,
  2014. wait_connect=False, scan_freq="2412")
  2015. if req_id:
  2016. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2017. if ev is None:
  2018. raise Exception("Request for identity timed out")
  2019. id = ev.split(':')[0].split('-')[-1]
  2020. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2021. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
  2022. if ev is None:
  2023. raise Exception("Request for password timed out")
  2024. id = ev.split(':')[0].split('-')[-1]
  2025. type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD"
  2026. dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw)
  2027. dev[0].wait_connected(timeout=10)
  2028. dev[0].request("REMOVE_NETWORK all")
  2029. def test_ap_wpa2_eap_vendor_test(dev, apdev):
  2030. """WPA2-Enterprise connection using EAP vendor test"""
  2031. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2032. hostapd.add_ap(apdev[0]['ifname'], params)
  2033. eap_connect(dev[0], apdev[0], "VENDOR-TEST", "vendor-test")
  2034. eap_reauth(dev[0], "VENDOR-TEST")
  2035. eap_connect(dev[1], apdev[0], "VENDOR-TEST", "vendor-test",
  2036. password="pending")
  2037. def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev):
  2038. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning"""
  2039. check_eap_capa(dev[0], "FAST")
  2040. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2041. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2042. eap_connect(dev[0], apdev[0], "FAST", "user",
  2043. anonymous_identity="FAST", password="password",
  2044. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2045. phase1="fast_provisioning=1", pac_file="blob://fast_pac")
  2046. hwsim_utils.test_connectivity(dev[0], hapd)
  2047. res = eap_reauth(dev[0], "FAST")
  2048. if res['tls_session_reused'] != '1':
  2049. raise Exception("EAP-FAST could not use PAC session ticket")
  2050. def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params):
  2051. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file"""
  2052. check_eap_capa(dev[0], "FAST")
  2053. pac_file = os.path.join(params['logdir'], "fast.pac")
  2054. pac_file2 = os.path.join(params['logdir'], "fast-bin.pac")
  2055. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2056. hostapd.add_ap(apdev[0]['ifname'], params)
  2057. try:
  2058. eap_connect(dev[0], apdev[0], "FAST", "user",
  2059. anonymous_identity="FAST", password="password",
  2060. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2061. phase1="fast_provisioning=1", pac_file=pac_file)
  2062. with open(pac_file, "r") as f:
  2063. data = f.read()
  2064. if "wpa_supplicant EAP-FAST PAC file - version 1" not in data:
  2065. raise Exception("PAC file header missing")
  2066. if "PAC-Key=" not in data:
  2067. raise Exception("PAC-Key missing from PAC file")
  2068. dev[0].request("REMOVE_NETWORK all")
  2069. eap_connect(dev[0], apdev[0], "FAST", "user",
  2070. anonymous_identity="FAST", password="password",
  2071. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2072. pac_file=pac_file)
  2073. eap_connect(dev[1], apdev[0], "FAST", "user",
  2074. anonymous_identity="FAST", password="password",
  2075. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2076. phase1="fast_provisioning=1 fast_pac_format=binary",
  2077. pac_file=pac_file2)
  2078. dev[1].request("REMOVE_NETWORK all")
  2079. eap_connect(dev[1], apdev[0], "FAST", "user",
  2080. anonymous_identity="FAST", password="password",
  2081. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2082. phase1="fast_pac_format=binary",
  2083. pac_file=pac_file2)
  2084. finally:
  2085. try:
  2086. os.remove(pac_file)
  2087. except:
  2088. pass
  2089. try:
  2090. os.remove(pac_file2)
  2091. except:
  2092. pass
  2093. def test_ap_wpa2_eap_fast_binary_pac(dev, apdev):
  2094. """WPA2-Enterprise connection using EAP-FAST and binary PAC format"""
  2095. check_eap_capa(dev[0], "FAST")
  2096. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2097. hostapd.add_ap(apdev[0]['ifname'], params)
  2098. eap_connect(dev[0], apdev[0], "FAST", "user",
  2099. anonymous_identity="FAST", password="password",
  2100. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2101. phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary",
  2102. pac_file="blob://fast_pac_bin")
  2103. res = eap_reauth(dev[0], "FAST")
  2104. if res['tls_session_reused'] != '1':
  2105. raise Exception("EAP-FAST could not use PAC session ticket")
  2106. def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev):
  2107. """WPA2-Enterprise connection using EAP-FAST and missing PAC config"""
  2108. check_eap_capa(dev[0], "FAST")
  2109. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2110. hostapd.add_ap(apdev[0]['ifname'], params)
  2111. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2112. identity="user", anonymous_identity="FAST",
  2113. password="password",
  2114. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2115. pac_file="blob://fast_pac_not_in_use",
  2116. wait_connect=False, scan_freq="2412")
  2117. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2118. if ev is None:
  2119. raise Exception("Timeout on EAP failure report")
  2120. dev[0].request("REMOVE_NETWORK all")
  2121. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2122. identity="user", anonymous_identity="FAST",
  2123. password="password",
  2124. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2125. wait_connect=False, scan_freq="2412")
  2126. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2127. if ev is None:
  2128. raise Exception("Timeout on EAP failure report")
  2129. def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev):
  2130. """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning"""
  2131. check_eap_capa(dev[0], "FAST")
  2132. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2133. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2134. eap_connect(dev[0], apdev[0], "FAST", "user",
  2135. anonymous_identity="FAST", password="password",
  2136. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  2137. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth")
  2138. hwsim_utils.test_connectivity(dev[0], hapd)
  2139. res = eap_reauth(dev[0], "FAST")
  2140. if res['tls_session_reused'] != '1':
  2141. raise Exception("EAP-FAST could not use PAC session ticket")
  2142. def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev):
  2143. """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing"""
  2144. check_eap_capa(dev[0], "FAST")
  2145. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2146. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2147. id = eap_connect(dev[0], apdev[0], "FAST", "user",
  2148. anonymous_identity="FAST", password="password",
  2149. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  2150. phase1="fast_provisioning=2",
  2151. pac_file="blob://fast_pac_auth")
  2152. dev[0].set_network_quoted(id, "identity", "user2")
  2153. dev[0].wait_disconnected()
  2154. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  2155. if ev is None:
  2156. raise Exception("EAP-FAST not started")
  2157. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  2158. if ev is None:
  2159. raise Exception("EAP failure not reported")
  2160. dev[0].wait_disconnected()
  2161. def test_ap_wpa2_eap_fast_prf_oom(dev, apdev):
  2162. """WPA2-Enterprise connection using EAP-FAST and OOM in PRF"""
  2163. check_eap_capa(dev[0], "FAST")
  2164. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2165. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2166. with alloc_fail(dev[0], 2, "openssl_tls_prf"):
  2167. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2168. identity="user", anonymous_identity="FAST",
  2169. password="password", ca_cert="auth_serv/ca.pem",
  2170. phase2="auth=GTC",
  2171. phase1="fast_provisioning=2",
  2172. pac_file="blob://fast_pac_auth",
  2173. wait_connect=False, scan_freq="2412")
  2174. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  2175. if ev is None:
  2176. raise Exception("EAP failure not reported")
  2177. dev[0].request("DISCONNECT")
  2178. def test_ap_wpa2_eap_fast_server_oom(dev, apdev):
  2179. """EAP-FAST/MSCHAPv2 and server OOM"""
  2180. check_eap_capa(dev[0], "FAST")
  2181. params = int_eap_server_params()
  2182. params['dh_file'] = 'auth_serv/dh.conf'
  2183. params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f'
  2184. params['eap_fast_a_id'] = '1011'
  2185. params['eap_fast_a_id_info'] = 'another test server'
  2186. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2187. with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"):
  2188. id = eap_connect(dev[0], apdev[0], "FAST", "user",
  2189. anonymous_identity="FAST", password="password",
  2190. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2191. phase1="fast_provisioning=1",
  2192. pac_file="blob://fast_pac",
  2193. expect_failure=True)
  2194. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2195. if ev is None:
  2196. raise Exception("No EAP failure reported")
  2197. dev[0].wait_disconnected()
  2198. dev[0].request("DISCONNECT")
  2199. dev[0].select_network(id, freq="2412")
  2200. def test_ap_wpa2_eap_tls_ocsp(dev, apdev):
  2201. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP"""
  2202. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2203. hostapd.add_ap(apdev[0]['ifname'], params)
  2204. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  2205. private_key="auth_serv/user.pkcs12",
  2206. private_key_passwd="whatever", ocsp=2)
  2207. def int_eap_server_params():
  2208. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2209. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2210. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  2211. "ca_cert": "auth_serv/ca.pem",
  2212. "server_cert": "auth_serv/server.pem",
  2213. "private_key": "auth_serv/server.key" }
  2214. return params
  2215. def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
  2216. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data"""
  2217. params = int_eap_server_params()
  2218. params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der"
  2219. hostapd.add_ap(apdev[0]['ifname'], params)
  2220. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2221. identity="tls user", ca_cert="auth_serv/ca.pem",
  2222. private_key="auth_serv/user.pkcs12",
  2223. private_key_passwd="whatever", ocsp=2,
  2224. wait_connect=False, scan_freq="2412")
  2225. count = 0
  2226. while True:
  2227. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2228. if ev is None:
  2229. raise Exception("Timeout on EAP status")
  2230. if 'bad certificate status response' in ev:
  2231. break
  2232. count = count + 1
  2233. if count > 10:
  2234. raise Exception("Unexpected number of EAP status messages")
  2235. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2236. if ev is None:
  2237. raise Exception("Timeout on EAP failure report")
  2238. def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
  2239. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
  2240. params = int_eap_server_params()
  2241. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
  2242. hostapd.add_ap(apdev[0]['ifname'], params)
  2243. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2244. identity="tls user", ca_cert="auth_serv/ca.pem",
  2245. private_key="auth_serv/user.pkcs12",
  2246. private_key_passwd="whatever", ocsp=2,
  2247. wait_connect=False, scan_freq="2412")
  2248. count = 0
  2249. while True:
  2250. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2251. if ev is None:
  2252. raise Exception("Timeout on EAP status")
  2253. if 'bad certificate status response' in ev:
  2254. break
  2255. count = count + 1
  2256. if count > 10:
  2257. raise Exception("Unexpected number of EAP status messages")
  2258. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2259. if ev is None:
  2260. raise Exception("Timeout on EAP failure report")
  2261. def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev):
  2262. """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer"""
  2263. params = int_eap_server_params()
  2264. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign"
  2265. hostapd.add_ap(apdev[0]['ifname'], params)
  2266. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2267. identity="tls user", ca_cert="auth_serv/ca.pem",
  2268. private_key="auth_serv/user.pkcs12",
  2269. private_key_passwd="whatever", ocsp=2,
  2270. wait_connect=False, scan_freq="2412")
  2271. count = 0
  2272. while True:
  2273. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2274. if ev is None:
  2275. raise Exception("Timeout on EAP status")
  2276. if 'bad certificate status response' in ev:
  2277. break
  2278. count = count + 1
  2279. if count > 10:
  2280. raise Exception("Unexpected number of EAP status messages")
  2281. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2282. if ev is None:
  2283. raise Exception("Timeout on EAP failure report")
  2284. def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params):
  2285. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  2286. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der")
  2287. if not os.path.exists(ocsp):
  2288. raise HwsimSkip("No OCSP response available")
  2289. params = int_eap_server_params()
  2290. params["ocsp_stapling_response"] = ocsp
  2291. hostapd.add_ap(apdev[0]['ifname'], params)
  2292. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2293. identity="pap user", ca_cert="auth_serv/ca.pem",
  2294. anonymous_identity="ttls", password="password",
  2295. phase2="auth=PAP", ocsp=2,
  2296. wait_connect=False, scan_freq="2412")
  2297. count = 0
  2298. while True:
  2299. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2300. if ev is None:
  2301. raise Exception("Timeout on EAP status")
  2302. if 'bad certificate status response' in ev:
  2303. break
  2304. if 'certificate revoked' in ev:
  2305. break
  2306. count = count + 1
  2307. if count > 10:
  2308. raise Exception("Unexpected number of EAP status messages")
  2309. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2310. if ev is None:
  2311. raise Exception("Timeout on EAP failure report")
  2312. def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params):
  2313. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  2314. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  2315. if not os.path.exists(ocsp):
  2316. raise HwsimSkip("No OCSP response available")
  2317. params = int_eap_server_params()
  2318. params["ocsp_stapling_response"] = ocsp
  2319. hostapd.add_ap(apdev[0]['ifname'], params)
  2320. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2321. identity="pap user", ca_cert="auth_serv/ca.pem",
  2322. anonymous_identity="ttls", password="password",
  2323. phase2="auth=PAP", ocsp=2,
  2324. wait_connect=False, scan_freq="2412")
  2325. count = 0
  2326. while True:
  2327. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2328. if ev is None:
  2329. raise Exception("Timeout on EAP status")
  2330. if 'bad certificate status response' in ev:
  2331. break
  2332. count = count + 1
  2333. if count > 10:
  2334. raise Exception("Unexpected number of EAP status messages")
  2335. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2336. if ev is None:
  2337. raise Exception("Timeout on EAP failure report")
  2338. def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params):
  2339. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  2340. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  2341. if not os.path.exists(ocsp):
  2342. raise HwsimSkip("No OCSP response available")
  2343. params = int_eap_server_params()
  2344. params["ocsp_stapling_response"] = ocsp
  2345. hostapd.add_ap(apdev[0]['ifname'], params)
  2346. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2347. identity="pap user", ca_cert="auth_serv/ca.pem",
  2348. anonymous_identity="ttls", password="password",
  2349. phase2="auth=PAP", ocsp=1, scan_freq="2412")
  2350. def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
  2351. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  2352. params = int_eap_server_params()
  2353. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2354. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2355. hostapd.add_ap(apdev[0]['ifname'], params)
  2356. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2357. identity="tls user", ca_cert="auth_serv/ca.pem",
  2358. private_key="auth_serv/user.pkcs12",
  2359. private_key_passwd="whatever",
  2360. domain_suffix_match="server3.w1.fi",
  2361. scan_freq="2412")
  2362. def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
  2363. """WPA2-Enterprise using EAP-TLS and domainmatch (CN)"""
  2364. params = int_eap_server_params()
  2365. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2366. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2367. hostapd.add_ap(apdev[0]['ifname'], params)
  2368. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2369. identity="tls user", ca_cert="auth_serv/ca.pem",
  2370. private_key="auth_serv/user.pkcs12",
  2371. private_key_passwd="whatever",
  2372. domain_match="server3.w1.fi",
  2373. scan_freq="2412")
  2374. def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
  2375. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  2376. check_domain_match_full(dev[0])
  2377. params = int_eap_server_params()
  2378. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2379. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2380. hostapd.add_ap(apdev[0]['ifname'], params)
  2381. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2382. identity="tls user", ca_cert="auth_serv/ca.pem",
  2383. private_key="auth_serv/user.pkcs12",
  2384. private_key_passwd="whatever",
  2385. domain_suffix_match="w1.fi",
  2386. scan_freq="2412")
  2387. def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
  2388. """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
  2389. params = int_eap_server_params()
  2390. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2391. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2392. hostapd.add_ap(apdev[0]['ifname'], params)
  2393. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2394. identity="tls user", ca_cert="auth_serv/ca.pem",
  2395. private_key="auth_serv/user.pkcs12",
  2396. private_key_passwd="whatever",
  2397. domain_suffix_match="example.com",
  2398. wait_connect=False,
  2399. scan_freq="2412")
  2400. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2401. identity="tls user", ca_cert="auth_serv/ca.pem",
  2402. private_key="auth_serv/user.pkcs12",
  2403. private_key_passwd="whatever",
  2404. domain_suffix_match="erver3.w1.fi",
  2405. wait_connect=False,
  2406. scan_freq="2412")
  2407. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2408. if ev is None:
  2409. raise Exception("Timeout on EAP failure report")
  2410. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2411. if ev is None:
  2412. raise Exception("Timeout on EAP failure report (2)")
  2413. def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev):
  2414. """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)"""
  2415. params = int_eap_server_params()
  2416. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2417. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2418. hostapd.add_ap(apdev[0]['ifname'], params)
  2419. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2420. identity="tls user", ca_cert="auth_serv/ca.pem",
  2421. private_key="auth_serv/user.pkcs12",
  2422. private_key_passwd="whatever",
  2423. domain_match="example.com",
  2424. wait_connect=False,
  2425. scan_freq="2412")
  2426. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2427. identity="tls user", ca_cert="auth_serv/ca.pem",
  2428. private_key="auth_serv/user.pkcs12",
  2429. private_key_passwd="whatever",
  2430. domain_match="w1.fi",
  2431. wait_connect=False,
  2432. scan_freq="2412")
  2433. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2434. if ev is None:
  2435. raise Exception("Timeout on EAP failure report")
  2436. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2437. if ev is None:
  2438. raise Exception("Timeout on EAP failure report (2)")
  2439. def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev):
  2440. """WPA2-Enterprise using EAP-TTLS and expired certificate"""
  2441. skip_with_fips(dev[0])
  2442. params = int_eap_server_params()
  2443. params["server_cert"] = "auth_serv/server-expired.pem"
  2444. params["private_key"] = "auth_serv/server-expired.key"
  2445. hostapd.add_ap(apdev[0]['ifname'], params)
  2446. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2447. identity="mschap user", password="password",
  2448. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2449. wait_connect=False,
  2450. scan_freq="2412")
  2451. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  2452. if ev is None:
  2453. raise Exception("Timeout on EAP certificate error report")
  2454. if "reason=4" not in ev or "certificate has expired" not in ev:
  2455. raise Exception("Unexpected failure reason: " + ev)
  2456. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2457. if ev is None:
  2458. raise Exception("Timeout on EAP failure report")
  2459. def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev):
  2460. """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration"""
  2461. skip_with_fips(dev[0])
  2462. params = int_eap_server_params()
  2463. params["server_cert"] = "auth_serv/server-expired.pem"
  2464. params["private_key"] = "auth_serv/server-expired.key"
  2465. hostapd.add_ap(apdev[0]['ifname'], params)
  2466. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2467. identity="mschap user", password="password",
  2468. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2469. phase1="tls_disable_time_checks=1",
  2470. scan_freq="2412")
  2471. def test_ap_wpa2_eap_ttls_long_duration(dev, apdev):
  2472. """WPA2-Enterprise using EAP-TTLS and long certificate duration"""
  2473. skip_with_fips(dev[0])
  2474. params = int_eap_server_params()
  2475. params["server_cert"] = "auth_serv/server-long-duration.pem"
  2476. params["private_key"] = "auth_serv/server-long-duration.key"
  2477. hostapd.add_ap(apdev[0]['ifname'], params)
  2478. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2479. identity="mschap user", password="password",
  2480. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2481. scan_freq="2412")
  2482. def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev):
  2483. """WPA2-Enterprise using EAP-TTLS and server cert with client EKU"""
  2484. skip_with_fips(dev[0])
  2485. params = int_eap_server_params()
  2486. params["server_cert"] = "auth_serv/server-eku-client.pem"
  2487. params["private_key"] = "auth_serv/server-eku-client.key"
  2488. hostapd.add_ap(apdev[0]['ifname'], params)
  2489. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2490. identity="mschap user", password="password",
  2491. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2492. wait_connect=False,
  2493. scan_freq="2412")
  2494. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2495. if ev is None:
  2496. raise Exception("Timeout on EAP failure report")
  2497. def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev):
  2498. """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU"""
  2499. skip_with_fips(dev[0])
  2500. params = int_eap_server_params()
  2501. params["server_cert"] = "auth_serv/server-eku-client-server.pem"
  2502. params["private_key"] = "auth_serv/server-eku-client-server.key"
  2503. hostapd.add_ap(apdev[0]['ifname'], params)
  2504. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2505. identity="mschap user", password="password",
  2506. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2507. scan_freq="2412")
  2508. def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev):
  2509. """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file"""
  2510. skip_with_fips(dev[0])
  2511. params = int_eap_server_params()
  2512. del params["server_cert"]
  2513. params["private_key"] = "auth_serv/server.pkcs12"
  2514. hostapd.add_ap(apdev[0]['ifname'], params)
  2515. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2516. identity="mschap user", password="password",
  2517. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2518. scan_freq="2412")
  2519. def test_ap_wpa2_eap_ttls_dh_params(dev, apdev):
  2520. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params"""
  2521. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2522. hostapd.add_ap(apdev[0]['ifname'], params)
  2523. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2524. anonymous_identity="ttls", password="password",
  2525. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  2526. dh_file="auth_serv/dh.conf")
  2527. def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev):
  2528. """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)"""
  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/dsaparam.pem")
  2535. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  2536. """EAP-TTLS and DH params file not found"""
  2537. skip_with_fips(dev[0])
  2538. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2539. hostapd.add_ap(apdev[0]['ifname'], params)
  2540. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2541. identity="mschap user", password="password",
  2542. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2543. dh_file="auth_serv/dh-no-such-file.conf",
  2544. scan_freq="2412", wait_connect=False)
  2545. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2546. if ev is None:
  2547. raise Exception("EAP failure timed out")
  2548. dev[0].request("REMOVE_NETWORK all")
  2549. dev[0].wait_disconnected()
  2550. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  2551. """EAP-TTLS and invalid DH params file"""
  2552. skip_with_fips(dev[0])
  2553. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2554. hostapd.add_ap(apdev[0]['ifname'], params)
  2555. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2556. identity="mschap user", password="password",
  2557. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2558. dh_file="auth_serv/ca.pem",
  2559. scan_freq="2412", wait_connect=False)
  2560. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2561. if ev is None:
  2562. raise Exception("EAP failure timed out")
  2563. dev[0].request("REMOVE_NETWORK all")
  2564. dev[0].wait_disconnected()
  2565. def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
  2566. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob"""
  2567. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2568. hostapd.add_ap(apdev[0]['ifname'], params)
  2569. dh = read_pem("auth_serv/dh2.conf")
  2570. if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
  2571. raise Exception("Could not set dhparams blob")
  2572. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2573. anonymous_identity="ttls", password="password",
  2574. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  2575. dh_file="blob://dhparams")
  2576. def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev):
  2577. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams"""
  2578. params = int_eap_server_params()
  2579. params["dh_file"] = "auth_serv/dh2.conf"
  2580. hostapd.add_ap(apdev[0]['ifname'], params)
  2581. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2582. anonymous_identity="ttls", password="password",
  2583. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  2584. def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev):
  2585. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)"""
  2586. params = int_eap_server_params()
  2587. params["dh_file"] = "auth_serv/dsaparam.pem"
  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_not_found(dev, apdev):
  2593. """EAP-TLS server and dhparams file not found"""
  2594. params = int_eap_server_params()
  2595. params["dh_file"] = "auth_serv/dh-no-such-file.conf"
  2596. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2597. if "FAIL" not in hapd.request("ENABLE"):
  2598. raise Exception("Invalid configuration accepted")
  2599. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  2600. """EAP-TLS server and invalid dhparams file"""
  2601. params = int_eap_server_params()
  2602. params["dh_file"] = "auth_serv/ca.pem"
  2603. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2604. if "FAIL" not in hapd.request("ENABLE"):
  2605. raise Exception("Invalid configuration accepted")
  2606. def test_ap_wpa2_eap_reauth(dev, apdev):
  2607. """WPA2-Enterprise and Authenticator forcing reauthentication"""
  2608. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2609. params['eap_reauth_period'] = '2'
  2610. hostapd.add_ap(apdev[0]['ifname'], params)
  2611. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  2612. password_hex="0123456789abcdef0123456789abcdef")
  2613. logger.info("Wait for reauthentication")
  2614. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2615. if ev is None:
  2616. raise Exception("Timeout on reauthentication")
  2617. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  2618. if ev is None:
  2619. raise Exception("Timeout on reauthentication")
  2620. for i in range(0, 20):
  2621. state = dev[0].get_status_field("wpa_state")
  2622. if state == "COMPLETED":
  2623. break
  2624. time.sleep(0.1)
  2625. if state != "COMPLETED":
  2626. raise Exception("Reauthentication did not complete")
  2627. def test_ap_wpa2_eap_request_identity_message(dev, apdev):
  2628. """Optional displayable message in EAP Request-Identity"""
  2629. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2630. params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com'
  2631. hostapd.add_ap(apdev[0]['ifname'], params)
  2632. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  2633. password_hex="0123456789abcdef0123456789abcdef")
  2634. def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev):
  2635. """WPA2-Enterprise using EAP-SIM/AKA and protected result indication"""
  2636. check_hlr_auc_gw_support()
  2637. params = int_eap_server_params()
  2638. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  2639. params['eap_sim_aka_result_ind'] = "1"
  2640. hostapd.add_ap(apdev[0]['ifname'], params)
  2641. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  2642. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  2643. phase1="result_ind=1")
  2644. eap_reauth(dev[0], "SIM")
  2645. eap_connect(dev[1], apdev[0], "SIM", "1232010000000000",
  2646. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  2647. dev[0].request("REMOVE_NETWORK all")
  2648. dev[1].request("REMOVE_NETWORK all")
  2649. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  2650. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  2651. phase1="result_ind=1")
  2652. eap_reauth(dev[0], "AKA")
  2653. eap_connect(dev[1], apdev[0], "AKA", "0232010000000000",
  2654. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  2655. dev[0].request("REMOVE_NETWORK all")
  2656. dev[1].request("REMOVE_NETWORK all")
  2657. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  2658. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  2659. phase1="result_ind=1")
  2660. eap_reauth(dev[0], "AKA'")
  2661. eap_connect(dev[1], apdev[0], "AKA'", "6555444333222111",
  2662. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  2663. def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev):
  2664. """WPA2-Enterprise connection resulting in too many EAP roundtrips"""
  2665. skip_with_fips(dev[0])
  2666. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2667. hostapd.add_ap(apdev[0]['ifname'], params)
  2668. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2669. eap="TTLS", identity="mschap user",
  2670. wait_connect=False, scan_freq="2412", ieee80211w="1",
  2671. anonymous_identity="ttls", password="password",
  2672. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2673. fragment_size="10")
  2674. ev = dev[0].wait_event(["EAP: more than"], timeout=20)
  2675. if ev is None:
  2676. raise Exception("EAP roundtrip limit not reached")
  2677. def test_ap_wpa2_eap_expanded_nak(dev, apdev):
  2678. """WPA2-Enterprise connection with EAP resulting in expanded NAK"""
  2679. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2680. hostapd.add_ap(apdev[0]['ifname'], params)
  2681. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2682. eap="PSK", identity="vendor-test",
  2683. password_hex="ff23456789abcdef0123456789abcdef",
  2684. wait_connect=False)
  2685. found = False
  2686. for i in range(0, 5):
  2687. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=10)
  2688. if ev is None:
  2689. raise Exception("Association and EAP start timed out")
  2690. if "refuse proposed method" in ev:
  2691. found = True
  2692. break
  2693. if not found:
  2694. raise Exception("Unexpected EAP status: " + ev)
  2695. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2696. if ev is None:
  2697. raise Exception("EAP failure timed out")
  2698. def test_ap_wpa2_eap_sql(dev, apdev, params):
  2699. """WPA2-Enterprise connection using SQLite for user DB"""
  2700. skip_with_fips(dev[0])
  2701. try:
  2702. import sqlite3
  2703. except ImportError:
  2704. raise HwsimSkip("No sqlite3 module available")
  2705. dbfile = os.path.join(params['logdir'], "eap-user.db")
  2706. try:
  2707. os.remove(dbfile)
  2708. except:
  2709. pass
  2710. con = sqlite3.connect(dbfile)
  2711. with con:
  2712. cur = con.cursor()
  2713. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  2714. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  2715. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)")
  2716. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)")
  2717. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)")
  2718. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)")
  2719. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  2720. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  2721. try:
  2722. params = int_eap_server_params()
  2723. params["eap_user_file"] = "sqlite:" + dbfile
  2724. hostapd.add_ap(apdev[0]['ifname'], params)
  2725. eap_connect(dev[0], apdev[0], "TTLS", "user-mschapv2",
  2726. anonymous_identity="ttls", password="password",
  2727. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  2728. dev[0].request("REMOVE_NETWORK all")
  2729. eap_connect(dev[1], apdev[0], "TTLS", "user-mschap",
  2730. anonymous_identity="ttls", password="password",
  2731. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  2732. dev[1].request("REMOVE_NETWORK all")
  2733. eap_connect(dev[0], apdev[0], "TTLS", "user-chap",
  2734. anonymous_identity="ttls", password="password",
  2735. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP")
  2736. eap_connect(dev[1], apdev[0], "TTLS", "user-pap",
  2737. anonymous_identity="ttls", password="password",
  2738. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2739. finally:
  2740. os.remove(dbfile)
  2741. def test_ap_wpa2_eap_non_ascii_identity(dev, apdev):
  2742. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  2743. params = int_eap_server_params()
  2744. hostapd.add_ap(apdev[0]['ifname'], params)
  2745. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2746. identity="\x80", password="password", wait_connect=False)
  2747. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2748. identity="a\x80", password="password", wait_connect=False)
  2749. for i in range(0, 2):
  2750. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2751. if ev is None:
  2752. raise Exception("Association and EAP start timed out")
  2753. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2754. if ev is None:
  2755. raise Exception("EAP method selection timed out")
  2756. def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev):
  2757. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  2758. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2759. hostapd.add_ap(apdev[0]['ifname'], params)
  2760. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2761. identity="\x80", password="password", wait_connect=False)
  2762. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2763. identity="a\x80", password="password", wait_connect=False)
  2764. for i in range(0, 2):
  2765. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2766. if ev is None:
  2767. raise Exception("Association and EAP start timed out")
  2768. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2769. if ev is None:
  2770. raise Exception("EAP method selection timed out")
  2771. def test_openssl_cipher_suite_config_wpas(dev, apdev):
  2772. """OpenSSL cipher suite configuration on wpa_supplicant"""
  2773. tls = dev[0].request("GET tls_library")
  2774. if not tls.startswith("OpenSSL"):
  2775. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  2776. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2777. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2778. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2779. anonymous_identity="ttls", password="password",
  2780. openssl_ciphers="AES128",
  2781. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2782. eap_connect(dev[1], apdev[0], "TTLS", "pap user",
  2783. anonymous_identity="ttls", password="password",
  2784. openssl_ciphers="EXPORT",
  2785. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2786. expect_failure=True, maybe_local_error=True)
  2787. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2788. identity="pap user", anonymous_identity="ttls",
  2789. password="password",
  2790. openssl_ciphers="FOO",
  2791. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2792. wait_connect=False)
  2793. ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2794. if ev is None:
  2795. raise Exception("EAP failure after invalid openssl_ciphers not reported")
  2796. dev[2].request("DISCONNECT")
  2797. def test_openssl_cipher_suite_config_hapd(dev, apdev):
  2798. """OpenSSL cipher suite configuration on hostapd"""
  2799. tls = dev[0].request("GET tls_library")
  2800. if not tls.startswith("OpenSSL"):
  2801. raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls)
  2802. params = int_eap_server_params()
  2803. params['openssl_ciphers'] = "AES256"
  2804. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2805. tls = hapd.request("GET tls_library")
  2806. if not tls.startswith("OpenSSL"):
  2807. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  2808. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2809. anonymous_identity="ttls", password="password",
  2810. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2811. eap_connect(dev[1], apdev[0], "TTLS", "pap user",
  2812. anonymous_identity="ttls", password="password",
  2813. openssl_ciphers="AES128",
  2814. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2815. expect_failure=True)
  2816. eap_connect(dev[2], apdev[0], "TTLS", "pap user",
  2817. anonymous_identity="ttls", password="password",
  2818. openssl_ciphers="HIGH:!ADH",
  2819. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2820. params['openssl_ciphers'] = "FOO"
  2821. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, no_enable=True)
  2822. if "FAIL" not in hapd2.request("ENABLE"):
  2823. raise Exception("Invalid openssl_ciphers value accepted")
  2824. def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
  2825. """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
  2826. p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2827. hapd = hostapd.add_ap(apdev[0]['ifname'], p)
  2828. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  2829. pid = find_wpas_process(dev[0])
  2830. id = eap_connect(dev[0], apdev[0], "TTLS", "pap-secret",
  2831. anonymous_identity="ttls", password=password,
  2832. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2833. time.sleep(1)
  2834. buf = read_process_memory(pid, password)
  2835. dev[0].request("DISCONNECT")
  2836. dev[0].wait_disconnected()
  2837. dev[0].relog()
  2838. msk = None
  2839. emsk = None
  2840. pmk = None
  2841. ptk = None
  2842. gtk = None
  2843. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  2844. for l in f.readlines():
  2845. if "EAP-TTLS: Derived key - hexdump" in l:
  2846. val = l.strip().split(':')[3].replace(' ', '')
  2847. msk = binascii.unhexlify(val)
  2848. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  2849. val = l.strip().split(':')[3].replace(' ', '')
  2850. emsk = binascii.unhexlify(val)
  2851. if "WPA: PMK - hexdump" in l:
  2852. val = l.strip().split(':')[3].replace(' ', '')
  2853. pmk = binascii.unhexlify(val)
  2854. if "WPA: PTK - hexdump" in l:
  2855. val = l.strip().split(':')[3].replace(' ', '')
  2856. ptk = binascii.unhexlify(val)
  2857. if "WPA: Group Key - hexdump" in l:
  2858. val = l.strip().split(':')[3].replace(' ', '')
  2859. gtk = binascii.unhexlify(val)
  2860. if not msk or not emsk or not pmk or not ptk or not gtk:
  2861. raise Exception("Could not find keys from debug log")
  2862. if len(gtk) != 16:
  2863. raise Exception("Unexpected GTK length")
  2864. kck = ptk[0:16]
  2865. kek = ptk[16:32]
  2866. tk = ptk[32:48]
  2867. fname = os.path.join(params['logdir'],
  2868. 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-')
  2869. logger.info("Checking keys in memory while associated")
  2870. get_key_locations(buf, password, "Password")
  2871. get_key_locations(buf, pmk, "PMK")
  2872. get_key_locations(buf, msk, "MSK")
  2873. get_key_locations(buf, emsk, "EMSK")
  2874. if password not in buf:
  2875. raise HwsimSkip("Password not found while associated")
  2876. if pmk not in buf:
  2877. raise HwsimSkip("PMK not found while associated")
  2878. if kck not in buf:
  2879. raise Exception("KCK not found while associated")
  2880. if kek not in buf:
  2881. raise Exception("KEK not found while associated")
  2882. if tk in buf:
  2883. raise Exception("TK found from memory")
  2884. if gtk in buf:
  2885. raise Exception("GTK found from memory")
  2886. logger.info("Checking keys in memory after disassociation")
  2887. buf = read_process_memory(pid, password)
  2888. # Note: Password is still present in network configuration
  2889. # Note: PMK is in PMKSA cache and EAP fast re-auth data
  2890. get_key_locations(buf, password, "Password")
  2891. get_key_locations(buf, pmk, "PMK")
  2892. get_key_locations(buf, msk, "MSK")
  2893. get_key_locations(buf, emsk, "EMSK")
  2894. verify_not_present(buf, kck, fname, "KCK")
  2895. verify_not_present(buf, kek, fname, "KEK")
  2896. verify_not_present(buf, tk, fname, "TK")
  2897. verify_not_present(buf, gtk, fname, "GTK")
  2898. dev[0].request("PMKSA_FLUSH")
  2899. dev[0].set_network_quoted(id, "identity", "foo")
  2900. logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush")
  2901. buf = read_process_memory(pid, password)
  2902. get_key_locations(buf, password, "Password")
  2903. get_key_locations(buf, pmk, "PMK")
  2904. get_key_locations(buf, msk, "MSK")
  2905. get_key_locations(buf, emsk, "EMSK")
  2906. verify_not_present(buf, pmk, fname, "PMK")
  2907. dev[0].request("REMOVE_NETWORK all")
  2908. logger.info("Checking keys in memory after network profile removal")
  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, password, fname, "password")
  2915. verify_not_present(buf, pmk, fname, "PMK")
  2916. verify_not_present(buf, kck, fname, "KCK")
  2917. verify_not_present(buf, kek, fname, "KEK")
  2918. verify_not_present(buf, tk, fname, "TK")
  2919. verify_not_present(buf, gtk, fname, "GTK")
  2920. verify_not_present(buf, msk, fname, "MSK")
  2921. verify_not_present(buf, emsk, fname, "EMSK")
  2922. def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev):
  2923. """WPA2-Enterprise connection and unexpected WEP EAPOL-Key"""
  2924. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2925. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2926. bssid = apdev[0]['bssid']
  2927. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2928. anonymous_identity="ttls", password="password",
  2929. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2930. # Send unexpected WEP EAPOL-Key; this gets dropped
  2931. res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
  2932. if "OK" not in res:
  2933. raise Exception("EAPOL_RX to wpa_supplicant failed")
  2934. def test_ap_wpa2_eap_in_bridge(dev, apdev):
  2935. """WPA2-EAP and wpas interface in a bridge"""
  2936. br_ifname='sta-br0'
  2937. ifname='wlan5'
  2938. try:
  2939. _test_ap_wpa2_eap_in_bridge(dev, apdev)
  2940. finally:
  2941. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  2942. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  2943. subprocess.call(['brctl', 'delbr', br_ifname])
  2944. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  2945. def _test_ap_wpa2_eap_in_bridge(dev, apdev):
  2946. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2947. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2948. br_ifname='sta-br0'
  2949. ifname='wlan5'
  2950. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  2951. subprocess.call(['brctl', 'addbr', br_ifname])
  2952. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  2953. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  2954. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  2955. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  2956. wpas.interface_add(ifname, br_ifname=br_ifname)
  2957. id = eap_connect(wpas, apdev[0], "PAX", "pax.user@example.com",
  2958. password_hex="0123456789abcdef0123456789abcdef")
  2959. eap_reauth(wpas, "PAX")
  2960. # Try again as a regression test for packet socket workaround
  2961. eap_reauth(wpas, "PAX")
  2962. wpas.request("DISCONNECT")
  2963. wpas.wait_disconnected()
  2964. wpas.request("RECONNECT")
  2965. wpas.wait_connected()
  2966. def test_ap_wpa2_eap_session_ticket(dev, apdev):
  2967. """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled"""
  2968. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2969. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2970. key_mgmt = hapd.get_config()['key_mgmt']
  2971. if key_mgmt.split(' ')[0] != "WPA-EAP":
  2972. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  2973. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2974. anonymous_identity="ttls", password="password",
  2975. ca_cert="auth_serv/ca.pem",
  2976. phase1="tls_disable_session_ticket=0", phase2="auth=PAP")
  2977. eap_reauth(dev[0], "TTLS")
  2978. def test_ap_wpa2_eap_no_workaround(dev, apdev):
  2979. """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0"""
  2980. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2981. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2982. key_mgmt = hapd.get_config()['key_mgmt']
  2983. if key_mgmt.split(' ')[0] != "WPA-EAP":
  2984. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  2985. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2986. anonymous_identity="ttls", password="password",
  2987. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  2988. phase2="auth=PAP")
  2989. eap_reauth(dev[0], "TTLS")
  2990. def test_ap_wpa2_eap_tls_check_crl(dev, apdev):
  2991. """EAP-TLS and server checking CRL"""
  2992. params = int_eap_server_params()
  2993. params['check_crl'] = '1'
  2994. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2995. # check_crl=1 and no CRL available --> reject connection
  2996. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  2997. client_cert="auth_serv/user.pem",
  2998. private_key="auth_serv/user.key", expect_failure=True)
  2999. dev[0].request("REMOVE_NETWORK all")
  3000. hapd.disable()
  3001. hapd.set("ca_cert", "auth_serv/ca-and-crl.pem")
  3002. hapd.enable()
  3003. # check_crl=1 and valid CRL --> accept
  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")
  3007. dev[0].request("REMOVE_NETWORK all")
  3008. hapd.disable()
  3009. hapd.set("check_crl", "2")
  3010. hapd.enable()
  3011. # check_crl=2 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. def test_ap_wpa2_eap_tls_oom(dev, apdev):
  3017. """EAP-TLS and OOM"""
  3018. check_subject_match_support(dev[0])
  3019. check_altsubject_match_support(dev[0])
  3020. check_domain_match_full(dev[0])
  3021. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3022. hostapd.add_ap(apdev[0]['ifname'], params)
  3023. tests = [ (1, "tls_connection_set_subject_match"),
  3024. (2, "tls_connection_set_subject_match"),
  3025. (3, "tls_connection_set_subject_match"),
  3026. (4, "tls_connection_set_subject_match") ]
  3027. for count, func in tests:
  3028. with alloc_fail(dev[0], count, func):
  3029. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3030. identity="tls user", ca_cert="auth_serv/ca.pem",
  3031. client_cert="auth_serv/user.pem",
  3032. private_key="auth_serv/user.key",
  3033. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  3034. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/",
  3035. domain_suffix_match="server.w1.fi",
  3036. domain_match="server.w1.fi",
  3037. wait_connect=False, scan_freq="2412")
  3038. # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE
  3039. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5)
  3040. if ev is None:
  3041. raise Exception("No passphrase request")
  3042. dev[0].request("REMOVE_NETWORK all")
  3043. dev[0].wait_disconnected()
  3044. def test_ap_wpa2_eap_tls_macacl(dev, apdev):
  3045. """WPA2-Enterprise connection using MAC ACL"""
  3046. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3047. params["macaddr_acl"] = "2"
  3048. hostapd.add_ap(apdev[0]['ifname'], params)
  3049. eap_connect(dev[1], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3050. client_cert="auth_serv/user.pem",
  3051. private_key="auth_serv/user.key")
  3052. def test_ap_wpa2_eap_oom(dev, apdev):
  3053. """EAP server and OOM"""
  3054. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3055. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3056. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  3057. with alloc_fail(hapd, 1, "eapol_auth_alloc"):
  3058. # The first attempt fails, but STA will send EAPOL-Start to retry and
  3059. # that succeeds.
  3060. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3061. identity="tls user", ca_cert="auth_serv/ca.pem",
  3062. client_cert="auth_serv/user.pem",
  3063. private_key="auth_serv/user.key",
  3064. scan_freq="2412")
  3065. def check_tls_ver(dev, ap, phase1, expected):
  3066. eap_connect(dev, ap, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3067. client_cert="auth_serv/user.pem",
  3068. private_key="auth_serv/user.key",
  3069. phase1=phase1)
  3070. ver = dev.get_status_field("eap_tls_version")
  3071. if ver != expected:
  3072. raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver))
  3073. def test_ap_wpa2_eap_tls_versions(dev, apdev):
  3074. """EAP-TLS and TLS version configuration"""
  3075. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3076. hostapd.add_ap(apdev[0]['ifname'], params)
  3077. tls = dev[0].request("GET tls_library")
  3078. if tls.startswith("OpenSSL"):
  3079. if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  3080. check_tls_ver(dev[0], apdev[0],
  3081. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
  3082. "TLSv1.2")
  3083. check_tls_ver(dev[1], apdev[0],
  3084. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1")
  3085. check_tls_ver(dev[2], apdev[0],
  3086. "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1")