test_ap_eap.py 244 KB

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