test_ap_eap.py 157 KB

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