1
0

ssl.h 379 KB

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