test_ap_eap.py 189 KB

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