ssl.h 377 KB

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