test_ap_eap.py 232 KB

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