internal.h 195 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235
  1. /* internal.h
  2. *
  3. * Copyright (C) 2006-2021 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLFSSL_INT_H
  22. #define WOLFSSL_INT_H
  23. #include <wolfssl/wolfcrypt/types.h>
  24. #include <wolfssl/ssl.h>
  25. #ifdef HAVE_CRL
  26. #include <wolfssl/crl.h>
  27. #endif
  28. #include <wolfssl/wolfcrypt/random.h>
  29. #ifndef NO_DES3
  30. #include <wolfssl/wolfcrypt/des3.h>
  31. #endif
  32. #ifdef HAVE_CHACHA
  33. #include <wolfssl/wolfcrypt/chacha.h>
  34. #endif
  35. #ifndef NO_ASN
  36. #include <wolfssl/wolfcrypt/asn.h>
  37. #include <wolfssl/wolfcrypt/pkcs12.h>
  38. #endif
  39. #ifndef NO_MD5
  40. #include <wolfssl/wolfcrypt/md5.h>
  41. #endif
  42. #ifndef NO_SHA
  43. #include <wolfssl/wolfcrypt/sha.h>
  44. #endif
  45. #ifndef NO_AES
  46. #include <wolfssl/wolfcrypt/aes.h>
  47. #endif
  48. #ifdef HAVE_POLY1305
  49. #include <wolfssl/wolfcrypt/poly1305.h>
  50. #endif
  51. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && defined(OPENSSL_EXTRA)
  52. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  53. #endif
  54. #ifdef HAVE_CAMELLIA
  55. #include <wolfssl/wolfcrypt/camellia.h>
  56. #endif
  57. #include <wolfssl/wolfcrypt/logging.h>
  58. #ifndef NO_HMAC
  59. #include <wolfssl/wolfcrypt/hmac.h>
  60. #endif
  61. #ifndef NO_RC4
  62. #include <wolfssl/wolfcrypt/arc4.h>
  63. #endif
  64. #ifndef NO_SHA256
  65. #include <wolfssl/wolfcrypt/sha256.h>
  66. #endif
  67. #if defined(WOLFSSL_SHA384)
  68. #include <wolfssl/wolfcrypt/sha512.h>
  69. #endif
  70. #ifdef HAVE_OCSP
  71. #include <wolfssl/ocsp.h>
  72. #endif
  73. #ifdef WOLFSSL_SHA384
  74. #include <wolfssl/wolfcrypt/sha512.h>
  75. #endif
  76. #ifdef WOLFSSL_SHA512
  77. #include <wolfssl/wolfcrypt/sha512.h>
  78. #endif
  79. #ifdef HAVE_AESGCM
  80. #include <wolfssl/wolfcrypt/sha512.h>
  81. #endif
  82. #ifdef WOLFSSL_RIPEMD
  83. #include <wolfssl/wolfcrypt/ripemd.h>
  84. #endif
  85. #ifndef NO_RSA
  86. #include <wolfssl/wolfcrypt/rsa.h>
  87. #endif
  88. #ifdef HAVE_ECC
  89. #include <wolfssl/wolfcrypt/ecc.h>
  90. #endif
  91. #ifndef NO_DH
  92. #include <wolfssl/wolfcrypt/dh.h>
  93. #endif
  94. #ifdef HAVE_ED25519
  95. #include <wolfssl/wolfcrypt/ed25519.h>
  96. #endif
  97. #ifdef HAVE_CURVE25519
  98. #include <wolfssl/wolfcrypt/curve25519.h>
  99. #endif
  100. #ifdef HAVE_ED448
  101. #include <wolfssl/wolfcrypt/ed448.h>
  102. #endif
  103. #ifdef HAVE_CURVE448
  104. #include <wolfssl/wolfcrypt/curve448.h>
  105. #endif
  106. #ifdef HAVE_PQC
  107. #include <wolfssl/wolfcrypt/falcon.h>
  108. #endif
  109. #ifdef HAVE_HKDF
  110. #include <wolfssl/wolfcrypt/kdf.h>
  111. #endif
  112. #ifndef WOLFSSL_NO_DEF_TICKET_ENC_CB
  113. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && \
  114. !defined(WOLFSSL_TICKET_ENC_AES128_GCM) && \
  115. !defined(WOLFSSL_TICKET_ENC_AES256_GCM)
  116. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  117. #else
  118. #include <wolfssl/wolfcrypt/aes.h>
  119. #endif
  120. #endif
  121. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  122. #include <wolfssl/wolfcrypt/hash.h>
  123. #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
  124. #include <wolfssl/callbacks.h>
  125. #endif
  126. #ifdef WOLFSSL_CALLBACKS
  127. #include <signal.h>
  128. #endif
  129. #ifdef USE_WINDOWS_API
  130. #ifdef WOLFSSL_GAME_BUILD
  131. #include "system/xtl.h"
  132. #else
  133. #if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
  134. /* On WinCE winsock2.h must be included before windows.h */
  135. #include <winsock2.h>
  136. #endif
  137. #include <windows.h>
  138. #endif
  139. #elif defined(THREADX)
  140. #ifndef SINGLE_THREADED
  141. #include "tx_api.h"
  142. #endif
  143. #elif defined(WOLFSSL_DEOS)
  144. /* do nothing, just don't pick Unix */
  145. #elif defined(MICRIUM)
  146. /* do nothing, just don't pick Unix */
  147. #elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
  148. /* do nothing */
  149. #elif defined(RTTHREAD)
  150. /* do nothing */
  151. #elif defined(EBSNET)
  152. /* do nothing */
  153. #elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
  154. /* do nothing */
  155. #elif defined(FREESCALE_FREE_RTOS)
  156. #include "fsl_os_abstraction.h"
  157. #elif defined(WOLFSSL_uITRON4)
  158. /* do nothing */
  159. #elif defined(WOLFSSL_uTKERNEL2)
  160. /* do nothing */
  161. #elif defined(WOLFSSL_CMSIS_RTOS)
  162. #include "cmsis_os.h"
  163. #elif defined(WOLFSSL_CMSIS_RTOSv2)
  164. #include "cmsis_os2.h"
  165. #elif defined(WOLFSSL_MDK_ARM)
  166. #if defined(WOLFSSL_MDK5)
  167. #include "cmsis_os.h"
  168. #else
  169. #include <rtl.h>
  170. #endif
  171. #elif defined(MBED)
  172. #elif defined(WOLFSSL_TIRTOS)
  173. /* do nothing */
  174. #elif defined(INTIME_RTOS)
  175. #include <rt.h>
  176. #elif defined(WOLFSSL_NUCLEUS_1_2)
  177. /* do nothing */
  178. #elif defined(WOLFSSL_APACHE_MYNEWT)
  179. #if !defined(WOLFSSL_LWIP)
  180. void mynewt_ctx_clear(void *ctx);
  181. void* mynewt_ctx_new();
  182. #endif
  183. #elif defined(WOLFSSL_ZEPHYR)
  184. #ifndef SINGLE_THREADED
  185. #include <kernel.h>
  186. #endif
  187. #elif defined(WOLFSSL_TELIT_M2MB)
  188. /* do nothing */
  189. #else
  190. #ifndef SINGLE_THREADED
  191. #if defined(WOLFSSL_LINUXKM)
  192. #define WOLFSSL_KTHREADS
  193. #include <linux/kthread.h>
  194. #elif defined(WOLFSSL_USER_MUTEX)
  195. /* do nothing */
  196. #else
  197. #define WOLFSSL_PTHREADS
  198. #include <pthread.h>
  199. #endif
  200. #endif
  201. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  202. #ifdef FUSION_RTOS
  203. #include <fclunistd.h>
  204. #else
  205. #include <unistd.h> /* for close of BIO */
  206. #endif
  207. #endif
  208. #endif
  209. #if !defined(CHAR_BIT) || (defined(OPENSSL_EXTRA) && !defined(INT_MAX))
  210. /* Needed for DTLS without big math and INT_MAX */
  211. #include <limits.h>
  212. #endif
  213. #ifdef HAVE_LIBZ
  214. #include "zlib.h"
  215. #endif
  216. #ifdef WOLFSSL_ASYNC_CRYPT
  217. #include <wolfssl/wolfcrypt/async.h>
  218. #endif
  219. #ifdef OPENSSL_EXTRA
  220. #ifdef WOLFCRYPT_HAVE_SRP
  221. #include <wolfssl/wolfcrypt/srp.h>
  222. #endif
  223. #endif
  224. #ifdef _MSC_VER
  225. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  226. #pragma warning(disable: 4996)
  227. #endif
  228. #ifdef NO_SHA
  229. #define WC_SHA_DIGEST_SIZE 20
  230. #endif
  231. #ifdef NO_SHA256
  232. #define WC_SHA256_DIGEST_SIZE 32
  233. #endif
  234. #ifdef NO_MD5
  235. #define WC_MD5_DIGEST_SIZE 16
  236. #endif
  237. #ifdef WOLFSSL_IOTSAFE
  238. #include <wolfssl/wolfcrypt/port/iotsafe/iotsafe.h>
  239. #endif
  240. #ifdef __cplusplus
  241. extern "C" {
  242. #endif
  243. /* Define or comment out the cipher suites you'd like to be compiled in
  244. make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined
  245. When adding cipher suites, add name to cipher_names, idx to cipher_name_idx
  246. Now that there is a maximum strength crypto build, the following BUILD_XXX
  247. flags need to be divided into two groups selected by WOLFSSL_MAX_STRENGTH.
  248. Those that do not use Perfect Forward Security and do not use AEAD ciphers
  249. need to be switched off. Allowed suites use (EC)DHE, AES-GCM|CCM, or
  250. CHACHA-POLY.
  251. */
  252. /* Check that if WOLFSSL_MAX_STRENGTH is set that all the required options are
  253. * not turned off. */
  254. #if defined(WOLFSSL_MAX_STRENGTH) && \
  255. ((!defined(HAVE_ECC) && (defined(NO_DH) || defined(NO_RSA))) || \
  256. (!defined(HAVE_AESGCM) && !defined(HAVE_AESCCM) && \
  257. (!defined(HAVE_POLY1305) || !defined(HAVE_CHACHA))) || \
  258. (defined(NO_SHA256) && !defined(WOLFSSL_SHA384)) || \
  259. !defined(NO_OLD_TLS))
  260. #error "You are trying to build max strength with requirements disabled."
  261. #endif
  262. #ifndef WOLFSSL_NO_TLS12
  263. #ifndef WOLFSSL_MAX_STRENGTH
  264. #ifdef WOLFSSL_AEAD_ONLY
  265. /* AES CBC ciphers are not allowed in AEAD only mode */
  266. #undef HAVE_AES_CBC
  267. #endif
  268. #ifndef WOLFSSL_AEAD_ONLY
  269. #if !defined(NO_RSA) && !defined(NO_RC4)
  270. #if defined(WOLFSSL_STATIC_RSA)
  271. #if !defined(NO_SHA)
  272. #define BUILD_SSL_RSA_WITH_RC4_128_SHA
  273. #endif
  274. #if !defined(NO_MD5)
  275. #define BUILD_SSL_RSA_WITH_RC4_128_MD5
  276. #endif
  277. #endif
  278. #endif
  279. #if !defined(NO_RSA) && !defined(NO_DES3)
  280. #if !defined(NO_SHA)
  281. #if defined(WOLFSSL_STATIC_RSA)
  282. #define BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA
  283. #endif
  284. #endif
  285. #endif
  286. #endif /* !WOLFSSL_AEAD_ONLY */
  287. #if !defined(NO_RSA) && !defined(NO_AES) && !defined(NO_TLS)
  288. #if !defined(NO_SHA) && defined(HAVE_AES_CBC)
  289. #if defined(WOLFSSL_STATIC_RSA)
  290. #ifdef WOLFSSL_AES_128
  291. #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA
  292. #endif
  293. #ifdef WOLFSSL_AES_256
  294. #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA
  295. #endif
  296. #endif
  297. #endif
  298. #if defined(WOLFSSL_STATIC_RSA)
  299. #if !defined (NO_SHA256) && defined(HAVE_AES_CBC)
  300. #ifdef WOLFSSL_AES_128
  301. #define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256
  302. #endif
  303. #ifdef WOLFSSL_AES_256
  304. #define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256
  305. #endif
  306. #endif
  307. #if defined (HAVE_AESGCM)
  308. #ifdef WOLFSSL_AES_128
  309. #define BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256
  310. #endif
  311. #if defined (WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  312. #define BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384
  313. #endif
  314. #endif
  315. #if defined (HAVE_AESCCM)
  316. #ifdef WOLFSSL_AES_128
  317. #define BUILD_TLS_RSA_WITH_AES_128_CCM_8
  318. #endif
  319. #ifdef WOLFSSL_AES_256
  320. #define BUILD_TLS_RSA_WITH_AES_256_CCM_8
  321. #endif
  322. #endif
  323. #endif
  324. #endif
  325. #if defined(HAVE_CAMELLIA) && !defined(NO_TLS) && !defined(NO_CAMELLIA_CBC)
  326. #ifndef NO_RSA
  327. #if defined(WOLFSSL_STATIC_RSA)
  328. #if !defined(NO_SHA)
  329. #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
  330. #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
  331. #endif
  332. #ifndef NO_SHA256
  333. #define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
  334. #define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
  335. #endif
  336. #endif
  337. #if !defined(NO_DH)
  338. #if !defined(NO_SHA)
  339. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
  340. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
  341. #endif
  342. #ifndef NO_SHA256
  343. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
  344. #define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
  345. #endif
  346. #endif
  347. #endif
  348. #endif
  349. #if defined(WOLFSSL_STATIC_PSK)
  350. #if !defined(NO_PSK) && !defined(NO_AES) && !defined(NO_TLS)
  351. #if !defined(NO_SHA)
  352. #ifdef WOLFSSL_AES_128
  353. #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA
  354. #endif
  355. #ifdef WOLFSSL_AES_256
  356. #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA
  357. #endif
  358. #endif
  359. #ifndef NO_SHA256
  360. #ifdef WOLFSSL_AES_128
  361. #ifdef HAVE_AES_CBC
  362. #define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256
  363. #endif
  364. #ifdef HAVE_AESGCM
  365. #define BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256
  366. #endif
  367. #endif /* WOLFSSL_AES_128 */
  368. #ifdef HAVE_AESCCM
  369. #ifdef WOLFSSL_AES_128
  370. #define BUILD_TLS_PSK_WITH_AES_128_CCM_8
  371. #define BUILD_TLS_PSK_WITH_AES_128_CCM
  372. #endif
  373. #ifdef WOLFSSL_AES_256
  374. #define BUILD_TLS_PSK_WITH_AES_256_CCM_8
  375. #define BUILD_TLS_PSK_WITH_AES_256_CCM
  376. #endif
  377. #endif
  378. #endif
  379. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  380. #ifdef HAVE_AES_CBC
  381. #define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA384
  382. #endif
  383. #ifdef HAVE_AESGCM
  384. #define BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384
  385. #endif
  386. #endif
  387. #endif
  388. #endif
  389. #if !defined(NO_TLS) && defined(HAVE_NULL_CIPHER)
  390. #if !defined(NO_RSA)
  391. #if defined(WOLFSSL_STATIC_RSA)
  392. #ifndef NO_MD5
  393. #define BUILD_TLS_RSA_WITH_NULL_MD5
  394. #endif
  395. #if !defined(NO_SHA)
  396. #define BUILD_TLS_RSA_WITH_NULL_SHA
  397. #endif
  398. #ifndef NO_SHA256
  399. #define BUILD_TLS_RSA_WITH_NULL_SHA256
  400. #endif
  401. #endif
  402. #endif
  403. #if !defined(NO_PSK) && defined(WOLFSSL_STATIC_PSK)
  404. #if !defined(NO_SHA)
  405. #define BUILD_TLS_PSK_WITH_NULL_SHA
  406. #endif
  407. #ifndef NO_SHA256
  408. #define BUILD_TLS_PSK_WITH_NULL_SHA256
  409. #endif
  410. #ifdef WOLFSSL_SHA384
  411. #define BUILD_TLS_PSK_WITH_NULL_SHA384
  412. #endif
  413. #endif
  414. #endif
  415. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  416. !defined(NO_RSA)
  417. #if !defined(NO_SHA)
  418. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  419. #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  420. #endif
  421. #if defined(WOLFSSL_AES_256) && defined(HAVE_AES_CBC)
  422. #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
  423. #endif
  424. #if !defined(NO_DES3)
  425. #define BUILD_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
  426. #endif
  427. #endif
  428. #if !defined(NO_SHA256) && defined(HAVE_AES_CBC)
  429. #ifdef WOLFSSL_AES_128
  430. #define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
  431. #endif
  432. #ifdef WOLFSSL_AES_256
  433. #define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
  434. #endif
  435. #endif
  436. #endif
  437. #if defined(HAVE_ANON) && !defined(NO_TLS) && !defined(NO_DH) && \
  438. !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  439. #ifdef HAVE_AES_CBC
  440. #define BUILD_TLS_DH_anon_WITH_AES_128_CBC_SHA
  441. #endif
  442. #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM)
  443. #define BUILD_TLS_DH_anon_WITH_AES_256_GCM_SHA384
  444. #endif
  445. #endif
  446. #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
  447. #ifndef NO_SHA256
  448. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && \
  449. defined(HAVE_AES_CBC)
  450. #define BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
  451. #endif
  452. #ifdef HAVE_NULL_CIPHER
  453. #define BUILD_TLS_DHE_PSK_WITH_NULL_SHA256
  454. #endif
  455. #endif
  456. #ifdef WOLFSSL_SHA384
  457. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && \
  458. defined(HAVE_AES_CBC)
  459. #define BUILD_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
  460. #endif
  461. #ifdef HAVE_NULL_CIPHER
  462. #define BUILD_TLS_DHE_PSK_WITH_NULL_SHA384
  463. #endif
  464. #endif
  465. #endif
  466. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || \
  467. defined(HAVE_CURVE448)) && !defined(NO_TLS)
  468. #if !defined(NO_AES)
  469. #if !defined(NO_SHA) && defined(HAVE_AES_CBC)
  470. #if !defined(NO_RSA)
  471. #ifdef WOLFSSL_AES_128
  472. #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
  473. #endif
  474. #ifdef WOLFSSL_AES_256
  475. #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
  476. #endif
  477. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  478. #ifdef WOLFSSL_AES_128
  479. #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
  480. #endif
  481. #ifdef WOLFSSL_AES_256
  482. #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
  483. #endif
  484. #endif
  485. #endif
  486. #if defined(HAVE_ECC) || \
  487. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  488. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  489. #ifdef WOLFSSL_AES_128
  490. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
  491. #endif
  492. #ifdef WOLFSSL_AES_256
  493. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
  494. #endif
  495. #endif
  496. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  497. #ifdef WOLFSSL_AES_128
  498. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
  499. #endif
  500. #ifdef WOLFSSL_AES_256
  501. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
  502. #endif
  503. #endif
  504. #endif /* NO_SHA */
  505. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  506. defined(HAVE_AES_CBC)
  507. #if !defined(NO_RSA)
  508. #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  509. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  510. #define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
  511. #endif
  512. #endif
  513. #if defined(HAVE_ECC) || \
  514. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  515. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  516. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
  517. #endif
  518. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  519. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
  520. #endif
  521. #endif
  522. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  523. defined(HAVE_AES_CBC)
  524. #if !defined(NO_RSA)
  525. #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
  526. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  527. #define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
  528. #endif
  529. #endif
  530. #if defined(HAVE_ECC) || \
  531. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  532. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  533. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
  534. #endif
  535. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  536. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
  537. #endif
  538. #endif
  539. #if defined (HAVE_AESGCM)
  540. #if !defined(NO_RSA)
  541. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  542. #ifdef WOLFSSL_AES_128
  543. #define BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
  544. #endif
  545. #endif
  546. #if defined(WOLFSSL_SHA384)
  547. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  548. #ifdef WOLFSSL_AES_256
  549. #define BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
  550. #endif
  551. #endif
  552. #endif
  553. #endif
  554. #if defined(WOLFSSL_STATIC_DH) && defined(WOLFSSL_AES_128) && \
  555. defined(HAVE_ECC)
  556. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
  557. #endif
  558. #if defined(WOLFSSL_SHA384)
  559. #if defined(WOLFSSL_STATIC_DH) && \
  560. defined(WOLFSSL_AES_256) && defined(HAVE_ECC)
  561. #define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
  562. #endif
  563. #endif
  564. #endif
  565. #endif /* NO_AES */
  566. #if !defined(NO_RC4)
  567. #if !defined(NO_SHA)
  568. #if !defined(NO_RSA)
  569. #ifndef WOLFSSL_AEAD_ONLY
  570. #define BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA
  571. #endif
  572. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  573. #define BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA
  574. #endif
  575. #endif
  576. #if defined(HAVE_ECC) || \
  577. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  578. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  579. #ifndef WOLFSSL_AEAD_ONLY
  580. #define BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
  581. #endif
  582. #endif
  583. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  584. #define BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
  585. #endif
  586. #endif
  587. #endif
  588. #if !defined(NO_DES3)
  589. #ifndef NO_SHA
  590. #if !defined(NO_RSA)
  591. #define BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
  592. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  593. #define BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
  594. #endif
  595. #endif
  596. #if defined(HAVE_ECC) || \
  597. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  598. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  599. #define BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
  600. #endif
  601. #if defined(WOLFSSL_STATIC_DH) && defined(HAVE_ECC)
  602. #define BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
  603. #endif
  604. #endif /* NO_SHA */
  605. #endif
  606. #if defined(HAVE_NULL_CIPHER)
  607. #if !defined(NO_SHA)
  608. #if defined(HAVE_ECC) || \
  609. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  610. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  611. #define BUILD_TLS_ECDHE_ECDSA_WITH_NULL_SHA
  612. #endif
  613. #endif
  614. #if !defined(NO_PSK) && !defined(NO_SHA256)
  615. #define BUILD_TLS_ECDHE_PSK_WITH_NULL_SHA256
  616. #endif
  617. #endif
  618. #if !defined(NO_PSK) && !defined(NO_SHA256) && !defined(NO_AES) && \
  619. defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  620. #define BUILD_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
  621. #endif
  622. #endif
  623. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  624. #if !defined(NO_OLD_POLY1305)
  625. #if defined(HAVE_ECC) || \
  626. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  627. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  628. #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256
  629. #endif
  630. #if !defined(NO_RSA) && defined(HAVE_ECC)
  631. #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
  632. #endif
  633. #if !defined(NO_DH) && !defined(NO_RSA)
  634. #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256
  635. #endif
  636. #endif /* NO_OLD_POLY1305 */
  637. #if !defined(NO_PSK)
  638. #define BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256
  639. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || \
  640. defined(HAVE_ED448)
  641. #define BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256
  642. #endif
  643. #ifndef NO_DH
  644. #define BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256
  645. #endif
  646. #endif /* !NO_PSK */
  647. #endif
  648. #endif /* !WOLFSSL_MAX_STRENGTH */
  649. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  650. !defined(NO_RSA) && defined(HAVE_AESGCM)
  651. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  652. #define BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
  653. #endif
  654. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  655. #define BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
  656. #endif
  657. #endif
  658. #if !defined(NO_DH) && !defined(NO_PSK) && !defined(NO_TLS)
  659. #ifndef NO_SHA256
  660. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  661. #define BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
  662. #endif
  663. #ifdef HAVE_AESCCM
  664. #ifdef WOLFSSL_AES_128
  665. #define BUILD_TLS_DHE_PSK_WITH_AES_128_CCM
  666. #endif
  667. #ifdef WOLFSSL_AES_256
  668. #define BUILD_TLS_DHE_PSK_WITH_AES_256_CCM
  669. #endif
  670. #endif
  671. #endif
  672. #if defined(WOLFSSL_SHA384) && defined(HAVE_AESGCM) && \
  673. defined(WOLFSSL_AES_256)
  674. #define BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
  675. #endif
  676. #endif
  677. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  678. && !defined(NO_TLS) && !defined(NO_AES)
  679. #ifdef HAVE_AESGCM
  680. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  681. #if defined(HAVE_ECC) || \
  682. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  683. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  684. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  685. #endif
  686. #ifndef NO_RSA
  687. #define BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  688. #endif
  689. #endif
  690. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  691. #if defined(HAVE_ECC) || \
  692. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  693. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  694. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
  695. #endif
  696. #ifndef NO_RSA
  697. #define BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  698. #endif
  699. #endif
  700. #endif
  701. #if defined(HAVE_AESCCM) && !defined(NO_SHA256)
  702. #if defined(HAVE_ECC) || \
  703. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  704. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  705. #ifdef WOLFSSL_AES_128
  706. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM
  707. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
  708. #endif
  709. #ifdef WOLFSSL_AES_256
  710. #define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
  711. #endif
  712. #endif
  713. #endif
  714. #endif
  715. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  716. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  717. #if defined(HAVE_ECC) || \
  718. (defined(HAVE_CURVE25519) && defined(HAVE_ED25519)) || \
  719. (defined(HAVE_CURVE448) && defined(HAVE_ED448))
  720. #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
  721. #endif
  722. #ifndef NO_RSA
  723. #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  724. #endif
  725. #endif
  726. #if !defined(NO_DH) && !defined(NO_RSA)
  727. #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  728. #endif
  729. #endif
  730. #endif
  731. #if defined(WOLFSSL_TLS13)
  732. #ifdef HAVE_AESGCM
  733. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  734. #define BUILD_TLS_AES_128_GCM_SHA256
  735. #endif
  736. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  737. #define BUILD_TLS_AES_256_GCM_SHA384
  738. #endif
  739. #endif
  740. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  741. #ifndef NO_SHA256
  742. #define BUILD_TLS_CHACHA20_POLY1305_SHA256
  743. #endif
  744. #endif
  745. #ifdef HAVE_AESCCM
  746. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  747. #define BUILD_TLS_AES_128_CCM_SHA256
  748. #define BUILD_TLS_AES_128_CCM_8_SHA256
  749. #endif
  750. #endif
  751. #ifdef HAVE_NULL_CIPHER
  752. #ifndef NO_SHA256
  753. #define BUILD_TLS_SHA256_SHA256
  754. #endif
  755. #ifdef WOLFSSL_SHA384
  756. #define BUILD_TLS_SHA384_SHA384
  757. #endif
  758. #endif
  759. #endif
  760. #if !defined(WOLFCRYPT_ONLY) && defined(NO_PSK) && \
  761. (defined(NO_DH) || !defined(HAVE_ANON)) && \
  762. defined(NO_RSA) && !defined(HAVE_ECC) && \
  763. !defined(HAVE_ED25519) && !defined(HAVE_ED448)
  764. #error "No cipher suites available with this build"
  765. #endif
  766. #ifdef WOLFSSL_MULTICAST
  767. #if defined(HAVE_NULL_CIPHER) && !defined(NO_SHA256)
  768. #define BUILD_WDM_WITH_NULL_SHA256
  769. #endif
  770. #endif
  771. #if defined(BUILD_SSL_RSA_WITH_RC4_128_SHA) || \
  772. defined(BUILD_SSL_RSA_WITH_RC4_128_MD5)
  773. #define BUILD_ARC4
  774. #endif
  775. #if defined(BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA)
  776. #define BUILD_DES3
  777. #endif
  778. #if defined(BUILD_TLS_RSA_WITH_AES_128_CBC_SHA) || \
  779. defined(BUILD_TLS_RSA_WITH_AES_256_CBC_SHA) || \
  780. defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) || \
  781. defined(BUILD_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256)
  782. #undef BUILD_AES
  783. #define BUILD_AES
  784. #endif
  785. #if defined(BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256) || \
  786. defined(BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256) || \
  787. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) || \
  788. defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) || \
  789. defined(BUILD_TLS_PSK_WITH_AES_128_GCM_SHA256) || \
  790. defined(BUILD_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256) || \
  791. defined(BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384) || \
  792. defined(BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384) || \
  793. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) || \
  794. defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384) || \
  795. defined(BUILD_TLS_PSK_WITH_AES_256_GCM_SHA384) || \
  796. defined(BUILD_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384) || \
  797. defined(BUILD_TLS_AES_128_GCM_SHA256) || \
  798. defined(BUILD_TLS_AES_256_GCM_SHA384)
  799. #define BUILD_AESGCM
  800. #else
  801. /* No AES-GCM cipher suites available with build */
  802. #define NO_AESGCM_AEAD
  803. #endif
  804. #if defined(BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256) || \
  805. defined(BUILD_TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
  806. defined(BUILD_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
  807. defined(BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256) || \
  808. defined(BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
  809. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) || \
  810. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256) || \
  811. defined(BUILD_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
  812. defined(BUILD_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256) || \
  813. defined(BUILD_TLS_CHACHA20_POLY1305_SHA256)
  814. /* Have an available ChaCha Poly cipher suite */
  815. #else
  816. /* No ChaCha Poly cipher suites available with build */
  817. #define NO_CHAPOL_AEAD
  818. #endif
  819. #ifdef NO_DES3
  820. #define DES_BLOCK_SIZE 8
  821. #else
  822. #undef BUILD_DES3
  823. #define BUILD_DES3
  824. #endif
  825. #if defined(NO_AES) || !defined(HAVE_AES_DECRYPT)
  826. #define AES_BLOCK_SIZE 16
  827. #undef BUILD_AES
  828. #else
  829. #undef BUILD_AES
  830. #define BUILD_AES
  831. #endif
  832. #ifndef NO_RC4
  833. #undef BUILD_ARC4
  834. #define BUILD_ARC4
  835. #endif
  836. #ifdef HAVE_CHACHA
  837. #define CHACHA20_BLOCK_SIZE 16
  838. #endif
  839. #if defined(WOLFSSL_MAX_STRENGTH) || \
  840. (defined(HAVE_AESGCM) && !defined(NO_AESGCM_AEAD)) || \
  841. defined(HAVE_AESCCM) || \
  842. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && \
  843. !defined(NO_CHAPOL_AEAD)) || \
  844. (defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER))
  845. #define HAVE_AEAD
  846. #endif
  847. #if defined(WOLFSSL_MAX_STRENGTH) || \
  848. defined(HAVE_ECC) || !defined(NO_DH)
  849. #define HAVE_PFS
  850. #endif
  851. /* actual cipher values, 2nd byte */
  852. enum {
  853. TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x16,
  854. TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x39,
  855. TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x33,
  856. TLS_DH_anon_WITH_AES_128_CBC_SHA = 0x34,
  857. TLS_RSA_WITH_AES_256_CBC_SHA = 0x35,
  858. TLS_RSA_WITH_AES_128_CBC_SHA = 0x2F,
  859. TLS_RSA_WITH_NULL_MD5 = 0x01,
  860. TLS_RSA_WITH_NULL_SHA = 0x02,
  861. TLS_PSK_WITH_AES_256_CBC_SHA = 0x8d,
  862. TLS_PSK_WITH_AES_128_CBC_SHA256 = 0xae,
  863. TLS_PSK_WITH_AES_256_CBC_SHA384 = 0xaf,
  864. TLS_PSK_WITH_AES_128_CBC_SHA = 0x8c,
  865. TLS_PSK_WITH_NULL_SHA256 = 0xb0,
  866. TLS_PSK_WITH_NULL_SHA384 = 0xb1,
  867. TLS_PSK_WITH_NULL_SHA = 0x2c,
  868. SSL_RSA_WITH_RC4_128_SHA = 0x05,
  869. SSL_RSA_WITH_RC4_128_MD5 = 0x04,
  870. SSL_RSA_WITH_3DES_EDE_CBC_SHA = 0x0A,
  871. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  872. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0x14,
  873. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0x13,
  874. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0x0A,
  875. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0x09,
  876. TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0x11,
  877. TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0x07,
  878. TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x12,
  879. TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x08,
  880. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0x27,
  881. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0x23,
  882. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0x28,
  883. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0x24,
  884. TLS_ECDHE_ECDSA_WITH_NULL_SHA = 0x06,
  885. TLS_ECDHE_PSK_WITH_NULL_SHA256 = 0x3a,
  886. TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 = 0x37,
  887. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  888. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0x0F,
  889. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0x0E,
  890. TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0x05,
  891. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0x04,
  892. TLS_ECDH_RSA_WITH_RC4_128_SHA = 0x0C,
  893. TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0x02,
  894. TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0D,
  895. TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x03,
  896. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0x29,
  897. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0x25,
  898. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0x2A,
  899. TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0x26,
  900. WDM_WITH_NULL_SHA256 = 0xFE, /* wolfSSL DTLS Multicast */
  901. /* SHA256 */
  902. TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x6b,
  903. TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x67,
  904. TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x3d,
  905. TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x3c,
  906. TLS_RSA_WITH_NULL_SHA256 = 0x3b,
  907. TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 = 0xb2,
  908. TLS_DHE_PSK_WITH_NULL_SHA256 = 0xb4,
  909. /* SHA384 */
  910. TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 = 0xb3,
  911. TLS_DHE_PSK_WITH_NULL_SHA384 = 0xb5,
  912. /* AES-GCM */
  913. TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x9c,
  914. TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x9d,
  915. TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x9e,
  916. TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x9f,
  917. TLS_DH_anon_WITH_AES_256_GCM_SHA384 = 0xa7,
  918. TLS_PSK_WITH_AES_128_GCM_SHA256 = 0xa8,
  919. TLS_PSK_WITH_AES_256_GCM_SHA384 = 0xa9,
  920. TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 = 0xaa,
  921. TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 = 0xab,
  922. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  923. TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2b,
  924. TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2c,
  925. TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2d,
  926. TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2e,
  927. TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0x2f,
  928. TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0x30,
  929. TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0x31,
  930. TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0x32,
  931. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  932. * also, in some of the other AES-CCM suites
  933. * there will be second byte number conflicts
  934. * with non-ECC AES-GCM */
  935. TLS_RSA_WITH_AES_128_CCM_8 = 0xa0,
  936. TLS_RSA_WITH_AES_256_CCM_8 = 0xa1,
  937. TLS_ECDHE_ECDSA_WITH_AES_128_CCM = 0xac,
  938. TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xae,
  939. TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xaf,
  940. TLS_PSK_WITH_AES_128_CCM = 0xa4,
  941. TLS_PSK_WITH_AES_256_CCM = 0xa5,
  942. TLS_PSK_WITH_AES_128_CCM_8 = 0xa8,
  943. TLS_PSK_WITH_AES_256_CCM_8 = 0xa9,
  944. TLS_DHE_PSK_WITH_AES_128_CCM = 0xa6,
  945. TLS_DHE_PSK_WITH_AES_256_CCM = 0xa7,
  946. /* Camellia */
  947. TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x41,
  948. TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x84,
  949. TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xba,
  950. TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc0,
  951. TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x45,
  952. TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x88,
  953. TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xbe,
  954. TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc4,
  955. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  956. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xa8,
  957. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xa9,
  958. TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xaa,
  959. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xac,
  960. TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xab,
  961. TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 = 0xad,
  962. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  963. TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x13,
  964. TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x14,
  965. TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 = 0x15,
  966. /* TLS v1.3 cipher suites */
  967. TLS_AES_128_GCM_SHA256 = 0x01,
  968. TLS_AES_256_GCM_SHA384 = 0x02,
  969. TLS_CHACHA20_POLY1305_SHA256 = 0x03,
  970. TLS_AES_128_CCM_SHA256 = 0x04,
  971. TLS_AES_128_CCM_8_SHA256 = 0x05,
  972. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  973. TLS_SHA256_SHA256 = 0xB4,
  974. TLS_SHA384_SHA384 = 0xB5,
  975. /* Fallback SCSV (Signaling Cipher Suite Value) */
  976. TLS_FALLBACK_SCSV = 0x56,
  977. /* Renegotiation Indication Extension Special Suite */
  978. TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0xff
  979. };
  980. #ifndef WOLFSSL_SESSION_TIMEOUT
  981. #define WOLFSSL_SESSION_TIMEOUT 500
  982. /* default session resumption cache timeout in seconds */
  983. #endif
  984. #ifndef WOLFSSL_DTLS_WINDOW_WORDS
  985. #define WOLFSSL_DTLS_WINDOW_WORDS 2
  986. #endif /* WOLFSSL_DTLS_WINDOW_WORDS */
  987. #define DTLS_WORD_BITS (sizeof(word32) * CHAR_BIT)
  988. #define DTLS_SEQ_BITS (WOLFSSL_DTLS_WINDOW_WORDS * DTLS_WORD_BITS)
  989. #define DTLS_SEQ_SZ (sizeof(word32) * WOLFSSL_DTLS_WINDOW_WORDS)
  990. #ifndef WOLFSSL_MULTICAST
  991. #define WOLFSSL_DTLS_PEERSEQ_SZ 1
  992. #else
  993. #ifndef WOLFSSL_MULTICAST_PEERS
  994. /* max allowed multicast group peers */
  995. #define WOLFSSL_MULTICAST_PEERS 100
  996. #endif
  997. #define WOLFSSL_DTLS_PEERSEQ_SZ WOLFSSL_MULTICAST_PEERS
  998. #endif /* WOLFSSL_MULTICAST */
  999. #ifndef WOLFSSL_MAX_MTU
  1000. /* 1500 - 100 bytes to account for UDP and IP headers */
  1001. #define WOLFSSL_MAX_MTU 1400
  1002. #endif /* WOLFSSL_MAX_MTU */
  1003. #ifndef WOLFSSL_DTLS_MTU_ADDITIONAL_READ_BUFFER
  1004. #define WOLFSSL_DTLS_MTU_ADDITIONAL_READ_BUFFER 500
  1005. #endif /* WOLFSSL_DTLS_MTU_ADDITIONAL_READ_BUFFER */
  1006. /* set minimum DH key size allowed */
  1007. #ifndef WOLFSSL_MIN_DHKEY_BITS
  1008. #ifdef WOLFSSL_MAX_STRENGTH
  1009. #define WOLFSSL_MIN_DHKEY_BITS 2048
  1010. #else
  1011. #define WOLFSSL_MIN_DHKEY_BITS 1024
  1012. #endif
  1013. #endif
  1014. #if (WOLFSSL_MIN_DHKEY_BITS % 8)
  1015. #error DH minimum bit size must be multiple of 8
  1016. #endif
  1017. #if (WOLFSSL_MIN_DHKEY_BITS > 16000)
  1018. #error DH minimum bit size must not be greater than 16000
  1019. #endif
  1020. #define MIN_DHKEY_SZ (WOLFSSL_MIN_DHKEY_BITS / 8)
  1021. /* set maximum DH key size allowed */
  1022. #ifndef WOLFSSL_MAX_DHKEY_BITS
  1023. #if (defined(USE_FAST_MATH) && defined(FP_MAX_BITS) && FP_MAX_BITS >= 16384)
  1024. #define WOLFSSL_MAX_DHKEY_BITS (FP_MAX_BITS / 2)
  1025. #else
  1026. #define WOLFSSL_MAX_DHKEY_BITS 4096
  1027. #endif
  1028. #endif
  1029. #if (WOLFSSL_MAX_DHKEY_BITS % 8)
  1030. #error DH maximum bit size must be multiple of 8
  1031. #endif
  1032. #if (WOLFSSL_MAX_DHKEY_BITS > 16384)
  1033. #error DH maximum bit size must not be greater than 16384
  1034. #endif
  1035. #define MAX_DHKEY_SZ (WOLFSSL_MAX_DHKEY_BITS / 8)
  1036. #ifndef MAX_PSK_ID_LEN
  1037. /* max psk identity/hint supported */
  1038. #if defined(WOLFSSL_TLS13)
  1039. /* OpenSSL has a 1472 byte session ticket */
  1040. #define MAX_PSK_ID_LEN 1536
  1041. #else
  1042. #define MAX_PSK_ID_LEN 128
  1043. #endif
  1044. #endif
  1045. #ifndef MAX_EARLY_DATA_SZ
  1046. /* maximum early data size */
  1047. #define MAX_EARLY_DATA_SZ 4096
  1048. #endif
  1049. #ifndef WOLFSSL_MAX_RSA_BITS
  1050. #if (defined(USE_FAST_MATH) && defined(FP_MAX_BITS) && FP_MAX_BITS >= 16384)
  1051. #define WOLFSSL_MAX_RSA_BITS (FP_MAX_BITS / 2)
  1052. #else
  1053. #define WOLFSSL_MAX_RSA_BITS 4096
  1054. #endif
  1055. #endif
  1056. #if (WOLFSSL_MAX_RSA_BITS % 8)
  1057. #error RSA maximum bit size must be multiple of 8
  1058. #endif
  1059. enum Misc {
  1060. CIPHER_BYTE = 0x00, /* Default ciphers */
  1061. ECC_BYTE = 0xC0, /* ECC first cipher suite byte */
  1062. CHACHA_BYTE = 0xCC, /* ChaCha first cipher suite */
  1063. TLS13_BYTE = 0x13, /* TLS v1.3 first byte of cipher suite */
  1064. SEND_CERT = 1,
  1065. SEND_BLANK_CERT = 2,
  1066. DTLS_MAJOR = 0xfe, /* DTLS major version number */
  1067. DTLS_MINOR = 0xff, /* DTLS minor version number */
  1068. DTLSv1_2_MINOR = 0xfd, /* DTLS minor version number */
  1069. SSLv3_MAJOR = 3, /* SSLv3 and TLSv1+ major version number */
  1070. SSLv3_MINOR = 0, /* TLSv1 minor version number */
  1071. TLSv1_MINOR = 1, /* TLSv1 minor version number */
  1072. TLSv1_1_MINOR = 2, /* TLSv1_1 minor version number */
  1073. TLSv1_2_MINOR = 3, /* TLSv1_2 minor version number */
  1074. TLSv1_3_MINOR = 4, /* TLSv1_3 minor version number */
  1075. TLS_DRAFT_MAJOR = 0x7f, /* Draft TLS major version number */
  1076. OLD_HELLO_ID = 0x01, /* SSLv2 Client Hello Indicator */
  1077. INVALID_BYTE = 0xff, /* Used to initialize cipher specs values */
  1078. NO_COMPRESSION = 0,
  1079. ZLIB_COMPRESSION = 221, /* wolfSSL zlib compression */
  1080. HELLO_EXT_SIG_ALGO = 13, /* ID for the sig_algo hello extension */
  1081. HELLO_EXT_EXTMS = 0x0017, /* ID for the extended master secret ext */
  1082. SECRET_LEN = WOLFSSL_MAX_MASTER_KEY_LENGTH,
  1083. /* pre RSA and all master */
  1084. TIMESTAMP_LEN = 4, /* timestamp size in ticket */
  1085. #ifdef WOLFSSL_TLS13
  1086. AGEADD_LEN = 4, /* ageAdd size in ticket */
  1087. NAMEDGROUP_LEN = 2, /* namedGroup size in ticket */
  1088. #ifdef WOLFSSL_EARLY_DATA
  1089. MAXEARLYDATASZ_LEN = 4, /* maxEarlyDataSz size in ticket */
  1090. #endif
  1091. #endif
  1092. #ifdef HAVE_PQC
  1093. ENCRYPT_LEN = 1500, /* allow 1500 bit static buffer for falcon */
  1094. #else
  1095. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || \
  1096. (defined(USE_FAST_MATH) && defined(FP_MAX_BITS) && FP_MAX_BITS >= 16384)
  1097. #if !defined(NO_PSK) && defined(USE_FAST_MATH)
  1098. ENCRYPT_LEN = (FP_MAX_BITS / 2 / 8) + MAX_PSK_ID_LEN + 2,
  1099. #else
  1100. ENCRYPT_LEN = 1024, /* allow 8192 bit static buffer */
  1101. #endif
  1102. #else
  1103. #ifndef NO_PSK
  1104. ENCRYPT_LEN = 512 + MAX_PSK_ID_LEN + 2, /* 4096 bit static buffer */
  1105. #else
  1106. ENCRYPT_LEN = 512, /* allow 4096 bit static buffer */
  1107. #endif
  1108. #endif
  1109. #endif
  1110. SIZEOF_SENDER = 4, /* clnt or srvr */
  1111. FINISHED_SZ = 36, /* WC_MD5_DIGEST_SIZE + WC_SHA_DIGEST_SIZE */
  1112. MAX_RECORD_SIZE = 16384, /* 2^14, max size by standard */
  1113. MAX_PLAINTEXT_SZ = (1 << 14), /* Max plaintext sz */
  1114. MAX_TLS_CIPHER_SZ = (1 << 14) + 2048, /* Max TLS encrypted data sz */
  1115. #ifdef WOLFSSL_TLS13
  1116. MAX_TLS13_PLAIN_SZ = (1 << 14) + 1, /* Max unencrypted data sz */
  1117. MAX_TLS13_ENC_SZ = (1 << 14) + 256, /* Max encrypted data sz */
  1118. #endif
  1119. MAX_MSG_EXTRA = 38 + WC_MAX_DIGEST_SIZE,
  1120. /* max added to msg, mac + pad from */
  1121. /* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max
  1122. digest sz + BLOC_SZ (iv) + pad byte (1) */
  1123. MAX_COMP_EXTRA = 1024, /* max compression extra */
  1124. MAX_MTU = WOLFSSL_MAX_MTU, /* max expected MTU */
  1125. MAX_UDP_SIZE = 8192 - 100, /* was MAX_MTU - 100 */
  1126. MAX_DH_SZ = (MAX_DHKEY_SZ * 3) + 12, /* DH_P, DH_G and DH_Pub */
  1127. /* 4096 p, pub, g + 2 byte size for each */
  1128. MAX_STR_VERSION = 8, /* string rep of protocol version */
  1129. PAD_MD5 = 48, /* pad length for finished */
  1130. PAD_SHA = 40, /* pad length for finished */
  1131. MAX_PAD_SIZE = 256, /* maximum length of padding */
  1132. LENGTH_SZ = 2, /* length field for HMAC, data only */
  1133. VERSION_SZ = 2, /* length of proctocol version */
  1134. SEQ_SZ = 8, /* 64 bit sequence number */
  1135. ALERT_SIZE = 2, /* level + description */
  1136. VERIFY_HEADER = 2, /* always use 2 bytes */
  1137. EXTS_SZ = 2, /* always use 2 bytes */
  1138. EXT_ID_SZ = 2, /* always use 2 bytes */
  1139. MAX_DH_SIZE = MAX_DHKEY_SZ+1,
  1140. /* Max size plus possible leading 0 */
  1141. MIN_FFHDE_GROUP = 0x100, /* Named group minimum for FFDHE parameters */
  1142. MAX_FFHDE_GROUP = 0x1FF, /* Named group maximum for FFDHE parameters */
  1143. SESSION_HINT_SZ = 4, /* session timeout hint */
  1144. SESSION_ADD_SZ = 4, /* session age add */
  1145. TICKET_NONCE_LEN_SZ = 1, /* Ticket nonce length size */
  1146. DEF_TICKET_NONCE_SZ = 1, /* Default ticket nonce size */
  1147. MAX_TICKET_NONCE_SZ = 8, /* maximum ticket nonce size */
  1148. MAX_LIFETIME = 604800, /* maximum ticket lifetime */
  1149. RAN_LEN = 32, /* random length */
  1150. SEED_LEN = RAN_LEN * 2, /* tls prf seed length */
  1151. ID_LEN = 32, /* session id length */
  1152. COOKIE_SECRET_SZ = 14, /* dtls cookie secret size */
  1153. MAX_COOKIE_LEN = 32, /* max dtls cookie size */
  1154. COOKIE_SZ = 20, /* use a 20 byte cookie */
  1155. SUITE_LEN = 2, /* cipher suite sz length */
  1156. ENUM_LEN = 1, /* always a byte */
  1157. OPAQUE8_LEN = 1, /* 1 byte */
  1158. OPAQUE16_LEN = 2, /* 2 bytes */
  1159. OPAQUE24_LEN = 3, /* 3 bytes */
  1160. OPAQUE32_LEN = 4, /* 4 bytes */
  1161. OPAQUE64_LEN = 8, /* 8 bytes */
  1162. COMP_LEN = 1, /* compression length */
  1163. CURVE_LEN = 2, /* ecc named curve length */
  1164. KE_GROUP_LEN = 2, /* key exchange group length */
  1165. SERVER_ID_LEN = 20, /* server session id length */
  1166. HANDSHAKE_HEADER_SZ = 4, /* type + length(3) */
  1167. RECORD_HEADER_SZ = 5, /* type + version + len(2) */
  1168. CERT_HEADER_SZ = 3, /* always 3 bytes */
  1169. REQ_HEADER_SZ = 2, /* cert request header sz */
  1170. HINT_LEN_SZ = 2, /* length of hint size field */
  1171. TRUNCATED_HMAC_SZ = 10, /* length of hmac w/ truncated hmac extension */
  1172. HELLO_EXT_SZ = 4, /* base length of a hello extension */
  1173. HELLO_EXT_TYPE_SZ = 2, /* length of a hello extension type */
  1174. HELLO_EXT_SZ_SZ = 2, /* length of a hello extension size */
  1175. HELLO_EXT_SIGALGO_SZ = 2, /* length of number of items in sigalgo list */
  1176. DTLS_HANDSHAKE_HEADER_SZ = 12, /* normal + seq(2) + offset(3) + length(3) */
  1177. DTLS_RECORD_HEADER_SZ = 13, /* normal + epoch(2) + seq_num(6) */
  1178. DTLS_HANDSHAKE_EXTRA = 8, /* diff from normal */
  1179. DTLS_RECORD_EXTRA = 8, /* diff from normal */
  1180. DTLS_HANDSHAKE_SEQ_SZ = 2, /* handshake header sequence number */
  1181. DTLS_HANDSHAKE_FRAG_SZ = 3, /* fragment offset and length are 24 bit */
  1182. DTLS_POOL_SZ = 255,/* allowed number of list items in TX pool */
  1183. DTLS_EXPORT_PRO = 165,/* wolfSSL protocol for serialized session */
  1184. DTLS_EXPORT_STATE_PRO = 166,/* wolfSSL protocol for serialized state */
  1185. TLS_EXPORT_PRO = 167,/* wolfSSL protocol for serialized TLS */
  1186. DTLS_EXPORT_OPT_SZ = 61, /* amount of bytes used from Options */
  1187. TLS_EXPORT_OPT_SZ = 65, /* amount of bytes used from Options */
  1188. DTLS_EXPORT_OPT_SZ_3 = 60, /* amount of bytes used from Options */
  1189. DTLS_EXPORT_KEY_SZ = 325 + (DTLS_SEQ_SZ * 2),
  1190. /* max amount of bytes used from Keys */
  1191. DTLS_EXPORT_MIN_KEY_SZ = 85 + (DTLS_SEQ_SZ * 2),
  1192. /* min amount of bytes used from Keys */
  1193. WOLFSSL_EXPORT_TLS = 1,
  1194. WOLFSSL_EXPORT_DTLS = 0,
  1195. #ifndef WOLFSSL_EXPORT_SPC_SZ
  1196. WOLFSSL_EXPORT_SPC_SZ = 16, /* amount of bytes used from CipherSpecs */
  1197. #endif
  1198. WOLFSSL_EXPORT_LEN = 2, /* 2 bytes for length and protocol */
  1199. WOLFSSL_EXPORT_VERSION = 4, /* wolfSSL version for serialized session */
  1200. /* older export versions supported */
  1201. WOLFSSL_EXPORT_VERSION_3 = 3, /* wolfSSL version before TLS 1.3 addition */
  1202. MAX_EXPORT_IP = 46, /* max ip size IPv4 mapped IPv6 */
  1203. DTLS_MTU_ADDITIONAL_READ_BUFFER = WOLFSSL_DTLS_MTU_ADDITIONAL_READ_BUFFER,
  1204. /* Additional bytes to read so that
  1205. * we can work with a peer that has
  1206. * a slightly different MTU than us. */
  1207. MAX_EXPORT_BUFFER = 514, /* max size of buffer for exporting */
  1208. MAX_EXPORT_STATE_BUFFER = (DTLS_EXPORT_MIN_KEY_SZ) + (3 * WOLFSSL_EXPORT_LEN),
  1209. /* max size of buffer for exporting state */
  1210. FINISHED_LABEL_SZ = 15, /* TLS finished label size */
  1211. TLS_FINISHED_SZ = 12, /* TLS has a shorter size */
  1212. TLS_FINISHED_SZ_MAX = WC_MAX_DIGEST_SIZE,
  1213. /* longest message digest size is SHA512, 64 */
  1214. EXT_MASTER_LABEL_SZ = 22, /* TLS extended master secret label sz */
  1215. MASTER_LABEL_SZ = 13, /* TLS master secret label sz */
  1216. KEY_LABEL_SZ = 13, /* TLS key block expansion sz */
  1217. PROTOCOL_LABEL_SZ = 9, /* Length of the protocol label */
  1218. MAX_LABEL_SZ = 34, /* Maximum length of a label */
  1219. MAX_REQUEST_SZ = 256, /* Maximum cert req len (no auth yet */
  1220. SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */
  1221. TLS_MAX_PAD_SZ = 255, /* Max padding in TLS */
  1222. #if defined(HAVE_FIPS) && \
  1223. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
  1224. MAX_SYM_KEY_SIZE = AES_256_KEY_SIZE,
  1225. #else
  1226. #if defined(HAVE_NULL_CIPHER) && defined(WOLFSSL_TLS13)
  1227. #if defined(WOLFSSL_SHA384) && WC_MAX_SYM_KEY_SIZE < 48
  1228. MAX_SYM_KEY_SIZE = WC_SHA384_DIGEST_SIZE,
  1229. #elif !defined(NO_SHA256) && WC_MAX_SYM_KEY_SIZE < 32
  1230. MAX_SYM_KEY_SIZE = WC_SHA256_DIGEST_SIZE,
  1231. #else
  1232. MAX_SYM_KEY_SIZE = WC_MAX_SYM_KEY_SIZE,
  1233. #endif
  1234. #else
  1235. MAX_SYM_KEY_SIZE = WC_MAX_SYM_KEY_SIZE,
  1236. #endif
  1237. #endif
  1238. #if defined(HAVE_SELFTEST) && \
  1239. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  1240. #ifndef WOLFSSL_AES_KEY_SIZE_ENUM
  1241. #define WOLFSSL_AES_KEY_SIZE_ENUM
  1242. AES_IV_SIZE = 16,
  1243. AES_128_KEY_SIZE = 16,
  1244. AES_192_KEY_SIZE = 24,
  1245. AES_256_KEY_SIZE = 32,
  1246. #endif
  1247. #endif
  1248. MAX_IV_SZ = AES_BLOCK_SIZE,
  1249. AEAD_SEQ_OFFSET = 4, /* Auth Data: Sequence number */
  1250. AEAD_TYPE_OFFSET = 8, /* Auth Data: Type */
  1251. AEAD_VMAJ_OFFSET = 9, /* Auth Data: Major Version */
  1252. AEAD_VMIN_OFFSET = 10, /* Auth Data: Minor Version */
  1253. AEAD_LEN_OFFSET = 11, /* Auth Data: Length */
  1254. AEAD_AUTH_DATA_SZ = 13, /* Size of the data to authenticate */
  1255. AEAD_NONCE_SZ = 12,
  1256. AESGCM_IMP_IV_SZ = 4, /* Size of GCM/CCM AEAD implicit IV */
  1257. AESGCM_EXP_IV_SZ = 8, /* Size of GCM/CCM AEAD explicit IV */
  1258. AESGCM_NONCE_SZ = AESGCM_EXP_IV_SZ + AESGCM_IMP_IV_SZ,
  1259. CHACHA20_IMP_IV_SZ = 12, /* Size of ChaCha20 AEAD implicit IV */
  1260. CHACHA20_NONCE_SZ = 12, /* Size of ChacCha20 nonce */
  1261. CHACHA20_OLD_OFFSET = 4, /* Offset for seq # in old poly1305 */
  1262. /* For any new implicit/explicit IV size adjust AEAD_MAX_***_SZ */
  1263. AES_GCM_AUTH_SZ = 16, /* AES-GCM Auth Tag length */
  1264. AES_CCM_16_AUTH_SZ = 16, /* AES-CCM-16 Auth Tag length */
  1265. AES_CCM_8_AUTH_SZ = 8, /* AES-CCM-8 Auth Tag Length */
  1266. AESCCM_NONCE_SZ = 12,
  1267. CAMELLIA_128_KEY_SIZE = 16, /* for 128 bit */
  1268. CAMELLIA_192_KEY_SIZE = 24, /* for 192 bit */
  1269. CAMELLIA_256_KEY_SIZE = 32, /* for 256 bit */
  1270. CAMELLIA_IV_SIZE = 16, /* always block size */
  1271. CHACHA20_256_KEY_SIZE = 32, /* for 256 bit */
  1272. CHACHA20_128_KEY_SIZE = 16, /* for 128 bit */
  1273. CHACHA20_IV_SIZE = 12, /* 96 bits for iv */
  1274. POLY1305_AUTH_SZ = 16, /* 128 bits */
  1275. HMAC_NONCE_SZ = 12, /* Size of HMAC nonce */
  1276. EVP_SALT_SIZE = 8, /* evp salt size 64 bits */
  1277. #ifndef ECDHE_SIZE /* allow this to be overridden at compile-time */
  1278. ECDHE_SIZE = 32, /* ECDHE server size defaults to 256 bit */
  1279. #endif
  1280. MAX_EXPORT_ECC_SZ = 256, /* Export ANS X9.62 max future size */
  1281. MAX_CURVE_NAME_SZ = 16, /* Maximum size of curve name string */
  1282. NEW_SA_MAJOR = 8, /* Most significant byte used with new sig algos */
  1283. ED25519_SA_MAJOR = 8, /* Most significant byte for ED25519 */
  1284. ED25519_SA_MINOR = 7, /* Least significant byte for ED25519 */
  1285. ED448_SA_MAJOR = 8, /* Most significant byte for ED448 */
  1286. ED448_SA_MINOR = 8, /* Least significant byte for ED448 */
  1287. PQC_SA_MAJOR = 0xFE,/* Most significant byte used with PQC sig algos
  1288. */
  1289. /* These match what OQS has defined in their OpenSSL fork. */
  1290. FALCON_LEVEL1_SA_MAJOR = 0xFE,
  1291. FALCON_LEVEL1_SA_MINOR = 0x0B,
  1292. FALCON_LEVEL5_SA_MAJOR = 0xFE,
  1293. FALCON_LEVEL5_SA_MINOR = 0x0E,
  1294. MIN_RSA_SHA512_PSS_BITS = 512 * 2 + 8 * 8, /* Min key size */
  1295. MIN_RSA_SHA384_PSS_BITS = 384 * 2 + 8 * 8, /* Min key size */
  1296. #if defined(HAVE_PQC)
  1297. MAX_CERT_VERIFY_SZ = 1600, /* For Falcon */
  1298. #elif !defined(NO_RSA)
  1299. MAX_CERT_VERIFY_SZ = WOLFSSL_MAX_RSA_BITS / 8, /* max RSA bytes */
  1300. #elif defined(HAVE_ECC)
  1301. MAX_CERT_VERIFY_SZ = ECC_MAX_SIG_SIZE, /* max ECC */
  1302. #elif defined(HAVE_ED448)
  1303. MAX_CERT_VERIFY_SZ = ED448_SIG_SIZE, /* max Ed448 */
  1304. #elif defined(HAVE_ED25519)
  1305. MAX_CERT_VERIFY_SZ = ED25519_SIG_SIZE, /* max Ed25519 */
  1306. #else
  1307. MAX_CERT_VERIFY_SZ = 1024, /* max default */
  1308. #endif
  1309. CLIENT_HELLO_FIRST = 35, /* Protocol + RAN_LEN + sizeof(id_len) */
  1310. MAX_SUITE_NAME = 48, /* maximum length of cipher suite string */
  1311. DTLS_TIMEOUT_INIT = 1, /* default timeout init for DTLS receive */
  1312. DTLS_TIMEOUT_MAX = 64, /* default max timeout for DTLS receive */
  1313. DTLS_TIMEOUT_MULTIPLIER = 2, /* default timeout multiplier for DTLS recv */
  1314. NULL_TERM_LEN = 1, /* length of null '\0' termination character */
  1315. MAX_PSK_KEY_LEN = 64, /* max psk key supported */
  1316. MIN_PSK_ID_LEN = 6, /* min length of identities */
  1317. MIN_PSK_BINDERS_LEN = 33, /* min length of binders */
  1318. MAX_TICKET_AGE_DIFF = 10, /* maximum ticket age difference in seconds */
  1319. TLS13_MAX_TICKET_AGE = 7*24*60*60, /* max ticket age in seconds, 7 days */
  1320. #ifndef MAX_WOLFSSL_FILE_SIZE
  1321. MAX_WOLFSSL_FILE_SIZE = 1024UL * 1024UL * 4, /* 4 mb file size alloc limit */
  1322. #endif
  1323. #if defined(HAVE_PQC)
  1324. MAX_X509_SIZE = 5120, /* max static x509 buffer size; falcon is big */
  1325. #elif defined(WOLFSSL_HAPROXY)
  1326. MAX_X509_SIZE = 3072, /* max static x509 buffer size */
  1327. #else
  1328. MAX_X509_SIZE = 2048, /* max static x509 buffer size */
  1329. #endif
  1330. CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */
  1331. NO_SNIFF = 0, /* not sniffing */
  1332. SNIFF = 1, /* currently sniffing */
  1333. HASH_SIG_SIZE = 2, /* default SHA1 RSA */
  1334. NO_COPY = 0, /* should we copy static buffer for write */
  1335. COPY = 1, /* should we copy static buffer for write */
  1336. INVALID_PEER_ID = 0xFFFF, /* Initialize value for peer ID. */
  1337. PREV_ORDER = -1, /* Sequence number is in previous epoch. */
  1338. PEER_ORDER = 1, /* Peer sequence number for verify. */
  1339. CUR_ORDER = 0, /* Current sequence number. */
  1340. WRITE_PROTO = 1, /* writing a protocol message */
  1341. READ_PROTO = 0 /* reading a protocol message */
  1342. };
  1343. /* minimum Downgrade Minor version */
  1344. #ifndef WOLFSSL_MIN_DOWNGRADE
  1345. #ifndef NO_OLD_TLS
  1346. #define WOLFSSL_MIN_DOWNGRADE TLSv1_MINOR
  1347. #else
  1348. #define WOLFSSL_MIN_DOWNGRADE TLSv1_2_MINOR
  1349. #endif
  1350. #endif
  1351. /* Set max implicit IV size for AEAD cipher suites */
  1352. #define AEAD_MAX_IMP_SZ 12
  1353. /* Set max explicit IV size for AEAD cipher suites */
  1354. #define AEAD_MAX_EXP_SZ 8
  1355. #ifndef WOLFSSL_MAX_SUITE_SZ
  1356. #define WOLFSSL_MAX_SUITE_SZ 300
  1357. /* 150 suites for now! */
  1358. #endif
  1359. /* number of items in the signature algo list */
  1360. #ifndef WOLFSSL_MAX_SIGALGO
  1361. #define WOLFSSL_MAX_SIGALGO 38
  1362. #endif
  1363. /* set minimum ECC key size allowed */
  1364. #ifndef WOLFSSL_MIN_ECC_BITS
  1365. #ifdef WOLFSSL_MAX_STRENGTH
  1366. #define WOLFSSL_MIN_ECC_BITS 256
  1367. #else
  1368. #define WOLFSSL_MIN_ECC_BITS 224
  1369. #endif
  1370. #endif /* WOLFSSL_MIN_ECC_BITS */
  1371. #if (WOLFSSL_MIN_ECC_BITS % 8)
  1372. /* Some ECC keys are not divisible by 8 such as prime239v1 or sect131r1.
  1373. In these cases round down to the nearest value divisible by 8. The
  1374. restriction of being divisible by 8 is in place to match wc_ecc_size
  1375. function from wolfSSL.
  1376. */
  1377. #error ECC minimum bit size must be a multiple of 8
  1378. #endif
  1379. #define MIN_ECCKEY_SZ (WOLFSSL_MIN_ECC_BITS / 8)
  1380. #ifdef HAVE_PQC
  1381. /* set minimum Falcon key size allowed */
  1382. #ifndef MIN_FALCONKEY_SZ
  1383. #define MIN_FALCONKEY_SZ 897
  1384. #endif
  1385. #endif
  1386. /* set minimum RSA key size allowed */
  1387. #ifndef WOLFSSL_MIN_RSA_BITS
  1388. #ifdef WOLFSSL_MAX_STRENGTH
  1389. #define WOLFSSL_MIN_RSA_BITS 2048
  1390. #else
  1391. #define WOLFSSL_MIN_RSA_BITS 1024
  1392. #endif
  1393. #endif /* WOLFSSL_MIN_RSA_BITS */
  1394. #if (WOLFSSL_MIN_RSA_BITS % 8)
  1395. /* This is to account for the example case of a min size of 2050 bits but
  1396. still allows 2049 bit key. So we need the measurement to be in bytes. */
  1397. #error RSA minimum bit size must be a multiple of 8
  1398. #endif
  1399. #define MIN_RSAKEY_SZ (WOLFSSL_MIN_RSA_BITS / 8)
  1400. #ifdef SESSION_INDEX
  1401. /* Shift values for making a session index */
  1402. #define SESSIDX_ROW_SHIFT 4
  1403. #define SESSIDX_IDX_MASK 0x0F
  1404. #endif
  1405. /* max cert chain peer depth */
  1406. #ifndef MAX_CHAIN_DEPTH
  1407. #define MAX_CHAIN_DEPTH 9
  1408. #endif
  1409. /* max size of a certificate message payload */
  1410. /* assumes MAX_CHAIN_DEPTH number of certificates at 2kb per certificate */
  1411. #ifndef MAX_CERTIFICATE_SZ
  1412. #define MAX_CERTIFICATE_SZ \
  1413. (CERT_HEADER_SZ + \
  1414. (MAX_X509_SIZE + CERT_HEADER_SZ) * MAX_CHAIN_DEPTH)
  1415. #endif
  1416. /* max size of a handshake message, currently set to the certificate */
  1417. #ifndef MAX_HANDSHAKE_SZ
  1418. #define MAX_HANDSHAKE_SZ MAX_CERTIFICATE_SZ
  1419. #endif
  1420. #ifndef SESSION_TICKET_LEN
  1421. #define SESSION_TICKET_LEN 256
  1422. #endif
  1423. #ifndef PREALLOC_SESSION_TICKET_LEN
  1424. #define PREALLOC_SESSION_TICKET_LEN 512
  1425. #endif
  1426. #ifndef SESSION_TICKET_HINT_DEFAULT
  1427. #define SESSION_TICKET_HINT_DEFAULT 300
  1428. #endif
  1429. #if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_WOLFSSL_SERVER)
  1430. /* Check chosen encryption is available. */
  1431. #if !(defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) && \
  1432. defined(WOLFSSL_TICKET_ENC_CHACHA20_POLY1305)
  1433. #error "ChaCha20-Poly1305 not available for default ticket encryption"
  1434. #endif
  1435. #if !defined(HAVE_AESGCM) && (defined(WOLFSSL_TICKET_ENC_AES128_GCM) || \
  1436. defined(WOLFSSL_TICKET_ENC_AES256_GCM))
  1437. #error "AES-GCM not available for default ticket encryption"
  1438. #endif
  1439. #ifndef WOLFSSL_TICKET_KEY_LIFETIME
  1440. /* Default lifetime is 1 hour from issue of first ticket with key. */
  1441. #define WOLFSSL_TICKET_KEY_LIFETIME (60 * 60)
  1442. #endif
  1443. #if WOLFSSL_TICKET_KEY_LIFETIME <= SESSION_TICKET_HINT_DEFAULT
  1444. #error "Ticket Key lifetime must be longer than ticket life hint."
  1445. #endif
  1446. #endif
  1447. #define MAX_ENCRYPT_SZ ENCRYPT_LEN
  1448. #define WOLFSSL_ASSERT_SIZEOF_GE(x, y) \
  1449. typedef char _args_test[sizeof((x)) >= sizeof((y)) ? 1 : -1]; \
  1450. (void)sizeof(_args_test)
  1451. /* states */
  1452. enum states {
  1453. NULL_STATE = 0,
  1454. SERVER_HELLOVERIFYREQUEST_COMPLETE,
  1455. SERVER_HELLO_RETRY_REQUEST_COMPLETE,
  1456. SERVER_HELLO_COMPLETE,
  1457. SERVER_ENCRYPTED_EXTENSIONS_COMPLETE,
  1458. SERVER_CERT_COMPLETE,
  1459. SERVER_CERT_VERIFY_COMPLETE,
  1460. SERVER_KEYEXCHANGE_COMPLETE,
  1461. SERVER_HELLODONE_COMPLETE,
  1462. SERVER_CHANGECIPHERSPEC_COMPLETE,
  1463. SERVER_FINISHED_COMPLETE,
  1464. CLIENT_HELLO_RETRY,
  1465. CLIENT_HELLO_COMPLETE,
  1466. CLIENT_KEYEXCHANGE_COMPLETE,
  1467. CLIENT_CHANGECIPHERSPEC_COMPLETE,
  1468. CLIENT_FINISHED_COMPLETE,
  1469. HANDSHAKE_DONE
  1470. };
  1471. /* SSL Version */
  1472. typedef struct ProtocolVersion {
  1473. byte major;
  1474. byte minor;
  1475. } WOLFSSL_PACK ProtocolVersion;
  1476. WOLFSSL_LOCAL ProtocolVersion MakeSSLv3(void);
  1477. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1(void);
  1478. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_1(void);
  1479. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_2(void);
  1480. WOLFSSL_LOCAL ProtocolVersion MakeTLSv1_3(void);
  1481. #ifdef WOLFSSL_DTLS
  1482. WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1(void);
  1483. WOLFSSL_LOCAL ProtocolVersion MakeDTLSv1_2(void);
  1484. #endif
  1485. #ifdef WOLFSSL_SESSION_EXPORT
  1486. WOLFSSL_LOCAL int wolfSSL_session_export_internal(WOLFSSL* ssl, byte* buf,
  1487. word32* sz, int type);
  1488. WOLFSSL_LOCAL int wolfSSL_session_import_internal(WOLFSSL* ssl, const byte* buf,
  1489. word32 sz, int type);
  1490. #ifdef WOLFSSL_DTLS
  1491. WOLFSSL_LOCAL int wolfSSL_dtls_export_state_internal(WOLFSSL* ssl,
  1492. byte* buf, word32 sz);
  1493. WOLFSSL_LOCAL int wolfSSL_dtls_import_state_internal(WOLFSSL* ssl,
  1494. const byte* buf, word32 sz);
  1495. WOLFSSL_LOCAL int wolfSSL_send_session(WOLFSSL* ssl);
  1496. #endif
  1497. #endif
  1498. struct WOLFSSL_BY_DIR_HASH {
  1499. unsigned long hash_value;
  1500. int last_suffix;
  1501. };
  1502. struct WOLFSSL_BY_DIR_entry {
  1503. char* dir_name;
  1504. int dir_type;
  1505. WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *hashes;
  1506. };
  1507. struct WOLFSSL_BY_DIR {
  1508. WOLF_STACK_OF(WOLFSSL_BY_DIR_entry) *dir_entry;
  1509. wolfSSL_Mutex lock; /* dir list lock */
  1510. };
  1511. /* wolfSSL method type */
  1512. struct WOLFSSL_METHOD {
  1513. ProtocolVersion version;
  1514. byte side; /* connection side, server or client */
  1515. byte downgrade; /* whether to downgrade version, default no */
  1516. };
  1517. /* wolfSSL buffer type - internal uses "buffer" type */
  1518. typedef WOLFSSL_BUFFER_INFO buffer;
  1519. typedef struct Suites Suites;
  1520. /* Declare opaque struct for API to use */
  1521. #ifndef WOLFSSL_CLIENT_SESSION_DEFINED
  1522. typedef struct ClientSession ClientSession;
  1523. #define WOLFSSL_CLIENT_SESSION_DEFINED
  1524. #endif
  1525. /* defaults to client */
  1526. WOLFSSL_LOCAL void InitSSL_Method(WOLFSSL_METHOD* method, ProtocolVersion pv);
  1527. WOLFSSL_LOCAL int InitSSL_Suites(WOLFSSL* ssl);
  1528. WOLFSSL_LOCAL int InitSSL_Side(WOLFSSL* ssl, word16 side);
  1529. /* for sniffer */
  1530. WOLFSSL_LOCAL int DoFinished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  1531. word32 size, word32 totalSz, int sniff);
  1532. #ifdef WOLFSSL_TLS13
  1533. WOLFSSL_LOCAL int DoTls13Finished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  1534. word32 size, word32 totalSz, int sniff);
  1535. #endif
  1536. WOLFSSL_LOCAL int DoApplicationData(WOLFSSL* ssl, byte* input, word32* inOutIdx,
  1537. int sniff);
  1538. /* TLS v1.3 needs these */
  1539. WOLFSSL_LOCAL int HandleTlsResumption(WOLFSSL* ssl, int bogusID,
  1540. Suites* clSuites);
  1541. #ifdef WOLFSSL_TLS13
  1542. WOLFSSL_LOCAL byte SuiteMac(byte* suite);
  1543. #endif
  1544. WOLFSSL_LOCAL int DoClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  1545. word32 helloSz);
  1546. #ifdef WOLFSSL_TLS13
  1547. WOLFSSL_LOCAL int DoTls13ClientHello(WOLFSSL* ssl, const byte* input,
  1548. word32* inOutIdx, word32 helloSz);
  1549. #endif
  1550. WOLFSSL_LOCAL int DoServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  1551. word32 helloSz);
  1552. WOLFSSL_LOCAL int CompleteServerHello(WOLFSSL *ssl);
  1553. WOLFSSL_LOCAL int CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
  1554. WOLFSSL_LOCAL int PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
  1555. word32 hashSigAlgoSz);
  1556. #if defined(WOLF_PRIVATE_KEY_ID) && !defined(NO_CHECK_PRIVATE_KEY)
  1557. WOLFSSL_LOCAL int CreateDevPrivateKey(void** pkey, byte* data, word32 length,
  1558. int hsType, int label, int id,
  1559. void* heap, int devId);
  1560. #endif
  1561. WOLFSSL_LOCAL int DecodePrivateKey(WOLFSSL *ssl, word16* length);
  1562. #ifdef WOLF_PRIVATE_KEY_ID
  1563. WOLFSSL_LOCAL int GetPrivateKeySigSize(WOLFSSL* ssl);
  1564. #ifndef NO_ASN
  1565. WOLFSSL_LOCAL int InitSigPkCb(WOLFSSL* ssl, SignatureCtx* sigCtx);
  1566. #endif
  1567. #endif
  1568. #ifdef WOLFSSL_ASYNC_IO
  1569. WOLFSSL_LOCAL void FreeAsyncCtx(WOLFSSL* ssl, byte freeAsync);
  1570. #endif
  1571. WOLFSSL_LOCAL void FreeKeyExchange(WOLFSSL* ssl);
  1572. WOLFSSL_LOCAL void FreeSuites(WOLFSSL* ssl);
  1573. WOLFSSL_LOCAL int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 totalSz);
  1574. WOLFSSL_LOCAL int MatchDomainName(const char* pattern, int len, const char* str);
  1575. #ifndef NO_CERTS
  1576. WOLFSSL_LOCAL int CheckForAltNames(DecodedCert* dCert, const char* domain, int* checkCN);
  1577. WOLFSSL_LOCAL int CheckIPAddr(DecodedCert* dCert, const char* ipasc);
  1578. #endif
  1579. WOLFSSL_LOCAL int CreateTicket(WOLFSSL* ssl);
  1580. WOLFSSL_LOCAL int HashRaw(WOLFSSL* ssl, const byte* output, int sz);
  1581. WOLFSSL_LOCAL int HashOutput(WOLFSSL* ssl, const byte* output, int sz,
  1582. int ivSz);
  1583. WOLFSSL_LOCAL int HashInput(WOLFSSL* ssl, const byte* input, int sz);
  1584. #ifdef HAVE_SNI
  1585. #ifndef NO_WOLFSSL_SERVER
  1586. WOLFSSL_LOCAL int SNI_Callback(WOLFSSL* ssl);
  1587. #endif
  1588. #endif
  1589. WOLFSSL_LOCAL int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input,
  1590. word16 sz); /* needed by sniffer */
  1591. #ifdef WOLFSSL_TLS13
  1592. WOLFSSL_LOCAL int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
  1593. word16 sz, const byte* aad, word16 aadSz,
  1594. int doAlert);
  1595. WOLFSSL_LOCAL int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input,
  1596. word32* inOutIdx, byte type,
  1597. word32 size, word32 totalSz);
  1598. WOLFSSL_LOCAL int DoTls13HandShakeMsg(WOLFSSL* ssl, byte* input,
  1599. word32* inOutIdx, word32 totalSz);
  1600. WOLFSSL_LOCAL int DoTls13ServerHello(WOLFSSL* ssl, const byte* input,
  1601. word32* inOutIdx, word32 helloSz,
  1602. byte* extMsgType);
  1603. WOLFSSL_LOCAL int RestartHandshakeHash(WOLFSSL* ssl);
  1604. #endif
  1605. int TimingPadVerify(WOLFSSL* ssl, const byte* input, int padLen, int macSz,
  1606. int pLen, int content);
  1607. enum {
  1608. FORCED_FREE = 1,
  1609. NO_FORCED_FREE = 0
  1610. };
  1611. /* only use compression extra if using compression */
  1612. #ifdef HAVE_LIBZ
  1613. #define COMP_EXTRA MAX_COMP_EXTRA
  1614. #else
  1615. #define COMP_EXTRA 0
  1616. #endif
  1617. /* only the sniffer needs space in the buffer for extra MTU record(s) */
  1618. #ifdef WOLFSSL_SNIFFER
  1619. #define MTU_EXTRA MAX_MTU * 3
  1620. #else
  1621. #define MTU_EXTRA 0
  1622. #endif
  1623. /* embedded callbacks require large static buffers, make sure on */
  1624. #ifdef WOLFSSL_CALLBACKS
  1625. #undef LARGE_STATIC_BUFFERS
  1626. #define LARGE_STATIC_BUFFERS
  1627. #endif
  1628. /* determine maximum record size */
  1629. #ifdef RECORD_SIZE
  1630. /* user supplied value */
  1631. #if RECORD_SIZE < 128 || RECORD_SIZE > MAX_RECORD_SIZE
  1632. #error Invalid record size
  1633. #endif
  1634. #else
  1635. /* give user option to use 16K static buffers */
  1636. #if defined(LARGE_STATIC_BUFFERS)
  1637. #define RECORD_SIZE MAX_RECORD_SIZE
  1638. #else
  1639. #ifdef WOLFSSL_DTLS
  1640. #define RECORD_SIZE MAX_MTU
  1641. #else
  1642. #define RECORD_SIZE 128
  1643. #endif
  1644. #endif
  1645. #endif
  1646. /* user option to turn off 16K output option */
  1647. /* if using small static buffers (default) and SSL_write tries to write data
  1648. larger than the record we have, dynamically get it, unless user says only
  1649. write in static buffer chunks */
  1650. #ifndef STATIC_CHUNKS_ONLY
  1651. #define OUTPUT_RECORD_SIZE MAX_RECORD_SIZE
  1652. #else
  1653. #define OUTPUT_RECORD_SIZE RECORD_SIZE
  1654. #endif
  1655. /* wolfSSL input buffer
  1656. RFC 2246:
  1657. length
  1658. The length (in bytes) of the following TLSPlaintext.fragment.
  1659. The length should not exceed 2^14.
  1660. */
  1661. #ifdef STATIC_BUFFER_LEN
  1662. /* user supplied option */
  1663. #if STATIC_BUFFER_LEN < 5 || STATIC_BUFFER_LEN > (RECORD_HEADER_SZ + \
  1664. RECORD_SIZE + COMP_EXTRA + MTU_EXTRA + MAX_MSG_EXTRA))
  1665. #error Invalid static buffer length
  1666. #endif
  1667. #elif defined(LARGE_STATIC_BUFFERS)
  1668. #define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \
  1669. MTU_EXTRA + MAX_MSG_EXTRA
  1670. #else
  1671. /* don't fragment memory from the record header */
  1672. #define STATIC_BUFFER_LEN RECORD_HEADER_SZ
  1673. #endif
  1674. typedef struct {
  1675. ALIGN16 byte staticBuffer[STATIC_BUFFER_LEN];
  1676. byte* buffer; /* place holder for static or dynamic buffer */
  1677. word32 length; /* total buffer length used */
  1678. word32 idx; /* idx to part of length already consumed */
  1679. word32 bufferSize; /* current buffer size */
  1680. byte dynamicFlag; /* dynamic memory currently in use */
  1681. byte offset; /* alignment offset attempt */
  1682. } bufferStatic;
  1683. /* Cipher Suites holder */
  1684. struct Suites {
  1685. word16 suiteSz; /* suite length in bytes */
  1686. word16 hashSigAlgoSz; /* SigAlgo extension length in bytes */
  1687. byte suites[WOLFSSL_MAX_SUITE_SZ];
  1688. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO]; /* sig/algo to offer */
  1689. byte setSuites; /* user set suites from default */
  1690. byte hashAlgo; /* selected hash algorithm */
  1691. byte sigAlgo; /* selected sig algorithm */
  1692. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  1693. WOLF_STACK_OF(WOLFSSL_CIPHER)* stack; /* stack of available cipher suites */
  1694. #endif
  1695. };
  1696. WOLFSSL_LOCAL void InitSuitesHashSigAlgo(Suites* suites, int haveECDSAsig,
  1697. int haveRSAsig, int haveFalconSig,
  1698. int haveAnon, int tls1_2, int keySz);
  1699. WOLFSSL_LOCAL void InitSuites(Suites* suites, ProtocolVersion pv, int keySz,
  1700. word16 haveRSA, word16 havePSK, word16 haveDH,
  1701. word16 haveECDSAsig, word16 haveECC,
  1702. word16 haveStaticECC, word16 haveFalconSig,
  1703. word16 haveAnon, int side);
  1704. WOLFSSL_LOCAL int MatchSuite(WOLFSSL* ssl, Suites* peerSuites);
  1705. WOLFSSL_LOCAL int SetCipherList(WOLFSSL_CTX* ctx, Suites* suites,
  1706. const char* list);
  1707. WOLFSSL_LOCAL int SetSuitesHashSigAlgo(Suites* suites, const char* list);
  1708. #ifndef PSK_TYPES_DEFINED
  1709. typedef unsigned int (*wc_psk_client_callback)(WOLFSSL*, const char*, char*,
  1710. unsigned int, unsigned char*, unsigned int);
  1711. typedef unsigned int (*wc_psk_server_callback)(WOLFSSL*, const char*,
  1712. unsigned char*, unsigned int);
  1713. #ifdef WOLFSSL_TLS13
  1714. typedef unsigned int (*wc_psk_client_cs_callback)(WOLFSSL*, const char*,
  1715. char*, unsigned int, unsigned char*, unsigned int,
  1716. const char* cipherName);
  1717. typedef unsigned int (*wc_psk_client_tls13_callback)(WOLFSSL*, const char*,
  1718. char*, unsigned int, unsigned char*, unsigned int,
  1719. const char** cipherName);
  1720. typedef unsigned int (*wc_psk_server_tls13_callback)(WOLFSSL*, const char*,
  1721. unsigned char*, unsigned int,
  1722. const char** cipherName);
  1723. #endif
  1724. #endif /* PSK_TYPES_DEFINED */
  1725. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  1726. !defined(WOLFSSL_DTLS_EXPORT_TYPES)
  1727. typedef int (*wc_dtls_export)(WOLFSSL* ssl,
  1728. unsigned char* exportBuffer, unsigned int sz, void* userCtx);
  1729. #define WOLFSSL_DTLS_EXPORT_TYPES
  1730. #endif /* WOLFSSL_DTLS_EXPORT_TYPES */
  1731. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  1732. #define MAX_DESCRIPTION_SZ 255
  1733. #endif
  1734. struct WOLFSSL_CIPHER {
  1735. byte cipherSuite0;
  1736. byte cipherSuite;
  1737. const WOLFSSL* ssl;
  1738. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  1739. char description[MAX_DESCRIPTION_SZ];
  1740. unsigned long offset;
  1741. unsigned int in_stack; /* TRUE if added to stack in wolfSSL_get_ciphers_compat */
  1742. int bits;
  1743. #endif
  1744. };
  1745. #ifdef NO_ASN
  1746. /* no_asn won't have */
  1747. typedef struct CertStatus CertStatus;
  1748. #endif
  1749. #ifndef HAVE_OCSP
  1750. typedef struct WOLFSSL_OCSP WOLFSSL_OCSP;
  1751. #endif
  1752. /* wolfSSL OCSP controller */
  1753. #ifdef HAVE_OCSP
  1754. struct WOLFSSL_OCSP {
  1755. WOLFSSL_CERT_MANAGER* cm; /* pointer back to cert manager */
  1756. OcspEntry* ocspList; /* OCSP response list */
  1757. wolfSSL_Mutex ocspLock; /* OCSP list lock */
  1758. int error;
  1759. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  1760. defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  1761. int(*statusCb)(WOLFSSL*, void*);
  1762. #endif
  1763. };
  1764. #endif
  1765. #ifndef MAX_DATE_SIZE
  1766. #define MAX_DATE_SIZE 32
  1767. #endif
  1768. typedef struct CRL_Entry CRL_Entry;
  1769. #ifdef NO_SHA
  1770. #define CRL_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  1771. #else
  1772. #define CRL_DIGEST_SIZE WC_SHA_DIGEST_SIZE
  1773. #endif
  1774. #ifdef NO_ASN
  1775. typedef struct RevokedCert RevokedCert;
  1776. #endif
  1777. /* Complete CRL */
  1778. struct CRL_Entry {
  1779. CRL_Entry* next; /* next entry */
  1780. byte issuerHash[CRL_DIGEST_SIZE]; /* issuer hash */
  1781. /* byte crlHash[CRL_DIGEST_SIZE]; raw crl data hash */
  1782. /* restore the hash here if needed for optimized comparisons */
  1783. byte lastDate[MAX_DATE_SIZE]; /* last date updated */
  1784. byte nextDate[MAX_DATE_SIZE]; /* next update date */
  1785. byte lastDateFormat; /* last date format */
  1786. byte nextDateFormat; /* next date format */
  1787. RevokedCert* certs; /* revoked cert list */
  1788. int totalCerts; /* number on list */
  1789. int verified;
  1790. byte* toBeSigned;
  1791. word32 tbsSz;
  1792. byte* signature;
  1793. word32 signatureSz;
  1794. word32 signatureOID;
  1795. #if !defined(NO_SKID) && !defined(NO_ASN)
  1796. byte extAuthKeyIdSet;
  1797. byte extAuthKeyId[KEYID_SIZE];
  1798. #endif
  1799. };
  1800. typedef struct CRL_Monitor CRL_Monitor;
  1801. /* CRL directory monitor */
  1802. struct CRL_Monitor {
  1803. char* path; /* full dir path, if valid pointer we're using */
  1804. int type; /* PEM or ASN1 type */
  1805. };
  1806. #if defined(HAVE_CRL) && defined(NO_FILESYSTEM)
  1807. #undef HAVE_CRL_MONITOR
  1808. #endif
  1809. /* wolfSSL CRL controller */
  1810. struct WOLFSSL_CRL {
  1811. WOLFSSL_CERT_MANAGER* cm; /* pointer back to cert manager */
  1812. CRL_Entry* crlList; /* our CRL list */
  1813. #ifdef HAVE_CRL_IO
  1814. CbCrlIO crlIOCb;
  1815. #endif
  1816. wolfSSL_Mutex crlLock; /* CRL list lock */
  1817. CRL_Monitor monitors[2]; /* PEM and DER possible */
  1818. #ifdef HAVE_CRL_MONITOR
  1819. pthread_cond_t cond; /* condition to signal setup */
  1820. pthread_t tid; /* monitoring thread */
  1821. int mfd; /* monitor fd, -1 if no init yet */
  1822. int setup; /* thread is setup predicate */
  1823. #endif
  1824. void* heap; /* heap hint for dynamic memory */
  1825. };
  1826. #ifdef NO_ASN
  1827. typedef struct Signer Signer;
  1828. #ifdef WOLFSSL_TRUST_PEER_CERT
  1829. typedef struct TrustedPeerCert TrustedPeerCert;
  1830. #endif
  1831. #endif
  1832. #ifndef CA_TABLE_SIZE
  1833. #define CA_TABLE_SIZE 11
  1834. #endif
  1835. #ifdef WOLFSSL_TRUST_PEER_CERT
  1836. #define TP_TABLE_SIZE 11
  1837. #endif
  1838. /* wolfSSL Certificate Manager */
  1839. struct WOLFSSL_CERT_MANAGER {
  1840. Signer* caTable[CA_TABLE_SIZE]; /* the CA signer table */
  1841. void* heap; /* heap helper */
  1842. #ifdef WOLFSSL_TRUST_PEER_CERT
  1843. TrustedPeerCert* tpTable[TP_TABLE_SIZE]; /* table of trusted peer certs */
  1844. wolfSSL_Mutex tpLock; /* trusted peer list lock */
  1845. #endif
  1846. WOLFSSL_CRL* crl; /* CRL checker */
  1847. WOLFSSL_OCSP* ocsp; /* OCSP checker */
  1848. #if !defined(NO_WOLFSSL_SERVER) && (defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  1849. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2))
  1850. WOLFSSL_OCSP* ocsp_stapling; /* OCSP checker for OCSP stapling */
  1851. #endif
  1852. char* ocspOverrideURL; /* use this responder */
  1853. void* ocspIOCtx; /* I/O callback CTX */
  1854. #ifndef NO_WOLFSSL_CM_VERIFY
  1855. VerifyCallback verifyCallback; /* Verify callback */
  1856. #endif
  1857. CallbackCACache caCacheCallback; /* CA cache addition callback */
  1858. CbMissingCRL cbMissingCRL; /* notify thru cb of missing crl */
  1859. CbOCSPIO ocspIOCb; /* I/O callback for OCSP lookup */
  1860. CbOCSPRespFree ocspRespFreeCb; /* Frees OCSP Response from IO Cb */
  1861. wolfSSL_Mutex caLock; /* CA list lock */
  1862. byte crlEnabled:1; /* is CRL on ? */
  1863. byte crlCheckAll:1; /* always leaf, but all ? */
  1864. byte ocspEnabled:1; /* is OCSP on ? */
  1865. byte ocspCheckAll:1; /* always leaf, but all ? */
  1866. byte ocspSendNonce:1; /* send the OCSP nonce ? */
  1867. byte ocspUseOverrideURL:1; /* ignore cert responder, override */
  1868. byte ocspStaplingEnabled:1; /* is OCSP Stapling on ? */
  1869. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  1870. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  1871. byte ocspMustStaple:1; /* server must respond with staple */
  1872. #endif
  1873. #ifndef NO_RSA
  1874. short minRsaKeySz; /* minimum allowed RSA key size */
  1875. #endif
  1876. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  1877. short minEccKeySz; /* minimum allowed ECC key size */
  1878. #endif
  1879. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
  1880. WOLFSSL_X509_STORE *x509_store_p; /* a pointer back to CTX x509 store */
  1881. /* CTX has ownership and free this */
  1882. /* with CTX free. */
  1883. #endif
  1884. #ifndef SINGLE_THREADED
  1885. wolfSSL_Mutex refMutex; /* reference count mutex */
  1886. #endif
  1887. int refCount; /* reference count */
  1888. #ifdef HAVE_PQC
  1889. short minFalconKeySz; /* minimum allowed Falcon key size */
  1890. #endif
  1891. };
  1892. WOLFSSL_LOCAL int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm,
  1893. const char* fname);
  1894. WOLFSSL_LOCAL int CM_RestoreCertCache(WOLFSSL_CERT_MANAGER* cm,
  1895. const char* fname);
  1896. WOLFSSL_LOCAL int CM_MemSaveCertCache(WOLFSSL_CERT_MANAGER* cm, void* mem,
  1897. int sz, int* used);
  1898. WOLFSSL_LOCAL int CM_MemRestoreCertCache(WOLFSSL_CERT_MANAGER* cm,
  1899. const void* mem, int sz);
  1900. WOLFSSL_LOCAL int CM_GetCertCacheMemSize(WOLFSSL_CERT_MANAGER* cm);
  1901. WOLFSSL_LOCAL int CM_VerifyBuffer_ex(WOLFSSL_CERT_MANAGER* cm, const byte* buff,
  1902. long sz, int format, int err_val);
  1903. #ifndef NO_CERTS
  1904. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  1905. typedef struct ProcPeerCertArgs {
  1906. buffer* certs;
  1907. #ifdef WOLFSSL_TLS13
  1908. buffer* exts; /* extensions */
  1909. #endif
  1910. DecodedCert* dCert;
  1911. word32 idx;
  1912. word32 begin;
  1913. int totalCerts; /* number of certs in certs buffer */
  1914. int count;
  1915. int certIdx;
  1916. int lastErr;
  1917. #ifdef WOLFSSL_TLS13
  1918. byte ctxSz;
  1919. #endif
  1920. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  1921. char untrustedDepth;
  1922. #endif
  1923. word16 fatal:1;
  1924. word16 verifyErr:1;
  1925. word16 dCertInit:1;
  1926. #ifdef WOLFSSL_TRUST_PEER_CERT
  1927. word16 haveTrustPeer:1; /* was cert verified by loaded trusted peer cert */
  1928. #endif
  1929. } ProcPeerCertArgs;
  1930. WOLFSSL_LOCAL int DoVerifyCallback(WOLFSSL_CERT_MANAGER* cm, WOLFSSL* ssl,
  1931. int ret, ProcPeerCertArgs* args);
  1932. #endif /* !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) */
  1933. #endif /* !defined NO_CERTS */
  1934. /* wolfSSL Sock Addr */
  1935. struct WOLFSSL_SOCKADDR {
  1936. unsigned int sz; /* sockaddr size */
  1937. void* sa; /* pointer to the sockaddr_in or sockaddr_in6 */
  1938. };
  1939. typedef struct WOLFSSL_DTLS_CTX {
  1940. WOLFSSL_SOCKADDR peer;
  1941. int rfd;
  1942. int wfd;
  1943. } WOLFSSL_DTLS_CTX;
  1944. typedef struct WOLFSSL_DTLS_PEERSEQ {
  1945. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  1946. /* Sliding window for current epoch */
  1947. word16 nextEpoch; /* Expected epoch in next record */
  1948. word16 nextSeq_hi; /* Expected sequence in next record */
  1949. word32 nextSeq_lo;
  1950. word32 prevWindow[WOLFSSL_DTLS_WINDOW_WORDS];
  1951. /* Sliding window for old epoch */
  1952. word32 prevSeq_lo;
  1953. word16 prevSeq_hi; /* Next sequence in allowed old epoch */
  1954. #ifdef WOLFSSL_MULTICAST
  1955. word16 peerId;
  1956. word32 highwaterMark;
  1957. #endif
  1958. } WOLFSSL_DTLS_PEERSEQ;
  1959. #define MAX_WRITE_IV_SZ 16 /* max size of client/server write_IV */
  1960. /* keys and secrets
  1961. * keep as a constant size (no additional ifdefs) for session export */
  1962. typedef struct Keys {
  1963. #if !defined(WOLFSSL_AEAD_ONLY) || defined(WOLFSSL_TLS13)
  1964. byte client_write_MAC_secret[WC_MAX_DIGEST_SIZE]; /* max sizes */
  1965. byte server_write_MAC_secret[WC_MAX_DIGEST_SIZE];
  1966. #endif
  1967. byte client_write_key[MAX_SYM_KEY_SIZE]; /* max sizes */
  1968. byte server_write_key[MAX_SYM_KEY_SIZE];
  1969. byte client_write_IV[MAX_WRITE_IV_SZ]; /* max sizes */
  1970. byte server_write_IV[MAX_WRITE_IV_SZ];
  1971. #if defined(HAVE_AEAD) || defined(WOLFSSL_SESSION_EXPORT)
  1972. byte aead_exp_IV[AEAD_MAX_EXP_SZ];
  1973. byte aead_enc_imp_IV[AEAD_MAX_IMP_SZ];
  1974. byte aead_dec_imp_IV[AEAD_MAX_IMP_SZ];
  1975. #endif
  1976. word32 peer_sequence_number_hi;
  1977. word32 peer_sequence_number_lo;
  1978. word32 sequence_number_hi;
  1979. word32 sequence_number_lo;
  1980. #ifdef WOLFSSL_DTLS
  1981. word16 curEpoch; /* Received epoch in current record */
  1982. word16 curSeq_hi; /* Received sequence in current record */
  1983. word32 curSeq_lo;
  1984. #ifdef WOLFSSL_MULTICAST
  1985. byte curPeerId; /* Received peer group ID in current record */
  1986. #endif
  1987. WOLFSSL_DTLS_PEERSEQ peerSeq[WOLFSSL_DTLS_PEERSEQ_SZ];
  1988. word16 dtls_peer_handshake_number;
  1989. word16 dtls_expected_peer_handshake_number;
  1990. word16 dtls_epoch; /* Current epoch */
  1991. word16 dtls_sequence_number_hi; /* Current epoch */
  1992. word32 dtls_sequence_number_lo;
  1993. word16 dtls_prev_sequence_number_hi; /* Previous epoch */
  1994. word32 dtls_prev_sequence_number_lo;
  1995. word16 dtls_handshake_number; /* Current tx handshake seq */
  1996. #endif
  1997. word32 encryptSz; /* last size of encrypted data */
  1998. word32 padSz; /* how much to advance after decrypt part */
  1999. byte encryptionOn; /* true after change cipher spec */
  2000. byte decryptedCur; /* only decrypt current record once */
  2001. #ifdef WOLFSSL_TLS13
  2002. byte updateResponseReq:1; /* KeyUpdate response from peer required. */
  2003. byte keyUpdateRespond:1; /* KeyUpdate is to be responded to. */
  2004. #endif
  2005. #ifdef WOLFSSL_RENESAS_TSIP_TLS
  2006. tsip_hmac_sha_key_index_t tsip_client_write_MAC_secret;
  2007. tsip_hmac_sha_key_index_t tsip_server_write_MAC_secret;
  2008. #endif
  2009. #ifdef WOLFSSL_RENESAS_SCEPROTECT
  2010. sce_hmac_sha_wrapped_key_t sce_client_write_MAC_secret;
  2011. sce_hmac_sha_wrapped_key_t sce_server_write_MAC_secret;
  2012. #endif
  2013. } Keys;
  2014. /** TLS Extensions - RFC 6066 */
  2015. #ifdef HAVE_TLS_EXTENSIONS
  2016. typedef enum {
  2017. #ifdef HAVE_SNI
  2018. TLSX_SERVER_NAME = 0x0000, /* a.k.a. SNI */
  2019. #endif
  2020. TLSX_MAX_FRAGMENT_LENGTH = 0x0001,
  2021. TLSX_TRUSTED_CA_KEYS = 0x0003,
  2022. TLSX_TRUNCATED_HMAC = 0x0004,
  2023. TLSX_STATUS_REQUEST = 0x0005, /* a.k.a. OCSP stapling */
  2024. TLSX_SUPPORTED_GROUPS = 0x000a, /* a.k.a. Supported Curves */
  2025. TLSX_EC_POINT_FORMATS = 0x000b,
  2026. #if !defined(NO_CERTS) && !defined(WOLFSSL_NO_SIGALG)
  2027. TLSX_SIGNATURE_ALGORITHMS = 0x000d, /* HELLO_EXT_SIG_ALGO */
  2028. #endif
  2029. #ifdef WOLFSSL_SRTP
  2030. TLSX_USE_SRTP = 0x000e, /* 14 */
  2031. #endif
  2032. TLSX_APPLICATION_LAYER_PROTOCOL = 0x0010, /* a.k.a. ALPN */
  2033. TLSX_STATUS_REQUEST_V2 = 0x0011, /* a.k.a. OCSP stapling v2 */
  2034. #if defined(HAVE_ENCRYPT_THEN_MAC) && !defined(WOLFSSL_AEAD_ONLY)
  2035. TLSX_ENCRYPT_THEN_MAC = 0x0016, /* RFC 7366 */
  2036. #endif
  2037. TLSX_EXTENDED_MASTER_SECRET = 0x0017, /* HELLO_EXT_EXTMS */
  2038. TLSX_SESSION_TICKET = 0x0023,
  2039. #ifdef WOLFSSL_TLS13
  2040. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2041. TLSX_PRE_SHARED_KEY = 0x0029,
  2042. #endif
  2043. #ifdef WOLFSSL_EARLY_DATA
  2044. TLSX_EARLY_DATA = 0x002a,
  2045. #endif
  2046. TLSX_SUPPORTED_VERSIONS = 0x002b,
  2047. #ifdef WOLFSSL_SEND_HRR_COOKIE
  2048. TLSX_COOKIE = 0x002c,
  2049. #endif
  2050. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2051. TLSX_PSK_KEY_EXCHANGE_MODES = 0x002d,
  2052. #endif
  2053. #ifdef WOLFSSL_POST_HANDSHAKE_AUTH
  2054. TLSX_POST_HANDSHAKE_AUTH = 0x0031,
  2055. #endif
  2056. #if !defined(NO_CERTS) && !defined(WOLFSSL_NO_SIGALG)
  2057. TLSX_SIGNATURE_ALGORITHMS_CERT = 0x0032,
  2058. #endif
  2059. TLSX_KEY_SHARE = 0x0033,
  2060. #endif
  2061. TLSX_RENEGOTIATION_INFO = 0xff01
  2062. } TLSX_Type;
  2063. typedef struct TLSX {
  2064. TLSX_Type type; /* Extension Type */
  2065. void* data; /* Extension Data */
  2066. word32 val; /* Extension Value */
  2067. byte resp; /* IsResponse Flag */
  2068. struct TLSX* next; /* List Behavior */
  2069. } TLSX;
  2070. WOLFSSL_LOCAL TLSX* TLSX_Find(TLSX* list, TLSX_Type type);
  2071. WOLFSSL_LOCAL void TLSX_Remove(TLSX** list, TLSX_Type type, void* heap);
  2072. WOLFSSL_LOCAL void TLSX_FreeAll(TLSX* list, void* heap);
  2073. WOLFSSL_LOCAL int TLSX_SupportExtensions(WOLFSSL* ssl);
  2074. WOLFSSL_LOCAL int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isRequest);
  2075. #if defined(WOLFSSL_TLS13) || !defined(NO_WOLFSSL_CLIENT)
  2076. WOLFSSL_LOCAL int TLSX_GetRequestSize(WOLFSSL* ssl, byte msgType,
  2077. word16* pLength);
  2078. WOLFSSL_LOCAL int TLSX_WriteRequest(WOLFSSL* ssl, byte* output,
  2079. byte msgType, word16* pOffset);
  2080. #endif
  2081. #if defined(WOLFSSL_TLS13) || !defined(NO_WOLFSSL_SERVER)
  2082. /* TLS 1.3 Certificate messages have extensions. */
  2083. WOLFSSL_LOCAL int TLSX_GetResponseSize(WOLFSSL* ssl, byte msgType,
  2084. word16* pLength);
  2085. WOLFSSL_LOCAL int TLSX_WriteResponse(WOLFSSL *ssl, byte* output, byte msgType,
  2086. word16* pOffset);
  2087. #endif
  2088. WOLFSSL_LOCAL int TLSX_ParseVersion(WOLFSSL* ssl, const byte* input,
  2089. word16 length, byte msgType, int* found);
  2090. WOLFSSL_LOCAL int TLSX_Parse(WOLFSSL* ssl, const byte* input, word16 length,
  2091. byte msgType, Suites *suites);
  2092. #elif defined(HAVE_SNI) \
  2093. || defined(HAVE_MAX_FRAGMENT) \
  2094. || defined(HAVE_TRUSTED_CA) \
  2095. || defined(HAVE_TRUNCATED_HMAC) \
  2096. || defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  2097. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) \
  2098. || defined(HAVE_SUPPORTED_CURVES) \
  2099. || defined(HAVE_ALPN) \
  2100. || defined(HAVE_SESSION_TICKET) \
  2101. || defined(HAVE_SECURE_RENEGOTIATION) \
  2102. || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  2103. #error Using TLS extensions requires HAVE_TLS_EXTENSIONS to be defined.
  2104. #endif /* HAVE_TLS_EXTENSIONS */
  2105. /** Server Name Indication - RFC 6066 (session 3) */
  2106. #ifdef HAVE_SNI
  2107. typedef struct SNI {
  2108. byte type; /* SNI Type */
  2109. union { char* host_name; } data; /* SNI Data */
  2110. struct SNI* next; /* List Behavior */
  2111. byte status; /* Matching result */
  2112. #ifndef NO_WOLFSSL_SERVER
  2113. byte options; /* Behavior options */
  2114. #endif
  2115. } SNI;
  2116. WOLFSSL_LOCAL int TLSX_UseSNI(TLSX** extensions, byte type, const void* data,
  2117. word16 size, void* heap);
  2118. WOLFSSL_LOCAL byte TLSX_SNI_Status(TLSX* extensions, byte type);
  2119. WOLFSSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type,
  2120. void** data);
  2121. #ifndef NO_WOLFSSL_SERVER
  2122. WOLFSSL_LOCAL void TLSX_SNI_SetOptions(TLSX* extensions, byte type,
  2123. byte options);
  2124. WOLFSSL_LOCAL int TLSX_SNI_GetFromBuffer(const byte* clientHello,
  2125. word32 helloSz, byte type, byte* sni, word32* inOutSz);
  2126. #endif
  2127. #endif /* HAVE_SNI */
  2128. /* Trusted CA Key Indication - RFC 6066 (section 6) */
  2129. #ifdef HAVE_TRUSTED_CA
  2130. typedef struct TCA {
  2131. byte type; /* TCA Type */
  2132. byte* id; /* TCA identifier */
  2133. word16 idSz; /* TCA identifier size */
  2134. struct TCA* next; /* List Behavior */
  2135. } TCA;
  2136. WOLFSSL_LOCAL int TLSX_UseTrustedCA(TLSX** extensions, byte type,
  2137. const byte* id, word16 idSz, void* heap);
  2138. #endif /* HAVE_TRUSTED_CA */
  2139. /* Application-Layer Protocol Negotiation - RFC 7301 */
  2140. #ifdef HAVE_ALPN
  2141. typedef struct ALPN {
  2142. char* protocol_name; /* ALPN protocol name */
  2143. struct ALPN* next; /* List Behavior */
  2144. byte options; /* Behavior options */
  2145. byte negotiated; /* ALPN protocol negotiated or not */
  2146. } ALPN;
  2147. WOLFSSL_LOCAL int TLSX_ALPN_GetRequest(TLSX* extensions,
  2148. void** data, word16 *dataSz);
  2149. WOLFSSL_LOCAL int TLSX_UseALPN(TLSX** extensions, const void* data,
  2150. word16 size, byte options, void* heap);
  2151. WOLFSSL_LOCAL int TLSX_ALPN_SetOptions(TLSX** extensions, byte option);
  2152. #endif /* HAVE_ALPN */
  2153. /** Maximum Fragment Length Negotiation - RFC 6066 (session 4) */
  2154. #ifdef HAVE_MAX_FRAGMENT
  2155. WOLFSSL_LOCAL int TLSX_UseMaxFragment(TLSX** extensions, byte mfl, void* heap);
  2156. #endif /* HAVE_MAX_FRAGMENT */
  2157. /** Truncated HMAC - RFC 6066 (session 7) */
  2158. #ifdef HAVE_TRUNCATED_HMAC
  2159. WOLFSSL_LOCAL int TLSX_UseTruncatedHMAC(TLSX** extensions, void* heap);
  2160. #endif /* HAVE_TRUNCATED_HMAC */
  2161. /** Certificate Status Request - RFC 6066 (session 8) */
  2162. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  2163. typedef struct {
  2164. byte status_type;
  2165. byte options;
  2166. WOLFSSL* ssl;
  2167. union {
  2168. OcspRequest ocsp;
  2169. } request;
  2170. #if defined(WOLFSSL_TLS13)
  2171. buffer response;
  2172. #endif
  2173. } CertificateStatusRequest;
  2174. WOLFSSL_LOCAL int TLSX_UseCertificateStatusRequest(TLSX** extensions,
  2175. byte status_type, byte options, WOLFSSL* ssl, void* heap, int devId);
  2176. #ifndef NO_CERTS
  2177. WOLFSSL_LOCAL int TLSX_CSR_InitRequest(TLSX* extensions, DecodedCert* cert,
  2178. void* heap);
  2179. #endif
  2180. WOLFSSL_LOCAL void* TLSX_CSR_GetRequest(TLSX* extensions);
  2181. WOLFSSL_LOCAL int TLSX_CSR_ForceRequest(WOLFSSL* ssl);
  2182. #endif
  2183. /** Certificate Status Request v2 - RFC 6961 */
  2184. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  2185. typedef struct CSRIv2 {
  2186. byte status_type;
  2187. byte options;
  2188. word16 requests;
  2189. union {
  2190. OcspRequest ocsp[1 + MAX_CHAIN_DEPTH];
  2191. } request;
  2192. struct CSRIv2* next;
  2193. } CertificateStatusRequestItemV2;
  2194. WOLFSSL_LOCAL int TLSX_UseCertificateStatusRequestV2(TLSX** extensions,
  2195. byte status_type, byte options, void* heap, int devId);
  2196. #ifndef NO_CERTS
  2197. WOLFSSL_LOCAL int TLSX_CSR2_InitRequests(TLSX* extensions, DecodedCert* cert,
  2198. byte isPeer, void* heap);
  2199. #endif
  2200. WOLFSSL_LOCAL void* TLSX_CSR2_GetRequest(TLSX* extensions, byte status_type,
  2201. byte idx);
  2202. WOLFSSL_LOCAL int TLSX_CSR2_ForceRequest(WOLFSSL* ssl);
  2203. #endif
  2204. /** Supported Elliptic Curves - RFC 4492 (session 4) */
  2205. #ifdef HAVE_SUPPORTED_CURVES
  2206. typedef struct SupportedCurve {
  2207. word16 name; /* Curve Names */
  2208. struct SupportedCurve* next; /* List Behavior */
  2209. } SupportedCurve;
  2210. typedef struct PointFormat {
  2211. byte format; /* PointFormat */
  2212. struct PointFormat* next; /* List Behavior */
  2213. } PointFormat;
  2214. WOLFSSL_LOCAL int TLSX_UseSupportedCurve(TLSX** extensions, word16 name,
  2215. void* heap);
  2216. WOLFSSL_LOCAL int TLSX_UsePointFormat(TLSX** extensions, byte point,
  2217. void* heap);
  2218. #ifndef NO_WOLFSSL_SERVER
  2219. WOLFSSL_LOCAL int TLSX_ValidateSupportedCurves(WOLFSSL* ssl, byte first,
  2220. byte second);
  2221. WOLFSSL_LOCAL int TLSX_SupportedCurve_CheckPriority(WOLFSSL* ssl);
  2222. WOLFSSL_LOCAL int TLSX_SupportedFFDHE_Set(WOLFSSL* ssl);
  2223. #endif
  2224. WOLFSSL_LOCAL int TLSX_SupportedCurve_Preferred(WOLFSSL* ssl,
  2225. int checkSupported);
  2226. #endif /* HAVE_SUPPORTED_CURVES */
  2227. /** Renegotiation Indication - RFC 5746 */
  2228. #if defined(HAVE_SECURE_RENEGOTIATION) \
  2229. || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  2230. enum key_cache_state {
  2231. SCR_CACHE_NULL = 0, /* empty / begin state */
  2232. SCR_CACHE_NEEDED, /* need to cache keys */
  2233. SCR_CACHE_COPY, /* we have a cached copy */
  2234. SCR_CACHE_PARTIAL, /* partial restore to real keys */
  2235. SCR_CACHE_COMPLETE /* complete restore to real keys */
  2236. };
  2237. /* Additional Connection State according to rfc5746 section 3.1 */
  2238. typedef struct SecureRenegotiation {
  2239. byte enabled; /* secure_renegotiation flag in rfc */
  2240. byte verifySet;
  2241. byte startScr; /* server requested client to start scr */
  2242. enum key_cache_state cache_status; /* track key cache state */
  2243. byte client_verify_data[TLS_FINISHED_SZ]; /* cached */
  2244. byte server_verify_data[TLS_FINISHED_SZ]; /* cached */
  2245. byte subject_hash_set; /* if peer cert hash is set */
  2246. byte subject_hash[KEYID_SIZE]; /* peer cert hash */
  2247. Keys tmp_keys; /* can't overwrite real keys yet */
  2248. } SecureRenegotiation;
  2249. WOLFSSL_LOCAL int TLSX_UseSecureRenegotiation(TLSX** extensions, void* heap);
  2250. #ifdef HAVE_SERVER_RENEGOTIATION_INFO
  2251. WOLFSSL_LOCAL int TLSX_AddEmptyRenegotiationInfo(TLSX** extensions, void* heap);
  2252. #endif
  2253. #endif /* HAVE_SECURE_RENEGOTIATION */
  2254. /** Session Ticket - RFC 5077 (session 3.2) */
  2255. #ifdef HAVE_SESSION_TICKET
  2256. typedef struct SessionTicket {
  2257. word32 lifetime;
  2258. #ifdef WOLFSSL_TLS13
  2259. word64 seen;
  2260. word32 ageAdd;
  2261. #endif
  2262. byte* data;
  2263. word16 size;
  2264. } SessionTicket;
  2265. #if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_WOLFSSL_SERVER)
  2266. /* Data passed to default SessionTicket enc/dec callback. */
  2267. typedef struct TicketEncCbCtx {
  2268. /* Name for this context. */
  2269. byte name[WOLFSSL_TICKET_NAME_SZ];
  2270. /* Current keys - current and next. */
  2271. byte key[2][WOLFSSL_TICKET_KEY_SZ];
  2272. /* Expirary date of keys. */
  2273. word32 expirary[2];
  2274. /* Random number generator to use for generating name, keys and IV. */
  2275. WC_RNG rng;
  2276. #ifndef SINGLE_THREADED
  2277. /* Mutex for access to changing keys. */
  2278. wolfSSL_Mutex mutex;
  2279. #endif
  2280. /* Pointer back to SSL_CTX. */
  2281. WOLFSSL_CTX* ctx;
  2282. } TicketEncCbCtx;
  2283. #endif /* !WOLFSSL_NO_DEF_TICKET_ENC_CB && !NO_WOLFSSL_SERVER */
  2284. WOLFSSL_LOCAL int TLSX_UseSessionTicket(TLSX** extensions,
  2285. SessionTicket* ticket, void* heap);
  2286. WOLFSSL_LOCAL SessionTicket* TLSX_SessionTicket_Create(word32 lifetime,
  2287. byte* data, word16 size, void* heap);
  2288. WOLFSSL_LOCAL void TLSX_SessionTicket_Free(SessionTicket* ticket, void* heap);
  2289. #endif /* HAVE_SESSION_TICKET */
  2290. #if defined(HAVE_ENCRYPT_THEN_MAC) && !defined(WOLFSSL_AEAD_ONLY)
  2291. int TLSX_EncryptThenMac_Respond(WOLFSSL* ssl);
  2292. #endif
  2293. #ifdef WOLFSSL_TLS13
  2294. /* Cookie extension information - cookie data. */
  2295. typedef struct Cookie {
  2296. word16 len;
  2297. byte data;
  2298. } Cookie;
  2299. WOLFSSL_LOCAL int TLSX_Cookie_Use(WOLFSSL* ssl, const byte* data, word16 len,
  2300. byte* mac, byte macSz, int resp);
  2301. /* Key Share - TLS v1.3 Specification */
  2302. /* The KeyShare extension information - entry in a linked list. */
  2303. typedef struct KeyShareEntry {
  2304. word16 group; /* NamedGroup */
  2305. byte* ke; /* Key exchange data */
  2306. word32 keLen; /* Key exchange data length */
  2307. void* key; /* Key struct */
  2308. word32 keyLen; /* Key size (bytes) */
  2309. byte* pubKey; /* Public key */
  2310. word32 pubKeyLen; /* Public key length */
  2311. #if !defined(NO_DH) || defined(HAVE_PQC)
  2312. byte* privKey; /* Private key - DH ond PQ KEMs only */
  2313. #endif
  2314. #ifdef WOLFSSL_ASYNC_CRYPT
  2315. int lastRet;
  2316. #endif
  2317. struct KeyShareEntry* next; /* List pointer */
  2318. } KeyShareEntry;
  2319. WOLFSSL_LOCAL int TLSX_KeyShare_Use(WOLFSSL* ssl, word16 group, word16 len,
  2320. byte* data, KeyShareEntry **kse);
  2321. WOLFSSL_LOCAL int TLSX_KeyShare_Empty(WOLFSSL* ssl);
  2322. WOLFSSL_LOCAL int TLSX_KeyShare_Establish(WOLFSSL* ssl, int* doHelloRetry);
  2323. WOLFSSL_LOCAL int TLSX_KeyShare_DeriveSecret(WOLFSSL* ssl);
  2324. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2325. /* Ticket nonce - for deriving PSK.
  2326. * Length allowed to be: 1..255. Only support 4 bytes.
  2327. */
  2328. typedef struct TicketNonce {
  2329. byte len;
  2330. byte data[MAX_TICKET_NONCE_SZ];
  2331. } TicketNonce;
  2332. /* The PreSharedKey extension information - entry in a linked list. */
  2333. typedef struct PreSharedKey {
  2334. word16 identityLen; /* Length of identity */
  2335. byte* identity; /* PSK identity */
  2336. word32 ticketAge; /* Age of the ticket */
  2337. byte cipherSuite0; /* Cipher Suite */
  2338. byte cipherSuite; /* Cipher Suite */
  2339. word32 binderLen; /* Length of HMAC */
  2340. byte binder[WC_MAX_DIGEST_SIZE]; /* HMAC of handshake */
  2341. byte hmac; /* HMAC algorithm */
  2342. byte resumption:1; /* Resumption PSK */
  2343. byte chosen:1; /* Server's choice */
  2344. struct PreSharedKey* next; /* List pointer */
  2345. } PreSharedKey;
  2346. WOLFSSL_LOCAL int TLSX_PreSharedKey_WriteBinders(PreSharedKey* list,
  2347. byte* output, byte msgType,
  2348. word16* pSz);
  2349. WOLFSSL_LOCAL int TLSX_PreSharedKey_GetSizeBinders(PreSharedKey* list,
  2350. byte msgType, word16* pSz);
  2351. WOLFSSL_LOCAL int TLSX_PreSharedKey_Use(WOLFSSL* ssl, const byte* identity,
  2352. word16 len, word32 age, byte hmac,
  2353. byte cipherSuite0, byte cipherSuite,
  2354. byte resumption,
  2355. PreSharedKey **preSharedKey);
  2356. /* The possible Pre-Shared Key key exchange modes. */
  2357. enum PskKeyExchangeMode {
  2358. PSK_KE,
  2359. PSK_DHE_KE
  2360. };
  2361. /* User can define this. */
  2362. #ifndef WOLFSSL_DEF_PSK_CIPHER
  2363. #define WOLFSSL_DEF_PSK_CIPHER TLS_AES_128_GCM_SHA256
  2364. #endif
  2365. WOLFSSL_LOCAL int TLSX_PskKeModes_Use(WOLFSSL* ssl, byte modes);
  2366. #ifdef WOLFSSL_EARLY_DATA
  2367. WOLFSSL_LOCAL int TLSX_EarlyData_Use(WOLFSSL* ssl, word32 max);
  2368. #endif
  2369. #endif /* HAVE_SESSION_TICKET || !NO_PSK */
  2370. /* The types of keys to derive for. */
  2371. enum DeriveKeyType {
  2372. no_key,
  2373. early_data_key,
  2374. handshake_key,
  2375. traffic_key,
  2376. update_traffic_key
  2377. };
  2378. WOLFSSL_LOCAL int DeriveEarlySecret(WOLFSSL* ssl);
  2379. WOLFSSL_LOCAL int DeriveHandshakeSecret(WOLFSSL* ssl);
  2380. WOLFSSL_LOCAL int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store);
  2381. WOLFSSL_LOCAL int DeriveMasterSecret(WOLFSSL* ssl);
  2382. WOLFSSL_LOCAL int DeriveResumptionPSK(WOLFSSL* ssl, byte* nonce, byte nonceLen, byte* secret);
  2383. WOLFSSL_LOCAL int DeriveResumptionSecret(WOLFSSL* ssl, byte* key);
  2384. WOLFSSL_LOCAL int Tls13_Exporter(WOLFSSL* ssl, unsigned char *out, size_t outLen,
  2385. const char *label, size_t labelLen,
  2386. const unsigned char *context, size_t contextLen);
  2387. /* The key update request values for KeyUpdate message. */
  2388. enum KeyUpdateRequest {
  2389. update_not_requested,
  2390. update_requested
  2391. };
  2392. #endif /* WOLFSSL_TLS13 */
  2393. #ifdef OPENSSL_EXTRA
  2394. enum SetCBIO {
  2395. WOLFSSL_CBIO_NONE = 0,
  2396. WOLFSSL_CBIO_RECV = 0x1,
  2397. WOLFSSL_CBIO_SEND = 0x2,
  2398. };
  2399. #endif
  2400. #ifdef WOLFSSL_STATIC_EPHEMERAL
  2401. /* contains static ephemeral keys */
  2402. typedef struct {
  2403. #ifndef NO_DH
  2404. DerBuffer* dhKey;
  2405. #endif
  2406. #ifdef HAVE_ECC
  2407. DerBuffer* ecKey;
  2408. #endif
  2409. #ifdef HAVE_CURVE25519
  2410. DerBuffer* x25519Key;
  2411. #endif
  2412. #ifdef HAVE_CURVE448
  2413. DerBuffer* x448Key;
  2414. #endif
  2415. } StaticKeyExchangeInfo_t;
  2416. #endif /* WOLFSSL_STATIC_EPHEMERAL */
  2417. /* wolfSSL context type */
  2418. struct WOLFSSL_CTX {
  2419. WOLFSSL_METHOD* method;
  2420. #ifdef SINGLE_THREADED
  2421. WC_RNG* rng; /* to be shared with WOLFSSL w/o locking */
  2422. #endif
  2423. wolfSSL_Mutex countMutex; /* reference count mutex */
  2424. int refCount; /* reference count */
  2425. int err; /* error code in case of mutex not created */
  2426. #ifndef NO_DH
  2427. buffer serverDH_P;
  2428. buffer serverDH_G;
  2429. #endif
  2430. #ifndef NO_CERTS
  2431. DerBuffer* certificate;
  2432. DerBuffer* certChain;
  2433. /* chain after self, in DER, with leading size for each cert */
  2434. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA) || defined(HAVE_LIGHTY)
  2435. WOLF_STACK_OF(WOLFSSL_X509_NAME)* ca_names;
  2436. #endif
  2437. #ifdef OPENSSL_EXTRA
  2438. WOLF_STACK_OF(WOLFSSL_X509)* x509Chain;
  2439. client_cert_cb CBClientCert; /* client certificate callback */
  2440. CertSetupCallback certSetupCb;
  2441. void* certSetupCbArg;
  2442. #endif
  2443. #ifdef WOLFSSL_TLS13
  2444. int certChainCnt;
  2445. #endif
  2446. DerBuffer* privateKey;
  2447. byte privateKeyType:6;
  2448. byte privateKeyId:1;
  2449. byte privateKeyLabel:1;
  2450. int privateKeySz;
  2451. int privateKeyDevId;
  2452. #ifdef OPENSSL_ALL
  2453. WOLFSSL_EVP_PKEY* privateKeyPKey;
  2454. #endif
  2455. WOLFSSL_CERT_MANAGER* cm; /* our cert manager, ctx owns SSL will use */
  2456. #endif
  2457. #ifdef KEEP_OUR_CERT
  2458. WOLFSSL_X509* ourCert; /* keep alive a X509 struct of cert */
  2459. int ownOurCert; /* Dispose of certificate if we own */
  2460. #endif
  2461. Suites* suites; /* make dynamic, user may not need/set */
  2462. void* heap; /* for user memory overrides */
  2463. byte verifyDepth;
  2464. byte verifyPeer:1;
  2465. byte verifyNone:1;
  2466. byte failNoCert:1;
  2467. byte failNoCertxPSK:1; /* fail if no cert with the exception of PSK*/
  2468. byte sessionCacheOff:1;
  2469. byte sessionCacheFlushOff:1;
  2470. #ifdef HAVE_EXT_CACHE
  2471. byte internalCacheOff:1;
  2472. byte internalCacheLookupOff:1;
  2473. #endif
  2474. byte sendVerify:2; /* for client side (can not be single bit) */
  2475. byte haveRSA:1; /* RSA available */
  2476. byte haveECC:1; /* ECC available */
  2477. byte haveDH:1; /* server DH parms set by user */
  2478. byte haveECDSAsig:1; /* server cert signed w/ ECDSA */
  2479. byte haveFalconSig:1; /* server cert signed w/ Falcon */
  2480. byte haveStaticECC:1; /* static server ECC private key */
  2481. byte partialWrite:1; /* only one msg per write call */
  2482. byte autoRetry:1; /* retry read/write on a WANT_{READ|WRITE} */
  2483. byte quietShutdown:1; /* don't send close notify */
  2484. byte groupMessages:1; /* group handshake messages before sending */
  2485. byte minDowngrade; /* minimum downgrade version */
  2486. byte haveEMS:1; /* have extended master secret extension */
  2487. byte useClientOrder:1; /* Use client's cipher preference order */
  2488. #if defined(HAVE_SESSION_TICKET)
  2489. byte noTicketTls12:1; /* TLS 1.2 server won't send ticket */
  2490. #endif
  2491. #ifdef WOLFSSL_TLS13
  2492. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  2493. unsigned int maxTicketTls13; /* maximum number of tickets to send */
  2494. #endif
  2495. byte noTicketTls13:1; /* TLS 1.3 Server won't create new Ticket */
  2496. byte noPskDheKe:1; /* Don't use (EC)DHE with PSK */
  2497. #endif
  2498. byte mutualAuth:1; /* Mutual authentication required */
  2499. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  2500. byte postHandshakeAuth:1; /* Post-handshake auth supported. */
  2501. byte verifyPostHandshake:1; /* Only send client cert req post
  2502. * handshake, not also during */
  2503. #endif
  2504. #ifndef NO_DH
  2505. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  2506. !defined(HAVE_SELFTEST)
  2507. byte dhKeyTested:1; /* Set when key has been tested. */
  2508. #endif
  2509. #endif
  2510. #if defined(HAVE_SECURE_RENEGOTIATION) || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  2511. byte useSecureReneg:1; /* when set will set WOLFSSL objects generated to enable */
  2512. #endif
  2513. #ifdef HAVE_ENCRYPT_THEN_MAC
  2514. byte disallowEncThenMac:1; /* Don't do Encrypt-Then-MAC */
  2515. #endif
  2516. #ifdef WOLFSSL_STATIC_MEMORY
  2517. byte onHeapHint:1; /* whether the ctx/method is put on heap hint */
  2518. #endif
  2519. #if defined(WOLFSSL_STATIC_EPHEMERAL) && !defined(SINGLE_THREADED)
  2520. byte staticKELockInit:1;
  2521. #endif
  2522. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SCTP)
  2523. byte dtlsSctp:1; /* DTLS-over-SCTP mode */
  2524. #endif
  2525. word16 minProto:1; /* sets min to min available */
  2526. word16 maxProto:1; /* sets max to max available */
  2527. #ifdef WOLFSSL_SRTP
  2528. word16 dtlsSrtpProfiles; /* DTLS-with-SRTP mode
  2529. * (list of selected profiles - up to 16) */
  2530. #endif
  2531. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST)
  2532. byte haveMcast; /* multicast requested */
  2533. byte mcastID; /* multicast group ID */
  2534. #endif
  2535. #if defined(WOLFSSL_DTLS) && \
  2536. (defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU))
  2537. word16 dtlsMtuSz; /* DTLS MTU size */
  2538. #endif
  2539. #ifndef NO_DH
  2540. word16 minDhKeySz; /* minimum DH key size */
  2541. word16 maxDhKeySz; /* maximum DH key size */
  2542. #endif
  2543. #ifndef NO_RSA
  2544. short minRsaKeySz; /* minimum RSA key size */
  2545. #endif
  2546. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  2547. short minEccKeySz; /* minimum ECC key size */
  2548. #endif
  2549. #ifdef HAVE_PQC
  2550. short minFalconKeySz; /* minimum Falcon key size */
  2551. #endif
  2552. unsigned long mask; /* store SSL_OP_ flags */
  2553. #ifdef OPENSSL_EXTRA
  2554. byte sessionCtx[ID_LEN]; /* app session context ID */
  2555. word32 disabledCurves; /* curves disabled by user */
  2556. const unsigned char *alpn_cli_protos;/* ALPN client protocol list */
  2557. unsigned int alpn_cli_protos_len;
  2558. byte sessionCtxSz;
  2559. byte cbioFlag; /* WOLFSSL_CBIO_RECV/SEND: CBIORecv/Send is set */
  2560. CallbackInfoState* CBIS; /* used to get info about SSL state */
  2561. WOLFSSL_X509_VERIFY_PARAM* param; /* verification parameters*/
  2562. #endif
  2563. #ifdef WOLFSSL_WOLFSENTRY_HOOKS
  2564. NetworkFilterCallback_t AcceptFilter;
  2565. void *AcceptFilter_arg;
  2566. NetworkFilterCallback_t ConnectFilter;
  2567. void *ConnectFilter_arg;
  2568. #endif /* WOLFSSL_WOLFSENTRY_HOOKS */
  2569. CallbackIORecv CBIORecv;
  2570. CallbackIOSend CBIOSend;
  2571. #ifdef WOLFSSL_DTLS
  2572. CallbackGenCookie CBIOCookie; /* gen cookie callback */
  2573. #endif /* WOLFSSL_DTLS */
  2574. #ifdef WOLFSSL_SESSION_EXPORT
  2575. #ifdef WOLFSSL_DTLS
  2576. wc_dtls_export dtls_export; /* export function for DTLS session */
  2577. #endif
  2578. CallbackGetPeer CBGetPeer;
  2579. CallbackSetPeer CBSetPeer;
  2580. #endif
  2581. VerifyCallback verifyCallback; /* cert verification callback */
  2582. void* verifyCbCtx; /* cert verify callback user ctx*/
  2583. #ifdef OPENSSL_ALL
  2584. CertVerifyCallback verifyCertCb;
  2585. void* verifyCertCbArg;
  2586. #endif /* OPENSSL_ALL */
  2587. #ifdef OPENSSL_EXTRA
  2588. SSL_Msg_Cb protoMsgCb; /* inspect protocol message callback */
  2589. void* protoMsgCtx; /* user set context with msg callback */
  2590. #endif
  2591. word32 timeout; /* session timeout */
  2592. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  2593. defined(HAVE_ED448)
  2594. word32 ecdhCurveOID; /* curve Ecc_Sum */
  2595. #endif
  2596. #ifdef HAVE_ECC
  2597. word16 eccTempKeySz; /* in octets 20 - 66 */
  2598. #endif
  2599. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  2600. word32 pkCurveOID; /* curve Ecc_Sum */
  2601. #endif
  2602. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  2603. byte havePSK; /* psk key set by user */
  2604. wc_psk_client_callback client_psk_cb; /* client callback */
  2605. wc_psk_server_callback server_psk_cb; /* server callback */
  2606. #ifdef WOLFSSL_TLS13
  2607. wc_psk_client_cs_callback client_psk_cs_cb; /* client callback */
  2608. wc_psk_client_tls13_callback client_psk_tls13_cb; /* client callback */
  2609. wc_psk_server_tls13_callback server_psk_tls13_cb; /* server callback */
  2610. #endif
  2611. void* psk_ctx;
  2612. char server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
  2613. #endif /* HAVE_SESSION_TICKET || !NO_PSK */
  2614. #ifdef WOLFSSL_TLS13
  2615. word16 group[WOLFSSL_MAX_GROUP_COUNT];
  2616. byte numGroups;
  2617. #endif
  2618. #ifdef WOLFSSL_EARLY_DATA
  2619. word32 maxEarlyDataSz;
  2620. #endif
  2621. #ifdef HAVE_ANON
  2622. byte haveAnon; /* User wants to allow Anon suites */
  2623. #endif /* HAVE_ANON */
  2624. #ifdef WOLFSSL_ENCRYPTED_KEYS
  2625. wc_pem_password_cb* passwd_cb;
  2626. void* passwd_userdata;
  2627. #endif
  2628. #ifdef WOLFSSL_LOCAL_X509_STORE
  2629. WOLFSSL_X509_STORE x509_store; /* points to ctx->cm */
  2630. WOLFSSL_X509_STORE* x509_store_pt; /* take ownership of external store */
  2631. #endif
  2632. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(WOLFSSL_WPAS_SMALL)
  2633. byte readAhead;
  2634. void* userPRFArg; /* passed to prf callback */
  2635. #endif
  2636. #ifdef HAVE_EX_DATA
  2637. WOLFSSL_CRYPTO_EX_DATA ex_data;
  2638. #endif
  2639. #if defined(HAVE_ALPN) && (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY))
  2640. CallbackALPNSelect alpnSelect;
  2641. void* alpnSelectArg;
  2642. #endif
  2643. #ifdef HAVE_SNI
  2644. CallbackSniRecv sniRecvCb;
  2645. void* sniRecvCbArg;
  2646. #endif
  2647. #if defined(WOLFSSL_MULTICAST) && defined(WOLFSSL_DTLS)
  2648. CallbackMcastHighwater mcastHwCb; /* Sequence number highwater callback */
  2649. word32 mcastFirstSeq; /* first trigger level */
  2650. word32 mcastSecondSeq; /* second trigger level */
  2651. word32 mcastMaxSeq; /* max level */
  2652. #endif
  2653. #ifdef HAVE_OCSP
  2654. WOLFSSL_OCSP ocsp;
  2655. #endif
  2656. int devId; /* async device id to use */
  2657. #ifdef HAVE_TLS_EXTENSIONS
  2658. TLSX* extensions; /* RFC 6066 TLS Extensions data */
  2659. #ifndef NO_WOLFSSL_SERVER
  2660. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  2661. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2662. OcspRequest* certOcspRequest;
  2663. #endif
  2664. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2665. OcspRequest* chainOcspRequest[MAX_CHAIN_DEPTH];
  2666. #endif
  2667. #endif
  2668. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  2669. SessionTicketEncCb ticketEncCb; /* enc/dec session ticket Cb */
  2670. void* ticketEncCtx; /* session encrypt context */
  2671. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) \
  2672. || defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY)
  2673. ticketCompatCb ticketEncWrapCb; /* callback for OpenSSL ticket key callback */
  2674. #endif
  2675. int ticketHint; /* ticket hint in seconds */
  2676. #ifndef WOLFSSL_NO_DEF_TICKET_ENC_CB
  2677. TicketEncCbCtx ticketKeyCtx;
  2678. #endif
  2679. #endif
  2680. #endif
  2681. #ifdef HAVE_SUPPORTED_CURVES
  2682. byte userCurves; /* indicates user called wolfSSL_CTX_UseSupportedCurve */
  2683. #endif
  2684. #ifdef ATOMIC_USER
  2685. CallbackMacEncrypt MacEncryptCb; /* Atomic User Mac/Encrypt Cb */
  2686. CallbackDecryptVerify DecryptVerifyCb; /* Atomic User Decrypt/Verify Cb */
  2687. #ifdef HAVE_ENCRYPT_THEN_MAC
  2688. CallbackEncryptMac EncryptMacCb; /* Atomic User Mac/Enc Cb */
  2689. CallbackVerifyDecrypt VerifyDecryptCb; /* Atomic User Dec/Verify Cb */
  2690. #endif
  2691. #endif
  2692. #ifdef HAVE_PK_CALLBACKS
  2693. #ifdef HAVE_ECC
  2694. CallbackEccKeyGen EccKeyGenCb; /* User EccKeyGen Callback Handler */
  2695. CallbackEccSign EccSignCb; /* User EccSign Callback handler */
  2696. void* EccSignCtx; /* Ecc Sign Callback Context */
  2697. CallbackEccVerify EccVerifyCb; /* User EccVerify Callback handler */
  2698. CallbackEccSharedSecret EccSharedSecretCb; /* User EccVerify Callback handler */
  2699. #endif /* HAVE_ECC */
  2700. #ifdef HAVE_HKDF
  2701. CallbackHKDFExtract HkdfExtractCb; /* User hkdf Extract Callback handler */
  2702. #endif
  2703. #ifdef HAVE_ED25519
  2704. /* User Ed25519Sign Callback handler */
  2705. CallbackEd25519Sign Ed25519SignCb;
  2706. /* User Ed25519Verify Callback handler */
  2707. CallbackEd25519Verify Ed25519VerifyCb;
  2708. #endif
  2709. #ifdef HAVE_CURVE25519
  2710. /* User X25519 KeyGen Callback Handler */
  2711. CallbackX25519KeyGen X25519KeyGenCb;
  2712. /* User X25519 SharedSecret Callback handler */
  2713. CallbackX25519SharedSecret X25519SharedSecretCb;
  2714. #endif
  2715. #ifdef HAVE_ED448
  2716. /* User Ed448Sign Callback handler */
  2717. CallbackEd448Sign Ed448SignCb;
  2718. /* User Ed448Verify Callback handler */
  2719. CallbackEd448Verify Ed448VerifyCb;
  2720. #endif
  2721. #ifdef HAVE_CURVE448
  2722. /* User X448 KeyGen Callback Handler */
  2723. CallbackX448KeyGen X448KeyGenCb;
  2724. /* User X448 SharedSecret Callback handler */
  2725. CallbackX448SharedSecret X448SharedSecretCb;
  2726. #endif
  2727. #ifndef NO_DH
  2728. CallbackDhAgree DhAgreeCb; /* User DH Agree Callback handler */
  2729. #endif
  2730. #ifndef NO_RSA
  2731. CallbackRsaSign RsaSignCb; /* User RsaSign Callback handler (priv key) */
  2732. CallbackRsaVerify RsaVerifyCb; /* User RsaVerify Callback handler (pub key) */
  2733. CallbackRsaVerify RsaSignCheckCb; /* User VerifyRsaSign Callback handler (priv key) */
  2734. #ifdef WC_RSA_PSS
  2735. CallbackRsaPssSign RsaPssSignCb; /* User RsaSign (priv key) */
  2736. CallbackRsaPssVerify RsaPssVerifyCb; /* User RsaVerify (pub key) */
  2737. CallbackRsaPssVerify RsaPssSignCheckCb; /* User VerifyRsaSign (priv key) */
  2738. #endif
  2739. CallbackRsaEnc RsaEncCb; /* User Rsa Public Encrypt handler */
  2740. CallbackRsaDec RsaDecCb; /* User Rsa Private Decrypt handler */
  2741. #endif /* NO_RSA */
  2742. CallbackGenPreMaster GenPreMasterCb; /* Use generate pre-master handler */
  2743. CallbackGenMasterSecret GenMasterCb; /* Use generate master secret handler */
  2744. CallbackGenSessionKey GenSessionKeyCb; /* Use generate session key handler */
  2745. CallbackEncryptKeys EncryptKeysCb;/* Use setting encrypt keys handler */
  2746. CallbackTlsFinished TlsFinishedCb; /* Use Tls finished handler */
  2747. #if !defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_AEAD_ONLY)
  2748. CallbackVerifyMac VerifyMacCb; /* Use Verify mac handler */
  2749. #endif
  2750. #endif /* HAVE_PK_CALLBACKS */
  2751. #ifdef HAVE_WOLF_EVENT
  2752. WOLF_EVENT_QUEUE event_queue;
  2753. #endif /* HAVE_WOLF_EVENT */
  2754. #ifdef HAVE_EXT_CACHE
  2755. WOLFSSL_SESSION*(*get_sess_cb)(WOLFSSL*, const unsigned char*, int, int*);
  2756. int (*new_sess_cb)(WOLFSSL*, WOLFSSL_SESSION*);
  2757. #endif
  2758. #if defined(HAVE_EXT_CACHE) || defined(HAVE_EX_DATA)
  2759. Rem_Sess_Cb rem_sess_cb;
  2760. #endif
  2761. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && !defined(NO_SHA256)
  2762. Srp* srp; /* TLS Secure Remote Password Protocol*/
  2763. byte* srp_password;
  2764. #endif
  2765. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  2766. wolfSSL_CTX_keylog_cb_func keyLogCb;
  2767. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  2768. #ifdef WOLFSSL_STATIC_EPHEMERAL
  2769. StaticKeyExchangeInfo_t staticKE;
  2770. #ifndef SINGLE_THREADED
  2771. wolfSSL_Mutex staticKELock;
  2772. #endif
  2773. #endif
  2774. };
  2775. WOLFSSL_LOCAL
  2776. int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap);
  2777. WOLFSSL_LOCAL
  2778. void FreeSSL_Ctx(WOLFSSL_CTX* ctx);
  2779. WOLFSSL_LOCAL
  2780. void SSL_CtxResourceFree(WOLFSSL_CTX* ctx);
  2781. #ifdef HAVE_EX_DATA_CLEANUP_HOOKS
  2782. void wolfSSL_CRYPTO_cleanup_ex_data(WOLFSSL_CRYPTO_EX_DATA* ex_data);
  2783. #endif
  2784. WOLFSSL_LOCAL
  2785. int DeriveTlsKeys(WOLFSSL* ssl);
  2786. WOLFSSL_LOCAL
  2787. int ProcessOldClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
  2788. word32 inSz, word16 sz);
  2789. #ifndef NO_CERTS
  2790. WOLFSSL_LOCAL
  2791. int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify);
  2792. WOLFSSL_LOCAL
  2793. int AlreadySigner(WOLFSSL_CERT_MANAGER* cm, byte* hash);
  2794. #ifdef WOLFSSL_TRUST_PEER_CERT
  2795. WOLFSSL_LOCAL
  2796. int AddTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int verify);
  2797. WOLFSSL_LOCAL
  2798. int AlreadyTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DecodedCert* cert);
  2799. #endif
  2800. #endif
  2801. /* All cipher suite related info
  2802. * Keep as a constant size (no ifdefs) for session export */
  2803. typedef struct CipherSpecs {
  2804. word16 key_size;
  2805. word16 iv_size;
  2806. word16 block_size;
  2807. word16 aead_mac_size;
  2808. byte bulk_cipher_algorithm;
  2809. byte cipher_type; /* block, stream, or aead */
  2810. byte mac_algorithm;
  2811. byte kea; /* key exchange algo */
  2812. byte sig_algo;
  2813. byte hash_size;
  2814. byte pad_size;
  2815. byte static_ecdh;
  2816. } CipherSpecs;
  2817. void InitCipherSpecs(CipherSpecs* cs);
  2818. /* Supported Key Exchange Protocols */
  2819. enum KeyExchangeAlgorithm {
  2820. no_kea,
  2821. rsa_kea,
  2822. diffie_hellman_kea,
  2823. fortezza_kea,
  2824. psk_kea,
  2825. dhe_psk_kea,
  2826. ecdhe_psk_kea,
  2827. ecc_diffie_hellman_kea,
  2828. ecc_static_diffie_hellman_kea /* for verify suite only */
  2829. };
  2830. /* Supported Authentication Schemes */
  2831. enum SignatureAlgorithm {
  2832. anonymous_sa_algo = 0,
  2833. rsa_sa_algo = 1,
  2834. dsa_sa_algo = 2,
  2835. ecc_dsa_sa_algo = 3,
  2836. rsa_pss_sa_algo = 8,
  2837. ed25519_sa_algo = 9,
  2838. rsa_pss_pss_algo = 10,
  2839. ed448_sa_algo = 11,
  2840. falcon_level1_sa_algo = 12,
  2841. falcon_level5_sa_algo = 13,
  2842. invalid_sa_algo = 255
  2843. };
  2844. #define PSS_RSAE_TO_PSS_PSS(macAlgo) \
  2845. ((macAlgo) + (pss_sha256 - sha256_mac))
  2846. #define PSS_PSS_HASH_TO_MAC(macAlgo) \
  2847. ((macAlgo) - (pss_sha256 - sha256_mac))
  2848. enum SigAlgRsaPss {
  2849. pss_sha256 = 0x09,
  2850. pss_sha384 = 0x0a,
  2851. pss_sha512 = 0x0b,
  2852. };
  2853. /* Supported ECC Curve Types */
  2854. enum EccCurves {
  2855. named_curve = 3
  2856. };
  2857. /* Valid client certificate request types from page 27 */
  2858. enum ClientCertificateType {
  2859. rsa_sign = 1,
  2860. dss_sign = 2,
  2861. rsa_fixed_dh = 3,
  2862. dss_fixed_dh = 4,
  2863. rsa_ephemeral_dh = 5,
  2864. dss_ephemeral_dh = 6,
  2865. fortezza_kea_cert = 20,
  2866. ecdsa_sign = 64,
  2867. rsa_fixed_ecdh = 65,
  2868. ecdsa_fixed_ecdh = 66,
  2869. falcon_sign = 67,
  2870. };
  2871. #ifndef WOLFSSL_AEAD_ONLY
  2872. enum CipherType { stream, block, aead };
  2873. #else
  2874. enum CipherType { aead };
  2875. #endif
  2876. #if defined(BUILD_AES) || defined(BUILD_AESGCM) || (defined(HAVE_CHACHA) && \
  2877. defined(HAVE_POLY1305)) || defined(WOLFSSL_TLS13)
  2878. #define CIPHER_NONCE
  2879. #endif
  2880. #if defined(WOLFSSL_DTLS) && defined(HAVE_SECURE_RENEGOTIATION)
  2881. enum CipherSrc {
  2882. KEYS_NOT_SET = 0,
  2883. KEYS, /* keys from ssl->keys are loaded */
  2884. SCR /* keys from ssl->secure_renegotiation->tmp_keys are loaded */
  2885. };
  2886. #endif
  2887. /* cipher for now */
  2888. typedef struct Ciphers {
  2889. #ifdef BUILD_ARC4
  2890. Arc4* arc4;
  2891. #endif
  2892. #ifdef BUILD_DES3
  2893. Des3* des3;
  2894. #endif
  2895. #if defined(BUILD_AES) || defined(BUILD_AESGCM)
  2896. Aes* aes;
  2897. #if (defined(BUILD_AESGCM) || defined(HAVE_AESCCM)) && \
  2898. !defined(WOLFSSL_NO_TLS12)
  2899. byte* additional;
  2900. #endif
  2901. #endif
  2902. #ifdef CIPHER_NONCE
  2903. byte* nonce;
  2904. #endif
  2905. #ifdef HAVE_CAMELLIA
  2906. Camellia* cam;
  2907. #endif
  2908. #ifdef HAVE_CHACHA
  2909. ChaCha* chacha;
  2910. #endif
  2911. #if defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER)
  2912. Hmac* hmac;
  2913. #endif
  2914. byte state;
  2915. byte setup; /* have we set it up flag for detection */
  2916. #if defined(WOLFSSL_DTLS) && defined(HAVE_SECURE_RENEGOTIATION)
  2917. enum CipherSrc src; /* DTLS uses this to determine which keys
  2918. * are currently loaded */
  2919. #endif
  2920. } Ciphers;
  2921. #ifdef HAVE_ONE_TIME_AUTH
  2922. /* Ciphers for one time authentication such as poly1305 */
  2923. typedef struct OneTimeAuth {
  2924. #ifdef HAVE_POLY1305
  2925. Poly1305* poly1305;
  2926. #endif
  2927. byte setup; /* flag for if a cipher has been set */
  2928. } OneTimeAuth;
  2929. #endif
  2930. WOLFSSL_LOCAL void InitCiphers(WOLFSSL* ssl);
  2931. WOLFSSL_LOCAL void FreeCiphers(WOLFSSL* ssl);
  2932. /* hashes type */
  2933. typedef struct Hashes {
  2934. #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
  2935. byte md5[WC_MD5_DIGEST_SIZE];
  2936. #endif
  2937. #if !defined(NO_SHA)
  2938. byte sha[WC_SHA_DIGEST_SIZE];
  2939. #endif
  2940. #ifndef NO_SHA256
  2941. byte sha256[WC_SHA256_DIGEST_SIZE];
  2942. #endif
  2943. #ifdef WOLFSSL_SHA384
  2944. byte sha384[WC_SHA384_DIGEST_SIZE];
  2945. #endif
  2946. #ifdef WOLFSSL_SHA512
  2947. byte sha512[WC_SHA512_DIGEST_SIZE];
  2948. #endif
  2949. } Hashes;
  2950. WOLFSSL_LOCAL int BuildCertHashes(WOLFSSL* ssl, Hashes* hashes);
  2951. #ifdef WOLFSSL_TLS13
  2952. typedef union Digest {
  2953. #ifndef NO_WOLFSSL_SHA256
  2954. wc_Sha256 sha256;
  2955. #endif
  2956. #ifdef WOLFSSL_SHA384
  2957. wc_Sha384 sha384;
  2958. #endif
  2959. #ifdef WOLFSSL_SHA512
  2960. wc_Sha512 sha512;
  2961. #endif
  2962. } Digest;
  2963. #endif
  2964. /* Static x509 buffer */
  2965. typedef struct x509_buffer {
  2966. int length; /* actual size */
  2967. byte buffer[MAX_X509_SIZE]; /* max static cert size */
  2968. } x509_buffer;
  2969. /* wolfSSL X509_CHAIN, for no dynamic memory SESSION_CACHE */
  2970. struct WOLFSSL_X509_CHAIN {
  2971. int count; /* total number in chain */
  2972. x509_buffer certs[MAX_CHAIN_DEPTH]; /* only allow max depth 4 for now */
  2973. };
  2974. typedef enum WOLFSSL_SESSION_TYPE {
  2975. WOLFSSL_SESSION_TYPE_UNKNOWN,
  2976. WOLFSSL_SESSION_TYPE_SSL, /* in ssl->session */
  2977. WOLFSSL_SESSION_TYPE_CACHE, /* pointer to internal cache */
  2978. WOLFSSL_SESSION_TYPE_HEAP /* allocated from heap SESSION_new */
  2979. } WOLFSSL_SESSION_TYPE;
  2980. /* wolfSSL session type */
  2981. struct WOLFSSL_SESSION {
  2982. /* WARNING Do not add fields here. They will be ignored in
  2983. * wolfSSL_DupSession. */
  2984. WOLFSSL_SESSION_TYPE type;
  2985. #ifndef NO_SESSION_CACHE
  2986. int cacheRow; /* row in session cache */
  2987. #endif
  2988. int refCount; /* reference count */
  2989. #ifndef SINGLE_THREADED
  2990. wolfSSL_Mutex refMutex; /* ref count mutex */
  2991. #endif
  2992. byte altSessionID[ID_LEN];
  2993. byte haveAltSessionID:1;
  2994. #ifdef HAVE_EX_DATA
  2995. byte ownExData:1;
  2996. Rem_Sess_Cb rem_sess_cb;
  2997. #endif
  2998. void* heap;
  2999. /* WARNING The above fields (up to and including the heap) are not copied
  3000. * in wolfSSL_DupSession. Place new fields after the heap
  3001. * member */
  3002. byte side; /* Either WOLFSSL_CLIENT_END or
  3003. WOLFSSL_SERVER_END */
  3004. word32 bornOn; /* create time in seconds */
  3005. word32 timeout; /* timeout in seconds */
  3006. byte sessionID[ID_LEN]; /* id for protocol or bogus
  3007. * ID for TLS 1.3 */
  3008. byte sessionIDSz;
  3009. byte* masterSecret; /* stored secret */
  3010. word16 haveEMS; /* ext master secret flag */
  3011. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  3012. WOLFSSL_X509* peer; /* peer cert */
  3013. #endif
  3014. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  3015. defined(HAVE_SESSION_TICKET))
  3016. ProtocolVersion version; /* which version was used */
  3017. #endif
  3018. #if defined(SESSION_CERTS) || !defined(NO_RESUME_SUITE_CHECK) || \
  3019. (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET))
  3020. byte cipherSuite0; /* first byte, normally 0 */
  3021. byte cipherSuite; /* 2nd byte, actual suite */
  3022. #endif
  3023. #ifndef NO_CLIENT_CACHE
  3024. word16 idLen; /* serverID length */
  3025. byte* serverID; /* for easier client lookup */
  3026. #endif
  3027. #ifdef OPENSSL_EXTRA
  3028. byte sessionCtxSz; /* sessionCtx length */
  3029. byte* sessionCtx; /* app specific context id */
  3030. #endif /* OPENSSL_EXTRA */
  3031. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3032. byte peerVerifyRet; /* cert verify error */
  3033. #endif
  3034. #ifdef WOLFSSL_TLS13
  3035. word16 namedGroup;
  3036. #endif
  3037. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  3038. #ifdef WOLFSSL_TLS13
  3039. word32 ticketSeen; /* Time ticket seen (ms) */
  3040. word32 ticketAdd; /* Added by client */
  3041. TicketNonce ticketNonce; /* Nonce used to derive PSK */
  3042. #endif
  3043. #ifdef WOLFSSL_EARLY_DATA
  3044. word32 maxEarlyDataSz;
  3045. #endif
  3046. #endif
  3047. #ifdef HAVE_SESSION_TICKET
  3048. byte* ticket;
  3049. word16 ticketLen;
  3050. word16 ticketLenAlloc; /* is dynamic */
  3051. #endif
  3052. #ifdef SESSION_CERTS
  3053. WOLFSSL_X509_CHAIN chain; /* peer cert chain, static */
  3054. #ifdef WOLFSSL_ALT_CERT_CHAINS
  3055. WOLFSSL_X509_CHAIN altChain; /* peer alt cert chain, static */
  3056. #endif
  3057. #endif
  3058. #ifdef HAVE_EX_DATA
  3059. WOLFSSL_CRYPTO_EX_DATA ex_data;
  3060. #endif
  3061. /* Below buffers are not allocated for the WOLFSSL_SESSION_TYPE_REF, instead
  3062. * the above pointers reference the session cache for backwards
  3063. * compatibility. For all other session types the above pointers reference
  3064. * these buffers directly. Keep these buffers at the end so that they don't
  3065. * get copied into the WOLFSSL_SESSION_TYPE_REF object. */
  3066. byte _masterSecret[SECRET_LEN];
  3067. #ifndef NO_CLIENT_CACHE
  3068. byte _serverID[SERVER_ID_LEN];
  3069. #endif
  3070. #ifdef HAVE_SESSION_TICKET
  3071. byte _staticTicket[SESSION_TICKET_LEN];
  3072. #endif
  3073. #ifdef OPENSSL_EXTRA
  3074. byte _sessionCtx[ID_LEN];
  3075. #endif
  3076. };
  3077. WOLFSSL_LOCAL int wolfSSL_RAND_Init(void);
  3078. WOLFSSL_LOCAL WOLFSSL_SESSION* wolfSSL_NewSession(void* heap);
  3079. WOLFSSL_LOCAL WOLFSSL_SESSION* wolfSSL_GetSession(
  3080. WOLFSSL* ssl, byte* masterSecret, byte restoreSessionCerts);
  3081. WOLFSSL_LOCAL void AddSession(WOLFSSL* ssl);
  3082. WOLFSSL_LOCAL int AddSessionToCache(WOLFSSL_CTX* ssl,
  3083. WOLFSSL_SESSION* addSession, const byte* id, byte idSz, int* sessionIndex,
  3084. int side, word16 useTicket, ClientSession** clientCacheEntry);
  3085. #ifndef NO_CLIENT_CACHE
  3086. WOLFSSL_LOCAL ClientSession* AddSessionToClientCache(int side, int row, int idx,
  3087. byte* serverID, word16 idLen, const byte* sessionID,
  3088. word16 useTicket);
  3089. #endif
  3090. WOLFSSL_LOCAL
  3091. WOLFSSL_SESSION* ClientSessionToSession(const WOLFSSL_SESSION* session);
  3092. WOLFSSL_LOCAL int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output);
  3093. WOLFSSL_LOCAL int wolfSSL_SetSession(WOLFSSL* ssl, WOLFSSL_SESSION* session);
  3094. WOLFSSL_LOCAL void wolfSSL_FreeSession(WOLFSSL_CTX* ctx,
  3095. WOLFSSL_SESSION* session);
  3096. WOLFSSL_LOCAL int wolfSSL_DupSession(const WOLFSSL_SESSION* input,
  3097. WOLFSSL_SESSION* output, int avoidSysCalls);
  3098. typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int, int, int);
  3099. #ifndef NO_CLIENT_CACHE
  3100. WOLFSSL_LOCAL WOLFSSL_SESSION* wolfSSL_GetSessionClient(
  3101. WOLFSSL* ssl, const byte* id, int len);
  3102. #endif
  3103. /* client connect state for nonblocking restart */
  3104. enum ConnectState {
  3105. CONNECT_BEGIN = 0,
  3106. CLIENT_HELLO_SENT,
  3107. HELLO_AGAIN, /* HELLO_AGAIN s for DTLS case */
  3108. HELLO_AGAIN_REPLY,
  3109. FIRST_REPLY_DONE,
  3110. FIRST_REPLY_FIRST,
  3111. FIRST_REPLY_SECOND,
  3112. FIRST_REPLY_THIRD,
  3113. FIRST_REPLY_FOURTH,
  3114. FINISHED_DONE,
  3115. SECOND_REPLY_DONE
  3116. };
  3117. /* server accept state for nonblocking restart */
  3118. enum AcceptState {
  3119. ACCEPT_BEGIN = 0,
  3120. ACCEPT_BEGIN_RENEG,
  3121. ACCEPT_CLIENT_HELLO_DONE,
  3122. ACCEPT_HELLO_RETRY_REQUEST_DONE,
  3123. ACCEPT_FIRST_REPLY_DONE,
  3124. SERVER_HELLO_SENT,
  3125. CERT_SENT,
  3126. CERT_VERIFY_SENT,
  3127. CERT_STATUS_SENT,
  3128. KEY_EXCHANGE_SENT,
  3129. CERT_REQ_SENT,
  3130. SERVER_HELLO_DONE,
  3131. ACCEPT_SECOND_REPLY_DONE,
  3132. TICKET_SENT,
  3133. CHANGE_CIPHER_SENT,
  3134. ACCEPT_FINISHED_DONE,
  3135. ACCEPT_THIRD_REPLY_DONE
  3136. };
  3137. /* TLS 1.3 server accept state for nonblocking restart */
  3138. enum AcceptStateTls13 {
  3139. TLS13_ACCEPT_BEGIN = 0,
  3140. TLS13_ACCEPT_BEGIN_RENEG,
  3141. TLS13_ACCEPT_CLIENT_HELLO_DONE,
  3142. TLS13_ACCEPT_HELLO_RETRY_REQUEST_DONE,
  3143. TLS13_ACCEPT_FIRST_REPLY_DONE,
  3144. TLS13_ACCEPT_SECOND_REPLY_DONE,
  3145. TLS13_SERVER_HELLO_SENT,
  3146. TLS13_ACCEPT_THIRD_REPLY_DONE,
  3147. TLS13_SERVER_EXTENSIONS_SENT,
  3148. TLS13_CERT_REQ_SENT,
  3149. TLS13_CERT_SENT,
  3150. TLS13_CERT_VERIFY_SENT,
  3151. TLS13_ACCEPT_FINISHED_SENT,
  3152. TLS13_PRE_TICKET_SENT,
  3153. TLS13_ACCEPT_FINISHED_DONE,
  3154. TLS13_TICKET_SENT
  3155. };
  3156. /* buffers for struct WOLFSSL */
  3157. typedef struct Buffers {
  3158. bufferStatic inputBuffer;
  3159. bufferStatic outputBuffer;
  3160. buffer domainName; /* for client check */
  3161. buffer clearOutputBuffer;
  3162. buffer sig; /* signature data */
  3163. buffer digest; /* digest data */
  3164. int prevSent; /* previous plain text bytes sent
  3165. when got WANT_WRITE */
  3166. int plainSz; /* plain text bytes in buffer to send
  3167. when got WANT_WRITE */
  3168. byte weOwnCert; /* SSL own cert flag */
  3169. byte weOwnCertChain; /* SSL own cert chain flag */
  3170. byte weOwnKey; /* SSL own key flag */
  3171. byte weOwnDH; /* SSL own dh (p,g) flag */
  3172. #ifndef NO_DH
  3173. buffer serverDH_P; /* WOLFSSL_CTX owns, unless we own */
  3174. buffer serverDH_G; /* WOLFSSL_CTX owns, unless we own */
  3175. buffer serverDH_Pub;
  3176. buffer serverDH_Priv;
  3177. DhKey* serverDH_Key;
  3178. #endif
  3179. #ifndef NO_CERTS
  3180. DerBuffer* certificate; /* WOLFSSL_CTX owns, unless we own */
  3181. DerBuffer* key; /* WOLFSSL_CTX owns, unless we own */
  3182. byte keyType:6; /* Type of key: RSA, ECC, Ed25519 */
  3183. byte keyId:1; /* Key data is an id not data */
  3184. byte keyLabel:1; /* Key data is a label not data */
  3185. int keySz; /* Size of RSA key */
  3186. int keyDevId; /* Device Id for key */
  3187. DerBuffer* certChain; /* WOLFSSL_CTX owns, unless we own */
  3188. /* chain after self, in DER, with leading size for each cert */
  3189. #ifdef WOLFSSL_TLS13
  3190. int certChainCnt;
  3191. DerBuffer* certExts;
  3192. #endif
  3193. #endif
  3194. #ifdef WOLFSSL_SEND_HRR_COOKIE
  3195. buffer tls13CookieSecret; /* HRR cookie secret */
  3196. #endif
  3197. #ifdef WOLFSSL_DTLS
  3198. WOLFSSL_DTLS_CTX dtlsCtx; /* DTLS connection context */
  3199. #ifndef NO_WOLFSSL_SERVER
  3200. buffer dtlsCookieSecret; /* DTLS cookie secret */
  3201. #endif /* NO_WOLFSSL_SERVER */
  3202. #endif
  3203. #ifdef HAVE_PK_CALLBACKS
  3204. #ifdef HAVE_ECC
  3205. buffer peerEccDsaKey; /* we own for Ecc Verify Callbacks */
  3206. #endif /* HAVE_ECC */
  3207. #ifdef HAVE_ED25519
  3208. buffer peerEd25519Key; /* for Ed25519 Verify Callbacks */
  3209. #endif /* HAVE_ED25519 */
  3210. #ifdef HAVE_ED448
  3211. buffer peerEd448Key; /* for Ed448 Verify Callbacks */
  3212. #endif /* HAVE_ED448 */
  3213. #ifndef NO_RSA
  3214. buffer peerRsaKey; /* we own for Rsa Verify Callbacks */
  3215. #endif /* NO_RSA */
  3216. #endif /* HAVE_PK_CALLBACKS */
  3217. } Buffers;
  3218. /* sub-states for send/do key share (key exchange) */
  3219. enum asyncState {
  3220. TLS_ASYNC_BEGIN = 0,
  3221. TLS_ASYNC_BUILD,
  3222. TLS_ASYNC_DO,
  3223. TLS_ASYNC_VERIFY,
  3224. TLS_ASYNC_FINALIZE,
  3225. TLS_ASYNC_END
  3226. };
  3227. /* sub-states for build message */
  3228. enum buildMsgState {
  3229. BUILD_MSG_BEGIN = 0,
  3230. BUILD_MSG_SIZE,
  3231. BUILD_MSG_HASH,
  3232. BUILD_MSG_VERIFY_MAC,
  3233. BUILD_MSG_ENCRYPT,
  3234. BUILD_MSG_ENCRYPTED_VERIFY_MAC,
  3235. };
  3236. /* sub-states for cipher operations */
  3237. enum cipherState {
  3238. CIPHER_STATE_BEGIN = 0,
  3239. CIPHER_STATE_DO,
  3240. CIPHER_STATE_END,
  3241. };
  3242. typedef struct Options {
  3243. #ifndef NO_PSK
  3244. wc_psk_client_callback client_psk_cb;
  3245. wc_psk_server_callback server_psk_cb;
  3246. #ifdef OPENSSL_EXTRA
  3247. wc_psk_use_session_cb_func session_psk_cb;
  3248. #endif
  3249. #ifdef WOLFSSL_TLS13
  3250. wc_psk_client_cs_callback client_psk_cs_cb; /* client callback */
  3251. wc_psk_client_tls13_callback client_psk_tls13_cb; /* client callback */
  3252. wc_psk_server_tls13_callback server_psk_tls13_cb; /* server callback */
  3253. #endif
  3254. void* psk_ctx;
  3255. #endif /* NO_PSK */
  3256. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(WOLFSSL_WPAS_SMALL)
  3257. unsigned long mask; /* store SSL_OP_ flags */
  3258. word16 minProto:1; /* sets min to min available */
  3259. word16 maxProto:1; /* sets max to max available */
  3260. #endif
  3261. #if defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TLS13)
  3262. unsigned int maxTicketTls13; /* maximum number of tickets to send */
  3263. unsigned int ticketsSent; /* keep track of the total sent */
  3264. #endif
  3265. /* on/off or small bit flags, optimize layout */
  3266. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  3267. word16 havePSK:1; /* psk key set by user */
  3268. #endif /* HAVE_SESSION_TICKET || !NO_PSK */
  3269. word16 sendVerify:2; /* false = 0, true = 1, sendBlank = 2 */
  3270. word16 sessionCacheOff:1;
  3271. word16 sessionCacheFlushOff:1;
  3272. #ifdef HAVE_EXT_CACHE
  3273. word16 internalCacheOff:1;
  3274. word16 internalCacheLookupOff:1;
  3275. #endif
  3276. word16 side:2; /* client, server or neither end */
  3277. word16 verifyPeer:1;
  3278. word16 verifyNone:1;
  3279. word16 failNoCert:1;
  3280. word16 failNoCertxPSK:1; /* fail for no cert except with PSK */
  3281. word16 downgrade:1; /* allow downgrade of versions */
  3282. word16 resuming:1;
  3283. word16 isPSK:1;
  3284. word16 haveSessionId:1; /* server may not send */
  3285. word16 tls:1; /* using TLS ? */
  3286. word16 tls1_1:1; /* using TLSv1.1+ ? */
  3287. word16 tls1_3:1; /* using TLSv1.3+ ? */
  3288. word16 dtls:1; /* using datagrams ? */
  3289. word16 connReset:1; /* has the peer reset */
  3290. word16 isClosed:1; /* if we consider conn closed */
  3291. word16 closeNotify:1; /* we've received a close notify */
  3292. word16 sentNotify:1; /* we've sent a close notify */
  3293. word16 usingCompression:1; /* are we using compression */
  3294. word16 haveRSA:1; /* RSA available */
  3295. word16 haveECC:1; /* ECC available */
  3296. word16 haveDH:1; /* server DH parms set by user */
  3297. word16 haveECDSAsig:1; /* server ECDSA signed cert */
  3298. word16 haveStaticECC:1; /* static server ECC private key */
  3299. word16 haveFalconSig:1; /* server Falcon signed cert */
  3300. word16 havePeerCert:1; /* do we have peer's cert */
  3301. word16 havePeerVerify:1; /* and peer's cert verify */
  3302. word16 usingPSK_cipher:1; /* are using psk as cipher */
  3303. word16 usingAnon_cipher:1; /* are we using an anon cipher */
  3304. word16 noPskDheKe:1; /* Don't use (EC)DHE with PSK */
  3305. word16 sendAlertState:1; /* nonblocking resume */
  3306. word16 partialWrite:1; /* only one msg per write call */
  3307. word16 quietShutdown:1; /* don't send close notify */
  3308. word16 certOnly:1; /* stop once we get cert */
  3309. word16 groupMessages:1; /* group handshake messages */
  3310. word16 saveArrays:1; /* save array Memory for user get keys
  3311. or psk */
  3312. word16 weOwnRng:1; /* will be true unless CTX owns */
  3313. word16 haveEMS:1; /* using extended master secret */
  3314. #ifdef HAVE_POLY1305
  3315. word16 oldPoly:1; /* set when to use old rfc way of poly*/
  3316. #endif
  3317. word16 haveAnon:1; /* User wants to allow Anon suites */
  3318. #ifdef HAVE_SESSION_TICKET
  3319. word16 createTicket:1; /* Server to create new Ticket */
  3320. word16 useTicket:1; /* Use Ticket not session cache */
  3321. word16 rejectTicket:1; /* Callback rejected ticket */
  3322. word16 noTicketTls12:1; /* TLS 1.2 server won't send ticket */
  3323. #ifdef WOLFSSL_TLS13
  3324. word16 noTicketTls13:1; /* Server won't create new Ticket */
  3325. #endif
  3326. #endif
  3327. #ifdef WOLFSSL_DTLS
  3328. word16 dtlsUseNonblock:1; /* are we using nonblocking socket */
  3329. word16 dtlsHsRetain:1; /* DTLS retaining HS data */
  3330. word16 haveMcast:1; /* using multicast ? */
  3331. #ifdef WOLFSSL_SCTP
  3332. word16 dtlsSctp:1; /* DTLS-over-SCTP mode */
  3333. #endif
  3334. #endif /* WOLFSSL_DTLS */
  3335. #if defined(HAVE_TLS_EXTENSIONS) && defined(HAVE_SUPPORTED_CURVES)
  3336. word16 userCurves:1; /* indicates user called wolfSSL_UseSupportedCurve */
  3337. #endif
  3338. word16 keepResources:1; /* Keep resources after handshake */
  3339. word16 useClientOrder:1; /* Use client's cipher order */
  3340. word16 mutualAuth:1; /* Mutual authentication is required */
  3341. word16 peerAuthGood:1; /* Any required peer auth done */
  3342. #if defined(WOLFSSL_TLS13) && (defined(HAVE_SESSION_TICKET) || !defined(NO_PSK))
  3343. word16 pskNegotiated:1; /* Session Ticket/PSK negotiated. */
  3344. #endif
  3345. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  3346. word16 postHandshakeAuth:1;/* Client send post_handshake_auth
  3347. * extension */
  3348. word16 verifyPostHandshake:1; /* Only send client cert req post
  3349. * handshake, not also during */
  3350. #endif
  3351. #if defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_SERVER)
  3352. word16 sendCookie:1; /* Server creates a Cookie in HRR */
  3353. #endif
  3354. #ifdef WOLFSSL_ALT_CERT_CHAINS
  3355. word16 usingAltCertChain:1;/* Alternate cert chain was used */
  3356. #endif
  3357. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  3358. word16 sentChangeCipher:1; /* Change Cipher Spec sent */
  3359. #endif
  3360. #if !defined(WOLFSSL_NO_CLIENT_AUTH) && \
  3361. ((defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \
  3362. (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH)))
  3363. word16 cacheMessages:1; /* Cache messages for sign/verify */
  3364. #endif
  3365. #ifndef NO_DH
  3366. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && \
  3367. !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  3368. word16 dhDoKeyTest:1; /* Need to do the DH Key prime test */
  3369. word16 dhKeyTested:1; /* Set when key has been tested. */
  3370. #endif
  3371. #endif
  3372. #ifdef SINGLE_THREADED
  3373. word16 ownSuites:1; /* if suites are malloced in ssl object */
  3374. #endif
  3375. #ifdef HAVE_ENCRYPT_THEN_MAC
  3376. word16 disallowEncThenMac:1; /* Don't do Encrypt-Then-MAC */
  3377. word16 encThenMac:1; /* Doing Encrypt-Then-MAC */
  3378. word16 startedETMRead:1; /* Doing Encrypt-Then-MAC read */
  3379. word16 startedETMWrite:1; /* Doing Encrypt-Then-MAC write */
  3380. #endif
  3381. #ifdef WOLFSSL_ASYNC_CRYPT
  3382. word16 buildArgsSet:1; /* buildArgs are set and need to
  3383. * be free'd */
  3384. #endif
  3385. word16 buildingMsg:1; /* If set then we need to re-enter the
  3386. * handshake logic. */
  3387. /* need full byte values for this section */
  3388. byte processReply; /* nonblocking resume */
  3389. byte cipherSuite0; /* first byte, normally 0 */
  3390. byte cipherSuite; /* second byte, actual suite */
  3391. byte serverState;
  3392. byte clientState;
  3393. byte handShakeState;
  3394. byte handShakeDone; /* at least one handshake complete */
  3395. byte minDowngrade; /* minimum downgrade version */
  3396. byte connectState; /* nonblocking resume */
  3397. byte acceptState; /* nonblocking resume */
  3398. byte asyncState; /* sub-state for enum asyncState */
  3399. byte buildMsgState; /* sub-state for enum buildMsgState */
  3400. byte alertCount; /* detect warning dos attempt */
  3401. #ifdef WOLFSSL_MULTICAST
  3402. word16 mcastID; /* Multicast group ID */
  3403. #endif
  3404. #ifndef NO_DH
  3405. word16 minDhKeySz; /* minimum DH key size */
  3406. word16 maxDhKeySz; /* minimum DH key size */
  3407. word16 dhKeySz; /* actual DH key size */
  3408. #endif
  3409. #ifndef NO_RSA
  3410. short minRsaKeySz; /* minimum RSA key size */
  3411. #endif
  3412. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  3413. short minEccKeySz; /* minimum ECC key size */
  3414. #endif
  3415. #if defined(HAVE_PQC)
  3416. short minFalconKeySz; /* minimum Falcon key size */
  3417. #endif
  3418. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3419. byte verifyDepth; /* maximum verification depth */
  3420. #endif
  3421. #ifdef WOLFSSL_EARLY_DATA
  3422. word16 pskIdIndex;
  3423. word32 maxEarlyDataSz;
  3424. #endif
  3425. #ifdef WOLFSSL_TLS13
  3426. byte oldMinor; /* client preferred version < TLS 1.3 */
  3427. #endif
  3428. } Options;
  3429. typedef struct Arrays {
  3430. byte* pendingMsg; /* defrag buffer */
  3431. byte* preMasterSecret;
  3432. word32 preMasterSz; /* differs for DH, actual size */
  3433. word32 pendingMsgSz; /* defrag buffer size */
  3434. word32 pendingMsgOffset; /* current offset into defrag buffer */
  3435. #if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
  3436. word32 psk_keySz; /* actual size */
  3437. char client_identity[MAX_PSK_ID_LEN + NULL_TERM_LEN];
  3438. char server_hint[MAX_PSK_ID_LEN + NULL_TERM_LEN];
  3439. byte psk_key[MAX_PSK_KEY_LEN];
  3440. #endif
  3441. byte clientRandom[RAN_LEN];
  3442. byte serverRandom[RAN_LEN];
  3443. byte sessionID[ID_LEN];
  3444. byte sessionIDSz;
  3445. #ifdef WOLFSSL_TLS13
  3446. byte secret[SECRET_LEN];
  3447. #endif
  3448. #ifdef HAVE_KEYING_MATERIAL
  3449. byte exporterSecret[WC_MAX_DIGEST_SIZE];
  3450. #endif
  3451. byte masterSecret[SECRET_LEN];
  3452. #if defined(WOLFSSL_RENESAS_TSIP_TLS) && \
  3453. !defined(NO_WOLFSSL_RENESAS_TSIP_TLS_SESSION)
  3454. byte tsip_masterSecret[TSIP_TLS_MASTERSECRET_SIZE];
  3455. #endif
  3456. #if defined(WOLFSSL_RENESAS_SCEPROTECT)
  3457. byte sce_masterSecret[SCE_TLS_MASTERSECRET_SIZE];
  3458. #endif
  3459. #ifdef WOLFSSL_DTLS
  3460. byte cookie[MAX_COOKIE_LEN];
  3461. byte cookieSz;
  3462. #endif
  3463. byte pendingMsgType; /* defrag buffer message type */
  3464. } Arrays;
  3465. #ifndef ASN_NAME_MAX
  3466. #ifndef NO_ASN
  3467. /* use value from asn.h */
  3468. #define ASN_NAME_MAX WC_ASN_NAME_MAX
  3469. #else
  3470. /* calculate for WOLFSSL_X509 */
  3471. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  3472. defined(WOLFSSL_CERT_EXT)
  3473. #define ASN_NAME_MAX 330
  3474. #else
  3475. #define ASN_NAME_MAX 256
  3476. #endif
  3477. #endif
  3478. #endif
  3479. #ifndef MAX_DATE_SZ
  3480. #define MAX_DATE_SZ 32
  3481. #endif
  3482. typedef enum {
  3483. STACK_TYPE_X509 = 0,
  3484. STACK_TYPE_GEN_NAME = 1,
  3485. STACK_TYPE_BIO = 2,
  3486. STACK_TYPE_OBJ = 3,
  3487. STACK_TYPE_STRING = 4,
  3488. STACK_TYPE_CIPHER = 5,
  3489. STACK_TYPE_ACCESS_DESCRIPTION = 6,
  3490. STACK_TYPE_X509_EXT = 7,
  3491. STACK_TYPE_NULL = 8,
  3492. STACK_TYPE_X509_NAME = 9,
  3493. STACK_TYPE_CONF_VALUE = 10,
  3494. STACK_TYPE_X509_INFO = 11,
  3495. STACK_TYPE_BY_DIR_entry = 12,
  3496. STACK_TYPE_BY_DIR_hash = 13,
  3497. STACK_TYPE_X509_OBJ = 14,
  3498. STACK_TYPE_DIST_POINT = 15,
  3499. STACK_TYPE_X509_CRL = 16,
  3500. STACK_TYPE_X509_NAME_ENTRY = 17,
  3501. STACK_TYPE_X509_REQ_ATTR = 18,
  3502. } WOLF_STACK_TYPE;
  3503. struct WOLFSSL_STACK {
  3504. unsigned long num; /* number of nodes in stack
  3505. * (safety measure for freeing and shortcut for count) */
  3506. #if defined(OPENSSL_ALL)
  3507. wolf_sk_compare_cb comp;
  3508. wolf_sk_hash_cb hash_fn;
  3509. unsigned long hash;
  3510. #endif
  3511. union {
  3512. WOLFSSL_X509* x509;
  3513. WOLFSSL_X509_NAME* name;
  3514. WOLFSSL_X509_NAME_ENTRY* name_entry;
  3515. WOLFSSL_X509_INFO* info;
  3516. WOLFSSL_BIO* bio;
  3517. WOLFSSL_ASN1_OBJECT* obj;
  3518. WOLFSSL_CIPHER cipher;
  3519. WOLFSSL_ACCESS_DESCRIPTION* access;
  3520. WOLFSSL_X509_EXTENSION* ext;
  3521. #ifdef OPENSSL_EXTRA
  3522. WOLFSSL_CONF_VALUE* conf;
  3523. #endif
  3524. void* generic;
  3525. char* string;
  3526. WOLFSSL_GENERAL_NAME* gn;
  3527. WOLFSSL_BY_DIR_entry* dir_entry;
  3528. WOLFSSL_BY_DIR_HASH* dir_hash;
  3529. WOLFSSL_X509_OBJECT* x509_obj;
  3530. WOLFSSL_DIST_POINT* dp;
  3531. WOLFSSL_X509_CRL* crl;
  3532. } data;
  3533. void* heap; /* memory heap hint */
  3534. WOLFSSL_STACK* next;
  3535. WOLF_STACK_TYPE type; /* Identifies type of stack. */
  3536. };
  3537. struct WOLFSSL_X509_NAME {
  3538. char *name;
  3539. int dynamicName;
  3540. int sz;
  3541. char staticName[ASN_NAME_MAX];
  3542. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  3543. !defined(NO_ASN)
  3544. DecodedName fullName;
  3545. int entrySz; /* number of entries */
  3546. WOLFSSL_X509_NAME_ENTRY entry[MAX_NAME_ENTRIES]; /* all entries i.e. CN */
  3547. WOLFSSL_X509* x509; /* x509 that struct belongs to */
  3548. #endif /* OPENSSL_EXTRA */
  3549. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(HAVE_LIGHTY)
  3550. byte raw[ASN_NAME_MAX];
  3551. int rawLen;
  3552. WOLF_STACK_OF(WOLFSSL_X509_NAME_ENTRY)* entries;
  3553. #endif
  3554. void* heap;
  3555. };
  3556. #ifndef EXTERNAL_SERIAL_SIZE
  3557. #define EXTERNAL_SERIAL_SIZE 32
  3558. #endif
  3559. #ifdef NO_ASN
  3560. typedef struct DNS_entry DNS_entry;
  3561. #endif
  3562. struct WOLFSSL_X509 {
  3563. int version;
  3564. int serialSz;
  3565. #ifdef WOLFSSL_SEP
  3566. int deviceTypeSz;
  3567. int hwTypeSz;
  3568. byte deviceType[EXTERNAL_SERIAL_SIZE];
  3569. byte hwType[EXTERNAL_SERIAL_SIZE];
  3570. int hwSerialNumSz;
  3571. byte hwSerialNum[EXTERNAL_SERIAL_SIZE];
  3572. #endif /* WOLFSSL_SEP */
  3573. #if (defined(WOLFSSL_SEP) || defined(WOLFSSL_QT) || defined (OPENSSL_ALL)) && \
  3574. (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL))
  3575. byte certPolicySet;
  3576. byte certPolicyCrit;
  3577. #endif /* (WOLFSSL_SEP || WOLFSSL_QT) && (OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL) */
  3578. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  3579. WOLFSSL_STACK* ext_sk; /* Store X509_EXTENSIONS from wolfSSL_X509_get_ext */
  3580. WOLFSSL_STACK* ext_sk_full; /* Store X509_EXTENSIONS from wolfSSL_X509_get0_extensions */
  3581. WOLFSSL_STACK* ext_d2i;/* Store d2i extensions from wolfSSL_X509_get_ext_d2i */
  3582. #endif /* WOLFSSL_QT || OPENSSL_ALL */
  3583. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
  3584. WOLFSSL_ASN1_INTEGER* serialNumber; /* Stores SN from wolfSSL_X509_get_serialNumber */
  3585. #endif
  3586. WOLFSSL_ASN1_TIME notBefore;
  3587. WOLFSSL_ASN1_TIME notAfter;
  3588. buffer sig;
  3589. int sigOID;
  3590. DNS_entry* altNames; /* alt names list */
  3591. buffer pubKey;
  3592. int pubKeyOID;
  3593. DNS_entry* altNamesNext; /* hint for retrieval */
  3594. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448) || \
  3595. defined(HAVE_PQC)
  3596. word32 pkCurveOID;
  3597. #endif /* HAVE_ECC || HAVE_PQC */
  3598. #ifndef NO_CERTS
  3599. DerBuffer* derCert; /* may need */
  3600. #endif
  3601. void* heap; /* heap hint */
  3602. byte dynamicMemory; /* dynamic memory flag */
  3603. byte isCa:1;
  3604. #ifdef WOLFSSL_CERT_EXT
  3605. char certPolicies[MAX_CERTPOL_NB][MAX_CERTPOL_SZ];
  3606. int certPoliciesNb;
  3607. #endif /* WOLFSSL_CERT_EXT */
  3608. #if defined(OPENSSL_EXTRA_X509_SMALL) || defined(OPENSSL_EXTRA)
  3609. #ifndef SINGLE_THREADED
  3610. wolfSSL_Mutex refMutex; /* ref count mutex */
  3611. #endif
  3612. int refCount; /* reference count */
  3613. #endif
  3614. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3615. #ifdef HAVE_EX_DATA
  3616. WOLFSSL_CRYPTO_EX_DATA ex_data;
  3617. #endif
  3618. byte* authKeyId; /* Points into authKeyIdSrc */
  3619. byte* authKeyIdSrc;
  3620. byte* subjKeyId;
  3621. byte* extKeyUsageSrc;
  3622. #ifdef OPENSSL_ALL
  3623. byte* subjAltNameSrc;
  3624. #endif
  3625. byte* rawCRLInfo;
  3626. byte* CRLInfo;
  3627. byte* authInfo;
  3628. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  3629. byte* authInfoCaIssuer;
  3630. int authInfoCaIssuerSz;
  3631. #endif
  3632. word32 pathLength;
  3633. word16 keyUsage;
  3634. int rawCRLInfoSz;
  3635. int CRLInfoSz;
  3636. int authInfoSz;
  3637. word32 authKeyIdSz;
  3638. word32 authKeyIdSrcSz;
  3639. word32 subjKeyIdSz;
  3640. byte extKeyUsage;
  3641. word32 extKeyUsageSz;
  3642. word32 extKeyUsageCount;
  3643. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  3644. byte nsCertType;
  3645. #endif
  3646. #ifdef OPENSSL_ALL
  3647. word32 subjAltNameSz;
  3648. #endif
  3649. byte CRLdistSet:1;
  3650. byte CRLdistCrit:1;
  3651. byte authInfoSet:1;
  3652. byte authInfoCrit:1;
  3653. byte keyUsageSet:1;
  3654. byte keyUsageCrit:1;
  3655. byte extKeyUsageCrit:1;
  3656. byte subjKeyIdSet:1;
  3657. byte subjKeyIdCrit:1;
  3658. byte basicConstSet:1;
  3659. byte basicConstCrit:1;
  3660. byte basicConstPlSet:1;
  3661. byte subjAltNameSet:1;
  3662. byte subjAltNameCrit:1;
  3663. byte authKeyIdSet:1;
  3664. byte authKeyIdCrit:1;
  3665. byte issuerSet:1;
  3666. #endif /* OPENSSL_EXTRA || OPENSSL_EXTRA_X509_SMALL */
  3667. #ifdef WOLFSSL_CERT_REQ
  3668. byte isCSR:1;
  3669. #endif
  3670. byte serial[EXTERNAL_SERIAL_SIZE];
  3671. char subjectCN[ASN_NAME_MAX]; /* common name short cut */
  3672. #if defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_GEN)
  3673. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  3674. /* stack of CSR attributes */
  3675. WOLF_STACK_OF(WOLFSSL_X509_ATRIBUTE)* reqAttributes;
  3676. #endif
  3677. #if defined(WOLFSSL_CERT_REQ)
  3678. char challengePw[CTC_NAME_SIZE]; /* for REQ certs */
  3679. char contentType[CTC_NAME_SIZE];
  3680. #endif
  3681. #endif /* WOLFSSL_CERT_REQ || WOLFSSL_CERT_GEN */
  3682. WOLFSSL_X509_NAME issuer;
  3683. WOLFSSL_X509_NAME subject;
  3684. #if defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  3685. WOLFSSL_X509_ALGOR algor;
  3686. WOLFSSL_X509_PUBKEY key;
  3687. #endif
  3688. #if defined(OPENSSL_EXTRA_X509_SMALL) || defined(OPENSSL_EXTRA) || \
  3689. defined(OPENSSL_ALL) || defined(KEEP_OUR_CERT) || \
  3690. defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)
  3691. byte notBeforeData[CTC_DATE_SIZE];
  3692. byte notAfterData[CTC_DATE_SIZE];
  3693. #endif
  3694. };
  3695. /* record layer header for PlainText, Compressed, and CipherText */
  3696. typedef struct RecordLayerHeader {
  3697. byte type;
  3698. byte pvMajor;
  3699. byte pvMinor;
  3700. byte length[2];
  3701. } RecordLayerHeader;
  3702. /* record layer header for DTLS PlainText, Compressed, and CipherText */
  3703. typedef struct DtlsRecordLayerHeader {
  3704. byte type;
  3705. byte pvMajor;
  3706. byte pvMinor;
  3707. byte sequence_number[8]; /* per record */
  3708. byte length[2];
  3709. } DtlsRecordLayerHeader;
  3710. typedef struct DtlsFrag {
  3711. word32 begin;
  3712. word32 end;
  3713. struct DtlsFrag* next;
  3714. } DtlsFrag;
  3715. typedef struct DtlsMsg {
  3716. struct DtlsMsg* next;
  3717. byte* buf;
  3718. byte* msg;
  3719. DtlsFrag* fragList;
  3720. word32 fragSz; /* Length of fragments received */
  3721. word16 epoch; /* Epoch that this message belongs to */
  3722. word32 seq; /* Handshake sequence number */
  3723. word32 sz; /* Length of whole message */
  3724. byte type;
  3725. } DtlsMsg;
  3726. #ifdef HAVE_NETX
  3727. /* NETX I/O Callback default */
  3728. typedef struct NetX_Ctx {
  3729. NX_TCP_SOCKET* nxSocket; /* send/recv socket handle */
  3730. NX_PACKET* nxPacket; /* incoming packet handle for short reads */
  3731. ULONG nxOffset; /* offset already read from nxPacket */
  3732. ULONG nxWait; /* wait option flag */
  3733. } NetX_Ctx;
  3734. #endif
  3735. /* Handshake messages received from peer (plus change cipher */
  3736. typedef struct MsgsReceived {
  3737. word16 got_hello_request:1;
  3738. word16 got_client_hello:2;
  3739. word16 got_server_hello:1;
  3740. word16 got_hello_verify_request:1;
  3741. word16 got_session_ticket:1;
  3742. word16 got_end_of_early_data:1;
  3743. word16 got_hello_retry_request:1;
  3744. word16 got_encrypted_extensions:1;
  3745. word16 got_certificate:1;
  3746. word16 got_certificate_status:1;
  3747. word16 got_server_key_exchange:1;
  3748. word16 got_certificate_request:1;
  3749. word16 got_server_hello_done:1;
  3750. word16 got_certificate_verify:1;
  3751. word16 got_client_key_exchange:1;
  3752. word16 got_finished:1;
  3753. word16 got_key_update:1;
  3754. word16 got_change_cipher:1;
  3755. } MsgsReceived;
  3756. /* Handshake hashes */
  3757. typedef struct HS_Hashes {
  3758. Hashes verifyHashes;
  3759. Hashes certHashes; /* for cert verify */
  3760. #ifndef NO_SHA
  3761. wc_Sha hashSha; /* sha hash of handshake msgs */
  3762. #endif
  3763. #if !defined(NO_MD5) && !defined(NO_OLD_TLS)
  3764. wc_Md5 hashMd5; /* md5 hash of handshake msgs */
  3765. #endif
  3766. #ifndef NO_SHA256
  3767. wc_Sha256 hashSha256; /* sha256 hash of handshake msgs */
  3768. #endif
  3769. #ifdef WOLFSSL_SHA384
  3770. wc_Sha384 hashSha384; /* sha384 hash of handshake msgs */
  3771. #endif
  3772. #ifdef WOLFSSL_SHA512
  3773. wc_Sha512 hashSha512; /* sha512 hash of handshake msgs */
  3774. #endif
  3775. #if (defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  3776. !defined(WOLFSSL_NO_CLIENT_AUTH)
  3777. byte* messages; /* handshake messages */
  3778. int length; /* length of handshake messages' data */
  3779. int prevLen; /* length of messages but last */
  3780. #endif
  3781. } HS_Hashes;
  3782. #ifndef WOLFSSL_NO_TLS12
  3783. /* Persistable BuildMessage arguments */
  3784. typedef struct BuildMsgArgs {
  3785. word32 digestSz;
  3786. word32 sz;
  3787. word32 pad;
  3788. word32 idx;
  3789. word32 headerSz;
  3790. word16 size;
  3791. word32 ivSz; /* TLSv1.1 IV */
  3792. byte* iv;
  3793. ALIGN16 byte staticIvBuffer[MAX_IV_SZ];
  3794. } BuildMsgArgs;
  3795. #endif
  3796. #ifdef WOLFSSL_ASYNC_IO
  3797. #define MAX_ASYNC_ARGS 18
  3798. typedef void (*FreeArgsCb)(struct WOLFSSL* ssl, void* pArgs);
  3799. struct WOLFSSL_ASYNC {
  3800. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WOLFSSL_NO_TLS12)
  3801. BuildMsgArgs buildArgs; /* holder for current BuildMessage args */
  3802. #endif
  3803. FreeArgsCb freeArgs; /* function pointer to cleanup args */
  3804. word32 args[MAX_ASYNC_ARGS]; /* holder for current args */
  3805. };
  3806. #endif
  3807. #ifdef HAVE_WRITE_DUP
  3808. #define WRITE_DUP_SIDE 1
  3809. #define READ_DUP_SIDE 2
  3810. typedef struct WriteDup {
  3811. wolfSSL_Mutex dupMutex; /* reference count mutex */
  3812. int dupCount; /* reference count */
  3813. int dupErr; /* under dupMutex, pass to other side */
  3814. } WriteDup;
  3815. WOLFSSL_LOCAL void FreeWriteDup(WOLFSSL* ssl);
  3816. WOLFSSL_LOCAL int NotifyWriteSide(WOLFSSL* ssl, int err);
  3817. #endif /* HAVE_WRITE_DUP */
  3818. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  3819. typedef struct CertReqCtx CertReqCtx;
  3820. struct CertReqCtx {
  3821. CertReqCtx* next;
  3822. byte len;
  3823. byte ctx;
  3824. };
  3825. #endif
  3826. #ifdef WOLFSSL_EARLY_DATA
  3827. typedef enum EarlyDataState {
  3828. no_early_data,
  3829. early_data_ext,
  3830. expecting_early_data,
  3831. process_early_data,
  3832. done_early_data
  3833. } EarlyDataState;
  3834. #endif
  3835. /* wolfSSL ssl type */
  3836. struct WOLFSSL {
  3837. WOLFSSL_CTX* ctx;
  3838. Suites* suites; /* only need during handshake */
  3839. Arrays* arrays;
  3840. #ifdef WOLFSSL_TLS13
  3841. byte clientSecret[SECRET_LEN];
  3842. byte serverSecret[SECRET_LEN];
  3843. #endif
  3844. HS_Hashes* hsHashes;
  3845. void* IOCB_ReadCtx;
  3846. void* IOCB_WriteCtx;
  3847. WC_RNG* rng;
  3848. void* verifyCbCtx; /* cert verify callback user ctx*/
  3849. VerifyCallback verifyCallback; /* cert verification callback */
  3850. void* heap; /* for user overrides */
  3851. #ifdef HAVE_WRITE_DUP
  3852. WriteDup* dupWrite; /* valid pointer indicates ON */
  3853. /* side that decrements dupCount to zero frees overall structure */
  3854. byte dupSide; /* write side or read side */
  3855. #endif
  3856. #ifdef OPENSSL_EXTRA
  3857. byte cbioFlag; /* WOLFSSL_CBIO_RECV/SEND: CBIORecv/Send is set */
  3858. #endif
  3859. #ifdef WOLFSSL_WOLFSENTRY_HOOKS
  3860. NetworkFilterCallback_t AcceptFilter;
  3861. void *AcceptFilter_arg;
  3862. NetworkFilterCallback_t ConnectFilter;
  3863. void *ConnectFilter_arg;
  3864. #endif /* WOLFSSL_WOLFSENTRY_HOOKS */
  3865. CallbackIORecv CBIORecv;
  3866. CallbackIOSend CBIOSend;
  3867. #ifdef WOLFSSL_STATIC_MEMORY
  3868. WOLFSSL_HEAP_HINT heap_hint;
  3869. #endif
  3870. #ifndef NO_HANDSHAKE_DONE_CB
  3871. HandShakeDoneCb hsDoneCb; /* notify user handshake done */
  3872. void* hsDoneCtx; /* user handshake cb context */
  3873. #endif
  3874. #ifdef WOLFSSL_ASYNC_IO
  3875. #ifdef WOLFSSL_ASYNC_CRYPT
  3876. WC_ASYNC_DEV* asyncDev;
  3877. #endif
  3878. /* Message building context should be stored here for functions that expect
  3879. * to encounter encryption blocking or fragment the message. */
  3880. struct WOLFSSL_ASYNC* async;
  3881. #endif
  3882. void* hsKey; /* Handshake key (RsaKey or ecc_key) allocated from heap */
  3883. word32 hsType; /* Type of Handshake key (hsKey) */
  3884. WOLFSSL_CIPHER cipher;
  3885. #ifndef WOLFSSL_AEAD_ONLY
  3886. hmacfp hmac;
  3887. #endif
  3888. Ciphers encrypt;
  3889. Ciphers decrypt;
  3890. Buffers buffers;
  3891. WOLFSSL_SESSION* session;
  3892. #ifndef NO_CLIENT_CACHE
  3893. ClientSession* clientSession;
  3894. #endif
  3895. WOLFSSL_ALERT_HISTORY alert_history;
  3896. int error;
  3897. int rfd; /* read file descriptor */
  3898. int wfd; /* write file descriptor */
  3899. int rflags; /* user read flags */
  3900. int wflags; /* user write flags */
  3901. word32 timeout; /* session timeout */
  3902. word32 fragOffset; /* fragment offset */
  3903. word16 curSize;
  3904. byte verifyDepth;
  3905. RecordLayerHeader curRL;
  3906. MsgsReceived msgsReceived; /* peer messages received */
  3907. ProtocolVersion version; /* negotiated version */
  3908. ProtocolVersion chVersion; /* client hello version */
  3909. CipherSpecs specs;
  3910. Keys keys;
  3911. Options options;
  3912. #ifdef OPENSSL_EXTRA
  3913. CallbackInfoState* CBIS; /* used to get info about SSL state */
  3914. int cbmode; /* read or write on info callback */
  3915. int cbtype; /* event type in info callback */
  3916. WOLFSSL_BIO* biord; /* socket bio read to free/close */
  3917. WOLFSSL_BIO* biowr; /* socket bio write to free/close */
  3918. byte sessionCtx[ID_LEN]; /* app session context ID */
  3919. WOLFSSL_X509_VERIFY_PARAM* param; /* verification parameters*/
  3920. #endif
  3921. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  3922. unsigned long peerVerifyRet;
  3923. #endif
  3924. #ifdef OPENSSL_EXTRA
  3925. byte readAhead;
  3926. byte sessionCtxSz; /* size of sessionCtx stored */
  3927. #ifdef HAVE_PK_CALLBACKS
  3928. void* loggingCtx; /* logging callback argument */
  3929. #endif
  3930. #endif /* OPENSSL_EXTRA */
  3931. #ifndef NO_RSA
  3932. RsaKey* peerRsaKey;
  3933. #if defined(WOLFSSL_RENESAS_TSIP_TLS) || defined(WOLFSSL_RENESAS_SCEPROTECT)
  3934. byte* peerSceTsipEncRsaKeyIndex;
  3935. #endif
  3936. byte peerRsaKeyPresent;
  3937. #endif
  3938. #if defined(WOLFSSL_TLS13) || defined(HAVE_FFDHE)
  3939. word16 namedGroup;
  3940. #endif
  3941. #ifdef WOLFSSL_TLS13
  3942. word16 group[WOLFSSL_MAX_GROUP_COUNT];
  3943. byte numGroups;
  3944. #endif
  3945. word16 pssAlgo;
  3946. #ifdef WOLFSSL_TLS13
  3947. word16 certHashSigAlgoSz; /* SigAlgoCert ext length in bytes */
  3948. byte certHashSigAlgo[WOLFSSL_MAX_SIGALGO]; /* cert sig/algo to
  3949. * offer */
  3950. #endif
  3951. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
  3952. int eccVerifyRes;
  3953. #endif
  3954. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  3955. defined(HAVE_ED448) || defined(HAVE_CURVE448)
  3956. word32 ecdhCurveOID; /* curve Ecc_Sum */
  3957. ecc_key* eccTempKey; /* private ECDHE key */
  3958. byte eccTempKeyPresent; /* also holds type */
  3959. byte peerEccKeyPresent;
  3960. #endif
  3961. #ifdef HAVE_ECC
  3962. ecc_key* peerEccKey; /* peer's ECDHE key */
  3963. ecc_key* peerEccDsaKey; /* peer's ECDSA key */
  3964. word16 eccTempKeySz; /* in octets 20 - 66 */
  3965. byte peerEccDsaKeyPresent;
  3966. #endif
  3967. #if defined(HAVE_ECC) || defined(HAVE_ED25519) || \
  3968. defined(HAVE_CURVE448) || defined(HAVE_ED448)
  3969. word32 pkCurveOID; /* curve Ecc_Sum */
  3970. #endif
  3971. #ifdef HAVE_ED25519
  3972. ed25519_key* peerEd25519Key;
  3973. byte peerEd25519KeyPresent;
  3974. #endif
  3975. #ifdef HAVE_CURVE25519
  3976. curve25519_key* peerX25519Key;
  3977. byte peerX25519KeyPresent;
  3978. #endif
  3979. #ifdef HAVE_ED448
  3980. ed448_key* peerEd448Key;
  3981. byte peerEd448KeyPresent;
  3982. #endif
  3983. #ifdef HAVE_CURVE448
  3984. curve448_key* peerX448Key;
  3985. byte peerX448KeyPresent;
  3986. #endif
  3987. #ifdef HAVE_PQC
  3988. falcon_key* peerFalconKey;
  3989. byte peerFalconKeyPresent;
  3990. #endif
  3991. #ifdef HAVE_LIBZ
  3992. z_stream c_stream; /* compression stream */
  3993. z_stream d_stream; /* decompression stream */
  3994. byte didStreamInit; /* for stream init and end */
  3995. #endif
  3996. #ifdef WOLFSSL_DTLS
  3997. int dtls_timeout_init; /* starting timeout value */
  3998. int dtls_timeout_max; /* maximum timeout value */
  3999. int dtls_timeout; /* current timeout value, changes */
  4000. #ifndef NO_ASN_TIME
  4001. word32 dtls_start_timeout;
  4002. #endif /* !NO_ASN_TIME */
  4003. word32 dtls_tx_msg_list_sz;
  4004. word32 dtls_rx_msg_list_sz;
  4005. DtlsMsg* dtls_tx_msg_list;
  4006. DtlsMsg* dtls_tx_msg;
  4007. DtlsMsg* dtls_rx_msg_list;
  4008. void* IOCB_CookieCtx; /* gen cookie ctx */
  4009. word32 dtls_expected_rx;
  4010. #ifdef WOLFSSL_SESSION_EXPORT
  4011. wc_dtls_export dtls_export; /* export function for session */
  4012. #endif
  4013. #if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)
  4014. word16 dtlsMtuSz;
  4015. #endif /* WOLFSSL_SCTP || WOLFSSL_DTLS_MTU */
  4016. #ifdef WOLFSSL_MULTICAST
  4017. void* mcastHwCbCtx; /* Multicast highwater callback ctx */
  4018. #endif /* WOLFSSL_MULTICAST */
  4019. #ifdef WOLFSSL_DTLS_DROP_STATS
  4020. word32 macDropCount;
  4021. word32 replayDropCount;
  4022. #endif /* WOLFSSL_DTLS_DROP_STATS */
  4023. #ifdef WOLFSSL_SRTP
  4024. word16 dtlsSrtpProfiles; /* DTLS-with-SRTP profiles list
  4025. * (selected profiles - up to 16) */
  4026. word16 dtlsSrtpId; /* DTLS-with-SRTP profile ID selected */
  4027. #endif
  4028. #endif /* WOLFSSL_DTLS */
  4029. #ifdef WOLFSSL_CALLBACKS
  4030. TimeoutInfo timeoutInfo; /* info saved during handshake */
  4031. HandShakeInfo handShakeInfo; /* info saved during handshake */
  4032. #endif
  4033. #ifdef OPENSSL_EXTRA
  4034. SSL_Msg_Cb protoMsgCb; /* inspect protocol message callback */
  4035. void* protoMsgCtx; /* user set context with msg callback */
  4036. #endif
  4037. #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
  4038. byte hsInfoOn; /* track handshake info */
  4039. byte toInfoOn; /* track timeout info */
  4040. #endif
  4041. #ifdef HAVE_FUZZER
  4042. CallbackFuzzer fuzzerCb; /* for testing with using fuzzer */
  4043. void* fuzzerCtx; /* user defined pointer */
  4044. #endif
  4045. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  4046. CertReqCtx* certReqCtx;
  4047. #endif
  4048. #ifdef WOLFSSL_LOCAL_X509_STORE
  4049. WOLFSSL_X509_STORE* x509_store_pt; /* take ownership of external store */
  4050. #endif
  4051. #ifdef KEEP_PEER_CERT
  4052. /* TODO put this on the heap so we can properly use the
  4053. * reference counter and not have to duplicate it. */
  4054. WOLFSSL_X509 peerCert; /* X509 peer cert */
  4055. #endif
  4056. #ifdef KEEP_OUR_CERT
  4057. WOLFSSL_X509* ourCert; /* keep alive a X509 struct of cert.
  4058. points to ctx if not owned (owned
  4059. flag found in buffers.weOwnCert) */
  4060. #endif
  4061. byte keepCert; /* keep certificate after handshake */
  4062. #ifdef HAVE_EX_DATA
  4063. WOLFSSL_CRYPTO_EX_DATA ex_data; /* external data, for Fortress */
  4064. #endif
  4065. int devId; /* async device id to use */
  4066. #ifdef HAVE_ONE_TIME_AUTH
  4067. OneTimeAuth auth;
  4068. #endif
  4069. #ifdef HAVE_TLS_EXTENSIONS
  4070. TLSX* extensions; /* RFC 6066 TLS Extensions data */
  4071. #ifdef HAVE_MAX_FRAGMENT
  4072. word16 max_fragment;
  4073. #endif
  4074. #ifdef HAVE_TRUNCATED_HMAC
  4075. byte truncated_hmac;
  4076. #endif
  4077. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  4078. byte status_request;
  4079. #endif
  4080. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  4081. byte status_request_v2;
  4082. #endif
  4083. #if defined(HAVE_SECURE_RENEGOTIATION) \
  4084. || defined(HAVE_SERVER_RENEGOTIATION_INFO)
  4085. int secure_rene_count; /* how many times */
  4086. SecureRenegotiation* secure_renegotiation; /* valid pointer indicates */
  4087. #endif /* user turned on */
  4088. #ifdef HAVE_ALPN
  4089. char* alpn_client_list; /* keep the client's list */
  4090. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  4091. CallbackALPNSelect alpnSelect;
  4092. void* alpnSelectArg;
  4093. #endif
  4094. #endif /* of accepted protocols */
  4095. #if !defined(NO_WOLFSSL_CLIENT) && defined(HAVE_SESSION_TICKET)
  4096. CallbackSessionTicket session_ticket_cb;
  4097. void* session_ticket_ctx;
  4098. byte expect_session_ticket;
  4099. #endif
  4100. #endif /* HAVE_TLS_EXTENSIONS */
  4101. #ifdef HAVE_OCSP
  4102. void* ocspIOCtx;
  4103. byte ocspProducedDate[MAX_DATE_SZ];
  4104. int ocspProducedDateFormat;
  4105. #ifdef OPENSSL_EXTRA
  4106. byte* ocspResp;
  4107. int ocspRespSz;
  4108. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
  4109. char* url;
  4110. #endif
  4111. #endif
  4112. #endif
  4113. #ifdef HAVE_NETX
  4114. NetX_Ctx nxCtx; /* NetX IO Context */
  4115. #endif
  4116. #if defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
  4117. void* mnCtx; /* mynewt mn_socket IO Context */
  4118. #endif /* defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP) */
  4119. #ifdef WOLFSSL_GNRC
  4120. struct gnrc_wolfssl_ctx *gnrcCtx; /* Riot-OS GNRC UDP/IP context */
  4121. #endif
  4122. #ifdef SESSION_INDEX
  4123. int sessionIndex; /* Session's location in the cache. */
  4124. #endif
  4125. #ifdef ATOMIC_USER
  4126. void* MacEncryptCtx; /* Atomic User Mac/Encrypt Callback Context */
  4127. void* DecryptVerifyCtx; /* Atomic User Decrypt/Verify Callback Context */
  4128. #ifdef HAVE_ENCRYPT_THEN_MAC
  4129. void* EncryptMacCtx; /* Atomic User Encrypt/Mac Callback Ctx */
  4130. void* VerifyDecryptCtx; /* Atomic User Verify/Decrypt Callback Ctx */
  4131. #endif
  4132. #endif
  4133. #ifdef HAVE_PK_CALLBACKS
  4134. #ifdef HAVE_ECC
  4135. void* EccKeyGenCtx; /* EccKeyGen Callback Context */
  4136. void* EccSignCtx; /* Ecc Sign Callback Context */
  4137. void* EccVerifyCtx; /* Ecc Verify Callback Context */
  4138. void* EccSharedSecretCtx; /* Ecc Pms Callback Context */
  4139. #endif /* HAVE_ECC */
  4140. #ifdef HAVE_HKDF
  4141. void* HkdfExtractCtx; /* Hkdf extract callback context */
  4142. #endif
  4143. #ifdef HAVE_ED25519
  4144. void* Ed25519SignCtx; /* ED25519 Sign Callback Context */
  4145. void* Ed25519VerifyCtx; /* ED25519 Verify Callback Context */
  4146. #endif
  4147. #ifdef HAVE_CURVE25519
  4148. void* X25519KeyGenCtx; /* X25519 KeyGen Callback Context */
  4149. void* X25519SharedSecretCtx; /* X25519 Pms Callback Context */
  4150. #endif
  4151. #ifdef HAVE_ED448
  4152. void* Ed448SignCtx; /* ED448 Sign Callback Context */
  4153. void* Ed448VerifyCtx; /* ED448 Verify Callback Context */
  4154. #endif
  4155. #ifdef HAVE_CURVE448
  4156. void* X448KeyGenCtx; /* X448 KeyGen Callback Context */
  4157. void* X448SharedSecretCtx; /* X448 Pms Callback Context */
  4158. #endif
  4159. #ifndef NO_DH
  4160. void* DhAgreeCtx; /* DH Pms Callback Context */
  4161. #endif /* !NO_DH */
  4162. #ifndef NO_RSA
  4163. void* RsaSignCtx; /* Rsa Sign Callback Context */
  4164. void* RsaVerifyCtx; /* Rsa Verify Callback Context */
  4165. #ifdef WC_RSA_PSS
  4166. void* RsaPssSignCtx; /* Rsa PSS Sign Callback Context */
  4167. void* RsaPssVerifyCtx; /* Rsa PSS Verify Callback Context */
  4168. #endif
  4169. void* RsaEncCtx; /* Rsa Public Encrypt Callback Context */
  4170. void* RsaDecCtx; /* Rsa Private Decrypt Callback Context */
  4171. #endif /* NO_RSA */
  4172. void* GenPreMasterCtx; /* Generate Premaster Callback Context */
  4173. void* GenMasterCtx; /* Generate Master Callback Context */
  4174. void* GenSessionKeyCtx; /* Generate Session Key Callback Context */
  4175. void* EncryptKeysCtx; /* Set Encrypt keys Callback Context */
  4176. void* TlsFinishedCtx; /* Generate Tls Finished Callback Context */
  4177. void* VerifyMacCtx; /* Verify mac Callback Context */
  4178. #endif /* HAVE_PK_CALLBACKS */
  4179. #ifdef HAVE_SECRET_CALLBACK
  4180. SessionSecretCb sessionSecretCb;
  4181. void* sessionSecretCtx;
  4182. #ifdef WOLFSSL_TLS13
  4183. Tls13SecretCb tls13SecretCb;
  4184. void* tls13SecretCtx;
  4185. #endif
  4186. #ifdef OPENSSL_EXTRA
  4187. SessionSecretCb keyLogCb;
  4188. #ifdef WOLFSSL_TLS13
  4189. Tls13SecretCb tls13KeyLogCb;
  4190. #endif
  4191. #endif
  4192. #endif /* HAVE_SECRET_CALLBACK */
  4193. #ifdef WOLFSSL_JNI
  4194. void* jObjectRef; /* reference to WolfSSLSession in JNI wrapper */
  4195. #endif /* WOLFSSL_JNI */
  4196. #ifdef WOLFSSL_EARLY_DATA
  4197. EarlyDataState earlyData;
  4198. word32 earlyDataSz;
  4199. byte earlyDataStatus;
  4200. #endif
  4201. #ifdef OPENSSL_ALL
  4202. long verifyCallbackResult;
  4203. #endif
  4204. #if defined(OPENSSL_EXTRA)
  4205. WOLFSSL_STACK* supportedCiphers; /* Used in wolfSSL_get_ciphers_compat */
  4206. WOLFSSL_STACK* peerCertChain; /* Used in wolfSSL_get_peer_cert_chain */
  4207. #ifdef KEEP_OUR_CERT
  4208. WOLFSSL_STACK* ourCertChain; /* Used in wolfSSL_add1_chain_cert */
  4209. #endif
  4210. #endif
  4211. #ifdef WOLFSSL_STATIC_EPHEMERAL
  4212. StaticKeyExchangeInfo_t staticKE;
  4213. #endif
  4214. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  4215. /* Added in libest port: allow applications to get the 'tls-unique' Channel
  4216. * Binding Type (https://tools.ietf.org/html/rfc5929#section-3). This is
  4217. * used in the EST protocol to bind an enrollment to a TLS session through
  4218. * 'proof-of-possession' (https://tools.ietf.org/html/rfc7030#section-3.4
  4219. * and https://tools.ietf.org/html/rfc7030#section-3.5). */
  4220. byte clientFinished[TLS_FINISHED_SZ_MAX];
  4221. byte serverFinished[TLS_FINISHED_SZ_MAX];
  4222. byte clientFinished_len;
  4223. byte serverFinished_len;
  4224. #endif
  4225. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA) || defined(HAVE_LIGHTY)
  4226. WOLF_STACK_OF(WOLFSSL_X509_NAME)* ca_names;
  4227. #endif
  4228. #if defined(WOLFSSL_IOTSAFE) && defined(HAVE_PK_CALLBACKS)
  4229. IOTSAFE iotsafe;
  4230. #endif
  4231. #ifdef WOLFSSL_LWIP_NATIVE
  4232. WOLFSSL_LWIP_NATIVE_STATE lwipCtx; /* LwIP native socket IO Context */
  4233. #endif
  4234. };
  4235. /*
  4236. * wolfSSL_PEM_read_bio_X509 pushes an ASN_NO_PEM_HEADER error
  4237. * to the error queue on file end. This should not be left
  4238. * for the caller to find so we clear the last error.
  4239. */
  4240. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_HAVE_ERROR_QUEUE)
  4241. #define CLEAR_ASN_NO_PEM_HEADER_ERROR(err) \
  4242. (err) = wolfSSL_ERR_peek_last_error(); \
  4243. if (ERR_GET_LIB(err) == ERR_LIB_PEM && \
  4244. ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { \
  4245. wc_RemoveErrorNode(-1); \
  4246. }
  4247. #else
  4248. #define CLEAR_ASN_NO_PEM_HEADER_ERROR(err) (void)(err);
  4249. #endif
  4250. /*
  4251. * The SSL object may have its own certificate store. The below macros simplify
  4252. * logic for choosing which WOLFSSL_CERT_MANAGER and WOLFSSL_X509_STORE to use.
  4253. * Always use SSL specific objects when available and revert to CTX otherwise.
  4254. */
  4255. #ifdef WOLFSSL_LOCAL_X509_STORE
  4256. #define SSL_CM(ssl) ((ssl)->x509_store_pt ? (ssl)->x509_store_pt->cm : (ssl)->ctx->cm)
  4257. #define SSL_STORE(ssl) ((ssl)->x509_store_pt ? (ssl)->x509_store_pt : \
  4258. ((ssl)->ctx->x509_store_pt ? (ssl)->ctx->x509_store_pt : \
  4259. &(ssl)->ctx->x509_store))
  4260. #else
  4261. #define SSL_CM(ssl) (ssl)->ctx->cm
  4262. #endif
  4263. #define SSL_CA_NAMES(ssl) ((ssl)->ca_names != NULL ? (ssl)->ca_names : \
  4264. (ssl)->ctx->ca_names)
  4265. WOLFSSL_LOCAL int SSL_CTX_RefCount(WOLFSSL_CTX* ctx, int incr);
  4266. WOLFSSL_LOCAL int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
  4267. WOLFSSL_LOCAL int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup);
  4268. WOLFSSL_LOCAL void FreeSSL(WOLFSSL* ssl, void* heap);
  4269. WOLFSSL_API void SSL_ResourceFree(WOLFSSL* ssl); /* Micrium uses */
  4270. #ifndef NO_CERTS
  4271. WOLFSSL_LOCAL int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
  4272. long sz, int format, int type, WOLFSSL* ssl,
  4273. long* used, int userChain, int verify);
  4274. WOLFSSL_LOCAL int ProcessFile(WOLFSSL_CTX* ctx, const char* fname, int format,
  4275. int type, WOLFSSL* ssl, int userChain,
  4276. WOLFSSL_CRL* crl, int verify);
  4277. WOLFSSL_LOCAL int CheckHostName(DecodedCert* dCert, const char *domainName,
  4278. size_t domainNameLen);
  4279. #endif
  4280. #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
  4281. WOLFSSL_LOCAL void InitHandShakeInfo(HandShakeInfo* info, WOLFSSL* ssl);
  4282. WOLFSSL_LOCAL void FinishHandShakeInfo(HandShakeInfo* info);
  4283. WOLFSSL_LOCAL void AddPacketName(WOLFSSL* ssl, const char* name);
  4284. WOLFSSL_LOCAL void InitTimeoutInfo(TimeoutInfo* info);
  4285. WOLFSSL_LOCAL void FreeTimeoutInfo(TimeoutInfo* info, void* heap);
  4286. WOLFSSL_LOCAL void AddPacketInfo(WOLFSSL* ssl, const char* name, int type,
  4287. const byte* data, int sz, int written, void* heap);
  4288. WOLFSSL_LOCAL void AddLateName(const char* name, TimeoutInfo* info);
  4289. WOLFSSL_LOCAL void AddLateRecordHeader(const RecordLayerHeader* rl,
  4290. TimeoutInfo* info);
  4291. #endif
  4292. /* Record Layer Header identifier from page 12 */
  4293. enum ContentType {
  4294. no_type = 0,
  4295. change_cipher_spec = 20,
  4296. alert = 21,
  4297. handshake = 22,
  4298. application_data = 23
  4299. };
  4300. /* handshake header, same for each message type, pgs 20/21 */
  4301. typedef struct HandShakeHeader {
  4302. byte type;
  4303. word24 length;
  4304. } HandShakeHeader;
  4305. /* DTLS handshake header, same for each message type */
  4306. typedef struct DtlsHandShakeHeader {
  4307. byte type;
  4308. word24 length;
  4309. byte message_seq[2]; /* start at 0, retransmit gets same # */
  4310. word24 fragment_offset; /* bytes in previous fragments */
  4311. word24 fragment_length; /* length of this fragment */
  4312. } DtlsHandShakeHeader;
  4313. enum HandShakeType {
  4314. hello_request = 0,
  4315. client_hello = 1,
  4316. server_hello = 2,
  4317. hello_verify_request = 3, /* DTLS addition */
  4318. session_ticket = 4,
  4319. end_of_early_data = 5,
  4320. hello_retry_request = 6,
  4321. encrypted_extensions = 8,
  4322. certificate = 11,
  4323. server_key_exchange = 12,
  4324. certificate_request = 13,
  4325. server_hello_done = 14,
  4326. certificate_verify = 15,
  4327. client_key_exchange = 16,
  4328. finished = 20,
  4329. certificate_status = 22,
  4330. key_update = 24,
  4331. change_cipher_hs = 55, /* simulate unique handshake type for sanity
  4332. checks. record layer change_cipher
  4333. conflicts with handshake finished */
  4334. message_hash = 254, /* synthetic message type for TLS v1.3 */
  4335. no_shake = 255 /* used to initialize the DtlsMsg record */
  4336. };
  4337. enum ProvisionSide {
  4338. PROVISION_CLIENT = 1,
  4339. PROVISION_SERVER = 2,
  4340. PROVISION_CLIENT_SERVER = 3
  4341. };
  4342. static const byte client[SIZEOF_SENDER+1] = { 0x43, 0x4C, 0x4E, 0x54, 0x00 }; /* CLNT */
  4343. static const byte server[SIZEOF_SENDER+1] = { 0x53, 0x52, 0x56, 0x52, 0x00 }; /* SRVR */
  4344. static const byte tls_client[FINISHED_LABEL_SZ + 1] = "client finished";
  4345. static const byte tls_server[FINISHED_LABEL_SZ + 1] = "server finished";
  4346. #ifdef OPENSSL_EXTRA
  4347. typedef struct {
  4348. int name_len;
  4349. const char *name;
  4350. int nid;
  4351. } WOLF_EC_NIST_NAME;
  4352. extern const WOLF_EC_NIST_NAME kNistCurves[];
  4353. /* This is the longest and shortest curve name in the kNistCurves list. Note we
  4354. * also have quantum-safe group names as well. */
  4355. #define kNistCurves_MIN_NAME_LEN 5
  4356. #ifdef HAVE_PQC
  4357. #define kNistCurves_MAX_NAME_LEN 32
  4358. #else
  4359. #define kNistCurves_MAX_NAME_LEN 7
  4360. #endif
  4361. #endif
  4362. /* internal functions */
  4363. WOLFSSL_LOCAL int SendChangeCipher(WOLFSSL* ssl);
  4364. WOLFSSL_LOCAL int SendTicket(WOLFSSL* ssl);
  4365. WOLFSSL_LOCAL int DoClientTicket(WOLFSSL* ssl, const byte* input, word32 len);
  4366. WOLFSSL_LOCAL int SendData(WOLFSSL* ssl, const void* data, int sz);
  4367. #ifdef WOLFSSL_TLS13
  4368. WOLFSSL_LOCAL int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType);
  4369. #endif
  4370. WOLFSSL_LOCAL int SendCertificate(WOLFSSL* ssl);
  4371. WOLFSSL_LOCAL int SendCertificateRequest(WOLFSSL* ssl);
  4372. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  4373. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4374. WOLFSSL_LOCAL int CreateOcspResponse(WOLFSSL* ssl, OcspRequest** ocspRequest,
  4375. buffer* response);
  4376. #endif
  4377. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  4378. !defined(NO_WOLFSSL_SERVER)
  4379. WOLFSSL_LOCAL int SendHelloRequest(WOLFSSL* ssl);
  4380. #endif
  4381. WOLFSSL_LOCAL int SendCertificateStatus(WOLFSSL* ssl);
  4382. WOLFSSL_LOCAL int SendServerKeyExchange(WOLFSSL* ssl);
  4383. WOLFSSL_LOCAL int SendBuffered(WOLFSSL* ssl);
  4384. WOLFSSL_LOCAL int ReceiveData(WOLFSSL* ssl, byte* output, int sz, int peek);
  4385. WOLFSSL_LOCAL int SendFinished(WOLFSSL* ssl);
  4386. WOLFSSL_LOCAL int SendAlert(WOLFSSL* ssl, int severity, int type);
  4387. WOLFSSL_LOCAL int ProcessReply(WOLFSSL* ssl);
  4388. WOLFSSL_LOCAL int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr);
  4389. WOLFSSL_LOCAL const char* AlertTypeToString(int type);
  4390. WOLFSSL_LOCAL int SetCipherSpecs(WOLFSSL* ssl);
  4391. WOLFSSL_LOCAL int MakeMasterSecret(WOLFSSL* ssl);
  4392. WOLFSSL_LOCAL int DeriveKeys(WOLFSSL* ssl);
  4393. WOLFSSL_LOCAL int StoreKeys(WOLFSSL* ssl, const byte* keyData, int side);
  4394. WOLFSSL_LOCAL int IsTLS(const WOLFSSL* ssl);
  4395. WOLFSSL_LOCAL int IsAtLeastTLSv1_2(const WOLFSSL* ssl);
  4396. WOLFSSL_LOCAL int IsAtLeastTLSv1_3(ProtocolVersion pv);
  4397. WOLFSSL_LOCAL int TLSv1_3_Capable(WOLFSSL* ssl);
  4398. WOLFSSL_LOCAL void FreeHandshakeResources(WOLFSSL* ssl);
  4399. WOLFSSL_LOCAL void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree);
  4400. WOLFSSL_LOCAL void ShrinkOutputBuffer(WOLFSSL* ssl);
  4401. WOLFSSL_LOCAL int VerifyClientSuite(WOLFSSL* ssl);
  4402. WOLFSSL_LOCAL int SetTicket(WOLFSSL* ssl, const byte* ticket, word32 length);
  4403. WOLFSSL_LOCAL int wolfSSL_GetMaxFragSize(WOLFSSL* ssl, int maxFragment);
  4404. #if defined(WOLFSSL_IOTSAFE) && defined(HAVE_PK_CALLBACKS)
  4405. WOLFSSL_LOCAL IOTSAFE *wolfSSL_get_iotsafe_ctx(WOLFSSL *ssl);
  4406. WOLFSSL_LOCAL int wolfSSL_set_iotsafe_ctx(WOLFSSL *ssl, IOTSAFE *iotsafe);
  4407. #endif
  4408. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  4409. WOLFSSL_LOCAL int SetECKeyInternal(WOLFSSL_EC_KEY* eckey);
  4410. WOLFSSL_LOCAL int SetECKeyExternal(WOLFSSL_EC_KEY* eckey);
  4411. #endif
  4412. WOLFSSL_LOCAL WC_RNG* WOLFSSL_RSA_GetRNG(WOLFSSL_RSA *rsa, WC_RNG **tmpRNG,
  4413. int *initTmpRng);
  4414. #ifndef NO_CERTS
  4415. #ifndef NO_RSA
  4416. #ifdef WC_RSA_PSS
  4417. WOLFSSL_LOCAL int CheckRsaPssPadding(const byte* plain, word32 plainSz,
  4418. byte* out, word32 sigSz, enum wc_HashType hashType);
  4419. WOLFSSL_LOCAL int ConvertHashPss(int hashAlgo,
  4420. enum wc_HashType* hashType, int* mgf);
  4421. #endif
  4422. WOLFSSL_LOCAL int VerifyRsaSign(WOLFSSL* ssl, byte* verifySig,
  4423. word32 sigSz, const byte* plain, word32 plainSz, int sigAlgo,
  4424. int hashAlgo, RsaKey* key, DerBuffer* keyBufInfo);
  4425. WOLFSSL_LOCAL int RsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4426. byte* out, word32* outSz, int sigAlgo, int hashAlgo, RsaKey* key,
  4427. DerBuffer* keyBufInfo);
  4428. WOLFSSL_LOCAL int RsaVerify(WOLFSSL* ssl, byte* in, word32 inSz,
  4429. byte** out, int sigAlgo, int hashAlgo, RsaKey* key,
  4430. buffer* keyBufInfo);
  4431. WOLFSSL_LOCAL int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out,
  4432. word32* outSz, RsaKey* key, DerBuffer* keyBufInfo);
  4433. WOLFSSL_LOCAL int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out,
  4434. word32* outSz, RsaKey* key, buffer* keyBufInfo);
  4435. #endif /* !NO_RSA */
  4436. #ifdef HAVE_ECC
  4437. WOLFSSL_LOCAL int EccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4438. byte* out, word32* outSz, ecc_key* key, DerBuffer* keyBufInfo);
  4439. WOLFSSL_LOCAL int EccVerify(WOLFSSL* ssl, const byte* in, word32 inSz,
  4440. const byte* out, word32 outSz, ecc_key* key, buffer* keyBufInfo);
  4441. WOLFSSL_LOCAL int EccSharedSecret(WOLFSSL* ssl, ecc_key* priv_key,
  4442. ecc_key* pub_key, byte* pubKeyDer, word32* pubKeySz, byte* out,
  4443. word32* outlen, int side);
  4444. #endif /* HAVE_ECC */
  4445. #ifdef HAVE_ED25519
  4446. WOLFSSL_LOCAL int Ed25519CheckPubKey(WOLFSSL* ssl);
  4447. WOLFSSL_LOCAL int Ed25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4448. byte* out, word32* outSz, ed25519_key* key, DerBuffer* keyBufInfo);
  4449. WOLFSSL_LOCAL int Ed25519Verify(WOLFSSL* ssl, const byte* in,
  4450. word32 inSz, const byte* msg, word32 msgSz, ed25519_key* key,
  4451. buffer* keyBufInfo);
  4452. #endif /* HAVE_ED25519 */
  4453. #ifdef HAVE_ED448
  4454. WOLFSSL_LOCAL int Ed448CheckPubKey(WOLFSSL* ssl);
  4455. WOLFSSL_LOCAL int Ed448Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
  4456. byte* out, word32* outSz, ed448_key* key, DerBuffer* keyBufInfo);
  4457. WOLFSSL_LOCAL int Ed448Verify(WOLFSSL* ssl, const byte* in,
  4458. word32 inSz, const byte* msg, word32 msgSz, ed448_key* key,
  4459. buffer* keyBufInfo);
  4460. #endif /* HAVE_ED448 */
  4461. #ifdef WOLFSSL_TRUST_PEER_CERT
  4462. /* options for searching hash table for a matching trusted peer cert */
  4463. #define WC_MATCH_SKID 0
  4464. #define WC_MATCH_NAME 1
  4465. WOLFSSL_LOCAL TrustedPeerCert* GetTrustedPeer(void* vp, DecodedCert* cert);
  4466. WOLFSSL_LOCAL int MatchTrustedPeer(TrustedPeerCert* tp,
  4467. DecodedCert* cert);
  4468. #endif
  4469. WOLFSSL_LOCAL Signer* GetCA(void* cm, byte* hash);
  4470. #ifndef NO_SKID
  4471. WOLFSSL_LOCAL Signer* GetCAByName(void* cm, byte* hash);
  4472. #endif
  4473. #endif /* !NO_CERTS */
  4474. WOLFSSL_LOCAL int BuildTlsHandshakeHash(WOLFSSL* ssl, byte* hash,
  4475. word32* hashLen);
  4476. WOLFSSL_LOCAL int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes,
  4477. const byte* sender);
  4478. WOLFSSL_LOCAL void FreeArrays(WOLFSSL* ssl, int keep);
  4479. WOLFSSL_LOCAL int CheckAvailableSize(WOLFSSL *ssl, int size);
  4480. WOLFSSL_LOCAL int GrowInputBuffer(WOLFSSL* ssl, int size, int usedLength);
  4481. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  4482. WOLFSSL_LOCAL void DoCertFatalAlert(WOLFSSL* ssl, int ret);
  4483. #endif
  4484. #ifndef NO_TLS
  4485. WOLFSSL_LOCAL int MakeTlsMasterSecret(WOLFSSL* ssl);
  4486. #ifndef WOLFSSL_AEAD_ONLY
  4487. WOLFSSL_LOCAL int TLS_hmac(WOLFSSL* ssl, byte* digest, const byte* in,
  4488. word32 sz, int padSz, int content, int verify, int epochOrder);
  4489. #endif
  4490. #endif
  4491. #ifndef NO_WOLFSSL_CLIENT
  4492. WOLFSSL_LOCAL int SendClientHello(WOLFSSL* ssl);
  4493. #ifdef WOLFSSL_TLS13
  4494. WOLFSSL_LOCAL int SendTls13ClientHello(WOLFSSL* ssl);
  4495. #endif
  4496. WOLFSSL_LOCAL int SendClientKeyExchange(WOLFSSL* ssl);
  4497. WOLFSSL_LOCAL int SendCertificateVerify(WOLFSSL* ssl);
  4498. #endif /* NO_WOLFSSL_CLIENT */
  4499. #ifndef NO_WOLFSSL_SERVER
  4500. WOLFSSL_LOCAL int SendServerHello(WOLFSSL* ssl);
  4501. WOLFSSL_LOCAL int SendServerHelloDone(WOLFSSL* ssl);
  4502. #endif /* NO_WOLFSSL_SERVER */
  4503. #ifdef WOLFSSL_DTLS
  4504. WOLFSSL_LOCAL DtlsMsg* DtlsMsgNew(word32 sz, void* heap);
  4505. WOLFSSL_LOCAL void DtlsMsgDelete(DtlsMsg* item, void* heap);
  4506. WOLFSSL_LOCAL void DtlsMsgListDelete(DtlsMsg* head, void* heap);
  4507. WOLFSSL_LOCAL void DtlsTxMsgListClean(WOLFSSL* ssl);
  4508. WOLFSSL_LOCAL int DtlsMsgSet(DtlsMsg* msg, word32 seq, word16 epoch,
  4509. const byte* data, byte type,
  4510. word32 fragOffset, word32 fragSz, void* heap);
  4511. WOLFSSL_LOCAL DtlsMsg* DtlsMsgFind(DtlsMsg* head, word16 epoch, word32 seq);
  4512. WOLFSSL_LOCAL void DtlsMsgStore(WOLFSSL* ssl, word16 epoch, word32 seq,
  4513. const byte* data, word32 dataSz, byte type,
  4514. word32 fragOffset, word32 fragSz,
  4515. void* heap);
  4516. WOLFSSL_LOCAL DtlsMsg* DtlsMsgInsert(DtlsMsg* head, DtlsMsg* item);
  4517. WOLFSSL_LOCAL int DtlsMsgPoolSave(WOLFSSL* ssl, const byte* data,
  4518. word32 dataSz, enum HandShakeType type);
  4519. WOLFSSL_LOCAL int DtlsMsgPoolTimeout(WOLFSSL* ssl);
  4520. WOLFSSL_LOCAL int VerifyForDtlsMsgPoolSend(WOLFSSL* ssl, byte type,
  4521. word32 fragOffset);
  4522. WOLFSSL_LOCAL int VerifyForTxDtlsMsgDelete(WOLFSSL* ssl, DtlsMsg* item);
  4523. WOLFSSL_LOCAL void DtlsMsgPoolReset(WOLFSSL* ssl);
  4524. WOLFSSL_LOCAL int DtlsMsgPoolSend(WOLFSSL* ssl, int sendOnlyFirstPacket);
  4525. #endif /* WOLFSSL_DTLS */
  4526. #if defined(HAVE_SECURE_RENEGOTIATION) && defined(WOLFSSL_DTLS)
  4527. WOLFSSL_LOCAL int DtlsSCRKeysSet(WOLFSSL* ssl);
  4528. WOLFSSL_LOCAL int IsDtlsMsgSCRKeys(WOLFSSL* ssl);
  4529. WOLFSSL_LOCAL int DtlsUseSCRKeys(WOLFSSL* ssl);
  4530. WOLFSSL_LOCAL int DtlsCheckOrder(WOLFSSL* ssl, int order);
  4531. #endif
  4532. WOLFSSL_LOCAL int IsSCR(WOLFSSL* ssl);
  4533. WOLFSSL_LOCAL int IsDtlsNotSctpMode(WOLFSSL* ssl);
  4534. WOLFSSL_LOCAL void WriteSEQ(WOLFSSL* ssl, int verifyOrder, byte* out);
  4535. #if defined(WOLFSSL_TLS13) && (defined(HAVE_SESSION_TICKET) || !defined(NO_PSK))
  4536. WOLFSSL_LOCAL word32 TimeNowInMilliseconds(void);
  4537. WOLFSSL_LOCAL int FindSuiteMac(WOLFSSL* ssl, byte* suite);
  4538. #endif
  4539. WOLFSSL_LOCAL word32 LowResTimer(void);
  4540. #ifndef NO_CERTS
  4541. WOLFSSL_LOCAL void InitX509Name(WOLFSSL_X509_NAME* name, int dynamicFlag,
  4542. void* heap);
  4543. WOLFSSL_LOCAL void FreeX509Name(WOLFSSL_X509_NAME* name);
  4544. WOLFSSL_LOCAL void InitX509(WOLFSSL_X509* x509, int dynamicFlag,
  4545. void* heap);
  4546. WOLFSSL_LOCAL void FreeX509(WOLFSSL_X509* x509);
  4547. WOLFSSL_LOCAL int CopyDecodedToX509(WOLFSSL_X509* x509,
  4548. DecodedCert* dCert);
  4549. #endif
  4550. #ifndef MAX_CIPHER_NAME
  4551. #define MAX_CIPHER_NAME 50
  4552. #endif
  4553. #ifdef WOLFSSL_NAMES_STATIC
  4554. typedef char cipher_name[MAX_CIPHER_NAME];
  4555. #else
  4556. typedef const char* cipher_name;
  4557. #endif
  4558. typedef struct CipherSuiteInfo {
  4559. cipher_name name;
  4560. #ifndef NO_ERROR_STRINGS
  4561. cipher_name name_iana;
  4562. #endif
  4563. byte cipherSuite0;
  4564. byte cipherSuite;
  4565. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  4566. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  4567. byte minor;
  4568. byte major;
  4569. #endif
  4570. byte flags;
  4571. } CipherSuiteInfo;
  4572. WOLFSSL_LOCAL const CipherSuiteInfo* GetCipherNames(void);
  4573. WOLFSSL_LOCAL int GetCipherNamesSize(void);
  4574. WOLFSSL_LOCAL const char* GetCipherNameInternal(byte cipherSuite0, byte cipherSuite);
  4575. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  4576. /* used in wolfSSL_sk_CIPHER_description */
  4577. #define MAX_SEGMENTS 5
  4578. #define MAX_SEGMENT_SZ 20
  4579. WOLFSSL_LOCAL int wolfSSL_sk_CIPHER_description(WOLFSSL_CIPHER* cipher);
  4580. WOLFSSL_LOCAL const char* GetCipherSegment(const WOLFSSL_CIPHER* cipher,
  4581. char n[][MAX_SEGMENT_SZ]);
  4582. WOLFSSL_LOCAL const char* GetCipherProtocol(byte minor);
  4583. WOLFSSL_LOCAL const char* GetCipherKeaStr(char n[][MAX_SEGMENT_SZ]);
  4584. WOLFSSL_LOCAL const char* GetCipherAuthStr(char n[][MAX_SEGMENT_SZ]);
  4585. WOLFSSL_LOCAL const char* GetCipherEncStr(char n[][MAX_SEGMENT_SZ]);
  4586. WOLFSSL_LOCAL const char* GetCipherMacStr(char n[][MAX_SEGMENT_SZ]);
  4587. WOLFSSL_LOCAL int SetCipherBits(const char* enc);
  4588. WOLFSSL_LOCAL int IsCipherAEAD(char n[][MAX_SEGMENT_SZ]);
  4589. #endif
  4590. WOLFSSL_LOCAL const char* GetCipherNameIana(byte cipherSuite0, byte cipherSuite);
  4591. WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl);
  4592. WOLFSSL_LOCAL const char* wolfSSL_get_cipher_name_iana(WOLFSSL* ssl);
  4593. WOLFSSL_LOCAL int GetCipherSuiteFromName(const char* name, byte* cipherSuite0,
  4594. byte* cipherSuite, int* flags);
  4595. enum encrypt_side {
  4596. ENCRYPT_SIDE_ONLY = 1,
  4597. DECRYPT_SIDE_ONLY,
  4598. ENCRYPT_AND_DECRYPT_SIDE
  4599. };
  4600. WOLFSSL_LOCAL int SetKeysSide(WOLFSSL* ssl, enum encrypt_side side);
  4601. /* Set*Internal and Set*External functions */
  4602. WOLFSSL_LOCAL int SetDsaInternal(WOLFSSL_DSA* dsa);
  4603. WOLFSSL_LOCAL int SetDsaExternal(WOLFSSL_DSA* dsa);
  4604. #ifndef HAVE_USER_RSA
  4605. WOLFSSL_LOCAL int SetRsaExternal(WOLFSSL_RSA* rsa);
  4606. WOLFSSL_LOCAL int SetRsaInternal(WOLFSSL_RSA* rsa);
  4607. #endif
  4608. typedef enum elem_set {
  4609. ELEMENT_P = 0x01,
  4610. ELEMENT_Q = 0x02,
  4611. ELEMENT_G = 0x04,
  4612. ELEMENT_PUB = 0x08,
  4613. ELEMENT_PRV = 0x10,
  4614. } Element_Set;
  4615. WOLFSSL_LOCAL int SetDhExternal_ex(WOLFSSL_DH *dh, int elm );
  4616. WOLFSSL_LOCAL int SetDhInternal(WOLFSSL_DH* dh);
  4617. WOLFSSL_LOCAL int SetDhExternal(WOLFSSL_DH *dh);
  4618. #if !defined(NO_DH) && (!defined(NO_CERTS) || !defined(NO_PSK))
  4619. WOLFSSL_LOCAL int DhGenKeyPair(WOLFSSL* ssl, DhKey* dhKey,
  4620. byte* priv, word32* privSz,
  4621. byte* pub, word32* pubSz);
  4622. WOLFSSL_LOCAL int DhAgree(WOLFSSL* ssl, DhKey* dhKey,
  4623. const byte* priv, word32 privSz,
  4624. const byte* otherPub, word32 otherPubSz,
  4625. byte* agree, word32* agreeSz,
  4626. const byte* prime, word32 primeSz);
  4627. #endif /* !NO_DH */
  4628. #ifdef HAVE_ECC
  4629. WOLFSSL_LOCAL int EccMakeKey(WOLFSSL* ssl, ecc_key* key, ecc_key* peer);
  4630. WOLFSSL_LOCAL word16 GetCurveByOID(int oidSum);
  4631. #endif
  4632. WOLFSSL_LOCAL int InitHandshakeHashes(WOLFSSL* ssl);
  4633. WOLFSSL_LOCAL void FreeHandshakeHashes(WOLFSSL* ssl);
  4634. #ifndef WOLFSSL_NO_TLS12
  4635. WOLFSSL_LOCAL void FreeBuildMsgArgs(WOLFSSL* ssl, BuildMsgArgs* args);
  4636. #endif
  4637. WOLFSSL_LOCAL int BuildMessage(WOLFSSL* ssl, byte* output, int outSz,
  4638. const byte* input, int inSz, int type, int hashOutput,
  4639. int sizeOnly, int asyncOkay, int epochOrder);
  4640. #ifdef WOLFSSL_TLS13
  4641. int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
  4642. int inSz, int type, int hashOutput, int sizeOnly, int asyncOkay);
  4643. #endif
  4644. WOLFSSL_LOCAL int AllocKey(WOLFSSL* ssl, int type, void** pKey);
  4645. WOLFSSL_LOCAL void FreeKey(WOLFSSL* ssl, int type, void** pKey);
  4646. #ifdef WOLFSSL_ASYNC_CRYPT
  4647. WOLFSSL_LOCAL int wolfSSL_AsyncInit(WOLFSSL* ssl, WC_ASYNC_DEV* asyncDev, word32 flags);
  4648. WOLFSSL_LOCAL int wolfSSL_AsyncPop(WOLFSSL* ssl, byte* state);
  4649. WOLFSSL_LOCAL int wolfSSL_AsyncPush(WOLFSSL* ssl, WC_ASYNC_DEV* asyncDev);
  4650. #endif
  4651. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  4652. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  4653. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  4654. WOLFSSL_LOCAL int LoadCertByIssuer(WOLFSSL_X509_STORE* store,
  4655. X509_NAME* issuer, int Type);
  4656. #endif
  4657. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  4658. WOLFSSL_LOCAL WOLFSSL_BY_DIR_HASH* wolfSSL_BY_DIR_HASH_new(void);
  4659. WOLFSSL_LOCAL void wolfSSL_BY_DIR_HASH_free(WOLFSSL_BY_DIR_HASH* dir_hash);
  4660. WOLFSSL_LOCAL WOLFSSL_STACK* wolfSSL_sk_BY_DIR_HASH_new_null(void);
  4661. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_HASH_find(
  4662. WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk, const WOLFSSL_BY_DIR_HASH* toFind);
  4663. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_HASH_num(const WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *sk);
  4664. WOLFSSL_LOCAL WOLFSSL_BY_DIR_HASH* wolfSSL_sk_BY_DIR_HASH_value(
  4665. const WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *sk, int i);
  4666. WOLFSSL_LOCAL WOLFSSL_BY_DIR_HASH* wolfSSL_sk_BY_DIR_HASH_pop(
  4667. WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk);
  4668. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_HASH_pop_free(WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk,
  4669. void (*f) (WOLFSSL_BY_DIR_HASH*));
  4670. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_HASH_free(WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH) *sk);
  4671. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_HASH_push(WOLF_STACK_OF(WOLFSSL_BY_DIR_HASH)* sk,
  4672. WOLFSSL_BY_DIR_HASH* in);
  4673. /* WOLFSSL_BY_DIR_entry stuff */
  4674. WOLFSSL_LOCAL WOLFSSL_BY_DIR_entry* wolfSSL_BY_DIR_entry_new(void);
  4675. WOLFSSL_LOCAL void wolfSSL_BY_DIR_entry_free(WOLFSSL_BY_DIR_entry* entry);
  4676. WOLFSSL_LOCAL WOLFSSL_STACK* wolfSSL_sk_BY_DIR_entry_new_null(void);
  4677. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_entry_num(const WOLF_STACK_OF(WOLFSSL_BY_DIR_entry) *sk);
  4678. WOLFSSL_LOCAL WOLFSSL_BY_DIR_entry* wolfSSL_sk_BY_DIR_entry_value(
  4679. const WOLF_STACK_OF(WOLFSSL_BY_DIR_entry) *sk, int i);
  4680. WOLFSSL_LOCAL WOLFSSL_BY_DIR_entry* wolfSSL_sk_BY_DIR_entry_pop(
  4681. WOLF_STACK_OF(WOLFSSL_BY_DIR_entry)* sk);
  4682. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_entry_pop_free(WOLF_STACK_OF(wolfSSL_BY_DIR_entry)* sk,
  4683. void (*f) (WOLFSSL_BY_DIR_entry*));
  4684. WOLFSSL_LOCAL void wolfSSL_sk_BY_DIR_entry_free(WOLF_STACK_OF(wolfSSL_BY_DIR_entry) *sk);
  4685. WOLFSSL_LOCAL int wolfSSL_sk_BY_DIR_entry_push(WOLF_STACK_OF(wolfSSL_BY_DIR_entry)* sk,
  4686. WOLFSSL_BY_DIR_entry* in);
  4687. #endif /* OPENSSL_ALL && !NO_FILESYSTEM && !NO_WOLFSSL_DIR */
  4688. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  4689. WOLFSSL_LOCAL int oid2nid(word32 oid, int grp);
  4690. WOLFSSL_LOCAL word32 nid2oid(int nid, int grp);
  4691. #endif
  4692. #ifdef WOLFSSL_STATIC_EPHEMERAL
  4693. WOLFSSL_LOCAL int wolfSSL_StaticEphemeralKeyLoad(WOLFSSL* ssl, int keyAlgo, void* keyPtr);
  4694. #endif
  4695. #ifndef NO_CERTS
  4696. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  4697. defined(OPENSSL_EXTRA_X509_SMALL)
  4698. WOLFSSL_LOCAL int wolfSSL_ASN1_STRING_canon(WOLFSSL_ASN1_STRING* asn_out,
  4699. const WOLFSSL_ASN1_STRING* asn_in);
  4700. #endif
  4701. #endif
  4702. #if defined(HAVE_EX_DATA) && \
  4703. (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  4704. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  4705. defined(HAVE_LIGHTY)) || defined(HAVE_EX_DATA) || \
  4706. defined(WOLFSSL_WPAS_SMALL)
  4707. WOLFSSL_LOCAL int wolfssl_get_ex_new_index(int class_index);
  4708. #endif
  4709. #if !defined(WC_NO_RNG) && (defined(OPENSSL_EXTRA) || \
  4710. (defined(OPENSSL_EXTRA_X509_SMALL) && !defined(NO_RSA)))
  4711. WOLFSSL_LOCAL WC_RNG* wolfssl_get_global_rng(void);
  4712. #endif
  4713. #if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
  4714. #if defined(WOLFSSL_KEY_GEN) && defined(WOLFSSL_PEM_TO_DER)
  4715. WOLFSSL_LOCAL int EncryptDerKey(byte *der, int *derSz, const EVP_CIPHER* cipher,
  4716. unsigned char* passwd, int passwdSz, byte **cipherInfo, int maxDerSz);
  4717. #endif
  4718. #endif
  4719. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && !defined(HAVE_USER_RSA)
  4720. WOLFSSL_LOCAL int wolfSSL_RSA_To_Der(WOLFSSL_RSA* rsa, byte** outBuf,
  4721. int publicKey, void* heap);
  4722. #endif
  4723. #ifdef __cplusplus
  4724. } /* extern "C" */
  4725. #endif
  4726. #endif /* wolfSSL_INT_H */