test_ap_eap.py 194 KB

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