ssl.h 383 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348
  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_API 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_API 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 wolfDTLSv1_server_method
  64. \sa wolfSSLv23_server_method
  65. \sa wolfSSL_CTX_new
  66. */
  67. WOLFSSL_API WOLFSSL_METHOD *wolfSSLv3_server_method(void);
  68. /*!
  69. \ingroup Setup
  70. \brief The wolfSSLv3_client_method() function is used to indicate
  71. that the application is a client and will only support the SSL 3.0
  72. protocol. This function allocates memory for and initializes a
  73. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  74. context with wolfSSL_CTX_new().
  75. \return * If successful, the call will return a pointer to the newly
  76. created WOLFSSL_METHOD structure.
  77. \return FAIL If memory allocation fails when calling XMALLOC, the
  78. failure value of the underlying malloc() implementation will be
  79. returned (typically NULL with errno will be set to ENOMEM).
  80. \param none No parameters.
  81. _Example_
  82. \code
  83. #include <wolfssl/ssl.h>
  84. WOLFSSL_METHOD* method;
  85. WOLFSSL_CTX* ctx;
  86. method = wolfSSLv3_client_method();
  87. if (method == NULL) {
  88. unable to get method
  89. }
  90. ctx = wolfSSL_CTX_new(method);
  91. ...
  92. \endcode
  93. \sa wolfTLSv1_client_method
  94. \sa wolfTLSv1_1_client_method
  95. \sa wolfTLSv1_2_client_method
  96. \sa wolfDTLSv1_client_method
  97. \sa wolfSSLv23_client_method
  98. \sa wolfSSL_CTX_new
  99. */
  100. WOLFSSL_API WOLFSSL_METHOD *wolfSSLv3_client_method(void);
  101. /*!
  102. \ingroup Setup
  103. \brief The wolfTLSv1_server_method() function is used to indicate that the
  104. application is a server and will only support the TLS 1.0 protocol. This
  105. function allocates memory for and initializes a new wolfSSL_METHOD
  106. structure to be used when creating the SSL/TLS context with
  107. wolfSSL_CTX_new().
  108. \return * If successful, the call will return a pointer to the newly
  109. created WOLFSSL_METHOD structure.
  110. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  111. value of the underlying malloc() implementation will be returned
  112. (typically NULL with errno will be set to ENOMEM).
  113. \param none No parameters.
  114. _Example_
  115. \code
  116. #include <wolfssl/ssl.h>
  117. WOLFSSL_METHOD* method;
  118. WOLFSSL_CTX* ctx;
  119. method = wolfTLSv1_server_method();
  120. if (method == NULL) {
  121. unable to get method
  122. }
  123. ctx = wolfSSL_CTX_new(method);
  124. ...
  125. \endcode
  126. \sa wolfSSLv3_server_method
  127. \sa wolfTLSv1_1_server_method
  128. \sa wolfTLSv1_2_server_method
  129. \sa wolfDTLSv1_server_method
  130. \sa wolfSSLv23_server_method
  131. \sa wolfSSL_CTX_new
  132. */
  133. WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_server_method(void);
  134. /*!
  135. \ingroup Setup
  136. \brief The wolfTLSv1_client_method() function is used to indicate
  137. that the application is a client and will only support the TLS 1.0
  138. protocol. This function allocates memory for and initializes a new
  139. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  140. with wolfSSL_CTX_new().
  141. \return * If successful, the call will return a pointer to the newly
  142. created WOLFSSL_METHOD structure.
  143. \return FAIL If memory allocation fails when calling XMALLOC,
  144. the failure value of the underlying malloc() implementation
  145. will be returned (typically NULL with errno will be set to ENOMEM).
  146. \param none No parameters.
  147. _Example_
  148. \code
  149. #include <wolfssl/ssl.h>
  150. WOLFSSL_METHOD* method;
  151. WOLFSSL_CTX* ctx;
  152. method = wolfTLSv1_client_method();
  153. if (method == NULL) {
  154. unable to get method
  155. }
  156. ctx = wolfSSL_CTX_new(method);
  157. ...
  158. \endcode
  159. \sa wolfSSLv3_client_method
  160. \sa wolfTLSv1_1_client_method
  161. \sa wolfTLSv1_2_client_method
  162. \sa wolfDTLSv1_client_method
  163. \sa wolfSSLv23_client_method
  164. \sa wolfSSL_CTX_new
  165. */
  166. WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_client_method(void);
  167. /*!
  168. \ingroup Setup
  169. \brief The wolfTLSv1_1_server_method() function is used to indicate
  170. that the application is a server and will only support the TLS 1.1
  171. protocol. This function allocates memory for and initializes a new
  172. wolfSSL_METHOD structure to be used when creating the SSL/TLS
  173. context with wolfSSL_CTX_new().
  174. \return * If successful, the call will return a pointer to the newly
  175. created WOLFSSL_METHOD structure.
  176. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  177. value of the underlying malloc() implementation will be returned
  178. (typically NULL with errno will be set to ENOMEM).
  179. \param none No parameters.
  180. _Example_
  181. \code
  182. #include <wolfssl/ssl.h>
  183. WOLFSSL_METHOD* method;
  184. WOLFSSL_CTX* ctx;
  185. method = wolfTLSv1_1_server_method();
  186. if (method == NULL) {
  187. // unable to get method
  188. }
  189. ctx = wolfSSL_CTX_new(method);
  190. ...
  191. \endcode
  192. \sa wolfSSLv3_server_method
  193. \sa wolfTLSv1_server_method
  194. \sa wolfTLSv1_2_server_method
  195. \sa wolfDTLSv1_server_method
  196. \sa wolfSSLv23_server_method
  197. \sa wolfSSL_CTX_new
  198. */
  199. WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_1_server_method(void);
  200. /*!
  201. \ingroup Setup
  202. \brief The wolfTLSv1_1_client_method() function is used to indicate
  203. that the application is a client and will only support the TLS 1.0
  204. protocol. This function allocates memory for and initializes a
  205. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  206. context with wolfSSL_CTX_new().
  207. \return * If successful, the call will return a pointer to the
  208. newly created WOLFSSL_METHOD structure.
  209. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  210. value of the underlying malloc() implementation will be returned
  211. (typically NULL with errno will be set to ENOMEM).
  212. \param none No parameters.
  213. _Example_
  214. \code
  215. #include <wolfssl/ssl.h>
  216. WOLFSSL_METHOD* method;
  217. WOLFSSL_CTX* ctx;
  218. method = wolfTLSv1_1_client_method();
  219. if (method == NULL) {
  220. // unable to get method
  221. }
  222. ctx = wolfSSL_CTX_new(method);
  223. ...
  224. \endcode
  225. \sa wolfSSLv3_client_method
  226. \sa wolfTLSv1_client_method
  227. \sa wolfTLSv1_2_client_method
  228. \sa wolfDTLSv1_client_method
  229. \sa wolfSSLv23_client_method
  230. \sa wolfSSL_CTX_new
  231. */
  232. WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_1_client_method(void);
  233. /*!
  234. \ingroup Setup
  235. \brief The wolfTLSv1_2_server_method() function is used to indicate
  236. that the application is a server and will only support the TLS 1.2
  237. protocol. This function allocates memory for and initializes a new
  238. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  239. with wolfSSL_CTX_new().
  240. \return * If successful, the call will return a pointer to the newly
  241. created WOLFSSL_METHOD structure.
  242. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  243. value of the underlying malloc() implementation will be returned
  244. (typically NULL with errno will be set to ENOMEM).
  245. \param none No parameters.
  246. _Example_
  247. \code
  248. #include <wolfssl/ssl.h>
  249. WOLFSSL_METHOD* method;
  250. WOLFSSL_CTX* ctx;
  251. method = wolfTLSv1_2_server_method();
  252. if (method == NULL) {
  253. // unable to get method
  254. }
  255. ctx = wolfSSL_CTX_new(method);
  256. ...
  257. \endcode
  258. \sa wolfSSLv3_server_method
  259. \sa wolfTLSv1_server_method
  260. \sa wolfTLSv1_1_server_method
  261. \sa wolfDTLSv1_server_method
  262. \sa wolfSSLv23_server_method
  263. \sa wolfSSL_CTX_new
  264. */
  265. WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_2_server_method(void);
  266. /*!
  267. \ingroup Setup
  268. \brief The wolfTLSv1_2_client_method() function is used to indicate
  269. that the application is a client and will only support the TLS 1.2
  270. protocol. This function allocates memory for and initializes a new
  271. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  272. with wolfSSL_CTX_new().
  273. \return * If successful, the call will return a pointer to the newly
  274. created WOLFSSL_METHOD structure.
  275. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  276. value of the underlying malloc() implementation will be returned
  277. (typically NULL with errno will be set to ENOMEM).
  278. \param none No parameters.
  279. _Example_
  280. \code
  281. #include <wolfssl/ssl.h>
  282. WOLFSSL_METHOD* method;
  283. WOLFSSL_CTX* ctx;
  284. method = wolfTLSv1_2_client_method();
  285. if (method == NULL) {
  286. // unable to get method
  287. }
  288. ctx = wolfSSL_CTX_new(method);
  289. ...
  290. \endcode
  291. \sa wolfSSLv3_client_method
  292. \sa wolfTLSv1_client_method
  293. \sa wolfTLSv1_1_client_method
  294. \sa wolfDTLSv1_client_method
  295. \sa wolfSSLv23_client_method
  296. \sa wolfSSL_CTX_new
  297. */
  298. WOLFSSL_API WOLFSSL_METHOD *wolfTLSv1_2_client_method(void);
  299. /*!
  300. \ingroup Setup
  301. \brief The wolfDTLSv1_client_method() function is used to indicate that
  302. the application is a client and will only support the DTLS 1.0 protocol.
  303. This function allocates memory for and initializes a new
  304. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  305. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  306. been compiled with DTLS support (--enable-dtls,
  307. or by defining wolfSSL_DTLS).
  308. \return * If successful, the call will return a pointer to the newly
  309. created WOLFSSL_METHOD structure.
  310. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  311. value of the underlying malloc() implementation will be returned
  312. (typically NULL with errno will be set to ENOMEM).
  313. \param none No parameters.
  314. _Example_
  315. \code
  316. WOLFSSL_METHOD* method;
  317. WOLFSSL_CTX* ctx;
  318. method = wolfDTLSv1_client_method();
  319. if (method == NULL) {
  320. // unable to get method
  321. }
  322. ctx = wolfSSL_CTX_new(method);
  323. ...
  324. \endcode
  325. \sa wolfSSLv3_client_method
  326. \sa wolfTLSv1_client_method
  327. \sa wolfTLSv1_1_client_method
  328. \sa wolfTLSv1_2_client_method
  329. \sa wolfSSLv23_client_method
  330. \sa wolfSSL_CTX_new
  331. */
  332. WOLFSSL_API WOLFSSL_METHOD *wolfDTLSv1_client_method(void);
  333. /*!
  334. \ingroup Setup
  335. \brief The wolfDTLSv1_server_method() function is used to indicate
  336. that the application is a server and will only support the DTLS 1.0
  337. protocol. This function allocates memory for and initializes a
  338. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  339. context with wolfSSL_CTX_new(). This function is only available
  340. when wolfSSL has been compiled with DTLS support (--enable-dtls,
  341. or by defining wolfSSL_DTLS).
  342. \return * If successful, the call will return a pointer to the newly
  343. created WOLFSSL_METHOD structure.
  344. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  345. value of the underlying malloc() implementation will be returned
  346. (typically NULL with errno will be set to ENOMEM).
  347. \param none No parameters.
  348. _Example_
  349. \code
  350. WOLFSSL_METHOD* method;
  351. WOLFSSL_CTX* ctx;
  352. method = wolfDTLSv1_server_method();
  353. if (method == NULL) {
  354. // unable to get method
  355. }
  356. ctx = wolfSSL_CTX_new(method);
  357. ...
  358. \endcode
  359. \sa wolfSSLv3_server_method
  360. \sa wolfTLSv1_server_method
  361. \sa wolfTLSv1_1_server_method
  362. \sa wolfTLSv1_2_server_method
  363. \sa wolfSSLv23_server_method
  364. \sa wolfSSL_CTX_new
  365. */
  366. WOLFSSL_API WOLFSSL_METHOD *wolfDTLSv1_server_method(void);
  367. /*!
  368. \brief This function creates and initializes a WOLFSSL_METHOD for the
  369. server side.
  370. \return This function returns a WOLFSSL_METHOD pointer.
  371. \param none No parameters.
  372. _Example_
  373. \code
  374. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  375. WOLFSSL* ssl = WOLFSSL_new(ctx);
  376. \endcode
  377. \sa wolfSSL_CTX_new
  378. */
  379. WOLFSSL_API WOLFSSL_METHOD *wolfDTLSv1_2_server_method(void);
  380. /*!
  381. \ingroup Setup
  382. \brief Since there is some differences between the first release and
  383. newer versions of chacha-poly AEAD construction we have added an option
  384. to communicate with servers/clients using the older version. By default
  385. wolfSSL uses the new version.
  386. \return 0 upon success
  387. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  388. \param value whether or not to use the older version of setting up the
  389. information for poly1305. Passing a flag value of 1 indicates yes use the
  390. old poly AEAD, to switch back to using the new version pass a flag value
  391. of 0.
  392. _Example_
  393. \code
  394. int ret = 0;
  395. WOLFSSL* ssl;
  396. ...
  397. ret = wolfSSL_use_old_poly(ssl, 1);
  398. if (ret != 0) {
  399. // failed to set poly1305 AEAD version
  400. }
  401. \endcode
  402. \sa none
  403. */
  404. WOLFSSL_API int wolfSSL_use_old_poly(WOLFSSL*, int);
  405. /*!
  406. \brief The wolfSSL_dtls_import() function is used to parse in a serialized
  407. session state. This allows for picking up the connection after the
  408. handshake has been completed.
  409. \return Success If successful, the amount of the buffer read will be
  410. returned.
  411. \return Failure All unsuccessful return values will be less than 0.
  412. \return VERSION_ERROR If a version mismatch is found ie DTLS v1 and ctx
  413. was set up for DTLS v1.2 then VERSION_ERROR is returned.
  414. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  415. \param buf serialized session to import.
  416. \param sz size of serialized session buffer.
  417. _Example_
  418. \code
  419. WOLFSSL* ssl;
  420. int ret;
  421. unsigned char buf[MAX];
  422. bufSz = MAX;
  423. ...
  424. //get information sent from wc_dtls_export function and place it in buf
  425. fread(buf, 1, bufSz, input);
  426. ret = wolfSSL_dtls_import(ssl, buf, bufSz);
  427. if (ret < 0) {
  428. // handle error case
  429. }
  430. // no wolfSSL_accept needed since handshake was already done
  431. ...
  432. ret = wolfSSL_write(ssl) and wolfSSL_read(ssl);
  433. ...
  434. \endcode
  435. \sa wolfSSL_new
  436. \sa wolfSSL_CTX_new
  437. \sa wolfSSL_CTX_dtls_set_export
  438. */
  439. WOLFSSL_API int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf,
  440. unsigned int sz);
  441. /*!
  442. \brief The wolfSSL_CTX_dtls_set_export() function is used to set
  443. the callback function for exporting a session. It is allowed to
  444. pass in NULL as the parameter func to clear the export function
  445. previously stored. Used on the server side and is called immediately
  446. after handshake is completed.
  447. \return SSL_SUCCESS upon success.
  448. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  449. \param ctx a pointer to a WOLFSSL_CTX structure, created
  450. with wolfSSL_CTX_new().
  451. \param func wc_dtls_export function to use when exporting a session.
  452. _Example_
  453. \code
  454. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  455. // body of send session (wc_dtls_export) that passses
  456. // buf (serialized session) to destination
  457. WOLFSSL_CTX* ctx;
  458. int ret;
  459. ...
  460. ret = wolfSSL_CTX_dtls_set_export(ctx, send_session);
  461. if (ret != SSL_SUCCESS) {
  462. // handle error case
  463. }
  464. ...
  465. ret = wolfSSL_accept(ssl);
  466. ...
  467. \endcode
  468. \sa wolfSSL_new
  469. \sa wolfSSL_CTX_new
  470. \sa wolfSSL_dtls_set_export
  471. \sa Static buffer use
  472. */
  473. WOLFSSL_API int wolfSSL_CTX_dtls_set_export(WOLFSSL_CTX* ctx,
  474. wc_dtls_export func);
  475. /*!
  476. \brief The wolfSSL_dtls_set_export() function is used to set the callback
  477. function for exporting a session. It is allowed to pass in NULL as the
  478. parameter func to clear the export function previously stored. Used on
  479. the server side and is called immediately after handshake is completed.
  480. \return SSL_SUCCESS upon success.
  481. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  482. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  483. \param func wc_dtls_export function to use when exporting a session.
  484. _Example_
  485. \code
  486. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  487. // body of send session (wc_dtls_export) that passses
  488. // buf (serialized session) to destination
  489. WOLFSSL* ssl;
  490. int ret;
  491. ...
  492. ret = wolfSSL_dtls_set_export(ssl, send_session);
  493. if (ret != SSL_SUCCESS) {
  494. // handle error case
  495. }
  496. ...
  497. ret = wolfSSL_accept(ssl);
  498. ...
  499. \endcode
  500. \sa wolfSSL_new
  501. \sa wolfSSL_CTX_new
  502. \sa wolfSSL_CTX_dtls_set_export
  503. */
  504. WOLFSSL_API int wolfSSL_dtls_set_export(WOLFSSL* ssl, wc_dtls_export func);
  505. /*!
  506. \brief The wolfSSL_dtls_export() function is used to serialize a
  507. WOLFSSL session into the provided buffer. Allows for less memory
  508. overhead than using a function callback for sending a session and
  509. choice over when the session is serialized. If buffer is NULL when
  510. passed to function then sz will be set to the size of buffer needed
  511. for serializing the WOLFSSL session.
  512. \return Success If successful, the amount of the buffer used will
  513. be returned.
  514. \return Failure All unsuccessful return values will be less than 0.
  515. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  516. \param buf buffer to hold serialized session.
  517. \param sz size of buffer.
  518. _Example_
  519. \code
  520. WOLFSSL* ssl;
  521. int ret;
  522. unsigned char buf[MAX];
  523. bufSz = MAX;
  524. ...
  525. ret = wolfSSL_dtls_export(ssl, buf, bufSz);
  526. if (ret < 0) {
  527. // handle error case
  528. }
  529. ...
  530. \endcode
  531. \sa wolfSSL_new
  532. \sa wolfSSL_CTX_new
  533. \sa wolfSSL_CTX_dtls_set_export
  534. \sa wolfSSL_dtls_import
  535. */
  536. WOLFSSL_API int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf,
  537. unsigned int* sz);
  538. /*!
  539. \brief This function is used to set aside static memory for a CTX. Memory
  540. set aside is then used for the CTX’s lifetime and for any SSL objects
  541. created from the CTX. By passing in a NULL ctx pointer and a
  542. wolfSSL_method_func function the creation of the CTX itself will also
  543. use static memory. wolfSSL_method_func has the function signature of
  544. WOLFSSL_METHOD* (*wolfSSL_method_func)(void* heap);. Passing in 0 for max
  545. makes it behave as if not set and no max concurrent use restrictions is
  546. in place. The flag value passed in determines how the memory is used and
  547. behavior while operating. Available flags are the following: 0 - default
  548. general memory, WOLFMEM_IO_POOL - used for input/output buffer when
  549. sending receiving messages and overrides general memory, so all memory
  550. in buffer passed in is used for IO, WOLFMEM_IO_FIXED - same as
  551. WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for
  552. their lifetime, WOLFMEM_TRACK_STATS - each SSL keeps track of memory
  553. stats while running.
  554. \return SSL_SUCCESS upon success.
  555. \return SSL_FAILURE upon failure.
  556. \param ctx address of pointer to a WOLFSSL_CTX structure.
  557. \param method function to create protocol. (should be NULL if ctx is not
  558. also NULL)
  559. \param buf memory to use for all operations.
  560. \param sz size of memory buffer being passed in.
  561. \param flag type of memory.
  562. \param max max concurrent operations.
  563. _Example_
  564. \code
  565. WOLFSSL_CTX* ctx;
  566. WOLFSSL* ssl;
  567. int ret;
  568. unsigned char memory[MAX];
  569. int memorySz = MAX;
  570. unsigned char IO[MAX];
  571. int IOSz = MAX;
  572. int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
  573. ...
  574. // create ctx also using static memory, start with general memory to use
  575. ctx = NULL:
  576. ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex,
  577. memory, memorySz, 0, MAX_CONCURRENT_HANDSHAKES);
  578. if (ret != SSL_SUCCESS) {
  579. // handle error case
  580. }
  581. // load in memory for use with IO
  582. ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag,
  583. MAX_CONCURRENT_IO);
  584. if (ret != SSL_SUCCESS) {
  585. // handle error case
  586. }
  587. ...
  588. \endcode
  589. \sa wolfSSL_CTX_new
  590. \sa wolfSSL_CTX_is_static_memory
  591. \sa wolfSSL_is_static_memory
  592. */
  593. WOLFSSL_API int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx,
  594. wolfSSL_method_func method,
  595. unsigned char* buf, unsigned int sz,
  596. int flag, int max);
  597. /*!
  598. \brief This function does not change any of the connections behavior
  599. and is used only for gathering information about the static memory usage.
  600. \return 1 is returned if using static memory for the CTX is true.
  601. \return 0 is returned if not using static memory.
  602. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  603. wolfSSL_CTX_new().
  604. \param mem_stats structure to hold information about static memory usage.
  605. _Example_
  606. \code
  607. WOLFSSL_CTX* ctx;
  608. int ret;
  609. WOLFSSL_MEM_STATS mem_stats;
  610. ...
  611. //get information about static memory with CTX
  612. ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
  613. if (ret == 1) {
  614. // handle case of is using static memory
  615. // print out or inspect elements of mem_stats
  616. }
  617. if (ret == 0) {
  618. //handle case of ctx not using static memory
  619. }
  620. \endcode
  621. \sa wolfSSL_CTX_new
  622. \sa wolfSSL_CTX_load_static_memory
  623. \sa wolfSSL_is_static_memory
  624. */
  625. WOLFSSL_API int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX* ctx,
  626. WOLFSSL_MEM_STATS* mem_stats);
  627. /*!
  628. \brief wolfSSL_is_static_memory is used to gather information about
  629. a SSL’s static memory usage. The return value indicates if static
  630. memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out
  631. if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent
  632. CTX when loading in static memory.
  633. \return 1 is returned if using static memory for the CTX is true.
  634. \return 0 is returned if not using static memory.
  635. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  636. \param mem_stats structure to contain static memory usage.
  637. _Example_
  638. \code
  639. WOLFSSL* ssl;
  640. int ret;
  641. WOLFSSL_MEM_CONN_STATS mem_stats;
  642. ...
  643. ret = wolfSSL_is_static_memory(ssl, mem_stats);
  644. if (ret == 1) {
  645. // handle case when is static memory
  646. // investigate elements in mem_stats if WOLFMEM_TRACK_STATS flag
  647. }
  648. ...
  649. \endcode
  650. \sa wolfSSL_new
  651. \sa wolfSSL_CTX_is_static_memory
  652. */
  653. WOLFSSL_API int wolfSSL_is_static_memory(WOLFSSL* ssl,
  654. WOLFSSL_MEM_CONN_STATS* mem_stats);
  655. /*!
  656. \ingroup CertsKeys
  657. \brief This function loads a certificate file into the SSL context
  658. (WOLFSSL_CTX). The file is provided by the file argument. The
  659. format argument specifies the format type of the file, either
  660. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please see the examples
  661. for proper usage.
  662. \return SSL_SUCCESS upon success.
  663. \return SSL_FAILURE If the function call fails, possible causes might
  664. include the file is in the wrong format, or the wrong format has been
  665. given using the “format” argument, file doesn’t exist, can’t be read,
  666. or is corrupted, an out of memory condition occurs, Base16 decoding
  667. fails on the file.
  668. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  669. wolfSSL_CTX_new()
  670. \param file a pointer to the name of the file containing the certificate
  671. to be loaded into the wolfSSL SSL context.
  672. \param format - format of the certificates pointed to by file. Possible
  673. options are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  674. _Example_
  675. \code
  676. int ret = 0;
  677. WOLFSSL_CTX* ctx;
  678. ...
  679. ret = wolfSSL_CTX_use_certificate_file(ctx, “./client-cert.pem”,
  680. SSL_FILETYPE_PEM);
  681. if (ret != SSL_SUCCESS) {
  682. // error loading cert file
  683. }
  684. ...
  685. \endcode
  686. \sa wolfSSL_CTX_use_certificate_buffer
  687. \sa wolfSSL_use_certificate_file
  688. \sa wolfSSL_use_certificate_buffer
  689. */
  690. WOLFSSL_API int wolfSSL_CTX_use_certificate_file(WOLFSSL_CTX*, const char*, int);
  691. /*!
  692. \ingroup CertsKeys
  693. \brief This function loads a private key file into the SSL context
  694. (WOLFSSL_CTX). The file is provided by the file argument. The format
  695. argument specifies the format type of the file - SSL_FILETYPE_ASN1or
  696. SSL_FILETYPE_PEM. Please see the examples for proper usage.
  697. \return SSL_SUCCESS upon success.
  698. \return SSL_FAILURE The file is in the wrong format, or the wrong format
  699. has been given using the “format” argument. The file doesn’t exist, can’t
  700. be read, or is corrupted. An out of memory condition occurs. Base16
  701. decoding fails on the file. The key file is encrypted but no password
  702. is provided.
  703. \param none No parameters.
  704. _Example_
  705. \code
  706. int ret = 0;
  707. WOLFSSL_CTX* ctx;
  708. ...
  709. ret = wolfSSL_CTX_use_PrivateKey_file(ctx, “./server-key.pem”,
  710. SSL_FILETYPE_PEM);
  711. if (ret != SSL_SUCCESS) {
  712. // error loading key file
  713. }
  714. ...
  715. \endcode
  716. \sa wolfSSL_CTX_use_PrivateKey_buffer
  717. \sa wolfSSL_use_PrivateKey_file
  718. \sa wolfSSL_use_PrivateKey_buffer
  719. */
  720. WOLFSSL_API int wolfSSL_CTX_use_PrivateKey_file(WOLFSSL_CTX*, const char*, int);
  721. /*!
  722. \ingroup CertsKeys
  723. \brief This function loads PEM-formatted CA certificate files into the SSL
  724. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  725. certificates and used to verify certs received from peers during the SSL
  726. handshake. The root certificate file, provided by the file argument, may
  727. be a single certificate or a file containing multiple certificates.
  728. If multiple CA certs are included in the same file, wolfSSL will load them
  729. in the same order they are presented in the file. The path argument is
  730. a pointer to the name of a directory that contains certificates of
  731. trusted root CAs. If the value of file is not NULL, path may be specified
  732. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  733. defined when building the library, wolfSSL will load all CA certificates
  734. located in the given directory. This function will attempt to load all
  735. files in the directory. This function expects PEM formatted CERT_TYPE
  736. file with header “-----BEGIN CERTIFICATE-----”.
  737. \return SSL_SUCCESS up success.
  738. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  739. path are NULL.
  740. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  741. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  742. read, or is corrupted.
  743. \return MEMORY_E will be returned if an out of memory condition occurs.
  744. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  745. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  746. before date.
  747. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  748. after date.
  749. \return BUFFER_E will be returned if a chain buffer is bigger than the
  750. receiving buffer.
  751. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  752. to open path.
  753. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  754. \param file pointer to name of the file containing PEM-formatted CA
  755. certificates.
  756. \param path pointer to the name of a directory to load PEM-formatted
  757. certificates from.
  758. _Example_
  759. \code
  760. int ret = 0;
  761. WOLFSSL_CTX* ctx;
  762. ...
  763. ret = wolfSSL_CTX_load_verify_locations(ctx, “./ca-cert.pem”, NULL);
  764. if (ret != WOLFSSL_SUCCESS) {
  765. // error loading CA certs
  766. }
  767. ...
  768. \endcode
  769. \sa wolfSSL_CTX_load_verify_locations_ex
  770. \sa wolfSSL_CTX_load_verify_buffer
  771. \sa wolfSSL_CTX_use_certificate_file
  772. \sa wolfSSL_CTX_use_PrivateKey_file
  773. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  774. \sa wolfSSL_CTX_use_certificate_chain_file
  775. \sa wolfSSL_use_certificate_file
  776. \sa wolfSSL_use_PrivateKey_file
  777. \sa wolfSSL_use_certificate_chain_file
  778. */
  779. WOLFSSL_API int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX*, const char*,
  780. const char*);
  781. /*!
  782. \ingroup CertsKeys
  783. \brief This function loads PEM-formatted CA certificate files into the SSL
  784. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  785. certificates and used to verify certs received from peers during the SSL
  786. handshake. The root certificate file, provided by the file argument, may
  787. be a single certificate or a file containing multiple certificates.
  788. If multiple CA certs are included in the same file, wolfSSL will load them
  789. in the same order they are presented in the file. The path argument is
  790. a pointer to the name of a directory that contains certificates of
  791. trusted root CAs. If the value of file is not NULL, path may be specified
  792. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  793. defined when building the library, wolfSSL will load all CA certificates
  794. located in the given directory. This function will attempt to load all
  795. files in the directory based on flags specified. This function expects PEM
  796. formatted CERT_TYPE files with header “-----BEGIN CERTIFICATE-----”.
  797. \return SSL_SUCCESS up success.
  798. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  799. path are NULL.
  800. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  801. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  802. read, or is corrupted.
  803. \return MEMORY_E will be returned if an out of memory condition occurs.
  804. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  805. \return BUFFER_E will be returned if a chain buffer is bigger than the
  806. receiving buffer.
  807. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  808. to open path.
  809. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  810. \param file pointer to name of the file containing PEM-formatted CA
  811. certificates.
  812. \param path pointer to the name of a directory to load PEM-formatted
  813. certificates from.
  814. \param flags possible mask values are: WOLFSSL_LOAD_FLAG_IGNORE_ERR,
  815. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY and WOLFSSL_LOAD_FLAG_PEM_CA_ONLY
  816. _Example_
  817. \code
  818. int ret = 0;
  819. WOLFSSL_CTX* ctx;
  820. ...
  821. ret = wolfSSL_CTX_load_verify_locations_ex(ctx, NUULL, “./certs/external",
  822. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY);
  823. if (ret != WOLFSSL_SUCCESS) {
  824. // error loading CA certs
  825. }
  826. ...
  827. \endcode
  828. \sa wolfSSL_CTX_load_verify_locations
  829. \sa wolfSSL_CTX_load_verify_buffer
  830. \sa wolfSSL_CTX_use_certificate_file
  831. \sa wolfSSL_CTX_use_PrivateKey_file
  832. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  833. \sa wolfSSL_CTX_use_certificate_chain_file
  834. \sa wolfSSL_use_certificate_file
  835. \sa wolfSSL_use_PrivateKey_file
  836. \sa wolfSSL_use_certificate_chain_file
  837. */
  838. WOLFSSL_API int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX*, const char*,
  839. const char*, unsigned int flags);
  840. /*!
  841. \ingroup Setup
  842. \brief This function loads a certificate to use for verifying a peer
  843. when performing a TLS/SSL handshake. The peer certificate sent during the
  844. handshake is compared by using the SKID when available and the signature.
  845. If these two things do not match then any loaded CAs are used. Feature is
  846. enabled by defining the macro WOLFSSL_TRUST_PEER_CERT. Please see the
  847. examples for proper usage.
  848. \return SSL_SUCCES upon success.
  849. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  850. type are invalid.
  851. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  852. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  853. read, or is corrupted.
  854. \return MEMORY_E will be returned if an out of memory condition occurs.
  855. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  856. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  857. \param file pointer to name of the file containing certificates
  858. \param type type of certificate being loaded ie SSL_FILETYPE_ASN1
  859. or SSL_FILETYPE_PEM.
  860. _Example_
  861. \code
  862. int ret = 0;
  863. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  864. ...
  865. ret = wolfSSL_CTX_trust_peer_cert(ctx, “./peer-cert.pem”,
  866. SSL_FILETYPE_PEM);
  867. if (ret != SSL_SUCCESS) {
  868. // error loading trusted peer cert
  869. }
  870. ...
  871. \endcode
  872. \sa wolfSSL_CTX_load_verify_buffer
  873. \sa wolfSSL_CTX_use_certificate_file
  874. \sa wolfSSL_CTX_use_PrivateKey_file
  875. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  876. \sa wolfSSL_CTX_use_certificate_chain_file
  877. \sa wolfSSL_CTX_trust_peer_buffer
  878. \sa wolfSSL_CTX_Unload_trust_peers
  879. \sa wolfSSL_use_certificate_file
  880. \sa wolfSSL_use_PrivateKey_file
  881. \sa wolfSSL_use_certificate_chain_file
  882. */
  883. WOLFSSL_API int wolfSSL_CTX_trust_peer_cert(WOLFSSL_CTX*, const char*, int);
  884. /*!
  885. \ingroup CertsKeys
  886. \brief This function loads a chain of certificates into the SSL
  887. context (WOLFSSL_CTX). The file containing the certificate chain
  888. is provided by the file argument, and must contain PEM-formatted
  889. certificates. This function will process up to MAX_CHAIN_DEPTH
  890. (default = 9, defined in internal.h) certificates, plus the subject cert.
  891. \return SSL_SUCCESS upon success
  892. \return SSL_FAILURE If the function call fails, possible causes might
  893. include the file is in the wrong format, or the wrong format has been
  894. given using the “format” argument, file doesn’t exist, can’t be read,
  895. or is corrupted, an out of memory condition occurs.
  896. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  897. wolfSSL_CTX_new()
  898. \param file a pointer to the name of the file containing the chain of
  899. certificates to be loaded into the wolfSSL SSL context. Certificates
  900. must be in PEM format.
  901. _Example_
  902. \code
  903. int ret = 0;
  904. WOLFSSL_CTX* ctx;
  905. ...
  906. ret = wolfSSL_CTX_use_certificate_chain_file(ctx, “./cert-chain.pem”);
  907. if (ret != SSL_SUCCESS) {
  908. // error loading cert file
  909. }
  910. ...
  911. \endcode
  912. \sa wolfSSL_CTX_use_certificate_file
  913. \sa wolfSSL_CTX_use_certificate_buffer
  914. \sa wolfSSL_use_certificate_file
  915. \sa wolfSSL_use_certificate_buffer
  916. */
  917. WOLFSSL_API int wolfSSL_CTX_use_certificate_chain_file(WOLFSSL_CTX *,
  918. const char *file);
  919. /*!
  920. \ingroup openSSL
  921. \brief This function loads the private RSA key used in the SSL connection
  922. into the SSL context (WOLFSSL_CTX). This function is only available when
  923. wolfSSL has been compiled with the OpenSSL compatibility layer enabled
  924. (--enable-opensslExtra, #define OPENSSL_EXTRA), and is identical to the
  925. more-typically used wolfSSL_CTX_use_PrivateKey_file() function. The file
  926. argument contains a pointer to the RSA private key file, in the format
  927. specified by format.
  928. \return SSL_SUCCESS upon success.
  929. \return SSL_FAILURE If the function call fails, possible causes might
  930. include: The input key file is in the wrong format, or the wrong format
  931. has been given using the “format” argument, file doesn’t exist, can’t
  932. be read, or is corrupted, an out of memory condition occurs.
  933. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  934. wolfSSL_CTX_new()
  935. \param file a pointer to the name of the file containing the RSA private
  936. key to be loaded into the wolfSSL SSL context, with format as specified
  937. by format.
  938. \param format the encoding type of the RSA private key specified by file.
  939. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  940. _Example_
  941. \code
  942. int ret = 0;
  943. WOLFSSL_CTX* ctx;
  944. ...
  945. ret = wolfSSL_CTX_use_RSAPrivateKey_file(ctx, “./server-key.pem”,
  946. SSL_FILETYPE_PEM);
  947. if (ret != SSL_SUCCESS) {
  948. // error loading private key file
  949. }
  950. ...
  951. \endcode
  952. \sa wolfSSL_CTX_use_PrivateKey_buffer
  953. \sa wolfSSL_CTX_use_PrivateKey_file
  954. \sa wolfSSL_use_RSAPrivateKey_file
  955. \sa wolfSSL_use_PrivateKey_buffer
  956. \sa wolfSSL_use_PrivateKey_file
  957. */
  958. WOLFSSL_API int wolfSSL_CTX_use_RSAPrivateKey_file(WOLFSSL_CTX*, const char*, int);
  959. /*!
  960. \ingroup IO
  961. \brief This function returns the maximum chain depth allowed, which is 9 by
  962. default, for a valid session i.e. there is a non-null session object (ssl).
  963. \return MAX_CHAIN_DEPTH returned if the WOLFSSL_CTX structure is not
  964. NULL. By default the value is 9.
  965. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  966. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  967. _Example_
  968. \code
  969. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  970. WOLFSSL* ssl = wolfSSL_new(ctx);
  971. ...
  972. long sslDep = wolfSSL_get_verify_depth(ssl);
  973. if(sslDep > EXPECTED){
  974. // The verified depth is greater than what was expected
  975. } else {
  976. // The verified depth is smaller or equal to the expected value
  977. }
  978. \endcode
  979. \sa wolfSSL_CTX_get_verify_depth
  980. */
  981. WOLFSSL_API long wolfSSL_get_verify_depth(WOLFSSL* ssl);
  982. /*!
  983. \ingroup Setup
  984. \brief This function gets the certificate chaining depth using the
  985. CTX structure.
  986. \return MAX_CHAIN_DEPTH returned if the CTX struct is not NULL. The
  987. constant representation of the max certificate chain peer depth.
  988. \return BAD_FUNC_ARG returned if the CTX structure is NULL.
  989. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  990. wolfSSL_CTX_new().
  991. _Example_
  992. \code
  993. WOLFSSL_METHOD method; // protocol method
  994. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  995. long ret = wolfSSL_CTX_get_verify_depth(ctx);
  996. if(ret == EXPECTED){
  997. // You have the expected value
  998. } else {
  999. // Handle an unexpected depth
  1000. }
  1001. \endcode
  1002. \sa wolfSSL_CTX_use_certificate_chain_file
  1003. \sa wolfSSL_get_verify_depth
  1004. */
  1005. WOLFSSL_API long wolfSSL_CTX_get_verify_depth(WOLFSSL_CTX* ctx);
  1006. /*!
  1007. \ingroup openSSL
  1008. \brief This function loads a certificate file into the SSL session
  1009. (WOLFSSL structure). The certificate file is provided by the file
  1010. argument. The format argument specifies the format type of the file -
  1011. either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1012. \return SSL_SUCCESS upon success
  1013. \return SSL_FAILURE If the function call fails, possible causes might
  1014. include: The file is in the wrong format, or the wrong format has been
  1015. given using the “format” argument, file doesn’t exist, can’t be read,
  1016. or is corrupted, an out of memory condition occurs, Base16 decoding
  1017. fails on the file
  1018. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1019. \param file a pointer to the name of the file containing the certificate to
  1020. be loaded into the wolfSSL SSL session, with format as specified by format.
  1021. \param format the encoding type of the certificate specified by file.
  1022. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1023. _Example_
  1024. \code
  1025. int ret = 0;
  1026. WOLFSSL* ssl;
  1027. ...
  1028. ret = wolfSSL_use_certificate_file(ssl, “./client-cert.pem”,
  1029. SSL_FILETYPE_PEM);
  1030. if (ret != SSL_SUCCESS) {
  1031. // error loading cert file
  1032. }
  1033. ...
  1034. \endcode
  1035. \sa wolfSSL_CTX_use_certificate_buffer
  1036. \sa wolfSSL_CTX_use_certificate_file
  1037. \sa wolfSSL_use_certificate_buffer
  1038. */
  1039. WOLFSSL_API int wolfSSL_use_certificate_file(WOLFSSL*, const char*, int);
  1040. /*!
  1041. \ingroup openSSL
  1042. \brief This function loads a private key file into the SSL session
  1043. (WOLFSSL structure). The key file is provided by the file argument.
  1044. The format argument specifies the format type of the file -
  1045. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1046. \return SSL_SUCCESS upon success.
  1047. \return SSL_FAILURE If the function call fails, possible causes might
  1048. include: The file is in the wrong format, or the wrong format has been
  1049. given using the “format” argument, The file doesn’t exist, can’t be read,
  1050. or is corrupted, An out of memory condition occurs, Base16 decoding
  1051. fails on the file, The key file is encrypted but no password is provided
  1052. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1053. \param file a pointer to the name of the file containing the key file to
  1054. be loaded into the wolfSSL SSL session, with format as specified by format.
  1055. \param format the encoding type of the key specified by file. Possible
  1056. values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1057. _Example_
  1058. \code
  1059. int ret = 0;
  1060. WOLFSSL* ssl;
  1061. ...
  1062. ret = wolfSSL_use_PrivateKey_file(ssl, “./server-key.pem”,
  1063. SSL_FILETYPE_PEM);
  1064. if (ret != SSL_SUCCESS) {
  1065. // error loading key file
  1066. }
  1067. ...
  1068. \endcode
  1069. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1070. \sa wolfSSL_CTX_use_PrivateKey_file
  1071. \sa wolfSSL_use_PrivateKey_buffer
  1072. */
  1073. WOLFSSL_API int wolfSSL_use_PrivateKey_file(WOLFSSL*, const char*, int);
  1074. /*!
  1075. \ingroup openSSL
  1076. \brief This function loads a chain of certificates into the SSL
  1077. session (WOLFSSL structure). The file containing the certificate
  1078. chain is provided by the file argument, and must contain PEM-formatted
  1079. certificates. This function will process up to MAX_CHAIN_DEPTH
  1080. (default = 9, defined in internal.h) certificates, plus the
  1081. subject certificate.
  1082. \return SSL_SUCCESS upon success.
  1083. \return SSL_FAILURE If the function call fails, possible causes
  1084. might include: The file is in the wrong format, or the wrong format
  1085. has been given using the “format” argument, file doesn’t exist,
  1086. can’t be read, or is corrupted, an out of memory condition occurs
  1087. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1088. \param file a pointer to the name of the file containing the chain
  1089. of certificates to be loaded into the wolfSSL SSL session.
  1090. Certificates must be in PEM format.
  1091. _Example_
  1092. \code
  1093. int ret = 0;
  1094. WOLFSSL* ctx;
  1095. ...
  1096. ret = wolfSSL_use_certificate_chain_file(ssl, “./cert-chain.pem”);
  1097. if (ret != SSL_SUCCESS) {
  1098. // error loading cert file
  1099. }
  1100. ...
  1101. \endcode
  1102. \sa wolfSSL_CTX_use_certificate_chain_file
  1103. \sa wolfSSL_CTX_use_certificate_chain_buffer
  1104. \sa wolfSSL_use_certificate_chain_buffer
  1105. */
  1106. WOLFSSL_API int wolfSSL_use_certificate_chain_file(WOLFSSL*, const char *file);
  1107. /*!
  1108. \ingroup openSSL
  1109. \brief This function loads the private RSA key used in the SSL
  1110. connection into the SSL session (WOLFSSL structure). This
  1111. function is only available when wolfSSL has been compiled with
  1112. the OpenSSL compatibility layer enabled (--enable-opensslExtra,
  1113. #define OPENSSL_EXTRA), and is identical to the more-typically
  1114. used wolfSSL_use_PrivateKey_file() function. The file argument
  1115. contains a pointer to the RSA private key file, in the format
  1116. specified by format.
  1117. \return SSL_SUCCESS upon success
  1118. \return SSL_FAILURE If the function call fails, possible causes might
  1119. include: The input key file is in the wrong format, or the wrong format
  1120. has been given using the “format” argument, file doesn’t exist, can’t
  1121. be read, or is corrupted, an out of memory condition occurs
  1122. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1123. \param file a pointer to the name of the file containing the RSA private
  1124. key to be loaded into the wolfSSL SSL session, with format as specified
  1125. by format.
  1126. \parm format the encoding type of the RSA private key specified by file.
  1127. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1128. _Example_
  1129. \code
  1130. int ret = 0;
  1131. WOLFSSL* ssl;
  1132. ...
  1133. ret = wolfSSL_use_RSAPrivateKey_file(ssl, “./server-key.pem”,
  1134. SSL_FILETYPE_PEM);
  1135. if (ret != SSL_SUCCESS) {
  1136. // error loading private key file
  1137. }
  1138. ...
  1139. \endcode
  1140. \sa wolfSSL_CTX_use_RSAPrivateKey_file
  1141. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1142. \sa wolfSSL_CTX_use_PrivateKey_file
  1143. \sa wolfSSL_use_PrivateKey_buffer
  1144. \sa wolfSSL_use_PrivateKey_file
  1145. */
  1146. WOLFSSL_API int wolfSSL_use_RSAPrivateKey_file(WOLFSSL*, const char*, int);
  1147. /*!
  1148. \ingroup CertsKeys
  1149. \brief This function is similar to wolfSSL_CTX_load_verify_locations,
  1150. but allows the loading of DER-formatted CA files into the SSL context
  1151. (WOLFSSL_CTX). It may still be used to load PEM-formatted CA files as
  1152. well. These certificates will be treated as trusted root certificates
  1153. and used to verify certs received from peers during the SSL handshake.
  1154. The root certificate file, provided by the file argument, may be a single
  1155. certificate or a file containing multiple certificates. If multiple CA
  1156. certs are included in the same file, wolfSSL will load them in the same
  1157. order they are presented in the file. The format argument specifies the
  1158. format which the certificates are in either, SSL_FILETYPE_PEM or
  1159. SSL_FILETYPE_ASN1 (DER). Unlike wolfSSL_CTX_load_verify_locations,
  1160. this function does not allow the loading of CA certificates from a given
  1161. directory path. Note that this function is only available when the wolfSSL
  1162. library was compiled with WOLFSSL_DER_LOAD defined.
  1163. \return SSL_SUCCESS upon success.
  1164. \return SSL_FAILURE upon failure.
  1165. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1166. wolfSSL_CTX_new()
  1167. \param file a pointer to the name of the file containing the CA
  1168. certificates to be loaded into the wolfSSL SSL context, with format
  1169. as specified by format.
  1170. \param format the encoding type of the certificates specified by file.
  1171. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1172. _Example_
  1173. \code
  1174. int ret = 0;
  1175. WOLFSSL_CTX* ctx;
  1176. ...
  1177. ret = wolfSSL_CTX_der_load_verify_locations(ctx, “./ca-cert.der”,
  1178. SSL_FILETYPE_ASN1);
  1179. if (ret != SSL_SUCCESS) {
  1180. // error loading CA certs
  1181. }
  1182. ...
  1183. \endcode
  1184. \sa wolfSSL_CTX_load_verify_locations
  1185. \sa wolfSSL_CTX_load_verify_buffer
  1186. */
  1187. WOLFSSL_API int wolfSSL_CTX_der_load_verify_locations(WOLFSSL_CTX*,
  1188. const char*, int);
  1189. /*!
  1190. \ingroup CertsKeys
  1191. \brief This function loads an NTRU private key file into the WOLFSSL
  1192. Context. It behaves like the normal version, only differing in its
  1193. ability to accept an NTRU raw key file. This function is needed since
  1194. the format of the file is different than the normal key file (buffer)
  1195. functions. Please see the examples for proper usage.
  1196. \return SSL_SUCCES upon success.
  1197. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  1198. be read, or is corrupted.
  1199. \return MEMORY_E will be returned if an out of memory condition occurs.
  1200. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  1201. \return BUFFER_E will be returned if a chain buffer is bigger than the
  1202. receiving buffer.
  1203. \return NO_PASSWORD will be returned if the key file is encrypted but
  1204. no password is provided.
  1205. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1206. wolfSSL_CTX_new()
  1207. \param file a pointer to the name of the file containing the NTRU
  1208. private key to be loaded into the wolfSSL SSL context.
  1209. _Example_
  1210. \code
  1211. int ret = 0;
  1212. WOLFSSL_CTX* ctx;
  1213. ...
  1214. ret = wolfSSL_CTX_use_NTRUPrivateKey_file(ctx, “./ntru-key.raw”);
  1215. if (ret != SSL_SUCCESS) {
  1216. // error loading NTRU private key
  1217. }
  1218. ...
  1219. \endcode
  1220. \sa wolfSSL_CTX_load_verify_buffer
  1221. \sa wolfSSL_CTX_use_certificate_buffer
  1222. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1223. \sa wolfSSL_CTX_use_certificate_chain_buffer
  1224. \sa wolfSSL_use_certificate_buffer
  1225. \sa wolfSSL_use_PrivateKey_buffer
  1226. \sa wolfSSL_use_certificate_chain_buffer
  1227. */
  1228. WOLFSSL_API int wolfSSL_CTX_use_NTRUPrivateKey_file(WOLFSSL_CTX*, const char*);
  1229. /*!
  1230. \ingroup Setup
  1231. \brief This function creates a new SSL context, taking a desired
  1232. SSL/TLS protocol method for input.
  1233. \return pointer If successful the call will return a pointer to the
  1234. newly-created WOLFSSL_CTX.
  1235. \return NULL upon failure.
  1236. \param method pointer to the desired WOLFSSL_METHOD to use for the SSL
  1237. context. This is created using one of the wolfSSLvXX_XXXX_method()
  1238. functions to specify SSL/TLS/DTLS protocol level.
  1239. _Example_
  1240. \code
  1241. WOLFSSL_CTX* ctx = 0;
  1242. WOLFSSL_METHOD* method = 0;
  1243. method = wolfSSLv3_client_method();
  1244. if (method == NULL) {
  1245. // unable to get method
  1246. }
  1247. ctx = wolfSSL_CTX_new(method);
  1248. if (ctx == NULL) {
  1249. // context creation failed
  1250. }
  1251. \endcode
  1252. \sa wolfSSL_new
  1253. */
  1254. WOLFSSL_API WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*);
  1255. /*!
  1256. \ingroup Setup
  1257. \brief This function creates a new SSL session, taking an already
  1258. created SSL context as input.
  1259. \return * If successful the call will return a pointer to the
  1260. newly-created wolfSSL structure.
  1261. \return NULL Upon failure.
  1262. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1263. _Example_
  1264. \code
  1265. #include <wolfssl/ssl.h>
  1266. WOLFSSL* ssl = NULL;
  1267. WOLFSSL_CTX* ctx = 0;
  1268. ctx = wolfSSL_CTX_new(method);
  1269. if (ctx == NULL) {
  1270. // context creation failed
  1271. }
  1272. ssl = wolfSSL_new(ctx);
  1273. if (ssl == NULL) {
  1274. // SSL object creation failed
  1275. }
  1276. \endcode
  1277. \sa wolfSSL_CTX_new
  1278. */
  1279. WOLFSSL_API WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
  1280. /*!
  1281. \ingroup Setup
  1282. \brief This function assigns a file descriptor (fd) as the
  1283. input/output facility for the SSL connection. Typically this will be
  1284. a socket file descriptor.
  1285. \return SSL_SUCCESS upon success.
  1286. \return Bad_FUNC_ARG upon failure.
  1287. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1288. \param fd file descriptor to use with SSL/TLS connection.
  1289. _Example_
  1290. \code
  1291. int sockfd;
  1292. WOLFSSL* ssl = 0;
  1293. ...
  1294. ret = wolfSSL_set_fd(ssl, sockfd);
  1295. if (ret != SSL_SUCCESS) {
  1296. // failed to set SSL file descriptor
  1297. }
  1298. \endcode
  1299. \sa wolfSSL_CTX_SetIOSend
  1300. \sa wolfSSL_CTX_SetIORecv
  1301. \sa wolfSSL_SetIOReadCtx
  1302. \sa wolfSSL_SetIOWriteCtx
  1303. */
  1304. WOLFSSL_API int wolfSSL_set_fd (WOLFSSL*, int);
  1305. /*!
  1306. \ingroup IO
  1307. \brief Get the name of cipher at priority level passed in.
  1308. \return string Success
  1309. \return 0 Priority is either out of bounds or not valid.
  1310. \param priority Integer representing the priority level of a cipher.
  1311. _Example_
  1312. \code
  1313. printf("The cipher at 1 is %s", wolfSSL_get_cipher_list(1));
  1314. \endcode
  1315. \sa wolfSSL_CIPHER_get_name
  1316. \sa wolfSSL_get_current_cipher
  1317. */
  1318. WOLFSSL_API char* wolfSSL_get_cipher_list(int priority);
  1319. /*!
  1320. \ingroup IO
  1321. \brief This function gets the ciphers enabled in wolfSSL.
  1322. \return SSL_SUCCESS returned if the function executed without error.
  1323. \return BAD_FUNC_ARG returned if the buf parameter was NULL or if the
  1324. len argument was less than or equal to zero.
  1325. \return BUFFER_E returned if the buffer is not large enough and
  1326. will overflow.
  1327. \param buf a char pointer representing the buffer.
  1328. \param len the length of the buffer.
  1329. _Example_
  1330. \code
  1331. static void ShowCiphers(void){
  1332. char* ciphers;
  1333. int ret = wolfSSL_get_ciphers(ciphers, (int)sizeof(ciphers));
  1334. if(ret == SSL_SUCCES){
  1335. printf(“%s\n”, ciphers);
  1336. }
  1337. }
  1338. \endcode
  1339. \sa GetCipherNames
  1340. \sa wolfSSL_get_cipher_list
  1341. \sa ShowCiphers
  1342. */
  1343. WOLFSSL_API int wolfSSL_get_ciphers(char*, int);
  1344. /*!
  1345. \ingroup IO
  1346. \brief This function gets the cipher name in the format DHE-RSA by
  1347. passing through argument to wolfSSL_get_cipher_name_internal.
  1348. \return string This function returns the string representation of the
  1349. cipher suite that was matched.
  1350. \return NULL error or cipher not found.
  1351. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1352. _Example_
  1353. \code
  1354. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1355. WOLFSSL* ssl = wolfSSL_new(ctx);
  1356. char* cipherS = wolfSSL_get_cipher_name(ssl);
  1357. if(cipher == NULL){
  1358. // There was not a cipher suite matched
  1359. } else {
  1360. // There was a cipher suite matched
  1361. printf(“%s\n”, cipherS);
  1362. }
  1363. \endcode
  1364. \sa wolfSSL_CIPHER_get_name
  1365. \sa wolfSSL_get_current_cipher
  1366. \sa wolfSSL_get_cipher_name_internal
  1367. */
  1368. WOLFSSL_API const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);
  1369. /*!
  1370. \ingroup IO
  1371. \brief This function returns the file descriptor (fd) used as the
  1372. input/output facility for the SSL connection. Typically this
  1373. will be a socket file descriptor.
  1374. \return fd If successful the call will return the SSL session file
  1375. descriptor.
  1376. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1377. _Example_
  1378. \code
  1379. int sockfd;
  1380. WOLFSSL* ssl = 0;
  1381. ...
  1382. sockfd = wolfSSL_get_fd(ssl);
  1383. ...
  1384. \endcode
  1385. \sa wolfSSL_set_fd
  1386. */
  1387. WOLFSSL_API int wolfSSL_get_fd(const WOLFSSL*);
  1388. /*!
  1389. \ingroup Setup
  1390. \brief This function informs the WOLFSSL object that the underlying
  1391. I/O is non-blocking. After an application creates a WOLFSSL object,
  1392. if it will be used with a non-blocking socket, call
  1393. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1394. that receiving EWOULDBLOCK means that the recvfrom call would
  1395. block rather than that it timed out.
  1396. \return none No return.
  1397. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1398. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  1399. Use 1 to specify non-blocking, otherwise 0.
  1400. _Example_
  1401. \code
  1402. WOLFSSL* ssl = 0;
  1403. ...
  1404. wolfSSL_set_using_nonblock(ssl, 1);
  1405. \endcode
  1406. \sa wolfSSL_get_using_nonblock
  1407. \sa wolfSSL_dtls_got_timeout
  1408. \sa wolfSSL_dtls_get_current_timeout
  1409. */
  1410. WOLFSSL_API void wolfSSL_set_using_nonblock(WOLFSSL*, int);
  1411. /*!
  1412. \ingroup IO
  1413. \brief This function allows the application to determine if wolfSSL is
  1414. using non-blocking I/O. If wolfSSL is using non-blocking I/O, this
  1415. function will return 1, otherwise 0. After an application creates a
  1416. WOLFSSL object, if it will be used with a non-blocking socket, call
  1417. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1418. that receiving EWOULDBLOCK means that the recvfrom call would block
  1419. rather than that it timed out.
  1420. \return 0 underlying I/O is blocking.
  1421. \return 1 underlying I/O is non-blocking.
  1422. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1423. _Example_
  1424. \code
  1425. int ret = 0;
  1426. WOLFSSL* ssl = 0;
  1427. ...
  1428. ret = wolfSSL_get_using_nonblock(ssl);
  1429. if (ret == 1) {
  1430. // underlying I/O is non-blocking
  1431. }
  1432. ...
  1433. \endcode
  1434. \sa wolfSSL_set_session
  1435. */
  1436. WOLFSSL_API int wolfSSL_get_using_nonblock(WOLFSSL*);
  1437. /*!
  1438. \ingroup IO
  1439. \brief This function writes sz bytes from the buffer, data, to the SSL
  1440. connection, ssl. If necessary, wolfSSL_write() will negotiate an SSL/TLS
  1441. session if the handshake has not already been performed yet by
  1442. wolfSSL_connect() or wolfSSL_accept(). wolfSSL_write() works with both
  1443. blocking and non-blocking I/O. When the underlying I/O is non-blocking,
  1444. wolfSSL_write() will return when the underlying I/O could not satisfy the
  1445. needs of wolfSSL_write() to continue. In this case, a call to
  1446. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1447. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call to
  1448. wolfSSL_write() when the underlying I/O is ready. If the underlying I/O
  1449. is blocking, wolfSSL_write() will only return once the buffer data of
  1450. size sz has been completely written or an error occurred.
  1451. \return >0 the number of bytes written upon success.
  1452. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1453. the specific error code.
  1454. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1455. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1456. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1457. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  1458. error code.
  1459. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1460. \param data data buffer which will be sent to peer.
  1461. \param sz size, in bytes, of data to send to the peer (data).
  1462. _Example_
  1463. \code
  1464. WOLFSSL* ssl = 0;
  1465. char msg[64] = “hello wolfssl!”;
  1466. int msgSz = (int)strlen(msg);
  1467. int flags;
  1468. int ret;
  1469. ...
  1470. ret = wolfSSL_write(ssl, msg, msgSz);
  1471. if (ret <= 0) {
  1472. // wolfSSL_write() failed, call wolfSSL_get_error()
  1473. }
  1474. \endcode
  1475. \sa wolfSSL_send
  1476. \sa wolfSSL_read
  1477. \sa wolfSSL_recv
  1478. */
  1479. WOLFSSL_API int wolfSSL_write(WOLFSSL*, const void*, int);
  1480. /*!
  1481. \ingroup IO
  1482. \brief This function reads sz bytes from the SSL session (ssl)
  1483. internal read buffer into the buffer data. The bytes read are removed
  1484. from the internal receive buffer. If necessary wolfSSL_read() will
  1485. negotiate an SSL/TLS session if the handshake has not already been
  1486. performed yet by wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS
  1487. protocol uses SSL records which have a maximum size of 16kB (the max
  1488. record size can be controlled by the MAX_RECORD_SIZE define in
  1489. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1490. entire SSL record internally before it is able to process and decrypt the
  1491. record. Because of this, a call to wolfSSL_read() will only be able to
  1492. return the maximum buffer size which has been decrypted at the time of
  1493. calling. There may be additional not-yet-decrypted data waiting in the
  1494. internal wolfSSL receive buffer which will be retrieved and decrypted with
  1495. the next call to wolfSSL_read(). If sz is larger than the number of bytes
  1496. in the internal read buffer, SSL_read() will return the bytes available in
  1497. the internal read buffer. If no bytes are buffered in the internal read
  1498. buffer yet, a call to wolfSSL_read() will trigger processing of the next
  1499. record.
  1500. \return >0 the number of bytes read upon success.
  1501. \return 0 will be returned upon failure. This may be caused by a either a
  1502. clean (close notify alert) shutdown or just that the peer closed the
  1503. connection. Call wolfSSL_get_error() for the specific error code.
  1504. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1505. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1506. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1507. call wolfSSL_read() again. Use wolfSSL_get_error() to get a specific
  1508. error code.
  1509. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1510. \param data buffer where wolfSSL_read() will place data read.
  1511. \param sz number of bytes to read into data.
  1512. _Example_
  1513. \code
  1514. WOLFSSL* ssl = 0;
  1515. char reply[1024];
  1516. ...
  1517. input = wolfSSL_read(ssl, reply, sizeof(reply));
  1518. if (input > 0) {
  1519. // “input” number of bytes returned into buffer “reply”
  1520. }
  1521. See wolfSSL examples (client, server, echoclient, echoserver) for more
  1522. complete examples of wolfSSL_read().
  1523. \endcode
  1524. \sa wolfSSL_recv
  1525. \sa wolfSSL_write
  1526. \sa wolfSSL_peek
  1527. \sa wolfSSL_pending
  1528. */
  1529. WOLFSSL_API int wolfSSL_read(WOLFSSL*, void*, int);
  1530. /*!
  1531. \ingroup IO
  1532. \brief This function copies sz bytes from the SSL session (ssl) internal
  1533. read buffer into the buffer data. This function is identical to
  1534. wolfSSL_read() except that the data in the internal SSL session
  1535. receive buffer is not removed or modified. If necessary, like
  1536. wolfSSL_read(), wolfSSL_peek() will negotiate an SSL/TLS session if
  1537. the handshake has not already been performed yet by wolfSSL_connect()
  1538. or wolfSSL_accept(). The SSL/TLS protocol uses SSL records which have a
  1539. maximum size of 16kB (the max record size can be controlled by the
  1540. MAX_RECORD_SIZE define in <wolfssl_root>/wolfssl/internal.h). As such,
  1541. wolfSSL needs to read an entire SSL record internally before it is able
  1542. to process and decrypt the record. Because of this, a call to
  1543. wolfSSL_peek() will only be able to return the maximum buffer size which
  1544. has been decrypted at the time of calling. There may be additional
  1545. not-yet-decrypted data waiting in the internal wolfSSL receive buffer
  1546. which will be retrieved and decrypted with the next call to
  1547. wolfSSL_peek() / wolfSSL_read(). If sz is larger than the number of bytes
  1548. in the internal read buffer, SSL_peek() will return the bytes available
  1549. in the internal read buffer. If no bytes are buffered in the internal
  1550. read buffer yet, a call to wolfSSL_peek() will trigger processing of the
  1551. next record.
  1552. \return >0 the number of bytes read upon success.
  1553. \return 0 will be returned upon failure. This may be caused by a either
  1554. a clean (close notify alert) shutdown or just that the peer closed the
  1555. connection. Call wolfSSL_get_error() for the specific error code.
  1556. \return SSL_FATAL_ERROR will be returned upon failure when either an
  1557. error occurred or, when using non-blocking sockets, the
  1558. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and and
  1559. the application needs to call wolfSSL_peek() again. Use
  1560. wolfSSL_get_error() to get a specific error code.
  1561. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1562. \param data buffer where wolfSSL_peek() will place data read.
  1563. \param sz number of bytes to read into data.
  1564. _Example_
  1565. \code
  1566. WOLFSSL* ssl = 0;
  1567. char reply[1024];
  1568. ...
  1569. input = wolfSSL_peek(ssl, reply, sizeof(reply));
  1570. if (input > 0) {
  1571. // “input” number of bytes returned into buffer “reply”
  1572. }
  1573. \endcode
  1574. \sa wolfSSL_read
  1575. */
  1576. WOLFSSL_API int wolfSSL_peek(WOLFSSL*, void*, int);
  1577. /*!
  1578. \ingroup IO
  1579. \brief This function is called on the server side and waits for an SSL
  1580. client to initiate the SSL/TLS handshake. When this function is called,
  1581. the underlying communication channel has already been set up.
  1582. wolfSSL_accept() works with both blocking and non-blocking I/O.
  1583. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  1584. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  1585. to continue the handshake. In this case, a call to wolfSSL_get_error()
  1586. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1587. The calling process must then repeat the call to wolfSSL_accept when
  1588. data is available to read and wolfSSL will pick up where it left off.
  1589. When using a non-blocking socket, nothing needs to be done, but select()
  1590. can be used to check for the required condition. If the underlying I/O
  1591. is blocking, wolfSSL_accept() will only return once the handshake has
  1592. been finished or an error occurred.
  1593. \return SSL_SUCCESS upon success.
  1594. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  1595. more detailed error code, call wolfSSL_get_error().
  1596. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1597. _Example_
  1598. \code
  1599. int ret = 0;
  1600. int err = 0;
  1601. WOLFSSL* ssl;
  1602. char buffer[80];
  1603. ...
  1604. ret = wolfSSL_accept(ssl);
  1605. if (ret != SSL_SUCCESS) {
  1606. err = wolfSSL_get_error(ssl, ret);
  1607. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  1608. }
  1609. \endcode
  1610. \sa wolfSSL_get_error
  1611. \sa wolfSSL_connect
  1612. */
  1613. WOLFSSL_API int wolfSSL_accept(WOLFSSL*);
  1614. /*!
  1615. \brief This function is called on the client side and initiates an
  1616. SSL/TLS handshake with a server. When this function is called, the
  1617. underlying communication channel has already been set up.
  1618. wolfSSL_connect() works with both blocking and non-blocking I/O.
  1619. When the underlying I/O is non-blocking, wolfSSL_connect() will return
  1620. when the underlying I/O could not satisfy the needs of wolfSSL_connect
  1621. to continue the handshake. In this case, a call to wolfSSL_get_error()
  1622. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The
  1623. calling process must then repeat the call to wolfSSL_connect() when
  1624. the underlying I/O is ready and wolfSSL will pick up where it left off.
  1625. When using a non-blocking socket, nothing needs to be done, but select()
  1626. can be used to check for the required condition. If the underlying I/O is
  1627. blocking, wolfSSL_connect() will only return once the handshake has been
  1628. finished or an error occurred. wolfSSL takes a different approach to
  1629. certificate verification than OpenSSL does. The default policy for the
  1630. client is to verify the server, this means that if you don't load CAs to
  1631. verify the server you'll get a connect error, unable to verify (-155). It
  1632. you want to mimic OpenSSL behavior of having SSL_connect succeed even if
  1633. verifying the server fails and reducing security you can do this by
  1634. calling: SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling
  1635. SSL_new(); Though it's not recommended.
  1636. \return SSL_SUCCESS upon success.
  1637. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  1638. more detailed error code, call wolfSSL_get_error().
  1639. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1640. _Example_
  1641. \code
  1642. int ret = 0;
  1643. int err = 0;
  1644. WOLFSSL* ssl;
  1645. char buffer[80];
  1646. ...
  1647. ret = wolfSSL_connect(ssl);
  1648. if (ret != SSL_SUCCESS) {
  1649. err = wolfSSL_get_error(ssl, ret);
  1650. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  1651. }
  1652. \endcode
  1653. \sa wolfSSL_get_error
  1654. \sa wolfSSL_accept
  1655. */
  1656. WOLFSSL_API int wolfSSL_connect_TLSv13(WOLFSSL*);
  1657. /*!
  1658. \ingroup Setup
  1659. \brief This function frees an allocated WOLFSSL_CTX object. This
  1660. function decrements the CTX reference count and only frees the context
  1661. when the reference count has reached 0.
  1662. \return none No return.
  1663. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1664. _Example_
  1665. \code
  1666. WOLFSSL_CTX* ctx = 0;
  1667. ...
  1668. wolfSSL_CTX_free(ctx);
  1669. \endcode
  1670. \sa wolfSSL_CTX_new
  1671. \sa wolfSSL_new
  1672. \sa wolfSSL_free
  1673. */
  1674. WOLFSSL_API void wolfSSL_CTX_free(WOLFSSL_CTX*);
  1675. /*!
  1676. \ingroup Setup
  1677. \brief This function frees an allocated wolfSSL object.
  1678. \return none No return.
  1679. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1680. _Example_
  1681. \code
  1682. #include <wolfssl/ssl.h>
  1683. WOLFSSL* ssl = 0;
  1684. ...
  1685. wolfSSL_free(ssl);
  1686. \endcode
  1687. \sa wolfSSL_CTX_new
  1688. \sa wolfSSL_new
  1689. \sa wolfSSL_CTX_free
  1690. */
  1691. WOLFSSL_API void wolfSSL_free(WOLFSSL*);
  1692. /*!
  1693. \ingroup TLS
  1694. \brief This function shuts down an active SSL/TLS connection using
  1695. the SSL session, ssl. This function will try to send a “close notify”
  1696. alert to the peer. The calling application can choose to wait for the
  1697. peer to send its “close notify” alert in response or just go ahead
  1698. and shut down the underlying connection after directly calling
  1699. wolfSSL_shutdown (to save resources). Either option is allowed by
  1700. the TLS specification. If the underlying connection will be used
  1701. again in the future, the complete two-directional shutdown procedure
  1702. must be performed to keep synchronization intact between the peers.
  1703. wolfSSL_shutdown() works with both blocking and non-blocking I/O.
  1704. When the underlying I/O is non-blocking, wolfSSL_shutdown() will
  1705. return an error if the underlying I/O could not satisfy the needs of
  1706. wolfSSL_shutdown() to continue. In this case, a call to
  1707. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1708. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call
  1709. to wolfSSL_shutdown() when the underlying I/O is ready.
  1710. \return SSL_SUCCESS will be returned upon success.
  1711. \return SSL_SHUTDOWN_NOT_DONE will be returned when shutdown has not
  1712. finished, and the function should be called again.
  1713. \return SSL_FATAL_ERROR will be returned upon failure. Call
  1714. wolfSSL_get_error() for a more specific error code.
  1715. \param ssl pointer to the SSL session created with wolfSSL_new().
  1716. _Example_
  1717. \code
  1718. #include <wolfssl/ssl.h>
  1719. int ret = 0;
  1720. WOLFSSL* ssl = 0;
  1721. ...
  1722. ret = wolfSSL_shutdown(ssl);
  1723. if (ret != 0) {
  1724. // failed to shut down SSL connection
  1725. }
  1726. \endcode
  1727. \sa wolfSSL_free
  1728. \sa wolfSSL_CTX_free
  1729. */
  1730. WOLFSSL_API int wolfSSL_shutdown(WOLFSSL*);
  1731. /*!
  1732. \ingroup IO
  1733. \brief This function writes sz bytes from the buffer, data, to the SSL
  1734. connection, ssl, using the specified flags for the underlying write
  1735. operation. If necessary wolfSSL_send() will negotiate an SSL/TLS session
  1736. if the handshake has not already been performed yet by wolfSSL_connect()
  1737. or wolfSSL_accept(). wolfSSL_send() works with both blocking and
  1738. non-blocking I/O. When the underlying I/O is non-blocking, wolfSSL_send()
  1739. will return when the underlying I/O could not satisfy the needs of
  1740. wolfSSL_send to continue. In this case, a call to wolfSSL_get_error()
  1741. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1742. The calling process must then repeat the call to wolfSSL_send() when
  1743. the underlying I/O is ready. If the underlying I/O is blocking,
  1744. wolfSSL_send() will only return once the buffer data of size sz has
  1745. been completely written or an error occurred.
  1746. \return >0 the number of bytes written upon success.
  1747. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1748. the specific error code.
  1749. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1750. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1751. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1752. call wolfSSL_send() again. Use wolfSSL_get_error() to get a specific
  1753. error code.
  1754. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1755. \param data data buffer to send to peer.
  1756. \param sz size, in bytes, of data to be sent to peer.
  1757. \param flags the send flags to use for the underlying send operation.
  1758. _Example_
  1759. \code
  1760. WOLFSSL* ssl = 0;
  1761. char msg[64] = “hello wolfssl!”;
  1762. int msgSz = (int)strlen(msg);
  1763. int flags = ... ;
  1764. ...
  1765. input = wolfSSL_send(ssl, msg, msgSz, flags);
  1766. if (input != msgSz) {
  1767. // wolfSSL_send() failed
  1768. }
  1769. \endcode
  1770. \sa wolfSSL_write
  1771. \sa wolfSSL_read
  1772. \sa wolfSSL_recv
  1773. */
  1774. WOLFSSL_API int wolfSSL_send(WOLFSSL*, const void*, int sz, int flags);
  1775. /*!
  1776. \ingroup IO
  1777. \brief This function reads sz bytes from the SSL session (ssl) internal
  1778. read buffer into the buffer data using the specified flags for the
  1779. underlying recv operation. The bytes read are removed from the internal
  1780. receive buffer. This function is identical to wolfSSL_read() except
  1781. that it allows the application to set the recv flags for the underlying
  1782. read operation. If necessary wolfSSL_recv() will negotiate an SSL/TLS
  1783. session if the handshake has not already been performed yet by
  1784. wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS protocol uses
  1785. SSL records which have a maximum size of 16kB (the max record size
  1786. can be controlled by the MAX_RECORD_SIZE define in
  1787. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1788. entire SSL record internally before it is able to process and decrypt
  1789. the record. Because of this, a call to wolfSSL_recv() will only be
  1790. able to return the maximum buffer size which has been decrypted at
  1791. the time of calling. There may be additional not-yet-decrypted data
  1792. waiting in the internal wolfSSL receive buffer which will be
  1793. retrieved and decrypted with the next call to wolfSSL_recv(). If sz
  1794. is larger than the number of bytes in the internal read buffer,
  1795. SSL_recv() will return the bytes available in the internal read buffer.
  1796. If no bytes are buffered in the internal read buffer yet, a call to
  1797. wolfSSL_recv() will trigger processing of the next record.
  1798. \return >0 the number of bytes read upon success.
  1799. \return 0 will be returned upon failure. This may be caused by a either
  1800. a clean (close notify alert) shutdown or just that the peer closed the
  1801. connection. Call wolfSSL_get_error() for the specific error code.
  1802. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1803. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1804. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1805. call wolfSSL_recv() again. Use wolfSSL_get_error() to get a specific
  1806. error code.
  1807. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1808. \param data buffer where wolfSSL_recv() will place data read.
  1809. \param sz number of bytes to read into data.
  1810. \param flags the recv flags to use for the underlying recv operation.
  1811. _Example_
  1812. \code
  1813. WOLFSSL* ssl = 0;
  1814. char reply[1024];
  1815. int flags = ... ;
  1816. ...
  1817. input = wolfSSL_recv(ssl, reply, sizeof(reply), flags);
  1818. if (input > 0) {
  1819. // “input” number of bytes returned into buffer “reply”
  1820. }
  1821. \endcode
  1822. \sa wolfSSL_read
  1823. \sa wolfSSL_write
  1824. \sa wolfSSL_peek
  1825. \sa wolfSSL_pending
  1826. */
  1827. WOLFSSL_API int wolfSSL_recv(WOLFSSL*, void*, int sz, int flags);
  1828. /*!
  1829. \ingroup Debug
  1830. \brief This function returns a unique error code describing why the
  1831. previous API function call (wolfSSL_connect, wolfSSL_accept, wolfSSL_read,
  1832. wolfSSL_write, etc.) resulted in an error return code (SSL_FAILURE).
  1833. The return value of the previous function is passed to wolfSSL_get_error
  1834. through ret. After wolfSSL_get_error is called and returns the unique
  1835. error code, wolfSSL_ERR_error_string() may be called to get a
  1836. human-readable error string. See wolfSSL_ERR_error_string() for more
  1837. information.
  1838. \return code On successful completion, this function will return the
  1839. unique error code describing why the previous API function failed.
  1840. \return SSL_ERROR_NONE will be returned if ret > 0.
  1841. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1842. \param ret return value of the previous function that resulted in an error
  1843. return code.
  1844. _Example_
  1845. \code
  1846. int err = 0;
  1847. WOLFSSL* ssl;
  1848. char buffer[80];
  1849. ...
  1850. err = wolfSSL_get_error(ssl, 0);
  1851. wolfSSL_ERR_error_string(err, buffer);
  1852. printf(“err = %d, %s\n”, err, buffer);
  1853. \endcode
  1854. \sa wolfSSL_ERR_error_string
  1855. \sa wolfSSL_ERR_error_string_n
  1856. \sa wolfSSL_ERR_print_errors_fp
  1857. \sa wolfSSL_load_error_strings
  1858. */
  1859. WOLFSSL_API int wolfSSL_get_error(WOLFSSL*, int);
  1860. /*!
  1861. \ingroup IO
  1862. \brief This function gets the alert history.
  1863. \return SSL_SUCCESS returned when the function completed successfully.
  1864. Either there was alert history or there wasn’t, either way, the
  1865. return value is SSL_SUCCESS.
  1866. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1867. \param h a pointer to a WOLFSSL_ALERT_HISTORY structure that will hold the
  1868. WOLFSSL struct’s alert_history member’s value.
  1869. _Example_
  1870. \code
  1871. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  1872. WOLFSSL* ssl = wolfSSL_new(ctx);
  1873. WOLFSSL_ALERT_HISTORY* h;
  1874. ...
  1875. wolfSSL_get_alert_history(ssl, h);
  1876. // h now has a copy of the ssl->alert_history contents
  1877. \endcode
  1878. \sa wolfSSL_get_error
  1879. */
  1880. WOLFSSL_API int wolfSSL_get_alert_history(WOLFSSL*, WOLFSSL_ALERT_HISTORY *);
  1881. /*!
  1882. \ingroup Setup
  1883. \brief This function sets the session to be used when the SSL object,
  1884. ssl, is used to establish a SSL/TLS connection. For session resumption,
  1885. before calling wolfSSL_shutdown() with your session object, an application
  1886. should save the session ID from the object with a call to
  1887. wolfSSL_get_session(), which returns a pointer to the session.
  1888. Later, the application should create a new WOLFSSL object and assign
  1889. the saved session with wolfSSL_set_session(). At this point, the
  1890. application may call wolfSSL_connect() and wolfSSL will try to resume
  1891. the session. The wolfSSL server code allows session resumption by default.
  1892. \return SSL_SUCCESS will be returned upon successfully setting the session.
  1893. \return SSL_FAILURE will be returned on failure. This could be caused
  1894. by the session cache being disabled, or if the session has timed out.
  1895. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1896. \param session pointer to the WOLFSSL_SESSION used to set the session
  1897. for ssl.
  1898. _Example_
  1899. \code
  1900. int ret = 0;
  1901. WOLFSSL* ssl = 0;
  1902. WOLFSSL_SESSION* session;
  1903. ...
  1904. ret = wolfSSL_get_session(ssl, session);
  1905. if (ret != SSL_SUCCESS) {
  1906. // failed to set the SSL session
  1907. }
  1908. ...
  1909. \endcode
  1910. \sa wolfSSL_get_session
  1911. */
  1912. WOLFSSL_API int wolfSSL_set_session(WOLFSSL*, WOLFSSL_SESSION*);
  1913. /*!
  1914. \ingroup IO
  1915. \brief This function returns a pointer to the current session
  1916. (WOLFSSL_SESSION) used in ssl. The WOLFSSL_SESSION pointed to
  1917. contains all the necessary information required to perform a session
  1918. resumption and reestablish the connection without a new handshake. For
  1919. session resumption, before calling wolfSSL_shutdown() with your session
  1920. object, an application should save the session ID from the object with a
  1921. call to wolfSSL_get_session(), which returns a pointer to the session.
  1922. Later, the application should create a new WOLFSSL object and assign the
  1923. saved session with wolfSSL_set_session(). At this point, the application
  1924. may call wolfSSL_connect() and wolfSSL will try to resume the session.
  1925. The wolfSSL server code allows session resumption by default.
  1926. \return pointer If successful the call will return a pointer to the the
  1927. current SSL session object.
  1928. \return NULL will be returned if ssl is NULL, the SSL session cache is
  1929. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  1930. functions fail.
  1931. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1932. _Example_
  1933. \code
  1934. WOLFSSL* ssl = 0;
  1935. WOLFSSL_SESSION* session = 0;
  1936. ...
  1937. session = wolfSSL_get_session(ssl);
  1938. if (session == NULL) {
  1939. // failed to get session pointer
  1940. }
  1941. ...
  1942. \endcode
  1943. \sa wolfSSL_set_session
  1944. */
  1945. WOLFSSL_API WOLFSSL_SESSION* wolfSSL_get_session(WOLFSSL*);
  1946. /*!
  1947. \ingroup IO
  1948. \brief This function flushes session from the session cache which
  1949. have expired. The time, tm, is used for the time comparison. Note
  1950. that wolfSSL currently uses a static table for sessions, so no flushing
  1951. is needed. As such, this function is currently just a stub. This
  1952. function provides OpenSSL compatibility (SSL_flush_sessions) when
  1953. wolfSSL is compiled with the OpenSSL compatibility layer.
  1954. \return none No returns.
  1955. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1956. wolfSSL_CTX_new().
  1957. \param tm time used in session expiration comparison.
  1958. _Example_
  1959. \code
  1960. WOLFSSL_CTX* ssl;
  1961. ...
  1962. wolfSSL_flush_sessions(ctx, time(0));
  1963. \endcode
  1964. \sa wolfSSL_get_session
  1965. \sa wolfSSL_set_session
  1966. */
  1967. WOLFSSL_API void wolfSSL_flush_sessions(WOLFSSL_CTX*, long);
  1968. /*!
  1969. \ingroup TLS
  1970. \brief This function associates the client session with the server id.
  1971. If the newSession flag is on, an existing session won’t be reused.
  1972. \return SSL_SUCCESS returned if the finction executed without error.
  1973. \return BAD_FUNC_ARG returned if the WOLFSSL struct or id parameter
  1974. is NULL or if len is not greater than zero.
  1975. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1976. \param id a constant byte pointer that will be copied to the
  1977. serverID member of the WOLFSSL_SESSION structure.
  1978. \param len an int type representing the length of the session id parameter.
  1979. \param newSession an int type representing the flag to denote whether
  1980. to reuse a session or not.
  1981. _Example_
  1982. \code
  1983. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol );
  1984. WOLFSSL* ssl = WOLFSSL_new(ctx);
  1985. const byte id[MAX_SIZE]; // or dynamically create space
  1986. int len = 0; // initialize length
  1987. int newSession = 0; // flag to allow
  1988. int ret = wolfSSL_SetServerID(ssl, id, len, newSession);
  1989. if(ret){
  1990. // The Id was successfully set
  1991. }
  1992. \endcode
  1993. \sa GetSessionClient
  1994. */
  1995. WOLFSSL_API int wolfSSL_SetServerID(WOLFSSL*, const unsigned char*,
  1996. int, int);
  1997. /*!
  1998. \ingroup IO
  1999. \brief This function gets the session index of the WOLFSSL structure.
  2000. \return int The function returns an int type representing the
  2001. sessionIndex within the WOLFSSL struct.
  2002. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2003. _Example_
  2004. \code
  2005. WOLFSSL_CTX_new( protocol method );
  2006. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2007. ...
  2008. int sesIdx = wolfSSL_GetSessionIndex(ssl);
  2009. if(sesIdx < 0 || sesIdx > sizeof(ssl->sessionIndex)/sizeof(int)){
  2010. // You have an out of bounds index number and something is not right.
  2011. }
  2012. \endcode
  2013. \sa wolfSSL_GetSessionAtIndex
  2014. */
  2015. WOLFSSL_API int wolfSSL_GetSessionIndex(WOLFSSL* ssl);
  2016. /*!
  2017. \ingroup IO
  2018. \brief This function gets the session at specified index of the session
  2019. cache and copies it into memory. The WOLFSSL_SESSION structure holds
  2020. the session information.
  2021. \return SSL_SUCCESS returned if the function executed successfully and
  2022. no errors were thrown.
  2023. \return BAD_MUTEX_E returned if there was an unlock or lock mutex error.
  2024. \return SSL_FAILURE returned if the function did not execute successfully.
  2025. \param idx an int type representing the session index.
  2026. \param session a pointer to the WOLFSSL_SESSION structure.
  2027. _Example_
  2028. \code
  2029. int idx; // The index to locate the session.
  2030. WOLFSSL_SESSION* session; // Buffer to copy to.
  2031. ...
  2032. if(wolfSSL_GetSessionAtIndex(idx, session) != SSL_SUCCESS){
  2033. // Failure case.
  2034. }
  2035. \endcode
  2036. \sa UnLockMutex
  2037. \sa LockMutex
  2038. \sa wolfSSL_GetSessionIndex
  2039. */
  2040. WOLFSSL_API int wolfSSL_GetSessionAtIndex(int index, WOLFSSL_SESSION* session);
  2041. /*!
  2042. \ingroup IO
  2043. \brief Returns the peer certificate chain from the WOLFSSL_SESSION struct.
  2044. \return pointer A pointer to a WOLFSSL_X509_CHAIN structure that
  2045. contains the peer certification chain.
  2046. \param session a pointer to a WOLFSSL_SESSION structure.
  2047. _Example_
  2048. \code
  2049. WOLFSSL_SESSION* session;
  2050. WOLFSSL_X509_CHAIN* chain;
  2051. ...
  2052. chain = wolfSSL_SESSION_get_peer_chain(session);
  2053. if(!chain){
  2054. // There was no chain. Failure case.
  2055. }
  2056. \endcode
  2057. \sa get_locked_session_stats
  2058. \sa wolfSSL_GetSessionAtIndex
  2059. \sa wolfSSL_GetSessionIndex
  2060. \sa AddSession
  2061. */
  2062. WOLFSSL_API
  2063. WOLFSSL_X509_CHAIN* wolfSSL_SESSION_get_peer_chain(WOLFSSL_SESSION* session);
  2064. /*!
  2065. \ingroup Setup
  2066. \brief This function sets the verification method for remote peers and
  2067. also allows a verify callback to be registered with the SSL context.
  2068. The verify callback will be called only when a verification failure has
  2069. occurred. If no verify callback is desired, the NULL pointer can be used
  2070. for verify_callback. The verification mode of peer certificates is a
  2071. logically OR’d list of flags. The possible flag values include:
  2072. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2073. received from the server and the handshake will continue as normal.
  2074. Server mode: the server will not send a certificate request to the client.
  2075. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2076. mode: the client will verify the certificate received from the server
  2077. during the handshake. This is turned on by default in wolfSSL, therefore,
  2078. using this option has no effect. Server mode: the server will send a
  2079. certificate request to the client and verify the client certificate
  2080. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2081. used on the client side. Server mode: the verification will fail on the
  2082. server side if the client fails to send a certificate when requested to
  2083. do so (when using SSL_VERIFY_PEER on the SSL server).
  2084. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2085. side. Server mode: the verification is the same as
  2086. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2087. If a PSK connection is being made then the connection will go through
  2088. without a peer cert.
  2089. \return none No return.
  2090. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2091. \param mode session timeout value in seconds
  2092. \param verify_callback callback to be called when verification fails.
  2093. If no callback is desired, the NULL pointer can be used for
  2094. verify_callback.
  2095. _Example_
  2096. \code
  2097. WOLFSSL_CTX* ctx = 0;
  2098. ...
  2099. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER |
  2100. SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  2101. \endcode
  2102. \sa wolfSSL_set_verify
  2103. */
  2104. WOLFSSL_API void wolfSSL_CTX_set_verify(WOLFSSL_CTX*, int,
  2105. VerifyCallback verify_callback);
  2106. /*!
  2107. \ingroup Setup
  2108. \brief This function sets the verification method for remote peers and
  2109. also allows a verify callback to be registered with the SSL session.
  2110. The verify callback will be called only when a verification failure has
  2111. occurred. If no verify callback is desired, the NULL pointer can be used
  2112. for verify_callback. The verification mode of peer certificates is a
  2113. logically OR’d list of flags. The possible flag values include:
  2114. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2115. received from the server and the handshake will continue as normal. Server
  2116. mode: the server will not send a certificate request to the client.
  2117. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2118. mode: the client will verify the certificate received from the server
  2119. during the handshake. This is turned on by default in wolfSSL, therefore,
  2120. using this option has no effect. Server mode: the server will send a
  2121. certificate request to the client and verify the client certificate
  2122. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2123. used on the client side. Server mode: the verification will fail on the
  2124. server side if the client fails to send a certificate when requested to do
  2125. so (when using SSL_VERIFY_PEER on the SSL server).
  2126. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2127. side. Server mode: the verification is the same as
  2128. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2129. If a PSK connection is being made then the connection will go through
  2130. without a peer cert.
  2131. \return none No return.
  2132. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2133. \param mode session timeout value in seconds.
  2134. \param verify_callback callback to be called when verification fails.
  2135. If no callback is desired, the NULL pointer can
  2136. be used for verify_callback.
  2137. _Example_
  2138. \code
  2139. WOLFSSL* ssl = 0;
  2140. ...
  2141. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  2142. \endcode
  2143. \sa wolfSSL_CTX_set_verify
  2144. */
  2145. WOLFSSL_API void wolfSSL_set_verify(WOLFSSL*, int, VerifyCallback verify_callback);
  2146. /*!
  2147. \ingroup CertsKeys
  2148. \brief This function stores user CTX object information for verify callback.
  2149. \return none No return.
  2150. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2151. \param ctx a void pointer that is set to WOLFSSL structure’s verifyCbCtx
  2152. member’s value.
  2153. _Example_
  2154. \code
  2155. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2156. WOLFSSL* ssl = wolfSSL_new(ctx);
  2157. (void*)ctx;
  2158. ...
  2159. if(ssl != NULL){
  2160. wolfSSL_SetCertCbCtx(ssl, ctx);
  2161. } else {
  2162. // Error case, the SSL is not initialized properly.
  2163. }
  2164. \endcode
  2165. \sa wolfSSL_CTX_save_cert_cache
  2166. \sa wolfSSL_CTX_restore_cert_cache
  2167. \sa wolfSSL_CTX_set_verify
  2168. */
  2169. WOLFSSL_API void wolfSSL_SetCertCbCtx(WOLFSSL*, void*);
  2170. /*!
  2171. \ingroup IO
  2172. \brief This function returns the number of bytes which are buffered and
  2173. available in the SSL object to be read by wolfSSL_read().
  2174. \return int This function returns the number of bytes pending.
  2175. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2176. _Example_
  2177. \code
  2178. int pending = 0;
  2179. WOLFSSL* ssl = 0;
  2180. ...
  2181. pending = wolfSSL_pending(ssl);
  2182. printf(“There are %d bytes buffered and available for reading”, pending);
  2183. \endcode
  2184. \sa wolfSSL_recv
  2185. \sa wolfSSL_read
  2186. \sa wolfSSL_peek
  2187. */
  2188. WOLFSSL_API int wolfSSL_pending(WOLFSSL*);
  2189. /*!
  2190. \ingroup Debug
  2191. \brief This function is for OpenSSL compatibility (SSL_load_error_string)
  2192. only and takes no action.
  2193. \return none No returns.
  2194. \param none No parameters.
  2195. _Example_
  2196. \code
  2197. wolfSSL_load_error_strings();
  2198. \endcode
  2199. \sa wolfSSL_get_error
  2200. \sa wolfSSL_ERR_error_string
  2201. \sa wolfSSL_ERR_error_string_n
  2202. \sa wolfSSL_ERR_print_errors_fp
  2203. \sa wolfSSL_load_error_strings
  2204. */
  2205. WOLFSSL_API void wolfSSL_load_error_strings(void);
  2206. /*!
  2207. \ingroup TLS
  2208. \brief This function is called internally in wolfSSL_CTX_new(). This
  2209. function is a wrapper around wolfSSL_Init() and exists for OpenSSL
  2210. compatibility (SSL_library_init) when wolfSSL has been compiled with
  2211. OpenSSL compatibility layer. wolfSSL_Init() is the more typically-used
  2212. wolfSSL initialization function.
  2213. \return SSL_SUCCESS If successful the call will return.
  2214. \return SSL_FATAL_ERROR is returned upon failure.
  2215. \param none No parameters.
  2216. _Example_
  2217. \code
  2218. int ret = 0;
  2219. ret = wolfSSL_library_init();
  2220. if (ret != SSL_SUCCESS) {
  2221. failed to initialize wolfSSL
  2222. }
  2223. ...
  2224. \endcode
  2225. \sa wolfSSL_Init
  2226. \sa wolfSSL_Cleanup
  2227. */
  2228. WOLFSSL_API int wolfSSL_library_init(void);
  2229. /*!
  2230. \ingroup Setup
  2231. \brief This function enables or disables SSL session caching.
  2232. Behavior depends on the value used for mode. The following values
  2233. for mode are available: SSL_SESS_CACHE_OFF- disable session caching.
  2234. Session caching is turned on by default. SSL_SESS_CACHE_NO_AUTO_CLEAR -
  2235. Disable auto-flushing of the session cache. Auto-flushing is turned on
  2236. by default.
  2237. \return SSL_SUCCESS will be returned upon success.
  2238. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2239. \param mode modifier used to change behavior of the session cache.
  2240. _Example_
  2241. \code
  2242. WOLFSSL_CTX* ctx = 0;
  2243. ...
  2244. ret = wolfSSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
  2245. if (ret != SSL_SUCCESS) {
  2246. // failed to turn SSL session caching off
  2247. }
  2248. \endcode
  2249. \sa wolfSSL_flush_sessions
  2250. \sa wolfSSL_get_session
  2251. \sa wolfSSL_set_session
  2252. \sa wolfSSL_get_sessionID
  2253. \sa wolfSSL_CTX_set_timeout
  2254. */
  2255. WOLFSSL_API long wolfSSL_CTX_set_session_cache_mode(WOLFSSL_CTX*, long);
  2256. /*!
  2257. \brief This function sets the session secret callback function. The
  2258. SessionSecretCb type has the signature: int (*SessionSecretCb)(WOLFSSL* ssl,
  2259. void* secret, int* secretSz, void* ctx). The sessionSecretCb member of
  2260. the WOLFSSL struct is set to the parameter cb.
  2261. \return SSL_SUCCESS returned if the execution of the function did not
  2262. return an error.
  2263. \return SSL_FATAL_ERROR returned if the WOLFSSL structure is NULL.
  2264. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2265. \param cb a SessionSecretCb type that is a function pointer with the above
  2266. signature.
  2267. _Example_
  2268. \code
  2269. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2270. WOLFSSL* ssl = wolfSSL_new(ctx);
  2271. // Signature of SessionSecretCb
  2272. int SessionSecretCB (WOLFSSL* ssl, void* secret, int* secretSz,
  2273. void* ctx) = SessionSecretCb;
  2274. int wolfSSL_set_session_secret_cb(ssl, SessionSecretCB, (void*)ssl->ctx){
  2275. // Function body.
  2276. }
  2277. \endcode
  2278. \sa SessionSecretCb
  2279. */
  2280. WOLFSSL_API int wolfSSL_set_session_secret_cb(WOLFSSL*, SessionSecretCb, void*);
  2281. /*!
  2282. \ingroup IO
  2283. \brief This function persists the session cache to file. It doesn’t use
  2284. memsave because of additional memory use.
  2285. \return SSL_SUCCESS returned if the function executed without error.
  2286. The session cache has been written to a file.
  2287. \return SSL_BAD_FILE returned if fname cannot be opened or is otherwise
  2288. corrupt.
  2289. \return FWRITE_ERROR returned if XFWRITE failed to write to the file.
  2290. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2291. \param name is a constant char pointer that points to a file for writing.
  2292. _Example_
  2293. \code
  2294. const char* fname;
  2295. ...
  2296. if(wolfSSL_save_session_cache(fname) != SSL_SUCCESS){
  2297. // Fail to write to file.
  2298. }
  2299. \endcode
  2300. \sa XFWRITE
  2301. \sa wolfSSL_restore_session_cache
  2302. \sa wolfSSL_memrestore_session_cache
  2303. */
  2304. WOLFSSL_API int wolfSSL_save_session_cache(const char*);
  2305. /*!
  2306. \ingroup IO
  2307. \brief This function restores the persistent session cache from file. It
  2308. does not use memstore because of additional memory use.
  2309. \return SSL_SUCCESS returned if the function executed without error.
  2310. \return SSL_BAD_FILE returned if the file passed into the function was
  2311. corrupted and could not be opened by XFOPEN.
  2312. \return FREAD_ERROR returned if the file had a read error from XFREAD.
  2313. \return CACHE_MATCH_ERROR returned if the session cache header match
  2314. failed.
  2315. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2316. \param fname a constant char pointer file input that will be read.
  2317. _Example_
  2318. \code
  2319. const char *fname;
  2320. ...
  2321. if(wolfSSL_restore_session_cache(fname) != SSL_SUCCESS){
  2322. // Failure case. The function did not return SSL_SUCCESS.
  2323. }
  2324. \endcode
  2325. \sa XFREAD
  2326. \sa XFOPEN
  2327. */
  2328. WOLFSSL_API int wolfSSL_restore_session_cache(const char*);
  2329. /*!
  2330. \ingroup IO
  2331. \brief This function persists session cache to memory.
  2332. \return SSL_SUCCESS returned if the function executed without error.
  2333. The session cache has been successfully persisted to memory.
  2334. \return BAD_MUTEX_E returned if there was a mutex lock error.
  2335. \return BUFFER_E returned if the buffer size was too small.
  2336. \param mem a void pointer representing the destination for the memory
  2337. copy, XMEMCPY().
  2338. \param sz an int type representing the size of mem.
  2339. _Example_
  2340. \code
  2341. void* mem;
  2342. int sz; // Max size of the memory buffer.
  2343. if(wolfSSL_memsave_session_cache(mem, sz) != SSL_SUCCESS){
  2344. // Failure case, you did not persist the session cache to memory
  2345. }
  2346. \endcode
  2347. \sa XMEMCPY
  2348. \sa wolfSSL_get_session_cache_memsize
  2349. */
  2350. WOLFSSL_API int wolfSSL_memsave_session_cache(void*, int);
  2351. /*!
  2352. \ingroup IO
  2353. \brief This function restores the persistent session cache from memory.
  2354. \return SSL_SUCCESS returned if the function executed without an error.
  2355. \return BUFFER_E returned if the memory buffer is too small.
  2356. \return BAD_MUTEX_E returned if the session cache mutex lock failed.
  2357. \return CACHE_MATCH_ERROR returned if the session cache header match
  2358. failed.
  2359. \param mem a constant void pointer containing the source of the
  2360. restoration.
  2361. \param sz an integer representing the size of the memory buffer.
  2362. _Example_
  2363. \code
  2364. const void* memoryFile;
  2365. int szMf;
  2366. ...
  2367. if(wolfSSL_memrestore_session_cache(memoryFile, szMf) != SSL_SUCCESS){
  2368. // Failure case. SSL_SUCCESS was not returned.
  2369. }
  2370. \endcode
  2371. \sa wolfSSL_save_session_cache
  2372. */
  2373. WOLFSSL_API int wolfSSL_memrestore_session_cache(const void*, int);
  2374. /*!
  2375. \ingroup IO
  2376. \brief This function returns how large the session cache save buffer
  2377. should be.
  2378. \return int This function returns an integer that represents the size of
  2379. the session cache save buffer.
  2380. \param none No parameters.
  2381. _Example_
  2382. \code
  2383. int sz = // Minimum size for error checking;
  2384. ...
  2385. if(sz < wolfSSL_get_session_cache_memsize()){
  2386. // Memory buffer is too small
  2387. }
  2388. \endcode
  2389. \sa wolfSSL_memrestore_session_cache
  2390. */
  2391. WOLFSSL_API int wolfSSL_get_session_cache_memsize(void);
  2392. /*!
  2393. \ingroup CertsKeys
  2394. \brief This function writes the cert cache from memory to file.
  2395. \return SSL_SUCCESS if CM_SaveCertCache exits normally.
  2396. \return BAD_FUNC_ARG is returned if either of the arguments are NULL.
  2397. \return SSL_BAD_FILE if the cert cache save file could not be opened.
  2398. \return BAD_MUTEX_E if the lock mutex failed.
  2399. \return MEMORY_E the allocation of memory failed.
  2400. \return FWRITE_ERROR Certificate cache file write failed.
  2401. \param ctx a pointer to a WOLFSSL_CTX structure, holding the
  2402. certificate information.
  2403. \param fname the cert cache buffer.
  2404. _Example_
  2405. \code
  2406. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  2407. const char* fname;
  2408. ...
  2409. if(wolfSSL_CTX_save_cert_cache(ctx, fname)){
  2410. // file was written.
  2411. }
  2412. \endcode
  2413. \sa CM_SaveCertCache
  2414. \sa DoMemSaveCertCache
  2415. */
  2416. WOLFSSL_API int wolfSSL_CTX_save_cert_cache(WOLFSSL_CTX*, const char*);
  2417. /*!
  2418. \ingroup CertsKeys
  2419. \brief This function persistes certificate cache from a file.
  2420. \return SSL_SUCCESS returned if the function, CM_RestoreCertCache,
  2421. executes normally.
  2422. \return SSL_BAD_FILE returned if XFOPEN returns XBADFILE. The file is
  2423. corrupted.
  2424. \return MEMORY_E returned if the allocated memory for the temp buffer
  2425. fails.
  2426. \return BAD_FUNC_ARG returned if fname or ctx have a NULL value.
  2427. \param ctx a pointer to a WOLFSSL_CTX structure, holding the certificate
  2428. information.
  2429. \param fname the cert cache buffer.
  2430. _Example_
  2431. \code
  2432. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  2433. WOLFSSL* ssl = wolfSSL_new(ctx);
  2434. const char* fname = "path to file";
  2435. ...
  2436. if(wolfSSL_CTX_restore_cert_cache(ctx, fname)){
  2437. // check to see if the execution was successful
  2438. }
  2439. \endcode
  2440. \sa CM_RestoreCertCache
  2441. \sa XFOPEN
  2442. */
  2443. WOLFSSL_API int wolfSSL_CTX_restore_cert_cache(WOLFSSL_CTX*, const char*);
  2444. /*!
  2445. \ingroup CertsKeys
  2446. \brief This function persists the certificate cache to memory.
  2447. \return SSL_SUCCESS returned on successful execution of the function.
  2448. No errors were thrown.
  2449. \return BAD_MUTEX_E mutex error where the WOLFSSL_CERT_MANAGER member
  2450. caLock was not 0 (zero).
  2451. \return BAD_FUNC_ARG returned if ctx, mem, or used is NULL or if sz
  2452. is less than or equal to 0 (zero).
  2453. \return BUFFER_E output buffer mem was too small.
  2454. \param ctx a pointer to a WOLFSSL_CTX structure, created
  2455. using wolfSSL_CTX_new().
  2456. \param mem a void pointer to the destination (output buffer).
  2457. \param sz the size of the output buffer.
  2458. \param used a pointer to size of the cert cache header.
  2459. _Example_
  2460. \code
  2461. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  2462. void* mem;
  2463. int sz;
  2464. int* used;
  2465. ...
  2466. if(wolfSSL_CTX_memsave_cert_cache(ctx, mem, sz, used) != SSL_SUCCESS){
  2467. // The function returned with an error
  2468. }
  2469. \endcode
  2470. \sa DoMemSaveCertCache
  2471. \sa GetCertCacheMemSize
  2472. \sa CM_MemRestoreCertCache
  2473. \sa CM_GetCertCacheMemSize
  2474. */
  2475. WOLFSSL_API int wolfSSL_CTX_memsave_cert_cache(WOLFSSL_CTX*, void*, int, int*);
  2476. /*!
  2477. \ingroup Setup
  2478. \brief This function restores the certificate cache from memory.
  2479. \return SSL_SUCCESS returned if the function and subroutines
  2480. executed without an error.
  2481. \return BAD_FUNC_ARG returned if the ctx or mem parameters are
  2482. NULL or if the sz parameter is less than or equal to zero.
  2483. \return BUFFER_E returned if the cert cache memory buffer is too small.
  2484. \return CACHE_MATCH_ERROR returned if there was a cert cache
  2485. header mismatch.
  2486. \return BAD_MUTEX_E returned if the lock mutex on failed.
  2487. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  2488. wolfSSL_CTX_new().
  2489. \param mem a void pointer with a value that will be restored to
  2490. the certificate cache.
  2491. \param sz an int type that represents the size of the mem parameter.
  2492. _Example_
  2493. \code
  2494. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  2495. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2496. void* mem;
  2497. int sz = (*int) sizeof(mem);
  2498. if(wolfSSL_CTX_memrestore_cert_cache(ssl->ctx, mem, sz)){
  2499. // The success case
  2500. }
  2501. \endcode
  2502. \sa CM_MemRestoreCertCache
  2503. */
  2504. WOLFSSL_API int wolfSSL_CTX_memrestore_cert_cache(WOLFSSL_CTX*, const void*, int);
  2505. /*!
  2506. \ingroup CertsKeys
  2507. \brief Returns the size the certificate cache save buffer needs to be.
  2508. \return int integer value returned representing the memory size
  2509. upon success.
  2510. \return BAD_FUNC_ARG is returned if the WOLFSSL_CTX struct is NULL.
  2511. \return BAD_MUTEX_E - returned if there was a mutex lock error.
  2512. \param ctx a pointer to a wolfSSL_CTX structure, created using
  2513. wolfSSL_CTX_new().
  2514. _Example_
  2515. \code
  2516. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol);
  2517. ...
  2518. int certCacheSize = wolfSSL_CTX_get_cert_cache_memsize(ctx);
  2519. if(certCacheSize != BAD_FUNC_ARG || certCacheSize != BAD_MUTEX_E){
  2520. // Successfully retrieved the memory size.
  2521. }
  2522. \endcode
  2523. \sa CM_GetCertCacheMemSize
  2524. */
  2525. WOLFSSL_API int wolfSSL_CTX_get_cert_cache_memsize(WOLFSSL_CTX*);
  2526. /*!
  2527. \ingroup Setup
  2528. \brief This function sets cipher suite list for a given WOLFSSL_CTX.
  2529. This cipher suite list becomes the default list for any new SSL sessions
  2530. (WOLFSSL) created using this context. The ciphers in the list should be
  2531. sorted in order of preference from highest to lowest. Each call to
  2532. wolfSSL_CTX_set_cipher_list() resets the cipher suite list for the
  2533. specific SSL context to the provided list each time the function is
  2534. called. The cipher suite list, list, is a null-terminated text string,
  2535. and a colon-delimited list. For example, one value for list may be
  2536. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256" Valid cipher
  2537. values are the full name values from the cipher_names[] array in
  2538. src/internal.c (for a definite list of valid cipher values check
  2539. src/internal.c)
  2540. \return SSL_SUCCESS will be returned upon successful function completion.
  2541. \return SSL_FAILURE will be returned on failure.
  2542. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2543. \param list null-terminated text string and a colon-delimited list of
  2544. cipher suites to use with the specified SSL context.
  2545. _Example_
  2546. \code
  2547. WOLFSSL_CTX* ctx = 0;
  2548. ...
  2549. ret = wolfSSL_CTX_set_cipher_list(ctx,
  2550. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2551. if (ret != SSL_SUCCESS) {
  2552. // failed to set cipher suite list
  2553. }
  2554. \endcode
  2555. \sa wolfSSL_set_cipher_list
  2556. \sa wolfSSL_CTX_new
  2557. */
  2558. WOLFSSL_API int wolfSSL_CTX_set_cipher_list(WOLFSSL_CTX*, const char*);
  2559. /*!
  2560. \ingroup Setup
  2561. \brief This function sets cipher suite list for a given WOLFSSL object
  2562. (SSL session). The ciphers in the list should be sorted in order of
  2563. preference from highest to lowest. Each call to wolfSSL_set_cipher_list()
  2564. resets the cipher suite list for the specific SSL session to the provided
  2565. list each time the function is called. The cipher suite list, list, is a
  2566. null-terminated text string, and a colon-delimited list. For example, one
  2567. value for list may be
  2568. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256".
  2569. Valid cipher values are the full name values from the cipher_names[]
  2570. array in src/internal.c (for a definite list of valid cipher values
  2571. check src/internal.c)
  2572. \return SSL_SUCCESS will be returned upon successful function completion.
  2573. \return SSL_FAILURE will be returned on failure.
  2574. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2575. \param list null-terminated text string and a colon-delimited list of
  2576. cipher suites to use with the specified SSL session.
  2577. _Example_
  2578. \code
  2579. int ret = 0;
  2580. WOLFSSL* ssl = 0;
  2581. ...
  2582. ret = wolfSSL_set_cipher_list(ssl,
  2583. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2584. if (ret != SSL_SUCCESS) {
  2585. // failed to set cipher suite list
  2586. }
  2587. \endcode
  2588. \sa wolfSSL_CTX_set_cipher_list
  2589. \sa wolfSSL_new
  2590. */
  2591. WOLFSSL_API int wolfSSL_set_cipher_list(WOLFSSL*, const char*);
  2592. /*!
  2593. \brief This function informs the WOLFSSL DTLS object that the underlying
  2594. UDP I/O is non-blocking. After an application creates a WOLFSSL object,
  2595. if it will be used with a non-blocking UDP socket, call
  2596. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2597. that receiving EWOULDBLOCK means that the recvfrom call would
  2598. block rather than that it timed out.
  2599. \return none No return.
  2600. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2601. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  2602. Use 1 to specify non-blocking, otherwise 0.
  2603. _Example_
  2604. \code
  2605. WOLFSSL* ssl = 0;
  2606. ...
  2607. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  2608. \endcode
  2609. \sa wolfSSL_dtls_get_using_nonblock
  2610. \sa wolfSSL_dtls_got_timeout
  2611. \sa wolfSSL_dtls_get_current_timeout
  2612. */
  2613. WOLFSSL_API void wolfSSL_dtls_set_using_nonblock(WOLFSSL*, int);
  2614. /*!
  2615. \brief This function allows the application to determine if wolfSSL is
  2616. using non-blocking I/O with UDP. If wolfSSL is using non-blocking I/O, this
  2617. function will return 1, otherwise 0. After an application creates a
  2618. WOLFSSL object, if it will be used with a non-blocking UDP socket, call
  2619. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2620. that receiving EWOULDBLOCK means that the recvfrom call would block
  2621. rather than that it timed out. This function is only meaningful to DTLS
  2622. sessions.
  2623. \return 0 underlying I/O is blocking.
  2624. \return 1 underlying I/O is non-blocking.
  2625. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2626. _Example_
  2627. \code
  2628. int ret = 0;
  2629. WOLFSSL* ssl = 0;
  2630. ...
  2631. ret = wolfSSL_dtls_get_using_nonblock(ssl);
  2632. if (ret == 1) {
  2633. // underlying I/O is non-blocking
  2634. }
  2635. ...
  2636. \endcode
  2637. \sa wolfSSL_dtls_set_using_nonblock
  2638. \sa wolfSSL_dtls_got_timeout
  2639. \sa wolfSSL_dtls_set_using_nonblock
  2640. */
  2641. WOLFSSL_API int wolfSSL_dtls_get_using_nonblock(WOLFSSL*);
  2642. /*!
  2643. \brief This function returns the current timeout value in seconds for
  2644. the WOLFSSL object. When using non-blocking sockets, something in the user
  2645. code needs to decide when to check for available recv data and how long
  2646. it has been waiting. The value returned by this function indicates how
  2647. long the application should wait.
  2648. \return seconds The current DTLS timeout value in seconds
  2649. \return NOT_COMPILED_IN if wolfSSL was not built with DTLS support.
  2650. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2651. _Example_
  2652. \code
  2653. int timeout = 0;
  2654. WOLFSSL* ssl;
  2655. ...
  2656. timeout = wolfSSL_get_dtls_current_timeout(ssl);
  2657. printf(“DTLS timeout (sec) = %d\n”, timeout);
  2658. \endcode
  2659. \sa wolfSSL_dtls
  2660. \sa wolfSSL_dtls_get_peer
  2661. \sa wolfSSL_dtls_got_timeout
  2662. \sa wolfSSL_dtls_set_peer
  2663. */
  2664. WOLFSSL_API int wolfSSL_dtls_get_current_timeout(WOLFSSL* ssl);
  2665. /*!
  2666. \ingroup Setup
  2667. \brief This function sets the dtls timeout.
  2668. \return SSL_SUCCESS returned if the function executes without an error.
  2669. The dtls_timeout_init and the dtls_timeout members of SSL have been set.
  2670. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  2671. the timeout is not greater than 0. It will also return if the timeout
  2672. argument exceeds the maximum value allowed.
  2673. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2674. \param timeout an int type that will be set to the dtls_timeout_init
  2675. member of the WOLFSSL structure.
  2676. _Example_
  2677. \code
  2678. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2679. WOLFSSL* ssl = wolfSSL_new(ctx);
  2680. int timeout = TIMEOUT;
  2681. ...
  2682. if(wolfSSL_dtls_set_timeout_init(ssl, timeout)){
  2683. // the dtls timeout was set
  2684. } else {
  2685. // Failed to set DTLS timeout.
  2686. }
  2687. \endcode
  2688. \sa wolfSSL_dtls_set_timeout_max
  2689. \sa wolfSSL_dtls_got_timeout
  2690. */
  2691. WOLFSSL_API int wolfSSL_dtls_set_timeout_init(WOLFSSL* ssl, int);
  2692. /*!
  2693. \brief This function sets the maximum dtls timeout.
  2694. \return SSL_SUCCESS returned if the function executed without an error.
  2695. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  2696. the timeout argument is not greater than zero or is less than the
  2697. dtls_timeout_init member of the WOLFSSL structure.
  2698. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2699. \param timeout an int type representing the dtls maximum timeout.
  2700. _Example_
  2701. \code
  2702. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2703. WOLFSSL* ssl = wolfSSL_new(ctx);
  2704. int timeout = TIMEOUTVAL;
  2705. ...
  2706. int ret = wolfSSL_dtls_set_timeout_max(ssl);
  2707. if(!ret){
  2708. // Failed to set the max timeout
  2709. }
  2710. \endcode
  2711. \sa wolfSSL_dtls_set_timeout_init
  2712. \sa wolfSSL_dtls_got_timeout
  2713. */
  2714. WOLFSSL_API int wolfSSL_dtls_set_timeout_max(WOLFSSL* ssl, int);
  2715. /*!
  2716. \brief When using non-blocking sockets with DTLS, this function should
  2717. be called on the WOLFSSL object when the controlling code thinks the
  2718. transmission has timed out. It performs the actions needed to retry
  2719. the last transmit, including adjusting the timeout value. If it
  2720. has been too long, this will return a failure.
  2721. \return SSL_SUCCESS will be returned upon success
  2722. \return SSL_FATAL_ERROR will be returned if there have been too many
  2723. retransmissions/timeouts without getting a response from the peer.
  2724. \return NOT_COMPILED_IN will be returned if wolfSSL was not compiled with
  2725. DTLS support.
  2726. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2727. _Example_
  2728. \code
  2729. See the following files for usage examples:
  2730. <wolfssl_root>/examples/client/client.c
  2731. <wolfssl_root>/examples/server/server.c
  2732. \endcode
  2733. \sa wolfSSL_dtls_get_current_timeout
  2734. \sa wolfSSL_dtls_get_peer
  2735. \sa wolfSSL_dtls_set_peer
  2736. \sa wolfSSL_dtls
  2737. */
  2738. WOLFSSL_API int wolfSSL_dtls_got_timeout(WOLFSSL* ssl);
  2739. /*!
  2740. \brief This function is used to determine if the SSL session has been
  2741. configured to use DTLS.
  2742. \return 1 If the SSL session (ssl) has been configured to use DTLS, this
  2743. function will return 1.
  2744. \return 0 otherwise.
  2745. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2746. _Example_
  2747. \code
  2748. int ret = 0;
  2749. WOLFSSL* ssl;
  2750. ...
  2751. ret = wolfSSL_dtls(ssl);
  2752. if (ret) {
  2753. // SSL session has been configured to use DTLS
  2754. }
  2755. \endcode
  2756. \sa wolfSSL_dtls_get_current_timeout
  2757. \sa wolfSSL_dtls_get_peer
  2758. \sa wolfSSL_dtls_got_timeout
  2759. \sa wolfSSL_dtls_set_peer
  2760. */
  2761. WOLFSSL_API int wolfSSL_dtls(WOLFSSL* ssl);
  2762. /*!
  2763. \brief This function sets the DTLS peer, peer (sockaddr_in) with size of
  2764. peerSz.
  2765. \return SSL_SUCCESS will be returned upon success.
  2766. \return SSL_FAILURE will be returned upon failure.
  2767. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  2768. with DTLS support.
  2769. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2770. \param peer pointer to peer’s sockaddr_in structure.
  2771. \param peerSz size of the sockaddr_in structure pointed to by peer.
  2772. _Example_
  2773. \code
  2774. int ret = 0;
  2775. WOLFSSL* ssl;
  2776. sockaddr_in addr;
  2777. ...
  2778. ret = wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
  2779. if (ret != SSL_SUCCESS) {
  2780. // failed to set DTLS peer
  2781. }
  2782. \endcode
  2783. \sa wolfSSL_dtls_get_current_timeout
  2784. \sa wolfSSL_dtls_get_peer
  2785. \sa wolfSSL_dtls_got_timeout
  2786. \sa wolfSSL_dtls
  2787. */
  2788. WOLFSSL_API int wolfSSL_dtls_set_peer(WOLFSSL*, void*, unsigned int);
  2789. /*!
  2790. \brief This function gets the sockaddr_in (of size peerSz) of the current
  2791. DTLS peer. The function will compare peerSz to the actual DTLS peer size
  2792. stored in the SSL session. If the peer will fit into peer, the peer’s
  2793. sockaddr_in will be copied into peer, with peerSz set to the size of peer.
  2794. \return SSL_SUCCESS will be returned upon success.
  2795. \return SSL_FAILURE will be returned upon failure.
  2796. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  2797. with DTLS support.
  2798. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2799. \param peer pointer to memory location to store peer’s sockaddr_in
  2800. structure.
  2801. \param peerSz input/output size. As input, the size of the allocated memory
  2802. pointed to by peer. As output, the size of the actual sockaddr_in structure
  2803. pointed to by peer.
  2804. _Example_
  2805. \code
  2806. int ret = 0;
  2807. WOLFSSL* ssl;
  2808. sockaddr_in addr;
  2809. ...
  2810. ret = wolfSSL_dtls_get_peer(ssl, &addr, sizeof(addr));
  2811. if (ret != SSL_SUCCESS) {
  2812. // failed to get DTLS peer
  2813. }
  2814. \endcode
  2815. \sa wolfSSL_dtls_get_current_timeout
  2816. \sa wolfSSL_dtls_got_timeout
  2817. \sa wolfSSL_dtls_set_peer
  2818. \sa wolfSSL_dtls
  2819. */
  2820. WOLFSSL_API int wolfSSL_dtls_get_peer(WOLFSSL*, void*, unsigned int*);
  2821. /*!
  2822. \ingroup Debug
  2823. \brief This function converts an error code returned by
  2824. wolfSSL_get_error() into a more human-readable error string.
  2825. errNumber is the error code returned by wolfSSL_get_error() and data
  2826. is the storage buffer which the error string will be placed in.
  2827. The maximum length of data is 80 characters by default, as defined by
  2828. MAX_ERROR_SZ is wolfssl/wolfcrypt/error.h.
  2829. \return success On successful completion, this function returns the same
  2830. string as is returned in data.
  2831. \return failure Upon failure, this function returns a string with the
  2832. appropriate failure reason, msg.
  2833. \param errNumber error code returned by wolfSSL_get_error().
  2834. \param data output buffer containing human-readable error string matching
  2835. errNumber.
  2836. _Example_
  2837. \code
  2838. int err = 0;
  2839. WOLFSSL* ssl;
  2840. char buffer[80];
  2841. ...
  2842. err = wolfSSL_get_error(ssl, 0);
  2843. wolfSSL_ERR_error_string(err, buffer);
  2844. printf(“err = %d, %s\n”, err, buffer);
  2845. \endcode
  2846. \sa wolfSSL_get_error
  2847. \sa wolfSSL_ERR_error_string_n
  2848. \sa wolfSSL_ERR_print_errors_fp
  2849. \sa wolfSSL_load_error_strings
  2850. */
  2851. WOLFSSL_API char* wolfSSL_ERR_error_string(unsigned long,char*);
  2852. /*!
  2853. \ingroup Debug
  2854. \brief This function is a version of wolfSSL_ERR_error_string() where
  2855. len specifies the maximum number of characters that may be written to buf.
  2856. Like wolfSSL_ERR_error_string(), this function converts an error code
  2857. returned from wolfSSL_get_error() into a more human-readable error string.
  2858. The human-readable string is placed in buf.
  2859. \return none No returns.
  2860. \param e error code returned by wolfSSL_get_error().
  2861. \param buff output buffer containing human-readable error string matching e.
  2862. \param len maximum length in characters which may be written to buf.
  2863. _Example_
  2864. \code
  2865. int err = 0;
  2866. WOLFSSL* ssl;
  2867. char buffer[80];
  2868. ...
  2869. err = wolfSSL_get_error(ssl, 0);
  2870. wolfSSL_ERR_error_string_n(err, buffer, 80);
  2871. printf(“err = %d, %s\n”, err, buffer);
  2872. \endcode
  2873. \sa wolfSSL_get_error
  2874. \sa wolfSSL_ERR_error_string
  2875. \sa wolfSSL_ERR_print_errors_fp
  2876. \sa wolfSSL_load_error_strings
  2877. */
  2878. WOLFSSL_API void wolfSSL_ERR_error_string_n(unsigned long e, char* buf,
  2879. unsigned long sz);
  2880. /*!
  2881. \ingroup TLS
  2882. \brief This function checks the shutdown conditions in closeNotify or
  2883. connReset or sentNotify members of the Options structure. The Options
  2884. structure is within the WOLFSSL structure.
  2885. \return 1 SSL_SENT_SHUTDOWN is returned.
  2886. \return 2 SS_RECEIVED_SHUTDOWN is returned.
  2887. \param ssl a constant pointer to a WOLFSSL structure, created using
  2888. wolfSSL_new().
  2889. _Example_
  2890. \code
  2891. #include <wolfssl/ssl.h>
  2892. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  2893. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2894. int ret;
  2895. ret = wolfSSL_get_shutdown(ssl);
  2896. if(ret == 1){
  2897. SSL_SENT_SHUTDOWN
  2898. } else if(ret == 2){
  2899. SSL_RECEIVED_SHUTDOWN
  2900. } else {
  2901. Fatal error.
  2902. }
  2903. \endcode
  2904. \sa wolfSSL_SESSION_free
  2905. */
  2906. WOLFSSL_API int wolfSSL_get_shutdown(const WOLFSSL*);
  2907. /*!
  2908. \ingroup IO
  2909. \brief This function returns the resuming member of the options struct. The
  2910. flag indicates whether or not to reuse a session. If not, a new session must
  2911. be established.
  2912. \return This function returns an int type held in the Options structure
  2913. representing the flag for session reuse.
  2914. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2915. _Example_
  2916. \code
  2917. WOLFSSL* ssl = wolfSSL_new(ctx);
  2918. if(!wolfSSL_session_reused(sslResume)){
  2919. // No session reuse allowed.
  2920. }
  2921. \endcode
  2922. \sa wolfSSL_SESSION_free
  2923. \sa wolfSSL_GetSessionIndex
  2924. \sa wolfSSL_memsave_session_cache
  2925. */
  2926. WOLFSSL_API int wolfSSL_session_reused(WOLFSSL*);
  2927. /*!
  2928. \ingroup TLS
  2929. \brief This function checks to see if the connection is established.
  2930. \return 0 returned if the connection is not established, i.e. the WOLFSSL
  2931. struct is NULL or the handshake is not done.
  2932. \return 1 returned if the connection is not established i.e. the WOLFSSL
  2933. struct is null or the handshake is not done.
  2934. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2935. _EXAMPLE_
  2936. \code
  2937. #include <wolfssl/ssl.h>
  2938. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  2939. WOLFSSL* ssl = wolfSSL_new(ctx);
  2940. ...
  2941. if(wolfSSL_is_init_finished(ssl)){
  2942. Handshake is done and connection is established
  2943. }
  2944. \endcode
  2945. \sa wolfSSL_set_accept_state
  2946. \sa wolfSSL_get_keys
  2947. \sa wolfSSL_set_shutdown
  2948. */
  2949. WOLFSSL_API int wolfSSL_is_init_finished(WOLFSSL*);
  2950. /*!
  2951. \ingroup IO
  2952. \brief Returns the SSL version being used as a string.
  2953. \return "SSLv3" Using SSLv3
  2954. \return "TLSv1" Using TLSv1
  2955. \return "TLSv1.1" Using TLSv1.1
  2956. \return "TLSv1.2" Using TLSv1.2
  2957. \return "TLSv1.3" Using TLSv1.3
  2958. \return "DTLS": Using DTLS
  2959. \return "DTLSv1.2" Using DTLSv1.2
  2960. \return "unknown" There was a problem determining which version of TLS
  2961. being used.
  2962. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2963. _Example_
  2964. \code
  2965. wolfSSL_Init();
  2966. WOLFSSL_CTX* ctx;
  2967. WOLFSSL* ssl;
  2968. WOLFSSL_METHOD method = // Some wolfSSL method
  2969. ctx = wolfSSL_CTX_new(method);
  2970. ssl = wolfSSL_new(ctx);
  2971. printf(wolfSSL_get_version("Using version: %s", ssl));
  2972. \endcode
  2973. \sa wolfSSL_lib_version
  2974. */
  2975. WOLFSSL_API const char* wolfSSL_get_version(WOLFSSL*);
  2976. /*!
  2977. \ingroup IO
  2978. \brief Returns the current cipher suit an ssl session is using.
  2979. \return ssl->options.cipherSuite An integer representing the current
  2980. cipher suite.
  2981. \return 0 The ssl session provided is null.
  2982. \param ssl The SSL session to check.
  2983. _Example_
  2984. \code
  2985. wolfSSL_Init();
  2986. WOLFSSL_CTX* ctx;
  2987. WOLFSSL* ssl;
  2988. WOLFSSL_METHOD method = // Some wolfSSL method
  2989. ctx = wolfSSL_CTX_new(method);
  2990. ssl = wolfSSL_new(ctx);
  2991. if(wolfSSL_get_current_cipher_suite(ssl) == 0)
  2992. {
  2993. // Error getting cipher suite
  2994. }
  2995. \endcode
  2996. \sa wolfSSL_CIPHER_get_name
  2997. \sa wolfSSL_get_current_cipher
  2998. \sa wolfSSL_get_cipher_list
  2999. */
  3000. WOLFSSL_API int wolfSSL_get_current_cipher_suite(WOLFSSL* ssl);
  3001. /*!
  3002. \ingroup IO
  3003. \brief This function returns a pointer to the current cipher in the
  3004. ssl session.
  3005. \return The function returns the address of the cipher member of the
  3006. WOLFSSL struct. This is a pointer to the WOLFSSL_CIPHER structure.
  3007. \return NULL returned if the WOLFSSL structure is NULL.
  3008. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3009. _Example_
  3010. \code
  3011. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3012. WOLFSSL* ssl = wolfSSL_new(ctx);
  3013. WOLFSSL_CIPHER* cipherCurr = wolfSSL_get_current_cipher;
  3014. if(!cipherCurr){
  3015. // Failure case.
  3016. } else {
  3017. // The cipher was returned to cipherCurr
  3018. }
  3019. \endcode
  3020. \sa wolfSSL_get_cipher
  3021. \sa wolfSSL_get_cipher_name_internal
  3022. \sa wolfSSL_get_cipher_name
  3023. */
  3024. WOLFSSL_API WOLFSSL_CIPHER* wolfSSL_get_current_cipher(WOLFSSL*);
  3025. /*!
  3026. \ingroup IO
  3027. \brief This function matches the cipher suite in the SSL object with
  3028. the available suites and returns the string representation.
  3029. \return string This function returns the string representation of the
  3030. matched cipher suite.
  3031. \return none It will return “None” if there are no suites matched.
  3032. \param cipher a constant pointer to a WOLFSSL_CIPHER structure.
  3033. _Example_
  3034. \code
  3035. // gets cipher name in the format DHE_RSA ...
  3036. const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl){
  3037. WOLFSSL_CIPHER* cipher;
  3038. const char* fullName;
  3039. cipher = wolfSSL_get_curent_cipher(ssl);
  3040. fullName = wolfSSL_CIPHER_get_name(cipher);
  3041. if(fullName){
  3042. // sanity check on returned cipher
  3043. }
  3044. \endcode
  3045. \sa wolfSSL_get_cipher
  3046. \sa wolfSSL_get_current_cipher
  3047. \sa wolfSSL_get_cipher_name_internal
  3048. \sa wolfSSL_get_cipher_name
  3049. */
  3050. WOLFSSL_API const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher);
  3051. /*!
  3052. \ingroup IO
  3053. \brief This function matches the cipher suite in the SSL object with
  3054. the available suites.
  3055. \return This function returns the string value of the suite matched. It
  3056. will return “None” if there are no suites matched.
  3057. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3058. _Example_
  3059. \code
  3060. #ifdef WOLFSSL_DTLS
  3061. // make sure a valid suite is used
  3062. if(wolfSSL_get_cipher(ssl) == NULL){
  3063. WOLFSSL_MSG(“Can not match cipher suite imported”);
  3064. return MATCH_SUITE_ERROR;
  3065. }
  3066. #endif // WOLFSSL_DTLS
  3067. \endcode
  3068. \sa wolfSSL_CIPHER_get_name
  3069. \sa wolfSSL_get_current_cipher
  3070. */
  3071. WOLFSSL_API const char* wolfSSL_get_cipher(WOLFSSL*);
  3072. /*!
  3073. \ingroup Setup
  3074. \brief This function returns the WOLFSSL_SESSION from the WOLFSSL structure.
  3075. \return WOLFSSL_SESSION On success return session pointer.
  3076. \return NULL on failure returns NULL.
  3077. \param ssl WOLFSSL structure to get session from.
  3078. _Example_
  3079. \code
  3080. WOLFSSL* ssl;
  3081. WOLFSSL_SESSION* ses;
  3082. // attempt/complete handshake
  3083. ses = wolfSSL_get1_session(ssl);
  3084. // check ses information
  3085. \endcode
  3086. \sa wolfSSL_new
  3087. \sa wolfSSL_free
  3088. */
  3089. WOLFSSL_API WOLFSSL_SESSION* wolfSSL_get1_session(WOLFSSL* ssl);
  3090. /*!
  3091. \ingroup Setup
  3092. \brief The wolfSSLv23_client_method() function is used to indicate that
  3093. the application is a client and will support the highest protocol
  3094. version supported by the server between SSL 3.0 - TLS 1.2. This function
  3095. allocates memory for and initializes a new WOLFSSL_METHOD structure
  3096. to be used when creating the SSL/TLS context with wolfSSL_CTX_new().
  3097. Both wolfSSL clients and servers have robust version downgrade capability.
  3098. If a specific protocol version method is used on either side, then only
  3099. that version will be negotiated or an error will be returned. For
  3100. example, a client that uses TLSv1 and tries to connect to a SSLv3 only
  3101. server will fail, likewise connecting to a TLSv1.1 will fail as well.
  3102. To resolve this issue, a client that uses the wolfSSLv23_client_method()
  3103. function will use the highest protocol version supported by the server and
  3104. downgrade to SSLv3 if needed. In this case, the client will be able to
  3105. connect to a server running SSLv3 - TLSv1.2.
  3106. \return pointer upon success a pointer to a WOLFSSL_METHOD.
  3107. \return Failure If memory allocation fails when calling XMALLOC,
  3108. the failure value of the underlying malloc() implementation will be
  3109. returned (typically NULL with errno will be set to ENOMEM).
  3110. \param none No parameters
  3111. _Example_
  3112. \code
  3113. WOLFSSL_METHOD* method;
  3114. WOLFSSL_CTX* ctx;
  3115. method = wolfSSLv23_client_method();
  3116. if (method == NULL) {
  3117. // unable to get method
  3118. }
  3119. ctx = wolfSSL_CTX_new(method);
  3120. ...
  3121. \endcode
  3122. \sa wolfSSLv3_client_method
  3123. \sa wolfTLSv1_client_method
  3124. \sa wolfTLSv1_1_client_method
  3125. \sa wolfTLSv1_2_client_method
  3126. \sa wolfDTLSv1_client_method
  3127. \sa wolfSSL_CTX_new
  3128. */
  3129. WOLFSSL_API WOLFSSL_METHOD* wolfSSLv23_client_method(void);
  3130. /*!
  3131. \ingroup IO
  3132. \brief This is used to set a byte pointer to the start of the
  3133. internal memory buffer.
  3134. \return size On success the size of the buffer is returned
  3135. \return SSL_FATAL_ERROR If an error case was encountered.
  3136. \param bio WOLFSSL_BIO structure to get memory buffer of.
  3137. \param p byte pointer to set to memory buffer.
  3138. _Example_
  3139. \code
  3140. WOLFSSL_BIO* bio;
  3141. const byte* p;
  3142. int ret;
  3143. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3144. ret = wolfSSL_BIO_get_mem_data(bio, &p);
  3145. // check ret value
  3146. \endcode
  3147. \sa wolfSSL_BIO_new
  3148. \sa wolfSSL_BIO_s_mem
  3149. \sa wolfSSL_BIO_set_fp
  3150. \sa wolfSSL_BIO_free
  3151. */
  3152. WOLFSSL_API int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);
  3153. /*!
  3154. \ingroup IO
  3155. \brief Sets the file descriptor for bio to use.
  3156. \return SSL_SUCCESS(1) upon success.
  3157. \param bio WOLFSSL_BIO structure to set fd.
  3158. \param fd file descriptor to use.
  3159. \param closeF flag for behavior when closing fd.
  3160. _Example_
  3161. \code
  3162. WOLFSSL_BIO* bio;
  3163. int fd;
  3164. // setup bio
  3165. wolfSSL_BIO_set_fd(bio, fd, BIO_NOCLOSE);
  3166. \endcode
  3167. \sa wolfSSL_BIO_new
  3168. \sa wolfSSL_BIO_free
  3169. */
  3170. WOLFSSL_API long wolfSSL_BIO_set_fd(WOLFSSL_BIO* b, int fd, int flag);
  3171. /*!
  3172. \ingroup IO
  3173. \brief Sets the close flag, used to indicate that the i/o stream should be
  3174. closed when the BIO is freed
  3175. \return SSL_SUCCESS(1) upon success.
  3176. \param bio WOLFSSL_BIO structure.
  3177. \param flag flag for behavior when closing i/o stream.
  3178. _Example_
  3179. \code
  3180. WOLFSSL_BIO* bio;
  3181. // setup bio
  3182. wolfSSL_BIO_set_close(bio, BIO_NOCLOSE);
  3183. \endcode
  3184. \sa wolfSSL_BIO_new
  3185. \sa wolfSSL_BIO_free
  3186. */
  3187. WOLFSSL_API int wolfSSL_BIO_set_close(WOLFSSL_BIO *b, long flag);
  3188. /*!
  3189. \ingroup IO
  3190. \brief This is used to get a BIO_SOCKET type WOLFSSL_BIO_METHOD.
  3191. \return WOLFSSL_BIO_METHOD pointer to a WOLFSSL_BIO_METHOD structure
  3192. that is a socket type
  3193. \param none No parameters.
  3194. _Example_
  3195. \code
  3196. WOLFSSL_BIO* bio;
  3197. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket);
  3198. \endcode
  3199. \sa wolfSSL_BIO_new
  3200. \sa wolfSSL_BIO_s_mem
  3201. */
  3202. WOLFSSL_API WOLFSSL_BIO_METHOD *wolfSSL_BIO_s_socket(void);
  3203. /*!
  3204. \ingroup IO
  3205. \brief This is used to set the size of write buffer for a
  3206. WOLFSSL_BIO. If write buffer has been previously set this
  3207. function will free it when resetting the size. It is similar to
  3208. wolfSSL_BIO_reset in that it resets read and write indexes to 0.
  3209. \return SSL_SUCCESS On successfully setting the write buffer.
  3210. \return SSL_FAILURE If an error case was encountered.
  3211. \param bio WOLFSSL_BIO structure to set fd.
  3212. \param size size of buffer to allocate.
  3213. _Example_
  3214. \code
  3215. WOLFSSL_BIO* bio;
  3216. int ret;
  3217. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3218. ret = wolfSSL_BIO_set_write_buf_size(bio, 15000);
  3219. // check return value
  3220. \endcode
  3221. \sa wolfSSL_BIO_new
  3222. \sa wolfSSL_BIO_s_mem
  3223. \sa wolfSSL_BIO_free
  3224. */
  3225. WOLFSSL_API int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *b, long size);
  3226. /*!
  3227. \ingroup IO
  3228. \brief This is used to pair two bios together. A pair of bios acts
  3229. similar to a two way pipe writing to one can be read by the other
  3230. and vice versa. It is expected that both bios be in the same thread,
  3231. this function is not thread safe. Freeing one of the two bios removes
  3232. both from being paired. If a write buffer size was not previously
  3233. set for either of the bios it is set to a default size of 17000
  3234. (WOLFSSL_BIO_SIZE) before being paired.
  3235. \return SSL_SUCCESS On successfully pairing the two bios.
  3236. \return SSL_FAILURE If an error case was encountered.
  3237. \param b1 WOLFSSL_BIO structure to set pair.
  3238. \param b2 second WOLFSSL_BIO structure to complete pair.
  3239. _Example_
  3240. \code
  3241. WOLFSSL_BIO* bio;
  3242. WOLFSSL_BIO* bio2;
  3243. int ret;
  3244. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3245. bio2 = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3246. ret = wolfSSL_BIO_make_bio_pair(bio, bio2);
  3247. // check ret value
  3248. \endcode
  3249. \sa wolfSSL_BIO_new
  3250. \sa wolfSSL_BIO_s_mem
  3251. \sa wolfSSL_BIO_free
  3252. */
  3253. WOLFSSL_API int wolfSSL_BIO_make_bio_pair(WOLFSSL_BIO *b1, WOLFSSL_BIO *b2);
  3254. /*!
  3255. \ingroup IO
  3256. \brief This is used to set the read request flag back to 0.
  3257. \return SSL_SUCCESS On successfully setting value.
  3258. \return SSL_FAILURE If an error case was encountered.
  3259. \param bio WOLFSSL_BIO structure to set read request flag.
  3260. _Example_
  3261. \code
  3262. WOLFSSL_BIO* bio;
  3263. int ret;
  3264. ...
  3265. ret = wolfSSL_BIO_ctrl_reset_read_request(bio);
  3266. // check ret value
  3267. \endcode
  3268. \sa wolfSSL_BIO_new, wolfSSL_BIO_s_mem
  3269. \sa wolfSSL_BIO_new, wolfSSL_BIO_free
  3270. */
  3271. WOLFSSL_API int wolfSSL_BIO_ctrl_reset_read_request(WOLFSSL_BIO *b);
  3272. /*!
  3273. \ingroup IO
  3274. \brief This is used to get a buffer pointer for reading from. Unlike
  3275. wolfSSL_BIO_nread the internal read index is not advanced by the number
  3276. returned from the function call. Reading past the value returned can
  3277. result in reading out of array bounds.
  3278. \return >=0 on success return the number of bytes to read
  3279. \param bio WOLFSSL_BIO structure to read from.
  3280. \param buf pointer to set at beginning of read array.
  3281. _Example_
  3282. \code
  3283. WOLFSSL_BIO* bio;
  3284. char* bufPt;
  3285. int ret;
  3286. // set up bio
  3287. ret = wolfSSL_BIO_nread0(bio, &bufPt); // read as many bytes as possible
  3288. // handle negative ret check
  3289. // read ret bytes from bufPt
  3290. \endcode
  3291. \sa wolfSSL_BIO_new
  3292. \sa wolfSSL_BIO_nwrite0
  3293. */
  3294. WOLFSSL_API int wolfSSL_BIO_nread0(WOLFSSL_BIO *bio, char **buf);
  3295. /*!
  3296. \ingroup IO
  3297. \brief This is used to get a buffer pointer for reading from. The internal
  3298. read index is advanced by the number returned from the function call with
  3299. buf being pointed to the beginning of the buffer to read from. In the
  3300. case that less bytes are in the read buffer than the value requested with
  3301. num the lesser value is returned. Reading past the value returned can
  3302. result in reading out of array bounds.
  3303. \return >=0 on success return the number of bytes to read
  3304. \return WOLFSSL_BIO_ERROR(-1) on error case with nothing to read return -1
  3305. \param bio WOLFSSL_BIO structure to read from.
  3306. \param buf pointer to set at beginning of read array.
  3307. \param num number of bytes to try and read.
  3308. _Example_
  3309. \code
  3310. WOLFSSL_BIO* bio;
  3311. char* bufPt;
  3312. int ret;
  3313. // set up bio
  3314. ret = wolfSSL_BIO_nread(bio, &bufPt, 10); // try to read 10 bytes
  3315. // handle negative ret check
  3316. // read ret bytes from bufPt
  3317. \endcode
  3318. \sa wolfSSL_BIO_new
  3319. \sa wolfSSL_BIO_nwrite
  3320. */
  3321. WOLFSSL_API int wolfSSL_BIO_nread(WOLFSSL_BIO *bio, char **buf, int num);
  3322. /*!
  3323. \ingroup IO
  3324. \brief Gets a pointer to the buffer for writing as many bytes as returned by
  3325. the function. Writing more bytes to the pointer returned then the value
  3326. returned can result in writing out of bounds.
  3327. \return int Returns the number of bytes that can be written to the buffer
  3328. pointer returned.
  3329. \return WOLFSSL_BIO_UNSET(-2) in the case that is not part of a bio pair
  3330. \return WOLFSSL_BIO_ERROR(-1) in the case that there is no more room to
  3331. write to
  3332. \param bio WOLFSSL_BIO structure to write to.
  3333. \param buf pointer to buffer to write to.
  3334. \param num number of bytes desired to be written.
  3335. _Example_
  3336. \code
  3337. WOLFSSL_BIO* bio;
  3338. char* bufPt;
  3339. int ret;
  3340. // set up bio
  3341. ret = wolfSSL_BIO_nwrite(bio, &bufPt, 10); // try to write 10 bytes
  3342. // handle negative ret check
  3343. // write ret bytes to bufPt
  3344. \endcode
  3345. \sa wolfSSL_BIO_new
  3346. \sa wolfSSL_BIO_free
  3347. \sa wolfSSL_BIO_nread
  3348. */
  3349. WOLFSSL_API int wolfSSL_BIO_nwrite(WOLFSSL_BIO *bio, char **buf, int num);
  3350. /*!
  3351. \ingroup IO
  3352. \brief Resets bio to an initial state. As an example for type BIO_BIO
  3353. this resets the read and write index.
  3354. \return 0 On successfully resetting the bio.
  3355. \return WOLFSSL_BIO_ERROR(-1) Returned on bad input or unsuccessful reset.
  3356. \param bio WOLFSSL_BIO structure to reset.
  3357. _Example_
  3358. \code
  3359. WOLFSSL_BIO* bio;
  3360. // setup bio
  3361. wolfSSL_BIO_reset(bio);
  3362. //use pt
  3363. \endcode
  3364. \sa wolfSSL_BIO_new
  3365. \sa wolfSSL_BIO_free
  3366. */
  3367. WOLFSSL_API int wolfSSL_BIO_reset(WOLFSSL_BIO *bio);
  3368. /*!
  3369. \ingroup IO
  3370. \brief This function adjusts the file pointer to the offset given. This
  3371. is the offset from the head of the file.
  3372. \return 0 On successfully seeking.
  3373. \return -1 If an error case was encountered.
  3374. \param bio WOLFSSL_BIO structure to set.
  3375. \param ofs offset into file.
  3376. _Example_
  3377. \code
  3378. WOLFSSL_BIO* bio;
  3379. XFILE fp;
  3380. int ret;
  3381. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3382. ret = wolfSSL_BIO_set_fp(bio, &fp);
  3383. // check ret value
  3384. ret = wolfSSL_BIO_seek(bio, 3);
  3385. // check ret value
  3386. \endcode
  3387. \sa wolfSSL_BIO_new
  3388. \sa wolfSSL_BIO_s_mem
  3389. \sa wolfSSL_BIO_set_fp
  3390. \sa wolfSSL_BIO_free
  3391. */
  3392. WOLFSSL_API int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs);
  3393. /*!
  3394. \ingroup IO
  3395. \brief This is used to set and write to a file. WIll overwrite any data
  3396. currently in the file and is set to close the file when the bio is freed.
  3397. \return SSL_SUCCESS On successfully opening and setting file.
  3398. \return SSL_FAILURE If an error case was encountered.
  3399. \param bio WOLFSSL_BIO structure to set file.
  3400. \param name name of file to write to.
  3401. _Example_
  3402. \code
  3403. WOLFSSL_BIO* bio;
  3404. int ret;
  3405. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3406. ret = wolfSSL_BIO_write_filename(bio, “test.txt”);
  3407. // check ret value
  3408. \endcode
  3409. \sa wolfSSL_BIO_new
  3410. \sa wolfSSL_BIO_s_file
  3411. \sa wolfSSL_BIO_set_fp
  3412. \sa wolfSSL_BIO_free
  3413. */
  3414. WOLFSSL_API int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name);
  3415. /*!
  3416. \ingroup IO
  3417. \brief This is used to set the end of file value. Common value is -1 so
  3418. as not to get confused with expected positive values.
  3419. \return 0 returned on completion
  3420. \param bio WOLFSSL_BIO structure to set end of file value.
  3421. \param v value to set in bio.
  3422. _Example_
  3423. \code
  3424. WOLFSSL_BIO* bio;
  3425. int ret;
  3426. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3427. ret = wolfSSL_BIO_set_mem_eof_return(bio, -1);
  3428. // check ret value
  3429. \endcode
  3430. \sa wolfSSL_BIO_new
  3431. \sa wolfSSL_BIO_s_mem
  3432. \sa wolfSSL_BIO_set_fp
  3433. \sa wolfSSL_BIO_free
  3434. */
  3435. WOLFSSL_API long wolfSSL_BIO_set_mem_eof_return(WOLFSSL_BIO *bio, int v);
  3436. /*!
  3437. \ingroup IO
  3438. \brief This is a getter function for WOLFSSL_BIO memory pointer.
  3439. \return SSL_SUCCESS On successfully getting the pointer SSL_SUCCESS is
  3440. returned (currently value of 1).
  3441. \return SSL_FAILURE Returned if NULL arguments are passed in (currently
  3442. value of 0).
  3443. \param bio pointer to the WOLFSSL_BIO structure for getting memory pointer.
  3444. \param ptr structure that is currently a char*. Is set to point to
  3445. bio’s memory.
  3446. _Example_
  3447. \code
  3448. WOLFSSL_BIO* bio;
  3449. WOLFSSL_BUF_MEM* pt;
  3450. // setup bio
  3451. wolfSSL_BIO_get_mem_ptr(bio, &pt);
  3452. //use pt
  3453. \endcode
  3454. \sa wolfSSL_BIO_new
  3455. \sa wolfSSL_BIO_s_mem
  3456. */
  3457. WOLFSSL_API long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **m);
  3458. /*!
  3459. \ingroup CertsKeys
  3460. \brief This function copies the name of the x509 into a buffer.
  3461. \return A char pointer to the buffer with the WOLFSSL_X509_NAME structures
  3462. name member’s data is returned if the function executed normally.
  3463. \param name a pointer to a WOLFSSL_X509 structure.
  3464. \param in a buffer to hold the name copied from the
  3465. WOLFSSL_X509_NAME structure.
  3466. \param sz the maximum size of the buffer.
  3467. _Example_
  3468. \code
  3469. WOLFSSL_X509 x509;
  3470. char* name;
  3471. ...
  3472. name = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3473. if(name <= 0){
  3474. // There’s nothing in the buffer.
  3475. }
  3476. \endcode
  3477. \sa wolfSSL_X509_get_subject_name
  3478. \sa wolfSSL_X509_get_issuer_name
  3479. \sa wolfSSL_X509_get_isCA
  3480. \sa wolfSSL_get_peer_certificate
  3481. \sa wolfSSL_X509_version
  3482. */
  3483. WOLFSSL_API char* wolfSSL_X509_NAME_oneline(WOLFSSL_X509_NAME*, char*, int);
  3484. /*!
  3485. \ingroup CertsKeys
  3486. \brief This function returns the name of the certificate issuer.
  3487. \return point a pointer to the WOLFSSL_X509 struct’s issuer member is
  3488. returned.
  3489. \return NULL if the cert passed in is NULL.
  3490. \param cert a pointer to a WOLFSSL_X509 structure.
  3491. _Example_
  3492. \code
  3493. WOLFSSL_X509* x509;
  3494. WOLFSSL_X509_NAME issuer;
  3495. ...
  3496. issuer = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3497. if(!issuer){
  3498. // NULL was returned
  3499. } else {
  3500. // issuer hods the name of the certificate issuer.
  3501. }
  3502. \endcode
  3503. \sa wolfSSL_X509_get_subject_name
  3504. \sa wolfSSL_X509_get_isCA
  3505. \sa wolfSSL_get_peer_certificate
  3506. \sa wolfSSL_X509_NAME_oneline
  3507. */
  3508. WOLFSSL_API WOLFSSL_X509_NAME* wolfSSL_X509_get_issuer_name(WOLFSSL_X509*);
  3509. /*!
  3510. \ingroup CertsKeys
  3511. \brief This function returns the subject member of the WOLFSSL_X509
  3512. structure.
  3513. \return pointer a pointer to the WOLFSSL_X509_NAME structure. The pointer
  3514. may be NULL if the WOLFSSL_X509 struct is NULL or if the subject member of
  3515. the structure is NULL.
  3516. \param cert a pointer to a WOLFSSL_X509 structure.
  3517. _Example_
  3518. \code
  3519. WOLFSSL_X509* cert;
  3520. WOLFSSL_X509_NAME name;
  3521. name = wolfSSL_X509_get_subject_name(cert);
  3522. if(name == NULL){
  3523. // Deal with the NULL cacse
  3524. }
  3525. \endcode
  3526. \sa wolfSSL_X509_get_issuer_name
  3527. \sa wolfSSL_X509_get_isCA
  3528. \sa wolfSSL_get_peer_certificate
  3529. */
  3530. WOLFSSL_API WOLFSSL_X509_NAME* wolfSSL_X509_get_subject_name(WOLFSSL_X509*);
  3531. /*!
  3532. \ingroup CertsKeys
  3533. \brief Checks the isCa member of the WOLFSSL_X509 structure and returns
  3534. the value.
  3535. \return isCA returns the value in the isCA member of the WOLFSSL_X509
  3536. structure is returned.
  3537. \return 0 returned if there is not a valid x509 structure passed in.
  3538. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3539. _Example_
  3540. /code
  3541. WOLFSSL* ssl;
  3542. ...
  3543. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  3544. WOLFSSL* ssl = wolfSSL_new(ctx);
  3545. ...
  3546. if(wolfSSL_X509_get_isCA(ssl)){
  3547. // This is the CA
  3548. }else {
  3549. // Failure case
  3550. }
  3551. \endcode
  3552. \sa wolfSSL_X509_get_issuer_name
  3553. \sa wolfSSL_X509_get_isCA
  3554. */
  3555. WOLFSSL_API int wolfSSL_X509_get_isCA(WOLFSSL_X509*);
  3556. /*!
  3557. \ingroup CertsKeys
  3558. \brief This function gets the text related to the passed in NID value.
  3559. \return int returns the size of the text buffer.
  3560. \param name WOLFSSL_X509_NAME to search for text.
  3561. \param nid NID to search for.
  3562. \param buf buffer to hold text when found.
  3563. \param len length of buffer.
  3564. _Example_
  3565. \code
  3566. WOLFSSL_X509_NAME* name;
  3567. char buffer[100];
  3568. int bufferSz;
  3569. int ret;
  3570. // get WOLFSSL_X509_NAME
  3571. ret = wolfSSL_X509_NAME_get_text_by_NID(name, NID_commonName,
  3572. buffer, bufferSz);
  3573. //check ret value
  3574. \endcode
  3575. \sa none
  3576. */
  3577. WOLFSSL_API int wolfSSL_X509_NAME_get_text_by_NID(
  3578. WOLFSSL_X509_NAME*, int, char*, int);
  3579. /*!
  3580. \ingroup CertsKeys
  3581. \brief This function returns the value stored in the sigOID
  3582. member of the WOLFSSL_X509 structure.
  3583. \return 0 returned if the WOLFSSL_X509 structure is NULL.
  3584. \return int an integer value is returned which was retrieved from
  3585. the x509 object.
  3586. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3587. _Example_
  3588. \code
  3589. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  3590. DYNAMIC_TYPE_X509);
  3591. ...
  3592. int x509SigType = wolfSSL_X509_get_signature_type(x509);
  3593. if(x509SigType != EXPECTED){
  3594. // Deal with an unexpected value
  3595. }
  3596. \endcode
  3597. \sa wolfSSL_X509_get_signature
  3598. \sa wolfSSL_X509_version
  3599. \sa wolfSSL_X509_get_der
  3600. \sa wolfSSL_X509_get_serial_number
  3601. \sa wolfSSL_X509_notBefore
  3602. \sa wolfSSL_X509_notAfter
  3603. \sa wolfSSL_X509_free
  3604. */
  3605. WOLFSSL_API int wolfSSL_X509_get_signature_type(WOLFSSL_X509*);
  3606. /*!
  3607. \ingroup CertsKeys
  3608. \brief Gets the X509 signature and stores it in the buffer.
  3609. \return SSL_SUCCESS returned if the function successfully executes.
  3610. The signature is loaded into the buffer.
  3611. \return SSL_FATAL_ERRROR returns if the x509 struct or the bufSz member
  3612. is NULL. There is also a check for the length member of the sig structure
  3613. (sig is a member of x509).
  3614. \param x509 pointer to a WOLFSSL_X509 structure.
  3615. \param buf a char pointer to the buffer.
  3616. \param bufSz an integer pointer to the size of the buffer.
  3617. _Example_
  3618. \code
  3619. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  3620. DYNAMIC_TYPE_X509);
  3621. unsigned char* buf; // Initialize
  3622. int* bufSz = sizeof(buf)/sizeof(unsigned char);
  3623. ...
  3624. if(wolfSSL_X509_get_signature(x509, buf, bufSz) != SSL_SUCCESS){
  3625. // The function did not execute successfully.
  3626. } else{
  3627. // The buffer was written to correctly.
  3628. }
  3629. \endcode
  3630. \sa wolfSSL_X509_get_serial_number
  3631. \sa wolfSSL_X509_get_signature_type
  3632. \sa wolfSSL_X509_get_device_type
  3633. */
  3634. WOLFSSL_API int wolfSSL_X509_get_signature(WOLFSSL_X509*, unsigned char*, int*);
  3635. /*!
  3636. \ingroup CertsKeys
  3637. \brief This function adds a certificate to the WOLFSSL_X509_STRE structure.
  3638. \return SSL_SUCCESS If certificate is added successfully.
  3639. \return SSL_FATAL_ERROR: If certificate is not added successfully.
  3640. \param str certificate store to add the certificate to.
  3641. \param x509 certificate to add.
  3642. _Example_
  3643. \code
  3644. WOLFSSL_X509_STORE* str;
  3645. WOLFSSL_X509* x509;
  3646. int ret;
  3647. ret = wolfSSL_X509_STORE_add_cert(str, x509);
  3648. //check ret value
  3649. \endcode
  3650. \sa wolfSSL_X509_free
  3651. */
  3652. WOLFSSL_API int wolfSSL_X509_STORE_add_cert(
  3653. WOLFSSL_X509_STORE*, WOLFSSL_X509*);
  3654. /*!
  3655. \ingroup CertsKeys
  3656. \brief This function is a getter function for chain variable
  3657. in WOLFSSL_X509_STORE_CTX structure. Currently chain is not populated.
  3658. \return pointer if successful returns WOLFSSL_STACK
  3659. (same as STACK_OF(WOLFSSL_X509)) pointer
  3660. \return Null upon failure
  3661. \param ctx certificate store ctx to get parse chain from.
  3662. _Example_
  3663. \code
  3664. WOLFSSL_STACK* sk;
  3665. WOLFSSL_X509_STORE_CTX* ctx;
  3666. sk = wolfSSL_X509_STORE_CTX_get_chain(ctx);
  3667. //check sk for NULL and then use it. sk needs freed after done.
  3668. \endcode
  3669. \sa wolfSSL_sk_X509_free
  3670. */
  3671. WOLFSSL_API WOLFSSL_STACK* wolfSSL_X509_STORE_CTX_get_chain(
  3672. WOLFSSL_X509_STORE_CTX* ctx);
  3673. /*!
  3674. \ingroup CertsKeys
  3675. \brief This function takes in a flag to change the behavior of the
  3676. WOLFSSL_X509_STORE structure passed in. An example of a flag used
  3677. is WOLFSSL_CRL_CHECK.
  3678. \return SSL_SUCCESS If no errors were encountered when setting the flag.
  3679. \return <0 a negative value will be returned upon failure.
  3680. \param str certificate store to set flag in.
  3681. \param flag flag for behavior.
  3682. _Example_
  3683. \code
  3684. WOLFSSL_X509_STORE* str;
  3685. int ret;
  3686. // create and set up str
  3687. ret = wolfSSL_X509_STORE_set_flags(str, WOLFSSL_CRL_CHECKALL);
  3688. If (ret != SSL_SUCCESS) {
  3689. //check ret value and handle error case
  3690. }
  3691. \endcode
  3692. \sa wolfSSL_X509_STORE_new
  3693. \sa wolfSSL_X509_STORE_free
  3694. */
  3695. WOLFSSL_API int wolfSSL_X509_STORE_set_flags(WOLFSSL_X509_STORE* store,
  3696. unsigned long flag);
  3697. /*!
  3698. \ingroup Setup
  3699. \brief This function is used to copy a WOLFSSL_ASN1_INTEGER
  3700. value to a WOLFSSL_BIGNUM structure.
  3701. \return pointer On successfully copying the WOLFSSL_ASN1_INTEGER
  3702. value a WOLFSSL_BIGNUM pointer is returned.
  3703. \return Null upon failure.
  3704. \param ai WOLFSSL_ASN1_INTEGER structure to copy from.
  3705. \param bn if wanting to copy into an already existing
  3706. WOLFSSL_BIGNUM struct then pass in a pointer to it.
  3707. Optionally this can be NULL and a new WOLFSSL_BIGNUM
  3708. structure will be created.
  3709. _Example_
  3710. \code
  3711. WOLFSSL_ASN1_INTEGER* ai;
  3712. WOLFSSL_BIGNUM* bn;
  3713. // create ai
  3714. bn = wolfSSL_ASN1_INTEGER_to_BN(ai, NULL);
  3715. // or if having already created bn and wanting to reuse structure
  3716. // wolfSSL_ASN1_INTEGER_to_BN(ai, bn);
  3717. // check bn is or return value is not NULL
  3718. \endcode
  3719. \sa none
  3720. */
  3721. WOLFSSL_API WOLFSSL_BIGNUM *wolfSSL_ASN1_INTEGER_to_BN(const WOLFSSL_ASN1_INTEGER *ai,
  3722. WOLFSSL_BIGNUM *bn);
  3723. /*!
  3724. \ingroup Setup
  3725. \brief This function adds the certificate to the internal chain
  3726. being built in the WOLFSSL_CTX structure.
  3727. \return SSL_SUCCESS after successfully adding the certificate.
  3728. \return SSL_FAILURE if failing to add the certificate to the chain.
  3729. \param ctx WOLFSSL_CTX structure to add certificate to.
  3730. \param x509 certificate to add to the chain.
  3731. _Example_
  3732. \code
  3733. WOLFSSL_CTX* ctx;
  3734. WOLFSSL_X509* x509;
  3735. int ret;
  3736. // create ctx
  3737. ret = wolfSSL_CTX_add_extra_chain_cert(ctx, x509);
  3738. // check ret value
  3739. \endcode
  3740. \sa wolfSSL_CTX_new
  3741. \sa wolfSSL_CTX_free
  3742. */
  3743. WOLFSSL_API long wolfSSL_CTX_add_extra_chain_cert(WOLFSSL_CTX*, WOLFSSL_X509*);
  3744. /*!
  3745. \ingroup Setup
  3746. \brief This function returns the get read ahead flag from a
  3747. WOLFSSL_CTX structure.
  3748. \return flag On success returns the read ahead flag.
  3749. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  3750. \param ctx WOLFSSL_CTX structure to get read ahead flag from.
  3751. _Example_
  3752. \code
  3753. WOLFSSL_CTX* ctx;
  3754. int flag;
  3755. // setup ctx
  3756. flag = wolfSSL_CTX_get_read_ahead(ctx);
  3757. //check flag
  3758. \endcode
  3759. \sa wolfSSL_CTX_new
  3760. \sa wolfSSL_CTX_free
  3761. \sa wolfSSL_CTX_set_read_ahead
  3762. */
  3763. WOLFSSL_API int wolfSSL_CTX_get_read_ahead(WOLFSSL_CTX*);
  3764. /*!
  3765. \ingroup Setup
  3766. \brief This function sets the read ahead flag in the WOLFSSL_CTX structure.
  3767. \return SSL_SUCCESS If ctx read ahead flag set.
  3768. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  3769. \param ctx WOLFSSL_CTX structure to set read ahead flag.
  3770. _Example_
  3771. \code
  3772. WOLFSSL_CTX* ctx;
  3773. int flag;
  3774. int ret;
  3775. // setup ctx
  3776. ret = wolfSSL_CTX_set_read_ahead(ctx, flag);
  3777. // check return value
  3778. \endcode
  3779. \sa wolfSSL_CTX_new
  3780. \sa wolfSSL_CTX_free
  3781. \sa wolfSSL_CTX_get_read_ahead
  3782. */
  3783. WOLFSSL_API int wolfSSL_CTX_set_read_ahead(WOLFSSL_CTX*, int v);
  3784. /*!
  3785. \ingroup Setup
  3786. \brief This function sets the options argument to use with OCSP.
  3787. \return SSL_FAILURE If ctx or it’s cert manager is NULL.
  3788. \return SSL_SUCCESS If successfully set.
  3789. \param ctx WOLFSSL_CTX structure to set user argument.
  3790. \param arg user argument.
  3791. _Example_
  3792. \code
  3793. WOLFSSL_CTX* ctx;
  3794. void* data;
  3795. int ret;
  3796. // setup ctx
  3797. ret = wolfSSL_CTX_set_tlsext_status_arg(ctx, data);
  3798. //check ret value
  3799. \endcode
  3800. \sa wolfSSL_CTX_new
  3801. \sa wolfSSL_CTX_free
  3802. */
  3803. WOLFSSL_API long wolfSSL_CTX_set_tlsext_status_arg(WOLFSSL_CTX*, void* arg);
  3804. /*!
  3805. \ingroup Setup
  3806. \brief This function sets the optional argument to be passed to
  3807. the PRF callback.
  3808. \return SSL_FAILURE If ctx is NULL.
  3809. \return SSL_SUCCESS If successfully set.
  3810. \param ctx WOLFSSL_CTX structure to set user argument.
  3811. \param arg user argument.
  3812. _Example_
  3813. \code
  3814. WOLFSSL_CTX* ctx;
  3815. void* data;
  3816. int ret;
  3817. // setup ctx
  3818. ret = wolfSSL_CTX_set_tlsext_opaques_prf_input_callback_arg(ctx, data);
  3819. //check ret value
  3820. \endcode
  3821. \sa wolfSSL_CTX_new
  3822. \sa wolfSSL_CTX_free
  3823. */
  3824. WOLFSSL_API long wolfSSL_CTX_set_tlsext_opaque_prf_input_callback_arg(
  3825. WOLFSSL_CTX*, void* arg);
  3826. /*!
  3827. \ingroup Setup
  3828. \brief This function sets the options mask in the ssl.
  3829. Some valid options are, SSL_OP_ALL, SSL_OP_COOKIE_EXCHANGE,
  3830. SSL_OP_NO_SSLv2, SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1,
  3831. SSL_OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_2, SSL_OP_NO_COMPRESSION.
  3832. \return val Returns the updated options mask value stored in ssl.
  3833. \param s WOLFSSL structure to set options mask.
  3834. \param op This function sets the options mask in the ssl.
  3835. Some valid options are:
  3836. SSL_OP_ALL
  3837. SSL_OP_COOKIE_EXCHANGE
  3838. SSL_OP_NO_SSLv2
  3839. SSL_OP_NO_SSLv3
  3840. SSL_OP_NO_TLSv1
  3841. SSL_OP_NO_TLSv1_1
  3842. SSL_OP_NO_TLSv1_2
  3843. SSL_OP_NO_COMPRESSION
  3844. _Example_
  3845. \code
  3846. WOLFSSL* ssl;
  3847. unsigned long mask;
  3848. mask = SSL_OP_NO_TLSv1
  3849. mask = wolfSSL_set_options(ssl, mask);
  3850. // check mask
  3851. \endcode
  3852. \sa wolfSSL_new
  3853. \sa wolfSSL_free
  3854. \sa wolfSSL_get_options
  3855. */
  3856. WOLFSSL_API long wolfSSL_set_options(WOLFSSL *s, long op);
  3857. /*!
  3858. \ingroup Setup
  3859. \brief This function returns the current options mask.
  3860. \return val Returns the mask value stored in ssl.
  3861. \param ssl WOLFSSL structure to get options mask from.
  3862. _Example_
  3863. \code
  3864. WOLFSSL* ssl;
  3865. unsigned long mask;
  3866. mask = wolfSSL_get_options(ssl);
  3867. // check mask
  3868. \endcode
  3869. \sa wolfSSL_new
  3870. \sa wolfSSL_free
  3871. \sa wolfSSL_set_options
  3872. */
  3873. WOLFSSL_API long wolfSSL_get_options(const WOLFSSL *s);
  3874. /*!
  3875. \ingroup Setup
  3876. \brief This is used to set the debug argument passed around.
  3877. \return SSL_SUCCESS On successful setting argument.
  3878. \return SSL_FAILURE If an NULL ssl passed in.
  3879. \param ssl WOLFSSL structure to set argument in.
  3880. \param arg argument to use.
  3881. _Example_
  3882. \code
  3883. WOLFSSL* ssl;
  3884. void* args;
  3885. int ret;
  3886. // create ssl object
  3887. ret = wolfSSL_set_tlsext_debug_arg(ssl, args);
  3888. // check ret value
  3889. \endcode
  3890. \sa wolfSSL_new
  3891. \sa wolfSSL_free
  3892. */
  3893. WOLFSSL_API long wolfSSL_set_tlsext_debug_arg(WOLFSSL *s, void *arg);
  3894. /*!
  3895. \ingroup openSSL
  3896. \brief This function is called when the client application request
  3897. that a server send back an OCSP status response (also known as
  3898. OCSP stapling).Currently, the only supported type is
  3899. TLSEXT_STATUSTYPE_ocsp.
  3900. \return 1 upon success.
  3901. \return 0 upon error.
  3902. \param s pointer to WolfSSL struct which is created by SSL_new() function
  3903. \param type ssl extension type which TLSEXT_STATUSTYPE_ocsp is
  3904. only supported.
  3905. _Example_
  3906. \code
  3907. WOLFSSL *ssl;
  3908. WOLFSSL_CTX *ctx;
  3909. int ret;
  3910. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  3911. ssl = wolfSSL_new(ctx);
  3912. ret = WolfSSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp);
  3913. wolfSSL_free(ssl);
  3914. wolfSSL_CTX_free(ctx);
  3915. \endcode
  3916. \sa wolfSSL_new
  3917. \sa wolfSSL_CTX_new
  3918. \sa wolfSSL_free
  3919. \sa wolfSSL_CTX_free
  3920. */
  3921. WOLFSSL_API long wolfSSL_set_tlsext_status_type(WOLFSSL *s, int type);
  3922. /*!
  3923. \ingroup Setup
  3924. \brief This is used to get the results after trying to verify the peer's
  3925. certificate.
  3926. \return X509_V_OK On successful verification.
  3927. \return SSL_FAILURE If an NULL ssl passed in.
  3928. \param ssl WOLFSSL structure to get verification results from.
  3929. _Example_
  3930. \code
  3931. WOLFSSL* ssl;
  3932. long ret;
  3933. // attempt/complete handshake
  3934. ret = wolfSSL_get_verify_result(ssl);
  3935. // check ret value
  3936. \endcode
  3937. \sa wolfSSL_new
  3938. \sa wolfSSL_free
  3939. */
  3940. WOLFSSL_API long wolfSSL_get_verify_result(const WOLFSSL *ssl);
  3941. /*!
  3942. \ingroup Debug
  3943. \brief This function converts an error code returned by
  3944. wolfSSL_get_error() into a more human-readable error string
  3945. and prints that string to the output file - fp. err is the
  3946. error code returned by wolfSSL_get_error() and fp is the
  3947. file which the error string will be placed in.
  3948. \return none No returns.
  3949. \param fp output file for human-readable error string to be written to.
  3950. \param err error code returned by wolfSSL_get_error().
  3951. _Example_
  3952. \code
  3953. int err = 0;
  3954. WOLFSSL* ssl;
  3955. FILE* fp = ...
  3956. ...
  3957. err = wolfSSL_get_error(ssl, 0);
  3958. wolfSSL_ERR_print_errors_fp(fp, err);
  3959. \endcode
  3960. \sa wolfSSL_get_error
  3961. \sa wolfSSL_ERR_error_string
  3962. \sa wolfSSL_ERR_error_string_n
  3963. \sa wolfSSL_load_error_strings
  3964. */
  3965. WOLFSSL_API void wolfSSL_ERR_print_errors_fp(FILE*, int err);
  3966. /*!
  3967. \ingroup Debug
  3968. \brief This function uses the provided callback to handle error reporting.
  3969. The callback function is executed for each error line. The string, length,
  3970. and userdata are passed into the callback parameters.
  3971. \return none No returns.
  3972. \param cb the callback function.
  3973. \param u userdata to pass into the callback function.
  3974. _Example_
  3975. \code
  3976. int error_cb(const char *str, size_t len, void *u)
  3977. { fprintf((FILE*)u, "%-*.*s\n", (int)len, (int)len, str); return 0; }
  3978. ...
  3979. FILE* fp = ...
  3980. wolfSSL_ERR_print_errors_cb(error_cb, fp);
  3981. \endcode
  3982. \sa wolfSSL_get_error
  3983. \sa wolfSSL_ERR_error_string
  3984. \sa wolfSSL_ERR_error_string_n
  3985. \sa wolfSSL_load_error_strings
  3986. */
  3987. WOLFSSL_API void wolfSSL_ERR_print_errors_cb (
  3988. int (*cb)(const char *str, size_t len, void *u), void *u);
  3989. /*!
  3990. \brief The function sets the client_psk_cb member of the
  3991. WOLFSSL_CTX structure.
  3992. \return none No returns.
  3993. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  3994. wolfSSL_CTX_new().
  3995. \param cb wc_psk_client_callback is a function pointer that will be
  3996. stored in the WOLFSSL_CTX structure.
  3997. _Example_
  3998. \code
  3999. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  4000. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4001. char* identity, unsigned int id_max_len, unsigned char* key,
  4002. Unsigned int key_max_len){
  4003. wolfSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
  4004. \endcode
  4005. \sa wolfSSL_set_psk_client_callback
  4006. \sa wolfSSL_set_psk_server_callback
  4007. \sa wolfSSL_CTX_set_psk_server_callback
  4008. \sa wolfSSL_CTX_set_psk_client_callback
  4009. */
  4010. WOLFSSL_API void wolfSSL_CTX_set_psk_client_callback(WOLFSSL_CTX*,
  4011. wc_psk_client_callback);
  4012. /*!
  4013. \brief Sets the PSK client side callback.
  4014. \return none No returns.
  4015. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4016. \param cb a function pointer to type wc_psk_client_callback.
  4017. _Example_
  4018. \code
  4019. WOLFSSL* ssl;
  4020. unsigned int cb(WOLFSSL*, const char*, char*) // Header of function*
  4021. {
  4022. // Function body
  4023. }
  4024. cb = wc_psk_client_callback;
  4025. if(ssl){
  4026. wolfSSL_set_psk_client_callback(ssl, cb);
  4027. } else {
  4028. // could not set callback
  4029. }
  4030. \endcode
  4031. \sa wolfSSL_CTX_set_psk_client_callback
  4032. \sa wolfSSL_CTX_set_psk_server_callback
  4033. \sa wolfSSL_set_psk_server_callback
  4034. */
  4035. WOLFSSL_API void wolfSSL_set_psk_client_callback(WOLFSSL*,
  4036. wc_psk_client_callback);
  4037. /*!
  4038. \ingroup CertsKeys
  4039. \brief This function returns the psk identity hint.
  4040. \return pointer a const char pointer to the value that was stored in
  4041. the arrays member of the WOLFSSL structure is returned.
  4042. \return NULL returned if the WOLFSSL or Arrays structures are NULL.
  4043. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4044. _Example_
  4045. \code
  4046. WOLFSSL* ssl = wolfSSL_new(ctx);
  4047. char* idHint;
  4048. ...
  4049. idHint = wolfSSL_get_psk_identity_hint(ssl);
  4050. if(idHint){
  4051. // The hint was retrieved
  4052. return idHint;
  4053. } else {
  4054. // Hint wasn’t successfully retrieved
  4055. }
  4056. \endcode
  4057. \sa wolfSSL_get_psk_identity
  4058. */
  4059. WOLFSSL_API const char* wolfSSL_get_psk_identity_hint(const WOLFSSL*);
  4060. /*!
  4061. \ingroup CertsKeys
  4062. \brief The function returns a constant pointer to the client_identity
  4063. member of the Arrays structure.
  4064. \return string the string value of the client_identity member of the
  4065. Arrays structure.
  4066. \return NULL if the WOLFSSL structure is NULL or if the Arrays member of
  4067. the WOLFSSL structure is NULL.
  4068. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4069. _Example_
  4070. \code
  4071. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4072. WOLFSSL* ssl = wolfSSL_new(ctx);
  4073. const char* pskID;
  4074. ...
  4075. pskID = wolfSSL_get_psk_identity(ssl);
  4076. if(pskID == NULL){
  4077. // There is not a value in pskID
  4078. }
  4079. \endcode
  4080. \sa wolfSSL_get_psk_identity_hint
  4081. \sa wolfSSL_use_psk_identity_hint
  4082. */
  4083. WOLFSSL_API const char* wolfSSL_get_psk_identity(const WOLFSSL*);
  4084. /*!
  4085. \ingroup CertsKeys
  4086. \brief This function stores the hint argument in the server_hint
  4087. member of the WOLFSSL_CTX structure.
  4088. \return SSL_SUCCESS returned for successful execution of the function.
  4089. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4090. wolfSSL_CTX_new().
  4091. \param hint a constant char pointer that will be copied to the
  4092. WOLFSSL_CTX structure.
  4093. _Example_
  4094. \code
  4095. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4096. const char* hint;
  4097. int ret;
  4098. ret = wolfSSL_CTX_use_psk_identity_hint(ctx, hint);
  4099. if(ret == SSL_SUCCESS){
  4100. // Function was successful.
  4101. return ret;
  4102. } else {
  4103. // Failure case.
  4104. }
  4105. \endcode
  4106. \sa wolfSSL_use_psk_identity_hint
  4107. */
  4108. WOLFSSL_API int wolfSSL_CTX_use_psk_identity_hint(WOLFSSL_CTX*, const char*);
  4109. /*!
  4110. \ingroup CertsKeys
  4111. \brief This function stores the hint argument in the server_hint member
  4112. of the Arrays structure within the WOLFSSL structure.
  4113. \return SSL_SUCCESS returned if the hint was successfully stored in the
  4114. WOLFSSL structure.
  4115. \return SSL_FAILURE returned if the WOLFSSL or Arrays structures are NULL.
  4116. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4117. \para hint a constant character pointer that holds the hint to be saved
  4118. in memory.
  4119. _Example_
  4120. \code
  4121. WOLFSSL* ssl = wolfSSL_new(ctx);
  4122. const char* hint;
  4123. ...
  4124. if(wolfSSL_use_psk_identity_hint(ssl, hint) != SSL_SUCCESS){
  4125. // Handle failure case.
  4126. }
  4127. \endcode
  4128. \sa wolfSSL_CTX_use_psk_identity_hint
  4129. */
  4130. WOLFSSL_API int wolfSSL_use_psk_identity_hint(WOLFSSL*, const char*);
  4131. /*!
  4132. \brief This function sets the psk callback for the server side in
  4133. the WOLFSSL_CTX structure.
  4134. \return none No returns.
  4135. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4136. \param cb a function pointer for the callback and will be stored in
  4137. the WOLFSSL_CTX structure.
  4138. _Example_
  4139. \code
  4140. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4141. WOLFSSL* ssl = wolfSSL_new(ctx);
  4142. unsigned int cb(WOLFSSL*, const char*, unsigned char*, unsigned int)
  4143. // signature requirement
  4144. {
  4145. // Function body.
  4146. }
  4147. if(ctx != NULL){
  4148. wolfSSL_CTX_set_psk_server_callback(ctx, cb);
  4149. } else {
  4150. // The CTX object was not properly initialized.
  4151. }
  4152. \endcode
  4153. \sa wc_psk_server_callback
  4154. \sa wolfSSL_set_psk_client_callback
  4155. \sa wolfSSL_set_psk_server_callback
  4156. \sa wolfSSL_CTX_set_psk_client_callback
  4157. */
  4158. WOLFSSL_API void wolfSSL_CTX_set_psk_server_callback(WOLFSSL_CTX*,
  4159. wc_psk_server_callback);
  4160. /*!
  4161. \brief Sets the psk callback for the server side by setting the
  4162. WOLFSSL structure options members.
  4163. \return none No returns.
  4164. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4165. \param cb a function pointer for the callback and will be stored in
  4166. the WOLFSSL structure.
  4167. _Example_
  4168. \code
  4169. WOLFSSL_CTX* ctx;
  4170. WOLFSSL* ssl;
  4171. int cb(WOLFSSL*, const char*, unsigned char*, unsigned int) // Required sig.
  4172. {
  4173. // Function body.
  4174. }
  4175. if(ssl != NULL && cb != NULL){
  4176. wolfSSL_set_psk_server_callback(ssl, cb);
  4177. }
  4178. \endcode
  4179. \sa wolfSSL_set_psk_client_callback
  4180. \sa wolfSSL_CTX_set_psk_server_callback
  4181. \sa wolfSSL_CTX_set_psk_client_callback
  4182. \sa wolfSSL_get_psk_identity_hint
  4183. \sa wc_psk_server_callback
  4184. \sa InitSuites
  4185. */
  4186. WOLFSSL_API void wolfSSL_set_psk_server_callback(WOLFSSL*,
  4187. wc_psk_server_callback);
  4188. /*!
  4189. \ingroup Setup
  4190. \brief This function enables the havAnon member of the CTX structure if
  4191. HAVE_ANON is defined during compilation.
  4192. \return SSL_SUCCESS returned if the function executed successfully and the
  4193. haveAnnon member of the CTX is set to 1.
  4194. \return SSL_FAILURE returned if the CTX structure was NULL.
  4195. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4196. wolfSSL_CTX_new().
  4197. _Example_
  4198. \code
  4199. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4200. WOLFSSL* ssl = wolfSSL_new(ctx);
  4201. ...
  4202. #ifdef HAVE_ANON
  4203. if(cipherList == NULL){
  4204. wolfSSL_CTX_allow_anon_cipher(ctx);
  4205. if(wolfSSL_CTX_set_cipher_list(ctx, “ADH_AES128_SHA”) != SSL_SUCCESS){
  4206. // failure case
  4207. }
  4208. }
  4209. #endif
  4210. \endcode
  4211. \sa none
  4212. */
  4213. WOLFSSL_API int wolfSSL_CTX_allow_anon_cipher(WOLFSSL_CTX*);
  4214. /*!
  4215. \ingroup Setup
  4216. \brief The wolfSSLv23_server_method() function is used to indicate
  4217. that the application is a server and will support clients connecting
  4218. with protocol version from SSL 3.0 - TLS 1.2. This function allocates
  4219. memory for and initializes a new WOLFSSL_METHOD structure to be used when
  4220. creating the SSL/TLS context with wolfSSL_CTX_new().
  4221. \return pointer If successful, the call will return a pointer to the newly
  4222. created WOLFSSL_METHOD structure.
  4223. \return Failure If memory allocation fails when calling XMALLOC, the
  4224. failure value of the underlying malloc() implementation will be returned
  4225. (typically NULL with errno will be set to ENOMEM).
  4226. \param none No parameters
  4227. _Example_
  4228. \code
  4229. WOLFSSL_METHOD* method;
  4230. WOLFSSL_CTX* ctx;
  4231. method = wolfSSLv23_server_method();
  4232. if (method == NULL) {
  4233. // unable to get method
  4234. }
  4235. ctx = wolfSSL_CTX_new(method);
  4236. ...
  4237. \endcode
  4238. \sa wolfSSLv3_server_method
  4239. \sa wolfTLSv1_server_method
  4240. \sa wolfTLSv1_1_server_method
  4241. \sa wolfTLSv1_2_server_method
  4242. \sa wolfDTLSv1_server_method
  4243. \sa wolfSSL_CTX_new
  4244. */
  4245. WOLFSSL_API WOLFSSL_METHOD *wolfSSLv23_server_method(void);
  4246. /*!
  4247. \ingroup Setup
  4248. \brief This is used to get the internal error state of the WOLFSSL structure.
  4249. \return wolfssl_error returns ssl error state, usually a negative
  4250. \return BAD_FUNC_ARG if ssl is NULL.
  4251. \return ssl WOLFSSL structure to get state from.
  4252. _Example_
  4253. \code
  4254. WOLFSSL* ssl;
  4255. int ret;
  4256. // create ssl object
  4257. ret = wolfSSL_state(ssl);
  4258. // check ret value
  4259. \endcode
  4260. \sa wolfSSL_new
  4261. \sa wolfSSL_free
  4262. */
  4263. WOLFSSL_API int wolfSSL_state(WOLFSSL* ssl);
  4264. /*!
  4265. \ingroup CertsKeys
  4266. \brief This function gets the peer’s certificate.
  4267. \return pointer a pointer to the peerCert member of the WOLFSSL_X509
  4268. structure if it exists.
  4269. \return 0 returned if the peer certificate issuer size is not defined.
  4270. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4271. _Example_
  4272. \code
  4273. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4274. WOLFSSL* ssl = wolfSSL_new(ctx);
  4275. ...
  4276. WOLFSSL_X509* peerCert = wolfSSL_get_peer_certificate(ssl);
  4277. if(peerCert){
  4278. // You have a pointer peerCert to the peer certification
  4279. }
  4280. \endcode
  4281. \sa wolfSSL_X509_get_issuer_name
  4282. \sa wolfSSL_X509_get_subject_name
  4283. \sa wolfSSL_X509_get_isCA
  4284. */
  4285. WOLFSSL_API WOLFSSL_X509* wolfSSL_get_peer_certificate(WOLFSSL* ssl);
  4286. /*!
  4287. \ingroup Debug
  4288. \brief This function is similar to calling wolfSSL_get_error() and
  4289. getting SSL_ERROR_WANT_READ in return. If the underlying error state
  4290. is SSL_ERROR_WANT_READ, this function will return 1, otherwise, 0.
  4291. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_READ, the
  4292. underlying I/O has data available for reading.
  4293. \return 0 There is no SSL_ERROR_WANT_READ error state.
  4294. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4295. _Example_
  4296. \code
  4297. int ret;
  4298. WOLFSSL* ssl = 0;
  4299. ...
  4300. ret = wolfSSL_want_read(ssl);
  4301. if (ret == 1) {
  4302. // underlying I/O has data available for reading (SSL_ERROR_WANT_READ)
  4303. }
  4304. \endcode
  4305. \sa wolfSSL_want_write
  4306. \sa wolfSSL_get_error
  4307. */
  4308. WOLFSSL_API int wolfSSL_want_read(WOLFSSL*);
  4309. /*!
  4310. \ingroup Debug
  4311. \brief This function is similar to calling wolfSSL_get_error() and getting
  4312. SSL_ERROR_WANT_WRITE in return. If the underlying error state is
  4313. SSL_ERROR_WANT_WRITE, this function will return 1, otherwise, 0.
  4314. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_WRITE, the
  4315. underlying I/O needs data to be written in order for progress to be
  4316. made in the underlying SSL connection.
  4317. \return 0 There is no SSL_ERROR_WANT_WRITE error state.
  4318. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4319. _Example_
  4320. \code
  4321. int ret;
  4322. WOLFSSL* ssl = 0;
  4323. ...
  4324. ret = wolfSSL_want_write(ssl);
  4325. if (ret == 1) {
  4326. // underlying I/O needs data to be written (SSL_ERROR_WANT_WRITE)
  4327. }
  4328. \endcode
  4329. \sa wolfSSL_want_read
  4330. \sa wolfSSL_get_error
  4331. */
  4332. WOLFSSL_API int wolfSSL_want_write(WOLFSSL*);
  4333. /*!
  4334. \ingroup Setup
  4335. \brief wolfSSL by default checks the peer certificate for a valid date
  4336. range and a verified signature. Calling this function before
  4337. wolfSSL_connect() or wolfSSL_accept() will add a domain name check to
  4338. the list of checks to perform. dn holds the domain name to check
  4339. against the peer certificate when it’s received.
  4340. \return SSL_SUCCESS upon success.
  4341. \return SSL_FAILURE will be returned if a memory error was encountered.
  4342. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4343. \param dn domain name to check against the peer certificate when received.
  4344. _Example_
  4345. \code
  4346. int ret = 0;
  4347. WOLFSSL* ssl;
  4348. char* domain = (char*) “www.yassl.com”;
  4349. ...
  4350. ret = wolfSSL_check_domain_name(ssl, domain);
  4351. if (ret != SSL_SUCCESS) {
  4352. // failed to enable domain name check
  4353. }
  4354. \endcode
  4355. \sa none
  4356. */
  4357. WOLFSSL_API int wolfSSL_check_domain_name(WOLFSSL* ssl, const char* dn);
  4358. /*!
  4359. \ingroup TLS
  4360. \brief Initializes the wolfSSL library for use. Must be called once per
  4361. application and before any other call to the library.
  4362. \return SSL_SUCCESS If successful the call will return.
  4363. \return BAD_MUTEX_E is an error that may be returned.
  4364. \return WC_INIT_E wolfCrypt initialization error returned.
  4365. _Example_
  4366. \code
  4367. int ret = 0;
  4368. ret = wolfSSL_Init();
  4369. if (ret != SSL_SUCCESS) {
  4370. failed to initialize wolfSSL library
  4371. }
  4372. \endcode
  4373. \sa wolfSSL_Cleanup
  4374. */
  4375. WOLFSSL_API int wolfSSL_Init(void);
  4376. /*!
  4377. \ingroup TLS
  4378. \brief Un-initializes the wolfSSL library from further use. Doesn’t have
  4379. to be called, though it will free any resources used by the library.
  4380. \return SSL_SUCCESS return no errors.
  4381. \return BAD_MUTEX_E a mutex error return.]
  4382. _Example_
  4383. \code
  4384. wolfSSL_Cleanup();
  4385. \endcode
  4386. \sa wolfSSL_Init
  4387. */
  4388. WOLFSSL_API int wolfSSL_Cleanup(void);
  4389. /*!
  4390. \ingroup IO
  4391. \brief This function returns the current library version.
  4392. \return LIBWOLFSSL_VERSION_STRING a const char pointer defining the
  4393. version.
  4394. \param none No parameters.
  4395. _Example_
  4396. \code
  4397. char version[MAXSIZE];
  4398. version = wolfSSL_KeepArrays();
  4399. if(version != ExpectedVersion){
  4400. // Handle the mismatch case
  4401. }
  4402. \endcode
  4403. \sa word32_wolfSSL_lib_version_hex
  4404. */
  4405. WOLFSSL_API const char* wolfSSL_lib_version(void);
  4406. /*!
  4407. \ingroup IO
  4408. \brief This function returns the current library version in hexadecimal
  4409. notation.
  4410. \return LILBWOLFSSL_VERSION_HEX returns the hexadecimal version defined in
  4411. wolfssl/version.h.
  4412. \param none No parameters.
  4413. _Example_
  4414. \code
  4415. word32 libV;
  4416. libV = wolfSSL_lib_version_hex();
  4417. if(libV != EXPECTED_HEX){
  4418. // How to handle an unexpected value
  4419. } else {
  4420. // The expected result for libV
  4421. }
  4422. \endcode
  4423. \sa wolfSSL_lib_version
  4424. */
  4425. WOLFSSL_API word32 wolfSSL_lib_version_hex(void);
  4426. /*!
  4427. \ingroup IO
  4428. \brief Performs the actual connect or accept based on the side of the SSL
  4429. method. If called from the client side then an wolfSSL_connect() is done
  4430. while a wolfSSL_accept() is performed if called from the server side.
  4431. \return SSL_SUCCESS will be returned if successful. (Note, older versions
  4432. will return 0.)
  4433. \return SSL_FATAL_ERROR will be returned if the underlying call resulted
  4434. in an error. Use wolfSSL_get_error() to get a specific error code.
  4435. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4436. _Example_
  4437. \code
  4438. int ret = SSL_FATAL_ERROR;
  4439. WOLFSSL* ssl = 0;
  4440. ...
  4441. ret = wolfSSL_negotiate(ssl);
  4442. if (ret == SSL_FATAL_ERROR) {
  4443. // SSL establishment failed
  4444. int error_code = wolfSSL_get_error(ssl);
  4445. ...
  4446. }
  4447. ...
  4448. \endcode
  4449. \sa SSL_connect
  4450. \sa SSL_accept
  4451. */
  4452. WOLFSSL_API int wolfSSL_negotiate(WOLFSSL* ssl);
  4453. /*!
  4454. \ingroup Setup
  4455. \brief Turns on the ability to use compression for the SSL connection.
  4456. Both sides must have compression turned on otherwise compression will not be
  4457. used. The zlib library performs the actual data compression. To compile
  4458. into the library use --with-libz for the configure system and define
  4459. HAVE_LIBZ otherwise. Keep in mind that while compressing data before
  4460. sending decreases the actual size of the messages being sent and received,
  4461. the amount of data saved by compression usually takes longer in time to
  4462. analyze than it does to send it raw on all but the slowest of networks.
  4463. \return SSL_SUCCESS upon success.
  4464. \return NOT_COMPILED_IN will be returned if compression support wasn’t
  4465. built into the library.
  4466. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4467. _Example_
  4468. \code
  4469. int ret = 0;
  4470. WOLFSSL* ssl = 0;
  4471. ...
  4472. ret = wolfSSL_set_compression(ssl);
  4473. if (ret == SSL_SUCCESS) {
  4474. // successfully enabled compression for SSL session
  4475. }
  4476. \endcode
  4477. \sa none
  4478. */
  4479. WOLFSSL_API int wolfSSL_set_compression(WOLFSSL* ssl);
  4480. /*!
  4481. \ingroup Setup
  4482. \brief This function sets the SSL session timeout value in seconds.
  4483. \return SSL_SUCCESS will be returned upon successfully setting the session.
  4484. \return BAD_FUNC_ARG will be returned if ssl is NULL.
  4485. \param ssl pointer to the SSL object, created with wolfSSL_new().
  4486. \param to value, in seconds, used to set the SSL session timeout.
  4487. _Example_
  4488. \code
  4489. int ret = 0;
  4490. WOLFSSL* ssl = 0;
  4491. ...
  4492. ret = wolfSSL_set_timeout(ssl, 500);
  4493. if (ret != SSL_SUCCESS) {
  4494. // failed to set session timeout value
  4495. }
  4496. ...
  4497. \endcode
  4498. \sa wolfSSL_get_session
  4499. \sa wolfSSL_set_session
  4500. */
  4501. WOLFSSL_API int wolfSSL_set_timeout(WOLFSSL*, unsigned int);
  4502. /*!
  4503. \ingroup Setup
  4504. \brief This function sets the timeout value for SSL sessions, in seconds,
  4505. for the specified SSL context.
  4506. \return SSL_SUCCESS will be returned upon success.
  4507. \return BAD_FUNC_ARG will be returned when the input context (ctx) is null.
  4508. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  4509. \param to session timeout value in seconds.
  4510. _Example_
  4511. \code
  4512. WOLFSSL_CTX* ctx = 0;
  4513. ...
  4514. ret = wolfSSL_CTX_set_timeout(ctx, 500);
  4515. if (ret != SSL_SUCCESS) {
  4516. // failed to set session timeout value
  4517. }
  4518. \endcode
  4519. \sa wolfSSL_flush_sessions
  4520. \sa wolfSSL_get_session
  4521. \sa wolfSSL_set_session
  4522. \sa wolfSSL_get_sessionID
  4523. \sa wolfSSL_CTX_set_session_cache_mode
  4524. */
  4525. WOLFSSL_API int wolfSSL_CTX_set_timeout(WOLFSSL_CTX*, unsigned int);
  4526. /*!
  4527. \ingroup openSSL
  4528. \brief Retrieves the peer’s certificate chain.
  4529. \return chain If successful the call will return the peer’s
  4530. certificate chain.
  4531. \return 0 will be returned if an invalid WOLFSSL pointer is passed to the
  4532. function.
  4533. \param ssl pointer to a valid WOLFSSL structure.
  4534. _Example_
  4535. \code
  4536. none
  4537. \endcode
  4538. \sa wolfSSL_get_chain_count
  4539. \sa wolfSSL_get_chain_length
  4540. \sa wolfSSL_get_chain_cert
  4541. \sa wolfSSL_get_chain_cert_pem
  4542. */
  4543. WOLFSSL_API WOLFSSL_X509_CHAIN* wolfSSL_get_peer_chain(WOLFSSL* ssl);
  4544. /*!
  4545. \ingroup openSSL
  4546. \brief Retrieve's the peers certificate chain count.
  4547. \return Success If successful the call will return the peer’s certificate
  4548. chain count.
  4549. \return 0 will be returned if an invalid chain pointer is passed to
  4550. the function.
  4551. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4552. _Example_
  4553. \code
  4554. none
  4555. \endcode
  4556. \sa wolfSSL_get_peer_chain
  4557. \sa wolfSSL_get_chain_length
  4558. \sa wolfSSL_get_chain_cert
  4559. \sa wolfSSL_get_chain_cert_pem
  4560. */
  4561. WOLFSSL_API int wolfSSL_get_chain_count(WOLFSSL_X509_CHAIN* chain);
  4562. /*!
  4563. \ingroup openSSL
  4564. \brief Retrieves the peer’s ASN1.DER certificate length in bytes
  4565. at index (idx).
  4566. \return Success If successful the call will return the peer’s
  4567. certificate length in bytes by index.
  4568. \return 0 will be returned if an invalid chain pointer is passed
  4569. to the function.
  4570. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4571. \param idx index to start of chain.
  4572. _Example_
  4573. \code
  4574. none
  4575. \endcode
  4576. \sa wolfSSL_get_peer_chain
  4577. \sa wolfSSL_get_chain_count
  4578. \sa wolfSSL_get_chain_cert
  4579. \sa wolfSSL_get_chain_cert_pem
  4580. */
  4581. WOLFSSL_API int wolfSSL_get_chain_length(WOLFSSL_X509_CHAIN*, int idx);
  4582. /*!
  4583. \ingroup openSSL
  4584. \brief Retrieves the peer’s ASN1.DER certificate at index (idx).
  4585. \return Success If successful the call will return the peer’s
  4586. certificate by index.
  4587. \return 0 will be returned if an invalid chain pointer is passed
  4588. to the function.
  4589. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4590. \param idx index to start of chain.
  4591. _Example_
  4592. \code
  4593. none
  4594. \endcode
  4595. \sa wolfSSL_get_peer_chain
  4596. \sa wolfSSL_get_chain_count
  4597. \sa wolfSSL_get_chain_length
  4598. \sa wolfSSL_get_chain_cert_pem
  4599. */
  4600. WOLFSSL_API unsigned char* wolfSSL_get_chain_cert(WOLFSSL_X509_CHAIN*, int idx);
  4601. /*!
  4602. \ingroup CertsKeys
  4603. \brief This function gets the peer’s wolfSSL_X509_certificate at
  4604. index (idx) from the chain of certificates.
  4605. \return pointer returns a pointer to a WOLFSSL_X509 structure.
  4606. \param chain a pointer to the WOLFSSL_X509_CHAIN used for no dynamic
  4607. memory SESSION_CACHE.
  4608. \param idx the index of the WOLFSSL_X509 certificate.
  4609. _Example_
  4610. \code
  4611. WOLFSSL_X509_CHAIN* chain = &session->chain;
  4612. int idx = 999; // set idx
  4613. ...
  4614. WOLFSSL_X509_CHAIN ptr;
  4615. prt = wolfSSL_get_chain_X509(chain, idx);
  4616. if(ptr != NULL){
  4617. //ptr contains the cert at the index specified
  4618. } else {
  4619. // ptr is NULL
  4620. }
  4621. \endcode
  4622. \sa InitDecodedCert
  4623. \sa ParseCertRelative
  4624. \sa CopyDecodedToX509
  4625. */
  4626. WOLFSSL_API WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN*, int idx);
  4627. /*!
  4628. \ingroup openSSL
  4629. \brief Retrieves the peer’s PEM certificate at index (idx).
  4630. \return Success If successful the call will return the peer’s
  4631. certificate by index.
  4632. \return 0 will be returned if an invalid chain pointer is passed to
  4633. the function.
  4634. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4635. \param idx indexto start of chain.
  4636. _Example_
  4637. \code
  4638. none
  4639. \endcode
  4640. \sa wolfSSL_get_peer_chain
  4641. \sa wolfSSL_get_chain_count
  4642. \sa wolfSSL_get_chain_length
  4643. \sa wolfSSL_get_chain_cert
  4644. */
  4645. WOLFSSL_API int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN*, int idx,
  4646. unsigned char* buf, int inLen, int* outLen);
  4647. /*!
  4648. \ingroup openSSL
  4649. \brief Retrieves the session’s ID. The session ID is always 32 bytes long.
  4650. \return id The session ID.
  4651. \param session pointer to a valid wolfssl session.
  4652. _Example_
  4653. \code
  4654. none
  4655. \endcode
  4656. \sa SSL_get_session
  4657. */
  4658. WOLFSSL_API const unsigned char* wolfSSL_get_sessionID(const WOLFSSL_SESSION* s);
  4659. /*!
  4660. \ingroup openSSL
  4661. \brief Retrieves the peer’s certificate serial number. The serial
  4662. number buffer (in) should be at least 32 bytes long and be provided
  4663. as the *inOutSz argument as input. After calling the function *inOutSz
  4664. will hold the actual length in bytes written to the in buffer.
  4665. \return SSL_SUCCESS upon success.
  4666. \return BAD_FUNC_ARG will be returned if a bad function argument
  4667. was encountered.
  4668. \param in The serial number buffer and should be at least 32 bytes long
  4669. \param inOutSz will hold the actual length in bytes written to the
  4670. in buffer.
  4671. _Example_
  4672. \code
  4673. none
  4674. \endcode
  4675. \sa SSL_get_peer_certificate
  4676. */
  4677. WOLFSSL_API int wolfSSL_X509_get_serial_number(WOLFSSL_X509*,unsigned char*,int*);
  4678. /*!
  4679. \ingroup CertsKeys
  4680. \brief Returns the common name of the subject from the certificate.
  4681. \return NULL returned if the x509 structure is null
  4682. \return string a string representation of the subject's common
  4683. name is returned upon success
  4684. \param x509 a pointer to a WOLFSSL_X509 structure containing
  4685. certificate information.
  4686. _Example_
  4687. \code
  4688. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4689. DYNAMIC_TYPE_X509);
  4690. ...
  4691. int x509Cn = wolfSSL_X509_get_subjectCN(x509);
  4692. if(x509Cn == NULL){
  4693. // Deal with NULL case
  4694. } else {
  4695. // x509Cn contains the common name
  4696. }
  4697. \endcode
  4698. \sa wolfSSL_X509_Name_get_entry
  4699. \sa wolfSSL_X509_get_next_altname
  4700. \sa wolfSSL_X509_get_issuer_name
  4701. \sa wolfSSL_X509_get_subject_name
  4702. */
  4703. WOLFSSL_API char* wolfSSL_X509_get_subjectCN(WOLFSSL_X509*);
  4704. /*!
  4705. \ingroup CertsKeys
  4706. \brief This function gets the DER encoded certificate in the
  4707. WOLFSSL_X509 struct.
  4708. \return buffer This function returns the DerBuffer structure’s
  4709. buffer member, which is of type byte.
  4710. \return NULL returned if the x509 or outSz parameter is NULL.
  4711. \param x509 a pointer to a WOLFSSL_X509 structure containing
  4712. certificate information.
  4713. \param outSz length of the derBuffer member of the WOLFSSL_X509 struct.
  4714. _Example_
  4715. \code
  4716. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4717. DYNAMIC_TYPE_X509);
  4718. int* outSz; // initialize
  4719. ...
  4720. byte* x509Der = wolfSSL_X509_get_der(x509, outSz);
  4721. if(x509Der == NULL){
  4722. // Failure case one of the parameters was NULL
  4723. }
  4724. \endcode
  4725. \sa wolfSSL_X509_version
  4726. \sa wolfSSL_X509_Name_get_entry
  4727. \sa wolfSSL_X509_get_next_altname
  4728. \sa wolfSSL_X509_get_issuer_name
  4729. \sa wolfSSL_X509_get_subject_name
  4730. */
  4731. WOLFSSL_API const unsigned char* wolfSSL_X509_get_der(WOLFSSL_X509*, int*);
  4732. /*!
  4733. \ingroup CertsKeys
  4734. \brief This function checks to see if x509 is NULL and if it’s not,
  4735. it returns the notAfter member of the x509 struct.
  4736. \return pointer to struct with ASN1_TIME to the notAfter
  4737. member of the x509 struct.
  4738. \return NULL returned if the x509 object is NULL.
  4739. \param x509 a pointer to the WOLFSSL_X509 struct.
  4740. _Example_
  4741. \code
  4742. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  4743. DYNAMIC_TYPE_X509) ;
  4744. ...
  4745. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notAfter(x509);
  4746. if(notAfter == NULL){
  4747. // Failure case, the x509 object is null.
  4748. }
  4749. \endcode
  4750. \sa wolfSSL_X509_get_notBefore
  4751. */
  4752. WOLFSSL_API WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notAfter(WOLFSSL_X509*);
  4753. /*!
  4754. \ingroup CertsKeys
  4755. \brief This function retrieves the version of the X509 certificate.
  4756. \return 0 returned if the x509 structure is NULL.
  4757. \return version the version stored in the x509 structure will be returned.
  4758. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4759. _Example_
  4760. \code
  4761. WOLFSSL_X509* x509;
  4762. int version;
  4763. ...
  4764. version = wolfSSL_X509_version(x509);
  4765. if(!version){
  4766. // The function returned 0, failure case.
  4767. }
  4768. \endcode
  4769. \sa wolfSSL_X509_get_subject_name
  4770. \sa wolfSSL_X509_get_issuer_name
  4771. \sa wolfSSL_X509_get_isCA
  4772. \sa wolfSSL_get_peer_certificate
  4773. */
  4774. WOLFSSL_API int wolfSSL_X509_version(WOLFSSL_X509*);
  4775. /*!
  4776. \ingroup CertsKeys
  4777. \brief If NO_STDIO_FILESYSTEM is defined this function will allocate
  4778. heap memory, initialize a WOLFSSL_X509 structure and return a pointer to it.
  4779. \return *WOLFSSL_X509 WOLFSSL_X509 structure pointer is returned if
  4780. the function executes successfully.
  4781. \return NULL if the call to XFTELL macro returns a negative value.
  4782. \param x509 a pointer to a WOLFSSL_X509 pointer.
  4783. \param file a defined type that is a pointer to a FILE.
  4784. _Example_
  4785. \code
  4786. WOLFSSL_X509* x509a = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4787. DYNAMIC_TYPE_X509);
  4788. WOLFSSL_X509** x509 = x509a;
  4789. XFILE file; (mapped to struct fs_file*)
  4790. ...
  4791. WOLFSSL_X509* newX509 = wolfSSL_X509_d2i_fp(x509, file);
  4792. if(newX509 == NULL){
  4793. // The function returned NULL
  4794. }
  4795. \endcode
  4796. \sa wolfSSL_X509_d2i
  4797. \sa XFTELL
  4798. \sa XREWIND
  4799. \sa XFSEEK
  4800. */
  4801. WOLFSSL_API WOLFSSL_X509*
  4802. wolfSSL_X509_d2i_fp(WOLFSSL_X509** x509, FILE* file);
  4803. /*!
  4804. \ingroup CertsKeys
  4805. \brief The function loads the x509 certificate into memory.
  4806. \return pointer a successful execution returns pointer to a
  4807. WOLFSSL_X509 structure.
  4808. \return NULL returned if the certificate was not able to be written.
  4809. \param fname the certificate file to be loaded.
  4810. \param format the format of the certificate.
  4811. _Example_
  4812. \code
  4813. #define cliCert “certs/client-cert.pem”
  4814. X509* x509;
  4815. x509 = wolfSSL_X509_load_certificate_file(cliCert, SSL_FILETYPE_PEM);
  4816. AssertNotNull(x509);
  4817. \endcode
  4818. \sa InitDecodedCert
  4819. \sa PemToDer
  4820. \sa wolfSSL_get_certificate
  4821. \sa AssertNotNull
  4822. */
  4823. WOLFSSL_API WOLFSSL_X509*
  4824. wolfSSL_X509_load_certificate_file(const char* fname, int format);
  4825. /*!
  4826. \ingroup CertsKeys
  4827. \brief This function copies the device type from the x509 structure
  4828. to the buffer.
  4829. \return pointer returns a byte pointer holding the device type from
  4830. the x509 structure.
  4831. \return NULL returned if the buffer size is NULL.
  4832. \param x509 pointer to a WOLFSSL_X509 structure, created with
  4833. WOLFSSL_X509_new().
  4834. \param in a pointer to a byte type that will hold the device type
  4835. (the buffer).
  4836. \param inOutSz the minimum of either the parameter inOutSz or the
  4837. deviceTypeSz member of the x509 structure.
  4838. _Example_
  4839. \code
  4840. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  4841. DYNAMIC_TYPE_X509);
  4842. byte* in;
  4843. int* inOutSz;
  4844. ...
  4845. byte* deviceType = wolfSSL_X509_get_device_type(x509, in, inOutSz);
  4846. if(!deviceType){
  4847. // Failure case, NULL was returned.
  4848. }
  4849. \endcode
  4850. \sa wolfSSL_X509_get_hw_type
  4851. \sa wolfSSL_X509_get_hw_serial_number
  4852. \sa wolfSSL_X509_d2i
  4853. */
  4854. WOLFSSL_API unsigned char*
  4855. wolfSSL_X509_get_device_type(WOLFSSL_X509*, unsigned char*, int*);
  4856. /*!
  4857. \ingroup CertsKeys
  4858. \brief The function copies the hwType member of the WOLFSSL_X509
  4859. structure to the buffer.
  4860. \return byte The function returns a byte type of the data previously held
  4861. in the hwType member of the WOLFSSL_X509 structure.
  4862. \return NULL returned if inOutSz is NULL.
  4863. \param x509 a pointer to a WOLFSSL_X509 structure containing certificate
  4864. information.
  4865. \param in pointer to type byte that represents the buffer.
  4866. \param inOutSz pointer to type int that represents the size of the buffer.
  4867. _Example_
  4868. \code
  4869. WOLFSSL_X509* x509; // X509 certificate
  4870. byte* in; // initialize the buffer
  4871. int* inOutSz; // holds the size of the buffer
  4872. ...
  4873. byte* hwType = wolfSSL_X509_get_hw_type(x509, in, inOutSz);
  4874. if(hwType == NULL){
  4875. // Failure case function returned NULL.
  4876. }
  4877. \endcode
  4878. \sa wolfSSL_X509_get_hw_serial_number
  4879. \sa wolfSSL_X509_get_device_type
  4880. */
  4881. WOLFSSL_API unsigned char*
  4882. wolfSSL_X509_get_hw_type(WOLFSSL_X509*, unsigned char*, int*);
  4883. /*!
  4884. \ingroup CertsKeys
  4885. \brief This function returns the hwSerialNum member of the x509 object.
  4886. \return pointer the function returns a byte pointer to the in buffer that
  4887. will contain the serial number loaded from the x509 object.
  4888. \param x509 pointer to a WOLFSSL_X509 structure containing certificate
  4889. information.
  4890. \param in a pointer to the buffer that will be copied to.
  4891. \param inOutSz a pointer to the size of the buffer.
  4892. _Example_
  4893. \code
  4894. char* serial;
  4895. byte* in;
  4896. int* inOutSz;
  4897. WOLFSSL_X509 x509;
  4898. ...
  4899. serial = wolfSSL_X509_get_hw_serial_number(x509, in, inOutSz);
  4900. if(serial == NULL || serial <= 0){
  4901. // Failure case
  4902. }
  4903. \endcode
  4904. \sa wolfSSL_X509_get_subject_name
  4905. \sa wolfSSL_X509_get_issuer_name
  4906. \sa wolfSSL_X509_get_isCA
  4907. \sa wolfSSL_get_peer_certificate
  4908. \sa wolfSSL_X509_version
  4909. */
  4910. WOLFSSL_API unsigned char*
  4911. wolfSSL_X509_get_hw_serial_number(WOLFSSL_X509*, unsigned char*, int*);
  4912. /*!
  4913. \ingroup IO
  4914. \brief This function is called on the client side and initiates an
  4915. SSL/TLS handshake with a server only long enough to get the peer’s
  4916. certificate chain. When this function is called, the underlying
  4917. communication channel has already been set up. wolfSSL_connect_cert()
  4918. works with both blocking and non-blocking I/O. When the underlying I/O
  4919. is non-blocking, wolfSSL_connect_cert() will return when the underlying
  4920. I/O could not satisfy the needs of wolfSSL_connect_cert() to continue the
  4921. handshake. In this case, a call to wolfSSL_get_error() will yield either
  4922. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then
  4923. repeat the call to wolfSSL_connect_cert() when the underlying I/O is ready
  4924. and wolfSSL will pick up where it left off. When using a non-blocking
  4925. socket, nothing needs to be done, but select() can be used to check for
  4926. the required condition. If the underlying I/O is blocking,
  4927. wolfSSL_connect_cert() will only return once the peer’s certificate chain
  4928. has been received.
  4929. \return SSL_SUCCESS upon success.
  4930. \return SSL_FAILURE will be returned if the SSL session parameter is NULL.
  4931. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a more
  4932. detailed error code, call wolfSSL_get_error().
  4933. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4934. _Example_
  4935. \code
  4936. int ret = 0;
  4937. int err = 0;
  4938. WOLFSSL* ssl;
  4939. char buffer[80];
  4940. ...
  4941. ret = wolfSSL_connect_cert(ssl);
  4942. if (ret != SSL_SUCCESS) {
  4943. err = wolfSSL_get_error(ssl, ret);
  4944. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  4945. }
  4946. \endcode
  4947. \sa wolfSSL_get_error
  4948. \sa wolfSSL_connect
  4949. \sa wolfSSL_accept
  4950. */
  4951. WOLFSSL_API int wolfSSL_connect_cert(WOLFSSL* ssl);
  4952. /*!
  4953. \ingroup openSSL
  4954. \brief wolfSSL_d2i_PKCS12_bio (d2i_PKCS12_bio) copies in the PKCS12
  4955. information from WOLFSSL_BIO to the structure WC_PKCS12. The information
  4956. is divided up in the structure as a list of Content Infos along with a
  4957. structure to hold optional MAC information. After the information has been
  4958. divided into chunks (but not decrypted) in the structure WC_PKCS12, it can
  4959. then be parsed and decrypted by calling.
  4960. \return WC_PKCS12 pointer to a WC_PKCS12 structure.
  4961. \return Failure If function failed it will return NULL.
  4962. \param bio WOLFSSL_BIO structure to read PKCS12 buffer from.
  4963. \param pkcs12 WC_PKCS12 structure pointer for new PKCS12 structure created.
  4964. Can be NULL
  4965. _Example_
  4966. \code
  4967. WC_PKCS12* pkcs;
  4968. WOLFSSL_BIO* bio;
  4969. WOLFSSL_X509* cert;
  4970. WOLFSSL_EVP_PKEY* pkey;
  4971. STACK_OF(X509) certs;
  4972. //bio loads in PKCS12 file
  4973. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  4974. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  4975. wc_PKCS12_free(pkcs)
  4976. //use cert, pkey, and optionally certs stack
  4977. \endcode
  4978. \sa wolfSSL_PKCS12_parse
  4979. \sa wc_PKCS12_free
  4980. */
  4981. WOLFSSL_API WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio,
  4982. WC_PKCS12** pkcs12);
  4983. /*!
  4984. \ingroup openSSL
  4985. \brief wolfSSL_i2d_PKCS12_bio (i2d_PKCS12_bio) copies in the cert
  4986. information from the structure WC_PKCS12 to WOLFSSL_BIO.
  4987. \return 1 for success.
  4988. \return Failure 0.
  4989. \param bio WOLFSSL_BIO structure to write PKCS12 buffer to.
  4990. \param pkcs12 WC_PKCS12 structure for PKCS12 structure as input.
  4991. _Example_
  4992. \code
  4993. WC_PKCS12 pkcs12;
  4994. FILE *f;
  4995. byte buffer[5300];
  4996. char file[] = "./test.p12";
  4997. int bytes;
  4998. WOLFSSL_BIO* bio;
  4999. pkcs12 = wc_PKCS12_new();
  5000. f = fopen(file, "rb");
  5001. bytes = (int)fread(buffer, 1, sizeof(buffer), f);
  5002. fclose(f);
  5003. //convert the DER file into an internal structure
  5004. wc_d2i_PKCS12(buffer, bytes, pkcs12);
  5005. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  5006. //convert PKCS12 structure into bio
  5007. wolfSSL_i2d_PKCS12_bio(bio, pkcs12);
  5008. wc_PKCS12_free(pkcs)
  5009. //use bio
  5010. \endcode
  5011. \sa wolfSSL_PKCS12_parse
  5012. \sa wc_PKCS12_free
  5013. */
  5014. WOLFSSL_API WC_PKCS12* wolfSSL_i2d_PKCS12_bio(WOLFSSL_BIO* bio,
  5015. WC_PKCS12* pkcs12);
  5016. /*!
  5017. \ingroup openSSL
  5018. \brief PKCS12 can be enabled with adding –enable-opensslextra to the
  5019. configure command. It can use triple DES and RC4 for decryption so would
  5020. recommend also enabling these features when enabling opensslextra
  5021. (--enable-des3 –enable-arc4). wolfSSL does not currently support RC2 so
  5022. decryption with RC2 is currently not available. This may be noticeable
  5023. with default encryption schemes used by OpenSSL command line to create
  5024. .p12 files. wolfSSL_PKCS12_parse (PKCS12_parse). The first thing this
  5025. function does is check the MAC is correct if present. If the MAC fails
  5026. then the function returns and does not try to decrypt any of the stored
  5027. Content Infos. This function then parses through each Content Info
  5028. looking for a bag type, if the bag type is known it is decrypted as
  5029. needed and either stored in the list of certificates being built or as
  5030. a key found. After parsing through all bags the key found is then
  5031. compared with the certificate list until a matching pair is found.
  5032. This matching pair is then returned as the key and certificate,
  5033. optionally the certificate list found is returned as a STACK_OF
  5034. certificates. At the moment a CRL, Secret or SafeContents bag will be
  5035. skipped over and not parsed. It can be seen if these or other “Unknown”
  5036. bags are skipped over by viewing the debug print out. Additional attributes
  5037. such as friendly name are skipped over when parsing a PKCS12 file.
  5038. \return SSL_SUCCESS On successfully parsing PKCS12.
  5039. \return SSL_FAILURE If an error case was encountered.
  5040. \param pkcs12 WC_PKCS12 structure to parse.
  5041. \param paswd password for decrypting PKCS12.
  5042. \param pkey structure to hold private key decoded from PKCS12.
  5043. \param cert structure to hold certificate decoded from PKCS12.
  5044. \param stack optional stack of extra certificates.
  5045. _Example_
  5046. \code
  5047. WC_PKCS12* pkcs;
  5048. WOLFSSL_BIO* bio;
  5049. WOLFSSL_X509* cert;
  5050. WOLFSSL_EVP_PKEY* pkey;
  5051. STACK_OF(X509) certs;
  5052. //bio loads in PKCS12 file
  5053. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5054. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5055. wc_PKCS12_free(pkcs)
  5056. //use cert, pkey, and optionally certs stack
  5057. \endcode
  5058. \sa wolfSSL_d2i_PKCS12_bio
  5059. \sa wc_PKCS12_free
  5060. */
  5061. WOLFSSL_API int wolfSSL_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
  5062. WOLFSSL_EVP_PKEY** pkey, WOLFSSL_X509** cert, WOLF_STACK_OF(WOLFSSL_X509)** ca);
  5063. /*!
  5064. \ingroup CertsKeys
  5065. \brief Server Diffie-Hellman Ephemeral parameters setting. This function
  5066. sets up the group parameters to be used if the server negotiates a cipher
  5067. suite that uses DHE.
  5068. \return SSL_SUCCESS upon success.
  5069. \return MEMORY_ERROR will be returned if a memory error was encountered.
  5070. \return SIDE_ERROR will be returned if this function is called on an SSL
  5071. client instead of an SSL server.
  5072. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5073. \param p Diffie-Hellman prime number parameter.
  5074. \param pSz size of p.
  5075. \param g Diffie-Hellman “generator” parameter.
  5076. \param gSz size of g.
  5077. _Example_
  5078. \code
  5079. WOLFSSL* ssl;
  5080. static unsigned char p[] = {...};
  5081. static unsigned char g[] = {...};
  5082. ...
  5083. wolfSSL_SetTmpDH(ssl, p, sizeof(p), g, sizeof(g));
  5084. \endcode
  5085. \sa SSL_accept
  5086. */
  5087. WOLFSSL_API int wolfSSL_SetTmpDH(WOLFSSL*, const unsigned char* p, int pSz,
  5088. const unsigned char* g, int gSz);
  5089. /*!
  5090. \ingroup CertsKeys
  5091. \brief The function calls the wolfSSL_SetTMpDH_buffer_wrapper,
  5092. which is a wrapper for Diffie-Hellman parameters.
  5093. \return SSL_SUCCESS on successful execution.
  5094. \return SSL_BAD_FILETYPE if the file type is not PEM and is not
  5095. ASN.1. It will also be returned if the wc_DhParamsLoad does not
  5096. return normally.
  5097. \return SSL_NO_PEM_HEADER returns from PemToDer if there is not
  5098. a PEM header.
  5099. \return SSL_BAD_FILE returned if there is a file error in PemToDer.
  5100. \return SSL_FATAL_ERROR returned from PemToDer if there was a copy error.
  5101. \return MEMORY_E - if there was a memory allocation error.
  5102. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  5103. there was otherwise a NULL argument passed to a subroutine.
  5104. \return DH_KEY_SIZE_E is returned if their is a key size error in
  5105. wolfSSL_SetTmpDH() or in wolfSSL_CTX_SetTmpDH().
  5106. \return SIDE_ERROR returned if it is not the server side
  5107. in wolfSSL_SetTmpDH.
  5108. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5109. \param buf allocated buffer passed in from wolfSSL_SetTMpDH_file_wrapper.
  5110. \param sz a long int that holds the size of the file
  5111. (fname within wolfSSL_SetTmpDH_file_wrapper).
  5112. \param format an integer type passed through from
  5113. wolfSSL_SetTmpDH_file_wrapper() that is a representation of the certificate
  5114. format.
  5115. _Example_
  5116. \code
  5117. Static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5118. Const char* fname, int format);
  5119. long sz = 0;
  5120. byte* myBuffer = staticBuffer[FILE_BUFFER_SIZE];
  5121. if(ssl)
  5122. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5123. \endcode
  5124. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5125. \sa wc_DhParamsLoad
  5126. \sa wolfSSL_SetTmpDH
  5127. \sa PemToDer
  5128. \sa wolfSSL_CTX_SetTmpDH
  5129. \sa wolfSSL_CTX_SetTmpDH_file
  5130. */
  5131. WOLFSSL_API int wolfSSL_SetTmpDH_buffer(WOLFSSL*, const unsigned char* b, long sz,
  5132. int format);
  5133. /*!
  5134. \ingroup CertsKeys
  5135. \brief This function calls wolfSSL_SetTmpDH_file_wrapper to set server
  5136. Diffie-Hellman parameters.
  5137. \return SSL_SUCCESS returned on successful completion of this function
  5138. and its subroutines.
  5139. \return MEMORY_E returned if a memory allocation failed in this function
  5140. or a subroutine.
  5141. \return SIDE_ERROR if the side member of the Options structure found
  5142. in the WOLFSSL struct is not the server side.
  5143. \return SSL_BAD_FILETYPE returns if the certificate fails a set of checks.
  5144. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5145. the value of the minDhKeySz member in the WOLFSSL struct.
  5146. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5147. than the value of the maxDhKeySz member in the WOLFSSL struct.
  5148. \return BAD_FUNC_ARG returns if an argument value is NULL that is not
  5149. permitted such as, the WOLFSSL structure.
  5150. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5151. \param fname a constant char pointer holding the certificate.
  5152. \param format an integer type that holds the format of the certification.
  5153. _Example_
  5154. \code
  5155. WOLFSSL* ssl = wolfSSL_new(ctx);
  5156. const char* dhParam;
  5157. AssertIntNE(SSL_SUCCESS,
  5158. wolfSSL_SetTmpDH_file(ssl, dhParam, SSL_FILETYPE_PEM));
  5159. \endcode
  5160. \sa wolfSSL_CTX_SetTmpDH_file
  5161. \sa wolfSSL_SetTmpDH_file_wrapper
  5162. \sa wolfSSL_SetTmpDH_buffer
  5163. \sa wolfSSL_CTX_SetTmpDH_buffer
  5164. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5165. \sa wolfSSL_SetTmpDH
  5166. \sa wolfSSL_CTX_SetTmpDH
  5167. */
  5168. WOLFSSL_API int wolfSSL_SetTmpDH_file(WOLFSSL*, const char* f, int format);
  5169. /*!
  5170. \ingroup CertsKeys
  5171. \brief Sets the parameters for the server CTX Diffie-Hellman.
  5172. \return SSL_SUCCESS returned if the function and all subroutines
  5173. return without error.
  5174. \return BAD_FUNC_ARG returned if the CTX, p or g parameters are NULL.
  5175. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5176. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5177. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5178. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5179. \return MEMORY_E returned if the allocation of memory failed in this
  5180. function or a subroutine.
  5181. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5182. wolfSSL_CTX_new().
  5183. \param p a constant unsigned char pointer loaded into the buffer
  5184. member of the serverDH_P struct.
  5185. \param pSz an int type representing the size of p, initialized
  5186. to MAX_DH_SIZE.
  5187. \param g a constant unsigned char pointer loaded into the buffer
  5188. member of the serverDH_G struct.
  5189. \param gSz an int type representing the size of g, initialized ot
  5190. MAX_DH_SIZE.
  5191. _Exmaple_
  5192. \code
  5193. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  5194. byte* p;
  5195. byte* g;
  5196. word32 pSz = (word32)sizeof(p)/sizeof(byte);
  5197. word32 gSz = (word32)sizeof(g)/sizeof(byte);
  5198. int ret = wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz);
  5199. if(ret != SSL_SUCCESS){
  5200. // Failure case
  5201. }
  5202. \endcode
  5203. \sa wolfSSL_SetTmpDH
  5204. \sa wc_DhParamsLoad
  5205. */
  5206. WOLFSSL_API int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX*, const unsigned char* p,
  5207. int pSz, const unsigned char* g, int gSz);
  5208. /*!
  5209. \ingroup CertsKeys
  5210. \brief A wrapper function that calls wolfSSL_SetTmpDH_buffer_wrapper
  5211. \return 0 returned for a successful execution.
  5212. \return BAD_FUNC_ARG returned if the ctx or buf parameters are NULL.
  5213. \return MEMORY_E if there is a memory allocation error.
  5214. \return SSL_BAD_FILETYPE returned if format is not correct.
  5215. \param ctx a pointer to a WOLFSSL structure, created using
  5216. wolfSSL_CTX_new().
  5217. \param buf a pointer to a constant unsigned char type that is
  5218. allocated as the buffer and passed through to
  5219. wolfSSL_SetTmpDH_buffer_wrapper.
  5220. \param sz a long integer type that is derived from the fname parameter
  5221. in wolfSSL_SetTmpDH_file_wrapper().
  5222. \param format an integer type passed through from
  5223. wolfSSL_SetTmpDH_file_wrapper().
  5224. _Example_
  5225. \code
  5226. static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5227. Const char* fname, int format);
  5228. #ifdef WOLFSSL_SMALL_STACK
  5229. byte staticBuffer[1]; // force heap usage
  5230. #else
  5231. byte* staticBuffer;
  5232. long sz = 0;
  5233. if(ssl){
  5234. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5235. } else {
  5236. ret = wolfSSL_CTX_SetTmpDH_buffer(ctx, myBuffer, sz, format);
  5237. }
  5238. \endcode
  5239. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5240. \sa wolfSSL_SetTMpDH_buffer
  5241. \sa wolfSSL_SetTmpDH_file_wrapper
  5242. \sa wolfSSL_CTX_SetTmpDH_file
  5243. */
  5244. WOLFSSL_API int wolfSSL_CTX_SetTmpDH_buffer(WOLFSSL_CTX*, const unsigned char* b,
  5245. long sz, int format);
  5246. /*!
  5247. \ingroup CertsKeys
  5248. \brief The function calls wolfSSL_SetTmpDH_file_wrapper to set the server
  5249. Diffie-Hellman parameters.
  5250. \return SSL_SUCCESS returned if the wolfSSL_SetTmpDH_file_wrapper or any
  5251. of its subroutines return successfully.
  5252. \return MEMORY_E returned if an allocation of dynamic memory fails in a
  5253. subroutine.
  5254. \return BAD_FUNC_ARG returned if the ctx or fname parameters are NULL or
  5255. if
  5256. a subroutine is passed a NULL argument.
  5257. \return SSL_BAD_FILE returned if the certificate file is unable to open or
  5258. if the a set of checks on the file fail from wolfSSL_SetTmpDH_file_wrapper.
  5259. \return SSL_BAD_FILETYPE returned if the format is not PEM or ASN.1 from
  5260. wolfSSL_SetTmpDH_buffer_wrapper().
  5261. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5262. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5263. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5264. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5265. \return SIDE_ERROR returned in wolfSSL_SetTmpDH() if the side is not the
  5266. server end.
  5267. \return SSL_NO_PEM_HEADER returned from PemToDer if there is no PEM header.
  5268. \return SSL_FATAL_ERROR returned from PemToDer if there is a memory copy
  5269. failure.
  5270. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5271. wolfSSL_CTX_new().
  5272. \param fname a constant character pointer to a certificate file.
  5273. \param format an integer type passed through from
  5274. wolfSSL_SetTmpDH_file_wrapper() that is a representation of
  5275. the certificate format.
  5276. _Example_
  5277. \code
  5278. #define dhParam “certs/dh2048.pem”
  5279. #DEFINE aSSERTiNTne(x, y) AssertInt(x, y, !=, ==)
  5280. WOLFSSL_CTX* ctx;
  5281. AssertNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  5282. AssertIntNE(SSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL, dhParam,
  5283. SSL_FILETYPE_PEM));
  5284. \endcode
  5285. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5286. \sa wolfSSL_SetTmpDH
  5287. \sa wolfSSL_CTX_SetTmpDH
  5288. \sa wolfSSL_SetTmpDH_buffer
  5289. \sa wolfSSL_CTX_SetTmpDH_buffer
  5290. \sa wolfSSL_SetTmpDH_file_wrapper
  5291. \sa AllocDer
  5292. \sa PemToDer
  5293. */
  5294. WOLFSSL_API int wolfSSL_CTX_SetTmpDH_file(WOLFSSL_CTX*, const char* f,
  5295. int format);
  5296. /*!
  5297. \ingroup CertsKeys
  5298. \brief This function sets the minimum size of the Diffie Hellman key size
  5299. by accessing the minDhKeySz member in the WOLFSSL_CTX structure.
  5300. \return SSL_SUCCESS returned if the function completes successfully.
  5301. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5302. the keySz is greater than 16,000 or not divisible by 8.
  5303. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5304. \param keySz a word16 type used to set the minimum DH key size. The
  5305. WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5306. _Example_
  5307. \code
  5308. public static int CTX_SetMinDhKey_Sz(IntPtr ctx, short minDhKey){
  5309. return wolfSSL_CTX_SetMinDhKey_Sz(local_ctx, minDhKey);
  5310. \endcode
  5311. \sa wolfSSL_SetMinDhKey_Sz
  5312. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5313. \sa wolfSSL_SetMaxDhKey_Sz
  5314. \sa wolfSSL_GetDhKey_Sz
  5315. \sa wolfSSL_CTX_SetTMpDH_file
  5316. */
  5317. WOLFSSL_API int wolfSSL_CTX_SetMinDhKey_Sz(WOLFSSL_CTX*, word16);
  5318. /*!
  5319. \ingroup CertsKeys
  5320. \brief Sets the minimum size for a Diffie-Hellman key in the WOLFSSL
  5321. structure in bytes.
  5322. \return SSL_SUCCESS the minimum size was successfully set.
  5323. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or the keySz parameter
  5324. was greater than the allowable size or not divisible by 8.
  5325. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5326. \param keySz a word16 type representing the bit size of the minimum DH key.
  5327. _Example_
  5328. \code
  5329. WOLFSSL* ssl = wolfSSL_new(ctx);
  5330. word16 keySz;
  5331. ...
  5332. if(wolfSSL_SetMinDhKey(ssl, keySz) != SSL_SUCCESS){
  5333. // Failed to set.
  5334. }
  5335. \endcode
  5336. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5337. \sa wolfSSL_GetDhKey_Sz
  5338. */
  5339. WOLFSSL_API int wolfSSL_SetMinDhKey_Sz(WOLFSSL*, word16);
  5340. /*!
  5341. \ingroup CertsKeys
  5342. \brief This function sets the maximum size of the Diffie Hellman key size
  5343. by accessing the maxDhKeySz member in the WOLFSSL_CTX structure.
  5344. \return SSL_SUCCESS returned if the function completes successfully.
  5345. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5346. the keySz is greater than 16,000 or not divisible by 8.
  5347. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5348. \param keySz a word16 type used to set the maximum DH key size. The
  5349. WOLFSSL_CTX struct holds this information in the maxDhKeySz member.
  5350. _Example_
  5351. \code
  5352. public static int CTX_SetMaxDhKey_Sz(IntPtr ctx, short maxDhKey){
  5353. return wolfSSL_CTX_SetMaxDhKey_Sz(local_ctx, maxDhKey);
  5354. \endcode
  5355. \sa wolfSSL_SetMinDhKey_Sz
  5356. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5357. \sa wolfSSL_SetMaxDhKey_Sz
  5358. \sa wolfSSL_GetDhKey_Sz
  5359. \sa wolfSSL_CTX_SetTMpDH_file
  5360. */
  5361. WOLFSSL_API int wolfSSL_CTX_SetMaxDhKey_Sz(WOLFSSL_CTX*, word16);
  5362. /*!
  5363. \ingroup CertsKeys
  5364. \brief Sets the maximum size for a Diffie-Hellman key in the WOLFSSL
  5365. structure in bytes.
  5366. \return SSL_SUCCESS the maximum size was successfully set.
  5367. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or the keySz parameter
  5368. was greater than the allowable size or not divisible by 8.
  5369. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5370. \param keySz a word16 type representing the bit size of the maximum DH key.
  5371. _Example_
  5372. \code
  5373. WOLFSSL* ssl = wolfSSL_new(ctx);
  5374. word16 keySz;
  5375. ...
  5376. if(wolfSSL_SetMaxDhKey(ssl, keySz) != SSL_SUCCESS){
  5377. // Failed to set.
  5378. }
  5379. \endcode
  5380. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5381. \sa wolfSSL_GetDhKey_Sz
  5382. */
  5383. WOLFSSL_API int wolfSSL_SetMaxDhKey_Sz(WOLFSSL*, word16);
  5384. /*!
  5385. \ingroup CertsKeys
  5386. \brief Returns the value of dhKeySz that is a member of the options
  5387. structure. This value represents the Diffie-Hellman key size in bytes.
  5388. \return dhKeySz returns the value held in ssl->options.dhKeySz which is an
  5389. integer value.
  5390. \return BAD_FUNC_ARG returns if the WOLFSSL struct is NULL.
  5391. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5392. _Example_
  5393. \code
  5394. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5395. WOLFSSL* ssl = wolfSSL_new(ctx);
  5396. int dhKeySz;
  5397. ...
  5398. dhKeySz = wolfSSL_GetDhKey_Sz(ssl);
  5399. if(dhKeySz == BAD_FUNC_ARG || dhKeySz <= 0){
  5400. // Failure case
  5401. } else {
  5402. // dhKeySz holds the size of the key.
  5403. }
  5404. \endcode
  5405. \sa wolfSSL_SetMinDhKey_sz
  5406. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5407. \sa wolfSSL_CTX_SetTmpDH
  5408. \sa wolfSSL_SetTmpDH
  5409. \sa wolfSSL_CTX_SetTmpDH_file
  5410. */
  5411. WOLFSSL_API int wolfSSL_GetDhKey_Sz(WOLFSSL*);
  5412. /*!
  5413. \ingroup CertsKeys
  5414. \brief Sets the minimum RSA key size in both the WOLFSSL_CTX structure
  5415. and the WOLFSSL_CERT_MANAGER structure.
  5416. \return SSL_SUCCESS returned on successful execution of the function.
  5417. \return BAD_FUNC_ARG returned if the ctx structure is NULL or the keySz
  5418. is less than zero or not divisible by 8.
  5419. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5420. wolfSSL_CTX_new().
  5421. \param keySz a short integer type stored in minRsaKeySz in the ctx
  5422. structure and the cm structure converted to bytes.
  5423. _Example_
  5424. \code
  5425. WOLFSSL_CTX* ctx = SSL_CTX_new(method);
  5426. (void)minDhKeyBits;
  5427. ourCert = myoptarg;
  5428. minDhKeyBits = atoi(myoptarg);
  5429. if(wolfSSL_CTX_SetMinRsaKey_Sz(ctx, minRsaKeyBits) != SSL_SUCCESS){
  5430. \endcode
  5431. \sa wolfSSL_SetMinRsaKey_Sz
  5432. */
  5433. WOLFSSL_API int wolfSSL_CTX_SetMinRsaKey_Sz(WOLFSSL_CTX*, short);
  5434. /*!
  5435. \ingroup CertsKeys
  5436. \brief Sets the minimum allowable key size in bytes for RSA located in the
  5437. WOLFSSL structure.
  5438. \return SSL_SUCCESS the minimum was set successfully.
  5439. \return BAD_FUNC_ARG returned if the ssl structure is NULL or if the ksySz
  5440. is less than zero or not divisible by 8.
  5441. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5442. \param keySz a short integer value representing the the minimum key in bits.
  5443. _Example_
  5444. \code
  5445. WOLFSSL* ssl = wolfSSL_new(ctx);
  5446. short keySz;
  5447. int isSet = wolfSSL_SetMinRsaKey_Sz(ssl, keySz);
  5448. if(isSet != SSL_SUCCESS){
  5449. Failed to set.
  5450. }
  5451. \endcode
  5452. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5453. */
  5454. WOLFSSL_API int wolfSSL_SetMinRsaKey_Sz(WOLFSSL*, short);
  5455. /*!
  5456. \ingroup CertsKeys
  5457. \brief Sets the minimum size in bytes for the ECC key in the WOLF_CTX
  5458. structure and the WOLFSSL_CERT_MANAGER structure.
  5459. \return SSL_SUCCESS returned for a successful execution and the minEccKeySz
  5460. member is set.
  5461. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5462. the keySz is negative or not divisible by 8.
  5463. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5464. wolfSSL_CTX_new().
  5465. \param keySz a short integer type that represents the minimum ECC key
  5466. size in bits.
  5467. _Example_
  5468. \code
  5469. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5470. short keySz; // minimum key size
  5471. if(wolfSSL_CTX_SetMinEccKey(ctx, keySz) != SSL_SUCCESS){
  5472. // Failed to set min key size
  5473. }
  5474. \endcode
  5475. \sa wolfSSL_SetMinEccKey_Sz
  5476. */
  5477. WOLFSSL_API int wolfSSL_CTX_SetMinEccKey_Sz(WOLFSSL_CTX*, short);
  5478. /*!
  5479. \ingroup CertsKeys
  5480. \brief Sets the value of the minEccKeySz member of the options structure.
  5481. The options struct is a member of the WOLFSSL structure and is
  5482. accessed through the ssl parameter.
  5483. \return SSL_SUCCESS if the function successfully set the minEccKeySz
  5484. member of the options structure.
  5485. \return BAD_FUNC_ARG if the WOLFSSL_CTX structure is NULL or if the
  5486. key size (keySz) is less than 0 (zero) or not divisible by 8.
  5487. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5488. \param keySz value used to set the minimum ECC key size. Sets
  5489. value in the options structure.
  5490. _Example_
  5491. \code
  5492. WOLFSSL* ssl = wolfSSL_new(ctx); // New session
  5493. short keySz = 999; // should be set to min key size allowable
  5494. ...
  5495. if(wolfSSL_SetMinEccKey_Sz(ssl, keySz) != SSL_SUCCESS){
  5496. // Failure case.
  5497. }
  5498. \endcode
  5499. \sa wolfSSL_CTX_SetMinEccKey_Sz
  5500. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5501. \sa wolfSSL_SetMinRsaKey_Sz
  5502. */
  5503. WOLFSSL_API int wolfSSL_SetMinEccKey_Sz(WOLFSSL*, short);
  5504. /*!
  5505. \ingroup CertsKeys
  5506. \brief This function is used by EAP_TLS and EAP-TTLS to derive
  5507. keying material from the master secret.
  5508. \return BUFFER_E returned if the actual size of the buffer exceeds
  5509. the maximum size allowable.
  5510. \return MEMORY_E returned if there is an error with memory allocation.
  5511. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5512. \param msk a void pointer variable that will hold the result
  5513. of the p_hash function.
  5514. \param len an unsigned integer that represents the length of
  5515. the msk variable.
  5516. \param label a constant char pointer that is copied from in wc_PRF().
  5517. _Example_
  5518. \code
  5519. WOLFSSL* ssl = wolfSSL_new(ctx);;
  5520. void* msk;
  5521. unsigned int len;
  5522. const char* label;
  5523. return wolfSSL_make_eap_keys(ssl, msk, len, label);
  5524. \endcode
  5525. \sa wc_PRF
  5526. \sa wc_HmacFinal
  5527. \sa wc_HmacUpdate
  5528. */
  5529. WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL*, void* key, unsigned int len,
  5530. const char* label);
  5531. /*!
  5532. \ingroup IO
  5533. \brief Simulates writev semantics but doesn’t actually do block at a time
  5534. because of SSL_write() behavior and because front adds may be small.
  5535. Makes porting into software that uses writev easier.
  5536. \return >0 the number of bytes written upon success.
  5537. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  5538. the specific error code.
  5539. \return MEMORY_ERROR will be returned if a memory error was encountered.
  5540. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  5541. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  5542. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  5543. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  5544. error code.
  5545. \param ssl pointer to the SSL session, created with wolfSSL_new().
  5546. \param iov array of I/O vectors to write
  5547. \param iovcnt number of vectors in iov array.
  5548. _Example_
  5549. \code
  5550. WOLFSSL* ssl = 0;
  5551. char *bufA = “hello\n”;
  5552. char *bufB = “hello world\n”;
  5553. int iovcnt;
  5554. struct iovec iov[2];
  5555. iov[0].iov_base = buffA;
  5556. iov[0].iov_len = strlen(buffA);
  5557. iov[1].iov_base = buffB;
  5558. iov[1].iov_len = strlen(buffB);
  5559. iovcnt = 2;
  5560. ...
  5561. ret = wolfSSL_writev(ssl, iov, iovcnt);
  5562. // wrote “ret” bytes, or error if <= 0.
  5563. \endcode
  5564. \sa wolfSSL_write
  5565. */
  5566. WOLFSSL_API int wolfSSL_writev(WOLFSSL* ssl, const struct iovec* iov,
  5567. int iovcnt);
  5568. /*!
  5569. \ingroup Setup
  5570. \brief This function unloads the CA signer list and frees
  5571. the whole signer table.
  5572. \return SSL_SUCCESS returned on successful execution of the function.
  5573. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or there
  5574. are otherwise unpermitted argument values passed in a subroutine.
  5575. \return BAD_MUTEX_E returned if there was a mutex error. The LockMutex()
  5576. did not return 0.
  5577. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5578. wolfSSL_CTX_new().
  5579. _Example_
  5580. \code
  5581. WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
  5582. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  5583. if(!wolfSSL_CTX_UnloadCAs(ctx)){
  5584. // The function did not unload CAs
  5585. }
  5586. \endcode
  5587. \sa wolfSSL_CertManagerUnloadCAs
  5588. \sa LockMutex
  5589. \sa FreeSignerTable
  5590. \sa UnlockMutex
  5591. */
  5592. WOLFSSL_API int wolfSSL_CTX_UnloadCAs(WOLFSSL_CTX*);
  5593. /*!
  5594. \ingroup Setup
  5595. \brief This function is used to unload all previously loaded trusted peer
  5596. certificates. Feature is enabled by defining the macro
  5597. WOLFSSL_TRUST_PEER_CERT.
  5598. \return SSL_SUCCESS upon success.
  5599. \return BAD_FUNC_ARG will be returned if ctx is NULL.
  5600. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5601. can’t be read, or is corrupted.
  5602. \return MEMORY_E will be returned if an out of memory condition occurs.
  5603. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5604. _Example_
  5605. \code
  5606. int ret = 0;
  5607. WOLFSSL_CTX* ctx;
  5608. ...
  5609. ret = wolfSSL_CTX_Unload_trust_peers(ctx);
  5610. if (ret != SSL_SUCCESS) {
  5611. // error unloading trusted peer certs
  5612. }
  5613. ...
  5614. \endcode
  5615. \sa wolfSSL_CTX_trust_peer_buffer
  5616. \sa wolfSSL_CTX_trust_peer_cert
  5617. */
  5618. WOLFSSL_API int wolfSSL_CTX_Unload_trust_peers(WOLFSSL_CTX*);
  5619. /*!
  5620. \ingroup Setup
  5621. \brief This function loads a certificate to use for verifying a peer
  5622. when performing a TLS/SSL handshake. The peer certificate sent during
  5623. the handshake is compared by using the SKID when available and the
  5624. signature. If these two things do not match then any loaded CAs are used.
  5625. Is the same functionality as wolfSSL_CTX_trust_peer_cert except is from
  5626. a buffer instead of a file. Feature is enabled by defining the macro
  5627. WOLFSSL_TRUST_PEER_CERT Please see the examples for proper usage.
  5628. \return SSL_SUCCESS upon success
  5629. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  5630. type are invalid.
  5631. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5632. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  5633. read, or is corrupted.
  5634. \return MEMORY_E will be returned if an out of memory condition occurs.
  5635. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5636. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5637. \param buffer pointer to the buffer containing certificates.
  5638. \param sz length of the buffer input.
  5639. \param type type of certificate being loaded i.e. SSL_FILETYPE_ASN1 or
  5640. SSL_FILETYPE_PEM.
  5641. _Example_
  5642. \code
  5643. int ret = 0;
  5644. WOLFSSL_CTX* ctx;
  5645. ...
  5646. ret = wolfSSL_CTX_trust_peer_buffer(ctx, bufferPtr, bufferSz,
  5647. SSL_FILETYPE_PEM);
  5648. if (ret != SSL_SUCCESS) {
  5649. // error loading trusted peer cert
  5650. }
  5651. ...
  5652. \endcode
  5653. \sa wolfSSL_CTX_load_verify_buffer
  5654. \sa wolfSSL_CTX_use_certificate_file
  5655. \sa wolfSSL_CTX_use_PrivateKey_file
  5656. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5657. \sa wolfSSL_CTX_use_certificate_chain_file
  5658. \sa wolfSSL_CTX_trust_peer_cert
  5659. \sa wolfSSL_CTX_Unload_trust_peers
  5660. \sa wolfSSL_use_certificate_file
  5661. \sa wolfSSL_use_PrivateKey_file
  5662. \sa wolfSSL_use_certificate_chain_file
  5663. */
  5664. WOLFSSL_API int wolfSSL_CTX_trust_peer_buffer(WOLFSSL_CTX*,
  5665. const unsigned char*, long, int);
  5666. /*!
  5667. \ingroup CertsKeys
  5668. \brief This function loads a CA certificate buffer into the WOLFSSL
  5669. Context. It behaves like the non-buffered version, only differing in
  5670. its ability to be called with a buffer as input instead of a file.
  5671. The buffer is provided by the in argument of size sz. format specifies
  5672. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5673. More than one CA certificate may be loaded per buffer as long as the
  5674. format is in PEM. Please see the examples for proper usage.
  5675. \return SSL_SUCCESS upon success
  5676. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5677. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5678. can’t be read, or is corrupted.
  5679. \return MEMORY_E will be returned if an out of memory condition occurs.
  5680. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5681. \return BUFFER_E will be returned if a chain buffer is bigger than
  5682. the receiving buffer.
  5683. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5684. \param in pointer to the CA certificate buffer.
  5685. \param sz size of the input CA certificate buffer, in.
  5686. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  5687. or SSL_FILETYPE_PEM.
  5688. _Example_
  5689. \code
  5690. int ret = 0;
  5691. int sz = 0;
  5692. WOLFSSL_CTX* ctx;
  5693. byte certBuff[...];
  5694. ...
  5695. ret = wolfSSL_CTX_load_verify_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  5696. if (ret != SSL_SUCCESS) {
  5697. // error loading CA certs from buffer
  5698. }
  5699. ...
  5700. \endcode
  5701. \sa wolfSSL_CTX_load_verify_locations
  5702. \sa wolfSSL_CTX_use_certificate_buffer
  5703. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5704. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5705. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5706. \sa wolfSSL_use_certificate_buffer
  5707. \sa wolfSSL_use_PrivateKey_buffer
  5708. \sa wolfSSL_use_certificate_chain_buffer
  5709. */
  5710. WOLFSSL_API int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX*,
  5711. const unsigned char*, long, int);
  5712. /*!
  5713. \ingroup CertsKeys
  5714. \brief This function loads a CA certificate chain buffer into the WOLFSSL
  5715. Context. It behaves like the non-buffered version, only differing in
  5716. its ability to be called with a buffer as input instead of a file.
  5717. The buffer is provided by the in argument of size sz. format specifies
  5718. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5719. More than one CA certificate may be loaded per buffer as long as the
  5720. format is in PEM. Please see the examples for proper usage.
  5721. \return SSL_SUCCESS upon success
  5722. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5723. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5724. can’t be read, or is corrupted.
  5725. \return MEMORY_E will be returned if an out of memory condition occurs.
  5726. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5727. \return BUFFER_E will be returned if a chain buffer is bigger than
  5728. the receiving buffer.
  5729. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5730. \param in pointer to the CA certificate buffer.
  5731. \param sz size of the input CA certificate buffer, in.
  5732. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  5733. or SSL_FILETYPE_PEM.
  5734. _Example_
  5735. \code
  5736. int ret = 0;
  5737. int sz = 0;
  5738. WOLFSSL_CTX* ctx;
  5739. byte certBuff[...];
  5740. ...
  5741. ret = wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  5742. certBuff, sz, WOLFSSL_FILETYPE_ASN1);
  5743. if (ret != SSL_SUCCESS) {
  5744. // error loading CA certs from buffer
  5745. }
  5746. ...
  5747. \endcode
  5748. \sa wolfSSL_CTX_load_verify_locations
  5749. \sa wolfSSL_CTX_use_certificate_buffer
  5750. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5751. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5752. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5753. \sa wolfSSL_use_certificate_buffer
  5754. \sa wolfSSL_use_PrivateKey_buffer
  5755. \sa wolfSSL_use_certificate_chain_buffer
  5756. */
  5757. WOLFSSL_API int wolfSSL_CTX_load_verify_chain_buffer_format(WOLFSSL_CTX*,
  5758. const unsigned char*, long, int);
  5759. /*!
  5760. \ingroup CertsKeys
  5761. \brief This function loads a certificate buffer into the WOLFSSL Context.
  5762. It behaves like the non-buffered version, only differing in its ability
  5763. to be called with a buffer as input instead of a file. The buffer is
  5764. provided by the in argument of size sz. format specifies the format
  5765. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  5766. see the examples for proper usage.
  5767. \return SSL_SUCCESS upon success
  5768. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5769. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5770. can’t be read, or is corrupted.
  5771. \return MEMORY_E will be returned if an out of memory condition occurs.
  5772. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5773. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5774. \param in the input buffer containing the certificate to be loaded.
  5775. \param sz the size of the input buffer.
  5776. \param format the format of the certificate located in the input
  5777. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5778. _Example_
  5779. \code
  5780. int ret = 0;
  5781. int sz = 0;
  5782. WOLFSSL_CTX* ctx;
  5783. byte certBuff[...];
  5784. ...
  5785. ret = wolfSSL_CTX_use_certificate_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  5786. if (ret != SSL_SUCCESS) {
  5787. // error loading certificate from buffer
  5788. }
  5789. ...
  5790. \endcode
  5791. \sa wolfSSL_CTX_load_verify_buffer
  5792. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5793. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5794. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5795. \sa wolfSSL_use_certificate_buffer
  5796. \sa wolfSSL_use_PrivateKey_buffer
  5797. \sa wolfSSL_use_certificate_chain_buffer
  5798. */
  5799. WOLFSSL_API int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX*,
  5800. const unsigned char*, long, int);
  5801. /*!
  5802. \ingroup CertsKeys
  5803. \brief This function loads a private key buffer into the SSL Context.
  5804. It behaves like the non-buffered version, only differing in its ability
  5805. to be called with a buffer as input instead of a file. The buffer is
  5806. provided by the in argument of size sz. format specifies the format type
  5807. of the buffer; SSL_FILETYPE_ASN1or SSL_FILETYPE_PEM. Please see the
  5808. examples for proper usage.
  5809. \return SSL_SUCCESS upon success
  5810. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5811. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  5812. read, or is corrupted.
  5813. \return MEMORY_E will be returned if an out of memory condition occurs.
  5814. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5815. \return NO_PASSWORD will be returned if the key file is encrypted but no
  5816. password is provided.
  5817. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5818. \param in the input buffer containing the private key to be loaded.
  5819. \param sz the size of the input buffer.
  5820. \param format the format of the private key located in the input
  5821. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5822. _Example_
  5823. \code
  5824. int ret = 0;
  5825. int sz = 0;
  5826. WOLFSSL_CTX* ctx;
  5827. byte keyBuff[...];
  5828. ...
  5829. ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, keyBuff, sz, SSL_FILETYPE_PEM);
  5830. if (ret != SSL_SUCCESS) {
  5831. // error loading private key from buffer
  5832. }
  5833. ...
  5834. \endcode
  5835. \sa wolfSSL_CTX_load_verify_buffer
  5836. \sa wolfSSL_CTX_use_certificate_buffer
  5837. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5838. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5839. \sa wolfSSL_use_certificate_buffer
  5840. \sa wolfSSL_use_PrivateKey_buffer
  5841. \sa wolfSSL_use_certificate_chain_buffer
  5842. */
  5843. WOLFSSL_API int wolfSSL_CTX_use_PrivateKey_buffer(WOLFSSL_CTX*,
  5844. const unsigned char*, long, int);
  5845. /*!
  5846. \ingroup CertsKeys
  5847. \brief This function loads a certificate chain buffer into the WOLFSSL
  5848. Context. It behaves like the non-buffered version, only differing in
  5849. its ability to be called with a buffer as input instead of a file.
  5850. The buffer is provided by the in argument of size sz. The buffer must
  5851. be in PEM format and start with the subject’s certificate, ending with
  5852. the root certificate. Please see the examples for proper usage.
  5853. \return SSL_SUCCESS upon success
  5854. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5855. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5856. can’t be read, or is corrupted.
  5857. \return MEMORY_E will be returned if an out of memory condition occurs.
  5858. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5859. \return BUFFER_E will be returned if a chain buffer is bigger than
  5860. the receiving buffer.
  5861. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5862. \param in the input buffer containing the PEM-formatted certificate
  5863. chain to be loaded.
  5864. \param sz the size of the input buffer.
  5865. _Example_
  5866. \code
  5867. int ret = 0;
  5868. int sz = 0;
  5869. WOLFSSL_CTX* ctx;
  5870. byte certChainBuff[...];
  5871. ...
  5872. ret = wolfSSL_CTX_use_certificate_chain_buffer(ctx, certChainBuff, sz);
  5873. if (ret != SSL_SUCCESS) {
  5874. // error loading certificate chain from buffer
  5875. }
  5876. ...
  5877. \endcode
  5878. \sa wolfSSL_CTX_load_verify_buffer
  5879. \sa wolfSSL_CTX_use_certificate_buffer
  5880. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5881. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5882. \sa wolfSSL_use_certificate_buffer
  5883. \sa wolfSSL_use_PrivateKey_buffer
  5884. \sa wolfSSL_use_certificate_chain_buffer
  5885. */
  5886. WOLFSSL_API int wolfSSL_CTX_use_certificate_chain_buffer(WOLFSSL_CTX*,
  5887. const unsigned char*, long);
  5888. /*!
  5889. \ingroup CertsKeys
  5890. \brief This function loads a certificate buffer into the WOLFSSL object.
  5891. It behaves like the non-buffered version, only differing in its ability
  5892. to be called with a buffer as input instead of a file. The buffer
  5893. is provided by the in argument of size sz. format specifies the format
  5894. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5895. Please see the examples for proper usage.
  5896. \return SSL_SUCCESS upon success.
  5897. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5898. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  5899. be read, or is corrupted.
  5900. \return MEMORY_E will be returned if an out of memory condition occurs.
  5901. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5902. \param ssl pointer to the SSL session, created with wolfSSL_new().
  5903. \param in buffer containing certificate to load.
  5904. \param sz size of the certificate located in buffer.
  5905. \param format format of the certificate to be loaded.
  5906. Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5907. _Example_
  5908. \code
  5909. int buffSz;
  5910. int ret;
  5911. byte certBuff[...];
  5912. WOLFSSL* ssl = 0;
  5913. ...
  5914. ret = wolfSSL_use_certificate_buffer(ssl, certBuff, buffSz, SSL_FILETYPE_PEM);
  5915. if (ret != SSL_SUCCESS) {
  5916. // failed to load certificate from buffer
  5917. }
  5918. \endcode
  5919. \sa wolfSSL_CTX_load_verify_buffer
  5920. \sa wolfSSL_CTX_use_certificate_buffer
  5921. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5922. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5923. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5924. \sa wolfSSL_use_PrivateKey_buffer
  5925. \sa wolfSSL_use_certificate_chain_buffer
  5926. */
  5927. WOLFSSL_API int wolfSSL_use_certificate_buffer(WOLFSSL*, const unsigned char*,
  5928. long, int);
  5929. /*!
  5930. \ingroup CertsKeys
  5931. \brief This function loads a private key buffer into the WOLFSSL object.
  5932. It behaves like the non-buffered version, only differing in its ability
  5933. to be called with a buffer as input instead of a file. The buffer is
  5934. provided by the in argument of size sz. format specifies the format
  5935. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  5936. see the examples for proper usage.
  5937. \return SSL_SUCCESS upon success.
  5938. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5939. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  5940. read, or is corrupted.
  5941. \return MEMORY_E will be returned if an out of memory condition occurs.
  5942. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5943. \return NO_PASSWORD will be returned if the key file is encrypted but no
  5944. password is provided.
  5945. \param ssl pointer to the SSL session, created with wolfSSL_new().
  5946. \param in buffer containing private key to load.
  5947. \param sz size of the private key located in buffer.
  5948. \param format format of the private key to be loaded. Possible values are
  5949. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5950. _Example_
  5951. \code
  5952. int buffSz;
  5953. int ret;
  5954. byte keyBuff[...];
  5955. WOLFSSL* ssl = 0;
  5956. ...
  5957. ret = wolfSSL_use_PrivateKey_buffer(ssl, keyBuff, buffSz, SSL_FILETYPE_PEM);
  5958. if (ret != SSL_SUCCESS) {
  5959. // failed to load private key from buffer
  5960. }
  5961. \endcode
  5962. \sa wolfSSL_use_PrivateKey
  5963. \sa wolfSSL_CTX_load_verify_buffer
  5964. \sa wolfSSL_CTX_use_certificate_buffer
  5965. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5966. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  5967. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5968. \sa wolfSSL_use_certificate_buffer
  5969. \sa wolfSSL_use_certificate_chain_buffer
  5970. */
  5971. WOLFSSL_API int wolfSSL_use_PrivateKey_buffer(WOLFSSL*, const unsigned char*,
  5972. long, int);
  5973. /*!
  5974. \ingroup CertsKeys
  5975. \brief This function loads a certificate chain buffer into the WOLFSSL
  5976. object. It behaves like the non-buffered version, only differing in its
  5977. ability to be called with a buffer as input instead of a file. The buffer
  5978. is provided by the in argument of size sz. The buffer must be in PEM format
  5979. and start with the subject’s certificate, ending with the root certificate.
  5980. Please see the examples for proper usage.
  5981. \return SSL_SUCCES upon success.
  5982. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5983. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5984. can’t be read, or is corrupted.
  5985. \return MEMORY_E will be returned if an out of memory condition occurs.
  5986. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5987. \return BUFFER_E will be returned if a chain buffer is bigger than
  5988. the receiving buffer.
  5989. \param ssl pointer to the SSL session, created with wolfSSL_new().
  5990. \param in buffer containing certificate to load.
  5991. \param sz size of the certificate located in buffer.
  5992. _Example_
  5993. \code
  5994. int buffSz;
  5995. int ret;
  5996. byte certChainBuff[...];
  5997. WOLFSSL* ssl = 0;
  5998. ...
  5999. ret = wolfSSL_use_certificate_chain_buffer(ssl, certChainBuff, buffSz);
  6000. if (ret != SSL_SUCCESS) {
  6001. // failed to load certificate chain from buffer
  6002. }
  6003. \endcode
  6004. \sa wolfSSL_CTX_load_verify_buffer
  6005. \sa wolfSSL_CTX_use_certificate_buffer
  6006. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6007. \sa wolfSSL_CTX_use_NTRUPrivateKey_file
  6008. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6009. \sa wolfSSL_use_certificate_buffer
  6010. \sa wolfSSL_use_PrivateKey_buffer
  6011. */
  6012. WOLFSSL_API int wolfSSL_use_certificate_chain_buffer(WOLFSSL*,
  6013. const unsigned char*, long);
  6014. /*!
  6015. \ingroup CertsKeys
  6016. \brief This function unloads any certificates or keys that SSL owns.
  6017. \return SSL_SUCCESS - returned if the function executed successfully.
  6018. \return BAD_FUNC_ARG - returned if the WOLFSSL object is NULL.
  6019. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6020. _Example_
  6021. \code
  6022. WOLFSSL* ssl = wolfSSL_new(ctx);
  6023. ...
  6024. int unloadKeys = wolfSSL_UnloadCertsKeys(ssl);
  6025. if(unloadKeys != SSL_SUCCESS){
  6026. // Failure case.
  6027. }
  6028. \endcode
  6029. \sa wolfSSL_CTX_UnloadCAs
  6030. */
  6031. WOLFSSL_API int wolfSSL_UnloadCertsKeys(WOLFSSL*);
  6032. /*!
  6033. \ingroup Setup
  6034. \brief This function turns on grouping of handshake messages where possible.
  6035. \return SSL_SUCCESS will be returned upon success.
  6036. \return BAD_FUNC_ARG will be returned if the input context is null.
  6037. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6038. _Example_
  6039. \code
  6040. WOLFSSL_CTX* ctx = 0;
  6041. ...
  6042. ret = wolfSSL_CTX_set_group_messages(ctx);
  6043. if (ret != SSL_SUCCESS) {
  6044. // failed to set handshake message grouping
  6045. }
  6046. \endcode
  6047. \sa wolfSSL_set_group_messages
  6048. \sa wolfSSL_CTX_new
  6049. */
  6050. WOLFSSL_API int wolfSSL_CTX_set_group_messages(WOLFSSL_CTX*);
  6051. /*!
  6052. \ingroup Setup
  6053. \brief This function turns on grouping of handshake messages where possible.
  6054. \return SSL_SUCCESS will be returned upon success.
  6055. \return BAD_FUNC_ARG will be returned if the input context is null.
  6056. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6057. _Example_
  6058. \code
  6059. WOLFSSL* ssl = 0;
  6060. ...
  6061. ret = wolfSSL_set_group_messages(ssl);
  6062. if (ret != SSL_SUCCESS) {
  6063. // failed to set handshake message grouping
  6064. }
  6065. \endcode
  6066. \sa wolfSSL_CTX_set_group_messages
  6067. \sa wolfSSL_new
  6068. */
  6069. WOLFSSL_API int wolfSSL_set_group_messages(WOLFSSL*);
  6070. /*!
  6071. \brief This function sets the fuzzer callback.
  6072. \return none No returns.
  6073. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6074. \param cbf a CallbackFuzzer type that is a function pointer of the form:
  6075. int (*CallbackFuzzer)(WOLFSSL* ssl, const unsigned char* buf, int sz, int
  6076. type, void* fuzzCtx);
  6077. \param fCtx a void pointer type that will be set to the fuzzerCtx member of
  6078. the WOLFSSL structure.
  6079. _Example_
  6080. \code
  6081. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6082. WOLFSSL* ssl = wolfSSL_new(ctx);
  6083. void* fCtx;
  6084. int callbackFuzzerCB(WOLFSSL* ssl, const unsigned char* buf, int sz,
  6085. int type, void* fuzzCtx){
  6086. // function definition
  6087. }
  6088. wolfSSL_SetFuzzerCb(ssl, callbackFuzzerCB, fCtx);
  6089. \endcode
  6090. \sa CallbackFuzzer
  6091. */
  6092. WOLFSSL_API void wolfSSL_SetFuzzerCb(WOLFSSL* ssl, CallbackFuzzer cbf, void* fCtx);
  6093. /*!
  6094. \brief This function sets a new dtls cookie secret.
  6095. \return 0 returned if the function executed without an error.
  6096. \return BAD_FUNC_ARG returned if there was an argument passed
  6097. to the function with an unacceptable value.
  6098. \return COOKIE_SECRET_SZ returned if the secret size is 0.
  6099. \return MEMORY_ERROR returned if there was a problem allocating
  6100. memory for a new cookie secret.
  6101. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6102. \param secret a constant byte pointer representing the secret buffer.
  6103. \param secretSz the size of the buffer.
  6104. _Example_
  6105. \code
  6106. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6107. WOLFSSL* ssl = wolfSSL_new(ctx);
  6108. const* byte secret;
  6109. word32 secretSz; // size of secret
  6110. if(!wolfSSL_DTLS_SetCookieSecret(ssl, secret, secretSz)){
  6111. // Code block for failure to set DTLS cookie secret
  6112. } else {
  6113. // Success! Cookie secret is set.
  6114. }
  6115. \endcode
  6116. \sa ForceZero
  6117. \sa wc_RNG_GenerateBlock
  6118. \sa XMEMCPY
  6119. */
  6120. WOLFSSL_API int wolfSSL_DTLS_SetCookieSecret(WOLFSSL*,
  6121. const unsigned char*,
  6122. unsigned int);
  6123. /*!
  6124. \ingroup Setup
  6125. \brief This function sets the minimum downgrade version allowed.
  6126. Applicable only when the connection allows downgrade using
  6127. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6128. \return SSL_SUCCESS returned if the function returned without
  6129. error and the minimum version is set.
  6130. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure was
  6131. NULL or if the minimum version is not supported.
  6132. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6133. wolfSSL_CTX_new().
  6134. \param version an integer representation of the version to be set as the
  6135. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6136. WOLFSSL_TLSV1_2 = 3.
  6137. _Example_
  6138. \code
  6139. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  6140. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6141. int version; // macrop representation
  6142. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6143. // Failed to set min version
  6144. }
  6145. \endcode
  6146. \sa SetMinVersionHelper
  6147. */
  6148. WOLFSSL_API int wolfSSL_CTX_SetMinVersion(WOLFSSL_CTX* ctx, int version);
  6149. /*!
  6150. \ingroup TLS
  6151. \brief This function sets the minimum downgrade version allowed.
  6152. Applicable only when the connection allows downgrade using
  6153. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6154. \return SSL_SUCCESS returned if this function and its subroutine executes
  6155. without error.
  6156. \return BAD_FUNC_ARG returned if the SSL object is NULL. In
  6157. the subroutine this error is thrown if there is not a good version match.
  6158. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6159. \param version an integer representation of the version to be set as the
  6160. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6161. WOLFSSL_TLSV1_2 = 3.
  6162. _Example_
  6163. \code
  6164. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol method);
  6165. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6166. int version; macro representation
  6167. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6168. Failed to set min version
  6169. }
  6170. \endcode
  6171. \sa SetMinVersionHelper
  6172. */
  6173. WOLFSSL_API int wolfSSL_SetMinVersion(WOLFSSL* ssl, int version);
  6174. /*!
  6175. \brief This function returns the size of the WOLFSSL object and will be
  6176. dependent on build options and settings. If SHOW_SIZES has been defined
  6177. when building wolfSSL, this function will also print the sizes of individual
  6178. objects within the WOLFSSL object (Suites, Ciphers, etc.) to stdout.
  6179. \return size This function returns the size of the WOLFSSL object.
  6180. \param none No parameters.
  6181. _Example_
  6182. \code
  6183. int size = 0;
  6184. size = wolfSSL_GetObjectSize();
  6185. printf(“sizeof(WOLFSSL) = %d\n”, size);
  6186. \endcode
  6187. \sa wolfSSL_new
  6188. */
  6189. WOLFSSL_API int wolfSSL_GetObjectSize(void); /* object size based on build */
  6190. /*!
  6191. \brief Returns the record layer size of the plaintext input. This is helpful
  6192. when an application wants to know how many bytes will be sent across the
  6193. Transport layer, given a specified plaintext input size. This function
  6194. must be called after the SSL/TLS handshake has been completed.
  6195. \return size Upon success, the requested size will be returned
  6196. \return INPUT_SIZE_E will be returned if the input size is greater than the
  6197. maximum TLS fragment size (see wolfSSL_GetMaxOutputSize())
  6198. \return BAD_FUNC_ARG will be returned upon invalid function argument, or if
  6199. the SSL/TLS handshake has not been completed yet
  6200. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6201. \param inSz size of plaintext data.
  6202. _Example_
  6203. \code
  6204. none
  6205. \endcode
  6206. \sa wolfSSL_GetMaxOutputSize
  6207. */
  6208. WOLFSSL_API int wolfSSL_GetOutputSize(WOLFSSL*, int);
  6209. /*!
  6210. \brief Returns the maximum record layer size for plaintext data. This
  6211. will correspond to either the maximum SSL/TLS record size as specified
  6212. by the protocol standard, the maximum TLS fragment size as set by the
  6213. TLS Max Fragment Length extension. This function is helpful when the
  6214. application has called wolfSSL_GetOutputSize() and received a INPUT_SIZE_E
  6215. error. This function must be called after the SSL/TLS handshake has been
  6216. completed.
  6217. \return size Upon success, the maximum output size will be returned
  6218. \return BAD_FUNC_ARG will be returned upon invalid function argument,
  6219. or if the SSL/TLS handshake has not been completed yet.
  6220. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6221. _Example_
  6222. \code
  6223. none
  6224. \endcode
  6225. \sa wolfSSL_GetOutputSize
  6226. */
  6227. WOLFSSL_API int wolfSSL_GetMaxOutputSize(WOLFSSL*);
  6228. /*!
  6229. \ingroup Setup
  6230. \brief This function sets the SSL/TLS protocol version for the specified
  6231. SSL session (WOLFSSL object) using the version as specified by version.
  6232. This will override the protocol setting for the SSL session (ssl) -
  6233. originally defined and set by the SSL context (wolfSSL_CTX_new())
  6234. method type.
  6235. \return SSL_SUCCESS upon success.
  6236. \return BAD_FUNC_ARG will be returned if the input SSL object is
  6237. NULL or an incorrect protocol version is given for version.
  6238. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6239. \param version SSL/TLS protocol version. Possible values include
  6240. WOLFSSL_SSLV3, WOLFSSL_TLSV1, WOLFSSL_TLSV1_1, WOLFSSL_TLSV1_2.
  6241. _Example_
  6242. \code
  6243. int ret = 0;
  6244. WOLFSSL* ssl;
  6245. ...
  6246. ret = wolfSSL_SetVersion(ssl, WOLFSSL_TLSV1);
  6247. if (ret != SSL_SUCCESS) {
  6248. // failed to set SSL session protocol version
  6249. }
  6250. \endcode
  6251. \sa wolfSSL_CTX_new
  6252. */
  6253. WOLFSSL_API int wolfSSL_SetVersion(WOLFSSL* ssl, int version);
  6254. /*!
  6255. \brief Allows caller to set the Atomic User Record Processing
  6256. Mac/Encrypt Callback. The callback should return 0 for success
  6257. or < 0 for an error. The ssl and ctx pointers are available
  6258. for the user’s convenience. macOut is the output buffer where
  6259. the result of the mac should be stored. macIn is the mac input
  6260. buffer and macInSz notes the size of the buffer. macContent
  6261. and macVerify are needed for wolfSSL_SetTlsHmacInner() and be
  6262. passed along as is. encOut is the output buffer where the result
  6263. on the encryption should be stored. encIn is the input buffer to
  6264. encrypt while encSz is the size of the input. An example callback
  6265. can be found wolfssl/test.h myMacEncryptCb().
  6266. \return none No return.
  6267. \param No parameters.
  6268. _Example_
  6269. \code
  6270. none
  6271. \endcode
  6272. \sa wolfSSL_SetMacEncryptCtx
  6273. \sa wolfSSL_GetMacEncryptCtx
  6274. */
  6275. WOLFSSL_API void wolfSSL_CTX_SetMacEncryptCb(WOLFSSL_CTX*, CallbackMacEncrypt);
  6276. /*!
  6277. \brief Allows caller to set the Atomic User Record Processing Mac/Encrypt
  6278. Callback Context to ctx.
  6279. \return none No return.
  6280. \param none No parameters.
  6281. _Example_
  6282. \code
  6283. none
  6284. \endcode
  6285. \sa wolfSSL_CTX_SetMacEncryptCb
  6286. \sa wolfSSL_GetMacEncryptCtx
  6287. */
  6288. WOLFSSL_API void wolfSSL_SetMacEncryptCtx(WOLFSSL* ssl, void *ctx);
  6289. /*!
  6290. \brief Allows caller to retrieve the Atomic User Record Processing
  6291. Mac/Encrypt Callback Context previously stored with
  6292. wolfSSL_SetMacEncryptCtx().
  6293. \return pointer If successful the call will return a valid pointer
  6294. to the context.
  6295. \return NULL will be returned for a blank context.
  6296. \param none No parameters.
  6297. _Example_
  6298. \code
  6299. none
  6300. \endcode
  6301. \sa wolfSSL_CTX_SetMacEncryptCb
  6302. \sa wolfSSL_SetMacEncryptCtx
  6303. */
  6304. WOLFSSL_API void* wolfSSL_GetMacEncryptCtx(WOLFSSL* ssl);
  6305. /*!
  6306. \brief Allows caller to set the Atomic User Record Processing
  6307. Decrypt/Verify Callback. The callback should return 0 for success
  6308. or < 0 for an error. The ssl and ctx pointers are available for
  6309. the user’s convenience. decOut is the output buffer where the result
  6310. of the decryption should be stored. decIn is the encrypted input
  6311. buffer and decInSz notes the size of the buffer. content and verify
  6312. are needed for wolfSSL_SetTlsHmacInner() and be passed along as is.
  6313. padSz is an output variable that should be set with the total value
  6314. of the padding. That is, the mac size plus any padding and pad bytes.
  6315. An example callback can be found wolfssl/test.h myDecryptVerifyCb().
  6316. \return none No returns.
  6317. \param none No parameters.
  6318. _Example_
  6319. \code
  6320. none
  6321. \endcode
  6322. \sa wolfSSL_SetMacEncryptCtx
  6323. \sa wolfSSL_GetMacEncryptCtx
  6324. */
  6325. WOLFSSL_API void wolfSSL_CTX_SetDecryptVerifyCb(WOLFSSL_CTX*,
  6326. CallbackDecryptVerify);
  6327. /*!
  6328. \brief Allows caller to set the Atomic User Record Processing
  6329. Decrypt/Verify Callback Context to ctx.
  6330. \return none No returns.
  6331. \param none No parameters.
  6332. _Example_
  6333. \code
  6334. none
  6335. \endcode
  6336. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6337. \sa wolfSSL_GetDecryptVerifyCtx
  6338. */
  6339. WOLFSSL_API void wolfSSL_SetDecryptVerifyCtx(WOLFSSL* ssl, void *ctx);
  6340. /*!
  6341. \brief Allows caller to retrieve the Atomic User Record Processing
  6342. Decrypt/Verify Callback Context previously stored with
  6343. wolfSSL_SetDecryptVerifyCtx().
  6344. \return pointer If successful the call will return a valid pointer to the
  6345. context.
  6346. \return NULL will be returned for a blank context.
  6347. \param none No parameters.
  6348. _Example_
  6349. \code
  6350. none
  6351. \endcode
  6352. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6353. \sa wolfSSL_SetDecryptVerifyCtx
  6354. */
  6355. WOLFSSL_API void* wolfSSL_GetDecryptVerifyCtx(WOLFSSL* ssl);
  6356. /*!
  6357. \brief Allows retrieval of the Hmac/Mac secret from the handshake process.
  6358. The verify parameter specifies whether this is for verification of a
  6359. peer message.
  6360. \return pointer If successful the call will return a valid pointer to the
  6361. secret. The size of the secret can be obtained from wolfSSL_GetHmacSize().
  6362. \return NULL will be returned for an error state.
  6363. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6364. \param verify specifies whether this is for verification of a peer message.
  6365. _Example_
  6366. \code
  6367. none
  6368. \endcode
  6369. \sa wolfSSL_GetHmacSize
  6370. */
  6371. WOLFSSL_API const unsigned char* wolfSSL_GetMacSecret(WOLFSSL*, int);
  6372. /*!
  6373. \brief Allows retrieval of the client write key from the handshake process.
  6374. \return pointer If successful the call will return a valid pointer to the
  6375. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  6376. \return NULL will be returned for an error state.
  6377. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6378. _Example_
  6379. \code
  6380. none
  6381. \endcode
  6382. \sa wolfSSL_GetKeySize
  6383. \sa wolfSSL_GetClientWriteIV
  6384. */
  6385. WOLFSSL_API const unsigned char* wolfSSL_GetClientWriteKey(WOLFSSL*);
  6386. /*!
  6387. \brief Allows retrieval of the client write IV (initialization vector)
  6388. from the handshake process.
  6389. \return pointer If successful the call will return a valid pointer to the
  6390. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  6391. \return NULL will be returned for an error state.
  6392. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6393. _Example_
  6394. \code
  6395. none
  6396. \endcode
  6397. \sa wolfSSL_GetCipherBlockSize()
  6398. \sa wolfSSL_GetClientWriteKey()
  6399. */
  6400. WOLFSSL_API const unsigned char* wolfSSL_GetClientWriteIV(WOLFSSL*);
  6401. /*!
  6402. \brief Allows retrieval of the server write key from the handshake process.
  6403. \return pointer If successful the call will return a valid pointer to the
  6404. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  6405. \return NULL will be returned for an error state.
  6406. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6407. _Example_
  6408. \code
  6409. none
  6410. \endcode
  6411. \sa wolfSSL_GetKeySize
  6412. \sa wolfSSL_GetServerWriteIV
  6413. */
  6414. WOLFSSL_API const unsigned char* wolfSSL_GetServerWriteKey(WOLFSSL*);
  6415. /*!
  6416. \brief Allows retrieval of the server write IV (initialization vector)
  6417. from the handshake process.
  6418. \return pointer If successful the call will return a valid pointer to the
  6419. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  6420. \return NULL will be returned for an error state.
  6421. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6422. \sa wolfSSL_GetCipherBlockSize
  6423. \sa wolfSSL_GetClientWriteKey
  6424. */
  6425. WOLFSSL_API const unsigned char* wolfSSL_GetServerWriteIV(WOLFSSL*);
  6426. /*!
  6427. \brief Allows retrieval of the key size from the handshake process.
  6428. \return size If successful the call will return the key size in bytes.
  6429. \return BAD_FUNC_ARG will be returned for an error state.
  6430. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6431. _Example_
  6432. \code
  6433. none
  6434. \endcode
  6435. \sa wolfSSL_GetClientWriteKey
  6436. \sa wolfSSL_GetServerWriteKey
  6437. */
  6438. WOLFSSL_API int wolfSSL_GetKeySize(WOLFSSL*);
  6439. /*!
  6440. \ingroup CertsKeys
  6441. \brief Returns the iv_size member of the specs structure
  6442. held in the WOLFSSL struct.
  6443. \return iv_size returns the value held in ssl->specs.iv_size.
  6444. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  6445. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6446. _Example_
  6447. \code
  6448. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6449. WOLFSSL* ssl = wolfSSL_new(ctx);
  6450. int ivSize;
  6451. ...
  6452. ivSize = wolfSSL_GetIVSize(ssl);
  6453. if(ivSize > 0){
  6454. // ivSize holds the specs.iv_size value.
  6455. }
  6456. \endcode
  6457. \sa wolfSSL_GetKeySize
  6458. \sa wolfSSL_GetClientWriteIV
  6459. \sa wolfSSL_GetServerWriteIV
  6460. */
  6461. WOLFSSL_API int wolfSSL_GetIVSize(WOLFSSL*);
  6462. /*!
  6463. \brief Allows retrieval of the side of this WOLFSSL connection.
  6464. \return success If successful the call will return either
  6465. WOLFSSL_SERVER_END or WOLFSSL_CLIENT_END depending on the
  6466. side of WOLFSSL object.
  6467. \return BAD_FUNC_ARG will be returned for an error state.
  6468. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6469. _Example_
  6470. \code
  6471. none
  6472. \endcode
  6473. \sa wolfSSL_GetClientWriteKey
  6474. \sa wolfSSL_GetServerWriteKey
  6475. */
  6476. WOLFSSL_API int wolfSSL_GetSide(WOLFSSL*);
  6477. /*!
  6478. \brief Allows caller to determine if the negotiated protocol version
  6479. is at least TLS version 1.1 or greater.
  6480. \return true/false If successful the call will return 1 for true or
  6481. 0 for false.
  6482. \return BAD_FUNC_ARG will be returned for an error state.
  6483. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6484. _Example_
  6485. \code
  6486. none
  6487. \endcode
  6488. \sa wolfSSL_GetSide
  6489. */
  6490. WOLFSSL_API int wolfSSL_IsTLSv1_1(WOLFSSL*);
  6491. /*!
  6492. \brief Allows caller to determine the negotiated bulk cipher algorithm
  6493. from the handshake.
  6494. \return If successful the call will return one of the following:
  6495. wolfssl_cipher_null, wolfssl_des, wolfssl_triple_des, wolfssl_aes,
  6496. wolfssl_aes_gcm, wolfssl_aes_ccm, wolfssl_camellia, wolfssl_hc128,
  6497. wolfssl_rabbit.
  6498. \return BAD_FUNC_ARG will be returned for an error state.
  6499. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6500. _Example_
  6501. \code
  6502. none
  6503. \endcode
  6504. \sa wolfSSL_GetCipherBlockSize
  6505. \sa wolfSSL_GetKeySize
  6506. */
  6507. WOLFSSL_API int wolfSSL_GetBulkCipher(WOLFSSL*);
  6508. /*!
  6509. \brief Allows caller to determine the negotiated cipher block size from
  6510. the handshake.
  6511. \return size If successful the call will return the size in bytes of the
  6512. cipher block size.
  6513. \return BAD_FUNC_ARG will be returned for an error state.
  6514. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6515. _Example_
  6516. \code
  6517. none
  6518. \endcode
  6519. \sa wolfSSL_GetBulkCipher
  6520. \sa wolfSSL_GetKeySize
  6521. */
  6522. WOLFSSL_API int wolfSSL_GetCipherBlockSize(WOLFSSL*);
  6523. /*!
  6524. \brief Allows caller to determine the negotiated aead mac size from the
  6525. handshake. For cipher type WOLFSSL_AEAD_TYPE.
  6526. \return size If successful the call will return the size in bytes of the
  6527. aead mac size.
  6528. \return BAD_FUNC_ARG will be returned for an error state.
  6529. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6530. _Example_
  6531. \code
  6532. none
  6533. \endcode
  6534. \sa wolfSSL_GetBulkCipher
  6535. \sa wolfSSL_GetKeySize
  6536. */
  6537. WOLFSSL_API int wolfSSL_GetAeadMacSize(WOLFSSL*);
  6538. /*!
  6539. \brief Allows caller to determine the negotiated (h)mac size from the
  6540. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  6541. \return size If successful the call will return the size in bytes of
  6542. the (h)mac size.
  6543. \return BAD_FUNC_ARG will be returned for an error state.
  6544. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6545. _Example_
  6546. \code
  6547. none
  6548. \endcode
  6549. \sa wolfSSL_GetBulkCipher
  6550. \sa wolfSSL_GetHmacType
  6551. */
  6552. WOLFSSL_API int wolfSSL_GetHmacSize(WOLFSSL*);
  6553. /*!
  6554. \brief Allows caller to determine the negotiated (h)mac type from the
  6555. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  6556. \return If successful the call will return one of the following:
  6557. MD5, SHA, SHA256, SHA384.
  6558. \return BAD_FUNC_ARG may be returned for an error state.
  6559. \return SSL_FATAL_ERROR may also be returned for an error state.
  6560. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6561. _Example_
  6562. \code
  6563. none
  6564. \endcode
  6565. \sa wolfSSL_GetBulkCipher
  6566. \sa wolfSSL_GetHmacSize
  6567. */
  6568. WOLFSSL_API int wolfSSL_GetHmacType(WOLFSSL*);
  6569. /*!
  6570. \brief Allows caller to determine the negotiated cipher type
  6571. from the handshake.
  6572. \return If successful the call will return one of the following:
  6573. WOLFSSL_BLOCK_TYPE, WOLFSSL_STREAM_TYPE, WOLFSSL_AEAD_TYPE.
  6574. \return BAD_FUNC_ARG will be returned for an error state.
  6575. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6576. _Example_
  6577. \code
  6578. none
  6579. \endcode
  6580. \sa wolfSSL_GetBulkCipher
  6581. \sa wolfSSL_GetHmacType
  6582. */
  6583. WOLFSSL_API int wolfSSL_GetCipherType(WOLFSSL*);
  6584. /*!
  6585. \brief Allows caller to set the Hmac Inner vector for message
  6586. sending/receiving. The result is written to inner which should
  6587. be at least wolfSSL_GetHmacSize() bytes. The size of the message
  6588. is specified by sz, content is the type of message, and verify
  6589. specifies whether this is a verification of a peer message. Valid
  6590. for cipher types excluding WOLFSSL_AEAD_TYPE.
  6591. \return 1 upon success.
  6592. \return BAD_FUNC_ARG will be returned for an error state.
  6593. \param none No parameters.
  6594. _Example_
  6595. \code
  6596. none
  6597. \endcode
  6598. \sa wolfSSL_GetBulkCipher
  6599. \sa wolfSSL_GetHmacType
  6600. */
  6601. WOLFSSL_API int wolfSSL_SetTlsHmacInner(WOLFSSL*, unsigned char*,
  6602. word32, int, int);
  6603. /*!
  6604. \brief Allows caller to set the Public Key Callback for ECC Signing.
  6605. The callback should return 0 for success or < 0 for an error.
  6606. The ssl and ctx pointers are available for the user’s convenience.
  6607. in is the input buffer to sign while inSz denotes the length of the input.
  6608. out is the output buffer where the result of the signature should be stored.
  6609. outSz is an input/output variable that specifies the size of the output
  6610. buffer upon invocation and the actual size of the signature should be stored
  6611. there before returning. keyDer is the ECC Private key in ASN1 format and
  6612. keySz is the length of the key in bytes. An example callback can be found
  6613. wolfssl/test.h myEccSign().
  6614. \return none No returns.
  6615. \param none No parameters.
  6616. _Example_
  6617. \code
  6618. none
  6619. \endcode
  6620. \sa wolfSSL_SetEccSignCtx
  6621. \sa wolfSSL_GetEccSignCtx
  6622. */
  6623. WOLFSSL_API void wolfSSL_CTX_SetEccSignCb(WOLFSSL_CTX*, CallbackEccSign);
  6624. /*!
  6625. \brief Allows caller to set the Public Key Ecc Signing Callback
  6626. Context to ctx.
  6627. \return none No returns.
  6628. \param none No parameters.
  6629. _Example_
  6630. \code
  6631. none
  6632. \endcode
  6633. \sa wolfSSL_CTX_SetEccSignCb
  6634. \sa wolfSSL_GetEccSignCtx
  6635. */
  6636. WOLFSSL_API void wolfSSL_SetEccSignCtx(WOLFSSL* ssl, void *ctx);
  6637. /*!
  6638. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  6639. Context previously stored with wolfSSL_SetEccSignCtx().
  6640. \return pointer If successful the call will return a valid pointer
  6641. to the context.
  6642. \return NULL will be returned for a blank context.
  6643. \param none No parameters.
  6644. _Example_
  6645. \code
  6646. none
  6647. \endcode
  6648. \sa wolfSSL_CTX_SetEccSignCb
  6649. \sa wolfSSL_SetEccSignCtx
  6650. */
  6651. WOLFSSL_API void* wolfSSL_GetEccSignCtx(WOLFSSL* ssl);
  6652. /*!
  6653. \brief Allows caller to set the Public Key Callback for ECC Verification.
  6654. The callback should return 0 for success or < 0 for an error.
  6655. The ssl and ctx pointers are available for the user’s convenience.
  6656. sig is the signature to verify and sigSz denotes the length of the
  6657. signature. hash is an input buffer containing the digest of the message
  6658. and hashSz denotes the length in bytes of the hash. result is an output
  6659. variable where the result of the verification should be stored, 1 for
  6660. success and 0 for failure. keyDer is the ECC Private key in ASN1
  6661. format and keySz is the length of the key in bytes. An example
  6662. callback can be found wolfssl/test.h myEccVerify().
  6663. \return none No returns.
  6664. \param none No parameters.
  6665. _Example_
  6666. \code
  6667. none
  6668. \endcode
  6669. \sa wolfSSL_SetEccVerifyCtx
  6670. \sa wolfSSL_GetEccVerifyCtx
  6671. */
  6672. WOLFSSL_API void wolfSSL_CTX_SetEccVerifyCb(WOLFSSL_CTX*, CallbackEccVerify);
  6673. /*!
  6674. \brief Allows caller to set the Public Key Ecc Verification Callback
  6675. Context to ctx.
  6676. \return none No returns.
  6677. \param none No parameters.
  6678. _Example_
  6679. \code
  6680. none
  6681. \endcode
  6682. \sa wolfSSL_CTX_SetEccVerifyCb
  6683. \sa wolfSSL_GetEccVerifyCtx
  6684. */
  6685. WOLFSSL_API void wolfSSL_SetEccVerifyCtx(WOLFSSL* ssl, void *ctx);
  6686. /*!
  6687. \brief Allows caller to retrieve the Public Key Ecc Verification Callback
  6688. Context previously stored with wolfSSL_SetEccVerifyCtx().
  6689. \return pointer If successful the call will return a valid pointer to the
  6690. context.
  6691. \return NULL will be returned for a blank context.
  6692. \param none No parameters.
  6693. _Example_
  6694. \code
  6695. none
  6696. \endcode
  6697. \sa wolfSSL_CTX_SetEccVerifyCb
  6698. \sa wolfSSL_SetEccVerifyCtx
  6699. */
  6700. WOLFSSL_API void* wolfSSL_GetEccVerifyCtx(WOLFSSL* ssl);
  6701. /*!
  6702. \brief Allows caller to set the Public Key Callback for RSA Signing.
  6703. The callback should return 0 for success or < 0 for an error.
  6704. The ssl and ctx pointers are available for the user’s convenience.
  6705. in is the input buffer to sign while inSz denotes the length of the input.
  6706. out is the output buffer where the result of the signature should be stored.
  6707. outSz is an input/output variable that specifies the size of the output
  6708. buffer upon invocation and the actual size of the signature should be
  6709. stored there before returning. keyDer is the RSA Private key in ASN1 format
  6710. and keySz is the length of the key in bytes. An example callback can be
  6711. found wolfssl/test.h myRsaSign().
  6712. \return none No returns.
  6713. \param none No parameters.
  6714. _Example_
  6715. \code
  6716. none
  6717. \endcode
  6718. \sa wolfSSL_SetRsaSignCtx
  6719. \sa wolfSSL_GetRsaSignCtx
  6720. */
  6721. WOLFSSL_API void wolfSSL_CTX_SetRsaSignCb(WOLFSSL_CTX*, CallbackRsaSign);
  6722. /*!
  6723. \brief Allows caller to set the Public Key RSA Signing Callback Context
  6724. to ctx.
  6725. \return none No Returns.
  6726. \param none No parameters.
  6727. _Example_
  6728. \code
  6729. none
  6730. \endcode
  6731. \sa wolfSSL_CTX_SetRsaSignCb
  6732. \sa wolfSSL_GetRsaSignCtx
  6733. */
  6734. WOLFSSL_API void wolfSSL_SetRsaSignCtx(WOLFSSL* ssl, void *ctx);
  6735. /*!
  6736. \brief Allows caller to retrieve the Public Key RSA Signing Callback
  6737. Context previously stored with wolfSSL_SetRsaSignCtx().
  6738. \return pointer If successful the call will return a valid pointer to the
  6739. context.
  6740. \return NULL will be returned for a blank context.
  6741. \param none No parameters.
  6742. \param none No parameters.
  6743. _Example_
  6744. \code
  6745. none
  6746. \endcode
  6747. \sa wolfSSL_CTX_SetRsaSignCb
  6748. \sa wolfSSL_SetRsaSignCtx
  6749. */
  6750. WOLFSSL_API void* wolfSSL_GetRsaSignCtx(WOLFSSL* ssl);
  6751. /*!
  6752. \brief Allows caller to set the Public Key Callback for RSA Verification.
  6753. The callback should return the number of plaintext bytes for success or
  6754. < 0 for an error. The ssl and ctx pointers are available for the user’s
  6755. convenience. sig is the signature to verify and sigSz denotes the length
  6756. of the signature. out should be set to the beginning of the verification
  6757. buffer after the decryption process and any padding. keyDer is the RSA
  6758. Public key in ASN1 format and keySz is the length of the key in bytes.
  6759. An example callback can be found wolfssl/test.h myRsaVerify().
  6760. \return none No returns.
  6761. \param none No parameters.
  6762. \sa wolfSSL_SetRsaVerifyCtx
  6763. \sa wolfSSL_GetRsaVerifyCtx
  6764. */
  6765. WOLFSSL_API void wolfSSL_CTX_SetRsaVerifyCb(WOLFSSL_CTX*, CallbackRsaVerify);
  6766. /*!
  6767. \brief Allows caller to set the Public Key RSA Verification Callback
  6768. Context to ctx.
  6769. \return none No returns.
  6770. \param none No parameters.
  6771. _Example_
  6772. \code
  6773. none
  6774. \endcode
  6775. \sa wolfSSL_CTX_SetRsaVerifyCb
  6776. \sa wolfSSL_GetRsaVerifyCtx
  6777. */
  6778. WOLFSSL_API void wolfSSL_SetRsaVerifyCtx(WOLFSSL* ssl, void *ctx);
  6779. /*!
  6780. \brief Allows caller to retrieve the Public Key RSA Verification Callback
  6781. Context previously stored with wolfSSL_SetRsaVerifyCtx().
  6782. \return pointer If successful the call will return a valid pointer to
  6783. the context.
  6784. \return NULL will be returned for a blank context.
  6785. \param none No parameters.
  6786. _Example_
  6787. \code
  6788. none
  6789. \endcode
  6790. \sa wolfSSL_CTX_SetRsaVerifyCb
  6791. \sa wolfSSL_SetRsaVerifyCtx
  6792. */
  6793. WOLFSSL_API void* wolfSSL_GetRsaVerifyCtx(WOLFSSL* ssl);
  6794. /*!
  6795. \brief Allows caller to set the Public Key Callback for RSA Public
  6796. Encrypt. The callback should return 0 for success or < 0 for an error.
  6797. The ssl and ctx pointers are available for the user’s convenience.
  6798. in is the input buffer to encrypt while inSz denotes the length of
  6799. the input. out is the output buffer where the result of the encryption
  6800. should be stored. outSz is an input/output variable that specifies
  6801. the size of the output buffer upon invocation and the actual size of
  6802. the encryption should be stored there before returning. keyDer is the
  6803. RSA Public key in ASN1 format and keySz is the length of the key in
  6804. bytes. An example callback can be found wolfssl/test.h myRsaEnc().
  6805. \return none No returns.
  6806. \param none No parameters.
  6807. _Examples_
  6808. \code
  6809. none
  6810. \endcode
  6811. \sa wolfSSL_SetRsaEncCtx
  6812. \sa wolfSSL_GetRsaEncCtx
  6813. */
  6814. WOLFSSL_API void wolfSSL_CTX_SetRsaEncCb(WOLFSSL_CTX*, CallbackRsaEnc);
  6815. /*!
  6816. \brief Allows caller to set the Public Key RSA Public Encrypt
  6817. Callback Context to ctx.
  6818. \return none No returns.
  6819. \param none No parameters.
  6820. _Example_
  6821. \code
  6822. none
  6823. \endcode
  6824. \sa wolfSSL_CTX_SetRsaEncCb
  6825. \sa wolfSSL_GetRsaEncCtx
  6826. */
  6827. WOLFSSL_API void wolfSSL_SetRsaEncCtx(WOLFSSL* ssl, void *ctx);
  6828. /*!
  6829. \brief Allows caller to retrieve the Public Key RSA Public Encrypt
  6830. Callback Context previously stored with wolfSSL_SetRsaEncCtx().
  6831. \return pointer If successful the call will return a valid pointer
  6832. to the context.
  6833. \return NULL will be returned for a blank context.
  6834. \param none No parameters.
  6835. _Example_
  6836. \code
  6837. none
  6838. \endcode
  6839. \sa wolfSSL_CTX_SetRsaEncCb
  6840. \sa wolfSSL_SetRsaEncCtx
  6841. */
  6842. WOLFSSL_API void* wolfSSL_GetRsaEncCtx(WOLFSSL* ssl);
  6843. /*!
  6844. \brief Allows caller to set the Public Key Callback for RSA Private
  6845. Decrypt. The callback should return the number of plaintext bytes
  6846. for success or < 0 for an error. The ssl and ctx pointers are available
  6847. for the user’s convenience. in is the input buffer to decrypt and inSz
  6848. denotes the length of the input. out should be set to the beginning
  6849. of the decryption buffer after the decryption process and any padding.
  6850. keyDer is the RSA Private key in ASN1 format and keySz is the length
  6851. of the key in bytes. An example callback can be found
  6852. wolfssl/test.h myRsaDec().
  6853. \return none No returns.
  6854. \param none No parameters.
  6855. _Example_
  6856. \code
  6857. none
  6858. \endcode
  6859. \sa wolfSSL_SetRsaDecCtx
  6860. \sa wolfSSL_GetRsaDecCtx
  6861. */
  6862. WOLFSSL_API void wolfSSL_CTX_SetRsaDecCb(WOLFSSL_CTX*, CallbackRsaDec);
  6863. /*!
  6864. \brief Allows caller to set the Public Key RSA Private Decrypt
  6865. Callback Context to ctx.
  6866. \return none No returns.
  6867. \param none No parameters.
  6868. _Example_
  6869. \code
  6870. none
  6871. \endcode
  6872. \sa wolfSSL_CTX_SetRsaDecCb
  6873. \sa wolfSSL_GetRsaDecCtx
  6874. */
  6875. WOLFSSL_API void wolfSSL_SetRsaDecCtx(WOLFSSL* ssl, void *ctx);
  6876. /*!
  6877. \brief Allows caller to retrieve the Public Key RSA Private Decrypt
  6878. Callback Context previously stored with wolfSSL_SetRsaDecCtx().
  6879. \return pointer If successful the call will return a valid pointer
  6880. to the context.
  6881. \return NULL will be returned for a blank context.
  6882. \param none No parameters.
  6883. _Example_
  6884. \code
  6885. none
  6886. \endcode
  6887. \sa wolfSSL_CTX_SetRsaDecCb
  6888. \sa wolfSSL_SetRsaDecCtx
  6889. */
  6890. WOLFSSL_API void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl);
  6891. /*!
  6892. \brief This function registers a callback with the SSL context
  6893. (WOLFSSL_CTX) to be called when a new CA certificate is loaded
  6894. into wolfSSL. The callback is given a buffer with the DER-encoded
  6895. certificate.
  6896. \return none No return.
  6897. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6898. \param callback function to be registered as the CA callback for the
  6899. wolfSSL context, ctx. The signature of this function must follow that
  6900. as shown above in the Synopsis section.
  6901. _Example_
  6902. \code
  6903. WOLFSSL_CTX* ctx = 0;
  6904. // CA callback prototype
  6905. int MyCACallback(unsigned char *der, int sz, int type);
  6906. // Register the custom CA callback with the SSL context
  6907. wolfSSL_CTX_SetCACb(ctx, MyCACallback);
  6908. int MyCACallback(unsigned char* der, int sz, int type)
  6909. {
  6910. // custom CA callback function, DER-encoded cert
  6911. // located in “der” of size “sz” with type “type”
  6912. }
  6913. \endcode
  6914. \sa wolfSSL_CTX_load_verify_locations
  6915. */
  6916. WOLFSSL_API void wolfSSL_CTX_SetCACb(WOLFSSL_CTX*, CallbackCACache);
  6917. /*!
  6918. \ingroup CertManager
  6919. \brief Allocates and initializes a new Certificate Manager context.
  6920. This context may be used independent of SSL needs. It may be used to
  6921. load certificates, verify certificates, and check the revocation status.
  6922. \return WOLFSSL_CERT_MANAGER If successful the call will return a valid
  6923. WOLFSSL_CERT_MANAGER pointer.
  6924. \return NULL will be returned for an error state.
  6925. \param none No parameters.
  6926. \sa wolfSSL_CertManagerFree
  6927. */
  6928. WOLFSSL_API WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew_ex(void* heap);
  6929. /*!
  6930. \ingroup CertManager
  6931. \brief Allocates and initializes a new Certificate Manager context.
  6932. This context may be used independent of SSL needs. It may be used to
  6933. load certificates, verify certificates, and check the revocation status.
  6934. \return WOLFSSL_CERT_MANAGER If successful the call will return a
  6935. valid WOLFSSL_CERT_MANAGER pointer.
  6936. \return NULL will be returned for an error state.
  6937. \param none No parameters.
  6938. _Example_
  6939. \code
  6940. #import <wolfssl/ssl.h>
  6941. WOLFSSL_CERT_MANAGER* cm;
  6942. cm = wolfSSL_CertManagerNew();
  6943. if (cm == NULL) {
  6944. // error creating new cert manager
  6945. }
  6946. \endcode
  6947. \sa wolfSSL_CertManagerFree
  6948. */
  6949. WOLFSSL_API WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew(void);
  6950. /*!
  6951. \ingroup CertManager
  6952. \brief Frees all resources associated with the Certificate Manager
  6953. context. Call this when you no longer need to use the Certificate Manager.
  6954. \return none
  6955. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  6956. wolfSSL_CertManagerNew().
  6957. _Example_
  6958. \code
  6959. #include <wolfssl/ssl.h>
  6960. WOLFSSL_CERT_MANAGER* cm;
  6961. ...
  6962. wolfSSL_CertManagerFree(cm);
  6963. \endcode
  6964. \sa wolfSSL_CertManagerNew
  6965. */
  6966. WOLFSSL_API void wolfSSL_CertManagerFree(WOLFSSL_CERT_MANAGER*);
  6967. /*!
  6968. \ingroup CertManager
  6969. \brief Specifies the locations for CA certificate loading into the
  6970. manager context. The PEM certificate CAfile may contain several
  6971. trusted CA certificates. If CApath is not NULL it specifies a
  6972. directory containing CA certificates in PEM format.
  6973. \return SSL_SUCCESS If successful the call will return.
  6974. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6975. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6976. can’t be read, or is corrupted.
  6977. \return MEMORY_E will be returned if an out of memory condition occurs.
  6978. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6979. \return BAD_FUNC_ARG is the error that will be returned if a
  6980. pointer is not provided.
  6981. \return SSL_FATAL_ERROR - will be returned upon failure.
  6982. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created
  6983. using wolfSSL_CertManagerNew().
  6984. \param file pointer to the name of the file containing CA
  6985. certificates to load.
  6986. \param path pointer to the name of a directory path containing CA c
  6987. ertificates to load. The NULL pointer may be used if no
  6988. certificate directory is desired.
  6989. _Example_
  6990. \code
  6991. #include <wolfssl/ssl.h>
  6992. int ret = 0;
  6993. WOLFSSL_CERT_MANAGER* cm;
  6994. ...
  6995. ret = wolfSSL_CertManagerLoadCA(cm, “path/to/cert-file.pem”, 0);
  6996. if (ret != SSL_SUCCESS) {
  6997. // error loading CA certs into cert manager
  6998. }
  6999. \endcode
  7000. \sa wolfSSL_CertManagerVerify
  7001. */
  7002. WOLFSSL_API int wolfSSL_CertManagerLoadCA(WOLFSSL_CERT_MANAGER*, const char* f,
  7003. const char* d);
  7004. /*!
  7005. \ingroup CertManager
  7006. \brief Loads the CA Buffer by calling wolfSSL_CTX_load_verify_buffer and
  7007. returning that result using a temporary cm so as not to lose the information
  7008. in the cm passed into the function.
  7009. \return SSL_FATAL_ERROR is returned if the WOLFSSL_CERT_MANAGER struct is
  7010. NULL or if wolfSSL_CTX_new() returns NULL.
  7011. \return SSL_SUCCESS is returned for a successful execution.
  7012. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7013. wolfSSL_CertManagerNew().
  7014. \param in buffer for cert information.
  7015. \param sz length of the buffer.
  7016. \param format certificate format, either PEM or DER.
  7017. _Example_
  7018. \code
  7019. WOLFSSL_CERT_MANAGER* cm = (WOLFSSL_CERT_MANAGER*)vp;
  7020. const unsigned char* in;
  7021. long sz;
  7022. int format;
  7023. if(wolfSSL_CertManagerLoadCABuffer(vp, sz, format) != SSL_SUCCESS){
  7024. Error returned. Failure case code block.
  7025. }
  7026. \endcode
  7027. \sa wolfSSL_CTX_load_verify_buffer
  7028. \sa ProcessChainBuffer
  7029. \sa ProcessBuffer
  7030. \sa cm_pick_method
  7031. */
  7032. WOLFSSL_API int wolfSSL_CertManagerLoadCABuffer(WOLFSSL_CERT_MANAGER*,
  7033. const unsigned char* in, long sz, int format);
  7034. /*!
  7035. \ingroup CertManager
  7036. \brief This function unloads the CA signer list.
  7037. \return SSL_SUCCESS returned on successful execution of the function.
  7038. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7039. \return BAD_MUTEX_E returned if there was a mutex error.
  7040. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure,
  7041. created using wolfSSL_CertManagerNew().
  7042. _Example_
  7043. \code
  7044. #include <wolfssl/ssl.h>
  7045. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7046. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7047. ...
  7048. if(wolfSSL_CertManagerUnloadCAs(ctx->cm) != SSL_SUCCESS){
  7049. Failure case.
  7050. }
  7051. \endcode
  7052. \sa FreeSignerTable
  7053. \sa UnlockMutex
  7054. */
  7055. WOLFSSL_API int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm);
  7056. /*!
  7057. \ingroup CertManager
  7058. \brief The function will free the Trusted Peer linked list and unlocks
  7059. the trusted peer list.
  7060. \return SSL_SUCCESS if the function completed normally.
  7061. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7062. \return BAD_MUTEX_E mutex error if tpLock, a member of the
  7063. WOLFSSL_CERT_MANAGER struct, is 0 (nill).
  7064. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7065. wolfSSL_CertManagerNew().
  7066. _Example_
  7067. \code
  7068. #include <wolfssl/ssl.h>
  7069. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7070. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7071. ...
  7072. if(wolfSSL_CertManagerUnload_trust_peers(cm) != SSL_SUCCESS){
  7073. The function did not execute successfully.
  7074. }
  7075. \endcode
  7076. \sa UnLockMutex
  7077. */
  7078. WOLFSSL_API int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm);
  7079. /*!
  7080. \ingroup CertManager
  7081. \brief Specifies the certificate to verify with the Certificate Manager
  7082. context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7083. \return SSL_SUCCESS If successful.
  7084. \return ASN_SIG_CONFIRM_E will be returned if the signature could not be
  7085. verified.
  7086. \return ASN_SIG_OID_E will be returned if the signature type is not
  7087. supported.
  7088. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7089. has been revoked.
  7090. \return CRL_MISSING is an error that is returned if a current issuer CRL is
  7091. not available.
  7092. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  7093. before date.
  7094. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  7095. after date.
  7096. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7097. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  7098. read, or is corrupted.
  7099. \return MEMORY_E will be returned if an out of memory condition occurs.
  7100. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7101. \return BAD_FUNC_ARG is the error that will be returned if a pointer is
  7102. not provided.
  7103. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7104. wolfSSL_CertManagerNew().
  7105. \param fname pointer to the name of the file containing the certificates
  7106. to verify.
  7107. \param format format of the certificate to verify - either
  7108. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7109. _Example_
  7110. \code
  7111. int ret = 0;
  7112. WOLFSSL_CERT_MANAGER* cm;
  7113. ...
  7114. ret = wolfSSL_CertManagerVerify(cm, “path/to/cert-file.pem”,
  7115. SSL_FILETYPE_PEM);
  7116. if (ret != SSL_SUCCESS) {
  7117. error verifying certificate
  7118. }
  7119. \endcode
  7120. \sa wolfSSL_CertManagerLoadCA
  7121. \sa wolfSSL_CertManagerVerifyBuffer
  7122. */
  7123. WOLFSSL_API int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER*, const char* f,
  7124. int format);
  7125. /*!
  7126. \ingroup CertManager
  7127. \brief Specifies the certificate buffer to verify with the Certificate
  7128. Manager context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7129. \return SSL_SUCCESS If successful.
  7130. \return ASN_SIG_CONFIRM_E will be returned if the signature could not
  7131. be verified.
  7132. \return ASN_SIG_OID_E will be returned if the signature type is not
  7133. supported.
  7134. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7135. has been revoked.
  7136. \return CRL_MISSING is an error that is returned if a current issuer CRL
  7137. is not available.
  7138. \return ASN_BEFORE_DATE_E will be returned if the current date is before
  7139. the before date.
  7140. \return ASN_AFTER_DATE_E will be returned if the current date is after
  7141. the after date.
  7142. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7143. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  7144. be read, or is corrupted.
  7145. \return MEMORY_E will be returned if an out of memory condition occurs.
  7146. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7147. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7148. is not provided.
  7149. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7150. wolfSSL_CertManagerNew().
  7151. \param buff buffer containing the certificates to verify.
  7152. \param sz size of the buffer, buf.
  7153. \param format format of the certificate to verify, located in buf - either
  7154. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7155. _Example_
  7156. \code
  7157. #include <wolfssl/ssl.h>
  7158. int ret = 0;
  7159. int sz = 0;
  7160. WOLFSSL_CERT_MANAGER* cm;
  7161. byte certBuff[...];
  7162. ...
  7163. ret = wolfSSL_CertManagerVerifyBuffer(cm, certBuff, sz, SSL_FILETYPE_PEM);
  7164. if (ret != SSL_SUCCESS) {
  7165. error verifying certificate
  7166. }
  7167. \endcode
  7168. \sa wolfSSL_CertManagerLoadCA
  7169. \sa wolfSSL_CertManagerVerify
  7170. */
  7171. WOLFSSL_API int wolfSSL_CertManagerVerifyBuffer(WOLFSSL_CERT_MANAGER* cm,
  7172. const unsigned char* buff, long sz, int format);
  7173. /*!
  7174. \ingroup CertManager
  7175. \brief The function sets the verifyCallback function in the Certificate
  7176. Manager. If present, it will be called for each cert loaded. If there is
  7177. a verification error, the verify callback can be used to over-ride the
  7178. error.
  7179. \return none No return.
  7180. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7181. wolfSSL_CertManagerNew().
  7182. \param vc a VerifyCallback function pointer to the callback routine
  7183. _Example_
  7184. \code
  7185. #include <wolfssl/ssl.h>
  7186. int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store)
  7187. { // do custom verification of certificate }
  7188. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7189. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7190. ...
  7191. wolfSSL_CertManagerSetVerify(cm, myVerify);
  7192. \endcode
  7193. \sa wolfSSL_CertManagerVerify
  7194. */
  7195. WOLFSSL_API void wolfSSL_CertManagerSetVerify(WOLFSSL_CERT_MANAGER* cm,
  7196. VerifyCallback vc);
  7197. /*!
  7198. \brief Check CRL if the option is enabled and compares the cert to the
  7199. CRL list.
  7200. \return SSL_SUCCESS returns if the function returned as expected. If
  7201. the crlEnabled member of the WOLFSSL_CERT_MANAGER struct is turned on.
  7202. \return MEMORY_E returns if the allocated memory failed.
  7203. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7204. \param cm a pointer to a WOLFSSL_CERT_MANAGER struct.
  7205. \param der pointer to a DER formatted certificate.
  7206. \param sz size of the certificate.
  7207. _Example_
  7208. \code
  7209. WOLFSSL_CERT_MANAGER* cm;
  7210. byte* der;
  7211. int sz; // size of der
  7212. ...
  7213. if(wolfSSL_CertManagerCheckCRL(cm, der, sz) != SSL_SUCCESS){
  7214. // Error returned. Deal with failure case.
  7215. }
  7216. \endcode
  7217. \sa CheckCertCRL
  7218. \sa ParseCertRelative
  7219. \sa wolfSSL_CertManagerSetCRL_CB
  7220. \sa InitDecodedCert
  7221. */
  7222. WOLFSSL_API int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER*,
  7223. unsigned char*, int sz);
  7224. /*!
  7225. \ingroup CertManager
  7226. \brief Turns on Certificate Revocation List checking when verifying
  7227. certificates with the Certificate Manager. By default, CRL checking
  7228. is off. options include WOLFSSL_CRL_CHECKALL which performs CRL
  7229. checking on each certificate in the chain versus the Leaf certificate
  7230. only which is the default.
  7231. \return SSL_SUCCESS If successful the call will return.
  7232. \return NOT_COMPILED_IN will be returned if wolfSSL was not built with
  7233. CRL enabled.
  7234. \return MEMORY_E will be returned if an out of memory condition occurs.
  7235. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7236. is not provided.
  7237. \return SSL_FAILURE will be returned if the CRL context cannot be
  7238. initialized properly.
  7239. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7240. wolfSSL_CertManagerNew().
  7241. \param options options to use when enabling the Certification Manager, cm.
  7242. _Example_
  7243. \code
  7244. #include <wolfssl/ssl.h>
  7245. int ret = 0;
  7246. WOLFSSL_CERT_MANAGER* cm;
  7247. ...
  7248. ret = wolfSSL_CertManagerEnableCRL(cm, 0);
  7249. if (ret != SSL_SUCCESS) {
  7250. error enabling cert manager
  7251. }
  7252. ...
  7253. \endcode
  7254. \sa wolfSSL_CertManagerDisableCRL
  7255. */
  7256. WOLFSSL_API int wolfSSL_CertManagerEnableCRL(WOLFSSL_CERT_MANAGER*,
  7257. int options);
  7258. /*!
  7259. \ingroup CertManager
  7260. \brief Turns off Certificate Revocation List checking when verifying
  7261. certificates with the Certificate Manager. By default, CRL checking is
  7262. off. You can use this function to temporarily or permanently disable CRL
  7263. checking with this Certificate Manager context that previously had CRL
  7264. checking enabled.
  7265. \return SSL_SUCCESS If successful the call will return.
  7266. \return BAD_FUNC_ARG is the error that will be returned if a function
  7267. pointer is not provided.
  7268. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7269. wolfSSL_CertManagerNew().
  7270. _Example_
  7271. \code
  7272. #include <wolfssl/ssl.h>
  7273. int ret = 0;
  7274. WOLFSSL_CERT_MANAGER* cm;
  7275. ...
  7276. ret = wolfSSL_CertManagerDisableCRL(cm);
  7277. if (ret != SSL_SUCCESS) {
  7278. error disabling cert manager
  7279. }
  7280. ...
  7281. \endcode
  7282. \sa wolfSSL_CertManagerEnableCRL
  7283. */
  7284. WOLFSSL_API int wolfSSL_CertManagerDisableCRL(WOLFSSL_CERT_MANAGER*);
  7285. /*!
  7286. \ingroup CertManager
  7287. \brief Error checks and passes through to LoadCRL() in order to load the
  7288. cert into the CRL for revocation checking.
  7289. \return SSL_SUCCESS if there is no error in wolfSSL_CertManagerLoadCRL and
  7290. if LoadCRL returns successfully.
  7291. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER struct is NULL.
  7292. \return SSL_FATAL_ERROR if wolfSSL_CertManagerEnableCRL returns anything
  7293. other than SSL_SUCCESS.
  7294. \return BAD_PATH_ERROR if the path is NULL.
  7295. \return MEMORY_E if LoadCRL fails to allocate heap memory.
  7296. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7297. wolfSSL_CertManagerNew().
  7298. \param path a constant char pointer holding the CRL path.
  7299. \param type type of certificate to be loaded.
  7300. \param monitor requests monitoring in LoadCRL().
  7301. _Example_
  7302. \code
  7303. #include <wolfssl/ssl.h>
  7304. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type,
  7305. int monitor);
  7306. wolfSSL_CertManagerLoadCRL(ssl->ctx->cm, path, type, monitor);
  7307. \endcode
  7308. \sa wolfSSL_CertManagerEnableCRL
  7309. \sa wolfSSL_LoadCRL
  7310. */
  7311. WOLFSSL_API int wolfSSL_CertManagerLoadCRL(WOLFSSL_CERT_MANAGER*,
  7312. const char*, int, int);
  7313. /*!
  7314. \ingroup CertManager
  7315. \brief The function loads the CRL file by calling BufferLoadCRL.
  7316. \return SSL_SUCCESS returned if the function completed without errors.
  7317. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7318. \return SSL_FATAL_ERROR returned if there is an error associated
  7319. with the WOLFSSL_CERT_MANAGER.
  7320. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  7321. \param buff a constant byte type and is the buffer.
  7322. \param sz a long int representing the size of the buffer.
  7323. \param type a long integer that holds the certificate type.
  7324. _Example_
  7325. \code
  7326. #include <wolfssl/ssl.h>
  7327. WOLFSSL_CERT_MANAGER* cm;
  7328. const unsigned char* buff;
  7329. long sz; size of buffer
  7330. int type; cert type
  7331. ...
  7332. int ret = wolfSSL_CertManagerLoadCRLBuffer(cm, buff, sz, type);
  7333. if(ret == SSL_SUCCESS){
  7334. return ret;
  7335. } else {
  7336. Failure case.
  7337. }
  7338. \endcode
  7339. \sa BufferLoadCRL
  7340. \sa wolfSSL_CertManagerEnableCRL
  7341. */
  7342. WOLFSSL_API int wolfSSL_CertManagerLoadCRLBuffer(WOLFSSL_CERT_MANAGER*,
  7343. const unsigned char*, long sz, int);
  7344. /*!
  7345. \ingroup CertManager
  7346. \brief This function sets the CRL Certificate Manager callback. If
  7347. HAVE_CRL is defined and a matching CRL record is not found then the
  7348. cbMissingCRL is called (set via wolfSSL_CertManagerSetCRL_Cb). This
  7349. allows you to externally retrieve the CRL and load it.
  7350. \return SSL_SUCCESS returned upon successful execution of the function and
  7351. subroutines.
  7352. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  7353. \param cm the WOLFSSL_CERT_MANAGER structure holding the information for
  7354. the certificate.
  7355. \param cb a function pointer to (*CbMissingCRL) that is set to the
  7356. cbMissingCRL member of the WOLFSSL_CERT_MANAGER.
  7357. _Example_
  7358. \code
  7359. #include <wolfssl/ssl.h>
  7360. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7361. WOLFSSL* ssl = wolfSSL_new(ctx);
  7362. void cb(const char* url){
  7363. Function body.
  7364. }
  7365. CbMissingCRL cb = CbMissingCRL;
  7366. if(ctx){
  7367. return wolfSSL_CertManagerSetCRL_Cb(ssl->ctx->cm, cb);
  7368. }
  7369. \endcode
  7370. \sa CbMissingCRL
  7371. \sa wolfSSL_SetCRL_Cb
  7372. */
  7373. WOLFSSL_API int wolfSSL_CertManagerSetCRL_Cb(WOLFSSL_CERT_MANAGER*,
  7374. CbMissingCRL);
  7375. /*!
  7376. \ingroup CertManager
  7377. \brief The function enables the WOLFSSL_CERT_MANAGER’s member, ocspEnabled
  7378. to signify that the OCSP check option is enabled.
  7379. \return SSL_SUCCESS returned on successful execution of the function. The
  7380. ocspEnabled member of the WOLFSSL_CERT_MANAGER is enabled.
  7381. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  7382. NULL or if an argument value that is not allowed is passed to a subroutine.
  7383. \return MEMORY_E returned if there is an error allocating memory within
  7384. this function or a subroutine.
  7385. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7386. wolfSSL_CertManagerNew().
  7387. \param der a byte pointer to the certificate.
  7388. \param sz an int type representing the size of the DER cert.
  7389. _Example_
  7390. \code
  7391. #import <wolfssl/ssl.h>
  7392. WOLFSSL* ssl = wolfSSL_new(ctx);
  7393. byte* der;
  7394. int sz; size of der
  7395. ...
  7396. if(wolfSSL_CertManagerCheckOCSP(cm, der, sz) != SSL_SUCCESS){
  7397. Failure case.
  7398. }
  7399. \endcode
  7400. \sa ParseCertRelative
  7401. \sa CheckCertOCSP
  7402. */
  7403. WOLFSSL_API int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER*,
  7404. unsigned char*, int sz);
  7405. /*!
  7406. \ingroup CertManager
  7407. \brief Turns on OCSP if it’s turned off and if compiled with the
  7408. set option available.
  7409. \return SSL_SUCCESS returned if the function call is successful.
  7410. \return BAD_FUNC_ARG if cm struct is NULL.
  7411. \return MEMORY_E if WOLFSSL_OCSP struct value is NULL.
  7412. \return SSL_FAILURE initialization of WOLFSSL_OCSP struct fails
  7413. to initialize.
  7414. \return NOT_COMPILED_IN build not compiled with correct feature enabled.
  7415. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7416. wolfSSL_CertManagerNew().
  7417. \param options used to set values in WOLFSSL_CERT_MANAGER struct.
  7418. _Example_
  7419. \code
  7420. #include <wolfssl/ssl.h>
  7421. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7422. WOLFSSL* ssl = wolfSSL_new(ctx);
  7423. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7424. int options;
  7425. if(wolfSSL_CertManagerEnableOCSP(ssl->ctx->cm, options) != SSL_SUCCESS){
  7426. Failure case.
  7427. }
  7428. \endcode
  7429. \sa wolfSSL_CertManagerNew
  7430. */
  7431. WOLFSSL_API int wolfSSL_CertManagerEnableOCSP(WOLFSSL_CERT_MANAGER*,
  7432. int options);
  7433. /*!
  7434. \ingroup CertManager
  7435. \brief Disables OCSP certificate revocation.
  7436. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled the
  7437. crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  7438. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  7439. \param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7440. _Example_
  7441. \code
  7442. #include <wolfssl/ssl.h>
  7443. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(method);
  7444. WOLFSSL* ssl = wolfSSL_new(ctx);
  7445. ...
  7446. if(wolfSSL_CertManagerDisableOCSP(ssl) != SSL_SUCCESS){
  7447. Fail case.
  7448. }
  7449. \endcode
  7450. \sa wolfSSL_DisableCRL
  7451. */
  7452. WOLFSSL_API int wolfSSL_CertManagerDisableOCSP(WOLFSSL_CERT_MANAGER*);
  7453. /*!
  7454. \ingroup CertManager
  7455. \brief The function copies the url to the ocspOverrideURL member of the
  7456. WOLFSSL_CERT_MANAGER structure.
  7457. \return SSL_SUCCESS the function was able to execute as expected.
  7458. \return BAD_FUNC_ARG the WOLFSSL_CERT_MANAGER struct is NULL.
  7459. \return MEMEORY_E Memory was not able to be allocated for the
  7460. ocspOverrideURL member of the certificate manager.
  7461. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7462. _Example_
  7463. \code
  7464. #include <wolfssl/ssl.h>
  7465. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7466. const char* url;
  7467. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url)
  7468. if(wolfSSL_CertManagerSetOCSPOverrideURL(ssl->ctx->cm, url) != SSL_SUCCESS){
  7469. Failure case.
  7470. }
  7471. \endcode
  7472. \sa ocspOverrideURL
  7473. \sa wolfSSL_SetOCSP_OverrideURL
  7474. */
  7475. WOLFSSL_API int wolfSSL_CertManagerSetOCSPOverrideURL(WOLFSSL_CERT_MANAGER*,
  7476. const char*);
  7477. /*!
  7478. \ingroup CertManager
  7479. \brief The function sets the OCSP callback in the WOLFSSL_CERT_MANAGER.
  7480. \return SSL_SUCCESS returned on successful execution. The arguments are
  7481. saved in the WOLFSSL_CERT_MANAGER structure.
  7482. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7483. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  7484. \param ioCb a function pointer of type CbOCSPIO.
  7485. \param respFreeCb - a function pointer of type CbOCSPRespFree.
  7486. \param ioCbCtx - a void pointer variable to the I/O callback user
  7487. registered context.
  7488. _Example_
  7489. \code
  7490. #include <wolfssl/ssl.h>
  7491. wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb,
  7492. CbOCSPRespFree respFreeCb, void* ioCbCtx){
  7493. return wolfSSL_CertManagerSetOCSP_Cb(ssl->ctx->cm, ioCb, respFreeCb, ioCbCtx);
  7494. \endcode
  7495. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  7496. \sa wolfSSL_CertManagerCheckOCSP
  7497. \sa wolfSSL_CertManagerEnableOCSPStapling
  7498. \sa wolfSSL_ENableOCSP
  7499. \sa wolfSSL_DisableOCSP
  7500. \sa wolfSSL_SetOCSP_Cb
  7501. */
  7502. WOLFSSL_API int wolfSSL_CertManagerSetOCSP_Cb(WOLFSSL_CERT_MANAGER*,
  7503. CbOCSPIO, CbOCSPRespFree, void*);
  7504. /*!
  7505. \ingroup CertManager
  7506. \brief This function turns on OCSP stapling if it is not turned on as well
  7507. as set the options.
  7508. \return SSL_SUCCESS returned if there were no errors and the function
  7509. executed successfully.
  7510. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  7511. NULL or otherwise if there was a unpermitted argument value passed to
  7512. a subroutine.
  7513. \return MEMORY_E returned if there was an issue allocating memory.
  7514. \return SSL_FAILURE returned if the initialization of the OCSP
  7515. structure failed.
  7516. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  7517. HAVE_CERTIFICATE_STATUS_REQUEST option.
  7518. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, a member of the
  7519. WOLFSSL_CTX structure.
  7520. _Example_
  7521. \code
  7522. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX* ctx){
  7523. return wolfSSL_CertManagerEnableOCSPStapling(ctx->cm);
  7524. \endcode
  7525. \sa wolfSSL_CTX_EnableOCSPStapling
  7526. */
  7527. WOLFSSL_API int wolfSSL_CertManagerEnableOCSPStapling(
  7528. WOLFSSL_CERT_MANAGER* cm);
  7529. /*!
  7530. \brief Enables CRL certificate revocation.
  7531. \return SSL_SUCCESS the function and subroutines returned with no errors.
  7532. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  7533. \return MEMORY_E returned if the allocation of memory failed.
  7534. \return SSL_FAILURE returned if the InitCRL function does not return
  7535. successfully.
  7536. \return NOT_COMPILED_IN HAVE_CRL was not enabled during the compiling.
  7537. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7538. \param options an integer that is used to determine the setting of
  7539. crlCheckAll member of the WOLFSSL_CERT_MANAGER structure.
  7540. _Example_
  7541. \code
  7542. WOLFSSL* ssl = wolfSSL_new(ctx);
  7543. if (wolfSSL_EnableCRL(ssl, WOLFSSL_CRL_CHECKALL) != SSL_SUCCESS){
  7544. // Failure case. SSL_SUCCESS was not returned by this function or
  7545. a subroutine
  7546. }
  7547. \endcode
  7548. \sa wolfSSL_CertManagerEnableCRL
  7549. \sa InitCRL
  7550. */
  7551. WOLFSSL_API int wolfSSL_EnableCRL(WOLFSSL* ssl, int options);
  7552. /*!
  7553. \brief Disables CRL certificate revocation.
  7554. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled
  7555. the crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  7556. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  7557. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7558. _Example_
  7559. \code
  7560. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7561. WOLFSSL* ssl = wolfSSL_new(ctx);
  7562. ...
  7563. if(wolfSSL_DisableCRL(ssl) != SSL_SUCCESS){
  7564. // Failure case
  7565. }
  7566. \endcode
  7567. \sa wolfSSL_CertManagerDisableCRL
  7568. \sa wolfSSL_CertManagerDisableOCSP
  7569. */
  7570. WOLFSSL_API int wolfSSL_DisableCRL(WOLFSSL* ssl);
  7571. /*!
  7572. \brief A wrapper function that ends up calling LoadCRL to load the
  7573. certificate for revocation checking.
  7574. \return WOLFSSL_SUCCESS returned if the function and all of the
  7575. subroutines executed without error.
  7576. \return SSL_FATAL_ERROR returned if one of the subroutines does not
  7577. return successfully.
  7578. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER or the WOLFSSL
  7579. structure are NULL.
  7580. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7581. \param path a constant character pointer that holds the path to the
  7582. crl file.
  7583. \param type an integer representing the type of certificate.
  7584. \param monitor an integer variable used to verify the monitor path if
  7585. requested.
  7586. _Example_
  7587. \code
  7588. WOLFSSL* ssl = wolfSSL_new(ctx);
  7589. const char* crlPemDir;
  7590. if(wolfSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, 0) != SSL_SUCCESS){
  7591. // Failure case. Did not return SSL_SUCCESS.
  7592. }
  7593. \endcode
  7594. \sa wolfSSL_CertManagerLoadCRL
  7595. \sa wolfSSL_CertManagerEnableCRL
  7596. \sa LoadCRL
  7597. */
  7598. WOLFSSL_API int wolfSSL_LoadCRL(WOLFSSL*, const char*, int, int);
  7599. /*!
  7600. \brief Sets the CRL callback in the WOLFSSL_CERT_MANAGER structure.
  7601. \return SSL_SUCCESS returned if the function or subroutine executes
  7602. without error. The cbMissingCRL member of the WOLFSSL_CERT_MANAGER is set.
  7603. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  7604. structure is NULL.
  7605. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7606. \param cb a function pointer to CbMissingCRL.
  7607. _Example_
  7608. \code
  7609. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  7610. WOLFSSL* ssl = wolfSSL_new(ctx);
  7611. void cb(const char* url) // required signature
  7612. {
  7613. // Function body
  7614. }
  7615. int crlCb = wolfSSL_SetCRL_Cb(ssl, cb);
  7616. if(crlCb != SSL_SUCCESS){
  7617. // The callback was not set properly
  7618. }
  7619. \endcode
  7620. \sa CbMissingCRL
  7621. \sa wolfSSL_CertManagerSetCRL_Cb
  7622. */
  7623. WOLFSSL_API int wolfSSL_SetCRL_Cb(WOLFSSL*, CbMissingCRL);
  7624. /*!
  7625. \brief This function enables OCSP certificate verification.
  7626. \return SSL_SUCCESS returned if the function and subroutines executes
  7627. without errors.
  7628. \return BAD_FUNC_ARG returned if an argument in this function or any
  7629. subroutine receives an invalid argument value.
  7630. \return MEMORY_E returned if there was an error allocating memory for
  7631. a structure or other variable.
  7632. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with the
  7633. HAVE_OCSP option.
  7634. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7635. \param options an integer type passed to wolfSSL_CertMangerENableOCSP()
  7636. used for settings check.
  7637. _Example_
  7638. \code
  7639. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7640. WOLFSSL* ssl = wolfSSL_new(ctx);
  7641. int options; // initialize to option constant
  7642. int ret = wolfSSL_EnableOCSP(ssl, options);
  7643. if(ret != SSL_SUCCESS){
  7644. // OCSP is not enabled
  7645. }
  7646. \endcode
  7647. \sa wolfSSL_CertManagerEnableOCSP
  7648. */
  7649. WOLFSSL_API int wolfSSL_EnableOCSP(WOLFSSL*, int options);
  7650. /*!
  7651. \brief Disables the OCSP certificate revocation option.
  7652. \return SSL_SUCCESS returned if the function and its subroutine return with
  7653. no errors. The ocspEnabled member of the WOLFSSL_CERT_MANAGER structure was
  7654. successfully set.
  7655. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  7656. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7657. _Example_
  7658. \code
  7659. WOLFSSL* ssl = wolfSSL_new(ctx);
  7660. if(wolfSSL_DisableOCSP(ssl) != SSL_SUCCESS){
  7661. // Returned with an error. Failure case in this block.
  7662. }
  7663. \endcode
  7664. \sa wolfSSL_CertManagerDisableOCSP
  7665. */
  7666. WOLFSSL_API int wolfSSL_DisableOCSP(WOLFSSL*);
  7667. /*!
  7668. \brief This function sets the ocspOverrideURL member in the
  7669. WOLFSSL_CERT_MANAGER structure.
  7670. \return SSL_SUCCESS returned on successful execution of the function.
  7671. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if a
  7672. unpermitted argument was passed to a subroutine.
  7673. \return MEMORY_E returned if there was an error allocating memory in the
  7674. subroutine.
  7675. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7676. \param url a constant char pointer to the url that will be stored in the
  7677. ocspOverrideURL member of the WOLFSSL_CERT_MANAGER structure.
  7678. _Example_
  7679. \code
  7680. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7681. WOLFSSL* ssl = wolfSSL_new(ctx);
  7682. char url[URLSZ];
  7683. ...
  7684. if(wolfSSL_SetOCSP_OverrideURL(ssl, url)){
  7685. // The override url is set to the new value
  7686. }
  7687. \endcode
  7688. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  7689. */
  7690. WOLFSSL_API int wolfSSL_SetOCSP_OverrideURL(WOLFSSL*, const char*);
  7691. /*!
  7692. \brief This function sets the OCSP callback in the
  7693. WOLFSSL_CERT_MANAGER structure.
  7694. \return SSL_SUCCESS returned if the function executes without error.
  7695. The ocspIOCb, ocspRespFreeCb, and ocspIOCtx members of the CM are set.
  7696. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  7697. structures are NULL.
  7698. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7699. \param ioCb a function pointer to type CbOCSPIO.
  7700. \param respFreeCb a function pointer to type CbOCSPRespFree which is the
  7701. call to free the response memory.
  7702. \param ioCbCtx a void pointer that will be held in the ocspIOCtx member
  7703. of the CM.
  7704. _Example_
  7705. \code
  7706. WOLFSSL* ssl = wolfSSL_new(ctx);
  7707. int OCSPIO_CB(void* , const char*, int , unsigned char* , int,
  7708. unsigned char**){ // must have this signature
  7709. // Function Body
  7710. }
  7711. void OCSPRespFree_CB(void* , unsigned char* ){ // must have this signature
  7712. // function body
  7713. }
  7714. void* ioCbCtx;
  7715. CbOCSPRespFree CB_OCSPRespFree;
  7716. if(wolfSSL_SetOCSP_Cb(ssl, OCSPIO_CB( pass args ), CB_OCSPRespFree,
  7717. ioCbCtx) != SSL_SUCCESS){
  7718. // Callback not set
  7719. }
  7720. \endcode
  7721. \sa wolfSSL_CertManagerSetOCSP_Cb
  7722. \sa CbOCSPIO
  7723. \sa CbOCSPRespFree
  7724. */
  7725. WOLFSSL_API int wolfSSL_SetOCSP_Cb(WOLFSSL*, CbOCSPIO, CbOCSPRespFree, void*);
  7726. /*!
  7727. \brief Enables CRL certificate verification through the CTX.
  7728. \return SSL_SUCCESS returned if this function and it’s subroutines
  7729. execute without errors.
  7730. \return BAD_FUNC_ARG returned if the CTX struct is NULL or there
  7731. was otherwise an invalid argument passed in a subroutine.
  7732. \return MEMORY_E returned if there was an error allocating
  7733. memory during execution of the function.
  7734. \return SSL_FAILURE returned if the crl member of the
  7735. WOLFSSL_CERT_MANAGER fails to initialize correctly.
  7736. \return NOT_COMPILED_IN wolfSSL was not compiled with the HAVE_CRL option.
  7737. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7738. _Example_
  7739. \code
  7740. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7741. WOLFSSL* ssl = wolfSSL_new(ctx);
  7742. ...
  7743. if(wolfSSL_CTX_EnableCRL(ssl->ctx, options) != SSL_SUCCESS){
  7744. // The function failed
  7745. }
  7746. \endcode
  7747. \sa wolfSSL_CertManagerEnableCRL
  7748. \sa InitCRL
  7749. \sa wolfSSL_CTX_DisableCRL
  7750. */
  7751. WOLFSSL_API int wolfSSL_CTX_EnableCRL(WOLFSSL_CTX* ctx, int options);
  7752. /*!
  7753. \brief This function disables CRL verification in the CTX structure.
  7754. \return SSL_SUCCESS returned if the function executes without error.
  7755. The crlEnabled member of the WOLFSSL_CERT_MANAGER struct is set to 0.
  7756. \return BAD_FUNC_ARG returned if either the CTX struct or the CM
  7757. struct has a NULL value.
  7758. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  7759. wolfSSL_CTX_new().
  7760. _Example_
  7761. \code
  7762. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7763. WOLFSSL* ssl = wolfSSL_new(ctx);
  7764. ...
  7765. if(wolfSSL_CTX_DisableCRL(ssl->ctx) != SSL_SUCCESS){
  7766. // Failure case.
  7767. }
  7768. \endcode
  7769. \sa wolfSSL_CertManagerDisableCRL
  7770. */
  7771. WOLFSSL_API int wolfSSL_CTX_DisableCRL(WOLFSSL_CTX* ctx);
  7772. /*!
  7773. \brief This function loads CRL into the WOLFSSL_CTX structure through
  7774. wolfSSL_CertManagerLoadCRL().
  7775. \return SSL_SUCCESS - returned if the function and its subroutines
  7776. execute without error.
  7777. \return BAD_FUNC_ARG - returned if this function or any subroutines
  7778. are passed NULL structures.
  7779. \return BAD_PATH_ERROR - returned if the path variable opens as NULL.
  7780. \return MEMORY_E - returned if an allocation of memory failed.
  7781. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  7782. wolfSSL_CTX_new().
  7783. \param path the path to the certificate.
  7784. \param type an integer variable holding the type of certificate.
  7785. \param monitor an integer variable used to determine if the monitor
  7786. path is requested.
  7787. _Example_
  7788. \code
  7789. WOLFSSL_CTX* ctx;
  7790. const char* path;
  7791. return wolfSSL_CTX_LoadCRL(ctx, path, SSL_FILETYPE_PEM, 0);
  7792. \endcode
  7793. \sa wolfSSL_CertManagerLoadCRL
  7794. \sa LoadCRL
  7795. */
  7796. WOLFSSL_API int wolfSSL_CTX_LoadCRL(WOLFSSL_CTX*, const char*, int, int);
  7797. /*!
  7798. \brief This function will set the callback argument to the cbMissingCRL
  7799. member of the WOLFSSL_CERT_MANAGER structure by calling
  7800. wolfSSL_CertManagerSetCRL_Cb.
  7801. \return SSL_SUCCESS returned for a successful execution. The
  7802. WOLFSSL_CERT_MANAGER structure’s member cbMssingCRL was successfully
  7803. set to cb.
  7804. \return BAD_FUNC_ARG returned if WOLFSSL_CTX or WOLFSSL_CERT_MANAGER
  7805. are NULL.
  7806. \param ctx a pointer to a WOLFSSL_CTX structure, created with
  7807. wolfSSL_CTX_new().
  7808. \param cb a pointer to a callback function of type CbMissingCRL.
  7809. Signature requirement:
  7810. void (*CbMissingCRL)(const char* url);
  7811. _Example_
  7812. \code
  7813. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  7814. void cb(const char* url) // Required signature
  7815. {
  7816. // Function body
  7817. }
  7818. if (wolfSSL_CTX_SetCRL_Cb(ctx, cb) != SSL_SUCCESS){
  7819. // Failure case, cb was not set correctly.
  7820. }
  7821. \endcode
  7822. \sa wolfSSL_CertManagerSetCRL_Cb
  7823. \sa CbMissingCRL
  7824. */
  7825. WOLFSSL_API int wolfSSL_CTX_SetCRL_Cb(WOLFSSL_CTX*, CbMissingCRL);
  7826. /*!
  7827. \brief This function sets options to configure behavior of OCSP
  7828. functionality in wolfSSL. The value of options if formed by or’ing
  7829. one or more of the following options:
  7830. WOLFSSL_OCSP_ENABLE - enable OCSP lookups WOLFSSL_OCSP_URL_OVERRIDE -
  7831. use the override URL instead of the URL in certificates. The override URL
  7832. is specified using the wolfSSL_CTX_SetOCSP_OverrideURL() function. This
  7833. function only sets the OCSP options when wolfSSL has been compiled with
  7834. OCSP support (--enable-ocsp, #define HAVE_OCSP).
  7835. \return SSL_SUCCESS is returned upon success.
  7836. \return SSL_FAILURE is returned upon failure.
  7837. \return NOT_COMPILED_IN is returned when this function has been called,
  7838. but OCSP support was not enabled when wolfSSL was compiled.
  7839. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  7840. \param options value used to set the OCSP options.
  7841. _Example_
  7842. \code
  7843. WOLFSSL_CTX* ctx = 0;
  7844. ...
  7845. wolfSSL_CTX_OCSP_set_options(ctx, WOLFSSL_OCSP_ENABLE);
  7846. \endcode
  7847. \sa wolfSSL_CTX_OCSP_set_override_url
  7848. */
  7849. WOLFSSL_API int wolfSSL_CTX_EnableOCSP(WOLFSSL_CTX*, int options);
  7850. /*!
  7851. \brief This function disables OCSP certificate revocation checking by
  7852. affecting the ocspEnabled member of the WOLFSSL_CERT_MANAGER structure.
  7853. \return SSL_SUCCESS returned if the function executes without error.
  7854. The ocspEnabled member of the CM has been disabled.
  7855. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  7856. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  7857. wolfSSL_CTX_new().
  7858. _Example_
  7859. \code
  7860. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7861. WOLFSSL* ssl = wolfSSL_new(ctx);
  7862. ...
  7863. if(!wolfSSL_CTX_DisableOCSP(ssl->ctx)){
  7864. // OCSP is not disabled
  7865. }
  7866. \endcode
  7867. \sa wolfSSL_DisableOCSP
  7868. \sa wolfSSL_CertManagerDisableOCSP
  7869. */
  7870. WOLFSSL_API int wolfSSL_CTX_DisableOCSP(WOLFSSL_CTX*);
  7871. /*!
  7872. \brief This function manually sets the URL for OCSP to use. By default,
  7873. OCSP will use the URL found in the individual certificate unless the
  7874. WOLFSSL_OCSP_URL_OVERRIDE option is set using the wolfSSL_CTX_EnableOCSP.
  7875. \return SSL_SUCCESS is returned upon success.
  7876. \return SSL_FAILURE is returned upon failure.
  7877. \return NOT_COMPILED_IN is returned when this function has been called,
  7878. but OCSP support was not enabled when wolfSSL was compiled.
  7879. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  7880. \param url pointer to the OCSP URL for wolfSSL to use.
  7881. _Example_
  7882. \code
  7883. WOLFSSL_CTX* ctx = 0;
  7884. ...
  7885. wolfSSL_CTX_OCSP_set_override_url(ctx, “custom-url-here”);
  7886. \endcode
  7887. \sa wolfSSL_CTX_OCSP_set_options
  7888. */
  7889. WOLFSSL_API int wolfSSL_CTX_SetOCSP_OverrideURL(WOLFSSL_CTX*, const char*);
  7890. /*!
  7891. \brief Sets the callback for the OCSP in the WOLFSSL_CTX structure.
  7892. \return SSL_SUCCESS returned if the function executed successfully. The
  7893. ocspIOCb, ocspRespFreeCb, and ocspIOCtx members in the CM were
  7894. successfully set.
  7895. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX or
  7896. WOLFSSL_CERT_MANAGER structure is NULL.
  7897. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7898. \param ioCb a CbOCSPIO type that is a function pointer.
  7899. \param respFreeCb a CbOCSPRespFree type that is a function pointer.
  7900. \param ioCbCtx a void pointer that will be held in the WOLFSSL_CERT_MANAGER.
  7901. _Example_
  7902. \code
  7903. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  7904. CbOCSPIO ocspIOCb;
  7905. CbOCSPRespFree ocspRespFreeCb;
  7906. void* ioCbCtx;
  7907. int isSetOCSP = wolfSSL_CTX_SetOCSP_Cb(ctx, ocspIOCb,
  7908. ocspRespFreeCb, ioCbCtx);
  7909. if(isSetOCSP != SSL_SUCCESS){
  7910. // The function did not return successfully.
  7911. }
  7912. \endcode
  7913. \sa wolfSSL_CertManagerSetOCSP_Cb
  7914. \sa CbOCSPIO
  7915. \sa CbOCSPRespFree
  7916. */
  7917. WOLFSSL_API int wolfSSL_CTX_SetOCSP_Cb(WOLFSSL_CTX*,
  7918. CbOCSPIO, CbOCSPRespFree, void*);
  7919. /*!
  7920. \brief This function enables OCSP stapling by calling
  7921. wolfSSL_CertManagerEnableOCSPStapling().
  7922. \return SSL_SUCCESS returned if there were no errors and the function
  7923. executed successfully.
  7924. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  7925. otherwise if there was a unpermitted argument value passed to a subroutine.
  7926. \return MEMORY_E returned if there was an issue allocating memory.
  7927. \return SSL_FAILURE returned if the initialization of the OCSP
  7928. structure failed.
  7929. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  7930. HAVE_CERTIFICATE_STATUS_REQUEST option.
  7931. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  7932. wolfSSL_CTX_new().
  7933. _Example_
  7934. \code
  7935. WOLFSSL* ssl = WOLFSSL_new();
  7936. ssl->method.version; // set to desired protocol
  7937. ...
  7938. if(!wolfSSL_CTX_EnableOCSPStapling(ssl->ctx)){
  7939. // OCSP stapling is not enabled
  7940. }
  7941. \endcode
  7942. \sa wolfSSL_CertManagerEnableOCSPStapling
  7943. \sa InitOCSP
  7944. */
  7945. WOLFSSL_API int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX*);
  7946. /*!
  7947. \ingroup CertsKeys
  7948. \brief Normally, at the end of the SSL handshake, wolfSSL frees
  7949. temporary arrays. Calling this function before the handshake begins
  7950. will prevent wolfSSL from freeing temporary arrays. Temporary arrays
  7951. may be needed for things such as wolfSSL_get_keys() or PSK hints.
  7952. When the user is done with temporary arrays, either wolfSSL_FreeArrays()
  7953. may be called to free the resources immediately, or alternatively the
  7954. resources will be freed when the associated SSL object is freed.
  7955. \return none No return.
  7956. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7957. _Example_
  7958. \code
  7959. WOLFSSL* ssl;
  7960. ...
  7961. wolfSSL_KeepArrays(ssl);
  7962. \endcode
  7963. \sa wolfSSL_FreeArrays
  7964. */
  7965. WOLFSSL_API void wolfSSL_KeepArrays(WOLFSSL*);
  7966. /*!
  7967. \ingroup CertsKeys
  7968. \brief Normally, at the end of the SSL handshake, wolfSSL frees temporary
  7969. arrays. If wolfSSL_KeepArrays() has been called before the handshake,
  7970. wolfSSL will not free temporary arrays. This function explicitly frees
  7971. temporary arrays and should be called when the user is done with temporary
  7972. arrays and does not want to wait for the SSL object to be freed to free
  7973. these resources.
  7974. \return none No return.
  7975. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7976. _Example_
  7977. \code
  7978. WOLFSSL* ssl;
  7979. ...
  7980. wolfSSL_FreeArrays(ssl);
  7981. \endcode
  7982. \sa wolfSSL_KeepArrays
  7983. */
  7984. WOLFSSL_API void wolfSSL_FreeArrays(WOLFSSL*);
  7985. /*!
  7986. \brief This function enables the use of Server Name Indication in the SSL
  7987. object passed in the 'ssl' parameter. It means that the SNI extension will
  7988. be sent on ClientHello by wolfSSL client and wolfSSL server will respond
  7989. ClientHello + SNI with either ServerHello + blank SNI or alert fatal in
  7990. case of SNI mismatch.
  7991. \return SSL_SUCCESS upon success.
  7992. \return BAD_FUNC_ARG is the error that will be returned in one of these
  7993. cases: ssl is NULL, data is NULL, type is a unknown value. (see below)
  7994. \return MEMORY_E is the error returned when there is not enough memory.
  7995. \param ssl pointer to a SSL object, created with wolfSSL_new().
  7996. \param type indicates which type of server name is been passed in data.
  7997. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  7998. \param data pointer to the server name data.
  7999. \param size size of the server name data.
  8000. _Example_
  8001. \code
  8002. int ret = 0;
  8003. WOLFSSL_CTX* ctx = 0;
  8004. WOLFSSL* ssl = 0;
  8005. ctx = wolfSSL_CTX_new(method);
  8006. if (ctx == NULL) {
  8007. // context creation failed
  8008. }
  8009. ssl = wolfSSL_new(ctx);
  8010. if (ssl == NULL) {
  8011. // ssl creation failed
  8012. }
  8013. ret = wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8014. strlen("www.yassl.com"));
  8015. if (ret != 0) {
  8016. // sni usage failed
  8017. }
  8018. \endcode
  8019. \sa wolfSSL_new
  8020. \sa wolfSSL_CTX_UseSNI
  8021. */
  8022. WOLFSSL_API int wolfSSL_UseSNI(WOLFSSL* ssl, unsigned char type,
  8023. const void* data, unsigned short size);
  8024. /*!
  8025. \brief This function enables the use of Server Name Indication for SSL
  8026. objects created from the SSL context passed in the 'ctx' parameter. It
  8027. means that the SNI extension will be sent on ClientHello by wolfSSL
  8028. clients and wolfSSL servers will respond ClientHello + SNI with either
  8029. ServerHello + blank SNI or alert fatal in case of SNI mismatch.
  8030. \return SSL_SUCCESS upon success.
  8031. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8032. cases: ctx is NULL, data is NULL, type is a unknown value. (see below)
  8033. \return MEMORY_E is the error returned when there is not enough memory.
  8034. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8035. \param type indicates which type of server name is been passed in data.
  8036. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8037. \param data pointer to the server name data.
  8038. \param size size of the server name data.
  8039. _Example_
  8040. \code
  8041. int ret = 0;
  8042. WOLFSSL_CTX* ctx = 0;
  8043. ctx = wolfSSL_CTX_new(method);
  8044. if (ctx == NULL) {
  8045. // context creation failed
  8046. }
  8047. ret = wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8048. strlen("www.yassl.com"));
  8049. if (ret != 0) {
  8050. // sni usage failed
  8051. }
  8052. \endcode
  8053. \sa wolfSSL_CTX_new
  8054. \sa wolfSSL_UseSNI
  8055. */
  8056. WOLFSSL_API int wolfSSL_CTX_UseSNI(WOLFSSL_CTX* ctx, unsigned char type,
  8057. const void* data, unsigned short size);
  8058. /*!
  8059. \brief This function is called on the server side to configure the
  8060. behavior of the SSL session using Server Name Indication in the SSL
  8061. object passed in the 'ssl' parameter. The options are explained below.
  8062. \return none No returns.
  8063. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8064. \param type indicates which type of server name is been passed in data.
  8065. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8066. \param options a bitwise semaphore with the chosen options. The available
  8067. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8068. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort the
  8069. handshake by sending a fatal-level unrecognized_name(112) alert if the
  8070. hostname provided by the client mismatch with the servers.
  8071. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the server
  8072. will not send a SNI response instead of aborting the session.
  8073. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH - With this option set, the server
  8074. will send a SNI response as if the host names match instead of aborting
  8075. the session.
  8076. _Example_
  8077. \code
  8078. int ret = 0;
  8079. WOLFSSL_CTX* ctx = 0;
  8080. WOLFSSL* ssl = 0;
  8081. ctx = wolfSSL_CTX_new(method);
  8082. if (ctx == NULL) {
  8083. // context creation failed
  8084. }
  8085. ssl = wolfSSL_new(ctx);
  8086. if (ssl == NULL) {
  8087. // ssl creation failed
  8088. }
  8089. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8090. if (ret != 0) {
  8091. // sni usage failed
  8092. }
  8093. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  8094. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8095. \endcode
  8096. \sa wolfSSL_new
  8097. \sa wolfSSL_UseSNI
  8098. \sa wolfSSL_CTX_SNI_SetOptions
  8099. */
  8100. WOLFSSL_API void wolfSSL_SNI_SetOptions(WOLFSSL* ssl, unsigned char type,
  8101. unsigned char options);
  8102. /*!
  8103. \brief This function is called on the server side to configure the behavior
  8104. of the SSL sessions using Server Name Indication for SSL objects created
  8105. from the SSL context passed in the 'ctx' parameter. The options are
  8106. explained below.
  8107. \return none No returns.
  8108. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8109. \param type indicates which type of server name is been passed in data.
  8110. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8111. \param options a bitwise semaphore with the chosen options. The available
  8112. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8113. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort
  8114. the handshake by sending a fatal-level unrecognized_name(112) alert if the
  8115. hostname provided by the client mismatch with the servers.
  8116. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the
  8117. server will not send a SNI response instead of aborting the session.
  8118. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH With this option set, the server
  8119. will send a SNI response as if the host names match instead of aborting
  8120. the session.
  8121. _Example_
  8122. \code
  8123. int ret = 0;
  8124. WOLFSSL_CTX* ctx = 0;
  8125. ctx = wolfSSL_CTX_new(method);
  8126. if (ctx == NULL) {
  8127. // context creation failed
  8128. }
  8129. ret = wolfSSL_CTX_UseSNI(ctx, 0, "www.yassl.com", strlen("www.yassl.com"));
  8130. if (ret != 0) {
  8131. // sni usage failed
  8132. }
  8133. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  8134. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8135. \endcode
  8136. \sa wolfSSL_CTX_new
  8137. \sa wolfSSL_CTX_UseSNI
  8138. \sa wolfSSL_SNI_SetOptions
  8139. */
  8140. WOLFSSL_API void wolfSSL_CTX_SNI_SetOptions(WOLFSSL_CTX* ctx,
  8141. unsigned char type, unsigned char options);
  8142. /*!
  8143. \brief This function is called on the server side to retrieve the Server
  8144. Name Indication provided by the client from the Client Hello message sent
  8145. by the client to start a session. It does not requires context or session
  8146. setup to retrieve the SNI.
  8147. \return SSL_SUCCESS upon success.
  8148. \return BAD_FUNC_ARG is the error that will be returned in one of this
  8149. cases: buffer is NULL, bufferSz <= 0, sni is NULL, inOutSz is NULL or <= 0
  8150. \return BUFFER_ERROR is the error returned when there is a malformed
  8151. Client Hello message.
  8152. \return INCOMPLETE_DATA is the error returned when there is not enough
  8153. data to complete the extraction.
  8154. \param buffer pointer to the data provided by the client (Client Hello).
  8155. \param bufferSz size of the Client Hello message.
  8156. \param type indicates which type of server name is been retrieved
  8157. from the buffer. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8158. \param sni pointer to where the output is going to be stored.
  8159. \param inOutSz pointer to the output size, this value will be updated
  8160. to MIN("SNI's length", inOutSz).
  8161. _Example_
  8162. \code
  8163. unsigned char buffer[1024] = {0};
  8164. unsigned char result[32] = {0};
  8165. int length = 32;
  8166. // read Client Hello to buffer...
  8167. ret = wolfSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), 0, result, &length));
  8168. if (ret != SSL_SUCCESS) {
  8169. // sni retrieve failed
  8170. }
  8171. \endcode
  8172. \sa wolfSSL_UseSNI
  8173. \sa wolfSSL_CTX_UseSNI
  8174. \sa wolfSSL_SNI_GetRequest
  8175. */
  8176. WOLFSSL_API int wolfSSL_SNI_GetFromBuffer(
  8177. const unsigned char* clientHello, unsigned int helloSz,
  8178. unsigned char type, unsigned char* sni, unsigned int* inOutSz);
  8179. /*!
  8180. \ingroup IO
  8181. \brief This function gets the status of an SNI object.
  8182. \return value This function returns the byte value of the SNI struct’s
  8183. status member if the SNI is not NULL.
  8184. \return 0 if the SNI object is NULL.
  8185. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8186. \param type the SNI type.
  8187. _Example_
  8188. \code
  8189. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8190. WOLFSSL* ssl = wolfSSL_new(ctx);
  8191. #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
  8192. Byte type = WOLFSSL_SNI_HOST_NAME;
  8193. char* request = (char*)&type;
  8194. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  8195. \endcode
  8196. \sa TLSX_SNI_Status
  8197. \sa TLSX_SNI_find
  8198. \sa TLSX_Find
  8199. */
  8200. WOLFSSL_API unsigned char wolfSSL_SNI_Status(WOLFSSL* ssl, unsigned char type);
  8201. /*!
  8202. \brief This function is called on the server side to retrieve the
  8203. Server Name Indication provided by the client in a SSL session.
  8204. \return size the size of the provided SNI data.
  8205. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8206. \param type indicates which type of server name is been retrieved in
  8207. data. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8208. \param data pointer to the data provided by the client.
  8209. _Example_
  8210. \code
  8211. int ret = 0;
  8212. WOLFSSL_CTX* ctx = 0;
  8213. WOLFSSL* ssl = 0;
  8214. ctx = wolfSSL_CTX_new(method);
  8215. if (ctx == NULL) {
  8216. // context creation failed
  8217. }
  8218. ssl = wolfSSL_new(ctx);
  8219. if (ssl == NULL) {
  8220. // ssl creation failed
  8221. }
  8222. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8223. if (ret != 0) {
  8224. // sni usage failed
  8225. }
  8226. if (wolfSSL_accept(ssl) == SSL_SUCCESS) {
  8227. void *data = NULL;
  8228. unsigned short size = wolfSSL_SNI_GetRequest(ssl, 0, &data);
  8229. }
  8230. \endcode
  8231. \sa wolfSSL_UseSNI
  8232. \sa wolfSSL_CTX_UseSNI
  8233. */
  8234. WOLFSSL_API unsigned short wolfSSL_SNI_GetRequest(WOLFSSL *ssl,
  8235. unsigned char type, void** data);
  8236. /*!
  8237. \ingroup Setup
  8238. \brief Setup ALPN use for a wolfSSL session.
  8239. \return SSL_SUCCESS: upon success.
  8240. \return BAD_FUNC_ARG Returned if ssl or protocol_name_list
  8241. is null or protocol_name_listSz is too large or options
  8242. contain something not supported.
  8243. \return MEMORY_ERROR Error allocating memory for protocol list.
  8244. \return SSL_FAILURE upon failure.
  8245. \param ssl The wolfSSL session to use.
  8246. \param protocol_name_list List of protocol names to use.
  8247. Comma delimited string is required.
  8248. \param protocol_name_listSz Size of the list of protocol names.
  8249. \param options WOLFSSL_ALPN_CONTINUE_ON_MISMATCH or
  8250. WOLFSSL_ALPN_FAILED_ON_MISMATCH.
  8251. _Example_
  8252. \code
  8253. wolfSSL_Init();
  8254. WOLFSSL_CTX* ctx;
  8255. WOLFSSL* ssl;
  8256. WOLFSSL_METHOD method = // Some wolfSSL method
  8257. ctx = wolfSSL_CTX_new(method);
  8258. ssl = wolfSSL_new(ctx);
  8259. char alpn_list[] = {};
  8260. if(wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  8261. WOLFSSL_APN_FAILED_ON_MISMATCH) != SSL_SUCCESS)
  8262. {
  8263. // Error setting session ticket
  8264. }
  8265. \endcode
  8266. \sa TLSX_UseALPN
  8267. */
  8268. WOLFSSL_API int wolfSSL_UseALPN(WOLFSSL* ssl, char *protocol_name_list,
  8269. unsigned int protocol_name_listSz,
  8270. unsigned char options);
  8271. /*!
  8272. \ingroup TLS
  8273. \brief This function gets the protocol name set by the server.
  8274. \return SSL_SUCCESS returned on successful execution where no
  8275. errors were thrown.
  8276. \return SSL_FATAL_ERROR returned if the extension was not found or
  8277. if there was no protocol match with peer. There will also be an
  8278. error thrown if there is more than one protocol name accepted.
  8279. \return SSL_ALPN_NOT_FOUND returned signifying that no protocol
  8280. match with peer was found.
  8281. \return BAD_FUNC_ARG returned if there was a NULL argument passed
  8282. into the function.
  8283. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8284. \param protocol_name a pointer to a char that represents the protocol
  8285. name and will be held in the ALPN structure.
  8286. \param size a word16 type that represents the size of the protocol_name.
  8287. _Example_
  8288. \code
  8289. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  8290. WOLFSSL* ssl = WOLFSSL_new(ctx);
  8291. ...
  8292. int err;
  8293. char* protocol_name = NULL;
  8294. Word16 protocol_nameSz = 0;
  8295. err = wolfSSL_ALPN_GetProtocol(ssl, &protocol_name, &protocol_nameSz);
  8296. if(err == SSL_SUCCESS){
  8297. // Sent ALPN protocol
  8298. }
  8299. \endcode
  8300. \sa TLSX_ALPN_GetRequest
  8301. \sa TLSX_Find
  8302. */
  8303. WOLFSSL_API int wolfSSL_ALPN_GetProtocol(WOLFSSL* ssl, char **protocol_name,
  8304. unsigned short *size);
  8305. /*!
  8306. \ingroup TLS
  8307. \brief This function copies the alpn_client_list data from the SSL
  8308. object to the buffer.
  8309. \return SSL_SUCCESS returned if the function executed without error. The
  8310. alpn_client_list member of the SSL object has been copied to the
  8311. list parameter.
  8312. \return BAD_FUNC_ARG returned if the list or listSz parameter is NULL.
  8313. \return BUFFER_ERROR returned if there will be a problem with the
  8314. list buffer (either it’s NULL or the size is 0).
  8315. \return MEMORY_ERROR returned if there was a problem dynamically
  8316. allocating memory.
  8317. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8318. \param list a pointer to the buffer. The data from the SSL object will
  8319. be copied into it.
  8320. \param listSz the buffer size.
  8321. _Example_
  8322. \code
  8323. #import <wolfssl/ssl.h>
  8324. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method);
  8325. WOLFSSL* ssl = wolfSSL_new(ctx);
  8326. #ifdef HAVE_ALPN
  8327. char* list = NULL;
  8328. word16 listSz = 0;
  8329. err = wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz);
  8330. if(err == SSL_SUCCESS){
  8331. List of protocols names sent by client
  8332. }
  8333. \endcode
  8334. \sa wolfSSL_UseALPN
  8335. */
  8336. WOLFSSL_API int wolfSSL_ALPN_GetPeerProtocol(WOLFSSL* ssl, char **list,
  8337. unsigned short *listSz);
  8338. /*!
  8339. \brief This function is called on the client side to enable the use of
  8340. Maximum Fragment Length in the SSL object passed in the 'ssl' parameter.
  8341. It means that the Maximum Fragment Length extension will be sent on
  8342. ClientHello by wolfSSL clients.
  8343. \return SSL_SUCCESS upon success.
  8344. \return BAD_FUNC_ARG is the error that will be returned in one of
  8345. these cases: ssl is NULL, mfl is out of range.
  8346. \return MEMORY_E is the error returned when there is not enough memory.
  8347. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8348. \param mfl indicates witch is the Maximum Fragment Length requested for the
  8349. session. The available options are: enum { WOLFSSL_MFL_2_9 = 1, 512 bytes
  8350. WOLFSSL_MFL_2_10 = 2, 1024 bytes WOLFSSL_MFL_2_11 = 3, 2048 bytes
  8351. WOLFSSL_MFL_2_12 = 4, 4096 bytes WOLFSSL_MFL_2_13 = 5, 8192
  8352. bytes wolfSSL ONLY!!! };
  8353. _Example_
  8354. \code
  8355. int ret = 0;
  8356. WOLFSSL_CTX* ctx = 0;
  8357. WOLFSSL* ssl = 0;
  8358. ctx = wolfSSL_CTX_new(method);
  8359. if (ctx == NULL) {
  8360. // context creation failed
  8361. }
  8362. ssl = wolfSSL_new(ctx);
  8363. if (ssl == NULL) {
  8364. // ssl creation failed
  8365. }
  8366. ret = wolfSSL_UseMaxFragment(ssl, WOLFSSL_MFL_2_11);
  8367. if (ret != 0) {
  8368. // max fragment usage failed
  8369. }
  8370. \endcode
  8371. \sa wolfSSL_new
  8372. \sa wolfSSL_CTX_UseMaxFragment
  8373. */
  8374. WOLFSSL_API int wolfSSL_UseMaxFragment(WOLFSSL* ssl, unsigned char mfl);
  8375. /*!
  8376. \brief This function is called on the client side to enable the use
  8377. of Maximum Fragment Length for SSL objects created from the SSL context
  8378. passed in the 'ctx' parameter. It means that the Maximum Fragment Length
  8379. extension will be sent on ClientHello by wolfSSL clients.
  8380. \return SSL_SUCCESS upon success.
  8381. \return BAD_FUNC_ARG is the error that will be returned in one of
  8382. these cases: ctx is NULL, mfl is out of range.
  8383. \return MEMORY_E is the error returned when there is not enough memory.
  8384. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8385. \param mfl indicates which is the Maximum Fragment Length requested
  8386. for the session. The available options are:
  8387. enum { WOLFSSL_MFL_2_9 = 1 512 bytes, WOLFSSL_MFL_2_10 = 2 1024 bytes,
  8388. WOLFSSL_MFL_2_11 = 3 2048 bytes WOLFSSL_MFL_2_12 = 4 4096 bytes,
  8389. WOLFSSL_MFL_2_13 = 5 8192 bytes wolfSSL ONLY!!!,
  8390. WOLFSSL_MFL_2_13 = 6 256 bytes wolfSSL ONLY!!!
  8391. };
  8392. _Example_
  8393. \code
  8394. int ret = 0;
  8395. WOLFSSL_CTX* ctx = 0;
  8396. ctx = wolfSSL_CTX_new(method);
  8397. if (ctx == NULL) {
  8398. // context creation failed
  8399. }
  8400. ret = wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11);
  8401. if (ret != 0) {
  8402. // max fragment usage failed
  8403. }
  8404. \endcode
  8405. \sa wolfSSL_CTX_new
  8406. \sa wolfSSL_UseMaxFragment
  8407. */
  8408. WOLFSSL_API int wolfSSL_CTX_UseMaxFragment(WOLFSSL_CTX* ctx, unsigned char mfl);
  8409. /*!
  8410. \brief This function is called on the client side to enable the use of
  8411. Truncated HMAC in the SSL object passed in the 'ssl' parameter. It
  8412. means that the Truncated HMAC extension will be sent on ClientHello
  8413. by wolfSSL clients.
  8414. \return SSL_SUCCESS upon success.
  8415. \return BAD_FUNC_ARG is the error that will be returned in one of
  8416. these cases: ssl is NULL
  8417. \return MEMORY_E is the error returned when there is not enough memory.
  8418. \param ssl pointer to a SSL object, created with wolfSSL_new()
  8419. _Example_
  8420. \code
  8421. int ret = 0;
  8422. WOLFSSL_CTX* ctx = 0;
  8423. WOLFSSL* ssl = 0;
  8424. ctx = wolfSSL_CTX_new(method);
  8425. if (ctx == NULL) {
  8426. // context creation failed
  8427. }
  8428. ssl = wolfSSL_new(ctx);
  8429. if (ssl == NULL) {
  8430. // ssl creation failed
  8431. }
  8432. ret = wolfSSL_UseTruncatedHMAC(ssl);
  8433. if (ret != 0) {
  8434. // truncated HMAC usage failed
  8435. }
  8436. \endcode
  8437. \sa wolfSSL_new
  8438. \sa wolfSSL_CTX_UseMaxFragment
  8439. */
  8440. WOLFSSL_API int wolfSSL_UseTruncatedHMAC(WOLFSSL* ssl);
  8441. /*!
  8442. \brief This function is called on the client side to enable the use of
  8443. Truncated HMAC for SSL objects created from the SSL context passed in
  8444. the 'ctx' parameter. It means that the Truncated HMAC extension will
  8445. be sent on ClientHello by wolfSSL clients.
  8446. \return SSL_SUCCESS upon success.
  8447. \return BAD_FUNC_ARG is the error that will be returned in one of
  8448. these cases: ctx is NULL
  8449. \return MEMORY_E is the error returned when there is not enough memory.
  8450. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8451. _Example_
  8452. \code
  8453. int ret = 0;
  8454. WOLFSSL_CTX* ctx = 0;
  8455. ctx = wolfSSL_CTX_new(method);
  8456. if (ctx == NULL) {
  8457. // context creation failed
  8458. }
  8459. ret = wolfSSL_CTX_UseTruncatedHMAC(ctx);
  8460. if (ret != 0) {
  8461. // truncated HMAC usage failed
  8462. }
  8463. \endcode
  8464. \sa wolfSSL_CTX_new
  8465. \sa wolfSSL_UseMaxFragment
  8466. */
  8467. WOLFSSL_API int wolfSSL_CTX_UseTruncatedHMAC(WOLFSSL_CTX* ctx);
  8468. /*!
  8469. \brief Stapling eliminates the need to contact the CA. Stapling
  8470. lowers the cost of certificate revocation check presented in OCSP.
  8471. \return SSL_SUCCESS returned if TLSX_UseCertificateStatusRequest
  8472. executes without error.
  8473. \return MEMORY_E returned if there is an error with the allocation
  8474. of memory.
  8475. \return BAD_FUNC_ARG returned if there is an argument that has a
  8476. NULL or otherwise unacceptable value passed into the function.
  8477. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8478. \param status_type a byte type that is passed through to
  8479. TLSX_UseCertificateStatusRequest() and stored in the
  8480. CertificateStatusRequest structure.
  8481. \param options a byte type that is passed through to
  8482. TLSX_UseCertificateStatusRequest() and stored in the
  8483. CertificateStatusRequest structure.
  8484. _Example_
  8485. \code
  8486. WOLFSSL* ssl = wolfSSL_new(ctx);
  8487. if (wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  8488. WOLFSSL_CSR2_OCSP_USE_NONCE) != SSL_SUCCESS){
  8489. // Failed case.
  8490. }
  8491. \endcode
  8492. \sa TLSX_UseCertificateStatusRequest
  8493. \sa wolfSSL_CTX_UseOCSPStapling
  8494. */
  8495. WOLFSSL_API int wolfSSL_UseOCSPStapling(WOLFSSL* ssl,
  8496. unsigned char status_type, unsigned char options);
  8497. /*!
  8498. \brief This function requests the certificate status during the handshake.
  8499. \return SSL_SUCCESS returned if the function and subroutines execute
  8500. without error.
  8501. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  8502. otherwise if a unpermitted value is passed to a subroutine.
  8503. \return MEMORY_E returned if the function or subroutine failed to properly
  8504. allocate memory.
  8505. \param ctx a pointer to a WOLFSSL_CTX structure,
  8506. created using wolfSSL_CTX_new().
  8507. \param status_type a byte type that is passed through to
  8508. TLSX_UseCertificateStatusRequest() and stored in the
  8509. CertificateStatusRequest structure.
  8510. \param options a byte type that is passed through to
  8511. TLSX_UseCertificateStatusRequest() and stored in the
  8512. CertificateStatusRequest structure.
  8513. _Example_
  8514. \code
  8515. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8516. WOLFSSL* ssl = wolfSSL_new(ctx);
  8517. byte statusRequest = 0; // Initialize status request
  8518. switch(statusRequest){
  8519. case WOLFSSL_CSR_OCSP:
  8520. if(wolfSSL_CTX_UseOCSPStapling(ssl->ctx, WOLFSSL_CSR_OCSP,
  8521. WOLF_CSR_OCSP_USE_NONCE) != SSL_SUCCESS){
  8522. // UseCertificateStatusRequest failed
  8523. }
  8524. // Continue switch cases
  8525. \endcode
  8526. \sa wolfSSL_UseOCSPStaplingV2
  8527. \sa wolfSSL_UseOCSPStapling
  8528. \sa TLSX_UseCertificateStatusRequest
  8529. */
  8530. WOLFSSL_API int wolfSSL_CTX_UseOCSPStapling(WOLFSSL_CTX* ctx,
  8531. unsigned char status_type, unsigned char options);
  8532. /*!
  8533. \brief The function sets the status type and options for OCSP.
  8534. \return SSL_SUCCESS - returned if the function and subroutines
  8535. executed without error.
  8536. \return MEMORY_E - returned if there was an allocation of memory error.
  8537. \return BAD_FUNC_ARG - returned if a NULL or otherwise unaccepted
  8538. argument was passed to the function or a subroutine.
  8539. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8540. \param status_type a byte type that loads the OCSP status type.
  8541. \param options a byte type that holds the OCSP options, set in
  8542. wolfSSL_SNI_SetOptions() and wolfSSL_CTX_SNI_SetOptions().
  8543. _Example_
  8544. \code
  8545. WOLFSSL* ssl = wolfSSL_new(ctx);
  8546. ...
  8547. if (wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP_MULTI, 0) != SSL_SUCCESS){
  8548. // Did not execute properly. Failure case code block.
  8549. }
  8550. \endcode
  8551. \sa TLSX_UseCertificatStatusRequestV2
  8552. \sa wolfSSL_SNI_SetOptions
  8553. \sa wolfSSL_CTX_SNI_SetOptions
  8554. */
  8555. WOLFSSL_API int wolfSSL_UseOCSPStaplingV2(WOLFSSL* ssl,
  8556. unsigned char status_type, unsigned char options);
  8557. /*!
  8558. \brief Creates and initializes the certificate status request
  8559. for OCSP Stapling.
  8560. \return SSL_SUCCESS if the function and subroutines executed without error.
  8561. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or if
  8562. the side variable is not client side.
  8563. \return MEMORY_E returned if the allocation of memory failed.
  8564. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8565. wolfSSL_CTX_new().
  8566. \param status_type a byte type that is located in the
  8567. CertificatStatusRequest structure and must be either WOLFSSL_CSR2_OCSP
  8568. or WOLFSSL_CSR2_OCSP_MULTI.
  8569. \param options a byte type that will be held in
  8570. CertificateStatusRequestItemV2 struct.
  8571. _Example_
  8572. \code
  8573. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8574. byte status_type;
  8575. byte options;
  8576. ...
  8577. if(wolfSSL_CTX_UseOCSPStaplingV2(ctx, status_type, options); != SSL_SUCCESS){
  8578. // Failure case.
  8579. }
  8580. \endcode
  8581. \sa TLSX_UseCertificateStatusRequestV2
  8582. \sa wc_RNG_GenerateBlock
  8583. \sa TLSX_Push
  8584. */
  8585. WOLFSSL_API int wolfSSL_CTX_UseOCSPStaplingV2(WOLFSSL_CTX* ctx,
  8586. unsigned char status_type, unsigned char options);
  8587. /*!
  8588. \brief This function is called on the client side to enable the use of
  8589. Supported Elliptic Curves Extension in the SSL object passed in the 'ssl'
  8590. parameter. It means that the supported curves enabled will be sent on
  8591. ClientHello by wolfSSL clients. This function can be called more than
  8592. one time to enable multiple curves.
  8593. \return SSL_SUCCESS upon success.
  8594. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8595. cases: ssl is NULL, name is a unknown value. (see below)
  8596. \return MEMORY_E is the error returned when there is not enough memory.
  8597. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8598. \param name indicates which curve will be supported for the session. The
  8599. available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  8600. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  8601. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  8602. WOLFSSL_ECC_SECP521R1 = 0x19 };
  8603. _Example_
  8604. \code
  8605. int ret = 0;
  8606. WOLFSSL_CTX* ctx = 0;
  8607. WOLFSSL* ssl = 0;
  8608. ctx = wolfSSL_CTX_new(method);
  8609. if (ctx == NULL) {
  8610. // context creation failed
  8611. }
  8612. ssl = wolfSSL_new(ctx);
  8613. if (ssl == NULL) {
  8614. // ssl creation failed
  8615. }
  8616. ret = wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1);
  8617. if (ret != 0) {
  8618. // Elliptic Curve Extension usage failed
  8619. }
  8620. \endcode
  8621. \sa wolfSSL_CTX_new
  8622. \sa wolfSSL_CTX_UseSupportedCurve
  8623. */
  8624. WOLFSSL_API int wolfSSL_UseSupportedCurve(WOLFSSL* ssl, word16 name);
  8625. /*!
  8626. \brief This function is called on the client side to enable the use of
  8627. Supported Elliptic Curves Extension for SSL objects created from the SSL
  8628. context passed in the 'ctx' parameter. It means that the supported curves
  8629. enabled will be sent on ClientHello by wolfSSL clients. This function can
  8630. be called more than one time to enable multiple curves.
  8631. \return SSL_SUCCESS upon success.
  8632. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8633. cases: ctx is NULL, name is a unknown value. (see below)
  8634. \return MEMORY_E is the error returned when there is not enough memory.
  8635. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8636. \param name indicates which curve will be supported for the session.
  8637. The available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  8638. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  8639. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  8640. WOLFSSL_ECC_SECP521R1 = 0x19 };
  8641. _Example_
  8642. \code
  8643. int ret = 0;
  8644. WOLFSSL_CTX* ctx = 0;
  8645. ctx = wolfSSL_CTX_new(method);
  8646. if (ctx == NULL) {
  8647. // context creation failed
  8648. }
  8649. ret = wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1);
  8650. if (ret != 0) {
  8651. // Elliptic Curve Extension usage failed
  8652. }
  8653. \endcode
  8654. \sa wolfSSL_CTX_new
  8655. \sa wolfSSL_UseSupportedCurve
  8656. */
  8657. WOLFSSL_API int wolfSSL_CTX_UseSupportedCurve(WOLFSSL_CTX* ctx,
  8658. word16 name);
  8659. /*!
  8660. \ingroup IO
  8661. \brief This function forces secure renegotiation for the supplied
  8662. WOLFSSL structure. This is not recommended.
  8663. \return SSL_SUCCESS Successfully set secure renegotiation.
  8664. \return BAD_FUNC_ARG Returns error if ssl is null.
  8665. \return MEMORY_E Returns error if unable to allocate memory for secure
  8666. renegotiation.
  8667. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8668. _Example_
  8669. \code
  8670. wolfSSL_Init();
  8671. WOLFSSL_CTX* ctx;
  8672. WOLFSSL* ssl;
  8673. WOLFSSL_METHOD method = // Some wolfSSL method
  8674. ctx = wolfSSL_CTX_new(method);
  8675. ssl = wolfSSL_new(ctx);
  8676. if(wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS)
  8677. {
  8678. // Error setting secure renegotiation
  8679. }
  8680. \endcode
  8681. \sa TLSX_Find
  8682. \sa TLSX_UseSecureRenegotiation
  8683. */
  8684. WOLFSSL_API int wolfSSL_UseSecureRenegotiation(WOLFSSL* ssl);
  8685. /*!
  8686. \ingroup IO
  8687. \brief This function executes a secure renegotiation handshake; this is user
  8688. forced as wolfSSL discourages this functionality.
  8689. \return SSL_SUCCESS returned if the function executed without error.
  8690. \return BAD_FUNC_ARG returned if the WOLFSSL structure was NULL or otherwise
  8691. if an unacceptable argument was passed in a subroutine.
  8692. \return SECURE_RENEGOTIATION_E returned if there was an error with
  8693. renegotiating the handshake.
  8694. \return SSL_FATAL_ERROR returned if there was an error with the
  8695. server or client configuration and the renegotiation could
  8696. not be completed. See wolfSSL_negotiate().
  8697. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8698. _Example_
  8699. \code
  8700. WOLFSSL* ssl = wolfSSL_new(ctx);
  8701. ...
  8702. if(wolfSSL_Rehandshake(ssl) != SSL_SUCCESS){
  8703. // There was an error and the rehandshake is not successful.
  8704. }
  8705. \endcode
  8706. \sa wolfSSL_negotiate
  8707. \sa wc_InitSha512
  8708. \sa wc_InitSha384
  8709. \sa wc_InitSha256
  8710. \sa wc_InitSha
  8711. \sa wc_InitMd5
  8712. */
  8713. WOLFSSL_API int wolfSSL_Rehandshake(WOLFSSL* ssl);
  8714. /*!
  8715. \ingroup IO
  8716. \brief Force provided WOLFSSL structure to use session ticket. The
  8717. constant HAVE_SESSION_TICKET should be defined and the constant
  8718. NO_WOLFSSL_CLIENT should not be defined to use this function.
  8719. \return SSL_SUCCESS Successfully set use session ticket.
  8720. \return BAD_FUNC_ARG Returned if ssl is null.
  8721. \return MEMORY_E Error allocating memory for setting session ticket.
  8722. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8723. _Example_
  8724. \code
  8725. wolfSSL_Init();
  8726. WOLFSSL_CTX* ctx;
  8727. WOLFSSL* ssl;
  8728. WOLFSSL_METHOD method = // Some wolfSSL method
  8729. ctx = wolfSSL_CTX_new(method);
  8730. ssl = wolfSSL_new(ctx);
  8731. if(wolfSSL_UseSessionTicket(ssl) != SSL_SUCCESS)
  8732. {
  8733. // Error setting session ticket
  8734. }
  8735. \endcode
  8736. \sa TLSX_UseSessionTicket
  8737. */
  8738. WOLFSSL_API int wolfSSL_UseSessionTicket(WOLFSSL* ssl);
  8739. /*!
  8740. \ingroup Setup
  8741. \brief This function sets wolfSSL context to use a session ticket.
  8742. \return SSL_SUCCESS Function executed successfully.
  8743. \return BAD_FUNC_ARG Returned if ctx is null.
  8744. \return MEMORY_E Error allocating memory in internal function.
  8745. \param ctx The WOLFSSL_CTX structure to use.
  8746. _Example_
  8747. \code
  8748. wolfSSL_Init();
  8749. WOLFSSL_CTX* ctx;
  8750. WOLFSSL_METHOD method = // Some wolfSSL method ;
  8751. ctx = wolfSSL_CTX_new(method);
  8752. if(wolfSSL_CTX_UseSessionTicket(ctx) != SSL_SUCCESS)
  8753. {
  8754. // Error setting session ticket
  8755. }
  8756. \endcode
  8757. \sa TLSX_UseSessionTicket
  8758. */
  8759. WOLFSSL_API int wolfSSL_CTX_UseSessionTicket(WOLFSSL_CTX* ctx);
  8760. /*!
  8761. \ingroup IO
  8762. \brief This function copies the ticket member of the Session structure to
  8763. the buffer.
  8764. \return SSL_SUCCESS returned if the function executed without error.
  8765. \return BAD_FUNC_ARG returned if one of the arguments was NULL or if the
  8766. bufSz argument was 0.
  8767. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8768. \param buf a byte pointer representing the memory buffer.
  8769. \param bufSz a word32 pointer representing the buffer size.
  8770. _Example_
  8771. \code
  8772. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8773. WOLFSSL* ssl = wolfSSL_new(ctx);
  8774. byte* buf;
  8775. word32 bufSz; // Initialize with buf size
  8776. if(wolfSSL_get_SessionTicket(ssl, buf, bufSz) <= 0){
  8777. // Nothing was written to the buffer
  8778. } else {
  8779. // the buffer holds the content from ssl->session.ticket
  8780. }
  8781. \endcode
  8782. \sa wolfSSL_UseSessionTicket
  8783. \sa wolfSSL_set_SessionTicket
  8784. */
  8785. WOLFSSL_API int wolfSSL_get_SessionTicket(WOLFSSL*, unsigned char*, word32*);
  8786. /*!
  8787. \ingroup IO
  8788. \brief This function sets the ticket member of the WOLFSSL_SESSION
  8789. structure within the WOLFSSL struct. The buffer passed into the function
  8790. is copied to memory.
  8791. \return SSL_SUCCESS returned on successful execution of the function.
  8792. The function returned without errors.
  8793. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL. This will
  8794. also be thrown if the buf argument is NULL but the bufSz argument
  8795. is not zero.
  8796. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8797. \param buf a byte pointer that gets loaded into the ticket member
  8798. of the session structure.
  8799. \param bufSz a word32 type that represents the size of the buffer.
  8800. _Example_
  8801. \code
  8802. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8803. WOLFSSL* ssl = wolfSSL_new(ctx);
  8804. byte* buffer; // File to load
  8805. word32 bufSz;
  8806. ...
  8807. if(wolfSSL_KeepArrays(ssl, buffer, bufSz) != SSL_SUCCESS){
  8808. // There was an error loading the buffer to memory.
  8809. }
  8810. \endcode
  8811. \sa wolfSSL_set_SessionTicket_cb
  8812. */
  8813. WOLFSSL_API int wolfSSL_set_SessionTicket(WOLFSSL*, const unsigned char*, word32);
  8814. /*!
  8815. \brief This function sets the session ticket callback. The type
  8816. CallbackSessionTicket is a function pointer with the signature of:
  8817. int (*CallbackSessionTicket)(WOLFSSL*, const unsigned char*, int, void*)
  8818. \return SSL_SUCCESS returned if the function executed without error.
  8819. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  8820. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8821. \param cb a function pointer to the type CallbackSessionTicket.
  8822. \param ctx a void pointer to the session_ticket_ctx member of the
  8823. WOLFSSL structure.
  8824. _Example_
  8825. \code
  8826. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8827. WOLFSSL* ssl = wolfSSL_new(ctx);
  8828. int sessionTicketCB(WOLFSSL* ssl, const unsigned char* ticket, int ticketSz,
  8829. void* ctx){ … }
  8830. wolfSSL_set_SessionTicket_cb(ssl, sessionTicketCB, (void*)”initial session”);
  8831. \endcode
  8832. \sa wolfSSL_set_SessionTicket
  8833. \sa CallbackSessionTicket
  8834. \sa sessionTicketCB
  8835. */
  8836. WOLFSSL_API int wolfSSL_set_SessionTicket_cb(WOLFSSL*,
  8837. CallbackSessionTicket, void*);
  8838. /*!
  8839. \brief This function sets the session ticket key encrypt callback function
  8840. for a server to support session tickets as specified in RFC 5077.
  8841. \return SSL_SUCCESS will be returned upon successfully setting the session.
  8842. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  8843. invalid arguments to the function.
  8844. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  8845. \param cb user callback function to encrypt/decrypt session tickets
  8846. \param ssl(Callback) pointer to the WOLFSSL object, created with
  8847. wolfSSL_new()
  8848. \param key_name(Callback) unique key name for this ticket context, should
  8849. be randomly generated
  8850. \param iv(Callback) unique IV for this ticket, up to 128 bits, should
  8851. be randomly generated
  8852. \param mac(Callback) up to 256 bit mac for this ticket
  8853. \param enc(Callback) if this encrypt parameter is true the user should fill
  8854. in key_name, iv, mac, and encrypt the ticket in-place of length inLen and
  8855. set the resulting output length in *outLen. Returning WOLFSSL_TICKET_RET_OK
  8856. tells wolfSSL that the encryption was successful. If this encrypt parameter
  8857. is false, the user should perform a decrypt of the ticket in-place of length
  8858. inLen using key_name, iv, and mac. The resulting decrypt length should be
  8859. set in *outLen. Returning WOLFSSL_TICKET_RET_OK tells wolfSSL to proceed
  8860. using the decrypted ticket. Returning WOLFSSL_TICKET_RET_CREATE tells
  8861. wolfSSL to use the decrypted ticket but also to generate a new one to
  8862. send to the client, helpful if recently rolled keys and don’t want to
  8863. force a full handshake. Returning WOLFSSL_TICKET_RET_REJECT tells
  8864. wolfSSL to reject this ticket, perform a full handshake, and create
  8865. a new standard session ID for normal session resumption. Returning
  8866. WOLFSSL_TICKET_RET_FATAL tells wolfSSL to end the connection
  8867. attempt with a fatal error.
  8868. \param ticket(Callback) the input/output buffer for the encrypted ticket.
  8869. See the enc parameter
  8870. \param inLen(Callback) the input length of the ticket parameter
  8871. \param outLen(Callback) the resulting output length of the ticket parameter.
  8872. When entering the callback outLen will indicate the maximum size available
  8873. in the ticket buffer.
  8874. \param userCtx(Callback) the user context set with
  8875. wolfSSL_CTX_set_TicketEncCtx()
  8876. _Example_
  8877. \code
  8878. See wolfssl/test.h myTicketEncCb() used by the example
  8879. server and example echoserver.
  8880. \endcode
  8881. \sa wolfSSL_CTX_set_TicketHint
  8882. \sa wolfSSL_CTX_set_TicketEncCtx
  8883. */
  8884. WOLFSSL_API int wolfSSL_CTX_set_TicketEncCb(WOLFSSL_CTX* ctx,
  8885. SessionTicketEncCb);
  8886. /*!
  8887. \brief This function sets the session ticket hint relayed to the client.
  8888. For server side use.
  8889. \return SSL_SUCCESS will be returned upon successfully setting the session.
  8890. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  8891. invalid arguments to the function.
  8892. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  8893. \param hint number of seconds the ticket might be valid for. Hint to client.
  8894. _Example_
  8895. \code
  8896. none
  8897. \endcode
  8898. \sa wolfSSL_CTX_set_TicketEncCb
  8899. */
  8900. WOLFSSL_API int wolfSSL_CTX_set_TicketHint(WOLFSSL_CTX* ctx, int);
  8901. /*!
  8902. \brief This function sets the session ticket encrypt user context for the
  8903. callback. For server side use.
  8904. \return SSL_SUCCESS will be returned upon successfully setting the session.
  8905. \return BAD_FUNC_ARG will be returned on failure. This is caused by
  8906. passing invalid arguments to the function.
  8907. \param ctx pointer to the WOLFSSL_CTX object, created
  8908. with wolfSSL_CTX_new().
  8909. \param userCtx the user context for the callback
  8910. _Example_
  8911. \code
  8912. none
  8913. \endcode
  8914. \sa wolfSSL_CTX_set_TicketEncCb
  8915. */
  8916. WOLFSSL_API int wolfSSL_CTX_set_TicketEncCtx(WOLFSSL_CTX* ctx, void*);
  8917. /*!
  8918. \ingroup IO
  8919. \brief Checks if QSH is used in the supplied SSL session.
  8920. \return 0 Not used
  8921. \return 1 Is used
  8922. \param ssl Pointer to the SSL session to check.
  8923. _Example_
  8924. \code
  8925. wolfSSL_Init();
  8926. WOLFSSL_CTX* ctx;
  8927. WOLFSSL* ssl;
  8928. WOLFSSL_METHOD method = // Some wolfSSL method
  8929. ctx = wolfSSL_CTX_new(method);
  8930. ssl = wolfSSL_new(ctx);
  8931. if(wolfSSL_isQSH(ssl) == 1)
  8932. {
  8933. // SSL is using QSH.
  8934. }
  8935. \endcode
  8936. \sa wolfSSL_UseSupportedQSH
  8937. */
  8938. WOLFSSL_API int wolfSSL_isQSH(WOLFSSL* ssl);
  8939. /*!
  8940. \ingroup Setup
  8941. \brief This function sets the ssl session to use supported QSH provided by
  8942. name.
  8943. \return SSL_SUCCESS Successfully set supported QSH.
  8944. \return BAD_FUNC_ARG ssl is null or name is invalid.
  8945. \return MEMORY_E Error allocating memory for operation.
  8946. \param ssl Pointer to ssl session to use.
  8947. \param name Name of a supported QSH. Valid names are WOLFSSL_NTRU_EESS439,
  8948. WOLFSSL_NTRU_EESS593, or WOLFSSL_NTRU_EESS743.
  8949. _Example_
  8950. \code
  8951. wolfSSL_Init();
  8952. WOLFSSL_CTX* ctx;
  8953. WOLFSSL* ssl;
  8954. WOLFSSL_METHOD method = // Some wolfSSL method ;
  8955. ctx = wolfSSL_CTX_new(method);
  8956. ssl = wolfSSL_new(ctx);
  8957. word16 qsh_name = WOLFSSL_NTRU_EESS439;
  8958. if(wolfSSL_UseSupportedQSH(ssl,qsh_name) != SSL_SUCCESS)
  8959. {
  8960. // Error setting QSH
  8961. }
  8962. \endcode
  8963. \sa TLSX_UseQSHScheme
  8964. */
  8965. WOLFSSL_API int wolfSSL_UseSupportedQSH(WOLFSSL* ssl, unsigned short name);
  8966. /*!
  8967. \ingroup CertsKeys
  8968. \brief If the flag is 1 keys will be sent in hello. If flag is 0 then the
  8969. keys will not be sent during hello.
  8970. \return 0 on success.
  8971. \return BAD_FUNC_ARG if the WOLFSSL structure is NULL.
  8972. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8973. \param flag an unsigned char input to determine if the keys will be sent
  8974. during hello.
  8975. _Example_
  8976. \code
  8977. WOLFSSL* ssl;
  8978. unsigned char flag = 1; // send keys
  8979. ...
  8980. if(!wolfSSL_UseClientQSHKeys(ssl, flag)){
  8981. // The keys will be sent during hello.
  8982. }
  8983. \endcode
  8984. \sa wolfSSL_UseALPN
  8985. \sa wolfSSL_UseSupportedQSH
  8986. \sa wolfSSL_isQSH
  8987. */
  8988. WOLFSSL_API int wolfSSL_UseClientQSHKeys(WOLFSSL* ssl, unsigned char flag);
  8989. /*!
  8990. \brief This function sets the handshake done callback. The hsDoneCb and
  8991. hsDoneCtx members of the WOLFSSL structure are set in this function.
  8992. \return SSL_SUCCESS returned if the function executed without an error.
  8993. The hsDoneCb and hsDoneCtx members of the WOLFSSL struct are set.
  8994. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL.
  8995. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8996. \param cb a function pointer of type HandShakeDoneCb with the signature of
  8997. the form: int (*HandShakeDoneCb)(WOLFSSL*, void*);
  8998. \param user_ctx a void pointer to the user registered context.
  8999. _Example_
  9000. \code
  9001. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9002. WOLFSSL* ssl = wolfSSL_new(ctx);
  9003. int myHsDoneCb(WOLFSSL* ssl, void* user_ctx){
  9004. // callback function
  9005. }
  9006. wolfSSL_SetHsDoneCb(ssl, myHsDoneCb, NULL);
  9007. \endcode
  9008. \sa HandShakeDoneCb
  9009. */
  9010. WOLFSSL_API int wolfSSL_SetHsDoneCb(WOLFSSL*, HandShakeDoneCb, void*);
  9011. /*!
  9012. \ingroup IO
  9013. \brief This function prints the statistics from the session.
  9014. \return SSL_SUCCESS returned if the function and subroutines return without
  9015. error. The session stats have been successfully retrieved and printed.
  9016. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9017. was passed an unacceptable argument.
  9018. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9019. \param none No parameters.
  9020. _Example_
  9021. \code
  9022. // You will need to have a session object to retrieve stats from.
  9023. if(wolfSSL_PrintSessionStats(void) != SSL_SUCCESS ){
  9024. // Did not print session stats
  9025. }
  9026. \endcode
  9027. \sa wolfSSL_get_session_stats
  9028. */
  9029. WOLFSSL_API int wolfSSL_PrintSessionStats(void);
  9030. /*!
  9031. \ingroup IO
  9032. \brief This function gets the statistics for the session.
  9033. \return SSL_SUCCESS returned if the function and subroutines return without
  9034. error. The session stats have been successfully retrieved and printed.
  9035. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9036. was passed an unacceptable argument.
  9037. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9038. \param active a word32 pointer representing the total current sessions.
  9039. \param total a word32 pointer representing the total sessions.
  9040. \param peak a word32 pointer representing the peak sessions.
  9041. \param maxSessions a word32 pointer representing the maximum sessions.
  9042. _Example_
  9043. \code
  9044. int wolfSSL_PrintSessionStats(void){
  9045. ret = wolfSSL_get_session_stats(&totalSessionsNow,
  9046. &totalSessionsSeen, &peak, &maxSessions);
  9047. return ret;
  9048. \endcode
  9049. \sa get_locked_session_stats
  9050. \sa wolfSSL_PrintSessionStats
  9051. */
  9052. WOLFSSL_API int wolfSSL_get_session_stats(unsigned int* active,
  9053. unsigned int* total,
  9054. unsigned int* peak,
  9055. unsigned int* maxSessions);
  9056. /*!
  9057. \ingroup TLS
  9058. \brief This function copies the values of cr and sr then passes through to
  9059. wc_PRF (pseudo random function) and returns that value.
  9060. \return 0 on success
  9061. \return BUFFER_E returned if there will be an error
  9062. with the size of the buffer.
  9063. \return MEMORY_E returned if a subroutine failed
  9064. to allocate dynamic memory.
  9065. \param ms the master secret held in the Arrays structure.
  9066. \param msLen the length of the master secret.
  9067. \param pms the pre-master secret held in the Arrays structure.
  9068. \param pmsLen the length of the pre-master secret.
  9069. \param cr the client random.
  9070. \param sr the server random.
  9071. \param tls1_2 signifies that the version is at least tls version 1.2.
  9072. \param hash_type signifies the hash type.
  9073. _Example_
  9074. \code
  9075. WOLFSSL* ssl;
  9076. called in MakeTlsMasterSecret and retrieves the necessary
  9077. information as follows:
  9078. int MakeTlsMasterSecret(WOLFSSL* ssl){
  9079. int ret;
  9080. ret = wolfSSL_makeTlsMasterSecret(ssl->arrays->masterSecret, SECRET_LEN,
  9081. ssl->arrays->preMasterSecret, ssl->arrays->preMasterSz,
  9082. ssl->arrays->clientRandom, ssl->arrays->serverRandom,
  9083. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9084. return ret;
  9085. }
  9086. \endcode
  9087. \sa wc_PRF
  9088. \sa MakeTlsMasterSecret
  9089. */
  9090. WOLFSSL_API
  9091. int wolfSSL_MakeTlsMasterSecret(unsigned char* ms, word32 msLen,
  9092. const unsigned char* pms, word32 pmsLen,
  9093. const unsigned char* cr, const unsigned char* sr,
  9094. int tls1_2, int hash_type);
  9095. /*!
  9096. \ingroup CertsKeys
  9097. \brief An external facing wrapper to derive TLS Keys.
  9098. \return 0 returned on success.
  9099. \return BUFFER_E returned if the sum of labLen and
  9100. seedLen (computes total size) exceeds the maximum size.
  9101. \return MEMORY_E returned if the allocation of memory failed.
  9102. \param key_data a byte pointer that is allocateded in DeriveTlsKeys
  9103. and passed through to wc_PRF to hold the final hash.
  9104. \param keyLen a word32 type that is derived in DeriveTlsKeys
  9105. from the WOLFSSL structure’s specs member.
  9106. \param ms a constant pointer type holding the master secret
  9107. held in the arrays structure within the WOLFSSL structure.
  9108. \param msLen a word32 type that holds the length of the
  9109. master secret in an enumerated define, SECRET_LEN.
  9110. \param sr a constant byte pointer to the serverRandom
  9111. member of the arrays structure within the WOLFSSL structure.
  9112. \param cr a constant byte pointer to the clientRandom
  9113. member of the arrays structure within the WOLFSSL structure.
  9114. \param tls1_2 an integer type returned from IsAtLeastTLSv1_2().
  9115. \param hash_type an integer type held in the WOLFSSL structure.
  9116. _Example_
  9117. \code
  9118. int DeriveTlsKeys(WOLFSSL* ssl){
  9119. int ret;
  9120. ret = wolfSSL_DeriveTlsKeys(key_data, length, ssl->arrays->masterSecret,
  9121. SECRET_LEN, ssl->arrays->clientRandom,
  9122. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9123. }
  9124. \endcode
  9125. \sa wc_PRF
  9126. \sa DeriveTlsKeys
  9127. \sa IsAtLeastTLSv1_2
  9128. */
  9129. WOLFSSL_API
  9130. int wolfSSL_DeriveTlsKeys(unsigned char* key_data, word32 keyLen,
  9131. const unsigned char* ms, word32 msLen,
  9132. const unsigned char* sr, const unsigned char* cr,
  9133. int tls1_2, int hash_type);
  9134. /*!
  9135. \brief wolfSSL_connect_ex() is an extension that allows
  9136. a HandShake Callback to be set. This can be useful in
  9137. embedded systems for debugging support when a debugger isn’t
  9138. available and sniffing is impractical. The HandShake Callback
  9139. will be called whether or not a handshake error occurred.
  9140. No dynamic memory is used since the maximum number of SSL
  9141. packets is known. Packet names can be accessed through packetNames[].
  9142. The connect extension also allows a Timeout Callback to be set along
  9143. with a timeout value. This is useful if the user doesn’t want
  9144. to wait for the TCP stack to timeout. This extension can be called
  9145. with either, both, or neither callbacks.
  9146. \return SSL_SUCCESS upon success.
  9147. \return GETTIME_ERROR will be returned if gettimeofday()
  9148. encountered an error.
  9149. \return SETITIMER_ERROR will be returned if setitimer()
  9150. encountered an error.
  9151. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9152. \return SSL_FATAL_ERROR will be returned if the underlying SSL_connect()
  9153. call encountered an error.
  9154. \param none No parameters.
  9155. _Example_
  9156. \code
  9157. none
  9158. \endcode
  9159. \sa wolfSSL_accept_ex
  9160. */
  9161. WOLFSSL_API int wolfSSL_connect_ex(WOLFSSL*, HandShakeCallBack, TimeoutCallBack,
  9162. WOLFSSL_TIMEVAL);
  9163. /*!
  9164. \brief wolfSSL_accept_ex() is an extension that allows a HandShake Callback
  9165. to be set. This can be useful in embedded systems for debugging support
  9166. when a debugger isn’t available and sniffing is impractical. The HandShake
  9167. Callback will be called whether or not a handshake error occurred.
  9168. No dynamic memory is used since the maximum number of SSL packets is known.
  9169. Packet names can be accessed through packetNames[]. The connect extension
  9170. also allows a Timeout Callback to be set along with a timeout value.
  9171. This is useful if the user doesn’t want to wait for the TCP stack to timeout.
  9172. This extension can be called with either, both, or neither callbacks.
  9173. \return SSL_SUCCESS upon success.
  9174. \return GETTIME_ERROR will be returned if gettimeofday()
  9175. encountered an error.
  9176. \return SETITIMER_ERROR will be returned if setitimer()
  9177. encountered an error.
  9178. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9179. \return SSL_FATAL_ERROR will be returned if the underlying
  9180. SSL_accept() call encountered an error.
  9181. \param none No parameters.
  9182. _Example_
  9183. \code
  9184. none
  9185. \endcode
  9186. \sa wolfSSL_connect_ex
  9187. */
  9188. WOLFSSL_API int wolfSSL_accept_ex(WOLFSSL*, HandShakeCallBack, TimeoutCallBack,
  9189. WOLFSSL_TIMEVAL);
  9190. /*!
  9191. \ingroup IO
  9192. \brief This is used to set the internal file pointer for a BIO.
  9193. \return SSL_SUCCESS On successfully setting file pointer.
  9194. \return SSL_FAILURE If an error case was encountered.
  9195. \param bio WOLFSSL_BIO structure to set pair.
  9196. \param fp file pointer to set in bio.
  9197. \param c close file behavior flag.
  9198. _Example_
  9199. \code
  9200. WOLFSSL_BIO* bio;
  9201. XFILE fp;
  9202. int ret;
  9203. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9204. ret = wolfSSL_BIO_set_fp(bio, fp, BIO_CLOSE);
  9205. // check ret value
  9206. \endcode
  9207. \sa wolfSSL_BIO_new
  9208. \sa wolfSSL_BIO_s_mem
  9209. \sa wolfSSL_BIO_get_fp
  9210. \sa wolfSSL_BIO_free
  9211. */
  9212. WOLFSSL_API long wolfSSL_BIO_set_fp(WOLFSSL_BIO *bio, XFILE fp, int c);
  9213. /*!
  9214. \ingroup IO
  9215. \brief This is used to get the internal file pointer for a BIO.
  9216. \return SSL_SUCCESS On successfully getting file pointer.
  9217. \return SSL_FAILURE If an error case was encountered.
  9218. \param bio WOLFSSL_BIO structure to set pair.
  9219. \param fp file pointer to set in bio.
  9220. _Example_
  9221. \code
  9222. WOLFSSL_BIO* bio;
  9223. XFILE fp;
  9224. int ret;
  9225. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9226. ret = wolfSSL_BIO_get_fp(bio, &fp);
  9227. // check ret value
  9228. \endcode
  9229. \sa wolfSSL_BIO_new
  9230. \sa wolfSSL_BIO_s_mem
  9231. \sa wolfSSL_BIO_set_fp
  9232. \sa wolfSSL_BIO_free
  9233. */
  9234. WOLFSSL_API long wolfSSL_BIO_get_fp(WOLFSSL_BIO *bio, XFILE* fp);
  9235. /*!
  9236. \ingroup Setup
  9237. \brief This function checks that the private key is a match
  9238. with the certificate being used.
  9239. \return SSL_SUCCESS On successfully match.
  9240. \return SSL_FAILURE If an error case was encountered.
  9241. \return <0 All error cases other than SSL_FAILURE are negative values.
  9242. \param ssl WOLFSSL structure to check.
  9243. _Example_
  9244. \code
  9245. WOLFSSL* ssl;
  9246. int ret;
  9247. // create and set up ssl
  9248. ret = wolfSSL_check_private_key(ssl);
  9249. // check ret value
  9250. \endcode
  9251. \sa wolfSSL_new
  9252. \sa wolfSSL_free
  9253. */
  9254. WOLFSSL_API int wolfSSL_check_private_key(const WOLFSSL* ssl);
  9255. /*!
  9256. \ingroup CertsKeys
  9257. \brief This function looks for and returns the extension index
  9258. matching the passed in NID value.
  9259. \return >= 0 If successful the extension index is returned.
  9260. \return -1 If extension is not found or error is encountered.
  9261. \param x509 certificate to get parse through for extension.
  9262. \param nid extension OID to be found.
  9263. \param lastPos start search from extension after lastPos.
  9264. Set to -1 initially.
  9265. _Example_
  9266. \code
  9267. const WOLFSSL_X509* x509;
  9268. int lastPos = -1;
  9269. int idx;
  9270. idx = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints, lastPos);
  9271. \endcode
  9272. */
  9273. WOLFSSL_API int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509,
  9274. int nid, int lastPos);
  9275. /*!
  9276. \ingroup CertsKeys
  9277. \brief This function looks for and returns the extension
  9278. matching the passed in NID value.
  9279. \return pointer If successful a STACK_OF(WOLFSSL_ASN1_OBJECT)
  9280. pointer is returned.
  9281. \return NULL If extension is not found or error is encountered.
  9282. \param x509 certificate to get parse through for extension.
  9283. \param nid extension OID to be found.
  9284. \param c if not NULL is set to -2 for multiple extensions found -1
  9285. if not found, 0 if found and not critical and 1 if found and critical.
  9286. \param idx if NULL return first extension matched otherwise if not
  9287. stored in x509 start at idx.
  9288. _Example_
  9289. \code
  9290. const WOLFSSL_X509* x509;
  9291. int c;
  9292. int idx = 0;
  9293. STACK_OF(WOLFSSL_ASN1_OBJECT)* sk;
  9294. sk = wolfSSL_X509_get_ext_d2i(x509, NID_basic_constraints, &c, &idx);
  9295. //check sk for NULL and then use it. sk needs freed after done.
  9296. \endcode
  9297. \sa wolfSSL_sk_ASN1_OBJECT_free
  9298. */
  9299. WOLFSSL_API void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509,
  9300. int nid, int* c, int* idx);
  9301. /*!
  9302. \ingroup CertsKeys
  9303. \brief This function returns the hash of the DER certificate.
  9304. \return SSL_SUCCESS On successfully creating a hash.
  9305. \return SSL_FAILURE Returned on bad input or unsuccessful hash.
  9306. \param x509 certificate to get the hash of.
  9307. \param digest the hash algorithm to use.
  9308. \param buf buffer to hold hash.
  9309. \param len length of buffer.
  9310. _Example_
  9311. \code
  9312. WOLFSSL_X509* x509;
  9313. unsigned char buffer[64];
  9314. unsigned int bufferSz;
  9315. int ret;
  9316. ret = wolfSSL_X509_digest(x509, wolfSSL_EVP_sha256(), buffer, &bufferSz);
  9317. //check ret value
  9318. \endcode
  9319. \sa none
  9320. */
  9321. WOLFSSL_API int wolfSSL_X509_digest(const WOLFSSL_X509* x509,
  9322. const WOLFSSL_EVP_MD* digest, unsigned char* buf, unsigned int* len);
  9323. /*!
  9324. \ingroup Setup
  9325. \brief his is used to set the certificate for WOLFSSL structure to use
  9326. during a handshake.
  9327. \return SSL_SUCCESS On successful setting argument.
  9328. \return SSL_FAILURE If a NULL argument passed in.
  9329. \param ssl WOLFSSL structure to set certificate in.
  9330. \param x509 certificate to use.
  9331. _Example_
  9332. \code WOLFSSL* ssl;
  9333. WOLFSSL_X509* x509
  9334. int ret;
  9335. // create ssl object and x509
  9336. ret = wolfSSL_use_certificate(ssl, x509);
  9337. // check ret value
  9338. \endcode
  9339. \sa wolfSSL_new
  9340. \sa wolfSSL_free
  9341. */
  9342. WOLFSSL_API int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509);
  9343. /*!
  9344. \ingroup Setup
  9345. \brief This is used to set the certificate for WOLFSSL structure
  9346. to use during a handshake. A DER formatted buffer is expected.
  9347. \return SSL_SUCCESS On successful setting argument.
  9348. \return SSL_FAILURE If a NULL argument passed in.
  9349. \param ssl WOLFSSL structure to set certificate in.
  9350. \param der DER certificate to use.
  9351. \param derSz size of the DER buffer passed in.
  9352. _Example_
  9353. \code
  9354. WOLFSSL* ssl;
  9355. unsigned char* der;
  9356. int derSz;
  9357. int ret;
  9358. // create ssl object and set DER variables
  9359. ret = wolfSSL_use_certificate_ASN1(ssl, der, derSz);
  9360. // check ret value
  9361. \endcode
  9362. \sa wolfSSL_new
  9363. \sa wolfSSL_free
  9364. */
  9365. WOLFSSL_API int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, unsigned char* der,
  9366. int derSz);
  9367. /*!
  9368. \ingroup CertsKeys
  9369. \brief This is used to set the private key for the WOLFSSL structure.
  9370. \return SSL_SUCCESS On successful setting argument.
  9371. \return SSL_FAILURE If a NULL ssl passed in. All error
  9372. cases will be negative values.
  9373. \param ssl WOLFSSL structure to set argument in.
  9374. \param pkey private key to use.
  9375. _Example_
  9376. \code
  9377. WOLFSSL* ssl;
  9378. WOLFSSL_EVP_PKEY* pkey;
  9379. int ret;
  9380. // create ssl object and set up private key
  9381. ret = wolfSSL_use_PrivateKey(ssl, pkey);
  9382. // check ret value
  9383. \endcode
  9384. \sa wolfSSL_new
  9385. \sa wolfSSL_free
  9386. */
  9387. WOLFSSL_API int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey);
  9388. /*!
  9389. \ingroup CertsKeys
  9390. \brief This is used to set the private key for the WOLFSSL
  9391. structure. A DER formatted key buffer is expected.
  9392. \return SSL_SUCCESS On successful setting parsing and
  9393. setting the private key.
  9394. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  9395. will be negative values.
  9396. \param pri type of private key.
  9397. \param ssl WOLFSSL structure to set argument in.
  9398. \param der buffer holding DER key.
  9399. \param derSz size of der buffer.
  9400. _Example_
  9401. \code
  9402. WOLFSSL* ssl;
  9403. unsigned char* pkey;
  9404. long pkeySz;
  9405. int ret;
  9406. // create ssl object and set up private key
  9407. ret = wolfSSL_use_PrivateKey_ASN1(1, ssl, pkey, pkeySz);
  9408. // check ret value
  9409. \endcode
  9410. \sa wolfSSL_new
  9411. \sa wolfSSL_free
  9412. \sa wolfSSL_use_PrivateKey
  9413. */
  9414. WOLFSSL_API int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl,
  9415. unsigned char* der, long derSz);
  9416. /*!
  9417. \ingroup CertsKeys
  9418. \brief This is used to set the private key for the WOLFSSL
  9419. structure. A DER formatted RSA key buffer is expected.
  9420. \return SSL_SUCCESS On successful setting parsing and setting
  9421. the private key.
  9422. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  9423. will be negative values.
  9424. \param ssl WOLFSSL structure to set argument in.
  9425. \param der buffer holding DER key.
  9426. \param derSz size of der buffer.
  9427. _Example_
  9428. \code
  9429. WOLFSSL* ssl;
  9430. unsigned char* pkey;
  9431. long pkeySz;
  9432. int ret;
  9433. // create ssl object and set up RSA private key
  9434. ret = wolfSSL_use_RSAPrivateKey_ASN1(ssl, pkey, pkeySz);
  9435. // check ret value
  9436. \endcode
  9437. \sa wolfSSL_new
  9438. \sa wolfSSL_free
  9439. \sa wolfSSL_use_PrivateKey
  9440. */
  9441. WOLFSSL_API int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, unsigned char* der,
  9442. long derSz);
  9443. /*!
  9444. \ingroup CertsKeys
  9445. \brief This function duplicates the parameters in dsa to a
  9446. newly created WOLFSSL_DH structure.
  9447. \return WOLFSSL_DH If duplicated returns WOLFSSL_DH structure
  9448. \return NULL upon failure
  9449. \param dsa WOLFSSL_DSA structure to duplicate.
  9450. _Example_
  9451. \code
  9452. WOLFSSL_DH* dh;
  9453. WOLFSSL_DSA* dsa;
  9454. // set up dsa
  9455. dh = wolfSSL_DSA_dup_DH(dsa);
  9456. // check dh is not null
  9457. \endcode
  9458. \sa none
  9459. */
  9460. WOLFSSL_API WOLFSSL_DH *wolfSSL_DSA_dup_DH(const WOLFSSL_DSA *r);
  9461. /*!
  9462. \ingroup Setup
  9463. \brief This is used to get the master key after completing a handshake.
  9464. \return >0 On successfully getting data returns a value greater than 0
  9465. \return 0 If no random data buffer or an error state returns 0
  9466. \return max If outSz passed in is 0 then the maximum buffer
  9467. size needed is returned
  9468. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  9469. \param out buffer to hold data.
  9470. \param outSz size of out buffer passed in. (if 0 function will
  9471. return max buffer size needed)
  9472. _Example_
  9473. \code
  9474. WOLFSSL_SESSION ssl;
  9475. unsigned char* buffer;
  9476. size_t bufferSz;
  9477. size_t ret;
  9478. // complete handshake and get session structure
  9479. bufferSz = wolfSSL_SESSION_get_master_secret(ses, NULL, 0);
  9480. buffer = malloc(bufferSz);
  9481. ret = wolfSSL_SESSION_get_master_secret(ses, buffer, bufferSz);
  9482. // check ret value
  9483. \endcode
  9484. \sa wolfSSL_new
  9485. \sa wolfSSL_free
  9486. */
  9487. WOLFSSL_API int wolfSSL_SESSION_get_master_key(const WOLFSSL_SESSION* ses,
  9488. unsigned char* out, int outSz);
  9489. /*!
  9490. \ingroup Setup
  9491. \brief This is used to get the master secret key length.
  9492. \return size Returns master secret key size.
  9493. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  9494. _Example_
  9495. \code
  9496. WOLFSSL_SESSION ssl;
  9497. unsigned char* buffer;
  9498. size_t bufferSz;
  9499. size_t ret;
  9500. // complete handshake and get session structure
  9501. bufferSz = wolfSSL_SESSION_get_master_secret_length(ses);
  9502. buffer = malloc(bufferSz);
  9503. // check ret value
  9504. \endcode
  9505. \sa wolfSSL_new
  9506. \sa wolfSSL_free
  9507. */
  9508. WOLFSSL_API int wolfSSL_SESSION_get_master_key_length(const WOLFSSL_SESSION* ses);
  9509. /*!
  9510. \ingroup Setup
  9511. \brief This is a setter function for the WOLFSSL_X509_STORE
  9512. structure in ctx.
  9513. \return none No return.
  9514. \param ctx pointer to the WOLFSSL_CTX structure for setting
  9515. cert store pointer.
  9516. \param str pointer to the WOLFSSL_X509_STORE to set in ctx.
  9517. _Example_
  9518. \code
  9519. WOLFSSL_CTX ctx;
  9520. WOLFSSL_X509_STORE* st;
  9521. // setup ctx and st
  9522. st = wolfSSL_CTX_set_cert_store(ctx, st);
  9523. //use st
  9524. \endcode
  9525. \sa wolfSSL_CTX_new
  9526. \sa wolfSSL_CTX_free
  9527. */
  9528. WOLFSSL_API void wolfSSL_CTX_set_cert_store(WOLFSSL_CTX* ctx,
  9529. WOLFSSL_X509_STORE* str);
  9530. /*!
  9531. \ingroup CertsKeys
  9532. \brief This function get the DER buffer from bio and converts it
  9533. to a WOLFSSL_X509 structure.
  9534. \return pointer returns a WOLFSSL_X509 structure pointer on success.
  9535. \return Null returns NULL on failure
  9536. \param bio pointer to the WOLFSSL_BIO structure that has the DER
  9537. certificate buffer.
  9538. \param x509 pointer that get set to new WOLFSSL_X509 structure created.
  9539. _Example_
  9540. \code
  9541. WOLFSSL_BIO* bio;
  9542. WOLFSSL_X509* x509;
  9543. // load DER into bio
  9544. x509 = wolfSSL_d2i_X509_bio(bio, NULL);
  9545. Or
  9546. wolfSSL_d2i_X509_bio(bio, &x509);
  9547. // use x509 returned (check for NULL)
  9548. \endcode
  9549. \sa none
  9550. */
  9551. WOLFSSL_X509* wolfSSL_d2i_X509_bio(WOLFSSL_BIO* bio, WOLFSSL_X509** x509);
  9552. /*!
  9553. \ingroup Setup
  9554. \brief This is a getter function for the WOLFSSL_X509_STORE
  9555. structure in ctx.
  9556. \return WOLFSSL_X509_STORE* On successfully getting the pointer.
  9557. \return NULL Returned if NULL arguments are passed in.
  9558. \param ctx pointer to the WOLFSSL_CTX structure for getting cert
  9559. store pointer.
  9560. _Example_
  9561. \code
  9562. WOLFSSL_CTX ctx;
  9563. WOLFSSL_X509_STORE* st;
  9564. // setup ctx
  9565. st = wolfSSL_CTX_get_cert_store(ctx);
  9566. //use st
  9567. \endcode
  9568. \sa wolfSSL_CTX_new
  9569. \sa wolfSSL_CTX_free
  9570. \sa wolfSSL_CTX_set_cert_store
  9571. */
  9572. WOLFSSL_API WOLFSSL_X509_STORE* wolfSSL_CTX_get_cert_store(WOLFSSL_CTX* ctx);
  9573. /*!
  9574. \ingroup IO
  9575. \brief Gets the number of pending bytes to read. If BIO type is BIO_BIO
  9576. then is the number to read from pair. If BIO contains an SSL object then
  9577. is pending data from SSL object (wolfSSL_pending(ssl)). If is BIO_MEMORY
  9578. type then returns the size of memory buffer.
  9579. \return >=0 number of pending bytes.
  9580. \param bio pointer to the WOLFSSL_BIO structure that has already
  9581. been created.
  9582. _Example_
  9583. \code
  9584. WOLFSSL_BIO* bio;
  9585. int pending;
  9586. bio = wolfSSL_BIO_new();
  9587. pending = wolfSSL_BIO_ctrl_pending(bio);
  9588. \endcode
  9589. \sa wolfSSL_BIO_make_bio_pair
  9590. \sa wolfSSL_BIO_new
  9591. */
  9592. WOLFSSL_API size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *b);
  9593. /*!
  9594. \ingroup Setup
  9595. \brief This is used to get the random data sent by the server
  9596. during the handshake.
  9597. \return >0 On successfully getting data returns a value greater than 0
  9598. \return 0 If no random data buffer or an error state returns 0
  9599. \return max If outSz passed in is 0 then the maximum buffer size
  9600. needed is returned
  9601. \param ssl WOLFSSL structure to get clients random data buffer from.
  9602. \param out buffer to hold random data.
  9603. \param outSz size of out buffer passed in. (if 0 function will return max
  9604. buffer size needed)
  9605. _Example_
  9606. \code
  9607. WOLFSSL ssl;
  9608. unsigned char* buffer;
  9609. size_t bufferSz;
  9610. size_t ret;
  9611. bufferSz = wolfSSL_get_server_random(ssl, NULL, 0);
  9612. buffer = malloc(bufferSz);
  9613. ret = wolfSSL_get_server_random(ssl, buffer, bufferSz);
  9614. // check ret value
  9615. \endcode
  9616. \sa wolfSSL_new
  9617. \sa wolfSSL_free
  9618. */
  9619. WOLFSSL_API size_t wolfSSL_get_server_random(const WOLFSSL *ssl,
  9620. unsigned char *out, size_t outlen);
  9621. /*!
  9622. \ingroup Setup
  9623. \brief This is used to get the random data sent by the client during
  9624. the handshake.
  9625. \return >0 On successfully getting data returns a value greater than 0
  9626. \return 0 If no random data buffer or an error state returns 0
  9627. \return max If outSz passed in is 0 then the maximum buffer size needed
  9628. is returned
  9629. \param ssl WOLFSSL structure to get clients random data buffer from.
  9630. \param out buffer to hold random data.
  9631. \param outSz size of out buffer passed in. (if 0 function will return max
  9632. buffer size needed)
  9633. _Example_
  9634. \code
  9635. WOLFSSL ssl;
  9636. unsigned char* buffer;
  9637. size_t bufferSz;
  9638. size_t ret;
  9639. bufferSz = wolfSSL_get_client_random(ssl, NULL, 0);
  9640. buffer = malloc(bufferSz);
  9641. ret = wolfSSL_get_client_random(ssl, buffer, bufferSz);
  9642. // check ret value
  9643. \endcode
  9644. \sa wolfSSL_new
  9645. \sa wolfSSL_free
  9646. */
  9647. WOLFSSL_API size_t wolfSSL_get_client_random(const WOLFSSL* ssl,
  9648. unsigned char* out, size_t outSz);
  9649. /*!
  9650. \ingroup Setup
  9651. \brief This is a getter function for the password callback set in ctx.
  9652. \return func On success returns the callback function.
  9653. \return NULL If ctx is NULL then NULL is returned.
  9654. \param ctx WOLFSSL_CTX structure to get call back from.
  9655. _Example_
  9656. \code
  9657. WOLFSSL_CTX* ctx;
  9658. pem_password_cb cb;
  9659. // setup ctx
  9660. cb = wolfSSL_CTX_get_default_passwd_cb(ctx);
  9661. //use cb
  9662. \endcode
  9663. \sa wolfSSL_CTX_new
  9664. \sa wolfSSL_CTX_free
  9665. */
  9666. WOLFSSL_API pem_password_cb* wolfSSL_CTX_get_default_passwd_cb(WOLFSSL_CTX *ctx);
  9667. /*!
  9668. \ingroup Setup
  9669. \brief This is a getter function for the password callback user
  9670. data set in ctx.
  9671. \return pointer On success returns the user data pointer.
  9672. \return NULL If ctx is NULL then NULL is returned.
  9673. \param ctx WOLFSSL_CTX structure to get user data from.
  9674. _Example_
  9675. \code
  9676. WOLFSSL_CTX* ctx;
  9677. void* data;
  9678. // setup ctx
  9679. data = wolfSSL_CTX_get_default_passwd_cb(ctx);
  9680. //use data
  9681. \endcode
  9682. \sa wolfSSL_CTX_new
  9683. \sa wolfSSL_CTX_free
  9684. */
  9685. WOLFSSL_API void *wolfSSL_CTX_get_default_passwd_cb_userdata(WOLFSSL_CTX *ctx);
  9686. /*!
  9687. \ingroup CertsKeys
  9688. \brief This function behaves the same as wolfSSL_PEM_read_bio_X509.
  9689. AUX signifies containing extra information such as trusted/rejected use
  9690. cases and friendly name for human readability.
  9691. \return WOLFSSL_X509 on successfully parsing the PEM buffer a WOLFSSL_X509
  9692. structure is returned.
  9693. \return Null if failed to parse PEM buffer.
  9694. \param bp WOLFSSL_BIO structure to get PEM buffer from.
  9695. \param x if setting WOLFSSL_X509 by function side effect.
  9696. \param cb password callback.
  9697. \param u NULL terminated user password.
  9698. _Example_
  9699. \code
  9700. WOLFSSL_BIO* bio;
  9701. WOLFSSL_X509* x509;
  9702. // setup bio
  9703. X509 = wolfSSL_PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
  9704. //check x509 is not null and then use it
  9705. \endcode
  9706. \sa wolfSSL_PEM_read_bio_X509
  9707. */
  9708. WOLFSSL_API WOLFSSL_X509 *wolfSSL_PEM_read_bio_X509_AUX
  9709. (WOLFSSL_BIO *bp, WOLFSSL_X509 **x, pem_password_cb *cb, void *u);
  9710. /*!
  9711. \ingroup CertsKeys
  9712. \brief Initializes the WOLFSSL_CTX structure’s dh member with the
  9713. Diffie-Hellman parameters.
  9714. \return SSL_SUCCESS returned if the function executed successfully.
  9715. \return BAD_FUNC_ARG returned if the ctx or dh structures are NULL.
  9716. \return SSL_FATAL_ERROR returned if there was an error setting a
  9717. structure value.
  9718. \return MEMORY_E returned if their was a failure to allocate memory.
  9719. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  9720. wolfSSL_CTX_new().
  9721. \param dh a pointer to a WOLFSSL_DH structure.
  9722. _Example_
  9723. \code
  9724. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9725. WOLFSSL_DH* dh;
  9726. return wolfSSL_CTX_set_tmp_dh(ctx, dh);
  9727. \endcode
  9728. \sa wolfSSL_BN_bn2bin
  9729. */
  9730. WOLFSSL_API long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX*, WOLFSSL_DH*);
  9731. /*!
  9732. \ingroup CertsKeys
  9733. \brief This function get the DSA parameters from a PEM buffer in bio.
  9734. \return WOLFSSL_DSA on successfully parsing the PEM buffer a WOLFSSL_DSA
  9735. structure is created and returned.
  9736. \return Null if failed to parse PEM buffer.
  9737. \param bio pointer to the WOLFSSL_BIO structure for getting PEM
  9738. memory pointer.
  9739. \param x pointer to be set to new WOLFSSL_DSA structure.
  9740. \param cb password callback function.
  9741. \param u null terminated password string.
  9742. _Example_
  9743. \code
  9744. WOLFSSL_BIO* bio;
  9745. WOLFSSL_DSA* dsa;
  9746. // setup bio
  9747. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  9748. // check dsa is not NULL and then use dsa
  9749. \endcode
  9750. \sa none
  9751. */
  9752. WOLFSSL_API WOLFSSL_DSA *wolfSSL_PEM_read_bio_DSAparams(WOLFSSL_BIO *bp,
  9753. WOLFSSL_DSA **x, pem_password_cb *cb, void *u);
  9754. /*!
  9755. \ingroup Debug
  9756. \brief This function returns the absolute value of the last error from
  9757. WOLFSSL_ERROR encountered.
  9758. \return error Returns absolute value of last error.
  9759. \param none No parameters.
  9760. _Example_
  9761. \code
  9762. unsigned long err;
  9763. ...
  9764. err = wolfSSL_ERR_peek_last_error();
  9765. // inspect err value
  9766. \endcode
  9767. \sa wolfSSL_ERR_print_errors_fp
  9768. */
  9769. WOLFSSL_API unsigned long wolfSSL_ERR_peek_last_error(void);
  9770. /*!
  9771. \ingroup CertsKeys
  9772. \brief This function gets the peer’s certificate chain.
  9773. \return pointer returns a pointer to the peer’s Certificate stack.
  9774. \return NULL returned if no peer certificate.
  9775. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9776. _Example_
  9777. \code
  9778. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9779. WOLFSSL* ssl = wolfSSL_new(ctx);
  9780. ...
  9781. wolfSSL_connect(ssl);
  9782. STACK_OF(WOLFSSL_X509)* chain = wolfSSL_get_peer_cert_chain(ssl);
  9783. ifchain){
  9784. // You have a pointer to the peer certificate chain
  9785. }
  9786. \endcode
  9787. \sa wolfSSL_X509_get_issuer_name
  9788. \sa wolfSSL_X509_get_subject_name
  9789. \sa wolfSSL_X509_get_isCA
  9790. */
  9791. WOLFSSL_API WOLF_STACK_OF(WOLFSSL_X509)* wolfSSL_get_peer_cert_chain(const WOLFSSL*);
  9792. /*!
  9793. \ingroup Setup
  9794. \brief This function resets option bits of WOLFSSL_CTX object.
  9795. \return option new option bits
  9796. \param ctx pointer to the SSL context.
  9797. _Example_
  9798. \code
  9799. WOLFSSL_CTX* ctx = 0;
  9800. ...
  9801. wolfSSL_CTX_clear_options(ctx, SSL_OP_NO_TLSv1);
  9802. \endcode
  9803. \sa wolfSSL_CTX_new
  9804. \sa wolfSSL_new
  9805. \sa wolfSSL_free
  9806. */
  9807. WOLFSSL_API long wolfSSL_CTX_clear_options(WOLFSSL_CTX*, long);
  9808. /*!
  9809. \ingroup IO
  9810. \brief This function sets the jObjectRef member of the WOLFSSL structure.
  9811. \return SSL_SUCCESS returned if jObjectRef is properly set to objPtr.
  9812. \return SSL_FAILURE returned if the function did not properly execute and
  9813. jObjectRef is not set.
  9814. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9815. \param objPtr a void pointer that will be set to jObjectRef.
  9816. _Example_
  9817. \code
  9818. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9819. WOLFSSL* ssl = WOLFSSL_new();
  9820. void* objPtr = &obj;
  9821. ...
  9822. if(wolfSSL_set_jobject(ssl, objPtr)){
  9823. // The success case
  9824. }
  9825. \endcode
  9826. \sa wolfSSL_get_jobject
  9827. */
  9828. WOLFSSL_API int wolfSSL_set_jobject(WOLFSSL* ssl, void* objPtr);
  9829. /*!
  9830. \ingroup IO
  9831. \brief This function returns the jObjectRef member of the WOLFSSL structure.
  9832. \return value If the WOLFSSL struct is not NULL, the function returns the
  9833. jObjectRef value.
  9834. \return NULL returned if the WOLFSSL struct is NULL.
  9835. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9836. _Example_
  9837. \code
  9838. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9839. WOLFSSL* ssl = wolfSSL(ctx);
  9840. ...
  9841. void* jobject = wolfSSL_get_jobject(ssl);
  9842. if(jobject != NULL){
  9843. // Success case
  9844. }
  9845. \endcode
  9846. \sa wolfSSL_set_jobject
  9847. */
  9848. WOLFSSL_API void* wolfSSL_get_jobject(WOLFSSL* ssl);
  9849. /*!
  9850. \ingroup Setup
  9851. \brief This function sets a callback in the ssl. The callback is to
  9852. observe handshake messages. NULL value of cb resets the callback.
  9853. \return SSL_SUCCESS On success.
  9854. \return SSL_FAILURE If an NULL ssl passed in.
  9855. \param ssl WOLFSSL structure to set callback argument.
  9856. _Example_
  9857. \code
  9858. static cb(int write_p, int version, int content_type,
  9859. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  9860. WOLFSSL* ssl;
  9861. ret = wolfSSL_set_msg_callback(ssl, cb);
  9862. // check ret
  9863. \endcode
  9864. \sa wolfSSL_set_msg_callback_arg
  9865. */
  9866. WOLFSSL_API int wolfSSL_set_msg_callback(WOLFSSL *ssl, SSL_Msg_Cb cb);
  9867. /*!
  9868. \ingroup Setup
  9869. \brief This function sets associated callback context value in the ssl.
  9870. The value is handed over to the callback argument.
  9871. \return none No return.
  9872. \param ssl WOLFSSL structure to set callback argument.
  9873. _Example_
  9874. \code
  9875. static cb(int write_p, int version, int content_type,
  9876. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  9877. WOLFSSL* ssl;
  9878. ret = wolfSSL_set_msg_callback(ssl, cb);
  9879. // check ret
  9880. wolfSSL_set_msg_callback(ssl, arg);
  9881. \endcode
  9882. \sa wolfSSL_set_msg_callback
  9883. */
  9884. WOLFSSL_API int wolfSSL_set_msg_callback_arg(WOLFSSL *ssl, void* arg);
  9885. /*!
  9886. \ingroup CertsKeys
  9887. \brief This function returns the next, if any, altname from the peer certificate.
  9888. \return NULL if there is not a next altname.
  9889. \return cert->altNamesNext->name from the WOLFSSL_X509 structure that is a
  9890. string value from the altName list is returned if it exists.
  9891. \param cert a pointer to the wolfSSL_X509 structure.
  9892. _Example_
  9893. \code
  9894. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  9895. DYNAMIC_TYPE_X509);
  9896. int x509NextAltName = wolfSSL_X509_get_next_altname(x509);
  9897. if(x509NextAltName == NULL){
  9898. //There isn’t another alt name
  9899. }
  9900. \endcode
  9901. \sa wolfSSL_X509_get_issuer_name
  9902. \sa wolfSSL_X509_get_subject_name
  9903. */
  9904. WOLFSSL_API char* wolfSSL_X509_get_next_altname(WOLFSSL_X509*);
  9905. /*!
  9906. \ingroup CertsKeys
  9907. \brief The function checks to see if x509 is NULL and if it’s not, it
  9908. returns the notBefore member of the x509 struct.
  9909. \return pointer to struct with ASN1_TIME to the notBefore
  9910. member of the x509 struct.
  9911. \return NULL the function returns NULL if the x509 structure is NULL.
  9912. \param x509 a pointer to the WOLFSSL_X509 struct.
  9913. _Example_
  9914. \code
  9915. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  9916. DYNAMIC_TYPE_X509) ;
  9917. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notBefore(x509);
  9918. if(notAfter == NULL){
  9919. //The x509 object was NULL
  9920. }
  9921. \endcode
  9922. \sa wolfSSL_X509_get_notAfter
  9923. */
  9924. WOLFSSL_API WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notBefore(WOLFSSL_X509*);
  9925. /*!
  9926. \ingroup IO
  9927. \brief This function is called on the client side and initiates an SSL/TLS handshake with a server. When this function is called, the underlying communication channel has already been set up.
  9928. wolfSSL_connect() works with both blocking and non-blocking I/O. When the underlying I/O is non-blocking, wolfSSL_connect() will return when the underlying I/O could not satisfy the needs of wolfSSL_connect to continue the handshake. In this case, a call to wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then repeat the call to wolfSSL_connect() when the underlying I/O is ready and wolfSSL will pick up where it left off. When using a non-blocking socket, nothing needs to be done, but select() can be used to check for the required condition.
  9929. If the underlying I/O is blocking, wolfSSL_connect() will only return once the handshake has been finished or an error occurred.
  9930. wolfSSL takes a different approach to certificate verification than OpenSSL does. The default policy for the client is to verify the server, this means that if you don't load CAs to verify the server you'll get a connect error, unable to verify (-155). It you want to mimic OpenSSL behavior of having SSL_connect succeed even if verifying the server fails and reducing security you can do this by calling: SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling SSL_new(); Though it's not recommended.
  9931. \return SSL_SUCCESS If successful.
  9932. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a more detailed error code, call wolfSSL_get_error().
  9933. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9934. _Example_
  9935. \code
  9936. int ret = 0;
  9937. int err = 0;
  9938. WOLFSSL* ssl;
  9939. char buffer[80];
  9940. ...
  9941. ret = wolfSSL_connect(ssl);
  9942. if (ret != SSL_SUCCESS) {
  9943. err = wolfSSL_get_error(ssl, ret);
  9944. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  9945. }
  9946. \endcode
  9947. \sa wolfSSL_get_error
  9948. \sa wolfSSL_accept
  9949. */
  9950. int wolfSSL_connect(WOLFSSL* ssl);