test_ap_eap.py 207 KB

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