test_ap_eap.py 192 KB

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