test_ap_eap.py 232 KB

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