wpa_auth.c 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157
  1. /*
  2. * IEEE 802.11 RSN / WPA Authenticator
  3. * Copyright (c) 2004-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. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "utils/state_machine.h"
  12. #include "utils/bitfield.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "crypto/aes.h"
  15. #include "crypto/aes_wrap.h"
  16. #include "crypto/aes_siv.h"
  17. #include "crypto/crypto.h"
  18. #include "crypto/sha1.h"
  19. #include "crypto/sha256.h"
  20. #include "crypto/random.h"
  21. #include "eapol_auth/eapol_auth_sm.h"
  22. #include "ap_config.h"
  23. #include "ieee802_11.h"
  24. #include "wpa_auth.h"
  25. #include "pmksa_cache_auth.h"
  26. #include "wpa_auth_i.h"
  27. #include "wpa_auth_ie.h"
  28. #define STATE_MACHINE_DATA struct wpa_state_machine
  29. #define STATE_MACHINE_DEBUG_PREFIX "WPA"
  30. #define STATE_MACHINE_ADDR sm->addr
  31. static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx);
  32. static int wpa_sm_step(struct wpa_state_machine *sm);
  33. static int wpa_verify_key_mic(int akmp, struct wpa_ptk *PTK, u8 *data,
  34. size_t data_len);
  35. #ifdef CONFIG_FILS
  36. static int wpa_aead_decrypt(struct wpa_state_machine *sm, struct wpa_ptk *ptk,
  37. u8 *buf, size_t buf_len, u16 *_key_data_len);
  38. #endif /* CONFIG_FILS */
  39. static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx);
  40. static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
  41. struct wpa_group *group);
  42. static void wpa_request_new_ptk(struct wpa_state_machine *sm);
  43. static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
  44. struct wpa_group *group);
  45. static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
  46. struct wpa_group *group);
  47. static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
  48. const u8 *pmk, unsigned int pmk_len,
  49. struct wpa_ptk *ptk);
  50. static void wpa_group_free(struct wpa_authenticator *wpa_auth,
  51. struct wpa_group *group);
  52. static void wpa_group_get(struct wpa_authenticator *wpa_auth,
  53. struct wpa_group *group);
  54. static void wpa_group_put(struct wpa_authenticator *wpa_auth,
  55. struct wpa_group *group);
  56. static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos);
  57. static const u32 dot11RSNAConfigGroupUpdateCount = 4;
  58. static const u32 dot11RSNAConfigPairwiseUpdateCount = 4;
  59. static const u32 eapol_key_timeout_first = 100; /* ms */
  60. static const u32 eapol_key_timeout_subseq = 1000; /* ms */
  61. static const u32 eapol_key_timeout_first_group = 500; /* ms */
  62. /* TODO: make these configurable */
  63. static const int dot11RSNAConfigPMKLifetime = 43200;
  64. static const int dot11RSNAConfigPMKReauthThreshold = 70;
  65. static const int dot11RSNAConfigSATimeout = 60;
  66. static inline int wpa_auth_mic_failure_report(
  67. struct wpa_authenticator *wpa_auth, const u8 *addr)
  68. {
  69. if (wpa_auth->cb.mic_failure_report)
  70. return wpa_auth->cb.mic_failure_report(wpa_auth->cb.ctx, addr);
  71. return 0;
  72. }
  73. static inline void wpa_auth_psk_failure_report(
  74. struct wpa_authenticator *wpa_auth, const u8 *addr)
  75. {
  76. if (wpa_auth->cb.psk_failure_report)
  77. wpa_auth->cb.psk_failure_report(wpa_auth->cb.ctx, addr);
  78. }
  79. static inline void wpa_auth_set_eapol(struct wpa_authenticator *wpa_auth,
  80. const u8 *addr, wpa_eapol_variable var,
  81. int value)
  82. {
  83. if (wpa_auth->cb.set_eapol)
  84. wpa_auth->cb.set_eapol(wpa_auth->cb.ctx, addr, var, value);
  85. }
  86. static inline int wpa_auth_get_eapol(struct wpa_authenticator *wpa_auth,
  87. const u8 *addr, wpa_eapol_variable var)
  88. {
  89. if (wpa_auth->cb.get_eapol == NULL)
  90. return -1;
  91. return wpa_auth->cb.get_eapol(wpa_auth->cb.ctx, addr, var);
  92. }
  93. static inline const u8 * wpa_auth_get_psk(struct wpa_authenticator *wpa_auth,
  94. const u8 *addr,
  95. const u8 *p2p_dev_addr,
  96. const u8 *prev_psk)
  97. {
  98. if (wpa_auth->cb.get_psk == NULL)
  99. return NULL;
  100. return wpa_auth->cb.get_psk(wpa_auth->cb.ctx, addr, p2p_dev_addr,
  101. prev_psk);
  102. }
  103. static inline int wpa_auth_get_msk(struct wpa_authenticator *wpa_auth,
  104. const u8 *addr, u8 *msk, size_t *len)
  105. {
  106. if (wpa_auth->cb.get_msk == NULL)
  107. return -1;
  108. return wpa_auth->cb.get_msk(wpa_auth->cb.ctx, addr, msk, len);
  109. }
  110. static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
  111. int vlan_id,
  112. enum wpa_alg alg, const u8 *addr, int idx,
  113. u8 *key, size_t key_len)
  114. {
  115. if (wpa_auth->cb.set_key == NULL)
  116. return -1;
  117. return wpa_auth->cb.set_key(wpa_auth->cb.ctx, vlan_id, alg, addr, idx,
  118. key, key_len);
  119. }
  120. static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
  121. const u8 *addr, int idx, u8 *seq)
  122. {
  123. if (wpa_auth->cb.get_seqnum == NULL)
  124. return -1;
  125. return wpa_auth->cb.get_seqnum(wpa_auth->cb.ctx, addr, idx, seq);
  126. }
  127. static inline int
  128. wpa_auth_send_eapol(struct wpa_authenticator *wpa_auth, const u8 *addr,
  129. const u8 *data, size_t data_len, int encrypt)
  130. {
  131. if (wpa_auth->cb.send_eapol == NULL)
  132. return -1;
  133. return wpa_auth->cb.send_eapol(wpa_auth->cb.ctx, addr, data, data_len,
  134. encrypt);
  135. }
  136. #ifdef CONFIG_MESH
  137. static inline int wpa_auth_start_ampe(struct wpa_authenticator *wpa_auth,
  138. const u8 *addr)
  139. {
  140. if (wpa_auth->cb.start_ampe == NULL)
  141. return -1;
  142. return wpa_auth->cb.start_ampe(wpa_auth->cb.ctx, addr);
  143. }
  144. #endif /* CONFIG_MESH */
  145. int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
  146. int (*cb)(struct wpa_state_machine *sm, void *ctx),
  147. void *cb_ctx)
  148. {
  149. if (wpa_auth->cb.for_each_sta == NULL)
  150. return 0;
  151. return wpa_auth->cb.for_each_sta(wpa_auth->cb.ctx, cb, cb_ctx);
  152. }
  153. int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
  154. int (*cb)(struct wpa_authenticator *a, void *ctx),
  155. void *cb_ctx)
  156. {
  157. if (wpa_auth->cb.for_each_auth == NULL)
  158. return 0;
  159. return wpa_auth->cb.for_each_auth(wpa_auth->cb.ctx, cb, cb_ctx);
  160. }
  161. void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
  162. logger_level level, const char *txt)
  163. {
  164. if (wpa_auth->cb.logger == NULL)
  165. return;
  166. wpa_auth->cb.logger(wpa_auth->cb.ctx, addr, level, txt);
  167. }
  168. void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
  169. logger_level level, const char *fmt, ...)
  170. {
  171. char *format;
  172. int maxlen;
  173. va_list ap;
  174. if (wpa_auth->cb.logger == NULL)
  175. return;
  176. maxlen = os_strlen(fmt) + 100;
  177. format = os_malloc(maxlen);
  178. if (!format)
  179. return;
  180. va_start(ap, fmt);
  181. vsnprintf(format, maxlen, fmt, ap);
  182. va_end(ap);
  183. wpa_auth_logger(wpa_auth, addr, level, format);
  184. os_free(format);
  185. }
  186. static void wpa_sta_disconnect(struct wpa_authenticator *wpa_auth,
  187. const u8 *addr)
  188. {
  189. if (wpa_auth->cb.disconnect == NULL)
  190. return;
  191. wpa_printf(MSG_DEBUG, "wpa_sta_disconnect STA " MACSTR, MAC2STR(addr));
  192. wpa_auth->cb.disconnect(wpa_auth->cb.ctx, addr,
  193. WLAN_REASON_PREV_AUTH_NOT_VALID);
  194. }
  195. static int wpa_use_aes_cmac(struct wpa_state_machine *sm)
  196. {
  197. int ret = 0;
  198. #ifdef CONFIG_IEEE80211R
  199. if (wpa_key_mgmt_ft(sm->wpa_key_mgmt))
  200. ret = 1;
  201. #endif /* CONFIG_IEEE80211R */
  202. #ifdef CONFIG_IEEE80211W
  203. if (wpa_key_mgmt_sha256(sm->wpa_key_mgmt))
  204. ret = 1;
  205. #endif /* CONFIG_IEEE80211W */
  206. if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN)
  207. ret = 1;
  208. return ret;
  209. }
  210. static void wpa_rekey_gmk(void *eloop_ctx, void *timeout_ctx)
  211. {
  212. struct wpa_authenticator *wpa_auth = eloop_ctx;
  213. if (random_get_bytes(wpa_auth->group->GMK, WPA_GMK_LEN)) {
  214. wpa_printf(MSG_ERROR, "Failed to get random data for WPA "
  215. "initialization.");
  216. } else {
  217. wpa_auth_logger(wpa_auth, NULL, LOGGER_DEBUG, "GMK rekeyd");
  218. wpa_hexdump_key(MSG_DEBUG, "GMK",
  219. wpa_auth->group->GMK, WPA_GMK_LEN);
  220. }
  221. if (wpa_auth->conf.wpa_gmk_rekey) {
  222. eloop_register_timeout(wpa_auth->conf.wpa_gmk_rekey, 0,
  223. wpa_rekey_gmk, wpa_auth, NULL);
  224. }
  225. }
  226. static void wpa_rekey_gtk(void *eloop_ctx, void *timeout_ctx)
  227. {
  228. struct wpa_authenticator *wpa_auth = eloop_ctx;
  229. struct wpa_group *group, *next;
  230. wpa_auth_logger(wpa_auth, NULL, LOGGER_DEBUG, "rekeying GTK");
  231. group = wpa_auth->group;
  232. while (group) {
  233. wpa_group_get(wpa_auth, group);
  234. group->GTKReKey = TRUE;
  235. do {
  236. group->changed = FALSE;
  237. wpa_group_sm_step(wpa_auth, group);
  238. } while (group->changed);
  239. next = group->next;
  240. wpa_group_put(wpa_auth, group);
  241. group = next;
  242. }
  243. if (wpa_auth->conf.wpa_group_rekey) {
  244. eloop_register_timeout(wpa_auth->conf.wpa_group_rekey,
  245. 0, wpa_rekey_gtk, wpa_auth, NULL);
  246. }
  247. }
  248. static void wpa_rekey_ptk(void *eloop_ctx, void *timeout_ctx)
  249. {
  250. struct wpa_authenticator *wpa_auth = eloop_ctx;
  251. struct wpa_state_machine *sm = timeout_ctx;
  252. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "rekeying PTK");
  253. wpa_request_new_ptk(sm);
  254. wpa_sm_step(sm);
  255. }
  256. static int wpa_auth_pmksa_clear_cb(struct wpa_state_machine *sm, void *ctx)
  257. {
  258. if (sm->pmksa == ctx)
  259. sm->pmksa = NULL;
  260. return 0;
  261. }
  262. static void wpa_auth_pmksa_free_cb(struct rsn_pmksa_cache_entry *entry,
  263. void *ctx)
  264. {
  265. struct wpa_authenticator *wpa_auth = ctx;
  266. wpa_auth_for_each_sta(wpa_auth, wpa_auth_pmksa_clear_cb, entry);
  267. }
  268. static int wpa_group_init_gmk_and_counter(struct wpa_authenticator *wpa_auth,
  269. struct wpa_group *group)
  270. {
  271. u8 buf[ETH_ALEN + 8 + sizeof(unsigned long)];
  272. u8 rkey[32];
  273. unsigned long ptr;
  274. if (random_get_bytes(group->GMK, WPA_GMK_LEN) < 0)
  275. return -1;
  276. wpa_hexdump_key(MSG_DEBUG, "GMK", group->GMK, WPA_GMK_LEN);
  277. /*
  278. * Counter = PRF-256(Random number, "Init Counter",
  279. * Local MAC Address || Time)
  280. */
  281. os_memcpy(buf, wpa_auth->addr, ETH_ALEN);
  282. wpa_get_ntp_timestamp(buf + ETH_ALEN);
  283. ptr = (unsigned long) group;
  284. os_memcpy(buf + ETH_ALEN + 8, &ptr, sizeof(ptr));
  285. if (random_get_bytes(rkey, sizeof(rkey)) < 0)
  286. return -1;
  287. if (sha1_prf(rkey, sizeof(rkey), "Init Counter", buf, sizeof(buf),
  288. group->Counter, WPA_NONCE_LEN) < 0)
  289. return -1;
  290. wpa_hexdump_key(MSG_DEBUG, "Key Counter",
  291. group->Counter, WPA_NONCE_LEN);
  292. return 0;
  293. }
  294. static struct wpa_group * wpa_group_init(struct wpa_authenticator *wpa_auth,
  295. int vlan_id, int delay_init)
  296. {
  297. struct wpa_group *group;
  298. group = os_zalloc(sizeof(struct wpa_group));
  299. if (group == NULL)
  300. return NULL;
  301. group->GTKAuthenticator = TRUE;
  302. group->vlan_id = vlan_id;
  303. group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
  304. if (random_pool_ready() != 1) {
  305. wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
  306. "for secure operations - update keys later when "
  307. "the first station connects");
  308. }
  309. /*
  310. * Set initial GMK/Counter value here. The actual values that will be
  311. * used in negotiations will be set once the first station tries to
  312. * connect. This allows more time for collecting additional randomness
  313. * on embedded devices.
  314. */
  315. if (wpa_group_init_gmk_and_counter(wpa_auth, group) < 0) {
  316. wpa_printf(MSG_ERROR, "Failed to get random data for WPA "
  317. "initialization.");
  318. os_free(group);
  319. return NULL;
  320. }
  321. group->GInit = TRUE;
  322. if (delay_init) {
  323. wpa_printf(MSG_DEBUG, "WPA: Delay group state machine start "
  324. "until Beacon frames have been configured");
  325. /* Initialization is completed in wpa_init_keys(). */
  326. } else {
  327. wpa_group_sm_step(wpa_auth, group);
  328. group->GInit = FALSE;
  329. wpa_group_sm_step(wpa_auth, group);
  330. }
  331. return group;
  332. }
  333. /**
  334. * wpa_init - Initialize WPA authenticator
  335. * @addr: Authenticator address
  336. * @conf: Configuration for WPA authenticator
  337. * @cb: Callback functions for WPA authenticator
  338. * Returns: Pointer to WPA authenticator data or %NULL on failure
  339. */
  340. struct wpa_authenticator * wpa_init(const u8 *addr,
  341. struct wpa_auth_config *conf,
  342. struct wpa_auth_callbacks *cb)
  343. {
  344. struct wpa_authenticator *wpa_auth;
  345. wpa_auth = os_zalloc(sizeof(struct wpa_authenticator));
  346. if (wpa_auth == NULL)
  347. return NULL;
  348. os_memcpy(wpa_auth->addr, addr, ETH_ALEN);
  349. os_memcpy(&wpa_auth->conf, conf, sizeof(*conf));
  350. os_memcpy(&wpa_auth->cb, cb, sizeof(*cb));
  351. if (wpa_auth_gen_wpa_ie(wpa_auth)) {
  352. wpa_printf(MSG_ERROR, "Could not generate WPA IE.");
  353. os_free(wpa_auth);
  354. return NULL;
  355. }
  356. wpa_auth->group = wpa_group_init(wpa_auth, 0, 1);
  357. if (wpa_auth->group == NULL) {
  358. os_free(wpa_auth->wpa_ie);
  359. os_free(wpa_auth);
  360. return NULL;
  361. }
  362. wpa_auth->pmksa = pmksa_cache_auth_init(wpa_auth_pmksa_free_cb,
  363. wpa_auth);
  364. if (wpa_auth->pmksa == NULL) {
  365. wpa_printf(MSG_ERROR, "PMKSA cache initialization failed.");
  366. os_free(wpa_auth->group);
  367. os_free(wpa_auth->wpa_ie);
  368. os_free(wpa_auth);
  369. return NULL;
  370. }
  371. #ifdef CONFIG_IEEE80211R
  372. wpa_auth->ft_pmk_cache = wpa_ft_pmk_cache_init();
  373. if (wpa_auth->ft_pmk_cache == NULL) {
  374. wpa_printf(MSG_ERROR, "FT PMK cache initialization failed.");
  375. os_free(wpa_auth->group);
  376. os_free(wpa_auth->wpa_ie);
  377. pmksa_cache_auth_deinit(wpa_auth->pmksa);
  378. os_free(wpa_auth);
  379. return NULL;
  380. }
  381. #endif /* CONFIG_IEEE80211R */
  382. if (wpa_auth->conf.wpa_gmk_rekey) {
  383. eloop_register_timeout(wpa_auth->conf.wpa_gmk_rekey, 0,
  384. wpa_rekey_gmk, wpa_auth, NULL);
  385. }
  386. if (wpa_auth->conf.wpa_group_rekey) {
  387. eloop_register_timeout(wpa_auth->conf.wpa_group_rekey, 0,
  388. wpa_rekey_gtk, wpa_auth, NULL);
  389. }
  390. #ifdef CONFIG_P2P
  391. if (WPA_GET_BE32(conf->ip_addr_start)) {
  392. int count = WPA_GET_BE32(conf->ip_addr_end) -
  393. WPA_GET_BE32(conf->ip_addr_start) + 1;
  394. if (count > 1000)
  395. count = 1000;
  396. if (count > 0)
  397. wpa_auth->ip_pool = bitfield_alloc(count);
  398. }
  399. #endif /* CONFIG_P2P */
  400. return wpa_auth;
  401. }
  402. int wpa_init_keys(struct wpa_authenticator *wpa_auth)
  403. {
  404. struct wpa_group *group = wpa_auth->group;
  405. wpa_printf(MSG_DEBUG, "WPA: Start group state machine to set initial "
  406. "keys");
  407. wpa_group_sm_step(wpa_auth, group);
  408. group->GInit = FALSE;
  409. wpa_group_sm_step(wpa_auth, group);
  410. if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
  411. return -1;
  412. return 0;
  413. }
  414. /**
  415. * wpa_deinit - Deinitialize WPA authenticator
  416. * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
  417. */
  418. void wpa_deinit(struct wpa_authenticator *wpa_auth)
  419. {
  420. struct wpa_group *group, *prev;
  421. eloop_cancel_timeout(wpa_rekey_gmk, wpa_auth, NULL);
  422. eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
  423. #ifdef CONFIG_PEERKEY
  424. while (wpa_auth->stsl_negotiations)
  425. wpa_stsl_remove(wpa_auth, wpa_auth->stsl_negotiations);
  426. #endif /* CONFIG_PEERKEY */
  427. pmksa_cache_auth_deinit(wpa_auth->pmksa);
  428. #ifdef CONFIG_IEEE80211R
  429. wpa_ft_pmk_cache_deinit(wpa_auth->ft_pmk_cache);
  430. wpa_auth->ft_pmk_cache = NULL;
  431. #endif /* CONFIG_IEEE80211R */
  432. #ifdef CONFIG_P2P
  433. bitfield_free(wpa_auth->ip_pool);
  434. #endif /* CONFIG_P2P */
  435. os_free(wpa_auth->wpa_ie);
  436. group = wpa_auth->group;
  437. while (group) {
  438. prev = group;
  439. group = group->next;
  440. os_free(prev);
  441. }
  442. os_free(wpa_auth);
  443. }
  444. /**
  445. * wpa_reconfig - Update WPA authenticator configuration
  446. * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
  447. * @conf: Configuration for WPA authenticator
  448. */
  449. int wpa_reconfig(struct wpa_authenticator *wpa_auth,
  450. struct wpa_auth_config *conf)
  451. {
  452. struct wpa_group *group;
  453. if (wpa_auth == NULL)
  454. return 0;
  455. os_memcpy(&wpa_auth->conf, conf, sizeof(*conf));
  456. if (wpa_auth_gen_wpa_ie(wpa_auth)) {
  457. wpa_printf(MSG_ERROR, "Could not generate WPA IE.");
  458. return -1;
  459. }
  460. /*
  461. * Reinitialize GTK to make sure it is suitable for the new
  462. * configuration.
  463. */
  464. group = wpa_auth->group;
  465. group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
  466. group->GInit = TRUE;
  467. wpa_group_sm_step(wpa_auth, group);
  468. group->GInit = FALSE;
  469. wpa_group_sm_step(wpa_auth, group);
  470. return 0;
  471. }
  472. struct wpa_state_machine *
  473. wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
  474. const u8 *p2p_dev_addr)
  475. {
  476. struct wpa_state_machine *sm;
  477. if (wpa_auth->group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
  478. return NULL;
  479. sm = os_zalloc(sizeof(struct wpa_state_machine));
  480. if (sm == NULL)
  481. return NULL;
  482. os_memcpy(sm->addr, addr, ETH_ALEN);
  483. if (p2p_dev_addr)
  484. os_memcpy(sm->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
  485. sm->wpa_auth = wpa_auth;
  486. sm->group = wpa_auth->group;
  487. wpa_group_get(sm->wpa_auth, sm->group);
  488. return sm;
  489. }
  490. int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
  491. struct wpa_state_machine *sm)
  492. {
  493. if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
  494. return -1;
  495. #ifdef CONFIG_IEEE80211R
  496. if (sm->ft_completed) {
  497. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
  498. "FT authentication already completed - do not "
  499. "start 4-way handshake");
  500. /* Go to PTKINITDONE state to allow GTK rekeying */
  501. sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
  502. return 0;
  503. }
  504. #endif /* CONFIG_IEEE80211R */
  505. #ifdef CONFIG_FILS
  506. if (sm->fils_completed) {
  507. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
  508. "FILS authentication already completed - do not start 4-way handshake");
  509. /* Go to PTKINITDONE state to allow GTK rekeying */
  510. sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
  511. return 0;
  512. }
  513. #endif /* CONFIG_FILS */
  514. if (sm->started) {
  515. os_memset(&sm->key_replay, 0, sizeof(sm->key_replay));
  516. sm->ReAuthenticationRequest = TRUE;
  517. return wpa_sm_step(sm);
  518. }
  519. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
  520. "start authentication");
  521. sm->started = 1;
  522. sm->Init = TRUE;
  523. if (wpa_sm_step(sm) == 1)
  524. return 1; /* should not really happen */
  525. sm->Init = FALSE;
  526. sm->AuthenticationRequest = TRUE;
  527. return wpa_sm_step(sm);
  528. }
  529. void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm)
  530. {
  531. /* WPA/RSN was not used - clear WPA state. This is needed if the STA
  532. * reassociates back to the same AP while the previous entry for the
  533. * STA has not yet been removed. */
  534. if (sm == NULL)
  535. return;
  536. sm->wpa_key_mgmt = 0;
  537. }
  538. static void wpa_free_sta_sm(struct wpa_state_machine *sm)
  539. {
  540. #ifdef CONFIG_P2P
  541. if (WPA_GET_BE32(sm->ip_addr)) {
  542. u32 start;
  543. wpa_printf(MSG_DEBUG, "P2P: Free assigned IP "
  544. "address %u.%u.%u.%u from " MACSTR,
  545. sm->ip_addr[0], sm->ip_addr[1],
  546. sm->ip_addr[2], sm->ip_addr[3],
  547. MAC2STR(sm->addr));
  548. start = WPA_GET_BE32(sm->wpa_auth->conf.ip_addr_start);
  549. bitfield_clear(sm->wpa_auth->ip_pool,
  550. WPA_GET_BE32(sm->ip_addr) - start);
  551. }
  552. #endif /* CONFIG_P2P */
  553. if (sm->GUpdateStationKeys) {
  554. sm->group->GKeyDoneStations--;
  555. sm->GUpdateStationKeys = FALSE;
  556. }
  557. #ifdef CONFIG_IEEE80211R
  558. os_free(sm->assoc_resp_ftie);
  559. wpabuf_free(sm->ft_pending_req_ies);
  560. #endif /* CONFIG_IEEE80211R */
  561. os_free(sm->last_rx_eapol_key);
  562. os_free(sm->wpa_ie);
  563. wpa_group_put(sm->wpa_auth, sm->group);
  564. os_free(sm);
  565. }
  566. void wpa_auth_sta_deinit(struct wpa_state_machine *sm)
  567. {
  568. if (sm == NULL)
  569. return;
  570. if (sm->wpa_auth->conf.wpa_strict_rekey && sm->has_GTK) {
  571. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  572. "strict rekeying - force GTK rekey since STA "
  573. "is leaving");
  574. eloop_cancel_timeout(wpa_rekey_gtk, sm->wpa_auth, NULL);
  575. eloop_register_timeout(0, 500000, wpa_rekey_gtk, sm->wpa_auth,
  576. NULL);
  577. }
  578. eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
  579. sm->pending_1_of_4_timeout = 0;
  580. eloop_cancel_timeout(wpa_sm_call_step, sm, NULL);
  581. eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
  582. if (sm->in_step_loop) {
  583. /* Must not free state machine while wpa_sm_step() is running.
  584. * Freeing will be completed in the end of wpa_sm_step(). */
  585. wpa_printf(MSG_DEBUG, "WPA: Registering pending STA state "
  586. "machine deinit for " MACSTR, MAC2STR(sm->addr));
  587. sm->pending_deinit = 1;
  588. } else
  589. wpa_free_sta_sm(sm);
  590. }
  591. static void wpa_request_new_ptk(struct wpa_state_machine *sm)
  592. {
  593. if (sm == NULL)
  594. return;
  595. sm->PTKRequest = TRUE;
  596. sm->PTK_valid = 0;
  597. }
  598. static int wpa_replay_counter_valid(struct wpa_key_replay_counter *ctr,
  599. const u8 *replay_counter)
  600. {
  601. int i;
  602. for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
  603. if (!ctr[i].valid)
  604. break;
  605. if (os_memcmp(replay_counter, ctr[i].counter,
  606. WPA_REPLAY_COUNTER_LEN) == 0)
  607. return 1;
  608. }
  609. return 0;
  610. }
  611. static void wpa_replay_counter_mark_invalid(struct wpa_key_replay_counter *ctr,
  612. const u8 *replay_counter)
  613. {
  614. int i;
  615. for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
  616. if (ctr[i].valid &&
  617. (replay_counter == NULL ||
  618. os_memcmp(replay_counter, ctr[i].counter,
  619. WPA_REPLAY_COUNTER_LEN) == 0))
  620. ctr[i].valid = FALSE;
  621. }
  622. }
  623. #ifdef CONFIG_IEEE80211R
  624. static int ft_check_msg_2_of_4(struct wpa_authenticator *wpa_auth,
  625. struct wpa_state_machine *sm,
  626. struct wpa_eapol_ie_parse *kde)
  627. {
  628. struct wpa_ie_data ie;
  629. struct rsn_mdie *mdie;
  630. if (wpa_parse_wpa_ie_rsn(kde->rsn_ie, kde->rsn_ie_len, &ie) < 0 ||
  631. ie.num_pmkid != 1 || ie.pmkid == NULL) {
  632. wpa_printf(MSG_DEBUG, "FT: No PMKR1Name in "
  633. "FT 4-way handshake message 2/4");
  634. return -1;
  635. }
  636. os_memcpy(sm->sup_pmk_r1_name, ie.pmkid, PMKID_LEN);
  637. wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from Supplicant",
  638. sm->sup_pmk_r1_name, PMKID_LEN);
  639. if (!kde->mdie || !kde->ftie) {
  640. wpa_printf(MSG_DEBUG, "FT: No %s in FT 4-way handshake "
  641. "message 2/4", kde->mdie ? "FTIE" : "MDIE");
  642. return -1;
  643. }
  644. mdie = (struct rsn_mdie *) (kde->mdie + 2);
  645. if (kde->mdie[1] < sizeof(struct rsn_mdie) ||
  646. os_memcmp(wpa_auth->conf.mobility_domain, mdie->mobility_domain,
  647. MOBILITY_DOMAIN_ID_LEN) != 0) {
  648. wpa_printf(MSG_DEBUG, "FT: MDIE mismatch");
  649. return -1;
  650. }
  651. if (sm->assoc_resp_ftie &&
  652. (kde->ftie[1] != sm->assoc_resp_ftie[1] ||
  653. os_memcmp(kde->ftie, sm->assoc_resp_ftie,
  654. 2 + sm->assoc_resp_ftie[1]) != 0)) {
  655. wpa_printf(MSG_DEBUG, "FT: FTIE mismatch");
  656. wpa_hexdump(MSG_DEBUG, "FT: FTIE in EAPOL-Key msg 2/4",
  657. kde->ftie, kde->ftie_len);
  658. wpa_hexdump(MSG_DEBUG, "FT: FTIE in (Re)AssocResp",
  659. sm->assoc_resp_ftie, 2 + sm->assoc_resp_ftie[1]);
  660. return -1;
  661. }
  662. return 0;
  663. }
  664. #endif /* CONFIG_IEEE80211R */
  665. static int wpa_receive_error_report(struct wpa_authenticator *wpa_auth,
  666. struct wpa_state_machine *sm, int group)
  667. {
  668. /* Supplicant reported a Michael MIC error */
  669. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
  670. "received EAPOL-Key Error Request "
  671. "(STA detected Michael MIC failure (group=%d))",
  672. group);
  673. if (group && wpa_auth->conf.wpa_group != WPA_CIPHER_TKIP) {
  674. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  675. "ignore Michael MIC failure report since "
  676. "group cipher is not TKIP");
  677. } else if (!group && sm->pairwise != WPA_CIPHER_TKIP) {
  678. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  679. "ignore Michael MIC failure report since "
  680. "pairwise cipher is not TKIP");
  681. } else {
  682. if (wpa_auth_mic_failure_report(wpa_auth, sm->addr) > 0)
  683. return 1; /* STA entry was removed */
  684. sm->dot11RSNAStatsTKIPRemoteMICFailures++;
  685. wpa_auth->dot11RSNAStatsTKIPRemoteMICFailures++;
  686. }
  687. /*
  688. * Error report is not a request for a new key handshake, but since
  689. * Authenticator may do it, let's change the keys now anyway.
  690. */
  691. wpa_request_new_ptk(sm);
  692. return 0;
  693. }
  694. static int wpa_try_alt_snonce(struct wpa_state_machine *sm, u8 *data,
  695. size_t data_len)
  696. {
  697. struct wpa_ptk PTK;
  698. int ok = 0;
  699. const u8 *pmk = NULL;
  700. unsigned int pmk_len;
  701. os_memset(&PTK, 0, sizeof(PTK));
  702. for (;;) {
  703. if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
  704. pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
  705. sm->p2p_dev_addr, pmk);
  706. if (pmk == NULL)
  707. break;
  708. pmk_len = PMK_LEN;
  709. } else {
  710. pmk = sm->PMK;
  711. pmk_len = sm->pmk_len;
  712. }
  713. wpa_derive_ptk(sm, sm->alt_SNonce, pmk, pmk_len, &PTK);
  714. if (wpa_verify_key_mic(sm->wpa_key_mgmt, &PTK, data, data_len)
  715. == 0) {
  716. ok = 1;
  717. break;
  718. }
  719. if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt))
  720. break;
  721. }
  722. if (!ok) {
  723. wpa_printf(MSG_DEBUG,
  724. "WPA: Earlier SNonce did not result in matching MIC");
  725. return -1;
  726. }
  727. wpa_printf(MSG_DEBUG,
  728. "WPA: Earlier SNonce resulted in matching MIC");
  729. sm->alt_snonce_valid = 0;
  730. os_memcpy(sm->SNonce, sm->alt_SNonce, WPA_NONCE_LEN);
  731. os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
  732. sm->PTK_valid = TRUE;
  733. return 0;
  734. }
  735. void wpa_receive(struct wpa_authenticator *wpa_auth,
  736. struct wpa_state_machine *sm,
  737. u8 *data, size_t data_len)
  738. {
  739. struct ieee802_1x_hdr *hdr;
  740. struct wpa_eapol_key *key;
  741. u16 key_info, key_data_length;
  742. enum { PAIRWISE_2, PAIRWISE_4, GROUP_2, REQUEST,
  743. SMK_M1, SMK_M3, SMK_ERROR } msg;
  744. char *msgtxt;
  745. struct wpa_eapol_ie_parse kde;
  746. const u8 *key_data;
  747. size_t keyhdrlen, mic_len;
  748. u8 *mic;
  749. if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
  750. return;
  751. wpa_hexdump(MSG_MSGDUMP, "WPA: RX EAPOL data", data, data_len);
  752. mic_len = wpa_mic_len(sm->wpa_key_mgmt);
  753. keyhdrlen = sizeof(*key) + mic_len + 2;
  754. if (data_len < sizeof(*hdr) + keyhdrlen) {
  755. wpa_printf(MSG_DEBUG, "WPA: Ignore too short EAPOL-Key frame");
  756. return;
  757. }
  758. hdr = (struct ieee802_1x_hdr *) data;
  759. key = (struct wpa_eapol_key *) (hdr + 1);
  760. mic = (u8 *) (key + 1);
  761. key_info = WPA_GET_BE16(key->key_info);
  762. key_data = mic + mic_len + 2;
  763. key_data_length = WPA_GET_BE16(mic + mic_len);
  764. wpa_printf(MSG_DEBUG, "WPA: Received EAPOL-Key from " MACSTR
  765. " key_info=0x%x type=%u mic_len=%u key_data_length=%u",
  766. MAC2STR(sm->addr), key_info, key->type,
  767. (unsigned int) mic_len, key_data_length);
  768. wpa_hexdump(MSG_MSGDUMP,
  769. "WPA: EAPOL-Key header (ending before Key MIC)",
  770. key, sizeof(*key));
  771. wpa_hexdump(MSG_MSGDUMP, "WPA: EAPOL-Key Key MIC",
  772. mic, mic_len);
  773. if (key_data_length > data_len - sizeof(*hdr) - keyhdrlen) {
  774. wpa_printf(MSG_INFO, "WPA: Invalid EAPOL-Key frame - "
  775. "key_data overflow (%d > %lu)",
  776. key_data_length,
  777. (unsigned long) (data_len - sizeof(*hdr) -
  778. keyhdrlen));
  779. return;
  780. }
  781. if (sm->wpa == WPA_VERSION_WPA2) {
  782. if (key->type == EAPOL_KEY_TYPE_WPA) {
  783. /*
  784. * Some deployed station implementations seem to send
  785. * msg 4/4 with incorrect type value in WPA2 mode.
  786. */
  787. wpa_printf(MSG_DEBUG, "Workaround: Allow EAPOL-Key "
  788. "with unexpected WPA type in RSN mode");
  789. } else if (key->type != EAPOL_KEY_TYPE_RSN) {
  790. wpa_printf(MSG_DEBUG, "Ignore EAPOL-Key with "
  791. "unexpected type %d in RSN mode",
  792. key->type);
  793. return;
  794. }
  795. } else {
  796. if (key->type != EAPOL_KEY_TYPE_WPA) {
  797. wpa_printf(MSG_DEBUG, "Ignore EAPOL-Key with "
  798. "unexpected type %d in WPA mode",
  799. key->type);
  800. return;
  801. }
  802. }
  803. wpa_hexdump(MSG_DEBUG, "WPA: Received Key Nonce", key->key_nonce,
  804. WPA_NONCE_LEN);
  805. wpa_hexdump(MSG_DEBUG, "WPA: Received Replay Counter",
  806. key->replay_counter, WPA_REPLAY_COUNTER_LEN);
  807. /* FIX: verify that the EAPOL-Key frame was encrypted if pairwise keys
  808. * are set */
  809. if ((key_info & (WPA_KEY_INFO_SMK_MESSAGE | WPA_KEY_INFO_REQUEST)) ==
  810. (WPA_KEY_INFO_SMK_MESSAGE | WPA_KEY_INFO_REQUEST)) {
  811. if (key_info & WPA_KEY_INFO_ERROR) {
  812. msg = SMK_ERROR;
  813. msgtxt = "SMK Error";
  814. } else {
  815. msg = SMK_M1;
  816. msgtxt = "SMK M1";
  817. }
  818. } else if (key_info & WPA_KEY_INFO_SMK_MESSAGE) {
  819. msg = SMK_M3;
  820. msgtxt = "SMK M3";
  821. } else if (key_info & WPA_KEY_INFO_REQUEST) {
  822. msg = REQUEST;
  823. msgtxt = "Request";
  824. } else if (!(key_info & WPA_KEY_INFO_KEY_TYPE)) {
  825. msg = GROUP_2;
  826. msgtxt = "2/2 Group";
  827. } else if (key_data_length == 0 ||
  828. (mic_len == 0 && (key_info & WPA_KEY_INFO_ENCR_KEY_DATA) &&
  829. key_data_length == AES_BLOCK_SIZE)) {
  830. msg = PAIRWISE_4;
  831. msgtxt = "4/4 Pairwise";
  832. } else {
  833. msg = PAIRWISE_2;
  834. msgtxt = "2/4 Pairwise";
  835. }
  836. /* TODO: key_info type validation for PeerKey */
  837. if (msg == REQUEST || msg == PAIRWISE_2 || msg == PAIRWISE_4 ||
  838. msg == GROUP_2) {
  839. u16 ver = key_info & WPA_KEY_INFO_TYPE_MASK;
  840. if (sm->pairwise == WPA_CIPHER_CCMP ||
  841. sm->pairwise == WPA_CIPHER_GCMP) {
  842. if (wpa_use_aes_cmac(sm) &&
  843. sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN &&
  844. !wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) &&
  845. !wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
  846. ver != WPA_KEY_INFO_TYPE_AES_128_CMAC) {
  847. wpa_auth_logger(wpa_auth, sm->addr,
  848. LOGGER_WARNING,
  849. "advertised support for "
  850. "AES-128-CMAC, but did not "
  851. "use it");
  852. return;
  853. }
  854. if (!wpa_use_aes_cmac(sm) &&
  855. !wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
  856. ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) {
  857. wpa_auth_logger(wpa_auth, sm->addr,
  858. LOGGER_WARNING,
  859. "did not use HMAC-SHA1-AES "
  860. "with CCMP/GCMP");
  861. return;
  862. }
  863. }
  864. if ((wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) ||
  865. wpa_key_mgmt_fils(sm->wpa_key_mgmt)) &&
  866. ver != WPA_KEY_INFO_TYPE_AKM_DEFINED) {
  867. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_WARNING,
  868. "did not use EAPOL-Key descriptor version 0 as required for AKM-defined cases");
  869. return;
  870. }
  871. }
  872. if (key_info & WPA_KEY_INFO_REQUEST) {
  873. if (sm->req_replay_counter_used &&
  874. os_memcmp(key->replay_counter, sm->req_replay_counter,
  875. WPA_REPLAY_COUNTER_LEN) <= 0) {
  876. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_WARNING,
  877. "received EAPOL-Key request with "
  878. "replayed counter");
  879. return;
  880. }
  881. }
  882. if (!(key_info & WPA_KEY_INFO_REQUEST) &&
  883. !wpa_replay_counter_valid(sm->key_replay, key->replay_counter)) {
  884. int i;
  885. if (msg == PAIRWISE_2 &&
  886. wpa_replay_counter_valid(sm->prev_key_replay,
  887. key->replay_counter) &&
  888. sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
  889. os_memcmp(sm->SNonce, key->key_nonce, WPA_NONCE_LEN) != 0)
  890. {
  891. /*
  892. * Some supplicant implementations (e.g., Windows XP
  893. * WZC) update SNonce for each EAPOL-Key 2/4. This
  894. * breaks the workaround on accepting any of the
  895. * pending requests, so allow the SNonce to be updated
  896. * even if we have already sent out EAPOL-Key 3/4.
  897. */
  898. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  899. "Process SNonce update from STA "
  900. "based on retransmitted EAPOL-Key "
  901. "1/4");
  902. sm->update_snonce = 1;
  903. os_memcpy(sm->alt_SNonce, sm->SNonce, WPA_NONCE_LEN);
  904. sm->alt_snonce_valid = TRUE;
  905. os_memcpy(sm->alt_replay_counter,
  906. sm->key_replay[0].counter,
  907. WPA_REPLAY_COUNTER_LEN);
  908. goto continue_processing;
  909. }
  910. if (msg == PAIRWISE_4 && sm->alt_snonce_valid &&
  911. sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
  912. os_memcmp(key->replay_counter, sm->alt_replay_counter,
  913. WPA_REPLAY_COUNTER_LEN) == 0) {
  914. /*
  915. * Supplicant may still be using the old SNonce since
  916. * there was two EAPOL-Key 2/4 messages and they had
  917. * different SNonce values.
  918. */
  919. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  920. "Try to process received EAPOL-Key 4/4 based on old Replay Counter and SNonce from an earlier EAPOL-Key 1/4");
  921. goto continue_processing;
  922. }
  923. if (msg == PAIRWISE_2 &&
  924. wpa_replay_counter_valid(sm->prev_key_replay,
  925. key->replay_counter) &&
  926. sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING) {
  927. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  928. "ignore retransmitted EAPOL-Key %s - "
  929. "SNonce did not change", msgtxt);
  930. } else {
  931. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  932. "received EAPOL-Key %s with "
  933. "unexpected replay counter", msgtxt);
  934. }
  935. for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
  936. if (!sm->key_replay[i].valid)
  937. break;
  938. wpa_hexdump(MSG_DEBUG, "pending replay counter",
  939. sm->key_replay[i].counter,
  940. WPA_REPLAY_COUNTER_LEN);
  941. }
  942. wpa_hexdump(MSG_DEBUG, "received replay counter",
  943. key->replay_counter, WPA_REPLAY_COUNTER_LEN);
  944. return;
  945. }
  946. continue_processing:
  947. #ifdef CONFIG_FILS
  948. if (sm->wpa == WPA_VERSION_WPA2 && mic_len == 0 &&
  949. !(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) {
  950. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  951. "WPA: Encr Key Data bit not set even though AEAD cipher is supposed to be used - drop frame");
  952. return;
  953. }
  954. #endif /* CONFIG_FILS */
  955. switch (msg) {
  956. case PAIRWISE_2:
  957. if (sm->wpa_ptk_state != WPA_PTK_PTKSTART &&
  958. sm->wpa_ptk_state != WPA_PTK_PTKCALCNEGOTIATING &&
  959. (!sm->update_snonce ||
  960. sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING)) {
  961. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
  962. "received EAPOL-Key msg 2/4 in "
  963. "invalid state (%d) - dropped",
  964. sm->wpa_ptk_state);
  965. return;
  966. }
  967. random_add_randomness(key->key_nonce, WPA_NONCE_LEN);
  968. if (sm->group->reject_4way_hs_for_entropy) {
  969. /*
  970. * The system did not have enough entropy to generate
  971. * strong random numbers. Reject the first 4-way
  972. * handshake(s) and collect some entropy based on the
  973. * information from it. Once enough entropy is
  974. * available, the next atempt will trigger GMK/Key
  975. * Counter update and the station will be allowed to
  976. * continue.
  977. */
  978. wpa_printf(MSG_DEBUG, "WPA: Reject 4-way handshake to "
  979. "collect more entropy for random number "
  980. "generation");
  981. random_mark_pool_ready();
  982. wpa_sta_disconnect(wpa_auth, sm->addr);
  983. return;
  984. }
  985. break;
  986. case PAIRWISE_4:
  987. if (sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING ||
  988. !sm->PTK_valid) {
  989. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
  990. "received EAPOL-Key msg 4/4 in "
  991. "invalid state (%d) - dropped",
  992. sm->wpa_ptk_state);
  993. return;
  994. }
  995. break;
  996. case GROUP_2:
  997. if (sm->wpa_ptk_group_state != WPA_PTK_GROUP_REKEYNEGOTIATING
  998. || !sm->PTK_valid) {
  999. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
  1000. "received EAPOL-Key msg 2/2 in "
  1001. "invalid state (%d) - dropped",
  1002. sm->wpa_ptk_group_state);
  1003. return;
  1004. }
  1005. break;
  1006. #ifdef CONFIG_PEERKEY
  1007. case SMK_M1:
  1008. case SMK_M3:
  1009. case SMK_ERROR:
  1010. if (!wpa_auth->conf.peerkey) {
  1011. wpa_printf(MSG_DEBUG, "RSN: SMK M1/M3/Error, but "
  1012. "PeerKey use disabled - ignoring message");
  1013. return;
  1014. }
  1015. if (!sm->PTK_valid) {
  1016. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1017. "received EAPOL-Key msg SMK in "
  1018. "invalid state - dropped");
  1019. return;
  1020. }
  1021. break;
  1022. #else /* CONFIG_PEERKEY */
  1023. case SMK_M1:
  1024. case SMK_M3:
  1025. case SMK_ERROR:
  1026. return; /* STSL disabled - ignore SMK messages */
  1027. #endif /* CONFIG_PEERKEY */
  1028. case REQUEST:
  1029. break;
  1030. }
  1031. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  1032. "received EAPOL-Key frame (%s)", msgtxt);
  1033. if (key_info & WPA_KEY_INFO_ACK) {
  1034. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1035. "received invalid EAPOL-Key: Key Ack set");
  1036. return;
  1037. }
  1038. if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
  1039. !(key_info & WPA_KEY_INFO_MIC)) {
  1040. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1041. "received invalid EAPOL-Key: Key MIC not set");
  1042. return;
  1043. }
  1044. #ifdef CONFIG_FILS
  1045. if (wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
  1046. (key_info & WPA_KEY_INFO_MIC)) {
  1047. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1048. "received invalid EAPOL-Key: Key MIC set");
  1049. return;
  1050. }
  1051. #endif /* CONFIG_FILS */
  1052. sm->MICVerified = FALSE;
  1053. if (sm->PTK_valid && !sm->update_snonce) {
  1054. if (mic_len &&
  1055. wpa_verify_key_mic(sm->wpa_key_mgmt, &sm->PTK, data,
  1056. data_len) &&
  1057. (msg != PAIRWISE_4 || !sm->alt_snonce_valid ||
  1058. wpa_try_alt_snonce(sm, data, data_len))) {
  1059. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1060. "received EAPOL-Key with invalid MIC");
  1061. return;
  1062. }
  1063. #ifdef CONFIG_FILS
  1064. if (!mic_len &&
  1065. wpa_aead_decrypt(sm, &sm->PTK, data, data_len,
  1066. &key_data_length) < 0) {
  1067. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1068. "received EAPOL-Key with invalid MIC");
  1069. return;
  1070. }
  1071. #endif /* CONFIG_FILS */
  1072. sm->MICVerified = TRUE;
  1073. eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
  1074. sm->pending_1_of_4_timeout = 0;
  1075. }
  1076. if (key_info & WPA_KEY_INFO_REQUEST) {
  1077. if (sm->MICVerified) {
  1078. sm->req_replay_counter_used = 1;
  1079. os_memcpy(sm->req_replay_counter, key->replay_counter,
  1080. WPA_REPLAY_COUNTER_LEN);
  1081. } else {
  1082. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1083. "received EAPOL-Key request with "
  1084. "invalid MIC");
  1085. return;
  1086. }
  1087. /*
  1088. * TODO: should decrypt key data field if encryption was used;
  1089. * even though MAC address KDE is not normally encrypted,
  1090. * supplicant is allowed to encrypt it.
  1091. */
  1092. if (msg == SMK_ERROR) {
  1093. #ifdef CONFIG_PEERKEY
  1094. wpa_smk_error(wpa_auth, sm, key_data, key_data_length);
  1095. #endif /* CONFIG_PEERKEY */
  1096. return;
  1097. } else if (key_info & WPA_KEY_INFO_ERROR) {
  1098. if (wpa_receive_error_report(
  1099. wpa_auth, sm,
  1100. !(key_info & WPA_KEY_INFO_KEY_TYPE)) > 0)
  1101. return; /* STA entry was removed */
  1102. } else if (key_info & WPA_KEY_INFO_KEY_TYPE) {
  1103. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1104. "received EAPOL-Key Request for new "
  1105. "4-Way Handshake");
  1106. wpa_request_new_ptk(sm);
  1107. #ifdef CONFIG_PEERKEY
  1108. } else if (msg == SMK_M1) {
  1109. wpa_smk_m1(wpa_auth, sm, key, key_data,
  1110. key_data_length);
  1111. #endif /* CONFIG_PEERKEY */
  1112. } else if (key_data_length > 0 &&
  1113. wpa_parse_kde_ies(key_data, key_data_length,
  1114. &kde) == 0 &&
  1115. kde.mac_addr) {
  1116. } else {
  1117. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1118. "received EAPOL-Key Request for GTK "
  1119. "rekeying");
  1120. eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
  1121. wpa_rekey_gtk(wpa_auth, NULL);
  1122. }
  1123. } else {
  1124. /* Do not allow the same key replay counter to be reused. */
  1125. wpa_replay_counter_mark_invalid(sm->key_replay,
  1126. key->replay_counter);
  1127. if (msg == PAIRWISE_2) {
  1128. /*
  1129. * Maintain a copy of the pending EAPOL-Key frames in
  1130. * case the EAPOL-Key frame was retransmitted. This is
  1131. * needed to allow EAPOL-Key msg 2/4 reply to another
  1132. * pending msg 1/4 to update the SNonce to work around
  1133. * unexpected supplicant behavior.
  1134. */
  1135. os_memcpy(sm->prev_key_replay, sm->key_replay,
  1136. sizeof(sm->key_replay));
  1137. } else {
  1138. os_memset(sm->prev_key_replay, 0,
  1139. sizeof(sm->prev_key_replay));
  1140. }
  1141. /*
  1142. * Make sure old valid counters are not accepted anymore and
  1143. * do not get copied again.
  1144. */
  1145. wpa_replay_counter_mark_invalid(sm->key_replay, NULL);
  1146. }
  1147. #ifdef CONFIG_PEERKEY
  1148. if (msg == SMK_M3) {
  1149. wpa_smk_m3(wpa_auth, sm, key, key_data, key_data_length);
  1150. return;
  1151. }
  1152. #endif /* CONFIG_PEERKEY */
  1153. os_free(sm->last_rx_eapol_key);
  1154. sm->last_rx_eapol_key = os_malloc(data_len);
  1155. if (sm->last_rx_eapol_key == NULL)
  1156. return;
  1157. os_memcpy(sm->last_rx_eapol_key, data, data_len);
  1158. sm->last_rx_eapol_key_len = data_len;
  1159. sm->rx_eapol_key_secure = !!(key_info & WPA_KEY_INFO_SECURE);
  1160. sm->EAPOLKeyReceived = TRUE;
  1161. sm->EAPOLKeyPairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
  1162. sm->EAPOLKeyRequest = !!(key_info & WPA_KEY_INFO_REQUEST);
  1163. os_memcpy(sm->SNonce, key->key_nonce, WPA_NONCE_LEN);
  1164. wpa_sm_step(sm);
  1165. }
  1166. static int wpa_gmk_to_gtk(const u8 *gmk, const char *label, const u8 *addr,
  1167. const u8 *gnonce, u8 *gtk, size_t gtk_len)
  1168. {
  1169. u8 data[ETH_ALEN + WPA_NONCE_LEN + 8 + 16];
  1170. u8 *pos;
  1171. int ret = 0;
  1172. /* GTK = PRF-X(GMK, "Group key expansion",
  1173. * AA || GNonce || Time || random data)
  1174. * The example described in the IEEE 802.11 standard uses only AA and
  1175. * GNonce as inputs here. Add some more entropy since this derivation
  1176. * is done only at the Authenticator and as such, does not need to be
  1177. * exactly same.
  1178. */
  1179. os_memcpy(data, addr, ETH_ALEN);
  1180. os_memcpy(data + ETH_ALEN, gnonce, WPA_NONCE_LEN);
  1181. pos = data + ETH_ALEN + WPA_NONCE_LEN;
  1182. wpa_get_ntp_timestamp(pos);
  1183. pos += 8;
  1184. if (random_get_bytes(pos, 16) < 0)
  1185. ret = -1;
  1186. #ifdef CONFIG_IEEE80211W
  1187. sha256_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data), gtk, gtk_len);
  1188. #else /* CONFIG_IEEE80211W */
  1189. if (sha1_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data), gtk, gtk_len)
  1190. < 0)
  1191. ret = -1;
  1192. #endif /* CONFIG_IEEE80211W */
  1193. return ret;
  1194. }
  1195. static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx)
  1196. {
  1197. struct wpa_authenticator *wpa_auth = eloop_ctx;
  1198. struct wpa_state_machine *sm = timeout_ctx;
  1199. sm->pending_1_of_4_timeout = 0;
  1200. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "EAPOL-Key timeout");
  1201. sm->TimeoutEvt = TRUE;
  1202. wpa_sm_step(sm);
  1203. }
  1204. void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
  1205. struct wpa_state_machine *sm, int key_info,
  1206. const u8 *key_rsc, const u8 *nonce,
  1207. const u8 *kde, size_t kde_len,
  1208. int keyidx, int encr, int force_version)
  1209. {
  1210. struct ieee802_1x_hdr *hdr;
  1211. struct wpa_eapol_key *key;
  1212. size_t len, mic_len, keyhdrlen;
  1213. int alg;
  1214. int key_data_len, pad_len = 0;
  1215. u8 *buf, *pos;
  1216. int version, pairwise;
  1217. int i;
  1218. u8 *key_mic, *key_data;
  1219. mic_len = wpa_mic_len(sm->wpa_key_mgmt);
  1220. keyhdrlen = sizeof(*key) + mic_len + 2;
  1221. len = sizeof(struct ieee802_1x_hdr) + keyhdrlen;
  1222. if (force_version)
  1223. version = force_version;
  1224. else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN ||
  1225. wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) ||
  1226. wpa_key_mgmt_fils(sm->wpa_key_mgmt))
  1227. version = WPA_KEY_INFO_TYPE_AKM_DEFINED;
  1228. else if (wpa_use_aes_cmac(sm))
  1229. version = WPA_KEY_INFO_TYPE_AES_128_CMAC;
  1230. else if (sm->pairwise != WPA_CIPHER_TKIP)
  1231. version = WPA_KEY_INFO_TYPE_HMAC_SHA1_AES;
  1232. else
  1233. version = WPA_KEY_INFO_TYPE_HMAC_MD5_RC4;
  1234. pairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
  1235. wpa_printf(MSG_DEBUG, "WPA: Send EAPOL(version=%d secure=%d mic=%d "
  1236. "ack=%d install=%d pairwise=%d kde_len=%lu keyidx=%d "
  1237. "encr=%d)",
  1238. version,
  1239. (key_info & WPA_KEY_INFO_SECURE) ? 1 : 0,
  1240. (key_info & WPA_KEY_INFO_MIC) ? 1 : 0,
  1241. (key_info & WPA_KEY_INFO_ACK) ? 1 : 0,
  1242. (key_info & WPA_KEY_INFO_INSTALL) ? 1 : 0,
  1243. pairwise, (unsigned long) kde_len, keyidx, encr);
  1244. key_data_len = kde_len;
  1245. if ((version == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
  1246. sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN ||
  1247. wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) ||
  1248. version == WPA_KEY_INFO_TYPE_AES_128_CMAC) && encr) {
  1249. pad_len = key_data_len % 8;
  1250. if (pad_len)
  1251. pad_len = 8 - pad_len;
  1252. key_data_len += pad_len + 8;
  1253. }
  1254. len += key_data_len;
  1255. if (!mic_len && encr)
  1256. len += AES_BLOCK_SIZE;
  1257. hdr = os_zalloc(len);
  1258. if (hdr == NULL)
  1259. return;
  1260. hdr->version = wpa_auth->conf.eapol_version;
  1261. hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
  1262. hdr->length = host_to_be16(len - sizeof(*hdr));
  1263. key = (struct wpa_eapol_key *) (hdr + 1);
  1264. key_mic = (u8 *) (key + 1);
  1265. key_data = ((u8 *) (hdr + 1)) + keyhdrlen;
  1266. key->type = sm->wpa == WPA_VERSION_WPA2 ?
  1267. EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA;
  1268. key_info |= version;
  1269. if (encr && sm->wpa == WPA_VERSION_WPA2)
  1270. key_info |= WPA_KEY_INFO_ENCR_KEY_DATA;
  1271. if (sm->wpa != WPA_VERSION_WPA2)
  1272. key_info |= keyidx << WPA_KEY_INFO_KEY_INDEX_SHIFT;
  1273. WPA_PUT_BE16(key->key_info, key_info);
  1274. alg = pairwise ? sm->pairwise : wpa_auth->conf.wpa_group;
  1275. WPA_PUT_BE16(key->key_length, wpa_cipher_key_len(alg));
  1276. if (key_info & WPA_KEY_INFO_SMK_MESSAGE)
  1277. WPA_PUT_BE16(key->key_length, 0);
  1278. /* FIX: STSL: what to use as key_replay_counter? */
  1279. for (i = RSNA_MAX_EAPOL_RETRIES - 1; i > 0; i--) {
  1280. sm->key_replay[i].valid = sm->key_replay[i - 1].valid;
  1281. os_memcpy(sm->key_replay[i].counter,
  1282. sm->key_replay[i - 1].counter,
  1283. WPA_REPLAY_COUNTER_LEN);
  1284. }
  1285. inc_byte_array(sm->key_replay[0].counter, WPA_REPLAY_COUNTER_LEN);
  1286. os_memcpy(key->replay_counter, sm->key_replay[0].counter,
  1287. WPA_REPLAY_COUNTER_LEN);
  1288. wpa_hexdump(MSG_DEBUG, "WPA: Replay Counter",
  1289. key->replay_counter, WPA_REPLAY_COUNTER_LEN);
  1290. sm->key_replay[0].valid = TRUE;
  1291. if (nonce)
  1292. os_memcpy(key->key_nonce, nonce, WPA_NONCE_LEN);
  1293. if (key_rsc)
  1294. os_memcpy(key->key_rsc, key_rsc, WPA_KEY_RSC_LEN);
  1295. if (kde && !encr) {
  1296. os_memcpy(key_data, kde, kde_len);
  1297. WPA_PUT_BE16(key_mic + mic_len, kde_len);
  1298. #ifdef CONFIG_FILS
  1299. } else if (!mic_len) {
  1300. const u8 *aad[1];
  1301. size_t aad_len[1];
  1302. WPA_PUT_BE16(key_mic, AES_BLOCK_SIZE + kde_len);
  1303. wpa_hexdump_key(MSG_DEBUG, "Plaintext EAPOL-Key Key Data",
  1304. kde, kde_len);
  1305. wpa_hexdump_key(MSG_DEBUG, "WPA: KEK",
  1306. sm->PTK.kek, sm->PTK.kek_len);
  1307. /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
  1308. * to Key Data (exclusive). */
  1309. aad[0] = (u8 *) hdr;
  1310. aad_len[0] = key_mic + 2 - (u8 *) hdr;
  1311. if (aes_siv_encrypt(sm->PTK.kek, sm->PTK.kek_len, kde, kde_len,
  1312. 1, aad, aad_len, key_mic + 2) < 0) {
  1313. wpa_printf(MSG_DEBUG, "WPA: AES-SIV encryption failed");
  1314. return;
  1315. }
  1316. wpa_hexdump(MSG_DEBUG, "WPA: Encrypted Key Data from SIV",
  1317. key_mic + 2, AES_BLOCK_SIZE + kde_len);
  1318. #endif /* CONFIG_FILS */
  1319. } else if (encr && kde) {
  1320. buf = os_zalloc(key_data_len);
  1321. if (buf == NULL) {
  1322. os_free(hdr);
  1323. return;
  1324. }
  1325. pos = buf;
  1326. os_memcpy(pos, kde, kde_len);
  1327. pos += kde_len;
  1328. if (pad_len)
  1329. *pos++ = 0xdd;
  1330. wpa_hexdump_key(MSG_DEBUG, "Plaintext EAPOL-Key Key Data",
  1331. buf, key_data_len);
  1332. if (version == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
  1333. sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN ||
  1334. wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) ||
  1335. version == WPA_KEY_INFO_TYPE_AES_128_CMAC) {
  1336. if (aes_wrap(sm->PTK.kek, sm->PTK.kek_len,
  1337. (key_data_len - 8) / 8, buf, key_data)) {
  1338. os_free(hdr);
  1339. os_free(buf);
  1340. return;
  1341. }
  1342. WPA_PUT_BE16(key_mic + mic_len, key_data_len);
  1343. #ifndef CONFIG_NO_RC4
  1344. } else if (sm->PTK.kek_len == 16) {
  1345. u8 ek[32];
  1346. os_memcpy(key->key_iv,
  1347. sm->group->Counter + WPA_NONCE_LEN - 16, 16);
  1348. inc_byte_array(sm->group->Counter, WPA_NONCE_LEN);
  1349. os_memcpy(ek, key->key_iv, 16);
  1350. os_memcpy(ek + 16, sm->PTK.kek, sm->PTK.kek_len);
  1351. os_memcpy(key_data, buf, key_data_len);
  1352. rc4_skip(ek, 32, 256, key_data, key_data_len);
  1353. WPA_PUT_BE16(key_mic + mic_len, key_data_len);
  1354. #endif /* CONFIG_NO_RC4 */
  1355. } else {
  1356. os_free(hdr);
  1357. os_free(buf);
  1358. return;
  1359. }
  1360. os_free(buf);
  1361. }
  1362. if (key_info & WPA_KEY_INFO_MIC) {
  1363. if (!sm->PTK_valid || !mic_len) {
  1364. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
  1365. "PTK not valid when sending EAPOL-Key "
  1366. "frame");
  1367. os_free(hdr);
  1368. return;
  1369. }
  1370. wpa_eapol_key_mic(sm->PTK.kck, sm->PTK.kck_len,
  1371. sm->wpa_key_mgmt, version,
  1372. (u8 *) hdr, len, key_mic);
  1373. #ifdef CONFIG_TESTING_OPTIONS
  1374. if (!pairwise &&
  1375. wpa_auth->conf.corrupt_gtk_rekey_mic_probability > 0.0 &&
  1376. drand48() <
  1377. wpa_auth->conf.corrupt_gtk_rekey_mic_probability) {
  1378. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  1379. "Corrupting group EAPOL-Key Key MIC");
  1380. key_mic[0]++;
  1381. }
  1382. #endif /* CONFIG_TESTING_OPTIONS */
  1383. }
  1384. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_inc_EapolFramesTx,
  1385. 1);
  1386. wpa_auth_send_eapol(wpa_auth, sm->addr, (u8 *) hdr, len,
  1387. sm->pairwise_set);
  1388. os_free(hdr);
  1389. }
  1390. static void wpa_send_eapol(struct wpa_authenticator *wpa_auth,
  1391. struct wpa_state_machine *sm, int key_info,
  1392. const u8 *key_rsc, const u8 *nonce,
  1393. const u8 *kde, size_t kde_len,
  1394. int keyidx, int encr)
  1395. {
  1396. int timeout_ms;
  1397. int pairwise = key_info & WPA_KEY_INFO_KEY_TYPE;
  1398. int ctr;
  1399. if (sm == NULL)
  1400. return;
  1401. __wpa_send_eapol(wpa_auth, sm, key_info, key_rsc, nonce, kde, kde_len,
  1402. keyidx, encr, 0);
  1403. ctr = pairwise ? sm->TimeoutCtr : sm->GTimeoutCtr;
  1404. if (ctr == 1 && wpa_auth->conf.tx_status)
  1405. timeout_ms = pairwise ? eapol_key_timeout_first :
  1406. eapol_key_timeout_first_group;
  1407. else
  1408. timeout_ms = eapol_key_timeout_subseq;
  1409. if (pairwise && ctr == 1 && !(key_info & WPA_KEY_INFO_MIC))
  1410. sm->pending_1_of_4_timeout = 1;
  1411. wpa_printf(MSG_DEBUG, "WPA: Use EAPOL-Key timeout of %u ms (retry "
  1412. "counter %d)", timeout_ms, ctr);
  1413. eloop_register_timeout(timeout_ms / 1000, (timeout_ms % 1000) * 1000,
  1414. wpa_send_eapol_timeout, wpa_auth, sm);
  1415. }
  1416. static int wpa_verify_key_mic(int akmp, struct wpa_ptk *PTK, u8 *data,
  1417. size_t data_len)
  1418. {
  1419. struct ieee802_1x_hdr *hdr;
  1420. struct wpa_eapol_key *key;
  1421. u16 key_info;
  1422. int ret = 0;
  1423. u8 mic[WPA_EAPOL_KEY_MIC_MAX_LEN], *mic_pos;
  1424. size_t mic_len = wpa_mic_len(akmp);
  1425. if (data_len < sizeof(*hdr) + sizeof(*key))
  1426. return -1;
  1427. hdr = (struct ieee802_1x_hdr *) data;
  1428. key = (struct wpa_eapol_key *) (hdr + 1);
  1429. mic_pos = (u8 *) (key + 1);
  1430. key_info = WPA_GET_BE16(key->key_info);
  1431. os_memcpy(mic, mic_pos, mic_len);
  1432. os_memset(mic_pos, 0, mic_len);
  1433. if (wpa_eapol_key_mic(PTK->kck, PTK->kck_len, akmp,
  1434. key_info & WPA_KEY_INFO_TYPE_MASK,
  1435. data, data_len, mic_pos) ||
  1436. os_memcmp_const(mic, mic_pos, mic_len) != 0)
  1437. ret = -1;
  1438. os_memcpy(mic_pos, mic, mic_len);
  1439. return ret;
  1440. }
  1441. void wpa_remove_ptk(struct wpa_state_machine *sm)
  1442. {
  1443. sm->PTK_valid = FALSE;
  1444. os_memset(&sm->PTK, 0, sizeof(sm->PTK));
  1445. if (wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 0, NULL,
  1446. 0))
  1447. wpa_printf(MSG_DEBUG,
  1448. "RSN: PTK removal from the driver failed");
  1449. sm->pairwise_set = FALSE;
  1450. eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
  1451. }
  1452. int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event)
  1453. {
  1454. int remove_ptk = 1;
  1455. if (sm == NULL)
  1456. return -1;
  1457. wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  1458. "event %d notification", event);
  1459. switch (event) {
  1460. case WPA_AUTH:
  1461. #ifdef CONFIG_MESH
  1462. /* PTKs are derived through AMPE */
  1463. if (wpa_auth_start_ampe(sm->wpa_auth, sm->addr)) {
  1464. /* not mesh */
  1465. break;
  1466. }
  1467. return 0;
  1468. #endif /* CONFIG_MESH */
  1469. case WPA_ASSOC:
  1470. break;
  1471. case WPA_DEAUTH:
  1472. case WPA_DISASSOC:
  1473. sm->DeauthenticationRequest = TRUE;
  1474. break;
  1475. case WPA_REAUTH:
  1476. case WPA_REAUTH_EAPOL:
  1477. if (!sm->started) {
  1478. /*
  1479. * When using WPS, we may end up here if the STA
  1480. * manages to re-associate without the previous STA
  1481. * entry getting removed. Consequently, we need to make
  1482. * sure that the WPA state machines gets initialized
  1483. * properly at this point.
  1484. */
  1485. wpa_printf(MSG_DEBUG, "WPA state machine had not been "
  1486. "started - initialize now");
  1487. sm->started = 1;
  1488. sm->Init = TRUE;
  1489. if (wpa_sm_step(sm) == 1)
  1490. return 1; /* should not really happen */
  1491. sm->Init = FALSE;
  1492. sm->AuthenticationRequest = TRUE;
  1493. break;
  1494. }
  1495. if (sm->GUpdateStationKeys) {
  1496. /*
  1497. * Reauthentication cancels the pending group key
  1498. * update for this STA.
  1499. */
  1500. sm->group->GKeyDoneStations--;
  1501. sm->GUpdateStationKeys = FALSE;
  1502. sm->PtkGroupInit = TRUE;
  1503. }
  1504. sm->ReAuthenticationRequest = TRUE;
  1505. break;
  1506. case WPA_ASSOC_FT:
  1507. #ifdef CONFIG_IEEE80211R
  1508. wpa_printf(MSG_DEBUG, "FT: Retry PTK configuration "
  1509. "after association");
  1510. wpa_ft_install_ptk(sm);
  1511. /* Using FT protocol, not WPA auth state machine */
  1512. sm->ft_completed = 1;
  1513. return 0;
  1514. #else /* CONFIG_IEEE80211R */
  1515. break;
  1516. #endif /* CONFIG_IEEE80211R */
  1517. }
  1518. #ifdef CONFIG_IEEE80211R
  1519. sm->ft_completed = 0;
  1520. #endif /* CONFIG_IEEE80211R */
  1521. #ifdef CONFIG_IEEE80211W
  1522. if (sm->mgmt_frame_prot && event == WPA_AUTH)
  1523. remove_ptk = 0;
  1524. #endif /* CONFIG_IEEE80211W */
  1525. #ifdef CONFIG_FILS
  1526. if (wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
  1527. (event == WPA_AUTH || event == WPA_ASSOC))
  1528. remove_ptk = 0;
  1529. #endif /* CONFIG_FILS */
  1530. if (remove_ptk) {
  1531. sm->PTK_valid = FALSE;
  1532. os_memset(&sm->PTK, 0, sizeof(sm->PTK));
  1533. if (event != WPA_REAUTH_EAPOL)
  1534. wpa_remove_ptk(sm);
  1535. }
  1536. if (sm->in_step_loop) {
  1537. /*
  1538. * wpa_sm_step() is already running - avoid recursive call to
  1539. * it by making the existing loop process the new update.
  1540. */
  1541. sm->changed = TRUE;
  1542. return 0;
  1543. }
  1544. return wpa_sm_step(sm);
  1545. }
  1546. SM_STATE(WPA_PTK, INITIALIZE)
  1547. {
  1548. SM_ENTRY_MA(WPA_PTK, INITIALIZE, wpa_ptk);
  1549. if (sm->Init) {
  1550. /* Init flag is not cleared here, so avoid busy
  1551. * loop by claiming nothing changed. */
  1552. sm->changed = FALSE;
  1553. }
  1554. sm->keycount = 0;
  1555. if (sm->GUpdateStationKeys)
  1556. sm->group->GKeyDoneStations--;
  1557. sm->GUpdateStationKeys = FALSE;
  1558. if (sm->wpa == WPA_VERSION_WPA)
  1559. sm->PInitAKeys = FALSE;
  1560. if (1 /* Unicast cipher supported AND (ESS OR ((IBSS or WDS) and
  1561. * Local AA > Remote AA)) */) {
  1562. sm->Pair = TRUE;
  1563. }
  1564. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 0);
  1565. wpa_remove_ptk(sm);
  1566. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid, 0);
  1567. sm->TimeoutCtr = 0;
  1568. if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
  1569. wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
  1570. WPA_EAPOL_authorized, 0);
  1571. }
  1572. }
  1573. SM_STATE(WPA_PTK, DISCONNECT)
  1574. {
  1575. SM_ENTRY_MA(WPA_PTK, DISCONNECT, wpa_ptk);
  1576. sm->Disconnect = FALSE;
  1577. wpa_sta_disconnect(sm->wpa_auth, sm->addr);
  1578. }
  1579. SM_STATE(WPA_PTK, DISCONNECTED)
  1580. {
  1581. SM_ENTRY_MA(WPA_PTK, DISCONNECTED, wpa_ptk);
  1582. sm->DeauthenticationRequest = FALSE;
  1583. }
  1584. SM_STATE(WPA_PTK, AUTHENTICATION)
  1585. {
  1586. SM_ENTRY_MA(WPA_PTK, AUTHENTICATION, wpa_ptk);
  1587. os_memset(&sm->PTK, 0, sizeof(sm->PTK));
  1588. sm->PTK_valid = FALSE;
  1589. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portControl_Auto,
  1590. 1);
  1591. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 1);
  1592. sm->AuthenticationRequest = FALSE;
  1593. }
  1594. static void wpa_group_ensure_init(struct wpa_authenticator *wpa_auth,
  1595. struct wpa_group *group)
  1596. {
  1597. if (group->first_sta_seen)
  1598. return;
  1599. /*
  1600. * System has run bit further than at the time hostapd was started
  1601. * potentially very early during boot up. This provides better chances
  1602. * of collecting more randomness on embedded systems. Re-initialize the
  1603. * GMK and Counter here to improve their strength if there was not
  1604. * enough entropy available immediately after system startup.
  1605. */
  1606. wpa_printf(MSG_DEBUG, "WPA: Re-initialize GMK/Counter on first "
  1607. "station");
  1608. if (random_pool_ready() != 1) {
  1609. wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
  1610. "to proceed - reject first 4-way handshake");
  1611. group->reject_4way_hs_for_entropy = TRUE;
  1612. } else {
  1613. group->first_sta_seen = TRUE;
  1614. group->reject_4way_hs_for_entropy = FALSE;
  1615. }
  1616. if (wpa_group_init_gmk_and_counter(wpa_auth, group) < 0 ||
  1617. wpa_gtk_update(wpa_auth, group) < 0 ||
  1618. wpa_group_config_group_keys(wpa_auth, group) < 0) {
  1619. wpa_printf(MSG_INFO, "WPA: GMK/GTK setup failed");
  1620. group->first_sta_seen = FALSE;
  1621. group->reject_4way_hs_for_entropy = TRUE;
  1622. }
  1623. }
  1624. SM_STATE(WPA_PTK, AUTHENTICATION2)
  1625. {
  1626. SM_ENTRY_MA(WPA_PTK, AUTHENTICATION2, wpa_ptk);
  1627. wpa_group_ensure_init(sm->wpa_auth, sm->group);
  1628. sm->ReAuthenticationRequest = FALSE;
  1629. /*
  1630. * Definition of ANonce selection in IEEE Std 802.11i-2004 is somewhat
  1631. * ambiguous. The Authenticator state machine uses a counter that is
  1632. * incremented by one for each 4-way handshake. However, the security
  1633. * analysis of 4-way handshake points out that unpredictable nonces
  1634. * help in preventing precomputation attacks. Instead of the state
  1635. * machine definition, use an unpredictable nonce value here to provide
  1636. * stronger protection against potential precomputation attacks.
  1637. */
  1638. if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
  1639. wpa_printf(MSG_ERROR, "WPA: Failed to get random data for "
  1640. "ANonce.");
  1641. sm->Disconnect = TRUE;
  1642. return;
  1643. }
  1644. wpa_hexdump(MSG_DEBUG, "WPA: Assign ANonce", sm->ANonce,
  1645. WPA_NONCE_LEN);
  1646. /* IEEE 802.11i does not clear TimeoutCtr here, but this is more
  1647. * logical place than INITIALIZE since AUTHENTICATION2 can be
  1648. * re-entered on ReAuthenticationRequest without going through
  1649. * INITIALIZE. */
  1650. sm->TimeoutCtr = 0;
  1651. }
  1652. SM_STATE(WPA_PTK, INITPMK)
  1653. {
  1654. u8 msk[2 * PMK_LEN];
  1655. size_t len = 2 * PMK_LEN;
  1656. SM_ENTRY_MA(WPA_PTK, INITPMK, wpa_ptk);
  1657. #ifdef CONFIG_IEEE80211R
  1658. sm->xxkey_len = 0;
  1659. #endif /* CONFIG_IEEE80211R */
  1660. if (sm->pmksa) {
  1661. wpa_printf(MSG_DEBUG, "WPA: PMK from PMKSA cache");
  1662. os_memcpy(sm->PMK, sm->pmksa->pmk, sm->pmksa->pmk_len);
  1663. sm->pmk_len = sm->pmksa->pmk_len;
  1664. } else if (wpa_auth_get_msk(sm->wpa_auth, sm->addr, msk, &len) == 0) {
  1665. unsigned int pmk_len;
  1666. if (sm->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
  1667. pmk_len = PMK_LEN_SUITE_B_192;
  1668. else
  1669. pmk_len = PMK_LEN;
  1670. wpa_printf(MSG_DEBUG, "WPA: PMK from EAPOL state machine "
  1671. "(MSK len=%lu PMK len=%u)", (unsigned long) len,
  1672. pmk_len);
  1673. if (len < pmk_len) {
  1674. wpa_printf(MSG_DEBUG,
  1675. "WPA: MSK not long enough (%u) to create PMK (%u)",
  1676. (unsigned int) len, (unsigned int) pmk_len);
  1677. sm->Disconnect = TRUE;
  1678. return;
  1679. }
  1680. os_memcpy(sm->PMK, msk, pmk_len);
  1681. sm->pmk_len = pmk_len;
  1682. #ifdef CONFIG_IEEE80211R
  1683. if (len >= 2 * PMK_LEN) {
  1684. os_memcpy(sm->xxkey, msk + PMK_LEN, PMK_LEN);
  1685. sm->xxkey_len = PMK_LEN;
  1686. }
  1687. #endif /* CONFIG_IEEE80211R */
  1688. } else {
  1689. wpa_printf(MSG_DEBUG, "WPA: Could not get PMK, get_msk: %p",
  1690. sm->wpa_auth->cb.get_msk);
  1691. sm->Disconnect = TRUE;
  1692. return;
  1693. }
  1694. os_memset(msk, 0, sizeof(msk));
  1695. sm->req_replay_counter_used = 0;
  1696. /* IEEE 802.11i does not set keyRun to FALSE, but not doing this
  1697. * will break reauthentication since EAPOL state machines may not be
  1698. * get into AUTHENTICATING state that clears keyRun before WPA state
  1699. * machine enters AUTHENTICATION2 state and goes immediately to INITPMK
  1700. * state and takes PMK from the previously used AAA Key. This will
  1701. * eventually fail in 4-Way Handshake because Supplicant uses PMK
  1702. * derived from the new AAA Key. Setting keyRun = FALSE here seems to
  1703. * be good workaround for this issue. */
  1704. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyRun, 0);
  1705. }
  1706. SM_STATE(WPA_PTK, INITPSK)
  1707. {
  1708. const u8 *psk;
  1709. SM_ENTRY_MA(WPA_PTK, INITPSK, wpa_ptk);
  1710. psk = wpa_auth_get_psk(sm->wpa_auth, sm->addr, sm->p2p_dev_addr, NULL);
  1711. if (psk) {
  1712. os_memcpy(sm->PMK, psk, PMK_LEN);
  1713. sm->pmk_len = PMK_LEN;
  1714. #ifdef CONFIG_IEEE80211R
  1715. os_memcpy(sm->xxkey, psk, PMK_LEN);
  1716. sm->xxkey_len = PMK_LEN;
  1717. #endif /* CONFIG_IEEE80211R */
  1718. }
  1719. sm->req_replay_counter_used = 0;
  1720. }
  1721. SM_STATE(WPA_PTK, PTKSTART)
  1722. {
  1723. u8 buf[2 + RSN_SELECTOR_LEN + PMKID_LEN], *pmkid = NULL;
  1724. size_t pmkid_len = 0;
  1725. SM_ENTRY_MA(WPA_PTK, PTKSTART, wpa_ptk);
  1726. sm->PTKRequest = FALSE;
  1727. sm->TimeoutEvt = FALSE;
  1728. sm->alt_snonce_valid = FALSE;
  1729. sm->TimeoutCtr++;
  1730. if (sm->TimeoutCtr > (int) dot11RSNAConfigPairwiseUpdateCount) {
  1731. /* No point in sending the EAPOL-Key - we will disconnect
  1732. * immediately following this. */
  1733. return;
  1734. }
  1735. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  1736. "sending 1/4 msg of 4-Way Handshake");
  1737. /*
  1738. * TODO: Could add PMKID even with WPA2-PSK, but only if there is only
  1739. * one possible PSK for this STA.
  1740. */
  1741. if (sm->wpa == WPA_VERSION_WPA2 &&
  1742. wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
  1743. sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN) {
  1744. pmkid = buf;
  1745. pmkid_len = 2 + RSN_SELECTOR_LEN + PMKID_LEN;
  1746. pmkid[0] = WLAN_EID_VENDOR_SPECIFIC;
  1747. pmkid[1] = RSN_SELECTOR_LEN + PMKID_LEN;
  1748. RSN_SELECTOR_PUT(&pmkid[2], RSN_KEY_DATA_PMKID);
  1749. if (sm->pmksa) {
  1750. os_memcpy(&pmkid[2 + RSN_SELECTOR_LEN],
  1751. sm->pmksa->pmkid, PMKID_LEN);
  1752. } else if (wpa_key_mgmt_suite_b(sm->wpa_key_mgmt)) {
  1753. /* No KCK available to derive PMKID */
  1754. pmkid = NULL;
  1755. } else {
  1756. /*
  1757. * Calculate PMKID since no PMKSA cache entry was
  1758. * available with pre-calculated PMKID.
  1759. */
  1760. rsn_pmkid(sm->PMK, sm->pmk_len, sm->wpa_auth->addr,
  1761. sm->addr, &pmkid[2 + RSN_SELECTOR_LEN],
  1762. wpa_key_mgmt_sha256(sm->wpa_key_mgmt));
  1763. }
  1764. }
  1765. wpa_send_eapol(sm->wpa_auth, sm,
  1766. WPA_KEY_INFO_ACK | WPA_KEY_INFO_KEY_TYPE, NULL,
  1767. sm->ANonce, pmkid, pmkid_len, 0, 0);
  1768. }
  1769. static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
  1770. const u8 *pmk, unsigned int pmk_len,
  1771. struct wpa_ptk *ptk)
  1772. {
  1773. #ifdef CONFIG_IEEE80211R
  1774. if (wpa_key_mgmt_ft(sm->wpa_key_mgmt))
  1775. return wpa_auth_derive_ptk_ft(sm, pmk, ptk);
  1776. #endif /* CONFIG_IEEE80211R */
  1777. return wpa_pmk_to_ptk(pmk, pmk_len, "Pairwise key expansion",
  1778. sm->wpa_auth->addr, sm->addr, sm->ANonce, snonce,
  1779. ptk, sm->wpa_key_mgmt, sm->pairwise);
  1780. }
  1781. #ifdef CONFIG_FILS
  1782. int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk,
  1783. size_t pmk_len, const u8 *snonce, const u8 *anonce)
  1784. {
  1785. u8 ick[FILS_ICK_MAX_LEN];
  1786. size_t ick_len;
  1787. int res;
  1788. res = fils_pmk_to_ptk(pmk, pmk_len, sm->addr, sm->wpa_auth->addr,
  1789. snonce, anonce, &sm->PTK, ick, &ick_len,
  1790. sm->wpa_key_mgmt, sm->pairwise);
  1791. if (res < 0)
  1792. return res;
  1793. sm->PTK_valid = TRUE;
  1794. res = fils_key_auth_sk(ick, ick_len, snonce, anonce,
  1795. sm->addr, sm->wpa_auth->addr,
  1796. NULL, 0, NULL, 0, /* TODO: SK+PFS */
  1797. sm->wpa_key_mgmt, sm->fils_key_auth_sta,
  1798. sm->fils_key_auth_ap,
  1799. &sm->fils_key_auth_len);
  1800. os_memset(ick, 0, sizeof(ick));
  1801. /* Store nonces for (Re)Association Request/Response frame processing */
  1802. os_memcpy(sm->SNonce, snonce, FILS_NONCE_LEN);
  1803. os_memcpy(sm->ANonce, anonce, FILS_NONCE_LEN);
  1804. return res;
  1805. }
  1806. static int wpa_aead_decrypt(struct wpa_state_machine *sm, struct wpa_ptk *ptk,
  1807. u8 *buf, size_t buf_len, u16 *_key_data_len)
  1808. {
  1809. struct ieee802_1x_hdr *hdr;
  1810. struct wpa_eapol_key *key;
  1811. u8 *pos;
  1812. u16 key_data_len;
  1813. u8 *tmp;
  1814. const u8 *aad[1];
  1815. size_t aad_len[1];
  1816. hdr = (struct ieee802_1x_hdr *) buf;
  1817. key = (struct wpa_eapol_key *) (hdr + 1);
  1818. pos = (u8 *) (key + 1);
  1819. key_data_len = WPA_GET_BE16(pos);
  1820. if (key_data_len < AES_BLOCK_SIZE ||
  1821. key_data_len > buf_len - sizeof(*hdr) - sizeof(*key) - 2) {
  1822. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
  1823. "No room for AES-SIV data in the frame");
  1824. return -1;
  1825. }
  1826. pos += 2; /* Pointing at the Encrypted Key Data field */
  1827. tmp = os_malloc(key_data_len);
  1828. if (!tmp)
  1829. return -1;
  1830. /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
  1831. * to Key Data (exclusive). */
  1832. aad[0] = buf;
  1833. aad_len[0] = pos - buf;
  1834. if (aes_siv_decrypt(ptk->kek, ptk->kek_len, pos, key_data_len,
  1835. 1, aad, aad_len, tmp) < 0) {
  1836. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
  1837. "Invalid AES-SIV data in the frame");
  1838. bin_clear_free(tmp, key_data_len);
  1839. return -1;
  1840. }
  1841. /* AEAD decryption and validation completed successfully */
  1842. key_data_len -= AES_BLOCK_SIZE;
  1843. wpa_hexdump_key(MSG_DEBUG, "WPA: Decrypted Key Data",
  1844. tmp, key_data_len);
  1845. /* Replace Key Data field with the decrypted version */
  1846. os_memcpy(pos, tmp, key_data_len);
  1847. pos -= 2; /* Key Data Length field */
  1848. WPA_PUT_BE16(pos, key_data_len);
  1849. bin_clear_free(tmp, key_data_len);
  1850. if (_key_data_len)
  1851. *_key_data_len = key_data_len;
  1852. return 0;
  1853. }
  1854. int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session,
  1855. const struct ieee80211_mgmt *mgmt, size_t frame_len,
  1856. u8 *pos, size_t left)
  1857. {
  1858. u16 fc, stype;
  1859. const u8 *end, *ie_start, *ie, *session, *crypt;
  1860. struct ieee802_11_elems elems;
  1861. const u8 *aad[5];
  1862. size_t aad_len[5];
  1863. if (!sm || !sm->PTK_valid) {
  1864. wpa_printf(MSG_DEBUG,
  1865. "FILS: No KEK to decrypt Assocication Request frame");
  1866. return -1;
  1867. }
  1868. if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
  1869. wpa_printf(MSG_DEBUG,
  1870. "FILS: Not a FILS AKM - reject association");
  1871. return -1;
  1872. }
  1873. end = ((const u8 *) mgmt) + frame_len;
  1874. fc = le_to_host16(mgmt->frame_control);
  1875. stype = WLAN_FC_GET_STYPE(fc);
  1876. if (stype == WLAN_FC_STYPE_REASSOC_REQ)
  1877. ie_start = mgmt->u.reassoc_req.variable;
  1878. else
  1879. ie_start = mgmt->u.assoc_req.variable;
  1880. ie = ie_start;
  1881. /*
  1882. * Find FILS Session element which is the last unencrypted element in
  1883. * the frame.
  1884. */
  1885. session = NULL;
  1886. while (ie + 1 < end) {
  1887. if (ie + 2 + ie[1] > end)
  1888. break;
  1889. if (ie[0] == WLAN_EID_EXTENSION &&
  1890. ie[1] >= 1 + FILS_SESSION_LEN &&
  1891. ie[2] == WLAN_EID_EXT_FILS_SESSION) {
  1892. session = ie;
  1893. break;
  1894. }
  1895. ie += 2 + ie[1];
  1896. }
  1897. if (!session) {
  1898. wpa_printf(MSG_DEBUG,
  1899. "FILS: Could not find FILS Session element in Association Request frame - reject");
  1900. return -1;
  1901. }
  1902. if (os_memcmp(fils_session, session + 3, FILS_SESSION_LEN) != 0) {
  1903. wpa_printf(MSG_DEBUG, "FILS: Session mismatch");
  1904. wpa_hexdump(MSG_DEBUG, "FILS: Expected FILS Session",
  1905. fils_session, FILS_SESSION_LEN);
  1906. wpa_hexdump(MSG_DEBUG, "FILS: Received FILS Session",
  1907. session + 3, FILS_SESSION_LEN);
  1908. return -1;
  1909. }
  1910. crypt = session + 2 + session[1];
  1911. if (end - crypt < AES_BLOCK_SIZE) {
  1912. wpa_printf(MSG_DEBUG,
  1913. "FILS: Too short frame to include AES-SIV data");
  1914. return -1;
  1915. }
  1916. /* AES-SIV AAD vectors */
  1917. /* The STA's MAC address */
  1918. aad[0] = mgmt->sa;
  1919. aad_len[0] = ETH_ALEN;
  1920. /* The AP's BSSID */
  1921. aad[1] = mgmt->da;
  1922. aad_len[1] = ETH_ALEN;
  1923. /* The STA's nonce */
  1924. aad[2] = sm->SNonce;
  1925. aad_len[2] = FILS_NONCE_LEN;
  1926. /* The AP's nonce */
  1927. aad[3] = sm->ANonce;
  1928. aad_len[3] = FILS_NONCE_LEN;
  1929. /*
  1930. * The (Re)Association Request frame from the Capability Information
  1931. * field to the FILS Session element (both inclusive).
  1932. */
  1933. aad[4] = (const u8 *) &mgmt->u.assoc_req.capab_info;
  1934. aad_len[4] = crypt - aad[0];
  1935. if (aes_siv_decrypt(sm->PTK.kek, sm->PTK.kek_len, crypt, end - crypt,
  1936. 1, aad, aad_len, pos + (crypt - ie_start)) < 0) {
  1937. wpa_printf(MSG_DEBUG,
  1938. "FILS: Invalid AES-SIV data in the frame");
  1939. return -1;
  1940. }
  1941. wpa_hexdump(MSG_DEBUG, "FILS: Decrypted Association Request elements",
  1942. pos, left - AES_BLOCK_SIZE);
  1943. if (ieee802_11_parse_elems(pos, left - AES_BLOCK_SIZE, &elems, 1) ==
  1944. ParseFailed) {
  1945. wpa_printf(MSG_DEBUG,
  1946. "FILS: Failed to parse decrypted elements");
  1947. return -1;
  1948. }
  1949. if (!elems.fils_key_confirm) {
  1950. wpa_printf(MSG_DEBUG, "FILS: No FILS Key Confirm element");
  1951. return -1;
  1952. }
  1953. if (elems.fils_key_confirm_len != sm->fils_key_auth_len) {
  1954. wpa_printf(MSG_DEBUG,
  1955. "FILS: Unexpected Key-Auth length %d (expected %d)",
  1956. elems.fils_key_confirm_len,
  1957. (int) sm->fils_key_auth_len);
  1958. return -1;
  1959. }
  1960. if (os_memcmp(elems.fils_key_confirm, sm->fils_key_auth_sta,
  1961. sm->fils_key_auth_len) != 0) {
  1962. wpa_printf(MSG_DEBUG, "FILS: Key-Auth mismatch");
  1963. wpa_hexdump(MSG_DEBUG, "FILS: Received Key-Auth",
  1964. elems.fils_key_confirm,
  1965. elems.fils_key_confirm_len);
  1966. wpa_hexdump(MSG_DEBUG, "FILS: Expected Key-Auth",
  1967. sm->fils_key_auth_sta, sm->fils_key_auth_len);
  1968. return -1;
  1969. }
  1970. return left - AES_BLOCK_SIZE;
  1971. }
  1972. int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf,
  1973. size_t current_len, size_t max_len)
  1974. {
  1975. u8 *end = buf + max_len;
  1976. u8 *pos = buf + current_len;
  1977. struct ieee80211_mgmt *mgmt;
  1978. struct wpabuf *plain;
  1979. u8 *len, *tmp, *tmp2;
  1980. u8 hdr[2];
  1981. u8 *gtk, dummy_gtk[32];
  1982. size_t gtk_len;
  1983. struct wpa_group *gsm;
  1984. const u8 *aad[5];
  1985. size_t aad_len[5];
  1986. if (!sm || !sm->PTK_valid)
  1987. return -1;
  1988. wpa_hexdump(MSG_DEBUG,
  1989. "FILS: Association Response frame before FILS processing",
  1990. buf, current_len);
  1991. mgmt = (struct ieee80211_mgmt *) buf;
  1992. /* AES-SIV AAD vectors */
  1993. /* The AP's BSSID */
  1994. aad[0] = mgmt->sa;
  1995. aad_len[0] = ETH_ALEN;
  1996. /* The STA's MAC address */
  1997. aad[1] = mgmt->da;
  1998. aad_len[1] = ETH_ALEN;
  1999. /* The AP's nonce */
  2000. aad[2] = sm->ANonce;
  2001. aad_len[2] = FILS_NONCE_LEN;
  2002. /* The STA's nonce */
  2003. aad[3] = sm->SNonce;
  2004. aad_len[3] = FILS_NONCE_LEN;
  2005. /*
  2006. * The (Re)Association Response frame from the Capability Information
  2007. * field (the same offset in both Association and Reassociation
  2008. * Response frames) to the FILS Session element (both inclusive).
  2009. */
  2010. aad[4] = (const u8 *) &mgmt->u.assoc_resp.capab_info;
  2011. aad_len[4] = pos - aad[4];
  2012. /* The following elements will be encrypted with AES-SIV */
  2013. plain = wpabuf_alloc(1000);
  2014. if (!plain)
  2015. return -1;
  2016. /* TODO: FILS Public Key */
  2017. /* FILS Key Confirmation */
  2018. wpabuf_put_u8(plain, WLAN_EID_EXTENSION); /* Element ID */
  2019. wpabuf_put_u8(plain, 1 + sm->fils_key_auth_len); /* Length */
  2020. /* Element ID Extension */
  2021. wpabuf_put_u8(plain, WLAN_EID_EXT_FILS_KEY_CONFIRM);
  2022. wpabuf_put_data(plain, sm->fils_key_auth_ap, sm->fils_key_auth_len);
  2023. /* TODO: FILS HLP Container */
  2024. /* TODO: FILS IP Address Assignment */
  2025. /* Key Delivery */
  2026. gsm = sm->group;
  2027. wpabuf_put_u8(plain, WLAN_EID_EXTENSION); /* Element ID */
  2028. len = wpabuf_put(plain, 1);
  2029. wpabuf_put_u8(plain, WLAN_EID_EXT_KEY_DELIVERY);
  2030. wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN,
  2031. wpabuf_put(plain, WPA_KEY_RSC_LEN));
  2032. /* GTK KDE */
  2033. gtk = gsm->GTK[gsm->GN - 1];
  2034. gtk_len = gsm->GTK_len;
  2035. if (sm->wpa_auth->conf.disable_gtk) {
  2036. /*
  2037. * Provide unique random GTK to each STA to prevent use
  2038. * of GTK in the BSS.
  2039. */
  2040. if (random_get_bytes(dummy_gtk, gtk_len) < 0) {
  2041. wpabuf_free(plain);
  2042. return -1;
  2043. }
  2044. gtk = dummy_gtk;
  2045. }
  2046. hdr[0] = gsm->GN & 0x03;
  2047. hdr[1] = 0;
  2048. tmp = wpabuf_put(plain, 0);
  2049. tmp2 = wpa_add_kde(tmp, RSN_KEY_DATA_GROUPKEY, hdr, 2,
  2050. gtk, gtk_len);
  2051. wpabuf_put(plain, tmp2 - tmp);
  2052. /* IGTK KDE */
  2053. tmp = wpabuf_put(plain, 0);
  2054. tmp2 = ieee80211w_kde_add(sm, tmp);
  2055. wpabuf_put(plain, tmp2 - tmp);
  2056. *len = (u8 *) wpabuf_put(plain, 0) - len - 1;
  2057. if (pos + wpabuf_len(plain) + AES_BLOCK_SIZE > end) {
  2058. wpa_printf(MSG_DEBUG,
  2059. "FILS: Not enough room for FILS elements");
  2060. wpabuf_free(plain);
  2061. return -1;
  2062. }
  2063. wpa_hexdump_buf_key(MSG_DEBUG, "FILS: Association Response plaintext",
  2064. plain);
  2065. if (aes_siv_encrypt(sm->PTK.kek, sm->PTK.kek_len,
  2066. wpabuf_head(plain), wpabuf_len(plain),
  2067. 5, aad, aad_len, pos) < 0) {
  2068. wpabuf_free(plain);
  2069. return -1;
  2070. }
  2071. wpa_hexdump(MSG_DEBUG,
  2072. "FILS: Encrypted Association Response elements",
  2073. pos, AES_BLOCK_SIZE + wpabuf_len(plain));
  2074. current_len += wpabuf_len(plain) + AES_BLOCK_SIZE;
  2075. wpabuf_free(plain);
  2076. sm->fils_completed = 1;
  2077. return current_len;
  2078. }
  2079. int fils_set_tk(struct wpa_state_machine *sm)
  2080. {
  2081. enum wpa_alg alg;
  2082. int klen;
  2083. if (!sm || !sm->PTK_valid)
  2084. return -1;
  2085. alg = wpa_cipher_to_alg(sm->pairwise);
  2086. klen = wpa_cipher_key_len(sm->pairwise);
  2087. wpa_printf(MSG_DEBUG, "FILS: Configure TK to the driver");
  2088. if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
  2089. sm->PTK.tk, klen)) {
  2090. wpa_printf(MSG_DEBUG, "FILS: Failed to set TK to the driver");
  2091. return -1;
  2092. }
  2093. return 0;
  2094. }
  2095. #endif /* CONFIG_FILS */
  2096. SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
  2097. {
  2098. struct wpa_authenticator *wpa_auth = sm->wpa_auth;
  2099. struct wpa_ptk PTK;
  2100. int ok = 0, psk_found = 0;
  2101. const u8 *pmk = NULL;
  2102. unsigned int pmk_len;
  2103. int ft;
  2104. const u8 *eapol_key_ie, *key_data, *mic;
  2105. u16 key_data_length;
  2106. size_t mic_len, eapol_key_ie_len;
  2107. struct ieee802_1x_hdr *hdr;
  2108. struct wpa_eapol_key *key;
  2109. struct wpa_eapol_ie_parse kde;
  2110. SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING, wpa_ptk);
  2111. sm->EAPOLKeyReceived = FALSE;
  2112. sm->update_snonce = FALSE;
  2113. os_memset(&PTK, 0, sizeof(PTK));
  2114. mic_len = wpa_mic_len(sm->wpa_key_mgmt);
  2115. /* WPA with IEEE 802.1X: use the derived PMK from EAP
  2116. * WPA-PSK: iterate through possible PSKs and select the one matching
  2117. * the packet */
  2118. for (;;) {
  2119. if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
  2120. pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
  2121. sm->p2p_dev_addr, pmk);
  2122. if (pmk == NULL)
  2123. break;
  2124. psk_found = 1;
  2125. pmk_len = PMK_LEN;
  2126. } else {
  2127. pmk = sm->PMK;
  2128. pmk_len = sm->pmk_len;
  2129. }
  2130. wpa_derive_ptk(sm, sm->SNonce, pmk, pmk_len, &PTK);
  2131. if (mic_len &&
  2132. wpa_verify_key_mic(sm->wpa_key_mgmt, &PTK,
  2133. sm->last_rx_eapol_key,
  2134. sm->last_rx_eapol_key_len) == 0) {
  2135. ok = 1;
  2136. break;
  2137. }
  2138. #ifdef CONFIG_FILS
  2139. if (!mic_len &&
  2140. wpa_aead_decrypt(sm, &PTK, sm->last_rx_eapol_key,
  2141. sm->last_rx_eapol_key_len, NULL) == 0) {
  2142. ok = 1;
  2143. break;
  2144. }
  2145. #endif /* CONFIG_FILS */
  2146. if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt))
  2147. break;
  2148. }
  2149. if (!ok) {
  2150. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2151. "invalid MIC in msg 2/4 of 4-Way Handshake");
  2152. if (psk_found)
  2153. wpa_auth_psk_failure_report(sm->wpa_auth, sm->addr);
  2154. return;
  2155. }
  2156. /*
  2157. * Note: last_rx_eapol_key length fields have already been validated in
  2158. * wpa_receive().
  2159. */
  2160. hdr = (struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
  2161. key = (struct wpa_eapol_key *) (hdr + 1);
  2162. mic = (u8 *) (key + 1);
  2163. key_data = mic + mic_len + 2;
  2164. key_data_length = WPA_GET_BE16(mic + mic_len);
  2165. if (key_data_length > sm->last_rx_eapol_key_len - sizeof(*hdr) -
  2166. sizeof(*key) - mic_len - 2)
  2167. return;
  2168. if (wpa_parse_kde_ies(key_data, key_data_length, &kde) < 0) {
  2169. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
  2170. "received EAPOL-Key msg 2/4 with invalid Key Data contents");
  2171. return;
  2172. }
  2173. if (kde.rsn_ie) {
  2174. eapol_key_ie = kde.rsn_ie;
  2175. eapol_key_ie_len = kde.rsn_ie_len;
  2176. } else if (kde.osen) {
  2177. eapol_key_ie = kde.osen;
  2178. eapol_key_ie_len = kde.osen_len;
  2179. } else {
  2180. eapol_key_ie = kde.wpa_ie;
  2181. eapol_key_ie_len = kde.wpa_ie_len;
  2182. }
  2183. ft = sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt);
  2184. if (sm->wpa_ie == NULL ||
  2185. wpa_compare_rsn_ie(ft, sm->wpa_ie, sm->wpa_ie_len,
  2186. eapol_key_ie, eapol_key_ie_len)) {
  2187. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
  2188. "WPA IE from (Re)AssocReq did not match with msg 2/4");
  2189. if (sm->wpa_ie) {
  2190. wpa_hexdump(MSG_DEBUG, "WPA IE in AssocReq",
  2191. sm->wpa_ie, sm->wpa_ie_len);
  2192. }
  2193. wpa_hexdump(MSG_DEBUG, "WPA IE in msg 2/4",
  2194. eapol_key_ie, eapol_key_ie_len);
  2195. /* MLME-DEAUTHENTICATE.request */
  2196. wpa_sta_disconnect(wpa_auth, sm->addr);
  2197. return;
  2198. }
  2199. #ifdef CONFIG_IEEE80211R
  2200. if (ft && ft_check_msg_2_of_4(wpa_auth, sm, &kde) < 0) {
  2201. wpa_sta_disconnect(wpa_auth, sm->addr);
  2202. return;
  2203. }
  2204. #endif /* CONFIG_IEEE80211R */
  2205. #ifdef CONFIG_P2P
  2206. if (kde.ip_addr_req && kde.ip_addr_req[0] &&
  2207. wpa_auth->ip_pool && WPA_GET_BE32(sm->ip_addr) == 0) {
  2208. int idx;
  2209. wpa_printf(MSG_DEBUG,
  2210. "P2P: IP address requested in EAPOL-Key exchange");
  2211. idx = bitfield_get_first_zero(wpa_auth->ip_pool);
  2212. if (idx >= 0) {
  2213. u32 start = WPA_GET_BE32(wpa_auth->conf.ip_addr_start);
  2214. bitfield_set(wpa_auth->ip_pool, idx);
  2215. WPA_PUT_BE32(sm->ip_addr, start + idx);
  2216. wpa_printf(MSG_DEBUG,
  2217. "P2P: Assigned IP address %u.%u.%u.%u to "
  2218. MACSTR, sm->ip_addr[0], sm->ip_addr[1],
  2219. sm->ip_addr[2], sm->ip_addr[3],
  2220. MAC2STR(sm->addr));
  2221. }
  2222. }
  2223. #endif /* CONFIG_P2P */
  2224. #ifdef CONFIG_IEEE80211R
  2225. if (sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
  2226. /*
  2227. * Verify that PMKR1Name from EAPOL-Key message 2/4 matches
  2228. * with the value we derived.
  2229. */
  2230. if (os_memcmp_const(sm->sup_pmk_r1_name, sm->pmk_r1_name,
  2231. WPA_PMK_NAME_LEN) != 0) {
  2232. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2233. "PMKR1Name mismatch in FT 4-way "
  2234. "handshake");
  2235. wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from "
  2236. "Supplicant",
  2237. sm->sup_pmk_r1_name, WPA_PMK_NAME_LEN);
  2238. wpa_hexdump(MSG_DEBUG, "FT: Derived PMKR1Name",
  2239. sm->pmk_r1_name, WPA_PMK_NAME_LEN);
  2240. return;
  2241. }
  2242. }
  2243. #endif /* CONFIG_IEEE80211R */
  2244. sm->pending_1_of_4_timeout = 0;
  2245. eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
  2246. if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
  2247. /* PSK may have changed from the previous choice, so update
  2248. * state machine data based on whatever PSK was selected here.
  2249. */
  2250. os_memcpy(sm->PMK, pmk, PMK_LEN);
  2251. sm->pmk_len = PMK_LEN;
  2252. }
  2253. sm->MICVerified = TRUE;
  2254. os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
  2255. sm->PTK_valid = TRUE;
  2256. }
  2257. SM_STATE(WPA_PTK, PTKCALCNEGOTIATING2)
  2258. {
  2259. SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING2, wpa_ptk);
  2260. sm->TimeoutCtr = 0;
  2261. }
  2262. #ifdef CONFIG_IEEE80211W
  2263. static int ieee80211w_kde_len(struct wpa_state_machine *sm)
  2264. {
  2265. if (sm->mgmt_frame_prot) {
  2266. size_t len;
  2267. len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
  2268. return 2 + RSN_SELECTOR_LEN + WPA_IGTK_KDE_PREFIX_LEN + len;
  2269. }
  2270. return 0;
  2271. }
  2272. static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos)
  2273. {
  2274. struct wpa_igtk_kde igtk;
  2275. struct wpa_group *gsm = sm->group;
  2276. u8 rsc[WPA_KEY_RSC_LEN];
  2277. size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
  2278. if (!sm->mgmt_frame_prot)
  2279. return pos;
  2280. igtk.keyid[0] = gsm->GN_igtk;
  2281. igtk.keyid[1] = 0;
  2282. if (gsm->wpa_group_state != WPA_GROUP_SETKEYSDONE ||
  2283. wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, rsc) < 0)
  2284. os_memset(igtk.pn, 0, sizeof(igtk.pn));
  2285. else
  2286. os_memcpy(igtk.pn, rsc, sizeof(igtk.pn));
  2287. os_memcpy(igtk.igtk, gsm->IGTK[gsm->GN_igtk - 4], len);
  2288. if (sm->wpa_auth->conf.disable_gtk) {
  2289. /*
  2290. * Provide unique random IGTK to each STA to prevent use of
  2291. * IGTK in the BSS.
  2292. */
  2293. if (random_get_bytes(igtk.igtk, len) < 0)
  2294. return pos;
  2295. }
  2296. pos = wpa_add_kde(pos, RSN_KEY_DATA_IGTK,
  2297. (const u8 *) &igtk, WPA_IGTK_KDE_PREFIX_LEN + len,
  2298. NULL, 0);
  2299. return pos;
  2300. }
  2301. #else /* CONFIG_IEEE80211W */
  2302. static int ieee80211w_kde_len(struct wpa_state_machine *sm)
  2303. {
  2304. return 0;
  2305. }
  2306. static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos)
  2307. {
  2308. return pos;
  2309. }
  2310. #endif /* CONFIG_IEEE80211W */
  2311. SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
  2312. {
  2313. u8 rsc[WPA_KEY_RSC_LEN], *_rsc, *gtk, *kde, *pos, dummy_gtk[32];
  2314. size_t gtk_len, kde_len;
  2315. struct wpa_group *gsm = sm->group;
  2316. u8 *wpa_ie;
  2317. int wpa_ie_len, secure, keyidx, encr = 0;
  2318. SM_ENTRY_MA(WPA_PTK, PTKINITNEGOTIATING, wpa_ptk);
  2319. sm->TimeoutEvt = FALSE;
  2320. sm->TimeoutCtr++;
  2321. if (sm->TimeoutCtr > (int) dot11RSNAConfigPairwiseUpdateCount) {
  2322. /* No point in sending the EAPOL-Key - we will disconnect
  2323. * immediately following this. */
  2324. return;
  2325. }
  2326. /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
  2327. GTK[GN], IGTK, [FTIE], [TIE * 2])
  2328. */
  2329. os_memset(rsc, 0, WPA_KEY_RSC_LEN);
  2330. wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
  2331. /* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
  2332. wpa_ie = sm->wpa_auth->wpa_ie;
  2333. wpa_ie_len = sm->wpa_auth->wpa_ie_len;
  2334. if (sm->wpa == WPA_VERSION_WPA &&
  2335. (sm->wpa_auth->conf.wpa & WPA_PROTO_RSN) &&
  2336. wpa_ie_len > wpa_ie[1] + 2 && wpa_ie[0] == WLAN_EID_RSN) {
  2337. /* WPA-only STA, remove RSN IE and possible MDIE */
  2338. wpa_ie = wpa_ie + wpa_ie[1] + 2;
  2339. if (wpa_ie[0] == WLAN_EID_MOBILITY_DOMAIN)
  2340. wpa_ie = wpa_ie + wpa_ie[1] + 2;
  2341. wpa_ie_len = wpa_ie[1] + 2;
  2342. }
  2343. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2344. "sending 3/4 msg of 4-Way Handshake");
  2345. if (sm->wpa == WPA_VERSION_WPA2) {
  2346. /* WPA2 send GTK in the 4-way handshake */
  2347. secure = 1;
  2348. gtk = gsm->GTK[gsm->GN - 1];
  2349. gtk_len = gsm->GTK_len;
  2350. if (sm->wpa_auth->conf.disable_gtk) {
  2351. /*
  2352. * Provide unique random GTK to each STA to prevent use
  2353. * of GTK in the BSS.
  2354. */
  2355. if (random_get_bytes(dummy_gtk, gtk_len) < 0)
  2356. return;
  2357. gtk = dummy_gtk;
  2358. }
  2359. keyidx = gsm->GN;
  2360. _rsc = rsc;
  2361. encr = 1;
  2362. } else {
  2363. /* WPA does not include GTK in msg 3/4 */
  2364. secure = 0;
  2365. gtk = NULL;
  2366. gtk_len = 0;
  2367. keyidx = 0;
  2368. _rsc = NULL;
  2369. if (sm->rx_eapol_key_secure) {
  2370. /*
  2371. * It looks like Windows 7 supplicant tries to use
  2372. * Secure bit in msg 2/4 after having reported Michael
  2373. * MIC failure and it then rejects the 4-way handshake
  2374. * if msg 3/4 does not set Secure bit. Work around this
  2375. * by setting the Secure bit here even in the case of
  2376. * WPA if the supplicant used it first.
  2377. */
  2378. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2379. "STA used Secure bit in WPA msg 2/4 - "
  2380. "set Secure for 3/4 as workaround");
  2381. secure = 1;
  2382. }
  2383. }
  2384. kde_len = wpa_ie_len + ieee80211w_kde_len(sm);
  2385. if (gtk)
  2386. kde_len += 2 + RSN_SELECTOR_LEN + 2 + gtk_len;
  2387. #ifdef CONFIG_IEEE80211R
  2388. if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
  2389. kde_len += 2 + PMKID_LEN; /* PMKR1Name into RSN IE */
  2390. kde_len += 300; /* FTIE + 2 * TIE */
  2391. }
  2392. #endif /* CONFIG_IEEE80211R */
  2393. #ifdef CONFIG_P2P
  2394. if (WPA_GET_BE32(sm->ip_addr) > 0)
  2395. kde_len += 2 + RSN_SELECTOR_LEN + 3 * 4;
  2396. #endif /* CONFIG_P2P */
  2397. kde = os_malloc(kde_len);
  2398. if (kde == NULL)
  2399. return;
  2400. pos = kde;
  2401. os_memcpy(pos, wpa_ie, wpa_ie_len);
  2402. pos += wpa_ie_len;
  2403. #ifdef CONFIG_IEEE80211R
  2404. if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
  2405. int res;
  2406. size_t elen;
  2407. elen = pos - kde;
  2408. res = wpa_insert_pmkid(kde, &elen, sm->pmk_r1_name);
  2409. if (res < 0) {
  2410. wpa_printf(MSG_ERROR, "FT: Failed to insert "
  2411. "PMKR1Name into RSN IE in EAPOL-Key data");
  2412. os_free(kde);
  2413. return;
  2414. }
  2415. pos -= wpa_ie_len;
  2416. pos += elen;
  2417. }
  2418. #endif /* CONFIG_IEEE80211R */
  2419. if (gtk) {
  2420. u8 hdr[2];
  2421. hdr[0] = keyidx & 0x03;
  2422. hdr[1] = 0;
  2423. pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
  2424. gtk, gtk_len);
  2425. }
  2426. pos = ieee80211w_kde_add(sm, pos);
  2427. #ifdef CONFIG_IEEE80211R
  2428. if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
  2429. int res;
  2430. struct wpa_auth_config *conf;
  2431. conf = &sm->wpa_auth->conf;
  2432. if (sm->assoc_resp_ftie &&
  2433. kde + kde_len - pos >= 2 + sm->assoc_resp_ftie[1]) {
  2434. os_memcpy(pos, sm->assoc_resp_ftie,
  2435. 2 + sm->assoc_resp_ftie[1]);
  2436. res = 2 + sm->assoc_resp_ftie[1];
  2437. } else {
  2438. res = wpa_write_ftie(conf, conf->r0_key_holder,
  2439. conf->r0_key_holder_len,
  2440. NULL, NULL, pos,
  2441. kde + kde_len - pos,
  2442. NULL, 0);
  2443. }
  2444. if (res < 0) {
  2445. wpa_printf(MSG_ERROR, "FT: Failed to insert FTIE "
  2446. "into EAPOL-Key Key Data");
  2447. os_free(kde);
  2448. return;
  2449. }
  2450. pos += res;
  2451. /* TIE[ReassociationDeadline] (TU) */
  2452. *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
  2453. *pos++ = 5;
  2454. *pos++ = WLAN_TIMEOUT_REASSOC_DEADLINE;
  2455. WPA_PUT_LE32(pos, conf->reassociation_deadline);
  2456. pos += 4;
  2457. /* TIE[KeyLifetime] (seconds) */
  2458. *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
  2459. *pos++ = 5;
  2460. *pos++ = WLAN_TIMEOUT_KEY_LIFETIME;
  2461. WPA_PUT_LE32(pos, conf->r0_key_lifetime * 60);
  2462. pos += 4;
  2463. }
  2464. #endif /* CONFIG_IEEE80211R */
  2465. #ifdef CONFIG_P2P
  2466. if (WPA_GET_BE32(sm->ip_addr) > 0) {
  2467. u8 addr[3 * 4];
  2468. os_memcpy(addr, sm->ip_addr, 4);
  2469. os_memcpy(addr + 4, sm->wpa_auth->conf.ip_addr_mask, 4);
  2470. os_memcpy(addr + 8, sm->wpa_auth->conf.ip_addr_go, 4);
  2471. pos = wpa_add_kde(pos, WFA_KEY_DATA_IP_ADDR_ALLOC,
  2472. addr, sizeof(addr), NULL, 0);
  2473. }
  2474. #endif /* CONFIG_P2P */
  2475. wpa_send_eapol(sm->wpa_auth, sm,
  2476. (secure ? WPA_KEY_INFO_SECURE : 0) |
  2477. (wpa_mic_len(sm->wpa_key_mgmt) ? WPA_KEY_INFO_MIC : 0) |
  2478. WPA_KEY_INFO_ACK | WPA_KEY_INFO_INSTALL |
  2479. WPA_KEY_INFO_KEY_TYPE,
  2480. _rsc, sm->ANonce, kde, pos - kde, keyidx, encr);
  2481. os_free(kde);
  2482. }
  2483. SM_STATE(WPA_PTK, PTKINITDONE)
  2484. {
  2485. SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk);
  2486. sm->EAPOLKeyReceived = FALSE;
  2487. if (sm->Pair) {
  2488. enum wpa_alg alg = wpa_cipher_to_alg(sm->pairwise);
  2489. int klen = wpa_cipher_key_len(sm->pairwise);
  2490. if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
  2491. sm->PTK.tk, klen)) {
  2492. wpa_sta_disconnect(sm->wpa_auth, sm->addr);
  2493. return;
  2494. }
  2495. /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
  2496. sm->pairwise_set = TRUE;
  2497. if (sm->wpa_auth->conf.wpa_ptk_rekey) {
  2498. eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
  2499. eloop_register_timeout(sm->wpa_auth->conf.
  2500. wpa_ptk_rekey, 0, wpa_rekey_ptk,
  2501. sm->wpa_auth, sm);
  2502. }
  2503. if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
  2504. wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
  2505. WPA_EAPOL_authorized, 1);
  2506. }
  2507. }
  2508. if (0 /* IBSS == TRUE */) {
  2509. sm->keycount++;
  2510. if (sm->keycount == 2) {
  2511. wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
  2512. WPA_EAPOL_portValid, 1);
  2513. }
  2514. } else {
  2515. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid,
  2516. 1);
  2517. }
  2518. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyAvailable, 0);
  2519. wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyDone, 1);
  2520. if (sm->wpa == WPA_VERSION_WPA)
  2521. sm->PInitAKeys = TRUE;
  2522. else
  2523. sm->has_GTK = TRUE;
  2524. wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_INFO,
  2525. "pairwise key handshake completed (%s)",
  2526. sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
  2527. #ifdef CONFIG_IEEE80211R
  2528. wpa_ft_push_pmk_r1(sm->wpa_auth, sm->addr);
  2529. #endif /* CONFIG_IEEE80211R */
  2530. }
  2531. SM_STEP(WPA_PTK)
  2532. {
  2533. struct wpa_authenticator *wpa_auth = sm->wpa_auth;
  2534. if (sm->Init)
  2535. SM_ENTER(WPA_PTK, INITIALIZE);
  2536. else if (sm->Disconnect
  2537. /* || FIX: dot11RSNAConfigSALifetime timeout */) {
  2538. wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
  2539. "WPA_PTK: sm->Disconnect");
  2540. SM_ENTER(WPA_PTK, DISCONNECT);
  2541. }
  2542. else if (sm->DeauthenticationRequest)
  2543. SM_ENTER(WPA_PTK, DISCONNECTED);
  2544. else if (sm->AuthenticationRequest)
  2545. SM_ENTER(WPA_PTK, AUTHENTICATION);
  2546. else if (sm->ReAuthenticationRequest)
  2547. SM_ENTER(WPA_PTK, AUTHENTICATION2);
  2548. else if (sm->PTKRequest)
  2549. SM_ENTER(WPA_PTK, PTKSTART);
  2550. else switch (sm->wpa_ptk_state) {
  2551. case WPA_PTK_INITIALIZE:
  2552. break;
  2553. case WPA_PTK_DISCONNECT:
  2554. SM_ENTER(WPA_PTK, DISCONNECTED);
  2555. break;
  2556. case WPA_PTK_DISCONNECTED:
  2557. SM_ENTER(WPA_PTK, INITIALIZE);
  2558. break;
  2559. case WPA_PTK_AUTHENTICATION:
  2560. SM_ENTER(WPA_PTK, AUTHENTICATION2);
  2561. break;
  2562. case WPA_PTK_AUTHENTICATION2:
  2563. if (wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
  2564. wpa_auth_get_eapol(sm->wpa_auth, sm->addr,
  2565. WPA_EAPOL_keyRun) > 0)
  2566. SM_ENTER(WPA_PTK, INITPMK);
  2567. else if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)
  2568. /* FIX: && 802.1X::keyRun */)
  2569. SM_ENTER(WPA_PTK, INITPSK);
  2570. break;
  2571. case WPA_PTK_INITPMK:
  2572. if (wpa_auth_get_eapol(sm->wpa_auth, sm->addr,
  2573. WPA_EAPOL_keyAvailable) > 0)
  2574. SM_ENTER(WPA_PTK, PTKSTART);
  2575. else {
  2576. wpa_auth->dot11RSNA4WayHandshakeFailures++;
  2577. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
  2578. "INITPMK - keyAvailable = false");
  2579. SM_ENTER(WPA_PTK, DISCONNECT);
  2580. }
  2581. break;
  2582. case WPA_PTK_INITPSK:
  2583. if (wpa_auth_get_psk(sm->wpa_auth, sm->addr, sm->p2p_dev_addr,
  2584. NULL))
  2585. SM_ENTER(WPA_PTK, PTKSTART);
  2586. else {
  2587. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
  2588. "no PSK configured for the STA");
  2589. wpa_auth->dot11RSNA4WayHandshakeFailures++;
  2590. SM_ENTER(WPA_PTK, DISCONNECT);
  2591. }
  2592. break;
  2593. case WPA_PTK_PTKSTART:
  2594. if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
  2595. sm->EAPOLKeyPairwise)
  2596. SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
  2597. else if (sm->TimeoutCtr >
  2598. (int) dot11RSNAConfigPairwiseUpdateCount) {
  2599. wpa_auth->dot11RSNA4WayHandshakeFailures++;
  2600. wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2601. "PTKSTART: Retry limit %d reached",
  2602. dot11RSNAConfigPairwiseUpdateCount);
  2603. SM_ENTER(WPA_PTK, DISCONNECT);
  2604. } else if (sm->TimeoutEvt)
  2605. SM_ENTER(WPA_PTK, PTKSTART);
  2606. break;
  2607. case WPA_PTK_PTKCALCNEGOTIATING:
  2608. if (sm->MICVerified)
  2609. SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING2);
  2610. else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
  2611. sm->EAPOLKeyPairwise)
  2612. SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
  2613. else if (sm->TimeoutEvt)
  2614. SM_ENTER(WPA_PTK, PTKSTART);
  2615. break;
  2616. case WPA_PTK_PTKCALCNEGOTIATING2:
  2617. SM_ENTER(WPA_PTK, PTKINITNEGOTIATING);
  2618. break;
  2619. case WPA_PTK_PTKINITNEGOTIATING:
  2620. if (sm->update_snonce)
  2621. SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
  2622. else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
  2623. sm->EAPOLKeyPairwise && sm->MICVerified)
  2624. SM_ENTER(WPA_PTK, PTKINITDONE);
  2625. else if (sm->TimeoutCtr >
  2626. (int) dot11RSNAConfigPairwiseUpdateCount) {
  2627. wpa_auth->dot11RSNA4WayHandshakeFailures++;
  2628. wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2629. "PTKINITNEGOTIATING: Retry limit %d "
  2630. "reached",
  2631. dot11RSNAConfigPairwiseUpdateCount);
  2632. SM_ENTER(WPA_PTK, DISCONNECT);
  2633. } else if (sm->TimeoutEvt)
  2634. SM_ENTER(WPA_PTK, PTKINITNEGOTIATING);
  2635. break;
  2636. case WPA_PTK_PTKINITDONE:
  2637. break;
  2638. }
  2639. }
  2640. SM_STATE(WPA_PTK_GROUP, IDLE)
  2641. {
  2642. SM_ENTRY_MA(WPA_PTK_GROUP, IDLE, wpa_ptk_group);
  2643. if (sm->Init) {
  2644. /* Init flag is not cleared here, so avoid busy
  2645. * loop by claiming nothing changed. */
  2646. sm->changed = FALSE;
  2647. }
  2648. sm->GTimeoutCtr = 0;
  2649. }
  2650. SM_STATE(WPA_PTK_GROUP, REKEYNEGOTIATING)
  2651. {
  2652. u8 rsc[WPA_KEY_RSC_LEN];
  2653. struct wpa_group *gsm = sm->group;
  2654. const u8 *kde;
  2655. u8 *kde_buf = NULL, *pos, hdr[2];
  2656. size_t kde_len;
  2657. u8 *gtk, dummy_gtk[32];
  2658. SM_ENTRY_MA(WPA_PTK_GROUP, REKEYNEGOTIATING, wpa_ptk_group);
  2659. sm->GTimeoutCtr++;
  2660. if (sm->GTimeoutCtr > (int) dot11RSNAConfigGroupUpdateCount) {
  2661. /* No point in sending the EAPOL-Key - we will disconnect
  2662. * immediately following this. */
  2663. return;
  2664. }
  2665. if (sm->wpa == WPA_VERSION_WPA)
  2666. sm->PInitAKeys = FALSE;
  2667. sm->TimeoutEvt = FALSE;
  2668. /* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
  2669. os_memset(rsc, 0, WPA_KEY_RSC_LEN);
  2670. if (gsm->wpa_group_state == WPA_GROUP_SETKEYSDONE)
  2671. wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
  2672. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2673. "sending 1/2 msg of Group Key Handshake");
  2674. gtk = gsm->GTK[gsm->GN - 1];
  2675. if (sm->wpa_auth->conf.disable_gtk) {
  2676. /*
  2677. * Provide unique random GTK to each STA to prevent use
  2678. * of GTK in the BSS.
  2679. */
  2680. if (random_get_bytes(dummy_gtk, gsm->GTK_len) < 0)
  2681. return;
  2682. gtk = dummy_gtk;
  2683. }
  2684. if (sm->wpa == WPA_VERSION_WPA2) {
  2685. kde_len = 2 + RSN_SELECTOR_LEN + 2 + gsm->GTK_len +
  2686. ieee80211w_kde_len(sm);
  2687. kde_buf = os_malloc(kde_len);
  2688. if (kde_buf == NULL)
  2689. return;
  2690. kde = pos = kde_buf;
  2691. hdr[0] = gsm->GN & 0x03;
  2692. hdr[1] = 0;
  2693. pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
  2694. gtk, gsm->GTK_len);
  2695. pos = ieee80211w_kde_add(sm, pos);
  2696. kde_len = pos - kde;
  2697. } else {
  2698. kde = gtk;
  2699. kde_len = gsm->GTK_len;
  2700. }
  2701. wpa_send_eapol(sm->wpa_auth, sm,
  2702. WPA_KEY_INFO_SECURE |
  2703. (wpa_mic_len(sm->wpa_key_mgmt) ? WPA_KEY_INFO_MIC : 0) |
  2704. WPA_KEY_INFO_ACK |
  2705. (!sm->Pair ? WPA_KEY_INFO_INSTALL : 0),
  2706. rsc, gsm->GNonce, kde, kde_len, gsm->GN, 1);
  2707. os_free(kde_buf);
  2708. }
  2709. SM_STATE(WPA_PTK_GROUP, REKEYESTABLISHED)
  2710. {
  2711. SM_ENTRY_MA(WPA_PTK_GROUP, REKEYESTABLISHED, wpa_ptk_group);
  2712. sm->EAPOLKeyReceived = FALSE;
  2713. if (sm->GUpdateStationKeys)
  2714. sm->group->GKeyDoneStations--;
  2715. sm->GUpdateStationKeys = FALSE;
  2716. sm->GTimeoutCtr = 0;
  2717. /* FIX: MLME.SetProtection.Request(TA, Tx_Rx) */
  2718. wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_INFO,
  2719. "group key handshake completed (%s)",
  2720. sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
  2721. sm->has_GTK = TRUE;
  2722. }
  2723. SM_STATE(WPA_PTK_GROUP, KEYERROR)
  2724. {
  2725. SM_ENTRY_MA(WPA_PTK_GROUP, KEYERROR, wpa_ptk_group);
  2726. if (sm->GUpdateStationKeys)
  2727. sm->group->GKeyDoneStations--;
  2728. sm->GUpdateStationKeys = FALSE;
  2729. sm->Disconnect = TRUE;
  2730. }
  2731. SM_STEP(WPA_PTK_GROUP)
  2732. {
  2733. if (sm->Init || sm->PtkGroupInit) {
  2734. SM_ENTER(WPA_PTK_GROUP, IDLE);
  2735. sm->PtkGroupInit = FALSE;
  2736. } else switch (sm->wpa_ptk_group_state) {
  2737. case WPA_PTK_GROUP_IDLE:
  2738. if (sm->GUpdateStationKeys ||
  2739. (sm->wpa == WPA_VERSION_WPA && sm->PInitAKeys))
  2740. SM_ENTER(WPA_PTK_GROUP, REKEYNEGOTIATING);
  2741. break;
  2742. case WPA_PTK_GROUP_REKEYNEGOTIATING:
  2743. if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
  2744. !sm->EAPOLKeyPairwise && sm->MICVerified)
  2745. SM_ENTER(WPA_PTK_GROUP, REKEYESTABLISHED);
  2746. else if (sm->GTimeoutCtr >
  2747. (int) dot11RSNAConfigGroupUpdateCount)
  2748. SM_ENTER(WPA_PTK_GROUP, KEYERROR);
  2749. else if (sm->TimeoutEvt)
  2750. SM_ENTER(WPA_PTK_GROUP, REKEYNEGOTIATING);
  2751. break;
  2752. case WPA_PTK_GROUP_KEYERROR:
  2753. SM_ENTER(WPA_PTK_GROUP, IDLE);
  2754. break;
  2755. case WPA_PTK_GROUP_REKEYESTABLISHED:
  2756. SM_ENTER(WPA_PTK_GROUP, IDLE);
  2757. break;
  2758. }
  2759. }
  2760. static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
  2761. struct wpa_group *group)
  2762. {
  2763. int ret = 0;
  2764. os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
  2765. inc_byte_array(group->Counter, WPA_NONCE_LEN);
  2766. if (wpa_gmk_to_gtk(group->GMK, "Group key expansion",
  2767. wpa_auth->addr, group->GNonce,
  2768. group->GTK[group->GN - 1], group->GTK_len) < 0)
  2769. ret = -1;
  2770. wpa_hexdump_key(MSG_DEBUG, "GTK",
  2771. group->GTK[group->GN - 1], group->GTK_len);
  2772. #ifdef CONFIG_IEEE80211W
  2773. if (wpa_auth->conf.ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  2774. size_t len;
  2775. len = wpa_cipher_key_len(wpa_auth->conf.group_mgmt_cipher);
  2776. os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
  2777. inc_byte_array(group->Counter, WPA_NONCE_LEN);
  2778. if (wpa_gmk_to_gtk(group->GMK, "IGTK key expansion",
  2779. wpa_auth->addr, group->GNonce,
  2780. group->IGTK[group->GN_igtk - 4], len) < 0)
  2781. ret = -1;
  2782. wpa_hexdump_key(MSG_DEBUG, "IGTK",
  2783. group->IGTK[group->GN_igtk - 4], len);
  2784. }
  2785. #endif /* CONFIG_IEEE80211W */
  2786. return ret;
  2787. }
  2788. static void wpa_group_gtk_init(struct wpa_authenticator *wpa_auth,
  2789. struct wpa_group *group)
  2790. {
  2791. wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
  2792. "GTK_INIT (VLAN-ID %d)", group->vlan_id);
  2793. group->changed = FALSE; /* GInit is not cleared here; avoid loop */
  2794. group->wpa_group_state = WPA_GROUP_GTK_INIT;
  2795. /* GTK[0..N] = 0 */
  2796. os_memset(group->GTK, 0, sizeof(group->GTK));
  2797. group->GN = 1;
  2798. group->GM = 2;
  2799. #ifdef CONFIG_IEEE80211W
  2800. group->GN_igtk = 4;
  2801. group->GM_igtk = 5;
  2802. #endif /* CONFIG_IEEE80211W */
  2803. /* GTK[GN] = CalcGTK() */
  2804. wpa_gtk_update(wpa_auth, group);
  2805. }
  2806. static int wpa_group_update_sta(struct wpa_state_machine *sm, void *ctx)
  2807. {
  2808. if (ctx != NULL && ctx != sm->group)
  2809. return 0;
  2810. if (sm->wpa_ptk_state != WPA_PTK_PTKINITDONE) {
  2811. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2812. "Not in PTKINITDONE; skip Group Key update");
  2813. sm->GUpdateStationKeys = FALSE;
  2814. return 0;
  2815. }
  2816. if (sm->GUpdateStationKeys) {
  2817. /*
  2818. * This should not really happen, so add a debug log entry.
  2819. * Since we clear the GKeyDoneStations before the loop, the
  2820. * station needs to be counted here anyway.
  2821. */
  2822. wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
  2823. "GUpdateStationKeys was already set when "
  2824. "marking station for GTK rekeying");
  2825. }
  2826. /* Do not rekey GTK/IGTK when STA is in WNM-Sleep Mode */
  2827. if (sm->is_wnmsleep)
  2828. return 0;
  2829. sm->group->GKeyDoneStations++;
  2830. sm->GUpdateStationKeys = TRUE;
  2831. wpa_sm_step(sm);
  2832. return 0;
  2833. }
  2834. #ifdef CONFIG_WNM
  2835. /* update GTK when exiting WNM-Sleep Mode */
  2836. void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm)
  2837. {
  2838. if (sm == NULL || sm->is_wnmsleep)
  2839. return;
  2840. wpa_group_update_sta(sm, NULL);
  2841. }
  2842. void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag)
  2843. {
  2844. if (sm)
  2845. sm->is_wnmsleep = !!flag;
  2846. }
  2847. int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos)
  2848. {
  2849. struct wpa_group *gsm = sm->group;
  2850. u8 *start = pos;
  2851. /*
  2852. * GTK subelement:
  2853. * Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
  2854. * Key[5..32]
  2855. */
  2856. *pos++ = WNM_SLEEP_SUBELEM_GTK;
  2857. *pos++ = 11 + gsm->GTK_len;
  2858. /* Key ID in B0-B1 of Key Info */
  2859. WPA_PUT_LE16(pos, gsm->GN & 0x03);
  2860. pos += 2;
  2861. *pos++ = gsm->GTK_len;
  2862. if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, pos) != 0)
  2863. return 0;
  2864. pos += 8;
  2865. os_memcpy(pos, gsm->GTK[gsm->GN - 1], gsm->GTK_len);
  2866. pos += gsm->GTK_len;
  2867. wpa_printf(MSG_DEBUG, "WNM: GTK Key ID %u in WNM-Sleep Mode exit",
  2868. gsm->GN);
  2869. wpa_hexdump_key(MSG_DEBUG, "WNM: GTK in WNM-Sleep Mode exit",
  2870. gsm->GTK[gsm->GN - 1], gsm->GTK_len);
  2871. return pos - start;
  2872. }
  2873. #ifdef CONFIG_IEEE80211W
  2874. int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos)
  2875. {
  2876. struct wpa_group *gsm = sm->group;
  2877. u8 *start = pos;
  2878. size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
  2879. /*
  2880. * IGTK subelement:
  2881. * Sub-elem ID[1] | Length[1] | KeyID[2] | PN[6] | Key[16]
  2882. */
  2883. *pos++ = WNM_SLEEP_SUBELEM_IGTK;
  2884. *pos++ = 2 + 6 + len;
  2885. WPA_PUT_LE16(pos, gsm->GN_igtk);
  2886. pos += 2;
  2887. if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, pos) != 0)
  2888. return 0;
  2889. pos += 6;
  2890. os_memcpy(pos, gsm->IGTK[gsm->GN_igtk - 4], len);
  2891. pos += len;
  2892. wpa_printf(MSG_DEBUG, "WNM: IGTK Key ID %u in WNM-Sleep Mode exit",
  2893. gsm->GN_igtk);
  2894. wpa_hexdump_key(MSG_DEBUG, "WNM: IGTK in WNM-Sleep Mode exit",
  2895. gsm->IGTK[gsm->GN_igtk - 4], len);
  2896. return pos - start;
  2897. }
  2898. #endif /* CONFIG_IEEE80211W */
  2899. #endif /* CONFIG_WNM */
  2900. static void wpa_group_setkeys(struct wpa_authenticator *wpa_auth,
  2901. struct wpa_group *group)
  2902. {
  2903. int tmp;
  2904. wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
  2905. "SETKEYS (VLAN-ID %d)", group->vlan_id);
  2906. group->changed = TRUE;
  2907. group->wpa_group_state = WPA_GROUP_SETKEYS;
  2908. group->GTKReKey = FALSE;
  2909. tmp = group->GM;
  2910. group->GM = group->GN;
  2911. group->GN = tmp;
  2912. #ifdef CONFIG_IEEE80211W
  2913. tmp = group->GM_igtk;
  2914. group->GM_igtk = group->GN_igtk;
  2915. group->GN_igtk = tmp;
  2916. #endif /* CONFIG_IEEE80211W */
  2917. /* "GKeyDoneStations = GNoStations" is done in more robust way by
  2918. * counting the STAs that are marked with GUpdateStationKeys instead of
  2919. * including all STAs that could be in not-yet-completed state. */
  2920. wpa_gtk_update(wpa_auth, group);
  2921. if (group->GKeyDoneStations) {
  2922. wpa_printf(MSG_DEBUG, "wpa_group_setkeys: Unexpected "
  2923. "GKeyDoneStations=%d when starting new GTK rekey",
  2924. group->GKeyDoneStations);
  2925. group->GKeyDoneStations = 0;
  2926. }
  2927. wpa_auth_for_each_sta(wpa_auth, wpa_group_update_sta, group);
  2928. wpa_printf(MSG_DEBUG, "wpa_group_setkeys: GKeyDoneStations=%d",
  2929. group->GKeyDoneStations);
  2930. }
  2931. static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
  2932. struct wpa_group *group)
  2933. {
  2934. int ret = 0;
  2935. if (wpa_auth_set_key(wpa_auth, group->vlan_id,
  2936. wpa_cipher_to_alg(wpa_auth->conf.wpa_group),
  2937. broadcast_ether_addr, group->GN,
  2938. group->GTK[group->GN - 1], group->GTK_len) < 0)
  2939. ret = -1;
  2940. #ifdef CONFIG_IEEE80211W
  2941. if (wpa_auth->conf.ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  2942. enum wpa_alg alg;
  2943. size_t len;
  2944. alg = wpa_cipher_to_alg(wpa_auth->conf.group_mgmt_cipher);
  2945. len = wpa_cipher_key_len(wpa_auth->conf.group_mgmt_cipher);
  2946. if (ret == 0 &&
  2947. wpa_auth_set_key(wpa_auth, group->vlan_id, alg,
  2948. broadcast_ether_addr, group->GN_igtk,
  2949. group->IGTK[group->GN_igtk - 4], len) < 0)
  2950. ret = -1;
  2951. }
  2952. #endif /* CONFIG_IEEE80211W */
  2953. return ret;
  2954. }
  2955. static int wpa_group_disconnect_cb(struct wpa_state_machine *sm, void *ctx)
  2956. {
  2957. if (sm->group == ctx) {
  2958. wpa_printf(MSG_DEBUG, "WPA: Mark STA " MACSTR
  2959. " for discconnection due to fatal failure",
  2960. MAC2STR(sm->addr));
  2961. sm->Disconnect = TRUE;
  2962. }
  2963. return 0;
  2964. }
  2965. static void wpa_group_fatal_failure(struct wpa_authenticator *wpa_auth,
  2966. struct wpa_group *group)
  2967. {
  2968. wpa_printf(MSG_DEBUG, "WPA: group state machine entering state FATAL_FAILURE");
  2969. group->changed = TRUE;
  2970. group->wpa_group_state = WPA_GROUP_FATAL_FAILURE;
  2971. wpa_auth_for_each_sta(wpa_auth, wpa_group_disconnect_cb, group);
  2972. }
  2973. static int wpa_group_setkeysdone(struct wpa_authenticator *wpa_auth,
  2974. struct wpa_group *group)
  2975. {
  2976. wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
  2977. "SETKEYSDONE (VLAN-ID %d)", group->vlan_id);
  2978. group->changed = TRUE;
  2979. group->wpa_group_state = WPA_GROUP_SETKEYSDONE;
  2980. if (wpa_group_config_group_keys(wpa_auth, group) < 0) {
  2981. wpa_group_fatal_failure(wpa_auth, group);
  2982. return -1;
  2983. }
  2984. return 0;
  2985. }
  2986. static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
  2987. struct wpa_group *group)
  2988. {
  2989. if (group->GInit) {
  2990. wpa_group_gtk_init(wpa_auth, group);
  2991. } else if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE) {
  2992. /* Do not allow group operations */
  2993. } else if (group->wpa_group_state == WPA_GROUP_GTK_INIT &&
  2994. group->GTKAuthenticator) {
  2995. wpa_group_setkeysdone(wpa_auth, group);
  2996. } else if (group->wpa_group_state == WPA_GROUP_SETKEYSDONE &&
  2997. group->GTKReKey) {
  2998. wpa_group_setkeys(wpa_auth, group);
  2999. } else if (group->wpa_group_state == WPA_GROUP_SETKEYS) {
  3000. if (group->GKeyDoneStations == 0)
  3001. wpa_group_setkeysdone(wpa_auth, group);
  3002. else if (group->GTKReKey)
  3003. wpa_group_setkeys(wpa_auth, group);
  3004. }
  3005. }
  3006. static int wpa_sm_step(struct wpa_state_machine *sm)
  3007. {
  3008. if (sm == NULL)
  3009. return 0;
  3010. if (sm->in_step_loop) {
  3011. /* This should not happen, but if it does, make sure we do not
  3012. * end up freeing the state machine too early by exiting the
  3013. * recursive call. */
  3014. wpa_printf(MSG_ERROR, "WPA: wpa_sm_step() called recursively");
  3015. return 0;
  3016. }
  3017. sm->in_step_loop = 1;
  3018. do {
  3019. if (sm->pending_deinit)
  3020. break;
  3021. sm->changed = FALSE;
  3022. sm->wpa_auth->group->changed = FALSE;
  3023. SM_STEP_RUN(WPA_PTK);
  3024. if (sm->pending_deinit)
  3025. break;
  3026. SM_STEP_RUN(WPA_PTK_GROUP);
  3027. if (sm->pending_deinit)
  3028. break;
  3029. wpa_group_sm_step(sm->wpa_auth, sm->group);
  3030. } while (sm->changed || sm->wpa_auth->group->changed);
  3031. sm->in_step_loop = 0;
  3032. if (sm->pending_deinit) {
  3033. wpa_printf(MSG_DEBUG, "WPA: Completing pending STA state "
  3034. "machine deinit for " MACSTR, MAC2STR(sm->addr));
  3035. wpa_free_sta_sm(sm);
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx)
  3041. {
  3042. struct wpa_state_machine *sm = eloop_ctx;
  3043. wpa_sm_step(sm);
  3044. }
  3045. void wpa_auth_sm_notify(struct wpa_state_machine *sm)
  3046. {
  3047. if (sm == NULL)
  3048. return;
  3049. eloop_register_timeout(0, 0, wpa_sm_call_step, sm, NULL);
  3050. }
  3051. void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth)
  3052. {
  3053. int tmp, i;
  3054. struct wpa_group *group;
  3055. if (wpa_auth == NULL)
  3056. return;
  3057. group = wpa_auth->group;
  3058. for (i = 0; i < 2; i++) {
  3059. tmp = group->GM;
  3060. group->GM = group->GN;
  3061. group->GN = tmp;
  3062. #ifdef CONFIG_IEEE80211W
  3063. tmp = group->GM_igtk;
  3064. group->GM_igtk = group->GN_igtk;
  3065. group->GN_igtk = tmp;
  3066. #endif /* CONFIG_IEEE80211W */
  3067. wpa_gtk_update(wpa_auth, group);
  3068. wpa_group_config_group_keys(wpa_auth, group);
  3069. }
  3070. }
  3071. static const char * wpa_bool_txt(int val)
  3072. {
  3073. return val ? "TRUE" : "FALSE";
  3074. }
  3075. #define RSN_SUITE "%02x-%02x-%02x-%d"
  3076. #define RSN_SUITE_ARG(s) \
  3077. ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
  3078. int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
  3079. {
  3080. int len = 0, ret;
  3081. char pmkid_txt[PMKID_LEN * 2 + 1];
  3082. #ifdef CONFIG_RSN_PREAUTH
  3083. const int preauth = 1;
  3084. #else /* CONFIG_RSN_PREAUTH */
  3085. const int preauth = 0;
  3086. #endif /* CONFIG_RSN_PREAUTH */
  3087. if (wpa_auth == NULL)
  3088. return len;
  3089. ret = os_snprintf(buf + len, buflen - len,
  3090. "dot11RSNAOptionImplemented=TRUE\n"
  3091. "dot11RSNAPreauthenticationImplemented=%s\n"
  3092. "dot11RSNAEnabled=%s\n"
  3093. "dot11RSNAPreauthenticationEnabled=%s\n",
  3094. wpa_bool_txt(preauth),
  3095. wpa_bool_txt(wpa_auth->conf.wpa & WPA_PROTO_RSN),
  3096. wpa_bool_txt(wpa_auth->conf.rsn_preauth));
  3097. if (os_snprintf_error(buflen - len, ret))
  3098. return len;
  3099. len += ret;
  3100. wpa_snprintf_hex(pmkid_txt, sizeof(pmkid_txt),
  3101. wpa_auth->dot11RSNAPMKIDUsed, PMKID_LEN);
  3102. ret = os_snprintf(
  3103. buf + len, buflen - len,
  3104. "dot11RSNAConfigVersion=%u\n"
  3105. "dot11RSNAConfigPairwiseKeysSupported=9999\n"
  3106. /* FIX: dot11RSNAConfigGroupCipher */
  3107. /* FIX: dot11RSNAConfigGroupRekeyMethod */
  3108. /* FIX: dot11RSNAConfigGroupRekeyTime */
  3109. /* FIX: dot11RSNAConfigGroupRekeyPackets */
  3110. "dot11RSNAConfigGroupRekeyStrict=%u\n"
  3111. "dot11RSNAConfigGroupUpdateCount=%u\n"
  3112. "dot11RSNAConfigPairwiseUpdateCount=%u\n"
  3113. "dot11RSNAConfigGroupCipherSize=%u\n"
  3114. "dot11RSNAConfigPMKLifetime=%u\n"
  3115. "dot11RSNAConfigPMKReauthThreshold=%u\n"
  3116. "dot11RSNAConfigNumberOfPTKSAReplayCounters=0\n"
  3117. "dot11RSNAConfigSATimeout=%u\n"
  3118. "dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE "\n"
  3119. "dot11RSNAPairwiseCipherSelected=" RSN_SUITE "\n"
  3120. "dot11RSNAGroupCipherSelected=" RSN_SUITE "\n"
  3121. "dot11RSNAPMKIDUsed=%s\n"
  3122. "dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE "\n"
  3123. "dot11RSNAPairwiseCipherRequested=" RSN_SUITE "\n"
  3124. "dot11RSNAGroupCipherRequested=" RSN_SUITE "\n"
  3125. "dot11RSNATKIPCounterMeasuresInvoked=%u\n"
  3126. "dot11RSNA4WayHandshakeFailures=%u\n"
  3127. "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n",
  3128. RSN_VERSION,
  3129. !!wpa_auth->conf.wpa_strict_rekey,
  3130. dot11RSNAConfigGroupUpdateCount,
  3131. dot11RSNAConfigPairwiseUpdateCount,
  3132. wpa_cipher_key_len(wpa_auth->conf.wpa_group) * 8,
  3133. dot11RSNAConfigPMKLifetime,
  3134. dot11RSNAConfigPMKReauthThreshold,
  3135. dot11RSNAConfigSATimeout,
  3136. RSN_SUITE_ARG(wpa_auth->dot11RSNAAuthenticationSuiteSelected),
  3137. RSN_SUITE_ARG(wpa_auth->dot11RSNAPairwiseCipherSelected),
  3138. RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherSelected),
  3139. pmkid_txt,
  3140. RSN_SUITE_ARG(wpa_auth->dot11RSNAAuthenticationSuiteRequested),
  3141. RSN_SUITE_ARG(wpa_auth->dot11RSNAPairwiseCipherRequested),
  3142. RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherRequested),
  3143. wpa_auth->dot11RSNATKIPCounterMeasuresInvoked,
  3144. wpa_auth->dot11RSNA4WayHandshakeFailures);
  3145. if (os_snprintf_error(buflen - len, ret))
  3146. return len;
  3147. len += ret;
  3148. /* TODO: dot11RSNAConfigPairwiseCiphersTable */
  3149. /* TODO: dot11RSNAConfigAuthenticationSuitesTable */
  3150. /* Private MIB */
  3151. ret = os_snprintf(buf + len, buflen - len, "hostapdWPAGroupState=%d\n",
  3152. wpa_auth->group->wpa_group_state);
  3153. if (os_snprintf_error(buflen - len, ret))
  3154. return len;
  3155. len += ret;
  3156. return len;
  3157. }
  3158. int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen)
  3159. {
  3160. int len = 0, ret;
  3161. u32 pairwise = 0;
  3162. if (sm == NULL)
  3163. return 0;
  3164. /* TODO: FF-FF-FF-FF-FF-FF entry for broadcast/multicast stats */
  3165. /* dot11RSNAStatsEntry */
  3166. pairwise = wpa_cipher_to_suite(sm->wpa == WPA_VERSION_WPA2 ?
  3167. WPA_PROTO_RSN : WPA_PROTO_WPA,
  3168. sm->pairwise);
  3169. if (pairwise == 0)
  3170. return 0;
  3171. ret = os_snprintf(
  3172. buf + len, buflen - len,
  3173. /* TODO: dot11RSNAStatsIndex */
  3174. "dot11RSNAStatsSTAAddress=" MACSTR "\n"
  3175. "dot11RSNAStatsVersion=1\n"
  3176. "dot11RSNAStatsSelectedPairwiseCipher=" RSN_SUITE "\n"
  3177. /* TODO: dot11RSNAStatsTKIPICVErrors */
  3178. "dot11RSNAStatsTKIPLocalMICFailures=%u\n"
  3179. "dot11RSNAStatsTKIPRemoteMICFailures=%u\n"
  3180. /* TODO: dot11RSNAStatsCCMPReplays */
  3181. /* TODO: dot11RSNAStatsCCMPDecryptErrors */
  3182. /* TODO: dot11RSNAStatsTKIPReplays */,
  3183. MAC2STR(sm->addr),
  3184. RSN_SUITE_ARG(pairwise),
  3185. sm->dot11RSNAStatsTKIPLocalMICFailures,
  3186. sm->dot11RSNAStatsTKIPRemoteMICFailures);
  3187. if (os_snprintf_error(buflen - len, ret))
  3188. return len;
  3189. len += ret;
  3190. /* Private MIB */
  3191. ret = os_snprintf(buf + len, buflen - len,
  3192. "hostapdWPAPTKState=%d\n"
  3193. "hostapdWPAPTKGroupState=%d\n",
  3194. sm->wpa_ptk_state,
  3195. sm->wpa_ptk_group_state);
  3196. if (os_snprintf_error(buflen - len, ret))
  3197. return len;
  3198. len += ret;
  3199. return len;
  3200. }
  3201. void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth)
  3202. {
  3203. if (wpa_auth)
  3204. wpa_auth->dot11RSNATKIPCounterMeasuresInvoked++;
  3205. }
  3206. int wpa_auth_pairwise_set(struct wpa_state_machine *sm)
  3207. {
  3208. return sm && sm->pairwise_set;
  3209. }
  3210. int wpa_auth_get_pairwise(struct wpa_state_machine *sm)
  3211. {
  3212. return sm->pairwise;
  3213. }
  3214. int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm)
  3215. {
  3216. if (sm == NULL)
  3217. return -1;
  3218. return sm->wpa_key_mgmt;
  3219. }
  3220. int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm)
  3221. {
  3222. if (sm == NULL)
  3223. return 0;
  3224. return sm->wpa;
  3225. }
  3226. int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
  3227. struct rsn_pmksa_cache_entry *entry)
  3228. {
  3229. if (sm == NULL || sm->pmksa != entry)
  3230. return -1;
  3231. sm->pmksa = NULL;
  3232. return 0;
  3233. }
  3234. struct rsn_pmksa_cache_entry *
  3235. wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm)
  3236. {
  3237. return sm ? sm->pmksa : NULL;
  3238. }
  3239. void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm)
  3240. {
  3241. if (sm)
  3242. sm->dot11RSNAStatsTKIPLocalMICFailures++;
  3243. }
  3244. const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth, size_t *len)
  3245. {
  3246. if (wpa_auth == NULL)
  3247. return NULL;
  3248. *len = wpa_auth->wpa_ie_len;
  3249. return wpa_auth->wpa_ie;
  3250. }
  3251. int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
  3252. unsigned int pmk_len,
  3253. int session_timeout, struct eapol_state_machine *eapol)
  3254. {
  3255. if (sm == NULL || sm->wpa != WPA_VERSION_WPA2 ||
  3256. sm->wpa_auth->conf.disable_pmksa_caching)
  3257. return -1;
  3258. if (sm->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
  3259. if (pmk_len > PMK_LEN_SUITE_B_192)
  3260. pmk_len = PMK_LEN_SUITE_B_192;
  3261. } else if (pmk_len > PMK_LEN) {
  3262. pmk_len = PMK_LEN;
  3263. }
  3264. if (pmksa_cache_auth_add(sm->wpa_auth->pmksa, pmk, pmk_len, NULL,
  3265. sm->PTK.kck, sm->PTK.kck_len,
  3266. sm->wpa_auth->addr, sm->addr, session_timeout,
  3267. eapol, sm->wpa_key_mgmt))
  3268. return 0;
  3269. return -1;
  3270. }
  3271. int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
  3272. const u8 *pmk, size_t len, const u8 *sta_addr,
  3273. int session_timeout,
  3274. struct eapol_state_machine *eapol)
  3275. {
  3276. if (wpa_auth == NULL)
  3277. return -1;
  3278. if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, len, NULL,
  3279. NULL, 0,
  3280. wpa_auth->addr,
  3281. sta_addr, session_timeout, eapol,
  3282. WPA_KEY_MGMT_IEEE8021X))
  3283. return 0;
  3284. return -1;
  3285. }
  3286. int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
  3287. const u8 *pmk, const u8 *pmkid)
  3288. {
  3289. if (wpa_auth->conf.disable_pmksa_caching)
  3290. return -1;
  3291. if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, PMK_LEN, pmkid,
  3292. NULL, 0,
  3293. wpa_auth->addr, addr, 0, NULL,
  3294. WPA_KEY_MGMT_SAE))
  3295. return 0;
  3296. return -1;
  3297. }
  3298. void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
  3299. const u8 *sta_addr)
  3300. {
  3301. struct rsn_pmksa_cache_entry *pmksa;
  3302. if (wpa_auth == NULL || wpa_auth->pmksa == NULL)
  3303. return;
  3304. pmksa = pmksa_cache_auth_get(wpa_auth->pmksa, sta_addr, NULL);
  3305. if (pmksa) {
  3306. wpa_printf(MSG_DEBUG, "WPA: Remove PMKSA cache entry for "
  3307. MACSTR " based on request", MAC2STR(sta_addr));
  3308. pmksa_cache_free_entry(wpa_auth->pmksa, pmksa);
  3309. }
  3310. }
  3311. int wpa_auth_pmksa_list(struct wpa_authenticator *wpa_auth, char *buf,
  3312. size_t len)
  3313. {
  3314. if (!wpa_auth || !wpa_auth->pmksa)
  3315. return 0;
  3316. return pmksa_cache_auth_list(wpa_auth->pmksa, buf, len);
  3317. }
  3318. void wpa_auth_pmksa_flush(struct wpa_authenticator *wpa_auth)
  3319. {
  3320. if (wpa_auth && wpa_auth->pmksa)
  3321. pmksa_cache_auth_flush(wpa_auth->pmksa);
  3322. }
  3323. struct rsn_pmksa_cache_entry *
  3324. wpa_auth_pmksa_get(struct wpa_authenticator *wpa_auth, const u8 *sta_addr,
  3325. const u8 *pmkid)
  3326. {
  3327. if (!wpa_auth || !wpa_auth->pmksa)
  3328. return NULL;
  3329. return pmksa_cache_auth_get(wpa_auth->pmksa, sta_addr, pmkid);
  3330. }
  3331. void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry *pmksa,
  3332. struct wpa_state_machine *sm,
  3333. struct wpa_authenticator *wpa_auth,
  3334. u8 *pmkid, u8 *pmk)
  3335. {
  3336. if (!sm)
  3337. return;
  3338. sm->pmksa = pmksa;
  3339. os_memcpy(pmk, pmksa->pmk, PMK_LEN);
  3340. os_memcpy(pmkid, pmksa->pmkid, PMKID_LEN);
  3341. os_memcpy(wpa_auth->dot11RSNAPMKIDUsed, pmksa->pmkid, PMKID_LEN);
  3342. }
  3343. /*
  3344. * Remove and free the group from wpa_authenticator. This is triggered by a
  3345. * callback to make sure nobody is currently iterating the group list while it
  3346. * gets modified.
  3347. */
  3348. static void wpa_group_free(struct wpa_authenticator *wpa_auth,
  3349. struct wpa_group *group)
  3350. {
  3351. struct wpa_group *prev = wpa_auth->group;
  3352. wpa_printf(MSG_DEBUG, "WPA: Remove group state machine for VLAN-ID %d",
  3353. group->vlan_id);
  3354. while (prev) {
  3355. if (prev->next == group) {
  3356. /* This never frees the special first group as needed */
  3357. prev->next = group->next;
  3358. os_free(group);
  3359. break;
  3360. }
  3361. prev = prev->next;
  3362. }
  3363. }
  3364. /* Increase the reference counter for group */
  3365. static void wpa_group_get(struct wpa_authenticator *wpa_auth,
  3366. struct wpa_group *group)
  3367. {
  3368. /* Skip the special first group */
  3369. if (wpa_auth->group == group)
  3370. return;
  3371. group->references++;
  3372. }
  3373. /* Decrease the reference counter and maybe free the group */
  3374. static void wpa_group_put(struct wpa_authenticator *wpa_auth,
  3375. struct wpa_group *group)
  3376. {
  3377. /* Skip the special first group */
  3378. if (wpa_auth->group == group)
  3379. return;
  3380. group->references--;
  3381. if (group->references)
  3382. return;
  3383. wpa_group_free(wpa_auth, group);
  3384. }
  3385. /*
  3386. * Add a group that has its references counter set to zero. Caller needs to
  3387. * call wpa_group_get() on the return value to mark the entry in use.
  3388. */
  3389. static struct wpa_group *
  3390. wpa_auth_add_group(struct wpa_authenticator *wpa_auth, int vlan_id)
  3391. {
  3392. struct wpa_group *group;
  3393. if (wpa_auth == NULL || wpa_auth->group == NULL)
  3394. return NULL;
  3395. wpa_printf(MSG_DEBUG, "WPA: Add group state machine for VLAN-ID %d",
  3396. vlan_id);
  3397. group = wpa_group_init(wpa_auth, vlan_id, 0);
  3398. if (group == NULL)
  3399. return NULL;
  3400. group->next = wpa_auth->group->next;
  3401. wpa_auth->group->next = group;
  3402. return group;
  3403. }
  3404. /*
  3405. * Enforce that the group state machine for the VLAN is running, increase
  3406. * reference counter as interface is up. References might have been increased
  3407. * even if a negative value is returned.
  3408. * Returns: -1 on error (group missing, group already failed); otherwise, 0
  3409. */
  3410. int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id)
  3411. {
  3412. struct wpa_group *group;
  3413. if (wpa_auth == NULL)
  3414. return 0;
  3415. group = wpa_auth->group;
  3416. while (group) {
  3417. if (group->vlan_id == vlan_id)
  3418. break;
  3419. group = group->next;
  3420. }
  3421. if (group == NULL) {
  3422. group = wpa_auth_add_group(wpa_auth, vlan_id);
  3423. if (group == NULL)
  3424. return -1;
  3425. }
  3426. wpa_printf(MSG_DEBUG,
  3427. "WPA: Ensure group state machine running for VLAN ID %d",
  3428. vlan_id);
  3429. wpa_group_get(wpa_auth, group);
  3430. group->num_setup_iface++;
  3431. if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
  3432. return -1;
  3433. return 0;
  3434. }
  3435. /*
  3436. * Decrease reference counter, expected to be zero afterwards.
  3437. * returns: -1 on error (group not found, group in fail state)
  3438. * -2 if wpa_group is still referenced
  3439. * 0 else
  3440. */
  3441. int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id)
  3442. {
  3443. struct wpa_group *group;
  3444. int ret = 0;
  3445. if (wpa_auth == NULL)
  3446. return 0;
  3447. group = wpa_auth->group;
  3448. while (group) {
  3449. if (group->vlan_id == vlan_id)
  3450. break;
  3451. group = group->next;
  3452. }
  3453. if (group == NULL)
  3454. return -1;
  3455. wpa_printf(MSG_DEBUG,
  3456. "WPA: Try stopping group state machine for VLAN ID %d",
  3457. vlan_id);
  3458. if (group->num_setup_iface <= 0) {
  3459. wpa_printf(MSG_ERROR,
  3460. "WPA: wpa_auth_release_group called more often than wpa_auth_ensure_group for VLAN ID %d, skipping.",
  3461. vlan_id);
  3462. return -1;
  3463. }
  3464. group->num_setup_iface--;
  3465. if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
  3466. ret = -1;
  3467. if (group->references > 1) {
  3468. wpa_printf(MSG_DEBUG,
  3469. "WPA: Cannot stop group state machine for VLAN ID %d as references are still hold",
  3470. vlan_id);
  3471. ret = -2;
  3472. }
  3473. wpa_group_put(wpa_auth, group);
  3474. return ret;
  3475. }
  3476. int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id)
  3477. {
  3478. struct wpa_group *group;
  3479. if (sm == NULL || sm->wpa_auth == NULL)
  3480. return 0;
  3481. group = sm->wpa_auth->group;
  3482. while (group) {
  3483. if (group->vlan_id == vlan_id)
  3484. break;
  3485. group = group->next;
  3486. }
  3487. if (group == NULL) {
  3488. group = wpa_auth_add_group(sm->wpa_auth, vlan_id);
  3489. if (group == NULL)
  3490. return -1;
  3491. }
  3492. if (sm->group == group)
  3493. return 0;
  3494. if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
  3495. return -1;
  3496. wpa_printf(MSG_DEBUG, "WPA: Moving STA " MACSTR " to use group state "
  3497. "machine for VLAN ID %d", MAC2STR(sm->addr), vlan_id);
  3498. wpa_group_get(sm->wpa_auth, group);
  3499. wpa_group_put(sm->wpa_auth, sm->group);
  3500. sm->group = group;
  3501. return 0;
  3502. }
  3503. void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
  3504. struct wpa_state_machine *sm, int ack)
  3505. {
  3506. if (wpa_auth == NULL || sm == NULL)
  3507. return;
  3508. wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key TX status for STA " MACSTR
  3509. " ack=%d", MAC2STR(sm->addr), ack);
  3510. if (sm->pending_1_of_4_timeout && ack) {
  3511. /*
  3512. * Some deployed supplicant implementations update their SNonce
  3513. * for each EAPOL-Key 2/4 message even within the same 4-way
  3514. * handshake and then fail to use the first SNonce when
  3515. * deriving the PTK. This results in unsuccessful 4-way
  3516. * handshake whenever the relatively short initial timeout is
  3517. * reached and EAPOL-Key 1/4 is retransmitted. Try to work
  3518. * around this by increasing the timeout now that we know that
  3519. * the station has received the frame.
  3520. */
  3521. int timeout_ms = eapol_key_timeout_subseq;
  3522. wpa_printf(MSG_DEBUG, "WPA: Increase initial EAPOL-Key 1/4 "
  3523. "timeout by %u ms because of acknowledged frame",
  3524. timeout_ms);
  3525. eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
  3526. eloop_register_timeout(timeout_ms / 1000,
  3527. (timeout_ms % 1000) * 1000,
  3528. wpa_send_eapol_timeout, wpa_auth, sm);
  3529. }
  3530. }
  3531. int wpa_auth_uses_sae(struct wpa_state_machine *sm)
  3532. {
  3533. if (sm == NULL)
  3534. return 0;
  3535. return wpa_key_mgmt_sae(sm->wpa_key_mgmt);
  3536. }
  3537. int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm)
  3538. {
  3539. if (sm == NULL)
  3540. return 0;
  3541. return sm->wpa_key_mgmt == WPA_KEY_MGMT_FT_SAE;
  3542. }
  3543. #ifdef CONFIG_P2P
  3544. int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr)
  3545. {
  3546. if (sm == NULL || WPA_GET_BE32(sm->ip_addr) == 0)
  3547. return -1;
  3548. os_memcpy(addr, sm->ip_addr, 4);
  3549. return 0;
  3550. }
  3551. #endif /* CONFIG_P2P */
  3552. int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
  3553. struct radius_das_attrs *attr)
  3554. {
  3555. return pmksa_cache_auth_radius_das_disconnect(wpa_auth->pmksa, attr);
  3556. }
  3557. void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth)
  3558. {
  3559. struct wpa_group *group;
  3560. if (!wpa_auth)
  3561. return;
  3562. for (group = wpa_auth->group; group; group = group->next)
  3563. wpa_group_config_group_keys(wpa_auth, group);
  3564. }