test_ap_eap.py 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183
  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. groups = [ 19, 20, 21, 25, 26 ]
  1706. if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  1707. logger.info("Add Brainpool EC groups since OpenSSL is new enough")
  1708. groups += [ 27, 28, 29, 30 ]
  1709. for i in groups:
  1710. logger.info("Group %d" % i)
  1711. params['pwd_group'] = str(i)
  1712. hostapd.add_ap(apdev[0]['ifname'], params)
  1713. try:
  1714. eap_connect(dev[0], apdev[0], "PWD", "pwd user",
  1715. password="secret password")
  1716. dev[0].request("REMOVE_NETWORK all")
  1717. dev[0].wait_disconnected()
  1718. dev[0].dump_monitor()
  1719. except:
  1720. if "BoringSSL" in tls and i in [ 25 ]:
  1721. logger.info("Ignore connection failure with group %d with BoringSSL" % i)
  1722. dev[0].request("DISCONNECT")
  1723. time.sleep(0.1)
  1724. dev[0].request("REMOVE_NETWORK all")
  1725. dev[0].dump_monitor()
  1726. continue
  1727. raise
  1728. def test_ap_wpa2_eap_pwd_invalid_group(dev, apdev):
  1729. """WPA2-Enterprise connection using invalid EAP-pwd group"""
  1730. check_eap_capa(dev[0], "PWD")
  1731. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1732. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1733. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf" }
  1734. params['pwd_group'] = "0"
  1735. hostapd.add_ap(apdev[0]['ifname'], params)
  1736. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PWD",
  1737. identity="pwd user", password="secret password",
  1738. scan_freq="2412", wait_connect=False)
  1739. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  1740. if ev is None:
  1741. raise Exception("Timeout on EAP failure report")
  1742. def test_ap_wpa2_eap_pwd_as_frag(dev, apdev):
  1743. """WPA2-Enterprise connection using EAP-pwd with server fragmentation"""
  1744. check_eap_capa(dev[0], "PWD")
  1745. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1746. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1747. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1748. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1749. "pwd_group": "19", "fragment_size": "40" }
  1750. hostapd.add_ap(apdev[0]['ifname'], params)
  1751. eap_connect(dev[0], apdev[0], "PWD", "pwd user", password="secret password")
  1752. def test_ap_wpa2_eap_gpsk(dev, apdev):
  1753. """WPA2-Enterprise connection using EAP-GPSK"""
  1754. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1755. hostapd.add_ap(apdev[0]['ifname'], params)
  1756. id = eap_connect(dev[0], apdev[0], "GPSK", "gpsk user",
  1757. password="abcdefghijklmnop0123456789abcdef")
  1758. eap_reauth(dev[0], "GPSK")
  1759. logger.info("Test forced algorithm selection")
  1760. for phase1 in [ "cipher=1", "cipher=2" ]:
  1761. dev[0].set_network_quoted(id, "phase1", phase1)
  1762. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1763. if ev is None:
  1764. raise Exception("EAP success timed out")
  1765. dev[0].wait_connected(timeout=10)
  1766. logger.info("Test failed algorithm negotiation")
  1767. dev[0].set_network_quoted(id, "phase1", "cipher=9")
  1768. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1769. if ev is None:
  1770. raise Exception("EAP failure timed out")
  1771. logger.info("Negative test with incorrect password")
  1772. dev[0].request("REMOVE_NETWORK all")
  1773. eap_connect(dev[0], apdev[0], "GPSK", "gpsk user",
  1774. password="ffcdefghijklmnop0123456789abcdef",
  1775. expect_failure=True)
  1776. def test_ap_wpa2_eap_sake(dev, apdev):
  1777. """WPA2-Enterprise connection using EAP-SAKE"""
  1778. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1779. hostapd.add_ap(apdev[0]['ifname'], params)
  1780. eap_connect(dev[0], apdev[0], "SAKE", "sake user",
  1781. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  1782. eap_reauth(dev[0], "SAKE")
  1783. logger.info("Negative test with incorrect password")
  1784. dev[0].request("REMOVE_NETWORK all")
  1785. eap_connect(dev[0], apdev[0], "SAKE", "sake user",
  1786. password_hex="ff23456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  1787. expect_failure=True)
  1788. def test_ap_wpa2_eap_eke(dev, apdev):
  1789. """WPA2-Enterprise connection using EAP-EKE"""
  1790. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1791. hostapd.add_ap(apdev[0]['ifname'], params)
  1792. id = eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello")
  1793. eap_reauth(dev[0], "EKE")
  1794. logger.info("Test forced algorithm selection")
  1795. for phase1 in [ "dhgroup=5 encr=1 prf=2 mac=2",
  1796. "dhgroup=4 encr=1 prf=2 mac=2",
  1797. "dhgroup=3 encr=1 prf=2 mac=2",
  1798. "dhgroup=3 encr=1 prf=1 mac=1" ]:
  1799. dev[0].set_network_quoted(id, "phase1", phase1)
  1800. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  1801. if ev is None:
  1802. raise Exception("EAP success timed out")
  1803. dev[0].wait_connected(timeout=10)
  1804. logger.info("Test failed algorithm negotiation")
  1805. dev[0].set_network_quoted(id, "phase1", "dhgroup=9 encr=9 prf=9 mac=9")
  1806. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  1807. if ev is None:
  1808. raise Exception("EAP failure timed out")
  1809. logger.info("Negative test with incorrect password")
  1810. dev[0].request("REMOVE_NETWORK all")
  1811. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello1",
  1812. expect_failure=True)
  1813. def test_ap_wpa2_eap_eke_serverid_nai(dev, apdev):
  1814. """WPA2-Enterprise connection using EAP-EKE with serverid NAI"""
  1815. params = int_eap_server_params()
  1816. params['server_id'] = 'example.server@w1.fi'
  1817. hostapd.add_ap(apdev[0]['ifname'], params)
  1818. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello")
  1819. def test_ap_wpa2_eap_eke_server_oom(dev, apdev):
  1820. """WPA2-Enterprise connection using EAP-EKE with server OOM"""
  1821. params = int_eap_server_params()
  1822. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1823. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  1824. for count,func in [ (1, "eap_eke_build_commit"),
  1825. (2, "eap_eke_build_commit"),
  1826. (3, "eap_eke_build_commit"),
  1827. (1, "eap_eke_build_confirm"),
  1828. (2, "eap_eke_build_confirm"),
  1829. (1, "eap_eke_process_commit"),
  1830. (2, "eap_eke_process_commit"),
  1831. (1, "eap_eke_process_confirm"),
  1832. (1, "eap_eke_process_identity"),
  1833. (2, "eap_eke_process_identity"),
  1834. (3, "eap_eke_process_identity"),
  1835. (4, "eap_eke_process_identity") ]:
  1836. with alloc_fail(hapd, count, func):
  1837. eap_connect(dev[0], apdev[0], "EKE", "eke user", password="hello",
  1838. expect_failure=True)
  1839. dev[0].request("REMOVE_NETWORK all")
  1840. for count,func,pw in [ (1, "eap_eke_init", "hello"),
  1841. (1, "eap_eke_get_session_id", "hello"),
  1842. (1, "eap_eke_getKey", "hello"),
  1843. (1, "eap_eke_build_msg", "hello"),
  1844. (1, "eap_eke_build_failure", "wrong"),
  1845. (1, "eap_eke_build_identity", "hello"),
  1846. (2, "eap_eke_build_identity", "hello") ]:
  1847. with alloc_fail(hapd, count, func):
  1848. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1849. eap="EKE", identity="eke user", password=pw,
  1850. wait_connect=False, scan_freq="2412")
  1851. # This would eventually time out, but we can stop after having
  1852. # reached the allocation failure.
  1853. for i in range(20):
  1854. time.sleep(0.1)
  1855. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1856. break
  1857. dev[0].request("REMOVE_NETWORK all")
  1858. for count in range(1, 1000):
  1859. try:
  1860. with alloc_fail(hapd, count, "eap_server_sm_step"):
  1861. dev[0].connect("test-wpa2-eap",
  1862. key_mgmt="WPA-EAP WPA-EAP-SHA256",
  1863. eap="EKE", identity="eke user", password=pw,
  1864. wait_connect=False, scan_freq="2412")
  1865. # This would eventually time out, but we can stop after having
  1866. # reached the allocation failure.
  1867. for i in range(10):
  1868. time.sleep(0.1)
  1869. if hapd.request("GET_ALLOC_FAIL").startswith('0'):
  1870. break
  1871. dev[0].request("REMOVE_NETWORK all")
  1872. except Exception, e:
  1873. if str(e) == "Allocation failure did not trigger":
  1874. if count < 30:
  1875. raise Exception("Too few allocation failures")
  1876. logger.info("%d allocation failures tested" % (count - 1))
  1877. break
  1878. raise e
  1879. def test_ap_wpa2_eap_ikev2(dev, apdev):
  1880. """WPA2-Enterprise connection using EAP-IKEv2"""
  1881. check_eap_capa(dev[0], "IKEV2")
  1882. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1883. hostapd.add_ap(apdev[0]['ifname'], params)
  1884. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1885. password="ike password")
  1886. eap_reauth(dev[0], "IKEV2")
  1887. dev[0].request("REMOVE_NETWORK all")
  1888. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1889. password="ike password", fragment_size="50")
  1890. logger.info("Negative test with incorrect password")
  1891. dev[0].request("REMOVE_NETWORK all")
  1892. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1893. password="ike-password", expect_failure=True)
  1894. def test_ap_wpa2_eap_ikev2_as_frag(dev, apdev):
  1895. """WPA2-Enterprise connection using EAP-IKEv2 with server fragmentation"""
  1896. check_eap_capa(dev[0], "IKEV2")
  1897. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1898. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  1899. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  1900. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  1901. "fragment_size": "50" }
  1902. hostapd.add_ap(apdev[0]['ifname'], params)
  1903. eap_connect(dev[0], apdev[0], "IKEV2", "ikev2 user",
  1904. password="ike password")
  1905. eap_reauth(dev[0], "IKEV2")
  1906. def test_ap_wpa2_eap_ikev2_oom(dev, apdev):
  1907. """WPA2-Enterprise connection using EAP-IKEv2 and OOM"""
  1908. check_eap_capa(dev[0], "IKEV2")
  1909. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1910. hostapd.add_ap(apdev[0]['ifname'], params)
  1911. tests = [ (1, "dh_init"),
  1912. (2, "dh_init"),
  1913. (1, "dh_derive_shared") ]
  1914. for count, func in tests:
  1915. with alloc_fail(dev[0], count, func):
  1916. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  1917. identity="ikev2 user", password="ike password",
  1918. wait_connect=False, scan_freq="2412")
  1919. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  1920. if ev is None:
  1921. raise Exception("EAP method not selected")
  1922. for i in range(10):
  1923. if "0:" in dev[0].request("GET_ALLOC_FAIL"):
  1924. break
  1925. time.sleep(0.02)
  1926. dev[0].request("REMOVE_NETWORK all")
  1927. tests = [ (1, "os_get_random;dh_init") ]
  1928. for count, func in tests:
  1929. with fail_test(dev[0], count, func):
  1930. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="IKEV2",
  1931. identity="ikev2 user", password="ike password",
  1932. wait_connect=False, scan_freq="2412")
  1933. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  1934. if ev is None:
  1935. raise Exception("EAP method not selected")
  1936. for i in range(10):
  1937. if "0:" in dev[0].request("GET_FAIL"):
  1938. break
  1939. time.sleep(0.02)
  1940. dev[0].request("REMOVE_NETWORK all")
  1941. def test_ap_wpa2_eap_pax(dev, apdev):
  1942. """WPA2-Enterprise connection using EAP-PAX"""
  1943. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1944. hostapd.add_ap(apdev[0]['ifname'], params)
  1945. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1946. password_hex="0123456789abcdef0123456789abcdef")
  1947. eap_reauth(dev[0], "PAX")
  1948. logger.info("Negative test with incorrect password")
  1949. dev[0].request("REMOVE_NETWORK all")
  1950. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  1951. password_hex="ff23456789abcdef0123456789abcdef",
  1952. expect_failure=True)
  1953. def test_ap_wpa2_eap_psk(dev, apdev):
  1954. """WPA2-Enterprise connection using EAP-PSK"""
  1955. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1956. params["wpa_key_mgmt"] = "WPA-EAP-SHA256"
  1957. params["ieee80211w"] = "2"
  1958. hostapd.add_ap(apdev[0]['ifname'], params)
  1959. eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com",
  1960. password_hex="0123456789abcdef0123456789abcdef", sha256=True)
  1961. eap_reauth(dev[0], "PSK", sha256=True)
  1962. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-5"),
  1963. ("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-5") ])
  1964. bss = dev[0].get_bss(apdev[0]['bssid'])
  1965. if 'flags' not in bss:
  1966. raise Exception("Could not get BSS flags from BSS table")
  1967. if "[WPA2-EAP-SHA256-CCMP]" not in bss['flags']:
  1968. raise Exception("Unexpected BSS flags: " + bss['flags'])
  1969. logger.info("Negative test with incorrect password")
  1970. dev[0].request("REMOVE_NETWORK all")
  1971. eap_connect(dev[0], apdev[0], "PSK", "psk.user@example.com",
  1972. password_hex="ff23456789abcdef0123456789abcdef", sha256=True,
  1973. expect_failure=True)
  1974. def test_ap_wpa2_eap_psk_oom(dev, apdev):
  1975. """WPA2-Enterprise connection using EAP-PSK and OOM"""
  1976. skip_with_fips(dev[0])
  1977. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  1978. hostapd.add_ap(apdev[0]['ifname'], params)
  1979. tests = [ (1, "aes_128_ctr_encrypt;aes_128_eax_encrypt"),
  1980. (1, "omac1_aes_128;aes_128_eax_encrypt"),
  1981. (2, "omac1_aes_128;aes_128_eax_encrypt"),
  1982. (3, "omac1_aes_128;aes_128_eax_encrypt"),
  1983. (1, "=aes_128_eax_encrypt"),
  1984. (1, "omac1_aes_vector"),
  1985. (1, "aes_128_ctr_encrypt;aes_128_eax_decrypt"),
  1986. (1, "omac1_aes_128;aes_128_eax_decrypt"),
  1987. (2, "omac1_aes_128;aes_128_eax_decrypt"),
  1988. (3, "omac1_aes_128;aes_128_eax_decrypt"),
  1989. (1, "=aes_128_eax_decrypt") ]
  1990. for count, func in tests:
  1991. with alloc_fail(dev[0], count, func):
  1992. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  1993. identity="psk.user@example.com",
  1994. password_hex="0123456789abcdef0123456789abcdef",
  1995. wait_connect=False, scan_freq="2412")
  1996. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=5)
  1997. if ev is None:
  1998. raise Exception("EAP method not selected")
  1999. for i in range(10):
  2000. if "0:" in dev[0].request("GET_ALLOC_FAIL"):
  2001. break
  2002. time.sleep(0.02)
  2003. dev[0].request("REMOVE_NETWORK all")
  2004. with alloc_fail(dev[0], 1, "aes_128_encrypt_block"):
  2005. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="PSK",
  2006. identity="psk.user@example.com",
  2007. password_hex="0123456789abcdef0123456789abcdef",
  2008. wait_connect=False, scan_freq="2412")
  2009. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2010. if ev is None:
  2011. raise Exception("EAP method failure not reported")
  2012. dev[0].request("REMOVE_NETWORK all")
  2013. def test_ap_wpa_eap_peap_eap_mschapv2(dev, apdev):
  2014. """WPA-Enterprise connection using EAP-PEAP/EAP-MSCHAPv2"""
  2015. check_eap_capa(dev[0], "MSCHAPV2")
  2016. params = hostapd.wpa_eap_params(ssid="test-wpa-eap")
  2017. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2018. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="PEAP",
  2019. identity="user", password="password", phase2="auth=MSCHAPV2",
  2020. ca_cert="auth_serv/ca.pem", wait_connect=False,
  2021. scan_freq="2412")
  2022. eap_check_auth(dev[0], "PEAP", True, rsn=False)
  2023. hwsim_utils.test_connectivity(dev[0], hapd)
  2024. eap_reauth(dev[0], "PEAP", rsn=False)
  2025. check_mib(dev[0], [ ("dot11RSNAAuthenticationSuiteRequested", "00-50-f2-1"),
  2026. ("dot11RSNAAuthenticationSuiteSelected", "00-50-f2-1") ])
  2027. status = dev[0].get_status(extra="VERBOSE")
  2028. if 'portControl' not in status:
  2029. raise Exception("portControl missing from STATUS-VERBOSE")
  2030. if status['portControl'] != 'Auto':
  2031. raise Exception("Unexpected portControl value: " + status['portControl'])
  2032. if 'eap_session_id' not in status:
  2033. raise Exception("eap_session_id missing from STATUS-VERBOSE")
  2034. if not status['eap_session_id'].startswith("19"):
  2035. raise Exception("Unexpected eap_session_id value: " + status['eap_session_id'])
  2036. def test_ap_wpa2_eap_interactive(dev, apdev):
  2037. """WPA2-Enterprise connection using interactive identity/password entry"""
  2038. check_eap_capa(dev[0], "MSCHAPV2")
  2039. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2040. hostapd.add_ap(apdev[0]['ifname'], params)
  2041. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  2042. tests = [ ("Connection with dynamic TTLS/MSCHAPv2 password entry",
  2043. "TTLS", "ttls", "DOMAIN\mschapv2 user", "auth=MSCHAPV2",
  2044. None, "password"),
  2045. ("Connection with dynamic TTLS/MSCHAPv2 identity and password entry",
  2046. "TTLS", "ttls", None, "auth=MSCHAPV2",
  2047. "DOMAIN\mschapv2 user", "password"),
  2048. ("Connection with dynamic TTLS/EAP-MSCHAPv2 password entry",
  2049. "TTLS", "ttls", "user", "autheap=MSCHAPV2", None, "password"),
  2050. ("Connection with dynamic TTLS/EAP-MD5 password entry",
  2051. "TTLS", "ttls", "user", "autheap=MD5", None, "password"),
  2052. ("Connection with dynamic PEAP/EAP-MSCHAPv2 password entry",
  2053. "PEAP", None, "user", "auth=MSCHAPV2", None, "password"),
  2054. ("Connection with dynamic PEAP/EAP-GTC password entry",
  2055. "PEAP", None, "user", "auth=GTC", None, "password") ]
  2056. for [desc,eap,anon,identity,phase2,req_id,req_pw] in tests:
  2057. logger.info(desc)
  2058. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap=eap,
  2059. anonymous_identity=anon, identity=identity,
  2060. ca_cert="auth_serv/ca.pem", phase2=phase2,
  2061. wait_connect=False, scan_freq="2412")
  2062. if req_id:
  2063. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2064. if ev is None:
  2065. raise Exception("Request for identity timed out")
  2066. id = ev.split(':')[0].split('-')[-1]
  2067. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2068. ev = dev[0].wait_event(["CTRL-REQ-PASSWORD","CTRL-REQ-OTP"])
  2069. if ev is None:
  2070. raise Exception("Request for password timed out")
  2071. id = ev.split(':')[0].split('-')[-1]
  2072. type = "OTP" if "CTRL-REQ-OTP" in ev else "PASSWORD"
  2073. dev[0].request("CTRL-RSP-" + type + "-" + id + ":" + req_pw)
  2074. dev[0].wait_connected(timeout=10)
  2075. dev[0].request("REMOVE_NETWORK all")
  2076. def test_ap_wpa2_eap_ext_enable_network_while_connected(dev, apdev):
  2077. """WPA2-Enterprise interactive identity entry and ENABLE_NETWORK"""
  2078. check_eap_capa(dev[0], "MSCHAPV2")
  2079. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2080. hostapd.add_ap(apdev[0]['ifname'], params)
  2081. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  2082. id_other = dev[0].connect("other", key_mgmt="NONE", scan_freq="2412",
  2083. only_add_network=True)
  2084. req_id = "DOMAIN\mschapv2 user"
  2085. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2086. anonymous_identity="ttls", identity=None,
  2087. password="password",
  2088. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2089. wait_connect=False, scan_freq="2412")
  2090. ev = dev[0].wait_event(["CTRL-REQ-IDENTITY"])
  2091. if ev is None:
  2092. raise Exception("Request for identity timed out")
  2093. id = ev.split(':')[0].split('-')[-1]
  2094. dev[0].request("CTRL-RSP-IDENTITY-" + id + ":" + req_id)
  2095. dev[0].wait_connected(timeout=10)
  2096. if "OK" not in dev[0].request("ENABLE_NETWORK " + str(id_other)):
  2097. raise Exception("Failed to enable network")
  2098. ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=1)
  2099. if ev is not None:
  2100. raise Exception("Unexpected reconnection attempt on ENABLE_NETWORK")
  2101. dev[0].request("REMOVE_NETWORK all")
  2102. def test_ap_wpa2_eap_vendor_test(dev, apdev):
  2103. """WPA2-Enterprise connection using EAP vendor test"""
  2104. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2105. hostapd.add_ap(apdev[0]['ifname'], params)
  2106. eap_connect(dev[0], apdev[0], "VENDOR-TEST", "vendor-test")
  2107. eap_reauth(dev[0], "VENDOR-TEST")
  2108. eap_connect(dev[1], apdev[0], "VENDOR-TEST", "vendor-test",
  2109. password="pending")
  2110. def test_ap_wpa2_eap_fast_mschapv2_unauth_prov(dev, apdev):
  2111. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and unauthenticated provisioning"""
  2112. check_eap_capa(dev[0], "FAST")
  2113. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2114. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2115. eap_connect(dev[0], apdev[0], "FAST", "user",
  2116. anonymous_identity="FAST", password="password",
  2117. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2118. phase1="fast_provisioning=1", pac_file="blob://fast_pac")
  2119. hwsim_utils.test_connectivity(dev[0], hapd)
  2120. res = eap_reauth(dev[0], "FAST")
  2121. if res['tls_session_reused'] != '1':
  2122. raise Exception("EAP-FAST could not use PAC session ticket")
  2123. def test_ap_wpa2_eap_fast_pac_file(dev, apdev, params):
  2124. """WPA2-Enterprise connection using EAP-FAST/MSCHAPv2 and PAC file"""
  2125. check_eap_capa(dev[0], "FAST")
  2126. pac_file = os.path.join(params['logdir'], "fast.pac")
  2127. pac_file2 = os.path.join(params['logdir'], "fast-bin.pac")
  2128. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2129. hostapd.add_ap(apdev[0]['ifname'], params)
  2130. try:
  2131. eap_connect(dev[0], apdev[0], "FAST", "user",
  2132. anonymous_identity="FAST", password="password",
  2133. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2134. phase1="fast_provisioning=1", pac_file=pac_file)
  2135. with open(pac_file, "r") as f:
  2136. data = f.read()
  2137. if "wpa_supplicant EAP-FAST PAC file - version 1" not in data:
  2138. raise Exception("PAC file header missing")
  2139. if "PAC-Key=" not in data:
  2140. raise Exception("PAC-Key missing from PAC file")
  2141. dev[0].request("REMOVE_NETWORK all")
  2142. eap_connect(dev[0], apdev[0], "FAST", "user",
  2143. anonymous_identity="FAST", password="password",
  2144. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2145. pac_file=pac_file)
  2146. eap_connect(dev[1], apdev[0], "FAST", "user",
  2147. anonymous_identity="FAST", password="password",
  2148. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2149. phase1="fast_provisioning=1 fast_pac_format=binary",
  2150. pac_file=pac_file2)
  2151. dev[1].request("REMOVE_NETWORK all")
  2152. eap_connect(dev[1], apdev[0], "FAST", "user",
  2153. anonymous_identity="FAST", password="password",
  2154. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2155. phase1="fast_pac_format=binary",
  2156. pac_file=pac_file2)
  2157. finally:
  2158. try:
  2159. os.remove(pac_file)
  2160. except:
  2161. pass
  2162. try:
  2163. os.remove(pac_file2)
  2164. except:
  2165. pass
  2166. def test_ap_wpa2_eap_fast_binary_pac(dev, apdev):
  2167. """WPA2-Enterprise connection using EAP-FAST and binary PAC format"""
  2168. check_eap_capa(dev[0], "FAST")
  2169. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2170. hostapd.add_ap(apdev[0]['ifname'], params)
  2171. eap_connect(dev[0], apdev[0], "FAST", "user",
  2172. anonymous_identity="FAST", password="password",
  2173. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2174. phase1="fast_provisioning=1 fast_max_pac_list_len=1 fast_pac_format=binary",
  2175. pac_file="blob://fast_pac_bin")
  2176. res = eap_reauth(dev[0], "FAST")
  2177. if res['tls_session_reused'] != '1':
  2178. raise Exception("EAP-FAST could not use PAC session ticket")
  2179. def test_ap_wpa2_eap_fast_missing_pac_config(dev, apdev):
  2180. """WPA2-Enterprise connection using EAP-FAST and missing PAC config"""
  2181. check_eap_capa(dev[0], "FAST")
  2182. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2183. hostapd.add_ap(apdev[0]['ifname'], params)
  2184. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2185. identity="user", anonymous_identity="FAST",
  2186. password="password",
  2187. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2188. pac_file="blob://fast_pac_not_in_use",
  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. dev[0].request("REMOVE_NETWORK all")
  2194. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2195. identity="user", anonymous_identity="FAST",
  2196. password="password",
  2197. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2198. wait_connect=False, scan_freq="2412")
  2199. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2200. if ev is None:
  2201. raise Exception("Timeout on EAP failure report")
  2202. def test_ap_wpa2_eap_fast_gtc_auth_prov(dev, apdev):
  2203. """WPA2-Enterprise connection using EAP-FAST/GTC and authenticated provisioning"""
  2204. check_eap_capa(dev[0], "FAST")
  2205. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2206. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2207. eap_connect(dev[0], apdev[0], "FAST", "user",
  2208. anonymous_identity="FAST", password="password",
  2209. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  2210. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth")
  2211. hwsim_utils.test_connectivity(dev[0], hapd)
  2212. res = eap_reauth(dev[0], "FAST")
  2213. if res['tls_session_reused'] != '1':
  2214. raise Exception("EAP-FAST could not use PAC session ticket")
  2215. def test_ap_wpa2_eap_fast_gtc_identity_change(dev, apdev):
  2216. """WPA2-Enterprise connection using EAP-FAST/GTC and identity changing"""
  2217. check_eap_capa(dev[0], "FAST")
  2218. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2219. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2220. id = eap_connect(dev[0], apdev[0], "FAST", "user",
  2221. anonymous_identity="FAST", password="password",
  2222. ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  2223. phase1="fast_provisioning=2",
  2224. pac_file="blob://fast_pac_auth")
  2225. dev[0].set_network_quoted(id, "identity", "user2")
  2226. dev[0].wait_disconnected()
  2227. ev = dev[0].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15)
  2228. if ev is None:
  2229. raise Exception("EAP-FAST not started")
  2230. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=5)
  2231. if ev is None:
  2232. raise Exception("EAP failure not reported")
  2233. dev[0].wait_disconnected()
  2234. def test_ap_wpa2_eap_fast_prf_oom(dev, apdev):
  2235. """WPA2-Enterprise connection using EAP-FAST and OOM in PRF"""
  2236. check_eap_capa(dev[0], "FAST")
  2237. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2238. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2239. with alloc_fail(dev[0], 2, "openssl_tls_prf"):
  2240. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="FAST",
  2241. identity="user", anonymous_identity="FAST",
  2242. password="password", ca_cert="auth_serv/ca.pem",
  2243. phase2="auth=GTC",
  2244. phase1="fast_provisioning=2",
  2245. pac_file="blob://fast_pac_auth",
  2246. wait_connect=False, scan_freq="2412")
  2247. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=15)
  2248. if ev is None:
  2249. raise Exception("EAP failure not reported")
  2250. dev[0].request("DISCONNECT")
  2251. def test_ap_wpa2_eap_fast_server_oom(dev, apdev):
  2252. """EAP-FAST/MSCHAPv2 and server OOM"""
  2253. check_eap_capa(dev[0], "FAST")
  2254. params = int_eap_server_params()
  2255. params['dh_file'] = 'auth_serv/dh.conf'
  2256. params['pac_opaque_encr_key'] = '000102030405060708090a0b0c0d0e0f'
  2257. params['eap_fast_a_id'] = '1011'
  2258. params['eap_fast_a_id_info'] = 'another test server'
  2259. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2260. with alloc_fail(hapd, 1, "tls_session_ticket_ext_cb"):
  2261. id = eap_connect(dev[0], apdev[0], "FAST", "user",
  2262. anonymous_identity="FAST", password="password",
  2263. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  2264. phase1="fast_provisioning=1",
  2265. pac_file="blob://fast_pac",
  2266. expect_failure=True)
  2267. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2268. if ev is None:
  2269. raise Exception("No EAP failure reported")
  2270. dev[0].wait_disconnected()
  2271. dev[0].request("DISCONNECT")
  2272. dev[0].select_network(id, freq="2412")
  2273. def test_ap_wpa2_eap_tls_ocsp(dev, apdev):
  2274. """WPA2-Enterprise connection using EAP-TLS and verifying OCSP"""
  2275. check_ocsp_support(dev[0])
  2276. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2277. hostapd.add_ap(apdev[0]['ifname'], params)
  2278. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  2279. private_key="auth_serv/user.pkcs12",
  2280. private_key_passwd="whatever", ocsp=2)
  2281. def int_eap_server_params():
  2282. params = { "ssid": "test-wpa2-eap", "wpa": "2", "wpa_key_mgmt": "WPA-EAP",
  2283. "rsn_pairwise": "CCMP", "ieee8021x": "1",
  2284. "eap_server": "1", "eap_user_file": "auth_serv/eap_user.conf",
  2285. "ca_cert": "auth_serv/ca.pem",
  2286. "server_cert": "auth_serv/server.pem",
  2287. "private_key": "auth_serv/server.key" }
  2288. return params
  2289. def test_ap_wpa2_eap_tls_ocsp_ca_signed_good(dev, apdev, params):
  2290. """EAP-TLS and CA signed OCSP response (good)"""
  2291. check_ocsp_support(dev[0])
  2292. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed.der")
  2293. if not os.path.exists(ocsp):
  2294. raise HwsimSkip("No OCSP response available")
  2295. params = int_eap_server_params()
  2296. params["ocsp_stapling_response"] = ocsp
  2297. hostapd.add_ap(apdev[0]['ifname'], params)
  2298. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2299. identity="tls user", ca_cert="auth_serv/ca.pem",
  2300. private_key="auth_serv/user.pkcs12",
  2301. private_key_passwd="whatever", ocsp=2,
  2302. scan_freq="2412")
  2303. def test_ap_wpa2_eap_tls_ocsp_ca_signed_revoked(dev, apdev, params):
  2304. """EAP-TLS and CA signed OCSP response (revoked)"""
  2305. check_ocsp_support(dev[0])
  2306. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-revoked.der")
  2307. if not os.path.exists(ocsp):
  2308. raise HwsimSkip("No OCSP response available")
  2309. params = int_eap_server_params()
  2310. params["ocsp_stapling_response"] = ocsp
  2311. hostapd.add_ap(apdev[0]['ifname'], params)
  2312. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2313. identity="tls user", ca_cert="auth_serv/ca.pem",
  2314. private_key="auth_serv/user.pkcs12",
  2315. private_key_passwd="whatever", ocsp=2,
  2316. wait_connect=False, scan_freq="2412")
  2317. count = 0
  2318. while True:
  2319. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2320. if ev is None:
  2321. raise Exception("Timeout on EAP status")
  2322. if 'bad certificate status response' in ev:
  2323. break
  2324. if 'certificate revoked' in ev:
  2325. break
  2326. count = count + 1
  2327. if count > 10:
  2328. raise Exception("Unexpected number of EAP status messages")
  2329. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2330. if ev is None:
  2331. raise Exception("Timeout on EAP failure report")
  2332. def test_ap_wpa2_eap_tls_ocsp_ca_signed_unknown(dev, apdev, params):
  2333. """EAP-TLS and CA signed OCSP response (unknown)"""
  2334. check_ocsp_support(dev[0])
  2335. ocsp = os.path.join(params['logdir'], "ocsp-resp-ca-signed-unknown.der")
  2336. if not os.path.exists(ocsp):
  2337. raise HwsimSkip("No OCSP response available")
  2338. params = int_eap_server_params()
  2339. params["ocsp_stapling_response"] = ocsp
  2340. hostapd.add_ap(apdev[0]['ifname'], params)
  2341. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2342. identity="tls user", ca_cert="auth_serv/ca.pem",
  2343. private_key="auth_serv/user.pkcs12",
  2344. private_key_passwd="whatever", ocsp=2,
  2345. wait_connect=False, scan_freq="2412")
  2346. count = 0
  2347. while True:
  2348. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2349. if ev is None:
  2350. raise Exception("Timeout on EAP status")
  2351. if 'bad certificate status response' in ev:
  2352. break
  2353. count = count + 1
  2354. if count > 10:
  2355. raise Exception("Unexpected number of EAP status messages")
  2356. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2357. if ev is None:
  2358. raise Exception("Timeout on EAP failure report")
  2359. def test_ap_wpa2_eap_tls_ocsp_server_signed(dev, apdev, params):
  2360. """EAP-TLS and server signed OCSP response"""
  2361. check_ocsp_support(dev[0])
  2362. ocsp = os.path.join(params['logdir'], "ocsp-resp-server-signed.der")
  2363. if not os.path.exists(ocsp):
  2364. raise HwsimSkip("No OCSP response available")
  2365. params = int_eap_server_params()
  2366. params["ocsp_stapling_response"] = ocsp
  2367. hostapd.add_ap(apdev[0]['ifname'], params)
  2368. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2369. identity="tls user", ca_cert="auth_serv/ca.pem",
  2370. private_key="auth_serv/user.pkcs12",
  2371. private_key_passwd="whatever", ocsp=2,
  2372. wait_connect=False, scan_freq="2412")
  2373. count = 0
  2374. while True:
  2375. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2376. if ev is None:
  2377. raise Exception("Timeout on EAP status")
  2378. if 'bad certificate status response' in ev:
  2379. break
  2380. count = count + 1
  2381. if count > 10:
  2382. raise Exception("Unexpected number of EAP status messages")
  2383. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2384. if ev is None:
  2385. raise Exception("Timeout on EAP failure report")
  2386. def test_ap_wpa2_eap_tls_ocsp_invalid_data(dev, apdev):
  2387. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP data"""
  2388. check_ocsp_support(dev[0])
  2389. params = int_eap_server_params()
  2390. params["ocsp_stapling_response"] = "auth_serv/ocsp-req.der"
  2391. hostapd.add_ap(apdev[0]['ifname'], params)
  2392. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2393. identity="tls user", ca_cert="auth_serv/ca.pem",
  2394. private_key="auth_serv/user.pkcs12",
  2395. private_key_passwd="whatever", ocsp=2,
  2396. wait_connect=False, scan_freq="2412")
  2397. count = 0
  2398. while True:
  2399. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2400. if ev is None:
  2401. raise Exception("Timeout on EAP status")
  2402. if 'bad certificate status response' in ev:
  2403. break
  2404. count = count + 1
  2405. if count > 10:
  2406. raise Exception("Unexpected number of EAP status messages")
  2407. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2408. if ev is None:
  2409. raise Exception("Timeout on EAP failure report")
  2410. def test_ap_wpa2_eap_tls_ocsp_invalid(dev, apdev):
  2411. """WPA2-Enterprise connection using EAP-TLS and invalid OCSP response"""
  2412. check_ocsp_support(dev[0])
  2413. params = int_eap_server_params()
  2414. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-invalid"
  2415. hostapd.add_ap(apdev[0]['ifname'], params)
  2416. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2417. identity="tls user", ca_cert="auth_serv/ca.pem",
  2418. private_key="auth_serv/user.pkcs12",
  2419. private_key_passwd="whatever", ocsp=2,
  2420. wait_connect=False, scan_freq="2412")
  2421. count = 0
  2422. while True:
  2423. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2424. if ev is None:
  2425. raise Exception("Timeout on EAP status")
  2426. if 'bad certificate status response' in ev:
  2427. break
  2428. count = count + 1
  2429. if count > 10:
  2430. raise Exception("Unexpected number of EAP status messages")
  2431. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2432. if ev is None:
  2433. raise Exception("Timeout on EAP failure report")
  2434. def test_ap_wpa2_eap_tls_ocsp_unknown_sign(dev, apdev):
  2435. """WPA2-Enterprise connection using EAP-TLS and unknown OCSP signer"""
  2436. check_ocsp_support(dev[0])
  2437. params = int_eap_server_params()
  2438. params["ocsp_stapling_response"] = "auth_serv/ocsp-server-cache.der-unknown-sign"
  2439. hostapd.add_ap(apdev[0]['ifname'], params)
  2440. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2441. identity="tls user", ca_cert="auth_serv/ca.pem",
  2442. private_key="auth_serv/user.pkcs12",
  2443. private_key_passwd="whatever", ocsp=2,
  2444. wait_connect=False, scan_freq="2412")
  2445. count = 0
  2446. while True:
  2447. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2448. if ev is None:
  2449. raise Exception("Timeout on EAP status")
  2450. if 'bad certificate status response' in ev:
  2451. break
  2452. count = count + 1
  2453. if count > 10:
  2454. raise Exception("Unexpected number of EAP status messages")
  2455. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2456. if ev is None:
  2457. raise Exception("Timeout on EAP failure report")
  2458. def test_ap_wpa2_eap_ttls_ocsp_revoked(dev, apdev, params):
  2459. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  2460. check_ocsp_support(dev[0])
  2461. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-revoked.der")
  2462. if not os.path.exists(ocsp):
  2463. raise HwsimSkip("No OCSP response available")
  2464. params = int_eap_server_params()
  2465. params["ocsp_stapling_response"] = ocsp
  2466. hostapd.add_ap(apdev[0]['ifname'], params)
  2467. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2468. identity="pap user", ca_cert="auth_serv/ca.pem",
  2469. anonymous_identity="ttls", password="password",
  2470. phase2="auth=PAP", ocsp=2,
  2471. wait_connect=False, scan_freq="2412")
  2472. count = 0
  2473. while True:
  2474. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2475. if ev is None:
  2476. raise Exception("Timeout on EAP status")
  2477. if 'bad certificate status response' in ev:
  2478. break
  2479. if 'certificate revoked' in ev:
  2480. break
  2481. count = count + 1
  2482. if count > 10:
  2483. raise Exception("Unexpected number of EAP status messages")
  2484. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2485. if ev is None:
  2486. raise Exception("Timeout on EAP failure report")
  2487. def test_ap_wpa2_eap_ttls_ocsp_unknown(dev, apdev, params):
  2488. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  2489. check_ocsp_support(dev[0])
  2490. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  2491. if not os.path.exists(ocsp):
  2492. raise HwsimSkip("No OCSP response available")
  2493. params = int_eap_server_params()
  2494. params["ocsp_stapling_response"] = ocsp
  2495. hostapd.add_ap(apdev[0]['ifname'], params)
  2496. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2497. identity="pap user", ca_cert="auth_serv/ca.pem",
  2498. anonymous_identity="ttls", password="password",
  2499. phase2="auth=PAP", ocsp=2,
  2500. wait_connect=False, scan_freq="2412")
  2501. count = 0
  2502. while True:
  2503. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"])
  2504. if ev is None:
  2505. raise Exception("Timeout on EAP status")
  2506. if 'bad certificate status response' in ev:
  2507. break
  2508. count = count + 1
  2509. if count > 10:
  2510. raise Exception("Unexpected number of EAP status messages")
  2511. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2512. if ev is None:
  2513. raise Exception("Timeout on EAP failure report")
  2514. def test_ap_wpa2_eap_ttls_optional_ocsp_unknown(dev, apdev, params):
  2515. """WPA2-Enterprise connection using EAP-TTLS and OCSP status revoked"""
  2516. ocsp = os.path.join(params['logdir'], "ocsp-server-cache-unknown.der")
  2517. if not os.path.exists(ocsp):
  2518. raise HwsimSkip("No OCSP response available")
  2519. params = int_eap_server_params()
  2520. params["ocsp_stapling_response"] = ocsp
  2521. hostapd.add_ap(apdev[0]['ifname'], params)
  2522. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2523. identity="pap user", ca_cert="auth_serv/ca.pem",
  2524. anonymous_identity="ttls", password="password",
  2525. phase2="auth=PAP", ocsp=1, scan_freq="2412")
  2526. def test_ap_wpa2_eap_tls_domain_suffix_match_cn_full(dev, apdev):
  2527. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  2528. params = int_eap_server_params()
  2529. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2530. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2531. hostapd.add_ap(apdev[0]['ifname'], params)
  2532. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2533. identity="tls user", ca_cert="auth_serv/ca.pem",
  2534. private_key="auth_serv/user.pkcs12",
  2535. private_key_passwd="whatever",
  2536. domain_suffix_match="server3.w1.fi",
  2537. scan_freq="2412")
  2538. def test_ap_wpa2_eap_tls_domain_match_cn(dev, apdev):
  2539. """WPA2-Enterprise using EAP-TLS and domainmatch (CN)"""
  2540. params = int_eap_server_params()
  2541. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2542. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2543. hostapd.add_ap(apdev[0]['ifname'], params)
  2544. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2545. identity="tls user", ca_cert="auth_serv/ca.pem",
  2546. private_key="auth_serv/user.pkcs12",
  2547. private_key_passwd="whatever",
  2548. domain_match="server3.w1.fi",
  2549. scan_freq="2412")
  2550. def test_ap_wpa2_eap_tls_domain_suffix_match_cn(dev, apdev):
  2551. """WPA2-Enterprise using EAP-TLS and domain suffix match (CN)"""
  2552. check_domain_match_full(dev[0])
  2553. params = int_eap_server_params()
  2554. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2555. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2556. hostapd.add_ap(apdev[0]['ifname'], params)
  2557. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2558. identity="tls user", ca_cert="auth_serv/ca.pem",
  2559. private_key="auth_serv/user.pkcs12",
  2560. private_key_passwd="whatever",
  2561. domain_suffix_match="w1.fi",
  2562. scan_freq="2412")
  2563. def test_ap_wpa2_eap_tls_domain_suffix_mismatch_cn(dev, apdev):
  2564. """WPA2-Enterprise using EAP-TLS and domain suffix mismatch (CN)"""
  2565. params = int_eap_server_params()
  2566. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2567. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2568. hostapd.add_ap(apdev[0]['ifname'], params)
  2569. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2570. identity="tls user", ca_cert="auth_serv/ca.pem",
  2571. private_key="auth_serv/user.pkcs12",
  2572. private_key_passwd="whatever",
  2573. domain_suffix_match="example.com",
  2574. wait_connect=False,
  2575. scan_freq="2412")
  2576. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2577. identity="tls user", ca_cert="auth_serv/ca.pem",
  2578. private_key="auth_serv/user.pkcs12",
  2579. private_key_passwd="whatever",
  2580. domain_suffix_match="erver3.w1.fi",
  2581. wait_connect=False,
  2582. scan_freq="2412")
  2583. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2584. if ev is None:
  2585. raise Exception("Timeout on EAP failure report")
  2586. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2587. if ev is None:
  2588. raise Exception("Timeout on EAP failure report (2)")
  2589. def test_ap_wpa2_eap_tls_domain_mismatch_cn(dev, apdev):
  2590. """WPA2-Enterprise using EAP-TLS and domain mismatch (CN)"""
  2591. params = int_eap_server_params()
  2592. params["server_cert"] = "auth_serv/server-no-dnsname.pem"
  2593. params["private_key"] = "auth_serv/server-no-dnsname.key"
  2594. hostapd.add_ap(apdev[0]['ifname'], params)
  2595. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2596. identity="tls user", ca_cert="auth_serv/ca.pem",
  2597. private_key="auth_serv/user.pkcs12",
  2598. private_key_passwd="whatever",
  2599. domain_match="example.com",
  2600. wait_connect=False,
  2601. scan_freq="2412")
  2602. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  2603. identity="tls user", ca_cert="auth_serv/ca.pem",
  2604. private_key="auth_serv/user.pkcs12",
  2605. private_key_passwd="whatever",
  2606. domain_match="w1.fi",
  2607. wait_connect=False,
  2608. scan_freq="2412")
  2609. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2610. if ev is None:
  2611. raise Exception("Timeout on EAP failure report")
  2612. ev = dev[1].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2613. if ev is None:
  2614. raise Exception("Timeout on EAP failure report (2)")
  2615. def test_ap_wpa2_eap_ttls_expired_cert(dev, apdev):
  2616. """WPA2-Enterprise using EAP-TTLS and expired certificate"""
  2617. skip_with_fips(dev[0])
  2618. params = int_eap_server_params()
  2619. params["server_cert"] = "auth_serv/server-expired.pem"
  2620. params["private_key"] = "auth_serv/server-expired.key"
  2621. hostapd.add_ap(apdev[0]['ifname'], params)
  2622. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2623. identity="mschap user", password="password",
  2624. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2625. wait_connect=False,
  2626. scan_freq="2412")
  2627. ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"])
  2628. if ev is None:
  2629. raise Exception("Timeout on EAP certificate error report")
  2630. if "reason=4" not in ev or "certificate has expired" not in ev:
  2631. raise Exception("Unexpected failure reason: " + ev)
  2632. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2633. if ev is None:
  2634. raise Exception("Timeout on EAP failure report")
  2635. def test_ap_wpa2_eap_ttls_ignore_expired_cert(dev, apdev):
  2636. """WPA2-Enterprise using EAP-TTLS and ignore certificate expiration"""
  2637. skip_with_fips(dev[0])
  2638. params = int_eap_server_params()
  2639. params["server_cert"] = "auth_serv/server-expired.pem"
  2640. params["private_key"] = "auth_serv/server-expired.key"
  2641. hostapd.add_ap(apdev[0]['ifname'], params)
  2642. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2643. identity="mschap user", password="password",
  2644. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2645. phase1="tls_disable_time_checks=1",
  2646. scan_freq="2412")
  2647. def test_ap_wpa2_eap_ttls_long_duration(dev, apdev):
  2648. """WPA2-Enterprise using EAP-TTLS and long certificate duration"""
  2649. skip_with_fips(dev[0])
  2650. params = int_eap_server_params()
  2651. params["server_cert"] = "auth_serv/server-long-duration.pem"
  2652. params["private_key"] = "auth_serv/server-long-duration.key"
  2653. hostapd.add_ap(apdev[0]['ifname'], params)
  2654. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2655. identity="mschap user", password="password",
  2656. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2657. scan_freq="2412")
  2658. def test_ap_wpa2_eap_ttls_server_cert_eku_client(dev, apdev):
  2659. """WPA2-Enterprise using EAP-TTLS and server cert with client EKU"""
  2660. skip_with_fips(dev[0])
  2661. params = int_eap_server_params()
  2662. params["server_cert"] = "auth_serv/server-eku-client.pem"
  2663. params["private_key"] = "auth_serv/server-eku-client.key"
  2664. hostapd.add_ap(apdev[0]['ifname'], params)
  2665. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2666. identity="mschap user", password="password",
  2667. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2668. wait_connect=False,
  2669. scan_freq="2412")
  2670. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2671. if ev is None:
  2672. raise Exception("Timeout on EAP failure report")
  2673. def test_ap_wpa2_eap_ttls_server_cert_eku_client_server(dev, apdev):
  2674. """WPA2-Enterprise using EAP-TTLS and server cert with client and server EKU"""
  2675. skip_with_fips(dev[0])
  2676. params = int_eap_server_params()
  2677. params["server_cert"] = "auth_serv/server-eku-client-server.pem"
  2678. params["private_key"] = "auth_serv/server-eku-client-server.key"
  2679. hostapd.add_ap(apdev[0]['ifname'], params)
  2680. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2681. identity="mschap user", password="password",
  2682. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2683. scan_freq="2412")
  2684. def test_ap_wpa2_eap_ttls_server_pkcs12(dev, apdev):
  2685. """WPA2-Enterprise using EAP-TTLS and server PKCS#12 file"""
  2686. skip_with_fips(dev[0])
  2687. params = int_eap_server_params()
  2688. del params["server_cert"]
  2689. params["private_key"] = "auth_serv/server.pkcs12"
  2690. hostapd.add_ap(apdev[0]['ifname'], params)
  2691. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2692. identity="mschap user", password="password",
  2693. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2694. scan_freq="2412")
  2695. def test_ap_wpa2_eap_ttls_dh_params(dev, apdev):
  2696. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params"""
  2697. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2698. hostapd.add_ap(apdev[0]['ifname'], params)
  2699. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2700. anonymous_identity="ttls", password="password",
  2701. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  2702. dh_file="auth_serv/dh.conf")
  2703. def test_ap_wpa2_eap_ttls_dh_params_dsa(dev, apdev):
  2704. """WPA2-Enterprise connection using EAP-TTLS and setting DH params (DSA)"""
  2705. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2706. hostapd.add_ap(apdev[0]['ifname'], params)
  2707. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2708. anonymous_identity="ttls", password="password",
  2709. ca_cert="auth_serv/ca.der", phase2="auth=PAP",
  2710. dh_file="auth_serv/dsaparam.pem")
  2711. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  2712. """EAP-TTLS and DH params file not found"""
  2713. skip_with_fips(dev[0])
  2714. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2715. hostapd.add_ap(apdev[0]['ifname'], params)
  2716. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2717. identity="mschap user", password="password",
  2718. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2719. dh_file="auth_serv/dh-no-such-file.conf",
  2720. scan_freq="2412", wait_connect=False)
  2721. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2722. if ev is None:
  2723. raise Exception("EAP failure timed out")
  2724. dev[0].request("REMOVE_NETWORK all")
  2725. dev[0].wait_disconnected()
  2726. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  2727. """EAP-TTLS and invalid DH params file"""
  2728. skip_with_fips(dev[0])
  2729. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2730. hostapd.add_ap(apdev[0]['ifname'], params)
  2731. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2732. identity="mschap user", password="password",
  2733. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2734. dh_file="auth_serv/ca.pem",
  2735. scan_freq="2412", wait_connect=False)
  2736. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2737. if ev is None:
  2738. raise Exception("EAP failure timed out")
  2739. dev[0].request("REMOVE_NETWORK all")
  2740. dev[0].wait_disconnected()
  2741. def test_ap_wpa2_eap_ttls_dh_params_blob(dev, apdev):
  2742. """WPA2-Enterprise connection using EAP-TTLS/CHAP and setting DH params from blob"""
  2743. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2744. hostapd.add_ap(apdev[0]['ifname'], params)
  2745. dh = read_pem("auth_serv/dh2.conf")
  2746. if "OK" not in dev[0].request("SET blob dhparams " + dh.encode("hex")):
  2747. raise Exception("Could not set dhparams blob")
  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. dh_file="blob://dhparams")
  2752. def test_ap_wpa2_eap_ttls_dh_params_server(dev, apdev):
  2753. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams"""
  2754. params = int_eap_server_params()
  2755. params["dh_file"] = "auth_serv/dh2.conf"
  2756. hostapd.add_ap(apdev[0]['ifname'], params)
  2757. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2758. anonymous_identity="ttls", password="password",
  2759. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  2760. def test_ap_wpa2_eap_ttls_dh_params_dsa_server(dev, apdev):
  2761. """WPA2-Enterprise using EAP-TTLS and alternative server dhparams (DSA)"""
  2762. params = int_eap_server_params()
  2763. params["dh_file"] = "auth_serv/dsaparam.pem"
  2764. hostapd.add_ap(apdev[0]['ifname'], params)
  2765. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2766. anonymous_identity="ttls", password="password",
  2767. ca_cert="auth_serv/ca.der", phase2="auth=PAP")
  2768. def test_ap_wpa2_eap_ttls_dh_params_not_found(dev, apdev):
  2769. """EAP-TLS server and dhparams file not found"""
  2770. params = int_eap_server_params()
  2771. params["dh_file"] = "auth_serv/dh-no-such-file.conf"
  2772. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2773. if "FAIL" not in hapd.request("ENABLE"):
  2774. raise Exception("Invalid configuration accepted")
  2775. def test_ap_wpa2_eap_ttls_dh_params_invalid(dev, apdev):
  2776. """EAP-TLS server and invalid dhparams file"""
  2777. params = int_eap_server_params()
  2778. params["dh_file"] = "auth_serv/ca.pem"
  2779. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  2780. if "FAIL" not in hapd.request("ENABLE"):
  2781. raise Exception("Invalid configuration accepted")
  2782. def test_ap_wpa2_eap_reauth(dev, apdev):
  2783. """WPA2-Enterprise and Authenticator forcing reauthentication"""
  2784. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2785. params['eap_reauth_period'] = '2'
  2786. hostapd.add_ap(apdev[0]['ifname'], params)
  2787. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  2788. password_hex="0123456789abcdef0123456789abcdef")
  2789. logger.info("Wait for reauthentication")
  2790. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2791. if ev is None:
  2792. raise Exception("Timeout on reauthentication")
  2793. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  2794. if ev is None:
  2795. raise Exception("Timeout on reauthentication")
  2796. for i in range(0, 20):
  2797. state = dev[0].get_status_field("wpa_state")
  2798. if state == "COMPLETED":
  2799. break
  2800. time.sleep(0.1)
  2801. if state != "COMPLETED":
  2802. raise Exception("Reauthentication did not complete")
  2803. def test_ap_wpa2_eap_request_identity_message(dev, apdev):
  2804. """Optional displayable message in EAP Request-Identity"""
  2805. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2806. params['eap_message'] = 'hello\\0networkid=netw,nasid=foo,portid=0,NAIRealms=example.com'
  2807. hostapd.add_ap(apdev[0]['ifname'], params)
  2808. eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
  2809. password_hex="0123456789abcdef0123456789abcdef")
  2810. def test_ap_wpa2_eap_sim_aka_result_ind(dev, apdev):
  2811. """WPA2-Enterprise using EAP-SIM/AKA and protected result indication"""
  2812. check_hlr_auc_gw_support()
  2813. params = int_eap_server_params()
  2814. params['eap_sim_db'] = "unix:/tmp/hlr_auc_gw.sock"
  2815. params['eap_sim_aka_result_ind'] = "1"
  2816. hostapd.add_ap(apdev[0]['ifname'], params)
  2817. eap_connect(dev[0], apdev[0], "SIM", "1232010000000000",
  2818. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  2819. phase1="result_ind=1")
  2820. eap_reauth(dev[0], "SIM")
  2821. eap_connect(dev[1], apdev[0], "SIM", "1232010000000000",
  2822. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  2823. dev[0].request("REMOVE_NETWORK all")
  2824. dev[1].request("REMOVE_NETWORK all")
  2825. eap_connect(dev[0], apdev[0], "AKA", "0232010000000000",
  2826. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123",
  2827. phase1="result_ind=1")
  2828. eap_reauth(dev[0], "AKA")
  2829. eap_connect(dev[1], apdev[0], "AKA", "0232010000000000",
  2830. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  2831. dev[0].request("REMOVE_NETWORK all")
  2832. dev[1].request("REMOVE_NETWORK all")
  2833. eap_connect(dev[0], apdev[0], "AKA'", "6555444333222111",
  2834. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123",
  2835. phase1="result_ind=1")
  2836. eap_reauth(dev[0], "AKA'")
  2837. eap_connect(dev[1], apdev[0], "AKA'", "6555444333222111",
  2838. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  2839. def test_ap_wpa2_eap_too_many_roundtrips(dev, apdev):
  2840. """WPA2-Enterprise connection resulting in too many EAP roundtrips"""
  2841. skip_with_fips(dev[0])
  2842. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2843. hostapd.add_ap(apdev[0]['ifname'], params)
  2844. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2845. eap="TTLS", identity="mschap user",
  2846. wait_connect=False, scan_freq="2412", ieee80211w="1",
  2847. anonymous_identity="ttls", password="password",
  2848. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  2849. fragment_size="10")
  2850. ev = dev[0].wait_event(["EAP: more than"], timeout=20)
  2851. if ev is None:
  2852. raise Exception("EAP roundtrip limit not reached")
  2853. def test_ap_wpa2_eap_expanded_nak(dev, apdev):
  2854. """WPA2-Enterprise connection with EAP resulting in expanded NAK"""
  2855. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2856. hostapd.add_ap(apdev[0]['ifname'], params)
  2857. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  2858. eap="PSK", identity="vendor-test",
  2859. password_hex="ff23456789abcdef0123456789abcdef",
  2860. wait_connect=False)
  2861. found = False
  2862. for i in range(0, 5):
  2863. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STATUS"], timeout=10)
  2864. if ev is None:
  2865. raise Exception("Association and EAP start timed out")
  2866. if "refuse proposed method" in ev:
  2867. found = True
  2868. break
  2869. if not found:
  2870. raise Exception("Unexpected EAP status: " + ev)
  2871. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"])
  2872. if ev is None:
  2873. raise Exception("EAP failure timed out")
  2874. def test_ap_wpa2_eap_sql(dev, apdev, params):
  2875. """WPA2-Enterprise connection using SQLite for user DB"""
  2876. skip_with_fips(dev[0])
  2877. try:
  2878. import sqlite3
  2879. except ImportError:
  2880. raise HwsimSkip("No sqlite3 module available")
  2881. dbfile = os.path.join(params['logdir'], "eap-user.db")
  2882. try:
  2883. os.remove(dbfile)
  2884. except:
  2885. pass
  2886. con = sqlite3.connect(dbfile)
  2887. with con:
  2888. cur = con.cursor()
  2889. cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)")
  2890. cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)")
  2891. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-pap','TTLS-PAP','password',1)")
  2892. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-chap','TTLS-CHAP','password',1)")
  2893. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschap','TTLS-MSCHAP','password',1)")
  2894. cur.execute("INSERT INTO users(identity,methods,password,phase2) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1)")
  2895. cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')")
  2896. cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)")
  2897. try:
  2898. params = int_eap_server_params()
  2899. params["eap_user_file"] = "sqlite:" + dbfile
  2900. hostapd.add_ap(apdev[0]['ifname'], params)
  2901. eap_connect(dev[0], apdev[0], "TTLS", "user-mschapv2",
  2902. anonymous_identity="ttls", password="password",
  2903. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  2904. dev[0].request("REMOVE_NETWORK all")
  2905. eap_connect(dev[1], apdev[0], "TTLS", "user-mschap",
  2906. anonymous_identity="ttls", password="password",
  2907. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP")
  2908. dev[1].request("REMOVE_NETWORK all")
  2909. eap_connect(dev[0], apdev[0], "TTLS", "user-chap",
  2910. anonymous_identity="ttls", password="password",
  2911. ca_cert="auth_serv/ca.pem", phase2="auth=CHAP")
  2912. eap_connect(dev[1], apdev[0], "TTLS", "user-pap",
  2913. anonymous_identity="ttls", password="password",
  2914. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2915. finally:
  2916. os.remove(dbfile)
  2917. def test_ap_wpa2_eap_non_ascii_identity(dev, apdev):
  2918. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  2919. params = int_eap_server_params()
  2920. hostapd.add_ap(apdev[0]['ifname'], params)
  2921. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2922. identity="\x80", password="password", wait_connect=False)
  2923. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2924. identity="a\x80", password="password", wait_connect=False)
  2925. for i in range(0, 2):
  2926. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2927. if ev is None:
  2928. raise Exception("Association and EAP start timed out")
  2929. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2930. if ev is None:
  2931. raise Exception("EAP method selection timed out")
  2932. def test_ap_wpa2_eap_non_ascii_identity2(dev, apdev):
  2933. """WPA2-Enterprise connection attempt using non-ASCII identity"""
  2934. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2935. hostapd.add_ap(apdev[0]['ifname'], params)
  2936. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2937. identity="\x80", password="password", wait_connect=False)
  2938. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2939. identity="a\x80", password="password", wait_connect=False)
  2940. for i in range(0, 2):
  2941. ev = dev[i].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  2942. if ev is None:
  2943. raise Exception("Association and EAP start timed out")
  2944. ev = dev[i].wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=10)
  2945. if ev is None:
  2946. raise Exception("EAP method selection timed out")
  2947. def test_openssl_cipher_suite_config_wpas(dev, apdev):
  2948. """OpenSSL cipher suite configuration on wpa_supplicant"""
  2949. tls = dev[0].request("GET tls_library")
  2950. if not tls.startswith("OpenSSL"):
  2951. raise HwsimSkip("TLS library is not OpenSSL: " + tls)
  2952. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  2953. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2954. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2955. anonymous_identity="ttls", password="password",
  2956. openssl_ciphers="AES128",
  2957. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2958. eap_connect(dev[1], apdev[0], "TTLS", "pap user",
  2959. anonymous_identity="ttls", password="password",
  2960. openssl_ciphers="EXPORT",
  2961. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2962. expect_failure=True, maybe_local_error=True)
  2963. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  2964. identity="pap user", anonymous_identity="ttls",
  2965. password="password",
  2966. openssl_ciphers="FOO",
  2967. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2968. wait_connect=False)
  2969. ev = dev[2].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  2970. if ev is None:
  2971. raise Exception("EAP failure after invalid openssl_ciphers not reported")
  2972. dev[2].request("DISCONNECT")
  2973. def test_openssl_cipher_suite_config_hapd(dev, apdev):
  2974. """OpenSSL cipher suite configuration on hostapd"""
  2975. tls = dev[0].request("GET tls_library")
  2976. if not tls.startswith("OpenSSL"):
  2977. raise HwsimSkip("wpa_supplicant TLS library is not OpenSSL: " + tls)
  2978. params = int_eap_server_params()
  2979. params['openssl_ciphers'] = "AES256"
  2980. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  2981. tls = hapd.request("GET tls_library")
  2982. if not tls.startswith("OpenSSL"):
  2983. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  2984. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  2985. anonymous_identity="ttls", password="password",
  2986. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2987. eap_connect(dev[1], apdev[0], "TTLS", "pap user",
  2988. anonymous_identity="ttls", password="password",
  2989. openssl_ciphers="AES128",
  2990. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  2991. expect_failure=True)
  2992. eap_connect(dev[2], apdev[0], "TTLS", "pap user",
  2993. anonymous_identity="ttls", password="password",
  2994. openssl_ciphers="HIGH:!ADH",
  2995. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  2996. params['openssl_ciphers'] = "FOO"
  2997. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, no_enable=True)
  2998. if "FAIL" not in hapd2.request("ENABLE"):
  2999. raise Exception("Invalid openssl_ciphers value accepted")
  3000. def test_wpa2_eap_ttls_pap_key_lifetime_in_memory(dev, apdev, params):
  3001. """Key lifetime in memory with WPA2-Enterprise using EAP-TTLS/PAP"""
  3002. p = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3003. hapd = hostapd.add_ap(apdev[0]['ifname'], p)
  3004. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  3005. pid = find_wpas_process(dev[0])
  3006. id = eap_connect(dev[0], apdev[0], "TTLS", "pap-secret",
  3007. anonymous_identity="ttls", password=password,
  3008. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  3009. time.sleep(1)
  3010. buf = read_process_memory(pid, password)
  3011. dev[0].request("DISCONNECT")
  3012. dev[0].wait_disconnected()
  3013. dev[0].relog()
  3014. msk = None
  3015. emsk = None
  3016. pmk = None
  3017. ptk = None
  3018. gtk = None
  3019. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  3020. for l in f.readlines():
  3021. if "EAP-TTLS: Derived key - hexdump" in l:
  3022. val = l.strip().split(':')[3].replace(' ', '')
  3023. msk = binascii.unhexlify(val)
  3024. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  3025. val = l.strip().split(':')[3].replace(' ', '')
  3026. emsk = binascii.unhexlify(val)
  3027. if "WPA: PMK - hexdump" in l:
  3028. val = l.strip().split(':')[3].replace(' ', '')
  3029. pmk = binascii.unhexlify(val)
  3030. if "WPA: PTK - hexdump" in l:
  3031. val = l.strip().split(':')[3].replace(' ', '')
  3032. ptk = binascii.unhexlify(val)
  3033. if "WPA: Group Key - hexdump" in l:
  3034. val = l.strip().split(':')[3].replace(' ', '')
  3035. gtk = binascii.unhexlify(val)
  3036. if not msk or not emsk or not pmk or not ptk or not gtk:
  3037. raise Exception("Could not find keys from debug log")
  3038. if len(gtk) != 16:
  3039. raise Exception("Unexpected GTK length")
  3040. kck = ptk[0:16]
  3041. kek = ptk[16:32]
  3042. tk = ptk[32:48]
  3043. fname = os.path.join(params['logdir'],
  3044. 'wpa2_eap_ttls_pap_key_lifetime_in_memory.memctx-')
  3045. logger.info("Checking keys in memory while associated")
  3046. get_key_locations(buf, password, "Password")
  3047. get_key_locations(buf, pmk, "PMK")
  3048. get_key_locations(buf, msk, "MSK")
  3049. get_key_locations(buf, emsk, "EMSK")
  3050. if password not in buf:
  3051. raise HwsimSkip("Password not found while associated")
  3052. if pmk not in buf:
  3053. raise HwsimSkip("PMK not found while associated")
  3054. if kck not in buf:
  3055. raise Exception("KCK not found while associated")
  3056. if kek not in buf:
  3057. raise Exception("KEK not found while associated")
  3058. if tk in buf:
  3059. raise Exception("TK found from memory")
  3060. if gtk in buf:
  3061. raise Exception("GTK found from memory")
  3062. logger.info("Checking keys in memory after disassociation")
  3063. buf = read_process_memory(pid, password)
  3064. # Note: Password is still present in network configuration
  3065. # Note: PMK is in PMKSA cache and EAP fast re-auth data
  3066. get_key_locations(buf, password, "Password")
  3067. get_key_locations(buf, pmk, "PMK")
  3068. get_key_locations(buf, msk, "MSK")
  3069. get_key_locations(buf, emsk, "EMSK")
  3070. verify_not_present(buf, kck, fname, "KCK")
  3071. verify_not_present(buf, kek, fname, "KEK")
  3072. verify_not_present(buf, tk, fname, "TK")
  3073. verify_not_present(buf, gtk, fname, "GTK")
  3074. dev[0].request("PMKSA_FLUSH")
  3075. dev[0].set_network_quoted(id, "identity", "foo")
  3076. logger.info("Checking keys in memory after PMKSA cache and EAP fast reauth flush")
  3077. buf = read_process_memory(pid, password)
  3078. get_key_locations(buf, password, "Password")
  3079. get_key_locations(buf, pmk, "PMK")
  3080. get_key_locations(buf, msk, "MSK")
  3081. get_key_locations(buf, emsk, "EMSK")
  3082. verify_not_present(buf, pmk, fname, "PMK")
  3083. dev[0].request("REMOVE_NETWORK all")
  3084. logger.info("Checking keys in memory after network profile removal")
  3085. buf = read_process_memory(pid, password)
  3086. get_key_locations(buf, password, "Password")
  3087. get_key_locations(buf, pmk, "PMK")
  3088. get_key_locations(buf, msk, "MSK")
  3089. get_key_locations(buf, emsk, "EMSK")
  3090. verify_not_present(buf, password, fname, "password")
  3091. verify_not_present(buf, pmk, fname, "PMK")
  3092. verify_not_present(buf, kck, fname, "KCK")
  3093. verify_not_present(buf, kek, fname, "KEK")
  3094. verify_not_present(buf, tk, fname, "TK")
  3095. verify_not_present(buf, gtk, fname, "GTK")
  3096. verify_not_present(buf, msk, fname, "MSK")
  3097. verify_not_present(buf, emsk, fname, "EMSK")
  3098. def test_ap_wpa2_eap_unexpected_wep_eapol_key(dev, apdev):
  3099. """WPA2-Enterprise connection and unexpected WEP EAPOL-Key"""
  3100. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3101. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3102. bssid = apdev[0]['bssid']
  3103. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  3104. anonymous_identity="ttls", password="password",
  3105. ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  3106. # Send unexpected WEP EAPOL-Key; this gets dropped
  3107. res = dev[0].request("EAPOL_RX " + bssid + " 0203002c0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
  3108. if "OK" not in res:
  3109. raise Exception("EAPOL_RX to wpa_supplicant failed")
  3110. def test_ap_wpa2_eap_in_bridge(dev, apdev):
  3111. """WPA2-EAP and wpas interface in a bridge"""
  3112. br_ifname='sta-br0'
  3113. ifname='wlan5'
  3114. try:
  3115. _test_ap_wpa2_eap_in_bridge(dev, apdev)
  3116. finally:
  3117. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  3118. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  3119. subprocess.call(['brctl', 'delbr', br_ifname])
  3120. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  3121. def _test_ap_wpa2_eap_in_bridge(dev, apdev):
  3122. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3123. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3124. br_ifname='sta-br0'
  3125. ifname='wlan5'
  3126. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  3127. subprocess.call(['brctl', 'addbr', br_ifname])
  3128. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  3129. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  3130. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  3131. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  3132. wpas.interface_add(ifname, br_ifname=br_ifname)
  3133. wpas.dump_monitor()
  3134. id = eap_connect(wpas, apdev[0], "PAX", "pax.user@example.com",
  3135. password_hex="0123456789abcdef0123456789abcdef")
  3136. wpas.dump_monitor()
  3137. eap_reauth(wpas, "PAX")
  3138. wpas.dump_monitor()
  3139. # Try again as a regression test for packet socket workaround
  3140. eap_reauth(wpas, "PAX")
  3141. wpas.dump_monitor()
  3142. wpas.request("DISCONNECT")
  3143. wpas.wait_disconnected()
  3144. wpas.dump_monitor()
  3145. wpas.request("RECONNECT")
  3146. wpas.wait_connected()
  3147. wpas.dump_monitor()
  3148. def test_ap_wpa2_eap_session_ticket(dev, apdev):
  3149. """WPA2-Enterprise connection using EAP-TTLS and TLS session ticket enabled"""
  3150. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3151. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3152. key_mgmt = hapd.get_config()['key_mgmt']
  3153. if key_mgmt.split(' ')[0] != "WPA-EAP":
  3154. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  3155. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  3156. anonymous_identity="ttls", password="password",
  3157. ca_cert="auth_serv/ca.pem",
  3158. phase1="tls_disable_session_ticket=0", phase2="auth=PAP")
  3159. eap_reauth(dev[0], "TTLS")
  3160. def test_ap_wpa2_eap_no_workaround(dev, apdev):
  3161. """WPA2-Enterprise connection using EAP-TTLS and eap_workaround=0"""
  3162. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3163. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3164. key_mgmt = hapd.get_config()['key_mgmt']
  3165. if key_mgmt.split(' ')[0] != "WPA-EAP":
  3166. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  3167. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  3168. anonymous_identity="ttls", password="password",
  3169. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  3170. phase2="auth=PAP")
  3171. eap_reauth(dev[0], "TTLS")
  3172. def test_ap_wpa2_eap_tls_check_crl(dev, apdev):
  3173. """EAP-TLS and server checking CRL"""
  3174. params = int_eap_server_params()
  3175. params['check_crl'] = '1'
  3176. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3177. # check_crl=1 and no CRL available --> reject connection
  3178. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3179. client_cert="auth_serv/user.pem",
  3180. private_key="auth_serv/user.key", expect_failure=True)
  3181. dev[0].request("REMOVE_NETWORK all")
  3182. hapd.disable()
  3183. hapd.set("ca_cert", "auth_serv/ca-and-crl.pem")
  3184. hapd.enable()
  3185. # check_crl=1 and valid CRL --> accept
  3186. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3187. client_cert="auth_serv/user.pem",
  3188. private_key="auth_serv/user.key")
  3189. dev[0].request("REMOVE_NETWORK all")
  3190. hapd.disable()
  3191. hapd.set("check_crl", "2")
  3192. hapd.enable()
  3193. # check_crl=2 and valid CRL --> accept
  3194. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3195. client_cert="auth_serv/user.pem",
  3196. private_key="auth_serv/user.key")
  3197. dev[0].request("REMOVE_NETWORK all")
  3198. def test_ap_wpa2_eap_tls_oom(dev, apdev):
  3199. """EAP-TLS and OOM"""
  3200. check_subject_match_support(dev[0])
  3201. check_altsubject_match_support(dev[0])
  3202. check_domain_match_full(dev[0])
  3203. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3204. hostapd.add_ap(apdev[0]['ifname'], params)
  3205. tests = [ (1, "tls_connection_set_subject_match"),
  3206. (2, "tls_connection_set_subject_match"),
  3207. (3, "tls_connection_set_subject_match"),
  3208. (4, "tls_connection_set_subject_match") ]
  3209. for count, func in tests:
  3210. with alloc_fail(dev[0], count, func):
  3211. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3212. identity="tls user", ca_cert="auth_serv/ca.pem",
  3213. client_cert="auth_serv/user.pem",
  3214. private_key="auth_serv/user.key",
  3215. subject_match="/C=FI/O=w1.fi/CN=server.w1.fi",
  3216. altsubject_match="EMAIL:noone@example.com;DNS:server.w1.fi;URI:http://example.com/",
  3217. domain_suffix_match="server.w1.fi",
  3218. domain_match="server.w1.fi",
  3219. wait_connect=False, scan_freq="2412")
  3220. # TLS parameter configuration error results in CTRL-REQ-PASSPHRASE
  3221. ev = dev[0].wait_event(["CTRL-REQ-PASSPHRASE"], timeout=5)
  3222. if ev is None:
  3223. raise Exception("No passphrase request")
  3224. dev[0].request("REMOVE_NETWORK all")
  3225. dev[0].wait_disconnected()
  3226. def test_ap_wpa2_eap_tls_macacl(dev, apdev):
  3227. """WPA2-Enterprise connection using MAC ACL"""
  3228. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3229. params["macaddr_acl"] = "2"
  3230. hostapd.add_ap(apdev[0]['ifname'], params)
  3231. eap_connect(dev[1], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3232. client_cert="auth_serv/user.pem",
  3233. private_key="auth_serv/user.key")
  3234. def test_ap_wpa2_eap_oom(dev, apdev):
  3235. """EAP server and OOM"""
  3236. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3237. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3238. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412)
  3239. with alloc_fail(hapd, 1, "eapol_auth_alloc"):
  3240. # The first attempt fails, but STA will send EAPOL-Start to retry and
  3241. # that succeeds.
  3242. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TLS",
  3243. identity="tls user", ca_cert="auth_serv/ca.pem",
  3244. client_cert="auth_serv/user.pem",
  3245. private_key="auth_serv/user.key",
  3246. scan_freq="2412")
  3247. def check_tls_ver(dev, ap, phase1, expected):
  3248. eap_connect(dev, ap, "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3249. client_cert="auth_serv/user.pem",
  3250. private_key="auth_serv/user.key",
  3251. phase1=phase1)
  3252. ver = dev.get_status_field("eap_tls_version")
  3253. if ver != expected:
  3254. raise Exception("Unexpected TLS version (expected %s): %s" % (expected, ver))
  3255. def test_ap_wpa2_eap_tls_versions(dev, apdev):
  3256. """EAP-TLS and TLS version configuration"""
  3257. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3258. hostapd.add_ap(apdev[0]['ifname'], params)
  3259. tls = dev[0].request("GET tls_library")
  3260. if tls.startswith("OpenSSL"):
  3261. if "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
  3262. check_tls_ver(dev[0], apdev[0],
  3263. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1",
  3264. "TLSv1.2")
  3265. check_tls_ver(dev[1], apdev[0],
  3266. "tls_disable_tlsv1_0=1 tls_disable_tlsv1_2=1", "TLSv1.1")
  3267. check_tls_ver(dev[2], apdev[0],
  3268. "tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=1", "TLSv1")
  3269. def test_rsn_ie_proto_eap_sta(dev, apdev):
  3270. """RSN element protocol testing for EAP cases on STA side"""
  3271. bssid = apdev[0]['bssid']
  3272. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3273. # This is the RSN element used normally by hostapd
  3274. params['own_ie_override'] = '30140100000fac040100000fac040100000fac010c00'
  3275. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3276. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="GPSK",
  3277. identity="gpsk user",
  3278. password="abcdefghijklmnop0123456789abcdef",
  3279. scan_freq="2412")
  3280. tests = [ ('No RSN Capabilities field',
  3281. '30120100000fac040100000fac040100000fac01'),
  3282. ('No AKM Suite fields',
  3283. '300c0100000fac040100000fac04'),
  3284. ('No Pairwise Cipher Suite fields',
  3285. '30060100000fac04'),
  3286. ('No Group Data Cipher Suite field',
  3287. '30020100') ]
  3288. for txt,ie in tests:
  3289. dev[0].request("DISCONNECT")
  3290. dev[0].wait_disconnected()
  3291. logger.info(txt)
  3292. hapd.disable()
  3293. hapd.set('own_ie_override', ie)
  3294. hapd.enable()
  3295. dev[0].request("BSS_FLUSH 0")
  3296. dev[0].scan_for_bss(bssid, 2412, force_scan=True, only_new=True)
  3297. dev[0].select_network(id, freq=2412)
  3298. dev[0].wait_connected()
  3299. def check_tls_session_resumption_capa(dev, hapd):
  3300. tls = hapd.request("GET tls_library")
  3301. if not tls.startswith("OpenSSL"):
  3302. raise HwsimSkip("hostapd TLS library is not OpenSSL: " + tls)
  3303. tls = dev.request("GET tls_library")
  3304. if not tls.startswith("OpenSSL"):
  3305. raise HwsimSkip("Session resumption not supported with this TLS library: " + tls)
  3306. def test_eap_ttls_pap_session_resumption(dev, apdev):
  3307. """EAP-TTLS/PAP session resumption"""
  3308. params = int_eap_server_params()
  3309. params['tls_session_lifetime'] = '60'
  3310. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3311. check_tls_session_resumption_capa(dev[0], hapd)
  3312. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  3313. anonymous_identity="ttls", password="password",
  3314. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  3315. phase2="auth=PAP")
  3316. if dev[0].get_status_field("tls_session_reused") != '0':
  3317. raise Exception("Unexpected session resumption on the first connection")
  3318. dev[0].request("REAUTHENTICATE")
  3319. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3320. if ev is None:
  3321. raise Exception("EAP success timed out")
  3322. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3323. if ev is None:
  3324. raise Exception("Key handshake with the AP timed out")
  3325. if dev[0].get_status_field("tls_session_reused") != '1':
  3326. raise Exception("Session resumption not used on the second connection")
  3327. def test_eap_ttls_chap_session_resumption(dev, apdev):
  3328. """EAP-TTLS/CHAP session resumption"""
  3329. params = int_eap_server_params()
  3330. params['tls_session_lifetime'] = '60'
  3331. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3332. check_tls_session_resumption_capa(dev[0], hapd)
  3333. eap_connect(dev[0], apdev[0], "TTLS", "chap user",
  3334. anonymous_identity="ttls", password="password",
  3335. ca_cert="auth_serv/ca.der", phase2="auth=CHAP")
  3336. if dev[0].get_status_field("tls_session_reused") != '0':
  3337. raise Exception("Unexpected session resumption on the first connection")
  3338. dev[0].request("REAUTHENTICATE")
  3339. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3340. if ev is None:
  3341. raise Exception("EAP success timed out")
  3342. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3343. if ev is None:
  3344. raise Exception("Key handshake with the AP timed out")
  3345. if dev[0].get_status_field("tls_session_reused") != '1':
  3346. raise Exception("Session resumption not used on the second connection")
  3347. def test_eap_ttls_mschap_session_resumption(dev, apdev):
  3348. """EAP-TTLS/MSCHAP session resumption"""
  3349. params = int_eap_server_params()
  3350. params['tls_session_lifetime'] = '60'
  3351. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3352. check_tls_session_resumption_capa(dev[0], hapd)
  3353. eap_connect(dev[0], apdev[0], "TTLS", "mschap user",
  3354. anonymous_identity="ttls", password="password",
  3355. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAP",
  3356. domain_suffix_match="server.w1.fi")
  3357. if dev[0].get_status_field("tls_session_reused") != '0':
  3358. raise Exception("Unexpected session resumption on the first connection")
  3359. dev[0].request("REAUTHENTICATE")
  3360. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3361. if ev is None:
  3362. raise Exception("EAP success timed out")
  3363. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3364. if ev is None:
  3365. raise Exception("Key handshake with the AP timed out")
  3366. if dev[0].get_status_field("tls_session_reused") != '1':
  3367. raise Exception("Session resumption not used on the second connection")
  3368. def test_eap_ttls_mschapv2_session_resumption(dev, apdev):
  3369. """EAP-TTLS/MSCHAPv2 session resumption"""
  3370. check_eap_capa(dev[0], "MSCHAPV2")
  3371. params = int_eap_server_params()
  3372. params['tls_session_lifetime'] = '60'
  3373. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3374. check_tls_session_resumption_capa(dev[0], hapd)
  3375. eap_connect(dev[0], apdev[0], "TTLS", "DOMAIN\mschapv2 user",
  3376. anonymous_identity="ttls", password="password",
  3377. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3378. domain_suffix_match="server.w1.fi")
  3379. if dev[0].get_status_field("tls_session_reused") != '0':
  3380. raise Exception("Unexpected session resumption on the first connection")
  3381. dev[0].request("REAUTHENTICATE")
  3382. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3383. if ev is None:
  3384. raise Exception("EAP success timed out")
  3385. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3386. if ev is None:
  3387. raise Exception("Key handshake with the AP timed out")
  3388. if dev[0].get_status_field("tls_session_reused") != '1':
  3389. raise Exception("Session resumption not used on the second connection")
  3390. def test_eap_ttls_eap_gtc_session_resumption(dev, apdev):
  3391. """EAP-TTLS/EAP-GTC session resumption"""
  3392. params = int_eap_server_params()
  3393. params['tls_session_lifetime'] = '60'
  3394. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3395. check_tls_session_resumption_capa(dev[0], hapd)
  3396. eap_connect(dev[0], apdev[0], "TTLS", "user",
  3397. anonymous_identity="ttls", password="password",
  3398. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC")
  3399. if dev[0].get_status_field("tls_session_reused") != '0':
  3400. raise Exception("Unexpected session resumption on the first connection")
  3401. dev[0].request("REAUTHENTICATE")
  3402. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3403. if ev is None:
  3404. raise Exception("EAP success timed out")
  3405. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3406. if ev is None:
  3407. raise Exception("Key handshake with the AP timed out")
  3408. if dev[0].get_status_field("tls_session_reused") != '1':
  3409. raise Exception("Session resumption not used on the second connection")
  3410. def test_eap_ttls_no_session_resumption(dev, apdev):
  3411. """EAP-TTLS session resumption disabled on server"""
  3412. params = int_eap_server_params()
  3413. params['tls_session_lifetime'] = '0'
  3414. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3415. eap_connect(dev[0], apdev[0], "TTLS", "pap user",
  3416. anonymous_identity="ttls", password="password",
  3417. ca_cert="auth_serv/ca.pem", eap_workaround='0',
  3418. phase2="auth=PAP")
  3419. if dev[0].get_status_field("tls_session_reused") != '0':
  3420. raise Exception("Unexpected session resumption on the first connection")
  3421. dev[0].request("REAUTHENTICATE")
  3422. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3423. if ev is None:
  3424. raise Exception("EAP success timed out")
  3425. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3426. if ev is None:
  3427. raise Exception("Key handshake with the AP timed out")
  3428. if dev[0].get_status_field("tls_session_reused") != '0':
  3429. raise Exception("Unexpected session resumption on the second connection")
  3430. def test_eap_peap_session_resumption(dev, apdev):
  3431. """EAP-PEAP session resumption"""
  3432. params = int_eap_server_params()
  3433. params['tls_session_lifetime'] = '60'
  3434. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3435. check_tls_session_resumption_capa(dev[0], hapd)
  3436. eap_connect(dev[0], apdev[0], "PEAP", "user",
  3437. anonymous_identity="peap", password="password",
  3438. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  3439. if dev[0].get_status_field("tls_session_reused") != '0':
  3440. raise Exception("Unexpected session resumption on the first connection")
  3441. dev[0].request("REAUTHENTICATE")
  3442. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3443. if ev is None:
  3444. raise Exception("EAP success timed out")
  3445. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3446. if ev is None:
  3447. raise Exception("Key handshake with the AP timed out")
  3448. if dev[0].get_status_field("tls_session_reused") != '1':
  3449. raise Exception("Session resumption not used on the second connection")
  3450. def test_eap_peap_no_session_resumption(dev, apdev):
  3451. """EAP-PEAP session resumption disabled on server"""
  3452. params = int_eap_server_params()
  3453. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3454. eap_connect(dev[0], apdev[0], "PEAP", "user",
  3455. anonymous_identity="peap", password="password",
  3456. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2")
  3457. if dev[0].get_status_field("tls_session_reused") != '0':
  3458. raise Exception("Unexpected session resumption on the first connection")
  3459. dev[0].request("REAUTHENTICATE")
  3460. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3461. if ev is None:
  3462. raise Exception("EAP success timed out")
  3463. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3464. if ev is None:
  3465. raise Exception("Key handshake with the AP timed out")
  3466. if dev[0].get_status_field("tls_session_reused") != '0':
  3467. raise Exception("Unexpected session resumption on the second connection")
  3468. def test_eap_tls_session_resumption(dev, apdev):
  3469. """EAP-TLS session resumption"""
  3470. params = int_eap_server_params()
  3471. params['tls_session_lifetime'] = '60'
  3472. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3473. check_tls_session_resumption_capa(dev[0], hapd)
  3474. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3475. client_cert="auth_serv/user.pem",
  3476. private_key="auth_serv/user.key")
  3477. if dev[0].get_status_field("tls_session_reused") != '0':
  3478. raise Exception("Unexpected session resumption on the first 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 second connection")
  3488. dev[0].request("REAUTHENTICATE")
  3489. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3490. if ev is None:
  3491. raise Exception("EAP success timed out")
  3492. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3493. if ev is None:
  3494. raise Exception("Key handshake with the AP timed out")
  3495. if dev[0].get_status_field("tls_session_reused") != '1':
  3496. raise Exception("Session resumption not used on the third connection")
  3497. def test_eap_tls_session_resumption_expiration(dev, apdev):
  3498. """EAP-TLS session resumption"""
  3499. params = int_eap_server_params()
  3500. params['tls_session_lifetime'] = '1'
  3501. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3502. check_tls_session_resumption_capa(dev[0], hapd)
  3503. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3504. client_cert="auth_serv/user.pem",
  3505. private_key="auth_serv/user.key")
  3506. if dev[0].get_status_field("tls_session_reused") != '0':
  3507. raise Exception("Unexpected session resumption on the first connection")
  3508. # Allow multiple attempts since OpenSSL may not expire the cached entry
  3509. # immediately.
  3510. for i in range(10):
  3511. time.sleep(1.2)
  3512. dev[0].request("REAUTHENTICATE")
  3513. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3514. if ev is None:
  3515. raise Exception("EAP success timed out")
  3516. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3517. if ev is None:
  3518. raise Exception("Key handshake with the AP timed out")
  3519. if dev[0].get_status_field("tls_session_reused") == '0':
  3520. break
  3521. if dev[0].get_status_field("tls_session_reused") != '0':
  3522. raise Exception("Session resumption used after lifetime expiration")
  3523. def test_eap_tls_no_session_resumption(dev, apdev):
  3524. """EAP-TLS session resumption disabled on server"""
  3525. params = int_eap_server_params()
  3526. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3527. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3528. client_cert="auth_serv/user.pem",
  3529. private_key="auth_serv/user.key")
  3530. if dev[0].get_status_field("tls_session_reused") != '0':
  3531. raise Exception("Unexpected session resumption on the first connection")
  3532. dev[0].request("REAUTHENTICATE")
  3533. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3534. if ev is None:
  3535. raise Exception("EAP success timed out")
  3536. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3537. if ev is None:
  3538. raise Exception("Key handshake with the AP timed out")
  3539. if dev[0].get_status_field("tls_session_reused") != '0':
  3540. raise Exception("Unexpected session resumption on the second connection")
  3541. def test_eap_tls_session_resumption_radius(dev, apdev):
  3542. """EAP-TLS session resumption (RADIUS)"""
  3543. params = { "ssid": "as", "beacon_int": "2000",
  3544. "radius_server_clients": "auth_serv/radius_clients.conf",
  3545. "radius_server_auth_port": '18128',
  3546. "eap_server": "1",
  3547. "eap_user_file": "auth_serv/eap_user.conf",
  3548. "ca_cert": "auth_serv/ca.pem",
  3549. "server_cert": "auth_serv/server.pem",
  3550. "private_key": "auth_serv/server.key",
  3551. "tls_session_lifetime": "60" }
  3552. authsrv = hostapd.add_ap(apdev[1]['ifname'], params)
  3553. check_tls_session_resumption_capa(dev[0], authsrv)
  3554. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3555. params['auth_server_port'] = "18128"
  3556. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3557. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3558. client_cert="auth_serv/user.pem",
  3559. private_key="auth_serv/user.key")
  3560. if dev[0].get_status_field("tls_session_reused") != '0':
  3561. raise Exception("Unexpected session resumption on the first connection")
  3562. dev[0].request("REAUTHENTICATE")
  3563. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3564. if ev is None:
  3565. raise Exception("EAP success timed out")
  3566. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3567. if ev is None:
  3568. raise Exception("Key handshake with the AP timed out")
  3569. if dev[0].get_status_field("tls_session_reused") != '1':
  3570. raise Exception("Session resumption not used on the second connection")
  3571. def test_eap_tls_no_session_resumption_radius(dev, apdev):
  3572. """EAP-TLS session resumption disabled (RADIUS)"""
  3573. params = { "ssid": "as", "beacon_int": "2000",
  3574. "radius_server_clients": "auth_serv/radius_clients.conf",
  3575. "radius_server_auth_port": '18128',
  3576. "eap_server": "1",
  3577. "eap_user_file": "auth_serv/eap_user.conf",
  3578. "ca_cert": "auth_serv/ca.pem",
  3579. "server_cert": "auth_serv/server.pem",
  3580. "private_key": "auth_serv/server.key",
  3581. "tls_session_lifetime": "0" }
  3582. hostapd.add_ap(apdev[1]['ifname'], params)
  3583. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  3584. params['auth_server_port'] = "18128"
  3585. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3586. eap_connect(dev[0], apdev[0], "TLS", "tls user", ca_cert="auth_serv/ca.pem",
  3587. client_cert="auth_serv/user.pem",
  3588. private_key="auth_serv/user.key")
  3589. if dev[0].get_status_field("tls_session_reused") != '0':
  3590. raise Exception("Unexpected session resumption on the first connection")
  3591. dev[0].request("REAUTHENTICATE")
  3592. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
  3593. if ev is None:
  3594. raise Exception("EAP success timed out")
  3595. ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=10)
  3596. if ev is None:
  3597. raise Exception("Key handshake with the AP timed out")
  3598. if dev[0].get_status_field("tls_session_reused") != '0':
  3599. raise Exception("Unexpected session resumption on the second connection")
  3600. def test_eap_mschapv2_errors(dev, apdev):
  3601. """EAP-MSCHAPv2 error cases"""
  3602. check_eap_capa(dev[0], "MSCHAPV2")
  3603. check_eap_capa(dev[0], "FAST")
  3604. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  3605. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3606. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  3607. identity="phase1-user", password="password",
  3608. scan_freq="2412")
  3609. dev[0].request("REMOVE_NETWORK all")
  3610. dev[0].wait_disconnected()
  3611. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  3612. (1, "nt_password_hash;mschapv2_derive_response"),
  3613. (1, "nt_password_hash;=mschapv2_derive_response"),
  3614. (1, "generate_nt_response;mschapv2_derive_response"),
  3615. (1, "generate_authenticator_response;mschapv2_derive_response"),
  3616. (1, "nt_password_hash;=mschapv2_derive_response"),
  3617. (1, "get_master_key;mschapv2_derive_response"),
  3618. (1, "os_get_random;eap_mschapv2_challenge_reply") ]
  3619. for count, func in tests:
  3620. with fail_test(dev[0], count, func):
  3621. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  3622. identity="phase1-user", password="password",
  3623. wait_connect=False, scan_freq="2412")
  3624. wait_fail_trigger(dev[0], "GET_FAIL")
  3625. dev[0].request("REMOVE_NETWORK all")
  3626. dev[0].wait_disconnected()
  3627. tests = [ (1, "hash_nt_password_hash;mschapv2_derive_response"),
  3628. (1, "hash_nt_password_hash;=mschapv2_derive_response"),
  3629. (1, "generate_nt_response_pwhash;mschapv2_derive_response"),
  3630. (1, "generate_authenticator_response_pwhash;mschapv2_derive_response") ]
  3631. for count, func in tests:
  3632. with fail_test(dev[0], count, func):
  3633. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  3634. identity="phase1-user",
  3635. password_hex="hash:8846f7eaee8fb117ad06bdd830b7586c",
  3636. wait_connect=False, scan_freq="2412")
  3637. wait_fail_trigger(dev[0], "GET_FAIL")
  3638. dev[0].request("REMOVE_NETWORK all")
  3639. dev[0].wait_disconnected()
  3640. tests = [ (1, "eap_mschapv2_init"),
  3641. (1, "eap_msg_alloc;eap_mschapv2_challenge_reply"),
  3642. (1, "eap_msg_alloc;eap_mschapv2_success"),
  3643. (1, "eap_mschapv2_getKey") ]
  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="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 = [ (1, "eap_msg_alloc;eap_mschapv2_failure") ]
  3653. for count, func in tests:
  3654. with alloc_fail(dev[0], count, func):
  3655. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="MSCHAPV2",
  3656. identity="phase1-user", password="wrong password",
  3657. wait_connect=False, scan_freq="2412")
  3658. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  3659. dev[0].request("REMOVE_NETWORK all")
  3660. dev[0].wait_disconnected()
  3661. tests = [ (2, "eap_mschapv2_init"),
  3662. (3, "eap_mschapv2_init") ]
  3663. for count, func in tests:
  3664. with alloc_fail(dev[0], count, func):
  3665. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="FAST",
  3666. anonymous_identity="FAST", identity="user",
  3667. password="password",
  3668. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  3669. phase1="fast_provisioning=1",
  3670. pac_file="blob://fast_pac",
  3671. wait_connect=False, scan_freq="2412")
  3672. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  3673. dev[0].request("REMOVE_NETWORK all")
  3674. dev[0].wait_disconnected()
  3675. def test_eap_gpsk_errors(dev, apdev):
  3676. """EAP-GPSK error cases"""
  3677. params = hostapd.wpa2_eap_params(ssid="test-wpa-eap")
  3678. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  3679. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  3680. identity="gpsk user",
  3681. password="abcdefghijklmnop0123456789abcdef",
  3682. scan_freq="2412")
  3683. dev[0].request("REMOVE_NETWORK all")
  3684. dev[0].wait_disconnected()
  3685. tests = [ (1, "os_get_random;eap_gpsk_send_gpsk_2", None),
  3686. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  3687. "cipher=1"),
  3688. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2",
  3689. "cipher=2"),
  3690. (1, "eap_gpsk_derive_keys_helper", None),
  3691. (2, "eap_gpsk_derive_keys_helper", None),
  3692. (1, "eap_gpsk_compute_mic_aes;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  3693. "cipher=1"),
  3694. (1, "hmac_sha256;eap_gpsk_compute_mic;eap_gpsk_send_gpsk_2",
  3695. "cipher=2"),
  3696. (1, "eap_gpsk_compute_mic;eap_gpsk_validate_gpsk_3_mic", None),
  3697. (1, "eap_gpsk_compute_mic;eap_gpsk_send_gpsk_4", None),
  3698. (1, "eap_gpsk_derive_mid_helper", None) ]
  3699. for count, func, phase1 in tests:
  3700. with fail_test(dev[0], count, func):
  3701. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  3702. identity="gpsk user",
  3703. password="abcdefghijklmnop0123456789abcdef",
  3704. phase1=phase1,
  3705. wait_connect=False, scan_freq="2412")
  3706. wait_fail_trigger(dev[0], "GET_FAIL")
  3707. dev[0].request("REMOVE_NETWORK all")
  3708. dev[0].wait_disconnected()
  3709. tests = [ (1, "eap_gpsk_init"),
  3710. (2, "eap_gpsk_init"),
  3711. (3, "eap_gpsk_init"),
  3712. (1, "eap_gpsk_process_id_server"),
  3713. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_2"),
  3714. (1, "eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  3715. (1, "eap_gpsk_derive_mid_helper;eap_gpsk_derive_session_id;eap_gpsk_send_gpsk_2"),
  3716. (1, "eap_gpsk_derive_keys"),
  3717. (1, "eap_gpsk_derive_keys_helper"),
  3718. (1, "eap_msg_alloc;eap_gpsk_send_gpsk_4"),
  3719. (1, "eap_gpsk_getKey"),
  3720. (1, "eap_gpsk_get_emsk"),
  3721. (1, "eap_gpsk_get_session_id") ]
  3722. for count, func in tests:
  3723. with alloc_fail(dev[0], count, func):
  3724. dev[0].request("ERP_FLUSH")
  3725. dev[0].connect("test-wpa-eap", key_mgmt="WPA-EAP", eap="GPSK",
  3726. identity="gpsk user", erp="1",
  3727. password="abcdefghijklmnop0123456789abcdef",
  3728. wait_connect=False, scan_freq="2412")
  3729. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  3730. dev[0].request("REMOVE_NETWORK all")
  3731. dev[0].wait_disconnected()
  3732. def test_ap_wpa2_eap_sim_db(dev, apdev, params):
  3733. """EAP-SIM DB error cases"""
  3734. sockpath = '/tmp/hlr_auc_gw.sock-test'
  3735. try:
  3736. os.remove(sockpath)
  3737. except:
  3738. pass
  3739. hparams = int_eap_server_params()
  3740. hparams['eap_sim_db'] = 'unix:' + sockpath
  3741. hapd = hostapd.add_ap(apdev[0]['ifname'], hparams)
  3742. # Initial test with hlr_auc_gw socket not available
  3743. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
  3744. eap="SIM", identity="1232010000000000",
  3745. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581",
  3746. scan_freq="2412", wait_connect=False)
  3747. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3748. if ev is None:
  3749. raise Exception("EAP-Failure not reported")
  3750. dev[0].wait_disconnected()
  3751. dev[0].request("DISCONNECT")
  3752. # Test with invalid responses and response timeout
  3753. class test_handler(SocketServer.DatagramRequestHandler):
  3754. def handle(self):
  3755. data = self.request[0].strip()
  3756. socket = self.request[1]
  3757. logger.debug("Received hlr_auc_gw request: " + data)
  3758. # EAP-SIM DB: Failed to parse response string
  3759. socket.sendto("FOO", self.client_address)
  3760. # EAP-SIM DB: Failed to parse response string
  3761. socket.sendto("FOO 1", self.client_address)
  3762. # EAP-SIM DB: Unknown external response
  3763. socket.sendto("FOO 1 2", self.client_address)
  3764. logger.info("No proper response - wait for pending eap_sim_db request timeout")
  3765. server = SocketServer.UnixDatagramServer(sockpath, test_handler)
  3766. server.timeout = 1
  3767. dev[0].select_network(id)
  3768. server.handle_request()
  3769. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  3770. if ev is None:
  3771. raise Exception("EAP-Failure not reported")
  3772. dev[0].wait_disconnected()
  3773. dev[0].request("DISCONNECT")
  3774. # Test with a valid response
  3775. class test_handler2(SocketServer.DatagramRequestHandler):
  3776. def handle(self):
  3777. data = self.request[0].strip()
  3778. socket = self.request[1]
  3779. logger.debug("Received hlr_auc_gw request: " + data)
  3780. fname = os.path.join(params['logdir'],
  3781. 'hlr_auc_gw.milenage_db')
  3782. cmd = subprocess.Popen(['../../hostapd/hlr_auc_gw',
  3783. '-m', fname, data],
  3784. stdout=subprocess.PIPE)
  3785. res = cmd.stdout.read().strip()
  3786. cmd.stdout.close()
  3787. logger.debug("hlr_auc_gw response: " + res)
  3788. socket.sendto(res, self.client_address)
  3789. server.RequestHandlerClass = test_handler2
  3790. dev[0].select_network(id)
  3791. server.handle_request()
  3792. dev[0].wait_connected()
  3793. dev[0].request("DISCONNECT")
  3794. dev[0].wait_disconnected()