test_ap_eap.py 229 KB

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