1
0

ssl.h 470 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117
  1. /*!
  2. \brief This function initializes the DTLS v1.2 client method.
  3. \return pointer This function returns a pointer to a new
  4. WOLFSSL_METHOD structure.
  5. \param none No parameters.
  6. _Example_
  7. \code
  8. wolfSSL_Init();
  9. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method());
  10. WOLFSSL* ssl = wolfSSL_new(ctx);
  11. \endcode
  12. \sa wolfSSL_Init
  13. \sa wolfSSL_CTX_new
  14. */
  15. WOLFSSL_METHOD *wolfDTLSv1_2_client_method_ex(void* heap);
  16. /*!
  17. \ingroup Setup
  18. \brief This function returns a WOLFSSL_METHOD similar to
  19. wolfSSLv23_client_method except that it is not determined
  20. which side yet (server/client).
  21. \return WOLFSSL_METHOD* On successful creations returns a WOLFSSL_METHOD
  22. pointer
  23. \return NULL Null if memory allocation error or failure to create method
  24. \param none No parameters.
  25. _Example_
  26. \code
  27. WOLFSSL* ctx;
  28. ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  29. // check ret value
  30. \endcode
  31. \sa wolfSSL_new
  32. \sa wolfSSL_free
  33. */
  34. WOLFSSL_METHOD *wolfSSLv23_method(void);
  35. /*!
  36. \ingroup Setup
  37. \brief The wolfSSLv3_server_method() function is used to indicate
  38. that the application is a server and will only support the SSL 3.0
  39. protocol. This function allocates memory for and initializes a new
  40. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  41. with wolfSSL_CTX_new().
  42. \return * If successful, the call will return a pointer to the newly
  43. created WOLFSSL_METHOD structure.
  44. \return FAIL If memory allocation fails when calling XMALLOC, the
  45. failure value of the underlying malloc() implementation will be returned
  46. (typically NULL with errno will be set to ENOMEM).
  47. \param none No parameters.
  48. _Example_
  49. \code
  50. #include <wolfssl/ssl.h>
  51. WOLFSSL_METHOD* method;
  52. WOLFSSL_CTX* ctx;
  53. method = wolfSSLv3_server_method();
  54. if (method == NULL) {
  55. unable to get method
  56. }
  57. ctx = wolfSSL_CTX_new(method);
  58. ...
  59. \endcode
  60. \sa wolfTLSv1_server_method
  61. \sa wolfTLSv1_1_server_method
  62. \sa wolfTLSv1_2_server_method
  63. \sa wolfTLSv1_3_server_method
  64. \sa wolfDTLSv1_server_method
  65. \sa wolfSSLv23_server_method
  66. \sa wolfSSL_CTX_new
  67. */
  68. WOLFSSL_METHOD *wolfSSLv3_server_method(void);
  69. /*!
  70. \ingroup Setup
  71. \brief The wolfSSLv3_client_method() function is used to indicate
  72. that the application is a client and will only support the SSL 3.0
  73. protocol. This function allocates memory for and initializes a
  74. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  75. context with wolfSSL_CTX_new().
  76. \return * If successful, the call will return a pointer to the newly
  77. created WOLFSSL_METHOD structure.
  78. \return FAIL If memory allocation fails when calling XMALLOC, the
  79. failure value of the underlying malloc() implementation will be
  80. returned (typically NULL with errno will be set to ENOMEM).
  81. \param none No parameters.
  82. _Example_
  83. \code
  84. #include <wolfssl/ssl.h>
  85. WOLFSSL_METHOD* method;
  86. WOLFSSL_CTX* ctx;
  87. method = wolfSSLv3_client_method();
  88. if (method == NULL) {
  89. unable to get method
  90. }
  91. ctx = wolfSSL_CTX_new(method);
  92. ...
  93. \endcode
  94. \sa wolfTLSv1_client_method
  95. \sa wolfTLSv1_1_client_method
  96. \sa wolfTLSv1_2_client_method
  97. \sa wolfTLSv1_3_client_method
  98. \sa wolfDTLSv1_client_method
  99. \sa wolfSSLv23_client_method
  100. \sa wolfSSL_CTX_new
  101. */
  102. WOLFSSL_METHOD *wolfSSLv3_client_method(void);
  103. /*!
  104. \ingroup Setup
  105. \brief The wolfTLSv1_server_method() function is used to indicate that the
  106. application is a server and will only support the TLS 1.0 protocol. This
  107. function allocates memory for and initializes a new wolfSSL_METHOD
  108. structure to be used when creating the SSL/TLS context with
  109. wolfSSL_CTX_new().
  110. \return * If successful, the call will return a pointer to the newly
  111. created WOLFSSL_METHOD structure.
  112. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  113. value of the underlying malloc() implementation will be returned
  114. (typically NULL with errno will be set to ENOMEM).
  115. \param none No parameters.
  116. _Example_
  117. \code
  118. #include <wolfssl/ssl.h>
  119. WOLFSSL_METHOD* method;
  120. WOLFSSL_CTX* ctx;
  121. method = wolfTLSv1_server_method();
  122. if (method == NULL) {
  123. unable to get method
  124. }
  125. ctx = wolfSSL_CTX_new(method);
  126. ...
  127. \endcode
  128. \sa wolfSSLv3_server_method
  129. \sa wolfTLSv1_1_server_method
  130. \sa wolfTLSv1_2_server_method
  131. \sa wolfTLSv1_3_server_method
  132. \sa wolfDTLSv1_server_method
  133. \sa wolfSSLv23_server_method
  134. \sa wolfSSL_CTX_new
  135. */
  136. WOLFSSL_METHOD *wolfTLSv1_server_method(void);
  137. /*!
  138. \ingroup Setup
  139. \brief The wolfTLSv1_client_method() function is used to indicate
  140. that the application is a client and will only support the TLS 1.0
  141. protocol. This function allocates memory for and initializes a new
  142. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  143. with wolfSSL_CTX_new().
  144. \return * If successful, the call will return a pointer to the newly
  145. created WOLFSSL_METHOD structure.
  146. \return FAIL If memory allocation fails when calling XMALLOC,
  147. the failure value of the underlying malloc() implementation
  148. will be returned (typically NULL with errno will be set to ENOMEM).
  149. \param none No parameters.
  150. _Example_
  151. \code
  152. #include <wolfssl/ssl.h>
  153. WOLFSSL_METHOD* method;
  154. WOLFSSL_CTX* ctx;
  155. method = wolfTLSv1_client_method();
  156. if (method == NULL) {
  157. unable to get method
  158. }
  159. ctx = wolfSSL_CTX_new(method);
  160. ...
  161. \endcode
  162. \sa wolfSSLv3_client_method
  163. \sa wolfTLSv1_1_client_method
  164. \sa wolfTLSv1_2_client_method
  165. \sa wolfTLSv1_3_client_method
  166. \sa wolfDTLSv1_client_method
  167. \sa wolfSSLv23_client_method
  168. \sa wolfSSL_CTX_new
  169. */
  170. WOLFSSL_METHOD *wolfTLSv1_client_method(void);
  171. /*!
  172. \ingroup Setup
  173. \brief The wolfTLSv1_1_server_method() function is used to indicate
  174. that the application is a server and will only support the TLS 1.1
  175. protocol. This function allocates memory for and initializes a new
  176. wolfSSL_METHOD structure to be used when creating the SSL/TLS
  177. context with wolfSSL_CTX_new().
  178. \return * If successful, the call will return a pointer to the newly
  179. created WOLFSSL_METHOD structure.
  180. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  181. value of the underlying malloc() implementation will be returned
  182. (typically NULL with errno will be set to ENOMEM).
  183. \param none No parameters.
  184. _Example_
  185. \code
  186. #include <wolfssl/ssl.h>
  187. WOLFSSL_METHOD* method;
  188. WOLFSSL_CTX* ctx;
  189. method = wolfTLSv1_1_server_method();
  190. if (method == NULL) {
  191. // unable to get method
  192. }
  193. ctx = wolfSSL_CTX_new(method);
  194. ...
  195. \endcode
  196. \sa wolfSSLv3_server_method
  197. \sa wolfTLSv1_server_method
  198. \sa wolfTLSv1_2_server_method
  199. \sa wolfTLSv1_3_server_method
  200. \sa wolfDTLSv1_server_method
  201. \sa wolfSSLv23_server_method
  202. \sa wolfSSL_CTX_new
  203. */
  204. WOLFSSL_METHOD *wolfTLSv1_1_server_method(void);
  205. /*!
  206. \ingroup Setup
  207. \brief The wolfTLSv1_1_client_method() function is used to indicate
  208. that the application is a client and will only support the TLS 1.0
  209. protocol. This function allocates memory for and initializes a
  210. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  211. context with wolfSSL_CTX_new().
  212. \return * If successful, the call will return a pointer to the
  213. newly created WOLFSSL_METHOD structure.
  214. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  215. value of the underlying malloc() implementation will be returned
  216. (typically NULL with errno will be set to ENOMEM).
  217. \param none No parameters.
  218. _Example_
  219. \code
  220. #include <wolfssl/ssl.h>
  221. WOLFSSL_METHOD* method;
  222. WOLFSSL_CTX* ctx;
  223. method = wolfTLSv1_1_client_method();
  224. if (method == NULL) {
  225. // unable to get method
  226. }
  227. ctx = wolfSSL_CTX_new(method);
  228. ...
  229. \endcode
  230. \sa wolfSSLv3_client_method
  231. \sa wolfTLSv1_client_method
  232. \sa wolfTLSv1_2_client_method
  233. \sa wolfTLSv1_3_client_method
  234. \sa wolfDTLSv1_client_method
  235. \sa wolfSSLv23_client_method
  236. \sa wolfSSL_CTX_new
  237. */
  238. WOLFSSL_METHOD *wolfTLSv1_1_client_method(void);
  239. /*!
  240. \ingroup Setup
  241. \brief The wolfTLSv1_2_server_method() function is used to indicate
  242. that the application is a server and will only support the TLS 1.2
  243. protocol. This function allocates memory for and initializes a new
  244. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  245. with wolfSSL_CTX_new().
  246. \return * If successful, the call will return a pointer to the newly
  247. created WOLFSSL_METHOD structure.
  248. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  249. value of the underlying malloc() implementation will be returned
  250. (typically NULL with errno will be set to ENOMEM).
  251. \param none No parameters.
  252. _Example_
  253. \code
  254. #include <wolfssl/ssl.h>
  255. WOLFSSL_METHOD* method;
  256. WOLFSSL_CTX* ctx;
  257. method = wolfTLSv1_2_server_method();
  258. if (method == NULL) {
  259. // unable to get method
  260. }
  261. ctx = wolfSSL_CTX_new(method);
  262. ...
  263. \endcode
  264. \sa wolfSSLv3_server_method
  265. \sa wolfTLSv1_server_method
  266. \sa wolfTLSv1_1_server_method
  267. \sa wolfTLSv1_3_server_method
  268. \sa wolfDTLSv1_server_method
  269. \sa wolfSSLv23_server_method
  270. \sa wolfSSL_CTX_new
  271. */
  272. WOLFSSL_METHOD *wolfTLSv1_2_server_method(void);
  273. /*!
  274. \ingroup Setup
  275. \brief The wolfTLSv1_2_client_method() function is used to indicate
  276. that the application is a client and will only support the TLS 1.2
  277. protocol. This function allocates memory for and initializes a new
  278. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  279. with wolfSSL_CTX_new().
  280. \return * If successful, the call will return a pointer to the newly
  281. created WOLFSSL_METHOD structure.
  282. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  283. value of the underlying malloc() implementation will be returned
  284. (typically NULL with errno will be set to ENOMEM).
  285. \param none No parameters.
  286. _Example_
  287. \code
  288. #include <wolfssl/ssl.h>
  289. WOLFSSL_METHOD* method;
  290. WOLFSSL_CTX* ctx;
  291. method = wolfTLSv1_2_client_method();
  292. if (method == NULL) {
  293. // unable to get method
  294. }
  295. ctx = wolfSSL_CTX_new(method);
  296. ...
  297. \endcode
  298. \sa wolfSSLv3_client_method
  299. \sa wolfTLSv1_client_method
  300. \sa wolfTLSv1_1_client_method
  301. \sa wolfTLSv1_3_client_method
  302. \sa wolfDTLSv1_client_method
  303. \sa wolfSSLv23_client_method
  304. \sa wolfSSL_CTX_new
  305. */
  306. WOLFSSL_METHOD *wolfTLSv1_2_client_method(void);
  307. /*!
  308. \ingroup Setup
  309. \brief The wolfDTLSv1_client_method() function is used to indicate that
  310. the application is a client and will only support the DTLS 1.0 protocol.
  311. This function allocates memory for and initializes a new
  312. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  313. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  314. been compiled with DTLS support (--enable-dtls,
  315. or by defining wolfSSL_DTLS).
  316. \return * If successful, the call will return a pointer to the newly
  317. created WOLFSSL_METHOD structure.
  318. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  319. value of the underlying malloc() implementation will be returned
  320. (typically NULL with errno will be set to ENOMEM).
  321. \param none No parameters.
  322. _Example_
  323. \code
  324. WOLFSSL_METHOD* method;
  325. WOLFSSL_CTX* ctx;
  326. method = wolfDTLSv1_client_method();
  327. if (method == NULL) {
  328. // unable to get method
  329. }
  330. ctx = wolfSSL_CTX_new(method);
  331. ...
  332. \endcode
  333. \sa wolfSSLv3_client_method
  334. \sa wolfTLSv1_client_method
  335. \sa wolfTLSv1_1_client_method
  336. \sa wolfTLSv1_2_client_method
  337. \sa wolfTLSv1_3_client_method
  338. \sa wolfSSLv23_client_method
  339. \sa wolfSSL_CTX_new
  340. */
  341. WOLFSSL_METHOD *wolfDTLSv1_client_method(void);
  342. /*!
  343. \ingroup Setup
  344. \brief The wolfDTLSv1_server_method() function is used to indicate
  345. that the application is a server and will only support the DTLS 1.0
  346. protocol. This function allocates memory for and initializes a
  347. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  348. context with wolfSSL_CTX_new(). This function is only available
  349. when wolfSSL has been compiled with DTLS support (--enable-dtls,
  350. or by defining wolfSSL_DTLS).
  351. \return * If successful, the call will return a pointer to the newly
  352. created WOLFSSL_METHOD structure.
  353. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  354. value of the underlying malloc() implementation will be returned
  355. (typically NULL with errno will be set to ENOMEM).
  356. \param none No parameters.
  357. _Example_
  358. \code
  359. WOLFSSL_METHOD* method;
  360. WOLFSSL_CTX* ctx;
  361. method = wolfDTLSv1_server_method();
  362. if (method == NULL) {
  363. // unable to get method
  364. }
  365. ctx = wolfSSL_CTX_new(method);
  366. ...
  367. \endcode
  368. \sa wolfSSLv3_server_method
  369. \sa wolfTLSv1_server_method
  370. \sa wolfTLSv1_1_server_method
  371. \sa wolfTLSv1_2_server_method
  372. \sa wolfTLSv1_3_server_method
  373. \sa wolfSSLv23_server_method
  374. \sa wolfSSL_CTX_new
  375. */
  376. WOLFSSL_METHOD *wolfDTLSv1_server_method(void);
  377. /*!
  378. \ingroup Setup
  379. \brief The wolfDTLSv1_3_server_method() function is used to indicate that
  380. the application is a server and will only support the DTLS 1.3
  381. protocol. This function allocates memory for and initializes a new
  382. wolfSSL_METHOD structure to be used when creating the SSL/TLS context with
  383. wolfSSL_CTX_new(). This function is only available when wolfSSL has been
  384. compiled with DTLSv1.3 support (--enable-dtls13, or by defining
  385. wolfSSL_DTLS13).
  386. \return * If successful, the call will return a pointer to the newly
  387. created WOLFSSL_METHOD structure.
  388. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  389. value of the underlying malloc() implementation will be returned
  390. (typically NULL with errno will be set to ENOMEM).
  391. \param none No parameters.
  392. _Example_
  393. \code
  394. WOLFSSL_METHOD* method;
  395. WOLFSSL_CTX* ctx;
  396. method = wolfDTLSv1_3_server_method();
  397. if (method == NULL) {
  398. // unable to get method
  399. }
  400. ctx = wolfSSL_CTX_new(method);
  401. ...
  402. \endcode
  403. \sa wolfDTLSv1_3_client_method
  404. */
  405. WOLFSSL_METHOD *wolfDTLSv1_3_server_method(void);
  406. /*!
  407. \ingroup Setup
  408. \brief The wolfDTLSv1_3_client_method() function is used to indicate that
  409. the application is a client and will only support the DTLS 1.3
  410. protocol. This function allocates memory for and initializes a new
  411. wolfSSL_METHOD structure to be used when creating the SSL/TLS context with
  412. wolfSSL_CTX_new(). This function is only available when wolfSSL has been
  413. compiled with DTLSv1.3 support (--enable-dtls13, or by defining
  414. wolfSSL_DTLS13).
  415. \return * If successful, the call will return a pointer to the newly
  416. created WOLFSSL_METHOD structure.
  417. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  418. value of the underlying malloc() implementation will be returned
  419. (typically NULL with errno will be set to ENOMEM).
  420. \param none No parameters.
  421. _Example_
  422. \code
  423. WOLFSSL_METHOD* method;
  424. WOLFSSL_CTX* ctx;
  425. method = wolfDTLSv1_3_client_method();
  426. if (method == NULL) {
  427. // unable to get method
  428. }
  429. ctx = wolfSSL_CTX_new(method);
  430. ...
  431. \endcode
  432. \sa wolfDTLSv1_3_server_method
  433. */
  434. WOLFSSL_METHOD* wolfDTLSv1_3_client_method(void);
  435. /*!
  436. \ingroup Setup
  437. \brief The wolfDTLS_server_method() function is used to indicate that the
  438. application is a server and will support the highest version of DTLS
  439. available and all the version up to the minimum version allowed. The
  440. default minimum version allowed is based on the define
  441. WOLFSSL_MIN_DTLS_DOWNGRADE and can be changed at runtime using
  442. wolfSSL_SetMinVersion(). This function allocates memory for and initializes
  443. a new wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  444. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  445. been compiled with DTLS support (--enable-dtls, or by defining
  446. wolfSSL_DTLS).
  447. \return * If successful, the call will return a pointer to the newly
  448. created WOLFSSL_METHOD structure.
  449. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  450. value of the underlying malloc() implementation will be returned
  451. (typically NULL with errno will be set to ENOMEM).
  452. \param none No parameters.
  453. _Example_
  454. \code
  455. WOLFSSL_METHOD* method;
  456. WOLFSSL_CTX* ctx;
  457. method = wolfDTLS_server_method();
  458. if (method == NULL) {
  459. // unable to get method
  460. }
  461. ctx = wolfSSL_CTX_new(method);
  462. ...
  463. \endcode
  464. \sa wolfDTLS_client_method
  465. \sa wolfSSL_SetMinVersion
  466. */
  467. WOLFSSL_METHOD *wolfDTLS_server_method(void);
  468. /*!
  469. \ingroup Setup
  470. \brief The wolfDTLS_client_method() function is used to indicate that the
  471. application is a client and will support the highest version of DTLS
  472. available and all the version up to the minimum version allowed. The
  473. default minimum version allowed is based on the define
  474. WOLFSSL_MIN_DTLS_DOWNGRADE and can be changed at runtime using
  475. wolfSSL_SetMinVersion(). This function allocates memory for and initializes
  476. a new wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  477. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  478. been compiled with DTLS support (--enable-dtls, or by defining
  479. wolfSSL_DTLS).
  480. \return * If successful, the call will return a pointer to the newly
  481. created WOLFSSL_METHOD structure.
  482. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  483. value of the underlying malloc() implementation will be returned
  484. (typically NULL with errno will be set to ENOMEM).
  485. \param none No parameters.
  486. _Example_
  487. \code
  488. WOLFSSL_METHOD* method;
  489. WOLFSSL_CTX* ctx;
  490. method = wolfDTLS_client_method();
  491. if (method == NULL) {
  492. // unable to get method
  493. }
  494. ctx = wolfSSL_CTX_new(method);
  495. ...
  496. \endcode
  497. \sa wolfDTLS_server_method
  498. \sa wolfSSL_SetMinVersion
  499. */
  500. WOLFSSL_METHOD *wolfDTLS_client_method(void);
  501. /*!
  502. \brief This function creates and initializes a WOLFSSL_METHOD for the
  503. server side.
  504. \return This function returns a WOLFSSL_METHOD pointer.
  505. \param none No parameters.
  506. _Example_
  507. \code
  508. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  509. WOLFSSL* ssl = WOLFSSL_new(ctx);
  510. \endcode
  511. \sa wolfSSL_CTX_new
  512. */
  513. WOLFSSL_METHOD *wolfDTLSv1_2_server_method(void);
  514. /*!
  515. \ingroup Setup
  516. \brief Since there is some differences between the first release and
  517. newer versions of chacha-poly AEAD construction we have added an option
  518. to communicate with servers/clients using the older version. By default
  519. wolfSSL uses the new version.
  520. \return 0 upon success
  521. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  522. \param value whether or not to use the older version of setting up the
  523. information for poly1305. Passing a flag value of 1 indicates yes use the
  524. old poly AEAD, to switch back to using the new version pass a flag value
  525. of 0.
  526. _Example_
  527. \code
  528. int ret = 0;
  529. WOLFSSL* ssl;
  530. ...
  531. ret = wolfSSL_use_old_poly(ssl, 1);
  532. if (ret != 0) {
  533. // failed to set poly1305 AEAD version
  534. }
  535. \endcode
  536. \sa none
  537. */
  538. int wolfSSL_use_old_poly(WOLFSSL* ssl, int value);
  539. /*!
  540. \brief The wolfSSL_dtls_import() function is used to parse in a serialized
  541. session state. This allows for picking up the connection after the
  542. handshake has been completed.
  543. \return Success If successful, the amount of the buffer read will be
  544. returned.
  545. \return Failure All unsuccessful return values will be less than 0.
  546. \return VERSION_ERROR If a version mismatch is found ie DTLS v1 and ctx
  547. was set up for DTLS v1.2 then VERSION_ERROR is returned.
  548. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  549. \param buf serialized session to import.
  550. \param sz size of serialized session buffer.
  551. _Example_
  552. \code
  553. WOLFSSL* ssl;
  554. int ret;
  555. unsigned char buf[MAX];
  556. bufSz = MAX;
  557. ...
  558. //get information sent from wc_dtls_export function and place it in buf
  559. fread(buf, 1, bufSz, input);
  560. ret = wolfSSL_dtls_import(ssl, buf, bufSz);
  561. if (ret < 0) {
  562. // handle error case
  563. }
  564. // no wolfSSL_accept needed since handshake was already done
  565. ...
  566. ret = wolfSSL_write(ssl) and wolfSSL_read(ssl);
  567. ...
  568. \endcode
  569. \sa wolfSSL_new
  570. \sa wolfSSL_CTX_new
  571. \sa wolfSSL_CTX_dtls_set_export
  572. */
  573. int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf,
  574. unsigned int sz);
  575. /*!
  576. \brief Used to import a serialized TLS session. This function is for
  577. importing the state of the connection.
  578. WARNING: buf contains sensitive information about the state and is best to
  579. be encrypted before storing if stored.
  580. Additional debug info can be displayed with the macro
  581. WOLFSSL_SESSION_EXPORT_DEBUG defined.
  582. \return the number of bytes read from buffer 'buf'
  583. \param ssl WOLFSSL structure to import the session into
  584. \param buf serialized session
  585. \param sz size of buffer 'buf'
  586. \sa wolfSSL_dtls_import
  587. \sa wolfSSL_tls_export
  588. */
  589. int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf,
  590. unsigned int sz);
  591. /*!
  592. \brief The wolfSSL_CTX_dtls_set_export() function is used to set
  593. the callback function for exporting a session. It is allowed to
  594. pass in NULL as the parameter func to clear the export function
  595. previously stored. Used on the server side and is called immediately
  596. after handshake is completed.
  597. \return SSL_SUCCESS upon success.
  598. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  599. \param ctx a pointer to a WOLFSSL_CTX structure, created
  600. with wolfSSL_CTX_new().
  601. \param func wc_dtls_export function to use when exporting a session.
  602. _Example_
  603. \code
  604. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  605. // body of send session (wc_dtls_export) that passes
  606. // buf (serialized session) to destination
  607. WOLFSSL_CTX* ctx;
  608. int ret;
  609. ...
  610. ret = wolfSSL_CTX_dtls_set_export(ctx, send_session);
  611. if (ret != SSL_SUCCESS) {
  612. // handle error case
  613. }
  614. ...
  615. ret = wolfSSL_accept(ssl);
  616. ...
  617. \endcode
  618. \sa wolfSSL_new
  619. \sa wolfSSL_CTX_new
  620. \sa wolfSSL_dtls_set_export
  621. \sa Static buffer use
  622. */
  623. int wolfSSL_CTX_dtls_set_export(WOLFSSL_CTX* ctx,
  624. wc_dtls_export func);
  625. /*!
  626. \brief The wolfSSL_dtls_set_export() function is used to set the callback
  627. function for exporting a session. It is allowed to pass in NULL as the
  628. parameter func to clear the export function previously stored. Used on
  629. the server side and is called immediately after handshake is completed.
  630. \return SSL_SUCCESS upon success.
  631. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  632. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  633. \param func wc_dtls_export function to use when exporting a session.
  634. _Example_
  635. \code
  636. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  637. // body of send session (wc_dtls_export) that passes
  638. // buf (serialized session) to destination
  639. WOLFSSL* ssl;
  640. int ret;
  641. ...
  642. ret = wolfSSL_dtls_set_export(ssl, send_session);
  643. if (ret != SSL_SUCCESS) {
  644. // handle error case
  645. }
  646. ...
  647. ret = wolfSSL_accept(ssl);
  648. ...
  649. \endcode
  650. \sa wolfSSL_new
  651. \sa wolfSSL_CTX_new
  652. \sa wolfSSL_CTX_dtls_set_export
  653. */
  654. int wolfSSL_dtls_set_export(WOLFSSL* ssl, wc_dtls_export func);
  655. /*!
  656. \brief The wolfSSL_dtls_export() function is used to serialize a
  657. WOLFSSL session into the provided buffer. Allows for less memory
  658. overhead than using a function callback for sending a session and
  659. choice over when the session is serialized. If buffer is NULL when
  660. passed to function then sz will be set to the size of buffer needed
  661. for serializing the WOLFSSL session.
  662. \return Success If successful, the amount of the buffer used will
  663. be returned.
  664. \return Failure All unsuccessful return values will be less than 0.
  665. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  666. \param buf buffer to hold serialized session.
  667. \param sz size of buffer.
  668. _Example_
  669. \code
  670. WOLFSSL* ssl;
  671. int ret;
  672. unsigned char buf[MAX];
  673. bufSz = MAX;
  674. ...
  675. ret = wolfSSL_dtls_export(ssl, buf, bufSz);
  676. if (ret < 0) {
  677. // handle error case
  678. }
  679. ...
  680. \endcode
  681. \sa wolfSSL_new
  682. \sa wolfSSL_CTX_new
  683. \sa wolfSSL_CTX_dtls_set_export
  684. \sa wolfSSL_dtls_import
  685. */
  686. int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf,
  687. unsigned int* sz);
  688. /*!
  689. \brief Used to export a serialized TLS session. This function is for
  690. exporting a serialized state of the connection.
  691. In most cases wolfSSL_get1_session should be used instead of
  692. wolfSSL_tls_export.
  693. Additional debug info can be displayed with the macro
  694. WOLFSSL_SESSION_EXPORT_DEBUG defined.
  695. WARNING: buf contains sensitive information about the state and is best to
  696. be encrypted before storing if stored.
  697. \return the number of bytes written into buffer 'buf'
  698. \param ssl WOLFSSL structure to export the session from
  699. \param buf output of serialized session
  700. \param sz size in bytes set in 'buf'
  701. \sa wolfSSL_dtls_import
  702. \sa wolfSSL_tls_import
  703. */
  704. int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf,
  705. unsigned int* sz);
  706. /*!
  707. \brief This function is used to set aside static memory for a CTX. Memory
  708. set aside is then used for the CTX’s lifetime and for any SSL objects
  709. created from the CTX. By passing in a NULL ctx pointer and a
  710. wolfSSL_method_func function the creation of the CTX itself will also
  711. use static memory. wolfSSL_method_func has the function signature of
  712. WOLFSSL_METHOD* (*wolfSSL_method_func)(void* heap);. Passing in 0 for max
  713. makes it behave as if not set and no max concurrent use restrictions is
  714. in place. The flag value passed in determines how the memory is used and
  715. behavior while operating. Available flags are the following: 0 - default
  716. general memory, WOLFMEM_IO_POOL - used for input/output buffer when
  717. sending receiving messages and overrides general memory, so all memory
  718. in buffer passed in is used for IO, WOLFMEM_IO_FIXED - same as
  719. WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for
  720. their lifetime, WOLFMEM_TRACK_STATS - each SSL keeps track of memory
  721. stats while running.
  722. \return SSL_SUCCESS upon success.
  723. \return SSL_FAILURE upon failure.
  724. \param ctx address of pointer to a WOLFSSL_CTX structure.
  725. \param method function to create protocol. (should be NULL if ctx is not
  726. also NULL)
  727. \param buf memory to use for all operations.
  728. \param sz size of memory buffer being passed in.
  729. \param flag type of memory.
  730. \param max max concurrent operations.
  731. _Example_
  732. \code
  733. WOLFSSL_CTX* ctx;
  734. WOLFSSL* ssl;
  735. int ret;
  736. unsigned char memory[MAX];
  737. int memorySz = MAX;
  738. unsigned char IO[MAX];
  739. int IOSz = MAX;
  740. int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
  741. ...
  742. // create ctx also using static memory, start with general memory to use
  743. ctx = NULL:
  744. ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex,
  745. memory, memorySz, 0, MAX_CONCURRENT_HANDSHAKES);
  746. if (ret != SSL_SUCCESS) {
  747. // handle error case
  748. }
  749. // load in memory for use with IO
  750. ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag,
  751. MAX_CONCURRENT_IO);
  752. if (ret != SSL_SUCCESS) {
  753. // handle error case
  754. }
  755. ...
  756. \endcode
  757. \sa wolfSSL_CTX_new
  758. \sa wolfSSL_CTX_is_static_memory
  759. \sa wolfSSL_is_static_memory
  760. */
  761. int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx,
  762. wolfSSL_method_func method,
  763. unsigned char* buf, unsigned int sz,
  764. int flag, int max);
  765. /*!
  766. \brief This function does not change any of the connections behavior
  767. and is used only for gathering information about the static memory usage.
  768. \return 1 is returned if using static memory for the CTX is true.
  769. \return 0 is returned if not using static memory.
  770. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  771. wolfSSL_CTX_new().
  772. \param mem_stats structure to hold information about static memory usage.
  773. _Example_
  774. \code
  775. WOLFSSL_CTX* ctx;
  776. int ret;
  777. WOLFSSL_MEM_STATS mem_stats;
  778. ...
  779. //get information about static memory with CTX
  780. ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
  781. if (ret == 1) {
  782. // handle case of is using static memory
  783. // print out or inspect elements of mem_stats
  784. }
  785. if (ret == 0) {
  786. //handle case of ctx not using static memory
  787. }
  788. \endcode
  789. \sa wolfSSL_CTX_new
  790. \sa wolfSSL_CTX_load_static_memory
  791. \sa wolfSSL_is_static_memory
  792. */
  793. int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX* ctx,
  794. WOLFSSL_MEM_STATS* mem_stats);
  795. /*!
  796. \brief wolfSSL_is_static_memory is used to gather information about
  797. a SSL’s static memory usage. The return value indicates if static
  798. memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out
  799. if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent
  800. CTX when loading in static memory.
  801. \return 1 is returned if using static memory for the CTX is true.
  802. \return 0 is returned if not using static memory.
  803. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  804. \param mem_stats structure to contain static memory usage.
  805. _Example_
  806. \code
  807. WOLFSSL* ssl;
  808. int ret;
  809. WOLFSSL_MEM_CONN_STATS mem_stats;
  810. ...
  811. ret = wolfSSL_is_static_memory(ssl, mem_stats);
  812. if (ret == 1) {
  813. // handle case when is static memory
  814. // investigate elements in mem_stats if WOLFMEM_TRACK_STATS flag
  815. }
  816. ...
  817. \endcode
  818. \sa wolfSSL_new
  819. \sa wolfSSL_CTX_is_static_memory
  820. */
  821. int wolfSSL_is_static_memory(WOLFSSL* ssl,
  822. WOLFSSL_MEM_CONN_STATS* mem_stats);
  823. /*!
  824. \ingroup CertsKeys
  825. \brief This function loads a certificate file into the SSL context
  826. (WOLFSSL_CTX). The file is provided by the file argument. The
  827. format argument specifies the format type of the file, either
  828. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please see the examples
  829. for proper usage.
  830. \return SSL_SUCCESS upon success.
  831. \return SSL_FAILURE If the function call fails, possible causes might
  832. include the file is in the wrong format, or the wrong format has been
  833. given using the “format” argument, file doesn’t exist, can’t be read,
  834. or is corrupted, an out of memory condition occurs, Base16 decoding
  835. fails on the file.
  836. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  837. wolfSSL_CTX_new()
  838. \param file a pointer to the name of the file containing the certificate
  839. to be loaded into the wolfSSL SSL context.
  840. \param format - format of the certificates pointed to by file. Possible
  841. options are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  842. _Example_
  843. \code
  844. int ret = 0;
  845. WOLFSSL_CTX* ctx;
  846. ...
  847. ret = wolfSSL_CTX_use_certificate_file(ctx, “./client-cert.pem”,
  848. SSL_FILETYPE_PEM);
  849. if (ret != SSL_SUCCESS) {
  850. // error loading cert file
  851. }
  852. ...
  853. \endcode
  854. \sa wolfSSL_CTX_use_certificate_buffer
  855. \sa wolfSSL_use_certificate_file
  856. \sa wolfSSL_use_certificate_buffer
  857. */
  858. int wolfSSL_CTX_use_certificate_file(WOLFSSL_CTX* ctx, const char* file,
  859. int format);
  860. /*!
  861. \ingroup CertsKeys
  862. \brief This function loads a private key file into the SSL context
  863. (WOLFSSL_CTX). The file is provided by the file argument. The format
  864. argument specifies the format type of the file - SSL_FILETYPE_ASN1or
  865. SSL_FILETYPE_PEM. Please see the examples for proper usage.
  866. If using an external key store and do not have the private key you can
  867. instead provide the public key and register the crypro callback to handle
  868. the signing. For this you can build with either build with crypto callbacks
  869. or PK callbacks. To enable crypto callbacks use --enable-cryptocb
  870. or WOLF_CRYPTO_CB and register a crypto callback using
  871. wc_CryptoCb_RegisterDevice and set the associated devId using
  872. wolfSSL_CTX_SetDevId.
  873. \return SSL_SUCCESS upon success.
  874. \return SSL_FAILURE The file is in the wrong format, or the wrong format
  875. has been given using the “format” argument. The file doesn’t exist, can’t
  876. be read, or is corrupted. An out of memory condition occurs. Base16
  877. decoding fails on the file. The key file is encrypted but no password
  878. is provided.
  879. \param none No parameters.
  880. _Example_
  881. \code
  882. int ret = 0;
  883. WOLFSSL_CTX* ctx;
  884. ...
  885. ret = wolfSSL_CTX_use_PrivateKey_file(ctx, “./server-key.pem”,
  886. SSL_FILETYPE_PEM);
  887. if (ret != SSL_SUCCESS) {
  888. // error loading key file
  889. }
  890. ...
  891. \endcode
  892. \sa wolfSSL_CTX_use_PrivateKey_buffer
  893. \sa wolfSSL_use_PrivateKey_file
  894. \sa wolfSSL_use_PrivateKey_buffer
  895. \sa wc_CryptoCb_RegisterDevice
  896. \sa wolfSSL_CTX_SetDevId
  897. */
  898. int wolfSSL_CTX_use_PrivateKey_file(WOLFSSL_CTX* ctx, const char* file, int format);
  899. /*!
  900. \ingroup CertsKeys
  901. \brief This function loads PEM-formatted CA certificate files into the SSL
  902. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  903. certificates and used to verify certs received from peers during the SSL
  904. handshake. The root certificate file, provided by the file argument, may
  905. be a single certificate or a file containing multiple certificates.
  906. If multiple CA certs are included in the same file, wolfSSL will load them
  907. in the same order they are presented in the file. The path argument is
  908. a pointer to the name of a directory that contains certificates of
  909. trusted root CAs. If the value of file is not NULL, path may be specified
  910. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  911. defined when building the library, wolfSSL will load all CA certificates
  912. located in the given directory. This function will attempt to load all
  913. files in the directory. This function expects PEM formatted CERT_TYPE
  914. file with header “-----BEGIN CERTIFICATE-----”.
  915. \return SSL_SUCCESS up success.
  916. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  917. path are NULL.
  918. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  919. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  920. read, or is corrupted.
  921. \return MEMORY_E will be returned if an out of memory condition occurs.
  922. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  923. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  924. before date.
  925. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  926. after date.
  927. \return BUFFER_E will be returned if a chain buffer is bigger than the
  928. receiving buffer.
  929. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  930. to open path.
  931. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  932. \param file pointer to name of the file containing PEM-formatted CA
  933. certificates.
  934. \param path pointer to the name of a directory to load PEM-formatted
  935. certificates from.
  936. _Example_
  937. \code
  938. int ret = 0;
  939. WOLFSSL_CTX* ctx;
  940. ...
  941. ret = wolfSSL_CTX_load_verify_locations(ctx, “./ca-cert.pem”, NULL);
  942. if (ret != WOLFSSL_SUCCESS) {
  943. // error loading CA certs
  944. }
  945. ...
  946. \endcode
  947. \sa wolfSSL_CTX_load_verify_locations_ex
  948. \sa wolfSSL_CTX_load_verify_buffer
  949. \sa wolfSSL_CTX_use_certificate_file
  950. \sa wolfSSL_CTX_use_PrivateKey_file
  951. \sa wolfSSL_CTX_use_certificate_chain_file
  952. \sa wolfSSL_use_certificate_file
  953. \sa wolfSSL_use_PrivateKey_file
  954. \sa wolfSSL_use_certificate_chain_file
  955. */
  956. int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
  957. const char* path);
  958. /*!
  959. \ingroup CertsKeys
  960. \brief This function loads PEM-formatted CA certificate files into the SSL
  961. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  962. certificates and used to verify certs received from peers during the SSL
  963. handshake. The root certificate file, provided by the file argument, may
  964. be a single certificate or a file containing multiple certificates.
  965. If multiple CA certs are included in the same file, wolfSSL will load them
  966. in the same order they are presented in the file. The path argument is
  967. a pointer to the name of a directory that contains certificates of
  968. trusted root CAs. If the value of file is not NULL, path may be specified
  969. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  970. defined when building the library, wolfSSL will load all CA certificates
  971. located in the given directory. This function will attempt to load all
  972. files in the directory based on flags specified. This function expects PEM
  973. formatted CERT_TYPE files with header “-----BEGIN CERTIFICATE-----”.
  974. \return SSL_SUCCESS up success.
  975. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  976. path are NULL. This will also be returned if at least one cert is loaded
  977. successfully but there is one or more that failed. Check error stack for reason.
  978. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  979. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  980. read, or is corrupted.
  981. \return MEMORY_E will be returned if an out of memory condition occurs.
  982. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  983. \return BUFFER_E will be returned if a chain buffer is bigger than the
  984. receiving buffer.
  985. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  986. to open path.
  987. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  988. \param file pointer to name of the file containing PEM-formatted CA
  989. certificates.
  990. \param path pointer to the name of a directory to load PEM-formatted
  991. certificates from.
  992. \param flags possible mask values are: WOLFSSL_LOAD_FLAG_IGNORE_ERR,
  993. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY and WOLFSSL_LOAD_FLAG_PEM_CA_ONLY
  994. _Example_
  995. \code
  996. int ret = 0;
  997. WOLFSSL_CTX* ctx;
  998. ...
  999. ret = wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, “./certs/external",
  1000. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY);
  1001. if (ret != WOLFSSL_SUCCESS) {
  1002. // error loading CA certs
  1003. }
  1004. ...
  1005. \endcode
  1006. \sa wolfSSL_CTX_load_verify_locations
  1007. \sa wolfSSL_CTX_load_verify_buffer
  1008. \sa wolfSSL_CTX_use_certificate_file
  1009. \sa wolfSSL_CTX_use_PrivateKey_file
  1010. \sa wolfSSL_CTX_use_certificate_chain_file
  1011. \sa wolfSSL_use_certificate_file
  1012. \sa wolfSSL_use_PrivateKey_file
  1013. \sa wolfSSL_use_certificate_chain_file
  1014. */
  1015. int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
  1016. const char* path, unsigned int flags);
  1017. /*!
  1018. \ingroup CertsKeys
  1019. \brief This function returns a pointer to an array of strings representing
  1020. directories wolfSSL will search for system CA certs when
  1021. wolfSSL_CTX_load_system_CA_certs is called. On systems that don't store
  1022. certificates in an accessible system directory (such as Apple platforms),
  1023. this function will always return NULL.
  1024. \return Valid pointer on success.
  1025. \return NULL pointer on failure.
  1026. \param num pointer to a word32 that will be populated with the length of the
  1027. array of strings.
  1028. _Example_
  1029. \code
  1030. WOLFSSL_CTX* ctx;
  1031. const char** dirs;
  1032. word32 numDirs;
  1033. dirs = wolfSSL_get_system_CA_dirs(&numDirs);
  1034. for (int i = 0; i < numDirs; ++i) {
  1035. printf("Potential system CA dir: %s\n", dirs[i]);
  1036. }
  1037. ...
  1038. \endcode
  1039. \sa wolfSSL_CTX_load_system_CA_certs
  1040. \sa wolfSSL_CTX_load_verify_locations
  1041. \sa wolfSSL_CTX_load_verify_locations_ex
  1042. */
  1043. const char** wolfSSL_get_system_CA_dirs(word32* num);
  1044. /*!
  1045. \ingroup CertsKeys
  1046. \brief On most platforms (including Linux and Windows), this function
  1047. attempts to load CA certificates into a WOLFSSL_CTX from an OS-dependent
  1048. CA certificate store. Loaded certificates will be trusted.
  1049. On Apple platforms (excluding macOS), certificates can't be obtained from
  1050. the system, and therefore cannot be loaded into the wolfSSL certificate
  1051. manager. For these platforms, this function enables TLS connections bound to
  1052. the WOLFSSL_CTX to use the native system trust APIs to verify authenticity
  1053. of the peer certificate chain if the authenticity of the peer cannot first
  1054. be authenticated against certificates loaded by the user.
  1055. The platforms supported and tested are: Linux (Debian, Ubuntu,
  1056. Gentoo, Fedora, RHEL), Windows 10/11, Android, macOS, and iOS.
  1057. \return WOLFSSL_SUCCESS on success.
  1058. \return WOLFSSL_BAD_PATH if no system CA certs were loaded.
  1059. \return WOLFSSL_FAILURE for other failure types (e.g. Windows cert store
  1060. wasn't properly closed).
  1061. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1062. _Example_
  1063. \code
  1064. int ret = 0;
  1065. WOLFSSL_CTX* ctx;
  1066. ...
  1067. ret = wolfSSL_CTX_load_system_CA_certs(ctx,);
  1068. if (ret != WOLFSSL_SUCCESS) {
  1069. // error loading system CA certs
  1070. }
  1071. ...
  1072. \endcode
  1073. \sa wolfSSL_get_system_CA_dirs
  1074. \sa wolfSSL_CTX_load_verify_locations
  1075. \sa wolfSSL_CTX_load_verify_locations_ex
  1076. */
  1077. int wolfSSL_CTX_load_system_CA_certs(WOLFSSL_CTX* ctx);
  1078. /*!
  1079. \ingroup Setup
  1080. \brief This function loads a certificate to use for verifying a peer
  1081. when performing a TLS/SSL handshake. The peer certificate sent during the
  1082. handshake is compared by using the SKID when available and the signature.
  1083. If these two things do not match then any loaded CAs are used. Feature is
  1084. enabled by defining the macro WOLFSSL_TRUST_PEER_CERT. Please see the
  1085. examples for proper usage.
  1086. \return SSL_SUCCES upon success.
  1087. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  1088. type are invalid.
  1089. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  1090. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  1091. read, or is corrupted.
  1092. \return MEMORY_E will be returned if an out of memory condition occurs.
  1093. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  1094. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1095. \param file pointer to name of the file containing certificates
  1096. \param type type of certificate being loaded ie SSL_FILETYPE_ASN1
  1097. or SSL_FILETYPE_PEM.
  1098. _Example_
  1099. \code
  1100. int ret = 0;
  1101. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1102. ...
  1103. ret = wolfSSL_CTX_trust_peer_cert(ctx, “./peer-cert.pem”,
  1104. SSL_FILETYPE_PEM);
  1105. if (ret != SSL_SUCCESS) {
  1106. // error loading trusted peer cert
  1107. }
  1108. ...
  1109. \endcode
  1110. \sa wolfSSL_CTX_load_verify_buffer
  1111. \sa wolfSSL_CTX_use_certificate_file
  1112. \sa wolfSSL_CTX_use_PrivateKey_file
  1113. \sa wolfSSL_CTX_use_certificate_chain_file
  1114. \sa wolfSSL_CTX_trust_peer_buffer
  1115. \sa wolfSSL_CTX_Unload_trust_peers
  1116. \sa wolfSSL_use_certificate_file
  1117. \sa wolfSSL_use_PrivateKey_file
  1118. \sa wolfSSL_use_certificate_chain_file
  1119. */
  1120. int wolfSSL_CTX_trust_peer_cert(WOLFSSL_CTX* ctx, const char* file, int type);
  1121. /*!
  1122. \ingroup CertsKeys
  1123. \brief This function loads a chain of certificates into the SSL
  1124. context (WOLFSSL_CTX). The file containing the certificate chain
  1125. is provided by the file argument, and must contain PEM-formatted
  1126. certificates. This function will process up to MAX_CHAIN_DEPTH
  1127. (default = 9, defined in internal.h) certificates, plus the subject cert.
  1128. \return SSL_SUCCESS upon success
  1129. \return SSL_FAILURE If the function call fails, possible causes might
  1130. include the file is in the wrong format, or the wrong format has been
  1131. given using the “format” argument, file doesn’t exist, can’t be read,
  1132. or is corrupted, an out of memory condition occurs.
  1133. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1134. wolfSSL_CTX_new()
  1135. \param file a pointer to the name of the file containing the chain of
  1136. certificates to be loaded into the wolfSSL SSL context. Certificates
  1137. must be in PEM format.
  1138. _Example_
  1139. \code
  1140. int ret = 0;
  1141. WOLFSSL_CTX* ctx;
  1142. ...
  1143. ret = wolfSSL_CTX_use_certificate_chain_file(ctx, “./cert-chain.pem”);
  1144. if (ret != SSL_SUCCESS) {
  1145. // error loading cert file
  1146. }
  1147. ...
  1148. \endcode
  1149. \sa wolfSSL_CTX_use_certificate_file
  1150. \sa wolfSSL_CTX_use_certificate_buffer
  1151. \sa wolfSSL_use_certificate_file
  1152. \sa wolfSSL_use_certificate_buffer
  1153. */
  1154. int wolfSSL_CTX_use_certificate_chain_file(WOLFSSL_CTX *ctx,
  1155. const char *file);
  1156. /*!
  1157. \ingroup openSSL
  1158. \brief This function loads the private RSA key used in the SSL connection
  1159. into the SSL context (WOLFSSL_CTX). This function is only available when
  1160. wolfSSL has been compiled with the OpenSSL compatibility layer enabled
  1161. (--enable-opensslExtra, #define OPENSSL_EXTRA), and is identical to the
  1162. more-typically used wolfSSL_CTX_use_PrivateKey_file() function. The file
  1163. argument contains a pointer to the RSA private key file, in the format
  1164. specified by format.
  1165. \return SSL_SUCCESS upon success.
  1166. \return SSL_FAILURE If the function call fails, possible causes might
  1167. include: The input key file is in the wrong format, or the wrong format
  1168. has been given using the “format” argument, file doesn’t exist, can’t
  1169. be read, or is corrupted, an out of memory condition occurs.
  1170. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1171. wolfSSL_CTX_new()
  1172. \param file a pointer to the name of the file containing the RSA private
  1173. key to be loaded into the wolfSSL SSL context, with format as specified
  1174. by format.
  1175. \param format the encoding type of the RSA private key specified by file.
  1176. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1177. _Example_
  1178. \code
  1179. int ret = 0;
  1180. WOLFSSL_CTX* ctx;
  1181. ...
  1182. ret = wolfSSL_CTX_use_RSAPrivateKey_file(ctx, “./server-key.pem”,
  1183. SSL_FILETYPE_PEM);
  1184. if (ret != SSL_SUCCESS) {
  1185. // error loading private key file
  1186. }
  1187. ...
  1188. \endcode
  1189. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1190. \sa wolfSSL_CTX_use_PrivateKey_file
  1191. \sa wolfSSL_use_RSAPrivateKey_file
  1192. \sa wolfSSL_use_PrivateKey_buffer
  1193. \sa wolfSSL_use_PrivateKey_file
  1194. */
  1195. int wolfSSL_CTX_use_RSAPrivateKey_file(WOLFSSL_CTX* ctx, const char* file, int format);
  1196. /*!
  1197. \ingroup IO
  1198. \brief This function returns the maximum chain depth allowed, which is 9 by
  1199. default, for a valid session i.e. there is a non-null session object (ssl).
  1200. \return MAX_CHAIN_DEPTH returned if the WOLFSSL structure is not
  1201. NULL. By default the value is 9.
  1202. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  1203. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1204. _Example_
  1205. \code
  1206. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1207. WOLFSSL* ssl = wolfSSL_new(ctx);
  1208. ...
  1209. long sslDep = wolfSSL_get_verify_depth(ssl);
  1210. if(sslDep > EXPECTED){
  1211. // The verified depth is greater than what was expected
  1212. } else {
  1213. // The verified depth is smaller or equal to the expected value
  1214. }
  1215. \endcode
  1216. \sa wolfSSL_CTX_get_verify_depth
  1217. */
  1218. long wolfSSL_get_verify_depth(WOLFSSL* ssl);
  1219. /*!
  1220. \ingroup Setup
  1221. \brief This function gets the certificate chaining depth using the
  1222. CTX structure.
  1223. \return MAX_CHAIN_DEPTH returned if the CTX struct is not NULL. The
  1224. constant representation of the max certificate chain peer depth.
  1225. \return BAD_FUNC_ARG returned if the CTX structure is NULL.
  1226. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1227. wolfSSL_CTX_new().
  1228. _Example_
  1229. \code
  1230. WOLFSSL_METHOD method; // protocol method
  1231. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  1232. long ret = wolfSSL_CTX_get_verify_depth(ctx);
  1233. if(ret == EXPECTED){
  1234. // You have the expected value
  1235. } else {
  1236. // Handle an unexpected depth
  1237. }
  1238. \endcode
  1239. \sa wolfSSL_CTX_use_certificate_chain_file
  1240. \sa wolfSSL_get_verify_depth
  1241. */
  1242. long wolfSSL_CTX_get_verify_depth(WOLFSSL_CTX* ctx);
  1243. /*!
  1244. \ingroup openSSL
  1245. \brief This function loads a certificate file into the SSL session
  1246. (WOLFSSL structure). The certificate file is provided by the file
  1247. argument. The format argument specifies the format type of the file -
  1248. either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1249. \return SSL_SUCCESS upon success
  1250. \return SSL_FAILURE If the function call fails, possible causes might
  1251. include: The file is in the wrong format, or the wrong format has been
  1252. given using the “format” argument, file doesn’t exist, can’t be read,
  1253. or is corrupted, an out of memory condition occurs, Base16 decoding
  1254. fails on the file
  1255. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1256. \param file a pointer to the name of the file containing the certificate to
  1257. be loaded into the wolfSSL SSL session, with format as specified by format.
  1258. \param format the encoding type of the certificate specified by file.
  1259. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1260. _Example_
  1261. \code
  1262. int ret = 0;
  1263. WOLFSSL* ssl;
  1264. ...
  1265. ret = wolfSSL_use_certificate_file(ssl, “./client-cert.pem”,
  1266. SSL_FILETYPE_PEM);
  1267. if (ret != SSL_SUCCESS) {
  1268. // error loading cert file
  1269. }
  1270. ...
  1271. \endcode
  1272. \sa wolfSSL_CTX_use_certificate_buffer
  1273. \sa wolfSSL_CTX_use_certificate_file
  1274. \sa wolfSSL_use_certificate_buffer
  1275. */
  1276. int wolfSSL_use_certificate_file(WOLFSSL* ssl, const char* file, int format);
  1277. /*!
  1278. \ingroup openSSL
  1279. \brief This function loads a private key file into the SSL session
  1280. (WOLFSSL structure). The key file is provided by the file argument.
  1281. The format argument specifies the format type of the file -
  1282. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1283. If using an external key store and do not have the private key you can
  1284. instead provide the public key and register the crypro callback to handle
  1285. the signing. For this you can build with either build with crypto callbacks
  1286. or PK callbacks. To enable crypto callbacks use --enable-cryptocb or
  1287. WOLF_CRYPTO_CB and register a crypto callback using
  1288. wc_CryptoCb_RegisterDevice and set the associated devId using
  1289. wolfSSL_SetDevId.
  1290. \return SSL_SUCCESS upon success.
  1291. \return SSL_FAILURE If the function call fails, possible causes might
  1292. include: The file is in the wrong format, or the wrong format has been
  1293. given using the “format” argument, The file doesn’t exist, can’t be read,
  1294. or is corrupted, An out of memory condition occurs, Base16 decoding
  1295. fails on the file, The key file is encrypted but no password is provided
  1296. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1297. \param file a pointer to the name of the file containing the key file to
  1298. be loaded into the wolfSSL SSL session, with format as specified by format.
  1299. \param format the encoding type of the key specified by file. Possible
  1300. values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1301. _Example_
  1302. \code
  1303. int ret = 0;
  1304. WOLFSSL* ssl;
  1305. ...
  1306. ret = wolfSSL_use_PrivateKey_file(ssl, “./server-key.pem”,
  1307. SSL_FILETYPE_PEM);
  1308. if (ret != SSL_SUCCESS) {
  1309. // error loading key file
  1310. }
  1311. ...
  1312. \endcode
  1313. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1314. \sa wolfSSL_CTX_use_PrivateKey_file
  1315. \sa wolfSSL_use_PrivateKey_buffer
  1316. \sa wc_CryptoCb_RegisterDevice
  1317. \sa wolfSSL_SetDevId
  1318. */
  1319. int wolfSSL_use_PrivateKey_file(WOLFSSL* ssl, const char* file, int format);
  1320. /*!
  1321. \ingroup openSSL
  1322. \brief This function loads a chain of certificates into the SSL
  1323. session (WOLFSSL structure). The file containing the certificate
  1324. chain is provided by the file argument, and must contain PEM-formatted
  1325. certificates. This function will process up to MAX_CHAIN_DEPTH
  1326. (default = 9, defined in internal.h) certificates, plus the
  1327. subject certificate.
  1328. \return SSL_SUCCESS upon success.
  1329. \return SSL_FAILURE If the function call fails, possible causes
  1330. might include: The file is in the wrong format, or the wrong format
  1331. has been given using the “format” argument, file doesn’t exist,
  1332. can’t be read, or is corrupted, an out of memory condition occurs
  1333. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1334. \param file a pointer to the name of the file containing the chain
  1335. of certificates to be loaded into the wolfSSL SSL session.
  1336. Certificates must be in PEM format.
  1337. _Example_
  1338. \code
  1339. int ret = 0;
  1340. WOLFSSL* ctx;
  1341. ...
  1342. ret = wolfSSL_use_certificate_chain_file(ssl, “./cert-chain.pem”);
  1343. if (ret != SSL_SUCCESS) {
  1344. // error loading cert file
  1345. }
  1346. ...
  1347. \endcode
  1348. \sa wolfSSL_CTX_use_certificate_chain_file
  1349. \sa wolfSSL_CTX_use_certificate_chain_buffer
  1350. \sa wolfSSL_use_certificate_chain_buffer
  1351. */
  1352. int wolfSSL_use_certificate_chain_file(WOLFSSL* ssl, const char *file);
  1353. /*!
  1354. \ingroup openSSL
  1355. \brief This function loads the private RSA key used in the SSL
  1356. connection into the SSL session (WOLFSSL structure). This
  1357. function is only available when wolfSSL has been compiled with
  1358. the OpenSSL compatibility layer enabled (--enable-opensslExtra,
  1359. #define OPENSSL_EXTRA), and is identical to the more-typically
  1360. used wolfSSL_use_PrivateKey_file() function. The file argument
  1361. contains a pointer to the RSA private key file, in the format
  1362. specified by format.
  1363. \return SSL_SUCCESS upon success
  1364. \return SSL_FAILURE If the function call fails, possible causes might
  1365. include: The input key file is in the wrong format, or the wrong format
  1366. has been given using the “format” argument, file doesn’t exist, can’t
  1367. be read, or is corrupted, an out of memory condition occurs
  1368. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1369. \param file a pointer to the name of the file containing the RSA private
  1370. key to be loaded into the wolfSSL SSL session, with format as specified
  1371. by format.
  1372. \param format the encoding type of the RSA private key specified by file.
  1373. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1374. _Example_
  1375. \code
  1376. int ret = 0;
  1377. WOLFSSL* ssl;
  1378. ...
  1379. ret = wolfSSL_use_RSAPrivateKey_file(ssl, “./server-key.pem”,
  1380. SSL_FILETYPE_PEM);
  1381. if (ret != SSL_SUCCESS) {
  1382. // error loading private key file
  1383. }
  1384. ...
  1385. \endcode
  1386. \sa wolfSSL_CTX_use_RSAPrivateKey_file
  1387. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1388. \sa wolfSSL_CTX_use_PrivateKey_file
  1389. \sa wolfSSL_use_PrivateKey_buffer
  1390. \sa wolfSSL_use_PrivateKey_file
  1391. */
  1392. int wolfSSL_use_RSAPrivateKey_file(WOLFSSL* ssl, const char* file, int format);
  1393. /*!
  1394. \ingroup CertsKeys
  1395. \brief This function is similar to wolfSSL_CTX_load_verify_locations,
  1396. but allows the loading of DER-formatted CA files into the SSL context
  1397. (WOLFSSL_CTX). It may still be used to load PEM-formatted CA files as
  1398. well. These certificates will be treated as trusted root certificates
  1399. and used to verify certs received from peers during the SSL handshake.
  1400. The root certificate file, provided by the file argument, may be a single
  1401. certificate or a file containing multiple certificates. If multiple CA
  1402. certs are included in the same file, wolfSSL will load them in the same
  1403. order they are presented in the file. The format argument specifies the
  1404. format which the certificates are in either, SSL_FILETYPE_PEM or
  1405. SSL_FILETYPE_ASN1 (DER). Unlike wolfSSL_CTX_load_verify_locations,
  1406. this function does not allow the loading of CA certificates from a given
  1407. directory path. Note that this function is only available when the wolfSSL
  1408. library was compiled with WOLFSSL_DER_LOAD defined.
  1409. \return SSL_SUCCESS upon success.
  1410. \return SSL_FAILURE upon failure.
  1411. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1412. wolfSSL_CTX_new()
  1413. \param file a pointer to the name of the file containing the CA
  1414. certificates to be loaded into the wolfSSL SSL context, with format
  1415. as specified by format.
  1416. \param format the encoding type of the certificates specified by file.
  1417. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1418. _Example_
  1419. \code
  1420. int ret = 0;
  1421. WOLFSSL_CTX* ctx;
  1422. ...
  1423. ret = wolfSSL_CTX_der_load_verify_locations(ctx, “./ca-cert.der”,
  1424. SSL_FILETYPE_ASN1);
  1425. if (ret != SSL_SUCCESS) {
  1426. // error loading CA certs
  1427. }
  1428. ...
  1429. \endcode
  1430. \sa wolfSSL_CTX_load_verify_locations
  1431. \sa wolfSSL_CTX_load_verify_buffer
  1432. */
  1433. int wolfSSL_CTX_der_load_verify_locations(WOLFSSL_CTX* ctx,
  1434. const char* file, int format);
  1435. /*!
  1436. \ingroup Setup
  1437. \brief This function creates a new SSL context, taking a desired
  1438. SSL/TLS protocol method for input.
  1439. \return pointer If successful the call will return a pointer to the
  1440. newly-created WOLFSSL_CTX.
  1441. \return NULL upon failure.
  1442. \param method pointer to the desired WOLFSSL_METHOD to use for the SSL
  1443. context. This is created using one of the wolfSSLvXX_XXXX_method()
  1444. functions to specify SSL/TLS/DTLS protocol level.
  1445. _Example_
  1446. \code
  1447. WOLFSSL_CTX* ctx = 0;
  1448. WOLFSSL_METHOD* method = 0;
  1449. method = wolfSSLv3_client_method();
  1450. if (method == NULL) {
  1451. // unable to get method
  1452. }
  1453. ctx = wolfSSL_CTX_new(method);
  1454. if (ctx == NULL) {
  1455. // context creation failed
  1456. }
  1457. \endcode
  1458. \sa wolfSSL_new
  1459. */
  1460. WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*);
  1461. /*!
  1462. \ingroup Setup
  1463. \brief This function creates a new SSL session, taking an already
  1464. created SSL context as input.
  1465. \return * If successful the call will return a pointer to the
  1466. newly-created wolfSSL structure.
  1467. \return NULL Upon failure.
  1468. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1469. _Example_
  1470. \code
  1471. #include <wolfssl/ssl.h>
  1472. WOLFSSL* ssl = NULL;
  1473. WOLFSSL_CTX* ctx = 0;
  1474. ctx = wolfSSL_CTX_new(method);
  1475. if (ctx == NULL) {
  1476. // context creation failed
  1477. }
  1478. ssl = wolfSSL_new(ctx);
  1479. if (ssl == NULL) {
  1480. // SSL object creation failed
  1481. }
  1482. \endcode
  1483. \sa wolfSSL_CTX_new
  1484. */
  1485. WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
  1486. /*!
  1487. \ingroup Setup
  1488. \brief This function assigns a file descriptor (fd) as the
  1489. input/output facility for the SSL connection. Typically this will be
  1490. a socket file descriptor.
  1491. \return SSL_SUCCESS upon success.
  1492. \return BAD_FUNC_ARG upon failure.
  1493. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1494. \param fd file descriptor to use with SSL/TLS connection.
  1495. _Example_
  1496. \code
  1497. int sockfd;
  1498. WOLFSSL* ssl = 0;
  1499. ...
  1500. ret = wolfSSL_set_fd(ssl, sockfd);
  1501. if (ret != SSL_SUCCESS) {
  1502. // failed to set SSL file descriptor
  1503. }
  1504. \endcode
  1505. \sa wolfSSL_CTX_SetIOSend
  1506. \sa wolfSSL_CTX_SetIORecv
  1507. \sa wolfSSL_SetIOReadCtx
  1508. \sa wolfSSL_SetIOWriteCtx
  1509. */
  1510. int wolfSSL_set_fd(WOLFSSL* ssl, int fd);
  1511. /*!
  1512. \ingroup Setup
  1513. \brief This function assigns a file descriptor (fd) as the
  1514. input/output facility for the SSL connection. Typically this will be
  1515. a socket file descriptor. This is a DTLS specific API because it marks that
  1516. the socket is connected. recvfrom and sendto calls on this fd will have the
  1517. addr and addr_len parameters set to NULL.
  1518. \return SSL_SUCCESS upon success.
  1519. \return BAD_FUNC_ARG upon failure.
  1520. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1521. \param fd file descriptor to use with SSL/TLS connection.
  1522. _Example_
  1523. \code
  1524. int sockfd;
  1525. WOLFSSL* ssl = 0;
  1526. ...
  1527. if (connect(sockfd, peer_addr, peer_addr_len) != 0) {
  1528. // handle connect error
  1529. }
  1530. ...
  1531. ret = wolfSSL_set_dtls_fd_connected(ssl, sockfd);
  1532. if (ret != SSL_SUCCESS) {
  1533. // failed to set SSL file descriptor
  1534. }
  1535. \endcode
  1536. \sa wolfSSL_CTX_SetIOSend
  1537. \sa wolfSSL_CTX_SetIORecv
  1538. \sa wolfSSL_SetIOReadCtx
  1539. \sa wolfSSL_SetIOWriteCtx
  1540. \sa wolfDTLS_SetChGoodCb
  1541. */
  1542. int wolfSSL_set_dtls_fd_connected(WOLFSSL* ssl, int fd);
  1543. /*!
  1544. \ingroup Setup
  1545. \brief Allows setting a callback for a correctly processed and verified DTLS
  1546. client hello. When using a cookie exchange mechanism (either the
  1547. HelloVerifyRequest in DTLS 1.2 or the HelloRetryRequest with a cookie
  1548. extension in DTLS 1.3) this callback is called after the cookie
  1549. exchange has succeeded. This is useful to use one WOLFSSL object as
  1550. the listener for new connections and being able to isolate the
  1551. WOLFSSL object once the ClientHello is verified (either through a
  1552. cookie exchange or just checking if the ClientHello had the correct
  1553. format).
  1554. DTLS 1.2:
  1555. https://datatracker.ietf.org/doc/html/rfc6347#section-4.2.1
  1556. DTLS 1.3:
  1557. https://www.rfc-editor.org/rfc/rfc8446#section-4.2.2
  1558. \return SSL_SUCCESS upon success.
  1559. \return BAD_FUNC_ARG upon failure.
  1560. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1561. \param fd file descriptor to use with SSL/TLS connection.
  1562. _Example_
  1563. \code
  1564. // Called when we have verified a connection
  1565. static int chGoodCb(WOLFSSL* ssl, void* arg)
  1566. {
  1567. // setup peer and file descriptors
  1568. }
  1569. if (wolfDTLS_SetChGoodCb(ssl, chGoodCb, NULL) != WOLFSSL_SUCCESS) {
  1570. // error setting callback
  1571. }
  1572. \endcode
  1573. \sa wolfSSL_set_dtls_fd_connected
  1574. */
  1575. int wolfDTLS_SetChGoodCb(WOLFSSL* ssl, ClientHelloGoodCb cb, void* user_ctx);
  1576. /*!
  1577. \ingroup IO
  1578. \brief Get the name of cipher at priority level passed in.
  1579. \return string Success
  1580. \return 0 Priority is either out of bounds or not valid.
  1581. \param priority Integer representing the priority level of a cipher.
  1582. _Example_
  1583. \code
  1584. printf("The cipher at 1 is %s", wolfSSL_get_cipher_list(1));
  1585. \endcode
  1586. \sa wolfSSL_CIPHER_get_name
  1587. \sa wolfSSL_get_current_cipher
  1588. */
  1589. char* wolfSSL_get_cipher_list(int priority);
  1590. /*!
  1591. \ingroup IO
  1592. \brief This function gets the ciphers enabled in wolfSSL.
  1593. \return SSL_SUCCESS returned if the function executed without error.
  1594. \return BAD_FUNC_ARG returned if the buf parameter was NULL or if the
  1595. len argument was less than or equal to zero.
  1596. \return BUFFER_E returned if the buffer is not large enough and
  1597. will overflow.
  1598. \param buf a char pointer representing the buffer.
  1599. \param len the length of the buffer.
  1600. _Example_
  1601. \code
  1602. static void ShowCiphers(void){
  1603. char* ciphers;
  1604. int ret = wolfSSL_get_ciphers(ciphers, (int)sizeof(ciphers));
  1605. if(ret == SSL_SUCCES){
  1606. printf(“%s\n”, ciphers);
  1607. }
  1608. }
  1609. \endcode
  1610. \sa GetCipherNames
  1611. \sa wolfSSL_get_cipher_list
  1612. \sa ShowCiphers
  1613. */
  1614. int wolfSSL_get_ciphers(char* buf, int len);
  1615. /*!
  1616. \ingroup IO
  1617. \brief This function gets the cipher name in the format DHE-RSA by
  1618. passing through argument to wolfSSL_get_cipher_name_internal.
  1619. \return string This function returns the string representation of the
  1620. cipher suite that was matched.
  1621. \return NULL error or cipher not found.
  1622. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1623. _Example_
  1624. \code
  1625. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1626. WOLFSSL* ssl = wolfSSL_new(ctx);
  1627. char* cipherS = wolfSSL_get_cipher_name(ssl);
  1628. if(cipher == NULL){
  1629. // There was not a cipher suite matched
  1630. } else {
  1631. // There was a cipher suite matched
  1632. printf(“%s\n”, cipherS);
  1633. }
  1634. \endcode
  1635. \sa wolfSSL_CIPHER_get_name
  1636. \sa wolfSSL_get_current_cipher
  1637. \sa wolfSSL_get_cipher_name_internal
  1638. */
  1639. const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);
  1640. /*!
  1641. \ingroup IO
  1642. \brief This function returns the file descriptor (fd) used as the
  1643. input/output facility for the SSL connection. Typically this
  1644. will be a socket file descriptor.
  1645. \return fd If successful the call will return the SSL session file
  1646. descriptor.
  1647. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1648. _Example_
  1649. \code
  1650. int sockfd;
  1651. WOLFSSL* ssl = 0;
  1652. ...
  1653. sockfd = wolfSSL_get_fd(ssl);
  1654. ...
  1655. \endcode
  1656. \sa wolfSSL_set_fd
  1657. */
  1658. int wolfSSL_get_fd(const WOLFSSL*);
  1659. /*!
  1660. \ingroup Setup
  1661. \brief This function informs the WOLFSSL object that the underlying
  1662. I/O is non-blocking. After an application creates a WOLFSSL object,
  1663. if it will be used with a non-blocking socket, call
  1664. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1665. that receiving EWOULDBLOCK means that the recvfrom call would
  1666. block rather than that it timed out.
  1667. \return none No return.
  1668. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1669. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  1670. Use 1 to specify non-blocking, otherwise 0.
  1671. _Example_
  1672. \code
  1673. WOLFSSL* ssl = 0;
  1674. ...
  1675. wolfSSL_set_using_nonblock(ssl, 1);
  1676. \endcode
  1677. \sa wolfSSL_get_using_nonblock
  1678. \sa wolfSSL_dtls_got_timeout
  1679. \sa wolfSSL_dtls_get_current_timeout
  1680. */
  1681. void wolfSSL_set_using_nonblock(WOLFSSL* ssl, int nonblock);
  1682. /*!
  1683. \ingroup IO
  1684. \brief This function allows the application to determine if wolfSSL is
  1685. using non-blocking I/O. If wolfSSL is using non-blocking I/O, this
  1686. function will return 1, otherwise 0. After an application creates a
  1687. WOLFSSL object, if it will be used with a non-blocking socket, call
  1688. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1689. that receiving EWOULDBLOCK means that the recvfrom call would block
  1690. rather than that it timed out.
  1691. \return 0 underlying I/O is blocking.
  1692. \return 1 underlying I/O is non-blocking.
  1693. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1694. _Example_
  1695. \code
  1696. int ret = 0;
  1697. WOLFSSL* ssl = 0;
  1698. ...
  1699. ret = wolfSSL_get_using_nonblock(ssl);
  1700. if (ret == 1) {
  1701. // underlying I/O is non-blocking
  1702. }
  1703. ...
  1704. \endcode
  1705. \sa wolfSSL_set_session
  1706. */
  1707. int wolfSSL_get_using_nonblock(WOLFSSL*);
  1708. /*!
  1709. \ingroup IO
  1710. \brief This function writes sz bytes from the buffer, data, to the SSL
  1711. connection, ssl. If necessary, wolfSSL_write() will negotiate an SSL/TLS
  1712. session if the handshake has not already been performed yet by
  1713. wolfSSL_connect() or wolfSSL_accept(). When using (D)TLSv1.3 and early data
  1714. feature is compiled in, this function progresses the handshake only up to
  1715. the point when it is possible to send data. Next invocations of
  1716. wolfSSL_Connect()/wolfSSL_Accept()/wolfSSL_read() will complete the
  1717. handshake. wolfSSL_write() works with both blocking and non-blocking I/O.
  1718. When the underlying I/O is non-blocking, wolfSSL_write() will return when
  1719. the underlying I/O could not satisfy the needs of wolfSSL_write() to
  1720. continue. In this case, a call to wolfSSL_get_error() will yield either
  1721. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then
  1722. repeat the call to wolfSSL_write() when the underlying I/O is ready. If the
  1723. underlying I/O is blocking, wolfSSL_write() will only return once the buffer
  1724. data of size sz has been completely written or an error occurred.
  1725. \return >0 the number of bytes written upon success.
  1726. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1727. the specific error code.
  1728. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1729. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1730. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1731. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  1732. error code.
  1733. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1734. \param data data buffer which will be sent to peer.
  1735. \param sz size, in bytes, of data to send to the peer (data).
  1736. _Example_
  1737. \code
  1738. WOLFSSL* ssl = 0;
  1739. char msg[64] = “hello wolfssl!”;
  1740. int msgSz = (int)strlen(msg);
  1741. int flags;
  1742. int ret;
  1743. ...
  1744. ret = wolfSSL_write(ssl, msg, msgSz);
  1745. if (ret <= 0) {
  1746. // wolfSSL_write() failed, call wolfSSL_get_error()
  1747. }
  1748. \endcode
  1749. \sa wolfSSL_send
  1750. \sa wolfSSL_read
  1751. \sa wolfSSL_recv
  1752. */
  1753. int wolfSSL_write(WOLFSSL* ssl, const void* data, int sz);
  1754. /*!
  1755. \ingroup IO
  1756. \brief This function reads sz bytes from the SSL session (ssl)
  1757. internal read buffer into the buffer data. The bytes read are removed
  1758. from the internal receive buffer. If necessary wolfSSL_read() will
  1759. negotiate an SSL/TLS session if the handshake has not already been
  1760. performed yet by wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS
  1761. protocol uses SSL records which have a maximum size of 16kB (the max
  1762. record size can be controlled by the MAX_RECORD_SIZE define in
  1763. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1764. entire SSL record internally before it is able to process and decrypt the
  1765. record. Because of this, a call to wolfSSL_read() will only be able to
  1766. return the maximum buffer size which has been decrypted at the time of
  1767. calling. There may be additional not-yet-decrypted data waiting in the
  1768. internal wolfSSL receive buffer which will be retrieved and decrypted with
  1769. the next call to wolfSSL_read(). If sz is larger than the number of bytes
  1770. in the internal read buffer, SSL_read() will return the bytes available in
  1771. the internal read buffer. If no bytes are buffered in the internal read
  1772. buffer yet, a call to wolfSSL_read() will trigger processing of the next
  1773. record.
  1774. \return >0 the number of bytes read upon success.
  1775. \return 0 will be returned upon failure. This may be caused by a either a
  1776. clean (close notify alert) shutdown or just that the peer closed the
  1777. connection. Call wolfSSL_get_error() for the specific error code.
  1778. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1779. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1780. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1781. call wolfSSL_read() again. Use wolfSSL_get_error() to get a specific
  1782. error code.
  1783. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1784. \param data buffer where wolfSSL_read() will place data read.
  1785. \param sz number of bytes to read into data.
  1786. _Example_
  1787. \code
  1788. WOLFSSL* ssl = 0;
  1789. char reply[1024];
  1790. ...
  1791. input = wolfSSL_read(ssl, reply, sizeof(reply));
  1792. if (input > 0) {
  1793. // “input” number of bytes returned into buffer “reply”
  1794. }
  1795. See wolfSSL examples (client, server, echoclient, echoserver) for more
  1796. complete examples of wolfSSL_read().
  1797. \endcode
  1798. \sa wolfSSL_recv
  1799. \sa wolfSSL_write
  1800. \sa wolfSSL_peek
  1801. \sa wolfSSL_pending
  1802. */
  1803. int wolfSSL_read(WOLFSSL* ssl, void* data, int sz);
  1804. /*!
  1805. \ingroup IO
  1806. \brief This function copies sz bytes from the SSL session (ssl) internal
  1807. read buffer into the buffer data. This function is identical to
  1808. wolfSSL_read() except that the data in the internal SSL session
  1809. receive buffer is not removed or modified. If necessary, like
  1810. wolfSSL_read(), wolfSSL_peek() will negotiate an SSL/TLS session if
  1811. the handshake has not already been performed yet by wolfSSL_connect()
  1812. or wolfSSL_accept(). The SSL/TLS protocol uses SSL records which have a
  1813. maximum size of 16kB (the max record size can be controlled by the
  1814. MAX_RECORD_SIZE define in <wolfssl_root>/wolfssl/internal.h). As such,
  1815. wolfSSL needs to read an entire SSL record internally before it is able
  1816. to process and decrypt the record. Because of this, a call to
  1817. wolfSSL_peek() will only be able to return the maximum buffer size which
  1818. has been decrypted at the time of calling. There may be additional
  1819. not-yet-decrypted data waiting in the internal wolfSSL receive buffer
  1820. which will be retrieved and decrypted with the next call to
  1821. wolfSSL_peek() / wolfSSL_read(). If sz is larger than the number of bytes
  1822. in the internal read buffer, SSL_peek() will return the bytes available
  1823. in the internal read buffer. If no bytes are buffered in the internal
  1824. read buffer yet, a call to wolfSSL_peek() will trigger processing of the
  1825. next record.
  1826. \return >0 the number of bytes read upon success.
  1827. \return 0 will be returned upon failure. This may be caused by a either
  1828. a clean (close notify alert) shutdown or just that the peer closed the
  1829. connection. Call wolfSSL_get_error() for the specific error code.
  1830. \return SSL_FATAL_ERROR will be returned upon failure when either an
  1831. error occurred or, when using non-blocking sockets, the
  1832. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and and
  1833. the application needs to call wolfSSL_peek() again. Use
  1834. wolfSSL_get_error() to get a specific error code.
  1835. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1836. \param data buffer where wolfSSL_peek() will place data read.
  1837. \param sz number of bytes to read into data.
  1838. _Example_
  1839. \code
  1840. WOLFSSL* ssl = 0;
  1841. char reply[1024];
  1842. ...
  1843. input = wolfSSL_peek(ssl, reply, sizeof(reply));
  1844. if (input > 0) {
  1845. // “input” number of bytes returned into buffer “reply”
  1846. }
  1847. \endcode
  1848. \sa wolfSSL_read
  1849. */
  1850. int wolfSSL_peek(WOLFSSL* ssl, void* data, int sz);
  1851. /*!
  1852. \ingroup IO
  1853. \brief This function is called on the server side and waits for an SSL
  1854. client to initiate the SSL/TLS handshake. When this function is called,
  1855. the underlying communication channel has already been set up.
  1856. wolfSSL_accept() works with both blocking and non-blocking I/O.
  1857. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  1858. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  1859. to continue the handshake. In this case, a call to wolfSSL_get_error()
  1860. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1861. The calling process must then repeat the call to wolfSSL_accept when
  1862. data is available to read and wolfSSL will pick up where it left off.
  1863. When using a non-blocking socket, nothing needs to be done, but select()
  1864. can be used to check for the required condition. If the underlying I/O
  1865. is blocking, wolfSSL_accept() will only return once the handshake has
  1866. been finished or an error occurred.
  1867. \return SSL_SUCCESS upon success.
  1868. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  1869. more detailed error code, call wolfSSL_get_error().
  1870. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1871. _Example_
  1872. \code
  1873. int ret = 0;
  1874. int err = 0;
  1875. WOLFSSL* ssl;
  1876. char buffer[80];
  1877. ...
  1878. ret = wolfSSL_accept(ssl);
  1879. if (ret != SSL_SUCCESS) {
  1880. err = wolfSSL_get_error(ssl, ret);
  1881. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  1882. }
  1883. \endcode
  1884. \sa wolfSSL_get_error
  1885. \sa wolfSSL_connect
  1886. */
  1887. int wolfSSL_accept(WOLFSSL*);
  1888. /*!
  1889. \ingroup Setup
  1890. \brief This function frees an allocated WOLFSSL_CTX object. This
  1891. function decrements the CTX reference count and only frees the context
  1892. when the reference count has reached 0.
  1893. \return none No return.
  1894. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1895. _Example_
  1896. \code
  1897. WOLFSSL_CTX* ctx = 0;
  1898. ...
  1899. wolfSSL_CTX_free(ctx);
  1900. \endcode
  1901. \sa wolfSSL_CTX_new
  1902. \sa wolfSSL_new
  1903. \sa wolfSSL_free
  1904. */
  1905. void wolfSSL_CTX_free(WOLFSSL_CTX*);
  1906. /*!
  1907. \ingroup Setup
  1908. \brief This function frees an allocated wolfSSL object.
  1909. \return none No return.
  1910. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1911. _Example_
  1912. \code
  1913. #include <wolfssl/ssl.h>
  1914. WOLFSSL* ssl = 0;
  1915. ...
  1916. wolfSSL_free(ssl);
  1917. \endcode
  1918. \sa wolfSSL_CTX_new
  1919. \sa wolfSSL_new
  1920. \sa wolfSSL_CTX_free
  1921. */
  1922. void wolfSSL_free(WOLFSSL*);
  1923. /*!
  1924. \ingroup TLS
  1925. \brief This function shuts down an active SSL/TLS connection using
  1926. the SSL session, ssl. This function will try to send a “close notify”
  1927. alert to the peer. The calling application can choose to wait for the
  1928. peer to send its “close notify” alert in response or just go ahead
  1929. and shut down the underlying connection after directly calling
  1930. wolfSSL_shutdown (to save resources). Either option is allowed by
  1931. the TLS specification. If the underlying connection will be used
  1932. again in the future, the complete two-directional shutdown procedure
  1933. must be performed to keep synchronization intact between the peers.
  1934. wolfSSL_shutdown() works with both blocking and non-blocking I/O.
  1935. When the underlying I/O is non-blocking, wolfSSL_shutdown() will
  1936. return an error if the underlying I/O could not satisfy the needs of
  1937. wolfSSL_shutdown() to continue. In this case, a call to
  1938. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1939. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call
  1940. to wolfSSL_shutdown() when the underlying I/O is ready.
  1941. \return SSL_SUCCESS will be returned upon success.
  1942. \return SSL_SHUTDOWN_NOT_DONE will be returned when shutdown has not
  1943. finished, and the function should be called again.
  1944. \return SSL_FATAL_ERROR will be returned upon failure. Call
  1945. wolfSSL_get_error() for a more specific error code.
  1946. \param ssl pointer to the SSL session created with wolfSSL_new().
  1947. _Example_
  1948. \code
  1949. #include <wolfssl/ssl.h>
  1950. int ret = 0;
  1951. WOLFSSL* ssl = 0;
  1952. ...
  1953. ret = wolfSSL_shutdown(ssl);
  1954. if (ret != 0) {
  1955. // failed to shut down SSL connection
  1956. }
  1957. \endcode
  1958. \sa wolfSSL_free
  1959. \sa wolfSSL_CTX_free
  1960. */
  1961. int wolfSSL_shutdown(WOLFSSL*);
  1962. /*!
  1963. \ingroup IO
  1964. \brief This function writes sz bytes from the buffer, data, to the SSL
  1965. connection, ssl, using the specified flags for the underlying write
  1966. operation. If necessary wolfSSL_send() will negotiate an SSL/TLS session
  1967. if the handshake has not already been performed yet by wolfSSL_connect()
  1968. or wolfSSL_accept(). wolfSSL_send() works with both blocking and
  1969. non-blocking I/O. When the underlying I/O is non-blocking, wolfSSL_send()
  1970. will return when the underlying I/O could not satisfy the needs of
  1971. wolfSSL_send to continue. In this case, a call to wolfSSL_get_error()
  1972. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1973. The calling process must then repeat the call to wolfSSL_send() when
  1974. the underlying I/O is ready. If the underlying I/O is blocking,
  1975. wolfSSL_send() will only return once the buffer data of size sz has
  1976. been completely written or an error occurred.
  1977. \return >0 the number of bytes written upon success.
  1978. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1979. the specific error code.
  1980. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1981. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1982. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1983. call wolfSSL_send() again. Use wolfSSL_get_error() to get a specific
  1984. error code.
  1985. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1986. \param data data buffer to send to peer.
  1987. \param sz size, in bytes, of data to be sent to peer.
  1988. \param flags the send flags to use for the underlying send operation.
  1989. _Example_
  1990. \code
  1991. WOLFSSL* ssl = 0;
  1992. char msg[64] = “hello wolfssl!”;
  1993. int msgSz = (int)strlen(msg);
  1994. int flags = ... ;
  1995. ...
  1996. input = wolfSSL_send(ssl, msg, msgSz, flags);
  1997. if (input != msgSz) {
  1998. // wolfSSL_send() failed
  1999. }
  2000. \endcode
  2001. \sa wolfSSL_write
  2002. \sa wolfSSL_read
  2003. \sa wolfSSL_recv
  2004. */
  2005. int wolfSSL_send(WOLFSSL* ssl, const void* data, int sz, int flags);
  2006. /*!
  2007. \ingroup IO
  2008. \brief This function reads sz bytes from the SSL session (ssl) internal
  2009. read buffer into the buffer data using the specified flags for the
  2010. underlying recv operation. The bytes read are removed from the internal
  2011. receive buffer. This function is identical to wolfSSL_read() except
  2012. that it allows the application to set the recv flags for the underlying
  2013. read operation. If necessary wolfSSL_recv() will negotiate an SSL/TLS
  2014. session if the handshake has not already been performed yet by
  2015. wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS protocol uses
  2016. SSL records which have a maximum size of 16kB (the max record size
  2017. can be controlled by the MAX_RECORD_SIZE define in
  2018. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  2019. entire SSL record internally before it is able to process and decrypt
  2020. the record. Because of this, a call to wolfSSL_recv() will only be
  2021. able to return the maximum buffer size which has been decrypted at
  2022. the time of calling. There may be additional not-yet-decrypted data
  2023. waiting in the internal wolfSSL receive buffer which will be
  2024. retrieved and decrypted with the next call to wolfSSL_recv(). If sz
  2025. is larger than the number of bytes in the internal read buffer,
  2026. SSL_recv() will return the bytes available in the internal read buffer.
  2027. If no bytes are buffered in the internal read buffer yet, a call to
  2028. wolfSSL_recv() will trigger processing of the next record.
  2029. \return >0 the number of bytes read upon success.
  2030. \return 0 will be returned upon failure. This may be caused by a either
  2031. a clean (close notify alert) shutdown or just that the peer closed the
  2032. connection. Call wolfSSL_get_error() for the specific error code.
  2033. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  2034. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  2035. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  2036. call wolfSSL_recv() again. Use wolfSSL_get_error() to get a specific
  2037. error code.
  2038. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2039. \param data buffer where wolfSSL_recv() will place data read.
  2040. \param sz number of bytes to read into data.
  2041. \param flags the recv flags to use for the underlying recv operation.
  2042. _Example_
  2043. \code
  2044. WOLFSSL* ssl = 0;
  2045. char reply[1024];
  2046. int flags = ... ;
  2047. ...
  2048. input = wolfSSL_recv(ssl, reply, sizeof(reply), flags);
  2049. if (input > 0) {
  2050. // “input” number of bytes returned into buffer “reply”
  2051. }
  2052. \endcode
  2053. \sa wolfSSL_read
  2054. \sa wolfSSL_write
  2055. \sa wolfSSL_peek
  2056. \sa wolfSSL_pending
  2057. */
  2058. int wolfSSL_recv(WOLFSSL* ssl, void* data, int sz, int flags);
  2059. /*!
  2060. \ingroup Debug
  2061. \brief This function returns a unique error code describing why the
  2062. previous API function call (wolfSSL_connect, wolfSSL_accept, wolfSSL_read,
  2063. wolfSSL_write, etc.) resulted in an error return code (SSL_FAILURE).
  2064. The return value of the previous function is passed to wolfSSL_get_error
  2065. through ret. After wolfSSL_get_error is called and returns the unique
  2066. error code, wolfSSL_ERR_error_string() may be called to get a
  2067. human-readable error string. See wolfSSL_ERR_error_string() for more
  2068. information.
  2069. \return On successful completion, this function will return the
  2070. unique error code describing why the previous API function failed.
  2071. \return SSL_ERROR_NONE will be returned if ret > 0. For ret <= 0, there are
  2072. some cases when this value can also be returned when a previous API appeared
  2073. to return an error code but no error actually occurred. An example is
  2074. calling wolfSSL_read() with a zero sz parameter. A 0 return from
  2075. wolfSSL_read() usually indicates an error but in this case no error
  2076. occurred. If wolfSSL_get_error() is called afterwards, SSL_ERROR_NONE will
  2077. be returned.
  2078. \param ssl pointer to the SSL object, created with wolfSSL_new().
  2079. \param ret return value of the previous function that resulted in an error
  2080. return code.
  2081. _Example_
  2082. \code
  2083. int err = 0;
  2084. WOLFSSL* ssl;
  2085. char buffer[80];
  2086. ...
  2087. err = wolfSSL_get_error(ssl, 0);
  2088. wolfSSL_ERR_error_string(err, buffer);
  2089. printf(“err = %d, %s\n”, err, buffer);
  2090. \endcode
  2091. \sa wolfSSL_ERR_error_string
  2092. \sa wolfSSL_ERR_error_string_n
  2093. \sa wolfSSL_ERR_print_errors_fp
  2094. \sa wolfSSL_load_error_strings
  2095. */
  2096. int wolfSSL_get_error(WOLFSSL* ssl, int ret);
  2097. /*!
  2098. \ingroup IO
  2099. \brief This function gets the alert history.
  2100. \return SSL_SUCCESS returned when the function completed successfully.
  2101. Either there was alert history or there wasn’t, either way, the
  2102. return value is SSL_SUCCESS.
  2103. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2104. \param h a pointer to a WOLFSSL_ALERT_HISTORY structure that will hold the
  2105. WOLFSSL struct’s alert_history member’s value.
  2106. _Example_
  2107. \code
  2108. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  2109. WOLFSSL* ssl = wolfSSL_new(ctx);
  2110. WOLFSSL_ALERT_HISTORY* h;
  2111. ...
  2112. wolfSSL_get_alert_history(ssl, h);
  2113. // h now has a copy of the ssl->alert_history contents
  2114. \endcode
  2115. \sa wolfSSL_get_error
  2116. */
  2117. int wolfSSL_get_alert_history(WOLFSSL* ssl, WOLFSSL_ALERT_HISTORY *h);
  2118. /*!
  2119. \ingroup Setup
  2120. \brief This function sets the session to be used when the SSL object,
  2121. ssl, is used to establish a SSL/TLS connection. For session resumption,
  2122. before calling wolfSSL_shutdown() with your session object, an application
  2123. should save the session ID from the object with a call to
  2124. wolfSSL_get1_session(), which returns a pointer to the session.
  2125. Later, the application should create a new WOLFSSL object and assign
  2126. the saved session with wolfSSL_set_session(). At this point, the
  2127. application may call wolfSSL_connect() and wolfSSL will try to resume
  2128. the session. The wolfSSL server code allows session resumption by default.
  2129. The object returned by wolfSSL_get1_session() needs to be freed after the
  2130. application is done with it by calling wolfSSL_SESSION_free() on it.
  2131. \return SSL_SUCCESS will be returned upon successfully setting the session.
  2132. \return SSL_FAILURE will be returned on failure. This could be caused
  2133. by the session cache being disabled, or if the session has timed out.
  2134. \return When OPENSSL_EXTRA and WOLFSSL_ERROR_CODE_OPENSSL are defined,
  2135. SSL_SUCCESS will be returned even if the session has timed out.
  2136. \param ssl pointer to the SSL object, created with wolfSSL_new().
  2137. \param session pointer to the WOLFSSL_SESSION used to set the session
  2138. for ssl.
  2139. _Example_
  2140. \code
  2141. int ret;
  2142. WOLFSSL* ssl;
  2143. WOLFSSL_SESSION* session;
  2144. ...
  2145. session = wolfSSL_get1_session(ssl);
  2146. if (session == NULL) {
  2147. // failed to get session object from ssl object
  2148. }
  2149. ...
  2150. ret = wolfSSL_set_session(ssl, session);
  2151. if (ret != SSL_SUCCESS) {
  2152. // failed to set the SSL session
  2153. }
  2154. wolfSSL_SESSION_free(session);
  2155. ...
  2156. \endcode
  2157. \sa wolfSSL_get1_session
  2158. */
  2159. int wolfSSL_set_session(WOLFSSL* ssl, WOLFSSL_SESSION* session);
  2160. /*!
  2161. \ingroup IO
  2162. \brief When NO_SESSION_CACHE_REF is defined this function returns a pointer
  2163. to the current session (WOLFSSL_SESSION) used in ssl. This function returns
  2164. a non-persistent pointer to the WOLFSSL_SESSION object. The pointer returned
  2165. will be freed when wolfSSL_free is called. This call should only be used to
  2166. inspect or modify the current session. For session resumption it is
  2167. recommended to use wolfSSL_get1_session(). For backwards compatibility when
  2168. NO_SESSION_CACHE_REF is not defined this function returns a persistent
  2169. session object pointer that is stored in the local cache. The cache size is
  2170. finite and there is a risk that the session object will be overwritten by
  2171. another ssl connection by the time the application calls
  2172. wolfSSL_set_session() on it. It is recommended to define
  2173. NO_SESSION_CACHE_REF in your application and to use wolfSSL_get1_session()
  2174. for session resumption.
  2175. \return pointer If successful the call will return a pointer to the the
  2176. current SSL session object.
  2177. \return NULL will be returned if ssl is NULL, the SSL session cache is
  2178. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  2179. functions fail.
  2180. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2181. _Example_
  2182. \code
  2183. WOLFSSL* ssl;
  2184. WOLFSSL_SESSION* session;
  2185. ...
  2186. session = wolfSSL_get_session(ssl);
  2187. if (session == NULL) {
  2188. // failed to get session pointer
  2189. }
  2190. ...
  2191. \endcode
  2192. \sa wolfSSL_get1_session
  2193. \sa wolfSSL_set_session
  2194. */
  2195. WOLFSSL_SESSION* wolfSSL_get_session(WOLFSSL* ssl);
  2196. /*!
  2197. \ingroup IO
  2198. \brief This function flushes session from the session cache which
  2199. have expired. The time, tm, is used for the time comparison. Note
  2200. that wolfSSL currently uses a static table for sessions, so no flushing
  2201. is needed. As such, this function is currently just a stub. This
  2202. function provides OpenSSL compatibility (SSL_flush_sessions) when
  2203. wolfSSL is compiled with the OpenSSL compatibility layer.
  2204. \return none No returns.
  2205. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  2206. wolfSSL_CTX_new().
  2207. \param tm time used in session expiration comparison.
  2208. _Example_
  2209. \code
  2210. WOLFSSL_CTX* ssl;
  2211. ...
  2212. wolfSSL_flush_sessions(ctx, time(0));
  2213. \endcode
  2214. \sa wolfSSL_get1_session
  2215. \sa wolfSSL_set_session
  2216. */
  2217. void wolfSSL_flush_sessions(WOLFSSL_CTX* ctx, long tm);
  2218. /*!
  2219. \ingroup TLS
  2220. \brief This function associates the client session with the server id.
  2221. If the newSession flag is on, an existing session won’t be reused.
  2222. \return SSL_SUCCESS returned if the function executed without error.
  2223. \return BAD_FUNC_ARG returned if the WOLFSSL struct or id parameter
  2224. is NULL or if len is not greater than zero.
  2225. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2226. \param id a constant byte pointer that will be copied to the
  2227. serverID member of the WOLFSSL_SESSION structure.
  2228. \param len an int type representing the length of the session id parameter.
  2229. \param newSession an int type representing the flag to denote whether
  2230. to reuse a session or not.
  2231. _Example_
  2232. \code
  2233. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol );
  2234. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2235. const byte id[MAX_SIZE]; // or dynamically create space
  2236. int len = 0; // initialize length
  2237. int newSession = 0; // flag to allow
  2238. int ret = wolfSSL_SetServerID(ssl, id, len, newSession);
  2239. if (ret == WOLFSSL_SUCCESS) {
  2240. // The Id was successfully set
  2241. }
  2242. \endcode
  2243. \sa wolfSSL_set_session
  2244. */
  2245. int wolfSSL_SetServerID(WOLFSSL* ssl, const unsigned char* id,
  2246. int len, int newSession);
  2247. /*!
  2248. \ingroup IO
  2249. \brief This function gets the session index of the WOLFSSL structure.
  2250. \return int The function returns an int type representing the
  2251. sessionIndex within the WOLFSSL struct.
  2252. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2253. _Example_
  2254. \code
  2255. WOLFSSL_CTX_new( protocol method );
  2256. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2257. ...
  2258. int sesIdx = wolfSSL_GetSessionIndex(ssl);
  2259. if(sesIdx < 0 || sesIdx > sizeof(ssl->sessionIndex)/sizeof(int)){
  2260. // You have an out of bounds index number and something is not right.
  2261. }
  2262. \endcode
  2263. \sa wolfSSL_GetSessionAtIndex
  2264. */
  2265. int wolfSSL_GetSessionIndex(WOLFSSL* ssl);
  2266. /*!
  2267. \ingroup IO
  2268. \brief This function gets the session at specified index of the session
  2269. cache and copies it into memory. The WOLFSSL_SESSION structure holds
  2270. the session information.
  2271. \return SSL_SUCCESS returned if the function executed successfully and
  2272. no errors were thrown.
  2273. \return BAD_MUTEX_E returned if there was an unlock or lock mutex error.
  2274. \return SSL_FAILURE returned if the function did not execute successfully.
  2275. \param idx an int type representing the session index.
  2276. \param session a pointer to the WOLFSSL_SESSION structure.
  2277. _Example_
  2278. \code
  2279. int idx; // The index to locate the session.
  2280. WOLFSSL_SESSION* session; // Buffer to copy to.
  2281. ...
  2282. if(wolfSSL_GetSessionAtIndex(idx, session) != SSL_SUCCESS){
  2283. // Failure case.
  2284. }
  2285. \endcode
  2286. \sa UnLockMutex
  2287. \sa LockMutex
  2288. \sa wolfSSL_GetSessionIndex
  2289. */
  2290. int wolfSSL_GetSessionAtIndex(int index, WOLFSSL_SESSION* session);
  2291. /*!
  2292. \ingroup IO
  2293. \brief Returns the peer certificate chain from the WOLFSSL_SESSION struct.
  2294. \return pointer A pointer to a WOLFSSL_X509_CHAIN structure that
  2295. contains the peer certification chain.
  2296. \param session a pointer to a WOLFSSL_SESSION structure.
  2297. _Example_
  2298. \code
  2299. WOLFSSL_SESSION* session;
  2300. WOLFSSL_X509_CHAIN* chain;
  2301. ...
  2302. chain = wolfSSL_SESSION_get_peer_chain(session);
  2303. if(!chain){
  2304. // There was no chain. Failure case.
  2305. }
  2306. \endcode
  2307. \sa wolfSSL_GetSessionAtIndex
  2308. \sa wolfSSL_GetSessionIndex
  2309. \sa AddSession
  2310. */
  2311. WOLFSSL_X509_CHAIN* wolfSSL_SESSION_get_peer_chain(WOLFSSL_SESSION* session);
  2312. /*!
  2313. \ingroup Setup
  2314. \brief This function sets the verification method for remote peers and
  2315. also allows a verify callback to be registered with the SSL context.
  2316. The verify callback will be called only when a verification failure has
  2317. occurred. If no verify callback is desired, the NULL pointer can be used
  2318. for verify_callback. The verification mode of peer certificates is a
  2319. logically OR’d list of flags. The possible flag values include:
  2320. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2321. received from the server and the handshake will continue as normal.
  2322. Server mode: the server will not send a certificate request to the client.
  2323. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2324. mode: the client will verify the certificate received from the server
  2325. during the handshake. This is turned on by default in wolfSSL, therefore,
  2326. using this option has no effect. Server mode: the server will send a
  2327. certificate request to the client and verify the client certificate
  2328. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2329. used on the client side. Server mode: the verification will fail on the
  2330. server side if the client fails to send a certificate when requested to
  2331. do so (when using SSL_VERIFY_PEER on the SSL server).
  2332. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2333. side. Server mode: the verification is the same as
  2334. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2335. If a PSK connection is being made then the connection will go through
  2336. without a peer cert.
  2337. \return none No return.
  2338. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2339. \param mode flags indicating verification mode for peer's cert.
  2340. \param verify_callback callback to be called when verification fails.
  2341. If no callback is desired, the NULL pointer can be used for
  2342. verify_callback.
  2343. _Example_
  2344. \code
  2345. WOLFSSL_CTX* ctx = 0;
  2346. ...
  2347. wolfSSL_CTX_set_verify(ctx, (WOLFSSL_VERIFY_PEER |
  2348. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT), NULL);
  2349. \endcode
  2350. \sa wolfSSL_set_verify
  2351. */
  2352. void wolfSSL_CTX_set_verify(WOLFSSL_CTX* ctx, int mode,
  2353. VerifyCallback verify_callback);
  2354. /*!
  2355. \ingroup Setup
  2356. \brief This function sets the verification method for remote peers and
  2357. also allows a verify callback to be registered with the SSL session.
  2358. The verify callback will be called only when a verification failure has
  2359. occurred. If no verify callback is desired, the NULL pointer can be used
  2360. for verify_callback. The verification mode of peer certificates is a
  2361. logically OR’d list of flags. The possible flag values include:
  2362. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2363. received from the server and the handshake will continue as normal. Server
  2364. mode: the server will not send a certificate request to the client.
  2365. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2366. mode: the client will verify the certificate received from the server
  2367. during the handshake. This is turned on by default in wolfSSL, therefore,
  2368. using this option has no effect. Server mode: the server will send a
  2369. certificate request to the client and verify the client certificate
  2370. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2371. used on the client side. Server mode: the verification will fail on the
  2372. server side if the client fails to send a certificate when requested to do
  2373. so (when using SSL_VERIFY_PEER on the SSL server).
  2374. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2375. side. Server mode: the verification is the same as
  2376. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2377. If a PSK connection is being made then the connection will go through
  2378. without a peer cert.
  2379. \return none No return.
  2380. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2381. \param mode flags indicating verification mode for peer's cert.
  2382. \param verify_callback callback to be called when verification fails.
  2383. If no callback is desired, the NULL pointer can
  2384. be used for verify_callback.
  2385. _Example_
  2386. \code
  2387. WOLFSSL* ssl = 0;
  2388. ...
  2389. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  2390. \endcode
  2391. \sa wolfSSL_CTX_set_verify
  2392. */
  2393. void wolfSSL_set_verify(WOLFSSL* ssl, int mode, VerifyCallback verify_callback);
  2394. /*!
  2395. \ingroup CertsKeys
  2396. \brief This function stores user CTX object information for verify callback.
  2397. \return none No return.
  2398. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2399. \param ctx a void pointer that is set to WOLFSSL structure’s verifyCbCtx
  2400. member’s value.
  2401. _Example_
  2402. \code
  2403. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2404. WOLFSSL* ssl = wolfSSL_new(ctx);
  2405. (void*)ctx;
  2406. ...
  2407. if(ssl != NULL){
  2408. wolfSSL_SetCertCbCtx(ssl, ctx);
  2409. } else {
  2410. // Error case, the SSL is not initialized properly.
  2411. }
  2412. \endcode
  2413. \sa wolfSSL_CTX_save_cert_cache
  2414. \sa wolfSSL_CTX_restore_cert_cache
  2415. \sa wolfSSL_CTX_set_verify
  2416. */
  2417. void wolfSSL_SetCertCbCtx(WOLFSSL* ssl, void* ctx);
  2418. /*!
  2419. \ingroup CertsKeys
  2420. \brief This function stores user CTX object information for verify callback.
  2421. \return none No return.
  2422. \param ctx a pointer to a WOLFSSL_CTX structure.
  2423. \param userCtx a void pointer that is used to set WOLFSSL_CTX structure’s
  2424. verifyCbCtx member’s value.
  2425. _Example_
  2426. \code
  2427. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2428. void* userCtx = NULL; // Assign some user defined context
  2429. ...
  2430. if(ctx != NULL){
  2431. wolfSSL_SetCertCbCtx(ctx, userCtx);
  2432. } else {
  2433. // Error case, the SSL is not initialized properly.
  2434. }
  2435. \endcode
  2436. \sa wolfSSL_CTX_save_cert_cache
  2437. \sa wolfSSL_CTX_restore_cert_cache
  2438. \sa wolfSSL_CTX_set_verify
  2439. */
  2440. void wolfSSL_CTX_SetCertCbCtx(WOLFSSL_CTX* ctx, void* userCtx);
  2441. /*!
  2442. \ingroup IO
  2443. \brief This function returns the number of bytes which are buffered and
  2444. available in the SSL object to be read by wolfSSL_read().
  2445. \return int This function returns the number of bytes pending.
  2446. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2447. _Example_
  2448. \code
  2449. int pending = 0;
  2450. WOLFSSL* ssl = 0;
  2451. ...
  2452. pending = wolfSSL_pending(ssl);
  2453. printf(“There are %d bytes buffered and available for reading”, pending);
  2454. \endcode
  2455. \sa wolfSSL_recv
  2456. \sa wolfSSL_read
  2457. \sa wolfSSL_peek
  2458. */
  2459. int wolfSSL_pending(WOLFSSL*);
  2460. /*!
  2461. \ingroup Debug
  2462. \brief This function is for OpenSSL compatibility (SSL_load_error_string)
  2463. only and takes no action.
  2464. \return none No returns.
  2465. \param none No parameters.
  2466. _Example_
  2467. \code
  2468. wolfSSL_load_error_strings();
  2469. \endcode
  2470. \sa wolfSSL_get_error
  2471. \sa wolfSSL_ERR_error_string
  2472. \sa wolfSSL_ERR_error_string_n
  2473. \sa wolfSSL_ERR_print_errors_fp
  2474. \sa wolfSSL_load_error_strings
  2475. */
  2476. void wolfSSL_load_error_strings(void);
  2477. /*!
  2478. \ingroup TLS
  2479. \brief This function is called internally in wolfSSL_CTX_new(). This
  2480. function is a wrapper around wolfSSL_Init() and exists for OpenSSL
  2481. compatibility (SSL_library_init) when wolfSSL has been compiled with
  2482. OpenSSL compatibility layer. wolfSSL_Init() is the more typically-used
  2483. wolfSSL initialization function.
  2484. \return SSL_SUCCESS If successful the call will return.
  2485. \return SSL_FATAL_ERROR is returned upon failure.
  2486. \param none No parameters.
  2487. _Example_
  2488. \code
  2489. int ret = 0;
  2490. ret = wolfSSL_library_init();
  2491. if (ret != SSL_SUCCESS) {
  2492. failed to initialize wolfSSL
  2493. }
  2494. ...
  2495. \endcode
  2496. \sa wolfSSL_Init
  2497. \sa wolfSSL_Cleanup
  2498. */
  2499. int wolfSSL_library_init(void);
  2500. /*!
  2501. \brief This function sets the Device Id at the WOLFSSL session level.
  2502. \return WOLFSSL_SUCCESS upon success.
  2503. \return BAD_FUNC_ARG if ssl is NULL.
  2504. \param ssl pointer to a SSL object, created with wolfSSL_new().
  2505. \param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
  2506. _Example_
  2507. \code
  2508. WOLFSSL* ssl;
  2509. int DevId = -2;
  2510. wolfSSL_SetDevId(ssl, devId);
  2511. \endcode
  2512. \sa wolfSSL_CTX_SetDevId
  2513. \sa wolfSSL_CTX_GetDevId
  2514. */
  2515. int wolfSSL_SetDevId(WOLFSSL* ssl, int devId);
  2516. /*!
  2517. \brief This function sets the Device Id at the WOLFSSL_CTX context level.
  2518. \return WOLFSSL_SUCCESS upon success.
  2519. \return BAD_FUNC_ARG if ssl is NULL.
  2520. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2521. \param devId ID to use with crypto callbacks or async hardware. Set to INVALID_DEVID (-2) if not used
  2522. _Example_
  2523. \code
  2524. WOLFSSL_CTX* ctx;
  2525. int DevId = -2;
  2526. wolfSSL_CTX_SetDevId(ctx, devId);
  2527. \endcode
  2528. \sa wolfSSL_SetDevId
  2529. \sa wolfSSL_CTX_GetDevId
  2530. */
  2531. int wolfSSL_CTX_SetDevId(WOLFSSL_CTX* ctx, int devId);
  2532. /*!
  2533. \brief This function retrieves the Device Id.
  2534. \return devId upon success.
  2535. \return INVALID_DEVID if both ssl and ctx are NULL.
  2536. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2537. \param ssl pointer to a SSL object, created with wolfSSL_new().
  2538. _Example_
  2539. \code
  2540. WOLFSSL_CTX* ctx;
  2541. wolfSSL_CTX_GetDevId(ctx, ssl);
  2542. \endcode
  2543. \sa wolfSSL_SetDevId
  2544. \sa wolfSSL_CTX_SetDevId
  2545. */
  2546. int wolfSSL_CTX_GetDevId(WOLFSSL_CTX* ctx, WOLFSSL* ssl);
  2547. /*!
  2548. \ingroup Setup
  2549. \brief This function enables or disables SSL session caching.
  2550. Behavior depends on the value used for mode. The following values
  2551. for mode are available: SSL_SESS_CACHE_OFF- disable session caching.
  2552. Session caching is turned on by default. SSL_SESS_CACHE_NO_AUTO_CLEAR -
  2553. Disable auto-flushing of the session cache. Auto-flushing is turned on
  2554. by default.
  2555. \return SSL_SUCCESS will be returned upon success.
  2556. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2557. \param mode modifier used to change behavior of the session cache.
  2558. _Example_
  2559. \code
  2560. WOLFSSL_CTX* ctx = 0;
  2561. ...
  2562. ret = wolfSSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
  2563. if (ret != SSL_SUCCESS) {
  2564. // failed to turn SSL session caching off
  2565. }
  2566. \endcode
  2567. \sa wolfSSL_flush_sessions
  2568. \sa wolfSSL_get1_session
  2569. \sa wolfSSL_set_session
  2570. \sa wolfSSL_get_sessionID
  2571. \sa wolfSSL_CTX_set_timeout
  2572. */
  2573. long wolfSSL_CTX_set_session_cache_mode(WOLFSSL_CTX* ctx, long mode);
  2574. /*!
  2575. \brief This function sets the session secret callback function. The
  2576. SessionSecretCb type has the signature: int (*SessionSecretCb)(WOLFSSL* ssl,
  2577. void* secret, int* secretSz, void* ctx). The sessionSecretCb member of
  2578. the WOLFSSL struct is set to the parameter cb.
  2579. \return SSL_SUCCESS returned if the execution of the function did not
  2580. return an error.
  2581. \return SSL_FATAL_ERROR returned if the WOLFSSL structure is NULL.
  2582. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2583. \param cb a SessionSecretCb type that is a function pointer with the above
  2584. signature.
  2585. \param ctx a pointer to the user context to be stored
  2586. _Example_
  2587. \code
  2588. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2589. WOLFSSL* ssl = wolfSSL_new(ctx);
  2590. // Signature of SessionSecretCb
  2591. int SessionSecretCB (WOLFSSL* ssl, void* secret, int* secretSz,
  2592. void* ctx) = SessionSecretCb;
  2593. int wolfSSL_set_session_secret_cb(ssl, SessionSecretCB, (void*)ssl->ctx){
  2594. // Function body.
  2595. }
  2596. \endcode
  2597. \sa SessionSecretCb
  2598. */
  2599. int wolfSSL_set_session_secret_cb(WOLFSSL* ssl, SessionSecretCb cb, void* ctx);
  2600. /*!
  2601. \ingroup IO
  2602. \brief This function persists the session cache to file. It doesn’t use
  2603. memsave because of additional memory use.
  2604. \return SSL_SUCCESS returned if the function executed without error.
  2605. The session cache has been written to a file.
  2606. \return SSL_BAD_FILE returned if fname cannot be opened or is otherwise
  2607. corrupt.
  2608. \return FWRITE_ERROR returned if XFWRITE failed to write to the file.
  2609. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2610. \param fname is a constant char pointer that points to a file for writing.
  2611. _Example_
  2612. \code
  2613. const char* fname;
  2614. ...
  2615. if(wolfSSL_save_session_cache(fname) != SSL_SUCCESS){
  2616. // Fail to write to file.
  2617. }
  2618. \endcode
  2619. \sa XFWRITE
  2620. \sa wolfSSL_restore_session_cache
  2621. \sa wolfSSL_memrestore_session_cache
  2622. */
  2623. int wolfSSL_save_session_cache(const char* fname);
  2624. /*!
  2625. \ingroup IO
  2626. \brief This function restores the persistent session cache from file. It
  2627. does not use memstore because of additional memory use.
  2628. \return SSL_SUCCESS returned if the function executed without error.
  2629. \return SSL_BAD_FILE returned if the file passed into the function was
  2630. corrupted and could not be opened by XFOPEN.
  2631. \return FREAD_ERROR returned if the file had a read error from XFREAD.
  2632. \return CACHE_MATCH_ERROR returned if the session cache header match
  2633. failed.
  2634. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2635. \param fname a constant char pointer file input that will be read.
  2636. _Example_
  2637. \code
  2638. const char *fname;
  2639. ...
  2640. if(wolfSSL_restore_session_cache(fname) != SSL_SUCCESS){
  2641. // Failure case. The function did not return SSL_SUCCESS.
  2642. }
  2643. \endcode
  2644. \sa XFREAD
  2645. \sa XFOPEN
  2646. */
  2647. int wolfSSL_restore_session_cache(const char* fname);
  2648. /*!
  2649. \ingroup IO
  2650. \brief This function persists session cache to memory.
  2651. \return SSL_SUCCESS returned if the function executed without error.
  2652. The session cache has been successfully persisted to memory.
  2653. \return BAD_MUTEX_E returned if there was a mutex lock error.
  2654. \return BUFFER_E returned if the buffer size was too small.
  2655. \param mem a void pointer representing the destination for the memory
  2656. copy, XMEMCPY().
  2657. \param sz an int type representing the size of mem.
  2658. _Example_
  2659. \code
  2660. void* mem;
  2661. int sz; // Max size of the memory buffer.
  2662. if(wolfSSL_memsave_session_cache(mem, sz) != SSL_SUCCESS){
  2663. // Failure case, you did not persist the session cache to memory
  2664. }
  2665. \endcode
  2666. \sa XMEMCPY
  2667. \sa wolfSSL_get_session_cache_memsize
  2668. */
  2669. int wolfSSL_memsave_session_cache(void* mem, int sz);
  2670. /*!
  2671. \ingroup IO
  2672. \brief This function restores the persistent session cache from memory.
  2673. \return SSL_SUCCESS returned if the function executed without an error.
  2674. \return BUFFER_E returned if the memory buffer is too small.
  2675. \return BAD_MUTEX_E returned if the session cache mutex lock failed.
  2676. \return CACHE_MATCH_ERROR returned if the session cache header match
  2677. failed.
  2678. \param mem a constant void pointer containing the source of the
  2679. restoration.
  2680. \param sz an integer representing the size of the memory buffer.
  2681. _Example_
  2682. \code
  2683. const void* memoryFile;
  2684. int szMf;
  2685. ...
  2686. if(wolfSSL_memrestore_session_cache(memoryFile, szMf) != SSL_SUCCESS){
  2687. // Failure case. SSL_SUCCESS was not returned.
  2688. }
  2689. \endcode
  2690. \sa wolfSSL_save_session_cache
  2691. */
  2692. int wolfSSL_memrestore_session_cache(const void* mem, int sz);
  2693. /*!
  2694. \ingroup IO
  2695. \brief This function returns how large the session cache save buffer
  2696. should be.
  2697. \return int This function returns an integer that represents the size of
  2698. the session cache save buffer.
  2699. \param none No parameters.
  2700. _Example_
  2701. \code
  2702. int sz = // Minimum size for error checking;
  2703. ...
  2704. if(sz < wolfSSL_get_session_cache_memsize()){
  2705. // Memory buffer is too small
  2706. }
  2707. \endcode
  2708. \sa wolfSSL_memrestore_session_cache
  2709. */
  2710. int wolfSSL_get_session_cache_memsize(void);
  2711. /*!
  2712. \ingroup CertsKeys
  2713. \brief This function writes the cert cache from memory to file.
  2714. \return SSL_SUCCESS if CM_SaveCertCache exits normally.
  2715. \return BAD_FUNC_ARG is returned if either of the arguments are NULL.
  2716. \return SSL_BAD_FILE if the cert cache save file could not be opened.
  2717. \return BAD_MUTEX_E if the lock mutex failed.
  2718. \return MEMORY_E the allocation of memory failed.
  2719. \return FWRITE_ERROR Certificate cache file write failed.
  2720. \param ctx a pointer to a WOLFSSL_CTX structure, holding the
  2721. certificate information.
  2722. \param fname a constant char pointer that points to a file for writing.
  2723. _Example_
  2724. \code
  2725. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  2726. const char* fname;
  2727. ...
  2728. if(wolfSSL_CTX_save_cert_cache(ctx, fname)){
  2729. // file was written.
  2730. }
  2731. \endcode
  2732. \sa CM_SaveCertCache
  2733. \sa DoMemSaveCertCache
  2734. */
  2735. int wolfSSL_CTX_save_cert_cache(WOLFSSL_CTX* ctx, const char* fname);
  2736. /*!
  2737. \ingroup CertsKeys
  2738. \brief This function persistes certificate cache from a file.
  2739. \return SSL_SUCCESS returned if the function, CM_RestoreCertCache,
  2740. executes normally.
  2741. \return SSL_BAD_FILE returned if XFOPEN returns XBADFILE. The file is
  2742. corrupted.
  2743. \return MEMORY_E returned if the allocated memory for the temp buffer
  2744. fails.
  2745. \return BAD_FUNC_ARG returned if fname or ctx have a NULL value.
  2746. \param ctx a pointer to a WOLFSSL_CTX structure, holding the certificate
  2747. information.
  2748. \param fname a constant char pointer that points to a file for reading.
  2749. _Example_
  2750. \code
  2751. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  2752. WOLFSSL* ssl = wolfSSL_new(ctx);
  2753. const char* fname = "path to file";
  2754. ...
  2755. if(wolfSSL_CTX_restore_cert_cache(ctx, fname)){
  2756. // check to see if the execution was successful
  2757. }
  2758. \endcode
  2759. \sa CM_RestoreCertCache
  2760. \sa XFOPEN
  2761. */
  2762. int wolfSSL_CTX_restore_cert_cache(WOLFSSL_CTX* ctx, const char* fname);
  2763. /*!
  2764. \ingroup CertsKeys
  2765. \brief This function persists the certificate cache to memory.
  2766. \return SSL_SUCCESS returned on successful execution of the function.
  2767. No errors were thrown.
  2768. \return BAD_MUTEX_E mutex error where the WOLFSSL_CERT_MANAGER member
  2769. caLock was not 0 (zero).
  2770. \return BAD_FUNC_ARG returned if ctx, mem, or used is NULL or if sz
  2771. is less than or equal to 0 (zero).
  2772. \return BUFFER_E output buffer mem was too small.
  2773. \param ctx a pointer to a WOLFSSL_CTX structure, created
  2774. using wolfSSL_CTX_new().
  2775. \param mem a void pointer to the destination (output buffer).
  2776. \param sz the size of the output buffer.
  2777. \param used a pointer to size of the cert cache header.
  2778. _Example_
  2779. \code
  2780. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  2781. void* mem;
  2782. int sz;
  2783. int* used;
  2784. ...
  2785. if(wolfSSL_CTX_memsave_cert_cache(ctx, mem, sz, used) != SSL_SUCCESS){
  2786. // The function returned with an error
  2787. }
  2788. \endcode
  2789. \sa DoMemSaveCertCache
  2790. \sa GetCertCacheMemSize
  2791. \sa CM_MemRestoreCertCache
  2792. \sa CM_GetCertCacheMemSize
  2793. */
  2794. int wolfSSL_CTX_memsave_cert_cache(WOLFSSL_CTX* ctx, void* mem, int sz, int* used);
  2795. /*!
  2796. \ingroup Setup
  2797. \brief This function restores the certificate cache from memory.
  2798. \return SSL_SUCCESS returned if the function and subroutines
  2799. executed without an error.
  2800. \return BAD_FUNC_ARG returned if the ctx or mem parameters are
  2801. NULL or if the sz parameter is less than or equal to zero.
  2802. \return BUFFER_E returned if the cert cache memory buffer is too small.
  2803. \return CACHE_MATCH_ERROR returned if there was a cert cache
  2804. header mismatch.
  2805. \return BAD_MUTEX_E returned if the lock mutex on failed.
  2806. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  2807. wolfSSL_CTX_new().
  2808. \param mem a void pointer with a value that will be restored to
  2809. the certificate cache.
  2810. \param sz an int type that represents the size of the mem parameter.
  2811. _Example_
  2812. \code
  2813. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  2814. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2815. void* mem;
  2816. int sz = (*int) sizeof(mem);
  2817. if(wolfSSL_CTX_memrestore_cert_cache(ssl->ctx, mem, sz)){
  2818. // The success case
  2819. }
  2820. \endcode
  2821. \sa CM_MemRestoreCertCache
  2822. */
  2823. int wolfSSL_CTX_memrestore_cert_cache(WOLFSSL_CTX* ctx, const void* mem, int sz);
  2824. /*!
  2825. \ingroup CertsKeys
  2826. \brief Returns the size the certificate cache save buffer needs to be.
  2827. \return int integer value returned representing the memory size
  2828. upon success.
  2829. \return BAD_FUNC_ARG is returned if the WOLFSSL_CTX struct is NULL.
  2830. \return BAD_MUTEX_E - returned if there was a mutex lock error.
  2831. \param ctx a pointer to a wolfSSL_CTX structure, created using
  2832. wolfSSL_CTX_new().
  2833. _Example_
  2834. \code
  2835. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol);
  2836. ...
  2837. int certCacheSize = wolfSSL_CTX_get_cert_cache_memsize(ctx);
  2838. if(certCacheSize != BAD_FUNC_ARG || certCacheSize != BAD_MUTEX_E){
  2839. // Successfully retrieved the memory size.
  2840. }
  2841. \endcode
  2842. \sa CM_GetCertCacheMemSize
  2843. */
  2844. int wolfSSL_CTX_get_cert_cache_memsize(WOLFSSL_CTX* ctx);
  2845. /*!
  2846. \ingroup Setup
  2847. \brief This function sets cipher suite list for a given WOLFSSL_CTX.
  2848. This cipher suite list becomes the default list for any new SSL sessions
  2849. (WOLFSSL) created using this context. The ciphers in the list should be
  2850. sorted in order of preference from highest to lowest. Each call to
  2851. wolfSSL_CTX_set_cipher_list() resets the cipher suite list for the
  2852. specific SSL context to the provided list each time the function is
  2853. called. The cipher suite list, list, is a null-terminated text string,
  2854. and a colon-delimited list. For example, one value for list may be
  2855. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256" Valid cipher
  2856. values are the full name values from the cipher_names[] array in
  2857. src/internal.c (for a definite list of valid cipher values check
  2858. src/internal.c)
  2859. \return SSL_SUCCESS will be returned upon successful function completion.
  2860. \return SSL_FAILURE will be returned on failure.
  2861. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2862. \param list null-terminated text string and a colon-delimited list of
  2863. cipher suites to use with the specified SSL context.
  2864. _Example_
  2865. \code
  2866. WOLFSSL_CTX* ctx = 0;
  2867. ...
  2868. ret = wolfSSL_CTX_set_cipher_list(ctx,
  2869. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2870. if (ret != SSL_SUCCESS) {
  2871. // failed to set cipher suite list
  2872. }
  2873. \endcode
  2874. \sa wolfSSL_set_cipher_list
  2875. \sa wolfSSL_CTX_new
  2876. */
  2877. int wolfSSL_CTX_set_cipher_list(WOLFSSL_CTX* ctx, const char* list);
  2878. /*!
  2879. \ingroup Setup
  2880. \brief This function sets cipher suite list for a given WOLFSSL object
  2881. (SSL session). The ciphers in the list should be sorted in order of
  2882. preference from highest to lowest. Each call to wolfSSL_set_cipher_list()
  2883. resets the cipher suite list for the specific SSL session to the provided
  2884. list each time the function is called. The cipher suite list, list, is a
  2885. null-terminated text string, and a colon-delimited list. For example, one
  2886. value for list may be
  2887. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256".
  2888. Valid cipher values are the full name values from the cipher_names[]
  2889. array in src/internal.c (for a definite list of valid cipher values
  2890. check src/internal.c)
  2891. \return SSL_SUCCESS will be returned upon successful function completion.
  2892. \return SSL_FAILURE will be returned on failure.
  2893. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2894. \param list null-terminated text string and a colon-delimited list of
  2895. cipher suites to use with the specified SSL session.
  2896. _Example_
  2897. \code
  2898. int ret = 0;
  2899. WOLFSSL* ssl = 0;
  2900. ...
  2901. ret = wolfSSL_set_cipher_list(ssl,
  2902. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2903. if (ret != SSL_SUCCESS) {
  2904. // failed to set cipher suite list
  2905. }
  2906. \endcode
  2907. \sa wolfSSL_CTX_set_cipher_list
  2908. \sa wolfSSL_new
  2909. */
  2910. int wolfSSL_set_cipher_list(WOLFSSL* ssl, const char* list);
  2911. /*!
  2912. \brief This function informs the WOLFSSL DTLS object that the underlying
  2913. UDP I/O is non-blocking. After an application creates a WOLFSSL object,
  2914. if it will be used with a non-blocking UDP socket, call
  2915. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2916. that receiving EWOULDBLOCK means that the recvfrom call would
  2917. block rather than that it timed out.
  2918. \return none No return.
  2919. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2920. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  2921. Use 1 to specify non-blocking, otherwise 0.
  2922. _Example_
  2923. \code
  2924. WOLFSSL* ssl = 0;
  2925. ...
  2926. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  2927. \endcode
  2928. \sa wolfSSL_dtls_get_using_nonblock
  2929. \sa wolfSSL_dtls_got_timeout
  2930. \sa wolfSSL_dtls_get_current_timeout
  2931. */
  2932. void wolfSSL_dtls_set_using_nonblock(WOLFSSL* ssl, int nonblock);
  2933. /*!
  2934. \brief This function allows the application to determine if wolfSSL is
  2935. using non-blocking I/O with UDP. If wolfSSL is using non-blocking I/O, this
  2936. function will return 1, otherwise 0. After an application creates a
  2937. WOLFSSL object, if it will be used with a non-blocking UDP socket, call
  2938. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2939. that receiving EWOULDBLOCK means that the recvfrom call would block
  2940. rather than that it timed out. This function is only meaningful to DTLS
  2941. sessions.
  2942. \return 0 underlying I/O is blocking.
  2943. \return 1 underlying I/O is non-blocking.
  2944. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2945. _Example_
  2946. \code
  2947. int ret = 0;
  2948. WOLFSSL* ssl = 0;
  2949. ...
  2950. ret = wolfSSL_dtls_get_using_nonblock(ssl);
  2951. if (ret == 1) {
  2952. // underlying I/O is non-blocking
  2953. }
  2954. ...
  2955. \endcode
  2956. \sa wolfSSL_dtls_set_using_nonblock
  2957. \sa wolfSSL_dtls_got_timeout
  2958. \sa wolfSSL_dtls_set_using_nonblock
  2959. */
  2960. int wolfSSL_dtls_get_using_nonblock(WOLFSSL* ssl);
  2961. /*!
  2962. \brief This function returns the current timeout value in seconds for
  2963. the WOLFSSL object. When using non-blocking sockets, something in the user
  2964. code needs to decide when to check for available recv data and how long
  2965. it has been waiting. The value returned by this function indicates how
  2966. long the application should wait.
  2967. \return seconds The current DTLS timeout value in seconds
  2968. \return NOT_COMPILED_IN if wolfSSL was not built with DTLS support.
  2969. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2970. _Example_
  2971. \code
  2972. int timeout = 0;
  2973. WOLFSSL* ssl;
  2974. ...
  2975. timeout = wolfSSL_get_dtls_current_timeout(ssl);
  2976. printf(“DTLS timeout (sec) = %d\n”, timeout);
  2977. \endcode
  2978. \sa wolfSSL_dtls
  2979. \sa wolfSSL_dtls_get_peer
  2980. \sa wolfSSL_dtls_got_timeout
  2981. \sa wolfSSL_dtls_set_peer
  2982. */
  2983. int wolfSSL_dtls_get_current_timeout(WOLFSSL* ssl);
  2984. /*!
  2985. \brief This function returns true if the application should setup a quicker
  2986. timeout. When using non-blocking sockets, something in the user code needs
  2987. to decide when to check for available data and how long it needs to wait. If
  2988. this function returns true, it means that the library already detected some
  2989. disruption in the communication, but it wants to wait for a little longer in
  2990. case some messages from the other peers are still in flight. Is up to the
  2991. application to fine tune the value of this timer, a good one may be
  2992. dtls_get_current_timeout() / 4.
  2993. \return true if the application code should setup a quicker timeout
  2994. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2995. \sa wolfSSL_dtls
  2996. \sa wolfSSL_dtls_get_peer
  2997. \sa wolfSSL_dtls_got_timeout
  2998. \sa wolfSSL_dtls_set_peer
  2999. \sa wolfSSL_dtls13_set_send_more_acks
  3000. */
  3001. int wolfSSL_dtls13_use_quick_timeout(WOLFSSL *ssl);
  3002. /*!
  3003. \ingroup Setup
  3004. \brief This function sets whether the library should send ACKs to the other
  3005. peer immediately when detecting disruption or not. Sending ACKs immediately
  3006. assures minimum latency but it may consume more bandwidth than necessary. If
  3007. the application manages the timer by itself and this option is set to 0 then
  3008. application code can use wolfSSL_dtls13_use_quick_timeout() to determine if
  3009. it should setup a quicker timeout to send those delayed ACKs.
  3010. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3011. \param value 1 to set the option, 0 to disable the option
  3012. \sa wolfSSL_dtls
  3013. \sa wolfSSL_dtls_get_peer
  3014. \sa wolfSSL_dtls_got_timeout
  3015. \sa wolfSSL_dtls_set_peer
  3016. \sa wolfSSL_dtls13_use_quick_timeout
  3017. */
  3018. void wolfSSL_dtls13_set_send_more_acks(WOLFSSL *ssl, int value);
  3019. /*!
  3020. \ingroup Setup
  3021. \brief This function sets the dtls timeout.
  3022. \return SSL_SUCCESS returned if the function executes without an error.
  3023. The dtls_timeout_init and the dtls_timeout members of SSL have been set.
  3024. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  3025. the timeout is not greater than 0. It will also return if the timeout
  3026. argument exceeds the maximum value allowed.
  3027. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3028. \param timeout an int type that will be set to the dtls_timeout_init
  3029. member of the WOLFSSL structure.
  3030. _Example_
  3031. \code
  3032. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  3033. WOLFSSL* ssl = wolfSSL_new(ctx);
  3034. int timeout = TIMEOUT;
  3035. ...
  3036. if(wolfSSL_dtls_set_timeout_init(ssl, timeout)){
  3037. // the dtls timeout was set
  3038. } else {
  3039. // Failed to set DTLS timeout.
  3040. }
  3041. \endcode
  3042. \sa wolfSSL_dtls_set_timeout_max
  3043. \sa wolfSSL_dtls_got_timeout
  3044. */
  3045. int wolfSSL_dtls_set_timeout_init(WOLFSSL* ssl, int);
  3046. /*!
  3047. \brief This function sets the maximum dtls timeout.
  3048. \return SSL_SUCCESS returned if the function executed without an error.
  3049. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  3050. the timeout argument is not greater than zero or is less than the
  3051. dtls_timeout_init member of the WOLFSSL structure.
  3052. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3053. \param timeout an int type representing the dtls maximum timeout.
  3054. _Example_
  3055. \code
  3056. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  3057. WOLFSSL* ssl = wolfSSL_new(ctx);
  3058. int timeout = TIMEOUTVAL;
  3059. ...
  3060. int ret = wolfSSL_dtls_set_timeout_max(ssl);
  3061. if(!ret){
  3062. // Failed to set the max timeout
  3063. }
  3064. \endcode
  3065. \sa wolfSSL_dtls_set_timeout_init
  3066. \sa wolfSSL_dtls_got_timeout
  3067. */
  3068. int wolfSSL_dtls_set_timeout_max(WOLFSSL* ssl, int);
  3069. /*!
  3070. \brief When using non-blocking sockets with DTLS, this function should
  3071. be called on the WOLFSSL object when the controlling code thinks the
  3072. transmission has timed out. It performs the actions needed to retry
  3073. the last transmit, including adjusting the timeout value. If it
  3074. has been too long, this will return a failure.
  3075. \return SSL_SUCCESS will be returned upon success
  3076. \return SSL_FATAL_ERROR will be returned if there have been too many
  3077. retransmissions/timeouts without getting a response from the peer.
  3078. \return NOT_COMPILED_IN will be returned if wolfSSL was not compiled with
  3079. DTLS support.
  3080. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3081. _Example_
  3082. \code
  3083. See the following files for usage examples:
  3084. <wolfssl_root>/examples/client/client.c
  3085. <wolfssl_root>/examples/server/server.c
  3086. \endcode
  3087. \sa wolfSSL_dtls_get_current_timeout
  3088. \sa wolfSSL_dtls_get_peer
  3089. \sa wolfSSL_dtls_set_peer
  3090. \sa wolfSSL_dtls
  3091. */
  3092. int wolfSSL_dtls_got_timeout(WOLFSSL* ssl);
  3093. /*!
  3094. \brief When using non-blocking sockets with DTLS, this function retransmits
  3095. the last handshake flight ignoring the expected timeout value and
  3096. retransmit count. It is useful for applications that are using DTLS and
  3097. need to manage even the timeout and retry count.
  3098. \return SSL_SUCCESS will be returned upon success
  3099. \return SSL_FATAL_ERROR will be returned if there have been too many
  3100. retransmissions/timeouts without getting a response from the peer.
  3101. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3102. _Example_
  3103. \code
  3104. int ret = 0;
  3105. WOLFSSL* ssl;
  3106. ...
  3107. ret = wolfSSL_dtls_retransmit(ssl);
  3108. \endcode
  3109. \sa wolfSSL_dtls_get_current_timeout
  3110. \sa wolfSSL_dtls_got_timeout
  3111. \sa wolfSSL_dtls
  3112. */
  3113. int wolfSSL_dtls_retransmit(WOLFSSL* ssl);
  3114. /*!
  3115. \brief This function is used to determine if the SSL session has been
  3116. configured to use DTLS.
  3117. \return 1 If the SSL session (ssl) has been configured to use DTLS, this
  3118. function will return 1.
  3119. \return 0 otherwise.
  3120. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3121. _Example_
  3122. \code
  3123. int ret = 0;
  3124. WOLFSSL* ssl;
  3125. ...
  3126. ret = wolfSSL_dtls(ssl);
  3127. if (ret) {
  3128. // SSL session has been configured to use DTLS
  3129. }
  3130. \endcode
  3131. \sa wolfSSL_dtls_get_current_timeout
  3132. \sa wolfSSL_dtls_get_peer
  3133. \sa wolfSSL_dtls_got_timeout
  3134. \sa wolfSSL_dtls_set_peer
  3135. */
  3136. int wolfSSL_dtls(WOLFSSL* ssl);
  3137. /*!
  3138. \brief This function sets the DTLS peer, peer (sockaddr_in) with size of
  3139. peerSz.
  3140. \return SSL_SUCCESS will be returned upon success.
  3141. \return SSL_FAILURE will be returned upon failure.
  3142. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  3143. with DTLS support.
  3144. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3145. \param peer pointer to peer’s sockaddr_in structure. If NULL then the peer
  3146. information in ssl is cleared.
  3147. \param peerSz size of the sockaddr_in structure pointed to by peer. If 0
  3148. then the peer information in ssl is cleared.
  3149. _Example_
  3150. \code
  3151. int ret = 0;
  3152. WOLFSSL* ssl;
  3153. sockaddr_in addr;
  3154. ...
  3155. ret = wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
  3156. if (ret != SSL_SUCCESS) {
  3157. // failed to set DTLS peer
  3158. }
  3159. \endcode
  3160. \sa wolfSSL_dtls_get_current_timeout
  3161. \sa wolfSSL_dtls_get_peer
  3162. \sa wolfSSL_dtls_got_timeout
  3163. \sa wolfSSL_dtls
  3164. */
  3165. int wolfSSL_dtls_set_peer(WOLFSSL* ssl, void* peer, unsigned int peerSz);
  3166. /*!
  3167. \brief This function gets the sockaddr_in (of size peerSz) of the current
  3168. DTLS peer. The function will compare peerSz to the actual DTLS peer size
  3169. stored in the SSL session. If the peer will fit into peer, the peer’s
  3170. sockaddr_in will be copied into peer, with peerSz set to the size of peer.
  3171. \return SSL_SUCCESS will be returned upon success.
  3172. \return SSL_FAILURE will be returned upon failure.
  3173. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  3174. with DTLS support.
  3175. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3176. \param peer pointer to memory location to store peer’s sockaddr_in
  3177. structure.
  3178. \param peerSz input/output size. As input, the size of the allocated memory
  3179. pointed to by peer. As output, the size of the actual sockaddr_in structure
  3180. pointed to by peer.
  3181. _Example_
  3182. \code
  3183. int ret = 0;
  3184. WOLFSSL* ssl;
  3185. sockaddr_in addr;
  3186. ...
  3187. ret = wolfSSL_dtls_get_peer(ssl, &addr, sizeof(addr));
  3188. if (ret != SSL_SUCCESS) {
  3189. // failed to get DTLS peer
  3190. }
  3191. \endcode
  3192. \sa wolfSSL_dtls_get_current_timeout
  3193. \sa wolfSSL_dtls_got_timeout
  3194. \sa wolfSSL_dtls_set_peer
  3195. \sa wolfSSL_dtls
  3196. */
  3197. int wolfSSL_dtls_get_peer(WOLFSSL* ssl, void* peer, unsigned int* peerSz);
  3198. /*!
  3199. \ingroup Debug
  3200. \brief This function converts an error code returned by
  3201. wolfSSL_get_error() into a more human-readable error string.
  3202. errNumber is the error code returned by wolfSSL_get_error() and data
  3203. is the storage buffer which the error string will be placed in.
  3204. The maximum length of data is 80 characters by default, as defined by
  3205. MAX_ERROR_SZ is wolfssl/wolfcrypt/error.h.
  3206. \return success On successful completion, this function returns the same
  3207. string as is returned in data.
  3208. \return failure Upon failure, this function returns a string with the
  3209. appropriate failure reason, msg.
  3210. \param errNumber error code returned by wolfSSL_get_error().
  3211. \param data output buffer containing human-readable error string matching
  3212. errNumber.
  3213. _Example_
  3214. \code
  3215. int err = 0;
  3216. WOLFSSL* ssl;
  3217. char buffer[80];
  3218. ...
  3219. err = wolfSSL_get_error(ssl, 0);
  3220. wolfSSL_ERR_error_string(err, buffer);
  3221. printf(“err = %d, %s\n”, err, buffer);
  3222. \endcode
  3223. \sa wolfSSL_get_error
  3224. \sa wolfSSL_ERR_error_string_n
  3225. \sa wolfSSL_ERR_print_errors_fp
  3226. \sa wolfSSL_load_error_strings
  3227. */
  3228. char* wolfSSL_ERR_error_string(unsigned long errNumber, char* data);
  3229. /*!
  3230. \ingroup Debug
  3231. \brief This function is a version of wolfSSL_ERR_error_string() where
  3232. len specifies the maximum number of characters that may be written to buf.
  3233. Like wolfSSL_ERR_error_string(), this function converts an error code
  3234. returned from wolfSSL_get_error() into a more human-readable error string.
  3235. The human-readable string is placed in buf.
  3236. \return none No returns.
  3237. \param e error code returned by wolfSSL_get_error().
  3238. \param buff output buffer containing human-readable error string matching e.
  3239. \param len maximum length in characters which may be written to buf.
  3240. _Example_
  3241. \code
  3242. int err = 0;
  3243. WOLFSSL* ssl;
  3244. char buffer[80];
  3245. ...
  3246. err = wolfSSL_get_error(ssl, 0);
  3247. wolfSSL_ERR_error_string_n(err, buffer, 80);
  3248. printf(“err = %d, %s\n”, err, buffer);
  3249. \endcode
  3250. \sa wolfSSL_get_error
  3251. \sa wolfSSL_ERR_error_string
  3252. \sa wolfSSL_ERR_print_errors_fp
  3253. \sa wolfSSL_load_error_strings
  3254. */
  3255. void wolfSSL_ERR_error_string_n(unsigned long e, char* buf,
  3256. unsigned long sz);
  3257. /*!
  3258. \ingroup TLS
  3259. \brief This function checks the shutdown conditions in closeNotify or
  3260. connReset or sentNotify members of the Options structure. The Options
  3261. structure is within the WOLFSSL structure.
  3262. \return 1 SSL_SENT_SHUTDOWN is returned.
  3263. \return 2 SSL_RECEIVED_SHUTDOWN is returned.
  3264. \param ssl a constant pointer to a WOLFSSL structure, created using
  3265. wolfSSL_new().
  3266. _Example_
  3267. \code
  3268. #include <wolfssl/ssl.h>
  3269. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  3270. WOLFSSL* ssl = WOLFSSL_new(ctx);
  3271. int ret;
  3272. ret = wolfSSL_get_shutdown(ssl);
  3273. if(ret == 1){
  3274. SSL_SENT_SHUTDOWN
  3275. } else if(ret == 2){
  3276. SSL_RECEIVED_SHUTDOWN
  3277. } else {
  3278. Fatal error.
  3279. }
  3280. \endcode
  3281. \sa wolfSSL_SESSION_free
  3282. */
  3283. int wolfSSL_get_shutdown(const WOLFSSL* ssl);
  3284. /*!
  3285. \ingroup IO
  3286. \brief This function returns the resuming member of the options struct. The
  3287. flag indicates whether or not to reuse a session. If not, a new session must
  3288. be established.
  3289. \return This function returns an int type held in the Options structure
  3290. representing the flag for session reuse.
  3291. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3292. _Example_
  3293. \code
  3294. WOLFSSL* ssl = wolfSSL_new(ctx);
  3295. if(!wolfSSL_session_reused(sslResume)){
  3296. // No session reuse allowed.
  3297. }
  3298. \endcode
  3299. \sa wolfSSL_SESSION_free
  3300. \sa wolfSSL_GetSessionIndex
  3301. \sa wolfSSL_memsave_session_cache
  3302. */
  3303. int wolfSSL_session_reused(WOLFSSL* ssl);
  3304. /*!
  3305. \ingroup TLS
  3306. \brief This function checks to see if the connection is established.
  3307. \return 0 returned if the connection is not established, i.e. the WOLFSSL
  3308. struct is NULL or the handshake is not done.
  3309. \return 1 returned if the connection is established i.e. the WOLFSSL
  3310. handshake is done.
  3311. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3312. _EXAMPLE_
  3313. \code
  3314. #include <wolfssl/ssl.h>
  3315. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3316. WOLFSSL* ssl = wolfSSL_new(ctx);
  3317. ...
  3318. if(wolfSSL_is_init_finished(ssl)){
  3319. Handshake is done and connection is established
  3320. }
  3321. \endcode
  3322. \sa wolfSSL_set_accept_state
  3323. \sa wolfSSL_get_keys
  3324. \sa wolfSSL_set_shutdown
  3325. */
  3326. int wolfSSL_is_init_finished(WOLFSSL* ssl);
  3327. /*!
  3328. \ingroup IO
  3329. \brief Returns the SSL version being used as a string.
  3330. \return "SSLv3" Using SSLv3
  3331. \return "TLSv1" Using TLSv1
  3332. \return "TLSv1.1" Using TLSv1.1
  3333. \return "TLSv1.2" Using TLSv1.2
  3334. \return "TLSv1.3" Using TLSv1.3
  3335. \return "DTLS": Using DTLS
  3336. \return "DTLSv1.2" Using DTLSv1.2
  3337. \return "unknown" There was a problem determining which version of TLS
  3338. being used.
  3339. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3340. _Example_
  3341. \code
  3342. wolfSSL_Init();
  3343. WOLFSSL_CTX* ctx;
  3344. WOLFSSL* ssl;
  3345. WOLFSSL_METHOD method = // Some wolfSSL method
  3346. ctx = wolfSSL_CTX_new(method);
  3347. ssl = wolfSSL_new(ctx);
  3348. printf(wolfSSL_get_version("Using version: %s", ssl));
  3349. \endcode
  3350. \sa wolfSSL_lib_version
  3351. */
  3352. const char* wolfSSL_get_version(WOLFSSL* ssl);
  3353. /*!
  3354. \ingroup IO
  3355. \brief Returns the current cipher suit an ssl session is using.
  3356. \return ssl->options.cipherSuite An integer representing the current
  3357. cipher suite.
  3358. \return 0 The ssl session provided is null.
  3359. \param ssl The SSL session to check.
  3360. _Example_
  3361. \code
  3362. wolfSSL_Init();
  3363. WOLFSSL_CTX* ctx;
  3364. WOLFSSL* ssl;
  3365. WOLFSSL_METHOD method = // Some wolfSSL method
  3366. ctx = wolfSSL_CTX_new(method);
  3367. ssl = wolfSSL_new(ctx);
  3368. if(wolfSSL_get_current_cipher_suite(ssl) == 0)
  3369. {
  3370. // Error getting cipher suite
  3371. }
  3372. \endcode
  3373. \sa wolfSSL_CIPHER_get_name
  3374. \sa wolfSSL_get_current_cipher
  3375. \sa wolfSSL_get_cipher_list
  3376. */
  3377. int wolfSSL_get_current_cipher_suite(WOLFSSL* ssl);
  3378. /*!
  3379. \ingroup IO
  3380. \brief This function returns a pointer to the current cipher in the
  3381. ssl session.
  3382. \return The function returns the address of the cipher member of the
  3383. WOLFSSL struct. This is a pointer to the WOLFSSL_CIPHER structure.
  3384. \return NULL returned if the WOLFSSL structure is NULL.
  3385. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3386. _Example_
  3387. \code
  3388. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3389. WOLFSSL* ssl = wolfSSL_new(ctx);
  3390. WOLFSSL_CIPHER* cipherCurr = wolfSSL_get_current_cipher;
  3391. if(!cipherCurr){
  3392. // Failure case.
  3393. } else {
  3394. // The cipher was returned to cipherCurr
  3395. }
  3396. \endcode
  3397. \sa wolfSSL_get_cipher
  3398. \sa wolfSSL_get_cipher_name_internal
  3399. \sa wolfSSL_get_cipher_name
  3400. */
  3401. WOLFSSL_CIPHER* wolfSSL_get_current_cipher(WOLFSSL* ssl);
  3402. /*!
  3403. \ingroup IO
  3404. \brief This function matches the cipher suite in the SSL object with
  3405. the available suites and returns the string representation.
  3406. \return string This function returns the string representation of the
  3407. matched cipher suite.
  3408. \return none It will return “None” if there are no suites matched.
  3409. \param cipher a constant pointer to a WOLFSSL_CIPHER structure.
  3410. _Example_
  3411. \code
  3412. // gets cipher name in the format DHE_RSA ...
  3413. const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl){
  3414. WOLFSSL_CIPHER* cipher;
  3415. const char* fullName;
  3416. cipher = wolfSSL_get_curent_cipher(ssl);
  3417. fullName = wolfSSL_CIPHER_get_name(cipher);
  3418. if(fullName){
  3419. // sanity check on returned cipher
  3420. }
  3421. \endcode
  3422. \sa wolfSSL_get_cipher
  3423. \sa wolfSSL_get_current_cipher
  3424. \sa wolfSSL_get_cipher_name_internal
  3425. \sa wolfSSL_get_cipher_name
  3426. */
  3427. const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher);
  3428. /*!
  3429. \ingroup IO
  3430. \brief This function matches the cipher suite in the SSL object with
  3431. the available suites.
  3432. \return This function returns the string value of the suite matched. It
  3433. will return “None” if there are no suites matched.
  3434. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3435. _Example_
  3436. \code
  3437. #ifdef WOLFSSL_DTLS
  3438. // make sure a valid suite is used
  3439. if(wolfSSL_get_cipher(ssl) == NULL){
  3440. WOLFSSL_MSG(“Can not match cipher suite imported”);
  3441. return MATCH_SUITE_ERROR;
  3442. }
  3443. #endif // WOLFSSL_DTLS
  3444. \endcode
  3445. \sa wolfSSL_CIPHER_get_name
  3446. \sa wolfSSL_get_current_cipher
  3447. */
  3448. const char* wolfSSL_get_cipher(WOLFSSL*);
  3449. /*!
  3450. \ingroup Setup
  3451. \brief This function returns the WOLFSSL_SESSION from the WOLFSSL structure
  3452. as a reference type. This requires calling wolfSSL_SESSION_free to release
  3453. the session reference. The WOLFSSL_SESSION pointed to contains all the
  3454. necessary information required to perform a session resumption and
  3455. reestablish the connection without a new handshake. For
  3456. session resumption, before calling wolfSSL_shutdown() with your session
  3457. object, an application should save the session ID from the object with a
  3458. call to wolfSSL_get1_session(), which returns a pointer to the session.
  3459. Later, the application should create a new WOLFSSL object and assign the
  3460. saved session with wolfSSL_set_session(). At this point, the application
  3461. may call wolfSSL_connect() and wolfSSL will try to resume the session.
  3462. The wolfSSL server code allows session resumption by default. The object
  3463. returned by wolfSSL_get1_session() needs to be freed after the application
  3464. is done with it by calling wolfSSL_SESSION_free() on it.
  3465. \return WOLFSSL_SESSION On success return session pointer.
  3466. \return NULL will be returned if ssl is NULL, the SSL session cache is
  3467. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  3468. functions fail.
  3469. \param ssl WOLFSSL structure to get session from.
  3470. _Example_
  3471. \code
  3472. WOLFSSL* ssl;
  3473. WOLFSSL_SESSION* ses;
  3474. // attempt/complete handshake
  3475. wolfSSL_connect(ssl);
  3476. ses = wolfSSL_get1_session(ssl);
  3477. // check ses information
  3478. // disconnect / setup new SSL instance
  3479. wolfSSL_set_session(ssl, ses);
  3480. // attempt/resume handshake
  3481. wolfSSL_SESSION_free(ses);
  3482. \endcode
  3483. \sa wolfSSL_new
  3484. \sa wolfSSL_free
  3485. \sa wolfSSL_SESSION_free
  3486. */
  3487. WOLFSSL_SESSION* wolfSSL_get1_session(WOLFSSL* ssl);
  3488. /*!
  3489. \ingroup Setup
  3490. \brief The wolfSSLv23_client_method() function is used to indicate that
  3491. the application is a client and will support the highest protocol
  3492. version supported by the server between SSL 3.0 - TLS 1.3. This function
  3493. allocates memory for and initializes a new WOLFSSL_METHOD structure
  3494. to be used when creating the SSL/TLS context with wolfSSL_CTX_new().
  3495. Both wolfSSL clients and servers have robust version downgrade capability.
  3496. If a specific protocol version method is used on either side, then only
  3497. that version will be negotiated or an error will be returned. For
  3498. example, a client that uses TLSv1 and tries to connect to a SSLv3 only
  3499. server will fail, likewise connecting to a TLSv1.1 will fail as well.
  3500. To resolve this issue, a client that uses the wolfSSLv23_client_method()
  3501. function will use the highest protocol version supported by the server and
  3502. downgrade to SSLv3 if needed. In this case, the client will be able to
  3503. connect to a server running SSLv3 - TLSv1.3.
  3504. \return pointer upon success a pointer to a WOLFSSL_METHOD.
  3505. \return Failure If memory allocation fails when calling XMALLOC,
  3506. the failure value of the underlying malloc() implementation will be
  3507. returned (typically NULL with errno will be set to ENOMEM).
  3508. \param none No parameters
  3509. _Example_
  3510. \code
  3511. WOLFSSL_METHOD* method;
  3512. WOLFSSL_CTX* ctx;
  3513. method = wolfSSLv23_client_method();
  3514. if (method == NULL) {
  3515. // unable to get method
  3516. }
  3517. ctx = wolfSSL_CTX_new(method);
  3518. ...
  3519. \endcode
  3520. \sa wolfSSLv3_client_method
  3521. \sa wolfTLSv1_client_method
  3522. \sa wolfTLSv1_1_client_method
  3523. \sa wolfTLSv1_2_client_method
  3524. \sa wolfTLSv1_3_client_method
  3525. \sa wolfDTLSv1_client_method
  3526. \sa wolfSSL_CTX_new
  3527. */
  3528. WOLFSSL_METHOD* wolfSSLv23_client_method(void);
  3529. /*!
  3530. \ingroup IO
  3531. \brief This is used to set a byte pointer to the start of the
  3532. internal memory buffer.
  3533. \return size On success the size of the buffer is returned
  3534. \return SSL_FATAL_ERROR If an error case was encountered.
  3535. \param bio WOLFSSL_BIO structure to get memory buffer of.
  3536. \param p byte pointer to set to memory buffer.
  3537. _Example_
  3538. \code
  3539. WOLFSSL_BIO* bio;
  3540. const byte* p;
  3541. int ret;
  3542. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3543. ret = wolfSSL_BIO_get_mem_data(bio, &p);
  3544. // check ret value
  3545. \endcode
  3546. \sa wolfSSL_BIO_new
  3547. \sa wolfSSL_BIO_s_mem
  3548. \sa wolfSSL_BIO_set_fp
  3549. \sa wolfSSL_BIO_free
  3550. */
  3551. int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);
  3552. /*!
  3553. \ingroup IO
  3554. \brief Sets the file descriptor for bio to use.
  3555. \return SSL_SUCCESS(1) upon success.
  3556. \param bio WOLFSSL_BIO structure to set fd.
  3557. \param fd file descriptor to use.
  3558. \param closeF flag for behavior when closing fd.
  3559. _Example_
  3560. \code
  3561. WOLFSSL_BIO* bio;
  3562. int fd;
  3563. // setup bio
  3564. wolfSSL_BIO_set_fd(bio, fd, BIO_NOCLOSE);
  3565. \endcode
  3566. \sa wolfSSL_BIO_new
  3567. \sa wolfSSL_BIO_free
  3568. */
  3569. long wolfSSL_BIO_set_fd(WOLFSSL_BIO* b, int fd, int flag);
  3570. /*!
  3571. \ingroup IO
  3572. \brief Sets the close flag, used to indicate that the i/o stream should be
  3573. closed when the BIO is freed
  3574. \return SSL_SUCCESS(1) upon success.
  3575. \param bio WOLFSSL_BIO structure.
  3576. \param flag flag for behavior when closing i/o stream.
  3577. _Example_
  3578. \code
  3579. WOLFSSL_BIO* bio;
  3580. // setup bio
  3581. wolfSSL_BIO_set_close(bio, BIO_NOCLOSE);
  3582. \endcode
  3583. \sa wolfSSL_BIO_new
  3584. \sa wolfSSL_BIO_free
  3585. */
  3586. int wolfSSL_BIO_set_close(WOLFSSL_BIO *b, long flag);
  3587. /*!
  3588. \ingroup IO
  3589. \brief This is used to get a BIO_SOCKET type WOLFSSL_BIO_METHOD.
  3590. \return WOLFSSL_BIO_METHOD pointer to a WOLFSSL_BIO_METHOD structure
  3591. that is a socket type
  3592. \param none No parameters.
  3593. _Example_
  3594. \code
  3595. WOLFSSL_BIO* bio;
  3596. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket);
  3597. \endcode
  3598. \sa wolfSSL_BIO_new
  3599. \sa wolfSSL_BIO_s_mem
  3600. */
  3601. WOLFSSL_BIO_METHOD *wolfSSL_BIO_s_socket(void);
  3602. /*!
  3603. \ingroup IO
  3604. \brief This is used to set the size of write buffer for a
  3605. WOLFSSL_BIO. If write buffer has been previously set this
  3606. function will free it when resetting the size. It is similar to
  3607. wolfSSL_BIO_reset in that it resets read and write indexes to 0.
  3608. \return SSL_SUCCESS On successfully setting the write buffer.
  3609. \return SSL_FAILURE If an error case was encountered.
  3610. \param bio WOLFSSL_BIO structure to set fd.
  3611. \param size size of buffer to allocate.
  3612. _Example_
  3613. \code
  3614. WOLFSSL_BIO* bio;
  3615. int ret;
  3616. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3617. ret = wolfSSL_BIO_set_write_buf_size(bio, 15000);
  3618. // check return value
  3619. \endcode
  3620. \sa wolfSSL_BIO_new
  3621. \sa wolfSSL_BIO_s_mem
  3622. \sa wolfSSL_BIO_free
  3623. */
  3624. int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *b, long size);
  3625. /*!
  3626. \ingroup IO
  3627. \brief This is used to pair two bios together. A pair of bios acts
  3628. similar to a two way pipe writing to one can be read by the other
  3629. and vice versa. It is expected that both bios be in the same thread,
  3630. this function is not thread safe. Freeing one of the two bios removes
  3631. both from being paired. If a write buffer size was not previously
  3632. set for either of the bios it is set to a default size of 17000
  3633. (WOLFSSL_BIO_SIZE) before being paired.
  3634. \return SSL_SUCCESS On successfully pairing the two bios.
  3635. \return SSL_FAILURE If an error case was encountered.
  3636. \param b1 WOLFSSL_BIO structure to set pair.
  3637. \param b2 second WOLFSSL_BIO structure to complete pair.
  3638. _Example_
  3639. \code
  3640. WOLFSSL_BIO* bio;
  3641. WOLFSSL_BIO* bio2;
  3642. int ret;
  3643. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3644. bio2 = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3645. ret = wolfSSL_BIO_make_bio_pair(bio, bio2);
  3646. // check ret value
  3647. \endcode
  3648. \sa wolfSSL_BIO_new
  3649. \sa wolfSSL_BIO_s_mem
  3650. \sa wolfSSL_BIO_free
  3651. */
  3652. int wolfSSL_BIO_make_bio_pair(WOLFSSL_BIO *b1, WOLFSSL_BIO *b2);
  3653. /*!
  3654. \ingroup IO
  3655. \brief This is used to set the read request flag back to 0.
  3656. \return SSL_SUCCESS On successfully setting value.
  3657. \return SSL_FAILURE If an error case was encountered.
  3658. \param bio WOLFSSL_BIO structure to set read request flag.
  3659. _Example_
  3660. \code
  3661. WOLFSSL_BIO* bio;
  3662. int ret;
  3663. ...
  3664. ret = wolfSSL_BIO_ctrl_reset_read_request(bio);
  3665. // check ret value
  3666. \endcode
  3667. \sa wolfSSL_BIO_new, wolfSSL_BIO_s_mem
  3668. \sa wolfSSL_BIO_new, wolfSSL_BIO_free
  3669. */
  3670. int wolfSSL_BIO_ctrl_reset_read_request(WOLFSSL_BIO *bio);
  3671. /*!
  3672. \ingroup IO
  3673. \brief This is used to get a buffer pointer for reading from. Unlike
  3674. wolfSSL_BIO_nread the internal read index is not advanced by the number
  3675. returned from the function call. Reading past the value returned can
  3676. result in reading out of array bounds.
  3677. \return >=0 on success return the number of bytes to read
  3678. \param bio WOLFSSL_BIO structure to read from.
  3679. \param buf pointer to set at beginning of read array.
  3680. _Example_
  3681. \code
  3682. WOLFSSL_BIO* bio;
  3683. char* bufPt;
  3684. int ret;
  3685. // set up bio
  3686. ret = wolfSSL_BIO_nread0(bio, &bufPt); // read as many bytes as possible
  3687. // handle negative ret check
  3688. // read ret bytes from bufPt
  3689. \endcode
  3690. \sa wolfSSL_BIO_new
  3691. \sa wolfSSL_BIO_nwrite0
  3692. */
  3693. int wolfSSL_BIO_nread0(WOLFSSL_BIO *bio, char **buf);
  3694. /*!
  3695. \ingroup IO
  3696. \brief This is used to get a buffer pointer for reading from. The internal
  3697. read index is advanced by the number returned from the function call with
  3698. buf being pointed to the beginning of the buffer to read from. In the
  3699. case that less bytes are in the read buffer than the value requested with
  3700. num the lesser value is returned. Reading past the value returned can
  3701. result in reading out of array bounds.
  3702. \return >=0 on success return the number of bytes to read
  3703. \return WOLFSSL_BIO_ERROR(-1) on error case with nothing to read return -1
  3704. \param bio WOLFSSL_BIO structure to read from.
  3705. \param buf pointer to set at beginning of read array.
  3706. \param num number of bytes to try and read.
  3707. _Example_
  3708. \code
  3709. WOLFSSL_BIO* bio;
  3710. char* bufPt;
  3711. int ret;
  3712. // set up bio
  3713. ret = wolfSSL_BIO_nread(bio, &bufPt, 10); // try to read 10 bytes
  3714. // handle negative ret check
  3715. // read ret bytes from bufPt
  3716. \endcode
  3717. \sa wolfSSL_BIO_new
  3718. \sa wolfSSL_BIO_nwrite
  3719. */
  3720. int wolfSSL_BIO_nread(WOLFSSL_BIO *bio, char **buf, int num);
  3721. /*!
  3722. \ingroup IO
  3723. \brief Gets a pointer to the buffer for writing as many bytes as returned by
  3724. the function. Writing more bytes to the pointer returned then the value
  3725. returned can result in writing out of bounds.
  3726. \return int Returns the number of bytes that can be written to the buffer
  3727. pointer returned.
  3728. \return WOLFSSL_BIO_UNSET(-2) in the case that is not part of a bio pair
  3729. \return WOLFSSL_BIO_ERROR(-1) in the case that there is no more room to
  3730. write to
  3731. \param bio WOLFSSL_BIO structure to write to.
  3732. \param buf pointer to buffer to write to.
  3733. \param num number of bytes desired to be written.
  3734. _Example_
  3735. \code
  3736. WOLFSSL_BIO* bio;
  3737. char* bufPt;
  3738. int ret;
  3739. // set up bio
  3740. ret = wolfSSL_BIO_nwrite(bio, &bufPt, 10); // try to write 10 bytes
  3741. // handle negative ret check
  3742. // write ret bytes to bufPt
  3743. \endcode
  3744. \sa wolfSSL_BIO_new
  3745. \sa wolfSSL_BIO_free
  3746. \sa wolfSSL_BIO_nread
  3747. */
  3748. int wolfSSL_BIO_nwrite(WOLFSSL_BIO *bio, char **buf, int num);
  3749. /*!
  3750. \ingroup IO
  3751. \brief Resets bio to an initial state. As an example for type BIO_BIO
  3752. this resets the read and write index.
  3753. \return 0 On successfully resetting the bio.
  3754. \return WOLFSSL_BIO_ERROR(-1) Returned on bad input or unsuccessful reset.
  3755. \param bio WOLFSSL_BIO structure to reset.
  3756. _Example_
  3757. \code
  3758. WOLFSSL_BIO* bio;
  3759. // setup bio
  3760. wolfSSL_BIO_reset(bio);
  3761. //use pt
  3762. \endcode
  3763. \sa wolfSSL_BIO_new
  3764. \sa wolfSSL_BIO_free
  3765. */
  3766. int wolfSSL_BIO_reset(WOLFSSL_BIO *bio);
  3767. /*!
  3768. \ingroup IO
  3769. \brief This function adjusts the file pointer to the offset given. This
  3770. is the offset from the head of the file.
  3771. \return 0 On successfully seeking.
  3772. \return -1 If an error case was encountered.
  3773. \param bio WOLFSSL_BIO structure to set.
  3774. \param ofs offset into file.
  3775. _Example_
  3776. \code
  3777. WOLFSSL_BIO* bio;
  3778. XFILE fp;
  3779. int ret;
  3780. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3781. ret = wolfSSL_BIO_set_fp(bio, &fp);
  3782. // check ret value
  3783. ret = wolfSSL_BIO_seek(bio, 3);
  3784. // check ret value
  3785. \endcode
  3786. \sa wolfSSL_BIO_new
  3787. \sa wolfSSL_BIO_s_mem
  3788. \sa wolfSSL_BIO_set_fp
  3789. \sa wolfSSL_BIO_free
  3790. */
  3791. int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs);
  3792. /*!
  3793. \ingroup IO
  3794. \brief This is used to set and write to a file. WIll overwrite any data
  3795. currently in the file and is set to close the file when the bio is freed.
  3796. \return SSL_SUCCESS On successfully opening and setting file.
  3797. \return SSL_FAILURE If an error case was encountered.
  3798. \param bio WOLFSSL_BIO structure to set file.
  3799. \param name name of file to write to.
  3800. _Example_
  3801. \code
  3802. WOLFSSL_BIO* bio;
  3803. int ret;
  3804. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3805. ret = wolfSSL_BIO_write_filename(bio, “test.txt”);
  3806. // check ret value
  3807. \endcode
  3808. \sa wolfSSL_BIO_new
  3809. \sa wolfSSL_BIO_s_file
  3810. \sa wolfSSL_BIO_set_fp
  3811. \sa wolfSSL_BIO_free
  3812. */
  3813. int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name);
  3814. /*!
  3815. \ingroup IO
  3816. \brief This is used to set the end of file value. Common value is -1 so
  3817. as not to get confused with expected positive values.
  3818. \return 0 returned on completion
  3819. \param bio WOLFSSL_BIO structure to set end of file value.
  3820. \param v value to set in bio.
  3821. _Example_
  3822. \code
  3823. WOLFSSL_BIO* bio;
  3824. int ret;
  3825. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3826. ret = wolfSSL_BIO_set_mem_eof_return(bio, -1);
  3827. // check ret value
  3828. \endcode
  3829. \sa wolfSSL_BIO_new
  3830. \sa wolfSSL_BIO_s_mem
  3831. \sa wolfSSL_BIO_set_fp
  3832. \sa wolfSSL_BIO_free
  3833. */
  3834. long wolfSSL_BIO_set_mem_eof_return(WOLFSSL_BIO *bio, int v);
  3835. /*!
  3836. \ingroup IO
  3837. \brief This is a getter function for WOLFSSL_BIO memory pointer.
  3838. \return SSL_SUCCESS On successfully getting the pointer SSL_SUCCESS is
  3839. returned (currently value of 1).
  3840. \return SSL_FAILURE Returned if NULL arguments are passed in (currently
  3841. value of 0).
  3842. \param bio pointer to the WOLFSSL_BIO structure for getting memory pointer.
  3843. \param ptr structure that is currently a char*. Is set to point to
  3844. bio’s memory.
  3845. _Example_
  3846. \code
  3847. WOLFSSL_BIO* bio;
  3848. WOLFSSL_BUF_MEM* pt;
  3849. // setup bio
  3850. wolfSSL_BIO_get_mem_ptr(bio, &pt);
  3851. //use pt
  3852. \endcode
  3853. \sa wolfSSL_BIO_new
  3854. \sa wolfSSL_BIO_s_mem
  3855. */
  3856. long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **m);
  3857. /*!
  3858. \ingroup CertsKeys
  3859. \brief This function copies the name of the x509 into a buffer.
  3860. \return A char pointer to the buffer with the WOLFSSL_X509_NAME structures
  3861. name member’s data is returned if the function executed normally.
  3862. \param name a pointer to a WOLFSSL_X509 structure.
  3863. \param in a buffer to hold the name copied from the
  3864. WOLFSSL_X509_NAME structure.
  3865. \param sz the maximum size of the buffer.
  3866. _Example_
  3867. \code
  3868. WOLFSSL_X509 x509;
  3869. char* name;
  3870. ...
  3871. name = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3872. if(name <= 0){
  3873. // There’s nothing in the buffer.
  3874. }
  3875. \endcode
  3876. \sa wolfSSL_X509_get_subject_name
  3877. \sa wolfSSL_X509_get_issuer_name
  3878. \sa wolfSSL_X509_get_isCA
  3879. \sa wolfSSL_get_peer_certificate
  3880. \sa wolfSSL_X509_version
  3881. */
  3882. char* wolfSSL_X509_NAME_oneline(WOLFSSL_X509_NAME* name, char* in, int sz);
  3883. /*!
  3884. \ingroup CertsKeys
  3885. \brief This function returns the name of the certificate issuer.
  3886. \return point a pointer to the WOLFSSL_X509 struct’s issuer member is
  3887. returned.
  3888. \return NULL if the cert passed in is NULL.
  3889. \param cert a pointer to a WOLFSSL_X509 structure.
  3890. _Example_
  3891. \code
  3892. WOLFSSL_X509* x509;
  3893. WOLFSSL_X509_NAME issuer;
  3894. ...
  3895. issuer = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3896. if(!issuer){
  3897. // NULL was returned
  3898. } else {
  3899. // issuer hods the name of the certificate issuer.
  3900. }
  3901. \endcode
  3902. \sa wolfSSL_X509_get_subject_name
  3903. \sa wolfSSL_X509_get_isCA
  3904. \sa wolfSSL_get_peer_certificate
  3905. \sa wolfSSL_X509_NAME_oneline
  3906. */
  3907. WOLFSSL_X509_NAME* wolfSSL_X509_get_issuer_name(WOLFSSL_X509* cert);
  3908. /*!
  3909. \ingroup CertsKeys
  3910. \brief This function returns the subject member of the WOLFSSL_X509
  3911. structure.
  3912. \return pointer a pointer to the WOLFSSL_X509_NAME structure. The pointer
  3913. may be NULL if the WOLFSSL_X509 struct is NULL or if the subject member of
  3914. the structure is NULL.
  3915. \param cert a pointer to a WOLFSSL_X509 structure.
  3916. _Example_
  3917. \code
  3918. WOLFSSL_X509* cert;
  3919. WOLFSSL_X509_NAME name;
  3920. name = wolfSSL_X509_get_subject_name(cert);
  3921. if(name == NULL){
  3922. // Deal with the NULL cacse
  3923. }
  3924. \endcode
  3925. \sa wolfSSL_X509_get_issuer_name
  3926. \sa wolfSSL_X509_get_isCA
  3927. \sa wolfSSL_get_peer_certificate
  3928. */
  3929. WOLFSSL_X509_NAME* wolfSSL_X509_get_subject_name(WOLFSSL_X509* cert);
  3930. /*!
  3931. \ingroup CertsKeys
  3932. \brief Checks the isCa member of the WOLFSSL_X509 structure and returns
  3933. the value.
  3934. \return isCA returns the value in the isCA member of the WOLFSSL_X509
  3935. structure is returned.
  3936. \return 0 returned if there is not a valid x509 structure passed in.
  3937. \param cert a pointer to a WOLFSSL_X509 structure.
  3938. _Example_
  3939. \code
  3940. WOLFSSL* ssl;
  3941. ...
  3942. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  3943. WOLFSSL* ssl = wolfSSL_new(ctx);
  3944. ...
  3945. if(wolfSSL_X509_get_isCA(ssl)){
  3946. // This is the CA
  3947. }else {
  3948. // Failure case
  3949. }
  3950. \endcode
  3951. \sa wolfSSL_X509_get_issuer_name
  3952. \sa wolfSSL_X509_get_isCA
  3953. */
  3954. int wolfSSL_X509_get_isCA(WOLFSSL_X509* cert);
  3955. /*!
  3956. \ingroup CertsKeys
  3957. \brief This function gets the text related to the passed in NID value.
  3958. \return int returns the size of the text buffer.
  3959. \param name WOLFSSL_X509_NAME to search for text.
  3960. \param nid NID to search for.
  3961. \param buf buffer to hold text when found.
  3962. \param len length of buffer.
  3963. _Example_
  3964. \code
  3965. WOLFSSL_X509_NAME* name;
  3966. char buffer[100];
  3967. int bufferSz;
  3968. int ret;
  3969. // get WOLFSSL_X509_NAME
  3970. ret = wolfSSL_X509_NAME_get_text_by_NID(name, NID_commonName,
  3971. buffer, bufferSz);
  3972. //check ret value
  3973. \endcode
  3974. \sa none
  3975. */
  3976. int wolfSSL_X509_NAME_get_text_by_NID(WOLFSSL_X509_NAME* name, int nid,
  3977. char* buf, int len);
  3978. /*!
  3979. \ingroup CertsKeys
  3980. \brief This function returns the value stored in the sigOID
  3981. member of the WOLFSSL_X509 structure.
  3982. \return 0 returned if the WOLFSSL_X509 structure is NULL.
  3983. \return int an integer value is returned which was retrieved from
  3984. the x509 object.
  3985. \param cert a pointer to a WOLFSSL_X509 structure.
  3986. _Example_
  3987. \code
  3988. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  3989. DYNAMIC_TYPE_X509);
  3990. ...
  3991. int x509SigType = wolfSSL_X509_get_signature_type(x509);
  3992. if(x509SigType != EXPECTED){
  3993. // Deal with an unexpected value
  3994. }
  3995. \endcode
  3996. \sa wolfSSL_X509_get_signature
  3997. \sa wolfSSL_X509_version
  3998. \sa wolfSSL_X509_get_der
  3999. \sa wolfSSL_X509_get_serial_number
  4000. \sa wolfSSL_X509_notBefore
  4001. \sa wolfSSL_X509_notAfter
  4002. \sa wolfSSL_X509_free
  4003. */
  4004. int wolfSSL_X509_get_signature_type(WOLFSSL_X509* cert);
  4005. /*!
  4006. \brief This function frees a WOLFSSL_X509 structure.
  4007. \param x509 a pointer to the WOLFSSL_X509 struct.
  4008. _Example_
  4009. \code
  4010. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALOC(sizeof(WOLFSSL_X509), NULL,
  4011. DYNAMIC_TYPE_X509) ;
  4012. wolfSSL_X509_free(x509);
  4013. \endcode
  4014. \sa wolfSSL_X509_get_signature
  4015. \sa wolfSSL_X509_version
  4016. \sa wolfSSL_X509_get_der
  4017. \sa wolfSSL_X509_get_serial_number
  4018. \sa wolfSSL_X509_notBefore
  4019. \sa wolfSSL_X509_notAfter
  4020. */
  4021. void wolfSSL_X509_free(WOLFSSL_X509* x509);
  4022. /*!
  4023. \ingroup CertsKeys
  4024. \brief Gets the X509 signature and stores it in the buffer.
  4025. \return SSL_SUCCESS returned if the function successfully executes.
  4026. The signature is loaded into the buffer.
  4027. \return SSL_FATAL_ERRROR returns if the x509 struct or the bufSz member
  4028. is NULL. There is also a check for the length member of the sig structure
  4029. (sig is a member of x509).
  4030. \param x509 pointer to a WOLFSSL_X509 structure.
  4031. \param buf a char pointer to the buffer.
  4032. \param bufSz an integer pointer to the size of the buffer.
  4033. _Example_
  4034. \code
  4035. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  4036. DYNAMIC_TYPE_X509);
  4037. unsigned char* buf; // Initialize
  4038. int* bufSz = sizeof(buf)/sizeof(unsigned char);
  4039. ...
  4040. if(wolfSSL_X509_get_signature(x509, buf, bufSz) != SSL_SUCCESS){
  4041. // The function did not execute successfully.
  4042. } else{
  4043. // The buffer was written to correctly.
  4044. }
  4045. \endcode
  4046. \sa wolfSSL_X509_get_serial_number
  4047. \sa wolfSSL_X509_get_signature_type
  4048. \sa wolfSSL_X509_get_device_type
  4049. */
  4050. int wolfSSL_X509_get_signature(WOLFSSL_X509* x509, unsigned char* buf, int* bufSz);
  4051. /*!
  4052. \ingroup CertsKeys
  4053. \brief This function adds a certificate to the WOLFSSL_X509_STRE structure.
  4054. \return SSL_SUCCESS If certificate is added successfully.
  4055. \return SSL_FATAL_ERROR: If certificate is not added successfully.
  4056. \param str certificate store to add the certificate to.
  4057. \param x509 certificate to add.
  4058. _Example_
  4059. \code
  4060. WOLFSSL_X509_STORE* str;
  4061. WOLFSSL_X509* x509;
  4062. int ret;
  4063. ret = wolfSSL_X509_STORE_add_cert(str, x509);
  4064. //check ret value
  4065. \endcode
  4066. \sa wolfSSL_X509_free
  4067. */
  4068. int wolfSSL_X509_STORE_add_cert(WOLFSSL_X509_STORE* store, WOLFSSL_X509* x509);
  4069. /*!
  4070. \ingroup CertsKeys
  4071. \brief This function is a getter function for chain variable
  4072. in WOLFSSL_X509_STORE_CTX structure. Currently chain is not populated.
  4073. \return pointer if successful returns WOLFSSL_STACK
  4074. (same as STACK_OF(WOLFSSL_X509)) pointer
  4075. \return Null upon failure
  4076. \param ctx certificate store ctx to get parse chain from.
  4077. _Example_
  4078. \code
  4079. WOLFSSL_STACK* sk;
  4080. WOLFSSL_X509_STORE_CTX* ctx;
  4081. sk = wolfSSL_X509_STORE_CTX_get_chain(ctx);
  4082. //check sk for NULL and then use it. sk needs freed after done.
  4083. \endcode
  4084. \sa wolfSSL_sk_X509_free
  4085. */
  4086. WOLFSSL_STACK* wolfSSL_X509_STORE_CTX_get_chain(
  4087. WOLFSSL_X509_STORE_CTX* ctx);
  4088. /*!
  4089. \ingroup CertsKeys
  4090. \brief This function takes in a flag to change the behavior of the
  4091. WOLFSSL_X509_STORE structure passed in. An example of a flag used
  4092. is WOLFSSL_CRL_CHECK.
  4093. \return SSL_SUCCESS If no errors were encountered when setting the flag.
  4094. \return <0 a negative value will be returned upon failure.
  4095. \param str certificate store to set flag in.
  4096. \param flag flag for behavior.
  4097. _Example_
  4098. \code
  4099. WOLFSSL_X509_STORE* str;
  4100. int ret;
  4101. // create and set up str
  4102. ret = wolfSSL_X509_STORE_set_flags(str, WOLFSSL_CRL_CHECKALL);
  4103. If (ret != SSL_SUCCESS) {
  4104. //check ret value and handle error case
  4105. }
  4106. \endcode
  4107. \sa wolfSSL_X509_STORE_new
  4108. \sa wolfSSL_X509_STORE_free
  4109. */
  4110. int wolfSSL_X509_STORE_set_flags(WOLFSSL_X509_STORE* store,
  4111. unsigned long flag);
  4112. /*!
  4113. \ingroup CertsKeys
  4114. \brief This function the certificate "not before" validity encoded as
  4115. a byte array.
  4116. \return NULL returned if the WOLFSSL_X509 structure is NULL.
  4117. \return byte is returned that contains the notBeforeData.
  4118. \param x509 pointer to a WOLFSSL_X509 structure.
  4119. _Example_
  4120. \code
  4121. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4122. DYNAMIC_TYPE_X509);
  4123. ...
  4124. byte* notBeforeData = wolfSSL_X509_notBefore(x509);
  4125. \endcode
  4126. \sa wolfSSL_X509_get_signature
  4127. \sa wolfSSL_X509_version
  4128. \sa wolfSSL_X509_get_der
  4129. \sa wolfSSL_X509_get_serial_number
  4130. \sa wolfSSL_X509_notAfter
  4131. \sa wolfSSL_X509_free
  4132. */
  4133. const byte* wolfSSL_X509_notBefore(WOLFSSL_X509* x509);
  4134. /*!
  4135. \ingroup CertsKeys
  4136. \brief This function the certificate "not after" validity encoded as
  4137. a byte array.
  4138. \return NULL returned if the WOLFSSL_X509 structure is NULL.
  4139. \return byte is returned that contains the notAfterData.
  4140. \param x509 pointer to a WOLFSSL_X509 structure.
  4141. _Example_
  4142. \code
  4143. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4144. DYNAMIC_TYPE_X509);
  4145. ...
  4146. byte* notAfterData = wolfSSL_X509_notAfter(x509);
  4147. \endcode
  4148. \sa wolfSSL_X509_get_signature
  4149. \sa wolfSSL_X509_version
  4150. \sa wolfSSL_X509_get_der
  4151. \sa wolfSSL_X509_get_serial_number
  4152. \sa wolfSSL_X509_notBefore
  4153. \sa wolfSSL_X509_free
  4154. */
  4155. const byte* wolfSSL_X509_notAfter(WOLFSSL_X509* x509);
  4156. /*!
  4157. \ingroup Setup
  4158. \brief This function is used to copy a WOLFSSL_ASN1_INTEGER
  4159. value to a WOLFSSL_BIGNUM structure.
  4160. \return pointer On successfully copying the WOLFSSL_ASN1_INTEGER
  4161. value a WOLFSSL_BIGNUM pointer is returned.
  4162. \return Null upon failure.
  4163. \param ai WOLFSSL_ASN1_INTEGER structure to copy from.
  4164. \param bn if wanting to copy into an already existing
  4165. WOLFSSL_BIGNUM struct then pass in a pointer to it.
  4166. Optionally this can be NULL and a new WOLFSSL_BIGNUM
  4167. structure will be created.
  4168. _Example_
  4169. \code
  4170. WOLFSSL_ASN1_INTEGER* ai;
  4171. WOLFSSL_BIGNUM* bn;
  4172. // create ai
  4173. bn = wolfSSL_ASN1_INTEGER_to_BN(ai, NULL);
  4174. // or if having already created bn and wanting to reuse structure
  4175. // wolfSSL_ASN1_INTEGER_to_BN(ai, bn);
  4176. // check bn is or return value is not NULL
  4177. \endcode
  4178. \sa none
  4179. */
  4180. WOLFSSL_BIGNUM *wolfSSL_ASN1_INTEGER_to_BN(const WOLFSSL_ASN1_INTEGER *ai,
  4181. WOLFSSL_BIGNUM *bn);
  4182. /*!
  4183. \ingroup Setup
  4184. \brief This function adds the certificate to the internal chain
  4185. being built in the WOLFSSL_CTX structure.
  4186. \return SSL_SUCCESS after successfully adding the certificate.
  4187. \return SSL_FAILURE if failing to add the certificate to the chain.
  4188. \param ctx WOLFSSL_CTX structure to add certificate to.
  4189. \param x509 certificate to add to the chain.
  4190. _Example_
  4191. \code
  4192. WOLFSSL_CTX* ctx;
  4193. WOLFSSL_X509* x509;
  4194. int ret;
  4195. // create ctx
  4196. ret = wolfSSL_CTX_add_extra_chain_cert(ctx, x509);
  4197. // check ret value
  4198. \endcode
  4199. \sa wolfSSL_CTX_new
  4200. \sa wolfSSL_CTX_free
  4201. */
  4202. long wolfSSL_CTX_add_extra_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509);
  4203. /*!
  4204. \ingroup Setup
  4205. \brief This function returns the get read ahead flag from a
  4206. WOLFSSL_CTX structure.
  4207. \return flag On success returns the read ahead flag.
  4208. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  4209. \param ctx WOLFSSL_CTX structure to get read ahead flag from.
  4210. _Example_
  4211. \code
  4212. WOLFSSL_CTX* ctx;
  4213. int flag;
  4214. // setup ctx
  4215. flag = wolfSSL_CTX_get_read_ahead(ctx);
  4216. //check flag
  4217. \endcode
  4218. \sa wolfSSL_CTX_new
  4219. \sa wolfSSL_CTX_free
  4220. \sa wolfSSL_CTX_set_read_ahead
  4221. */
  4222. int wolfSSL_CTX_get_read_ahead(WOLFSSL_CTX* ctx);
  4223. /*!
  4224. \ingroup Setup
  4225. \brief This function sets the read ahead flag in the WOLFSSL_CTX structure.
  4226. \return SSL_SUCCESS If ctx read ahead flag set.
  4227. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  4228. \param ctx WOLFSSL_CTX structure to set read ahead flag.
  4229. \param v read ahead flag
  4230. _Example_
  4231. \code
  4232. WOLFSSL_CTX* ctx;
  4233. int flag;
  4234. int ret;
  4235. // setup ctx
  4236. ret = wolfSSL_CTX_set_read_ahead(ctx, flag);
  4237. // check return value
  4238. \endcode
  4239. \sa wolfSSL_CTX_new
  4240. \sa wolfSSL_CTX_free
  4241. \sa wolfSSL_CTX_get_read_ahead
  4242. */
  4243. int wolfSSL_CTX_set_read_ahead(WOLFSSL_CTX* ctx, int v);
  4244. /*!
  4245. \ingroup Setup
  4246. \brief This function sets the options argument to use with OCSP.
  4247. \return SSL_FAILURE If ctx or it’s cert manager is NULL.
  4248. \return SSL_SUCCESS If successfully set.
  4249. \param ctx WOLFSSL_CTX structure to set user argument.
  4250. \param arg user argument.
  4251. _Example_
  4252. \code
  4253. WOLFSSL_CTX* ctx;
  4254. void* data;
  4255. int ret;
  4256. // setup ctx
  4257. ret = wolfSSL_CTX_set_tlsext_status_arg(ctx, data);
  4258. //check ret value
  4259. \endcode
  4260. \sa wolfSSL_CTX_new
  4261. \sa wolfSSL_CTX_free
  4262. */
  4263. long wolfSSL_CTX_set_tlsext_status_arg(WOLFSSL_CTX* ctx, void* arg);
  4264. /*!
  4265. \ingroup Setup
  4266. \brief This function sets the optional argument to be passed to
  4267. the PRF callback.
  4268. \return SSL_FAILURE If ctx is NULL.
  4269. \return SSL_SUCCESS If successfully set.
  4270. \param ctx WOLFSSL_CTX structure to set user argument.
  4271. \param arg user argument.
  4272. _Example_
  4273. \code
  4274. WOLFSSL_CTX* ctx;
  4275. void* data;
  4276. int ret;
  4277. // setup ctx
  4278. ret = wolfSSL_CTX_set_tlsext_opaques_prf_input_callback_arg(ctx, data);
  4279. //check ret value
  4280. \endcode
  4281. \sa wolfSSL_CTX_new
  4282. \sa wolfSSL_CTX_free
  4283. */
  4284. long wolfSSL_CTX_set_tlsext_opaque_prf_input_callback_arg(
  4285. WOLFSSL_CTX* ctx, void* arg);
  4286. /*!
  4287. \ingroup Setup
  4288. \brief This function sets the options mask in the ssl.
  4289. Some valid options are, SSL_OP_ALL, SSL_OP_COOKIE_EXCHANGE,
  4290. SSL_OP_NO_SSLv2, SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1,
  4291. SSL_OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_2, SSL_OP_NO_COMPRESSION.
  4292. \return val Returns the updated options mask value stored in ssl.
  4293. \param s WOLFSSL structure to set options mask.
  4294. \param op This function sets the options mask in the ssl.
  4295. Some valid options are:
  4296. SSL_OP_ALL
  4297. SSL_OP_COOKIE_EXCHANGE
  4298. SSL_OP_NO_SSLv2
  4299. SSL_OP_NO_SSLv3
  4300. SSL_OP_NO_TLSv1
  4301. SSL_OP_NO_TLSv1_1
  4302. SSL_OP_NO_TLSv1_2
  4303. SSL_OP_NO_COMPRESSION
  4304. _Example_
  4305. \code
  4306. WOLFSSL* ssl;
  4307. unsigned long mask;
  4308. mask = SSL_OP_NO_TLSv1
  4309. mask = wolfSSL_set_options(ssl, mask);
  4310. // check mask
  4311. \endcode
  4312. \sa wolfSSL_new
  4313. \sa wolfSSL_free
  4314. \sa wolfSSL_get_options
  4315. */
  4316. long wolfSSL_set_options(WOLFSSL *s, long op);
  4317. /*!
  4318. \ingroup Setup
  4319. \brief This function returns the current options mask.
  4320. \return val Returns the mask value stored in ssl.
  4321. \param ssl WOLFSSL structure to get options mask from.
  4322. _Example_
  4323. \code
  4324. WOLFSSL* ssl;
  4325. unsigned long mask;
  4326. mask = wolfSSL_get_options(ssl);
  4327. // check mask
  4328. \endcode
  4329. \sa wolfSSL_new
  4330. \sa wolfSSL_free
  4331. \sa wolfSSL_set_options
  4332. */
  4333. long wolfSSL_get_options(const WOLFSSL *ssl);
  4334. /*!
  4335. \ingroup Setup
  4336. \brief This is used to set the debug argument passed around.
  4337. \return SSL_SUCCESS On successful setting argument.
  4338. \return SSL_FAILURE If an NULL ssl passed in.
  4339. \param ssl WOLFSSL structure to set argument in.
  4340. \param arg argument to use.
  4341. _Example_
  4342. \code
  4343. WOLFSSL* ssl;
  4344. void* args;
  4345. int ret;
  4346. // create ssl object
  4347. ret = wolfSSL_set_tlsext_debug_arg(ssl, args);
  4348. // check ret value
  4349. \endcode
  4350. \sa wolfSSL_new
  4351. \sa wolfSSL_free
  4352. */
  4353. long wolfSSL_set_tlsext_debug_arg(WOLFSSL *ssl, void *arg);
  4354. /*!
  4355. \ingroup openSSL
  4356. \brief This function is called when the client application request
  4357. that a server send back an OCSP status response (also known as
  4358. OCSP stapling).Currently, the only supported type is
  4359. TLSEXT_STATUSTYPE_ocsp.
  4360. \return 1 upon success.
  4361. \return 0 upon error.
  4362. \param s pointer to WOLFSSL struct which is created by SSL_new() function
  4363. \param type ssl extension type which TLSEXT_STATUSTYPE_ocsp is
  4364. only supported.
  4365. _Example_
  4366. \code
  4367. WOLFSSL *ssl;
  4368. WOLFSSL_CTX *ctx;
  4369. int ret;
  4370. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4371. ssl = wolfSSL_new(ctx);
  4372. ret = WolfSSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp);
  4373. wolfSSL_free(ssl);
  4374. wolfSSL_CTX_free(ctx);
  4375. \endcode
  4376. \sa wolfSSL_new
  4377. \sa wolfSSL_CTX_new
  4378. \sa wolfSSL_free
  4379. \sa wolfSSL_CTX_free
  4380. */
  4381. long wolfSSL_set_tlsext_status_type(WOLFSSL *s, int type);
  4382. /*!
  4383. \ingroup Setup
  4384. \brief This is used to get the results after trying to verify the peer's
  4385. certificate.
  4386. \return X509_V_OK On successful verification.
  4387. \return SSL_FAILURE If an NULL ssl passed in.
  4388. \param ssl WOLFSSL structure to get verification results from.
  4389. _Example_
  4390. \code
  4391. WOLFSSL* ssl;
  4392. long ret;
  4393. // attempt/complete handshake
  4394. ret = wolfSSL_get_verify_result(ssl);
  4395. // check ret value
  4396. \endcode
  4397. \sa wolfSSL_new
  4398. \sa wolfSSL_free
  4399. */
  4400. long wolfSSL_get_verify_result(const WOLFSSL *ssl);
  4401. /*!
  4402. \ingroup Debug
  4403. \brief This function converts an error code returned by
  4404. wolfSSL_get_error() into a more human-readable error string
  4405. and prints that string to the output file - fp. err is the
  4406. error code returned by wolfSSL_get_error() and fp is the
  4407. file which the error string will be placed in.
  4408. \return none No returns.
  4409. \param fp output file for human-readable error string to be written to.
  4410. \param err error code returned by wolfSSL_get_error().
  4411. _Example_
  4412. \code
  4413. int err = 0;
  4414. WOLFSSL* ssl;
  4415. FILE* fp = ...
  4416. ...
  4417. err = wolfSSL_get_error(ssl, 0);
  4418. wolfSSL_ERR_print_errors_fp(fp, err);
  4419. \endcode
  4420. \sa wolfSSL_get_error
  4421. \sa wolfSSL_ERR_error_string
  4422. \sa wolfSSL_ERR_error_string_n
  4423. \sa wolfSSL_load_error_strings
  4424. */
  4425. void wolfSSL_ERR_print_errors_fp(XFILE fp, int err);
  4426. /*!
  4427. \ingroup Debug
  4428. \brief This function uses the provided callback to handle error reporting.
  4429. The callback function is executed for each error line. The string, length,
  4430. and userdata are passed into the callback parameters.
  4431. \return none No returns.
  4432. \param cb the callback function.
  4433. \param u userdata to pass into the callback function.
  4434. _Example_
  4435. \code
  4436. int error_cb(const char *str, size_t len, void *u)
  4437. { fprintf((FILE*)u, "%-*.*s\n", (int)len, (int)len, str); return 0; }
  4438. ...
  4439. FILE* fp = ...
  4440. wolfSSL_ERR_print_errors_cb(error_cb, fp);
  4441. \endcode
  4442. \sa wolfSSL_get_error
  4443. \sa wolfSSL_ERR_error_string
  4444. \sa wolfSSL_ERR_error_string_n
  4445. \sa wolfSSL_load_error_strings
  4446. */
  4447. void wolfSSL_ERR_print_errors_cb (
  4448. int (*cb)(const char *str, size_t len, void *u), void *u);
  4449. /*!
  4450. \brief The function sets the client_psk_cb member of the
  4451. WOLFSSL_CTX structure.
  4452. \return none No returns.
  4453. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4454. wolfSSL_CTX_new().
  4455. \param cb wc_psk_client_callback is a function pointer that will be
  4456. stored in the WOLFSSL_CTX structure. Return value is the key length on
  4457. success or zero on error.
  4458. unsigned int (*wc_psk_client_callback)
  4459. PSK client callback parameters:
  4460. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4461. const char* hint - A stored string that could be displayed to provide a
  4462. hint to the user.
  4463. char* identity - The ID will be stored here.
  4464. unsigned int id_max_len - Size of the ID buffer.
  4465. unsigned char* key - The key will be stored here.
  4466. unsigned int key_max_len - The max size of the key.
  4467. _Example_
  4468. \code
  4469. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  4470. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4471. char* identity, unsigned int id_max_len, unsigned char* key,
  4472. Unsigned int key_max_len){
  4473. wolfSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
  4474. \endcode
  4475. \sa wolfSSL_set_psk_client_callback
  4476. \sa wolfSSL_set_psk_server_callback
  4477. \sa wolfSSL_CTX_set_psk_server_callback
  4478. \sa wolfSSL_CTX_set_psk_client_callback
  4479. */
  4480. void wolfSSL_CTX_set_psk_client_callback(WOLFSSL_CTX* ctx,
  4481. wc_psk_client_callback cb);
  4482. /*!
  4483. \brief Sets the PSK client side callback.
  4484. \return none No returns.
  4485. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4486. \param cb a function pointer to type wc_psk_client_callback. Return value
  4487. is the key length on success or zero on error.
  4488. unsigned int (*wc_psk_client_callback)
  4489. PSK client callback parameters:
  4490. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4491. const char* hint - A stored string that could be displayed to provide a
  4492. hint to the user.
  4493. char* identity - The ID will be stored here.
  4494. unsigned int id_max_len - Size of the ID buffer.
  4495. unsigned char* key - The key will be stored here.
  4496. unsigned int key_max_len - The max size of the key.
  4497. _Example_
  4498. \code
  4499. WOLFSSL* ssl;
  4500. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4501. char* identity, unsigned int id_max_len, unsigned char* key,
  4502. Unsigned int key_max_len){
  4503. if(ssl){
  4504. wolfSSL_set_psk_client_callback(ssl, my_psk_client_cb);
  4505. } else {
  4506. // could not set callback
  4507. }
  4508. \endcode
  4509. \sa wolfSSL_CTX_set_psk_client_callback
  4510. \sa wolfSSL_CTX_set_psk_server_callback
  4511. \sa wolfSSL_set_psk_server_callback
  4512. */
  4513. void wolfSSL_set_psk_client_callback(WOLFSSL* ssl,
  4514. wc_psk_client_callback);
  4515. /*!
  4516. \ingroup CertsKeys
  4517. \brief This function returns the psk identity hint.
  4518. \return pointer a const char pointer to the value that was stored in
  4519. the arrays member of the WOLFSSL structure is returned.
  4520. \return NULL returned if the WOLFSSL or Arrays structures are NULL.
  4521. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4522. _Example_
  4523. \code
  4524. WOLFSSL* ssl = wolfSSL_new(ctx);
  4525. char* idHint;
  4526. ...
  4527. idHint = wolfSSL_get_psk_identity_hint(ssl);
  4528. if(idHint){
  4529. // The hint was retrieved
  4530. return idHint;
  4531. } else {
  4532. // Hint wasn’t successfully retrieved
  4533. }
  4534. \endcode
  4535. \sa wolfSSL_get_psk_identity
  4536. */
  4537. const char* wolfSSL_get_psk_identity_hint(const WOLFSSL*);
  4538. /*!
  4539. \ingroup CertsKeys
  4540. \brief The function returns a constant pointer to the client_identity
  4541. member of the Arrays structure.
  4542. \return string the string value of the client_identity member of the
  4543. Arrays structure.
  4544. \return NULL if the WOLFSSL structure is NULL or if the Arrays member of
  4545. the WOLFSSL structure is NULL.
  4546. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4547. _Example_
  4548. \code
  4549. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4550. WOLFSSL* ssl = wolfSSL_new(ctx);
  4551. const char* pskID;
  4552. ...
  4553. pskID = wolfSSL_get_psk_identity(ssl);
  4554. if(pskID == NULL){
  4555. // There is not a value in pskID
  4556. }
  4557. \endcode
  4558. \sa wolfSSL_get_psk_identity_hint
  4559. \sa wolfSSL_use_psk_identity_hint
  4560. */
  4561. const char* wolfSSL_get_psk_identity(const WOLFSSL*);
  4562. /*!
  4563. \ingroup CertsKeys
  4564. \brief This function stores the hint argument in the server_hint
  4565. member of the WOLFSSL_CTX structure.
  4566. \return SSL_SUCCESS returned for successful execution of the function.
  4567. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4568. wolfSSL_CTX_new().
  4569. \param hint a constant char pointer that will be copied to the
  4570. WOLFSSL_CTX structure.
  4571. _Example_
  4572. \code
  4573. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4574. const char* hint;
  4575. int ret;
  4576. ret = wolfSSL_CTX_use_psk_identity_hint(ctx, hint);
  4577. if(ret == SSL_SUCCESS){
  4578. // Function was successful.
  4579. return ret;
  4580. } else {
  4581. // Failure case.
  4582. }
  4583. \endcode
  4584. \sa wolfSSL_use_psk_identity_hint
  4585. */
  4586. int wolfSSL_CTX_use_psk_identity_hint(WOLFSSL_CTX* ctx, const char* hint);
  4587. /*!
  4588. \ingroup CertsKeys
  4589. \brief This function stores the hint argument in the server_hint member
  4590. of the Arrays structure within the WOLFSSL structure.
  4591. \return SSL_SUCCESS returned if the hint was successfully stored in the
  4592. WOLFSSL structure.
  4593. \return SSL_FAILURE returned if the WOLFSSL or Arrays structures are NULL.
  4594. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4595. \param hint a constant character pointer that holds the hint to be saved
  4596. in memory.
  4597. _Example_
  4598. \code
  4599. WOLFSSL* ssl = wolfSSL_new(ctx);
  4600. const char* hint;
  4601. ...
  4602. if(wolfSSL_use_psk_identity_hint(ssl, hint) != SSL_SUCCESS){
  4603. // Handle failure case.
  4604. }
  4605. \endcode
  4606. \sa wolfSSL_CTX_use_psk_identity_hint
  4607. */
  4608. int wolfSSL_use_psk_identity_hint(WOLFSSL* ssl, const char* hint);
  4609. /*!
  4610. \brief This function sets the psk callback for the server side in
  4611. the WOLFSSL_CTX structure.
  4612. \return none No returns.
  4613. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4614. \param cb a function pointer for the callback and will be stored in
  4615. the WOLFSSL_CTX structure. Return value is the key length on success or
  4616. zero on error.
  4617. unsigned int (*wc_psk_server_callback)
  4618. PSK server callback parameters
  4619. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4620. char* identity - The ID will be stored here.
  4621. unsigned char* key - The key will be stored here.
  4622. unsigned int key_max_len - The max size of the key.
  4623. _Example_
  4624. \code
  4625. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4626. WOLFSSL* ssl = wolfSSL_new(ctx);
  4627. static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
  4628. unsigned char* key, unsigned int key_max_len)
  4629. {
  4630. // Function body.
  4631. }
  4632. if(ctx != NULL){
  4633. wolfSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
  4634. } else {
  4635. // The CTX object was not properly initialized.
  4636. }
  4637. \endcode
  4638. \sa wc_psk_server_callback
  4639. \sa wolfSSL_set_psk_client_callback
  4640. \sa wolfSSL_set_psk_server_callback
  4641. \sa wolfSSL_CTX_set_psk_client_callback
  4642. */
  4643. void wolfSSL_CTX_set_psk_server_callback(WOLFSSL_CTX* ctx,
  4644. wc_psk_server_callback cb);
  4645. /*!
  4646. \brief Sets the psk callback for the server side by setting the
  4647. WOLFSSL structure options members.
  4648. \return none No returns.
  4649. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4650. \param cb a function pointer for the callback and will be stored in
  4651. the WOLFSSL structure. Return value is the key length on success or zero
  4652. on error.
  4653. unsigned int (*wc_psk_server_callback)
  4654. PSK server callback parameters
  4655. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4656. char* identity - The ID will be stored here.
  4657. unsigned char* key - The key will be stored here.
  4658. unsigned int key_max_len - The max size of the key.
  4659. _Example_
  4660. \code
  4661. WOLFSSL_CTX* ctx;
  4662. WOLFSSL* ssl;
  4663. static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
  4664. unsigned char* key, unsigned int key_max_len)
  4665. {
  4666. // Function body.
  4667. }
  4668. if(ssl != NULL && cb != NULL){
  4669. wolfSSL_set_psk_server_callback(ssl, my_psk_server_cb);
  4670. }
  4671. \endcode
  4672. \sa wolfSSL_set_psk_client_callback
  4673. \sa wolfSSL_CTX_set_psk_server_callback
  4674. \sa wolfSSL_CTX_set_psk_client_callback
  4675. \sa wolfSSL_get_psk_identity_hint
  4676. \sa wc_psk_server_callback
  4677. \sa InitSuites
  4678. */
  4679. void wolfSSL_set_psk_server_callback(WOLFSSL* ssl,
  4680. wc_psk_server_callback cb);
  4681. /*!
  4682. \brief Sets a PSK user context in the WOLFSSL structure options member.
  4683. \return WOLFSSL_SUCCESS or WOLFSSL_FAILURE
  4684. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4685. \param psk_ctx void pointer to user PSK context
  4686. \sa wolfSSL_get_psk_callback_ctx
  4687. \sa wolfSSL_CTX_set_psk_callback_ctx
  4688. \sa wolfSSL_CTX_get_psk_callback_ctx
  4689. */
  4690. int wolfSSL_set_psk_callback_ctx(WOLFSSL* ssl, void* psk_ctx);
  4691. /*!
  4692. \brief Sets a PSK user context in the WOLFSSL_CTX structure.
  4693. \return WOLFSSL_SUCCESS or WOLFSSL_FAILURE
  4694. \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
  4695. \param psk_ctx void pointer to user PSK context
  4696. \sa wolfSSL_set_psk_callback_ctx
  4697. \sa wolfSSL_get_psk_callback_ctx
  4698. \sa wolfSSL_CTX_get_psk_callback_ctx
  4699. */
  4700. int wolfSSL_CTX_set_psk_callback_ctx(WOLFSSL_CTX* ctx, void* psk_ctx);
  4701. /*!
  4702. \brief Get a PSK user context in the WOLFSSL structure options member.
  4703. \return void pointer to user PSK context
  4704. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4705. \sa wolfSSL_set_psk_callback_ctx
  4706. \sa wolfSSL_CTX_set_psk_callback_ctx
  4707. \sa wolfSSL_CTX_get_psk_callback_ctx
  4708. */
  4709. void* wolfSSL_get_psk_callback_ctx(WOLFSSL* ssl);
  4710. /*!
  4711. \brief Get a PSK user context in the WOLFSSL_CTX structure.
  4712. \return void pointer to user PSK context
  4713. \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
  4714. \sa wolfSSL_CTX_set_psk_callback_ctx
  4715. \sa wolfSSL_set_psk_callback_ctx
  4716. \sa wolfSSL_get_psk_callback_ctx
  4717. */
  4718. void* wolfSSL_CTX_get_psk_callback_ctx(WOLFSSL_CTX* ctx);
  4719. /*!
  4720. \ingroup Setup
  4721. \brief This function enables the havAnon member of the CTX structure if
  4722. HAVE_ANON is defined during compilation.
  4723. \return SSL_SUCCESS returned if the function executed successfully and the
  4724. haveAnnon member of the CTX is set to 1.
  4725. \return SSL_FAILURE returned if the CTX structure was NULL.
  4726. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4727. wolfSSL_CTX_new().
  4728. _Example_
  4729. \code
  4730. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4731. WOLFSSL* ssl = wolfSSL_new(ctx);
  4732. ...
  4733. #ifdef HAVE_ANON
  4734. if(cipherList == NULL){
  4735. wolfSSL_CTX_allow_anon_cipher(ctx);
  4736. if(wolfSSL_CTX_set_cipher_list(ctx, “ADH_AES128_SHA”) != SSL_SUCCESS){
  4737. // failure case
  4738. }
  4739. }
  4740. #endif
  4741. \endcode
  4742. \sa none
  4743. */
  4744. int wolfSSL_CTX_allow_anon_cipher(WOLFSSL_CTX*);
  4745. /*!
  4746. \ingroup Setup
  4747. \brief The wolfSSLv23_server_method() function is used to indicate
  4748. that the application is a server and will support clients connecting
  4749. with protocol version from SSL 3.0 - TLS 1.3. This function allocates
  4750. memory for and initializes a new WOLFSSL_METHOD structure to be used when
  4751. creating the SSL/TLS context with wolfSSL_CTX_new().
  4752. \return pointer If successful, the call will return a pointer to the newly
  4753. created WOLFSSL_METHOD structure.
  4754. \return Failure If memory allocation fails when calling XMALLOC, the
  4755. failure value of the underlying malloc() implementation will be returned
  4756. (typically NULL with errno will be set to ENOMEM).
  4757. \param none No parameters
  4758. _Example_
  4759. \code
  4760. WOLFSSL_METHOD* method;
  4761. WOLFSSL_CTX* ctx;
  4762. method = wolfSSLv23_server_method();
  4763. if (method == NULL) {
  4764. // unable to get method
  4765. }
  4766. ctx = wolfSSL_CTX_new(method);
  4767. ...
  4768. \endcode
  4769. \sa wolfSSLv3_server_method
  4770. \sa wolfTLSv1_server_method
  4771. \sa wolfTLSv1_1_server_method
  4772. \sa wolfTLSv1_2_server_method
  4773. \sa wolfTLSv1_3_server_method
  4774. \sa wolfDTLSv1_server_method
  4775. \sa wolfSSL_CTX_new
  4776. */
  4777. WOLFSSL_METHOD *wolfSSLv23_server_method(void);
  4778. /*!
  4779. \ingroup Setup
  4780. \brief This is used to get the internal error state of the WOLFSSL structure.
  4781. \return wolfssl_error returns ssl error state, usually a negative
  4782. \return BAD_FUNC_ARG if ssl is NULL.
  4783. \return ssl WOLFSSL structure to get state from.
  4784. _Example_
  4785. \code
  4786. WOLFSSL* ssl;
  4787. int ret;
  4788. // create ssl object
  4789. ret = wolfSSL_state(ssl);
  4790. // check ret value
  4791. \endcode
  4792. \sa wolfSSL_new
  4793. \sa wolfSSL_free
  4794. */
  4795. int wolfSSL_state(WOLFSSL* ssl);
  4796. /*!
  4797. \ingroup CertsKeys
  4798. \brief This function gets the peer’s certificate.
  4799. \return pointer a pointer to the peerCert member of the WOLFSSL_X509
  4800. structure if it exists.
  4801. \return 0 returned if the peer certificate issuer size is not defined.
  4802. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4803. _Example_
  4804. \code
  4805. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4806. WOLFSSL* ssl = wolfSSL_new(ctx);
  4807. ...
  4808. WOLFSSL_X509* peerCert = wolfSSL_get_peer_certificate(ssl);
  4809. if(peerCert){
  4810. // You have a pointer peerCert to the peer certification
  4811. }
  4812. \endcode
  4813. \sa wolfSSL_X509_get_issuer_name
  4814. \sa wolfSSL_X509_get_subject_name
  4815. \sa wolfSSL_X509_get_isCA
  4816. */
  4817. WOLFSSL_X509* wolfSSL_get_peer_certificate(WOLFSSL* ssl);
  4818. /*!
  4819. \ingroup Debug
  4820. \brief This function is similar to calling wolfSSL_get_error() and
  4821. getting SSL_ERROR_WANT_READ in return. If the underlying error state
  4822. is SSL_ERROR_WANT_READ, this function will return 1, otherwise, 0.
  4823. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_READ, the
  4824. underlying I/O has data available for reading.
  4825. \return 0 There is no SSL_ERROR_WANT_READ error state.
  4826. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4827. _Example_
  4828. \code
  4829. int ret;
  4830. WOLFSSL* ssl = 0;
  4831. ...
  4832. ret = wolfSSL_want_read(ssl);
  4833. if (ret == 1) {
  4834. // underlying I/O has data available for reading (SSL_ERROR_WANT_READ)
  4835. }
  4836. \endcode
  4837. \sa wolfSSL_want_write
  4838. \sa wolfSSL_get_error
  4839. */
  4840. int wolfSSL_want_read(WOLFSSL*);
  4841. /*!
  4842. \ingroup Debug
  4843. \brief This function is similar to calling wolfSSL_get_error() and getting
  4844. SSL_ERROR_WANT_WRITE in return. If the underlying error state is
  4845. SSL_ERROR_WANT_WRITE, this function will return 1, otherwise, 0.
  4846. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_WRITE, the
  4847. underlying I/O needs data to be written in order for progress to be
  4848. made in the underlying SSL connection.
  4849. \return 0 There is no SSL_ERROR_WANT_WRITE error state.
  4850. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4851. _Example_
  4852. \code
  4853. int ret;
  4854. WOLFSSL* ssl = 0;
  4855. ...
  4856. ret = wolfSSL_want_write(ssl);
  4857. if (ret == 1) {
  4858. // underlying I/O needs data to be written (SSL_ERROR_WANT_WRITE)
  4859. }
  4860. \endcode
  4861. \sa wolfSSL_want_read
  4862. \sa wolfSSL_get_error
  4863. */
  4864. int wolfSSL_want_write(WOLFSSL*);
  4865. /*!
  4866. \ingroup Setup
  4867. \brief wolfSSL by default checks the peer certificate for a valid date
  4868. range and a verified signature. Calling this function before
  4869. wolfSSL_connect() or wolfSSL_accept() will add a domain name check to
  4870. the list of checks to perform. dn holds the domain name to check
  4871. against the peer certificate when it’s received.
  4872. \return SSL_SUCCESS upon success.
  4873. \return SSL_FAILURE will be returned if a memory error was encountered.
  4874. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4875. \param dn domain name to check against the peer certificate when received.
  4876. _Example_
  4877. \code
  4878. int ret = 0;
  4879. WOLFSSL* ssl;
  4880. char* domain = (char*) “www.yassl.com”;
  4881. ...
  4882. ret = wolfSSL_check_domain_name(ssl, domain);
  4883. if (ret != SSL_SUCCESS) {
  4884. // failed to enable domain name check
  4885. }
  4886. \endcode
  4887. \sa none
  4888. */
  4889. int wolfSSL_check_domain_name(WOLFSSL* ssl, const char* dn);
  4890. /*!
  4891. \ingroup TLS
  4892. \brief Initializes the wolfSSL library for use. Must be called once per
  4893. application and before any other call to the library.
  4894. \return SSL_SUCCESS If successful the call will return.
  4895. \return BAD_MUTEX_E is an error that may be returned.
  4896. \return WC_INIT_E wolfCrypt initialization error returned.
  4897. _Example_
  4898. \code
  4899. int ret = 0;
  4900. ret = wolfSSL_Init();
  4901. if (ret != SSL_SUCCESS) {
  4902. failed to initialize wolfSSL library
  4903. }
  4904. \endcode
  4905. \sa wolfSSL_Cleanup
  4906. */
  4907. int wolfSSL_Init(void);
  4908. /*!
  4909. \ingroup TLS
  4910. \brief Un-initializes the wolfSSL library from further use. Doesn’t have
  4911. to be called, though it will free any resources used by the library.
  4912. \return SSL_SUCCESS return no errors.
  4913. \return BAD_MUTEX_E a mutex error return.]
  4914. _Example_
  4915. \code
  4916. wolfSSL_Cleanup();
  4917. \endcode
  4918. \sa wolfSSL_Init
  4919. */
  4920. int wolfSSL_Cleanup(void);
  4921. /*!
  4922. \ingroup IO
  4923. \brief This function returns the current library version.
  4924. \return LIBWOLFSSL_VERSION_STRING a const char pointer defining the
  4925. version.
  4926. \param none No parameters.
  4927. _Example_
  4928. \code
  4929. char version[MAXSIZE];
  4930. version = wolfSSL_KeepArrays();
  4931. if(version != ExpectedVersion){
  4932. // Handle the mismatch case
  4933. }
  4934. \endcode
  4935. \sa word32_wolfSSL_lib_version_hex
  4936. */
  4937. const char* wolfSSL_lib_version(void);
  4938. /*!
  4939. \ingroup IO
  4940. \brief This function returns the current library version in hexadecimal
  4941. notation.
  4942. \return LILBWOLFSSL_VERSION_HEX returns the hexadecimal version defined in
  4943. wolfssl/version.h.
  4944. \param none No parameters.
  4945. _Example_
  4946. \code
  4947. word32 libV;
  4948. libV = wolfSSL_lib_version_hex();
  4949. if(libV != EXPECTED_HEX){
  4950. // How to handle an unexpected value
  4951. } else {
  4952. // The expected result for libV
  4953. }
  4954. \endcode
  4955. \sa wolfSSL_lib_version
  4956. */
  4957. word32 wolfSSL_lib_version_hex(void);
  4958. /*!
  4959. \ingroup IO
  4960. \brief Performs the actual connect or accept based on the side of the SSL
  4961. method. If called from the client side then an wolfSSL_connect() is done
  4962. while a wolfSSL_accept() is performed if called from the server side.
  4963. \return SSL_SUCCESS will be returned if successful. (Note, older versions
  4964. will return 0.)
  4965. \return SSL_FATAL_ERROR will be returned if the underlying call resulted
  4966. in an error. Use wolfSSL_get_error() to get a specific error code.
  4967. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4968. _Example_
  4969. \code
  4970. int ret = SSL_FATAL_ERROR;
  4971. WOLFSSL* ssl = 0;
  4972. ...
  4973. ret = wolfSSL_negotiate(ssl);
  4974. if (ret == SSL_FATAL_ERROR) {
  4975. // SSL establishment failed
  4976. int error_code = wolfSSL_get_error(ssl);
  4977. ...
  4978. }
  4979. ...
  4980. \endcode
  4981. \sa SSL_connect
  4982. \sa SSL_accept
  4983. */
  4984. int wolfSSL_negotiate(WOLFSSL* ssl);
  4985. /*!
  4986. \ingroup Setup
  4987. \brief Turns on the ability to use compression for the SSL connection.
  4988. Both sides must have compression turned on otherwise compression will not be
  4989. used. The zlib library performs the actual data compression. To compile
  4990. into the library use --with-libz for the configure system and define
  4991. HAVE_LIBZ otherwise. Keep in mind that while compressing data before
  4992. sending decreases the actual size of the messages being sent and received,
  4993. the amount of data saved by compression usually takes longer in time to
  4994. analyze than it does to send it raw on all but the slowest of networks.
  4995. \return SSL_SUCCESS upon success.
  4996. \return NOT_COMPILED_IN will be returned if compression support wasn’t
  4997. built into the library.
  4998. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4999. _Example_
  5000. \code
  5001. int ret = 0;
  5002. WOLFSSL* ssl = 0;
  5003. ...
  5004. ret = wolfSSL_set_compression(ssl);
  5005. if (ret == SSL_SUCCESS) {
  5006. // successfully enabled compression for SSL session
  5007. }
  5008. \endcode
  5009. \sa none
  5010. */
  5011. int wolfSSL_set_compression(WOLFSSL* ssl);
  5012. /*!
  5013. \ingroup Setup
  5014. \brief This function sets the SSL session timeout value in seconds.
  5015. \return SSL_SUCCESS will be returned upon successfully setting the session.
  5016. \return BAD_FUNC_ARG will be returned if ssl is NULL.
  5017. \param ssl pointer to the SSL object, created with wolfSSL_new().
  5018. \param to value, in seconds, used to set the SSL session timeout.
  5019. _Example_
  5020. \code
  5021. int ret = 0;
  5022. WOLFSSL* ssl = 0;
  5023. ...
  5024. ret = wolfSSL_set_timeout(ssl, 500);
  5025. if (ret != SSL_SUCCESS) {
  5026. // failed to set session timeout value
  5027. }
  5028. ...
  5029. \endcode
  5030. \sa wolfSSL_get1_session
  5031. \sa wolfSSL_set_session
  5032. */
  5033. int wolfSSL_set_timeout(WOLFSSL* ssl, unsigned int to);
  5034. /*!
  5035. \ingroup Setup
  5036. \brief This function sets the timeout value for SSL sessions, in seconds,
  5037. for the specified SSL context.
  5038. \return the previous timeout value, if WOLFSSL_ERROR_CODE_OPENSSL is
  5039. \return defined on success. If not defined, SSL_SUCCESS will be returned.
  5040. \return BAD_FUNC_ARG will be returned when the input context (ctx) is null.
  5041. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5042. \param to session timeout value in seconds.
  5043. _Example_
  5044. \code
  5045. WOLFSSL_CTX* ctx = 0;
  5046. ...
  5047. ret = wolfSSL_CTX_set_timeout(ctx, 500);
  5048. if (ret != SSL_SUCCESS) {
  5049. // failed to set session timeout value
  5050. }
  5051. \endcode
  5052. \sa wolfSSL_flush_sessions
  5053. \sa wolfSSL_get1_session
  5054. \sa wolfSSL_set_session
  5055. \sa wolfSSL_get_sessionID
  5056. \sa wolfSSL_CTX_set_session_cache_mode
  5057. */
  5058. int wolfSSL_CTX_set_timeout(WOLFSSL_CTX* ctx, unsigned int to);
  5059. /*!
  5060. \ingroup openSSL
  5061. \brief Retrieves the peer’s certificate chain.
  5062. \return chain If successful the call will return the peer’s
  5063. certificate chain.
  5064. \return 0 will be returned if an invalid WOLFSSL pointer is passed to the
  5065. function.
  5066. \param ssl pointer to a valid WOLFSSL structure.
  5067. _Example_
  5068. \code
  5069. none
  5070. \endcode
  5071. \sa wolfSSL_get_chain_count
  5072. \sa wolfSSL_get_chain_length
  5073. \sa wolfSSL_get_chain_cert
  5074. \sa wolfSSL_get_chain_cert_pem
  5075. */
  5076. WOLFSSL_X509_CHAIN* wolfSSL_get_peer_chain(WOLFSSL* ssl);
  5077. /*!
  5078. \ingroup openSSL
  5079. \brief Retrieve's the peers certificate chain count.
  5080. \return Success If successful the call will return the peer’s certificate
  5081. chain count.
  5082. \return 0 will be returned if an invalid chain pointer is passed to
  5083. the function.
  5084. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5085. _Example_
  5086. \code
  5087. none
  5088. \endcode
  5089. \sa wolfSSL_get_peer_chain
  5090. \sa wolfSSL_get_chain_length
  5091. \sa wolfSSL_get_chain_cert
  5092. \sa wolfSSL_get_chain_cert_pem
  5093. */
  5094. int wolfSSL_get_chain_count(WOLFSSL_X509_CHAIN* chain);
  5095. /*!
  5096. \ingroup openSSL
  5097. \brief Retrieves the peer’s ASN1.DER certificate length in bytes
  5098. at index (idx).
  5099. \return Success If successful the call will return the peer’s
  5100. certificate length in bytes by index.
  5101. \return 0 will be returned if an invalid chain pointer is passed
  5102. to the function.
  5103. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5104. \param idx index to start of chain.
  5105. _Example_
  5106. \code
  5107. none
  5108. \endcode
  5109. \sa wolfSSL_get_peer_chain
  5110. \sa wolfSSL_get_chain_count
  5111. \sa wolfSSL_get_chain_cert
  5112. \sa wolfSSL_get_chain_cert_pem
  5113. */
  5114. int wolfSSL_get_chain_length(WOLFSSL_X509_CHAIN* chain, int idx);
  5115. /*!
  5116. \ingroup openSSL
  5117. \brief Retrieves the peer’s ASN1.DER certificate at index (idx).
  5118. \return Success If successful the call will return the peer’s
  5119. certificate by index.
  5120. \return 0 will be returned if an invalid chain pointer is passed
  5121. to the function.
  5122. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5123. \param idx index to start of chain.
  5124. _Example_
  5125. \code
  5126. none
  5127. \endcode
  5128. \sa wolfSSL_get_peer_chain
  5129. \sa wolfSSL_get_chain_count
  5130. \sa wolfSSL_get_chain_length
  5131. \sa wolfSSL_get_chain_cert_pem
  5132. */
  5133. unsigned char* wolfSSL_get_chain_cert(WOLFSSL_X509_CHAIN* chain, int idx);
  5134. /*!
  5135. \ingroup CertsKeys
  5136. \brief This function gets the peer’s wolfSSL_X509_certificate at
  5137. index (idx) from the chain of certificates.
  5138. \return pointer returns a pointer to a WOLFSSL_X509 structure.
  5139. \param chain a pointer to the WOLFSSL_X509_CHAIN used for no dynamic
  5140. memory SESSION_CACHE.
  5141. \param idx the index of the WOLFSSL_X509 certificate.
  5142. Note that it is the user's responsibility to free the returned memory
  5143. by calling wolfSSL_FreeX509().
  5144. _Example_
  5145. \code
  5146. WOLFSSL_X509_CHAIN* chain = &session->chain;
  5147. int idx = 999; // set idx
  5148. ...
  5149. WOLFSSL_X509_CHAIN ptr;
  5150. prt = wolfSSL_get_chain_X509(chain, idx);
  5151. if(ptr != NULL){
  5152. // ptr contains the cert at the index specified
  5153. wolfSSL_FreeX509(ptr);
  5154. } else {
  5155. // ptr is NULL
  5156. }
  5157. \endcode
  5158. \sa InitDecodedCert
  5159. \sa ParseCertRelative
  5160. \sa CopyDecodedToX509
  5161. */
  5162. WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx);
  5163. /*!
  5164. \ingroup openSSL
  5165. \brief Retrieves the peer’s PEM certificate at index (idx).
  5166. \return Success If successful the call will return the peer’s
  5167. certificate by index.
  5168. \return 0 will be returned if an invalid chain pointer is passed to
  5169. the function.
  5170. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5171. \param idx indexto start of chain.
  5172. _Example_
  5173. \code
  5174. none
  5175. \endcode
  5176. \sa wolfSSL_get_peer_chain
  5177. \sa wolfSSL_get_chain_count
  5178. \sa wolfSSL_get_chain_length
  5179. \sa wolfSSL_get_chain_cert
  5180. */
  5181. int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN* chain, int idx,
  5182. unsigned char* buf, int inLen, int* outLen);
  5183. /*!
  5184. \ingroup openSSL
  5185. \brief Retrieves the session’s ID. The session ID is always 32 bytes long.
  5186. \return id The session ID.
  5187. \param session pointer to a valid wolfssl session.
  5188. _Example_
  5189. \code
  5190. none
  5191. \endcode
  5192. \sa SSL_get_session
  5193. */
  5194. const unsigned char* wolfSSL_get_sessionID(const WOLFSSL_SESSION* s);
  5195. /*!
  5196. \ingroup openSSL
  5197. \brief Retrieves the peer’s certificate serial number. The serial
  5198. number buffer (in) should be at least 32 bytes long and be provided
  5199. as the *inOutSz argument as input. After calling the function *inOutSz
  5200. will hold the actual length in bytes written to the in buffer.
  5201. \return SSL_SUCCESS upon success.
  5202. \return BAD_FUNC_ARG will be returned if a bad function argument
  5203. was encountered.
  5204. \param in The serial number buffer and should be at least 32 bytes long
  5205. \param inOutSz will hold the actual length in bytes written to the
  5206. in buffer.
  5207. _Example_
  5208. \code
  5209. none
  5210. \endcode
  5211. \sa SSL_get_peer_certificate
  5212. */
  5213. int wolfSSL_X509_get_serial_number(WOLFSSL_X509* x509, unsigned char* in,
  5214. int* inOutSz);
  5215. /*!
  5216. \ingroup CertsKeys
  5217. \brief Returns the common name of the subject from the certificate.
  5218. \return NULL returned if the x509 structure is null
  5219. \return string a string representation of the subject's common
  5220. name is returned upon success
  5221. \param x509 a pointer to a WOLFSSL_X509 structure containing
  5222. certificate information.
  5223. _Example_
  5224. \code
  5225. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5226. DYNAMIC_TYPE_X509);
  5227. ...
  5228. int x509Cn = wolfSSL_X509_get_subjectCN(x509);
  5229. if(x509Cn == NULL){
  5230. // Deal with NULL case
  5231. } else {
  5232. // x509Cn contains the common name
  5233. }
  5234. \endcode
  5235. \sa wolfSSL_X509_Name_get_entry
  5236. \sa wolfSSL_X509_get_next_altname
  5237. \sa wolfSSL_X509_get_issuer_name
  5238. \sa wolfSSL_X509_get_subject_name
  5239. */
  5240. char* wolfSSL_X509_get_subjectCN(WOLFSSL_X509*);
  5241. /*!
  5242. \ingroup CertsKeys
  5243. \brief This function gets the DER encoded certificate in the
  5244. WOLFSSL_X509 struct.
  5245. \return buffer This function returns the DerBuffer structure’s
  5246. buffer member, which is of type byte.
  5247. \return NULL returned if the x509 or outSz parameter is NULL.
  5248. \param x509 a pointer to a WOLFSSL_X509 structure containing
  5249. certificate information.
  5250. \param outSz length of the derBuffer member of the WOLFSSL_X509 struct.
  5251. _Example_
  5252. \code
  5253. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5254. DYNAMIC_TYPE_X509);
  5255. int* outSz; // initialize
  5256. ...
  5257. byte* x509Der = wolfSSL_X509_get_der(x509, outSz);
  5258. if(x509Der == NULL){
  5259. // Failure case one of the parameters was NULL
  5260. }
  5261. \endcode
  5262. \sa wolfSSL_X509_version
  5263. \sa wolfSSL_X509_Name_get_entry
  5264. \sa wolfSSL_X509_get_next_altname
  5265. \sa wolfSSL_X509_get_issuer_name
  5266. \sa wolfSSL_X509_get_subject_name
  5267. */
  5268. const unsigned char* wolfSSL_X509_get_der(WOLFSSL_X509* x509, int* outSz);
  5269. /*!
  5270. \ingroup CertsKeys
  5271. \brief This function checks to see if x509 is NULL and if it’s not,
  5272. it returns the notAfter member of the x509 struct.
  5273. \return pointer to struct with ASN1_TIME to the notAfter
  5274. member of the x509 struct.
  5275. \return NULL returned if the x509 object is NULL.
  5276. \param x509 a pointer to the WOLFSSL_X509 struct.
  5277. _Example_
  5278. \code
  5279. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  5280. DYNAMIC_TYPE_X509) ;
  5281. ...
  5282. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notAfter(x509);
  5283. if(notAfter == NULL){
  5284. // Failure case, the x509 object is null.
  5285. }
  5286. \endcode
  5287. \sa wolfSSL_X509_get_notBefore
  5288. */
  5289. WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notAfter(WOLFSSL_X509*);
  5290. /*!
  5291. \ingroup CertsKeys
  5292. \brief This function retrieves the version of the X509 certificate.
  5293. \return 0 returned if the x509 structure is NULL.
  5294. \return version the version stored in the x509 structure will be returned.
  5295. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5296. _Example_
  5297. \code
  5298. WOLFSSL_X509* x509;
  5299. int version;
  5300. ...
  5301. version = wolfSSL_X509_version(x509);
  5302. if(!version){
  5303. // The function returned 0, failure case.
  5304. }
  5305. \endcode
  5306. \sa wolfSSL_X509_get_subject_name
  5307. \sa wolfSSL_X509_get_issuer_name
  5308. \sa wolfSSL_X509_get_isCA
  5309. \sa wolfSSL_get_peer_certificate
  5310. */
  5311. int wolfSSL_X509_version(WOLFSSL_X509*);
  5312. /*!
  5313. \ingroup CertsKeys
  5314. \brief If NO_STDIO_FILESYSTEM is defined this function will allocate
  5315. heap memory, initialize a WOLFSSL_X509 structure and return a pointer to it.
  5316. \return *WOLFSSL_X509 WOLFSSL_X509 structure pointer is returned if
  5317. the function executes successfully.
  5318. \return NULL if the call to XFTELL macro returns a negative value.
  5319. \param x509 a pointer to a WOLFSSL_X509 pointer.
  5320. \param file a defined type that is a pointer to a FILE.
  5321. _Example_
  5322. \code
  5323. WOLFSSL_X509* x509a = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5324. DYNAMIC_TYPE_X509);
  5325. WOLFSSL_X509** x509 = x509a;
  5326. XFILE file; (mapped to struct fs_file*)
  5327. ...
  5328. WOLFSSL_X509* newX509 = wolfSSL_X509_d2i_fp(x509, file);
  5329. if(newX509 == NULL){
  5330. // The function returned NULL
  5331. }
  5332. \endcode
  5333. \sa wolfSSL_X509_d2i
  5334. \sa XFTELL
  5335. \sa XREWIND
  5336. \sa XFSEEK
  5337. */
  5338. WOLFSSL_X509*
  5339. wolfSSL_X509_d2i_fp(WOLFSSL_X509** x509, FILE* file);
  5340. /*!
  5341. \ingroup CertsKeys
  5342. \brief The function loads the x509 certificate into memory.
  5343. \return pointer a successful execution returns pointer to a
  5344. WOLFSSL_X509 structure.
  5345. \return NULL returned if the certificate was not able to be written.
  5346. \param fname the certificate file to be loaded.
  5347. \param format the format of the certificate.
  5348. _Example_
  5349. \code
  5350. #define cliCert “certs/client-cert.pem”
  5351. X509* x509;
  5352. x509 = wolfSSL_X509_load_certificate_file(cliCert, SSL_FILETYPE_PEM);
  5353. AssertNotNull(x509);
  5354. \endcode
  5355. \sa InitDecodedCert
  5356. \sa PemToDer
  5357. \sa wolfSSL_get_certificate
  5358. \sa AssertNotNull
  5359. */
  5360. WOLFSSL_X509*
  5361. wolfSSL_X509_load_certificate_file(const char* fname, int format);
  5362. /*!
  5363. \ingroup CertsKeys
  5364. \brief This function copies the device type from the x509 structure
  5365. to the buffer.
  5366. \return pointer returns a byte pointer holding the device type from
  5367. the x509 structure.
  5368. \return NULL returned if the buffer size is NULL.
  5369. \param x509 pointer to a WOLFSSL_X509 structure, created with
  5370. WOLFSSL_X509_new().
  5371. \param in a pointer to a byte type that will hold the device type
  5372. (the buffer).
  5373. \param inOutSz the minimum of either the parameter inOutSz or the
  5374. deviceTypeSz member of the x509 structure.
  5375. _Example_
  5376. \code
  5377. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  5378. DYNAMIC_TYPE_X509);
  5379. byte* in;
  5380. int* inOutSz;
  5381. ...
  5382. byte* deviceType = wolfSSL_X509_get_device_type(x509, in, inOutSz);
  5383. if(!deviceType){
  5384. // Failure case, NULL was returned.
  5385. }
  5386. \endcode
  5387. \sa wolfSSL_X509_get_hw_type
  5388. \sa wolfSSL_X509_get_hw_serial_number
  5389. \sa wolfSSL_X509_d2i
  5390. */
  5391. unsigned char*
  5392. wolfSSL_X509_get_device_type(WOLFSSL_X509* x509, unsigned char* in,
  5393. int* inOutSz);
  5394. /*!
  5395. \ingroup CertsKeys
  5396. \brief The function copies the hwType member of the WOLFSSL_X509
  5397. structure to the buffer.
  5398. \return byte The function returns a byte type of the data previously held
  5399. in the hwType member of the WOLFSSL_X509 structure.
  5400. \return NULL returned if inOutSz is NULL.
  5401. \param x509 a pointer to a WOLFSSL_X509 structure containing certificate
  5402. information.
  5403. \param in pointer to type byte that represents the buffer.
  5404. \param inOutSz pointer to type int that represents the size of the buffer.
  5405. _Example_
  5406. \code
  5407. WOLFSSL_X509* x509; // X509 certificate
  5408. byte* in; // initialize the buffer
  5409. int* inOutSz; // holds the size of the buffer
  5410. ...
  5411. byte* hwType = wolfSSL_X509_get_hw_type(x509, in, inOutSz);
  5412. if(hwType == NULL){
  5413. // Failure case function returned NULL.
  5414. }
  5415. \endcode
  5416. \sa wolfSSL_X509_get_hw_serial_number
  5417. \sa wolfSSL_X509_get_device_type
  5418. */
  5419. unsigned char*
  5420. wolfSSL_X509_get_hw_type(WOLFSSL_X509* x509, unsigned char* in,
  5421. int* inOutSz);
  5422. /*!
  5423. \ingroup CertsKeys
  5424. \brief This function returns the hwSerialNum member of the x509 object.
  5425. \return pointer the function returns a byte pointer to the in buffer that
  5426. will contain the serial number loaded from the x509 object.
  5427. \param x509 pointer to a WOLFSSL_X509 structure containing certificate
  5428. information.
  5429. \param in a pointer to the buffer that will be copied to.
  5430. \param inOutSz a pointer to the size of the buffer.
  5431. _Example_
  5432. \code
  5433. char* serial;
  5434. byte* in;
  5435. int* inOutSz;
  5436. WOLFSSL_X509 x509;
  5437. ...
  5438. serial = wolfSSL_X509_get_hw_serial_number(x509, in, inOutSz);
  5439. if(serial == NULL || serial <= 0){
  5440. // Failure case
  5441. }
  5442. \endcode
  5443. \sa wolfSSL_X509_get_subject_name
  5444. \sa wolfSSL_X509_get_issuer_name
  5445. \sa wolfSSL_X509_get_isCA
  5446. \sa wolfSSL_get_peer_certificate
  5447. \sa wolfSSL_X509_version
  5448. */
  5449. unsigned char*
  5450. wolfSSL_X509_get_hw_serial_number(WOLFSSL_X509* x509,
  5451. unsigned char* in, int* inOutSz);
  5452. /*!
  5453. \ingroup IO
  5454. \brief This function is called on the client side and initiates an
  5455. SSL/TLS handshake with a server only long enough to get the peer’s
  5456. certificate chain. When this function is called, the underlying
  5457. communication channel has already been set up. wolfSSL_connect_cert()
  5458. works with both blocking and non-blocking I/O. When the underlying I/O
  5459. is non-blocking, wolfSSL_connect_cert() will return when the underlying
  5460. I/O could not satisfy the needs of wolfSSL_connect_cert() to continue the
  5461. handshake. In this case, a call to wolfSSL_get_error() will yield either
  5462. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then
  5463. repeat the call to wolfSSL_connect_cert() when the underlying I/O is ready
  5464. and wolfSSL will pick up where it left off. When using a non-blocking
  5465. socket, nothing needs to be done, but select() can be used to check for
  5466. the required condition. If the underlying I/O is blocking,
  5467. wolfSSL_connect_cert() will only return once the peer’s certificate chain
  5468. has been received.
  5469. \return SSL_SUCCESS upon success.
  5470. \return SSL_FAILURE will be returned if the SSL session parameter is NULL.
  5471. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a more
  5472. detailed error code, call wolfSSL_get_error().
  5473. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5474. _Example_
  5475. \code
  5476. int ret = 0;
  5477. int err = 0;
  5478. WOLFSSL* ssl;
  5479. char buffer[80];
  5480. ...
  5481. ret = wolfSSL_connect_cert(ssl);
  5482. if (ret != SSL_SUCCESS) {
  5483. err = wolfSSL_get_error(ssl, ret);
  5484. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  5485. }
  5486. \endcode
  5487. \sa wolfSSL_get_error
  5488. \sa wolfSSL_connect
  5489. \sa wolfSSL_accept
  5490. */
  5491. int wolfSSL_connect_cert(WOLFSSL* ssl);
  5492. /*!
  5493. \ingroup openSSL
  5494. \brief wolfSSL_d2i_PKCS12_bio (d2i_PKCS12_bio) copies in the PKCS12
  5495. information from WOLFSSL_BIO to the structure WC_PKCS12. The information
  5496. is divided up in the structure as a list of Content Infos along with a
  5497. structure to hold optional MAC information. After the information has been
  5498. divided into chunks (but not decrypted) in the structure WC_PKCS12, it can
  5499. then be parsed and decrypted by calling.
  5500. \return WC_PKCS12 pointer to a WC_PKCS12 structure.
  5501. \return Failure If function failed it will return NULL.
  5502. \param bio WOLFSSL_BIO structure to read PKCS12 buffer from.
  5503. \param pkcs12 WC_PKCS12 structure pointer for new PKCS12 structure created.
  5504. Can be NULL
  5505. _Example_
  5506. \code
  5507. WC_PKCS12* pkcs;
  5508. WOLFSSL_BIO* bio;
  5509. WOLFSSL_X509* cert;
  5510. WOLFSSL_EVP_PKEY* pkey;
  5511. STACK_OF(X509) certs;
  5512. //bio loads in PKCS12 file
  5513. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5514. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5515. wc_PKCS12_free(pkcs)
  5516. //use cert, pkey, and optionally certs stack
  5517. \endcode
  5518. \sa wolfSSL_PKCS12_parse
  5519. \sa wc_PKCS12_free
  5520. */
  5521. WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio,
  5522. WC_PKCS12** pkcs12);
  5523. /*!
  5524. \ingroup openSSL
  5525. \brief wolfSSL_i2d_PKCS12_bio (i2d_PKCS12_bio) copies in the cert
  5526. information from the structure WC_PKCS12 to WOLFSSL_BIO.
  5527. \return 1 for success.
  5528. \return Failure 0.
  5529. \param bio WOLFSSL_BIO structure to write PKCS12 buffer to.
  5530. \param pkcs12 WC_PKCS12 structure for PKCS12 structure as input.
  5531. _Example_
  5532. \code
  5533. WC_PKCS12 pkcs12;
  5534. FILE *f;
  5535. byte buffer[5300];
  5536. char file[] = "./test.p12";
  5537. int bytes;
  5538. WOLFSSL_BIO* bio;
  5539. pkcs12 = wc_PKCS12_new();
  5540. f = fopen(file, "rb");
  5541. bytes = (int)fread(buffer, 1, sizeof(buffer), f);
  5542. fclose(f);
  5543. //convert the DER file into an internal structure
  5544. wc_d2i_PKCS12(buffer, bytes, pkcs12);
  5545. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  5546. //convert PKCS12 structure into bio
  5547. wolfSSL_i2d_PKCS12_bio(bio, pkcs12);
  5548. wc_PKCS12_free(pkcs)
  5549. //use bio
  5550. \endcode
  5551. \sa wolfSSL_PKCS12_parse
  5552. \sa wc_PKCS12_free
  5553. */
  5554. WC_PKCS12* wolfSSL_i2d_PKCS12_bio(WOLFSSL_BIO* bio,
  5555. WC_PKCS12* pkcs12);
  5556. /*!
  5557. \ingroup openSSL
  5558. \brief PKCS12 can be enabled with adding –enable-opensslextra to the
  5559. configure command. It can use triple DES and RC4 for decryption so would
  5560. recommend also enabling these features when enabling opensslextra
  5561. (--enable-des3 –enable-arc4). wolfSSL does not currently support RC2 so
  5562. decryption with RC2 is currently not available. This may be noticeable
  5563. with default encryption schemes used by OpenSSL command line to create
  5564. .p12 files. wolfSSL_PKCS12_parse (PKCS12_parse). The first thing this
  5565. function does is check the MAC is correct if present. If the MAC fails
  5566. then the function returns and does not try to decrypt any of the stored
  5567. Content Infos. This function then parses through each Content Info
  5568. looking for a bag type, if the bag type is known it is decrypted as
  5569. needed and either stored in the list of certificates being built or as
  5570. a key found. After parsing through all bags the key found is then
  5571. compared with the certificate list until a matching pair is found.
  5572. This matching pair is then returned as the key and certificate,
  5573. optionally the certificate list found is returned as a STACK_OF
  5574. certificates. At the moment a CRL, Secret or SafeContents bag will be
  5575. skipped over and not parsed. It can be seen if these or other “Unknown”
  5576. bags are skipped over by viewing the debug print out. Additional attributes
  5577. such as friendly name are skipped over when parsing a PKCS12 file.
  5578. \return SSL_SUCCESS On successfully parsing PKCS12.
  5579. \return SSL_FAILURE If an error case was encountered.
  5580. \param pkcs12 WC_PKCS12 structure to parse.
  5581. \param paswd password for decrypting PKCS12.
  5582. \param pkey structure to hold private key decoded from PKCS12.
  5583. \param cert structure to hold certificate decoded from PKCS12.
  5584. \param stack optional stack of extra certificates.
  5585. _Example_
  5586. \code
  5587. WC_PKCS12* pkcs;
  5588. WOLFSSL_BIO* bio;
  5589. WOLFSSL_X509* cert;
  5590. WOLFSSL_EVP_PKEY* pkey;
  5591. STACK_OF(X509) certs;
  5592. //bio loads in PKCS12 file
  5593. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5594. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5595. wc_PKCS12_free(pkcs)
  5596. //use cert, pkey, and optionally certs stack
  5597. \endcode
  5598. \sa wolfSSL_d2i_PKCS12_bio
  5599. \sa wc_PKCS12_free
  5600. */
  5601. int wolfSSL_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
  5602. WOLFSSL_EVP_PKEY** pkey, WOLFSSL_X509** cert, WOLF_STACK_OF(WOLFSSL_X509)** ca);
  5603. /*!
  5604. \ingroup CertsKeys
  5605. \brief Server Diffie-Hellman Ephemeral parameters setting. This function
  5606. sets up the group parameters to be used if the server negotiates a cipher
  5607. suite that uses DHE.
  5608. \return SSL_SUCCESS upon success.
  5609. \return MEMORY_ERROR will be returned if a memory error was encountered.
  5610. \return SIDE_ERROR will be returned if this function is called on an SSL
  5611. client instead of an SSL server.
  5612. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5613. \param p Diffie-Hellman prime number parameter.
  5614. \param pSz size of p.
  5615. \param g Diffie-Hellman “generator” parameter.
  5616. \param gSz size of g.
  5617. _Example_
  5618. \code
  5619. WOLFSSL* ssl;
  5620. static unsigned char p[] = {...};
  5621. static unsigned char g[] = {...};
  5622. ...
  5623. wolfSSL_SetTmpDH(ssl, p, sizeof(p), g, sizeof(g));
  5624. \endcode
  5625. \sa SSL_accept
  5626. */
  5627. int wolfSSL_SetTmpDH(WOLFSSL* ssl, const unsigned char* p, int pSz,
  5628. const unsigned char* g, int gSz);
  5629. /*!
  5630. \ingroup CertsKeys
  5631. \brief The function calls the wolfSSL_SetTMpDH_buffer_wrapper,
  5632. which is a wrapper for Diffie-Hellman parameters.
  5633. \return SSL_SUCCESS on successful execution.
  5634. \return SSL_BAD_FILETYPE if the file type is not PEM and is not
  5635. ASN.1. It will also be returned if the wc_DhParamsLoad does not
  5636. return normally.
  5637. \return SSL_NO_PEM_HEADER returns from PemToDer if there is not
  5638. a PEM header.
  5639. \return SSL_BAD_FILE returned if there is a file error in PemToDer.
  5640. \return SSL_FATAL_ERROR returned from PemToDer if there was a copy error.
  5641. \return MEMORY_E - if there was a memory allocation error.
  5642. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  5643. there was otherwise a NULL argument passed to a subroutine.
  5644. \return DH_KEY_SIZE_E is returned if their is a key size error in
  5645. wolfSSL_SetTmpDH() or in wolfSSL_CTX_SetTmpDH().
  5646. \return SIDE_ERROR returned if it is not the server side
  5647. in wolfSSL_SetTmpDH.
  5648. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5649. \param buf allocated buffer passed in from wolfSSL_SetTMpDH_file_wrapper.
  5650. \param sz a long int that holds the size of the file
  5651. (fname within wolfSSL_SetTmpDH_file_wrapper).
  5652. \param format an integer type passed through from
  5653. wolfSSL_SetTmpDH_file_wrapper() that is a representation of the certificate
  5654. format.
  5655. _Example_
  5656. \code
  5657. Static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5658. Const char* fname, int format);
  5659. long sz = 0;
  5660. byte* myBuffer = staticBuffer[FILE_BUFFER_SIZE];
  5661. if(ssl)
  5662. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5663. \endcode
  5664. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5665. \sa wc_DhParamsLoad
  5666. \sa wolfSSL_SetTmpDH
  5667. \sa PemToDer
  5668. \sa wolfSSL_CTX_SetTmpDH
  5669. \sa wolfSSL_CTX_SetTmpDH_file
  5670. */
  5671. int wolfSSL_SetTmpDH_buffer(WOLFSSL* ssl, const unsigned char* b, long sz,
  5672. int format);
  5673. /*!
  5674. \ingroup CertsKeys
  5675. \brief This function calls wolfSSL_SetTmpDH_file_wrapper to set server
  5676. Diffie-Hellman parameters.
  5677. \return SSL_SUCCESS returned on successful completion of this function
  5678. and its subroutines.
  5679. \return MEMORY_E returned if a memory allocation failed in this function
  5680. or a subroutine.
  5681. \return SIDE_ERROR if the side member of the Options structure found
  5682. in the WOLFSSL struct is not the server side.
  5683. \return SSL_BAD_FILETYPE returns if the certificate fails a set of checks.
  5684. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5685. the value of the minDhKeySz member in the WOLFSSL struct.
  5686. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5687. than the value of the maxDhKeySz member in the WOLFSSL struct.
  5688. \return BAD_FUNC_ARG returns if an argument value is NULL that is not
  5689. permitted such as, the WOLFSSL structure.
  5690. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5691. \param fname a constant char pointer holding the certificate.
  5692. \param format an integer type that holds the format of the certification.
  5693. _Example_
  5694. \code
  5695. WOLFSSL* ssl = wolfSSL_new(ctx);
  5696. const char* dhParam;
  5697. AssertIntNE(SSL_SUCCESS,
  5698. wolfSSL_SetTmpDH_file(ssl, dhParam, SSL_FILETYPE_PEM));
  5699. \endcode
  5700. \sa wolfSSL_CTX_SetTmpDH_file
  5701. \sa wolfSSL_SetTmpDH_file_wrapper
  5702. \sa wolfSSL_SetTmpDH_buffer
  5703. \sa wolfSSL_CTX_SetTmpDH_buffer
  5704. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5705. \sa wolfSSL_SetTmpDH
  5706. \sa wolfSSL_CTX_SetTmpDH
  5707. */
  5708. int wolfSSL_SetTmpDH_file(WOLFSSL* ssl, const char* f, int format);
  5709. /*!
  5710. \ingroup CertsKeys
  5711. \brief Sets the parameters for the server CTX Diffie-Hellman.
  5712. \return SSL_SUCCESS returned if the function and all subroutines
  5713. return without error.
  5714. \return BAD_FUNC_ARG returned if the CTX, p or g parameters are NULL.
  5715. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5716. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5717. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5718. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5719. \return MEMORY_E returned if the allocation of memory failed in this
  5720. function or a subroutine.
  5721. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5722. wolfSSL_CTX_new().
  5723. \param p a constant unsigned char pointer loaded into the buffer
  5724. member of the serverDH_P struct.
  5725. \param pSz an int type representing the size of p, initialized
  5726. to MAX_DH_SIZE.
  5727. \param g a constant unsigned char pointer loaded into the buffer
  5728. member of the serverDH_G struct.
  5729. \param gSz an int type representing the size of g, initialized to
  5730. MAX_DH_SIZE.
  5731. _Exmaple_
  5732. \code
  5733. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  5734. byte* p;
  5735. byte* g;
  5736. word32 pSz = (word32)sizeof(p)/sizeof(byte);
  5737. word32 gSz = (word32)sizeof(g)/sizeof(byte);
  5738. int ret = wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz);
  5739. if(ret != SSL_SUCCESS){
  5740. // Failure case
  5741. }
  5742. \endcode
  5743. \sa wolfSSL_SetTmpDH
  5744. \sa wc_DhParamsLoad
  5745. */
  5746. int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX* ctx, const unsigned char* p,
  5747. int pSz, const unsigned char* g, int gSz);
  5748. /*!
  5749. \ingroup CertsKeys
  5750. \brief A wrapper function that calls wolfSSL_SetTmpDH_buffer_wrapper
  5751. \return 0 returned for a successful execution.
  5752. \return BAD_FUNC_ARG returned if the ctx or buf parameters are NULL.
  5753. \return MEMORY_E if there is a memory allocation error.
  5754. \return SSL_BAD_FILETYPE returned if format is not correct.
  5755. \param ctx a pointer to a WOLFSSL structure, created using
  5756. wolfSSL_CTX_new().
  5757. \param buf a pointer to a constant unsigned char type that is
  5758. allocated as the buffer and passed through to
  5759. wolfSSL_SetTmpDH_buffer_wrapper.
  5760. \param sz a long integer type that is derived from the fname parameter
  5761. in wolfSSL_SetTmpDH_file_wrapper().
  5762. \param format an integer type passed through from
  5763. wolfSSL_SetTmpDH_file_wrapper().
  5764. _Example_
  5765. \code
  5766. static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5767. Const char* fname, int format);
  5768. #ifdef WOLFSSL_SMALL_STACK
  5769. byte staticBuffer[1]; // force heap usage
  5770. #else
  5771. byte* staticBuffer;
  5772. long sz = 0;
  5773. if(ssl){
  5774. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5775. } else {
  5776. ret = wolfSSL_CTX_SetTmpDH_buffer(ctx, myBuffer, sz, format);
  5777. }
  5778. \endcode
  5779. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5780. \sa wolfSSL_SetTMpDH_buffer
  5781. \sa wolfSSL_SetTmpDH_file_wrapper
  5782. \sa wolfSSL_CTX_SetTmpDH_file
  5783. */
  5784. int wolfSSL_CTX_SetTmpDH_buffer(WOLFSSL_CTX* ctx, const unsigned char* b,
  5785. long sz, int format);
  5786. /*!
  5787. \ingroup CertsKeys
  5788. \brief The function calls wolfSSL_SetTmpDH_file_wrapper to set the server
  5789. Diffie-Hellman parameters.
  5790. \return SSL_SUCCESS returned if the wolfSSL_SetTmpDH_file_wrapper or any
  5791. of its subroutines return successfully.
  5792. \return MEMORY_E returned if an allocation of dynamic memory fails in a
  5793. subroutine.
  5794. \return BAD_FUNC_ARG returned if the ctx or fname parameters are NULL or
  5795. if
  5796. a subroutine is passed a NULL argument.
  5797. \return SSL_BAD_FILE returned if the certificate file is unable to open or
  5798. if the a set of checks on the file fail from wolfSSL_SetTmpDH_file_wrapper.
  5799. \return SSL_BAD_FILETYPE returned if the format is not PEM or ASN.1 from
  5800. wolfSSL_SetTmpDH_buffer_wrapper().
  5801. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5802. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5803. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5804. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5805. \return SIDE_ERROR returned in wolfSSL_SetTmpDH() if the side is not the
  5806. server end.
  5807. \return SSL_NO_PEM_HEADER returned from PemToDer if there is no PEM header.
  5808. \return SSL_FATAL_ERROR returned from PemToDer if there is a memory copy
  5809. failure.
  5810. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5811. wolfSSL_CTX_new().
  5812. \param fname a constant character pointer to a certificate file.
  5813. \param format an integer type passed through from
  5814. wolfSSL_SetTmpDH_file_wrapper() that is a representation of
  5815. the certificate format.
  5816. _Example_
  5817. \code
  5818. #define dhParam “certs/dh2048.pem”
  5819. #DEFINE aSSERTiNTne(x, y) AssertInt(x, y, !=, ==)
  5820. WOLFSSL_CTX* ctx;
  5821. AssertNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  5822. AssertIntNE(SSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL, dhParam,
  5823. SSL_FILETYPE_PEM));
  5824. \endcode
  5825. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5826. \sa wolfSSL_SetTmpDH
  5827. \sa wolfSSL_CTX_SetTmpDH
  5828. \sa wolfSSL_SetTmpDH_buffer
  5829. \sa wolfSSL_CTX_SetTmpDH_buffer
  5830. \sa wolfSSL_SetTmpDH_file_wrapper
  5831. \sa AllocDer
  5832. \sa PemToDer
  5833. */
  5834. int wolfSSL_CTX_SetTmpDH_file(WOLFSSL_CTX* ctx, const char* f,
  5835. int format);
  5836. /*!
  5837. \ingroup CertsKeys
  5838. \brief This function sets the minimum size (in bits) of the Diffie Hellman
  5839. key size by accessing the minDhKeySz member in the WOLFSSL_CTX structure.
  5840. \return SSL_SUCCESS returned if the function completes successfully.
  5841. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5842. the keySz_bits is greater than 16,000 or not divisible by 8.
  5843. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5844. \param keySz_bits a word16 type used to set the minimum DH key size in bits.
  5845. The WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5846. _Example_
  5847. \code
  5848. public static int CTX_SetMinDhKey_Sz(IntPtr ctx, short minDhKey){
  5849. return wolfSSL_CTX_SetMinDhKey_Sz(local_ctx, minDhKeyBits);
  5850. \endcode
  5851. \sa wolfSSL_SetMinDhKey_Sz
  5852. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5853. \sa wolfSSL_SetMaxDhKey_Sz
  5854. \sa wolfSSL_GetDhKey_Sz
  5855. \sa wolfSSL_CTX_SetTMpDH_file
  5856. */
  5857. int wolfSSL_CTX_SetMinDhKey_Sz(WOLFSSL_CTX* ctx, word16);
  5858. /*!
  5859. \ingroup CertsKeys
  5860. \brief Sets the minimum size (in bits) for a Diffie-Hellman key in the
  5861. WOLFSSL structure.
  5862. \return SSL_SUCCESS the minimum size was successfully set.
  5863. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or if the keySz_bits is
  5864. greater than 16,000 or not divisible by 8.
  5865. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5866. \param keySz_bits a word16 type used to set the minimum DH key size in bits.
  5867. The WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5868. _Example_
  5869. \code
  5870. WOLFSSL* ssl = wolfSSL_new(ctx);
  5871. word16 keySz_bits;
  5872. ...
  5873. if(wolfSSL_SetMinDhKey_Sz(ssl, keySz_bits) != SSL_SUCCESS){
  5874. // Failed to set.
  5875. }
  5876. \endcode
  5877. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5878. \sa wolfSSL_GetDhKey_Sz
  5879. */
  5880. int wolfSSL_SetMinDhKey_Sz(WOLFSSL* ssl, word16 keySz_bits);
  5881. /*!
  5882. \ingroup CertsKeys
  5883. \brief This function sets the maximum size (in bits) of the Diffie Hellman
  5884. key size by accessing the maxDhKeySz member in the WOLFSSL_CTX structure.
  5885. \return SSL_SUCCESS returned if the function completes successfully.
  5886. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5887. the keySz_bits is greater than 16,000 or not divisible by 8.
  5888. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5889. \param keySz_bits a word16 type used to set the maximum DH key size in bits.
  5890. The WOLFSSL_CTX struct holds this information in the maxDhKeySz member.
  5891. _Example_
  5892. \code
  5893. public static int CTX_SetMaxDhKey_Sz(IntPtr ctx, short maxDhKey){
  5894. return wolfSSL_CTX_SetMaxDhKey_Sz(local_ctx, keySz_bits);
  5895. \endcode
  5896. \sa wolfSSL_SetMinDhKey_Sz
  5897. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5898. \sa wolfSSL_SetMaxDhKey_Sz
  5899. \sa wolfSSL_GetDhKey_Sz
  5900. \sa wolfSSL_CTX_SetTMpDH_file
  5901. */
  5902. int wolfSSL_CTX_SetMaxDhKey_Sz(WOLFSSL_CTX* ctx, word16 keySz_bits);
  5903. /*!
  5904. \ingroup CertsKeys
  5905. \brief Sets the maximum size (in bits) for a Diffie-Hellman key in the
  5906. WOLFSSL structure.
  5907. \return SSL_SUCCESS the maximum size was successfully set.
  5908. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or the keySz parameter
  5909. was greater than the allowable size or not divisible by 8.
  5910. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5911. \param keySz a word16 type representing the bit size of the maximum DH key.
  5912. _Example_
  5913. \code
  5914. WOLFSSL* ssl = wolfSSL_new(ctx);
  5915. word16 keySz;
  5916. ...
  5917. if(wolfSSL_SetMaxDhKey(ssl, keySz) != SSL_SUCCESS){
  5918. // Failed to set.
  5919. }
  5920. \endcode
  5921. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5922. \sa wolfSSL_GetDhKey_Sz
  5923. */
  5924. int wolfSSL_SetMaxDhKey_Sz(WOLFSSL* ssl, word16 keySz_bits);
  5925. /*!
  5926. \ingroup CertsKeys
  5927. \brief Returns the value of dhKeySz (in bits) that is a member of the
  5928. options structure. This value represents the Diffie-Hellman key size in
  5929. bytes.
  5930. \return dhKeySz returns the value held in ssl->options.dhKeySz which is an
  5931. integer value representing a size in bits.
  5932. \return BAD_FUNC_ARG returns if the WOLFSSL struct is NULL.
  5933. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5934. _Example_
  5935. \code
  5936. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5937. WOLFSSL* ssl = wolfSSL_new(ctx);
  5938. int dhKeySz;
  5939. ...
  5940. dhKeySz = wolfSSL_GetDhKey_Sz(ssl);
  5941. if(dhKeySz == BAD_FUNC_ARG || dhKeySz <= 0){
  5942. // Failure case
  5943. } else {
  5944. // dhKeySz holds the size of the key.
  5945. }
  5946. \endcode
  5947. \sa wolfSSL_SetMinDhKey_sz
  5948. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5949. \sa wolfSSL_CTX_SetTmpDH
  5950. \sa wolfSSL_SetTmpDH
  5951. \sa wolfSSL_CTX_SetTmpDH_file
  5952. */
  5953. int wolfSSL_GetDhKey_Sz(WOLFSSL*);
  5954. /*!
  5955. \ingroup CertsKeys
  5956. \brief Sets the minimum RSA key size in both the WOLFSSL_CTX structure
  5957. and the WOLFSSL_CERT_MANAGER structure.
  5958. \return SSL_SUCCESS returned on successful execution of the function.
  5959. \return BAD_FUNC_ARG returned if the ctx structure is NULL or the keySz
  5960. is less than zero or not divisible by 8.
  5961. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5962. wolfSSL_CTX_new().
  5963. \param keySz a short integer type stored in minRsaKeySz in the ctx
  5964. structure and the cm structure converted to bytes.
  5965. _Example_
  5966. \code
  5967. WOLFSSL_CTX* ctx = SSL_CTX_new(method);
  5968. (void)minDhKeyBits;
  5969. ourCert = myoptarg;
  5970. minDhKeyBits = atoi(myoptarg);
  5971. if(wolfSSL_CTX_SetMinRsaKey_Sz(ctx, minRsaKeyBits) != SSL_SUCCESS){
  5972. \endcode
  5973. \sa wolfSSL_SetMinRsaKey_Sz
  5974. */
  5975. int wolfSSL_CTX_SetMinRsaKey_Sz(WOLFSSL_CTX* ctx, short keySz);
  5976. /*!
  5977. \ingroup CertsKeys
  5978. \brief Sets the minimum allowable key size in bits for RSA located in the
  5979. WOLFSSL structure.
  5980. \return SSL_SUCCESS the minimum was set successfully.
  5981. \return BAD_FUNC_ARG returned if the ssl structure is NULL or if the ksySz
  5982. is less than zero or not divisible by 8.
  5983. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5984. \param keySz a short integer value representing the the minimum key in bits.
  5985. _Example_
  5986. \code
  5987. WOLFSSL* ssl = wolfSSL_new(ctx);
  5988. short keySz;
  5989. int isSet = wolfSSL_SetMinRsaKey_Sz(ssl, keySz);
  5990. if(isSet != SSL_SUCCESS){
  5991. Failed to set.
  5992. }
  5993. \endcode
  5994. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5995. */
  5996. int wolfSSL_SetMinRsaKey_Sz(WOLFSSL* ssl, short keySz);
  5997. /*!
  5998. \ingroup CertsKeys
  5999. \brief Sets the minimum size in bits for the ECC key in the WOLF_CTX
  6000. structure and the WOLFSSL_CERT_MANAGER structure.
  6001. \return SSL_SUCCESS returned for a successful execution and the minEccKeySz
  6002. member is set.
  6003. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  6004. the keySz is negative or not divisible by 8.
  6005. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6006. wolfSSL_CTX_new().
  6007. \param keySz a short integer type that represents the minimum ECC key
  6008. size in bits.
  6009. _Example_
  6010. \code
  6011. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  6012. short keySz; // minimum key size
  6013. if(wolfSSL_CTX_SetMinEccKey(ctx, keySz) != SSL_SUCCESS){
  6014. // Failed to set min key size
  6015. }
  6016. \endcode
  6017. \sa wolfSSL_SetMinEccKey_Sz
  6018. */
  6019. int wolfSSL_CTX_SetMinEccKey_Sz(WOLFSSL_CTX* ssl, short keySz);
  6020. /*!
  6021. \ingroup CertsKeys
  6022. \brief Sets the value of the minEccKeySz member of the options structure.
  6023. The options struct is a member of the WOLFSSL structure and is
  6024. accessed through the ssl parameter.
  6025. \return SSL_SUCCESS if the function successfully set the minEccKeySz
  6026. member of the options structure.
  6027. \return BAD_FUNC_ARG if the WOLFSSL_CTX structure is NULL or if the
  6028. key size (keySz) is less than 0 (zero) or not divisible by 8.
  6029. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6030. \param keySz value used to set the minimum ECC key size. Sets
  6031. value in the options structure.
  6032. _Example_
  6033. \code
  6034. WOLFSSL* ssl = wolfSSL_new(ctx); // New session
  6035. short keySz = 999; // should be set to min key size allowable
  6036. ...
  6037. if(wolfSSL_SetMinEccKey_Sz(ssl, keySz) != SSL_SUCCESS){
  6038. // Failure case.
  6039. }
  6040. \endcode
  6041. \sa wolfSSL_CTX_SetMinEccKey_Sz
  6042. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  6043. \sa wolfSSL_SetMinRsaKey_Sz
  6044. */
  6045. int wolfSSL_SetMinEccKey_Sz(WOLFSSL* ssl, short keySz);
  6046. /*!
  6047. \ingroup CertsKeys
  6048. \brief This function is used by EAP_TLS and EAP-TTLS to derive
  6049. keying material from the master secret.
  6050. \return BUFFER_E returned if the actual size of the buffer exceeds
  6051. the maximum size allowable.
  6052. \return MEMORY_E returned if there is an error with memory allocation.
  6053. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6054. \param msk a void pointer variable that will hold the result
  6055. of the p_hash function.
  6056. \param len an unsigned integer that represents the length of
  6057. the msk variable.
  6058. \param label a constant char pointer that is copied from in wc_PRF().
  6059. _Example_
  6060. \code
  6061. WOLFSSL* ssl = wolfSSL_new(ctx);;
  6062. void* msk;
  6063. unsigned int len;
  6064. const char* label;
  6065. return wolfSSL_make_eap_keys(ssl, msk, len, label);
  6066. \endcode
  6067. \sa wc_PRF
  6068. \sa wc_HmacFinal
  6069. \sa wc_HmacUpdate
  6070. */
  6071. int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
  6072. const char* label);
  6073. /*!
  6074. \ingroup IO
  6075. \brief Simulates writev semantics but doesn’t actually do block at a time
  6076. because of SSL_write() behavior and because front adds may be small.
  6077. Makes porting into software that uses writev easier.
  6078. \return >0 the number of bytes written upon success.
  6079. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  6080. the specific error code.
  6081. \return MEMORY_ERROR will be returned if a memory error was encountered.
  6082. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  6083. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  6084. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  6085. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  6086. error code.
  6087. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6088. \param iov array of I/O vectors to write
  6089. \param iovcnt number of vectors in iov array.
  6090. _Example_
  6091. \code
  6092. WOLFSSL* ssl = 0;
  6093. char *bufA = “hello\n”;
  6094. char *bufB = “hello world\n”;
  6095. int iovcnt;
  6096. struct iovec iov[2];
  6097. iov[0].iov_base = buffA;
  6098. iov[0].iov_len = strlen(buffA);
  6099. iov[1].iov_base = buffB;
  6100. iov[1].iov_len = strlen(buffB);
  6101. iovcnt = 2;
  6102. ...
  6103. ret = wolfSSL_writev(ssl, iov, iovcnt);
  6104. // wrote “ret” bytes, or error if <= 0.
  6105. \endcode
  6106. \sa wolfSSL_write
  6107. */
  6108. int wolfSSL_writev(WOLFSSL* ssl, const struct iovec* iov,
  6109. int iovcnt);
  6110. /*!
  6111. \ingroup Setup
  6112. \brief This function unloads the CA signer list and frees
  6113. the whole signer table.
  6114. \return SSL_SUCCESS returned on successful execution of the function.
  6115. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or there
  6116. are otherwise unpermitted argument values passed in a subroutine.
  6117. \return BAD_MUTEX_E returned if there was a mutex error. The LockMutex()
  6118. did not return 0.
  6119. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6120. wolfSSL_CTX_new().
  6121. _Example_
  6122. \code
  6123. WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
  6124. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  6125. if(wolfSSL_CTX_UnloadCAs(ctx) != SSL_SUCCESS){
  6126. // The function did not unload CAs
  6127. }
  6128. \endcode
  6129. \sa wolfSSL_CertManagerUnloadCAs
  6130. \sa LockMutex
  6131. \sa UnlockMutex
  6132. */
  6133. int wolfSSL_CTX_UnloadCAs(WOLFSSL_CTX*);
  6134. /*!
  6135. \ingroup Setup
  6136. \brief This function unloads intermediate certificates added to the CA
  6137. signer list and frees them.
  6138. \return SSL_SUCCESS returned on successful execution of the function.
  6139. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or there
  6140. are otherwise unpermitted argument values passed in a subroutine.
  6141. \return BAD_STATE_E returned if the WOLFSSL_CTX has a reference count > 1.
  6142. \return BAD_MUTEX_E returned if there was a mutex error. The LockMutex()
  6143. did not return 0.
  6144. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6145. wolfSSL_CTX_new().
  6146. _Example_
  6147. \code
  6148. WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
  6149. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  6150. if(wolfSSL_CTX_UnloadIntermediateCerts(ctx) != NULL){
  6151. // The function did not unload CAs
  6152. }
  6153. \endcode
  6154. \sa wolfSSL_CTX_UnloadCAs
  6155. \sa wolfSSL_CertManagerUnloadIntermediateCerts
  6156. */
  6157. int wolfSSL_CTX_UnloadIntermediateCerts(WOLFSSL_CTX* ctx);
  6158. /*!
  6159. \ingroup Setup
  6160. \brief This function is used to unload all previously loaded trusted peer
  6161. certificates. Feature is enabled by defining the macro
  6162. WOLFSSL_TRUST_PEER_CERT.
  6163. \return SSL_SUCCESS upon success.
  6164. \return BAD_FUNC_ARG will be returned if ctx is NULL.
  6165. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6166. can’t be read, or is corrupted.
  6167. \return MEMORY_E will be returned if an out of memory condition occurs.
  6168. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6169. _Example_
  6170. \code
  6171. int ret = 0;
  6172. WOLFSSL_CTX* ctx;
  6173. ...
  6174. ret = wolfSSL_CTX_Unload_trust_peers(ctx);
  6175. if (ret != SSL_SUCCESS) {
  6176. // error unloading trusted peer certs
  6177. }
  6178. ...
  6179. \endcode
  6180. \sa wolfSSL_CTX_trust_peer_buffer
  6181. \sa wolfSSL_CTX_trust_peer_cert
  6182. */
  6183. int wolfSSL_CTX_Unload_trust_peers(WOLFSSL_CTX*);
  6184. /*!
  6185. \ingroup Setup
  6186. \brief This function loads a certificate to use for verifying a peer
  6187. when performing a TLS/SSL handshake. The peer certificate sent during
  6188. the handshake is compared by using the SKID when available and the
  6189. signature. If these two things do not match then any loaded CAs are used.
  6190. Is the same functionality as wolfSSL_CTX_trust_peer_cert except is from
  6191. a buffer instead of a file. Feature is enabled by defining the macro
  6192. WOLFSSL_TRUST_PEER_CERT Please see the examples for proper usage.
  6193. \return SSL_SUCCESS upon success
  6194. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  6195. type are invalid.
  6196. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6197. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6198. read, or is corrupted.
  6199. \return MEMORY_E will be returned if an out of memory condition occurs.
  6200. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6201. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6202. \param buffer pointer to the buffer containing certificates.
  6203. \param sz length of the buffer input.
  6204. \param type type of certificate being loaded i.e. SSL_FILETYPE_ASN1 or
  6205. SSL_FILETYPE_PEM.
  6206. _Example_
  6207. \code
  6208. int ret = 0;
  6209. WOLFSSL_CTX* ctx;
  6210. ...
  6211. ret = wolfSSL_CTX_trust_peer_buffer(ctx, bufferPtr, bufferSz,
  6212. SSL_FILETYPE_PEM);
  6213. if (ret != SSL_SUCCESS) {
  6214. // error loading trusted peer cert
  6215. }
  6216. ...
  6217. \endcode
  6218. \sa wolfSSL_CTX_load_verify_buffer
  6219. \sa wolfSSL_CTX_use_certificate_file
  6220. \sa wolfSSL_CTX_use_PrivateKey_file
  6221. \sa wolfSSL_CTX_use_certificate_chain_file
  6222. \sa wolfSSL_CTX_trust_peer_cert
  6223. \sa wolfSSL_CTX_Unload_trust_peers
  6224. \sa wolfSSL_use_certificate_file
  6225. \sa wolfSSL_use_PrivateKey_file
  6226. \sa wolfSSL_use_certificate_chain_file
  6227. */
  6228. int wolfSSL_CTX_trust_peer_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
  6229. long sz, int format);
  6230. /*!
  6231. \ingroup CertsKeys
  6232. \brief This function loads a CA certificate buffer into the WOLFSSL
  6233. Context. It behaves like the non-buffered version, only differing in
  6234. its ability to be called with a buffer as input instead of a file.
  6235. The buffer is provided by the in argument of size sz. format specifies
  6236. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6237. More than one CA certificate may be loaded per buffer as long as the
  6238. format is in PEM. Please see the examples for proper usage.
  6239. \return SSL_SUCCESS upon success
  6240. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6241. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6242. can’t be read, or is corrupted.
  6243. \return MEMORY_E will be returned if an out of memory condition occurs.
  6244. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6245. \return BUFFER_E will be returned if a chain buffer is bigger than
  6246. the receiving buffer.
  6247. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6248. \param in pointer to the CA certificate buffer.
  6249. \param sz size of the input CA certificate buffer, in.
  6250. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6251. or SSL_FILETYPE_PEM.
  6252. _Example_
  6253. \code
  6254. int ret = 0;
  6255. WOLFSSL_CTX* ctx;
  6256. byte certBuff[...];
  6257. long sz = sizeof(certBuff);
  6258. ...
  6259. ret = wolfSSL_CTX_load_verify_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  6260. if (ret != SSL_SUCCESS) {
  6261. // error loading CA certs from buffer
  6262. }
  6263. ...
  6264. \endcode
  6265. \sa wolfSSL_CTX_load_verify_locations
  6266. \sa wolfSSL_CTX_use_certificate_buffer
  6267. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6268. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6269. \sa wolfSSL_use_certificate_buffer
  6270. \sa wolfSSL_use_PrivateKey_buffer
  6271. \sa wolfSSL_use_certificate_chain_buffer
  6272. */
  6273. int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
  6274. long sz, int format);
  6275. /*!
  6276. \ingroup CertsKeys
  6277. \brief This function loads a CA certificate buffer into the WOLFSSL
  6278. Context. It behaves like the non-buffered version, only differing in
  6279. its ability to be called with a buffer as input instead of a file.
  6280. The buffer is provided by the in argument of size sz. format specifies
  6281. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6282. More than one CA certificate may be loaded per buffer as long as the
  6283. format is in PEM. The _ex version was added in PR 2413 and supports
  6284. additional arguments for userChain and flags.
  6285. \return SSL_SUCCESS upon success
  6286. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6287. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6288. can’t be read, or is corrupted.
  6289. \return MEMORY_E will be returned if an out of memory condition occurs.
  6290. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6291. \return BUFFER_E will be returned if a chain buffer is bigger than
  6292. the receiving buffer.
  6293. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6294. \param in pointer to the CA certificate buffer.
  6295. \param sz size of the input CA certificate buffer, in.
  6296. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6297. or SSL_FILETYPE_PEM.
  6298. \param userChain If using format WOLFSSL_FILETYPE_ASN1 this set to non-zero
  6299. indicates a chain of DER's is being presented.
  6300. \param flags: See ssl.h around WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS.
  6301. _Example_
  6302. \code
  6303. int ret = 0;
  6304. WOLFSSL_CTX* ctx;
  6305. byte certBuff[...];
  6306. long sz = sizeof(certBuff);
  6307. ...
  6308. // Example for force loading an expired certificate
  6309. ret = wolfSSL_CTX_load_verify_buffer_ex(ctx, certBuff, sz, SSL_FILETYPE_PEM,
  6310. 0, (WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY));
  6311. if (ret != SSL_SUCCESS) {
  6312. // error loading CA certs from buffer
  6313. }
  6314. ...
  6315. \endcode
  6316. \sa wolfSSL_CTX_load_verify_buffer
  6317. \sa wolfSSL_CTX_load_verify_locations
  6318. \sa wolfSSL_CTX_use_certificate_buffer
  6319. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6320. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6321. \sa wolfSSL_use_certificate_buffer
  6322. \sa wolfSSL_use_PrivateKey_buffer
  6323. \sa wolfSSL_use_certificate_chain_buffer
  6324. */
  6325. int wolfSSL_CTX_load_verify_buffer_ex(WOLFSSL_CTX* ctx,
  6326. const unsigned char* in, long sz,
  6327. int format, int userChain, word32 flags);
  6328. /*!
  6329. \ingroup CertsKeys
  6330. \brief This function loads a CA certificate chain buffer into the WOLFSSL
  6331. Context. It behaves like the non-buffered version, only differing in
  6332. its ability to be called with a buffer as input instead of a file.
  6333. The buffer is provided by the in argument of size sz. format specifies
  6334. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6335. More than one CA certificate may be loaded per buffer as long as the
  6336. format is in PEM. Please see the examples for proper usage.
  6337. \return SSL_SUCCESS upon success
  6338. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6339. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6340. can’t be read, or is corrupted.
  6341. \return MEMORY_E will be returned if an out of memory condition occurs.
  6342. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6343. \return BUFFER_E will be returned if a chain buffer is bigger than
  6344. the receiving buffer.
  6345. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6346. \param in pointer to the CA certificate buffer.
  6347. \param sz size of the input CA certificate buffer, in.
  6348. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6349. or SSL_FILETYPE_PEM.
  6350. _Example_
  6351. \code
  6352. int ret = 0;
  6353. WOLFSSL_CTX* ctx;
  6354. byte certBuff[...];
  6355. long sz = sizeof(certBuff);
  6356. ...
  6357. ret = wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  6358. certBuff, sz, WOLFSSL_FILETYPE_ASN1);
  6359. if (ret != SSL_SUCCESS) {
  6360. // error loading CA certs from buffer
  6361. }
  6362. ...
  6363. \endcode
  6364. \sa wolfSSL_CTX_load_verify_locations
  6365. \sa wolfSSL_CTX_use_certificate_buffer
  6366. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6367. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6368. \sa wolfSSL_use_certificate_buffer
  6369. \sa wolfSSL_use_PrivateKey_buffer
  6370. \sa wolfSSL_use_certificate_chain_buffer
  6371. */
  6372. int wolfSSL_CTX_load_verify_chain_buffer_format(WOLFSSL_CTX* ctx,
  6373. const unsigned char* in,
  6374. long sz, int format);
  6375. /*!
  6376. \ingroup CertsKeys
  6377. \brief This function loads a certificate buffer into the WOLFSSL Context.
  6378. It behaves like the non-buffered version, only differing in its ability
  6379. to be called with a buffer as input instead of a file. The buffer is
  6380. provided by the in argument of size sz. format specifies the format
  6381. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  6382. see the examples for proper usage.
  6383. \return SSL_SUCCESS upon success
  6384. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6385. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6386. can’t be read, or is corrupted.
  6387. \return MEMORY_E will be returned if an out of memory condition occurs.
  6388. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6389. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6390. \param in the input buffer containing the certificate to be loaded.
  6391. \param sz the size of the input buffer.
  6392. \param format the format of the certificate located in the input
  6393. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6394. _Example_
  6395. \code
  6396. int ret = 0;
  6397. WOLFSSL_CTX* ctx;
  6398. byte certBuff[...];
  6399. long sz = sizeof(certBuff);
  6400. ...
  6401. ret = wolfSSL_CTX_use_certificate_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  6402. if (ret != SSL_SUCCESS) {
  6403. // error loading certificate from buffer
  6404. }
  6405. ...
  6406. \endcode
  6407. \sa wolfSSL_CTX_load_verify_buffer
  6408. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6409. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6410. \sa wolfSSL_use_certificate_buffer
  6411. \sa wolfSSL_use_PrivateKey_buffer
  6412. \sa wolfSSL_use_certificate_chain_buffer
  6413. */
  6414. int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX* ctx,
  6415. const unsigned char* in, long sz,
  6416. int format);
  6417. /*!
  6418. \ingroup CertsKeys
  6419. \brief This function loads a private key buffer into the SSL Context.
  6420. It behaves like the non-buffered version, only differing in its ability
  6421. to be called with a buffer as input instead of a file. The buffer is
  6422. provided by the in argument of size sz. format specifies the format type
  6423. of the buffer; SSL_FILETYPE_ASN1or SSL_FILETYPE_PEM. Please see the
  6424. examples for proper usage.
  6425. \return SSL_SUCCESS upon success
  6426. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6427. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6428. read, or is corrupted.
  6429. \return MEMORY_E will be returned if an out of memory condition occurs.
  6430. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6431. \return NO_PASSWORD will be returned if the key file is encrypted but no
  6432. password is provided.
  6433. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6434. \param in the input buffer containing the private key to be loaded.
  6435. \param sz the size of the input buffer.
  6436. \param format the format of the private key located in the input
  6437. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6438. _Example_
  6439. \code
  6440. int ret = 0;
  6441. WOLFSSL_CTX* ctx;
  6442. byte keyBuff[...];
  6443. long sz = sizeof(certBuff);
  6444. ...
  6445. ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, keyBuff, sz, SSL_FILETYPE_PEM);
  6446. if (ret != SSL_SUCCESS) {
  6447. // error loading private key from buffer
  6448. }
  6449. ...
  6450. \endcode
  6451. \sa wolfSSL_CTX_load_verify_buffer
  6452. \sa wolfSSL_CTX_use_certificate_buffer
  6453. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6454. \sa wolfSSL_use_certificate_buffer
  6455. \sa wolfSSL_use_PrivateKey_buffer
  6456. \sa wolfSSL_use_certificate_chain_buffer
  6457. */
  6458. int wolfSSL_CTX_use_PrivateKey_buffer(WOLFSSL_CTX* ctx,
  6459. const unsigned char* in, long sz,
  6460. int format);
  6461. /*!
  6462. \ingroup CertsKeys
  6463. \brief This function loads a certificate chain buffer into the WOLFSSL
  6464. Context. It behaves like the non-buffered version, only differing in
  6465. its ability to be called with a buffer as input instead of a file.
  6466. The buffer is provided by the in argument of size sz. The buffer must
  6467. be in PEM format and start with the subject’s certificate, ending with
  6468. the root certificate. Please see the examples for proper usage.
  6469. \return SSL_SUCCESS upon success
  6470. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6471. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6472. can’t be read, or is corrupted.
  6473. \return MEMORY_E will be returned if an out of memory condition occurs.
  6474. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6475. \return BUFFER_E will be returned if a chain buffer is bigger than
  6476. the receiving buffer.
  6477. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6478. \param in the input buffer containing the PEM-formatted certificate
  6479. chain to be loaded.
  6480. \param sz the size of the input buffer.
  6481. _Example_
  6482. \code
  6483. int ret = 0;
  6484. WOLFSSL_CTX* ctx;
  6485. byte certChainBuff[...];
  6486. long sz = sizeof(certBuff);
  6487. ...
  6488. ret = wolfSSL_CTX_use_certificate_chain_buffer(ctx, certChainBuff, sz);
  6489. if (ret != SSL_SUCCESS) {
  6490. // error loading certificate chain from buffer
  6491. }
  6492. ...
  6493. \endcode
  6494. \sa wolfSSL_CTX_load_verify_buffer
  6495. \sa wolfSSL_CTX_use_certificate_buffer
  6496. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6497. \sa wolfSSL_use_certificate_buffer
  6498. \sa wolfSSL_use_PrivateKey_buffer
  6499. \sa wolfSSL_use_certificate_chain_buffer
  6500. */
  6501. int wolfSSL_CTX_use_certificate_chain_buffer(WOLFSSL_CTX* ctx,
  6502. const unsigned char* in, long sz);
  6503. /*!
  6504. \ingroup CertsKeys
  6505. \brief This function loads a certificate buffer into the WOLFSSL object.
  6506. It behaves like the non-buffered version, only differing in its ability
  6507. to be called with a buffer as input instead of a file. The buffer
  6508. is provided by the in argument of size sz. format specifies the format
  6509. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6510. Please see the examples for proper usage.
  6511. \return SSL_SUCCESS upon success.
  6512. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6513. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  6514. be read, or is corrupted.
  6515. \return MEMORY_E will be returned if an out of memory condition occurs.
  6516. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6517. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6518. \param in buffer containing certificate to load.
  6519. \param sz size of the certificate located in buffer.
  6520. \param format format of the certificate to be loaded.
  6521. Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6522. _Example_
  6523. \code
  6524. int ret;
  6525. byte certBuff[...];
  6526. WOLFSSL* ssl = 0;
  6527. long buffSz = sizeof(certBuff);
  6528. ...
  6529. ret = wolfSSL_use_certificate_buffer(ssl, certBuff, buffSz, SSL_FILETYPE_PEM);
  6530. if (ret != SSL_SUCCESS) {
  6531. // failed to load certificate from buffer
  6532. }
  6533. \endcode
  6534. \sa wolfSSL_CTX_load_verify_buffer
  6535. \sa wolfSSL_CTX_use_certificate_buffer
  6536. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6537. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6538. \sa wolfSSL_use_PrivateKey_buffer
  6539. \sa wolfSSL_use_certificate_chain_buffer
  6540. */
  6541. int wolfSSL_use_certificate_buffer(WOLFSSL* ssl, const unsigned char* in,
  6542. long sz, int format);
  6543. /*!
  6544. \ingroup CertsKeys
  6545. \brief This function loads a private key buffer into the WOLFSSL object.
  6546. It behaves like the non-buffered version, only differing in its ability
  6547. to be called with a buffer as input instead of a file. The buffer is
  6548. provided by the in argument of size sz. format specifies the format
  6549. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  6550. see the examples for proper usage.
  6551. \return SSL_SUCCESS upon success.
  6552. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6553. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6554. read, or is corrupted.
  6555. \return MEMORY_E will be returned if an out of memory condition occurs.
  6556. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6557. \return NO_PASSWORD will be returned if the key file is encrypted but no
  6558. password is provided.
  6559. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6560. \param in buffer containing private key to load.
  6561. \param sz size of the private key located in buffer.
  6562. \param format format of the private key to be loaded. Possible values are
  6563. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6564. _Example_
  6565. \code
  6566. int ret;
  6567. byte keyBuff[...];
  6568. WOLFSSL* ssl = 0;
  6569. long buffSz = sizeof(certBuff);
  6570. ...
  6571. ret = wolfSSL_use_PrivateKey_buffer(ssl, keyBuff, buffSz, SSL_FILETYPE_PEM);
  6572. if (ret != SSL_SUCCESS) {
  6573. // failed to load private key from buffer
  6574. }
  6575. \endcode
  6576. \sa wolfSSL_use_PrivateKey
  6577. \sa wolfSSL_CTX_load_verify_buffer
  6578. \sa wolfSSL_CTX_use_certificate_buffer
  6579. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6580. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6581. \sa wolfSSL_use_certificate_buffer
  6582. \sa wolfSSL_use_certificate_chain_buffer
  6583. */
  6584. int wolfSSL_use_PrivateKey_buffer(WOLFSSL* ssl, const unsigned char* in,
  6585. long sz, int format);
  6586. /*!
  6587. \ingroup CertsKeys
  6588. \brief This function loads a certificate chain buffer into the WOLFSSL
  6589. object. It behaves like the non-buffered version, only differing in its
  6590. ability to be called with a buffer as input instead of a file. The buffer
  6591. is provided by the in argument of size sz. The buffer must be in PEM format
  6592. and start with the subject’s certificate, ending with the root certificate.
  6593. Please see the examples for proper usage.
  6594. \return SSL_SUCCES upon success.
  6595. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6596. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6597. can’t be read, or is corrupted.
  6598. \return MEMORY_E will be returned if an out of memory condition occurs.
  6599. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6600. \return BUFFER_E will be returned if a chain buffer is bigger than
  6601. the receiving buffer.
  6602. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6603. \param in buffer containing certificate to load.
  6604. \param sz size of the certificate located in buffer.
  6605. _Example_
  6606. \code
  6607. int ret;
  6608. byte certChainBuff[...];
  6609. WOLFSSL* ssl = 0;
  6610. long buffSz = sizeof(certBuff);
  6611. ...
  6612. ret = wolfSSL_use_certificate_chain_buffer(ssl, certChainBuff, buffSz);
  6613. if (ret != SSL_SUCCESS) {
  6614. // failed to load certificate chain from buffer
  6615. }
  6616. \endcode
  6617. \sa wolfSSL_CTX_load_verify_buffer
  6618. \sa wolfSSL_CTX_use_certificate_buffer
  6619. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6620. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6621. \sa wolfSSL_use_certificate_buffer
  6622. \sa wolfSSL_use_PrivateKey_buffer
  6623. */
  6624. int wolfSSL_use_certificate_chain_buffer(WOLFSSL* ssl,
  6625. const unsigned char* in, long sz);
  6626. /*!
  6627. \ingroup CertsKeys
  6628. \brief This function unloads any certificates or keys that SSL owns.
  6629. \return SSL_SUCCESS - returned if the function executed successfully.
  6630. \return BAD_FUNC_ARG - returned if the WOLFSSL object is NULL.
  6631. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6632. _Example_
  6633. \code
  6634. WOLFSSL* ssl = wolfSSL_new(ctx);
  6635. ...
  6636. int unloadKeys = wolfSSL_UnloadCertsKeys(ssl);
  6637. if(unloadKeys != SSL_SUCCESS){
  6638. // Failure case.
  6639. }
  6640. \endcode
  6641. \sa wolfSSL_CTX_UnloadCAs
  6642. */
  6643. int wolfSSL_UnloadCertsKeys(WOLFSSL*);
  6644. /*!
  6645. \ingroup Setup
  6646. \brief This function turns on grouping of handshake messages where possible.
  6647. \return SSL_SUCCESS will be returned upon success.
  6648. \return BAD_FUNC_ARG will be returned if the input context is null.
  6649. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6650. _Example_
  6651. \code
  6652. WOLFSSL_CTX* ctx = 0;
  6653. ...
  6654. ret = wolfSSL_CTX_set_group_messages(ctx);
  6655. if (ret != SSL_SUCCESS) {
  6656. // failed to set handshake message grouping
  6657. }
  6658. \endcode
  6659. \sa wolfSSL_set_group_messages
  6660. \sa wolfSSL_CTX_new
  6661. */
  6662. int wolfSSL_CTX_set_group_messages(WOLFSSL_CTX*);
  6663. /*!
  6664. \ingroup Setup
  6665. \brief This function turns on grouping of handshake messages where possible.
  6666. \return SSL_SUCCESS will be returned upon success.
  6667. \return BAD_FUNC_ARG will be returned if the input context is null.
  6668. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6669. _Example_
  6670. \code
  6671. WOLFSSL* ssl = 0;
  6672. ...
  6673. ret = wolfSSL_set_group_messages(ssl);
  6674. if (ret != SSL_SUCCESS) {
  6675. // failed to set handshake message grouping
  6676. }
  6677. \endcode
  6678. \sa wolfSSL_CTX_set_group_messages
  6679. \sa wolfSSL_new
  6680. */
  6681. int wolfSSL_set_group_messages(WOLFSSL*);
  6682. /*!
  6683. \brief This function sets the fuzzer callback.
  6684. \return none No returns.
  6685. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6686. \param cbf a CallbackFuzzer type that is a function pointer of the form:
  6687. int (*CallbackFuzzer)(WOLFSSL* ssl, const unsigned char* buf, int sz, int
  6688. type, void* fuzzCtx);
  6689. \param fCtx a void pointer type that will be set to the fuzzerCtx member of
  6690. the WOLFSSL structure.
  6691. _Example_
  6692. \code
  6693. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6694. WOLFSSL* ssl = wolfSSL_new(ctx);
  6695. void* fCtx;
  6696. int callbackFuzzerCB(WOLFSSL* ssl, const unsigned char* buf, int sz,
  6697. int type, void* fuzzCtx){
  6698. // function definition
  6699. }
  6700. wolfSSL_SetFuzzerCb(ssl, callbackFuzzerCB, fCtx);
  6701. \endcode
  6702. \sa CallbackFuzzer
  6703. */
  6704. void wolfSSL_SetFuzzerCb(WOLFSSL* ssl, CallbackFuzzer cbf, void* fCtx);
  6705. /*!
  6706. \brief This function sets a new dtls cookie secret.
  6707. \return 0 returned if the function executed without an error.
  6708. \return BAD_FUNC_ARG returned if there was an argument passed
  6709. to the function with an unacceptable value.
  6710. \return COOKIE_SECRET_SZ returned if the secret size is 0.
  6711. \return MEMORY_ERROR returned if there was a problem allocating
  6712. memory for a new cookie secret.
  6713. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6714. \param secret a constant byte pointer representing the secret buffer.
  6715. \param secretSz the size of the buffer.
  6716. _Example_
  6717. \code
  6718. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6719. WOLFSSL* ssl = wolfSSL_new(ctx);
  6720. const* byte secret;
  6721. word32 secretSz; // size of secret
  6722. if(!wolfSSL_DTLS_SetCookieSecret(ssl, secret, secretSz)){
  6723. // Code block for failure to set DTLS cookie secret
  6724. } else {
  6725. // Success! Cookie secret is set.
  6726. }
  6727. \endcode
  6728. \sa ForceZero
  6729. \sa wc_RNG_GenerateBlock
  6730. */
  6731. int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
  6732. const unsigned char* secret,
  6733. unsigned int secretSz);
  6734. /*!
  6735. \brief This function retrieves the random number.
  6736. \return rng upon success.
  6737. \return NULL if ssl is NULL.
  6738. \param ssl pointer to a SSL object, created with wolfSSL_new().
  6739. _Example_
  6740. \code
  6741. WOLFSSL* ssl;
  6742. wolfSSL_GetRNG(ssl);
  6743. \endcode
  6744. \sa wolfSSL_CTX_new_rng
  6745. */
  6746. WC_RNG* wolfSSL_GetRNG(WOLFSSL* ssl);
  6747. /*!
  6748. \ingroup Setup
  6749. \brief This function sets the minimum downgrade version allowed.
  6750. Applicable only when the connection allows downgrade using
  6751. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6752. \return SSL_SUCCESS returned if the function returned without
  6753. error and the minimum version is set.
  6754. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure was
  6755. NULL or if the minimum version is not supported.
  6756. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6757. wolfSSL_CTX_new().
  6758. \param version an integer representation of the version to be set as the
  6759. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6760. WOLFSSL_TLSV1_2 = 3.
  6761. _Example_
  6762. \code
  6763. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  6764. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6765. int version; // macrop representation
  6766. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6767. // Failed to set min version
  6768. }
  6769. \endcode
  6770. \sa SetMinVersionHelper
  6771. */
  6772. int wolfSSL_CTX_SetMinVersion(WOLFSSL_CTX* ctx, int version);
  6773. /*!
  6774. \ingroup TLS
  6775. \brief This function sets the minimum downgrade version allowed.
  6776. Applicable only when the connection allows downgrade using
  6777. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6778. \return SSL_SUCCESS returned if this function and its subroutine executes
  6779. without error.
  6780. \return BAD_FUNC_ARG returned if the SSL object is NULL. In
  6781. the subroutine this error is thrown if there is not a good version match.
  6782. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6783. \param version an integer representation of the version to be set as the
  6784. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6785. WOLFSSL_TLSV1_2 = 3.
  6786. _Example_
  6787. \code
  6788. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol method);
  6789. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6790. int version; macro representation
  6791. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6792. Failed to set min version
  6793. }
  6794. \endcode
  6795. \sa SetMinVersionHelper
  6796. */
  6797. int wolfSSL_SetMinVersion(WOLFSSL* ssl, int version);
  6798. /*!
  6799. \brief This function returns the size of the WOLFSSL object and will be
  6800. dependent on build options and settings. If SHOW_SIZES has been defined
  6801. when building wolfSSL, this function will also print the sizes of individual
  6802. objects within the WOLFSSL object (Suites, Ciphers, etc.) to stdout.
  6803. \return size This function returns the size of the WOLFSSL object.
  6804. \param none No parameters.
  6805. _Example_
  6806. \code
  6807. int size = 0;
  6808. size = wolfSSL_GetObjectSize();
  6809. printf(“sizeof(WOLFSSL) = %d\n”, size);
  6810. \endcode
  6811. \sa wolfSSL_new
  6812. */
  6813. int wolfSSL_GetObjectSize(void); /* object size based on build */
  6814. /*!
  6815. \brief Returns the record layer size of the plaintext input. This is helpful
  6816. when an application wants to know how many bytes will be sent across the
  6817. Transport layer, given a specified plaintext input size. This function
  6818. must be called after the SSL/TLS handshake has been completed.
  6819. \return size Upon success, the requested size will be returned
  6820. \return INPUT_SIZE_E will be returned if the input size is greater than the
  6821. maximum TLS fragment size (see wolfSSL_GetMaxOutputSize())
  6822. \return BAD_FUNC_ARG will be returned upon invalid function argument, or if
  6823. the SSL/TLS handshake has not been completed yet
  6824. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6825. \param inSz size of plaintext data.
  6826. _Example_
  6827. \code
  6828. none
  6829. \endcode
  6830. \sa wolfSSL_GetMaxOutputSize
  6831. */
  6832. int wolfSSL_GetOutputSize(WOLFSSL* ssl, int inSz);
  6833. /*!
  6834. \brief Returns the maximum record layer size for plaintext data. This
  6835. will correspond to either the maximum SSL/TLS record size as specified
  6836. by the protocol standard, the maximum TLS fragment size as set by the
  6837. TLS Max Fragment Length extension. This function is helpful when the
  6838. application has called wolfSSL_GetOutputSize() and received a INPUT_SIZE_E
  6839. error. This function must be called after the SSL/TLS handshake has been
  6840. completed.
  6841. \return size Upon success, the maximum output size will be returned
  6842. \return BAD_FUNC_ARG will be returned upon invalid function argument,
  6843. or if the SSL/TLS handshake has not been completed yet.
  6844. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6845. _Example_
  6846. \code
  6847. none
  6848. \endcode
  6849. \sa wolfSSL_GetOutputSize
  6850. */
  6851. int wolfSSL_GetMaxOutputSize(WOLFSSL*);
  6852. /*!
  6853. \ingroup Setup
  6854. \brief This function sets the SSL/TLS protocol version for the specified
  6855. SSL session (WOLFSSL object) using the version as specified by version.
  6856. This will override the protocol setting for the SSL session (ssl) -
  6857. originally defined and set by the SSL context (wolfSSL_CTX_new())
  6858. method type.
  6859. \return SSL_SUCCESS upon success.
  6860. \return BAD_FUNC_ARG will be returned if the input SSL object is
  6861. NULL or an incorrect protocol version is given for version.
  6862. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6863. \param version SSL/TLS protocol version. Possible values include
  6864. WOLFSSL_SSLV3, WOLFSSL_TLSV1, WOLFSSL_TLSV1_1, WOLFSSL_TLSV1_2.
  6865. _Example_
  6866. \code
  6867. int ret = 0;
  6868. WOLFSSL* ssl;
  6869. ...
  6870. ret = wolfSSL_SetVersion(ssl, WOLFSSL_TLSV1);
  6871. if (ret != SSL_SUCCESS) {
  6872. // failed to set SSL session protocol version
  6873. }
  6874. \endcode
  6875. \sa wolfSSL_CTX_new
  6876. */
  6877. int wolfSSL_SetVersion(WOLFSSL* ssl, int version);
  6878. /*!
  6879. \brief Allows caller to set the Atomic User Record Processing
  6880. Mac/Encrypt Callback. The callback should return 0 for success
  6881. or < 0 for an error. The ssl and ctx pointers are available
  6882. for the user’s convenience. macOut is the output buffer where
  6883. the result of the mac should be stored. macIn is the mac input
  6884. buffer and macInSz notes the size of the buffer. macContent
  6885. and macVerify are needed for wolfSSL_SetTlsHmacInner() and be
  6886. passed along as is. encOut is the output buffer where the result
  6887. on the encryption should be stored. encIn is the input buffer to
  6888. encrypt while encSz is the size of the input. An example callback
  6889. can be found wolfssl/test.h myMacEncryptCb().
  6890. \return none No return.
  6891. \param No parameters.
  6892. _Example_
  6893. \code
  6894. none
  6895. \endcode
  6896. \sa wolfSSL_SetMacEncryptCtx
  6897. \sa wolfSSL_GetMacEncryptCtx
  6898. */
  6899. void wolfSSL_CTX_SetMacEncryptCb(WOLFSSL_CTX* ctx, CallbackMacEncrypti cb);
  6900. /*!
  6901. \brief Allows caller to set the Atomic User Record Processing Mac/Encrypt
  6902. Callback Context to ctx.
  6903. \return none No return.
  6904. \param none No parameters.
  6905. _Example_
  6906. \code
  6907. none
  6908. \endcode
  6909. \sa wolfSSL_CTX_SetMacEncryptCb
  6910. \sa wolfSSL_GetMacEncryptCtx
  6911. */
  6912. void wolfSSL_SetMacEncryptCtx(WOLFSSL* ssl, void *ctx);
  6913. /*!
  6914. \brief Allows caller to retrieve the Atomic User Record Processing
  6915. Mac/Encrypt Callback Context previously stored with
  6916. wolfSSL_SetMacEncryptCtx().
  6917. \return pointer If successful the call will return a valid pointer
  6918. to the context.
  6919. \return NULL will be returned for a blank context.
  6920. \param none No parameters.
  6921. _Example_
  6922. \code
  6923. none
  6924. \endcode
  6925. \sa wolfSSL_CTX_SetMacEncryptCb
  6926. \sa wolfSSL_SetMacEncryptCtx
  6927. */
  6928. void* wolfSSL_GetMacEncryptCtx(WOLFSSL* ssl);
  6929. /*!
  6930. \brief Allows caller to set the Atomic User Record Processing
  6931. Decrypt/Verify Callback. The callback should return 0 for success
  6932. or < 0 for an error. The ssl and ctx pointers are available for
  6933. the user’s convenience. decOut is the output buffer where the result
  6934. of the decryption should be stored. decIn is the encrypted input
  6935. buffer and decInSz notes the size of the buffer. content and verify
  6936. are needed for wolfSSL_SetTlsHmacInner() and be passed along as is.
  6937. padSz is an output variable that should be set with the total value
  6938. of the padding. That is, the mac size plus any padding and pad bytes.
  6939. An example callback can be found wolfssl/test.h myDecryptVerifyCb().
  6940. \return none No returns.
  6941. \param none No parameters.
  6942. _Example_
  6943. \code
  6944. none
  6945. \endcode
  6946. \sa wolfSSL_SetMacEncryptCtx
  6947. \sa wolfSSL_GetMacEncryptCtx
  6948. */
  6949. void wolfSSL_CTX_SetDecryptVerifyCb(WOLFSSL_CTX* ctx,
  6950. CallbackDecryptVerify cb);
  6951. /*!
  6952. \brief Allows caller to set the Atomic User Record Processing
  6953. Decrypt/Verify Callback Context to ctx.
  6954. \return none No returns.
  6955. \param none No parameters.
  6956. _Example_
  6957. \code
  6958. none
  6959. \endcode
  6960. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6961. \sa wolfSSL_GetDecryptVerifyCtx
  6962. */
  6963. void wolfSSL_SetDecryptVerifyCtx(WOLFSSL* ssl, void *ctx);
  6964. /*!
  6965. \brief Allows caller to retrieve the Atomic User Record Processing
  6966. Decrypt/Verify Callback Context previously stored with
  6967. wolfSSL_SetDecryptVerifyCtx().
  6968. \return pointer If successful the call will return a valid pointer to the
  6969. context.
  6970. \return NULL will be returned for a blank context.
  6971. \param none No parameters.
  6972. _Example_
  6973. \code
  6974. none
  6975. \endcode
  6976. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6977. \sa wolfSSL_SetDecryptVerifyCtx
  6978. */
  6979. void* wolfSSL_GetDecryptVerifyCtx(WOLFSSL* ssl);
  6980. /*!
  6981. \brief Allows retrieval of the Hmac/Mac secret from the handshake process.
  6982. The verify parameter specifies whether this is for verification of a
  6983. peer message.
  6984. \return pointer If successful the call will return a valid pointer to the
  6985. secret. The size of the secret can be obtained from wolfSSL_GetHmacSize().
  6986. \return NULL will be returned for an error state.
  6987. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6988. \param verify specifies whether this is for verification of a peer message.
  6989. _Example_
  6990. \code
  6991. none
  6992. \endcode
  6993. \sa wolfSSL_GetHmacSize
  6994. */
  6995. const unsigned char* wolfSSL_GetMacSecret(WOLFSSL* ssl, int verify);
  6996. /*!
  6997. \brief Allows retrieval of the client write key from the handshake process.
  6998. \return pointer If successful the call will return a valid pointer to the
  6999. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  7000. \return NULL will be returned for an error state.
  7001. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7002. _Example_
  7003. \code
  7004. none
  7005. \endcode
  7006. \sa wolfSSL_GetKeySize
  7007. \sa wolfSSL_GetClientWriteIV
  7008. */
  7009. const unsigned char* wolfSSL_GetClientWriteKey(WOLFSSL*);
  7010. /*!
  7011. \brief Allows retrieval of the client write IV (initialization vector)
  7012. from the handshake process.
  7013. \return pointer If successful the call will return a valid pointer to the
  7014. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  7015. \return NULL will be returned for an error state.
  7016. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7017. _Example_
  7018. \code
  7019. none
  7020. \endcode
  7021. \sa wolfSSL_GetCipherBlockSize()
  7022. \sa wolfSSL_GetClientWriteKey()
  7023. */
  7024. const unsigned char* wolfSSL_GetClientWriteIV(WOLFSSL*);
  7025. /*!
  7026. \brief Allows retrieval of the server write key from the handshake process.
  7027. \return pointer If successful the call will return a valid pointer to the
  7028. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  7029. \return NULL will be returned for an error state.
  7030. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7031. _Example_
  7032. \code
  7033. none
  7034. \endcode
  7035. \sa wolfSSL_GetKeySize
  7036. \sa wolfSSL_GetServerWriteIV
  7037. */
  7038. const unsigned char* wolfSSL_GetServerWriteKey(WOLFSSL*);
  7039. /*!
  7040. \brief Allows retrieval of the server write IV (initialization vector)
  7041. from the handshake process.
  7042. \return pointer If successful the call will return a valid pointer to the
  7043. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  7044. \return NULL will be returned for an error state.
  7045. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7046. \sa wolfSSL_GetCipherBlockSize
  7047. \sa wolfSSL_GetClientWriteKey
  7048. */
  7049. const unsigned char* wolfSSL_GetServerWriteIV(WOLFSSL*);
  7050. /*!
  7051. \brief Allows retrieval of the key size from the handshake process.
  7052. \return size If successful the call will return the key size in bytes.
  7053. \return BAD_FUNC_ARG will be returned for an error state.
  7054. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7055. _Example_
  7056. \code
  7057. none
  7058. \endcode
  7059. \sa wolfSSL_GetClientWriteKey
  7060. \sa wolfSSL_GetServerWriteKey
  7061. */
  7062. int wolfSSL_GetKeySize(WOLFSSL*);
  7063. /*!
  7064. \ingroup CertsKeys
  7065. \brief Returns the iv_size member of the specs structure
  7066. held in the WOLFSSL struct.
  7067. \return iv_size returns the value held in ssl->specs.iv_size.
  7068. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  7069. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7070. _Example_
  7071. \code
  7072. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7073. WOLFSSL* ssl = wolfSSL_new(ctx);
  7074. int ivSize;
  7075. ...
  7076. ivSize = wolfSSL_GetIVSize(ssl);
  7077. if(ivSize > 0){
  7078. // ivSize holds the specs.iv_size value.
  7079. }
  7080. \endcode
  7081. \sa wolfSSL_GetKeySize
  7082. \sa wolfSSL_GetClientWriteIV
  7083. \sa wolfSSL_GetServerWriteIV
  7084. */
  7085. int wolfSSL_GetIVSize(WOLFSSL*);
  7086. /*!
  7087. \brief Allows retrieval of the side of this WOLFSSL connection.
  7088. \return success If successful the call will return either
  7089. WOLFSSL_SERVER_END or WOLFSSL_CLIENT_END depending on the
  7090. side of WOLFSSL object.
  7091. \return BAD_FUNC_ARG will be returned for an error state.
  7092. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7093. _Example_
  7094. \code
  7095. none
  7096. \endcode
  7097. \sa wolfSSL_GetClientWriteKey
  7098. \sa wolfSSL_GetServerWriteKey
  7099. */
  7100. int wolfSSL_GetSide(WOLFSSL*);
  7101. /*!
  7102. \brief Allows caller to determine if the negotiated protocol version
  7103. is at least TLS version 1.1 or greater.
  7104. \return true/false If successful the call will return 1 for true or
  7105. 0 for false.
  7106. \return BAD_FUNC_ARG will be returned for an error state.
  7107. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7108. _Example_
  7109. \code
  7110. none
  7111. \endcode
  7112. \sa wolfSSL_GetSide
  7113. */
  7114. int wolfSSL_IsTLSv1_1(WOLFSSL*);
  7115. /*!
  7116. \brief Allows caller to determine the negotiated bulk cipher algorithm
  7117. from the handshake.
  7118. \return If successful the call will return one of the following:
  7119. wolfssl_cipher_null, wolfssl_des, wolfssl_triple_des, wolfssl_aes,
  7120. wolfssl_aes_gcm, wolfssl_aes_ccm, wolfssl_camellia.
  7121. \return BAD_FUNC_ARG will be returned for an error state.
  7122. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7123. _Example_
  7124. \code
  7125. none
  7126. \endcode
  7127. \sa wolfSSL_GetCipherBlockSize
  7128. \sa wolfSSL_GetKeySize
  7129. */
  7130. int wolfSSL_GetBulkCipher(WOLFSSL*);
  7131. /*!
  7132. \brief Allows caller to determine the negotiated cipher block size from
  7133. the handshake.
  7134. \return size If successful the call will return the size in bytes of the
  7135. cipher block size.
  7136. \return BAD_FUNC_ARG will be returned for an error state.
  7137. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7138. _Example_
  7139. \code
  7140. none
  7141. \endcode
  7142. \sa wolfSSL_GetBulkCipher
  7143. \sa wolfSSL_GetKeySize
  7144. */
  7145. int wolfSSL_GetCipherBlockSize(WOLFSSL*);
  7146. /*!
  7147. \brief Allows caller to determine the negotiated aead mac size from the
  7148. handshake. For cipher type WOLFSSL_AEAD_TYPE.
  7149. \return size If successful the call will return the size in bytes of the
  7150. aead mac size.
  7151. \return BAD_FUNC_ARG will be returned for an error state.
  7152. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7153. _Example_
  7154. \code
  7155. none
  7156. \endcode
  7157. \sa wolfSSL_GetBulkCipher
  7158. \sa wolfSSL_GetKeySize
  7159. */
  7160. int wolfSSL_GetAeadMacSize(WOLFSSL*);
  7161. /*!
  7162. \brief Allows caller to determine the negotiated (h)mac size from the
  7163. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  7164. \return size If successful the call will return the size in bytes of
  7165. the (h)mac size.
  7166. \return BAD_FUNC_ARG will be returned for an error state.
  7167. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7168. _Example_
  7169. \code
  7170. none
  7171. \endcode
  7172. \sa wolfSSL_GetBulkCipher
  7173. \sa wolfSSL_GetHmacType
  7174. */
  7175. int wolfSSL_GetHmacSize(WOLFSSL*);
  7176. /*!
  7177. \brief Allows caller to determine the negotiated (h)mac type from the
  7178. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  7179. \return If successful the call will return one of the following:
  7180. MD5, SHA, SHA256, SHA384.
  7181. \return BAD_FUNC_ARG may be returned for an error state.
  7182. \return SSL_FATAL_ERROR may also be returned for an error state.
  7183. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7184. _Example_
  7185. \code
  7186. none
  7187. \endcode
  7188. \sa wolfSSL_GetBulkCipher
  7189. \sa wolfSSL_GetHmacSize
  7190. */
  7191. int wolfSSL_GetHmacType(WOLFSSL*);
  7192. /*!
  7193. \brief Allows caller to determine the negotiated cipher type
  7194. from the handshake.
  7195. \return If successful the call will return one of the following:
  7196. WOLFSSL_BLOCK_TYPE, WOLFSSL_STREAM_TYPE, WOLFSSL_AEAD_TYPE.
  7197. \return BAD_FUNC_ARG will be returned for an error state.
  7198. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7199. _Example_
  7200. \code
  7201. none
  7202. \endcode
  7203. \sa wolfSSL_GetBulkCipher
  7204. \sa wolfSSL_GetHmacType
  7205. */
  7206. int wolfSSL_GetCipherType(WOLFSSL*);
  7207. /*!
  7208. \brief Allows caller to set the Hmac Inner vector for message
  7209. sending/receiving. The result is written to inner which should
  7210. be at least wolfSSL_GetHmacSize() bytes. The size of the message
  7211. is specified by sz, content is the type of message, and verify
  7212. specifies whether this is a verification of a peer message. Valid
  7213. for cipher types excluding WOLFSSL_AEAD_TYPE.
  7214. \return 1 upon success.
  7215. \return BAD_FUNC_ARG will be returned for an error state.
  7216. \param none No parameters.
  7217. _Example_
  7218. \code
  7219. none
  7220. \endcode
  7221. \sa wolfSSL_GetBulkCipher
  7222. \sa wolfSSL_GetHmacType
  7223. */
  7224. int wolfSSL_SetTlsHmacInner(WOLFSSL* ssl, byte* inner,
  7225. word32 sz, int content, int verify);
  7226. /*!
  7227. \brief Allows caller to set the Public Key Callback for ECC Signing.
  7228. The callback should return 0 for success or < 0 for an error.
  7229. The ssl and ctx pointers are available for the user’s convenience.
  7230. in is the input buffer to sign while inSz denotes the length of the input.
  7231. out is the output buffer where the result of the signature should be stored.
  7232. outSz is an input/output variable that specifies the size of the output
  7233. buffer upon invocation and the actual size of the signature should be stored
  7234. there before returning. keyDer is the ECC Private key in ASN1 format and
  7235. keySz is the length of the key in bytes. An example callback can be found
  7236. wolfssl/test.h myEccSign().
  7237. \return none No returns.
  7238. \param none No parameters.
  7239. _Example_
  7240. \code
  7241. none
  7242. \endcode
  7243. \sa wolfSSL_SetEccSignCtx
  7244. \sa wolfSSL_GetEccSignCtx
  7245. */
  7246. void wolfSSL_CTX_SetEccSignCb(WOLFSSL_CTX* ctx, CallbackEccSign cb);
  7247. /*!
  7248. \brief Allows caller to set the Public Key Ecc Signing Callback
  7249. Context to ctx.
  7250. \return none No returns.
  7251. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7252. \param ctx a pointer to the user context to be stored
  7253. _Example_
  7254. \code
  7255. none
  7256. \endcode
  7257. \sa wolfSSL_CTX_SetEccSignCb
  7258. \sa wolfSSL_GetEccSignCtx
  7259. */
  7260. void wolfSSL_SetEccSignCtx(WOLFSSL* ssl, void *ctx);
  7261. /*!
  7262. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  7263. Context previously stored with wolfSSL_SetEccSignCtx().
  7264. \return pointer If successful the call will return a valid pointer
  7265. to the context.
  7266. \return NULL will be returned for a blank context.
  7267. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7268. _Example_
  7269. \code
  7270. none
  7271. \endcode
  7272. \sa wolfSSL_CTX_SetEccSignCb
  7273. \sa wolfSSL_SetEccSignCtx
  7274. */
  7275. void* wolfSSL_GetEccSignCtx(WOLFSSL* ssl);
  7276. /*!
  7277. \brief Allows caller to set the Public Key Ecc Signing Callback
  7278. Context to ctx.
  7279. \return none No returns.
  7280. \param ctx a pointer to a WOLFSSL_CTX structure, created
  7281. with wolfSSL_CTX_new().
  7282. \param ctx a pointer to the user context to be stored
  7283. _Example_
  7284. \code
  7285. none
  7286. \endcode
  7287. \sa wolfSSL_CTX_SetEccSignCb
  7288. \sa wolfSSL_CTX_GetEccSignCtx
  7289. */
  7290. void wolfSSL_CTX_SetEccSignCtx(WOLFSSL_CTX* ctx, void *userCtx);
  7291. /*!
  7292. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  7293. Context previously stored with wolfSSL_SetEccSignCtx().
  7294. \return pointer If successful the call will return a valid pointer
  7295. to the context.
  7296. \return NULL will be returned for a blank context.
  7297. \param ctx a pointer to a WOLFSSL_CTX structure, created
  7298. with wolfSSL_CTX_new().
  7299. _Example_
  7300. \code
  7301. none
  7302. \endcode
  7303. \sa wolfSSL_CTX_SetEccSignCb
  7304. \sa wolfSSL_CTX_SetEccSignCtx
  7305. */
  7306. void* wolfSSL_CTX_GetEccSignCtx(WOLFSSL_CTX* ctx);
  7307. /*!
  7308. \brief Allows caller to set the Public Key Callback for ECC Verification.
  7309. The callback should return 0 for success or < 0 for an error.
  7310. The ssl and ctx pointers are available for the user’s convenience.
  7311. sig is the signature to verify and sigSz denotes the length of the
  7312. signature. hash is an input buffer containing the digest of the message
  7313. and hashSz denotes the length in bytes of the hash. result is an output
  7314. variable where the result of the verification should be stored, 1 for
  7315. success and 0 for failure. keyDer is the ECC Private key in ASN1
  7316. format and keySz is the length of the key in bytes. An example
  7317. callback can be found wolfssl/test.h myEccVerify().
  7318. \return none No returns.
  7319. \param none No parameters.
  7320. _Example_
  7321. \code
  7322. none
  7323. \endcode
  7324. \sa wolfSSL_SetEccVerifyCtx
  7325. \sa wolfSSL_GetEccVerifyCtx
  7326. */
  7327. void wolfSSL_CTX_SetEccVerifyCb(WOLFSSL_CTX* ctx, CallbackEccVerify cb);
  7328. /*!
  7329. \brief Allows caller to set the Public Key Ecc Verification Callback
  7330. Context to ctx.
  7331. \return none No returns.
  7332. \param none No parameters.
  7333. _Example_
  7334. \code
  7335. none
  7336. \endcode
  7337. \sa wolfSSL_CTX_SetEccVerifyCb
  7338. \sa wolfSSL_GetEccVerifyCtx
  7339. */
  7340. void wolfSSL_SetEccVerifyCtx(WOLFSSL* ssl, void *ctx);
  7341. /*!
  7342. \brief Allows caller to retrieve the Public Key Ecc Verification Callback
  7343. Context previously stored with wolfSSL_SetEccVerifyCtx().
  7344. \return pointer If successful the call will return a valid pointer to the
  7345. context.
  7346. \return NULL will be returned for a blank context.
  7347. \param none No parameters.
  7348. _Example_
  7349. \code
  7350. none
  7351. \endcode
  7352. \sa wolfSSL_CTX_SetEccVerifyCb
  7353. \sa wolfSSL_SetEccVerifyCtx
  7354. */
  7355. void* wolfSSL_GetEccVerifyCtx(WOLFSSL* ssl);
  7356. /*!
  7357. \brief Allows caller to set the Public Key Callback for RSA Signing.
  7358. The callback should return 0 for success or < 0 for an error.
  7359. The ssl and ctx pointers are available for the user’s convenience.
  7360. in is the input buffer to sign while inSz denotes the length of the input.
  7361. out is the output buffer where the result of the signature should be stored.
  7362. outSz is an input/output variable that specifies the size of the output
  7363. buffer upon invocation and the actual size of the signature should be
  7364. stored there before returning. keyDer is the RSA Private key in ASN1 format
  7365. and keySz is the length of the key in bytes. An example callback can be
  7366. found wolfssl/test.h myRsaSign().
  7367. \return none No returns.
  7368. \param none No parameters.
  7369. _Example_
  7370. \code
  7371. none
  7372. \endcode
  7373. \sa wolfSSL_SetRsaSignCtx
  7374. \sa wolfSSL_GetRsaSignCtx
  7375. */
  7376. void wolfSSL_CTX_SetRsaSignCb(WOLFSSL_CTX* ctx, CallbackRsaSign cb);
  7377. /*!
  7378. \brief Allows caller to set the Public Key RSA Signing Callback Context
  7379. to ctx.
  7380. \return none No Returns.
  7381. \param none No parameters.
  7382. _Example_
  7383. \code
  7384. none
  7385. \endcode
  7386. \sa wolfSSL_CTX_SetRsaSignCb
  7387. \sa wolfSSL_GetRsaSignCtx
  7388. */
  7389. void wolfSSL_SetRsaSignCtx(WOLFSSL* ssl, void *ctx);
  7390. /*!
  7391. \brief Allows caller to retrieve the Public Key RSA Signing Callback
  7392. Context previously stored with wolfSSL_SetRsaSignCtx().
  7393. \return pointer If successful the call will return a valid pointer to the
  7394. context.
  7395. \return NULL will be returned for a blank context.
  7396. \param none No parameters.
  7397. \param none No parameters.
  7398. _Example_
  7399. \code
  7400. none
  7401. \endcode
  7402. \sa wolfSSL_CTX_SetRsaSignCb
  7403. \sa wolfSSL_SetRsaSignCtx
  7404. */
  7405. void* wolfSSL_GetRsaSignCtx(WOLFSSL* ssl);
  7406. /*!
  7407. \brief Allows caller to set the Public Key Callback for RSA Verification.
  7408. The callback should return the number of plaintext bytes for success or
  7409. < 0 for an error. The ssl and ctx pointers are available for the user’s
  7410. convenience. sig is the signature to verify and sigSz denotes the length
  7411. of the signature. out should be set to the beginning of the verification
  7412. buffer after the decryption process and any padding. keyDer is the RSA
  7413. Public key in ASN1 format and keySz is the length of the key in bytes.
  7414. An example callback can be found wolfssl/test.h myRsaVerify().
  7415. \return none No returns.
  7416. \param none No parameters.
  7417. \sa wolfSSL_SetRsaVerifyCtx
  7418. \sa wolfSSL_GetRsaVerifyCtx
  7419. */
  7420. void wolfSSL_CTX_SetRsaVerifyCb(WOLFSSL_CTX* ctx, CallbackRsaVerify cb);
  7421. /*!
  7422. \brief Allows caller to set the Public Key RSA Verification Callback
  7423. Context to ctx.
  7424. \return none No returns.
  7425. \param none No parameters.
  7426. _Example_
  7427. \code
  7428. none
  7429. \endcode
  7430. \sa wolfSSL_CTX_SetRsaVerifyCb
  7431. \sa wolfSSL_GetRsaVerifyCtx
  7432. */
  7433. void wolfSSL_SetRsaVerifyCtx(WOLFSSL* ssl, void *ctx);
  7434. /*!
  7435. \brief Allows caller to retrieve the Public Key RSA Verification Callback
  7436. Context previously stored with wolfSSL_SetRsaVerifyCtx().
  7437. \return pointer If successful the call will return a valid pointer to
  7438. the context.
  7439. \return NULL will be returned for a blank context.
  7440. \param none No parameters.
  7441. _Example_
  7442. \code
  7443. none
  7444. \endcode
  7445. \sa wolfSSL_CTX_SetRsaVerifyCb
  7446. \sa wolfSSL_SetRsaVerifyCtx
  7447. */
  7448. void* wolfSSL_GetRsaVerifyCtx(WOLFSSL* ssl);
  7449. /*!
  7450. \brief Allows caller to set the Public Key Callback for RSA Public
  7451. Encrypt. The callback should return 0 for success or < 0 for an error.
  7452. The ssl and ctx pointers are available for the user’s convenience.
  7453. in is the input buffer to encrypt while inSz denotes the length of
  7454. the input. out is the output buffer where the result of the encryption
  7455. should be stored. outSz is an input/output variable that specifies
  7456. the size of the output buffer upon invocation and the actual size of
  7457. the encryption should be stored there before returning. keyDer is the
  7458. RSA Public key in ASN1 format and keySz is the length of the key in
  7459. bytes. An example callback can be found wolfssl/test.h myRsaEnc().
  7460. \return none No returns.
  7461. \param none No parameters.
  7462. _Examples_
  7463. \code
  7464. none
  7465. \endcode
  7466. \sa wolfSSL_SetRsaEncCtx
  7467. \sa wolfSSL_GetRsaEncCtx
  7468. */
  7469. void wolfSSL_CTX_SetRsaEncCb(WOLFSSL_CTX* ctx, CallbackRsaEnc cb);
  7470. /*!
  7471. \brief Allows caller to set the Public Key RSA Public Encrypt
  7472. Callback Context to ctx.
  7473. \return none No returns.
  7474. \param none No parameters.
  7475. _Example_
  7476. \code
  7477. none
  7478. \endcode
  7479. \sa wolfSSL_CTX_SetRsaEncCb
  7480. \sa wolfSSL_GetRsaEncCtx
  7481. */
  7482. void wolfSSL_SetRsaEncCtx(WOLFSSL* ssl, void *ctx);
  7483. /*!
  7484. \brief Allows caller to retrieve the Public Key RSA Public Encrypt
  7485. Callback Context previously stored with wolfSSL_SetRsaEncCtx().
  7486. \return pointer If successful the call will return a valid pointer
  7487. to the context.
  7488. \return NULL will be returned for a blank context.
  7489. \param none No parameters.
  7490. _Example_
  7491. \code
  7492. none
  7493. \endcode
  7494. \sa wolfSSL_CTX_SetRsaEncCb
  7495. \sa wolfSSL_SetRsaEncCtx
  7496. */
  7497. void* wolfSSL_GetRsaEncCtx(WOLFSSL* ssl);
  7498. /*!
  7499. \brief Allows caller to set the Public Key Callback for RSA Private
  7500. Decrypt. The callback should return the number of plaintext bytes
  7501. for success or < 0 for an error. The ssl and ctx pointers are available
  7502. for the user’s convenience. in is the input buffer to decrypt and inSz
  7503. denotes the length of the input. out should be set to the beginning
  7504. of the decryption buffer after the decryption process and any padding.
  7505. keyDer is the RSA Private key in ASN1 format and keySz is the length
  7506. of the key in bytes. An example callback can be found
  7507. wolfssl/test.h myRsaDec().
  7508. \return none No returns.
  7509. \param none No parameters.
  7510. _Example_
  7511. \code
  7512. none
  7513. \endcode
  7514. \sa wolfSSL_SetRsaDecCtx
  7515. \sa wolfSSL_GetRsaDecCtx
  7516. */
  7517. void wolfSSL_CTX_SetRsaDecCb(WOLFSSL_CTX* ctx, CallbackRsaDec cb);
  7518. /*!
  7519. \brief Allows caller to set the Public Key RSA Private Decrypt
  7520. Callback Context to ctx.
  7521. \return none No returns.
  7522. \param none No parameters.
  7523. _Example_
  7524. \code
  7525. none
  7526. \endcode
  7527. \sa wolfSSL_CTX_SetRsaDecCb
  7528. \sa wolfSSL_GetRsaDecCtx
  7529. */
  7530. void wolfSSL_SetRsaDecCtx(WOLFSSL* ssl, void *ctx);
  7531. /*!
  7532. \brief Allows caller to retrieve the Public Key RSA Private Decrypt
  7533. Callback Context previously stored with wolfSSL_SetRsaDecCtx().
  7534. \return pointer If successful the call will return a valid pointer
  7535. to the context.
  7536. \return NULL will be returned for a blank context.
  7537. \param none No parameters.
  7538. _Example_
  7539. \code
  7540. none
  7541. \endcode
  7542. \sa wolfSSL_CTX_SetRsaDecCb
  7543. \sa wolfSSL_SetRsaDecCtx
  7544. */
  7545. void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl);
  7546. /*!
  7547. \brief This function registers a callback with the SSL context
  7548. (WOLFSSL_CTX) to be called when a new CA certificate is loaded
  7549. into wolfSSL. The callback is given a buffer with the DER-encoded
  7550. certificate.
  7551. \return none No return.
  7552. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  7553. \param callback function to be registered as the CA callback for the
  7554. wolfSSL context, ctx. The signature of this function must follow that
  7555. as shown above in the Synopsis section.
  7556. _Example_
  7557. \code
  7558. WOLFSSL_CTX* ctx = 0;
  7559. // CA callback prototype
  7560. int MyCACallback(unsigned char *der, int sz, int type);
  7561. // Register the custom CA callback with the SSL context
  7562. wolfSSL_CTX_SetCACb(ctx, MyCACallback);
  7563. int MyCACallback(unsigned char* der, int sz, int type)
  7564. {
  7565. // custom CA callback function, DER-encoded cert
  7566. // located in “der” of size “sz” with type “type”
  7567. }
  7568. \endcode
  7569. \sa wolfSSL_CTX_load_verify_locations
  7570. */
  7571. void wolfSSL_CTX_SetCACb(WOLFSSL_CTX* ctx, CallbackCACache cb);
  7572. /*!
  7573. \ingroup CertManager
  7574. \brief Allocates and initializes a new Certificate Manager context.
  7575. This context may be used independent of SSL needs. It may be used to
  7576. load certificates, verify certificates, and check the revocation status.
  7577. \return WOLFSSL_CERT_MANAGER If successful the call will return a valid
  7578. WOLFSSL_CERT_MANAGER pointer.
  7579. \return NULL will be returned for an error state.
  7580. \param none No parameters.
  7581. \sa wolfSSL_CertManagerFree
  7582. */
  7583. WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew_ex(void* heap);
  7584. /*!
  7585. \ingroup CertManager
  7586. \brief Allocates and initializes a new Certificate Manager context.
  7587. This context may be used independent of SSL needs. It may be used to
  7588. load certificates, verify certificates, and check the revocation status.
  7589. \return WOLFSSL_CERT_MANAGER If successful the call will return a
  7590. valid WOLFSSL_CERT_MANAGER pointer.
  7591. \return NULL will be returned for an error state.
  7592. \param none No parameters.
  7593. _Example_
  7594. \code
  7595. #import <wolfssl/ssl.h>
  7596. WOLFSSL_CERT_MANAGER* cm;
  7597. cm = wolfSSL_CertManagerNew();
  7598. if (cm == NULL) {
  7599. // error creating new cert manager
  7600. }
  7601. \endcode
  7602. \sa wolfSSL_CertManagerFree
  7603. */
  7604. WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew(void);
  7605. /*!
  7606. \ingroup CertManager
  7607. \brief Frees all resources associated with the Certificate Manager
  7608. context. Call this when you no longer need to use the Certificate Manager.
  7609. \return none
  7610. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7611. wolfSSL_CertManagerNew().
  7612. _Example_
  7613. \code
  7614. #include <wolfssl/ssl.h>
  7615. WOLFSSL_CERT_MANAGER* cm;
  7616. ...
  7617. wolfSSL_CertManagerFree(cm);
  7618. \endcode
  7619. \sa wolfSSL_CertManagerNew
  7620. */
  7621. void wolfSSL_CertManagerFree(WOLFSSL_CERT_MANAGER*);
  7622. /*!
  7623. \ingroup CertManager
  7624. \brief Specifies the locations for CA certificate loading into the
  7625. manager context. The PEM certificate CAfile may contain several
  7626. trusted CA certificates. If CApath is not NULL it specifies a
  7627. directory containing CA certificates in PEM format.
  7628. \return SSL_SUCCESS If successful the call will return.
  7629. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7630. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  7631. can’t be read, or is corrupted.
  7632. \return MEMORY_E will be returned if an out of memory condition occurs.
  7633. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7634. \return BAD_FUNC_ARG is the error that will be returned if a
  7635. pointer is not provided.
  7636. \return SSL_FATAL_ERROR - will be returned upon failure.
  7637. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created
  7638. using wolfSSL_CertManagerNew().
  7639. \param file pointer to the name of the file containing CA
  7640. certificates to load.
  7641. \param path pointer to the name of a directory path containing CA c
  7642. ertificates to load. The NULL pointer may be used if no
  7643. certificate directory is desired.
  7644. _Example_
  7645. \code
  7646. #include <wolfssl/ssl.h>
  7647. int ret = 0;
  7648. WOLFSSL_CERT_MANAGER* cm;
  7649. ...
  7650. ret = wolfSSL_CertManagerLoadCA(cm, “path/to/cert-file.pem”, 0);
  7651. if (ret != SSL_SUCCESS) {
  7652. // error loading CA certs into cert manager
  7653. }
  7654. \endcode
  7655. \sa wolfSSL_CertManagerVerify
  7656. */
  7657. int wolfSSL_CertManagerLoadCA(WOLFSSL_CERT_MANAGER* cm, const char* f,
  7658. const char* d);
  7659. /*!
  7660. \ingroup CertManager
  7661. \brief Loads the CA Buffer by calling wolfSSL_CTX_load_verify_buffer and
  7662. returning that result using a temporary cm so as not to lose the information
  7663. in the cm passed into the function.
  7664. \return SSL_FATAL_ERROR is returned if the WOLFSSL_CERT_MANAGER struct is
  7665. NULL or if wolfSSL_CTX_new() returns NULL.
  7666. \return SSL_SUCCESS is returned for a successful execution.
  7667. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7668. wolfSSL_CertManagerNew().
  7669. \param in buffer for cert information.
  7670. \param sz length of the buffer.
  7671. \param format certificate format, either PEM or DER.
  7672. _Example_
  7673. \code
  7674. WOLFSSL_CERT_MANAGER* cm = (WOLFSSL_CERT_MANAGER*)vp;
  7675. const unsigned char* in;
  7676. long sz;
  7677. int format;
  7678. if(wolfSSL_CertManagerLoadCABuffer(vp, sz, format) != SSL_SUCCESS){
  7679. Error returned. Failure case code block.
  7680. }
  7681. \endcode
  7682. \sa wolfSSL_CTX_load_verify_buffer
  7683. \sa ProcessChainBuffer
  7684. \sa ProcessBuffer
  7685. \sa cm_pick_method
  7686. */
  7687. int wolfSSL_CertManagerLoadCABuffer(WOLFSSL_CERT_MANAGER* cm,
  7688. const unsigned char* in, long sz, int format);
  7689. /*!
  7690. \ingroup CertManager
  7691. \brief This function unloads the CA signer list.
  7692. \return SSL_SUCCESS returned on successful execution of the function.
  7693. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7694. \return BAD_MUTEX_E returned if there was a mutex error.
  7695. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure,
  7696. created using wolfSSL_CertManagerNew().
  7697. _Example_
  7698. \code
  7699. #include <wolfssl/ssl.h>
  7700. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7701. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CTX_GetCertManager(ctx);
  7702. ...
  7703. if(wolfSSL_CertManagerUnloadCAs(cm) != SSL_SUCCESS){
  7704. Failure case.
  7705. }
  7706. \endcode
  7707. \sa UnlockMutex
  7708. */
  7709. int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm);
  7710. /*!
  7711. \ingroup CertManager
  7712. \brief This function unloads intermediate certificates add to the CA
  7713. signer list.
  7714. \return SSL_SUCCESS returned on successful execution of the function.
  7715. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7716. \return BAD_MUTEX_E returned if there was a mutex error.
  7717. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure,
  7718. created using wolfSSL_CertManagerNew().
  7719. _Example_
  7720. \code
  7721. #include <wolfssl/ssl.h>
  7722. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7723. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CTX_GetCertManager(ctx);
  7724. ...
  7725. if(wolfSSL_CertManagerUnloadIntermediateCerts(cm) != SSL_SUCCESS){
  7726. Failure case.
  7727. }
  7728. \endcode
  7729. \sa UnlockMutex
  7730. */
  7731. int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm);
  7732. /*!
  7733. \ingroup CertManager
  7734. \brief The function will free the Trusted Peer linked list and unlocks
  7735. the trusted peer list.
  7736. \return SSL_SUCCESS if the function completed normally.
  7737. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7738. \return BAD_MUTEX_E mutex error if tpLock, a member of the
  7739. WOLFSSL_CERT_MANAGER struct, is 0 (nill).
  7740. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7741. wolfSSL_CertManagerNew().
  7742. _Example_
  7743. \code
  7744. #include <wolfssl/ssl.h>
  7745. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7746. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7747. ...
  7748. if(wolfSSL_CertManagerUnload_trust_peers(cm) != SSL_SUCCESS){
  7749. The function did not execute successfully.
  7750. }
  7751. \endcode
  7752. \sa UnLockMutex
  7753. */
  7754. int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm);
  7755. /*!
  7756. \ingroup CertManager
  7757. \brief Specifies the certificate to verify with the Certificate Manager
  7758. context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7759. \return SSL_SUCCESS If successful.
  7760. \return ASN_SIG_CONFIRM_E will be returned if the signature could not be
  7761. verified.
  7762. \return ASN_SIG_OID_E will be returned if the signature type is not
  7763. supported.
  7764. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7765. has been revoked.
  7766. \return CRL_MISSING is an error that is returned if a current issuer CRL is
  7767. not available.
  7768. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  7769. before date.
  7770. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  7771. after date.
  7772. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7773. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  7774. read, or is corrupted.
  7775. \return MEMORY_E will be returned if an out of memory condition occurs.
  7776. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7777. \return BAD_FUNC_ARG is the error that will be returned if a pointer is
  7778. not provided.
  7779. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7780. wolfSSL_CertManagerNew().
  7781. \param fname pointer to the name of the file containing the certificates
  7782. to verify.
  7783. \param format format of the certificate to verify - either
  7784. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7785. _Example_
  7786. \code
  7787. int ret = 0;
  7788. WOLFSSL_CERT_MANAGER* cm;
  7789. ...
  7790. ret = wolfSSL_CertManagerVerify(cm, “path/to/cert-file.pem”,
  7791. SSL_FILETYPE_PEM);
  7792. if (ret != SSL_SUCCESS) {
  7793. error verifying certificate
  7794. }
  7795. \endcode
  7796. \sa wolfSSL_CertManagerLoadCA
  7797. \sa wolfSSL_CertManagerVerifyBuffer
  7798. */
  7799. int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER* cm, const char* f,
  7800. int format);
  7801. /*!
  7802. \ingroup CertManager
  7803. \brief Specifies the certificate buffer to verify with the Certificate
  7804. Manager context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7805. \return SSL_SUCCESS If successful.
  7806. \return ASN_SIG_CONFIRM_E will be returned if the signature could not
  7807. be verified.
  7808. \return ASN_SIG_OID_E will be returned if the signature type is not
  7809. supported.
  7810. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7811. has been revoked.
  7812. \return CRL_MISSING is an error that is returned if a current issuer CRL
  7813. is not available.
  7814. \return ASN_BEFORE_DATE_E will be returned if the current date is before
  7815. the before date.
  7816. \return ASN_AFTER_DATE_E will be returned if the current date is after
  7817. the after date.
  7818. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7819. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  7820. be read, or is corrupted.
  7821. \return MEMORY_E will be returned if an out of memory condition occurs.
  7822. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7823. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7824. is not provided.
  7825. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7826. wolfSSL_CertManagerNew().
  7827. \param buff buffer containing the certificates to verify.
  7828. \param sz size of the buffer, buf.
  7829. \param format format of the certificate to verify, located in buf - either
  7830. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7831. _Example_
  7832. \code
  7833. #include <wolfssl/ssl.h>
  7834. int ret = 0;
  7835. int sz = 0;
  7836. WOLFSSL_CERT_MANAGER* cm;
  7837. byte certBuff[...];
  7838. ...
  7839. ret = wolfSSL_CertManagerVerifyBuffer(cm, certBuff, sz, SSL_FILETYPE_PEM);
  7840. if (ret != SSL_SUCCESS) {
  7841. error verifying certificate
  7842. }
  7843. \endcode
  7844. \sa wolfSSL_CertManagerLoadCA
  7845. \sa wolfSSL_CertManagerVerify
  7846. */
  7847. int wolfSSL_CertManagerVerifyBuffer(WOLFSSL_CERT_MANAGER* cm,
  7848. const unsigned char* buff, long sz, int format);
  7849. /*!
  7850. \ingroup CertManager
  7851. \brief The function sets the verifyCallback function in the Certificate
  7852. Manager. If present, it will be called for each cert loaded. If there is
  7853. a verification error, the verify callback can be used to over-ride the
  7854. error.
  7855. \return none No return.
  7856. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7857. wolfSSL_CertManagerNew().
  7858. \param vc a VerifyCallback function pointer to the callback routine
  7859. _Example_
  7860. \code
  7861. #include <wolfssl/ssl.h>
  7862. int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store)
  7863. { // do custom verification of certificate }
  7864. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7865. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7866. ...
  7867. wolfSSL_CertManagerSetVerify(cm, myVerify);
  7868. \endcode
  7869. \sa wolfSSL_CertManagerVerify
  7870. */
  7871. void wolfSSL_CertManagerSetVerify(WOLFSSL_CERT_MANAGER* cm,
  7872. VerifyCallback vc);
  7873. /*!
  7874. \brief Check CRL if the option is enabled and compares the cert to the
  7875. CRL list.
  7876. \return SSL_SUCCESS returns if the function returned as expected. If
  7877. the crlEnabled member of the WOLFSSL_CERT_MANAGER struct is turned on.
  7878. \return MEMORY_E returns if the allocated memory failed.
  7879. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7880. \param cm a pointer to a WOLFSSL_CERT_MANAGER struct.
  7881. \param der pointer to a DER formatted certificate.
  7882. \param sz size of the certificate.
  7883. _Example_
  7884. \code
  7885. WOLFSSL_CERT_MANAGER* cm;
  7886. byte* der;
  7887. int sz; // size of der
  7888. ...
  7889. if(wolfSSL_CertManagerCheckCRL(cm, der, sz) != SSL_SUCCESS){
  7890. // Error returned. Deal with failure case.
  7891. }
  7892. \endcode
  7893. \sa CheckCertCRL
  7894. \sa ParseCertRelative
  7895. \sa wolfSSL_CertManagerSetCRL_CB
  7896. \sa InitDecodedCert
  7897. */
  7898. int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
  7899. unsigned char* der, int sz);
  7900. /*!
  7901. \ingroup CertManager
  7902. \brief Turns on Certificate Revocation List checking when verifying
  7903. certificates with the Certificate Manager. By default, CRL checking
  7904. is off. options include WOLFSSL_CRL_CHECKALL which performs CRL
  7905. checking on each certificate in the chain versus the Leaf certificate
  7906. only which is the default.
  7907. \return SSL_SUCCESS If successful the call will return.
  7908. \return NOT_COMPILED_IN will be returned if wolfSSL was not built with
  7909. CRL enabled.
  7910. \return MEMORY_E will be returned if an out of memory condition occurs.
  7911. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7912. is not provided.
  7913. \return SSL_FAILURE will be returned if the CRL context cannot be
  7914. initialized properly.
  7915. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7916. wolfSSL_CertManagerNew().
  7917. \param options options to use when enabling the Certification Manager, cm.
  7918. _Example_
  7919. \code
  7920. #include <wolfssl/ssl.h>
  7921. int ret = 0;
  7922. WOLFSSL_CERT_MANAGER* cm;
  7923. ...
  7924. ret = wolfSSL_CertManagerEnableCRL(cm, 0);
  7925. if (ret != SSL_SUCCESS) {
  7926. error enabling cert manager
  7927. }
  7928. ...
  7929. \endcode
  7930. \sa wolfSSL_CertManagerDisableCRL
  7931. */
  7932. int wolfSSL_CertManagerEnableCRL(WOLFSSL_CERT_MANAGER* cm,
  7933. int options);
  7934. /*!
  7935. \ingroup CertManager
  7936. \brief Turns off Certificate Revocation List checking when verifying
  7937. certificates with the Certificate Manager. By default, CRL checking is
  7938. off. You can use this function to temporarily or permanently disable CRL
  7939. checking with this Certificate Manager context that previously had CRL
  7940. checking enabled.
  7941. \return SSL_SUCCESS If successful the call will return.
  7942. \return BAD_FUNC_ARG is the error that will be returned if a function
  7943. pointer is not provided.
  7944. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7945. wolfSSL_CertManagerNew().
  7946. _Example_
  7947. \code
  7948. #include <wolfssl/ssl.h>
  7949. int ret = 0;
  7950. WOLFSSL_CERT_MANAGER* cm;
  7951. ...
  7952. ret = wolfSSL_CertManagerDisableCRL(cm);
  7953. if (ret != SSL_SUCCESS) {
  7954. error disabling cert manager
  7955. }
  7956. ...
  7957. \endcode
  7958. \sa wolfSSL_CertManagerEnableCRL
  7959. */
  7960. int wolfSSL_CertManagerDisableCRL(WOLFSSL_CERT_MANAGER*);
  7961. /*!
  7962. \ingroup CertManager
  7963. \brief Error checks and passes through to LoadCRL() in order to load the
  7964. cert into the CRL for revocation checking. An updated CRL can be loaded by
  7965. first calling wolfSSL_CertManagerFreeCRL, then loading the new CRL.
  7966. \return SSL_SUCCESS if there is no error in wolfSSL_CertManagerLoadCRL and
  7967. if LoadCRL returns successfully.
  7968. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER struct is NULL.
  7969. \return SSL_FATAL_ERROR if wolfSSL_CertManagerEnableCRL returns anything
  7970. other than SSL_SUCCESS.
  7971. \return BAD_PATH_ERROR if the path is NULL.
  7972. \return MEMORY_E if LoadCRL fails to allocate heap memory.
  7973. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7974. wolfSSL_CertManagerNew().
  7975. \param path a constant char pointer holding the CRL path.
  7976. \param type type of certificate to be loaded.
  7977. \param monitor requests monitoring in LoadCRL().
  7978. _Example_
  7979. \code
  7980. #include <wolfssl/ssl.h>
  7981. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type,
  7982. int monitor);
  7983. wolfSSL_CertManagerLoadCRL(SSL_CM(ssl), path, type, monitor);
  7984. \endcode
  7985. \sa wolfSSL_CertManagerEnableCRL
  7986. \sa wolfSSL_LoadCRL
  7987. \sa wolfSSL_CertManagerFreeCRL
  7988. */
  7989. int wolfSSL_CertManagerLoadCRL(WOLFSSL_CERT_MANAGER* cm,
  7990. const char* path, int type, int monitor);
  7991. /*!
  7992. \ingroup CertManager
  7993. \brief The function loads the CRL file by calling BufferLoadCRL.
  7994. \return SSL_SUCCESS returned if the function completed without errors.
  7995. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7996. \return SSL_FATAL_ERROR returned if there is an error associated
  7997. with the WOLFSSL_CERT_MANAGER.
  7998. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  7999. \param buff a constant byte type and is the buffer.
  8000. \param sz a long int representing the size of the buffer.
  8001. \param type a long integer that holds the certificate type.
  8002. _Example_
  8003. \code
  8004. #include <wolfssl/ssl.h>
  8005. WOLFSSL_CERT_MANAGER* cm;
  8006. const unsigned char* buff;
  8007. long sz; size of buffer
  8008. int type; cert type
  8009. ...
  8010. int ret = wolfSSL_CertManagerLoadCRLBuffer(cm, buff, sz, type);
  8011. if(ret == SSL_SUCCESS){
  8012. return ret;
  8013. } else {
  8014. Failure case.
  8015. }
  8016. \endcode
  8017. \sa BufferLoadCRL
  8018. \sa wolfSSL_CertManagerEnableCRL
  8019. */
  8020. int wolfSSL_CertManagerLoadCRLBuffer(WOLFSSL_CERT_MANAGER* cm,
  8021. const unsigned char* buff, long sz,
  8022. int type);
  8023. /*!
  8024. \ingroup CertManager
  8025. \brief This function sets the CRL Certificate Manager callback. If
  8026. HAVE_CRL is defined and a matching CRL record is not found then the
  8027. cbMissingCRL is called (set via wolfSSL_CertManagerSetCRL_Cb). This
  8028. allows you to externally retrieve the CRL and load it.
  8029. \return SSL_SUCCESS returned upon successful execution of the function and
  8030. subroutines.
  8031. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  8032. \param cm the WOLFSSL_CERT_MANAGER structure holding the information for
  8033. the certificate.
  8034. \param cb a function pointer to (*CbMissingCRL) that is set to the
  8035. cbMissingCRL member of the WOLFSSL_CERT_MANAGER.
  8036. _Example_
  8037. \code
  8038. #include <wolfssl/ssl.h>
  8039. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  8040. WOLFSSL* ssl = wolfSSL_new(ctx);
  8041. void cb(const char* url){
  8042. Function body.
  8043. }
  8044. CbMissingCRL cb = CbMissingCRL;
  8045. if(ctx){
  8046. return wolfSSL_CertManagerSetCRL_Cb(SSL_CM(ssl), cb);
  8047. }
  8048. \endcode
  8049. \sa CbMissingCRL
  8050. \sa wolfSSL_SetCRL_Cb
  8051. */
  8052. int wolfSSL_CertManagerSetCRL_Cb(WOLFSSL_CERT_MANAGER* cm,
  8053. CbMissingCRL cb);
  8054. /*!
  8055. \ingroup CertManager
  8056. \brief This function sets the CRL Update callback. If
  8057. HAVE_CRL and HAVE_CRL_UPDATE_CB is defined , and an entry with the same
  8058. issuer and a lower CRL number exists when a CRL is added, then the
  8059. CbUpdateCRL is called with the details of the existing entry and the
  8060. new one replacing it.
  8061. \return SSL_SUCCESS returned upon successful execution of the function and
  8062. subroutines.
  8063. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  8064. \param cm the WOLFSSL_CERT_MANAGER structure holding the information for
  8065. the certificate.
  8066. \param cb a function pointer to (*CbUpdateCRL) that is set to the
  8067. cbUpdateCRL member of the WOLFSSL_CERT_MANAGER.
  8068. Signature requirement:
  8069. void (*CbUpdateCRL)(CrlInfo *old, CrlInfo *new);
  8070. _Example_
  8071. \code
  8072. #include <wolfssl/ssl.h>
  8073. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  8074. WOLFSSL* ssl = wolfSSL_new(ctx);
  8075. void cb(CrlInfo *old, CrlInfo *new){
  8076. Function body.
  8077. }
  8078. CbUpdateCRL cb = CbUpdateCRL;
  8079. if(ctx){
  8080. return wolfSSL_CertManagerSetCRLUpdate_Cb(SSL_CM(ssl), cb);
  8081. }
  8082. \endcode
  8083. \sa CbUpdateCRL
  8084. */
  8085. int wolfSSL_CertManagerSetCRLUpdate_Cb(WOLFSSL_CERT_MANAGER* cm,
  8086. CbUpdateCRL cb);
  8087. /*!
  8088. \ingroup CertManager
  8089. \brief This function yields a structure with parsed CRL information from
  8090. an encoded CRL buffer.
  8091. \return SSL_SUCCESS returned upon successful execution of the function and
  8092. subroutines.
  8093. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  8094. \param cm the WOLFSSL_CERT_MANAGER structure..
  8095. \param info pointer to caller managed CrlInfo structure that will receive
  8096. the CRL information.
  8097. \param buff input buffer containing encoded CRL.
  8098. \param sz the length in bytes of the input CRL data in buff.
  8099. \param type WOLFSSL_FILETYPE_PEM or WOLFSSL_FILETYPE_DER
  8100. _Example_
  8101. \code
  8102. #include <wolfssl/ssl.h>
  8103. CrlInfo info;
  8104. WOLFSSL_CERT_MANAGER* cm = NULL;
  8105. cm = wolfSSL_CertManagerNew();
  8106. // Read crl data from file into buffer
  8107. wolfSSL_CertManagerGetCRLInfo(cm, &info, crlData, crlDataLen,
  8108. WOLFSSL_FILETYPE_PEM);
  8109. \endcode
  8110. \sa CbUpdateCRL
  8111. \sa wolfSSL_SetCRL_Cb
  8112. */
  8113. int wolfSSL_CertManagerGetCRLInfo(WOLFSSL_CERT_MANAGER* cm, CrlInfo* info,
  8114. const byte* buff, long sz, int type)
  8115. /*!
  8116. \ingroup CertManager
  8117. \brief This function frees the CRL stored in the Cert Manager. An
  8118. application can update the CRL by calling wolfSSL_CertManagerFreeCRL
  8119. and then loading the new CRL.
  8120. \return SSL_SUCCESS returned upon successful execution of the function and
  8121. subroutines.
  8122. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  8123. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  8124. wolfSSL_CertManagerNew().
  8125. _Example_
  8126. \code
  8127. #include <wolfssl/ssl.h>
  8128. const char* crl1 = "./certs/crl/crl.pem";
  8129. WOLFSSL_CERT_MANAGER* cm = NULL;
  8130. cm = wolfSSL_CertManagerNew();
  8131. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0);
  8132. wolfSSL_CertManagerFreeCRL(cm);
  8133. \endcode
  8134. \sa wolfSSL_CertManagerLoadCRL
  8135. */
  8136. int wolfSSL_CertManagerFreeCRL(WOLFSSL_CERT_MANAGER* cm);
  8137. /*!
  8138. \ingroup CertManager
  8139. \brief The function enables the WOLFSSL_CERT_MANAGER’s member, ocspEnabled
  8140. to signify that the OCSP check option is enabled.
  8141. \return SSL_SUCCESS returned on successful execution of the function. The
  8142. ocspEnabled member of the WOLFSSL_CERT_MANAGER is enabled.
  8143. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  8144. NULL or if an argument value that is not allowed is passed to a subroutine.
  8145. \return MEMORY_E returned if there is an error allocating memory within
  8146. this function or a subroutine.
  8147. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  8148. wolfSSL_CertManagerNew().
  8149. \param der a byte pointer to the certificate.
  8150. \param sz an int type representing the size of the DER cert.
  8151. _Example_
  8152. \code
  8153. #import <wolfssl/ssl.h>
  8154. WOLFSSL* ssl = wolfSSL_new(ctx);
  8155. byte* der;
  8156. int sz; size of der
  8157. ...
  8158. if(wolfSSL_CertManagerCheckOCSP(cm, der, sz) != SSL_SUCCESS){
  8159. Failure case.
  8160. }
  8161. \endcode
  8162. \sa ParseCertRelative
  8163. \sa CheckCertOCSP
  8164. */
  8165. int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
  8166. unsigned char* der, int sz);
  8167. /*!
  8168. \ingroup CertManager
  8169. \brief Turns on OCSP if it’s turned off and if compiled with the
  8170. set option available.
  8171. \return SSL_SUCCESS returned if the function call is successful.
  8172. \return BAD_FUNC_ARG if cm struct is NULL.
  8173. \return MEMORY_E if WOLFSSL_OCSP struct value is NULL.
  8174. \return SSL_FAILURE initialization of WOLFSSL_OCSP struct fails
  8175. to initialize.
  8176. \return NOT_COMPILED_IN build not compiled with correct feature enabled.
  8177. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  8178. wolfSSL_CertManagerNew().
  8179. \param options used to set values in WOLFSSL_CERT_MANAGER struct.
  8180. _Example_
  8181. \code
  8182. #include <wolfssl/ssl.h>
  8183. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  8184. WOLFSSL* ssl = wolfSSL_new(ctx);
  8185. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  8186. int options;
  8187. if(wolfSSL_CertManagerEnableOCSP(SSL_CM(ssl), options) != SSL_SUCCESS){
  8188. Failure case.
  8189. }
  8190. \endcode
  8191. \sa wolfSSL_CertManagerNew
  8192. */
  8193. int wolfSSL_CertManagerEnableOCSP(WOLFSSL_CERT_MANAGER* cm,
  8194. int options);
  8195. /*!
  8196. \ingroup CertManager
  8197. \brief Disables OCSP certificate revocation.
  8198. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled the
  8199. crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8200. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  8201. \param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8202. _Example_
  8203. \code
  8204. #include <wolfssl/ssl.h>
  8205. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(method);
  8206. WOLFSSL* ssl = wolfSSL_new(ctx);
  8207. ...
  8208. if(wolfSSL_CertManagerDisableOCSP(ssl) != SSL_SUCCESS){
  8209. Fail case.
  8210. }
  8211. \endcode
  8212. \sa wolfSSL_DisableCRL
  8213. */
  8214. int wolfSSL_CertManagerDisableOCSP(WOLFSSL_CERT_MANAGER*);
  8215. /*!
  8216. \ingroup CertManager
  8217. \brief The function copies the url to the ocspOverrideURL member of the
  8218. WOLFSSL_CERT_MANAGER structure.
  8219. \return SSL_SUCCESS the function was able to execute as expected.
  8220. \return BAD_FUNC_ARG the WOLFSSL_CERT_MANAGER struct is NULL.
  8221. \return MEMEORY_E Memory was not able to be allocated for the
  8222. ocspOverrideURL member of the certificate manager.
  8223. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8224. _Example_
  8225. \code
  8226. #include <wolfssl/ssl.h>
  8227. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  8228. const char* url;
  8229. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url)
  8230. if(wolfSSL_CertManagerSetOCSPOverrideURL(SSL_CM(ssl), url) != SSL_SUCCESS){
  8231. Failure case.
  8232. }
  8233. \endcode
  8234. \sa ocspOverrideURL
  8235. \sa wolfSSL_SetOCSP_OverrideURL
  8236. */
  8237. int wolfSSL_CertManagerSetOCSPOverrideURL(WOLFSSL_CERT_MANAGER* cm,
  8238. const char* url);
  8239. /*!
  8240. \ingroup CertManager
  8241. \brief The function sets the OCSP callback in the WOLFSSL_CERT_MANAGER.
  8242. \return SSL_SUCCESS returned on successful execution. The arguments are
  8243. saved in the WOLFSSL_CERT_MANAGER structure.
  8244. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  8245. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  8246. \param ioCb a function pointer of type CbOCSPIO.
  8247. \param respFreeCb - a function pointer of type CbOCSPRespFree.
  8248. \param ioCbCtx - a void pointer variable to the I/O callback user
  8249. registered context.
  8250. _Example_
  8251. \code
  8252. #include <wolfssl/ssl.h>
  8253. wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb,
  8254. CbOCSPRespFree respFreeCb, void* ioCbCtx){
  8255. return wolfSSL_CertManagerSetOCSP_Cb(SSL_CM(ssl), ioCb, respFreeCb, ioCbCtx);
  8256. \endcode
  8257. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  8258. \sa wolfSSL_CertManagerCheckOCSP
  8259. \sa wolfSSL_CertManagerEnableOCSPStapling
  8260. \sa wolfSSL_EnableOCSP
  8261. \sa wolfSSL_DisableOCSP
  8262. \sa wolfSSL_SetOCSP_Cb
  8263. */
  8264. int wolfSSL_CertManagerSetOCSP_Cb(WOLFSSL_CERT_MANAGER* cm,
  8265. CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8266. void* ioCbCtx);
  8267. /*!
  8268. \ingroup CertManager
  8269. \brief This function turns on OCSP stapling if it is not turned on as well
  8270. as set the options.
  8271. \return SSL_SUCCESS returned if there were no errors and the function
  8272. executed successfully.
  8273. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  8274. NULL or otherwise if there was a unpermitted argument value passed to
  8275. a subroutine.
  8276. \return MEMORY_E returned if there was an issue allocating memory.
  8277. \return SSL_FAILURE returned if the initialization of the OCSP
  8278. structure failed.
  8279. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  8280. HAVE_CERTIFICATE_STATUS_REQUEST option.
  8281. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, a member of the
  8282. WOLFSSL_CTX structure.
  8283. _Example_
  8284. \code
  8285. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX* ctx){
  8286. return wolfSSL_CertManagerEnableOCSPStapling(ctx->cm);
  8287. \endcode
  8288. \sa wolfSSL_CTX_EnableOCSPStapling
  8289. */
  8290. int wolfSSL_CertManagerEnableOCSPStapling(
  8291. WOLFSSL_CERT_MANAGER* cm);
  8292. /*!
  8293. \brief Enables CRL certificate revocation.
  8294. \return SSL_SUCCESS the function and subroutines returned with no errors.
  8295. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  8296. \return MEMORY_E returned if the allocation of memory failed.
  8297. \return SSL_FAILURE returned if the InitCRL function does not return
  8298. successfully.
  8299. \return NOT_COMPILED_IN HAVE_CRL was not enabled during the compiling.
  8300. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8301. \param options an integer that is used to determine the setting of
  8302. crlCheckAll member of the WOLFSSL_CERT_MANAGER structure.
  8303. _Example_
  8304. \code
  8305. WOLFSSL* ssl = wolfSSL_new(ctx);
  8306. if (wolfSSL_EnableCRL(ssl, WOLFSSL_CRL_CHECKALL) != SSL_SUCCESS){
  8307. // Failure case. SSL_SUCCESS was not returned by this function or
  8308. a subroutine
  8309. }
  8310. \endcode
  8311. \sa wolfSSL_CertManagerEnableCRL
  8312. \sa InitCRL
  8313. */
  8314. int wolfSSL_EnableCRL(WOLFSSL* ssl, int options);
  8315. /*!
  8316. \brief Disables CRL certificate revocation.
  8317. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled
  8318. the crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8319. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  8320. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8321. _Example_
  8322. \code
  8323. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8324. WOLFSSL* ssl = wolfSSL_new(ctx);
  8325. ...
  8326. if(wolfSSL_DisableCRL(ssl) != SSL_SUCCESS){
  8327. // Failure case
  8328. }
  8329. \endcode
  8330. \sa wolfSSL_CertManagerDisableCRL
  8331. \sa wolfSSL_CertManagerDisableOCSP
  8332. */
  8333. int wolfSSL_DisableCRL(WOLFSSL* ssl);
  8334. /*!
  8335. \brief A wrapper function that ends up calling LoadCRL to load the
  8336. certificate for revocation checking.
  8337. \return WOLFSSL_SUCCESS returned if the function and all of the
  8338. subroutines executed without error.
  8339. \return SSL_FATAL_ERROR returned if one of the subroutines does not
  8340. return successfully.
  8341. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER or the WOLFSSL
  8342. structure are NULL.
  8343. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8344. \param path a constant character pointer that holds the path to the
  8345. crl file.
  8346. \param type an integer representing the type of certificate.
  8347. \param monitor an integer variable used to verify the monitor path if
  8348. requested.
  8349. _Example_
  8350. \code
  8351. WOLFSSL* ssl = wolfSSL_new(ctx);
  8352. const char* crlPemDir;
  8353. if(wolfSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, 0) != SSL_SUCCESS){
  8354. // Failure case. Did not return SSL_SUCCESS.
  8355. }
  8356. \endcode
  8357. \sa wolfSSL_CertManagerLoadCRL
  8358. \sa wolfSSL_CertManagerEnableCRL
  8359. \sa LoadCRL
  8360. */
  8361. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type, int monitor);
  8362. /*!
  8363. \brief Sets the CRL callback in the WOLFSSL_CERT_MANAGER structure.
  8364. \return SSL_SUCCESS returned if the function or subroutine executes
  8365. without error. The cbMissingCRL member of the WOLFSSL_CERT_MANAGER is set.
  8366. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  8367. structure is NULL.
  8368. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8369. \param cb a function pointer to CbMissingCRL.
  8370. _Example_
  8371. \code
  8372. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8373. WOLFSSL* ssl = wolfSSL_new(ctx);
  8374. void cb(const char* url) // required signature
  8375. {
  8376. // Function body
  8377. }
  8378. int crlCb = wolfSSL_SetCRL_Cb(ssl, cb);
  8379. if(crlCb != SSL_SUCCESS){
  8380. // The callback was not set properly
  8381. }
  8382. \endcode
  8383. \sa CbMissingCRL
  8384. \sa wolfSSL_CertManagerSetCRL_Cb
  8385. */
  8386. int wolfSSL_SetCRL_Cb(WOLFSSL* ssl, CbMissingCRL cb);
  8387. /*!
  8388. \brief This function enables OCSP certificate verification. The value of
  8389. options if formed by or’ing one or more of the following options:
  8390. WOLFSSL_OCSP_URL_OVERRIDE - use the override URL instead of the URL in
  8391. certificates. The override URL is specified using the
  8392. wolfSSL_CTX_SetOCSP_OverrideURL() function.
  8393. WOLFSSL_OCSP_CHECKALL - Set all OCSP checks on
  8394. WOLFSSL_OCSP_NO_NONCE - Set nonce option for creating OCSP requests
  8395. \return SSL_SUCCESS returned if the function and subroutines executes
  8396. without errors.
  8397. \return BAD_FUNC_ARG returned if an argument in this function or any
  8398. subroutine receives an invalid argument value.
  8399. \return MEMORY_E returned if there was an error allocating memory for
  8400. a structure or other variable.
  8401. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with the
  8402. HAVE_OCSP option.
  8403. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8404. \param options an integer type passed to wolfSSL_CertMangerENableOCSP()
  8405. used for settings check.
  8406. _Example_
  8407. \code
  8408. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8409. WOLFSSL* ssl = wolfSSL_new(ctx);
  8410. int options; // initialize to option constant
  8411. int ret = wolfSSL_EnableOCSP(ssl, options);
  8412. if(ret != SSL_SUCCESS){
  8413. // OCSP is not enabled
  8414. }
  8415. \endcode
  8416. \sa wolfSSL_CertManagerEnableOCSP
  8417. */
  8418. int wolfSSL_EnableOCSP(WOLFSSL* ssl, int options);
  8419. /*!
  8420. \brief Disables the OCSP certificate revocation option.
  8421. \return SSL_SUCCESS returned if the function and its subroutine return with
  8422. no errors. The ocspEnabled member of the WOLFSSL_CERT_MANAGER structure was
  8423. successfully set.
  8424. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  8425. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8426. _Example_
  8427. \code
  8428. WOLFSSL* ssl = wolfSSL_new(ctx);
  8429. if(wolfSSL_DisableOCSP(ssl) != SSL_SUCCESS){
  8430. // Returned with an error. Failure case in this block.
  8431. }
  8432. \endcode
  8433. \sa wolfSSL_CertManagerDisableOCSP
  8434. */
  8435. int wolfSSL_DisableOCSP(WOLFSSL*);
  8436. /*!
  8437. \brief This function sets the ocspOverrideURL member in the
  8438. WOLFSSL_CERT_MANAGER structure.
  8439. \return SSL_SUCCESS returned on successful execution of the function.
  8440. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if a
  8441. unpermitted argument was passed to a subroutine.
  8442. \return MEMORY_E returned if there was an error allocating memory in the
  8443. subroutine.
  8444. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8445. \param url a constant char pointer to the url that will be stored in the
  8446. ocspOverrideURL member of the WOLFSSL_CERT_MANAGER structure.
  8447. _Example_
  8448. \code
  8449. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8450. WOLFSSL* ssl = wolfSSL_new(ctx);
  8451. char url[URLSZ];
  8452. ...
  8453. if(wolfSSL_SetOCSP_OverrideURL(ssl, url)){
  8454. // The override url is set to the new value
  8455. }
  8456. \endcode
  8457. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  8458. */
  8459. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url);
  8460. /*!
  8461. \brief This function sets the OCSP callback in the
  8462. WOLFSSL_CERT_MANAGER structure.
  8463. \return SSL_SUCCESS returned if the function executes without error.
  8464. The ocspIOCb, ocspRespFreeCb, and ocspIOCtx members of the CM are set.
  8465. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  8466. structures are NULL.
  8467. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8468. \param ioCb a function pointer to type CbOCSPIO.
  8469. \param respFreeCb a function pointer to type CbOCSPRespFree which is the
  8470. call to free the response memory.
  8471. \param ioCbCtx a void pointer that will be held in the ocspIOCtx member
  8472. of the CM.
  8473. _Example_
  8474. \code
  8475. WOLFSSL* ssl = wolfSSL_new(ctx);
  8476. int OCSPIO_CB(void* , const char*, int , unsigned char* , int,
  8477. unsigned char**){ // must have this signature
  8478. // Function Body
  8479. }
  8480. void OCSPRespFree_CB(void* , unsigned char* ){ // must have this signature
  8481. // function body
  8482. }
  8483. void* ioCbCtx;
  8484. CbOCSPRespFree CB_OCSPRespFree;
  8485. if(wolfSSL_SetOCSP_Cb(ssl, OCSPIO_CB( pass args ), CB_OCSPRespFree,
  8486. ioCbCtx) != SSL_SUCCESS){
  8487. // Callback not set
  8488. }
  8489. \endcode
  8490. \sa wolfSSL_CertManagerSetOCSP_Cb
  8491. \sa CbOCSPIO
  8492. \sa CbOCSPRespFree
  8493. */
  8494. int wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8495. void* ioCbCtx);
  8496. /*!
  8497. \brief Enables CRL certificate verification through the CTX.
  8498. \return SSL_SUCCESS returned if this function and it’s subroutines
  8499. execute without errors.
  8500. \return BAD_FUNC_ARG returned if the CTX struct is NULL or there
  8501. was otherwise an invalid argument passed in a subroutine.
  8502. \return MEMORY_E returned if there was an error allocating
  8503. memory during execution of the function.
  8504. \return SSL_FAILURE returned if the crl member of the
  8505. WOLFSSL_CERT_MANAGER fails to initialize correctly.
  8506. \return NOT_COMPILED_IN wolfSSL was not compiled with the HAVE_CRL option.
  8507. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8508. _Example_
  8509. \code
  8510. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8511. WOLFSSL* ssl = wolfSSL_new(ctx);
  8512. ...
  8513. if(wolfSSL_CTX_EnableCRL(ssl->ctx, options) != SSL_SUCCESS){
  8514. // The function failed
  8515. }
  8516. \endcode
  8517. \sa wolfSSL_CertManagerEnableCRL
  8518. \sa InitCRL
  8519. \sa wolfSSL_CTX_DisableCRL
  8520. */
  8521. int wolfSSL_CTX_EnableCRL(WOLFSSL_CTX* ctx, int options);
  8522. /*!
  8523. \brief This function disables CRL verification in the CTX structure.
  8524. \return SSL_SUCCESS returned if the function executes without error.
  8525. The crlEnabled member of the WOLFSSL_CERT_MANAGER struct is set to 0.
  8526. \return BAD_FUNC_ARG returned if either the CTX struct or the CM
  8527. struct has a NULL value.
  8528. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8529. wolfSSL_CTX_new().
  8530. _Example_
  8531. \code
  8532. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8533. WOLFSSL* ssl = wolfSSL_new(ctx);
  8534. ...
  8535. if(wolfSSL_CTX_DisableCRL(ssl->ctx) != SSL_SUCCESS){
  8536. // Failure case.
  8537. }
  8538. \endcode
  8539. \sa wolfSSL_CertManagerDisableCRL
  8540. */
  8541. int wolfSSL_CTX_DisableCRL(WOLFSSL_CTX* ctx);
  8542. /*!
  8543. \brief This function loads CRL into the WOLFSSL_CTX structure through
  8544. wolfSSL_CertManagerLoadCRL().
  8545. \return SSL_SUCCESS - returned if the function and its subroutines
  8546. execute without error.
  8547. \return BAD_FUNC_ARG - returned if this function or any subroutines
  8548. are passed NULL structures.
  8549. \return BAD_PATH_ERROR - returned if the path variable opens as NULL.
  8550. \return MEMORY_E - returned if an allocation of memory failed.
  8551. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8552. wolfSSL_CTX_new().
  8553. \param path the path to the certificate.
  8554. \param type an integer variable holding the type of certificate.
  8555. \param monitor an integer variable used to determine if the monitor
  8556. path is requested.
  8557. _Example_
  8558. \code
  8559. WOLFSSL_CTX* ctx;
  8560. const char* path;
  8561. return wolfSSL_CTX_LoadCRL(ctx, path, SSL_FILETYPE_PEM, 0);
  8562. \endcode
  8563. \sa wolfSSL_CertManagerLoadCRL
  8564. \sa LoadCRL
  8565. */
  8566. int wolfSSL_CTX_LoadCRL(WOLFSSL_CTX* ctx, const char* path, int type, int monitor);
  8567. /*!
  8568. \brief This function will set the callback argument to the cbMissingCRL
  8569. member of the WOLFSSL_CERT_MANAGER structure by calling
  8570. wolfSSL_CertManagerSetCRL_Cb.
  8571. \return SSL_SUCCESS returned for a successful execution. The
  8572. WOLFSSL_CERT_MANAGER structure’s member cbMssingCRL was successfully
  8573. set to cb.
  8574. \return BAD_FUNC_ARG returned if WOLFSSL_CTX or WOLFSSL_CERT_MANAGER
  8575. are NULL.
  8576. \param ctx a pointer to a WOLFSSL_CTX structure, created with
  8577. wolfSSL_CTX_new().
  8578. \param cb a pointer to a callback function of type CbMissingCRL.
  8579. Signature requirement:
  8580. void (*CbMissingCRL)(const char* url);
  8581. _Example_
  8582. \code
  8583. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8584. void cb(const char* url) // Required signature
  8585. {
  8586. // Function body
  8587. }
  8588. if (wolfSSL_CTX_SetCRL_Cb(ctx, cb) != SSL_SUCCESS){
  8589. // Failure case, cb was not set correctly.
  8590. }
  8591. \endcode
  8592. \sa wolfSSL_CertManagerSetCRL_Cb
  8593. \sa CbMissingCRL
  8594. */
  8595. int wolfSSL_CTX_SetCRL_Cb(WOLFSSL_CTX* ctx, CbMissingCRL cb);
  8596. /*!
  8597. \brief This function sets options to configure behavior of OCSP
  8598. functionality in wolfSSL. The value of options if formed by or’ing
  8599. one or more of the following options:
  8600. WOLFSSL_OCSP_URL_OVERRIDE - use the override URL instead of the URL in
  8601. certificates. The override URL is specified using the
  8602. wolfSSL_CTX_SetOCSP_OverrideURL() function.
  8603. WOLFSSL_OCSP_CHECKALL - Set all OCSP checks on
  8604. WOLFSSL_OCSP_NO_NONCE - Set nonce option for creating OCSP requests
  8605. This function only sets the OCSP options when wolfSSL has been compiled with
  8606. OCSP support (--enable-ocsp, #define HAVE_OCSP).
  8607. \return SSL_SUCCESS is returned upon success.
  8608. \return SSL_FAILURE is returned upon failure.
  8609. \return NOT_COMPILED_IN is returned when this function has been called,
  8610. but OCSP support was not enabled when wolfSSL was compiled.
  8611. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  8612. \param options value used to set the OCSP options.
  8613. _Example_
  8614. \code
  8615. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8616. int options; // initialize to option constant
  8617. int ret = wolfSSL_CTX_EnableOCSP(ctx, options);
  8618. if(ret != SSL_SUCCESS){
  8619. // OCSP is not enabled
  8620. }
  8621. \endcode
  8622. \sa wolfSSL_CertManagerEnableOCSP
  8623. \sa wolfSSL_EnableOCSP
  8624. */
  8625. int wolfSSL_CTX_EnableOCSP(WOLFSSL_CTX* ctx, int options);
  8626. /*!
  8627. \brief This function disables OCSP certificate revocation checking by
  8628. affecting the ocspEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8629. \return SSL_SUCCESS returned if the function executes without error.
  8630. The ocspEnabled member of the CM has been disabled.
  8631. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  8632. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8633. wolfSSL_CTX_new().
  8634. _Example_
  8635. \code
  8636. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8637. WOLFSSL* ssl = wolfSSL_new(ctx);
  8638. ...
  8639. if(!wolfSSL_CTX_DisableOCSP(ssl->ctx)){
  8640. // OCSP is not disabled
  8641. }
  8642. \endcode
  8643. \sa wolfSSL_DisableOCSP
  8644. \sa wolfSSL_CertManagerDisableOCSP
  8645. */
  8646. int wolfSSL_CTX_DisableOCSP(WOLFSSL_CTX*);
  8647. /*!
  8648. \brief This function manually sets the URL for OCSP to use. By default,
  8649. OCSP will use the URL found in the individual certificate unless the
  8650. WOLFSSL_OCSP_URL_OVERRIDE option is set using the wolfSSL_CTX_EnableOCSP.
  8651. \return SSL_SUCCESS is returned upon success.
  8652. \return SSL_FAILURE is returned upon failure.
  8653. \return NOT_COMPILED_IN is returned when this function has been called,
  8654. but OCSP support was not enabled when wolfSSL was compiled.
  8655. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  8656. \param url pointer to the OCSP URL for wolfSSL to use.
  8657. _Example_
  8658. \code
  8659. WOLFSSL_CTX* ctx = 0;
  8660. ...
  8661. wolfSSL_CTX_OCSP_set_override_url(ctx, “custom-url-here”);
  8662. \endcode
  8663. \sa wolfSSL_CTX_OCSP_set_options
  8664. */
  8665. int wolfSSL_CTX_SetOCSP_OverrideURL(WOLFSSL_CTX* ctx, const char* url);
  8666. /*!
  8667. \brief Sets the callback for the OCSP in the WOLFSSL_CTX structure.
  8668. \return SSL_SUCCESS returned if the function executed successfully. The
  8669. ocspIOCb, ocspRespFreeCb, and ocspIOCtx members in the CM were
  8670. successfully set.
  8671. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX or
  8672. WOLFSSL_CERT_MANAGER structure is NULL.
  8673. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8674. \param ioCb a CbOCSPIO type that is a function pointer.
  8675. \param respFreeCb a CbOCSPRespFree type that is a function pointer.
  8676. \param ioCbCtx a void pointer that will be held in the WOLFSSL_CERT_MANAGER.
  8677. _Example_
  8678. \code
  8679. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8680. CbOCSPIO ocspIOCb;
  8681. CbOCSPRespFree ocspRespFreeCb;
  8682. void* ioCbCtx;
  8683. int isSetOCSP = wolfSSL_CTX_SetOCSP_Cb(ctx, ocspIOCb,
  8684. ocspRespFreeCb, ioCbCtx);
  8685. if(isSetOCSP != SSL_SUCCESS){
  8686. // The function did not return successfully.
  8687. }
  8688. \endcode
  8689. \sa wolfSSL_CertManagerSetOCSP_Cb
  8690. \sa CbOCSPIO
  8691. \sa CbOCSPRespFree
  8692. */
  8693. int wolfSSL_CTX_SetOCSP_Cb(WOLFSSL_CTX* ctx,
  8694. CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8695. void* ioCbCtx);
  8696. /*!
  8697. \brief This function enables OCSP stapling by calling
  8698. wolfSSL_CertManagerEnableOCSPStapling().
  8699. \return SSL_SUCCESS returned if there were no errors and the function
  8700. executed successfully.
  8701. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  8702. otherwise if there was a unpermitted argument value passed to a subroutine.
  8703. \return MEMORY_E returned if there was an issue allocating memory.
  8704. \return SSL_FAILURE returned if the initialization of the OCSP
  8705. structure failed.
  8706. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  8707. HAVE_CERTIFICATE_STATUS_REQUEST option.
  8708. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8709. wolfSSL_CTX_new().
  8710. _Example_
  8711. \code
  8712. WOLFSSL* ssl = WOLFSSL_new();
  8713. ssl->method.version; // set to desired protocol
  8714. ...
  8715. if(!wolfSSL_CTX_EnableOCSPStapling(ssl->ctx)){
  8716. // OCSP stapling is not enabled
  8717. }
  8718. \endcode
  8719. \sa wolfSSL_CertManagerEnableOCSPStapling
  8720. \sa InitOCSP
  8721. */
  8722. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX*);
  8723. /*!
  8724. \ingroup CertsKeys
  8725. \brief Normally, at the end of the SSL handshake, wolfSSL frees
  8726. temporary arrays. Calling this function before the handshake begins
  8727. will prevent wolfSSL from freeing temporary arrays. Temporary arrays
  8728. may be needed for things such as wolfSSL_get_keys() or PSK hints.
  8729. When the user is done with temporary arrays, either wolfSSL_FreeArrays()
  8730. may be called to free the resources immediately, or alternatively the
  8731. resources will be freed when the associated SSL object is freed.
  8732. \return none No return.
  8733. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8734. _Example_
  8735. \code
  8736. WOLFSSL* ssl;
  8737. ...
  8738. wolfSSL_KeepArrays(ssl);
  8739. \endcode
  8740. \sa wolfSSL_FreeArrays
  8741. */
  8742. void wolfSSL_KeepArrays(WOLFSSL*);
  8743. /*!
  8744. \ingroup CertsKeys
  8745. \brief Normally, at the end of the SSL handshake, wolfSSL frees temporary
  8746. arrays. If wolfSSL_KeepArrays() has been called before the handshake,
  8747. wolfSSL will not free temporary arrays. This function explicitly frees
  8748. temporary arrays and should be called when the user is done with temporary
  8749. arrays and does not want to wait for the SSL object to be freed to free
  8750. these resources.
  8751. \return none No return.
  8752. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8753. _Example_
  8754. \code
  8755. WOLFSSL* ssl;
  8756. ...
  8757. wolfSSL_FreeArrays(ssl);
  8758. \endcode
  8759. \sa wolfSSL_KeepArrays
  8760. */
  8761. void wolfSSL_FreeArrays(WOLFSSL*);
  8762. /*!
  8763. \brief This function enables the use of Server Name Indication in the SSL
  8764. object passed in the 'ssl' parameter. It means that the SNI extension will
  8765. be sent on ClientHello by wolfSSL client and wolfSSL server will respond
  8766. ClientHello + SNI with either ServerHello + blank SNI or alert fatal in
  8767. case of SNI mismatch.
  8768. \return WOLFSSL_SUCCESS upon success.
  8769. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8770. cases: ssl is NULL, data is NULL, type is a unknown value. (see below)
  8771. \return MEMORY_E is the error returned when there is not enough memory.
  8772. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8773. \param type indicates which type of server name is been passed in data.
  8774. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8775. \param data pointer to the server name data.
  8776. \param size size of the server name data.
  8777. _Example_
  8778. \code
  8779. int ret = 0;
  8780. WOLFSSL_CTX* ctx = 0;
  8781. WOLFSSL* ssl = 0;
  8782. ctx = wolfSSL_CTX_new(method);
  8783. if (ctx == NULL) {
  8784. // context creation failed
  8785. }
  8786. ssl = wolfSSL_new(ctx);
  8787. if (ssl == NULL) {
  8788. // ssl creation failed
  8789. }
  8790. ret = wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8791. strlen("www.yassl.com"));
  8792. if (ret != WOLFSSL_SUCCESS) {
  8793. // sni usage failed
  8794. }
  8795. \endcode
  8796. \sa wolfSSL_new
  8797. \sa wolfSSL_CTX_UseSNI
  8798. */
  8799. int wolfSSL_UseSNI(WOLFSSL* ssl, unsigned char type,
  8800. const void* data, unsigned short size);
  8801. /*!
  8802. \brief This function enables the use of Server Name Indication for SSL
  8803. objects created from the SSL context passed in the 'ctx' parameter. It
  8804. means that the SNI extension will be sent on ClientHello by wolfSSL
  8805. clients and wolfSSL servers will respond ClientHello + SNI with either
  8806. ServerHello + blank SNI or alert fatal in case of SNI mismatch.
  8807. \return WOLFSSL_SUCCESS upon success.
  8808. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8809. cases: ctx is NULL, data is NULL, type is a unknown value. (see below)
  8810. \return MEMORY_E is the error returned when there is not enough memory.
  8811. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8812. \param type indicates which type of server name is been passed in data.
  8813. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8814. \param data pointer to the server name data.
  8815. \param size size of the server name data.
  8816. _Example_
  8817. \code
  8818. int ret = 0;
  8819. WOLFSSL_CTX* ctx = 0;
  8820. ctx = wolfSSL_CTX_new(method);
  8821. if (ctx == NULL) {
  8822. // context creation failed
  8823. }
  8824. ret = wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8825. strlen("www.yassl.com"));
  8826. if (ret != WOLFSSL_SUCCESS) {
  8827. // sni usage failed
  8828. }
  8829. \endcode
  8830. \sa wolfSSL_CTX_new
  8831. \sa wolfSSL_UseSNI
  8832. */
  8833. int wolfSSL_CTX_UseSNI(WOLFSSL_CTX* ctx, unsigned char type,
  8834. const void* data, unsigned short size);
  8835. /*!
  8836. \brief This function is called on the server side to configure the
  8837. behavior of the SSL session using Server Name Indication in the SSL
  8838. object passed in the 'ssl' parameter. The options are explained below.
  8839. \return none No returns.
  8840. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8841. \param type indicates which type of server name is been passed in data.
  8842. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8843. \param options a bitwise semaphore with the chosen options. The available
  8844. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8845. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort the
  8846. handshake by sending a fatal-level unrecognized_name(112) alert if the
  8847. hostname provided by the client mismatch with the servers.
  8848. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the server
  8849. will not send a SNI response instead of aborting the session.
  8850. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH - With this option set, the server
  8851. will send a SNI response as if the host names match instead of aborting
  8852. the session.
  8853. _Example_
  8854. \code
  8855. int ret = 0;
  8856. WOLFSSL_CTX* ctx = 0;
  8857. WOLFSSL* ssl = 0;
  8858. ctx = wolfSSL_CTX_new(method);
  8859. if (ctx == NULL) {
  8860. // context creation failed
  8861. }
  8862. ssl = wolfSSL_new(ctx);
  8863. if (ssl == NULL) {
  8864. // ssl creation failed
  8865. }
  8866. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8867. if (ret != WOLFSSL_SUCCESS) {
  8868. // sni usage failed
  8869. }
  8870. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  8871. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8872. \endcode
  8873. \sa wolfSSL_new
  8874. \sa wolfSSL_UseSNI
  8875. \sa wolfSSL_CTX_SNI_SetOptions
  8876. */
  8877. void wolfSSL_SNI_SetOptions(WOLFSSL* ssl, unsigned char type,
  8878. unsigned char options);
  8879. /*!
  8880. \brief This function is called on the server side to configure the behavior
  8881. of the SSL sessions using Server Name Indication for SSL objects created
  8882. from the SSL context passed in the 'ctx' parameter. The options are
  8883. explained below.
  8884. \return none No returns.
  8885. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8886. \param type indicates which type of server name is been passed in data.
  8887. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8888. \param options a bitwise semaphore with the chosen options. The available
  8889. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8890. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort
  8891. the handshake by sending a fatal-level unrecognized_name(112) alert if the
  8892. hostname provided by the client mismatch with the servers.
  8893. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the
  8894. server will not send a SNI response instead of aborting the session.
  8895. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH With this option set, the server
  8896. will send a SNI response as if the host names match instead of aborting
  8897. the session.
  8898. _Example_
  8899. \code
  8900. int ret = 0;
  8901. WOLFSSL_CTX* ctx = 0;
  8902. ctx = wolfSSL_CTX_new(method);
  8903. if (ctx == NULL) {
  8904. // context creation failed
  8905. }
  8906. ret = wolfSSL_CTX_UseSNI(ctx, 0, "www.yassl.com", strlen("www.yassl.com"));
  8907. if (ret != WOLFSSL_SUCCESS) {
  8908. // sni usage failed
  8909. }
  8910. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  8911. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8912. \endcode
  8913. \sa wolfSSL_CTX_new
  8914. \sa wolfSSL_CTX_UseSNI
  8915. \sa wolfSSL_SNI_SetOptions
  8916. */
  8917. void wolfSSL_CTX_SNI_SetOptions(WOLFSSL_CTX* ctx,
  8918. unsigned char type, unsigned char options);
  8919. /*!
  8920. \brief This function is called on the server side to retrieve the Server
  8921. Name Indication provided by the client from the Client Hello message sent
  8922. by the client to start a session. It does not requires context or session
  8923. setup to retrieve the SNI.
  8924. \return WOLFSSL_SUCCESS upon success.
  8925. \return BAD_FUNC_ARG is the error that will be returned in one of this
  8926. cases: buffer is NULL, bufferSz <= 0, sni is NULL, inOutSz is NULL or <= 0
  8927. \return BUFFER_ERROR is the error returned when there is a malformed
  8928. Client Hello message.
  8929. \return INCOMPLETE_DATA is the error returned when there is not enough
  8930. data to complete the extraction.
  8931. \param buffer pointer to the data provided by the client (Client Hello).
  8932. \param bufferSz size of the Client Hello message.
  8933. \param type indicates which type of server name is been retrieved
  8934. from the buffer. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8935. \param sni pointer to where the output is going to be stored.
  8936. \param inOutSz pointer to the output size, this value will be updated
  8937. to MIN("SNI's length", inOutSz).
  8938. _Example_
  8939. \code
  8940. unsigned char buffer[1024] = {0};
  8941. unsigned char result[32] = {0};
  8942. int length = 32;
  8943. // read Client Hello to buffer...
  8944. ret = wolfSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), 0, result, &length));
  8945. if (ret != WOLFSSL_SUCCESS) {
  8946. // sni retrieve failed
  8947. }
  8948. \endcode
  8949. \sa wolfSSL_UseSNI
  8950. \sa wolfSSL_CTX_UseSNI
  8951. \sa wolfSSL_SNI_GetRequest
  8952. */
  8953. int wolfSSL_SNI_GetFromBuffer(
  8954. const unsigned char* clientHello, unsigned int helloSz,
  8955. unsigned char type, unsigned char* sni, unsigned int* inOutSz);
  8956. /*!
  8957. \ingroup IO
  8958. \brief This function gets the status of an SNI object.
  8959. \return value This function returns the byte value of the SNI struct’s
  8960. status member if the SNI is not NULL.
  8961. \return 0 if the SNI object is NULL.
  8962. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8963. \param type the SNI type.
  8964. _Example_
  8965. \code
  8966. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8967. WOLFSSL* ssl = wolfSSL_new(ctx);
  8968. #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
  8969. Byte type = WOLFSSL_SNI_HOST_NAME;
  8970. char* request = (char*)&type;
  8971. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  8972. \endcode
  8973. \sa TLSX_SNI_Status
  8974. \sa TLSX_SNI_find
  8975. \sa TLSX_Find
  8976. */
  8977. unsigned char wolfSSL_SNI_Status(WOLFSSL* ssl, unsigned char type);
  8978. /*!
  8979. \brief This function is called on the server side to retrieve the
  8980. Server Name Indication provided by the client in a SSL session.
  8981. \return size the size of the provided SNI data.
  8982. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8983. \param type indicates which type of server name is been retrieved in
  8984. data. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8985. \param data pointer to the data provided by the client.
  8986. _Example_
  8987. \code
  8988. int ret = 0;
  8989. WOLFSSL_CTX* ctx = 0;
  8990. WOLFSSL* ssl = 0;
  8991. ctx = wolfSSL_CTX_new(method);
  8992. if (ctx == NULL) {
  8993. // context creation failed
  8994. }
  8995. ssl = wolfSSL_new(ctx);
  8996. if (ssl == NULL) {
  8997. // ssl creation failed
  8998. }
  8999. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  9000. if (ret != WOLFSSL_SUCCESS) {
  9001. // sni usage failed
  9002. }
  9003. if (wolfSSL_accept(ssl) == SSL_SUCCESS) {
  9004. void *data = NULL;
  9005. unsigned short size = wolfSSL_SNI_GetRequest(ssl, 0, &data);
  9006. }
  9007. \endcode
  9008. \sa wolfSSL_UseSNI
  9009. \sa wolfSSL_CTX_UseSNI
  9010. */
  9011. unsigned short wolfSSL_SNI_GetRequest(WOLFSSL *ssl,
  9012. unsigned char type, void** data);
  9013. /*!
  9014. \ingroup Setup
  9015. \brief Setup ALPN use for a wolfSSL session.
  9016. \return WOLFSSL_SUCCESS: upon success.
  9017. \return BAD_FUNC_ARG Returned if ssl or protocol_name_list
  9018. is null or protocol_name_listSz is too large or options
  9019. contain something not supported.
  9020. \return MEMORY_ERROR Error allocating memory for protocol list.
  9021. \return SSL_FAILURE upon failure.
  9022. \param ssl The wolfSSL session to use.
  9023. \param protocol_name_list List of protocol names to use.
  9024. Comma delimited string is required.
  9025. \param protocol_name_listSz Size of the list of protocol names.
  9026. \param options WOLFSSL_ALPN_CONTINUE_ON_MISMATCH or
  9027. WOLFSSL_ALPN_FAILED_ON_MISMATCH.
  9028. _Example_
  9029. \code
  9030. wolfSSL_Init();
  9031. WOLFSSL_CTX* ctx;
  9032. WOLFSSL* ssl;
  9033. WOLFSSL_METHOD method = // Some wolfSSL method
  9034. ctx = wolfSSL_CTX_new(method);
  9035. ssl = wolfSSL_new(ctx);
  9036. char alpn_list[] = {};
  9037. if (wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  9038. WOLFSSL_APN_FAILED_ON_MISMATCH) != WOLFSSL_SUCCESS)
  9039. {
  9040. // Error setting session ticket
  9041. }
  9042. \endcode
  9043. \sa TLSX_UseALPN
  9044. */
  9045. int wolfSSL_UseALPN(WOLFSSL* ssl, char *protocol_name_list,
  9046. unsigned int protocol_name_listSz,
  9047. unsigned char options);
  9048. /*!
  9049. \ingroup TLS
  9050. \brief This function gets the protocol name set by the server.
  9051. \return SSL_SUCCESS returned on successful execution where no
  9052. errors were thrown.
  9053. \return SSL_FATAL_ERROR returned if the extension was not found or
  9054. if there was no protocol match with peer. There will also be an
  9055. error thrown if there is more than one protocol name accepted.
  9056. \return SSL_ALPN_NOT_FOUND returned signifying that no protocol
  9057. match with peer was found.
  9058. \return BAD_FUNC_ARG returned if there was a NULL argument passed
  9059. into the function.
  9060. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9061. \param protocol_name a pointer to a char that represents the protocol
  9062. name and will be held in the ALPN structure.
  9063. \param size a word16 type that represents the size of the protocol_name.
  9064. _Example_
  9065. \code
  9066. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  9067. WOLFSSL* ssl = WOLFSSL_new(ctx);
  9068. ...
  9069. int err;
  9070. char* protocol_name = NULL;
  9071. Word16 protocol_nameSz = 0;
  9072. err = wolfSSL_ALPN_GetProtocol(ssl, &protocol_name, &protocol_nameSz);
  9073. if(err == SSL_SUCCESS){
  9074. // Sent ALPN protocol
  9075. }
  9076. \endcode
  9077. \sa TLSX_ALPN_GetRequest
  9078. \sa TLSX_Find
  9079. */
  9080. int wolfSSL_ALPN_GetProtocol(WOLFSSL* ssl, char **protocol_name,
  9081. unsigned short *size);
  9082. /*!
  9083. \ingroup TLS
  9084. \brief This function copies the alpn_client_list data from the SSL
  9085. object to the buffer.
  9086. \return SSL_SUCCESS returned if the function executed without error. The
  9087. alpn_client_list member of the SSL object has been copied to the
  9088. list parameter.
  9089. \return BAD_FUNC_ARG returned if the list or listSz parameter is NULL.
  9090. \return BUFFER_ERROR returned if there will be a problem with the
  9091. list buffer (either it’s NULL or the size is 0).
  9092. \return MEMORY_ERROR returned if there was a problem dynamically
  9093. allocating memory.
  9094. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9095. \param list a pointer to the buffer. The data from the SSL object will
  9096. be copied into it.
  9097. \param listSz the buffer size.
  9098. _Example_
  9099. \code
  9100. #import <wolfssl/ssl.h>
  9101. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method);
  9102. WOLFSSL* ssl = wolfSSL_new(ctx);
  9103. #ifdef HAVE_ALPN
  9104. char* list = NULL;
  9105. word16 listSz = 0;
  9106. err = wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz);
  9107. if(err == SSL_SUCCESS){
  9108. List of protocols names sent by client
  9109. }
  9110. \endcode
  9111. \sa wolfSSL_UseALPN
  9112. */
  9113. int wolfSSL_ALPN_GetPeerProtocol(WOLFSSL* ssl, char **list,
  9114. unsigned short *listSz);
  9115. /*!
  9116. \brief This function is called on the client side to enable the use of
  9117. Maximum Fragment Length in the SSL object passed in the 'ssl' parameter.
  9118. It means that the Maximum Fragment Length extension will be sent on
  9119. ClientHello by wolfSSL clients.
  9120. \return SSL_SUCCESS upon success.
  9121. \return BAD_FUNC_ARG is the error that will be returned in one of
  9122. these cases: ssl is NULL, mfl is out of range.
  9123. \return MEMORY_E is the error returned when there is not enough memory.
  9124. \param ssl pointer to a SSL object, created with wolfSSL_new().
  9125. \param mfl indicates which is the Maximum Fragment Length requested for the
  9126. session. The available options are: enum { WOLFSSL_MFL_2_9 = 1, 512 bytes
  9127. WOLFSSL_MFL_2_10 = 2, 1024 bytes WOLFSSL_MFL_2_11 = 3, 2048 bytes
  9128. WOLFSSL_MFL_2_12 = 4, 4096 bytes WOLFSSL_MFL_2_13 = 5, 8192
  9129. bytes wolfSSL ONLY!!! };
  9130. _Example_
  9131. \code
  9132. int ret = 0;
  9133. WOLFSSL_CTX* ctx = 0;
  9134. WOLFSSL* ssl = 0;
  9135. ctx = wolfSSL_CTX_new(method);
  9136. if (ctx == NULL) {
  9137. // context creation failed
  9138. }
  9139. ssl = wolfSSL_new(ctx);
  9140. if (ssl == NULL) {
  9141. // ssl creation failed
  9142. }
  9143. ret = wolfSSL_UseMaxFragment(ssl, WOLFSSL_MFL_2_11);
  9144. if (ret != 0) {
  9145. // max fragment usage failed
  9146. }
  9147. \endcode
  9148. \sa wolfSSL_new
  9149. \sa wolfSSL_CTX_UseMaxFragment
  9150. */
  9151. int wolfSSL_UseMaxFragment(WOLFSSL* ssl, unsigned char mfl);
  9152. /*!
  9153. \brief This function is called on the client side to enable the use
  9154. of Maximum Fragment Length for SSL objects created from the SSL context
  9155. passed in the 'ctx' parameter. It means that the Maximum Fragment Length
  9156. extension will be sent on ClientHello by wolfSSL clients.
  9157. \return SSL_SUCCESS upon success.
  9158. \return BAD_FUNC_ARG is the error that will be returned in one of
  9159. these cases: ctx is NULL, mfl is out of range.
  9160. \return MEMORY_E is the error returned when there is not enough memory.
  9161. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  9162. \param mfl indicates which is the Maximum Fragment Length requested
  9163. for the session. The available options are:
  9164. enum { WOLFSSL_MFL_2_9 = 1 512 bytes, WOLFSSL_MFL_2_10 = 2 1024 bytes,
  9165. WOLFSSL_MFL_2_11 = 3 2048 bytes WOLFSSL_MFL_2_12 = 4 4096 bytes,
  9166. WOLFSSL_MFL_2_13 = 5 8192 bytes wolfSSL ONLY!!!,
  9167. WOLFSSL_MFL_2_13 = 6 256 bytes wolfSSL ONLY!!!
  9168. };
  9169. _Example_
  9170. \code
  9171. int ret = 0;
  9172. WOLFSSL_CTX* ctx = 0;
  9173. ctx = wolfSSL_CTX_new(method);
  9174. if (ctx == NULL) {
  9175. // context creation failed
  9176. }
  9177. ret = wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11);
  9178. if (ret != 0) {
  9179. // max fragment usage failed
  9180. }
  9181. \endcode
  9182. \sa wolfSSL_CTX_new
  9183. \sa wolfSSL_UseMaxFragment
  9184. */
  9185. int wolfSSL_CTX_UseMaxFragment(WOLFSSL_CTX* ctx, unsigned char mfl);
  9186. /*!
  9187. \brief This function is called on the client side to enable the use of
  9188. Truncated HMAC in the SSL object passed in the 'ssl' parameter. It
  9189. means that the Truncated HMAC extension will be sent on ClientHello
  9190. by wolfSSL clients.
  9191. \return SSL_SUCCESS upon success.
  9192. \return BAD_FUNC_ARG is the error that will be returned in one of
  9193. these cases: ssl is NULL
  9194. \return MEMORY_E is the error returned when there is not enough memory.
  9195. \param ssl pointer to a SSL object, created with wolfSSL_new()
  9196. _Example_
  9197. \code
  9198. int ret = 0;
  9199. WOLFSSL_CTX* ctx = 0;
  9200. WOLFSSL* ssl = 0;
  9201. ctx = wolfSSL_CTX_new(method);
  9202. if (ctx == NULL) {
  9203. // context creation failed
  9204. }
  9205. ssl = wolfSSL_new(ctx);
  9206. if (ssl == NULL) {
  9207. // ssl creation failed
  9208. }
  9209. ret = wolfSSL_UseTruncatedHMAC(ssl);
  9210. if (ret != 0) {
  9211. // truncated HMAC usage failed
  9212. }
  9213. \endcode
  9214. \sa wolfSSL_new
  9215. \sa wolfSSL_CTX_UseMaxFragment
  9216. */
  9217. int wolfSSL_UseTruncatedHMAC(WOLFSSL* ssl);
  9218. /*!
  9219. \brief This function is called on the client side to enable the use of
  9220. Truncated HMAC for SSL objects created from the SSL context passed in
  9221. the 'ctx' parameter. It means that the Truncated HMAC extension will
  9222. be sent on ClientHello by wolfSSL clients.
  9223. \return SSL_SUCCESS upon success.
  9224. \return BAD_FUNC_ARG is the error that will be returned in one of
  9225. these cases: ctx is NULL
  9226. \return MEMORY_E is the error returned when there is not enough memory.
  9227. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  9228. _Example_
  9229. \code
  9230. int ret = 0;
  9231. WOLFSSL_CTX* ctx = 0;
  9232. ctx = wolfSSL_CTX_new(method);
  9233. if (ctx == NULL) {
  9234. // context creation failed
  9235. }
  9236. ret = wolfSSL_CTX_UseTruncatedHMAC(ctx);
  9237. if (ret != 0) {
  9238. // truncated HMAC usage failed
  9239. }
  9240. \endcode
  9241. \sa wolfSSL_CTX_new
  9242. \sa wolfSSL_UseMaxFragment
  9243. */
  9244. int wolfSSL_CTX_UseTruncatedHMAC(WOLFSSL_CTX* ctx);
  9245. /*!
  9246. \brief Stapling eliminates the need to contact the CA. Stapling
  9247. lowers the cost of certificate revocation check presented in OCSP.
  9248. \return SSL_SUCCESS returned if TLSX_UseCertificateStatusRequest
  9249. executes without error.
  9250. \return MEMORY_E returned if there is an error with the allocation
  9251. of memory.
  9252. \return BAD_FUNC_ARG returned if there is an argument that has a
  9253. NULL or otherwise unacceptable value passed into the function.
  9254. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9255. \param status_type a byte type that is passed through to
  9256. TLSX_UseCertificateStatusRequest() and stored in the
  9257. CertificateStatusRequest structure.
  9258. \param options a byte type that is passed through to
  9259. TLSX_UseCertificateStatusRequest() and stored in the
  9260. CertificateStatusRequest structure.
  9261. _Example_
  9262. \code
  9263. WOLFSSL* ssl = wolfSSL_new(ctx);
  9264. if (wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  9265. WOLFSSL_CSR2_OCSP_USE_NONCE) != SSL_SUCCESS){
  9266. // Failed case.
  9267. }
  9268. \endcode
  9269. \sa TLSX_UseCertificateStatusRequest
  9270. \sa wolfSSL_CTX_UseOCSPStapling
  9271. */
  9272. int wolfSSL_UseOCSPStapling(WOLFSSL* ssl,
  9273. unsigned char status_type, unsigned char options);
  9274. /*!
  9275. \brief This function requests the certificate status during the handshake.
  9276. \return SSL_SUCCESS returned if the function and subroutines execute
  9277. without error.
  9278. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  9279. otherwise if a unpermitted value is passed to a subroutine.
  9280. \return MEMORY_E returned if the function or subroutine failed to properly
  9281. allocate memory.
  9282. \param ctx a pointer to a WOLFSSL_CTX structure,
  9283. created using wolfSSL_CTX_new().
  9284. \param status_type a byte type that is passed through to
  9285. TLSX_UseCertificateStatusRequest() and stored in the
  9286. CertificateStatusRequest structure.
  9287. \param options a byte type that is passed through to
  9288. TLSX_UseCertificateStatusRequest() and stored in the
  9289. CertificateStatusRequest structure.
  9290. _Example_
  9291. \code
  9292. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9293. WOLFSSL* ssl = wolfSSL_new(ctx);
  9294. byte statusRequest = 0; // Initialize status request
  9295. switch(statusRequest){
  9296. case WOLFSSL_CSR_OCSP:
  9297. if(wolfSSL_CTX_UseOCSPStapling(ssl->ctx, WOLFSSL_CSR_OCSP,
  9298. WOLF_CSR_OCSP_USE_NONCE) != SSL_SUCCESS){
  9299. // UseCertificateStatusRequest failed
  9300. }
  9301. // Continue switch cases
  9302. \endcode
  9303. \sa wolfSSL_UseOCSPStaplingV2
  9304. \sa wolfSSL_UseOCSPStapling
  9305. \sa TLSX_UseCertificateStatusRequest
  9306. */
  9307. int wolfSSL_CTX_UseOCSPStapling(WOLFSSL_CTX* ctx,
  9308. unsigned char status_type, unsigned char options);
  9309. /*!
  9310. \brief The function sets the status type and options for OCSP.
  9311. \return SSL_SUCCESS - returned if the function and subroutines
  9312. executed without error.
  9313. \return MEMORY_E - returned if there was an allocation of memory error.
  9314. \return BAD_FUNC_ARG - returned if a NULL or otherwise unaccepted
  9315. argument was passed to the function or a subroutine.
  9316. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9317. \param status_type a byte type that loads the OCSP status type.
  9318. \param options a byte type that holds the OCSP options, set in
  9319. wolfSSL_SNI_SetOptions() and wolfSSL_CTX_SNI_SetOptions().
  9320. _Example_
  9321. \code
  9322. WOLFSSL* ssl = wolfSSL_new(ctx);
  9323. ...
  9324. if (wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP_MULTI, 0) != SSL_SUCCESS){
  9325. // Did not execute properly. Failure case code block.
  9326. }
  9327. \endcode
  9328. \sa TLSX_UseCertificatStatusRequestV2
  9329. \sa wolfSSL_SNI_SetOptions
  9330. \sa wolfSSL_CTX_SNI_SetOptions
  9331. */
  9332. int wolfSSL_UseOCSPStaplingV2(WOLFSSL* ssl,
  9333. unsigned char status_type, unsigned char options);
  9334. /*!
  9335. \brief Creates and initializes the certificate status request
  9336. for OCSP Stapling.
  9337. \return SSL_SUCCESS if the function and subroutines executed without error.
  9338. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or if
  9339. the side variable is not client side.
  9340. \return MEMORY_E returned if the allocation of memory failed.
  9341. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  9342. wolfSSL_CTX_new().
  9343. \param status_type a byte type that is located in the
  9344. CertificatStatusRequest structure and must be either WOLFSSL_CSR2_OCSP
  9345. or WOLFSSL_CSR2_OCSP_MULTI.
  9346. \param options a byte type that will be held in
  9347. CertificateStatusRequestItemV2 struct.
  9348. _Example_
  9349. \code
  9350. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9351. byte status_type;
  9352. byte options;
  9353. ...
  9354. if(wolfSSL_CTX_UseOCSPStaplingV2(ctx, status_type, options); != SSL_SUCCESS){
  9355. // Failure case.
  9356. }
  9357. \endcode
  9358. \sa TLSX_UseCertificateStatusRequestV2
  9359. \sa wc_RNG_GenerateBlock
  9360. \sa TLSX_Push
  9361. */
  9362. int wolfSSL_CTX_UseOCSPStaplingV2(WOLFSSL_CTX* ctx,
  9363. unsigned char status_type, unsigned char options);
  9364. /*!
  9365. \brief This function is called on the client side to enable the use of
  9366. Supported Elliptic Curves Extension in the SSL object passed in the 'ssl'
  9367. parameter. It means that the supported curves enabled will be sent on
  9368. ClientHello by wolfSSL clients. This function can be called more than
  9369. one time to enable multiple curves.
  9370. \return SSL_SUCCESS upon success.
  9371. \return BAD_FUNC_ARG is the error that will be returned in one of these
  9372. cases: ssl is NULL, name is a unknown value. (see below)
  9373. \return MEMORY_E is the error returned when there is not enough memory.
  9374. \param ssl pointer to a SSL object, created with wolfSSL_new().
  9375. \param name indicates which curve will be supported for the session. The
  9376. available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  9377. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  9378. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  9379. WOLFSSL_ECC_SECP521R1 = 0x19 };
  9380. _Example_
  9381. \code
  9382. int ret = 0;
  9383. WOLFSSL_CTX* ctx = 0;
  9384. WOLFSSL* ssl = 0;
  9385. ctx = wolfSSL_CTX_new(method);
  9386. if (ctx == NULL) {
  9387. // context creation failed
  9388. }
  9389. ssl = wolfSSL_new(ctx);
  9390. if (ssl == NULL) {
  9391. // ssl creation failed
  9392. }
  9393. ret = wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1);
  9394. if (ret != 0) {
  9395. // Elliptic Curve Extension usage failed
  9396. }
  9397. \endcode
  9398. \sa wolfSSL_CTX_new
  9399. \sa wolfSSL_CTX_UseSupportedCurve
  9400. */
  9401. int wolfSSL_UseSupportedCurve(WOLFSSL* ssl, word16 name);
  9402. /*!
  9403. \brief This function is called on the client side to enable the use of
  9404. Supported Elliptic Curves Extension for SSL objects created from the SSL
  9405. context passed in the 'ctx' parameter. It means that the supported curves
  9406. enabled will be sent on ClientHello by wolfSSL clients. This function can
  9407. be called more than one time to enable multiple curves.
  9408. \return SSL_SUCCESS upon success.
  9409. \return BAD_FUNC_ARG is the error that will be returned in one of these
  9410. cases: ctx is NULL, name is a unknown value. (see below)
  9411. \return MEMORY_E is the error returned when there is not enough memory.
  9412. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  9413. \param name indicates which curve will be supported for the session.
  9414. The available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  9415. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  9416. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  9417. WOLFSSL_ECC_SECP521R1 = 0x19 };
  9418. _Example_
  9419. \code
  9420. int ret = 0;
  9421. WOLFSSL_CTX* ctx = 0;
  9422. ctx = wolfSSL_CTX_new(method);
  9423. if (ctx == NULL) {
  9424. // context creation failed
  9425. }
  9426. ret = wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1);
  9427. if (ret != 0) {
  9428. // Elliptic Curve Extension usage failed
  9429. }
  9430. \endcode
  9431. \sa wolfSSL_CTX_new
  9432. \sa wolfSSL_UseSupportedCurve
  9433. */
  9434. int wolfSSL_CTX_UseSupportedCurve(WOLFSSL_CTX* ctx,
  9435. word16 name);
  9436. /*!
  9437. \ingroup IO
  9438. \brief This function forces secure renegotiation for the supplied
  9439. WOLFSSL structure. This is not recommended.
  9440. \return SSL_SUCCESS Successfully set secure renegotiation.
  9441. \return BAD_FUNC_ARG Returns error if ssl is null.
  9442. \return MEMORY_E Returns error if unable to allocate memory for secure
  9443. renegotiation.
  9444. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9445. _Example_
  9446. \code
  9447. wolfSSL_Init();
  9448. WOLFSSL_CTX* ctx;
  9449. WOLFSSL* ssl;
  9450. WOLFSSL_METHOD method = // Some wolfSSL method
  9451. ctx = wolfSSL_CTX_new(method);
  9452. ssl = wolfSSL_new(ctx);
  9453. if(wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS)
  9454. {
  9455. // Error setting secure renegotiation
  9456. }
  9457. \endcode
  9458. \sa TLSX_Find
  9459. \sa TLSX_UseSecureRenegotiation
  9460. */
  9461. int wolfSSL_UseSecureRenegotiation(WOLFSSL* ssl);
  9462. /*!
  9463. \ingroup IO
  9464. \brief This function executes a secure renegotiation handshake; this is user
  9465. forced as wolfSSL discourages this functionality.
  9466. \return SSL_SUCCESS returned if the function executed without error.
  9467. \return BAD_FUNC_ARG returned if the WOLFSSL structure was NULL or otherwise
  9468. if an unacceptable argument was passed in a subroutine.
  9469. \return SECURE_RENEGOTIATION_E returned if there was an error with
  9470. renegotiating the handshake.
  9471. \return SSL_FATAL_ERROR returned if there was an error with the
  9472. server or client configuration and the renegotiation could
  9473. not be completed. See wolfSSL_negotiate().
  9474. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9475. _Example_
  9476. \code
  9477. WOLFSSL* ssl = wolfSSL_new(ctx);
  9478. ...
  9479. if(wolfSSL_Rehandshake(ssl) != SSL_SUCCESS){
  9480. // There was an error and the rehandshake is not successful.
  9481. }
  9482. \endcode
  9483. \sa wolfSSL_negotiate
  9484. \sa wc_InitSha512
  9485. \sa wc_InitSha384
  9486. \sa wc_InitSha256
  9487. \sa wc_InitSha
  9488. \sa wc_InitMd5
  9489. */
  9490. int wolfSSL_Rehandshake(WOLFSSL* ssl);
  9491. /*!
  9492. \ingroup IO
  9493. \brief Force provided WOLFSSL structure to use session ticket. The
  9494. constant HAVE_SESSION_TICKET should be defined and the constant
  9495. NO_WOLFSSL_CLIENT should not be defined to use this function.
  9496. \return SSL_SUCCESS Successfully set use session ticket.
  9497. \return BAD_FUNC_ARG Returned if ssl is null.
  9498. \return MEMORY_E Error allocating memory for setting session ticket.
  9499. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9500. _Example_
  9501. \code
  9502. wolfSSL_Init();
  9503. WOLFSSL_CTX* ctx;
  9504. WOLFSSL* ssl;
  9505. WOLFSSL_METHOD method = // Some wolfSSL method
  9506. ctx = wolfSSL_CTX_new(method);
  9507. ssl = wolfSSL_new(ctx);
  9508. if(wolfSSL_UseSessionTicket(ssl) != SSL_SUCCESS)
  9509. {
  9510. // Error setting session ticket
  9511. }
  9512. \endcode
  9513. \sa TLSX_UseSessionTicket
  9514. */
  9515. int wolfSSL_UseSessionTicket(WOLFSSL* ssl);
  9516. /*!
  9517. \ingroup Setup
  9518. \brief This function sets wolfSSL context to use a session ticket.
  9519. \return SSL_SUCCESS Function executed successfully.
  9520. \return BAD_FUNC_ARG Returned if ctx is null.
  9521. \return MEMORY_E Error allocating memory in internal function.
  9522. \param ctx The WOLFSSL_CTX structure to use.
  9523. _Example_
  9524. \code
  9525. wolfSSL_Init();
  9526. WOLFSSL_CTX* ctx;
  9527. WOLFSSL_METHOD method = // Some wolfSSL method ;
  9528. ctx = wolfSSL_CTX_new(method);
  9529. if(wolfSSL_CTX_UseSessionTicket(ctx) != SSL_SUCCESS)
  9530. {
  9531. // Error setting session ticket
  9532. }
  9533. \endcode
  9534. \sa TLSX_UseSessionTicket
  9535. */
  9536. int wolfSSL_CTX_UseSessionTicket(WOLFSSL_CTX* ctx);
  9537. /*!
  9538. \ingroup IO
  9539. \brief This function copies the ticket member of the Session structure to
  9540. the buffer.
  9541. \return SSL_SUCCESS returned if the function executed without error.
  9542. \return BAD_FUNC_ARG returned if one of the arguments was NULL or if the
  9543. bufSz argument was 0.
  9544. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9545. \param buf a byte pointer representing the memory buffer.
  9546. \param bufSz a word32 pointer representing the buffer size.
  9547. _Example_
  9548. \code
  9549. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9550. WOLFSSL* ssl = wolfSSL_new(ctx);
  9551. byte* buf;
  9552. word32 bufSz; // Initialize with buf size
  9553. if(wolfSSL_get_SessionTicket(ssl, buf, bufSz) <= 0){
  9554. // Nothing was written to the buffer
  9555. } else {
  9556. // the buffer holds the content from ssl->session->ticket
  9557. }
  9558. \endcode
  9559. \sa wolfSSL_UseSessionTicket
  9560. \sa wolfSSL_set_SessionTicket
  9561. */
  9562. int wolfSSL_get_SessionTicket(WOLFSSL* ssl, unsigned char* buf, word32* bufSz);
  9563. /*!
  9564. \ingroup IO
  9565. \brief This function sets the ticket member of the WOLFSSL_SESSION
  9566. structure within the WOLFSSL struct. The buffer passed into the function
  9567. is copied to memory.
  9568. \return SSL_SUCCESS returned on successful execution of the function.
  9569. The function returned without errors.
  9570. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL. This will
  9571. also be thrown if the buf argument is NULL but the bufSz argument
  9572. is not zero.
  9573. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9574. \param buf a byte pointer that gets loaded into the ticket member
  9575. of the session structure.
  9576. \param bufSz a word32 type that represents the size of the buffer.
  9577. _Example_
  9578. \code
  9579. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9580. WOLFSSL* ssl = wolfSSL_new(ctx);
  9581. byte* buffer; // File to load
  9582. word32 bufSz;
  9583. ...
  9584. if(wolfSSL_KeepArrays(ssl, buffer, bufSz) != SSL_SUCCESS){
  9585. // There was an error loading the buffer to memory.
  9586. }
  9587. \endcode
  9588. \sa wolfSSL_set_SessionTicket_cb
  9589. */
  9590. int wolfSSL_set_SessionTicket(WOLFSSL* ssl, const unsigned char* buf,
  9591. word32 bufSz);
  9592. /*!
  9593. \brief This function sets the session ticket callback. The type
  9594. CallbackSessionTicket is a function pointer with the signature of:
  9595. int (*CallbackSessionTicket)(WOLFSSL*, const unsigned char*, int, void*)
  9596. \return SSL_SUCCESS returned if the function executed without error.
  9597. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  9598. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9599. \param cb a function pointer to the type CallbackSessionTicket.
  9600. \param ctx a void pointer to the session_ticket_ctx member of the
  9601. WOLFSSL structure.
  9602. _Example_
  9603. \code
  9604. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9605. WOLFSSL* ssl = wolfSSL_new(ctx);
  9606. int sessionTicketCB(WOLFSSL* ssl, const unsigned char* ticket, int ticketSz,
  9607. void* ctx){ … }
  9608. wolfSSL_set_SessionTicket_cb(ssl, sessionTicketCB, (void*)”initial session”);
  9609. \endcode
  9610. \sa wolfSSL_get_SessionTicket
  9611. \sa CallbackSessionTicket
  9612. \sa sessionTicketCB
  9613. */
  9614. int wolfSSL_set_SessionTicket_cb(WOLFSSL* ssl,
  9615. CallbackSessionTicket cb, void* ctx);
  9616. /*!
  9617. \brief This function sends a session ticket to the client after a TLS v1.3
  9618. handhsake has been established.
  9619. \return WOLFSSL_SUCCESS returned if a new session ticket was sent.
  9620. \return BAD_FUNC_ARG returned if WOLFSSL structure is NULL, or not using
  9621. TLS v1.3.
  9622. \return SIDE_ERROR returned if not a server.
  9623. \return NOT_READY_ERROR returned if the handshake has not completed.
  9624. \return WOLFSSL_FATAL_ERROR returned if creating or sending message fails.
  9625. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9626. _Example_
  9627. \code
  9628. int ret;
  9629. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9630. WOLFSSL* ssl = wolfSSL_new(ctx);
  9631. ret = wolfSSL_send_SessionTicket(ssl);
  9632. if (ret != WOLFSSL_SUCCESS) {
  9633. // New session ticket not sent.
  9634. }
  9635. \endcode
  9636. \sa wolfSSL_get_SessionTicket
  9637. \sa CallbackSessionTicket
  9638. \sa sessionTicketCB
  9639. */
  9640. int wolfSSL_send_SessionTicket(WOLFSSL* ssl);
  9641. /*!
  9642. \brief This function sets the session ticket key encrypt callback function
  9643. for a server to support session tickets as specified in RFC 5077.
  9644. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9645. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  9646. invalid arguments to the function.
  9647. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  9648. \param cb user callback function to encrypt/decrypt session tickets
  9649. \param ssl(Callback) pointer to the WOLFSSL object, created with
  9650. wolfSSL_new()
  9651. \param key_name(Callback) unique key name for this ticket context, should
  9652. be randomly generated
  9653. \param iv(Callback) unique IV for this ticket, up to 128 bits, should
  9654. be randomly generated
  9655. \param mac(Callback) up to 256 bit mac for this ticket
  9656. \param enc(Callback) if this encrypt parameter is true the user should fill
  9657. in key_name, iv, mac, and encrypt the ticket in-place of length inLen and
  9658. set the resulting output length in *outLen. Returning WOLFSSL_TICKET_RET_OK
  9659. tells wolfSSL that the encryption was successful. If this encrypt parameter
  9660. is false, the user should perform a decrypt of the ticket in-place of length
  9661. inLen using key_name, iv, and mac. The resulting decrypt length should be
  9662. set in *outLen. Returning WOLFSSL_TICKET_RET_OK tells wolfSSL to proceed
  9663. using the decrypted ticket. Returning WOLFSSL_TICKET_RET_CREATE tells
  9664. wolfSSL to use the decrypted ticket but also to generate a new one to
  9665. send to the client, helpful if recently rolled keys and don’t want to
  9666. force a full handshake. Returning WOLFSSL_TICKET_RET_REJECT tells
  9667. wolfSSL to reject this ticket, perform a full handshake, and create
  9668. a new standard session ID for normal session resumption. Returning
  9669. WOLFSSL_TICKET_RET_FATAL tells wolfSSL to end the connection
  9670. attempt with a fatal error.
  9671. \param ticket(Callback) the input/output buffer for the encrypted ticket.
  9672. See the enc parameter
  9673. \param inLen(Callback) the input length of the ticket parameter
  9674. \param outLen(Callback) the resulting output length of the ticket parameter.
  9675. When entering the callback outLen will indicate the maximum size available
  9676. in the ticket buffer.
  9677. \param userCtx(Callback) the user context set with
  9678. wolfSSL_CTX_set_TicketEncCtx()
  9679. _Example_
  9680. \code
  9681. See wolfssl/test.h myTicketEncCb() used by the example
  9682. server and example echoserver.
  9683. \endcode
  9684. \sa wolfSSL_CTX_set_TicketHint
  9685. \sa wolfSSL_CTX_set_TicketEncCtx
  9686. */
  9687. int wolfSSL_CTX_set_TicketEncCb(WOLFSSL_CTX* ctx,
  9688. SessionTicketEncCb);
  9689. /*!
  9690. \brief This function sets the session ticket hint relayed to the client.
  9691. For server side use.
  9692. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9693. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  9694. invalid arguments to the function.
  9695. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  9696. \param hint number of seconds the ticket might be valid for. Hint to client.
  9697. _Example_
  9698. \code
  9699. none
  9700. \endcode
  9701. \sa wolfSSL_CTX_set_TicketEncCb
  9702. */
  9703. int wolfSSL_CTX_set_TicketHint(WOLFSSL_CTX* ctx, int);
  9704. /*!
  9705. \brief This function sets the session ticket encrypt user context for the
  9706. callback. For server side use.
  9707. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9708. \return BAD_FUNC_ARG will be returned on failure. This is caused by
  9709. passing invalid arguments to the function.
  9710. \param ctx pointer to the WOLFSSL_CTX object, created
  9711. with wolfSSL_CTX_new().
  9712. \param userCtx the user context for the callback
  9713. _Example_
  9714. \code
  9715. none
  9716. \endcode
  9717. \sa wolfSSL_CTX_set_TicketEncCb
  9718. */
  9719. int wolfSSL_CTX_set_TicketEncCtx(WOLFSSL_CTX* ctx, void*);
  9720. /*!
  9721. \brief This function gets the session ticket encrypt user context for the
  9722. callback. For server side use.
  9723. \return userCtx will be returned upon successfully getting the session.
  9724. \return NULL will be returned on failure. This is caused by
  9725. passing invalid arguments to the function, or when the user context has
  9726. not been set.
  9727. \param ctx pointer to the WOLFSSL_CTX object, created
  9728. with wolfSSL_CTX_new().
  9729. _Example_
  9730. \code
  9731. none
  9732. \endcode
  9733. \sa wolfSSL_CTX_set_TicketEncCtx
  9734. */
  9735. void* wolfSSL_CTX_get_TicketEncCtx(WOLFSSL_CTX* ctx);
  9736. /*!
  9737. \brief This function sets the handshake done callback. The hsDoneCb and
  9738. hsDoneCtx members of the WOLFSSL structure are set in this function.
  9739. \return SSL_SUCCESS returned if the function executed without an error.
  9740. The hsDoneCb and hsDoneCtx members of the WOLFSSL struct are set.
  9741. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL.
  9742. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9743. \param cb a function pointer of type HandShakeDoneCb with the signature of
  9744. the form: int (*HandShakeDoneCb)(WOLFSSL*, void*);
  9745. \param user_ctx a void pointer to the user registered context.
  9746. _Example_
  9747. \code
  9748. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9749. WOLFSSL* ssl = wolfSSL_new(ctx);
  9750. int myHsDoneCb(WOLFSSL* ssl, void* user_ctx){
  9751. // callback function
  9752. }
  9753. wolfSSL_SetHsDoneCb(ssl, myHsDoneCb, NULL);
  9754. \endcode
  9755. \sa HandShakeDoneCb
  9756. */
  9757. int wolfSSL_SetHsDoneCb(WOLFSSL* ssl, HandShakeDoneCb cb, void* user_ctx);
  9758. /*!
  9759. \ingroup IO
  9760. \brief This function prints the statistics from the session.
  9761. \return SSL_SUCCESS returned if the function and subroutines return without
  9762. error. The session stats have been successfully retrieved and printed.
  9763. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9764. was passed an unacceptable argument.
  9765. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9766. \param none No parameters.
  9767. _Example_
  9768. \code
  9769. // You will need to have a session object to retrieve stats from.
  9770. if(wolfSSL_PrintSessionStats(void) != SSL_SUCCESS ){
  9771. // Did not print session stats
  9772. }
  9773. \endcode
  9774. \sa wolfSSL_get_session_stats
  9775. */
  9776. int wolfSSL_PrintSessionStats(void);
  9777. /*!
  9778. \ingroup IO
  9779. \brief This function gets the statistics for the session.
  9780. \return SSL_SUCCESS returned if the function and subroutines return without
  9781. error. The session stats have been successfully retrieved and printed.
  9782. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9783. was passed an unacceptable argument.
  9784. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9785. \param active a word32 pointer representing the total current sessions.
  9786. \param total a word32 pointer representing the total sessions.
  9787. \param peak a word32 pointer representing the peak sessions.
  9788. \param maxSessions a word32 pointer representing the maximum sessions.
  9789. _Example_
  9790. \code
  9791. int wolfSSL_PrintSessionStats(void){
  9792. ret = wolfSSL_get_session_stats(&totalSessionsNow,
  9793. &totalSessionsSeen, &peak, &maxSessions);
  9794. return ret;
  9795. \endcode
  9796. \sa wolfSSL_PrintSessionStats
  9797. */
  9798. int wolfSSL_get_session_stats(unsigned int* active,
  9799. unsigned int* total,
  9800. unsigned int* peak,
  9801. unsigned int* maxSessions);
  9802. /*!
  9803. \ingroup TLS
  9804. \brief This function copies the values of cr and sr then passes through to
  9805. wc_PRF (pseudo random function) and returns that value.
  9806. \return 0 on success
  9807. \return BUFFER_E returned if there will be an error
  9808. with the size of the buffer.
  9809. \return MEMORY_E returned if a subroutine failed
  9810. to allocate dynamic memory.
  9811. \param ms the master secret held in the Arrays structure.
  9812. \param msLen the length of the master secret.
  9813. \param pms the pre-master secret held in the Arrays structure.
  9814. \param pmsLen the length of the pre-master secret.
  9815. \param cr the client random.
  9816. \param sr the server random.
  9817. \param tls1_2 signifies that the version is at least tls version 1.2.
  9818. \param hash_type signifies the hash type.
  9819. _Example_
  9820. \code
  9821. WOLFSSL* ssl;
  9822. called in MakeTlsMasterSecret and retrieves the necessary
  9823. information as follows:
  9824. int MakeTlsMasterSecret(WOLFSSL* ssl){
  9825. int ret;
  9826. ret = wolfSSL_makeTlsMasterSecret(ssl->arrays->masterSecret, SECRET_LEN,
  9827. ssl->arrays->preMasterSecret, ssl->arrays->preMasterSz,
  9828. ssl->arrays->clientRandom, ssl->arrays->serverRandom,
  9829. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9830. return ret;
  9831. }
  9832. \endcode
  9833. \sa wc_PRF
  9834. \sa MakeTlsMasterSecret
  9835. */
  9836. int wolfSSL_MakeTlsMasterSecret(unsigned char* ms, word32 msLen,
  9837. const unsigned char* pms, word32 pmsLen,
  9838. const unsigned char* cr, const unsigned char* sr,
  9839. int tls1_2, int hash_type);
  9840. /*!
  9841. \ingroup CertsKeys
  9842. \brief An external facing wrapper to derive TLS Keys.
  9843. \return 0 returned on success.
  9844. \return BUFFER_E returned if the sum of labLen and
  9845. seedLen (computes total size) exceeds the maximum size.
  9846. \return MEMORY_E returned if the allocation of memory failed.
  9847. \param key_data a byte pointer that is allocateded in DeriveTlsKeys
  9848. and passed through to wc_PRF to hold the final hash.
  9849. \param keyLen a word32 type that is derived in DeriveTlsKeys
  9850. from the WOLFSSL structure’s specs member.
  9851. \param ms a constant pointer type holding the master secret
  9852. held in the arrays structure within the WOLFSSL structure.
  9853. \param msLen a word32 type that holds the length of the
  9854. master secret in an enumerated define, SECRET_LEN.
  9855. \param sr a constant byte pointer to the serverRandom
  9856. member of the arrays structure within the WOLFSSL structure.
  9857. \param cr a constant byte pointer to the clientRandom
  9858. member of the arrays structure within the WOLFSSL structure.
  9859. \param tls1_2 an integer type returned from IsAtLeastTLSv1_2().
  9860. \param hash_type an integer type held in the WOLFSSL structure.
  9861. _Example_
  9862. \code
  9863. int DeriveTlsKeys(WOLFSSL* ssl){
  9864. int ret;
  9865. ret = wolfSSL_DeriveTlsKeys(key_data, length, ssl->arrays->masterSecret,
  9866. SECRET_LEN, ssl->arrays->clientRandom,
  9867. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9868. }
  9869. \endcode
  9870. \sa wc_PRF
  9871. \sa DeriveTlsKeys
  9872. \sa IsAtLeastTLSv1_2
  9873. */
  9874. int wolfSSL_DeriveTlsKeys(unsigned char* key_data, word32 keyLen,
  9875. const unsigned char* ms, word32 msLen,
  9876. const unsigned char* sr, const unsigned char* cr,
  9877. int tls1_2, int hash_type);
  9878. /*!
  9879. \brief wolfSSL_connect_ex() is an extension that allows
  9880. a HandShake Callback to be set. This can be useful in
  9881. embedded systems for debugging support when a debugger isn’t
  9882. available and sniffing is impractical. The HandShake Callback
  9883. will be called whether or not a handshake error occurred.
  9884. No dynamic memory is used since the maximum number of SSL
  9885. packets is known. Packet names can be accessed through packetNames[].
  9886. The connect extension also allows a Timeout Callback to be set along
  9887. with a timeout value. This is useful if the user doesn’t want
  9888. to wait for the TCP stack to timeout. This extension can be called
  9889. with either, both, or neither callbacks.
  9890. \return SSL_SUCCESS upon success.
  9891. \return GETTIME_ERROR will be returned if gettimeofday()
  9892. encountered an error.
  9893. \return SETITIMER_ERROR will be returned if setitimer()
  9894. encountered an error.
  9895. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9896. \return SSL_FATAL_ERROR will be returned if the underlying SSL_connect()
  9897. call encountered an error.
  9898. \param none No parameters.
  9899. _Example_
  9900. \code
  9901. none
  9902. \endcode
  9903. \sa wolfSSL_accept_ex
  9904. */
  9905. int wolfSSL_connect_ex(WOLFSSL* ssl, HandShakeCallBack hsCb,
  9906. TimeoutCallBack toCb, WOLFSSL_TIMEVAL timeout);
  9907. /*!
  9908. \brief wolfSSL_accept_ex() is an extension that allows a HandShake Callback
  9909. to be set. This can be useful in embedded systems for debugging support
  9910. when a debugger isn’t available and sniffing is impractical. The HandShake
  9911. Callback will be called whether or not a handshake error occurred.
  9912. No dynamic memory is used since the maximum number of SSL packets is known.
  9913. Packet names can be accessed through packetNames[]. The connect extension
  9914. also allows a Timeout Callback to be set along with a timeout value.
  9915. This is useful if the user doesn’t want to wait for the TCP stack to timeout.
  9916. This extension can be called with either, both, or neither callbacks.
  9917. \return SSL_SUCCESS upon success.
  9918. \return GETTIME_ERROR will be returned if gettimeofday()
  9919. encountered an error.
  9920. \return SETITIMER_ERROR will be returned if setitimer()
  9921. encountered an error.
  9922. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9923. \return SSL_FATAL_ERROR will be returned if the underlying
  9924. SSL_accept() call encountered an error.
  9925. \param none No parameters.
  9926. _Example_
  9927. \code
  9928. none
  9929. \endcode
  9930. \sa wolfSSL_connect_ex
  9931. */
  9932. int wolfSSL_accept_ex(WOLFSSL* ssl, HandShakeCallBacki hsCb,
  9933. TimeoutCallBack toCb, WOLFSSL_TIMEVAL timeout);
  9934. /*!
  9935. \ingroup IO
  9936. \brief This is used to set the internal file pointer for a BIO.
  9937. \return SSL_SUCCESS On successfully setting file pointer.
  9938. \return SSL_FAILURE If an error case was encountered.
  9939. \param bio WOLFSSL_BIO structure to set pair.
  9940. \param fp file pointer to set in bio.
  9941. \param c close file behavior flag.
  9942. _Example_
  9943. \code
  9944. WOLFSSL_BIO* bio;
  9945. XFILE fp;
  9946. int ret;
  9947. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9948. ret = wolfSSL_BIO_set_fp(bio, fp, BIO_CLOSE);
  9949. // check ret value
  9950. \endcode
  9951. \sa wolfSSL_BIO_new
  9952. \sa wolfSSL_BIO_s_mem
  9953. \sa wolfSSL_BIO_get_fp
  9954. \sa wolfSSL_BIO_free
  9955. */
  9956. long wolfSSL_BIO_set_fp(WOLFSSL_BIO *bio, XFILE fp, int c);
  9957. /*!
  9958. \ingroup IO
  9959. \brief This is used to get the internal file pointer for a BIO.
  9960. \return SSL_SUCCESS On successfully getting file pointer.
  9961. \return SSL_FAILURE If an error case was encountered.
  9962. \param bio WOLFSSL_BIO structure to set pair.
  9963. \param fp file pointer to set in bio.
  9964. _Example_
  9965. \code
  9966. WOLFSSL_BIO* bio;
  9967. XFILE fp;
  9968. int ret;
  9969. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9970. ret = wolfSSL_BIO_get_fp(bio, &fp);
  9971. // check ret value
  9972. \endcode
  9973. \sa wolfSSL_BIO_new
  9974. \sa wolfSSL_BIO_s_mem
  9975. \sa wolfSSL_BIO_set_fp
  9976. \sa wolfSSL_BIO_free
  9977. */
  9978. long wolfSSL_BIO_get_fp(WOLFSSL_BIO *bio, XFILE* fp);
  9979. /*!
  9980. \ingroup Setup
  9981. \brief This function checks that the private key is a match
  9982. with the certificate being used.
  9983. \return SSL_SUCCESS On successfully match.
  9984. \return SSL_FAILURE If an error case was encountered.
  9985. \return <0 All error cases other than SSL_FAILURE are negative values.
  9986. \param ssl WOLFSSL structure to check.
  9987. _Example_
  9988. \code
  9989. WOLFSSL* ssl;
  9990. int ret;
  9991. // create and set up ssl
  9992. ret = wolfSSL_check_private_key(ssl);
  9993. // check ret value
  9994. \endcode
  9995. \sa wolfSSL_new
  9996. \sa wolfSSL_free
  9997. */
  9998. int wolfSSL_check_private_key(const WOLFSSL* ssl);
  9999. /*!
  10000. \ingroup CertsKeys
  10001. \brief This function looks for and returns the extension index
  10002. matching the passed in NID value.
  10003. \return >= 0 If successful the extension index is returned.
  10004. \return -1 If extension is not found or error is encountered.
  10005. \param x509 certificate to get parse through for extension.
  10006. \param nid extension OID to be found.
  10007. \param lastPos start search from extension after lastPos.
  10008. Set to -1 initially.
  10009. _Example_
  10010. \code
  10011. const WOLFSSL_X509* x509;
  10012. int lastPos = -1;
  10013. int idx;
  10014. idx = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints, lastPos);
  10015. \endcode
  10016. */
  10017. int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509,
  10018. int nid, int lastPos);
  10019. /*!
  10020. \ingroup CertsKeys
  10021. \brief This function looks for and returns the extension
  10022. matching the passed in NID value.
  10023. \return pointer If successful a STACK_OF(WOLFSSL_ASN1_OBJECT)
  10024. pointer is returned.
  10025. \return NULL If extension is not found or error is encountered.
  10026. \param x509 certificate to get parse through for extension.
  10027. \param nid extension OID to be found.
  10028. \param c if not NULL is set to -2 for multiple extensions found -1
  10029. if not found, 0 if found and not critical and 1 if found and critical.
  10030. \param idx if NULL return first extension matched otherwise if not
  10031. stored in x509 start at idx.
  10032. _Example_
  10033. \code
  10034. const WOLFSSL_X509* x509;
  10035. int c;
  10036. int idx = 0;
  10037. STACK_OF(WOLFSSL_ASN1_OBJECT)* sk;
  10038. sk = wolfSSL_X509_get_ext_d2i(x509, NID_basic_constraints, &c, &idx);
  10039. //check sk for NULL and then use it. sk needs freed after done.
  10040. \endcode
  10041. \sa wolfSSL_sk_ASN1_OBJECT_free
  10042. */
  10043. void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509,
  10044. int nid, int* c, int* idx);
  10045. /*!
  10046. \ingroup CertsKeys
  10047. \brief This function returns the hash of the DER certificate.
  10048. \return SSL_SUCCESS On successfully creating a hash.
  10049. \return SSL_FAILURE Returned on bad input or unsuccessful hash.
  10050. \param x509 certificate to get the hash of.
  10051. \param digest the hash algorithm to use.
  10052. \param buf buffer to hold hash.
  10053. \param len length of buffer.
  10054. _Example_
  10055. \code
  10056. WOLFSSL_X509* x509;
  10057. unsigned char buffer[64];
  10058. unsigned int bufferSz;
  10059. int ret;
  10060. ret = wolfSSL_X509_digest(x509, wolfSSL_EVP_sha256(), buffer, &bufferSz);
  10061. //check ret value
  10062. \endcode
  10063. \sa none
  10064. */
  10065. int wolfSSL_X509_digest(const WOLFSSL_X509* x509,
  10066. const WOLFSSL_EVP_MD* digest, unsigned char* buf, unsigned int* len);
  10067. /*!
  10068. \ingroup Setup
  10069. \brief his is used to set the certificate for WOLFSSL structure to use
  10070. during a handshake.
  10071. \return SSL_SUCCESS On successful setting argument.
  10072. \return SSL_FAILURE If a NULL argument passed in.
  10073. \param ssl WOLFSSL structure to set certificate in.
  10074. \param x509 certificate to use.
  10075. _Example_
  10076. \code WOLFSSL* ssl;
  10077. WOLFSSL_X509* x509
  10078. int ret;
  10079. // create ssl object and x509
  10080. ret = wolfSSL_use_certificate(ssl, x509);
  10081. // check ret value
  10082. \endcode
  10083. \sa wolfSSL_new
  10084. \sa wolfSSL_free
  10085. */
  10086. int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509);
  10087. /*!
  10088. \ingroup Setup
  10089. \brief This is used to set the certificate for WOLFSSL structure
  10090. to use during a handshake. A DER formatted buffer is expected.
  10091. \return SSL_SUCCESS On successful setting argument.
  10092. \return SSL_FAILURE If a NULL argument passed in.
  10093. \param ssl WOLFSSL structure to set certificate in.
  10094. \param der DER certificate to use.
  10095. \param derSz size of the DER buffer passed in.
  10096. _Example_
  10097. \code
  10098. WOLFSSL* ssl;
  10099. unsigned char* der;
  10100. int derSz;
  10101. int ret;
  10102. // create ssl object and set DER variables
  10103. ret = wolfSSL_use_certificate_ASN1(ssl, der, derSz);
  10104. // check ret value
  10105. \endcode
  10106. \sa wolfSSL_new
  10107. \sa wolfSSL_free
  10108. */
  10109. int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, unsigned char* der,
  10110. int derSz);
  10111. /*!
  10112. \ingroup CertsKeys
  10113. \brief This is used to set the private key for the WOLFSSL structure.
  10114. \return SSL_SUCCESS On successful setting argument.
  10115. \return SSL_FAILURE If a NULL ssl passed in. All error
  10116. cases will be negative values.
  10117. \param ssl WOLFSSL structure to set argument in.
  10118. \param pkey private key to use.
  10119. _Example_
  10120. \code
  10121. WOLFSSL* ssl;
  10122. WOLFSSL_EVP_PKEY* pkey;
  10123. int ret;
  10124. // create ssl object and set up private key
  10125. ret = wolfSSL_use_PrivateKey(ssl, pkey);
  10126. // check ret value
  10127. \endcode
  10128. \sa wolfSSL_new
  10129. \sa wolfSSL_free
  10130. */
  10131. int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey);
  10132. /*!
  10133. \ingroup CertsKeys
  10134. \brief This is used to set the private key for the WOLFSSL
  10135. structure. A DER formatted key buffer is expected.
  10136. \return SSL_SUCCESS On successful setting parsing and
  10137. setting the private key.
  10138. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  10139. will be negative values.
  10140. \param pri type of private key.
  10141. \param ssl WOLFSSL structure to set argument in.
  10142. \param der buffer holding DER key.
  10143. \param derSz size of der buffer.
  10144. _Example_
  10145. \code
  10146. WOLFSSL* ssl;
  10147. unsigned char* pkey;
  10148. long pkeySz;
  10149. int ret;
  10150. // create ssl object and set up private key
  10151. ret = wolfSSL_use_PrivateKey_ASN1(1, ssl, pkey, pkeySz);
  10152. // check ret value
  10153. \endcode
  10154. \sa wolfSSL_new
  10155. \sa wolfSSL_free
  10156. \sa wolfSSL_use_PrivateKey
  10157. */
  10158. int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl,
  10159. unsigned char* der, long derSz);
  10160. /*!
  10161. \ingroup CertsKeys
  10162. \brief This is used to set the private key for the WOLFSSL
  10163. structure. A DER formatted RSA key buffer is expected.
  10164. \return SSL_SUCCESS On successful setting parsing and setting
  10165. the private key.
  10166. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  10167. will be negative values.
  10168. \param ssl WOLFSSL structure to set argument in.
  10169. \param der buffer holding DER key.
  10170. \param derSz size of der buffer.
  10171. _Example_
  10172. \code
  10173. WOLFSSL* ssl;
  10174. unsigned char* pkey;
  10175. long pkeySz;
  10176. int ret;
  10177. // create ssl object and set up RSA private key
  10178. ret = wolfSSL_use_RSAPrivateKey_ASN1(ssl, pkey, pkeySz);
  10179. // check ret value
  10180. \endcode
  10181. \sa wolfSSL_new
  10182. \sa wolfSSL_free
  10183. \sa wolfSSL_use_PrivateKey
  10184. */
  10185. int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, unsigned char* der,
  10186. long derSz);
  10187. /*!
  10188. \ingroup CertsKeys
  10189. \brief This function duplicates the parameters in dsa to a
  10190. newly created WOLFSSL_DH structure.
  10191. \return WOLFSSL_DH If duplicated returns WOLFSSL_DH structure
  10192. \return NULL upon failure
  10193. \param dsa WOLFSSL_DSA structure to duplicate.
  10194. _Example_
  10195. \code
  10196. WOLFSSL_DH* dh;
  10197. WOLFSSL_DSA* dsa;
  10198. // set up dsa
  10199. dh = wolfSSL_DSA_dup_DH(dsa);
  10200. // check dh is not null
  10201. \endcode
  10202. \sa none
  10203. */
  10204. WOLFSSL_DH *wolfSSL_DSA_dup_DH(const WOLFSSL_DSA *r);
  10205. /*!
  10206. \ingroup Setup
  10207. \brief This is used to get the master key after completing a handshake.
  10208. \return >0 On successfully getting data returns a value greater than 0
  10209. \return 0 If no random data buffer or an error state returns 0
  10210. \return max If outSz passed in is 0 then the maximum buffer
  10211. size needed is returned
  10212. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  10213. \param out buffer to hold data.
  10214. \param outSz size of out buffer passed in. (if 0 function will
  10215. return max buffer size needed)
  10216. _Example_
  10217. \code
  10218. WOLFSSL_SESSION ssl;
  10219. unsigned char* buffer;
  10220. size_t bufferSz;
  10221. size_t ret;
  10222. // complete handshake and get session structure
  10223. bufferSz = wolfSSL_SESSION_get_master_secret(ses, NULL, 0);
  10224. buffer = malloc(bufferSz);
  10225. ret = wolfSSL_SESSION_get_master_secret(ses, buffer, bufferSz);
  10226. // check ret value
  10227. \endcode
  10228. \sa wolfSSL_new
  10229. \sa wolfSSL_free
  10230. */
  10231. int wolfSSL_SESSION_get_master_key(const WOLFSSL_SESSION* ses,
  10232. unsigned char* out, int outSz);
  10233. /*!
  10234. \ingroup Setup
  10235. \brief This is used to get the master secret key length.
  10236. \return size Returns master secret key size.
  10237. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  10238. _Example_
  10239. \code
  10240. WOLFSSL_SESSION ssl;
  10241. unsigned char* buffer;
  10242. size_t bufferSz;
  10243. size_t ret;
  10244. // complete handshake and get session structure
  10245. bufferSz = wolfSSL_SESSION_get_master_secret_length(ses);
  10246. buffer = malloc(bufferSz);
  10247. // check ret value
  10248. \endcode
  10249. \sa wolfSSL_new
  10250. \sa wolfSSL_free
  10251. */
  10252. int wolfSSL_SESSION_get_master_key_length(const WOLFSSL_SESSION* ses);
  10253. /*!
  10254. \ingroup Setup
  10255. \brief This is a setter function for the WOLFSSL_X509_STORE
  10256. structure in ctx.
  10257. \return none No return.
  10258. \param ctx pointer to the WOLFSSL_CTX structure for setting
  10259. cert store pointer.
  10260. \param str pointer to the WOLFSSL_X509_STORE to set in ctx.
  10261. _Example_
  10262. \code
  10263. WOLFSSL_CTX ctx;
  10264. WOLFSSL_X509_STORE* st;
  10265. // setup ctx and st
  10266. st = wolfSSL_CTX_set_cert_store(ctx, st);
  10267. //use st
  10268. \endcode
  10269. \sa wolfSSL_CTX_new
  10270. \sa wolfSSL_CTX_free
  10271. */
  10272. void wolfSSL_CTX_set_cert_store(WOLFSSL_CTX* ctx,
  10273. WOLFSSL_X509_STORE* str);
  10274. /*!
  10275. \ingroup CertsKeys
  10276. \brief This function get the DER buffer from bio and converts it
  10277. to a WOLFSSL_X509 structure.
  10278. \return pointer returns a WOLFSSL_X509 structure pointer on success.
  10279. \return Null returns NULL on failure
  10280. \param bio pointer to the WOLFSSL_BIO structure that has the DER
  10281. certificate buffer.
  10282. \param x509 pointer that get set to new WOLFSSL_X509 structure created.
  10283. _Example_
  10284. \code
  10285. WOLFSSL_BIO* bio;
  10286. WOLFSSL_X509* x509;
  10287. // load DER into bio
  10288. x509 = wolfSSL_d2i_X509_bio(bio, NULL);
  10289. Or
  10290. wolfSSL_d2i_X509_bio(bio, &x509);
  10291. // use x509 returned (check for NULL)
  10292. \endcode
  10293. \sa none
  10294. */
  10295. WOLFSSL_X509* wolfSSL_d2i_X509_bio(WOLFSSL_BIO* bio, WOLFSSL_X509** x509);
  10296. /*!
  10297. \ingroup Setup
  10298. \brief This is a getter function for the WOLFSSL_X509_STORE
  10299. structure in ctx.
  10300. \return WOLFSSL_X509_STORE* On successfully getting the pointer.
  10301. \return NULL Returned if NULL arguments are passed in.
  10302. \param ctx pointer to the WOLFSSL_CTX structure for getting cert
  10303. store pointer.
  10304. _Example_
  10305. \code
  10306. WOLFSSL_CTX ctx;
  10307. WOLFSSL_X509_STORE* st;
  10308. // setup ctx
  10309. st = wolfSSL_CTX_get_cert_store(ctx);
  10310. //use st
  10311. \endcode
  10312. \sa wolfSSL_CTX_new
  10313. \sa wolfSSL_CTX_free
  10314. \sa wolfSSL_CTX_set_cert_store
  10315. */
  10316. WOLFSSL_X509_STORE* wolfSSL_CTX_get_cert_store(WOLFSSL_CTX* ctx);
  10317. /*!
  10318. \ingroup IO
  10319. \brief Gets the number of pending bytes to read. If BIO type is BIO_BIO
  10320. then is the number to read from pair. If BIO contains an SSL object then
  10321. is pending data from SSL object (wolfSSL_pending(ssl)). If is BIO_MEMORY
  10322. type then returns the size of memory buffer.
  10323. \return >=0 number of pending bytes.
  10324. \param bio pointer to the WOLFSSL_BIO structure that has already
  10325. been created.
  10326. _Example_
  10327. \code
  10328. WOLFSSL_BIO* bio;
  10329. int pending;
  10330. bio = wolfSSL_BIO_new();
  10331. pending = wolfSSL_BIO_ctrl_pending(bio);
  10332. \endcode
  10333. \sa wolfSSL_BIO_make_bio_pair
  10334. \sa wolfSSL_BIO_new
  10335. */
  10336. size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *b);
  10337. /*!
  10338. \ingroup Setup
  10339. \brief This is used to get the random data sent by the server
  10340. during the handshake.
  10341. \return >0 On successfully getting data returns a value greater than 0
  10342. \return 0 If no random data buffer or an error state returns 0
  10343. \return max If outSz passed in is 0 then the maximum buffer size
  10344. needed is returned
  10345. \param ssl WOLFSSL structure to get clients random data buffer from.
  10346. \param out buffer to hold random data.
  10347. \param outSz size of out buffer passed in. (if 0 function will return max
  10348. buffer size needed)
  10349. _Example_
  10350. \code
  10351. WOLFSSL ssl;
  10352. unsigned char* buffer;
  10353. size_t bufferSz;
  10354. size_t ret;
  10355. bufferSz = wolfSSL_get_server_random(ssl, NULL, 0);
  10356. buffer = malloc(bufferSz);
  10357. ret = wolfSSL_get_server_random(ssl, buffer, bufferSz);
  10358. // check ret value
  10359. \endcode
  10360. \sa wolfSSL_new
  10361. \sa wolfSSL_free
  10362. */
  10363. size_t wolfSSL_get_server_random(const WOLFSSL *ssl,
  10364. unsigned char *out, size_t outlen);
  10365. /*!
  10366. \ingroup Setup
  10367. \brief This is used to get the random data sent by the client during
  10368. the handshake.
  10369. \return >0 On successfully getting data returns a value greater than 0
  10370. \return 0 If no random data buffer or an error state returns 0
  10371. \return max If outSz passed in is 0 then the maximum buffer size needed
  10372. is returned
  10373. \param ssl WOLFSSL structure to get clients random data buffer from.
  10374. \param out buffer to hold random data.
  10375. \param outSz size of out buffer passed in. (if 0 function will return max
  10376. buffer size needed)
  10377. _Example_
  10378. \code
  10379. WOLFSSL ssl;
  10380. unsigned char* buffer;
  10381. size_t bufferSz;
  10382. size_t ret;
  10383. bufferSz = wolfSSL_get_client_random(ssl, NULL, 0);
  10384. buffer = malloc(bufferSz);
  10385. ret = wolfSSL_get_client_random(ssl, buffer, bufferSz);
  10386. // check ret value
  10387. \endcode
  10388. \sa wolfSSL_new
  10389. \sa wolfSSL_free
  10390. */
  10391. size_t wolfSSL_get_client_random(const WOLFSSL* ssl,
  10392. unsigned char* out, size_t outSz);
  10393. /*!
  10394. \ingroup Setup
  10395. \brief This is a getter function for the password callback set in ctx.
  10396. \return func On success returns the callback function.
  10397. \return NULL If ctx is NULL then NULL is returned.
  10398. \param ctx WOLFSSL_CTX structure to get call back from.
  10399. _Example_
  10400. \code
  10401. WOLFSSL_CTX* ctx;
  10402. wc_pem_password_cb cb;
  10403. // setup ctx
  10404. cb = wolfSSL_CTX_get_default_passwd_cb(ctx);
  10405. //use cb
  10406. \endcode
  10407. \sa wolfSSL_CTX_new
  10408. \sa wolfSSL_CTX_free
  10409. */
  10410. wc_pem_password_cb* wolfSSL_CTX_get_default_passwd_cb(WOLFSSL_CTX*
  10411. ctx);
  10412. /*!
  10413. \ingroup Setup
  10414. \brief This is a getter function for the password callback user
  10415. data set in ctx.
  10416. \return pointer On success returns the user data pointer.
  10417. \return NULL If ctx is NULL then NULL is returned.
  10418. \param ctx WOLFSSL_CTX structure to get user data from.
  10419. _Example_
  10420. \code
  10421. WOLFSSL_CTX* ctx;
  10422. void* data;
  10423. // setup ctx
  10424. data = wolfSSL_CTX_get_default_passwd_cb(ctx);
  10425. //use data
  10426. \endcode
  10427. \sa wolfSSL_CTX_new
  10428. \sa wolfSSL_CTX_free
  10429. */
  10430. void *wolfSSL_CTX_get_default_passwd_cb_userdata(WOLFSSL_CTX *ctx);
  10431. /*!
  10432. \ingroup CertsKeys
  10433. \brief This function behaves the same as wolfSSL_PEM_read_bio_X509.
  10434. AUX signifies containing extra information such as trusted/rejected use
  10435. cases and friendly name for human readability.
  10436. \return WOLFSSL_X509 on successfully parsing the PEM buffer a WOLFSSL_X509
  10437. structure is returned.
  10438. \return Null if failed to parse PEM buffer.
  10439. \param bp WOLFSSL_BIO structure to get PEM buffer from.
  10440. \param x if setting WOLFSSL_X509 by function side effect.
  10441. \param cb password callback.
  10442. \param u NULL terminated user password.
  10443. _Example_
  10444. \code
  10445. WOLFSSL_BIO* bio;
  10446. WOLFSSL_X509* x509;
  10447. // setup bio
  10448. X509 = wolfSSL_PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
  10449. //check x509 is not null and then use it
  10450. \endcode
  10451. \sa wolfSSL_PEM_read_bio_X509
  10452. */
  10453. WOLFSSL_X509 *wolfSSL_PEM_read_bio_X509_AUX
  10454. (WOLFSSL_BIO *bp, WOLFSSL_X509 **x, wc_pem_password_cb *cb, void *u);
  10455. /*!
  10456. \ingroup CertsKeys
  10457. \brief Initializes the WOLFSSL_CTX structure’s dh member with the
  10458. Diffie-Hellman parameters.
  10459. \return SSL_SUCCESS returned if the function executed successfully.
  10460. \return BAD_FUNC_ARG returned if the ctx or dh structures are NULL.
  10461. \return SSL_FATAL_ERROR returned if there was an error setting a
  10462. structure value.
  10463. \return MEMORY_E returned if their was a failure to allocate memory.
  10464. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  10465. wolfSSL_CTX_new().
  10466. \param dh a pointer to a WOLFSSL_DH structure.
  10467. _Example_
  10468. \code
  10469. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10470. WOLFSSL_DH* dh;
  10471. return wolfSSL_CTX_set_tmp_dh(ctx, dh);
  10472. \endcode
  10473. \sa wolfSSL_BN_bn2bin
  10474. */
  10475. long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh);
  10476. /*!
  10477. \ingroup CertsKeys
  10478. \brief This function get the DSA parameters from a PEM buffer in bio.
  10479. \return WOLFSSL_DSA on successfully parsing the PEM buffer a WOLFSSL_DSA
  10480. structure is created and returned.
  10481. \return Null if failed to parse PEM buffer.
  10482. \param bio pointer to the WOLFSSL_BIO structure for getting PEM
  10483. memory pointer.
  10484. \param x pointer to be set to new WOLFSSL_DSA structure.
  10485. \param cb password callback function.
  10486. \param u null terminated password string.
  10487. _Example_
  10488. \code
  10489. WOLFSSL_BIO* bio;
  10490. WOLFSSL_DSA* dsa;
  10491. // setup bio
  10492. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  10493. // check dsa is not NULL and then use dsa
  10494. \endcode
  10495. \sa none
  10496. */
  10497. WOLFSSL_DSA *wolfSSL_PEM_read_bio_DSAparams(WOLFSSL_BIO *bp,
  10498. WOLFSSL_DSA **x, wc_pem_password_cb *cb, void *u);
  10499. /*!
  10500. \ingroup Debug
  10501. \brief This function returns the absolute value of the last error from
  10502. WOLFSSL_ERROR encountered.
  10503. \return error Returns absolute value of last error.
  10504. \param none No parameters.
  10505. _Example_
  10506. \code
  10507. unsigned long err;
  10508. ...
  10509. err = wolfSSL_ERR_peek_last_error();
  10510. // inspect err value
  10511. \endcode
  10512. \sa wolfSSL_ERR_print_errors_fp
  10513. */
  10514. unsigned long wolfSSL_ERR_peek_last_error(void);
  10515. /*!
  10516. \ingroup CertsKeys
  10517. \brief This function gets the peer’s certificate chain.
  10518. \return pointer returns a pointer to the peer’s Certificate stack.
  10519. \return NULL returned if no peer certificate.
  10520. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10521. _Example_
  10522. \code
  10523. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  10524. WOLFSSL* ssl = wolfSSL_new(ctx);
  10525. ...
  10526. wolfSSL_connect(ssl);
  10527. STACK_OF(WOLFSSL_X509)* chain = wolfSSL_get_peer_cert_chain(ssl);
  10528. ifchain){
  10529. // You have a pointer to the peer certificate chain
  10530. }
  10531. \endcode
  10532. \sa wolfSSL_X509_get_issuer_name
  10533. \sa wolfSSL_X509_get_subject_name
  10534. \sa wolfSSL_X509_get_isCA
  10535. */
  10536. WOLF_STACK_OF(WOLFSSL_X509)* wolfSSL_get_peer_cert_chain(const WOLFSSL*);
  10537. /*!
  10538. \ingroup Setup
  10539. \brief This function resets option bits of WOLFSSL_CTX object.
  10540. \return option new option bits
  10541. \param ctx pointer to the SSL context.
  10542. _Example_
  10543. \code
  10544. WOLFSSL_CTX* ctx = 0;
  10545. ...
  10546. wolfSSL_CTX_clear_options(ctx, SSL_OP_NO_TLSv1);
  10547. \endcode
  10548. \sa wolfSSL_CTX_new
  10549. \sa wolfSSL_new
  10550. \sa wolfSSL_free
  10551. */
  10552. long wolfSSL_CTX_clear_options(WOLFSSL_CTX* ctx, long opt);
  10553. /*!
  10554. \ingroup IO
  10555. \brief This function sets the jObjectRef member of the WOLFSSL structure.
  10556. \return SSL_SUCCESS returned if jObjectRef is properly set to objPtr.
  10557. \return SSL_FAILURE returned if the function did not properly execute and
  10558. jObjectRef is not set.
  10559. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10560. \param objPtr a void pointer that will be set to jObjectRef.
  10561. _Example_
  10562. \code
  10563. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10564. WOLFSSL* ssl = WOLFSSL_new();
  10565. void* objPtr = &obj;
  10566. ...
  10567. if(wolfSSL_set_jobject(ssl, objPtr)){
  10568. // The success case
  10569. }
  10570. \endcode
  10571. \sa wolfSSL_get_jobject
  10572. */
  10573. int wolfSSL_set_jobject(WOLFSSL* ssl, void* objPtr);
  10574. /*!
  10575. \ingroup IO
  10576. \brief This function returns the jObjectRef member of the WOLFSSL structure.
  10577. \return value If the WOLFSSL struct is not NULL, the function returns the
  10578. jObjectRef value.
  10579. \return NULL returned if the WOLFSSL struct is NULL.
  10580. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10581. _Example_
  10582. \code
  10583. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10584. WOLFSSL* ssl = wolfSSL(ctx);
  10585. ...
  10586. void* jobject = wolfSSL_get_jobject(ssl);
  10587. if(jobject != NULL){
  10588. // Success case
  10589. }
  10590. \endcode
  10591. \sa wolfSSL_set_jobject
  10592. */
  10593. void* wolfSSL_get_jobject(WOLFSSL* ssl);
  10594. /*!
  10595. \ingroup Setup
  10596. \brief This function sets a callback in the ssl. The callback is to
  10597. observe handshake messages. NULL value of cb resets the callback.
  10598. \return SSL_SUCCESS On success.
  10599. \return SSL_FAILURE If an NULL ssl passed in.
  10600. \param ssl WOLFSSL structure to set callback argument.
  10601. _Example_
  10602. \code
  10603. static cb(int write_p, int version, int content_type,
  10604. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  10605. WOLFSSL* ssl;
  10606. ret = wolfSSL_set_msg_callback(ssl, cb);
  10607. // check ret
  10608. \endcode
  10609. \sa wolfSSL_set_msg_callback_arg
  10610. */
  10611. int wolfSSL_set_msg_callback(WOLFSSL *ssl, SSL_Msg_Cb cb);
  10612. /*!
  10613. \ingroup Setup
  10614. \brief This function sets associated callback context value in the ssl.
  10615. The value is handed over to the callback argument.
  10616. \return none No return.
  10617. \param ssl WOLFSSL structure to set callback argument.
  10618. _Example_
  10619. \code
  10620. static cb(int write_p, int version, int content_type,
  10621. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  10622. WOLFSSL* ssl;
  10623. ret = wolfSSL_set_msg_callback(ssl, cb);
  10624. // check ret
  10625. wolfSSL_set_msg_callback(ssl, arg);
  10626. \endcode
  10627. \sa wolfSSL_set_msg_callback
  10628. */
  10629. int wolfSSL_set_msg_callback_arg(WOLFSSL *ssl, void* arg);
  10630. /*!
  10631. \ingroup CertsKeys
  10632. \brief This function returns the next, if any, altname from the peer certificate.
  10633. \return NULL if there is not a next altname.
  10634. \return cert->altNamesNext->name from the WOLFSSL_X509 structure that is a
  10635. string value from the altName list is returned if it exists.
  10636. \param cert a pointer to the wolfSSL_X509 structure.
  10637. _Example_
  10638. \code
  10639. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  10640. DYNAMIC_TYPE_X509);
  10641. int x509NextAltName = wolfSSL_X509_get_next_altname(x509);
  10642. if(x509NextAltName == NULL){
  10643. //There isn’t another alt name
  10644. }
  10645. \endcode
  10646. \sa wolfSSL_X509_get_issuer_name
  10647. \sa wolfSSL_X509_get_subject_name
  10648. */
  10649. char* wolfSSL_X509_get_next_altname(WOLFSSL_X509*);
  10650. /*!
  10651. \ingroup CertsKeys
  10652. \brief The function checks to see if x509 is NULL and if it’s not, it
  10653. returns the notBefore member of the x509 struct.
  10654. \return pointer to struct with ASN1_TIME to the notBefore
  10655. member of the x509 struct.
  10656. \return NULL the function returns NULL if the x509 structure is NULL.
  10657. \param x509 a pointer to the WOLFSSL_X509 struct.
  10658. _Example_
  10659. \code
  10660. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  10661. DYNAMIC_TYPE_X509) ;
  10662. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notBefore(x509);
  10663. if(notAfter == NULL){
  10664. //The x509 object was NULL
  10665. }
  10666. \endcode
  10667. \sa wolfSSL_X509_get_notAfter
  10668. */
  10669. WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notBefore(WOLFSSL_X509*);
  10670. /*!
  10671. \ingroup IO
  10672. \brief This function is called on the client side and initiates an SSL/TLS
  10673. handshake with a server. When this function is called, the underlying
  10674. communication channel has already been set up.
  10675. wolfSSL_connect() works with both blocking and non-blocking I/O. When the
  10676. underlying I/O is non-blocking, wolfSSL_connect() will return when the
  10677. underlying I/O could not satisfy the needs of wolfSSL_connect to continue
  10678. the handshake. In this case, a call to wolfSSL_get_error() will yield
  10679. either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process
  10680. must then repeat the call to wolfSSL_connect() when the underlying I/O is
  10681. ready and wolfSSL will pick up where it left off. When using a non-blocking
  10682. socket, nothing needs to be done, but select() can be used to check for the
  10683. required condition.
  10684. If the underlying I/O is blocking, wolfSSL_connect() will only return once
  10685. the handshake has been finished or an error occurred.
  10686. wolfSSL takes a different approach to certificate verification than OpenSSL
  10687. does. The default policy for the client is to verify the server, this
  10688. means that if you don't load CAs to verify the server you'll get a connect
  10689. error, unable to verify (-155). It you want to mimic OpenSSL behavior of
  10690. having SSL_connect succeed even if verifying the server fails and reducing
  10691. security you can do this by calling:
  10692. SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling SSL_new();
  10693. Though it's not recommended.
  10694. \return SSL_SUCCESS If successful.
  10695. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10696. more detailed error code, call wolfSSL_get_error().
  10697. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10698. _Example_
  10699. \code
  10700. int ret = 0;
  10701. int err = 0;
  10702. WOLFSSL* ssl;
  10703. char buffer[80];
  10704. ...
  10705. ret = wolfSSL_connect(ssl);
  10706. if (ret != SSL_SUCCESS) {
  10707. err = wolfSSL_get_error(ssl, ret);
  10708. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10709. }
  10710. \endcode
  10711. \sa wolfSSL_get_error
  10712. \sa wolfSSL_accept
  10713. */
  10714. int wolfSSL_connect(WOLFSSL* ssl);
  10715. /*!
  10716. \ingroup Setup
  10717. \brief This function is called on the server side to indicate that a
  10718. HelloRetryRequest message must contain a Cookie and, in case of using
  10719. protocol DTLS v1.3, that the handshake will always include a cookie
  10720. exchange. Please note that when using protocol DTLS v1.3, the cookie
  10721. exchange is enabled by default. The Cookie holds a hash of the current
  10722. transcript so that another server process can handle the ClientHello in
  10723. reply. The secret is used when generating the integrity check on the Cookie
  10724. data.
  10725. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10726. \param [in] secret a pointer to a buffer holding the secret.
  10727. Passing NULL indicates to generate a new random secret.
  10728. \param [in] secretSz Size of the secret in bytes.
  10729. Passing 0 indicates to use the default size: WC_SHA256_DIGEST_SIZE (or WC_SHA_DIGEST_SIZE when SHA-256 not available).
  10730. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10731. \return SIDE_ERROR if called with a client.
  10732. \return WOLFSSL_SUCCESS if successful.
  10733. \return MEMORY_ERROR if allocating dynamic memory for storing secret failed.
  10734. \return Another -ve value on internal error.
  10735. _Example_
  10736. \code
  10737. int ret;
  10738. WOLFSSL* ssl;
  10739. char secret[32];
  10740. ...
  10741. ret = wolfSSL__send_hrr_cookie(ssl, secret, sizeof(secret));
  10742. if (ret != WOLFSSL_SUCCESS) {
  10743. // failed to set use of Cookie and secret
  10744. }
  10745. \endcode
  10746. \sa wolfSSL_new
  10747. \sa wolfSSL_disable_hrr_cookie
  10748. */
  10749. int wolfSSL_send_hrr_cookie(WOLFSSL* ssl,
  10750. const unsigned char* secret, unsigned int secretSz);
  10751. /*!
  10752. \ingroup Setup
  10753. \brief This function is called on the server side to indicate that a
  10754. HelloRetryRequest message must NOT contain a Cookie and that, if using
  10755. protocol DTLS v1.3, a cookie exchange will not be included in the
  10756. handshake. Please note that not doing a cookie exchange when using protocol
  10757. DTLS v1.3 can make the server susceptible to DoS/Amplification attacks.
  10758. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10759. \return WOLFSSL_SUCCESS if successful
  10760. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3
  10761. \return SIDE_ERROR if invoked on client
  10762. \sa wolfSSL_send_hrr_cookie
  10763. */
  10764. int wolfSSL_disable_hrr_cookie(WOLFSSL* ssl);
  10765. /*!
  10766. \ingroup Setup
  10767. \brief This function is called on the server to stop it from sending
  10768. a resumption session ticket once the handshake is complete.
  10769. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10770. with wolfSSL_CTX_new().
  10771. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10772. \return SIDE_ERROR if called with a client.
  10773. \return 0 if successful.
  10774. _Example_
  10775. \code
  10776. int ret;
  10777. WOLFSSL_CTX* ctx;
  10778. ...
  10779. ret = wolfSSL_CTX_no_ticket_TLSv13(ctx);
  10780. if (ret != 0) {
  10781. // failed to set no ticket
  10782. }
  10783. \endcode
  10784. \sa wolfSSL_no_ticket_TLSv13
  10785. */
  10786. int wolfSSL_CTX_no_ticket_TLSv13(WOLFSSL_CTX* ctx);
  10787. /*!
  10788. \ingroup Setup
  10789. \brief This function is called on the server to stop it from sending
  10790. a resumption session ticket once the handshake is complete.
  10791. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10792. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10793. \return SIDE_ERROR if called with a client.
  10794. \return 0 if successful.
  10795. _Example_
  10796. \code
  10797. int ret;
  10798. WOLFSSL* ssl;
  10799. ...
  10800. ret = wolfSSL_no_ticket_TLSv13(ssl);
  10801. if (ret != 0) {
  10802. // failed to set no ticket
  10803. }
  10804. \endcode
  10805. \sa wolfSSL_CTX_no_ticket_TLSv13
  10806. */
  10807. int wolfSSL_no_ticket_TLSv13(WOLFSSL* ssl);
  10808. /*!
  10809. \ingroup Setup
  10810. \brief This function is called on a TLS v1.3 wolfSSL context to disallow
  10811. Diffie-Hellman (DH) style key exchanges when handshakes are using
  10812. pre-shared keys for authentication.
  10813. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10814. with wolfSSL_CTX_new().
  10815. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10816. \return 0 if successful.
  10817. _Example_
  10818. \code
  10819. int ret;
  10820. WOLFSSL_CTX* ctx;
  10821. ...
  10822. ret = wolfSSL_CTX_no_dhe_psk(ctx);
  10823. if (ret != 0) {
  10824. // failed to set no DHE for PSK handshakes
  10825. }
  10826. \endcode
  10827. \sa wolfSSL_no_dhe_psk
  10828. */
  10829. int wolfSSL_CTX_no_dhe_psk(WOLFSSL_CTX* ctx);
  10830. /*!
  10831. \ingroup Setup
  10832. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10833. disallow Diffie-Hellman (DH) style key exchanges when handshakes are using
  10834. pre-shared keys for authentication.
  10835. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10836. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10837. \return 0 if successful.
  10838. _Example_
  10839. \code
  10840. int ret;
  10841. WOLFSSL* ssl;
  10842. ...
  10843. ret = wolfSSL_no_dhe_psk(ssl);
  10844. if (ret != 0) {
  10845. // failed to set no DHE for PSK handshakes
  10846. }
  10847. \endcode
  10848. \sa wolfSSL_CTX_no_dhe_psk
  10849. */
  10850. int wolfSSL_no_dhe_psk(WOLFSSL* ssl);
  10851. /*!
  10852. \ingroup IO
  10853. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10854. force the rollover of keys. A KeyUpdate message is sent to the peer and
  10855. new keys are calculated for encryption. The peer will send back a KeyUpdate
  10856. message and the new decryption keys will then be calculated.
  10857. This function can only be called after a handshake has been completed.
  10858. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10859. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10860. \return WANT_WRITE if the writing is not ready.
  10861. \return WOLFSSL_SUCCESS if successful.
  10862. _Example_
  10863. \code
  10864. int ret;
  10865. WOLFSSL* ssl;
  10866. ...
  10867. ret = wolfSSL_update_keys(ssl);
  10868. if (ret == WANT_WRITE) {
  10869. // need to call again when I/O ready
  10870. }
  10871. else if (ret != WOLFSSL_SUCCESS) {
  10872. // failed to send key update
  10873. }
  10874. \endcode
  10875. \sa wolfSSL_write
  10876. */
  10877. int wolfSSL_update_keys(WOLFSSL* ssl);
  10878. /*!
  10879. \ingroup IO
  10880. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10881. determine whether a rollover of keys is in progress. When
  10882. wolfSSL_update_keys() is called, a KeyUpdate message is sent and the
  10883. encryption key is updated. The decryption key is updated when the response
  10884. is received.
  10885. \param [in] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10886. \param [out] required 0 when no key update response required. 1 when no key update response required.
  10887. \return 0 on successful.
  10888. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10889. _Example_
  10890. \code
  10891. int ret;
  10892. WOLFSSL* ssl;
  10893. int required;
  10894. ...
  10895. ret = wolfSSL_key_update_response(ssl, &required);
  10896. if (ret != 0) {
  10897. // bad parameters
  10898. }
  10899. if (required) {
  10900. // encrypt Key updated, awaiting response to change decrypt key
  10901. }
  10902. \endcode
  10903. \sa wolfSSL_update_keys
  10904. */
  10905. int wolfSSL_key_update_response(WOLFSSL* ssl, int* required);
  10906. /*!
  10907. \ingroup Setup
  10908. \brief This function is called on a TLS v1.3 client wolfSSL context to allow
  10909. a client certificate to be sent post handshake upon request from server.
  10910. This is useful when connecting to a web server that has some pages that
  10911. require client authentication and others that don't.
  10912. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10913. with wolfSSL_CTX_new().
  10914. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10915. \return SIDE_ERROR if called with a server.
  10916. \return 0 if successful.
  10917. _Example_
  10918. \code
  10919. int ret;
  10920. WOLFSSL_CTX* ctx;
  10921. ...
  10922. ret = wolfSSL_allow_post_handshake_auth(ctx);
  10923. if (ret != 0) {
  10924. // failed to allow post handshake authentication
  10925. }
  10926. \endcode
  10927. \sa wolfSSL_allow_post_handshake_auth
  10928. \sa wolfSSL_request_certificate
  10929. */
  10930. int wolfSSL_CTX_allow_post_handshake_auth(WOLFSSL_CTX* ctx);
  10931. /*!
  10932. \ingroup Setup
  10933. \brief This function is called on a TLS v1.3 client wolfSSL to allow
  10934. a client certificate to be sent post handshake upon request from server.
  10935. A Post-Handshake Client Authentication extension is sent in the ClientHello.
  10936. This is useful when connecting to a web server that has some pages that
  10937. require client authentication and others that don't.
  10938. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10939. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10940. \return SIDE_ERROR if called with a server.
  10941. \return 0 if successful.
  10942. _Example_
  10943. \code
  10944. int ret;
  10945. WOLFSSL* ssl;
  10946. ...
  10947. ret = wolfSSL_allow_post_handshake_auth(ssl);
  10948. if (ret != 0) {
  10949. // failed to allow post handshake authentication
  10950. }
  10951. \endcode
  10952. \sa wolfSSL_CTX_allow_post_handshake_auth
  10953. \sa wolfSSL_request_certificate
  10954. */
  10955. int wolfSSL_allow_post_handshake_auth(WOLFSSL* ssl);
  10956. /*!
  10957. \ingroup IO
  10958. \brief This function requests a client certificate from the TLS v1.3 client.
  10959. This is useful when a web server is serving some pages that require client
  10960. authentication and others that don't.
  10961. A maximum of 256 requests can be sent on a connection.
  10962. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10963. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10964. \return WANT_WRITE if the writing is not ready.
  10965. \return SIDE_ERROR if called with a client.
  10966. \return NOT_READY_ERROR if called when the handshake is not finished.
  10967. \return POST_HAND_AUTH_ERROR if posthandshake authentication is disallowed.
  10968. \return MEMORY_E if dynamic memory allocation fails.
  10969. \return WOLFSSL_SUCCESS if successful.
  10970. _Example_
  10971. \code
  10972. int ret;
  10973. WOLFSSL* ssl;
  10974. ...
  10975. ret = wolfSSL_request_certificate(ssl);
  10976. if (ret == WANT_WRITE) {
  10977. // need to call again when I/O ready
  10978. }
  10979. else if (ret != WOLFSSL_SUCCESS) {
  10980. // failed to request a client certificate
  10981. }
  10982. \endcode
  10983. \sa wolfSSL_allow_post_handshake_auth
  10984. \sa wolfSSL_write
  10985. */
  10986. int wolfSSL_request_certificate(WOLFSSL* ssl);
  10987. /*!
  10988. \ingroup Setup
  10989. \brief This function sets the list of elliptic curve groups to allow on
  10990. a wolfSSL context in order of preference.
  10991. The list is a null-terminated text string, and a colon-delimited list.
  10992. Call this function to set the key exchange elliptic curve parameters to
  10993. use with the TLS v1.3 connections.
  10994. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10995. with wolfSSL_CTX_new().
  10996. \param [in] list a string that is a colon-delimited list of elliptic curve
  10997. groups.
  10998. \return WOLFSSL_FAILURE if pointer parameters are NULL, there are more than
  10999. WOLFSSL_MAX_GROUP_COUNT groups, a group name is not recognized or not
  11000. using TLS v1.3.
  11001. \return WOLFSSL_SUCCESS if successful.
  11002. _Example_
  11003. \code
  11004. int ret;
  11005. WOLFSSL_CTX* ctx;
  11006. const char* list = "P-384:P-256";
  11007. ...
  11008. ret = wolfSSL_CTX_set1_groups_list(ctx, list);
  11009. if (ret != WOLFSSL_SUCCESS) {
  11010. // failed to set group list
  11011. }
  11012. \endcode
  11013. \sa wolfSSL_set1_groups_list
  11014. \sa wolfSSL_CTX_set_groups
  11015. \sa wolfSSL_set_groups
  11016. \sa wolfSSL_UseKeyShare
  11017. \sa wolfSSL_preferred_group
  11018. */
  11019. int wolfSSL_CTX_set1_groups_list(WOLFSSL_CTX *ctx, char *list);
  11020. /*!
  11021. \ingroup Setup
  11022. \brief This function sets the list of elliptic curve groups to allow on
  11023. a wolfSSL in order of preference.
  11024. The list is a null-terminated text string, and a colon-delimited list.
  11025. Call this function to set the key exchange elliptic curve parameters to
  11026. use with the TLS v1.3 connections.
  11027. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11028. \param [in] list a string that is a colon separated list of key exchange
  11029. groups.
  11030. \return WOLFSSL_FAILURE if pointer parameters are NULL, there are more than
  11031. WOLFSSL_MAX_GROUP_COUNT groups, a group name is not recognized or not
  11032. using TLS v1.3.
  11033. \return WOLFSSL_SUCCESS if successful.
  11034. _Example_
  11035. \code
  11036. int ret;
  11037. WOLFSSL* ssl;
  11038. const char* list = "P-384:P-256";
  11039. ...
  11040. ret = wolfSSL_CTX_set1_groups_list(ssl, list);
  11041. if (ret != WOLFSSL_SUCCESS) {
  11042. // failed to set group list
  11043. }
  11044. \endcode
  11045. \sa wolfSSL_CTX_set1_groups_list
  11046. \sa wolfSSL_CTX_set_groups
  11047. \sa wolfSSL_set_groups
  11048. \sa wolfSSL_UseKeyShare
  11049. \sa wolfSSL_preferred_group
  11050. */
  11051. int wolfSSL_set1_groups_list(WOLFSSL *ssl, char *list);
  11052. /*!
  11053. \ingroup TLS
  11054. \brief This function returns the key exchange group the client prefers to
  11055. use in the TLS v1.3 handshake.
  11056. Call this function to after a handshake is complete to determine which
  11057. group the server prefers so that this information can be used in future
  11058. connections to pre-generate a key pair for key exchange.
  11059. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11060. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  11061. \return SIDE_ERROR if called with a server.
  11062. \return NOT_READY_ERROR if called before handshake is complete.
  11063. \return Group identifier if successful.
  11064. _Example_
  11065. \code
  11066. int ret;
  11067. int group;
  11068. WOLFSSL* ssl;
  11069. ...
  11070. ret = wolfSSL_CTX_set1_groups_list(ssl)
  11071. if (ret < 0) {
  11072. // failed to get group
  11073. }
  11074. group = ret;
  11075. \endcode
  11076. \sa wolfSSL_UseKeyShare
  11077. \sa wolfSSL_CTX_set_groups
  11078. \sa wolfSSL_set_groups
  11079. \sa wolfSSL_CTX_set1_groups_list
  11080. \sa wolfSSL_set1_groups_list
  11081. */
  11082. int wolfSSL_preferred_group(WOLFSSL* ssl);
  11083. /*!
  11084. \ingroup Setup
  11085. \brief This function sets the list of elliptic curve groups to allow on
  11086. a wolfSSL context in order of preference.
  11087. The list is an array of group identifiers with the number of identifiers
  11088. specified in count.
  11089. Call this function to set the key exchange elliptic curve parameters to
  11090. use with the TLS v1.3 connections.
  11091. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11092. with wolfSSL_CTX_new().
  11093. \param [in] groups a list of key exchange groups by identifier.
  11094. \param [in] count the number of key exchange groups in groups.
  11095. \return BAD_FUNC_ARG if a pointer parameter is null, the number of groups
  11096. exceeds WOLFSSL_MAX_GROUP_COUNT or not using TLS v1.3.
  11097. \return WOLFSSL_SUCCESS if successful.
  11098. _Example_
  11099. \code
  11100. int ret;
  11101. WOLFSSL_CTX* ctx;
  11102. int* groups = { WOLFSSL_ECC_X25519, WOLFSSL_ECC_SECP256R1 };
  11103. int count = 2;
  11104. ...
  11105. ret = wolfSSL_CTX_set1_groups_list(ctx, groups, count);
  11106. if (ret != WOLFSSL_SUCCESS) {
  11107. // failed to set group list
  11108. }
  11109. \endcode
  11110. \sa wolfSSL_set_groups
  11111. \sa wolfSSL_UseKeyShare
  11112. \sa wolfSSL_CTX_set_groups
  11113. \sa wolfSSL_set_groups
  11114. \sa wolfSSL_CTX_set1_groups_list
  11115. \sa wolfSSL_set1_groups_list
  11116. \sa wolfSSL_preferred_group
  11117. */
  11118. int wolfSSL_CTX_set_groups(WOLFSSL_CTX* ctx, int* groups,
  11119. int count);
  11120. /*!
  11121. \ingroup Setup
  11122. \brief This function sets the list of elliptic curve groups to allow on
  11123. a wolfSSL.
  11124. The list is an array of group identifiers with the number of identifiers
  11125. specified in count.
  11126. Call this function to set the key exchange elliptic curve parameters to
  11127. use with the TLS v1.3 connections.
  11128. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11129. \param [in] groups a list of key exchange groups by identifier.
  11130. \param [in] count the number of key exchange groups in groups.
  11131. \return BAD_FUNC_ARG if a pointer parameter is null, the number of groups
  11132. exceeds WOLFSSL_MAX_GROUP_COUNT, any of the identifiers are unrecognized or
  11133. not using TLS v1.3.
  11134. \return WOLFSSL_SUCCESS if successful.
  11135. _Example_
  11136. \code
  11137. int ret;
  11138. WOLFSSL* ssl;
  11139. int* groups = { WOLFSSL_ECC_X25519, WOLFSSL_ECC_SECP256R1 };
  11140. int count = 2;
  11141. ...
  11142. ret = wolfSSL_set_groups(ssl, groups, count);
  11143. if (ret != WOLFSSL_SUCCESS) {
  11144. // failed to set group list
  11145. }
  11146. \endcode
  11147. \sa wolfSSL_CTX_set_groups
  11148. \sa wolfSSL_UseKeyShare
  11149. \sa wolfSSL_CTX_set_groups
  11150. \sa wolfSSL_set_groups
  11151. \sa wolfSSL_CTX_set1_groups_list
  11152. \sa wolfSSL_set1_groups_list
  11153. \sa wolfSSL_preferred_group
  11154. */
  11155. int wolfSSL_set_groups(WOLFSSL* ssl, int* groups, int count);
  11156. /*!
  11157. \ingroup IO
  11158. \brief This function is called on the client side and initiates a
  11159. TLS v1.3 handshake with a server. When this function is called, the
  11160. underlying communication channel has already been set up.
  11161. wolfSSL_connect() works with both blocking and non-blocking I/O.
  11162. When the underlying I/O is non-blocking, wolfSSL_connect() will return
  11163. when the underlying I/O could not satisfy the needs of wolfSSL_connect
  11164. to continue the handshake. In this case, a call to wolfSSL_get_error()
  11165. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The
  11166. calling process must then repeat the call to wolfSSL_connect() when
  11167. the underlying I/O is ready and wolfSSL will pick up where it left off.
  11168. When using a non-blocking socket, nothing needs to be done, but select()
  11169. can be used to check for the required condition. If the underlying I/O is
  11170. blocking, wolfSSL_connect() will only return once the handshake has been
  11171. finished or an error occurred. wolfSSL takes a different approach to
  11172. certificate verification than OpenSSL does. The default policy for the
  11173. client is to verify the server, this means that if you don't load CAs to
  11174. verify the server you'll get a connect error, unable to verify (-155). It
  11175. you want to mimic OpenSSL behavior of having SSL_connect succeed even if
  11176. verifying the server fails and reducing security you can do this by
  11177. calling: SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling
  11178. SSL_new(); Though it's not recommended.
  11179. \return SSL_SUCCESS upon success.
  11180. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  11181. more detailed error code, call wolfSSL_get_error().
  11182. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11183. _Example_
  11184. \code
  11185. int ret = 0;
  11186. int err = 0;
  11187. WOLFSSL* ssl;
  11188. char buffer[80];
  11189. ...
  11190. ret = wolfSSL_connect_TLSv13(ssl);
  11191. if (ret != SSL_SUCCESS) {
  11192. err = wolfSSL_get_error(ssl, ret);
  11193. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11194. }
  11195. \endcode
  11196. \sa wolfSSL_get_error
  11197. \sa wolfSSL_connect
  11198. \sa wolfSSL_accept_TLSv13
  11199. \sa wolfSSL_accept
  11200. */
  11201. int wolfSSL_connect_TLSv13(WOLFSSL*);
  11202. /*!
  11203. \ingroup IO
  11204. \brief This function is called on the server side and waits for a SSL/TLS
  11205. client to initiate the SSL/TLS handshake. When this function is called,
  11206. the underlying communication channel has already been set up.
  11207. wolfSSL_accept() works with both blocking and non-blocking I/O.
  11208. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  11209. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  11210. to continue the handshake. In this case, a call to wolfSSL_get_error()
  11211. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  11212. The calling process must then repeat the call to wolfSSL_accept when
  11213. data is available to read and wolfSSL will pick up where it left off.
  11214. When using a non-blocking socket, nothing needs to be done, but select()
  11215. can be used to check for the required condition. If the underlying I/O
  11216. is blocking, wolfSSL_accept() will only return once the handshake has
  11217. been finished or an error occurred.
  11218. Call this function when expecting a TLS v1.3 connection though older
  11219. version ClientHello messages are supported.
  11220. \return SSL_SUCCESS upon success.
  11221. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  11222. more detailed error code, call wolfSSL_get_error().
  11223. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11224. _Example_
  11225. \code
  11226. int ret = 0;
  11227. int err = 0;
  11228. WOLFSSL* ssl;
  11229. char buffer[80];
  11230. ...
  11231. ret = wolfSSL_accept_TLSv13(ssl);
  11232. if (ret != SSL_SUCCESS) {
  11233. err = wolfSSL_get_error(ssl, ret);
  11234. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11235. }
  11236. \endcode
  11237. \sa wolfSSL_get_error
  11238. \sa wolfSSL_connect_TLSv13
  11239. \sa wolfSSL_connect
  11240. \sa wolfSSL_accept_TLSv13
  11241. \sa wolfSSL_accept
  11242. */
  11243. wolfSSL_accept_TLSv13(WOLFSSL* ssl);
  11244. /*!
  11245. \ingroup Setup
  11246. \brief This function sets the maximum amount of early data that a
  11247. TLS v1.3 client or server is willing to exchange using the wolfSSL context.
  11248. Call this function to limit the amount of early data to process to mitigate
  11249. replay attacks. Early data is protected by keys derived from those of the
  11250. connection that the session ticket was sent and therefore will be the same
  11251. every time a session ticket is used in resumption.
  11252. The value is included in the session ticket for resumption.
  11253. A server value of zero indicates no early data is to be sent by client using
  11254. session tickets. A client value of zero indicates that the client will
  11255. not send any early data.
  11256. It is recommended that the number of early data bytes be kept as low as
  11257. practically possible in the application.
  11258. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11259. with wolfSSL_CTX_new().
  11260. \param [in] sz the amount of early data to accept in bytes.
  11261. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  11262. \return 0 if successful.
  11263. _Example_
  11264. \code
  11265. int ret;
  11266. WOLFSSL_CTX* ctx;
  11267. ...
  11268. ret = wolfSSL_CTX_set_max_early_data(ctx, 128);
  11269. if (ret != WOLFSSL_SUCCESS) {
  11270. // failed to set group list
  11271. }
  11272. \endcode
  11273. \sa wolfSSL_set_max_early_data
  11274. \sa wolfSSL_write_early_data
  11275. \sa wolfSSL_read_early_data
  11276. */
  11277. int wolfSSL_CTX_set_max_early_data(WOLFSSL_CTX* ctx,
  11278. unsigned int sz);
  11279. /*!
  11280. \ingroup Setup
  11281. \brief This function sets the maximum amount of early data that a
  11282. TLS v1.3 client or server is willing to exchange.
  11283. Call this function to limit the amount of early data to process to mitigate
  11284. replay attacks. Early data is protected by keys derived from those of the
  11285. connection that the session ticket was sent and therefore will be the same
  11286. every time a session ticket is used in resumption.
  11287. The value is included in the session ticket for resumption.
  11288. A server value of zero indicates no early data is to be sent by client using
  11289. session tickets. A client value of zero indicates that the client will
  11290. not send any early data.
  11291. It is recommended that the number of early data bytes be kept as low as
  11292. practically possible in the application.
  11293. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11294. \param [in] sz the amount of early data to accept from client in bytes.
  11295. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  11296. \return 0 if successful.
  11297. _Example_
  11298. \code
  11299. int ret;
  11300. WOLFSSL* ssl;
  11301. ...
  11302. ret = wolfSSL_set_max_early_data(ssl, 128);
  11303. if (ret != WOLFSSL_SUCCESS) {
  11304. // failed to set group list
  11305. }
  11306. \endcode
  11307. \sa wolfSSL_CTX_set_max_early_data
  11308. \sa wolfSSL_write_early_data
  11309. \sa wolfSSL_read_early_data
  11310. */
  11311. int wolfSSL_set_max_early_data(WOLFSSL* ssl, unsigned int sz);
  11312. /*!
  11313. \ingroup IO
  11314. \brief This function writes early data to the server on resumption.
  11315. Call this function instead of wolfSSL_connect() or wolfSSL_connect_TLSv13()
  11316. to connect to the server and send the data in the handshake.
  11317. This function is only used with clients.
  11318. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11319. \param [in] data the buffer holding the early data to write to server.
  11320. \param [in] sz the amount of early data to write in bytes.
  11321. \param [out] outSz the amount of early data written in bytes.
  11322. \return BAD_FUNC_ARG if a pointer parameter is NULL, sz is less than 0 or
  11323. not using TLSv1.3.
  11324. \return SIDE_ERROR if called with a server.
  11325. \return WOLFSSL_FATAL_ERROR if the connection is not made.
  11326. \return WOLFSSL_SUCCESS if successful.
  11327. _Example_
  11328. \code
  11329. int ret = 0;
  11330. int err = 0;
  11331. WOLFSSL* ssl;
  11332. byte earlyData[] = { early data };
  11333. int outSz;
  11334. char buffer[80];
  11335. ...
  11336. ret = wolfSSL_write_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
  11337. if (ret != WOLFSSL_SUCCESS) {
  11338. err = wolfSSL_get_error(ssl, ret);
  11339. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11340. goto err_label;
  11341. }
  11342. if (outSz < sizeof(earlyData)) {
  11343. // not all early data was sent
  11344. }
  11345. ret = wolfSSL_connect_TLSv13(ssl);
  11346. if (ret != SSL_SUCCESS) {
  11347. err = wolfSSL_get_error(ssl, ret);
  11348. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11349. }
  11350. \endcode
  11351. \sa wolfSSL_read_early_data
  11352. \sa wolfSSL_connect
  11353. \sa wolfSSL_connect_TLSv13
  11354. */
  11355. int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data,
  11356. int sz, int* outSz);
  11357. /*!
  11358. \ingroup IO
  11359. \brief This function reads any early data from a client on resumption.
  11360. Call this function instead of wolfSSL_accept() or wolfSSL_accept_TLSv13()
  11361. to accept a client and read any early data in the handshake. The function
  11362. should be invoked until wolfSSL_is_init_finished() returns true. Early data
  11363. may be sent by the client in multiple messages. If there is no early data
  11364. then the handshake will be processed as normal. This function is only used
  11365. with servers.
  11366. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11367. \param [out] data a buffer to hold the early data read from client.
  11368. \param [in] sz size of the buffer in bytes.
  11369. \param [out] outSz number of bytes of early data read.
  11370. \return BAD_FUNC_ARG if a pointer parameter is NULL, sz is less than 0 or
  11371. not using TLSv1.3.
  11372. \return SIDE_ERROR if called with a client.
  11373. \return WOLFSSL_FATAL_ERROR if accepting a connection fails.
  11374. \return Number of early data bytes read (may be zero).
  11375. _Example_
  11376. \code
  11377. int ret = 0;
  11378. int err = 0;
  11379. WOLFSSL* ssl;
  11380. byte earlyData[128];
  11381. int outSz;
  11382. char buffer[80];
  11383. ...
  11384. do {
  11385. ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
  11386. if (ret < 0) {
  11387. err = wolfSSL_get_error(ssl, ret);
  11388. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11389. }
  11390. if (outSz > 0) {
  11391. // early data available
  11392. }
  11393. } while (!wolfSSL_is_init_finished(ssl));
  11394. \endcode
  11395. \sa wolfSSL_write_early_data
  11396. \sa wolfSSL_accept
  11397. \sa wolfSSL_accept_TLSv13
  11398. */
  11399. int wolfSSL_read_early_data(WOLFSSL* ssl, void* data, int sz,
  11400. int* outSz);
  11401. /*!
  11402. \ingroup Setup
  11403. \brief This function sets the Pre-Shared Key (PSK) client side callback
  11404. for TLS v1.3 connections.
  11405. The callback is used to find a PSK identity and return its key and
  11406. the name of the cipher to use for the handshake.
  11407. The function sets the client_psk_tls13_cb member of the
  11408. WOLFSSL_CTX structure.
  11409. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11410. with wolfSSL_CTX_new().
  11411. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 client.
  11412. _Example_
  11413. \code
  11414. WOLFSSL_CTX* ctx;
  11415. ...
  11416. wolfSSL_CTX_set_psk_client_tls13_callback(ctx, my_psk_client_tls13_cb);
  11417. \endcode
  11418. \sa wolfSSL_set_psk_client_tls13_callback
  11419. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11420. \sa wolfSSL_set_psk_server_tls13_callback
  11421. */
  11422. void wolfSSL_CTX_set_psk_client_tls13_callback(WOLFSSL_CTX* ctx,
  11423. wc_psk_client_tls13_callback cb);
  11424. /*!
  11425. \ingroup Setup
  11426. \brief This function sets the Pre-Shared Key (PSK) client side callback
  11427. for TLS v1.3 connections.
  11428. The callback is used to find a PSK identity and return its key and
  11429. the name of the cipher to use for the handshake.
  11430. The function sets the client_psk_tls13_cb member of the options field in
  11431. WOLFSSL structure.
  11432. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11433. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 client.
  11434. _Example_
  11435. \code
  11436. WOLFSSL* ssl;
  11437. ...
  11438. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  11439. \endcode
  11440. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11441. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11442. \sa wolfSSL_set_psk_server_tls13_callback
  11443. */
  11444. void wolfSSL_set_psk_client_tls13_callback(WOLFSSL* ssl,
  11445. wc_psk_client_tls13_callback cb);
  11446. /*!
  11447. \ingroup Setup
  11448. \brief This function sets the Pre-Shared Key (PSK) server side callback
  11449. for TLS v1.3 connections.
  11450. The callback is used to find a PSK identity and return its key and
  11451. the name of the cipher to use for the handshake.
  11452. The function sets the server_psk_tls13_cb member of the
  11453. WOLFSSL_CTX structure.
  11454. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11455. with wolfSSL_CTX_new().
  11456. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 server.
  11457. _Example_
  11458. \code
  11459. WOLFSSL_CTX* ctx;
  11460. ...
  11461. wolfSSL_CTX_set_psk_server_tls13_callback(ctx, my_psk_client_tls13_cb);
  11462. \endcode
  11463. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11464. \sa wolfSSL_set_psk_client_tls13_callback
  11465. \sa wolfSSL_set_psk_server_tls13_callback
  11466. */
  11467. void wolfSSL_CTX_set_psk_server_tls13_callback(WOLFSSL_CTX* ctx,
  11468. wc_psk_server_tls13_callback cb);
  11469. /*!
  11470. \ingroup Setup
  11471. \brief This function sets the Pre-Shared Key (PSK) server side callback
  11472. for TLS v1.3 connections.
  11473. The callback is used to find a PSK identity and return its key and
  11474. the name of the cipher to use for the handshake.
  11475. The function sets the server_psk_tls13_cb member of the options field in
  11476. WOLFSSL structure.
  11477. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11478. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 server.
  11479. _Example_
  11480. \code
  11481. WOLFSSL* ssl;
  11482. ...
  11483. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  11484. \endcode
  11485. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11486. \sa wolfSSL_set_psk_client_tls13_callback
  11487. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11488. */
  11489. void wolfSSL_set_psk_server_tls13_callback(WOLFSSL* ssl,
  11490. wc_psk_server_tls13_callback cb);
  11491. /*!
  11492. \ingroup Setup
  11493. \brief This function creates a key share entry from the group including
  11494. generating a key pair.
  11495. The KeyShare extension contains all the generated public keys for key
  11496. exchange. If this function is called, then only the groups specified will
  11497. be included.
  11498. Call this function when a preferred group has been previously established
  11499. for the server.
  11500. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11501. \param [in] group a key exchange group identifier.
  11502. \return BAD_FUNC_ARG if ssl is NULL.
  11503. \return MEMORY_E when dynamic memory allocation fails.
  11504. \return WOLFSSL_SUCCESS if successful.
  11505. _Example_
  11506. \code
  11507. int ret;
  11508. WOLFSSL* ssl;
  11509. ...
  11510. ret = wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_X25519);
  11511. if (ret != WOLFSSL_SUCCESS) {
  11512. // failed to set key share
  11513. }
  11514. \endcode
  11515. \sa wolfSSL_preferred_group
  11516. \sa wolfSSL_CTX_set1_groups_list
  11517. \sa wolfSSL_set1_groups_list
  11518. \sa wolfSSL_CTX_set_groups
  11519. \sa wolfSSL_set_groups
  11520. \sa wolfSSL_NoKeyShares
  11521. */
  11522. int wolfSSL_UseKeyShare(WOLFSSL* ssl, word16 group);
  11523. /*!
  11524. \ingroup Setup
  11525. \brief This function is called to ensure no key shares are sent in the
  11526. ClientHello. This will force the server to respond with a HelloRetryRequest
  11527. if a key exchange is required in the handshake.
  11528. Call this function when the expected key exchange group is not known and
  11529. to avoid the generation of keys unnecessarily.
  11530. Note that an extra round-trip will be required to complete the handshake
  11531. when a key exchange is required.
  11532. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11533. \return BAD_FUNC_ARG if ssl is NULL.
  11534. \return SIDE_ERROR if called with a server.
  11535. \return WOLFSSL_SUCCESS if successful.
  11536. _Example_
  11537. \code
  11538. int ret;
  11539. WOLFSSL* ssl;
  11540. ...
  11541. ret = wolfSSL_NoKeyShares(ssl);
  11542. if (ret != WOLFSSL_SUCCESS) {
  11543. // failed to set no key shares
  11544. }
  11545. \endcode
  11546. \sa wolfSSL_UseKeyShare
  11547. */
  11548. int wolfSSL_NoKeyShares(WOLFSSL* ssl);
  11549. /*!
  11550. \ingroup Setup
  11551. \brief This function is used to indicate
  11552. that the application is a server and will only support the TLS 1.3
  11553. protocol. This function allocates memory for and initializes a new
  11554. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11555. with wolfSSL_CTX_new().
  11556. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11557. \return If successful, the call will return a pointer to the newly
  11558. created WOLFSSL_METHOD structure.
  11559. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11560. value of the underlying malloc() implementation will be returned
  11561. (typically NULL with errno will be set to ENOMEM).
  11562. _Example_
  11563. \code
  11564. #include <wolfssl/ssl.h>
  11565. WOLFSSL_METHOD* method;
  11566. WOLFSSL_CTX* ctx;
  11567. method = wolfTLSv1_3_server_method_ex(NULL);
  11568. if (method == NULL) {
  11569. // unable to get method
  11570. }
  11571. ctx = wolfSSL_CTX_new(method);
  11572. ...
  11573. \endcode
  11574. \sa wolfSSLv3_server_method
  11575. \sa wolfTLSv1_server_method
  11576. \sa wolfTLSv1_1_server_method
  11577. \sa wolfTLSv1_2_server_method
  11578. \sa wolfTLSv1_3_server_method
  11579. \sa wolfDTLSv1_server_method
  11580. \sa wolfSSLv23_server_method
  11581. \sa wolfSSL_CTX_new
  11582. */
  11583. WOLFSSL_METHOD *wolfTLSv1_3_server_method_ex(void* heap);
  11584. /*!
  11585. \ingroup Setup
  11586. \brief This function is used to indicate
  11587. that the application is a client and will only support the TLS 1.3
  11588. protocol. This function allocates memory for and initializes a new
  11589. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11590. with wolfSSL_CTX_new().
  11591. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11592. \return If successful, the call will return a pointer to the newly
  11593. created WOLFSSL_METHOD structure.
  11594. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11595. value of the underlying malloc() implementation will be returned
  11596. (typically NULL with errno will be set to ENOMEM).
  11597. _Example_
  11598. \code
  11599. #include <wolfssl/ssl.h>
  11600. WOLFSSL_METHOD* method;
  11601. WOLFSSL_CTX* ctx;
  11602. method = wolfTLSv1_3_client_method_ex(NULL);
  11603. if (method == NULL) {
  11604. // unable to get method
  11605. }
  11606. ctx = wolfSSL_CTX_new(method);
  11607. ...
  11608. \endcode
  11609. \sa wolfSSLv3_client_method
  11610. \sa wolfTLSv1_client_method
  11611. \sa wolfTLSv1_1_client_method
  11612. \sa wolfTLSv1_2_client_method
  11613. \sa wolfTLSv1_3_client_method
  11614. \sa wolfDTLSv1_client_method
  11615. \sa wolfSSLv23_client_method
  11616. \sa wolfSSL_CTX_new
  11617. */
  11618. WOLFSSL_METHOD *wolfTLSv1_3_client_method_ex(void* heap);
  11619. /*!
  11620. \ingroup Setup
  11621. \brief This function is used to indicate
  11622. that the application is a server and will only support the TLS 1.3
  11623. protocol. This function allocates memory for and initializes a new
  11624. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11625. with wolfSSL_CTX_new().
  11626. \return If successful, the call will return a pointer to the newly
  11627. created WOLFSSL_METHOD structure.
  11628. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11629. value of the underlying malloc() implementation will be returned
  11630. (typically NULL with errno will be set to ENOMEM).
  11631. _Example_
  11632. \code
  11633. #include <wolfssl/ssl.h>
  11634. WOLFSSL_METHOD* method;
  11635. WOLFSSL_CTX* ctx;
  11636. method = wolfTLSv1_3_server_method();
  11637. if (method == NULL) {
  11638. // unable to get method
  11639. }
  11640. ctx = wolfSSL_CTX_new(method);
  11641. ...
  11642. \endcode
  11643. \sa wolfSSLv3_server_method
  11644. \sa wolfTLSv1_server_method
  11645. \sa wolfTLSv1_1_server_method
  11646. \sa wolfTLSv1_2_server_method
  11647. \sa wolfTLSv1_3_server_method_ex
  11648. \sa wolfDTLSv1_server_method
  11649. \sa wolfSSLv23_server_method
  11650. \sa wolfSSL_CTX_new
  11651. */
  11652. WOLFSSL_METHOD *wolfTLSv1_3_server_method(void);
  11653. /*!
  11654. \ingroup Setup
  11655. \brief This function is used to indicate
  11656. that the application is a client and will only support the TLS 1.3
  11657. protocol. This function allocates memory for and initializes a new
  11658. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11659. with wolfSSL_CTX_new().
  11660. \return If successful, the call will return a pointer to the newly
  11661. created WOLFSSL_METHOD structure.
  11662. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11663. value of the underlying malloc() implementation will be returned
  11664. (typically NULL with errno will be set to ENOMEM).
  11665. _Example_
  11666. \code
  11667. #include <wolfssl/ssl.h>
  11668. WOLFSSL_METHOD* method;
  11669. WOLFSSL_CTX* ctx;
  11670. method = wolfTLSv1_3_client_method();
  11671. if (method == NULL) {
  11672. // unable to get method
  11673. }
  11674. ctx = wolfSSL_CTX_new(method);
  11675. ...
  11676. \endcode
  11677. \sa wolfSSLv3_client_method
  11678. \sa wolfTLSv1_client_method
  11679. \sa wolfTLSv1_1_client_method
  11680. \sa wolfTLSv1_2_client_method
  11681. \sa wolfTLSv1_3_client_method_ex
  11682. \sa wolfDTLSv1_client_method
  11683. \sa wolfSSLv23_client_method
  11684. \sa wolfSSL_CTX_new
  11685. */
  11686. WOLFSSL_METHOD *wolfTLSv1_3_client_method(void);
  11687. /*!
  11688. \ingroup Setup
  11689. \brief This function returns a WOLFSSL_METHOD similar to
  11690. wolfTLSv1_3_client_method except that it is not determined
  11691. which side yet (server/client).
  11692. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11693. \return WOLFSSL_METHOD On successful creations returns a WOLFSSL_METHOD
  11694. pointer
  11695. \return NULL Null if memory allocation error or failure to create method
  11696. _Example_
  11697. \code
  11698. WOLFSSL* ctx;
  11699. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method_ex(NULL));
  11700. // check ret value
  11701. \endcode
  11702. \sa wolfSSL_new
  11703. \sa wolfSSL_free
  11704. */
  11705. WOLFSSL_METHOD *wolfTLSv1_3_method_ex(void* heap);
  11706. /*!
  11707. \ingroup Setup
  11708. \brief This function returns a WOLFSSL_METHOD similar to
  11709. wolfTLSv1_3_client_method except that it is not determined
  11710. which side yet (server/client).
  11711. \return WOLFSSL_METHOD On successful creations returns a WOLFSSL_METHOD
  11712. pointer
  11713. \return NULL Null if memory allocation error or failure to create method
  11714. _Example_
  11715. \code
  11716. WOLFSSL* ctx;
  11717. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method());
  11718. // check ret value
  11719. \endcode
  11720. \sa wolfSSL_new
  11721. \sa wolfSSL_free
  11722. */
  11723. WOLFSSL_METHOD *wolfTLSv1_3_method(void);
  11724. /*!
  11725. \ingroup SSL
  11726. \brief This function sets a fixed / static ephemeral key for testing only
  11727. \return 0 Key loaded successfully
  11728. \param ctx A WOLFSSL_CTX context pointer
  11729. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11730. \param key key file path (if keySz == 0) or actual key buffer (PEM or ASN.1)
  11731. \param keySz key size (should be 0 for "key" arg is file path)
  11732. \param format WOLFSSL_FILETYPE_ASN1 or WOLFSSL_FILETYPE_PEM
  11733. \sa wolfSSL_CTX_get_ephemeral_key
  11734. */
  11735. int wolfSSL_CTX_set_ephemeral_key(WOLFSSL_CTX* ctx, int keyAlgo, const char* key, unsigned int keySz, int format);
  11736. /*!
  11737. \ingroup SSL
  11738. \brief This function sets a fixed / static ephemeral key for testing only
  11739. \return 0 Key loaded successfully
  11740. \param ssl A WOLFSSL object pointer
  11741. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11742. \param key key file path (if keySz == 0) or actual key buffer (PEM or ASN.1)
  11743. \param keySz key size (should be 0 for "key" arg is file path)
  11744. \param format WOLFSSL_FILETYPE_ASN1 or WOLFSSL_FILETYPE_PEM
  11745. \sa wolfSSL_get_ephemeral_key
  11746. */
  11747. int wolfSSL_set_ephemeral_key(WOLFSSL* ssl, int keyAlgo, const char* key, unsigned int keySz, int format);
  11748. /*!
  11749. \ingroup SSL
  11750. \brief This function returns pointer to loaded key as ASN.1/DER
  11751. \return 0 Key returned successfully
  11752. \param ctx A WOLFSSL_CTX context pointer
  11753. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11754. \param key key buffer pointer
  11755. \param keySz key size pointer
  11756. \sa wolfSSL_CTX_set_ephemeral_key
  11757. */
  11758. int wolfSSL_CTX_get_ephemeral_key(WOLFSSL_CTX* ctx, int keyAlgo,
  11759. const unsigned char** key, unsigned int* keySz);
  11760. /*!
  11761. \ingroup SSL
  11762. \brief This function returns pointer to loaded key as ASN.1/DER
  11763. \return 0 Key returned successfully
  11764. \param ssl A WOLFSSL object pointer
  11765. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11766. \param key key buffer pointer
  11767. \param keySz key size pointer
  11768. \sa wolfSSL_set_ephemeral_key
  11769. */
  11770. int wolfSSL_get_ephemeral_key(WOLFSSL* ssl, int keyAlgo,
  11771. const unsigned char** key, unsigned int* keySz);
  11772. /*!
  11773. \ingroup SSL
  11774. \brief Sign a message with the chosen message digest, padding, and RSA key
  11775. \return WOLFSSL_SUCCESS on success and c on error
  11776. \param type Hash NID
  11777. \param m Message to sign. Most likely this will be the digest of
  11778. the message to sign
  11779. \param mLen Length of message to sign
  11780. \param sigRet Output buffer
  11781. \param sigLen On Input: length of sigRet buffer
  11782. On Output: length of data written to sigRet
  11783. \param rsa RSA key used to sign the input
  11784. \param flag 1: Output the signature
  11785. 0: Output the value that the unpadded signature should be
  11786. compared to. Note: for RSA_PKCS1_PSS_PADDING the
  11787. wc_RsaPSS_CheckPadding_ex function should be used to check
  11788. the output of a *Verify* function.
  11789. \param padding Padding to use. Only RSA_PKCS1_PSS_PADDING and
  11790. RSA_PKCS1_PADDING are currently supported for signing.
  11791. */
  11792. int wolfSSL_RSA_sign_generic_padding(int type, const unsigned char* m,
  11793. unsigned int mLen, unsigned char* sigRet,
  11794. unsigned int* sigLen, WOLFSSL_RSA* rsa,
  11795. int flag, int padding);
  11796. /*!
  11797. \brief checks if DTLSv1.3 stack has some messages sent but not yet acknowledged
  11798. by the other peer
  11799. \return 1 if there are pending messages, 0 otherwise
  11800. \param ssl A WOLFSSL object pointer
  11801. */
  11802. int wolfSSL_dtls13_has_pending_msg(WOLFSSL *ssl);
  11803. /*!
  11804. \ingroup SSL
  11805. \brief Get the maximum size of Early Data from a session.
  11806. \param [in] s the WOLFSSL_SESSION instance.
  11807. \return the value of max_early_data that was configured in the WOLFSSL* the session
  11808. was derived from.
  11809. \sa wolfSSL_set_max_early_data
  11810. \sa wolfSSL_write_early_data
  11811. \sa wolfSSL_read_early_data
  11812. */
  11813. unsigned int wolfSSL_SESSION_get_max_early_data(const WOLFSSL_SESSION *s);
  11814. /*!
  11815. \ingroup SSL
  11816. \brief Get a new index for external data. This entry applies also for the
  11817. following API:
  11818. - wolfSSL_CTX_get_ex_new_index
  11819. - wolfSSL_get_ex_new_index
  11820. - wolfSSL_SESSION_get_ex_new_index
  11821. - wolfSSL_X509_get_ex_new_index
  11822. \param [in] All input parameters are ignored. The callback functions are not
  11823. supported with wolfSSL.
  11824. \return The new index value to be used with the external data API for this
  11825. object class.
  11826. */
  11827. int wolfSSL_CRYPTO_get_ex_new_index(int, void*, void*, void*, void*);
  11828. /*!
  11829. \ingroup Setup
  11830. \brief In case this function is called in a client side, set certificate types
  11831. that can be sent to its peer. In case called in a server side,
  11832. set certificate types that can be acceptable from its peer. Put cert types in the
  11833. buffer with prioritised order. To reset the settings to default, pass NULL
  11834. for the buffer or pass zero for len. By default, certificate type is only X509.
  11835. In case both side intend to send or accept "Raw public key" cert,
  11836. WOLFSSL_CERT_TYPE_RPK should be included in the buffer to set.
  11837. \return WOLFSSL_SUCCESS if cert types set successfully
  11838. \return BAD_FUNC_ARG if NULL was passed for ctx, illegal value was specified as
  11839. cert type, buf size exceed MAX_CLIENT_CERT_TYPE_CNT was specified or
  11840. a duplicate value is found in buf.
  11841. \param ctx WOLFSSL_CTX object pointer
  11842. \param buf A buffer where certificate types are stored
  11843. \param len buf size in bytes (same as number of certificate types included)
  11844. _Example_
  11845. \code
  11846. int ret;
  11847. WOLFSSL_CTX* ctx;
  11848. char buf[] = {WOLFSSL_CERT_TYPE_RPK, WOLFSSL_CERT_TYPE_X509};
  11849. int len = sizeof(buf)/sizeof(char);
  11850. ...
  11851. ret = wolfSSL_CTX_set_client_cert_type(ctx, buf, len);
  11852. \endcode
  11853. \sa wolfSSL_set_client_cert_type
  11854. \sa wolfSSL_CTX_set_server_cert_type
  11855. \sa wolfSSL_set_server_cert_type
  11856. \sa wolfSSL_get_negotiated_client_cert_type
  11857. \sa wolfSSL_get_negotiated_server_cert_type
  11858. */
  11859. int wolfSSL_CTX_set_client_cert_type(WOLFSSL_CTX* ctx, const char* buf, int len);
  11860. /*!
  11861. \ingroup Setup
  11862. \brief In case this function is called in a server side, set certificate types
  11863. that can be sent to its peer. In case called in a client side,
  11864. set certificate types that can be acceptable from its peer. Put cert types in the
  11865. buffer with prioritised order. To reset the settings to default, pass NULL
  11866. for the buffer or pass zero for len. By default, certificate type is only X509.
  11867. In case both side intend to send or accept "Raw public key" cert,
  11868. WOLFSSL_CERT_TYPE_RPK should be included in the buffer to set.
  11869. \return WOLFSSL_SUCCESS if cert types set successfully
  11870. \return BAD_FUNC_ARG if NULL was passed for ctx, illegal value was specified as
  11871. cert type, buf size exceed MAX_SERVER_CERT_TYPE_CNT was specified or
  11872. a duplicate value is found in buf.
  11873. \param ctx WOLFSSL_CTX object pointer
  11874. \param buf A buffer where certificate types are stored
  11875. \param len buf size in bytes (same as number of certificate types included)
  11876. _Example_
  11877. \code
  11878. int ret;
  11879. WOLFSSL_CTX* ctx;
  11880. char buf[] = {WOLFSSL_CERT_TYPE_RPK, WOLFSSL_CERT_TYPE_X509};
  11881. int len = sizeof(buf)/sizeof(char);
  11882. ...
  11883. ret = wolfSSL_CTX_set_server_cert_type(ctx, buf, len);
  11884. \endcode
  11885. \sa wolfSSL_set_client_cert_type
  11886. \sa wolfSSL_CTX_set_client_cert_type
  11887. \sa wolfSSL_set_server_cert_type
  11888. \sa wolfSSL_get_negotiated_client_cert_type
  11889. \sa wolfSSL_get_negotiated_server_cert_type
  11890. */
  11891. int wolfSSL_CTX_set_server_cert_type(WOLFSSL_CTX* ctx, const char* buf, int len);
  11892. /*!
  11893. \ingroup Setup
  11894. \brief In case this function is called in a client side, set certificate types
  11895. that can be sent to its peer. In case called in a server side,
  11896. set certificate types that can be acceptable from its peer. Put cert types in the
  11897. buffer with prioritised order. To reset the settings to default, pass NULL
  11898. for the buffer or pass zero for len. By default, certificate type is only X509.
  11899. In case both side intend to send or accept "Raw public key" cert,
  11900. WOLFSSL_CERT_TYPE_RPK should be included in the buffer to set.
  11901. \return WOLFSSL_SUCCESS if cert types set successfully
  11902. \return BAD_FUNC_ARG if NULL was passed for ctx, illegal value was specified as
  11903. cert type, buf size exceed MAX_CLIENT_CERT_TYPE_CNT was specified or
  11904. a duplicate value is found in buf.
  11905. \param ssl WOLFSSL object pointer
  11906. \param buf A buffer where certificate types are stored
  11907. \param len buf size in bytes (same as number of certificate types included)
  11908. _Example_
  11909. \code
  11910. int ret;
  11911. WOLFSSL* ssl;
  11912. char buf[] = {WOLFSSL_CERT_TYPE_RPK, WOLFSSL_CERT_TYPE_X509};
  11913. int len = sizeof(buf)/sizeof(char);
  11914. ...
  11915. ret = wolfSSL_set_client_cert_type(ssl, buf, len);
  11916. \endcode
  11917. \sa wolfSSL_CTX_set_client_cert_type
  11918. \sa wolfSSL_CTX_set_server_cert_type
  11919. \sa wolfSSL_set_server_cert_type
  11920. \sa wolfSSL_get_negotiated_client_cert_type
  11921. \sa wolfSSL_get_negotiated_server_cert_type
  11922. */
  11923. int wolfSSL_set_client_cert_type(WOLFSSL* ssl, const char* buf, int len);
  11924. /*!
  11925. \ingroup Setup
  11926. \brief In case this function is called in a server side, set certificate types
  11927. that can be sent to its peer. In case called in a client side,
  11928. set certificate types that can be acceptable from its peer. Put cert types in the
  11929. buffer with prioritised order. To reset the settings to default, pass NULL
  11930. for the buffer or pass zero for len. By default, certificate type is only X509.
  11931. In case both side intend to send or accept "Raw public key" cert,
  11932. WOLFSSL_CERT_TYPE_RPK should be included in the buffer to set.
  11933. \return WOLFSSL_SUCCESS if cert types set successfully
  11934. \return BAD_FUNC_ARG if NULL was passed for ctx, illegal value was specified as
  11935. cert type, buf size exceed MAX_SERVER_CERT_TYPE_CNT was specified or
  11936. a duplicate value is found in buf.
  11937. \param ctx WOLFSSL_CTX object pointer
  11938. \param buf A buffer where certificate types are stored
  11939. \param len buf size in bytes (same as number of certificate types included)
  11940. _Example_
  11941. \code
  11942. int ret;
  11943. WOLFSSL* ssl;
  11944. char buf[] = {WOLFSSL_CERT_TYPE_RPK, WOLFSSL_CERT_TYPE_X509};
  11945. int len = sizeof(buf)/sizeof(char);
  11946. ...
  11947. ret = wolfSSL_set_server_cert_type(ssl, buf, len);
  11948. \endcode
  11949. \sa wolfSSL_set_client_cert_type
  11950. \sa wolfSSL_CTX_set_server_cert_type
  11951. \sa wolfSSL_set_server_cert_type
  11952. \sa wolfSSL_get_negotiated_client_cert_type
  11953. \sa wolfSSL_get_negotiated_server_cert_type
  11954. */
  11955. int wolfSSL_set_server_cert_type(WOLFSSL* ssl, const char* buf, int len);
  11956. /*!
  11957. \ingroup SSL
  11958. \brief This function returns the result of the client certificate type
  11959. negotiation done in ClientHello and ServerHello. WOLFSSL_SUCCESS is returned as
  11960. a return value if no negotiation occurs and WOLFSSL_CERT_TYPE_UNKNOWN is
  11961. returned as the certificate type.
  11962. \return WOLFSSL_SUCCESS if a negotiated certificate type could be got
  11963. \return BAD_FUNC_ARG if NULL was passed for ctx or tp
  11964. \param ssl WOLFSSL object pointer
  11965. \param tp A buffer where a certificate type is to be returned. One of three
  11966. certificate types will be returned: WOLFSSL_CERT_TYPE_RPK,
  11967. WOLFSSL_CERT_TYPE_X509 or WOLFSSL_CERT_TYPE_UNKNOWN.
  11968. _Example_
  11969. \code
  11970. int ret;
  11971. WOLFSSL* ssl;
  11972. int tp;
  11973. ...
  11974. ret = wolfSSL_get_negotiated_client_cert_type(ssl, &tp);
  11975. \endcode
  11976. \sa wolfSSL_set_client_cert_type
  11977. \sa wolfSSL_CTX_set_client_cert_type
  11978. \sa wolfSSL_set_server_cert_type
  11979. \sa wolfSSL_CTX_set_server_cert_type
  11980. \sa wolfSSL_get_negotiated_server_cert_type
  11981. */
  11982. int wolfSSL_get_negotiated_client_cert_type(WOLFSSL* ssl, int* tp);
  11983. /*!
  11984. \ingroup SSL
  11985. \brief This function returns the result of the server certificate type
  11986. negotiation done in ClientHello and ServerHello. WOLFSSL_SUCCESS is returned as
  11987. a return value if no negotiation occurs and WOLFSSL_CERT_TYPE_UNKNOWN is
  11988. returned as the certificate type.
  11989. \return WOLFSSL_SUCCESS if a negotiated certificate type could be got
  11990. \return BAD_FUNC_ARG if NULL was passed for ctx or tp
  11991. \param ssl WOLFSSL object pointer
  11992. \param tp A buffer where a certificate type is to be returned. One of three
  11993. certificate types will be returned: WOLFSSL_CERT_TYPE_RPK,
  11994. WOLFSSL_CERT_TYPE_X509 or WOLFSSL_CERT_TYPE_UNKNOWN.
  11995. _Example_
  11996. \code
  11997. int ret;
  11998. WOLFSSL* ssl;
  11999. int tp;
  12000.  ...
  12001. ret = wolfSSL_get_negotiated_server_cert_type(ssl, &tp);
  12002. \endcode
  12003. \sa wolfSSL_set_client_cert_type
  12004. \sa wolfSSL_CTX_set_client_cert_type
  12005. \sa wolfSSL_set_server_cert_type
  12006. \sa wolfSSL_CTX_set_server_cert_type
  12007. \sa wolfSSL_get_negotiated_client_cert_type
  12008. */
  12009. int wolfSSL_get_negotiated_server_cert_type(WOLFSSL* ssl, int* tp);
  12010. /*!
  12011. \brief Enable use of ConnectionID extensions for the SSL object. See RFC 9146
  12012. and RFC 9147
  12013. \return WOLFSSL_SUCCESS on success, error code otherwise
  12014. \param ssl A WOLFSSL object pointer
  12015. \sa wolfSSL_dtls_cid_is_enabled
  12016. \sa wolfSSL_dtls_cid_set
  12017. \sa wolfSSL_dtls_cid_get_rx_size
  12018. \sa wolfSSL_dtls_cid_get_rx
  12019. \sa wolfSSL_dtls_cid_get_tx_size
  12020. \sa wolfSSL_dtls_cid_get_tx
  12021. */
  12022. int wolfSSL_dtls_cid_use(WOLFSSL* ssl);
  12023. /*!
  12024. \brief If invoked after the handshake is complete it checks if ConnectionID was
  12025. successfully negotiated for the SSL object. See RFC 9146 and RFC 9147
  12026. \return 1 if ConnectionID was correctly negotiated, 0 otherwise
  12027. \param ssl A WOLFSSL object pointer
  12028. \sa wolfSSL_dtls_cid_use
  12029. \sa wolfSSL_dtls_cid_set
  12030. \sa wolfSSL_dtls_cid_get_rx_size
  12031. \sa wolfSSL_dtls_cid_get_rx
  12032. \sa wolfSSL_dtls_cid_get_tx_size
  12033. \sa wolfSSL_dtls_cid_get_tx
  12034. */
  12035. int wolfSSL_dtls_cid_is_enabled(WOLFSSL* ssl);
  12036. /*!
  12037. \brief Set the ConnectionID used by the other peer to send records in this
  12038. connection. See RFC 9146 and RFC 9147. The ConnectionID must be at maximum
  12039. DTLS_CID_MAX_SIZE, that is an tunable compile time define, and it can't
  12040. never be bigger than 255 bytes.
  12041. \return WOLFSSL_SUCCESS if ConnectionID was correctly set, error code otherwise
  12042. \param ssl A WOLFSSL object pointern
  12043. \param cid the ConnectionID to be used
  12044. \param size of the ConnectionID provided
  12045. \sa wolfSSL_dtls_cid_use
  12046. \sa wolfSSL_dtls_cid_is_enabled
  12047. \sa wolfSSL_dtls_cid_get_rx_size
  12048. \sa wolfSSL_dtls_cid_get_rx
  12049. \sa wolfSSL_dtls_cid_get_tx_size
  12050. \sa wolfSSL_dtls_cid_get_tx
  12051. */
  12052. int wolfSSL_dtls_cid_set(WOLFSSL* ssl, unsigned char* cid,
  12053. unsigned int size);
  12054. /*!
  12055. \brief Get the size of the ConnectionID used by the other peer to send records
  12056. in this connection. See RFC 9146 and RFC 9147. The size is stored in the
  12057. parameter size.
  12058. \return WOLFSSL_SUCCESS if ConnectionID was correctly negotiated, error code
  12059. otherwise
  12060. \param ssl A WOLFSSL object pointern
  12061. \param size a pointer to an unsigned int where the size will be stored
  12062. \sa wolfSSL_dtls_cid_use
  12063. \sa wolfSSL_dtls_cid_is_enabled
  12064. \sa wolfSSL_dtls_cid_set
  12065. \sa wolfSSL_dtls_cid_get_rx
  12066. \sa wolfSSL_dtls_cid_get_tx_size
  12067. \sa wolfSSL_dtls_cid_get_tx
  12068. */
  12069. int wolfSSL_dtls_cid_get_rx_size(WOLFSSL* ssl,
  12070. unsigned int* size);
  12071. /*!
  12072. \brief Copy the ConnectionID used by the other peer to send records in this
  12073. connection into the buffer pointed by the parameter buffer. See RFC 9146 and RFC
  12074. 9147. The available space in the buffer need to be provided in bufferSz.
  12075. \return WOLFSSL_SUCCESS if ConnectionID was correctly copied, error code
  12076. otherwise
  12077. \param ssl A WOLFSSL object pointern
  12078. \param buffer A buffer where the ConnectionID will be copied
  12079. \param bufferSz available space in buffer
  12080. \sa wolfSSL_dtls_cid_use
  12081. \sa wolfSSL_dtls_cid_is_enabled
  12082. \sa wolfSSL_dtls_cid_set
  12083. \sa wolfSSL_dtls_cid_get_rx_size
  12084. \sa wolfSSL_dtls_cid_get_tx_size
  12085. \sa wolfSSL_dtls_cid_get_tx
  12086. */
  12087. int wolfSSL_dtls_cid_get_rx(WOLFSSL* ssl, unsigned char* buffer,
  12088. unsigned int bufferSz);
  12089. /*!
  12090. \brief Get the size of the ConnectionID used to send records in this
  12091. connection. See RFC 9146 and RFC 9147. The size is stored in the parameter size.
  12092. \return WOLFSSL_SUCCESS if ConnectionID size was correctly stored, error
  12093. code otherwise
  12094. \param ssl A WOLFSSL object pointern
  12095. \param size a pointer to an unsigned int where the size will be stored
  12096. \sa wolfSSL_dtls_cid_use
  12097. \sa wolfSSL_dtls_cid_is_enabled
  12098. \sa wolfSSL_dtls_cid_set
  12099. \sa wolfSSL_dtls_cid_get_rx_size
  12100. \sa wolfSSL_dtls_cid_get_rx
  12101. \sa wolfSSL_dtls_cid_get_tx
  12102. */
  12103. int wolfSSL_dtls_cid_get_tx_size(WOLFSSL* ssl, unsigned int* size);
  12104. /*!
  12105. \brief Copy the ConnectionID used when sending records in this connection into
  12106. the buffer pointer by the parameter buffer. See RFC 9146 and RFC 9147. The
  12107. available size need to be provided in bufferSz.
  12108. \return WOLFSSL_SUCCESS if ConnectionID was correctly copied, error code
  12109. otherwise
  12110. \param ssl A WOLFSSL object pointern
  12111. \param buffer A buffer where the ConnectionID will be copied
  12112. \param bufferSz available space in buffer
  12113. \sa wolfSSL_dtls_cid_use
  12114. \sa wolfSSL_dtls_cid_is_enabled
  12115. \sa wolfSSL_dtls_cid_set
  12116. \sa wolfSSL_dtls_cid_get_rx_size
  12117. \sa wolfSSL_dtls_cid_get_rx
  12118. \sa wolfSSL_dtls_cid_get_tx_size
  12119. */
  12120. int wolfSSL_dtls_cid_get_tx(WOLFSSL* ssl, unsigned char* buffer,
  12121. unsigned int bufferSz);
  12122. /*!
  12123. \ingroup TLS
  12124. \brief This function returns the raw list of ciphersuites and signature
  12125. algorithms offered by the client. The lists are only stored and returned
  12126. inside a callback setup with wolfSSL_CTX_set_cert_cb(). This is useful to
  12127. be able to dynamically load certificates and keys based on the available
  12128. ciphersuites and signature algorithms.
  12129. \param [in] ssl The WOLFSSL object to extract the lists from.
  12130. \param [out] optional suites Raw and unfiltered list of client ciphersuites
  12131. \param [out] optional suiteSz Size of suites in bytes
  12132. \param [out] optional hashSigAlgo Raw and unfiltered list of client
  12133. signature algorithms
  12134. \param [out] optional hashSigAlgoSz Size of hashSigAlgo in bytes
  12135. \return WOLFSSL_SUCCESS when suites available
  12136. \return WOLFSSL_FAILURE when suites not available
  12137. _Example_
  12138. \code
  12139. int certCB(WOLFSSL* ssl, void* arg)
  12140. {
  12141. const byte* suites = NULL;
  12142. word16 suiteSz = 0;
  12143. const byte* hashSigAlgo = NULL;
  12144. word16 hashSigAlgoSz = 0;
  12145. wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  12146. &hashSigAlgoSz);
  12147. // Choose certificate to load based on ciphersuites and sigalgs
  12148. }
  12149. WOLFSSL* ctx;
  12150. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method_ex(NULL));
  12151. wolfSSL_CTX_set_cert_cb(ctx, certCB, NULL);
  12152. \endcode
  12153. \sa wolfSSL_get_ciphersuite_info
  12154. \sa wolfSSL_get_sigalg_info
  12155. */
  12156. int wolfSSL_get_client_suites_sigalgs(const WOLFSSL* ssl,
  12157. const byte** suites, word16* suiteSz,
  12158. const byte** hashSigAlgo, word16* hashSigAlgoSz);
  12159. /*!
  12160. \ingroup TLS
  12161. \brief This returns information about the ciphersuite directly from the
  12162. raw ciphersuite bytes.
  12163. \param [in] first First byte of the ciphersuite
  12164. \param [in] second Second byte of the ciphersuite
  12165. \return WOLFSSL_CIPHERSUITE_INFO A struct containing information about the
  12166. type of authentication used in the ciphersuite.
  12167. _Example_
  12168. \code
  12169. WOLFSSL_CIPHERSUITE_INFO info =
  12170. wolfSSL_get_ciphersuite_info(suites[0], suites[1]);
  12171. if (info.rsaAuth)
  12172. haveRSA = 1;
  12173. else if (info.eccAuth)
  12174. haveECC = 1;
  12175. \endcode
  12176. \sa wolfSSL_get_client_suites_sigalgs
  12177. \sa wolfSSL_get_sigalg_info
  12178. */
  12179. WOLFSSL_CIPHERSUITE_INFO wolfSSL_get_ciphersuite_info(byte first,
  12180. byte second);
  12181. /*!
  12182. \ingroup TLS
  12183. \brief This returns information about the hash and signature algorithm
  12184. directly from the raw ciphersuite bytes.
  12185. \param [in] first First byte of the hash and signature algorithm
  12186. \param [in] second Second byte of the hash and signature algorithm
  12187. \param [out] hashAlgo The enum wc_HashType of the MAC algorithm
  12188. \param [out] sigAlgo The enum Key_Sum of the authentication algorithm
  12189. \return 0 when info was correctly set
  12190. \return BAD_FUNC_ARG when either input parameters are NULL or the bytes
  12191. are not a recognized sigalg suite
  12192. _Example_
  12193. \code
  12194. enum wc_HashType hashAlgo;
  12195. enum Key_Sum sigAlgo;
  12196. wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  12197. &hashAlgo, &sigAlgo);
  12198. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  12199. haveRSA = 1;
  12200. else if (sigAlgo == ECDSAk)
  12201. haveECC = 1;
  12202. \endcode
  12203. \sa wolfSSL_get_client_suites_sigalgs
  12204. \sa wolfSSL_get_ciphersuite_info
  12205. */
  12206. int wolfSSL_get_sigalg_info(byte first, byte second,
  12207. int* hashAlgo, int* sigAlgo);