test_ap_eap.py 207 KB

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