test_ap_eap.py 240 KB

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