ssl.h 433 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020
  1. /*!
  2. \brief This function initializes the DTLS v1.2 client method.
  3. \return pointer This function returns a pointer to a new
  4. WOLFSSL_METHOD structure.
  5. \param none No parameters.
  6. _Example_
  7. \code
  8. wolfSSL_Init();
  9. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method());
  10. WOLFSSL* ssl = wolfSSL_new(ctx);
  11. \endcode
  12. \sa wolfSSL_Init
  13. \sa wolfSSL_CTX_new
  14. */
  15. WOLFSSL_METHOD *wolfDTLSv1_2_client_method_ex(void* heap);
  16. /*!
  17. \ingroup Setup
  18. \brief This function returns a WOLFSSL_METHOD similar to
  19. wolfSSLv23_client_method except that it is not determined
  20. which side yet (server/client).
  21. \return WOLFSSL_METHOD* On successful creations returns a WOLFSSL_METHOD
  22. pointer
  23. \return NULL Null if memory allocation error or failure to create method
  24. \param none No parameters.
  25. _Example_
  26. \code
  27. WOLFSSL* ctx;
  28. ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  29. // check ret value
  30. \endcode
  31. \sa wolfSSL_new
  32. \sa wolfSSL_free
  33. */
  34. WOLFSSL_METHOD *wolfSSLv23_method(void);
  35. /*!
  36. \ingroup Setup
  37. \brief The wolfSSLv3_server_method() function is used to indicate
  38. that the application is a server and will only support the SSL 3.0
  39. protocol. This function allocates memory for and initializes a new
  40. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  41. with wolfSSL_CTX_new().
  42. \return * If successful, the call will return a pointer to the newly
  43. created WOLFSSL_METHOD structure.
  44. \return FAIL If memory allocation fails when calling XMALLOC, the
  45. failure value of the underlying malloc() implementation will be returned
  46. (typically NULL with errno will be set to ENOMEM).
  47. \param none No parameters.
  48. _Example_
  49. \code
  50. #include <wolfssl/ssl.h>
  51. WOLFSSL_METHOD* method;
  52. WOLFSSL_CTX* ctx;
  53. method = wolfSSLv3_server_method();
  54. if (method == NULL) {
  55. unable to get method
  56. }
  57. ctx = wolfSSL_CTX_new(method);
  58. ...
  59. \endcode
  60. \sa wolfTLSv1_server_method
  61. \sa wolfTLSv1_1_server_method
  62. \sa wolfTLSv1_2_server_method
  63. \sa wolfTLSv1_3_server_method
  64. \sa wolfDTLSv1_server_method
  65. \sa wolfSSLv23_server_method
  66. \sa wolfSSL_CTX_new
  67. */
  68. WOLFSSL_METHOD *wolfSSLv3_server_method(void);
  69. /*!
  70. \ingroup Setup
  71. \brief The wolfSSLv3_client_method() function is used to indicate
  72. that the application is a client and will only support the SSL 3.0
  73. protocol. This function allocates memory for and initializes a
  74. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  75. context with wolfSSL_CTX_new().
  76. \return * If successful, the call will return a pointer to the newly
  77. created WOLFSSL_METHOD structure.
  78. \return FAIL If memory allocation fails when calling XMALLOC, the
  79. failure value of the underlying malloc() implementation will be
  80. returned (typically NULL with errno will be set to ENOMEM).
  81. \param none No parameters.
  82. _Example_
  83. \code
  84. #include <wolfssl/ssl.h>
  85. WOLFSSL_METHOD* method;
  86. WOLFSSL_CTX* ctx;
  87. method = wolfSSLv3_client_method();
  88. if (method == NULL) {
  89. unable to get method
  90. }
  91. ctx = wolfSSL_CTX_new(method);
  92. ...
  93. \endcode
  94. \sa wolfTLSv1_client_method
  95. \sa wolfTLSv1_1_client_method
  96. \sa wolfTLSv1_2_client_method
  97. \sa wolfTLSv1_3_client_method
  98. \sa wolfDTLSv1_client_method
  99. \sa wolfSSLv23_client_method
  100. \sa wolfSSL_CTX_new
  101. */
  102. WOLFSSL_METHOD *wolfSSLv3_client_method(void);
  103. /*!
  104. \ingroup Setup
  105. \brief The wolfTLSv1_server_method() function is used to indicate that the
  106. application is a server and will only support the TLS 1.0 protocol. This
  107. function allocates memory for and initializes a new wolfSSL_METHOD
  108. structure to be used when creating the SSL/TLS context with
  109. wolfSSL_CTX_new().
  110. \return * If successful, the call will return a pointer to the newly
  111. created WOLFSSL_METHOD structure.
  112. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  113. value of the underlying malloc() implementation will be returned
  114. (typically NULL with errno will be set to ENOMEM).
  115. \param none No parameters.
  116. _Example_
  117. \code
  118. #include <wolfssl/ssl.h>
  119. WOLFSSL_METHOD* method;
  120. WOLFSSL_CTX* ctx;
  121. method = wolfTLSv1_server_method();
  122. if (method == NULL) {
  123. unable to get method
  124. }
  125. ctx = wolfSSL_CTX_new(method);
  126. ...
  127. \endcode
  128. \sa wolfSSLv3_server_method
  129. \sa wolfTLSv1_1_server_method
  130. \sa wolfTLSv1_2_server_method
  131. \sa wolfTLSv1_3_server_method
  132. \sa wolfDTLSv1_server_method
  133. \sa wolfSSLv23_server_method
  134. \sa wolfSSL_CTX_new
  135. */
  136. WOLFSSL_METHOD *wolfTLSv1_server_method(void);
  137. /*!
  138. \ingroup Setup
  139. \brief The wolfTLSv1_client_method() function is used to indicate
  140. that the application is a client and will only support the TLS 1.0
  141. protocol. This function allocates memory for and initializes a new
  142. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  143. with wolfSSL_CTX_new().
  144. \return * If successful, the call will return a pointer to the newly
  145. created WOLFSSL_METHOD structure.
  146. \return FAIL If memory allocation fails when calling XMALLOC,
  147. the failure value of the underlying malloc() implementation
  148. will be returned (typically NULL with errno will be set to ENOMEM).
  149. \param none No parameters.
  150. _Example_
  151. \code
  152. #include <wolfssl/ssl.h>
  153. WOLFSSL_METHOD* method;
  154. WOLFSSL_CTX* ctx;
  155. method = wolfTLSv1_client_method();
  156. if (method == NULL) {
  157. unable to get method
  158. }
  159. ctx = wolfSSL_CTX_new(method);
  160. ...
  161. \endcode
  162. \sa wolfSSLv3_client_method
  163. \sa wolfTLSv1_1_client_method
  164. \sa wolfTLSv1_2_client_method
  165. \sa wolfTLSv1_3_client_method
  166. \sa wolfDTLSv1_client_method
  167. \sa wolfSSLv23_client_method
  168. \sa wolfSSL_CTX_new
  169. */
  170. WOLFSSL_METHOD *wolfTLSv1_client_method(void);
  171. /*!
  172. \ingroup Setup
  173. \brief The wolfTLSv1_1_server_method() function is used to indicate
  174. that the application is a server and will only support the TLS 1.1
  175. protocol. This function allocates memory for and initializes a new
  176. wolfSSL_METHOD structure to be used when creating the SSL/TLS
  177. context with wolfSSL_CTX_new().
  178. \return * If successful, the call will return a pointer to the newly
  179. created WOLFSSL_METHOD structure.
  180. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  181. value of the underlying malloc() implementation will be returned
  182. (typically NULL with errno will be set to ENOMEM).
  183. \param none No parameters.
  184. _Example_
  185. \code
  186. #include <wolfssl/ssl.h>
  187. WOLFSSL_METHOD* method;
  188. WOLFSSL_CTX* ctx;
  189. method = wolfTLSv1_1_server_method();
  190. if (method == NULL) {
  191. // unable to get method
  192. }
  193. ctx = wolfSSL_CTX_new(method);
  194. ...
  195. \endcode
  196. \sa wolfSSLv3_server_method
  197. \sa wolfTLSv1_server_method
  198. \sa wolfTLSv1_2_server_method
  199. \sa wolfTLSv1_3_server_method
  200. \sa wolfDTLSv1_server_method
  201. \sa wolfSSLv23_server_method
  202. \sa wolfSSL_CTX_new
  203. */
  204. WOLFSSL_METHOD *wolfTLSv1_1_server_method(void);
  205. /*!
  206. \ingroup Setup
  207. \brief The wolfTLSv1_1_client_method() function is used to indicate
  208. that the application is a client and will only support the TLS 1.0
  209. protocol. This function allocates memory for and initializes a
  210. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  211. context with wolfSSL_CTX_new().
  212. \return * If successful, the call will return a pointer to the
  213. newly created WOLFSSL_METHOD structure.
  214. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  215. value of the underlying malloc() implementation will be returned
  216. (typically NULL with errno will be set to ENOMEM).
  217. \param none No parameters.
  218. _Example_
  219. \code
  220. #include <wolfssl/ssl.h>
  221. WOLFSSL_METHOD* method;
  222. WOLFSSL_CTX* ctx;
  223. method = wolfTLSv1_1_client_method();
  224. if (method == NULL) {
  225. // unable to get method
  226. }
  227. ctx = wolfSSL_CTX_new(method);
  228. ...
  229. \endcode
  230. \sa wolfSSLv3_client_method
  231. \sa wolfTLSv1_client_method
  232. \sa wolfTLSv1_2_client_method
  233. \sa wolfTLSv1_3_client_method
  234. \sa wolfDTLSv1_client_method
  235. \sa wolfSSLv23_client_method
  236. \sa wolfSSL_CTX_new
  237. */
  238. WOLFSSL_METHOD *wolfTLSv1_1_client_method(void);
  239. /*!
  240. \ingroup Setup
  241. \brief The wolfTLSv1_2_server_method() function is used to indicate
  242. that the application is a server and will only support the TLS 1.2
  243. protocol. This function allocates memory for and initializes a new
  244. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  245. with wolfSSL_CTX_new().
  246. \return * If successful, the call will return a pointer to the newly
  247. created WOLFSSL_METHOD structure.
  248. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  249. value of the underlying malloc() implementation will be returned
  250. (typically NULL with errno will be set to ENOMEM).
  251. \param none No parameters.
  252. _Example_
  253. \code
  254. #include <wolfssl/ssl.h>
  255. WOLFSSL_METHOD* method;
  256. WOLFSSL_CTX* ctx;
  257. method = wolfTLSv1_2_server_method();
  258. if (method == NULL) {
  259. // unable to get method
  260. }
  261. ctx = wolfSSL_CTX_new(method);
  262. ...
  263. \endcode
  264. \sa wolfSSLv3_server_method
  265. \sa wolfTLSv1_server_method
  266. \sa wolfTLSv1_1_server_method
  267. \sa wolfTLSv1_3_server_method
  268. \sa wolfDTLSv1_server_method
  269. \sa wolfSSLv23_server_method
  270. \sa wolfSSL_CTX_new
  271. */
  272. WOLFSSL_METHOD *wolfTLSv1_2_server_method(void);
  273. /*!
  274. \ingroup Setup
  275. \brief The wolfTLSv1_2_client_method() function is used to indicate
  276. that the application is a client and will only support the TLS 1.2
  277. protocol. This function allocates memory for and initializes a new
  278. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  279. with wolfSSL_CTX_new().
  280. \return * If successful, the call will return a pointer to the newly
  281. created WOLFSSL_METHOD structure.
  282. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  283. value of the underlying malloc() implementation will be returned
  284. (typically NULL with errno will be set to ENOMEM).
  285. \param none No parameters.
  286. _Example_
  287. \code
  288. #include <wolfssl/ssl.h>
  289. WOLFSSL_METHOD* method;
  290. WOLFSSL_CTX* ctx;
  291. method = wolfTLSv1_2_client_method();
  292. if (method == NULL) {
  293. // unable to get method
  294. }
  295. ctx = wolfSSL_CTX_new(method);
  296. ...
  297. \endcode
  298. \sa wolfSSLv3_client_method
  299. \sa wolfTLSv1_client_method
  300. \sa wolfTLSv1_1_client_method
  301. \sa wolfTLSv1_3_client_method
  302. \sa wolfDTLSv1_client_method
  303. \sa wolfSSLv23_client_method
  304. \sa wolfSSL_CTX_new
  305. */
  306. WOLFSSL_METHOD *wolfTLSv1_2_client_method(void);
  307. /*!
  308. \ingroup Setup
  309. \brief The wolfDTLSv1_client_method() function is used to indicate that
  310. the application is a client and will only support the DTLS 1.0 protocol.
  311. This function allocates memory for and initializes a new
  312. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  313. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  314. been compiled with DTLS support (--enable-dtls,
  315. or by defining wolfSSL_DTLS).
  316. \return * If successful, the call will return a pointer to the newly
  317. created WOLFSSL_METHOD structure.
  318. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  319. value of the underlying malloc() implementation will be returned
  320. (typically NULL with errno will be set to ENOMEM).
  321. \param none No parameters.
  322. _Example_
  323. \code
  324. WOLFSSL_METHOD* method;
  325. WOLFSSL_CTX* ctx;
  326. method = wolfDTLSv1_client_method();
  327. if (method == NULL) {
  328. // unable to get method
  329. }
  330. ctx = wolfSSL_CTX_new(method);
  331. ...
  332. \endcode
  333. \sa wolfSSLv3_client_method
  334. \sa wolfTLSv1_client_method
  335. \sa wolfTLSv1_1_client_method
  336. \sa wolfTLSv1_2_client_method
  337. \sa wolfTLSv1_3_client_method
  338. \sa wolfSSLv23_client_method
  339. \sa wolfSSL_CTX_new
  340. */
  341. WOLFSSL_METHOD *wolfDTLSv1_client_method(void);
  342. /*!
  343. \ingroup Setup
  344. \brief The wolfDTLSv1_server_method() function is used to indicate
  345. that the application is a server and will only support the DTLS 1.0
  346. protocol. This function allocates memory for and initializes a
  347. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  348. context with wolfSSL_CTX_new(). This function is only available
  349. when wolfSSL has been compiled with DTLS support (--enable-dtls,
  350. or by defining wolfSSL_DTLS).
  351. \return * If successful, the call will return a pointer to the newly
  352. created WOLFSSL_METHOD structure.
  353. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  354. value of the underlying malloc() implementation will be returned
  355. (typically NULL with errno will be set to ENOMEM).
  356. \param none No parameters.
  357. _Example_
  358. \code
  359. WOLFSSL_METHOD* method;
  360. WOLFSSL_CTX* ctx;
  361. method = wolfDTLSv1_server_method();
  362. if (method == NULL) {
  363. // unable to get method
  364. }
  365. ctx = wolfSSL_CTX_new(method);
  366. ...
  367. \endcode
  368. \sa wolfSSLv3_server_method
  369. \sa wolfTLSv1_server_method
  370. \sa wolfTLSv1_1_server_method
  371. \sa wolfTLSv1_2_server_method
  372. \sa wolfTLSv1_3_server_method
  373. \sa wolfSSLv23_server_method
  374. \sa wolfSSL_CTX_new
  375. */
  376. WOLFSSL_METHOD *wolfDTLSv1_server_method(void);
  377. /*!
  378. \brief This function creates and initializes a WOLFSSL_METHOD for the
  379. server side.
  380. \return This function returns a WOLFSSL_METHOD pointer.
  381. \param none No parameters.
  382. _Example_
  383. \code
  384. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  385. WOLFSSL* ssl = WOLFSSL_new(ctx);
  386. \endcode
  387. \sa wolfSSL_CTX_new
  388. */
  389. WOLFSSL_METHOD *wolfDTLSv1_2_server_method(void);
  390. /*!
  391. \ingroup Setup
  392. \brief Since there is some differences between the first release and
  393. newer versions of chacha-poly AEAD construction we have added an option
  394. to communicate with servers/clients using the older version. By default
  395. wolfSSL uses the new version.
  396. \return 0 upon success
  397. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  398. \param value whether or not to use the older version of setting up the
  399. information for poly1305. Passing a flag value of 1 indicates yes use the
  400. old poly AEAD, to switch back to using the new version pass a flag value
  401. of 0.
  402. _Example_
  403. \code
  404. int ret = 0;
  405. WOLFSSL* ssl;
  406. ...
  407. ret = wolfSSL_use_old_poly(ssl, 1);
  408. if (ret != 0) {
  409. // failed to set poly1305 AEAD version
  410. }
  411. \endcode
  412. \sa none
  413. */
  414. int wolfSSL_use_old_poly(WOLFSSL* ssl, int value);
  415. /*!
  416. \brief The wolfSSL_dtls_import() function is used to parse in a serialized
  417. session state. This allows for picking up the connection after the
  418. handshake has been completed.
  419. \return Success If successful, the amount of the buffer read will be
  420. returned.
  421. \return Failure All unsuccessful return values will be less than 0.
  422. \return VERSION_ERROR If a version mismatch is found ie DTLS v1 and ctx
  423. was set up for DTLS v1.2 then VERSION_ERROR is returned.
  424. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  425. \param buf serialized session to import.
  426. \param sz size of serialized session buffer.
  427. _Example_
  428. \code
  429. WOLFSSL* ssl;
  430. int ret;
  431. unsigned char buf[MAX];
  432. bufSz = MAX;
  433. ...
  434. //get information sent from wc_dtls_export function and place it in buf
  435. fread(buf, 1, bufSz, input);
  436. ret = wolfSSL_dtls_import(ssl, buf, bufSz);
  437. if (ret < 0) {
  438. // handle error case
  439. }
  440. // no wolfSSL_accept needed since handshake was already done
  441. ...
  442. ret = wolfSSL_write(ssl) and wolfSSL_read(ssl);
  443. ...
  444. \endcode
  445. \sa wolfSSL_new
  446. \sa wolfSSL_CTX_new
  447. \sa wolfSSL_CTX_dtls_set_export
  448. */
  449. int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf,
  450. unsigned int sz);
  451. /*!
  452. \brief Used to import a serialized TLS session. This function is for
  453. importing the state of the connection.
  454. WARNING: buf contains sensitive information about the state and is best to
  455. be encrypted before storing if stored.
  456. Additional debug info can be displayed with the macro
  457. WOLFSSL_SESSION_EXPORT_DEBUG defined.
  458. \return the number of bytes read from buffer 'buf'
  459. \param ssl WOLFSSL structure to import the session into
  460. \param buf serialized session
  461. \param sz size of buffer 'buf'
  462. \sa wolfSSL_dtls_import
  463. \sa wolfSSL_tls_export
  464. */
  465. int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf,
  466. unsigned int sz);
  467. /*!
  468. \brief The wolfSSL_CTX_dtls_set_export() function is used to set
  469. the callback function for exporting a session. It is allowed to
  470. pass in NULL as the parameter func to clear the export function
  471. previously stored. Used on the server side and is called immediately
  472. after handshake is completed.
  473. \return SSL_SUCCESS upon success.
  474. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  475. \param ctx a pointer to a WOLFSSL_CTX structure, created
  476. with wolfSSL_CTX_new().
  477. \param func wc_dtls_export function to use when exporting a session.
  478. _Example_
  479. \code
  480. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  481. // body of send session (wc_dtls_export) that passses
  482. // buf (serialized session) to destination
  483. WOLFSSL_CTX* ctx;
  484. int ret;
  485. ...
  486. ret = wolfSSL_CTX_dtls_set_export(ctx, send_session);
  487. if (ret != SSL_SUCCESS) {
  488. // handle error case
  489. }
  490. ...
  491. ret = wolfSSL_accept(ssl);
  492. ...
  493. \endcode
  494. \sa wolfSSL_new
  495. \sa wolfSSL_CTX_new
  496. \sa wolfSSL_dtls_set_export
  497. \sa Static buffer use
  498. */
  499. int wolfSSL_CTX_dtls_set_export(WOLFSSL_CTX* ctx,
  500. wc_dtls_export func);
  501. /*!
  502. \brief The wolfSSL_dtls_set_export() function is used to set the callback
  503. function for exporting a session. It is allowed to pass in NULL as the
  504. parameter func to clear the export function previously stored. Used on
  505. the server side and is called immediately after handshake is completed.
  506. \return SSL_SUCCESS upon success.
  507. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  508. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  509. \param func wc_dtls_export function to use when exporting a session.
  510. _Example_
  511. \code
  512. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  513. // body of send session (wc_dtls_export) that passses
  514. // buf (serialized session) to destination
  515. WOLFSSL* ssl;
  516. int ret;
  517. ...
  518. ret = wolfSSL_dtls_set_export(ssl, send_session);
  519. if (ret != SSL_SUCCESS) {
  520. // handle error case
  521. }
  522. ...
  523. ret = wolfSSL_accept(ssl);
  524. ...
  525. \endcode
  526. \sa wolfSSL_new
  527. \sa wolfSSL_CTX_new
  528. \sa wolfSSL_CTX_dtls_set_export
  529. */
  530. int wolfSSL_dtls_set_export(WOLFSSL* ssl, wc_dtls_export func);
  531. /*!
  532. \brief The wolfSSL_dtls_export() function is used to serialize a
  533. WOLFSSL session into the provided buffer. Allows for less memory
  534. overhead than using a function callback for sending a session and
  535. choice over when the session is serialized. If buffer is NULL when
  536. passed to function then sz will be set to the size of buffer needed
  537. for serializing the WOLFSSL session.
  538. \return Success If successful, the amount of the buffer used will
  539. be returned.
  540. \return Failure All unsuccessful return values will be less than 0.
  541. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  542. \param buf buffer to hold serialized session.
  543. \param sz size of buffer.
  544. _Example_
  545. \code
  546. WOLFSSL* ssl;
  547. int ret;
  548. unsigned char buf[MAX];
  549. bufSz = MAX;
  550. ...
  551. ret = wolfSSL_dtls_export(ssl, buf, bufSz);
  552. if (ret < 0) {
  553. // handle error case
  554. }
  555. ...
  556. \endcode
  557. \sa wolfSSL_new
  558. \sa wolfSSL_CTX_new
  559. \sa wolfSSL_CTX_dtls_set_export
  560. \sa wolfSSL_dtls_import
  561. */
  562. int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf,
  563. unsigned int* sz);
  564. /*!
  565. \brief Used to export a serialized TLS session. This function is for
  566. importing a serialized state of the connection.
  567. In most cases wolfSSL_get1_session should be used instead of
  568. wolfSSL_tls_export.
  569. Additional debug info can be displayed with the macro
  570. WOLFSSL_SESSION_EXPORT_DEBUG defined.
  571. WARNING: buf contains sensitive information about the state and is best to
  572. be encrypted before storing if stored.
  573. \return the number of bytes written into buffer 'buf'
  574. \param ssl WOLFSSL structure to export the session from
  575. \param buf output of serialized session
  576. \param sz size in bytes set in 'buf'
  577. \sa wolfSSL_dtls_import
  578. \sa wolfSSL_tls_import
  579. */
  580. int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf,
  581. unsigned int* sz);
  582. /*!
  583. \brief This function is used to set aside static memory for a CTX. Memory
  584. set aside is then used for the CTX’s lifetime and for any SSL objects
  585. created from the CTX. By passing in a NULL ctx pointer and a
  586. wolfSSL_method_func function the creation of the CTX itself will also
  587. use static memory. wolfSSL_method_func has the function signature of
  588. WOLFSSL_METHOD* (*wolfSSL_method_func)(void* heap);. Passing in 0 for max
  589. makes it behave as if not set and no max concurrent use restrictions is
  590. in place. The flag value passed in determines how the memory is used and
  591. behavior while operating. Available flags are the following: 0 - default
  592. general memory, WOLFMEM_IO_POOL - used for input/output buffer when
  593. sending receiving messages and overrides general memory, so all memory
  594. in buffer passed in is used for IO, WOLFMEM_IO_FIXED - same as
  595. WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for
  596. their lifetime, WOLFMEM_TRACK_STATS - each SSL keeps track of memory
  597. stats while running.
  598. \return SSL_SUCCESS upon success.
  599. \return SSL_FAILURE upon failure.
  600. \param ctx address of pointer to a WOLFSSL_CTX structure.
  601. \param method function to create protocol. (should be NULL if ctx is not
  602. also NULL)
  603. \param buf memory to use for all operations.
  604. \param sz size of memory buffer being passed in.
  605. \param flag type of memory.
  606. \param max max concurrent operations.
  607. _Example_
  608. \code
  609. WOLFSSL_CTX* ctx;
  610. WOLFSSL* ssl;
  611. int ret;
  612. unsigned char memory[MAX];
  613. int memorySz = MAX;
  614. unsigned char IO[MAX];
  615. int IOSz = MAX;
  616. int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
  617. ...
  618. // create ctx also using static memory, start with general memory to use
  619. ctx = NULL:
  620. ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex,
  621. memory, memorySz, 0, MAX_CONCURRENT_HANDSHAKES);
  622. if (ret != SSL_SUCCESS) {
  623. // handle error case
  624. }
  625. // load in memory for use with IO
  626. ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag,
  627. MAX_CONCURRENT_IO);
  628. if (ret != SSL_SUCCESS) {
  629. // handle error case
  630. }
  631. ...
  632. \endcode
  633. \sa wolfSSL_CTX_new
  634. \sa wolfSSL_CTX_is_static_memory
  635. \sa wolfSSL_is_static_memory
  636. */
  637. int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx,
  638. wolfSSL_method_func method,
  639. unsigned char* buf, unsigned int sz,
  640. int flag, int max);
  641. /*!
  642. \brief This function does not change any of the connections behavior
  643. and is used only for gathering information about the static memory usage.
  644. \return 1 is returned if using static memory for the CTX is true.
  645. \return 0 is returned if not using static memory.
  646. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  647. wolfSSL_CTX_new().
  648. \param mem_stats structure to hold information about static memory usage.
  649. _Example_
  650. \code
  651. WOLFSSL_CTX* ctx;
  652. int ret;
  653. WOLFSSL_MEM_STATS mem_stats;
  654. ...
  655. //get information about static memory with CTX
  656. ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
  657. if (ret == 1) {
  658. // handle case of is using static memory
  659. // print out or inspect elements of mem_stats
  660. }
  661. if (ret == 0) {
  662. //handle case of ctx not using static memory
  663. }
  664. \endcode
  665. \sa wolfSSL_CTX_new
  666. \sa wolfSSL_CTX_load_static_memory
  667. \sa wolfSSL_is_static_memory
  668. */
  669. int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX* ctx,
  670. WOLFSSL_MEM_STATS* mem_stats);
  671. /*!
  672. \brief wolfSSL_is_static_memory is used to gather information about
  673. a SSL’s static memory usage. The return value indicates if static
  674. memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out
  675. if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent
  676. CTX when loading in static memory.
  677. \return 1 is returned if using static memory for the CTX is true.
  678. \return 0 is returned if not using static memory.
  679. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  680. \param mem_stats structure to contain static memory usage.
  681. _Example_
  682. \code
  683. WOLFSSL* ssl;
  684. int ret;
  685. WOLFSSL_MEM_CONN_STATS mem_stats;
  686. ...
  687. ret = wolfSSL_is_static_memory(ssl, mem_stats);
  688. if (ret == 1) {
  689. // handle case when is static memory
  690. // investigate elements in mem_stats if WOLFMEM_TRACK_STATS flag
  691. }
  692. ...
  693. \endcode
  694. \sa wolfSSL_new
  695. \sa wolfSSL_CTX_is_static_memory
  696. */
  697. int wolfSSL_is_static_memory(WOLFSSL* ssl,
  698. WOLFSSL_MEM_CONN_STATS* mem_stats);
  699. /*!
  700. \ingroup CertsKeys
  701. \brief This function loads a certificate file into the SSL context
  702. (WOLFSSL_CTX). The file is provided by the file argument. The
  703. format argument specifies the format type of the file, either
  704. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please see the examples
  705. for proper usage.
  706. \return SSL_SUCCESS upon success.
  707. \return SSL_FAILURE If the function call fails, possible causes might
  708. include the file is in the wrong format, or the wrong format has been
  709. given using the “format” argument, file doesn’t exist, can’t be read,
  710. or is corrupted, an out of memory condition occurs, Base16 decoding
  711. fails on the file.
  712. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  713. wolfSSL_CTX_new()
  714. \param file a pointer to the name of the file containing the certificate
  715. to be loaded into the wolfSSL SSL context.
  716. \param format - format of the certificates pointed to by file. Possible
  717. options are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  718. _Example_
  719. \code
  720. int ret = 0;
  721. WOLFSSL_CTX* ctx;
  722. ...
  723. ret = wolfSSL_CTX_use_certificate_file(ctx, “./client-cert.pem”,
  724. SSL_FILETYPE_PEM);
  725. if (ret != SSL_SUCCESS) {
  726. // error loading cert file
  727. }
  728. ...
  729. \endcode
  730. \sa wolfSSL_CTX_use_certificate_buffer
  731. \sa wolfSSL_use_certificate_file
  732. \sa wolfSSL_use_certificate_buffer
  733. */
  734. int wolfSSL_CTX_use_certificate_file(WOLFSSL_CTX* ctx, const char* file,
  735. int format);
  736. /*!
  737. \ingroup CertsKeys
  738. \brief This function loads a private key file into the SSL context
  739. (WOLFSSL_CTX). The file is provided by the file argument. The format
  740. argument specifies the format type of the file - SSL_FILETYPE_ASN1or
  741. SSL_FILETYPE_PEM. Please see the examples for proper usage.
  742. If using an external key store and do not have the private key you can
  743. instead provide the public key and register the crypro callback to handle
  744. the signing. For this you can build with either build with crypto callbacks
  745. or PK callbacks. To enable crypto callbacks use --enable-cryptocb
  746. or WOLF_CRYPTO_CB and register a crypto callback using
  747. wc_CryptoCb_RegisterDevice and set the associated devId using
  748. wolfSSL_CTX_SetDevId.
  749. \return SSL_SUCCESS upon success.
  750. \return SSL_FAILURE The file is in the wrong format, or the wrong format
  751. has been given using the “format” argument. The file doesn’t exist, can’t
  752. be read, or is corrupted. An out of memory condition occurs. Base16
  753. decoding fails on the file. The key file is encrypted but no password
  754. is provided.
  755. \param none No parameters.
  756. _Example_
  757. \code
  758. int ret = 0;
  759. WOLFSSL_CTX* ctx;
  760. ...
  761. ret = wolfSSL_CTX_use_PrivateKey_file(ctx, “./server-key.pem”,
  762. SSL_FILETYPE_PEM);
  763. if (ret != SSL_SUCCESS) {
  764. // error loading key file
  765. }
  766. ...
  767. \endcode
  768. \sa wolfSSL_CTX_use_PrivateKey_buffer
  769. \sa wolfSSL_use_PrivateKey_file
  770. \sa wolfSSL_use_PrivateKey_buffer
  771. \sa wc_CryptoCb_RegisterDevice
  772. \sa wolfSSL_CTX_SetDevId
  773. */
  774. int wolfSSL_CTX_use_PrivateKey_file(WOLFSSL_CTX* ctx, const char* file, int format);
  775. /*!
  776. \ingroup CertsKeys
  777. \brief This function loads PEM-formatted CA certificate files into the SSL
  778. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  779. certificates and used to verify certs received from peers during the SSL
  780. handshake. The root certificate file, provided by the file argument, may
  781. be a single certificate or a file containing multiple certificates.
  782. If multiple CA certs are included in the same file, wolfSSL will load them
  783. in the same order they are presented in the file. The path argument is
  784. a pointer to the name of a directory that contains certificates of
  785. trusted root CAs. If the value of file is not NULL, path may be specified
  786. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  787. defined when building the library, wolfSSL will load all CA certificates
  788. located in the given directory. This function will attempt to load all
  789. files in the directory. This function expects PEM formatted CERT_TYPE
  790. file with header “-----BEGIN CERTIFICATE-----”.
  791. \return SSL_SUCCESS up success.
  792. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  793. path are NULL.
  794. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  795. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  796. read, or is corrupted.
  797. \return MEMORY_E will be returned if an out of memory condition occurs.
  798. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  799. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  800. before date.
  801. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  802. after date.
  803. \return BUFFER_E will be returned if a chain buffer is bigger than the
  804. receiving buffer.
  805. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  806. to open path.
  807. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  808. \param file pointer to name of the file containing PEM-formatted CA
  809. certificates.
  810. \param path pointer to the name of a directory to load PEM-formatted
  811. certificates from.
  812. _Example_
  813. \code
  814. int ret = 0;
  815. WOLFSSL_CTX* ctx;
  816. ...
  817. ret = wolfSSL_CTX_load_verify_locations(ctx, “./ca-cert.pem”, NULL);
  818. if (ret != WOLFSSL_SUCCESS) {
  819. // error loading CA certs
  820. }
  821. ...
  822. \endcode
  823. \sa wolfSSL_CTX_load_verify_locations_ex
  824. \sa wolfSSL_CTX_load_verify_buffer
  825. \sa wolfSSL_CTX_use_certificate_file
  826. \sa wolfSSL_CTX_use_PrivateKey_file
  827. \sa wolfSSL_CTX_use_certificate_chain_file
  828. \sa wolfSSL_use_certificate_file
  829. \sa wolfSSL_use_PrivateKey_file
  830. \sa wolfSSL_use_certificate_chain_file
  831. */
  832. int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
  833. const char* format);
  834. /*!
  835. \ingroup CertsKeys
  836. \brief This function loads PEM-formatted CA certificate files into the SSL
  837. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  838. certificates and used to verify certs received from peers during the SSL
  839. handshake. The root certificate file, provided by the file argument, may
  840. be a single certificate or a file containing multiple certificates.
  841. If multiple CA certs are included in the same file, wolfSSL will load them
  842. in the same order they are presented in the file. The path argument is
  843. a pointer to the name of a directory that contains certificates of
  844. trusted root CAs. If the value of file is not NULL, path may be specified
  845. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  846. defined when building the library, wolfSSL will load all CA certificates
  847. located in the given directory. This function will attempt to load all
  848. files in the directory based on flags specified. This function expects PEM
  849. formatted CERT_TYPE files with header “-----BEGIN CERTIFICATE-----”.
  850. \return SSL_SUCCESS up success.
  851. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  852. path are NULL. This will also be returned if at least one cert is loaded
  853. successfully but there is one or more that failed. Check error stack for reason.
  854. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  855. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  856. read, or is corrupted.
  857. \return MEMORY_E will be returned if an out of memory condition occurs.
  858. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  859. \return BUFFER_E will be returned if a chain buffer is bigger than the
  860. receiving buffer.
  861. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  862. to open path.
  863. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  864. \param file pointer to name of the file containing PEM-formatted CA
  865. certificates.
  866. \param path pointer to the name of a directory to load PEM-formatted
  867. certificates from.
  868. \param flags possible mask values are: WOLFSSL_LOAD_FLAG_IGNORE_ERR,
  869. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY and WOLFSSL_LOAD_FLAG_PEM_CA_ONLY
  870. _Example_
  871. \code
  872. int ret = 0;
  873. WOLFSSL_CTX* ctx;
  874. ...
  875. ret = wolfSSL_CTX_load_verify_locations_ex(ctx, NUULL, “./certs/external",
  876. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY);
  877. if (ret != WOLFSSL_SUCCESS) {
  878. // error loading CA certs
  879. }
  880. ...
  881. \endcode
  882. \sa wolfSSL_CTX_load_verify_locations
  883. \sa wolfSSL_CTX_load_verify_buffer
  884. \sa wolfSSL_CTX_use_certificate_file
  885. \sa wolfSSL_CTX_use_PrivateKey_file
  886. \sa wolfSSL_CTX_use_certificate_chain_file
  887. \sa wolfSSL_use_certificate_file
  888. \sa wolfSSL_use_PrivateKey_file
  889. \sa wolfSSL_use_certificate_chain_file
  890. */
  891. int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
  892. const char* path, unsigned int flags);
  893. /*!
  894. \ingroup Setup
  895. \brief This function loads a certificate to use for verifying a peer
  896. when performing a TLS/SSL handshake. The peer certificate sent during the
  897. handshake is compared by using the SKID when available and the signature.
  898. If these two things do not match then any loaded CAs are used. Feature is
  899. enabled by defining the macro WOLFSSL_TRUST_PEER_CERT. Please see the
  900. examples for proper usage.
  901. \return SSL_SUCCES upon success.
  902. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  903. type are invalid.
  904. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  905. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  906. read, or is corrupted.
  907. \return MEMORY_E will be returned if an out of memory condition occurs.
  908. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  909. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  910. \param file pointer to name of the file containing certificates
  911. \param type type of certificate being loaded ie SSL_FILETYPE_ASN1
  912. or SSL_FILETYPE_PEM.
  913. _Example_
  914. \code
  915. int ret = 0;
  916. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  917. ...
  918. ret = wolfSSL_CTX_trust_peer_cert(ctx, “./peer-cert.pem”,
  919. SSL_FILETYPE_PEM);
  920. if (ret != SSL_SUCCESS) {
  921. // error loading trusted peer cert
  922. }
  923. ...
  924. \endcode
  925. \sa wolfSSL_CTX_load_verify_buffer
  926. \sa wolfSSL_CTX_use_certificate_file
  927. \sa wolfSSL_CTX_use_PrivateKey_file
  928. \sa wolfSSL_CTX_use_certificate_chain_file
  929. \sa wolfSSL_CTX_trust_peer_buffer
  930. \sa wolfSSL_CTX_Unload_trust_peers
  931. \sa wolfSSL_use_certificate_file
  932. \sa wolfSSL_use_PrivateKey_file
  933. \sa wolfSSL_use_certificate_chain_file
  934. */
  935. int wolfSSL_CTX_trust_peer_cert(WOLFSSL_CTX* ctx, const char* file, int type);
  936. /*!
  937. \ingroup CertsKeys
  938. \brief This function loads a chain of certificates into the SSL
  939. context (WOLFSSL_CTX). The file containing the certificate chain
  940. is provided by the file argument, and must contain PEM-formatted
  941. certificates. This function will process up to MAX_CHAIN_DEPTH
  942. (default = 9, defined in internal.h) certificates, plus the subject cert.
  943. \return SSL_SUCCESS upon success
  944. \return SSL_FAILURE If the function call fails, possible causes might
  945. include the file is in the wrong format, or the wrong format has been
  946. given using the “format” argument, file doesn’t exist, can’t be read,
  947. or is corrupted, an out of memory condition occurs.
  948. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  949. wolfSSL_CTX_new()
  950. \param file a pointer to the name of the file containing the chain of
  951. certificates to be loaded into the wolfSSL SSL context. Certificates
  952. must be in PEM format.
  953. _Example_
  954. \code
  955. int ret = 0;
  956. WOLFSSL_CTX* ctx;
  957. ...
  958. ret = wolfSSL_CTX_use_certificate_chain_file(ctx, “./cert-chain.pem”);
  959. if (ret != SSL_SUCCESS) {
  960. // error loading cert file
  961. }
  962. ...
  963. \endcode
  964. \sa wolfSSL_CTX_use_certificate_file
  965. \sa wolfSSL_CTX_use_certificate_buffer
  966. \sa wolfSSL_use_certificate_file
  967. \sa wolfSSL_use_certificate_buffer
  968. */
  969. int wolfSSL_CTX_use_certificate_chain_file(WOLFSSL_CTX *ctx,
  970. const char *file);
  971. /*!
  972. \ingroup openSSL
  973. \brief This function loads the private RSA key used in the SSL connection
  974. into the SSL context (WOLFSSL_CTX). This function is only available when
  975. wolfSSL has been compiled with the OpenSSL compatibility layer enabled
  976. (--enable-opensslExtra, #define OPENSSL_EXTRA), and is identical to the
  977. more-typically used wolfSSL_CTX_use_PrivateKey_file() function. The file
  978. argument contains a pointer to the RSA private key file, in the format
  979. specified by format.
  980. \return SSL_SUCCESS upon success.
  981. \return SSL_FAILURE If the function call fails, possible causes might
  982. include: The input key file is in the wrong format, or the wrong format
  983. has been given using the “format” argument, file doesn’t exist, can’t
  984. be read, or is corrupted, an out of memory condition occurs.
  985. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  986. wolfSSL_CTX_new()
  987. \param file a pointer to the name of the file containing the RSA private
  988. key to be loaded into the wolfSSL SSL context, with format as specified
  989. by format.
  990. \param format the encoding type of the RSA private key specified by file.
  991. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  992. _Example_
  993. \code
  994. int ret = 0;
  995. WOLFSSL_CTX* ctx;
  996. ...
  997. ret = wolfSSL_CTX_use_RSAPrivateKey_file(ctx, “./server-key.pem”,
  998. SSL_FILETYPE_PEM);
  999. if (ret != SSL_SUCCESS) {
  1000. // error loading private key file
  1001. }
  1002. ...
  1003. \endcode
  1004. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1005. \sa wolfSSL_CTX_use_PrivateKey_file
  1006. \sa wolfSSL_use_RSAPrivateKey_file
  1007. \sa wolfSSL_use_PrivateKey_buffer
  1008. \sa wolfSSL_use_PrivateKey_file
  1009. */
  1010. int wolfSSL_CTX_use_RSAPrivateKey_file(WOLFSSL_CTX* ctx, const char* file, int format);
  1011. /*!
  1012. \ingroup IO
  1013. \brief This function returns the maximum chain depth allowed, which is 9 by
  1014. default, for a valid session i.e. there is a non-null session object (ssl).
  1015. \return MAX_CHAIN_DEPTH returned if the WOLFSSL_CTX structure is not
  1016. NULL. By default the value is 9.
  1017. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  1018. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1019. _Example_
  1020. \code
  1021. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1022. WOLFSSL* ssl = wolfSSL_new(ctx);
  1023. ...
  1024. long sslDep = wolfSSL_get_verify_depth(ssl);
  1025. if(sslDep > EXPECTED){
  1026. // The verified depth is greater than what was expected
  1027. } else {
  1028. // The verified depth is smaller or equal to the expected value
  1029. }
  1030. \endcode
  1031. \sa wolfSSL_CTX_get_verify_depth
  1032. */
  1033. long wolfSSL_get_verify_depth(WOLFSSL* ssl);
  1034. /*!
  1035. \ingroup Setup
  1036. \brief This function gets the certificate chaining depth using the
  1037. CTX structure.
  1038. \return MAX_CHAIN_DEPTH returned if the CTX struct is not NULL. The
  1039. constant representation of the max certificate chain peer depth.
  1040. \return BAD_FUNC_ARG returned if the CTX structure is NULL.
  1041. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1042. wolfSSL_CTX_new().
  1043. _Example_
  1044. \code
  1045. WOLFSSL_METHOD method; // protocol method
  1046. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  1047. long ret = wolfSSL_CTX_get_verify_depth(ctx);
  1048. if(ret == EXPECTED){
  1049. // You have the expected value
  1050. } else {
  1051. // Handle an unexpected depth
  1052. }
  1053. \endcode
  1054. \sa wolfSSL_CTX_use_certificate_chain_file
  1055. \sa wolfSSL_get_verify_depth
  1056. */
  1057. long wolfSSL_CTX_get_verify_depth(WOLFSSL_CTX* ctx);
  1058. /*!
  1059. \ingroup openSSL
  1060. \brief This function loads a certificate file into the SSL session
  1061. (WOLFSSL structure). The certificate file is provided by the file
  1062. argument. The format argument specifies the format type of the file -
  1063. either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1064. \return SSL_SUCCESS upon success
  1065. \return SSL_FAILURE If the function call fails, possible causes might
  1066. include: The file is in the wrong format, or the wrong format has been
  1067. given using the “format” argument, file doesn’t exist, can’t be read,
  1068. or is corrupted, an out of memory condition occurs, Base16 decoding
  1069. fails on the file
  1070. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1071. \param file a pointer to the name of the file containing the certificate to
  1072. be loaded into the wolfSSL SSL session, with format as specified by format.
  1073. \param format the encoding type of the certificate specified by file.
  1074. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1075. _Example_
  1076. \code
  1077. int ret = 0;
  1078. WOLFSSL* ssl;
  1079. ...
  1080. ret = wolfSSL_use_certificate_file(ssl, “./client-cert.pem”,
  1081. SSL_FILETYPE_PEM);
  1082. if (ret != SSL_SUCCESS) {
  1083. // error loading cert file
  1084. }
  1085. ...
  1086. \endcode
  1087. \sa wolfSSL_CTX_use_certificate_buffer
  1088. \sa wolfSSL_CTX_use_certificate_file
  1089. \sa wolfSSL_use_certificate_buffer
  1090. */
  1091. int wolfSSL_use_certificate_file(WOLFSSL* ssl, const char* file, int format);
  1092. /*!
  1093. \ingroup openSSL
  1094. \brief This function loads a private key file into the SSL session
  1095. (WOLFSSL structure). The key file is provided by the file argument.
  1096. The format argument specifies the format type of the file -
  1097. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1098. If using an external key store and do not have the private key you can
  1099. instead provide the public key and register the crypro callback to handle
  1100. the signing. For this you can build with either build with crypto callbacks
  1101. or PK callbacks. To enable crypto callbacks use --enable-cryptocb or
  1102. WOLF_CRYPTO_CB and register a crypto callback using
  1103. wc_CryptoCb_RegisterDevice and set the associated devId using
  1104. wolfSSL_SetDevId.
  1105. \return SSL_SUCCESS upon success.
  1106. \return SSL_FAILURE If the function call fails, possible causes might
  1107. include: The file is in the wrong format, or the wrong format has been
  1108. given using the “format” argument, The file doesn’t exist, can’t be read,
  1109. or is corrupted, An out of memory condition occurs, Base16 decoding
  1110. fails on the file, The key file is encrypted but no password is provided
  1111. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1112. \param file a pointer to the name of the file containing the key file to
  1113. be loaded into the wolfSSL SSL session, with format as specified by format.
  1114. \param format the encoding type of the key specified by file. Possible
  1115. values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1116. _Example_
  1117. \code
  1118. int ret = 0;
  1119. WOLFSSL* ssl;
  1120. ...
  1121. ret = wolfSSL_use_PrivateKey_file(ssl, “./server-key.pem”,
  1122. SSL_FILETYPE_PEM);
  1123. if (ret != SSL_SUCCESS) {
  1124. // error loading key file
  1125. }
  1126. ...
  1127. \endcode
  1128. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1129. \sa wolfSSL_CTX_use_PrivateKey_file
  1130. \sa wolfSSL_use_PrivateKey_buffer
  1131. \sa wc_CryptoCb_RegisterDevice
  1132. \sa wolfSSL_SetDevId
  1133. */
  1134. int wolfSSL_use_PrivateKey_file(WOLFSSL* ssl, const char* file, int format);
  1135. /*!
  1136. \ingroup openSSL
  1137. \brief This function loads a chain of certificates into the SSL
  1138. session (WOLFSSL structure). The file containing the certificate
  1139. chain is provided by the file argument, and must contain PEM-formatted
  1140. certificates. This function will process up to MAX_CHAIN_DEPTH
  1141. (default = 9, defined in internal.h) certificates, plus the
  1142. subject certificate.
  1143. \return SSL_SUCCESS upon success.
  1144. \return SSL_FAILURE If the function call fails, possible causes
  1145. might include: The file is in the wrong format, or the wrong format
  1146. has been given using the “format” argument, file doesn’t exist,
  1147. can’t be read, or is corrupted, an out of memory condition occurs
  1148. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1149. \param file a pointer to the name of the file containing the chain
  1150. of certificates to be loaded into the wolfSSL SSL session.
  1151. Certificates must be in PEM format.
  1152. _Example_
  1153. \code
  1154. int ret = 0;
  1155. WOLFSSL* ctx;
  1156. ...
  1157. ret = wolfSSL_use_certificate_chain_file(ssl, “./cert-chain.pem”);
  1158. if (ret != SSL_SUCCESS) {
  1159. // error loading cert file
  1160. }
  1161. ...
  1162. \endcode
  1163. \sa wolfSSL_CTX_use_certificate_chain_file
  1164. \sa wolfSSL_CTX_use_certificate_chain_buffer
  1165. \sa wolfSSL_use_certificate_chain_buffer
  1166. */
  1167. int wolfSSL_use_certificate_chain_file(WOLFSSL* ssl, const char *file);
  1168. /*!
  1169. \ingroup openSSL
  1170. \brief This function loads the private RSA key used in the SSL
  1171. connection into the SSL session (WOLFSSL structure). This
  1172. function is only available when wolfSSL has been compiled with
  1173. the OpenSSL compatibility layer enabled (--enable-opensslExtra,
  1174. #define OPENSSL_EXTRA), and is identical to the more-typically
  1175. used wolfSSL_use_PrivateKey_file() function. The file argument
  1176. contains a pointer to the RSA private key file, in the format
  1177. specified by format.
  1178. \return SSL_SUCCESS upon success
  1179. \return SSL_FAILURE If the function call fails, possible causes might
  1180. include: The input key file is in the wrong format, or the wrong format
  1181. has been given using the “format” argument, file doesn’t exist, can’t
  1182. be read, or is corrupted, an out of memory condition occurs
  1183. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1184. \param file a pointer to the name of the file containing the RSA private
  1185. key to be loaded into the wolfSSL SSL session, with format as specified
  1186. by format.
  1187. \parm format the encoding type of the RSA private key specified by file.
  1188. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1189. _Example_
  1190. \code
  1191. int ret = 0;
  1192. WOLFSSL* ssl;
  1193. ...
  1194. ret = wolfSSL_use_RSAPrivateKey_file(ssl, “./server-key.pem”,
  1195. SSL_FILETYPE_PEM);
  1196. if (ret != SSL_SUCCESS) {
  1197. // error loading private key file
  1198. }
  1199. ...
  1200. \endcode
  1201. \sa wolfSSL_CTX_use_RSAPrivateKey_file
  1202. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1203. \sa wolfSSL_CTX_use_PrivateKey_file
  1204. \sa wolfSSL_use_PrivateKey_buffer
  1205. \sa wolfSSL_use_PrivateKey_file
  1206. */
  1207. int wolfSSL_use_RSAPrivateKey_file(WOLFSSL* ssl, const char* file, int format);
  1208. /*!
  1209. \ingroup CertsKeys
  1210. \brief This function is similar to wolfSSL_CTX_load_verify_locations,
  1211. but allows the loading of DER-formatted CA files into the SSL context
  1212. (WOLFSSL_CTX). It may still be used to load PEM-formatted CA files as
  1213. well. These certificates will be treated as trusted root certificates
  1214. and used to verify certs received from peers during the SSL handshake.
  1215. The root certificate file, provided by the file argument, may be a single
  1216. certificate or a file containing multiple certificates. If multiple CA
  1217. certs are included in the same file, wolfSSL will load them in the same
  1218. order they are presented in the file. The format argument specifies the
  1219. format which the certificates are in either, SSL_FILETYPE_PEM or
  1220. SSL_FILETYPE_ASN1 (DER). Unlike wolfSSL_CTX_load_verify_locations,
  1221. this function does not allow the loading of CA certificates from a given
  1222. directory path. Note that this function is only available when the wolfSSL
  1223. library was compiled with WOLFSSL_DER_LOAD defined.
  1224. \return SSL_SUCCESS upon success.
  1225. \return SSL_FAILURE upon failure.
  1226. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1227. wolfSSL_CTX_new()
  1228. \param file a pointer to the name of the file containing the CA
  1229. certificates to be loaded into the wolfSSL SSL context, with format
  1230. as specified by format.
  1231. \param format the encoding type of the certificates specified by file.
  1232. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1233. _Example_
  1234. \code
  1235. int ret = 0;
  1236. WOLFSSL_CTX* ctx;
  1237. ...
  1238. ret = wolfSSL_CTX_der_load_verify_locations(ctx, “./ca-cert.der”,
  1239. SSL_FILETYPE_ASN1);
  1240. if (ret != SSL_SUCCESS) {
  1241. // error loading CA certs
  1242. }
  1243. ...
  1244. \endcode
  1245. \sa wolfSSL_CTX_load_verify_locations
  1246. \sa wolfSSL_CTX_load_verify_buffer
  1247. */
  1248. int wolfSSL_CTX_der_load_verify_locations(WOLFSSL_CTX* ctx,
  1249. const char* file, int format);
  1250. /*!
  1251. \ingroup Setup
  1252. \brief This function creates a new SSL context, taking a desired
  1253. SSL/TLS protocol method for input.
  1254. \return pointer If successful the call will return a pointer to the
  1255. newly-created WOLFSSL_CTX.
  1256. \return NULL upon failure.
  1257. \param method pointer to the desired WOLFSSL_METHOD to use for the SSL
  1258. context. This is created using one of the wolfSSLvXX_XXXX_method()
  1259. functions to specify SSL/TLS/DTLS protocol level.
  1260. _Example_
  1261. \code
  1262. WOLFSSL_CTX* ctx = 0;
  1263. WOLFSSL_METHOD* method = 0;
  1264. method = wolfSSLv3_client_method();
  1265. if (method == NULL) {
  1266. // unable to get method
  1267. }
  1268. ctx = wolfSSL_CTX_new(method);
  1269. if (ctx == NULL) {
  1270. // context creation failed
  1271. }
  1272. \endcode
  1273. \sa wolfSSL_new
  1274. */
  1275. WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*);
  1276. /*!
  1277. \ingroup Setup
  1278. \brief This function creates a new SSL session, taking an already
  1279. created SSL context as input.
  1280. \return * If successful the call will return a pointer to the
  1281. newly-created wolfSSL structure.
  1282. \return NULL Upon failure.
  1283. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1284. _Example_
  1285. \code
  1286. #include <wolfssl/ssl.h>
  1287. WOLFSSL* ssl = NULL;
  1288. WOLFSSL_CTX* ctx = 0;
  1289. ctx = wolfSSL_CTX_new(method);
  1290. if (ctx == NULL) {
  1291. // context creation failed
  1292. }
  1293. ssl = wolfSSL_new(ctx);
  1294. if (ssl == NULL) {
  1295. // SSL object creation failed
  1296. }
  1297. \endcode
  1298. \sa wolfSSL_CTX_new
  1299. */
  1300. WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
  1301. /*!
  1302. \ingroup Setup
  1303. \brief This function assigns a file descriptor (fd) as the
  1304. input/output facility for the SSL connection. Typically this will be
  1305. a socket file descriptor.
  1306. \return SSL_SUCCESS upon success.
  1307. \return Bad_FUNC_ARG upon failure.
  1308. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1309. \param fd file descriptor to use with SSL/TLS connection.
  1310. _Example_
  1311. \code
  1312. int sockfd;
  1313. WOLFSSL* ssl = 0;
  1314. ...
  1315. ret = wolfSSL_set_fd(ssl, sockfd);
  1316. if (ret != SSL_SUCCESS) {
  1317. // failed to set SSL file descriptor
  1318. }
  1319. \endcode
  1320. \sa wolfSSL_CTX_SetIOSend
  1321. \sa wolfSSL_CTX_SetIORecv
  1322. \sa wolfSSL_SetIOReadCtx
  1323. \sa wolfSSL_SetIOWriteCtx
  1324. */
  1325. int wolfSSL_set_fd (WOLFSSL* ssl, int fd);
  1326. /*!
  1327. \ingroup IO
  1328. \brief Get the name of cipher at priority level passed in.
  1329. \return string Success
  1330. \return 0 Priority is either out of bounds or not valid.
  1331. \param priority Integer representing the priority level of a cipher.
  1332. _Example_
  1333. \code
  1334. printf("The cipher at 1 is %s", wolfSSL_get_cipher_list(1));
  1335. \endcode
  1336. \sa wolfSSL_CIPHER_get_name
  1337. \sa wolfSSL_get_current_cipher
  1338. */
  1339. char* wolfSSL_get_cipher_list(int priority);
  1340. /*!
  1341. \ingroup IO
  1342. \brief This function gets the ciphers enabled in wolfSSL.
  1343. \return SSL_SUCCESS returned if the function executed without error.
  1344. \return BAD_FUNC_ARG returned if the buf parameter was NULL or if the
  1345. len argument was less than or equal to zero.
  1346. \return BUFFER_E returned if the buffer is not large enough and
  1347. will overflow.
  1348. \param buf a char pointer representing the buffer.
  1349. \param len the length of the buffer.
  1350. _Example_
  1351. \code
  1352. static void ShowCiphers(void){
  1353. char* ciphers;
  1354. int ret = wolfSSL_get_ciphers(ciphers, (int)sizeof(ciphers));
  1355. if(ret == SSL_SUCCES){
  1356. printf(“%s\n”, ciphers);
  1357. }
  1358. }
  1359. \endcode
  1360. \sa GetCipherNames
  1361. \sa wolfSSL_get_cipher_list
  1362. \sa ShowCiphers
  1363. */
  1364. int wolfSSL_get_ciphers(char* buf, int len);
  1365. /*!
  1366. \ingroup IO
  1367. \brief This function gets the cipher name in the format DHE-RSA by
  1368. passing through argument to wolfSSL_get_cipher_name_internal.
  1369. \return string This function returns the string representation of the
  1370. cipher suite that was matched.
  1371. \return NULL error or cipher not found.
  1372. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1373. _Example_
  1374. \code
  1375. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1376. WOLFSSL* ssl = wolfSSL_new(ctx);
  1377. char* cipherS = wolfSSL_get_cipher_name(ssl);
  1378. if(cipher == NULL){
  1379. // There was not a cipher suite matched
  1380. } else {
  1381. // There was a cipher suite matched
  1382. printf(“%s\n”, cipherS);
  1383. }
  1384. \endcode
  1385. \sa wolfSSL_CIPHER_get_name
  1386. \sa wolfSSL_get_current_cipher
  1387. \sa wolfSSL_get_cipher_name_internal
  1388. */
  1389. const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);
  1390. /*!
  1391. \ingroup IO
  1392. \brief This function returns the file descriptor (fd) used as the
  1393. input/output facility for the SSL connection. Typically this
  1394. will be a socket file descriptor.
  1395. \return fd If successful the call will return the SSL session file
  1396. descriptor.
  1397. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1398. _Example_
  1399. \code
  1400. int sockfd;
  1401. WOLFSSL* ssl = 0;
  1402. ...
  1403. sockfd = wolfSSL_get_fd(ssl);
  1404. ...
  1405. \endcode
  1406. \sa wolfSSL_set_fd
  1407. */
  1408. int wolfSSL_get_fd(const WOLFSSL*);
  1409. /*!
  1410. \ingroup Setup
  1411. \brief This function informs the WOLFSSL object that the underlying
  1412. I/O is non-blocking. After an application creates a WOLFSSL object,
  1413. if it will be used with a non-blocking socket, call
  1414. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1415. that receiving EWOULDBLOCK means that the recvfrom call would
  1416. block rather than that it timed out.
  1417. \return none No return.
  1418. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1419. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  1420. Use 1 to specify non-blocking, otherwise 0.
  1421. _Example_
  1422. \code
  1423. WOLFSSL* ssl = 0;
  1424. ...
  1425. wolfSSL_set_using_nonblock(ssl, 1);
  1426. \endcode
  1427. \sa wolfSSL_get_using_nonblock
  1428. \sa wolfSSL_dtls_got_timeout
  1429. \sa wolfSSL_dtls_get_current_timeout
  1430. */
  1431. void wolfSSL_set_using_nonblock(WOLFSSL* ssl, int nonblock);
  1432. /*!
  1433. \ingroup IO
  1434. \brief This function allows the application to determine if wolfSSL is
  1435. using non-blocking I/O. If wolfSSL is using non-blocking I/O, this
  1436. function will return 1, otherwise 0. After an application creates a
  1437. WOLFSSL object, if it will be used with a non-blocking socket, call
  1438. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1439. that receiving EWOULDBLOCK means that the recvfrom call would block
  1440. rather than that it timed out.
  1441. \return 0 underlying I/O is blocking.
  1442. \return 1 underlying I/O is non-blocking.
  1443. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1444. _Example_
  1445. \code
  1446. int ret = 0;
  1447. WOLFSSL* ssl = 0;
  1448. ...
  1449. ret = wolfSSL_get_using_nonblock(ssl);
  1450. if (ret == 1) {
  1451. // underlying I/O is non-blocking
  1452. }
  1453. ...
  1454. \endcode
  1455. \sa wolfSSL_set_session
  1456. */
  1457. int wolfSSL_get_using_nonblock(WOLFSSL*);
  1458. /*!
  1459. \ingroup IO
  1460. \brief This function writes sz bytes from the buffer, data, to the SSL
  1461. connection, ssl. If necessary, wolfSSL_write() will negotiate an SSL/TLS
  1462. session if the handshake has not already been performed yet by
  1463. wolfSSL_connect() or wolfSSL_accept(). wolfSSL_write() works with both
  1464. blocking and non-blocking I/O. When the underlying I/O is non-blocking,
  1465. wolfSSL_write() will return when the underlying I/O could not satisfy the
  1466. needs of wolfSSL_write() to continue. In this case, a call to
  1467. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1468. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call to
  1469. wolfSSL_write() when the underlying I/O is ready. If the underlying I/O
  1470. is blocking, wolfSSL_write() will only return once the buffer data of
  1471. size sz has been completely written or an error occurred.
  1472. \return >0 the number of bytes written upon success.
  1473. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1474. the specific error code.
  1475. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1476. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1477. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1478. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  1479. error code.
  1480. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1481. \param data data buffer which will be sent to peer.
  1482. \param sz size, in bytes, of data to send to the peer (data).
  1483. _Example_
  1484. \code
  1485. WOLFSSL* ssl = 0;
  1486. char msg[64] = “hello wolfssl!”;
  1487. int msgSz = (int)strlen(msg);
  1488. int flags;
  1489. int ret;
  1490. ...
  1491. ret = wolfSSL_write(ssl, msg, msgSz);
  1492. if (ret <= 0) {
  1493. // wolfSSL_write() failed, call wolfSSL_get_error()
  1494. }
  1495. \endcode
  1496. \sa wolfSSL_send
  1497. \sa wolfSSL_read
  1498. \sa wolfSSL_recv
  1499. */
  1500. int wolfSSL_write(WOLFSSL* ssl, const void* data, int sz);
  1501. /*!
  1502. \ingroup IO
  1503. \brief This function reads sz bytes from the SSL session (ssl)
  1504. internal read buffer into the buffer data. The bytes read are removed
  1505. from the internal receive buffer. If necessary wolfSSL_read() will
  1506. negotiate an SSL/TLS session if the handshake has not already been
  1507. performed yet by wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS
  1508. protocol uses SSL records which have a maximum size of 16kB (the max
  1509. record size can be controlled by the MAX_RECORD_SIZE define in
  1510. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1511. entire SSL record internally before it is able to process and decrypt the
  1512. record. Because of this, a call to wolfSSL_read() will only be able to
  1513. return the maximum buffer size which has been decrypted at the time of
  1514. calling. There may be additional not-yet-decrypted data waiting in the
  1515. internal wolfSSL receive buffer which will be retrieved and decrypted with
  1516. the next call to wolfSSL_read(). If sz is larger than the number of bytes
  1517. in the internal read buffer, SSL_read() will return the bytes available in
  1518. the internal read buffer. If no bytes are buffered in the internal read
  1519. buffer yet, a call to wolfSSL_read() will trigger processing of the next
  1520. record.
  1521. \return >0 the number of bytes read upon success.
  1522. \return 0 will be returned upon failure. This may be caused by a either a
  1523. clean (close notify alert) shutdown or just that the peer closed the
  1524. connection. Call wolfSSL_get_error() for the specific error code.
  1525. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1526. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1527. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1528. call wolfSSL_read() again. Use wolfSSL_get_error() to get a specific
  1529. error code.
  1530. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1531. \param data buffer where wolfSSL_read() will place data read.
  1532. \param sz number of bytes to read into data.
  1533. _Example_
  1534. \code
  1535. WOLFSSL* ssl = 0;
  1536. char reply[1024];
  1537. ...
  1538. input = wolfSSL_read(ssl, reply, sizeof(reply));
  1539. if (input > 0) {
  1540. // “input” number of bytes returned into buffer “reply”
  1541. }
  1542. See wolfSSL examples (client, server, echoclient, echoserver) for more
  1543. complete examples of wolfSSL_read().
  1544. \endcode
  1545. \sa wolfSSL_recv
  1546. \sa wolfSSL_write
  1547. \sa wolfSSL_peek
  1548. \sa wolfSSL_pending
  1549. */
  1550. int wolfSSL_read(WOLFSSL* ssl, void* data, int sz);
  1551. /*!
  1552. \ingroup IO
  1553. \brief This function copies sz bytes from the SSL session (ssl) internal
  1554. read buffer into the buffer data. This function is identical to
  1555. wolfSSL_read() except that the data in the internal SSL session
  1556. receive buffer is not removed or modified. If necessary, like
  1557. wolfSSL_read(), wolfSSL_peek() will negotiate an SSL/TLS session if
  1558. the handshake has not already been performed yet by wolfSSL_connect()
  1559. or wolfSSL_accept(). The SSL/TLS protocol uses SSL records which have a
  1560. maximum size of 16kB (the max record size can be controlled by the
  1561. MAX_RECORD_SIZE define in <wolfssl_root>/wolfssl/internal.h). As such,
  1562. wolfSSL needs to read an entire SSL record internally before it is able
  1563. to process and decrypt the record. Because of this, a call to
  1564. wolfSSL_peek() will only be able to return the maximum buffer size which
  1565. has been decrypted at the time of calling. There may be additional
  1566. not-yet-decrypted data waiting in the internal wolfSSL receive buffer
  1567. which will be retrieved and decrypted with the next call to
  1568. wolfSSL_peek() / wolfSSL_read(). If sz is larger than the number of bytes
  1569. in the internal read buffer, SSL_peek() will return the bytes available
  1570. in the internal read buffer. If no bytes are buffered in the internal
  1571. read buffer yet, a call to wolfSSL_peek() will trigger processing of the
  1572. next record.
  1573. \return >0 the number of bytes read upon success.
  1574. \return 0 will be returned upon failure. This may be caused by a either
  1575. a clean (close notify alert) shutdown or just that the peer closed the
  1576. connection. Call wolfSSL_get_error() for the specific error code.
  1577. \return SSL_FATAL_ERROR will be returned upon failure when either an
  1578. error occurred or, when using non-blocking sockets, the
  1579. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and and
  1580. the application needs to call wolfSSL_peek() again. Use
  1581. wolfSSL_get_error() to get a specific error code.
  1582. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1583. \param data buffer where wolfSSL_peek() will place data read.
  1584. \param sz number of bytes to read into data.
  1585. _Example_
  1586. \code
  1587. WOLFSSL* ssl = 0;
  1588. char reply[1024];
  1589. ...
  1590. input = wolfSSL_peek(ssl, reply, sizeof(reply));
  1591. if (input > 0) {
  1592. // “input” number of bytes returned into buffer “reply”
  1593. }
  1594. \endcode
  1595. \sa wolfSSL_read
  1596. */
  1597. int wolfSSL_peek(WOLFSSL* ssl, void* data, int sz);
  1598. /*!
  1599. \ingroup IO
  1600. \brief This function is called on the server side and waits for an SSL
  1601. client to initiate the SSL/TLS handshake. When this function is called,
  1602. the underlying communication channel has already been set up.
  1603. wolfSSL_accept() works with both blocking and non-blocking I/O.
  1604. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  1605. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  1606. to continue the handshake. In this case, a call to wolfSSL_get_error()
  1607. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1608. The calling process must then repeat the call to wolfSSL_accept when
  1609. data is available to read and wolfSSL will pick up where it left off.
  1610. When using a non-blocking socket, nothing needs to be done, but select()
  1611. can be used to check for the required condition. If the underlying I/O
  1612. is blocking, wolfSSL_accept() will only return once the handshake has
  1613. been finished or an error occurred.
  1614. \return SSL_SUCCESS upon success.
  1615. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  1616. more detailed error code, call wolfSSL_get_error().
  1617. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1618. _Example_
  1619. \code
  1620. int ret = 0;
  1621. int err = 0;
  1622. WOLFSSL* ssl;
  1623. char buffer[80];
  1624. ...
  1625. ret = wolfSSL_accept(ssl);
  1626. if (ret != SSL_SUCCESS) {
  1627. err = wolfSSL_get_error(ssl, ret);
  1628. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  1629. }
  1630. \endcode
  1631. \sa wolfSSL_get_error
  1632. \sa wolfSSL_connect
  1633. */
  1634. int wolfSSL_accept(WOLFSSL*);
  1635. /*!
  1636. \ingroup Setup
  1637. \brief This function frees an allocated WOLFSSL_CTX object. This
  1638. function decrements the CTX reference count and only frees the context
  1639. when the reference count has reached 0.
  1640. \return none No return.
  1641. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1642. _Example_
  1643. \code
  1644. WOLFSSL_CTX* ctx = 0;
  1645. ...
  1646. wolfSSL_CTX_free(ctx);
  1647. \endcode
  1648. \sa wolfSSL_CTX_new
  1649. \sa wolfSSL_new
  1650. \sa wolfSSL_free
  1651. */
  1652. void wolfSSL_CTX_free(WOLFSSL_CTX*);
  1653. /*!
  1654. \ingroup Setup
  1655. \brief This function frees an allocated wolfSSL object.
  1656. \return none No return.
  1657. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1658. _Example_
  1659. \code
  1660. #include <wolfssl/ssl.h>
  1661. WOLFSSL* ssl = 0;
  1662. ...
  1663. wolfSSL_free(ssl);
  1664. \endcode
  1665. \sa wolfSSL_CTX_new
  1666. \sa wolfSSL_new
  1667. \sa wolfSSL_CTX_free
  1668. */
  1669. void wolfSSL_free(WOLFSSL*);
  1670. /*!
  1671. \ingroup TLS
  1672. \brief This function shuts down an active SSL/TLS connection using
  1673. the SSL session, ssl. This function will try to send a “close notify”
  1674. alert to the peer. The calling application can choose to wait for the
  1675. peer to send its “close notify” alert in response or just go ahead
  1676. and shut down the underlying connection after directly calling
  1677. wolfSSL_shutdown (to save resources). Either option is allowed by
  1678. the TLS specification. If the underlying connection will be used
  1679. again in the future, the complete two-directional shutdown procedure
  1680. must be performed to keep synchronization intact between the peers.
  1681. wolfSSL_shutdown() works with both blocking and non-blocking I/O.
  1682. When the underlying I/O is non-blocking, wolfSSL_shutdown() will
  1683. return an error if the underlying I/O could not satisfy the needs of
  1684. wolfSSL_shutdown() to continue. In this case, a call to
  1685. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1686. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call
  1687. to wolfSSL_shutdown() when the underlying I/O is ready.
  1688. \return SSL_SUCCESS will be returned upon success.
  1689. \return SSL_SHUTDOWN_NOT_DONE will be returned when shutdown has not
  1690. finished, and the function should be called again.
  1691. \return SSL_FATAL_ERROR will be returned upon failure. Call
  1692. wolfSSL_get_error() for a more specific error code.
  1693. \param ssl pointer to the SSL session created with wolfSSL_new().
  1694. _Example_
  1695. \code
  1696. #include <wolfssl/ssl.h>
  1697. int ret = 0;
  1698. WOLFSSL* ssl = 0;
  1699. ...
  1700. ret = wolfSSL_shutdown(ssl);
  1701. if (ret != 0) {
  1702. // failed to shut down SSL connection
  1703. }
  1704. \endcode
  1705. \sa wolfSSL_free
  1706. \sa wolfSSL_CTX_free
  1707. */
  1708. int wolfSSL_shutdown(WOLFSSL*);
  1709. /*!
  1710. \ingroup IO
  1711. \brief This function writes sz bytes from the buffer, data, to the SSL
  1712. connection, ssl, using the specified flags for the underlying write
  1713. operation. If necessary wolfSSL_send() will negotiate an SSL/TLS session
  1714. if the handshake has not already been performed yet by wolfSSL_connect()
  1715. or wolfSSL_accept(). wolfSSL_send() works with both blocking and
  1716. non-blocking I/O. When the underlying I/O is non-blocking, wolfSSL_send()
  1717. will return when the underlying I/O could not satisfy the needs of
  1718. wolfSSL_send to continue. In this case, a call to wolfSSL_get_error()
  1719. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1720. The calling process must then repeat the call to wolfSSL_send() when
  1721. the underlying I/O is ready. If the underlying I/O is blocking,
  1722. wolfSSL_send() will only return once the buffer data of size sz has
  1723. been completely written or an error occurred.
  1724. \return >0 the number of bytes written upon success.
  1725. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1726. the specific error code.
  1727. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1728. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1729. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1730. call wolfSSL_send() again. Use wolfSSL_get_error() to get a specific
  1731. error code.
  1732. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1733. \param data data buffer to send to peer.
  1734. \param sz size, in bytes, of data to be sent to peer.
  1735. \param flags the send flags to use for the underlying send operation.
  1736. _Example_
  1737. \code
  1738. WOLFSSL* ssl = 0;
  1739. char msg[64] = “hello wolfssl!”;
  1740. int msgSz = (int)strlen(msg);
  1741. int flags = ... ;
  1742. ...
  1743. input = wolfSSL_send(ssl, msg, msgSz, flags);
  1744. if (input != msgSz) {
  1745. // wolfSSL_send() failed
  1746. }
  1747. \endcode
  1748. \sa wolfSSL_write
  1749. \sa wolfSSL_read
  1750. \sa wolfSSL_recv
  1751. */
  1752. int wolfSSL_send(WOLFSSL* ssl, const void* data, int sz, int flags);
  1753. /*!
  1754. \ingroup IO
  1755. \brief This function reads sz bytes from the SSL session (ssl) internal
  1756. read buffer into the buffer data using the specified flags for the
  1757. underlying recv operation. The bytes read are removed from the internal
  1758. receive buffer. This function is identical to wolfSSL_read() except
  1759. that it allows the application to set the recv flags for the underlying
  1760. read operation. If necessary wolfSSL_recv() will negotiate an SSL/TLS
  1761. session if the handshake has not already been performed yet by
  1762. wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS protocol uses
  1763. SSL records which have a maximum size of 16kB (the max record size
  1764. can be controlled by the MAX_RECORD_SIZE define in
  1765. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1766. entire SSL record internally before it is able to process and decrypt
  1767. the record. Because of this, a call to wolfSSL_recv() will only be
  1768. able to return the maximum buffer size which has been decrypted at
  1769. the time of calling. There may be additional not-yet-decrypted data
  1770. waiting in the internal wolfSSL receive buffer which will be
  1771. retrieved and decrypted with the next call to wolfSSL_recv(). If sz
  1772. is larger than the number of bytes in the internal read buffer,
  1773. SSL_recv() will return the bytes available in the internal read buffer.
  1774. If no bytes are buffered in the internal read buffer yet, a call to
  1775. wolfSSL_recv() will trigger processing of the next record.
  1776. \return >0 the number of bytes read upon success.
  1777. \return 0 will be returned upon failure. This may be caused by a either
  1778. a clean (close notify alert) shutdown or just that the peer closed the
  1779. connection. Call wolfSSL_get_error() for the specific error code.
  1780. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1781. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1782. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1783. call wolfSSL_recv() again. Use wolfSSL_get_error() to get a specific
  1784. error code.
  1785. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1786. \param data buffer where wolfSSL_recv() will place data read.
  1787. \param sz number of bytes to read into data.
  1788. \param flags the recv flags to use for the underlying recv operation.
  1789. _Example_
  1790. \code
  1791. WOLFSSL* ssl = 0;
  1792. char reply[1024];
  1793. int flags = ... ;
  1794. ...
  1795. input = wolfSSL_recv(ssl, reply, sizeof(reply), flags);
  1796. if (input > 0) {
  1797. // “input” number of bytes returned into buffer “reply”
  1798. }
  1799. \endcode
  1800. \sa wolfSSL_read
  1801. \sa wolfSSL_write
  1802. \sa wolfSSL_peek
  1803. \sa wolfSSL_pending
  1804. */
  1805. int wolfSSL_recv(WOLFSSL* ssl, void* data, int sz, int flags);
  1806. /*!
  1807. \ingroup Debug
  1808. \brief This function returns a unique error code describing why the
  1809. previous API function call (wolfSSL_connect, wolfSSL_accept, wolfSSL_read,
  1810. wolfSSL_write, etc.) resulted in an error return code (SSL_FAILURE).
  1811. The return value of the previous function is passed to wolfSSL_get_error
  1812. through ret. After wolfSSL_get_error is called and returns the unique
  1813. error code, wolfSSL_ERR_error_string() may be called to get a
  1814. human-readable error string. See wolfSSL_ERR_error_string() for more
  1815. information.
  1816. \return On successful completion, this function will return the
  1817. unique error code describing why the previous API function failed.
  1818. \return SSL_ERROR_NONE will be returned if ret > 0. For ret <= 0, there are
  1819. some cases when this value can also be returned when a previous API appeared
  1820. to return an error code but no error actually occurred. An example is
  1821. calling wolfSSL_read() with a zero sz parameter. A 0 return from
  1822. wolfSSL_read() usually indicates an error but in this case no error
  1823. occurred. If wolfSSL_get_error() is called afterwards, SSL_ERROR_NONE will
  1824. be returned.
  1825. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1826. \param ret return value of the previous function that resulted in an error
  1827. return code.
  1828. _Example_
  1829. \code
  1830. int err = 0;
  1831. WOLFSSL* ssl;
  1832. char buffer[80];
  1833. ...
  1834. err = wolfSSL_get_error(ssl, 0);
  1835. wolfSSL_ERR_error_string(err, buffer);
  1836. printf(“err = %d, %s\n”, err, buffer);
  1837. \endcode
  1838. \sa wolfSSL_ERR_error_string
  1839. \sa wolfSSL_ERR_error_string_n
  1840. \sa wolfSSL_ERR_print_errors_fp
  1841. \sa wolfSSL_load_error_strings
  1842. */
  1843. int wolfSSL_get_error(WOLFSSL* ssl, int ret);
  1844. /*!
  1845. \ingroup IO
  1846. \brief This function gets the alert history.
  1847. \return SSL_SUCCESS returned when the function completed successfully.
  1848. Either there was alert history or there wasn’t, either way, the
  1849. return value is SSL_SUCCESS.
  1850. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1851. \param h a pointer to a WOLFSSL_ALERT_HISTORY structure that will hold the
  1852. WOLFSSL struct’s alert_history member’s value.
  1853. _Example_
  1854. \code
  1855. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  1856. WOLFSSL* ssl = wolfSSL_new(ctx);
  1857. WOLFSSL_ALERT_HISTORY* h;
  1858. ...
  1859. wolfSSL_get_alert_history(ssl, h);
  1860. // h now has a copy of the ssl->alert_history contents
  1861. \endcode
  1862. \sa wolfSSL_get_error
  1863. */
  1864. int wolfSSL_get_alert_history(WOLFSSL* ssl, WOLFSSL_ALERT_HISTORY *h);
  1865. /*!
  1866. \ingroup Setup
  1867. \brief This function sets the session to be used when the SSL object,
  1868. ssl, is used to establish a SSL/TLS connection. For session resumption,
  1869. before calling wolfSSL_shutdown() with your session object, an application
  1870. should save the session ID from the object with a call to
  1871. wolfSSL_get1_session(), which returns a pointer to the session.
  1872. Later, the application should create a new WOLFSSL object and assign
  1873. the saved session with wolfSSL_set_session(). At this point, the
  1874. application may call wolfSSL_connect() and wolfSSL will try to resume
  1875. the session. The wolfSSL server code allows session resumption by default.
  1876. The object returned by wolfSSL_get1_session() needs to be freed after the
  1877. application is done with it by calling wolfSSL_SESSION_free() on it.
  1878. \return SSL_SUCCESS will be returned upon successfully setting the session.
  1879. \return SSL_FAILURE will be returned on failure. This could be caused
  1880. by the session cache being disabled, or if the session has timed out.
  1881. \return When OPENSSL_EXTRA and WOLFSSL_ERROR_CODE_OPENSSL are defined,
  1882. SSL_SUCCESS will be returned even if the session has timed out.
  1883. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1884. \param session pointer to the WOLFSSL_SESSION used to set the session
  1885. for ssl.
  1886. _Example_
  1887. \code
  1888. int ret;
  1889. WOLFSSL* ssl;
  1890. WOLFSSL_SESSION* session;
  1891. ...
  1892. session = wolfSSL_get1_session(ssl);
  1893. if (session == NULL) {
  1894. // failed to get session object from ssl object
  1895. }
  1896. ...
  1897. ret = wolfSSL_set_session(ssl, session);
  1898. if (ret != SSL_SUCCESS) {
  1899. // failed to set the SSL session
  1900. }
  1901. wolfSSL_SESSION_free(session);
  1902. ...
  1903. \endcode
  1904. \sa wolfSSL_get1_session
  1905. */
  1906. int wolfSSL_set_session(WOLFSSL* ssl, WOLFSSL_SESSION* session);
  1907. /*!
  1908. \ingroup IO
  1909. \brief When NO_SESSION_CACHE_REF is defined this function returns a pointer
  1910. to the current session (WOLFSSL_SESSION) used in ssl. This function returns
  1911. a non-persistent pointer to the WOLFSSL_SESSION object. The pointer returned
  1912. will be freed when wolfSSL_free is called. This call should only be used to
  1913. inspect or modify the current session. For session resumption it is
  1914. recommended to use wolfSSL_get1_session(). For backwards compatibility when
  1915. NO_SESSION_CACHE_REF is not defined this function returns a persistent
  1916. session object pointer that is stored in the local cache. The cache size is
  1917. finite and there is a risk that the session object will be overwritten by
  1918. another ssl connection by the time the application calls
  1919. wolfSSL_set_session() on it. It is recommended to define
  1920. NO_SESSION_CACHE_REF in your application and to use wolfSSL_get1_session()
  1921. for session resumption.
  1922. \return pointer If successful the call will return a pointer to the the
  1923. current SSL session object.
  1924. \return NULL will be returned if ssl is NULL, the SSL session cache is
  1925. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  1926. functions fail.
  1927. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1928. _Example_
  1929. \code
  1930. WOLFSSL* ssl;
  1931. WOLFSSL_SESSION* session;
  1932. ...
  1933. session = wolfSSL_get_session(ssl);
  1934. if (session == NULL) {
  1935. // failed to get session pointer
  1936. }
  1937. ...
  1938. \endcode
  1939. \sa wolfSSL_get1_session
  1940. \sa wolfSSL_set_session
  1941. */
  1942. WOLFSSL_SESSION* wolfSSL_get_session(WOLFSSL* ssl);
  1943. /*!
  1944. \ingroup IO
  1945. \brief This function flushes session from the session cache which
  1946. have expired. The time, tm, is used for the time comparison. Note
  1947. that wolfSSL currently uses a static table for sessions, so no flushing
  1948. is needed. As such, this function is currently just a stub. This
  1949. function provides OpenSSL compatibility (SSL_flush_sessions) when
  1950. wolfSSL is compiled with the OpenSSL compatibility layer.
  1951. \return none No returns.
  1952. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1953. wolfSSL_CTX_new().
  1954. \param tm time used in session expiration comparison.
  1955. _Example_
  1956. \code
  1957. WOLFSSL_CTX* ssl;
  1958. ...
  1959. wolfSSL_flush_sessions(ctx, time(0));
  1960. \endcode
  1961. \sa wolfSSL_get1_session
  1962. \sa wolfSSL_set_session
  1963. */
  1964. void wolfSSL_flush_sessions(WOLFSSL_CTX* ctx, long tm);
  1965. /*!
  1966. \ingroup TLS
  1967. \brief This function associates the client session with the server id.
  1968. If the newSession flag is on, an existing session won’t be reused.
  1969. \return SSL_SUCCESS returned if the function executed without error.
  1970. \return BAD_FUNC_ARG returned if the WOLFSSL struct or id parameter
  1971. is NULL or if len is not greater than zero.
  1972. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1973. \param id a constant byte pointer that will be copied to the
  1974. serverID member of the WOLFSSL_SESSION structure.
  1975. \param len an int type representing the length of the session id parameter.
  1976. \param newSession an int type representing the flag to denote whether
  1977. to reuse a session or not.
  1978. _Example_
  1979. \code
  1980. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol );
  1981. WOLFSSL* ssl = WOLFSSL_new(ctx);
  1982. const byte id[MAX_SIZE]; // or dynamically create space
  1983. int len = 0; // initialize length
  1984. int newSession = 0; // flag to allow
  1985. int ret = wolfSSL_SetServerID(ssl, id, len, newSession);
  1986. if (ret == WOLFSSL_SUCCESS) {
  1987. // The Id was successfully set
  1988. }
  1989. \endcode
  1990. \sa wolfSSL_set_session
  1991. */
  1992. int wolfSSL_SetServerID(WOLFSSL* ssl, const unsigned char* id,
  1993. int len, int newSession);
  1994. /*!
  1995. \ingroup IO
  1996. \brief This function gets the session index of the WOLFSSL structure.
  1997. \return int The function returns an int type representing the
  1998. sessionIndex within the WOLFSSL struct.
  1999. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2000. _Example_
  2001. \code
  2002. WOLFSSL_CTX_new( protocol method );
  2003. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2004. ...
  2005. int sesIdx = wolfSSL_GetSessionIndex(ssl);
  2006. if(sesIdx < 0 || sesIdx > sizeof(ssl->sessionIndex)/sizeof(int)){
  2007. // You have an out of bounds index number and something is not right.
  2008. }
  2009. \endcode
  2010. \sa wolfSSL_GetSessionAtIndex
  2011. */
  2012. int wolfSSL_GetSessionIndex(WOLFSSL* ssl);
  2013. /*!
  2014. \ingroup IO
  2015. \brief This function gets the session at specified index of the session
  2016. cache and copies it into memory. The WOLFSSL_SESSION structure holds
  2017. the session information.
  2018. \return SSL_SUCCESS returned if the function executed successfully and
  2019. no errors were thrown.
  2020. \return BAD_MUTEX_E returned if there was an unlock or lock mutex error.
  2021. \return SSL_FAILURE returned if the function did not execute successfully.
  2022. \param idx an int type representing the session index.
  2023. \param session a pointer to the WOLFSSL_SESSION structure.
  2024. _Example_
  2025. \code
  2026. int idx; // The index to locate the session.
  2027. WOLFSSL_SESSION* session; // Buffer to copy to.
  2028. ...
  2029. if(wolfSSL_GetSessionAtIndex(idx, session) != SSL_SUCCESS){
  2030. // Failure case.
  2031. }
  2032. \endcode
  2033. \sa UnLockMutex
  2034. \sa LockMutex
  2035. \sa wolfSSL_GetSessionIndex
  2036. */
  2037. int wolfSSL_GetSessionAtIndex(int index, WOLFSSL_SESSION* session);
  2038. /*!
  2039. \ingroup IO
  2040. \brief Returns the peer certificate chain from the WOLFSSL_SESSION struct.
  2041. \return pointer A pointer to a WOLFSSL_X509_CHAIN structure that
  2042. contains the peer certification chain.
  2043. \param session a pointer to a WOLFSSL_SESSION structure.
  2044. _Example_
  2045. \code
  2046. WOLFSSL_SESSION* session;
  2047. WOLFSSL_X509_CHAIN* chain;
  2048. ...
  2049. chain = wolfSSL_SESSION_get_peer_chain(session);
  2050. if(!chain){
  2051. // There was no chain. Failure case.
  2052. }
  2053. \endcode
  2054. \sa wolfSSL_GetSessionAtIndex
  2055. \sa wolfSSL_GetSessionIndex
  2056. \sa AddSession
  2057. */
  2058. WOLFSSL_X509_CHAIN* wolfSSL_SESSION_get_peer_chain(WOLFSSL_SESSION* session);
  2059. /*!
  2060. \ingroup Setup
  2061. \brief This function sets the verification method for remote peers and
  2062. also allows a verify callback to be registered with the SSL context.
  2063. The verify callback will be called only when a verification failure has
  2064. occurred. If no verify callback is desired, the NULL pointer can be used
  2065. for verify_callback. The verification mode of peer certificates is a
  2066. logically OR’d list of flags. The possible flag values include:
  2067. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2068. received from the server and the handshake will continue as normal.
  2069. Server mode: the server will not send a certificate request to the client.
  2070. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2071. mode: the client will verify the certificate received from the server
  2072. during the handshake. This is turned on by default in wolfSSL, therefore,
  2073. using this option has no effect. Server mode: the server will send a
  2074. certificate request to the client and verify the client certificate
  2075. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2076. used on the client side. Server mode: the verification will fail on the
  2077. server side if the client fails to send a certificate when requested to
  2078. do so (when using SSL_VERIFY_PEER on the SSL server).
  2079. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2080. side. Server mode: the verification is the same as
  2081. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2082. If a PSK connection is being made then the connection will go through
  2083. without a peer cert.
  2084. \return none No return.
  2085. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2086. \param mode session timeout value in seconds
  2087. \param verify_callback callback to be called when verification fails.
  2088. If no callback is desired, the NULL pointer can be used for
  2089. verify_callback.
  2090. _Example_
  2091. \code
  2092. WOLFSSL_CTX* ctx = 0;
  2093. ...
  2094. wolfSSL_CTX_set_verify(ctx, (WOLFSSL_VERIFY_PEER |
  2095. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT), NULL);
  2096. \endcode
  2097. \sa wolfSSL_set_verify
  2098. */
  2099. void wolfSSL_CTX_set_verify(WOLFSSL_CTX* ctx, int mode,
  2100. VerifyCallback verify_callback);
  2101. /*!
  2102. \ingroup Setup
  2103. \brief This function sets the verification method for remote peers and
  2104. also allows a verify callback to be registered with the SSL session.
  2105. The verify callback will be called only when a verification failure has
  2106. occurred. If no verify callback is desired, the NULL pointer can be used
  2107. for verify_callback. The verification mode of peer certificates is a
  2108. logically OR’d list of flags. The possible flag values include:
  2109. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2110. received from the server and the handshake will continue as normal. Server
  2111. mode: the server will not send a certificate request to the client.
  2112. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2113. mode: the client will verify the certificate received from the server
  2114. during the handshake. This is turned on by default in wolfSSL, therefore,
  2115. using this option has no effect. Server mode: the server will send a
  2116. certificate request to the client and verify the client certificate
  2117. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2118. used on the client side. Server mode: the verification will fail on the
  2119. server side if the client fails to send a certificate when requested to do
  2120. so (when using SSL_VERIFY_PEER on the SSL server).
  2121. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2122. side. Server mode: the verification is the same as
  2123. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2124. If a PSK connection is being made then the connection will go through
  2125. without a peer cert.
  2126. \return none No return.
  2127. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2128. \param mode session timeout value in seconds.
  2129. \param verify_callback callback to be called when verification fails.
  2130. If no callback is desired, the NULL pointer can
  2131. be used for verify_callback.
  2132. _Example_
  2133. \code
  2134. WOLFSSL* ssl = 0;
  2135. ...
  2136. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  2137. \endcode
  2138. \sa wolfSSL_CTX_set_verify
  2139. */
  2140. void wolfSSL_set_verify(WOLFSSL* ssl, int mode, VerifyCallback verify_callback);
  2141. /*!
  2142. \ingroup CertsKeys
  2143. \brief This function stores user CTX object information for verify callback.
  2144. \return none No return.
  2145. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2146. \param ctx a void pointer that is set to WOLFSSL structure’s verifyCbCtx
  2147. member’s value.
  2148. _Example_
  2149. \code
  2150. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2151. WOLFSSL* ssl = wolfSSL_new(ctx);
  2152. (void*)ctx;
  2153. ...
  2154. if(ssl != NULL){
  2155. wolfSSL_SetCertCbCtx(ssl, ctx);
  2156. } else {
  2157. // Error case, the SSL is not initialized properly.
  2158. }
  2159. \endcode
  2160. \sa wolfSSL_CTX_save_cert_cache
  2161. \sa wolfSSL_CTX_restore_cert_cache
  2162. \sa wolfSSL_CTX_set_verify
  2163. */
  2164. void wolfSSL_SetCertCbCtx(WOLFSSL* ssl, void* ctx);
  2165. /*!
  2166. \ingroup CertsKeys
  2167. \brief This function stores user CTX object information for verify callback.
  2168. \return none No return.
  2169. \param ctx a pointer to a WOLFSSL_CTX structure.
  2170. \param userCtx a void pointer that is used to set WOLFSSL_CTX structure’s
  2171. verifyCbCtx member’s value.
  2172. _Example_
  2173. \code
  2174. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2175. void* userCtx = NULL; // Assign some user defined context
  2176. ...
  2177. if(ctx != NULL){
  2178. wolfSSL_SetCertCbCtx(ctx, userCtx);
  2179. } else {
  2180. // Error case, the SSL is not initialized properly.
  2181. }
  2182. \endcode
  2183. \sa wolfSSL_CTX_save_cert_cache
  2184. \sa wolfSSL_CTX_restore_cert_cache
  2185. \sa wolfSSL_CTX_set_verify
  2186. */
  2187. void wolfSSL_CTX_SetCertCbCtx(WOLFSSL_CTX* ctx, void* userCtx);
  2188. /*!
  2189. \ingroup IO
  2190. \brief This function returns the number of bytes which are buffered and
  2191. available in the SSL object to be read by wolfSSL_read().
  2192. \return int This function returns the number of bytes pending.
  2193. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2194. _Example_
  2195. \code
  2196. int pending = 0;
  2197. WOLFSSL* ssl = 0;
  2198. ...
  2199. pending = wolfSSL_pending(ssl);
  2200. printf(“There are %d bytes buffered and available for reading”, pending);
  2201. \endcode
  2202. \sa wolfSSL_recv
  2203. \sa wolfSSL_read
  2204. \sa wolfSSL_peek
  2205. */
  2206. int wolfSSL_pending(WOLFSSL*);
  2207. /*!
  2208. \ingroup Debug
  2209. \brief This function is for OpenSSL compatibility (SSL_load_error_string)
  2210. only and takes no action.
  2211. \return none No returns.
  2212. \param none No parameters.
  2213. _Example_
  2214. \code
  2215. wolfSSL_load_error_strings();
  2216. \endcode
  2217. \sa wolfSSL_get_error
  2218. \sa wolfSSL_ERR_error_string
  2219. \sa wolfSSL_ERR_error_string_n
  2220. \sa wolfSSL_ERR_print_errors_fp
  2221. \sa wolfSSL_load_error_strings
  2222. */
  2223. void wolfSSL_load_error_strings(void);
  2224. /*!
  2225. \ingroup TLS
  2226. \brief This function is called internally in wolfSSL_CTX_new(). This
  2227. function is a wrapper around wolfSSL_Init() and exists for OpenSSL
  2228. compatibility (SSL_library_init) when wolfSSL has been compiled with
  2229. OpenSSL compatibility layer. wolfSSL_Init() is the more typically-used
  2230. wolfSSL initialization function.
  2231. \return SSL_SUCCESS If successful the call will return.
  2232. \return SSL_FATAL_ERROR is returned upon failure.
  2233. \param none No parameters.
  2234. _Example_
  2235. \code
  2236. int ret = 0;
  2237. ret = wolfSSL_library_init();
  2238. if (ret != SSL_SUCCESS) {
  2239. failed to initialize wolfSSL
  2240. }
  2241. ...
  2242. \endcode
  2243. \sa wolfSSL_Init
  2244. \sa wolfSSL_Cleanup
  2245. */
  2246. int wolfSSL_library_init(void);
  2247. /*!
  2248. \brief This function sets the Device Id at the WOLFSSL session level.
  2249. \return WOLFSSL_SUCCESS upon success.
  2250. \return BAD_FUNC_ARG if ssl is NULL.
  2251. \param ssl pointer to a SSL object, created with wolfSSL_new().
  2252. \param devId ID to use with async hardware
  2253. _Example_
  2254. \code
  2255. WOLFSSL* ssl;
  2256. int DevId = -2;
  2257. wolfSSL_SetDevId(ssl, devId);
  2258. \endcode
  2259. \sa wolfSSL_CTX_SetDevId
  2260. \sa wolfSSL_CTX_GetDevId
  2261. */
  2262. int wolfSSL_SetDevId(WOLFSSL* ssl, int devId);
  2263. /*!
  2264. \brief This function sets the Device Id at the WOLFSSL_CTX context level.
  2265. \return WOLFSSL_SUCCESS upon success.
  2266. \return BAD_FUNC_ARG if ssl is NULL.
  2267. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2268. \param devId ID to use with async hardware
  2269. _Example_
  2270. \code
  2271. WOLFSSL_CTX* ctx;
  2272. int DevId = -2;
  2273. wolfSSL_CTX_SetDevId(ctx, devId);
  2274. \endcode
  2275. \sa wolfSSL_SetDevId
  2276. \sa wolfSSL_CTX_GetDevId
  2277. */
  2278. int wolfSSL_CTX_SetDevId(WOLFSSL_CTX* ctx, int devId);
  2279. /*!
  2280. \brief This function retrieves the Device Id.
  2281. \return devId upon success.
  2282. \return INVALID_DEVID if both ssl and ctx are NULL.
  2283. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2284. \param ssl pointer to a SSL object, created with wolfSSL_new().
  2285. _Example_
  2286. \code
  2287. WOLFSSL_CTX* ctx;
  2288. wolfSSL_CTX_GetDevId(ctx, ssl);
  2289. \endcode
  2290. \sa wolfSSL_SetDevId
  2291. \sa wolfSSL_CTX_SetDevId
  2292. */
  2293. int wolfSSL_CTX_GetDevId(WOLFSSL_CTX* ctx, WOLFSSL* ssl);
  2294. /*!
  2295. \ingroup Setup
  2296. \brief This function enables or disables SSL session caching.
  2297. Behavior depends on the value used for mode. The following values
  2298. for mode are available: SSL_SESS_CACHE_OFF- disable session caching.
  2299. Session caching is turned on by default. SSL_SESS_CACHE_NO_AUTO_CLEAR -
  2300. Disable auto-flushing of the session cache. Auto-flushing is turned on
  2301. by default.
  2302. \return SSL_SUCCESS will be returned upon success.
  2303. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2304. \param mode modifier used to change behavior of the session cache.
  2305. _Example_
  2306. \code
  2307. WOLFSSL_CTX* ctx = 0;
  2308. ...
  2309. ret = wolfSSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
  2310. if (ret != SSL_SUCCESS) {
  2311. // failed to turn SSL session caching off
  2312. }
  2313. \endcode
  2314. \sa wolfSSL_flush_sessions
  2315. \sa wolfSSL_get1_session
  2316. \sa wolfSSL_set_session
  2317. \sa wolfSSL_get_sessionID
  2318. \sa wolfSSL_CTX_set_timeout
  2319. */
  2320. long wolfSSL_CTX_set_session_cache_mode(WOLFSSL_CTX* ctx, long mode);
  2321. /*!
  2322. \brief This function sets the session secret callback function. The
  2323. SessionSecretCb type has the signature: int (*SessionSecretCb)(WOLFSSL* ssl,
  2324. void* secret, int* secretSz, void* ctx). The sessionSecretCb member of
  2325. the WOLFSSL struct is set to the parameter cb.
  2326. \return SSL_SUCCESS returned if the execution of the function did not
  2327. return an error.
  2328. \return SSL_FATAL_ERROR returned if the WOLFSSL structure is NULL.
  2329. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2330. \param cb a SessionSecretCb type that is a function pointer with the above
  2331. signature.
  2332. _Example_
  2333. \code
  2334. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2335. WOLFSSL* ssl = wolfSSL_new(ctx);
  2336. // Signature of SessionSecretCb
  2337. int SessionSecretCB (WOLFSSL* ssl, void* secret, int* secretSz,
  2338. void* ctx) = SessionSecretCb;
  2339. int wolfSSL_set_session_secret_cb(ssl, SessionSecretCB, (void*)ssl->ctx){
  2340. // Function body.
  2341. }
  2342. \endcode
  2343. \sa SessionSecretCb
  2344. */
  2345. int wolfSSL_set_session_secret_cb(WOLFSSL* ssl, SessionSecretCb cb, void* ctx);
  2346. /*!
  2347. \ingroup IO
  2348. \brief This function persists the session cache to file. It doesn’t use
  2349. memsave because of additional memory use.
  2350. \return SSL_SUCCESS returned if the function executed without error.
  2351. The session cache has been written to a file.
  2352. \return SSL_BAD_FILE returned if fname cannot be opened or is otherwise
  2353. corrupt.
  2354. \return FWRITE_ERROR returned if XFWRITE failed to write to the file.
  2355. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2356. \param name is a constant char pointer that points to a file for writing.
  2357. _Example_
  2358. \code
  2359. const char* fname;
  2360. ...
  2361. if(wolfSSL_save_session_cache(fname) != SSL_SUCCESS){
  2362. // Fail to write to file.
  2363. }
  2364. \endcode
  2365. \sa XFWRITE
  2366. \sa wolfSSL_restore_session_cache
  2367. \sa wolfSSL_memrestore_session_cache
  2368. */
  2369. int wolfSSL_save_session_cache(const char*);
  2370. /*!
  2371. \ingroup IO
  2372. \brief This function restores the persistent session cache from file. It
  2373. does not use memstore because of additional memory use.
  2374. \return SSL_SUCCESS returned if the function executed without error.
  2375. \return SSL_BAD_FILE returned if the file passed into the function was
  2376. corrupted and could not be opened by XFOPEN.
  2377. \return FREAD_ERROR returned if the file had a read error from XFREAD.
  2378. \return CACHE_MATCH_ERROR returned if the session cache header match
  2379. failed.
  2380. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2381. \param fname a constant char pointer file input that will be read.
  2382. _Example_
  2383. \code
  2384. const char *fname;
  2385. ...
  2386. if(wolfSSL_restore_session_cache(fname) != SSL_SUCCESS){
  2387. // Failure case. The function did not return SSL_SUCCESS.
  2388. }
  2389. \endcode
  2390. \sa XFREAD
  2391. \sa XFOPEN
  2392. */
  2393. int wolfSSL_restore_session_cache(const char*);
  2394. /*!
  2395. \ingroup IO
  2396. \brief This function persists session cache to memory.
  2397. \return SSL_SUCCESS returned if the function executed without error.
  2398. The session cache has been successfully persisted to memory.
  2399. \return BAD_MUTEX_E returned if there was a mutex lock error.
  2400. \return BUFFER_E returned if the buffer size was too small.
  2401. \param mem a void pointer representing the destination for the memory
  2402. copy, XMEMCPY().
  2403. \param sz an int type representing the size of mem.
  2404. _Example_
  2405. \code
  2406. void* mem;
  2407. int sz; // Max size of the memory buffer.
  2408. if(wolfSSL_memsave_session_cache(mem, sz) != SSL_SUCCESS){
  2409. // Failure case, you did not persist the session cache to memory
  2410. }
  2411. \endcode
  2412. \sa XMEMCPY
  2413. \sa wolfSSL_get_session_cache_memsize
  2414. */
  2415. int wolfSSL_memsave_session_cache(void* mem, int sz);
  2416. /*!
  2417. \ingroup IO
  2418. \brief This function restores the persistent session cache from memory.
  2419. \return SSL_SUCCESS returned if the function executed without an error.
  2420. \return BUFFER_E returned if the memory buffer is too small.
  2421. \return BAD_MUTEX_E returned if the session cache mutex lock failed.
  2422. \return CACHE_MATCH_ERROR returned if the session cache header match
  2423. failed.
  2424. \param mem a constant void pointer containing the source of the
  2425. restoration.
  2426. \param sz an integer representing the size of the memory buffer.
  2427. _Example_
  2428. \code
  2429. const void* memoryFile;
  2430. int szMf;
  2431. ...
  2432. if(wolfSSL_memrestore_session_cache(memoryFile, szMf) != SSL_SUCCESS){
  2433. // Failure case. SSL_SUCCESS was not returned.
  2434. }
  2435. \endcode
  2436. \sa wolfSSL_save_session_cache
  2437. */
  2438. int wolfSSL_memrestore_session_cache(const void* mem, int sz);
  2439. /*!
  2440. \ingroup IO
  2441. \brief This function returns how large the session cache save buffer
  2442. should be.
  2443. \return int This function returns an integer that represents the size of
  2444. the session cache save buffer.
  2445. \param none No parameters.
  2446. _Example_
  2447. \code
  2448. int sz = // Minimum size for error checking;
  2449. ...
  2450. if(sz < wolfSSL_get_session_cache_memsize()){
  2451. // Memory buffer is too small
  2452. }
  2453. \endcode
  2454. \sa wolfSSL_memrestore_session_cache
  2455. */
  2456. int wolfSSL_get_session_cache_memsize(void);
  2457. /*!
  2458. \ingroup CertsKeys
  2459. \brief This function writes the cert cache from memory to file.
  2460. \return SSL_SUCCESS if CM_SaveCertCache exits normally.
  2461. \return BAD_FUNC_ARG is returned if either of the arguments are NULL.
  2462. \return SSL_BAD_FILE if the cert cache save file could not be opened.
  2463. \return BAD_MUTEX_E if the lock mutex failed.
  2464. \return MEMORY_E the allocation of memory failed.
  2465. \return FWRITE_ERROR Certificate cache file write failed.
  2466. \param ctx a pointer to a WOLFSSL_CTX structure, holding the
  2467. certificate information.
  2468. \param fname the cert cache buffer.
  2469. _Example_
  2470. \code
  2471. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  2472. const char* fname;
  2473. ...
  2474. if(wolfSSL_CTX_save_cert_cache(ctx, fname)){
  2475. // file was written.
  2476. }
  2477. \endcode
  2478. \sa CM_SaveCertCache
  2479. \sa DoMemSaveCertCache
  2480. */
  2481. int wolfSSL_CTX_save_cert_cache(WOLFSSL_CTX* ctx, const char* fname);
  2482. /*!
  2483. \ingroup CertsKeys
  2484. \brief This function persistes certificate cache from a file.
  2485. \return SSL_SUCCESS returned if the function, CM_RestoreCertCache,
  2486. executes normally.
  2487. \return SSL_BAD_FILE returned if XFOPEN returns XBADFILE. The file is
  2488. corrupted.
  2489. \return MEMORY_E returned if the allocated memory for the temp buffer
  2490. fails.
  2491. \return BAD_FUNC_ARG returned if fname or ctx have a NULL value.
  2492. \param ctx a pointer to a WOLFSSL_CTX structure, holding the certificate
  2493. information.
  2494. \param fname the cert cache buffer.
  2495. _Example_
  2496. \code
  2497. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  2498. WOLFSSL* ssl = wolfSSL_new(ctx);
  2499. const char* fname = "path to file";
  2500. ...
  2501. if(wolfSSL_CTX_restore_cert_cache(ctx, fname)){
  2502. // check to see if the execution was successful
  2503. }
  2504. \endcode
  2505. \sa CM_RestoreCertCache
  2506. \sa XFOPEN
  2507. */
  2508. int wolfSSL_CTX_restore_cert_cache(WOLFSSL_CTX* ctx, const char* fname);
  2509. /*!
  2510. \ingroup CertsKeys
  2511. \brief This function persists the certificate cache to memory.
  2512. \return SSL_SUCCESS returned on successful execution of the function.
  2513. No errors were thrown.
  2514. \return BAD_MUTEX_E mutex error where the WOLFSSL_CERT_MANAGER member
  2515. caLock was not 0 (zero).
  2516. \return BAD_FUNC_ARG returned if ctx, mem, or used is NULL or if sz
  2517. is less than or equal to 0 (zero).
  2518. \return BUFFER_E output buffer mem was too small.
  2519. \param ctx a pointer to a WOLFSSL_CTX structure, created
  2520. using wolfSSL_CTX_new().
  2521. \param mem a void pointer to the destination (output buffer).
  2522. \param sz the size of the output buffer.
  2523. \param used a pointer to size of the cert cache header.
  2524. _Example_
  2525. \code
  2526. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  2527. void* mem;
  2528. int sz;
  2529. int* used;
  2530. ...
  2531. if(wolfSSL_CTX_memsave_cert_cache(ctx, mem, sz, used) != SSL_SUCCESS){
  2532. // The function returned with an error
  2533. }
  2534. \endcode
  2535. \sa DoMemSaveCertCache
  2536. \sa GetCertCacheMemSize
  2537. \sa CM_MemRestoreCertCache
  2538. \sa CM_GetCertCacheMemSize
  2539. */
  2540. int wolfSSL_CTX_memsave_cert_cache(WOLFSSL_CTX* ctx, void* mem, int sz, int* used);
  2541. /*!
  2542. \ingroup Setup
  2543. \brief This function restores the certificate cache from memory.
  2544. \return SSL_SUCCESS returned if the function and subroutines
  2545. executed without an error.
  2546. \return BAD_FUNC_ARG returned if the ctx or mem parameters are
  2547. NULL or if the sz parameter is less than or equal to zero.
  2548. \return BUFFER_E returned if the cert cache memory buffer is too small.
  2549. \return CACHE_MATCH_ERROR returned if there was a cert cache
  2550. header mismatch.
  2551. \return BAD_MUTEX_E returned if the lock mutex on failed.
  2552. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  2553. wolfSSL_CTX_new().
  2554. \param mem a void pointer with a value that will be restored to
  2555. the certificate cache.
  2556. \param sz an int type that represents the size of the mem parameter.
  2557. _Example_
  2558. \code
  2559. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  2560. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2561. void* mem;
  2562. int sz = (*int) sizeof(mem);
  2563. if(wolfSSL_CTX_memrestore_cert_cache(ssl->ctx, mem, sz)){
  2564. // The success case
  2565. }
  2566. \endcode
  2567. \sa CM_MemRestoreCertCache
  2568. */
  2569. int wolfSSL_CTX_memrestore_cert_cache(WOLFSSL_CTX* ctx, const void* mem, int sz);
  2570. /*!
  2571. \ingroup CertsKeys
  2572. \brief Returns the size the certificate cache save buffer needs to be.
  2573. \return int integer value returned representing the memory size
  2574. upon success.
  2575. \return BAD_FUNC_ARG is returned if the WOLFSSL_CTX struct is NULL.
  2576. \return BAD_MUTEX_E - returned if there was a mutex lock error.
  2577. \param ctx a pointer to a wolfSSL_CTX structure, created using
  2578. wolfSSL_CTX_new().
  2579. _Example_
  2580. \code
  2581. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol);
  2582. ...
  2583. int certCacheSize = wolfSSL_CTX_get_cert_cache_memsize(ctx);
  2584. if(certCacheSize != BAD_FUNC_ARG || certCacheSize != BAD_MUTEX_E){
  2585. // Successfully retrieved the memory size.
  2586. }
  2587. \endcode
  2588. \sa CM_GetCertCacheMemSize
  2589. */
  2590. int wolfSSL_CTX_get_cert_cache_memsize(WOLFSSL_CTX*);
  2591. /*!
  2592. \ingroup Setup
  2593. \brief This function sets cipher suite list for a given WOLFSSL_CTX.
  2594. This cipher suite list becomes the default list for any new SSL sessions
  2595. (WOLFSSL) created using this context. The ciphers in the list should be
  2596. sorted in order of preference from highest to lowest. Each call to
  2597. wolfSSL_CTX_set_cipher_list() resets the cipher suite list for the
  2598. specific SSL context to the provided list each time the function is
  2599. called. The cipher suite list, list, is a null-terminated text string,
  2600. and a colon-delimited list. For example, one value for list may be
  2601. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256" Valid cipher
  2602. values are the full name values from the cipher_names[] array in
  2603. src/internal.c (for a definite list of valid cipher values check
  2604. src/internal.c)
  2605. \return SSL_SUCCESS will be returned upon successful function completion.
  2606. \return SSL_FAILURE will be returned on failure.
  2607. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2608. \param list null-terminated text string and a colon-delimited list of
  2609. cipher suites to use with the specified SSL context.
  2610. _Example_
  2611. \code
  2612. WOLFSSL_CTX* ctx = 0;
  2613. ...
  2614. ret = wolfSSL_CTX_set_cipher_list(ctx,
  2615. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2616. if (ret != SSL_SUCCESS) {
  2617. // failed to set cipher suite list
  2618. }
  2619. \endcode
  2620. \sa wolfSSL_set_cipher_list
  2621. \sa wolfSSL_CTX_new
  2622. */
  2623. int wolfSSL_CTX_set_cipher_list(WOLFSSL_CTX* ctx, const char* list);
  2624. /*!
  2625. \ingroup Setup
  2626. \brief This function sets cipher suite list for a given WOLFSSL object
  2627. (SSL session). The ciphers in the list should be sorted in order of
  2628. preference from highest to lowest. Each call to wolfSSL_set_cipher_list()
  2629. resets the cipher suite list for the specific SSL session to the provided
  2630. list each time the function is called. The cipher suite list, list, is a
  2631. null-terminated text string, and a colon-delimited list. For example, one
  2632. value for list may be
  2633. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256".
  2634. Valid cipher values are the full name values from the cipher_names[]
  2635. array in src/internal.c (for a definite list of valid cipher values
  2636. check src/internal.c)
  2637. \return SSL_SUCCESS will be returned upon successful function completion.
  2638. \return SSL_FAILURE will be returned on failure.
  2639. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2640. \param list null-terminated text string and a colon-delimited list of
  2641. cipher suites to use with the specified SSL session.
  2642. _Example_
  2643. \code
  2644. int ret = 0;
  2645. WOLFSSL* ssl = 0;
  2646. ...
  2647. ret = wolfSSL_set_cipher_list(ssl,
  2648. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2649. if (ret != SSL_SUCCESS) {
  2650. // failed to set cipher suite list
  2651. }
  2652. \endcode
  2653. \sa wolfSSL_CTX_set_cipher_list
  2654. \sa wolfSSL_new
  2655. */
  2656. int wolfSSL_set_cipher_list(WOLFSSL* ssl, const char* list);
  2657. /*!
  2658. \brief This function informs the WOLFSSL DTLS object that the underlying
  2659. UDP I/O is non-blocking. After an application creates a WOLFSSL object,
  2660. if it will be used with a non-blocking UDP socket, call
  2661. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2662. that receiving EWOULDBLOCK means that the recvfrom call would
  2663. block rather than that it timed out.
  2664. \return none No return.
  2665. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2666. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  2667. Use 1 to specify non-blocking, otherwise 0.
  2668. _Example_
  2669. \code
  2670. WOLFSSL* ssl = 0;
  2671. ...
  2672. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  2673. \endcode
  2674. \sa wolfSSL_dtls_get_using_nonblock
  2675. \sa wolfSSL_dtls_got_timeout
  2676. \sa wolfSSL_dtls_get_current_timeout
  2677. */
  2678. void wolfSSL_dtls_set_using_nonblock(WOLFSSL* ssl, int nonblock);
  2679. /*!
  2680. \brief This function allows the application to determine if wolfSSL is
  2681. using non-blocking I/O with UDP. If wolfSSL is using non-blocking I/O, this
  2682. function will return 1, otherwise 0. After an application creates a
  2683. WOLFSSL object, if it will be used with a non-blocking UDP socket, call
  2684. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2685. that receiving EWOULDBLOCK means that the recvfrom call would block
  2686. rather than that it timed out. This function is only meaningful to DTLS
  2687. sessions.
  2688. \return 0 underlying I/O is blocking.
  2689. \return 1 underlying I/O is non-blocking.
  2690. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2691. _Example_
  2692. \code
  2693. int ret = 0;
  2694. WOLFSSL* ssl = 0;
  2695. ...
  2696. ret = wolfSSL_dtls_get_using_nonblock(ssl);
  2697. if (ret == 1) {
  2698. // underlying I/O is non-blocking
  2699. }
  2700. ...
  2701. \endcode
  2702. \sa wolfSSL_dtls_set_using_nonblock
  2703. \sa wolfSSL_dtls_got_timeout
  2704. \sa wolfSSL_dtls_set_using_nonblock
  2705. */
  2706. int wolfSSL_dtls_get_using_nonblock(WOLFSSL*);
  2707. /*!
  2708. \brief This function returns the current timeout value in seconds for
  2709. the WOLFSSL object. When using non-blocking sockets, something in the user
  2710. code needs to decide when to check for available recv data and how long
  2711. it has been waiting. The value returned by this function indicates how
  2712. long the application should wait.
  2713. \return seconds The current DTLS timeout value in seconds
  2714. \return NOT_COMPILED_IN if wolfSSL was not built with DTLS support.
  2715. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2716. _Example_
  2717. \code
  2718. int timeout = 0;
  2719. WOLFSSL* ssl;
  2720. ...
  2721. timeout = wolfSSL_get_dtls_current_timeout(ssl);
  2722. printf(“DTLS timeout (sec) = %d\n”, timeout);
  2723. \endcode
  2724. \sa wolfSSL_dtls
  2725. \sa wolfSSL_dtls_get_peer
  2726. \sa wolfSSL_dtls_got_timeout
  2727. \sa wolfSSL_dtls_set_peer
  2728. */
  2729. int wolfSSL_dtls_get_current_timeout(WOLFSSL* ssl);
  2730. /*!
  2731. \ingroup Setup
  2732. \brief This function sets the dtls timeout.
  2733. \return SSL_SUCCESS returned if the function executes without an error.
  2734. The dtls_timeout_init and the dtls_timeout members of SSL have been set.
  2735. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  2736. the timeout is not greater than 0. It will also return if the timeout
  2737. argument exceeds the maximum value allowed.
  2738. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2739. \param timeout an int type that will be set to the dtls_timeout_init
  2740. member of the WOLFSSL structure.
  2741. _Example_
  2742. \code
  2743. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2744. WOLFSSL* ssl = wolfSSL_new(ctx);
  2745. int timeout = TIMEOUT;
  2746. ...
  2747. if(wolfSSL_dtls_set_timeout_init(ssl, timeout)){
  2748. // the dtls timeout was set
  2749. } else {
  2750. // Failed to set DTLS timeout.
  2751. }
  2752. \endcode
  2753. \sa wolfSSL_dtls_set_timeout_max
  2754. \sa wolfSSL_dtls_got_timeout
  2755. */
  2756. int wolfSSL_dtls_set_timeout_init(WOLFSSL* ssl, int);
  2757. /*!
  2758. \brief This function sets the maximum dtls timeout.
  2759. \return SSL_SUCCESS returned if the function executed without an error.
  2760. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  2761. the timeout argument is not greater than zero or is less than the
  2762. dtls_timeout_init member of the WOLFSSL structure.
  2763. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2764. \param timeout an int type representing the dtls maximum timeout.
  2765. _Example_
  2766. \code
  2767. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2768. WOLFSSL* ssl = wolfSSL_new(ctx);
  2769. int timeout = TIMEOUTVAL;
  2770. ...
  2771. int ret = wolfSSL_dtls_set_timeout_max(ssl);
  2772. if(!ret){
  2773. // Failed to set the max timeout
  2774. }
  2775. \endcode
  2776. \sa wolfSSL_dtls_set_timeout_init
  2777. \sa wolfSSL_dtls_got_timeout
  2778. */
  2779. int wolfSSL_dtls_set_timeout_max(WOLFSSL* ssl, int);
  2780. /*!
  2781. \brief When using non-blocking sockets with DTLS, this function should
  2782. be called on the WOLFSSL object when the controlling code thinks the
  2783. transmission has timed out. It performs the actions needed to retry
  2784. the last transmit, including adjusting the timeout value. If it
  2785. has been too long, this will return a failure.
  2786. \return SSL_SUCCESS will be returned upon success
  2787. \return SSL_FATAL_ERROR will be returned if there have been too many
  2788. retransmissions/timeouts without getting a response from the peer.
  2789. \return NOT_COMPILED_IN will be returned if wolfSSL was not compiled with
  2790. DTLS support.
  2791. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2792. _Example_
  2793. \code
  2794. See the following files for usage examples:
  2795. <wolfssl_root>/examples/client/client.c
  2796. <wolfssl_root>/examples/server/server.c
  2797. \endcode
  2798. \sa wolfSSL_dtls_get_current_timeout
  2799. \sa wolfSSL_dtls_get_peer
  2800. \sa wolfSSL_dtls_set_peer
  2801. \sa wolfSSL_dtls
  2802. */
  2803. int wolfSSL_dtls_got_timeout(WOLFSSL* ssl);
  2804. /*!
  2805. \brief This function is used to determine if the SSL session has been
  2806. configured to use DTLS.
  2807. \return 1 If the SSL session (ssl) has been configured to use DTLS, this
  2808. function will return 1.
  2809. \return 0 otherwise.
  2810. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2811. _Example_
  2812. \code
  2813. int ret = 0;
  2814. WOLFSSL* ssl;
  2815. ...
  2816. ret = wolfSSL_dtls(ssl);
  2817. if (ret) {
  2818. // SSL session has been configured to use DTLS
  2819. }
  2820. \endcode
  2821. \sa wolfSSL_dtls_get_current_timeout
  2822. \sa wolfSSL_dtls_get_peer
  2823. \sa wolfSSL_dtls_got_timeout
  2824. \sa wolfSSL_dtls_set_peer
  2825. */
  2826. int wolfSSL_dtls(WOLFSSL* ssl);
  2827. /*!
  2828. \brief This function sets the DTLS peer, peer (sockaddr_in) with size of
  2829. peerSz.
  2830. \return SSL_SUCCESS will be returned upon success.
  2831. \return SSL_FAILURE will be returned upon failure.
  2832. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  2833. with DTLS support.
  2834. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2835. \param peer pointer to peer’s sockaddr_in structure.
  2836. \param peerSz size of the sockaddr_in structure pointed to by peer.
  2837. _Example_
  2838. \code
  2839. int ret = 0;
  2840. WOLFSSL* ssl;
  2841. sockaddr_in addr;
  2842. ...
  2843. ret = wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
  2844. if (ret != SSL_SUCCESS) {
  2845. // failed to set DTLS peer
  2846. }
  2847. \endcode
  2848. \sa wolfSSL_dtls_get_current_timeout
  2849. \sa wolfSSL_dtls_get_peer
  2850. \sa wolfSSL_dtls_got_timeout
  2851. \sa wolfSSL_dtls
  2852. */
  2853. int wolfSSL_dtls_set_peer(WOLFSSL* ssl, void* peer, unsigned int peerSz);
  2854. /*!
  2855. \brief This function gets the sockaddr_in (of size peerSz) of the current
  2856. DTLS peer. The function will compare peerSz to the actual DTLS peer size
  2857. stored in the SSL session. If the peer will fit into peer, the peer’s
  2858. sockaddr_in will be copied into peer, with peerSz set to the size of peer.
  2859. \return SSL_SUCCESS will be returned upon success.
  2860. \return SSL_FAILURE will be returned upon failure.
  2861. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  2862. with DTLS support.
  2863. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2864. \param peer pointer to memory location to store peer’s sockaddr_in
  2865. structure.
  2866. \param peerSz input/output size. As input, the size of the allocated memory
  2867. pointed to by peer. As output, the size of the actual sockaddr_in structure
  2868. pointed to by peer.
  2869. _Example_
  2870. \code
  2871. int ret = 0;
  2872. WOLFSSL* ssl;
  2873. sockaddr_in addr;
  2874. ...
  2875. ret = wolfSSL_dtls_get_peer(ssl, &addr, sizeof(addr));
  2876. if (ret != SSL_SUCCESS) {
  2877. // failed to get DTLS peer
  2878. }
  2879. \endcode
  2880. \sa wolfSSL_dtls_get_current_timeout
  2881. \sa wolfSSL_dtls_got_timeout
  2882. \sa wolfSSL_dtls_set_peer
  2883. \sa wolfSSL_dtls
  2884. */
  2885. int wolfSSL_dtls_get_peer(WOLFSSL* ssl, void* peer, unsigned int* peerSz);
  2886. /*!
  2887. \ingroup Debug
  2888. \brief This function converts an error code returned by
  2889. wolfSSL_get_error() into a more human-readable error string.
  2890. errNumber is the error code returned by wolfSSL_get_error() and data
  2891. is the storage buffer which the error string will be placed in.
  2892. The maximum length of data is 80 characters by default, as defined by
  2893. MAX_ERROR_SZ is wolfssl/wolfcrypt/error.h.
  2894. \return success On successful completion, this function returns the same
  2895. string as is returned in data.
  2896. \return failure Upon failure, this function returns a string with the
  2897. appropriate failure reason, msg.
  2898. \param errNumber error code returned by wolfSSL_get_error().
  2899. \param data output buffer containing human-readable error string matching
  2900. errNumber.
  2901. _Example_
  2902. \code
  2903. int err = 0;
  2904. WOLFSSL* ssl;
  2905. char buffer[80];
  2906. ...
  2907. err = wolfSSL_get_error(ssl, 0);
  2908. wolfSSL_ERR_error_string(err, buffer);
  2909. printf(“err = %d, %s\n”, err, buffer);
  2910. \endcode
  2911. \sa wolfSSL_get_error
  2912. \sa wolfSSL_ERR_error_string_n
  2913. \sa wolfSSL_ERR_print_errors_fp
  2914. \sa wolfSSL_load_error_strings
  2915. */
  2916. char* wolfSSL_ERR_error_string(unsigned long,char*);
  2917. /*!
  2918. \ingroup Debug
  2919. \brief This function is a version of wolfSSL_ERR_error_string() where
  2920. len specifies the maximum number of characters that may be written to buf.
  2921. Like wolfSSL_ERR_error_string(), this function converts an error code
  2922. returned from wolfSSL_get_error() into a more human-readable error string.
  2923. The human-readable string is placed in buf.
  2924. \return none No returns.
  2925. \param e error code returned by wolfSSL_get_error().
  2926. \param buff output buffer containing human-readable error string matching e.
  2927. \param len maximum length in characters which may be written to buf.
  2928. _Example_
  2929. \code
  2930. int err = 0;
  2931. WOLFSSL* ssl;
  2932. char buffer[80];
  2933. ...
  2934. err = wolfSSL_get_error(ssl, 0);
  2935. wolfSSL_ERR_error_string_n(err, buffer, 80);
  2936. printf(“err = %d, %s\n”, err, buffer);
  2937. \endcode
  2938. \sa wolfSSL_get_error
  2939. \sa wolfSSL_ERR_error_string
  2940. \sa wolfSSL_ERR_print_errors_fp
  2941. \sa wolfSSL_load_error_strings
  2942. */
  2943. void wolfSSL_ERR_error_string_n(unsigned long e, char* buf,
  2944. unsigned long sz);
  2945. /*!
  2946. \ingroup TLS
  2947. \brief This function checks the shutdown conditions in closeNotify or
  2948. connReset or sentNotify members of the Options structure. The Options
  2949. structure is within the WOLFSSL structure.
  2950. \return 1 SSL_SENT_SHUTDOWN is returned.
  2951. \return 2 SS_RECEIVED_SHUTDOWN is returned.
  2952. \param ssl a constant pointer to a WOLFSSL structure, created using
  2953. wolfSSL_new().
  2954. _Example_
  2955. \code
  2956. #include <wolfssl/ssl.h>
  2957. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  2958. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2959. int ret;
  2960. ret = wolfSSL_get_shutdown(ssl);
  2961. if(ret == 1){
  2962. SSL_SENT_SHUTDOWN
  2963. } else if(ret == 2){
  2964. SSL_RECEIVED_SHUTDOWN
  2965. } else {
  2966. Fatal error.
  2967. }
  2968. \endcode
  2969. \sa wolfSSL_SESSION_free
  2970. */
  2971. int wolfSSL_get_shutdown(const WOLFSSL*);
  2972. /*!
  2973. \ingroup IO
  2974. \brief This function returns the resuming member of the options struct. The
  2975. flag indicates whether or not to reuse a session. If not, a new session must
  2976. be established.
  2977. \return This function returns an int type held in the Options structure
  2978. representing the flag for session reuse.
  2979. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2980. _Example_
  2981. \code
  2982. WOLFSSL* ssl = wolfSSL_new(ctx);
  2983. if(!wolfSSL_session_reused(sslResume)){
  2984. // No session reuse allowed.
  2985. }
  2986. \endcode
  2987. \sa wolfSSL_SESSION_free
  2988. \sa wolfSSL_GetSessionIndex
  2989. \sa wolfSSL_memsave_session_cache
  2990. */
  2991. int wolfSSL_session_reused(WOLFSSL*);
  2992. /*!
  2993. \ingroup TLS
  2994. \brief This function checks to see if the connection is established.
  2995. \return 0 returned if the connection is not established, i.e. the WOLFSSL
  2996. struct is NULL or the handshake is not done.
  2997. \return 1 returned if the connection is not established i.e. the WOLFSSL
  2998. struct is null or the handshake is not done.
  2999. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3000. _EXAMPLE_
  3001. \code
  3002. #include <wolfssl/ssl.h>
  3003. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3004. WOLFSSL* ssl = wolfSSL_new(ctx);
  3005. ...
  3006. if(wolfSSL_is_init_finished(ssl)){
  3007. Handshake is done and connection is established
  3008. }
  3009. \endcode
  3010. \sa wolfSSL_set_accept_state
  3011. \sa wolfSSL_get_keys
  3012. \sa wolfSSL_set_shutdown
  3013. */
  3014. int wolfSSL_is_init_finished(WOLFSSL*);
  3015. /*!
  3016. \ingroup IO
  3017. \brief Returns the SSL version being used as a string.
  3018. \return "SSLv3" Using SSLv3
  3019. \return "TLSv1" Using TLSv1
  3020. \return "TLSv1.1" Using TLSv1.1
  3021. \return "TLSv1.2" Using TLSv1.2
  3022. \return "TLSv1.3" Using TLSv1.3
  3023. \return "DTLS": Using DTLS
  3024. \return "DTLSv1.2" Using DTLSv1.2
  3025. \return "unknown" There was a problem determining which version of TLS
  3026. being used.
  3027. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3028. _Example_
  3029. \code
  3030. wolfSSL_Init();
  3031. WOLFSSL_CTX* ctx;
  3032. WOLFSSL* ssl;
  3033. WOLFSSL_METHOD method = // Some wolfSSL method
  3034. ctx = wolfSSL_CTX_new(method);
  3035. ssl = wolfSSL_new(ctx);
  3036. printf(wolfSSL_get_version("Using version: %s", ssl));
  3037. \endcode
  3038. \sa wolfSSL_lib_version
  3039. */
  3040. const char* wolfSSL_get_version(WOLFSSL*);
  3041. /*!
  3042. \ingroup IO
  3043. \brief Returns the current cipher suit an ssl session is using.
  3044. \return ssl->options.cipherSuite An integer representing the current
  3045. cipher suite.
  3046. \return 0 The ssl session provided is null.
  3047. \param ssl The SSL session to check.
  3048. _Example_
  3049. \code
  3050. wolfSSL_Init();
  3051. WOLFSSL_CTX* ctx;
  3052. WOLFSSL* ssl;
  3053. WOLFSSL_METHOD method = // Some wolfSSL method
  3054. ctx = wolfSSL_CTX_new(method);
  3055. ssl = wolfSSL_new(ctx);
  3056. if(wolfSSL_get_current_cipher_suite(ssl) == 0)
  3057. {
  3058. // Error getting cipher suite
  3059. }
  3060. \endcode
  3061. \sa wolfSSL_CIPHER_get_name
  3062. \sa wolfSSL_get_current_cipher
  3063. \sa wolfSSL_get_cipher_list
  3064. */
  3065. int wolfSSL_get_current_cipher_suite(WOLFSSL* ssl);
  3066. /*!
  3067. \ingroup IO
  3068. \brief This function returns a pointer to the current cipher in the
  3069. ssl session.
  3070. \return The function returns the address of the cipher member of the
  3071. WOLFSSL struct. This is a pointer to the WOLFSSL_CIPHER structure.
  3072. \return NULL returned if the WOLFSSL structure is NULL.
  3073. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3074. _Example_
  3075. \code
  3076. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3077. WOLFSSL* ssl = wolfSSL_new(ctx);
  3078. WOLFSSL_CIPHER* cipherCurr = wolfSSL_get_current_cipher;
  3079. if(!cipherCurr){
  3080. // Failure case.
  3081. } else {
  3082. // The cipher was returned to cipherCurr
  3083. }
  3084. \endcode
  3085. \sa wolfSSL_get_cipher
  3086. \sa wolfSSL_get_cipher_name_internal
  3087. \sa wolfSSL_get_cipher_name
  3088. */
  3089. WOLFSSL_CIPHER* wolfSSL_get_current_cipher(WOLFSSL*);
  3090. /*!
  3091. \ingroup IO
  3092. \brief This function matches the cipher suite in the SSL object with
  3093. the available suites and returns the string representation.
  3094. \return string This function returns the string representation of the
  3095. matched cipher suite.
  3096. \return none It will return “None” if there are no suites matched.
  3097. \param cipher a constant pointer to a WOLFSSL_CIPHER structure.
  3098. _Example_
  3099. \code
  3100. // gets cipher name in the format DHE_RSA ...
  3101. const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl){
  3102. WOLFSSL_CIPHER* cipher;
  3103. const char* fullName;
  3104. cipher = wolfSSL_get_curent_cipher(ssl);
  3105. fullName = wolfSSL_CIPHER_get_name(cipher);
  3106. if(fullName){
  3107. // sanity check on returned cipher
  3108. }
  3109. \endcode
  3110. \sa wolfSSL_get_cipher
  3111. \sa wolfSSL_get_current_cipher
  3112. \sa wolfSSL_get_cipher_name_internal
  3113. \sa wolfSSL_get_cipher_name
  3114. */
  3115. const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher);
  3116. /*!
  3117. \ingroup IO
  3118. \brief This function matches the cipher suite in the SSL object with
  3119. the available suites.
  3120. \return This function returns the string value of the suite matched. It
  3121. will return “None” if there are no suites matched.
  3122. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3123. _Example_
  3124. \code
  3125. #ifdef WOLFSSL_DTLS
  3126. // make sure a valid suite is used
  3127. if(wolfSSL_get_cipher(ssl) == NULL){
  3128. WOLFSSL_MSG(“Can not match cipher suite imported”);
  3129. return MATCH_SUITE_ERROR;
  3130. }
  3131. #endif // WOLFSSL_DTLS
  3132. \endcode
  3133. \sa wolfSSL_CIPHER_get_name
  3134. \sa wolfSSL_get_current_cipher
  3135. */
  3136. const char* wolfSSL_get_cipher(WOLFSSL*);
  3137. /*!
  3138. \ingroup Setup
  3139. \brief This function returns the WOLFSSL_SESSION from the WOLFSSL structure
  3140. as a reference type. This requires calling wolfSSL_SESSION_free to release
  3141. the session reference. The WOLFSSL_SESSION pointed to contains all the
  3142. necessary information required to perform a session resumption and
  3143. reestablish the connection without a new handshake. For
  3144. session resumption, before calling wolfSSL_shutdown() with your session
  3145. object, an application should save the session ID from the object with a
  3146. call to wolfSSL_get1_session(), which returns a pointer to the session.
  3147. Later, the application should create a new WOLFSSL object and assign the
  3148. saved session with wolfSSL_set_session(). At this point, the application
  3149. may call wolfSSL_connect() and wolfSSL will try to resume the session.
  3150. The wolfSSL server code allows session resumption by default. The object
  3151. returned by wolfSSL_get1_session() needs to be freed after the application
  3152. is done with it by calling wolfSSL_SESSION_free() on it.
  3153. \return WOLFSSL_SESSION On success return session pointer.
  3154. \return NULL will be returned if ssl is NULL, the SSL session cache is
  3155. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  3156. functions fail.
  3157. \param ssl WOLFSSL structure to get session from.
  3158. _Example_
  3159. \code
  3160. WOLFSSL* ssl;
  3161. WOLFSSL_SESSION* ses;
  3162. // attempt/complete handshake
  3163. wolfSSL_connect(ssl);
  3164. ses = wolfSSL_get1_session(ssl);
  3165. // check ses information
  3166. // disconnect / setup new SSL instance
  3167. wolfSSL_set_session(ssl, ses);
  3168. // attempt/resume handshake
  3169. wolfSSL_SESSION_free(ses);
  3170. \endcode
  3171. \sa wolfSSL_new
  3172. \sa wolfSSL_free
  3173. \sa wolfSSL_SESSION_free
  3174. */
  3175. WOLFSSL_SESSION* wolfSSL_get1_session(WOLFSSL* ssl);
  3176. /*!
  3177. \ingroup Setup
  3178. \brief The wolfSSLv23_client_method() function is used to indicate that
  3179. the application is a client and will support the highest protocol
  3180. version supported by the server between SSL 3.0 - TLS 1.3. This function
  3181. allocates memory for and initializes a new WOLFSSL_METHOD structure
  3182. to be used when creating the SSL/TLS context with wolfSSL_CTX_new().
  3183. Both wolfSSL clients and servers have robust version downgrade capability.
  3184. If a specific protocol version method is used on either side, then only
  3185. that version will be negotiated or an error will be returned. For
  3186. example, a client that uses TLSv1 and tries to connect to a SSLv3 only
  3187. server will fail, likewise connecting to a TLSv1.1 will fail as well.
  3188. To resolve this issue, a client that uses the wolfSSLv23_client_method()
  3189. function will use the highest protocol version supported by the server and
  3190. downgrade to SSLv3 if needed. In this case, the client will be able to
  3191. connect to a server running SSLv3 - TLSv1.3.
  3192. \return pointer upon success a pointer to a WOLFSSL_METHOD.
  3193. \return Failure If memory allocation fails when calling XMALLOC,
  3194. the failure value of the underlying malloc() implementation will be
  3195. returned (typically NULL with errno will be set to ENOMEM).
  3196. \param none No parameters
  3197. _Example_
  3198. \code
  3199. WOLFSSL_METHOD* method;
  3200. WOLFSSL_CTX* ctx;
  3201. method = wolfSSLv23_client_method();
  3202. if (method == NULL) {
  3203. // unable to get method
  3204. }
  3205. ctx = wolfSSL_CTX_new(method);
  3206. ...
  3207. \endcode
  3208. \sa wolfSSLv3_client_method
  3209. \sa wolfTLSv1_client_method
  3210. \sa wolfTLSv1_1_client_method
  3211. \sa wolfTLSv1_2_client_method
  3212. \sa wolfTLSv1_3_client_method
  3213. \sa wolfDTLSv1_client_method
  3214. \sa wolfSSL_CTX_new
  3215. */
  3216. WOLFSSL_METHOD* wolfSSLv23_client_method(void);
  3217. /*!
  3218. \ingroup IO
  3219. \brief This is used to set a byte pointer to the start of the
  3220. internal memory buffer.
  3221. \return size On success the size of the buffer is returned
  3222. \return SSL_FATAL_ERROR If an error case was encountered.
  3223. \param bio WOLFSSL_BIO structure to get memory buffer of.
  3224. \param p byte pointer to set to memory buffer.
  3225. _Example_
  3226. \code
  3227. WOLFSSL_BIO* bio;
  3228. const byte* p;
  3229. int ret;
  3230. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3231. ret = wolfSSL_BIO_get_mem_data(bio, &p);
  3232. // check ret value
  3233. \endcode
  3234. \sa wolfSSL_BIO_new
  3235. \sa wolfSSL_BIO_s_mem
  3236. \sa wolfSSL_BIO_set_fp
  3237. \sa wolfSSL_BIO_free
  3238. */
  3239. int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);
  3240. /*!
  3241. \ingroup IO
  3242. \brief Sets the file descriptor for bio to use.
  3243. \return SSL_SUCCESS(1) upon success.
  3244. \param bio WOLFSSL_BIO structure to set fd.
  3245. \param fd file descriptor to use.
  3246. \param closeF flag for behavior when closing fd.
  3247. _Example_
  3248. \code
  3249. WOLFSSL_BIO* bio;
  3250. int fd;
  3251. // setup bio
  3252. wolfSSL_BIO_set_fd(bio, fd, BIO_NOCLOSE);
  3253. \endcode
  3254. \sa wolfSSL_BIO_new
  3255. \sa wolfSSL_BIO_free
  3256. */
  3257. long wolfSSL_BIO_set_fd(WOLFSSL_BIO* b, int fd, int flag);
  3258. /*!
  3259. \ingroup IO
  3260. \brief Sets the close flag, used to indicate that the i/o stream should be
  3261. closed when the BIO is freed
  3262. \return SSL_SUCCESS(1) upon success.
  3263. \param bio WOLFSSL_BIO structure.
  3264. \param flag flag for behavior when closing i/o stream.
  3265. _Example_
  3266. \code
  3267. WOLFSSL_BIO* bio;
  3268. // setup bio
  3269. wolfSSL_BIO_set_close(bio, BIO_NOCLOSE);
  3270. \endcode
  3271. \sa wolfSSL_BIO_new
  3272. \sa wolfSSL_BIO_free
  3273. */
  3274. int wolfSSL_BIO_set_close(WOLFSSL_BIO *b, long flag);
  3275. /*!
  3276. \ingroup IO
  3277. \brief This is used to get a BIO_SOCKET type WOLFSSL_BIO_METHOD.
  3278. \return WOLFSSL_BIO_METHOD pointer to a WOLFSSL_BIO_METHOD structure
  3279. that is a socket type
  3280. \param none No parameters.
  3281. _Example_
  3282. \code
  3283. WOLFSSL_BIO* bio;
  3284. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket);
  3285. \endcode
  3286. \sa wolfSSL_BIO_new
  3287. \sa wolfSSL_BIO_s_mem
  3288. */
  3289. WOLFSSL_BIO_METHOD *wolfSSL_BIO_s_socket(void);
  3290. /*!
  3291. \ingroup IO
  3292. \brief This is used to set the size of write buffer for a
  3293. WOLFSSL_BIO. If write buffer has been previously set this
  3294. function will free it when resetting the size. It is similar to
  3295. wolfSSL_BIO_reset in that it resets read and write indexes to 0.
  3296. \return SSL_SUCCESS On successfully setting the write buffer.
  3297. \return SSL_FAILURE If an error case was encountered.
  3298. \param bio WOLFSSL_BIO structure to set fd.
  3299. \param size size of buffer to allocate.
  3300. _Example_
  3301. \code
  3302. WOLFSSL_BIO* bio;
  3303. int ret;
  3304. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3305. ret = wolfSSL_BIO_set_write_buf_size(bio, 15000);
  3306. // check return value
  3307. \endcode
  3308. \sa wolfSSL_BIO_new
  3309. \sa wolfSSL_BIO_s_mem
  3310. \sa wolfSSL_BIO_free
  3311. */
  3312. int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *b, long size);
  3313. /*!
  3314. \ingroup IO
  3315. \brief This is used to pair two bios together. A pair of bios acts
  3316. similar to a two way pipe writing to one can be read by the other
  3317. and vice versa. It is expected that both bios be in the same thread,
  3318. this function is not thread safe. Freeing one of the two bios removes
  3319. both from being paired. If a write buffer size was not previously
  3320. set for either of the bios it is set to a default size of 17000
  3321. (WOLFSSL_BIO_SIZE) before being paired.
  3322. \return SSL_SUCCESS On successfully pairing the two bios.
  3323. \return SSL_FAILURE If an error case was encountered.
  3324. \param b1 WOLFSSL_BIO structure to set pair.
  3325. \param b2 second WOLFSSL_BIO structure to complete pair.
  3326. _Example_
  3327. \code
  3328. WOLFSSL_BIO* bio;
  3329. WOLFSSL_BIO* bio2;
  3330. int ret;
  3331. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3332. bio2 = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3333. ret = wolfSSL_BIO_make_bio_pair(bio, bio2);
  3334. // check ret value
  3335. \endcode
  3336. \sa wolfSSL_BIO_new
  3337. \sa wolfSSL_BIO_s_mem
  3338. \sa wolfSSL_BIO_free
  3339. */
  3340. int wolfSSL_BIO_make_bio_pair(WOLFSSL_BIO *b1, WOLFSSL_BIO *b2);
  3341. /*!
  3342. \ingroup IO
  3343. \brief This is used to set the read request flag back to 0.
  3344. \return SSL_SUCCESS On successfully setting value.
  3345. \return SSL_FAILURE If an error case was encountered.
  3346. \param bio WOLFSSL_BIO structure to set read request flag.
  3347. _Example_
  3348. \code
  3349. WOLFSSL_BIO* bio;
  3350. int ret;
  3351. ...
  3352. ret = wolfSSL_BIO_ctrl_reset_read_request(bio);
  3353. // check ret value
  3354. \endcode
  3355. \sa wolfSSL_BIO_new, wolfSSL_BIO_s_mem
  3356. \sa wolfSSL_BIO_new, wolfSSL_BIO_free
  3357. */
  3358. int wolfSSL_BIO_ctrl_reset_read_request(WOLFSSL_BIO *b);
  3359. /*!
  3360. \ingroup IO
  3361. \brief This is used to get a buffer pointer for reading from. Unlike
  3362. wolfSSL_BIO_nread the internal read index is not advanced by the number
  3363. returned from the function call. Reading past the value returned can
  3364. result in reading out of array bounds.
  3365. \return >=0 on success return the number of bytes to read
  3366. \param bio WOLFSSL_BIO structure to read from.
  3367. \param buf pointer to set at beginning of read array.
  3368. _Example_
  3369. \code
  3370. WOLFSSL_BIO* bio;
  3371. char* bufPt;
  3372. int ret;
  3373. // set up bio
  3374. ret = wolfSSL_BIO_nread0(bio, &bufPt); // read as many bytes as possible
  3375. // handle negative ret check
  3376. // read ret bytes from bufPt
  3377. \endcode
  3378. \sa wolfSSL_BIO_new
  3379. \sa wolfSSL_BIO_nwrite0
  3380. */
  3381. int wolfSSL_BIO_nread0(WOLFSSL_BIO *bio, char **buf);
  3382. /*!
  3383. \ingroup IO
  3384. \brief This is used to get a buffer pointer for reading from. The internal
  3385. read index is advanced by the number returned from the function call with
  3386. buf being pointed to the beginning of the buffer to read from. In the
  3387. case that less bytes are in the read buffer than the value requested with
  3388. num the lesser value is returned. Reading past the value returned can
  3389. result in reading out of array bounds.
  3390. \return >=0 on success return the number of bytes to read
  3391. \return WOLFSSL_BIO_ERROR(-1) on error case with nothing to read return -1
  3392. \param bio WOLFSSL_BIO structure to read from.
  3393. \param buf pointer to set at beginning of read array.
  3394. \param num number of bytes to try and read.
  3395. _Example_
  3396. \code
  3397. WOLFSSL_BIO* bio;
  3398. char* bufPt;
  3399. int ret;
  3400. // set up bio
  3401. ret = wolfSSL_BIO_nread(bio, &bufPt, 10); // try to read 10 bytes
  3402. // handle negative ret check
  3403. // read ret bytes from bufPt
  3404. \endcode
  3405. \sa wolfSSL_BIO_new
  3406. \sa wolfSSL_BIO_nwrite
  3407. */
  3408. int wolfSSL_BIO_nread(WOLFSSL_BIO *bio, char **buf, int num);
  3409. /*!
  3410. \ingroup IO
  3411. \brief Gets a pointer to the buffer for writing as many bytes as returned by
  3412. the function. Writing more bytes to the pointer returned then the value
  3413. returned can result in writing out of bounds.
  3414. \return int Returns the number of bytes that can be written to the buffer
  3415. pointer returned.
  3416. \return WOLFSSL_BIO_UNSET(-2) in the case that is not part of a bio pair
  3417. \return WOLFSSL_BIO_ERROR(-1) in the case that there is no more room to
  3418. write to
  3419. \param bio WOLFSSL_BIO structure to write to.
  3420. \param buf pointer to buffer to write to.
  3421. \param num number of bytes desired to be written.
  3422. _Example_
  3423. \code
  3424. WOLFSSL_BIO* bio;
  3425. char* bufPt;
  3426. int ret;
  3427. // set up bio
  3428. ret = wolfSSL_BIO_nwrite(bio, &bufPt, 10); // try to write 10 bytes
  3429. // handle negative ret check
  3430. // write ret bytes to bufPt
  3431. \endcode
  3432. \sa wolfSSL_BIO_new
  3433. \sa wolfSSL_BIO_free
  3434. \sa wolfSSL_BIO_nread
  3435. */
  3436. int wolfSSL_BIO_nwrite(WOLFSSL_BIO *bio, char **buf, int num);
  3437. /*!
  3438. \ingroup IO
  3439. \brief Resets bio to an initial state. As an example for type BIO_BIO
  3440. this resets the read and write index.
  3441. \return 0 On successfully resetting the bio.
  3442. \return WOLFSSL_BIO_ERROR(-1) Returned on bad input or unsuccessful reset.
  3443. \param bio WOLFSSL_BIO structure to reset.
  3444. _Example_
  3445. \code
  3446. WOLFSSL_BIO* bio;
  3447. // setup bio
  3448. wolfSSL_BIO_reset(bio);
  3449. //use pt
  3450. \endcode
  3451. \sa wolfSSL_BIO_new
  3452. \sa wolfSSL_BIO_free
  3453. */
  3454. int wolfSSL_BIO_reset(WOLFSSL_BIO *bio);
  3455. /*!
  3456. \ingroup IO
  3457. \brief This function adjusts the file pointer to the offset given. This
  3458. is the offset from the head of the file.
  3459. \return 0 On successfully seeking.
  3460. \return -1 If an error case was encountered.
  3461. \param bio WOLFSSL_BIO structure to set.
  3462. \param ofs offset into file.
  3463. _Example_
  3464. \code
  3465. WOLFSSL_BIO* bio;
  3466. XFILE fp;
  3467. int ret;
  3468. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3469. ret = wolfSSL_BIO_set_fp(bio, &fp);
  3470. // check ret value
  3471. ret = wolfSSL_BIO_seek(bio, 3);
  3472. // check ret value
  3473. \endcode
  3474. \sa wolfSSL_BIO_new
  3475. \sa wolfSSL_BIO_s_mem
  3476. \sa wolfSSL_BIO_set_fp
  3477. \sa wolfSSL_BIO_free
  3478. */
  3479. int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs);
  3480. /*!
  3481. \ingroup IO
  3482. \brief This is used to set and write to a file. WIll overwrite any data
  3483. currently in the file and is set to close the file when the bio is freed.
  3484. \return SSL_SUCCESS On successfully opening and setting file.
  3485. \return SSL_FAILURE If an error case was encountered.
  3486. \param bio WOLFSSL_BIO structure to set file.
  3487. \param name name of file to write to.
  3488. _Example_
  3489. \code
  3490. WOLFSSL_BIO* bio;
  3491. int ret;
  3492. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3493. ret = wolfSSL_BIO_write_filename(bio, “test.txt”);
  3494. // check ret value
  3495. \endcode
  3496. \sa wolfSSL_BIO_new
  3497. \sa wolfSSL_BIO_s_file
  3498. \sa wolfSSL_BIO_set_fp
  3499. \sa wolfSSL_BIO_free
  3500. */
  3501. int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name);
  3502. /*!
  3503. \ingroup IO
  3504. \brief This is used to set the end of file value. Common value is -1 so
  3505. as not to get confused with expected positive values.
  3506. \return 0 returned on completion
  3507. \param bio WOLFSSL_BIO structure to set end of file value.
  3508. \param v value to set in bio.
  3509. _Example_
  3510. \code
  3511. WOLFSSL_BIO* bio;
  3512. int ret;
  3513. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3514. ret = wolfSSL_BIO_set_mem_eof_return(bio, -1);
  3515. // check ret value
  3516. \endcode
  3517. \sa wolfSSL_BIO_new
  3518. \sa wolfSSL_BIO_s_mem
  3519. \sa wolfSSL_BIO_set_fp
  3520. \sa wolfSSL_BIO_free
  3521. */
  3522. long wolfSSL_BIO_set_mem_eof_return(WOLFSSL_BIO *bio, int v);
  3523. /*!
  3524. \ingroup IO
  3525. \brief This is a getter function for WOLFSSL_BIO memory pointer.
  3526. \return SSL_SUCCESS On successfully getting the pointer SSL_SUCCESS is
  3527. returned (currently value of 1).
  3528. \return SSL_FAILURE Returned if NULL arguments are passed in (currently
  3529. value of 0).
  3530. \param bio pointer to the WOLFSSL_BIO structure for getting memory pointer.
  3531. \param ptr structure that is currently a char*. Is set to point to
  3532. bio’s memory.
  3533. _Example_
  3534. \code
  3535. WOLFSSL_BIO* bio;
  3536. WOLFSSL_BUF_MEM* pt;
  3537. // setup bio
  3538. wolfSSL_BIO_get_mem_ptr(bio, &pt);
  3539. //use pt
  3540. \endcode
  3541. \sa wolfSSL_BIO_new
  3542. \sa wolfSSL_BIO_s_mem
  3543. */
  3544. long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **m);
  3545. /*!
  3546. \ingroup CertsKeys
  3547. \brief This function copies the name of the x509 into a buffer.
  3548. \return A char pointer to the buffer with the WOLFSSL_X509_NAME structures
  3549. name member’s data is returned if the function executed normally.
  3550. \param name a pointer to a WOLFSSL_X509 structure.
  3551. \param in a buffer to hold the name copied from the
  3552. WOLFSSL_X509_NAME structure.
  3553. \param sz the maximum size of the buffer.
  3554. _Example_
  3555. \code
  3556. WOLFSSL_X509 x509;
  3557. char* name;
  3558. ...
  3559. name = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3560. if(name <= 0){
  3561. // There’s nothing in the buffer.
  3562. }
  3563. \endcode
  3564. \sa wolfSSL_X509_get_subject_name
  3565. \sa wolfSSL_X509_get_issuer_name
  3566. \sa wolfSSL_X509_get_isCA
  3567. \sa wolfSSL_get_peer_certificate
  3568. \sa wolfSSL_X509_version
  3569. */
  3570. char* wolfSSL_X509_NAME_oneline(WOLFSSL_X509_NAME* name, char* in, int sz);
  3571. /*!
  3572. \ingroup CertsKeys
  3573. \brief This function returns the name of the certificate issuer.
  3574. \return point a pointer to the WOLFSSL_X509 struct’s issuer member is
  3575. returned.
  3576. \return NULL if the cert passed in is NULL.
  3577. \param cert a pointer to a WOLFSSL_X509 structure.
  3578. _Example_
  3579. \code
  3580. WOLFSSL_X509* x509;
  3581. WOLFSSL_X509_NAME issuer;
  3582. ...
  3583. issuer = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3584. if(!issuer){
  3585. // NULL was returned
  3586. } else {
  3587. // issuer hods the name of the certificate issuer.
  3588. }
  3589. \endcode
  3590. \sa wolfSSL_X509_get_subject_name
  3591. \sa wolfSSL_X509_get_isCA
  3592. \sa wolfSSL_get_peer_certificate
  3593. \sa wolfSSL_X509_NAME_oneline
  3594. */
  3595. WOLFSSL_X509_NAME* wolfSSL_X509_get_issuer_name(WOLFSSL_X509*);
  3596. /*!
  3597. \ingroup CertsKeys
  3598. \brief This function returns the subject member of the WOLFSSL_X509
  3599. structure.
  3600. \return pointer a pointer to the WOLFSSL_X509_NAME structure. The pointer
  3601. may be NULL if the WOLFSSL_X509 struct is NULL or if the subject member of
  3602. the structure is NULL.
  3603. \param cert a pointer to a WOLFSSL_X509 structure.
  3604. _Example_
  3605. \code
  3606. WOLFSSL_X509* cert;
  3607. WOLFSSL_X509_NAME name;
  3608. name = wolfSSL_X509_get_subject_name(cert);
  3609. if(name == NULL){
  3610. // Deal with the NULL cacse
  3611. }
  3612. \endcode
  3613. \sa wolfSSL_X509_get_issuer_name
  3614. \sa wolfSSL_X509_get_isCA
  3615. \sa wolfSSL_get_peer_certificate
  3616. */
  3617. WOLFSSL_X509_NAME* wolfSSL_X509_get_subject_name(WOLFSSL_X509*);
  3618. /*!
  3619. \ingroup CertsKeys
  3620. \brief Checks the isCa member of the WOLFSSL_X509 structure and returns
  3621. the value.
  3622. \return isCA returns the value in the isCA member of the WOLFSSL_X509
  3623. structure is returned.
  3624. \return 0 returned if there is not a valid x509 structure passed in.
  3625. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3626. _Example_
  3627. \code
  3628. WOLFSSL* ssl;
  3629. ...
  3630. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  3631. WOLFSSL* ssl = wolfSSL_new(ctx);
  3632. ...
  3633. if(wolfSSL_X509_get_isCA(ssl)){
  3634. // This is the CA
  3635. }else {
  3636. // Failure case
  3637. }
  3638. \endcode
  3639. \sa wolfSSL_X509_get_issuer_name
  3640. \sa wolfSSL_X509_get_isCA
  3641. */
  3642. int wolfSSL_X509_get_isCA(WOLFSSL_X509*);
  3643. /*!
  3644. \ingroup CertsKeys
  3645. \brief This function gets the text related to the passed in NID value.
  3646. \return int returns the size of the text buffer.
  3647. \param name WOLFSSL_X509_NAME to search for text.
  3648. \param nid NID to search for.
  3649. \param buf buffer to hold text when found.
  3650. \param len length of buffer.
  3651. _Example_
  3652. \code
  3653. WOLFSSL_X509_NAME* name;
  3654. char buffer[100];
  3655. int bufferSz;
  3656. int ret;
  3657. // get WOLFSSL_X509_NAME
  3658. ret = wolfSSL_X509_NAME_get_text_by_NID(name, NID_commonName,
  3659. buffer, bufferSz);
  3660. //check ret value
  3661. \endcode
  3662. \sa none
  3663. */
  3664. int wolfSSL_X509_NAME_get_text_by_NID(WOLFSSL_X509_NAME* name, int nid,
  3665. char* buf, int len);
  3666. /*!
  3667. \ingroup CertsKeys
  3668. \brief This function returns the value stored in the sigOID
  3669. member of the WOLFSSL_X509 structure.
  3670. \return 0 returned if the WOLFSSL_X509 structure is NULL.
  3671. \return int an integer value is returned which was retrieved from
  3672. the x509 object.
  3673. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3674. _Example_
  3675. \code
  3676. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  3677. DYNAMIC_TYPE_X509);
  3678. ...
  3679. int x509SigType = wolfSSL_X509_get_signature_type(x509);
  3680. if(x509SigType != EXPECTED){
  3681. // Deal with an unexpected value
  3682. }
  3683. \endcode
  3684. \sa wolfSSL_X509_get_signature
  3685. \sa wolfSSL_X509_version
  3686. \sa wolfSSL_X509_get_der
  3687. \sa wolfSSL_X509_get_serial_number
  3688. \sa wolfSSL_X509_notBefore
  3689. \sa wolfSSL_X509_notAfter
  3690. \sa wolfSSL_X509_free
  3691. */
  3692. int wolfSSL_X509_get_signature_type(WOLFSSL_X509*);
  3693. /*!
  3694. \brief This function frees a WOLFSSL_X509 structure.
  3695. \param x509 a pointer to the WOLFSSL_X509 struct.
  3696. _Example_
  3697. \code
  3698. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALOC(sizeof(WOLFSSL_X509), NULL,
  3699. DYNAMIC_TYPE_X509) ;
  3700. wolfSSL_X509_free(x509);
  3701. \endcode
  3702. \sa wolfSSL_X509_get_signature
  3703. \sa wolfSSL_X509_version
  3704. \sa wolfSSL_X509_get_der
  3705. \sa wolfSSL_X509_get_serial_number
  3706. \sa wolfSSL_X509_notBefore
  3707. \sa wolfSSL_X509_notAfter
  3708. */
  3709. void wolfSSL_X509_free(WOLFSSL_X509* x509);
  3710. /*!
  3711. \ingroup CertsKeys
  3712. \brief Gets the X509 signature and stores it in the buffer.
  3713. \return SSL_SUCCESS returned if the function successfully executes.
  3714. The signature is loaded into the buffer.
  3715. \return SSL_FATAL_ERRROR returns if the x509 struct or the bufSz member
  3716. is NULL. There is also a check for the length member of the sig structure
  3717. (sig is a member of x509).
  3718. \param x509 pointer to a WOLFSSL_X509 structure.
  3719. \param buf a char pointer to the buffer.
  3720. \param bufSz an integer pointer to the size of the buffer.
  3721. _Example_
  3722. \code
  3723. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  3724. DYNAMIC_TYPE_X509);
  3725. unsigned char* buf; // Initialize
  3726. int* bufSz = sizeof(buf)/sizeof(unsigned char);
  3727. ...
  3728. if(wolfSSL_X509_get_signature(x509, buf, bufSz) != SSL_SUCCESS){
  3729. // The function did not execute successfully.
  3730. } else{
  3731. // The buffer was written to correctly.
  3732. }
  3733. \endcode
  3734. \sa wolfSSL_X509_get_serial_number
  3735. \sa wolfSSL_X509_get_signature_type
  3736. \sa wolfSSL_X509_get_device_type
  3737. */
  3738. int wolfSSL_X509_get_signature(WOLFSSL_X509* x509, unsigned char* buf, int* bufSz);
  3739. /*!
  3740. \ingroup CertsKeys
  3741. \brief This function adds a certificate to the WOLFSSL_X509_STRE structure.
  3742. \return SSL_SUCCESS If certificate is added successfully.
  3743. \return SSL_FATAL_ERROR: If certificate is not added successfully.
  3744. \param str certificate store to add the certificate to.
  3745. \param x509 certificate to add.
  3746. _Example_
  3747. \code
  3748. WOLFSSL_X509_STORE* str;
  3749. WOLFSSL_X509* x509;
  3750. int ret;
  3751. ret = wolfSSL_X509_STORE_add_cert(str, x509);
  3752. //check ret value
  3753. \endcode
  3754. \sa wolfSSL_X509_free
  3755. */
  3756. int wolfSSL_X509_STORE_add_cert(WOLFSSL_X509_STORE* store, WOLFSSL_X509* x509);
  3757. /*!
  3758. \ingroup CertsKeys
  3759. \brief This function is a getter function for chain variable
  3760. in WOLFSSL_X509_STORE_CTX structure. Currently chain is not populated.
  3761. \return pointer if successful returns WOLFSSL_STACK
  3762. (same as STACK_OF(WOLFSSL_X509)) pointer
  3763. \return Null upon failure
  3764. \param ctx certificate store ctx to get parse chain from.
  3765. _Example_
  3766. \code
  3767. WOLFSSL_STACK* sk;
  3768. WOLFSSL_X509_STORE_CTX* ctx;
  3769. sk = wolfSSL_X509_STORE_CTX_get_chain(ctx);
  3770. //check sk for NULL and then use it. sk needs freed after done.
  3771. \endcode
  3772. \sa wolfSSL_sk_X509_free
  3773. */
  3774. WOLFSSL_STACK* wolfSSL_X509_STORE_CTX_get_chain(
  3775. WOLFSSL_X509_STORE_CTX* ctx);
  3776. /*!
  3777. \ingroup CertsKeys
  3778. \brief This function takes in a flag to change the behavior of the
  3779. WOLFSSL_X509_STORE structure passed in. An example of a flag used
  3780. is WOLFSSL_CRL_CHECK.
  3781. \return SSL_SUCCESS If no errors were encountered when setting the flag.
  3782. \return <0 a negative value will be returned upon failure.
  3783. \param str certificate store to set flag in.
  3784. \param flag flag for behavior.
  3785. _Example_
  3786. \code
  3787. WOLFSSL_X509_STORE* str;
  3788. int ret;
  3789. // create and set up str
  3790. ret = wolfSSL_X509_STORE_set_flags(str, WOLFSSL_CRL_CHECKALL);
  3791. If (ret != SSL_SUCCESS) {
  3792. //check ret value and handle error case
  3793. }
  3794. \endcode
  3795. \sa wolfSSL_X509_STORE_new
  3796. \sa wolfSSL_X509_STORE_free
  3797. */
  3798. int wolfSSL_X509_STORE_set_flags(WOLFSSL_X509_STORE* store,
  3799. unsigned long flag);
  3800. /*!
  3801. \ingroup CertsKeys
  3802. \brief This function the certificate "not before" validity encoded as
  3803. a byte array.
  3804. \return NULL returned if the WOLFSSL_X509 structure is NULL.
  3805. \return byte is returned that contains the notBeforeData.
  3806. \param x509 pointer to a WOLFSSL_X509 structure.
  3807. _Example_
  3808. \code
  3809. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  3810. DYNAMIC_TYPE_X509);
  3811. ...
  3812. byte* notBeforeData = wolfSSL_X509_notBefore(x509);
  3813. \endcode
  3814. \sa wolfSSL_X509_get_signature
  3815. \sa wolfSSL_X509_version
  3816. \sa wolfSSL_X509_get_der
  3817. \sa wolfSSL_X509_get_serial_number
  3818. \sa wolfSSL_X509_notAfter
  3819. \sa wolfSSL_X509_free
  3820. */
  3821. const byte* wolfSSL_X509_notBefore(WOLFSSL_X509* x509);
  3822. /*!
  3823. \ingroup CertsKeys
  3824. \brief This function the certificate "not after" validity encoded as
  3825. a byte array.
  3826. \return NULL returned if the WOLFSSL_X509 structure is NULL.
  3827. \return byte is returned that contains the notAfterData.
  3828. \param x509 pointer to a WOLFSSL_X509 structure.
  3829. _Example_
  3830. \code
  3831. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  3832. DYNAMIC_TYPE_X509);
  3833. ...
  3834. byte* notAfterData = wolfSSL_X509_notAfter(x509);
  3835. \endcode
  3836. \sa wolfSSL_X509_get_signature
  3837. \sa wolfSSL_X509_version
  3838. \sa wolfSSL_X509_get_der
  3839. \sa wolfSSL_X509_get_serial_number
  3840. \sa wolfSSL_X509_notBefore
  3841. \sa wolfSSL_X509_free
  3842. */
  3843. const byte* wolfSSL_X509_notAfter(WOLFSSL_X509* x509);
  3844. /*!
  3845. \ingroup Setup
  3846. \brief This function is used to copy a WOLFSSL_ASN1_INTEGER
  3847. value to a WOLFSSL_BIGNUM structure.
  3848. \return pointer On successfully copying the WOLFSSL_ASN1_INTEGER
  3849. value a WOLFSSL_BIGNUM pointer is returned.
  3850. \return Null upon failure.
  3851. \param ai WOLFSSL_ASN1_INTEGER structure to copy from.
  3852. \param bn if wanting to copy into an already existing
  3853. WOLFSSL_BIGNUM struct then pass in a pointer to it.
  3854. Optionally this can be NULL and a new WOLFSSL_BIGNUM
  3855. structure will be created.
  3856. _Example_
  3857. \code
  3858. WOLFSSL_ASN1_INTEGER* ai;
  3859. WOLFSSL_BIGNUM* bn;
  3860. // create ai
  3861. bn = wolfSSL_ASN1_INTEGER_to_BN(ai, NULL);
  3862. // or if having already created bn and wanting to reuse structure
  3863. // wolfSSL_ASN1_INTEGER_to_BN(ai, bn);
  3864. // check bn is or return value is not NULL
  3865. \endcode
  3866. \sa none
  3867. */
  3868. WOLFSSL_BIGNUM *wolfSSL_ASN1_INTEGER_to_BN(const WOLFSSL_ASN1_INTEGER *ai,
  3869. WOLFSSL_BIGNUM *bn);
  3870. /*!
  3871. \ingroup Setup
  3872. \brief This function adds the certificate to the internal chain
  3873. being built in the WOLFSSL_CTX structure.
  3874. \return SSL_SUCCESS after successfully adding the certificate.
  3875. \return SSL_FAILURE if failing to add the certificate to the chain.
  3876. \param ctx WOLFSSL_CTX structure to add certificate to.
  3877. \param x509 certificate to add to the chain.
  3878. _Example_
  3879. \code
  3880. WOLFSSL_CTX* ctx;
  3881. WOLFSSL_X509* x509;
  3882. int ret;
  3883. // create ctx
  3884. ret = wolfSSL_CTX_add_extra_chain_cert(ctx, x509);
  3885. // check ret value
  3886. \endcode
  3887. \sa wolfSSL_CTX_new
  3888. \sa wolfSSL_CTX_free
  3889. */
  3890. long wolfSSL_CTX_add_extra_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509);
  3891. /*!
  3892. \ingroup Setup
  3893. \brief This function returns the get read ahead flag from a
  3894. WOLFSSL_CTX structure.
  3895. \return flag On success returns the read ahead flag.
  3896. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  3897. \param ctx WOLFSSL_CTX structure to get read ahead flag from.
  3898. _Example_
  3899. \code
  3900. WOLFSSL_CTX* ctx;
  3901. int flag;
  3902. // setup ctx
  3903. flag = wolfSSL_CTX_get_read_ahead(ctx);
  3904. //check flag
  3905. \endcode
  3906. \sa wolfSSL_CTX_new
  3907. \sa wolfSSL_CTX_free
  3908. \sa wolfSSL_CTX_set_read_ahead
  3909. */
  3910. int wolfSSL_CTX_get_read_ahead(WOLFSSL_CTX*);
  3911. /*!
  3912. \ingroup Setup
  3913. \brief This function sets the read ahead flag in the WOLFSSL_CTX structure.
  3914. \return SSL_SUCCESS If ctx read ahead flag set.
  3915. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  3916. \param ctx WOLFSSL_CTX structure to set read ahead flag.
  3917. _Example_
  3918. \code
  3919. WOLFSSL_CTX* ctx;
  3920. int flag;
  3921. int ret;
  3922. // setup ctx
  3923. ret = wolfSSL_CTX_set_read_ahead(ctx, flag);
  3924. // check return value
  3925. \endcode
  3926. \sa wolfSSL_CTX_new
  3927. \sa wolfSSL_CTX_free
  3928. \sa wolfSSL_CTX_get_read_ahead
  3929. */
  3930. int wolfSSL_CTX_set_read_ahead(WOLFSSL_CTX* ctx, int v);
  3931. /*!
  3932. \ingroup Setup
  3933. \brief This function sets the options argument to use with OCSP.
  3934. \return SSL_FAILURE If ctx or it’s cert manager is NULL.
  3935. \return SSL_SUCCESS If successfully set.
  3936. \param ctx WOLFSSL_CTX structure to set user argument.
  3937. \param arg user argument.
  3938. _Example_
  3939. \code
  3940. WOLFSSL_CTX* ctx;
  3941. void* data;
  3942. int ret;
  3943. // setup ctx
  3944. ret = wolfSSL_CTX_set_tlsext_status_arg(ctx, data);
  3945. //check ret value
  3946. \endcode
  3947. \sa wolfSSL_CTX_new
  3948. \sa wolfSSL_CTX_free
  3949. */
  3950. long wolfSSL_CTX_set_tlsext_status_arg(WOLFSSL_CTX* ctx, void* arg);
  3951. /*!
  3952. \ingroup Setup
  3953. \brief This function sets the optional argument to be passed to
  3954. the PRF callback.
  3955. \return SSL_FAILURE If ctx is NULL.
  3956. \return SSL_SUCCESS If successfully set.
  3957. \param ctx WOLFSSL_CTX structure to set user argument.
  3958. \param arg user argument.
  3959. _Example_
  3960. \code
  3961. WOLFSSL_CTX* ctx;
  3962. void* data;
  3963. int ret;
  3964. // setup ctx
  3965. ret = wolfSSL_CTX_set_tlsext_opaques_prf_input_callback_arg(ctx, data);
  3966. //check ret value
  3967. \endcode
  3968. \sa wolfSSL_CTX_new
  3969. \sa wolfSSL_CTX_free
  3970. */
  3971. long wolfSSL_CTX_set_tlsext_opaque_prf_input_callback_arg(
  3972. WOLFSSL_CTX* ctx, void* arg);
  3973. /*!
  3974. \ingroup Setup
  3975. \brief This function sets the options mask in the ssl.
  3976. Some valid options are, SSL_OP_ALL, SSL_OP_COOKIE_EXCHANGE,
  3977. SSL_OP_NO_SSLv2, SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1,
  3978. SSL_OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_2, SSL_OP_NO_COMPRESSION.
  3979. \return val Returns the updated options mask value stored in ssl.
  3980. \param s WOLFSSL structure to set options mask.
  3981. \param op This function sets the options mask in the ssl.
  3982. Some valid options are:
  3983. SSL_OP_ALL
  3984. SSL_OP_COOKIE_EXCHANGE
  3985. SSL_OP_NO_SSLv2
  3986. SSL_OP_NO_SSLv3
  3987. SSL_OP_NO_TLSv1
  3988. SSL_OP_NO_TLSv1_1
  3989. SSL_OP_NO_TLSv1_2
  3990. SSL_OP_NO_COMPRESSION
  3991. _Example_
  3992. \code
  3993. WOLFSSL* ssl;
  3994. unsigned long mask;
  3995. mask = SSL_OP_NO_TLSv1
  3996. mask = wolfSSL_set_options(ssl, mask);
  3997. // check mask
  3998. \endcode
  3999. \sa wolfSSL_new
  4000. \sa wolfSSL_free
  4001. \sa wolfSSL_get_options
  4002. */
  4003. long wolfSSL_set_options(WOLFSSL *s, long op);
  4004. /*!
  4005. \ingroup Setup
  4006. \brief This function returns the current options mask.
  4007. \return val Returns the mask value stored in ssl.
  4008. \param ssl WOLFSSL structure to get options mask from.
  4009. _Example_
  4010. \code
  4011. WOLFSSL* ssl;
  4012. unsigned long mask;
  4013. mask = wolfSSL_get_options(ssl);
  4014. // check mask
  4015. \endcode
  4016. \sa wolfSSL_new
  4017. \sa wolfSSL_free
  4018. \sa wolfSSL_set_options
  4019. */
  4020. long wolfSSL_get_options(const WOLFSSL *s);
  4021. /*!
  4022. \ingroup Setup
  4023. \brief This is used to set the debug argument passed around.
  4024. \return SSL_SUCCESS On successful setting argument.
  4025. \return SSL_FAILURE If an NULL ssl passed in.
  4026. \param ssl WOLFSSL structure to set argument in.
  4027. \param arg argument to use.
  4028. _Example_
  4029. \code
  4030. WOLFSSL* ssl;
  4031. void* args;
  4032. int ret;
  4033. // create ssl object
  4034. ret = wolfSSL_set_tlsext_debug_arg(ssl, args);
  4035. // check ret value
  4036. \endcode
  4037. \sa wolfSSL_new
  4038. \sa wolfSSL_free
  4039. */
  4040. long wolfSSL_set_tlsext_debug_arg(WOLFSSL *s, void *arg);
  4041. /*!
  4042. \ingroup openSSL
  4043. \brief This function is called when the client application request
  4044. that a server send back an OCSP status response (also known as
  4045. OCSP stapling).Currently, the only supported type is
  4046. TLSEXT_STATUSTYPE_ocsp.
  4047. \return 1 upon success.
  4048. \return 0 upon error.
  4049. \param s pointer to WolfSSL struct which is created by SSL_new() function
  4050. \param type ssl extension type which TLSEXT_STATUSTYPE_ocsp is
  4051. only supported.
  4052. _Example_
  4053. \code
  4054. WOLFSSL *ssl;
  4055. WOLFSSL_CTX *ctx;
  4056. int ret;
  4057. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4058. ssl = wolfSSL_new(ctx);
  4059. ret = WolfSSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp);
  4060. wolfSSL_free(ssl);
  4061. wolfSSL_CTX_free(ctx);
  4062. \endcode
  4063. \sa wolfSSL_new
  4064. \sa wolfSSL_CTX_new
  4065. \sa wolfSSL_free
  4066. \sa wolfSSL_CTX_free
  4067. */
  4068. long wolfSSL_set_tlsext_status_type(WOLFSSL *s, int type);
  4069. /*!
  4070. \ingroup Setup
  4071. \brief This is used to get the results after trying to verify the peer's
  4072. certificate.
  4073. \return X509_V_OK On successful verification.
  4074. \return SSL_FAILURE If an NULL ssl passed in.
  4075. \param ssl WOLFSSL structure to get verification results from.
  4076. _Example_
  4077. \code
  4078. WOLFSSL* ssl;
  4079. long ret;
  4080. // attempt/complete handshake
  4081. ret = wolfSSL_get_verify_result(ssl);
  4082. // check ret value
  4083. \endcode
  4084. \sa wolfSSL_new
  4085. \sa wolfSSL_free
  4086. */
  4087. long wolfSSL_get_verify_result(const WOLFSSL *ssl);
  4088. /*!
  4089. \ingroup Debug
  4090. \brief This function converts an error code returned by
  4091. wolfSSL_get_error() into a more human-readable error string
  4092. and prints that string to the output file - fp. err is the
  4093. error code returned by wolfSSL_get_error() and fp is the
  4094. file which the error string will be placed in.
  4095. \return none No returns.
  4096. \param fp output file for human-readable error string to be written to.
  4097. \param err error code returned by wolfSSL_get_error().
  4098. _Example_
  4099. \code
  4100. int err = 0;
  4101. WOLFSSL* ssl;
  4102. FILE* fp = ...
  4103. ...
  4104. err = wolfSSL_get_error(ssl, 0);
  4105. wolfSSL_ERR_print_errors_fp(fp, err);
  4106. \endcode
  4107. \sa wolfSSL_get_error
  4108. \sa wolfSSL_ERR_error_string
  4109. \sa wolfSSL_ERR_error_string_n
  4110. \sa wolfSSL_load_error_strings
  4111. */
  4112. void wolfSSL_ERR_print_errors_fp(XFILE fp, int err);
  4113. /*!
  4114. \ingroup Debug
  4115. \brief This function uses the provided callback to handle error reporting.
  4116. The callback function is executed for each error line. The string, length,
  4117. and userdata are passed into the callback parameters.
  4118. \return none No returns.
  4119. \param cb the callback function.
  4120. \param u userdata to pass into the callback function.
  4121. _Example_
  4122. \code
  4123. int error_cb(const char *str, size_t len, void *u)
  4124. { fprintf((FILE*)u, "%-*.*s\n", (int)len, (int)len, str); return 0; }
  4125. ...
  4126. FILE* fp = ...
  4127. wolfSSL_ERR_print_errors_cb(error_cb, fp);
  4128. \endcode
  4129. \sa wolfSSL_get_error
  4130. \sa wolfSSL_ERR_error_string
  4131. \sa wolfSSL_ERR_error_string_n
  4132. \sa wolfSSL_load_error_strings
  4133. */
  4134. void wolfSSL_ERR_print_errors_cb (
  4135. int (*cb)(const char *str, size_t len, void *u), void *u);
  4136. /*!
  4137. \brief The function sets the client_psk_cb member of the
  4138. WOLFSSL_CTX structure.
  4139. \return none No returns.
  4140. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4141. wolfSSL_CTX_new().
  4142. \param cb wc_psk_client_callback is a function pointer that will be
  4143. stored in the WOLFSSL_CTX structure. Return value is the key length on
  4144. success or zero on error.
  4145. unsigned int (*wc_psk_client_callback)
  4146. PSK client callback parameters:
  4147. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4148. const char* hint - A stored string that could be displayed to provide a
  4149. hint to the user.
  4150. char* identity - The ID will be stored here.
  4151. unsigned int id_max_len - Size of the ID buffer.
  4152. unsigned char* key - The key will be stored here.
  4153. unsigned int key_max_len - The max size of the key.
  4154. _Example_
  4155. \code
  4156. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  4157. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4158. char* identity, unsigned int id_max_len, unsigned char* key,
  4159. Unsigned int key_max_len){
  4160. wolfSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
  4161. \endcode
  4162. \sa wolfSSL_set_psk_client_callback
  4163. \sa wolfSSL_set_psk_server_callback
  4164. \sa wolfSSL_CTX_set_psk_server_callback
  4165. \sa wolfSSL_CTX_set_psk_client_callback
  4166. */
  4167. void wolfSSL_CTX_set_psk_client_callback(WOLFSSL_CTX* ctx,
  4168. wc_psk_client_callback);
  4169. /*!
  4170. \brief Sets the PSK client side callback.
  4171. \return none No returns.
  4172. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4173. \param cb a function pointer to type wc_psk_client_callback. Return value
  4174. is the key length on success or zero on error.
  4175. unsigned int (*wc_psk_client_callback)
  4176. PSK client callback parameters:
  4177. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4178. const char* hint - A stored string that could be displayed to provide a
  4179. hint to the user.
  4180. char* identity - The ID will be stored here.
  4181. unsigned int id_max_len - Size of the ID buffer.
  4182. unsigned char* key - The key will be stored here.
  4183. unsigned int key_max_len - The max size of the key.
  4184. _Example_
  4185. \code
  4186. WOLFSSL* ssl;
  4187. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4188. char* identity, unsigned int id_max_len, unsigned char* key,
  4189. Unsigned int key_max_len){
  4190. if(ssl){
  4191. wolfSSL_set_psk_client_callback(ssl, my_psk_client_cb);
  4192. } else {
  4193. // could not set callback
  4194. }
  4195. \endcode
  4196. \sa wolfSSL_CTX_set_psk_client_callback
  4197. \sa wolfSSL_CTX_set_psk_server_callback
  4198. \sa wolfSSL_set_psk_server_callback
  4199. */
  4200. void wolfSSL_set_psk_client_callback(WOLFSSL* ssl,
  4201. wc_psk_client_callback);
  4202. /*!
  4203. \ingroup CertsKeys
  4204. \brief This function returns the psk identity hint.
  4205. \return pointer a const char pointer to the value that was stored in
  4206. the arrays member of the WOLFSSL structure is returned.
  4207. \return NULL returned if the WOLFSSL or Arrays structures are NULL.
  4208. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4209. _Example_
  4210. \code
  4211. WOLFSSL* ssl = wolfSSL_new(ctx);
  4212. char* idHint;
  4213. ...
  4214. idHint = wolfSSL_get_psk_identity_hint(ssl);
  4215. if(idHint){
  4216. // The hint was retrieved
  4217. return idHint;
  4218. } else {
  4219. // Hint wasn’t successfully retrieved
  4220. }
  4221. \endcode
  4222. \sa wolfSSL_get_psk_identity
  4223. */
  4224. const char* wolfSSL_get_psk_identity_hint(const WOLFSSL*);
  4225. /*!
  4226. \ingroup CertsKeys
  4227. \brief The function returns a constant pointer to the client_identity
  4228. member of the Arrays structure.
  4229. \return string the string value of the client_identity member of the
  4230. Arrays structure.
  4231. \return NULL if the WOLFSSL structure is NULL or if the Arrays member of
  4232. the WOLFSSL structure is NULL.
  4233. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4234. _Example_
  4235. \code
  4236. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4237. WOLFSSL* ssl = wolfSSL_new(ctx);
  4238. const char* pskID;
  4239. ...
  4240. pskID = wolfSSL_get_psk_identity(ssl);
  4241. if(pskID == NULL){
  4242. // There is not a value in pskID
  4243. }
  4244. \endcode
  4245. \sa wolfSSL_get_psk_identity_hint
  4246. \sa wolfSSL_use_psk_identity_hint
  4247. */
  4248. const char* wolfSSL_get_psk_identity(const WOLFSSL*);
  4249. /*!
  4250. \ingroup CertsKeys
  4251. \brief This function stores the hint argument in the server_hint
  4252. member of the WOLFSSL_CTX structure.
  4253. \return SSL_SUCCESS returned for successful execution of the function.
  4254. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4255. wolfSSL_CTX_new().
  4256. \param hint a constant char pointer that will be copied to the
  4257. WOLFSSL_CTX structure.
  4258. _Example_
  4259. \code
  4260. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4261. const char* hint;
  4262. int ret;
  4263. ret = wolfSSL_CTX_use_psk_identity_hint(ctx, hint);
  4264. if(ret == SSL_SUCCESS){
  4265. // Function was successful.
  4266. return ret;
  4267. } else {
  4268. // Failure case.
  4269. }
  4270. \endcode
  4271. \sa wolfSSL_use_psk_identity_hint
  4272. */
  4273. int wolfSSL_CTX_use_psk_identity_hint(WOLFSSL_CTX* ctx, const char* hint);
  4274. /*!
  4275. \ingroup CertsKeys
  4276. \brief This function stores the hint argument in the server_hint member
  4277. of the Arrays structure within the WOLFSSL structure.
  4278. \return SSL_SUCCESS returned if the hint was successfully stored in the
  4279. WOLFSSL structure.
  4280. \return SSL_FAILURE returned if the WOLFSSL or Arrays structures are NULL.
  4281. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4282. \param hint a constant character pointer that holds the hint to be saved
  4283. in memory.
  4284. _Example_
  4285. \code
  4286. WOLFSSL* ssl = wolfSSL_new(ctx);
  4287. const char* hint;
  4288. ...
  4289. if(wolfSSL_use_psk_identity_hint(ssl, hint) != SSL_SUCCESS){
  4290. // Handle failure case.
  4291. }
  4292. \endcode
  4293. \sa wolfSSL_CTX_use_psk_identity_hint
  4294. */
  4295. int wolfSSL_use_psk_identity_hint(WOLFSSL* ssl, const char* hint);
  4296. /*!
  4297. \brief This function sets the psk callback for the server side in
  4298. the WOLFSSL_CTX structure.
  4299. \return none No returns.
  4300. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4301. \param cb a function pointer for the callback and will be stored in
  4302. the WOLFSSL_CTX structure. Return value is the key length on success or
  4303. zero on error.
  4304. unsigned int (*wc_psk_server_callback)
  4305. PSK server callback parameters
  4306. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4307. char* identity - The ID will be stored here.
  4308. unsigned char* key - The key will be stored here.
  4309. unsigned int key_max_len - The max size of the key.
  4310. _Example_
  4311. \code
  4312. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4313. WOLFSSL* ssl = wolfSSL_new(ctx);
  4314. static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
  4315. unsigned char* key, unsigned int key_max_len)
  4316. {
  4317. // Function body.
  4318. }
  4319. if(ctx != NULL){
  4320. wolfSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
  4321. } else {
  4322. // The CTX object was not properly initialized.
  4323. }
  4324. \endcode
  4325. \sa wc_psk_server_callback
  4326. \sa wolfSSL_set_psk_client_callback
  4327. \sa wolfSSL_set_psk_server_callback
  4328. \sa wolfSSL_CTX_set_psk_client_callback
  4329. */
  4330. void wolfSSL_CTX_set_psk_server_callback(WOLFSSL_CTX* ctx,
  4331. wc_psk_server_callback cb);
  4332. /*!
  4333. \brief Sets the psk callback for the server side by setting the
  4334. WOLFSSL structure options members.
  4335. \return none No returns.
  4336. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4337. \param cb a function pointer for the callback and will be stored in
  4338. the WOLFSSL structure. Return value is the key length on success or zero
  4339. on error.
  4340. unsigned int (*wc_psk_server_callback)
  4341. PSK server callback parameters
  4342. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4343. char* identity - The ID will be stored here.
  4344. unsigned char* key - The key will be stored here.
  4345. unsigned int key_max_len - The max size of the key.
  4346. _Example_
  4347. \code
  4348. WOLFSSL_CTX* ctx;
  4349. WOLFSSL* ssl;
  4350. static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
  4351. unsigned char* key, unsigned int key_max_len)
  4352. {
  4353. // Function body.
  4354. }
  4355. if(ssl != NULL && cb != NULL){
  4356. wolfSSL_set_psk_server_callback(ssl, my_psk_server_cb);
  4357. }
  4358. \endcode
  4359. \sa wolfSSL_set_psk_client_callback
  4360. \sa wolfSSL_CTX_set_psk_server_callback
  4361. \sa wolfSSL_CTX_set_psk_client_callback
  4362. \sa wolfSSL_get_psk_identity_hint
  4363. \sa wc_psk_server_callback
  4364. \sa InitSuites
  4365. */
  4366. void wolfSSL_set_psk_server_callback(WOLFSSL* ssl,
  4367. wc_psk_server_callback cb);
  4368. /*!
  4369. \brief Sets a PSK user context in the WOLFSSL structure options member.
  4370. \return WOLFSSL_SUCCESS or WOLFSSL_FAILURE
  4371. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4372. \param psk_ctx void pointer to user PSK context
  4373. \sa wolfSSL_get_psk_callback_ctx
  4374. \sa wolfSSL_CTX_set_psk_callback_ctx
  4375. \sa wolfSSL_CTX_get_psk_callback_ctx
  4376. */
  4377. int wolfSSL_set_psk_callback_ctx(WOLFSSL* ssl, void* psk_ctx);
  4378. /*!
  4379. \brief Sets a PSK user context in the WOLFSSL_CTX structure.
  4380. \return WOLFSSL_SUCCESS or WOLFSSL_FAILURE
  4381. \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
  4382. \param psk_ctx void pointer to user PSK context
  4383. \sa wolfSSL_set_psk_callback_ctx
  4384. \sa wolfSSL_get_psk_callback_ctx
  4385. \sa wolfSSL_CTX_get_psk_callback_ctx
  4386. */
  4387. int wolfSSL_CTX_set_psk_callback_ctx(WOLFSSL_CTX* ctx, void* psk_ctx);
  4388. /*!
  4389. \brief Get a PSK user context in the WOLFSSL structure options member.
  4390. \return void pointer to user PSK context
  4391. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4392. \sa wolfSSL_set_psk_callback_ctx
  4393. \sa wolfSSL_CTX_set_psk_callback_ctx
  4394. \sa wolfSSL_CTX_get_psk_callback_ctx
  4395. */
  4396. void* wolfSSL_get_psk_callback_ctx(WOLFSSL* ssl);
  4397. /*!
  4398. \brief Get a PSK user context in the WOLFSSL_CTX structure.
  4399. \return void pointer to user PSK context
  4400. \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
  4401. \sa wolfSSL_CTX_set_psk_callback_ctx
  4402. \sa wolfSSL_set_psk_callback_ctx
  4403. \sa wolfSSL_get_psk_callback_ctx
  4404. */
  4405. void* wolfSSL_CTX_get_psk_callback_ctx(WOLFSSL_CTX* ctx);
  4406. /*!
  4407. \ingroup Setup
  4408. \brief This function enables the havAnon member of the CTX structure if
  4409. HAVE_ANON is defined during compilation.
  4410. \return SSL_SUCCESS returned if the function executed successfully and the
  4411. haveAnnon member of the CTX is set to 1.
  4412. \return SSL_FAILURE returned if the CTX structure was NULL.
  4413. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4414. wolfSSL_CTX_new().
  4415. _Example_
  4416. \code
  4417. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4418. WOLFSSL* ssl = wolfSSL_new(ctx);
  4419. ...
  4420. #ifdef HAVE_ANON
  4421. if(cipherList == NULL){
  4422. wolfSSL_CTX_allow_anon_cipher(ctx);
  4423. if(wolfSSL_CTX_set_cipher_list(ctx, “ADH_AES128_SHA”) != SSL_SUCCESS){
  4424. // failure case
  4425. }
  4426. }
  4427. #endif
  4428. \endcode
  4429. \sa none
  4430. */
  4431. int wolfSSL_CTX_allow_anon_cipher(WOLFSSL_CTX*);
  4432. /*!
  4433. \ingroup Setup
  4434. \brief The wolfSSLv23_server_method() function is used to indicate
  4435. that the application is a server and will support clients connecting
  4436. with protocol version from SSL 3.0 - TLS 1.3. This function allocates
  4437. memory for and initializes a new WOLFSSL_METHOD structure to be used when
  4438. creating the SSL/TLS context with wolfSSL_CTX_new().
  4439. \return pointer If successful, the call will return a pointer to the newly
  4440. created WOLFSSL_METHOD structure.
  4441. \return Failure If memory allocation fails when calling XMALLOC, the
  4442. failure value of the underlying malloc() implementation will be returned
  4443. (typically NULL with errno will be set to ENOMEM).
  4444. \param none No parameters
  4445. _Example_
  4446. \code
  4447. WOLFSSL_METHOD* method;
  4448. WOLFSSL_CTX* ctx;
  4449. method = wolfSSLv23_server_method();
  4450. if (method == NULL) {
  4451. // unable to get method
  4452. }
  4453. ctx = wolfSSL_CTX_new(method);
  4454. ...
  4455. \endcode
  4456. \sa wolfSSLv3_server_method
  4457. \sa wolfTLSv1_server_method
  4458. \sa wolfTLSv1_1_server_method
  4459. \sa wolfTLSv1_2_server_method
  4460. \sa wolfTLSv1_3_server_method
  4461. \sa wolfDTLSv1_server_method
  4462. \sa wolfSSL_CTX_new
  4463. */
  4464. WOLFSSL_METHOD *wolfSSLv23_server_method(void);
  4465. /*!
  4466. \ingroup Setup
  4467. \brief This is used to get the internal error state of the WOLFSSL structure.
  4468. \return wolfssl_error returns ssl error state, usually a negative
  4469. \return BAD_FUNC_ARG if ssl is NULL.
  4470. \return ssl WOLFSSL structure to get state from.
  4471. _Example_
  4472. \code
  4473. WOLFSSL* ssl;
  4474. int ret;
  4475. // create ssl object
  4476. ret = wolfSSL_state(ssl);
  4477. // check ret value
  4478. \endcode
  4479. \sa wolfSSL_new
  4480. \sa wolfSSL_free
  4481. */
  4482. int wolfSSL_state(WOLFSSL* ssl);
  4483. /*!
  4484. \ingroup CertsKeys
  4485. \brief This function gets the peer’s certificate.
  4486. \return pointer a pointer to the peerCert member of the WOLFSSL_X509
  4487. structure if it exists.
  4488. \return 0 returned if the peer certificate issuer size is not defined.
  4489. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4490. _Example_
  4491. \code
  4492. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4493. WOLFSSL* ssl = wolfSSL_new(ctx);
  4494. ...
  4495. WOLFSSL_X509* peerCert = wolfSSL_get_peer_certificate(ssl);
  4496. if(peerCert){
  4497. // You have a pointer peerCert to the peer certification
  4498. }
  4499. \endcode
  4500. \sa wolfSSL_X509_get_issuer_name
  4501. \sa wolfSSL_X509_get_subject_name
  4502. \sa wolfSSL_X509_get_isCA
  4503. */
  4504. WOLFSSL_X509* wolfSSL_get_peer_certificate(WOLFSSL* ssl);
  4505. /*!
  4506. \ingroup Debug
  4507. \brief This function is similar to calling wolfSSL_get_error() and
  4508. getting SSL_ERROR_WANT_READ in return. If the underlying error state
  4509. is SSL_ERROR_WANT_READ, this function will return 1, otherwise, 0.
  4510. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_READ, the
  4511. underlying I/O has data available for reading.
  4512. \return 0 There is no SSL_ERROR_WANT_READ error state.
  4513. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4514. _Example_
  4515. \code
  4516. int ret;
  4517. WOLFSSL* ssl = 0;
  4518. ...
  4519. ret = wolfSSL_want_read(ssl);
  4520. if (ret == 1) {
  4521. // underlying I/O has data available for reading (SSL_ERROR_WANT_READ)
  4522. }
  4523. \endcode
  4524. \sa wolfSSL_want_write
  4525. \sa wolfSSL_get_error
  4526. */
  4527. int wolfSSL_want_read(WOLFSSL*);
  4528. /*!
  4529. \ingroup Debug
  4530. \brief This function is similar to calling wolfSSL_get_error() and getting
  4531. SSL_ERROR_WANT_WRITE in return. If the underlying error state is
  4532. SSL_ERROR_WANT_WRITE, this function will return 1, otherwise, 0.
  4533. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_WRITE, the
  4534. underlying I/O needs data to be written in order for progress to be
  4535. made in the underlying SSL connection.
  4536. \return 0 There is no SSL_ERROR_WANT_WRITE error state.
  4537. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4538. _Example_
  4539. \code
  4540. int ret;
  4541. WOLFSSL* ssl = 0;
  4542. ...
  4543. ret = wolfSSL_want_write(ssl);
  4544. if (ret == 1) {
  4545. // underlying I/O needs data to be written (SSL_ERROR_WANT_WRITE)
  4546. }
  4547. \endcode
  4548. \sa wolfSSL_want_read
  4549. \sa wolfSSL_get_error
  4550. */
  4551. int wolfSSL_want_write(WOLFSSL*);
  4552. /*!
  4553. \ingroup Setup
  4554. \brief wolfSSL by default checks the peer certificate for a valid date
  4555. range and a verified signature. Calling this function before
  4556. wolfSSL_connect() or wolfSSL_accept() will add a domain name check to
  4557. the list of checks to perform. dn holds the domain name to check
  4558. against the peer certificate when it’s received.
  4559. \return SSL_SUCCESS upon success.
  4560. \return SSL_FAILURE will be returned if a memory error was encountered.
  4561. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4562. \param dn domain name to check against the peer certificate when received.
  4563. _Example_
  4564. \code
  4565. int ret = 0;
  4566. WOLFSSL* ssl;
  4567. char* domain = (char*) “www.yassl.com”;
  4568. ...
  4569. ret = wolfSSL_check_domain_name(ssl, domain);
  4570. if (ret != SSL_SUCCESS) {
  4571. // failed to enable domain name check
  4572. }
  4573. \endcode
  4574. \sa none
  4575. */
  4576. int wolfSSL_check_domain_name(WOLFSSL* ssl, const char* dn);
  4577. /*!
  4578. \ingroup TLS
  4579. \brief Initializes the wolfSSL library for use. Must be called once per
  4580. application and before any other call to the library.
  4581. \return SSL_SUCCESS If successful the call will return.
  4582. \return BAD_MUTEX_E is an error that may be returned.
  4583. \return WC_INIT_E wolfCrypt initialization error returned.
  4584. _Example_
  4585. \code
  4586. int ret = 0;
  4587. ret = wolfSSL_Init();
  4588. if (ret != SSL_SUCCESS) {
  4589. failed to initialize wolfSSL library
  4590. }
  4591. \endcode
  4592. \sa wolfSSL_Cleanup
  4593. */
  4594. int wolfSSL_Init(void);
  4595. /*!
  4596. \ingroup TLS
  4597. \brief Un-initializes the wolfSSL library from further use. Doesn’t have
  4598. to be called, though it will free any resources used by the library.
  4599. \return SSL_SUCCESS return no errors.
  4600. \return BAD_MUTEX_E a mutex error return.]
  4601. _Example_
  4602. \code
  4603. wolfSSL_Cleanup();
  4604. \endcode
  4605. \sa wolfSSL_Init
  4606. */
  4607. int wolfSSL_Cleanup(void);
  4608. /*!
  4609. \ingroup IO
  4610. \brief This function returns the current library version.
  4611. \return LIBWOLFSSL_VERSION_STRING a const char pointer defining the
  4612. version.
  4613. \param none No parameters.
  4614. _Example_
  4615. \code
  4616. char version[MAXSIZE];
  4617. version = wolfSSL_KeepArrays();
  4618. if(version != ExpectedVersion){
  4619. // Handle the mismatch case
  4620. }
  4621. \endcode
  4622. \sa word32_wolfSSL_lib_version_hex
  4623. */
  4624. const char* wolfSSL_lib_version(void);
  4625. /*!
  4626. \ingroup IO
  4627. \brief This function returns the current library version in hexadecimal
  4628. notation.
  4629. \return LILBWOLFSSL_VERSION_HEX returns the hexadecimal version defined in
  4630. wolfssl/version.h.
  4631. \param none No parameters.
  4632. _Example_
  4633. \code
  4634. word32 libV;
  4635. libV = wolfSSL_lib_version_hex();
  4636. if(libV != EXPECTED_HEX){
  4637. // How to handle an unexpected value
  4638. } else {
  4639. // The expected result for libV
  4640. }
  4641. \endcode
  4642. \sa wolfSSL_lib_version
  4643. */
  4644. word32 wolfSSL_lib_version_hex(void);
  4645. /*!
  4646. \ingroup IO
  4647. \brief Performs the actual connect or accept based on the side of the SSL
  4648. method. If called from the client side then an wolfSSL_connect() is done
  4649. while a wolfSSL_accept() is performed if called from the server side.
  4650. \return SSL_SUCCESS will be returned if successful. (Note, older versions
  4651. will return 0.)
  4652. \return SSL_FATAL_ERROR will be returned if the underlying call resulted
  4653. in an error. Use wolfSSL_get_error() to get a specific error code.
  4654. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4655. _Example_
  4656. \code
  4657. int ret = SSL_FATAL_ERROR;
  4658. WOLFSSL* ssl = 0;
  4659. ...
  4660. ret = wolfSSL_negotiate(ssl);
  4661. if (ret == SSL_FATAL_ERROR) {
  4662. // SSL establishment failed
  4663. int error_code = wolfSSL_get_error(ssl);
  4664. ...
  4665. }
  4666. ...
  4667. \endcode
  4668. \sa SSL_connect
  4669. \sa SSL_accept
  4670. */
  4671. int wolfSSL_negotiate(WOLFSSL* ssl);
  4672. /*!
  4673. \ingroup Setup
  4674. \brief Turns on the ability to use compression for the SSL connection.
  4675. Both sides must have compression turned on otherwise compression will not be
  4676. used. The zlib library performs the actual data compression. To compile
  4677. into the library use --with-libz for the configure system and define
  4678. HAVE_LIBZ otherwise. Keep in mind that while compressing data before
  4679. sending decreases the actual size of the messages being sent and received,
  4680. the amount of data saved by compression usually takes longer in time to
  4681. analyze than it does to send it raw on all but the slowest of networks.
  4682. \return SSL_SUCCESS upon success.
  4683. \return NOT_COMPILED_IN will be returned if compression support wasn’t
  4684. built into the library.
  4685. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4686. _Example_
  4687. \code
  4688. int ret = 0;
  4689. WOLFSSL* ssl = 0;
  4690. ...
  4691. ret = wolfSSL_set_compression(ssl);
  4692. if (ret == SSL_SUCCESS) {
  4693. // successfully enabled compression for SSL session
  4694. }
  4695. \endcode
  4696. \sa none
  4697. */
  4698. int wolfSSL_set_compression(WOLFSSL* ssl);
  4699. /*!
  4700. \ingroup Setup
  4701. \brief This function sets the SSL session timeout value in seconds.
  4702. \return SSL_SUCCESS will be returned upon successfully setting the session.
  4703. \return BAD_FUNC_ARG will be returned if ssl is NULL.
  4704. \param ssl pointer to the SSL object, created with wolfSSL_new().
  4705. \param to value, in seconds, used to set the SSL session timeout.
  4706. _Example_
  4707. \code
  4708. int ret = 0;
  4709. WOLFSSL* ssl = 0;
  4710. ...
  4711. ret = wolfSSL_set_timeout(ssl, 500);
  4712. if (ret != SSL_SUCCESS) {
  4713. // failed to set session timeout value
  4714. }
  4715. ...
  4716. \endcode
  4717. \sa wolfSSL_get1_session
  4718. \sa wolfSSL_set_session
  4719. */
  4720. int wolfSSL_set_timeout(WOLFSSL* ssl, unsigned int to);
  4721. /*!
  4722. \ingroup Setup
  4723. \brief This function sets the timeout value for SSL sessions, in seconds,
  4724. for the specified SSL context.
  4725. \return the previous timeout value, if WOLFSSL_ERROR_CODE_OPENSSL is
  4726. \return defined on success. If not defined, SSL_SUCCESS will be returned.
  4727. \return BAD_FUNC_ARG will be returned when the input context (ctx) is null.
  4728. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  4729. \param to session timeout value in seconds.
  4730. _Example_
  4731. \code
  4732. WOLFSSL_CTX* ctx = 0;
  4733. ...
  4734. ret = wolfSSL_CTX_set_timeout(ctx, 500);
  4735. if (ret != SSL_SUCCESS) {
  4736. // failed to set session timeout value
  4737. }
  4738. \endcode
  4739. \sa wolfSSL_flush_sessions
  4740. \sa wolfSSL_get1_session
  4741. \sa wolfSSL_set_session
  4742. \sa wolfSSL_get_sessionID
  4743. \sa wolfSSL_CTX_set_session_cache_mode
  4744. */
  4745. int wolfSSL_CTX_set_timeout(WOLFSSL_CTX* ctx, unsigned int to);
  4746. /*!
  4747. \ingroup openSSL
  4748. \brief Retrieves the peer’s certificate chain.
  4749. \return chain If successful the call will return the peer’s
  4750. certificate chain.
  4751. \return 0 will be returned if an invalid WOLFSSL pointer is passed to the
  4752. function.
  4753. \param ssl pointer to a valid WOLFSSL structure.
  4754. _Example_
  4755. \code
  4756. none
  4757. \endcode
  4758. \sa wolfSSL_get_chain_count
  4759. \sa wolfSSL_get_chain_length
  4760. \sa wolfSSL_get_chain_cert
  4761. \sa wolfSSL_get_chain_cert_pem
  4762. */
  4763. WOLFSSL_X509_CHAIN* wolfSSL_get_peer_chain(WOLFSSL* ssl);
  4764. /*!
  4765. \ingroup openSSL
  4766. \brief Retrieve's the peers certificate chain count.
  4767. \return Success If successful the call will return the peer’s certificate
  4768. chain count.
  4769. \return 0 will be returned if an invalid chain pointer is passed to
  4770. the function.
  4771. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4772. _Example_
  4773. \code
  4774. none
  4775. \endcode
  4776. \sa wolfSSL_get_peer_chain
  4777. \sa wolfSSL_get_chain_length
  4778. \sa wolfSSL_get_chain_cert
  4779. \sa wolfSSL_get_chain_cert_pem
  4780. */
  4781. int wolfSSL_get_chain_count(WOLFSSL_X509_CHAIN* chain);
  4782. /*!
  4783. \ingroup openSSL
  4784. \brief Retrieves the peer’s ASN1.DER certificate length in bytes
  4785. at index (idx).
  4786. \return Success If successful the call will return the peer’s
  4787. certificate length in bytes by index.
  4788. \return 0 will be returned if an invalid chain pointer is passed
  4789. to the function.
  4790. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4791. \param idx index to start of chain.
  4792. _Example_
  4793. \code
  4794. none
  4795. \endcode
  4796. \sa wolfSSL_get_peer_chain
  4797. \sa wolfSSL_get_chain_count
  4798. \sa wolfSSL_get_chain_cert
  4799. \sa wolfSSL_get_chain_cert_pem
  4800. */
  4801. int wolfSSL_get_chain_length(WOLFSSL_X509_CHAIN* chain, int idx);
  4802. /*!
  4803. \ingroup openSSL
  4804. \brief Retrieves the peer’s ASN1.DER certificate at index (idx).
  4805. \return Success If successful the call will return the peer’s
  4806. certificate by index.
  4807. \return 0 will be returned if an invalid chain pointer is passed
  4808. to the function.
  4809. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4810. \param idx index to start of chain.
  4811. _Example_
  4812. \code
  4813. none
  4814. \endcode
  4815. \sa wolfSSL_get_peer_chain
  4816. \sa wolfSSL_get_chain_count
  4817. \sa wolfSSL_get_chain_length
  4818. \sa wolfSSL_get_chain_cert_pem
  4819. */
  4820. unsigned char* wolfSSL_get_chain_cert(WOLFSSL_X509_CHAIN* chain, int idx);
  4821. /*!
  4822. \ingroup CertsKeys
  4823. \brief This function gets the peer’s wolfSSL_X509_certificate at
  4824. index (idx) from the chain of certificates.
  4825. \return pointer returns a pointer to a WOLFSSL_X509 structure.
  4826. \param chain a pointer to the WOLFSSL_X509_CHAIN used for no dynamic
  4827. memory SESSION_CACHE.
  4828. \param idx the index of the WOLFSSL_X509 certificate.
  4829. _Example_
  4830. \code
  4831. WOLFSSL_X509_CHAIN* chain = &session->chain;
  4832. int idx = 999; // set idx
  4833. ...
  4834. WOLFSSL_X509_CHAIN ptr;
  4835. prt = wolfSSL_get_chain_X509(chain, idx);
  4836. if(ptr != NULL){
  4837. //ptr contains the cert at the index specified
  4838. } else {
  4839. // ptr is NULL
  4840. }
  4841. \endcode
  4842. \sa InitDecodedCert
  4843. \sa ParseCertRelative
  4844. \sa CopyDecodedToX509
  4845. */
  4846. WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx);
  4847. /*!
  4848. \ingroup openSSL
  4849. \brief Retrieves the peer’s PEM certificate at index (idx).
  4850. \return Success If successful the call will return the peer’s
  4851. certificate by index.
  4852. \return 0 will be returned if an invalid chain pointer is passed to
  4853. the function.
  4854. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  4855. \param idx indexto start of chain.
  4856. _Example_
  4857. \code
  4858. none
  4859. \endcode
  4860. \sa wolfSSL_get_peer_chain
  4861. \sa wolfSSL_get_chain_count
  4862. \sa wolfSSL_get_chain_length
  4863. \sa wolfSSL_get_chain_cert
  4864. */
  4865. int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN* chain, int idx,
  4866. unsigned char* buf, int inLen, int* outLen);
  4867. /*!
  4868. \ingroup openSSL
  4869. \brief Retrieves the session’s ID. The session ID is always 32 bytes long.
  4870. \return id The session ID.
  4871. \param session pointer to a valid wolfssl session.
  4872. _Example_
  4873. \code
  4874. none
  4875. \endcode
  4876. \sa SSL_get_session
  4877. */
  4878. const unsigned char* wolfSSL_get_sessionID(const WOLFSSL_SESSION* s);
  4879. /*!
  4880. \ingroup openSSL
  4881. \brief Retrieves the peer’s certificate serial number. The serial
  4882. number buffer (in) should be at least 32 bytes long and be provided
  4883. as the *inOutSz argument as input. After calling the function *inOutSz
  4884. will hold the actual length in bytes written to the in buffer.
  4885. \return SSL_SUCCESS upon success.
  4886. \return BAD_FUNC_ARG will be returned if a bad function argument
  4887. was encountered.
  4888. \param in The serial number buffer and should be at least 32 bytes long
  4889. \param inOutSz will hold the actual length in bytes written to the
  4890. in buffer.
  4891. _Example_
  4892. \code
  4893. none
  4894. \endcode
  4895. \sa SSL_get_peer_certificate
  4896. */
  4897. int wolfSSL_X509_get_serial_number(WOLFSSL_X509* x509, unsigned char* in,
  4898. int* inOutSz);
  4899. /*!
  4900. \ingroup CertsKeys
  4901. \brief Returns the common name of the subject from the certificate.
  4902. \return NULL returned if the x509 structure is null
  4903. \return string a string representation of the subject's common
  4904. name is returned upon success
  4905. \param x509 a pointer to a WOLFSSL_X509 structure containing
  4906. certificate information.
  4907. _Example_
  4908. \code
  4909. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4910. DYNAMIC_TYPE_X509);
  4911. ...
  4912. int x509Cn = wolfSSL_X509_get_subjectCN(x509);
  4913. if(x509Cn == NULL){
  4914. // Deal with NULL case
  4915. } else {
  4916. // x509Cn contains the common name
  4917. }
  4918. \endcode
  4919. \sa wolfSSL_X509_Name_get_entry
  4920. \sa wolfSSL_X509_get_next_altname
  4921. \sa wolfSSL_X509_get_issuer_name
  4922. \sa wolfSSL_X509_get_subject_name
  4923. */
  4924. char* wolfSSL_X509_get_subjectCN(WOLFSSL_X509*);
  4925. /*!
  4926. \ingroup CertsKeys
  4927. \brief This function gets the DER encoded certificate in the
  4928. WOLFSSL_X509 struct.
  4929. \return buffer This function returns the DerBuffer structure’s
  4930. buffer member, which is of type byte.
  4931. \return NULL returned if the x509 or outSz parameter is NULL.
  4932. \param x509 a pointer to a WOLFSSL_X509 structure containing
  4933. certificate information.
  4934. \param outSz length of the derBuffer member of the WOLFSSL_X509 struct.
  4935. _Example_
  4936. \code
  4937. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4938. DYNAMIC_TYPE_X509);
  4939. int* outSz; // initialize
  4940. ...
  4941. byte* x509Der = wolfSSL_X509_get_der(x509, outSz);
  4942. if(x509Der == NULL){
  4943. // Failure case one of the parameters was NULL
  4944. }
  4945. \endcode
  4946. \sa wolfSSL_X509_version
  4947. \sa wolfSSL_X509_Name_get_entry
  4948. \sa wolfSSL_X509_get_next_altname
  4949. \sa wolfSSL_X509_get_issuer_name
  4950. \sa wolfSSL_X509_get_subject_name
  4951. */
  4952. const unsigned char* wolfSSL_X509_get_der(WOLFSSL_X509* x509, int* outSz);
  4953. /*!
  4954. \ingroup CertsKeys
  4955. \brief This function checks to see if x509 is NULL and if it’s not,
  4956. it returns the notAfter member of the x509 struct.
  4957. \return pointer to struct with ASN1_TIME to the notAfter
  4958. member of the x509 struct.
  4959. \return NULL returned if the x509 object is NULL.
  4960. \param x509 a pointer to the WOLFSSL_X509 struct.
  4961. _Example_
  4962. \code
  4963. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  4964. DYNAMIC_TYPE_X509) ;
  4965. ...
  4966. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notAfter(x509);
  4967. if(notAfter == NULL){
  4968. // Failure case, the x509 object is null.
  4969. }
  4970. \endcode
  4971. \sa wolfSSL_X509_get_notBefore
  4972. */
  4973. WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notAfter(WOLFSSL_X509*);
  4974. /*!
  4975. \ingroup CertsKeys
  4976. \brief This function retrieves the version of the X509 certificate.
  4977. \return 0 returned if the x509 structure is NULL.
  4978. \return version the version stored in the x509 structure will be returned.
  4979. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4980. _Example_
  4981. \code
  4982. WOLFSSL_X509* x509;
  4983. int version;
  4984. ...
  4985. version = wolfSSL_X509_version(x509);
  4986. if(!version){
  4987. // The function returned 0, failure case.
  4988. }
  4989. \endcode
  4990. \sa wolfSSL_X509_get_subject_name
  4991. \sa wolfSSL_X509_get_issuer_name
  4992. \sa wolfSSL_X509_get_isCA
  4993. \sa wolfSSL_get_peer_certificate
  4994. */
  4995. int wolfSSL_X509_version(WOLFSSL_X509*);
  4996. /*!
  4997. \ingroup CertsKeys
  4998. \brief If NO_STDIO_FILESYSTEM is defined this function will allocate
  4999. heap memory, initialize a WOLFSSL_X509 structure and return a pointer to it.
  5000. \return *WOLFSSL_X509 WOLFSSL_X509 structure pointer is returned if
  5001. the function executes successfully.
  5002. \return NULL if the call to XFTELL macro returns a negative value.
  5003. \param x509 a pointer to a WOLFSSL_X509 pointer.
  5004. \param file a defined type that is a pointer to a FILE.
  5005. _Example_
  5006. \code
  5007. WOLFSSL_X509* x509a = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5008. DYNAMIC_TYPE_X509);
  5009. WOLFSSL_X509** x509 = x509a;
  5010. XFILE file; (mapped to struct fs_file*)
  5011. ...
  5012. WOLFSSL_X509* newX509 = wolfSSL_X509_d2i_fp(x509, file);
  5013. if(newX509 == NULL){
  5014. // The function returned NULL
  5015. }
  5016. \endcode
  5017. \sa wolfSSL_X509_d2i
  5018. \sa XFTELL
  5019. \sa XREWIND
  5020. \sa XFSEEK
  5021. */
  5022. WOLFSSL_X509*
  5023. wolfSSL_X509_d2i_fp(WOLFSSL_X509** x509, FILE* file);
  5024. /*!
  5025. \ingroup CertsKeys
  5026. \brief The function loads the x509 certificate into memory.
  5027. \return pointer a successful execution returns pointer to a
  5028. WOLFSSL_X509 structure.
  5029. \return NULL returned if the certificate was not able to be written.
  5030. \param fname the certificate file to be loaded.
  5031. \param format the format of the certificate.
  5032. _Example_
  5033. \code
  5034. #define cliCert “certs/client-cert.pem”
  5035. X509* x509;
  5036. x509 = wolfSSL_X509_load_certificate_file(cliCert, SSL_FILETYPE_PEM);
  5037. AssertNotNull(x509);
  5038. \endcode
  5039. \sa InitDecodedCert
  5040. \sa PemToDer
  5041. \sa wolfSSL_get_certificate
  5042. \sa AssertNotNull
  5043. */
  5044. WOLFSSL_X509*
  5045. wolfSSL_X509_load_certificate_file(const char* fname, int format);
  5046. /*!
  5047. \ingroup CertsKeys
  5048. \brief This function copies the device type from the x509 structure
  5049. to the buffer.
  5050. \return pointer returns a byte pointer holding the device type from
  5051. the x509 structure.
  5052. \return NULL returned if the buffer size is NULL.
  5053. \param x509 pointer to a WOLFSSL_X509 structure, created with
  5054. WOLFSSL_X509_new().
  5055. \param in a pointer to a byte type that will hold the device type
  5056. (the buffer).
  5057. \param inOutSz the minimum of either the parameter inOutSz or the
  5058. deviceTypeSz member of the x509 structure.
  5059. _Example_
  5060. \code
  5061. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  5062. DYNAMIC_TYPE_X509);
  5063. byte* in;
  5064. int* inOutSz;
  5065. ...
  5066. byte* deviceType = wolfSSL_X509_get_device_type(x509, in, inOutSz);
  5067. if(!deviceType){
  5068. // Failure case, NULL was returned.
  5069. }
  5070. \endcode
  5071. \sa wolfSSL_X509_get_hw_type
  5072. \sa wolfSSL_X509_get_hw_serial_number
  5073. \sa wolfSSL_X509_d2i
  5074. */
  5075. unsigned char*
  5076. wolfSSL_X509_get_device_type(WOLFSSL_X509* x509, unsigned char* in,
  5077. int* inOutSz);
  5078. /*!
  5079. \ingroup CertsKeys
  5080. \brief The function copies the hwType member of the WOLFSSL_X509
  5081. structure to the buffer.
  5082. \return byte The function returns a byte type of the data previously held
  5083. in the hwType member of the WOLFSSL_X509 structure.
  5084. \return NULL returned if inOutSz is NULL.
  5085. \param x509 a pointer to a WOLFSSL_X509 structure containing certificate
  5086. information.
  5087. \param in pointer to type byte that represents the buffer.
  5088. \param inOutSz pointer to type int that represents the size of the buffer.
  5089. _Example_
  5090. \code
  5091. WOLFSSL_X509* x509; // X509 certificate
  5092. byte* in; // initialize the buffer
  5093. int* inOutSz; // holds the size of the buffer
  5094. ...
  5095. byte* hwType = wolfSSL_X509_get_hw_type(x509, in, inOutSz);
  5096. if(hwType == NULL){
  5097. // Failure case function returned NULL.
  5098. }
  5099. \endcode
  5100. \sa wolfSSL_X509_get_hw_serial_number
  5101. \sa wolfSSL_X509_get_device_type
  5102. */
  5103. unsigned char*
  5104. wolfSSL_X509_get_hw_type(WOLFSSL_X509* x509, unsigned char* in,
  5105. int* inOutSz);
  5106. /*!
  5107. \ingroup CertsKeys
  5108. \brief This function returns the hwSerialNum member of the x509 object.
  5109. \return pointer the function returns a byte pointer to the in buffer that
  5110. will contain the serial number loaded from the x509 object.
  5111. \param x509 pointer to a WOLFSSL_X509 structure containing certificate
  5112. information.
  5113. \param in a pointer to the buffer that will be copied to.
  5114. \param inOutSz a pointer to the size of the buffer.
  5115. _Example_
  5116. \code
  5117. char* serial;
  5118. byte* in;
  5119. int* inOutSz;
  5120. WOLFSSL_X509 x509;
  5121. ...
  5122. serial = wolfSSL_X509_get_hw_serial_number(x509, in, inOutSz);
  5123. if(serial == NULL || serial <= 0){
  5124. // Failure case
  5125. }
  5126. \endcode
  5127. \sa wolfSSL_X509_get_subject_name
  5128. \sa wolfSSL_X509_get_issuer_name
  5129. \sa wolfSSL_X509_get_isCA
  5130. \sa wolfSSL_get_peer_certificate
  5131. \sa wolfSSL_X509_version
  5132. */
  5133. unsigned char*
  5134. wolfSSL_X509_get_hw_serial_number(WOLFSSL_X509* x509,
  5135. unsigned char* in, int* inOutSz);
  5136. /*!
  5137. \ingroup IO
  5138. \brief This function is called on the client side and initiates an
  5139. SSL/TLS handshake with a server only long enough to get the peer’s
  5140. certificate chain. When this function is called, the underlying
  5141. communication channel has already been set up. wolfSSL_connect_cert()
  5142. works with both blocking and non-blocking I/O. When the underlying I/O
  5143. is non-blocking, wolfSSL_connect_cert() will return when the underlying
  5144. I/O could not satisfy the needs of wolfSSL_connect_cert() to continue the
  5145. handshake. In this case, a call to wolfSSL_get_error() will yield either
  5146. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then
  5147. repeat the call to wolfSSL_connect_cert() when the underlying I/O is ready
  5148. and wolfSSL will pick up where it left off. When using a non-blocking
  5149. socket, nothing needs to be done, but select() can be used to check for
  5150. the required condition. If the underlying I/O is blocking,
  5151. wolfSSL_connect_cert() will only return once the peer’s certificate chain
  5152. has been received.
  5153. \return SSL_SUCCESS upon success.
  5154. \return SSL_FAILURE will be returned if the SSL session parameter is NULL.
  5155. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a more
  5156. detailed error code, call wolfSSL_get_error().
  5157. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5158. _Example_
  5159. \code
  5160. int ret = 0;
  5161. int err = 0;
  5162. WOLFSSL* ssl;
  5163. char buffer[80];
  5164. ...
  5165. ret = wolfSSL_connect_cert(ssl);
  5166. if (ret != SSL_SUCCESS) {
  5167. err = wolfSSL_get_error(ssl, ret);
  5168. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  5169. }
  5170. \endcode
  5171. \sa wolfSSL_get_error
  5172. \sa wolfSSL_connect
  5173. \sa wolfSSL_accept
  5174. */
  5175. int wolfSSL_connect_cert(WOLFSSL* ssl);
  5176. /*!
  5177. \ingroup openSSL
  5178. \brief wolfSSL_d2i_PKCS12_bio (d2i_PKCS12_bio) copies in the PKCS12
  5179. information from WOLFSSL_BIO to the structure WC_PKCS12. The information
  5180. is divided up in the structure as a list of Content Infos along with a
  5181. structure to hold optional MAC information. After the information has been
  5182. divided into chunks (but not decrypted) in the structure WC_PKCS12, it can
  5183. then be parsed and decrypted by calling.
  5184. \return WC_PKCS12 pointer to a WC_PKCS12 structure.
  5185. \return Failure If function failed it will return NULL.
  5186. \param bio WOLFSSL_BIO structure to read PKCS12 buffer from.
  5187. \param pkcs12 WC_PKCS12 structure pointer for new PKCS12 structure created.
  5188. Can be NULL
  5189. _Example_
  5190. \code
  5191. WC_PKCS12* pkcs;
  5192. WOLFSSL_BIO* bio;
  5193. WOLFSSL_X509* cert;
  5194. WOLFSSL_EVP_PKEY* pkey;
  5195. STACK_OF(X509) certs;
  5196. //bio loads in PKCS12 file
  5197. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5198. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5199. wc_PKCS12_free(pkcs)
  5200. //use cert, pkey, and optionally certs stack
  5201. \endcode
  5202. \sa wolfSSL_PKCS12_parse
  5203. \sa wc_PKCS12_free
  5204. */
  5205. WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio,
  5206. WC_PKCS12** pkcs12);
  5207. /*!
  5208. \ingroup openSSL
  5209. \brief wolfSSL_i2d_PKCS12_bio (i2d_PKCS12_bio) copies in the cert
  5210. information from the structure WC_PKCS12 to WOLFSSL_BIO.
  5211. \return 1 for success.
  5212. \return Failure 0.
  5213. \param bio WOLFSSL_BIO structure to write PKCS12 buffer to.
  5214. \param pkcs12 WC_PKCS12 structure for PKCS12 structure as input.
  5215. _Example_
  5216. \code
  5217. WC_PKCS12 pkcs12;
  5218. FILE *f;
  5219. byte buffer[5300];
  5220. char file[] = "./test.p12";
  5221. int bytes;
  5222. WOLFSSL_BIO* bio;
  5223. pkcs12 = wc_PKCS12_new();
  5224. f = fopen(file, "rb");
  5225. bytes = (int)fread(buffer, 1, sizeof(buffer), f);
  5226. fclose(f);
  5227. //convert the DER file into an internal structure
  5228. wc_d2i_PKCS12(buffer, bytes, pkcs12);
  5229. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  5230. //convert PKCS12 structure into bio
  5231. wolfSSL_i2d_PKCS12_bio(bio, pkcs12);
  5232. wc_PKCS12_free(pkcs)
  5233. //use bio
  5234. \endcode
  5235. \sa wolfSSL_PKCS12_parse
  5236. \sa wc_PKCS12_free
  5237. */
  5238. WC_PKCS12* wolfSSL_i2d_PKCS12_bio(WOLFSSL_BIO* bio,
  5239. WC_PKCS12* pkcs12);
  5240. /*!
  5241. \ingroup openSSL
  5242. \brief PKCS12 can be enabled with adding –enable-opensslextra to the
  5243. configure command. It can use triple DES and RC4 for decryption so would
  5244. recommend also enabling these features when enabling opensslextra
  5245. (--enable-des3 –enable-arc4). wolfSSL does not currently support RC2 so
  5246. decryption with RC2 is currently not available. This may be noticeable
  5247. with default encryption schemes used by OpenSSL command line to create
  5248. .p12 files. wolfSSL_PKCS12_parse (PKCS12_parse). The first thing this
  5249. function does is check the MAC is correct if present. If the MAC fails
  5250. then the function returns and does not try to decrypt any of the stored
  5251. Content Infos. This function then parses through each Content Info
  5252. looking for a bag type, if the bag type is known it is decrypted as
  5253. needed and either stored in the list of certificates being built or as
  5254. a key found. After parsing through all bags the key found is then
  5255. compared with the certificate list until a matching pair is found.
  5256. This matching pair is then returned as the key and certificate,
  5257. optionally the certificate list found is returned as a STACK_OF
  5258. certificates. At the moment a CRL, Secret or SafeContents bag will be
  5259. skipped over and not parsed. It can be seen if these or other “Unknown”
  5260. bags are skipped over by viewing the debug print out. Additional attributes
  5261. such as friendly name are skipped over when parsing a PKCS12 file.
  5262. \return SSL_SUCCESS On successfully parsing PKCS12.
  5263. \return SSL_FAILURE If an error case was encountered.
  5264. \param pkcs12 WC_PKCS12 structure to parse.
  5265. \param paswd password for decrypting PKCS12.
  5266. \param pkey structure to hold private key decoded from PKCS12.
  5267. \param cert structure to hold certificate decoded from PKCS12.
  5268. \param stack optional stack of extra certificates.
  5269. _Example_
  5270. \code
  5271. WC_PKCS12* pkcs;
  5272. WOLFSSL_BIO* bio;
  5273. WOLFSSL_X509* cert;
  5274. WOLFSSL_EVP_PKEY* pkey;
  5275. STACK_OF(X509) certs;
  5276. //bio loads in PKCS12 file
  5277. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5278. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5279. wc_PKCS12_free(pkcs)
  5280. //use cert, pkey, and optionally certs stack
  5281. \endcode
  5282. \sa wolfSSL_d2i_PKCS12_bio
  5283. \sa wc_PKCS12_free
  5284. */
  5285. int wolfSSL_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
  5286. WOLFSSL_EVP_PKEY** pkey, WOLFSSL_X509** cert, WOLF_STACK_OF(WOLFSSL_X509)** ca);
  5287. /*!
  5288. \ingroup CertsKeys
  5289. \brief Server Diffie-Hellman Ephemeral parameters setting. This function
  5290. sets up the group parameters to be used if the server negotiates a cipher
  5291. suite that uses DHE.
  5292. \return SSL_SUCCESS upon success.
  5293. \return MEMORY_ERROR will be returned if a memory error was encountered.
  5294. \return SIDE_ERROR will be returned if this function is called on an SSL
  5295. client instead of an SSL server.
  5296. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5297. \param p Diffie-Hellman prime number parameter.
  5298. \param pSz size of p.
  5299. \param g Diffie-Hellman “generator” parameter.
  5300. \param gSz size of g.
  5301. _Example_
  5302. \code
  5303. WOLFSSL* ssl;
  5304. static unsigned char p[] = {...};
  5305. static unsigned char g[] = {...};
  5306. ...
  5307. wolfSSL_SetTmpDH(ssl, p, sizeof(p), g, sizeof(g));
  5308. \endcode
  5309. \sa SSL_accept
  5310. */
  5311. int wolfSSL_SetTmpDH(WOLFSSL* ssl, const unsigned char* p, int pSz,
  5312. const unsigned char* g, int gSz);
  5313. /*!
  5314. \ingroup CertsKeys
  5315. \brief The function calls the wolfSSL_SetTMpDH_buffer_wrapper,
  5316. which is a wrapper for Diffie-Hellman parameters.
  5317. \return SSL_SUCCESS on successful execution.
  5318. \return SSL_BAD_FILETYPE if the file type is not PEM and is not
  5319. ASN.1. It will also be returned if the wc_DhParamsLoad does not
  5320. return normally.
  5321. \return SSL_NO_PEM_HEADER returns from PemToDer if there is not
  5322. a PEM header.
  5323. \return SSL_BAD_FILE returned if there is a file error in PemToDer.
  5324. \return SSL_FATAL_ERROR returned from PemToDer if there was a copy error.
  5325. \return MEMORY_E - if there was a memory allocation error.
  5326. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  5327. there was otherwise a NULL argument passed to a subroutine.
  5328. \return DH_KEY_SIZE_E is returned if their is a key size error in
  5329. wolfSSL_SetTmpDH() or in wolfSSL_CTX_SetTmpDH().
  5330. \return SIDE_ERROR returned if it is not the server side
  5331. in wolfSSL_SetTmpDH.
  5332. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5333. \param buf allocated buffer passed in from wolfSSL_SetTMpDH_file_wrapper.
  5334. \param sz a long int that holds the size of the file
  5335. (fname within wolfSSL_SetTmpDH_file_wrapper).
  5336. \param format an integer type passed through from
  5337. wolfSSL_SetTmpDH_file_wrapper() that is a representation of the certificate
  5338. format.
  5339. _Example_
  5340. \code
  5341. Static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5342. Const char* fname, int format);
  5343. long sz = 0;
  5344. byte* myBuffer = staticBuffer[FILE_BUFFER_SIZE];
  5345. if(ssl)
  5346. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5347. \endcode
  5348. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5349. \sa wc_DhParamsLoad
  5350. \sa wolfSSL_SetTmpDH
  5351. \sa PemToDer
  5352. \sa wolfSSL_CTX_SetTmpDH
  5353. \sa wolfSSL_CTX_SetTmpDH_file
  5354. */
  5355. int wolfSSL_SetTmpDH_buffer(WOLFSSL* ssl, const unsigned char* b, long sz,
  5356. int format);
  5357. /*!
  5358. \ingroup CertsKeys
  5359. \brief This function calls wolfSSL_SetTmpDH_file_wrapper to set server
  5360. Diffie-Hellman parameters.
  5361. \return SSL_SUCCESS returned on successful completion of this function
  5362. and its subroutines.
  5363. \return MEMORY_E returned if a memory allocation failed in this function
  5364. or a subroutine.
  5365. \return SIDE_ERROR if the side member of the Options structure found
  5366. in the WOLFSSL struct is not the server side.
  5367. \return SSL_BAD_FILETYPE returns if the certificate fails a set of checks.
  5368. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5369. the value of the minDhKeySz member in the WOLFSSL struct.
  5370. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5371. than the value of the maxDhKeySz member in the WOLFSSL struct.
  5372. \return BAD_FUNC_ARG returns if an argument value is NULL that is not
  5373. permitted such as, the WOLFSSL structure.
  5374. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5375. \param fname a constant char pointer holding the certificate.
  5376. \param format an integer type that holds the format of the certification.
  5377. _Example_
  5378. \code
  5379. WOLFSSL* ssl = wolfSSL_new(ctx);
  5380. const char* dhParam;
  5381. AssertIntNE(SSL_SUCCESS,
  5382. wolfSSL_SetTmpDH_file(ssl, dhParam, SSL_FILETYPE_PEM));
  5383. \endcode
  5384. \sa wolfSSL_CTX_SetTmpDH_file
  5385. \sa wolfSSL_SetTmpDH_file_wrapper
  5386. \sa wolfSSL_SetTmpDH_buffer
  5387. \sa wolfSSL_CTX_SetTmpDH_buffer
  5388. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5389. \sa wolfSSL_SetTmpDH
  5390. \sa wolfSSL_CTX_SetTmpDH
  5391. */
  5392. int wolfSSL_SetTmpDH_file(WOLFSSL* ssl, const char* f, int format);
  5393. /*!
  5394. \ingroup CertsKeys
  5395. \brief Sets the parameters for the server CTX Diffie-Hellman.
  5396. \return SSL_SUCCESS returned if the function and all subroutines
  5397. return without error.
  5398. \return BAD_FUNC_ARG returned if the CTX, p or g parameters are NULL.
  5399. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5400. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5401. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5402. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5403. \return MEMORY_E returned if the allocation of memory failed in this
  5404. function or a subroutine.
  5405. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5406. wolfSSL_CTX_new().
  5407. \param p a constant unsigned char pointer loaded into the buffer
  5408. member of the serverDH_P struct.
  5409. \param pSz an int type representing the size of p, initialized
  5410. to MAX_DH_SIZE.
  5411. \param g a constant unsigned char pointer loaded into the buffer
  5412. member of the serverDH_G struct.
  5413. \param gSz an int type representing the size of g, initialized ot
  5414. MAX_DH_SIZE.
  5415. _Exmaple_
  5416. \code
  5417. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  5418. byte* p;
  5419. byte* g;
  5420. word32 pSz = (word32)sizeof(p)/sizeof(byte);
  5421. word32 gSz = (word32)sizeof(g)/sizeof(byte);
  5422. int ret = wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz);
  5423. if(ret != SSL_SUCCESS){
  5424. // Failure case
  5425. }
  5426. \endcode
  5427. \sa wolfSSL_SetTmpDH
  5428. \sa wc_DhParamsLoad
  5429. */
  5430. int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX* ctx, const unsigned char* p,
  5431. int pSz, const unsigned char* g, int gSz);
  5432. /*!
  5433. \ingroup CertsKeys
  5434. \brief A wrapper function that calls wolfSSL_SetTmpDH_buffer_wrapper
  5435. \return 0 returned for a successful execution.
  5436. \return BAD_FUNC_ARG returned if the ctx or buf parameters are NULL.
  5437. \return MEMORY_E if there is a memory allocation error.
  5438. \return SSL_BAD_FILETYPE returned if format is not correct.
  5439. \param ctx a pointer to a WOLFSSL structure, created using
  5440. wolfSSL_CTX_new().
  5441. \param buf a pointer to a constant unsigned char type that is
  5442. allocated as the buffer and passed through to
  5443. wolfSSL_SetTmpDH_buffer_wrapper.
  5444. \param sz a long integer type that is derived from the fname parameter
  5445. in wolfSSL_SetTmpDH_file_wrapper().
  5446. \param format an integer type passed through from
  5447. wolfSSL_SetTmpDH_file_wrapper().
  5448. _Example_
  5449. \code
  5450. static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5451. Const char* fname, int format);
  5452. #ifdef WOLFSSL_SMALL_STACK
  5453. byte staticBuffer[1]; // force heap usage
  5454. #else
  5455. byte* staticBuffer;
  5456. long sz = 0;
  5457. if(ssl){
  5458. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5459. } else {
  5460. ret = wolfSSL_CTX_SetTmpDH_buffer(ctx, myBuffer, sz, format);
  5461. }
  5462. \endcode
  5463. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5464. \sa wolfSSL_SetTMpDH_buffer
  5465. \sa wolfSSL_SetTmpDH_file_wrapper
  5466. \sa wolfSSL_CTX_SetTmpDH_file
  5467. */
  5468. int wolfSSL_CTX_SetTmpDH_buffer(WOLFSSL_CTX* ctx, const unsigned char* b,
  5469. long sz, int format);
  5470. /*!
  5471. \ingroup CertsKeys
  5472. \brief The function calls wolfSSL_SetTmpDH_file_wrapper to set the server
  5473. Diffie-Hellman parameters.
  5474. \return SSL_SUCCESS returned if the wolfSSL_SetTmpDH_file_wrapper or any
  5475. of its subroutines return successfully.
  5476. \return MEMORY_E returned if an allocation of dynamic memory fails in a
  5477. subroutine.
  5478. \return BAD_FUNC_ARG returned if the ctx or fname parameters are NULL or
  5479. if
  5480. a subroutine is passed a NULL argument.
  5481. \return SSL_BAD_FILE returned if the certificate file is unable to open or
  5482. if the a set of checks on the file fail from wolfSSL_SetTmpDH_file_wrapper.
  5483. \return SSL_BAD_FILETYPE returned if the format is not PEM or ASN.1 from
  5484. wolfSSL_SetTmpDH_buffer_wrapper().
  5485. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5486. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5487. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5488. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5489. \return SIDE_ERROR returned in wolfSSL_SetTmpDH() if the side is not the
  5490. server end.
  5491. \return SSL_NO_PEM_HEADER returned from PemToDer if there is no PEM header.
  5492. \return SSL_FATAL_ERROR returned from PemToDer if there is a memory copy
  5493. failure.
  5494. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5495. wolfSSL_CTX_new().
  5496. \param fname a constant character pointer to a certificate file.
  5497. \param format an integer type passed through from
  5498. wolfSSL_SetTmpDH_file_wrapper() that is a representation of
  5499. the certificate format.
  5500. _Example_
  5501. \code
  5502. #define dhParam “certs/dh2048.pem”
  5503. #DEFINE aSSERTiNTne(x, y) AssertInt(x, y, !=, ==)
  5504. WOLFSSL_CTX* ctx;
  5505. AssertNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  5506. AssertIntNE(SSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL, dhParam,
  5507. SSL_FILETYPE_PEM));
  5508. \endcode
  5509. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5510. \sa wolfSSL_SetTmpDH
  5511. \sa wolfSSL_CTX_SetTmpDH
  5512. \sa wolfSSL_SetTmpDH_buffer
  5513. \sa wolfSSL_CTX_SetTmpDH_buffer
  5514. \sa wolfSSL_SetTmpDH_file_wrapper
  5515. \sa AllocDer
  5516. \sa PemToDer
  5517. */
  5518. int wolfSSL_CTX_SetTmpDH_file(WOLFSSL_CTX* ctx, const char* f,
  5519. int format);
  5520. /*!
  5521. \ingroup CertsKeys
  5522. \brief This function sets the minimum size (in bits) of the Diffie Hellman
  5523. key size by accessing the minDhKeySz member in the WOLFSSL_CTX structure.
  5524. \return SSL_SUCCESS returned if the function completes successfully.
  5525. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5526. the keySz_bits is greater than 16,000 or not divisible by 8.
  5527. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5528. \param keySz_bits a word16 type used to set the minimum DH key size in bits.
  5529. The WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5530. _Example_
  5531. \code
  5532. public static int CTX_SetMinDhKey_Sz(IntPtr ctx, short minDhKey){
  5533. return wolfSSL_CTX_SetMinDhKey_Sz(local_ctx, minDhKeyBits);
  5534. \endcode
  5535. \sa wolfSSL_SetMinDhKey_Sz
  5536. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5537. \sa wolfSSL_SetMaxDhKey_Sz
  5538. \sa wolfSSL_GetDhKey_Sz
  5539. \sa wolfSSL_CTX_SetTMpDH_file
  5540. */
  5541. int wolfSSL_CTX_SetMinDhKey_Sz(WOLFSSL_CTX* ctx, word16);
  5542. /*!
  5543. \ingroup CertsKeys
  5544. \brief Sets the minimum size (in bits) for a Diffie-Hellman key in the
  5545. WOLFSSL structure.
  5546. \return SSL_SUCCESS the minimum size was successfully set.
  5547. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or if the keySz_bits is
  5548. greater than 16,000 or not divisible by 8.
  5549. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5550. \param keySz_bits a word16 type used to set the minimum DH key size in bits.
  5551. The WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5552. _Example_
  5553. \code
  5554. WOLFSSL* ssl = wolfSSL_new(ctx);
  5555. word16 keySz_bits;
  5556. ...
  5557. if(wolfSSL_SetMinDhKey_Sz(ssl, keySz_bits) != SSL_SUCCESS){
  5558. // Failed to set.
  5559. }
  5560. \endcode
  5561. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5562. \sa wolfSSL_GetDhKey_Sz
  5563. */
  5564. int wolfSSL_SetMinDhKey_Sz(WOLFSSL* ssl, word16 keySz_bits);
  5565. /*!
  5566. \ingroup CertsKeys
  5567. \brief This function sets the maximum size (in bits) of the Diffie Hellman
  5568. key size by accessing the maxDhKeySz member in the WOLFSSL_CTX structure.
  5569. \return SSL_SUCCESS returned if the function completes successfully.
  5570. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5571. the keySz_bits is greater than 16,000 or not divisible by 8.
  5572. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5573. \param keySz_bits a word16 type used to set the maximum DH key size in bits.
  5574. The WOLFSSL_CTX struct holds this information in the maxDhKeySz member.
  5575. _Example_
  5576. \code
  5577. public static int CTX_SetMaxDhKey_Sz(IntPtr ctx, short maxDhKey){
  5578. return wolfSSL_CTX_SetMaxDhKey_Sz(local_ctx, keySz_bits);
  5579. \endcode
  5580. \sa wolfSSL_SetMinDhKey_Sz
  5581. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5582. \sa wolfSSL_SetMaxDhKey_Sz
  5583. \sa wolfSSL_GetDhKey_Sz
  5584. \sa wolfSSL_CTX_SetTMpDH_file
  5585. */
  5586. int wolfSSL_CTX_SetMaxDhKey_Sz(WOLFSSL_CTX* ctx, word16 keySz_bits);
  5587. /*!
  5588. \ingroup CertsKeys
  5589. \brief Sets the maximum size (in bits) for a Diffie-Hellman key in the
  5590. WOLFSSL structure.
  5591. \return SSL_SUCCESS the maximum size was successfully set.
  5592. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or the keySz parameter
  5593. was greater than the allowable size or not divisible by 8.
  5594. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5595. \param keySz a word16 type representing the bit size of the maximum DH key.
  5596. _Example_
  5597. \code
  5598. WOLFSSL* ssl = wolfSSL_new(ctx);
  5599. word16 keySz;
  5600. ...
  5601. if(wolfSSL_SetMaxDhKey(ssl, keySz) != SSL_SUCCESS){
  5602. // Failed to set.
  5603. }
  5604. \endcode
  5605. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5606. \sa wolfSSL_GetDhKey_Sz
  5607. */
  5608. int wolfSSL_SetMaxDhKey_Sz(WOLFSSL* ssl, word16 keySz_bits);
  5609. /*!
  5610. \ingroup CertsKeys
  5611. \brief Returns the value of dhKeySz (in bits) that is a member of the
  5612. options structure. This value represents the Diffie-Hellman key size in
  5613. bytes.
  5614. \return dhKeySz returns the value held in ssl->options.dhKeySz which is an
  5615. integer value representing a size in bits.
  5616. \return BAD_FUNC_ARG returns if the WOLFSSL struct is NULL.
  5617. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5618. _Example_
  5619. \code
  5620. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5621. WOLFSSL* ssl = wolfSSL_new(ctx);
  5622. int dhKeySz;
  5623. ...
  5624. dhKeySz = wolfSSL_GetDhKey_Sz(ssl);
  5625. if(dhKeySz == BAD_FUNC_ARG || dhKeySz <= 0){
  5626. // Failure case
  5627. } else {
  5628. // dhKeySz holds the size of the key.
  5629. }
  5630. \endcode
  5631. \sa wolfSSL_SetMinDhKey_sz
  5632. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5633. \sa wolfSSL_CTX_SetTmpDH
  5634. \sa wolfSSL_SetTmpDH
  5635. \sa wolfSSL_CTX_SetTmpDH_file
  5636. */
  5637. int wolfSSL_GetDhKey_Sz(WOLFSSL*);
  5638. /*!
  5639. \ingroup CertsKeys
  5640. \brief Sets the minimum RSA key size in both the WOLFSSL_CTX structure
  5641. and the WOLFSSL_CERT_MANAGER structure.
  5642. \return SSL_SUCCESS returned on successful execution of the function.
  5643. \return BAD_FUNC_ARG returned if the ctx structure is NULL or the keySz
  5644. is less than zero or not divisible by 8.
  5645. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5646. wolfSSL_CTX_new().
  5647. \param keySz a short integer type stored in minRsaKeySz in the ctx
  5648. structure and the cm structure converted to bytes.
  5649. _Example_
  5650. \code
  5651. WOLFSSL_CTX* ctx = SSL_CTX_new(method);
  5652. (void)minDhKeyBits;
  5653. ourCert = myoptarg;
  5654. minDhKeyBits = atoi(myoptarg);
  5655. if(wolfSSL_CTX_SetMinRsaKey_Sz(ctx, minRsaKeyBits) != SSL_SUCCESS){
  5656. \endcode
  5657. \sa wolfSSL_SetMinRsaKey_Sz
  5658. */
  5659. int wolfSSL_CTX_SetMinRsaKey_Sz(WOLFSSL_CTX* ctx, short keySz);
  5660. /*!
  5661. \ingroup CertsKeys
  5662. \brief Sets the minimum allowable key size in bits for RSA located in the
  5663. WOLFSSL structure.
  5664. \return SSL_SUCCESS the minimum was set successfully.
  5665. \return BAD_FUNC_ARG returned if the ssl structure is NULL or if the ksySz
  5666. is less than zero or not divisible by 8.
  5667. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5668. \param keySz a short integer value representing the the minimum key in bits.
  5669. _Example_
  5670. \code
  5671. WOLFSSL* ssl = wolfSSL_new(ctx);
  5672. short keySz;
  5673. int isSet = wolfSSL_SetMinRsaKey_Sz(ssl, keySz);
  5674. if(isSet != SSL_SUCCESS){
  5675. Failed to set.
  5676. }
  5677. \endcode
  5678. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5679. */
  5680. int wolfSSL_SetMinRsaKey_Sz(WOLFSSL* ssl, short keySz);
  5681. /*!
  5682. \ingroup CertsKeys
  5683. \brief Sets the minimum size in bits for the ECC key in the WOLF_CTX
  5684. structure and the WOLFSSL_CERT_MANAGER structure.
  5685. \return SSL_SUCCESS returned for a successful execution and the minEccKeySz
  5686. member is set.
  5687. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5688. the keySz is negative or not divisible by 8.
  5689. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5690. wolfSSL_CTX_new().
  5691. \param keySz a short integer type that represents the minimum ECC key
  5692. size in bits.
  5693. _Example_
  5694. \code
  5695. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5696. short keySz; // minimum key size
  5697. if(wolfSSL_CTX_SetMinEccKey(ctx, keySz) != SSL_SUCCESS){
  5698. // Failed to set min key size
  5699. }
  5700. \endcode
  5701. \sa wolfSSL_SetMinEccKey_Sz
  5702. */
  5703. int wolfSSL_CTX_SetMinEccKey_Sz(WOLFSSL_CTX* ssl, short keySz);
  5704. /*!
  5705. \ingroup CertsKeys
  5706. \brief Sets the value of the minEccKeySz member of the options structure.
  5707. The options struct is a member of the WOLFSSL structure and is
  5708. accessed through the ssl parameter.
  5709. \return SSL_SUCCESS if the function successfully set the minEccKeySz
  5710. member of the options structure.
  5711. \return BAD_FUNC_ARG if the WOLFSSL_CTX structure is NULL or if the
  5712. key size (keySz) is less than 0 (zero) or not divisible by 8.
  5713. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5714. \param keySz value used to set the minimum ECC key size. Sets
  5715. value in the options structure.
  5716. _Example_
  5717. \code
  5718. WOLFSSL* ssl = wolfSSL_new(ctx); // New session
  5719. short keySz = 999; // should be set to min key size allowable
  5720. ...
  5721. if(wolfSSL_SetMinEccKey_Sz(ssl, keySz) != SSL_SUCCESS){
  5722. // Failure case.
  5723. }
  5724. \endcode
  5725. \sa wolfSSL_CTX_SetMinEccKey_Sz
  5726. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5727. \sa wolfSSL_SetMinRsaKey_Sz
  5728. */
  5729. int wolfSSL_SetMinEccKey_Sz(WOLFSSL* ssl, short keySz);
  5730. /*!
  5731. \ingroup CertsKeys
  5732. \brief This function is used by EAP_TLS and EAP-TTLS to derive
  5733. keying material from the master secret.
  5734. \return BUFFER_E returned if the actual size of the buffer exceeds
  5735. the maximum size allowable.
  5736. \return MEMORY_E returned if there is an error with memory allocation.
  5737. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5738. \param msk a void pointer variable that will hold the result
  5739. of the p_hash function.
  5740. \param len an unsigned integer that represents the length of
  5741. the msk variable.
  5742. \param label a constant char pointer that is copied from in wc_PRF().
  5743. _Example_
  5744. \code
  5745. WOLFSSL* ssl = wolfSSL_new(ctx);;
  5746. void* msk;
  5747. unsigned int len;
  5748. const char* label;
  5749. return wolfSSL_make_eap_keys(ssl, msk, len, label);
  5750. \endcode
  5751. \sa wc_PRF
  5752. \sa wc_HmacFinal
  5753. \sa wc_HmacUpdate
  5754. */
  5755. int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
  5756. const char* label);
  5757. /*!
  5758. \ingroup IO
  5759. \brief Simulates writev semantics but doesn’t actually do block at a time
  5760. because of SSL_write() behavior and because front adds may be small.
  5761. Makes porting into software that uses writev easier.
  5762. \return >0 the number of bytes written upon success.
  5763. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  5764. the specific error code.
  5765. \return MEMORY_ERROR will be returned if a memory error was encountered.
  5766. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  5767. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  5768. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  5769. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  5770. error code.
  5771. \param ssl pointer to the SSL session, created with wolfSSL_new().
  5772. \param iov array of I/O vectors to write
  5773. \param iovcnt number of vectors in iov array.
  5774. _Example_
  5775. \code
  5776. WOLFSSL* ssl = 0;
  5777. char *bufA = “hello\n”;
  5778. char *bufB = “hello world\n”;
  5779. int iovcnt;
  5780. struct iovec iov[2];
  5781. iov[0].iov_base = buffA;
  5782. iov[0].iov_len = strlen(buffA);
  5783. iov[1].iov_base = buffB;
  5784. iov[1].iov_len = strlen(buffB);
  5785. iovcnt = 2;
  5786. ...
  5787. ret = wolfSSL_writev(ssl, iov, iovcnt);
  5788. // wrote “ret” bytes, or error if <= 0.
  5789. \endcode
  5790. \sa wolfSSL_write
  5791. */
  5792. int wolfSSL_writev(WOLFSSL* ssl, const struct iovec* iov,
  5793. int iovcnt);
  5794. /*!
  5795. \ingroup Setup
  5796. \brief This function unloads the CA signer list and frees
  5797. the whole signer table.
  5798. \return SSL_SUCCESS returned on successful execution of the function.
  5799. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or there
  5800. are otherwise unpermitted argument values passed in a subroutine.
  5801. \return BAD_MUTEX_E returned if there was a mutex error. The LockMutex()
  5802. did not return 0.
  5803. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5804. wolfSSL_CTX_new().
  5805. _Example_
  5806. \code
  5807. WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
  5808. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  5809. if(!wolfSSL_CTX_UnloadCAs(ctx)){
  5810. // The function did not unload CAs
  5811. }
  5812. \endcode
  5813. \sa wolfSSL_CertManagerUnloadCAs
  5814. \sa LockMutex
  5815. \sa FreeSignerTable
  5816. \sa UnlockMutex
  5817. */
  5818. int wolfSSL_CTX_UnloadCAs(WOLFSSL_CTX*);
  5819. /*!
  5820. \ingroup Setup
  5821. \brief This function is used to unload all previously loaded trusted peer
  5822. certificates. Feature is enabled by defining the macro
  5823. WOLFSSL_TRUST_PEER_CERT.
  5824. \return SSL_SUCCESS upon success.
  5825. \return BAD_FUNC_ARG will be returned if ctx is NULL.
  5826. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5827. can’t be read, or is corrupted.
  5828. \return MEMORY_E will be returned if an out of memory condition occurs.
  5829. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5830. _Example_
  5831. \code
  5832. int ret = 0;
  5833. WOLFSSL_CTX* ctx;
  5834. ...
  5835. ret = wolfSSL_CTX_Unload_trust_peers(ctx);
  5836. if (ret != SSL_SUCCESS) {
  5837. // error unloading trusted peer certs
  5838. }
  5839. ...
  5840. \endcode
  5841. \sa wolfSSL_CTX_trust_peer_buffer
  5842. \sa wolfSSL_CTX_trust_peer_cert
  5843. */
  5844. int wolfSSL_CTX_Unload_trust_peers(WOLFSSL_CTX*);
  5845. /*!
  5846. \ingroup Setup
  5847. \brief This function loads a certificate to use for verifying a peer
  5848. when performing a TLS/SSL handshake. The peer certificate sent during
  5849. the handshake is compared by using the SKID when available and the
  5850. signature. If these two things do not match then any loaded CAs are used.
  5851. Is the same functionality as wolfSSL_CTX_trust_peer_cert except is from
  5852. a buffer instead of a file. Feature is enabled by defining the macro
  5853. WOLFSSL_TRUST_PEER_CERT Please see the examples for proper usage.
  5854. \return SSL_SUCCESS upon success
  5855. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  5856. type are invalid.
  5857. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5858. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  5859. read, or is corrupted.
  5860. \return MEMORY_E will be returned if an out of memory condition occurs.
  5861. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5862. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5863. \param buffer pointer to the buffer containing certificates.
  5864. \param sz length of the buffer input.
  5865. \param type type of certificate being loaded i.e. SSL_FILETYPE_ASN1 or
  5866. SSL_FILETYPE_PEM.
  5867. _Example_
  5868. \code
  5869. int ret = 0;
  5870. WOLFSSL_CTX* ctx;
  5871. ...
  5872. ret = wolfSSL_CTX_trust_peer_buffer(ctx, bufferPtr, bufferSz,
  5873. SSL_FILETYPE_PEM);
  5874. if (ret != SSL_SUCCESS) {
  5875. // error loading trusted peer cert
  5876. }
  5877. ...
  5878. \endcode
  5879. \sa wolfSSL_CTX_load_verify_buffer
  5880. \sa wolfSSL_CTX_use_certificate_file
  5881. \sa wolfSSL_CTX_use_PrivateKey_file
  5882. \sa wolfSSL_CTX_use_certificate_chain_file
  5883. \sa wolfSSL_CTX_trust_peer_cert
  5884. \sa wolfSSL_CTX_Unload_trust_peers
  5885. \sa wolfSSL_use_certificate_file
  5886. \sa wolfSSL_use_PrivateKey_file
  5887. \sa wolfSSL_use_certificate_chain_file
  5888. */
  5889. int wolfSSL_CTX_trust_peer_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
  5890. long sz, int format);
  5891. /*!
  5892. \ingroup CertsKeys
  5893. \brief This function loads a CA certificate buffer into the WOLFSSL
  5894. Context. It behaves like the non-buffered version, only differing in
  5895. its ability to be called with a buffer as input instead of a file.
  5896. The buffer is provided by the in argument of size sz. format specifies
  5897. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5898. More than one CA certificate may be loaded per buffer as long as the
  5899. format is in PEM. Please see the examples for proper usage.
  5900. \return SSL_SUCCESS upon success
  5901. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5902. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5903. can’t be read, or is corrupted.
  5904. \return MEMORY_E will be returned if an out of memory condition occurs.
  5905. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5906. \return BUFFER_E will be returned if a chain buffer is bigger than
  5907. the receiving buffer.
  5908. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5909. \param in pointer to the CA certificate buffer.
  5910. \param sz size of the input CA certificate buffer, in.
  5911. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  5912. or SSL_FILETYPE_PEM.
  5913. _Example_
  5914. \code
  5915. int ret = 0;
  5916. int sz = 0;
  5917. WOLFSSL_CTX* ctx;
  5918. byte certBuff[...];
  5919. ...
  5920. ret = wolfSSL_CTX_load_verify_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  5921. if (ret != SSL_SUCCESS) {
  5922. // error loading CA certs from buffer
  5923. }
  5924. ...
  5925. \endcode
  5926. \sa wolfSSL_CTX_load_verify_locations
  5927. \sa wolfSSL_CTX_use_certificate_buffer
  5928. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5929. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5930. \sa wolfSSL_use_certificate_buffer
  5931. \sa wolfSSL_use_PrivateKey_buffer
  5932. \sa wolfSSL_use_certificate_chain_buffer
  5933. */
  5934. int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
  5935. long sz, int format);
  5936. /*!
  5937. \ingroup CertsKeys
  5938. \brief This function loads a CA certificate buffer into the WOLFSSL
  5939. Context. It behaves like the non-buffered version, only differing in
  5940. its ability to be called with a buffer as input instead of a file.
  5941. The buffer is provided by the in argument of size sz. format specifies
  5942. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5943. More than one CA certificate may be loaded per buffer as long as the
  5944. format is in PEM. The _ex version was added in PR 2413 and supports
  5945. additional arguments for userChain and flags.
  5946. \return SSL_SUCCESS upon success
  5947. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  5948. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  5949. can’t be read, or is corrupted.
  5950. \return MEMORY_E will be returned if an out of memory condition occurs.
  5951. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  5952. \return BUFFER_E will be returned if a chain buffer is bigger than
  5953. the receiving buffer.
  5954. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  5955. \param in pointer to the CA certificate buffer.
  5956. \param sz size of the input CA certificate buffer, in.
  5957. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  5958. or SSL_FILETYPE_PEM.
  5959. \param userChain If using format WOLFSSL_FILETYPE_ASN1 this set to non-zero
  5960. indicates a chain of DER's is being presented.
  5961. \param flags: See ssl.h around WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS.
  5962. _Example_
  5963. \code
  5964. int ret = 0;
  5965. int sz = 0;
  5966. WOLFSSL_CTX* ctx;
  5967. byte certBuff[...];
  5968. ...
  5969. // Example for force loading an expired certificate
  5970. ret = wolfSSL_CTX_load_verify_buffer_ex(ctx, certBuff, sz, SSL_FILETYPE_PEM,
  5971. 0, (WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY));
  5972. if (ret != SSL_SUCCESS) {
  5973. // error loading CA certs from buffer
  5974. }
  5975. ...
  5976. \endcode
  5977. \sa wolfSSL_CTX_load_verify_buffer
  5978. \sa wolfSSL_CTX_load_verify_locations
  5979. \sa wolfSSL_CTX_use_certificate_buffer
  5980. \sa wolfSSL_CTX_use_PrivateKey_buffer
  5981. \sa wolfSSL_CTX_use_certificate_chain_buffer
  5982. \sa wolfSSL_use_certificate_buffer
  5983. \sa wolfSSL_use_PrivateKey_buffer
  5984. \sa wolfSSL_use_certificate_chain_buffer
  5985. */
  5986. int wolfSSL_CTX_load_verify_buffer_ex(WOLFSSL_CTX* ctx,
  5987. const unsigned char* in, long sz,
  5988. int format, int userChain, word32 flags);
  5989. /*!
  5990. \ingroup CertsKeys
  5991. \brief This function loads a CA certificate chain buffer into the WOLFSSL
  5992. Context. It behaves like the non-buffered version, only differing in
  5993. its ability to be called with a buffer as input instead of a file.
  5994. The buffer is provided by the in argument of size sz. format specifies
  5995. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  5996. More than one CA certificate may be loaded per buffer as long as the
  5997. format is in PEM. Please see the examples for proper usage.
  5998. \return SSL_SUCCESS upon success
  5999. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6000. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6001. can’t be read, or is corrupted.
  6002. \return MEMORY_E will be returned if an out of memory condition occurs.
  6003. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6004. \return BUFFER_E will be returned if a chain buffer is bigger than
  6005. the receiving buffer.
  6006. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6007. \param in pointer to the CA certificate buffer.
  6008. \param sz size of the input CA certificate buffer, in.
  6009. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6010. or SSL_FILETYPE_PEM.
  6011. _Example_
  6012. \code
  6013. int ret = 0;
  6014. int sz = 0;
  6015. WOLFSSL_CTX* ctx;
  6016. byte certBuff[...];
  6017. ...
  6018. ret = wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  6019. certBuff, sz, WOLFSSL_FILETYPE_ASN1);
  6020. if (ret != SSL_SUCCESS) {
  6021. // error loading CA certs from buffer
  6022. }
  6023. ...
  6024. \endcode
  6025. \sa wolfSSL_CTX_load_verify_locations
  6026. \sa wolfSSL_CTX_use_certificate_buffer
  6027. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6028. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6029. \sa wolfSSL_use_certificate_buffer
  6030. \sa wolfSSL_use_PrivateKey_buffer
  6031. \sa wolfSSL_use_certificate_chain_buffer
  6032. */
  6033. int wolfSSL_CTX_load_verify_chain_buffer_format(WOLFSSL_CTX* ctx,
  6034. const unsigned char* in,
  6035. long sz, int format);
  6036. /*!
  6037. \ingroup CertsKeys
  6038. \brief This function loads a certificate buffer into the WOLFSSL Context.
  6039. It behaves like the non-buffered version, only differing in its ability
  6040. to be called with a buffer as input instead of a file. The buffer is
  6041. provided by the in argument of size sz. format specifies the format
  6042. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  6043. see the examples for proper usage.
  6044. \return SSL_SUCCESS upon success
  6045. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6046. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6047. can’t be read, or is corrupted.
  6048. \return MEMORY_E will be returned if an out of memory condition occurs.
  6049. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6050. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6051. \param in the input buffer containing the certificate to be loaded.
  6052. \param sz the size of the input buffer.
  6053. \param format the format of the certificate located in the input
  6054. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6055. _Example_
  6056. \code
  6057. int ret = 0;
  6058. int sz = 0;
  6059. WOLFSSL_CTX* ctx;
  6060. byte certBuff[...];
  6061. ...
  6062. ret = wolfSSL_CTX_use_certificate_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  6063. if (ret != SSL_SUCCESS) {
  6064. // error loading certificate from buffer
  6065. }
  6066. ...
  6067. \endcode
  6068. \sa wolfSSL_CTX_load_verify_buffer
  6069. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6070. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6071. \sa wolfSSL_use_certificate_buffer
  6072. \sa wolfSSL_use_PrivateKey_buffer
  6073. \sa wolfSSL_use_certificate_chain_buffer
  6074. */
  6075. int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX* ctx,
  6076. const unsigned char* in, long sz,
  6077. int format);
  6078. /*!
  6079. \ingroup CertsKeys
  6080. \brief This function loads a private key buffer into the SSL Context.
  6081. It behaves like the non-buffered version, only differing in its ability
  6082. to be called with a buffer as input instead of a file. The buffer is
  6083. provided by the in argument of size sz. format specifies the format type
  6084. of the buffer; SSL_FILETYPE_ASN1or SSL_FILETYPE_PEM. Please see the
  6085. examples for proper usage.
  6086. \return SSL_SUCCESS upon success
  6087. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6088. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6089. read, or is corrupted.
  6090. \return MEMORY_E will be returned if an out of memory condition occurs.
  6091. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6092. \return NO_PASSWORD will be returned if the key file is encrypted but no
  6093. password is provided.
  6094. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6095. \param in the input buffer containing the private key to be loaded.
  6096. \param sz the size of the input buffer.
  6097. \param format the format of the private key located in the input
  6098. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6099. _Example_
  6100. \code
  6101. int ret = 0;
  6102. int sz = 0;
  6103. WOLFSSL_CTX* ctx;
  6104. byte keyBuff[...];
  6105. ...
  6106. ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, keyBuff, sz, SSL_FILETYPE_PEM);
  6107. if (ret != SSL_SUCCESS) {
  6108. // error loading private key from buffer
  6109. }
  6110. ...
  6111. \endcode
  6112. \sa wolfSSL_CTX_load_verify_buffer
  6113. \sa wolfSSL_CTX_use_certificate_buffer
  6114. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6115. \sa wolfSSL_use_certificate_buffer
  6116. \sa wolfSSL_use_PrivateKey_buffer
  6117. \sa wolfSSL_use_certificate_chain_buffer
  6118. */
  6119. int wolfSSL_CTX_use_PrivateKey_buffer(WOLFSSL_CTX* ctx,
  6120. const unsigned char* in, long sz,
  6121. int format);
  6122. /*!
  6123. \ingroup CertsKeys
  6124. \brief This function loads a certificate chain buffer into the WOLFSSL
  6125. Context. It behaves like the non-buffered version, only differing in
  6126. its ability to be called with a buffer as input instead of a file.
  6127. The buffer is provided by the in argument of size sz. The buffer must
  6128. be in PEM format and start with the subject’s certificate, ending with
  6129. the root certificate. Please see the examples for proper usage.
  6130. \return SSL_SUCCESS upon success
  6131. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6132. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6133. can’t be read, or is corrupted.
  6134. \return MEMORY_E will be returned if an out of memory condition occurs.
  6135. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6136. \return BUFFER_E will be returned if a chain buffer is bigger than
  6137. the receiving buffer.
  6138. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6139. \param in the input buffer containing the PEM-formatted certificate
  6140. chain to be loaded.
  6141. \param sz the size of the input buffer.
  6142. _Example_
  6143. \code
  6144. int ret = 0;
  6145. int sz = 0;
  6146. WOLFSSL_CTX* ctx;
  6147. byte certChainBuff[...];
  6148. ...
  6149. ret = wolfSSL_CTX_use_certificate_chain_buffer(ctx, certChainBuff, sz);
  6150. if (ret != SSL_SUCCESS) {
  6151. // error loading certificate chain from buffer
  6152. }
  6153. ...
  6154. \endcode
  6155. \sa wolfSSL_CTX_load_verify_buffer
  6156. \sa wolfSSL_CTX_use_certificate_buffer
  6157. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6158. \sa wolfSSL_use_certificate_buffer
  6159. \sa wolfSSL_use_PrivateKey_buffer
  6160. \sa wolfSSL_use_certificate_chain_buffer
  6161. */
  6162. int wolfSSL_CTX_use_certificate_chain_buffer(WOLFSSL_CTX* ctx,
  6163. const unsigned char* in, long sz);
  6164. /*!
  6165. \ingroup CertsKeys
  6166. \brief This function loads a certificate buffer into the WOLFSSL object.
  6167. It behaves like the non-buffered version, only differing in its ability
  6168. to be called with a buffer as input instead of a file. The buffer
  6169. is provided by the in argument of size sz. format specifies the format
  6170. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6171. Please see the examples for proper usage.
  6172. \return SSL_SUCCESS upon success.
  6173. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6174. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  6175. be read, or is corrupted.
  6176. \return MEMORY_E will be returned if an out of memory condition occurs.
  6177. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6178. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6179. \param in buffer containing certificate to load.
  6180. \param sz size of the certificate located in buffer.
  6181. \param format format of the certificate to be loaded.
  6182. Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6183. _Example_
  6184. \code
  6185. int buffSz;
  6186. int ret;
  6187. byte certBuff[...];
  6188. WOLFSSL* ssl = 0;
  6189. ...
  6190. ret = wolfSSL_use_certificate_buffer(ssl, certBuff, buffSz, SSL_FILETYPE_PEM);
  6191. if (ret != SSL_SUCCESS) {
  6192. // failed to load certificate from buffer
  6193. }
  6194. \endcode
  6195. \sa wolfSSL_CTX_load_verify_buffer
  6196. \sa wolfSSL_CTX_use_certificate_buffer
  6197. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6198. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6199. \sa wolfSSL_use_PrivateKey_buffer
  6200. \sa wolfSSL_use_certificate_chain_buffer
  6201. */
  6202. int wolfSSL_use_certificate_buffer(WOLFSSL* ssl, const unsigned char* in,
  6203. long sz, int format);
  6204. /*!
  6205. \ingroup CertsKeys
  6206. \brief This function loads a private key buffer into the WOLFSSL object.
  6207. It behaves like the non-buffered version, only differing in its ability
  6208. to be called with a buffer as input instead of a file. The buffer is
  6209. provided by the in argument of size sz. format specifies the format
  6210. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  6211. see the examples for proper usage.
  6212. \return SSL_SUCCESS upon success.
  6213. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6214. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6215. read, or is corrupted.
  6216. \return MEMORY_E will be returned if an out of memory condition occurs.
  6217. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6218. \return NO_PASSWORD will be returned if the key file is encrypted but no
  6219. password is provided.
  6220. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6221. \param in buffer containing private key to load.
  6222. \param sz size of the private key located in buffer.
  6223. \param format format of the private key to be loaded. Possible values are
  6224. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6225. _Example_
  6226. \code
  6227. int buffSz;
  6228. int ret;
  6229. byte keyBuff[...];
  6230. WOLFSSL* ssl = 0;
  6231. ...
  6232. ret = wolfSSL_use_PrivateKey_buffer(ssl, keyBuff, buffSz, SSL_FILETYPE_PEM);
  6233. if (ret != SSL_SUCCESS) {
  6234. // failed to load private key from buffer
  6235. }
  6236. \endcode
  6237. \sa wolfSSL_use_PrivateKey
  6238. \sa wolfSSL_CTX_load_verify_buffer
  6239. \sa wolfSSL_CTX_use_certificate_buffer
  6240. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6241. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6242. \sa wolfSSL_use_certificate_buffer
  6243. \sa wolfSSL_use_certificate_chain_buffer
  6244. */
  6245. int wolfSSL_use_PrivateKey_buffer(WOLFSSL* ssl, const unsigned char* in,
  6246. long sz, int format);
  6247. /*!
  6248. \ingroup CertsKeys
  6249. \brief This function loads a certificate chain buffer into the WOLFSSL
  6250. object. It behaves like the non-buffered version, only differing in its
  6251. ability to be called with a buffer as input instead of a file. The buffer
  6252. is provided by the in argument of size sz. The buffer must be in PEM format
  6253. and start with the subject’s certificate, ending with the root certificate.
  6254. Please see the examples for proper usage.
  6255. \return SSL_SUCCES upon success.
  6256. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6257. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6258. can’t be read, or is corrupted.
  6259. \return MEMORY_E will be returned if an out of memory condition occurs.
  6260. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6261. \return BUFFER_E will be returned if a chain buffer is bigger than
  6262. the receiving buffer.
  6263. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6264. \param in buffer containing certificate to load.
  6265. \param sz size of the certificate located in buffer.
  6266. _Example_
  6267. \code
  6268. int buffSz;
  6269. int ret;
  6270. byte certChainBuff[...];
  6271. WOLFSSL* ssl = 0;
  6272. ...
  6273. ret = wolfSSL_use_certificate_chain_buffer(ssl, certChainBuff, buffSz);
  6274. if (ret != SSL_SUCCESS) {
  6275. // failed to load certificate chain from buffer
  6276. }
  6277. \endcode
  6278. \sa wolfSSL_CTX_load_verify_buffer
  6279. \sa wolfSSL_CTX_use_certificate_buffer
  6280. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6281. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6282. \sa wolfSSL_use_certificate_buffer
  6283. \sa wolfSSL_use_PrivateKey_buffer
  6284. */
  6285. int wolfSSL_use_certificate_chain_buffer(WOLFSSL* ssl,
  6286. const unsigned char* in, long sz);
  6287. /*!
  6288. \ingroup CertsKeys
  6289. \brief This function unloads any certificates or keys that SSL owns.
  6290. \return SSL_SUCCESS - returned if the function executed successfully.
  6291. \return BAD_FUNC_ARG - returned if the WOLFSSL object is NULL.
  6292. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6293. _Example_
  6294. \code
  6295. WOLFSSL* ssl = wolfSSL_new(ctx);
  6296. ...
  6297. int unloadKeys = wolfSSL_UnloadCertsKeys(ssl);
  6298. if(unloadKeys != SSL_SUCCESS){
  6299. // Failure case.
  6300. }
  6301. \endcode
  6302. \sa wolfSSL_CTX_UnloadCAs
  6303. */
  6304. int wolfSSL_UnloadCertsKeys(WOLFSSL*);
  6305. /*!
  6306. \ingroup Setup
  6307. \brief This function turns on grouping of handshake messages where possible.
  6308. \return SSL_SUCCESS will be returned upon success.
  6309. \return BAD_FUNC_ARG will be returned if the input context is null.
  6310. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6311. _Example_
  6312. \code
  6313. WOLFSSL_CTX* ctx = 0;
  6314. ...
  6315. ret = wolfSSL_CTX_set_group_messages(ctx);
  6316. if (ret != SSL_SUCCESS) {
  6317. // failed to set handshake message grouping
  6318. }
  6319. \endcode
  6320. \sa wolfSSL_set_group_messages
  6321. \sa wolfSSL_CTX_new
  6322. */
  6323. int wolfSSL_CTX_set_group_messages(WOLFSSL_CTX*);
  6324. /*!
  6325. \ingroup Setup
  6326. \brief This function turns on grouping of handshake messages where possible.
  6327. \return SSL_SUCCESS will be returned upon success.
  6328. \return BAD_FUNC_ARG will be returned if the input context is null.
  6329. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6330. _Example_
  6331. \code
  6332. WOLFSSL* ssl = 0;
  6333. ...
  6334. ret = wolfSSL_set_group_messages(ssl);
  6335. if (ret != SSL_SUCCESS) {
  6336. // failed to set handshake message grouping
  6337. }
  6338. \endcode
  6339. \sa wolfSSL_CTX_set_group_messages
  6340. \sa wolfSSL_new
  6341. */
  6342. int wolfSSL_set_group_messages(WOLFSSL*);
  6343. /*!
  6344. \brief This function sets the fuzzer callback.
  6345. \return none No returns.
  6346. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6347. \param cbf a CallbackFuzzer type that is a function pointer of the form:
  6348. int (*CallbackFuzzer)(WOLFSSL* ssl, const unsigned char* buf, int sz, int
  6349. type, void* fuzzCtx);
  6350. \param fCtx a void pointer type that will be set to the fuzzerCtx member of
  6351. the WOLFSSL structure.
  6352. _Example_
  6353. \code
  6354. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6355. WOLFSSL* ssl = wolfSSL_new(ctx);
  6356. void* fCtx;
  6357. int callbackFuzzerCB(WOLFSSL* ssl, const unsigned char* buf, int sz,
  6358. int type, void* fuzzCtx){
  6359. // function definition
  6360. }
  6361. wolfSSL_SetFuzzerCb(ssl, callbackFuzzerCB, fCtx);
  6362. \endcode
  6363. \sa CallbackFuzzer
  6364. */
  6365. void wolfSSL_SetFuzzerCb(WOLFSSL* ssl, CallbackFuzzer cbf, void* fCtx);
  6366. /*!
  6367. \brief This function sets a new dtls cookie secret.
  6368. \return 0 returned if the function executed without an error.
  6369. \return BAD_FUNC_ARG returned if there was an argument passed
  6370. to the function with an unacceptable value.
  6371. \return COOKIE_SECRET_SZ returned if the secret size is 0.
  6372. \return MEMORY_ERROR returned if there was a problem allocating
  6373. memory for a new cookie secret.
  6374. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6375. \param secret a constant byte pointer representing the secret buffer.
  6376. \param secretSz the size of the buffer.
  6377. _Example_
  6378. \code
  6379. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6380. WOLFSSL* ssl = wolfSSL_new(ctx);
  6381. const* byte secret;
  6382. word32 secretSz; // size of secret
  6383. if(!wolfSSL_DTLS_SetCookieSecret(ssl, secret, secretSz)){
  6384. // Code block for failure to set DTLS cookie secret
  6385. } else {
  6386. // Success! Cookie secret is set.
  6387. }
  6388. \endcode
  6389. \sa ForceZero
  6390. \sa wc_RNG_GenerateBlock
  6391. */
  6392. int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
  6393. const unsigned char* secret,
  6394. unsigned int secretSz);
  6395. /*!
  6396. \brief This function retrieves the random number.
  6397. \return rng upon success.
  6398. \return NULL if ssl is NULL.
  6399. \param ssl pointer to a SSL object, created with wolfSSL_new().
  6400. _Example_
  6401. \code
  6402. WOLFSSL* ssl;
  6403. wolfSSL_GetRNG(ssl);
  6404. \endcode
  6405. \sa wolfSSL_CTX_new_rng
  6406. */
  6407. WC_RNG* wolfSSL_GetRNG(WOLFSSL* ssl);
  6408. /*!
  6409. \ingroup Setup
  6410. \brief This function sets the minimum downgrade version allowed.
  6411. Applicable only when the connection allows downgrade using
  6412. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6413. \return SSL_SUCCESS returned if the function returned without
  6414. error and the minimum version is set.
  6415. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure was
  6416. NULL or if the minimum version is not supported.
  6417. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6418. wolfSSL_CTX_new().
  6419. \param version an integer representation of the version to be set as the
  6420. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6421. WOLFSSL_TLSV1_2 = 3.
  6422. _Example_
  6423. \code
  6424. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  6425. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6426. int version; // macrop representation
  6427. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6428. // Failed to set min version
  6429. }
  6430. \endcode
  6431. \sa SetMinVersionHelper
  6432. */
  6433. int wolfSSL_CTX_SetMinVersion(WOLFSSL_CTX* ctx, int version);
  6434. /*!
  6435. \ingroup TLS
  6436. \brief This function sets the minimum downgrade version allowed.
  6437. Applicable only when the connection allows downgrade using
  6438. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6439. \return SSL_SUCCESS returned if this function and its subroutine executes
  6440. without error.
  6441. \return BAD_FUNC_ARG returned if the SSL object is NULL. In
  6442. the subroutine this error is thrown if there is not a good version match.
  6443. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6444. \param version an integer representation of the version to be set as the
  6445. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6446. WOLFSSL_TLSV1_2 = 3.
  6447. _Example_
  6448. \code
  6449. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol method);
  6450. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6451. int version; macro representation
  6452. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6453. Failed to set min version
  6454. }
  6455. \endcode
  6456. \sa SetMinVersionHelper
  6457. */
  6458. int wolfSSL_SetMinVersion(WOLFSSL* ssl, int version);
  6459. /*!
  6460. \brief This function returns the size of the WOLFSSL object and will be
  6461. dependent on build options and settings. If SHOW_SIZES has been defined
  6462. when building wolfSSL, this function will also print the sizes of individual
  6463. objects within the WOLFSSL object (Suites, Ciphers, etc.) to stdout.
  6464. \return size This function returns the size of the WOLFSSL object.
  6465. \param none No parameters.
  6466. _Example_
  6467. \code
  6468. int size = 0;
  6469. size = wolfSSL_GetObjectSize();
  6470. printf(“sizeof(WOLFSSL) = %d\n”, size);
  6471. \endcode
  6472. \sa wolfSSL_new
  6473. */
  6474. int wolfSSL_GetObjectSize(void); /* object size based on build */
  6475. /*!
  6476. \brief Returns the record layer size of the plaintext input. This is helpful
  6477. when an application wants to know how many bytes will be sent across the
  6478. Transport layer, given a specified plaintext input size. This function
  6479. must be called after the SSL/TLS handshake has been completed.
  6480. \return size Upon success, the requested size will be returned
  6481. \return INPUT_SIZE_E will be returned if the input size is greater than the
  6482. maximum TLS fragment size (see wolfSSL_GetMaxOutputSize())
  6483. \return BAD_FUNC_ARG will be returned upon invalid function argument, or if
  6484. the SSL/TLS handshake has not been completed yet
  6485. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6486. \param inSz size of plaintext data.
  6487. _Example_
  6488. \code
  6489. none
  6490. \endcode
  6491. \sa wolfSSL_GetMaxOutputSize
  6492. */
  6493. int wolfSSL_GetOutputSize(WOLFSSL* ssl, int inSz);
  6494. /*!
  6495. \brief Returns the maximum record layer size for plaintext data. This
  6496. will correspond to either the maximum SSL/TLS record size as specified
  6497. by the protocol standard, the maximum TLS fragment size as set by the
  6498. TLS Max Fragment Length extension. This function is helpful when the
  6499. application has called wolfSSL_GetOutputSize() and received a INPUT_SIZE_E
  6500. error. This function must be called after the SSL/TLS handshake has been
  6501. completed.
  6502. \return size Upon success, the maximum output size will be returned
  6503. \return BAD_FUNC_ARG will be returned upon invalid function argument,
  6504. or if the SSL/TLS handshake has not been completed yet.
  6505. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6506. _Example_
  6507. \code
  6508. none
  6509. \endcode
  6510. \sa wolfSSL_GetOutputSize
  6511. */
  6512. int wolfSSL_GetMaxOutputSize(WOLFSSL*);
  6513. /*!
  6514. \ingroup Setup
  6515. \brief This function sets the SSL/TLS protocol version for the specified
  6516. SSL session (WOLFSSL object) using the version as specified by version.
  6517. This will override the protocol setting for the SSL session (ssl) -
  6518. originally defined and set by the SSL context (wolfSSL_CTX_new())
  6519. method type.
  6520. \return SSL_SUCCESS upon success.
  6521. \return BAD_FUNC_ARG will be returned if the input SSL object is
  6522. NULL or an incorrect protocol version is given for version.
  6523. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6524. \param version SSL/TLS protocol version. Possible values include
  6525. WOLFSSL_SSLV3, WOLFSSL_TLSV1, WOLFSSL_TLSV1_1, WOLFSSL_TLSV1_2.
  6526. _Example_
  6527. \code
  6528. int ret = 0;
  6529. WOLFSSL* ssl;
  6530. ...
  6531. ret = wolfSSL_SetVersion(ssl, WOLFSSL_TLSV1);
  6532. if (ret != SSL_SUCCESS) {
  6533. // failed to set SSL session protocol version
  6534. }
  6535. \endcode
  6536. \sa wolfSSL_CTX_new
  6537. */
  6538. int wolfSSL_SetVersion(WOLFSSL* ssl, int version);
  6539. /*!
  6540. \brief Allows caller to set the Atomic User Record Processing
  6541. Mac/Encrypt Callback. The callback should return 0 for success
  6542. or < 0 for an error. The ssl and ctx pointers are available
  6543. for the user’s convenience. macOut is the output buffer where
  6544. the result of the mac should be stored. macIn is the mac input
  6545. buffer and macInSz notes the size of the buffer. macContent
  6546. and macVerify are needed for wolfSSL_SetTlsHmacInner() and be
  6547. passed along as is. encOut is the output buffer where the result
  6548. on the encryption should be stored. encIn is the input buffer to
  6549. encrypt while encSz is the size of the input. An example callback
  6550. can be found wolfssl/test.h myMacEncryptCb().
  6551. \return none No return.
  6552. \param No parameters.
  6553. _Example_
  6554. \code
  6555. none
  6556. \endcode
  6557. \sa wolfSSL_SetMacEncryptCtx
  6558. \sa wolfSSL_GetMacEncryptCtx
  6559. */
  6560. void wolfSSL_CTX_SetMacEncryptCb(WOLFSSL_CTX* ctx, CallbackMacEncrypti cb);
  6561. /*!
  6562. \brief Allows caller to set the Atomic User Record Processing Mac/Encrypt
  6563. Callback Context to ctx.
  6564. \return none No return.
  6565. \param none No parameters.
  6566. _Example_
  6567. \code
  6568. none
  6569. \endcode
  6570. \sa wolfSSL_CTX_SetMacEncryptCb
  6571. \sa wolfSSL_GetMacEncryptCtx
  6572. */
  6573. void wolfSSL_SetMacEncryptCtx(WOLFSSL* ssl, void *ctx);
  6574. /*!
  6575. \brief Allows caller to retrieve the Atomic User Record Processing
  6576. Mac/Encrypt Callback Context previously stored with
  6577. wolfSSL_SetMacEncryptCtx().
  6578. \return pointer If successful the call will return a valid pointer
  6579. to the context.
  6580. \return NULL will be returned for a blank context.
  6581. \param none No parameters.
  6582. _Example_
  6583. \code
  6584. none
  6585. \endcode
  6586. \sa wolfSSL_CTX_SetMacEncryptCb
  6587. \sa wolfSSL_SetMacEncryptCtx
  6588. */
  6589. void* wolfSSL_GetMacEncryptCtx(WOLFSSL* ssl);
  6590. /*!
  6591. \brief Allows caller to set the Atomic User Record Processing
  6592. Decrypt/Verify Callback. The callback should return 0 for success
  6593. or < 0 for an error. The ssl and ctx pointers are available for
  6594. the user’s convenience. decOut is the output buffer where the result
  6595. of the decryption should be stored. decIn is the encrypted input
  6596. buffer and decInSz notes the size of the buffer. content and verify
  6597. are needed for wolfSSL_SetTlsHmacInner() and be passed along as is.
  6598. padSz is an output variable that should be set with the total value
  6599. of the padding. That is, the mac size plus any padding and pad bytes.
  6600. An example callback can be found wolfssl/test.h myDecryptVerifyCb().
  6601. \return none No returns.
  6602. \param none No parameters.
  6603. _Example_
  6604. \code
  6605. none
  6606. \endcode
  6607. \sa wolfSSL_SetMacEncryptCtx
  6608. \sa wolfSSL_GetMacEncryptCtx
  6609. */
  6610. void wolfSSL_CTX_SetDecryptVerifyCb(WOLFSSL_CTX* ctx,
  6611. CallbackDecryptVerify cb);
  6612. /*!
  6613. \brief Allows caller to set the Atomic User Record Processing
  6614. Decrypt/Verify Callback Context to ctx.
  6615. \return none No returns.
  6616. \param none No parameters.
  6617. _Example_
  6618. \code
  6619. none
  6620. \endcode
  6621. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6622. \sa wolfSSL_GetDecryptVerifyCtx
  6623. */
  6624. void wolfSSL_SetDecryptVerifyCtx(WOLFSSL* ssl, void *ctx);
  6625. /*!
  6626. \brief Allows caller to retrieve the Atomic User Record Processing
  6627. Decrypt/Verify Callback Context previously stored with
  6628. wolfSSL_SetDecryptVerifyCtx().
  6629. \return pointer If successful the call will return a valid pointer to the
  6630. context.
  6631. \return NULL will be returned for a blank context.
  6632. \param none No parameters.
  6633. _Example_
  6634. \code
  6635. none
  6636. \endcode
  6637. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6638. \sa wolfSSL_SetDecryptVerifyCtx
  6639. */
  6640. void* wolfSSL_GetDecryptVerifyCtx(WOLFSSL* ssl);
  6641. /*!
  6642. \brief Allows retrieval of the Hmac/Mac secret from the handshake process.
  6643. The verify parameter specifies whether this is for verification of a
  6644. peer message.
  6645. \return pointer If successful the call will return a valid pointer to the
  6646. secret. The size of the secret can be obtained from wolfSSL_GetHmacSize().
  6647. \return NULL will be returned for an error state.
  6648. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6649. \param verify specifies whether this is for verification of a peer message.
  6650. _Example_
  6651. \code
  6652. none
  6653. \endcode
  6654. \sa wolfSSL_GetHmacSize
  6655. */
  6656. const unsigned char* wolfSSL_GetMacSecret(WOLFSSL* ssl, int verify);
  6657. /*!
  6658. \brief Allows retrieval of the client write key from the handshake process.
  6659. \return pointer If successful the call will return a valid pointer to the
  6660. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  6661. \return NULL will be returned for an error state.
  6662. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6663. _Example_
  6664. \code
  6665. none
  6666. \endcode
  6667. \sa wolfSSL_GetKeySize
  6668. \sa wolfSSL_GetClientWriteIV
  6669. */
  6670. const unsigned char* wolfSSL_GetClientWriteKey(WOLFSSL*);
  6671. /*!
  6672. \brief Allows retrieval of the client write IV (initialization vector)
  6673. from the handshake process.
  6674. \return pointer If successful the call will return a valid pointer to the
  6675. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  6676. \return NULL will be returned for an error state.
  6677. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6678. _Example_
  6679. \code
  6680. none
  6681. \endcode
  6682. \sa wolfSSL_GetCipherBlockSize()
  6683. \sa wolfSSL_GetClientWriteKey()
  6684. */
  6685. const unsigned char* wolfSSL_GetClientWriteIV(WOLFSSL*);
  6686. /*!
  6687. \brief Allows retrieval of the server write key from the handshake process.
  6688. \return pointer If successful the call will return a valid pointer to the
  6689. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  6690. \return NULL will be returned for an error state.
  6691. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6692. _Example_
  6693. \code
  6694. none
  6695. \endcode
  6696. \sa wolfSSL_GetKeySize
  6697. \sa wolfSSL_GetServerWriteIV
  6698. */
  6699. const unsigned char* wolfSSL_GetServerWriteKey(WOLFSSL*);
  6700. /*!
  6701. \brief Allows retrieval of the server write IV (initialization vector)
  6702. from the handshake process.
  6703. \return pointer If successful the call will return a valid pointer to the
  6704. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  6705. \return NULL will be returned for an error state.
  6706. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6707. \sa wolfSSL_GetCipherBlockSize
  6708. \sa wolfSSL_GetClientWriteKey
  6709. */
  6710. const unsigned char* wolfSSL_GetServerWriteIV(WOLFSSL*);
  6711. /*!
  6712. \brief Allows retrieval of the key size from the handshake process.
  6713. \return size If successful the call will return the key size in bytes.
  6714. \return BAD_FUNC_ARG will be returned for an error state.
  6715. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6716. _Example_
  6717. \code
  6718. none
  6719. \endcode
  6720. \sa wolfSSL_GetClientWriteKey
  6721. \sa wolfSSL_GetServerWriteKey
  6722. */
  6723. int wolfSSL_GetKeySize(WOLFSSL*);
  6724. /*!
  6725. \ingroup CertsKeys
  6726. \brief Returns the iv_size member of the specs structure
  6727. held in the WOLFSSL struct.
  6728. \return iv_size returns the value held in ssl->specs.iv_size.
  6729. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  6730. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6731. _Example_
  6732. \code
  6733. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6734. WOLFSSL* ssl = wolfSSL_new(ctx);
  6735. int ivSize;
  6736. ...
  6737. ivSize = wolfSSL_GetIVSize(ssl);
  6738. if(ivSize > 0){
  6739. // ivSize holds the specs.iv_size value.
  6740. }
  6741. \endcode
  6742. \sa wolfSSL_GetKeySize
  6743. \sa wolfSSL_GetClientWriteIV
  6744. \sa wolfSSL_GetServerWriteIV
  6745. */
  6746. int wolfSSL_GetIVSize(WOLFSSL*);
  6747. /*!
  6748. \brief Allows retrieval of the side of this WOLFSSL connection.
  6749. \return success If successful the call will return either
  6750. WOLFSSL_SERVER_END or WOLFSSL_CLIENT_END depending on the
  6751. side of WOLFSSL object.
  6752. \return BAD_FUNC_ARG will be returned for an error state.
  6753. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6754. _Example_
  6755. \code
  6756. none
  6757. \endcode
  6758. \sa wolfSSL_GetClientWriteKey
  6759. \sa wolfSSL_GetServerWriteKey
  6760. */
  6761. int wolfSSL_GetSide(WOLFSSL*);
  6762. /*!
  6763. \brief Allows caller to determine if the negotiated protocol version
  6764. is at least TLS version 1.1 or greater.
  6765. \return true/false If successful the call will return 1 for true or
  6766. 0 for false.
  6767. \return BAD_FUNC_ARG will be returned for an error state.
  6768. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6769. _Example_
  6770. \code
  6771. none
  6772. \endcode
  6773. \sa wolfSSL_GetSide
  6774. */
  6775. int wolfSSL_IsTLSv1_1(WOLFSSL*);
  6776. /*!
  6777. \brief Allows caller to determine the negotiated bulk cipher algorithm
  6778. from the handshake.
  6779. \return If successful the call will return one of the following:
  6780. wolfssl_cipher_null, wolfssl_des, wolfssl_triple_des, wolfssl_aes,
  6781. wolfssl_aes_gcm, wolfssl_aes_ccm, wolfssl_camellia.
  6782. \return BAD_FUNC_ARG will be returned for an error state.
  6783. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6784. _Example_
  6785. \code
  6786. none
  6787. \endcode
  6788. \sa wolfSSL_GetCipherBlockSize
  6789. \sa wolfSSL_GetKeySize
  6790. */
  6791. int wolfSSL_GetBulkCipher(WOLFSSL*);
  6792. /*!
  6793. \brief Allows caller to determine the negotiated cipher block size from
  6794. the handshake.
  6795. \return size If successful the call will return the size in bytes of the
  6796. cipher block size.
  6797. \return BAD_FUNC_ARG will be returned for an error state.
  6798. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6799. _Example_
  6800. \code
  6801. none
  6802. \endcode
  6803. \sa wolfSSL_GetBulkCipher
  6804. \sa wolfSSL_GetKeySize
  6805. */
  6806. int wolfSSL_GetCipherBlockSize(WOLFSSL*);
  6807. /*!
  6808. \brief Allows caller to determine the negotiated aead mac size from the
  6809. handshake. For cipher type WOLFSSL_AEAD_TYPE.
  6810. \return size If successful the call will return the size in bytes of the
  6811. aead mac size.
  6812. \return BAD_FUNC_ARG will be returned for an error state.
  6813. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6814. _Example_
  6815. \code
  6816. none
  6817. \endcode
  6818. \sa wolfSSL_GetBulkCipher
  6819. \sa wolfSSL_GetKeySize
  6820. */
  6821. int wolfSSL_GetAeadMacSize(WOLFSSL*);
  6822. /*!
  6823. \brief Allows caller to determine the negotiated (h)mac size from the
  6824. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  6825. \return size If successful the call will return the size in bytes of
  6826. the (h)mac size.
  6827. \return BAD_FUNC_ARG will be returned for an error state.
  6828. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6829. _Example_
  6830. \code
  6831. none
  6832. \endcode
  6833. \sa wolfSSL_GetBulkCipher
  6834. \sa wolfSSL_GetHmacType
  6835. */
  6836. int wolfSSL_GetHmacSize(WOLFSSL*);
  6837. /*!
  6838. \brief Allows caller to determine the negotiated (h)mac type from the
  6839. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  6840. \return If successful the call will return one of the following:
  6841. MD5, SHA, SHA256, SHA384.
  6842. \return BAD_FUNC_ARG may be returned for an error state.
  6843. \return SSL_FATAL_ERROR may also be returned for an error state.
  6844. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6845. _Example_
  6846. \code
  6847. none
  6848. \endcode
  6849. \sa wolfSSL_GetBulkCipher
  6850. \sa wolfSSL_GetHmacSize
  6851. */
  6852. int wolfSSL_GetHmacType(WOLFSSL*);
  6853. /*!
  6854. \brief Allows caller to determine the negotiated cipher type
  6855. from the handshake.
  6856. \return If successful the call will return one of the following:
  6857. WOLFSSL_BLOCK_TYPE, WOLFSSL_STREAM_TYPE, WOLFSSL_AEAD_TYPE.
  6858. \return BAD_FUNC_ARG will be returned for an error state.
  6859. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6860. _Example_
  6861. \code
  6862. none
  6863. \endcode
  6864. \sa wolfSSL_GetBulkCipher
  6865. \sa wolfSSL_GetHmacType
  6866. */
  6867. int wolfSSL_GetCipherType(WOLFSSL*);
  6868. /*!
  6869. \brief Allows caller to set the Hmac Inner vector for message
  6870. sending/receiving. The result is written to inner which should
  6871. be at least wolfSSL_GetHmacSize() bytes. The size of the message
  6872. is specified by sz, content is the type of message, and verify
  6873. specifies whether this is a verification of a peer message. Valid
  6874. for cipher types excluding WOLFSSL_AEAD_TYPE.
  6875. \return 1 upon success.
  6876. \return BAD_FUNC_ARG will be returned for an error state.
  6877. \param none No parameters.
  6878. _Example_
  6879. \code
  6880. none
  6881. \endcode
  6882. \sa wolfSSL_GetBulkCipher
  6883. \sa wolfSSL_GetHmacType
  6884. */
  6885. int wolfSSL_SetTlsHmacInner(WOLFSSL* ssl, byte* inner,
  6886. word32 sz, int content, int verify);
  6887. /*!
  6888. \brief Allows caller to set the Public Key Callback for ECC Signing.
  6889. The callback should return 0 for success or < 0 for an error.
  6890. The ssl and ctx pointers are available for the user’s convenience.
  6891. in is the input buffer to sign while inSz denotes the length of the input.
  6892. out is the output buffer where the result of the signature should be stored.
  6893. outSz is an input/output variable that specifies the size of the output
  6894. buffer upon invocation and the actual size of the signature should be stored
  6895. there before returning. keyDer is the ECC Private key in ASN1 format and
  6896. keySz is the length of the key in bytes. An example callback can be found
  6897. wolfssl/test.h myEccSign().
  6898. \return none No returns.
  6899. \param none No parameters.
  6900. _Example_
  6901. \code
  6902. none
  6903. \endcode
  6904. \sa wolfSSL_SetEccSignCtx
  6905. \sa wolfSSL_GetEccSignCtx
  6906. */
  6907. void wolfSSL_CTX_SetEccSignCb(WOLFSSL_CTX* ctx, CallbackEccSign cb);
  6908. /*!
  6909. \brief Allows caller to set the Public Key Ecc Signing Callback
  6910. Context to ctx.
  6911. \return none No returns.
  6912. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6913. \param ctx a pointer to the user context to be stored
  6914. _Example_
  6915. \code
  6916. none
  6917. \endcode
  6918. \sa wolfSSL_CTX_SetEccSignCb
  6919. \sa wolfSSL_GetEccSignCtx
  6920. */
  6921. void wolfSSL_SetEccSignCtx(WOLFSSL* ssl, void *ctx);
  6922. /*!
  6923. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  6924. Context previously stored with wolfSSL_SetEccSignCtx().
  6925. \return pointer If successful the call will return a valid pointer
  6926. to the context.
  6927. \return NULL will be returned for a blank context.
  6928. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6929. _Example_
  6930. \code
  6931. none
  6932. \endcode
  6933. \sa wolfSSL_CTX_SetEccSignCb
  6934. \sa wolfSSL_SetEccSignCtx
  6935. */
  6936. void* wolfSSL_GetEccSignCtx(WOLFSSL* ssl);
  6937. /*!
  6938. \brief Allows caller to set the Public Key Ecc Signing Callback
  6939. Context to ctx.
  6940. \return none No returns.
  6941. \param ctx a pointer to a WOLFSSL_CTX structure, created
  6942. with wolfSSL_CTX_new().
  6943. \param ctx a pointer to the user context to be stored
  6944. _Example_
  6945. \code
  6946. none
  6947. \endcode
  6948. \sa wolfSSL_CTX_SetEccSignCb
  6949. \sa wolfSSL_CTX_GetEccSignCtx
  6950. */
  6951. void wolfSSL_CTX_SetEccSignCtx(WOLFSSL_CTX* ctx, void *userCtx);
  6952. /*!
  6953. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  6954. Context previously stored with wolfSSL_SetEccSignCtx().
  6955. \return pointer If successful the call will return a valid pointer
  6956. to the context.
  6957. \return NULL will be returned for a blank context.
  6958. \param ctx a pointer to a WOLFSSL_CTX structure, created
  6959. with wolfSSL_CTX_new().
  6960. _Example_
  6961. \code
  6962. none
  6963. \endcode
  6964. \sa wolfSSL_CTX_SetEccSignCb
  6965. \sa wolfSSL_CTX_SetEccSignCtx
  6966. */
  6967. void* wolfSSL_CTX_GetEccSignCtx(WOLFSSL_CTX* ctx);
  6968. /*!
  6969. \brief Allows caller to set the Public Key Callback for ECC Verification.
  6970. The callback should return 0 for success or < 0 for an error.
  6971. The ssl and ctx pointers are available for the user’s convenience.
  6972. sig is the signature to verify and sigSz denotes the length of the
  6973. signature. hash is an input buffer containing the digest of the message
  6974. and hashSz denotes the length in bytes of the hash. result is an output
  6975. variable where the result of the verification should be stored, 1 for
  6976. success and 0 for failure. keyDer is the ECC Private key in ASN1
  6977. format and keySz is the length of the key in bytes. An example
  6978. callback can be found wolfssl/test.h myEccVerify().
  6979. \return none No returns.
  6980. \param none No parameters.
  6981. _Example_
  6982. \code
  6983. none
  6984. \endcode
  6985. \sa wolfSSL_SetEccVerifyCtx
  6986. \sa wolfSSL_GetEccVerifyCtx
  6987. */
  6988. void wolfSSL_CTX_SetEccVerifyCb(WOLFSSL_CTX* ctx, CallbackEccVerify cb);
  6989. /*!
  6990. \brief Allows caller to set the Public Key Ecc Verification Callback
  6991. Context to ctx.
  6992. \return none No returns.
  6993. \param none No parameters.
  6994. _Example_
  6995. \code
  6996. none
  6997. \endcode
  6998. \sa wolfSSL_CTX_SetEccVerifyCb
  6999. \sa wolfSSL_GetEccVerifyCtx
  7000. */
  7001. void wolfSSL_SetEccVerifyCtx(WOLFSSL* ssl, void *ctx);
  7002. /*!
  7003. \brief Allows caller to retrieve the Public Key Ecc Verification Callback
  7004. Context previously stored with wolfSSL_SetEccVerifyCtx().
  7005. \return pointer If successful the call will return a valid pointer to the
  7006. context.
  7007. \return NULL will be returned for a blank context.
  7008. \param none No parameters.
  7009. _Example_
  7010. \code
  7011. none
  7012. \endcode
  7013. \sa wolfSSL_CTX_SetEccVerifyCb
  7014. \sa wolfSSL_SetEccVerifyCtx
  7015. */
  7016. void* wolfSSL_GetEccVerifyCtx(WOLFSSL* ssl);
  7017. /*!
  7018. \brief Allows caller to set the Public Key Callback for RSA Signing.
  7019. The callback should return 0 for success or < 0 for an error.
  7020. The ssl and ctx pointers are available for the user’s convenience.
  7021. in is the input buffer to sign while inSz denotes the length of the input.
  7022. out is the output buffer where the result of the signature should be stored.
  7023. outSz is an input/output variable that specifies the size of the output
  7024. buffer upon invocation and the actual size of the signature should be
  7025. stored there before returning. keyDer is the RSA Private key in ASN1 format
  7026. and keySz is the length of the key in bytes. An example callback can be
  7027. found wolfssl/test.h myRsaSign().
  7028. \return none No returns.
  7029. \param none No parameters.
  7030. _Example_
  7031. \code
  7032. none
  7033. \endcode
  7034. \sa wolfSSL_SetRsaSignCtx
  7035. \sa wolfSSL_GetRsaSignCtx
  7036. */
  7037. void wolfSSL_CTX_SetRsaSignCb(WOLFSSL_CTX* ctx, CallbackRsaSign cb);
  7038. /*!
  7039. \brief Allows caller to set the Public Key RSA Signing Callback Context
  7040. to ctx.
  7041. \return none No Returns.
  7042. \param none No parameters.
  7043. _Example_
  7044. \code
  7045. none
  7046. \endcode
  7047. \sa wolfSSL_CTX_SetRsaSignCb
  7048. \sa wolfSSL_GetRsaSignCtx
  7049. */
  7050. void wolfSSL_SetRsaSignCtx(WOLFSSL* ssl, void *ctx);
  7051. /*!
  7052. \brief Allows caller to retrieve the Public Key RSA Signing Callback
  7053. Context previously stored with wolfSSL_SetRsaSignCtx().
  7054. \return pointer If successful the call will return a valid pointer to the
  7055. context.
  7056. \return NULL will be returned for a blank context.
  7057. \param none No parameters.
  7058. \param none No parameters.
  7059. _Example_
  7060. \code
  7061. none
  7062. \endcode
  7063. \sa wolfSSL_CTX_SetRsaSignCb
  7064. \sa wolfSSL_SetRsaSignCtx
  7065. */
  7066. void* wolfSSL_GetRsaSignCtx(WOLFSSL* ssl);
  7067. /*!
  7068. \brief Allows caller to set the Public Key Callback for RSA Verification.
  7069. The callback should return the number of plaintext bytes for success or
  7070. < 0 for an error. The ssl and ctx pointers are available for the user’s
  7071. convenience. sig is the signature to verify and sigSz denotes the length
  7072. of the signature. out should be set to the beginning of the verification
  7073. buffer after the decryption process and any padding. keyDer is the RSA
  7074. Public key in ASN1 format and keySz is the length of the key in bytes.
  7075. An example callback can be found wolfssl/test.h myRsaVerify().
  7076. \return none No returns.
  7077. \param none No parameters.
  7078. \sa wolfSSL_SetRsaVerifyCtx
  7079. \sa wolfSSL_GetRsaVerifyCtx
  7080. */
  7081. void wolfSSL_CTX_SetRsaVerifyCb(WOLFSSL_CTX* ctx, CallbackRsaVerify cb);
  7082. /*!
  7083. \brief Allows caller to set the Public Key RSA Verification Callback
  7084. Context to ctx.
  7085. \return none No returns.
  7086. \param none No parameters.
  7087. _Example_
  7088. \code
  7089. none
  7090. \endcode
  7091. \sa wolfSSL_CTX_SetRsaVerifyCb
  7092. \sa wolfSSL_GetRsaVerifyCtx
  7093. */
  7094. void wolfSSL_SetRsaVerifyCtx(WOLFSSL* ssl, void *ctx);
  7095. /*!
  7096. \brief Allows caller to retrieve the Public Key RSA Verification Callback
  7097. Context previously stored with wolfSSL_SetRsaVerifyCtx().
  7098. \return pointer If successful the call will return a valid pointer to
  7099. the context.
  7100. \return NULL will be returned for a blank context.
  7101. \param none No parameters.
  7102. _Example_
  7103. \code
  7104. none
  7105. \endcode
  7106. \sa wolfSSL_CTX_SetRsaVerifyCb
  7107. \sa wolfSSL_SetRsaVerifyCtx
  7108. */
  7109. void* wolfSSL_GetRsaVerifyCtx(WOLFSSL* ssl);
  7110. /*!
  7111. \brief Allows caller to set the Public Key Callback for RSA Public
  7112. Encrypt. The callback should return 0 for success or < 0 for an error.
  7113. The ssl and ctx pointers are available for the user’s convenience.
  7114. in is the input buffer to encrypt while inSz denotes the length of
  7115. the input. out is the output buffer where the result of the encryption
  7116. should be stored. outSz is an input/output variable that specifies
  7117. the size of the output buffer upon invocation and the actual size of
  7118. the encryption should be stored there before returning. keyDer is the
  7119. RSA Public key in ASN1 format and keySz is the length of the key in
  7120. bytes. An example callback can be found wolfssl/test.h myRsaEnc().
  7121. \return none No returns.
  7122. \param none No parameters.
  7123. _Examples_
  7124. \code
  7125. none
  7126. \endcode
  7127. \sa wolfSSL_SetRsaEncCtx
  7128. \sa wolfSSL_GetRsaEncCtx
  7129. */
  7130. void wolfSSL_CTX_SetRsaEncCb(WOLFSSL_CTX* ctx, CallbackRsaEnc cb);
  7131. /*!
  7132. \brief Allows caller to set the Public Key RSA Public Encrypt
  7133. Callback Context to ctx.
  7134. \return none No returns.
  7135. \param none No parameters.
  7136. _Example_
  7137. \code
  7138. none
  7139. \endcode
  7140. \sa wolfSSL_CTX_SetRsaEncCb
  7141. \sa wolfSSL_GetRsaEncCtx
  7142. */
  7143. void wolfSSL_SetRsaEncCtx(WOLFSSL* ssl, void *ctx);
  7144. /*!
  7145. \brief Allows caller to retrieve the Public Key RSA Public Encrypt
  7146. Callback Context previously stored with wolfSSL_SetRsaEncCtx().
  7147. \return pointer If successful the call will return a valid pointer
  7148. to the context.
  7149. \return NULL will be returned for a blank context.
  7150. \param none No parameters.
  7151. _Example_
  7152. \code
  7153. none
  7154. \endcode
  7155. \sa wolfSSL_CTX_SetRsaEncCb
  7156. \sa wolfSSL_SetRsaEncCtx
  7157. */
  7158. void* wolfSSL_GetRsaEncCtx(WOLFSSL* ssl);
  7159. /*!
  7160. \brief Allows caller to set the Public Key Callback for RSA Private
  7161. Decrypt. The callback should return the number of plaintext bytes
  7162. for success or < 0 for an error. The ssl and ctx pointers are available
  7163. for the user’s convenience. in is the input buffer to decrypt and inSz
  7164. denotes the length of the input. out should be set to the beginning
  7165. of the decryption buffer after the decryption process and any padding.
  7166. keyDer is the RSA Private key in ASN1 format and keySz is the length
  7167. of the key in bytes. An example callback can be found
  7168. wolfssl/test.h myRsaDec().
  7169. \return none No returns.
  7170. \param none No parameters.
  7171. _Example_
  7172. \code
  7173. none
  7174. \endcode
  7175. \sa wolfSSL_SetRsaDecCtx
  7176. \sa wolfSSL_GetRsaDecCtx
  7177. */
  7178. void wolfSSL_CTX_SetRsaDecCb(WOLFSSL_CTX* ctx, CallbackRsaDec cb);
  7179. /*!
  7180. \brief Allows caller to set the Public Key RSA Private Decrypt
  7181. Callback Context to ctx.
  7182. \return none No returns.
  7183. \param none No parameters.
  7184. _Example_
  7185. \code
  7186. none
  7187. \endcode
  7188. \sa wolfSSL_CTX_SetRsaDecCb
  7189. \sa wolfSSL_GetRsaDecCtx
  7190. */
  7191. void wolfSSL_SetRsaDecCtx(WOLFSSL* ssl, void *ctx);
  7192. /*!
  7193. \brief Allows caller to retrieve the Public Key RSA Private Decrypt
  7194. Callback Context previously stored with wolfSSL_SetRsaDecCtx().
  7195. \return pointer If successful the call will return a valid pointer
  7196. to the context.
  7197. \return NULL will be returned for a blank context.
  7198. \param none No parameters.
  7199. _Example_
  7200. \code
  7201. none
  7202. \endcode
  7203. \sa wolfSSL_CTX_SetRsaDecCb
  7204. \sa wolfSSL_SetRsaDecCtx
  7205. */
  7206. void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl);
  7207. /*!
  7208. \brief This function registers a callback with the SSL context
  7209. (WOLFSSL_CTX) to be called when a new CA certificate is loaded
  7210. into wolfSSL. The callback is given a buffer with the DER-encoded
  7211. certificate.
  7212. \return none No return.
  7213. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  7214. \param callback function to be registered as the CA callback for the
  7215. wolfSSL context, ctx. The signature of this function must follow that
  7216. as shown above in the Synopsis section.
  7217. _Example_
  7218. \code
  7219. WOLFSSL_CTX* ctx = 0;
  7220. // CA callback prototype
  7221. int MyCACallback(unsigned char *der, int sz, int type);
  7222. // Register the custom CA callback with the SSL context
  7223. wolfSSL_CTX_SetCACb(ctx, MyCACallback);
  7224. int MyCACallback(unsigned char* der, int sz, int type)
  7225. {
  7226. // custom CA callback function, DER-encoded cert
  7227. // located in “der” of size “sz” with type “type”
  7228. }
  7229. \endcode
  7230. \sa wolfSSL_CTX_load_verify_locations
  7231. */
  7232. void wolfSSL_CTX_SetCACb(WOLFSSL_CTX* ctx, CallbackCACache cb);
  7233. /*!
  7234. \ingroup CertManager
  7235. \brief Allocates and initializes a new Certificate Manager context.
  7236. This context may be used independent of SSL needs. It may be used to
  7237. load certificates, verify certificates, and check the revocation status.
  7238. \return WOLFSSL_CERT_MANAGER If successful the call will return a valid
  7239. WOLFSSL_CERT_MANAGER pointer.
  7240. \return NULL will be returned for an error state.
  7241. \param none No parameters.
  7242. \sa wolfSSL_CertManagerFree
  7243. */
  7244. WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew_ex(void* heap);
  7245. /*!
  7246. \ingroup CertManager
  7247. \brief Allocates and initializes a new Certificate Manager context.
  7248. This context may be used independent of SSL needs. It may be used to
  7249. load certificates, verify certificates, and check the revocation status.
  7250. \return WOLFSSL_CERT_MANAGER If successful the call will return a
  7251. valid WOLFSSL_CERT_MANAGER pointer.
  7252. \return NULL will be returned for an error state.
  7253. \param none No parameters.
  7254. _Example_
  7255. \code
  7256. #import <wolfssl/ssl.h>
  7257. WOLFSSL_CERT_MANAGER* cm;
  7258. cm = wolfSSL_CertManagerNew();
  7259. if (cm == NULL) {
  7260. // error creating new cert manager
  7261. }
  7262. \endcode
  7263. \sa wolfSSL_CertManagerFree
  7264. */
  7265. WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew(void);
  7266. /*!
  7267. \ingroup CertManager
  7268. \brief Frees all resources associated with the Certificate Manager
  7269. context. Call this when you no longer need to use the Certificate Manager.
  7270. \return none
  7271. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7272. wolfSSL_CertManagerNew().
  7273. _Example_
  7274. \code
  7275. #include <wolfssl/ssl.h>
  7276. WOLFSSL_CERT_MANAGER* cm;
  7277. ...
  7278. wolfSSL_CertManagerFree(cm);
  7279. \endcode
  7280. \sa wolfSSL_CertManagerNew
  7281. */
  7282. void wolfSSL_CertManagerFree(WOLFSSL_CERT_MANAGER*);
  7283. /*!
  7284. \ingroup CertManager
  7285. \brief Specifies the locations for CA certificate loading into the
  7286. manager context. The PEM certificate CAfile may contain several
  7287. trusted CA certificates. If CApath is not NULL it specifies a
  7288. directory containing CA certificates in PEM format.
  7289. \return SSL_SUCCESS If successful the call will return.
  7290. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7291. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  7292. can’t be read, or is corrupted.
  7293. \return MEMORY_E will be returned if an out of memory condition occurs.
  7294. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7295. \return BAD_FUNC_ARG is the error that will be returned if a
  7296. pointer is not provided.
  7297. \return SSL_FATAL_ERROR - will be returned upon failure.
  7298. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created
  7299. using wolfSSL_CertManagerNew().
  7300. \param file pointer to the name of the file containing CA
  7301. certificates to load.
  7302. \param path pointer to the name of a directory path containing CA c
  7303. ertificates to load. The NULL pointer may be used if no
  7304. certificate directory is desired.
  7305. _Example_
  7306. \code
  7307. #include <wolfssl/ssl.h>
  7308. int ret = 0;
  7309. WOLFSSL_CERT_MANAGER* cm;
  7310. ...
  7311. ret = wolfSSL_CertManagerLoadCA(cm, “path/to/cert-file.pem”, 0);
  7312. if (ret != SSL_SUCCESS) {
  7313. // error loading CA certs into cert manager
  7314. }
  7315. \endcode
  7316. \sa wolfSSL_CertManagerVerify
  7317. */
  7318. int wolfSSL_CertManagerLoadCA(WOLFSSL_CERT_MANAGER* cm, const char* f,
  7319. const char* d);
  7320. /*!
  7321. \ingroup CertManager
  7322. \brief Loads the CA Buffer by calling wolfSSL_CTX_load_verify_buffer and
  7323. returning that result using a temporary cm so as not to lose the information
  7324. in the cm passed into the function.
  7325. \return SSL_FATAL_ERROR is returned if the WOLFSSL_CERT_MANAGER struct is
  7326. NULL or if wolfSSL_CTX_new() returns NULL.
  7327. \return SSL_SUCCESS is returned for a successful execution.
  7328. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7329. wolfSSL_CertManagerNew().
  7330. \param in buffer for cert information.
  7331. \param sz length of the buffer.
  7332. \param format certificate format, either PEM or DER.
  7333. _Example_
  7334. \code
  7335. WOLFSSL_CERT_MANAGER* cm = (WOLFSSL_CERT_MANAGER*)vp;
  7336. const unsigned char* in;
  7337. long sz;
  7338. int format;
  7339. if(wolfSSL_CertManagerLoadCABuffer(vp, sz, format) != SSL_SUCCESS){
  7340. Error returned. Failure case code block.
  7341. }
  7342. \endcode
  7343. \sa wolfSSL_CTX_load_verify_buffer
  7344. \sa ProcessChainBuffer
  7345. \sa ProcessBuffer
  7346. \sa cm_pick_method
  7347. */
  7348. int wolfSSL_CertManagerLoadCABuffer(WOLFSSL_CERT_MANAGER* cm,
  7349. const unsigned char* in, long sz, int format);
  7350. /*!
  7351. \ingroup CertManager
  7352. \brief This function unloads the CA signer list.
  7353. \return SSL_SUCCESS returned on successful execution of the function.
  7354. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7355. \return BAD_MUTEX_E returned if there was a mutex error.
  7356. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure,
  7357. created using wolfSSL_CertManagerNew().
  7358. _Example_
  7359. \code
  7360. #include <wolfssl/ssl.h>
  7361. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7362. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7363. ...
  7364. if(wolfSSL_CertManagerUnloadCAs(ctx->cm) != SSL_SUCCESS){
  7365. Failure case.
  7366. }
  7367. \endcode
  7368. \sa FreeSignerTable
  7369. \sa UnlockMutex
  7370. */
  7371. int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm);
  7372. /*!
  7373. \ingroup CertManager
  7374. \brief The function will free the Trusted Peer linked list and unlocks
  7375. the trusted peer list.
  7376. \return SSL_SUCCESS if the function completed normally.
  7377. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7378. \return BAD_MUTEX_E mutex error if tpLock, a member of the
  7379. WOLFSSL_CERT_MANAGER struct, is 0 (nill).
  7380. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7381. wolfSSL_CertManagerNew().
  7382. _Example_
  7383. \code
  7384. #include <wolfssl/ssl.h>
  7385. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7386. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7387. ...
  7388. if(wolfSSL_CertManagerUnload_trust_peers(cm) != SSL_SUCCESS){
  7389. The function did not execute successfully.
  7390. }
  7391. \endcode
  7392. \sa UnLockMutex
  7393. */
  7394. int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm);
  7395. /*!
  7396. \ingroup CertManager
  7397. \brief Specifies the certificate to verify with the Certificate Manager
  7398. context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7399. \return SSL_SUCCESS If successful.
  7400. \return ASN_SIG_CONFIRM_E will be returned if the signature could not be
  7401. verified.
  7402. \return ASN_SIG_OID_E will be returned if the signature type is not
  7403. supported.
  7404. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7405. has been revoked.
  7406. \return CRL_MISSING is an error that is returned if a current issuer CRL is
  7407. not available.
  7408. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  7409. before date.
  7410. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  7411. after date.
  7412. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7413. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  7414. read, or is corrupted.
  7415. \return MEMORY_E will be returned if an out of memory condition occurs.
  7416. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7417. \return BAD_FUNC_ARG is the error that will be returned if a pointer is
  7418. not provided.
  7419. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7420. wolfSSL_CertManagerNew().
  7421. \param fname pointer to the name of the file containing the certificates
  7422. to verify.
  7423. \param format format of the certificate to verify - either
  7424. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7425. _Example_
  7426. \code
  7427. int ret = 0;
  7428. WOLFSSL_CERT_MANAGER* cm;
  7429. ...
  7430. ret = wolfSSL_CertManagerVerify(cm, “path/to/cert-file.pem”,
  7431. SSL_FILETYPE_PEM);
  7432. if (ret != SSL_SUCCESS) {
  7433. error verifying certificate
  7434. }
  7435. \endcode
  7436. \sa wolfSSL_CertManagerLoadCA
  7437. \sa wolfSSL_CertManagerVerifyBuffer
  7438. */
  7439. int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER* cm, const char* f,
  7440. int format);
  7441. /*!
  7442. \ingroup CertManager
  7443. \brief Specifies the certificate buffer to verify with the Certificate
  7444. Manager context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7445. \return SSL_SUCCESS If successful.
  7446. \return ASN_SIG_CONFIRM_E will be returned if the signature could not
  7447. be verified.
  7448. \return ASN_SIG_OID_E will be returned if the signature type is not
  7449. supported.
  7450. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7451. has been revoked.
  7452. \return CRL_MISSING is an error that is returned if a current issuer CRL
  7453. is not available.
  7454. \return ASN_BEFORE_DATE_E will be returned if the current date is before
  7455. the before date.
  7456. \return ASN_AFTER_DATE_E will be returned if the current date is after
  7457. the after date.
  7458. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7459. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  7460. be read, or is corrupted.
  7461. \return MEMORY_E will be returned if an out of memory condition occurs.
  7462. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7463. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7464. is not provided.
  7465. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7466. wolfSSL_CertManagerNew().
  7467. \param buff buffer containing the certificates to verify.
  7468. \param sz size of the buffer, buf.
  7469. \param format format of the certificate to verify, located in buf - either
  7470. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7471. _Example_
  7472. \code
  7473. #include <wolfssl/ssl.h>
  7474. int ret = 0;
  7475. int sz = 0;
  7476. WOLFSSL_CERT_MANAGER* cm;
  7477. byte certBuff[...];
  7478. ...
  7479. ret = wolfSSL_CertManagerVerifyBuffer(cm, certBuff, sz, SSL_FILETYPE_PEM);
  7480. if (ret != SSL_SUCCESS) {
  7481. error verifying certificate
  7482. }
  7483. \endcode
  7484. \sa wolfSSL_CertManagerLoadCA
  7485. \sa wolfSSL_CertManagerVerify
  7486. */
  7487. int wolfSSL_CertManagerVerifyBuffer(WOLFSSL_CERT_MANAGER* cm,
  7488. const unsigned char* buff, long sz, int format);
  7489. /*!
  7490. \ingroup CertManager
  7491. \brief The function sets the verifyCallback function in the Certificate
  7492. Manager. If present, it will be called for each cert loaded. If there is
  7493. a verification error, the verify callback can be used to over-ride the
  7494. error.
  7495. \return none No return.
  7496. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7497. wolfSSL_CertManagerNew().
  7498. \param vc a VerifyCallback function pointer to the callback routine
  7499. _Example_
  7500. \code
  7501. #include <wolfssl/ssl.h>
  7502. int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store)
  7503. { // do custom verification of certificate }
  7504. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7505. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7506. ...
  7507. wolfSSL_CertManagerSetVerify(cm, myVerify);
  7508. \endcode
  7509. \sa wolfSSL_CertManagerVerify
  7510. */
  7511. void wolfSSL_CertManagerSetVerify(WOLFSSL_CERT_MANAGER* cm,
  7512. VerifyCallback vc);
  7513. /*!
  7514. \brief Check CRL if the option is enabled and compares the cert to the
  7515. CRL list.
  7516. \return SSL_SUCCESS returns if the function returned as expected. If
  7517. the crlEnabled member of the WOLFSSL_CERT_MANAGER struct is turned on.
  7518. \return MEMORY_E returns if the allocated memory failed.
  7519. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7520. \param cm a pointer to a WOLFSSL_CERT_MANAGER struct.
  7521. \param der pointer to a DER formatted certificate.
  7522. \param sz size of the certificate.
  7523. _Example_
  7524. \code
  7525. WOLFSSL_CERT_MANAGER* cm;
  7526. byte* der;
  7527. int sz; // size of der
  7528. ...
  7529. if(wolfSSL_CertManagerCheckCRL(cm, der, sz) != SSL_SUCCESS){
  7530. // Error returned. Deal with failure case.
  7531. }
  7532. \endcode
  7533. \sa CheckCertCRL
  7534. \sa ParseCertRelative
  7535. \sa wolfSSL_CertManagerSetCRL_CB
  7536. \sa InitDecodedCert
  7537. */
  7538. int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
  7539. unsigned char* der, int sz);
  7540. /*!
  7541. \ingroup CertManager
  7542. \brief Turns on Certificate Revocation List checking when verifying
  7543. certificates with the Certificate Manager. By default, CRL checking
  7544. is off. options include WOLFSSL_CRL_CHECKALL which performs CRL
  7545. checking on each certificate in the chain versus the Leaf certificate
  7546. only which is the default.
  7547. \return SSL_SUCCESS If successful the call will return.
  7548. \return NOT_COMPILED_IN will be returned if wolfSSL was not built with
  7549. CRL enabled.
  7550. \return MEMORY_E will be returned if an out of memory condition occurs.
  7551. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7552. is not provided.
  7553. \return SSL_FAILURE will be returned if the CRL context cannot be
  7554. initialized properly.
  7555. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7556. wolfSSL_CertManagerNew().
  7557. \param options options to use when enabling the Certification Manager, cm.
  7558. _Example_
  7559. \code
  7560. #include <wolfssl/ssl.h>
  7561. int ret = 0;
  7562. WOLFSSL_CERT_MANAGER* cm;
  7563. ...
  7564. ret = wolfSSL_CertManagerEnableCRL(cm, 0);
  7565. if (ret != SSL_SUCCESS) {
  7566. error enabling cert manager
  7567. }
  7568. ...
  7569. \endcode
  7570. \sa wolfSSL_CertManagerDisableCRL
  7571. */
  7572. int wolfSSL_CertManagerEnableCRL(WOLFSSL_CERT_MANAGER* cm,
  7573. int options);
  7574. /*!
  7575. \ingroup CertManager
  7576. \brief Turns off Certificate Revocation List checking when verifying
  7577. certificates with the Certificate Manager. By default, CRL checking is
  7578. off. You can use this function to temporarily or permanently disable CRL
  7579. checking with this Certificate Manager context that previously had CRL
  7580. checking enabled.
  7581. \return SSL_SUCCESS If successful the call will return.
  7582. \return BAD_FUNC_ARG is the error that will be returned if a function
  7583. pointer is not provided.
  7584. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7585. wolfSSL_CertManagerNew().
  7586. _Example_
  7587. \code
  7588. #include <wolfssl/ssl.h>
  7589. int ret = 0;
  7590. WOLFSSL_CERT_MANAGER* cm;
  7591. ...
  7592. ret = wolfSSL_CertManagerDisableCRL(cm);
  7593. if (ret != SSL_SUCCESS) {
  7594. error disabling cert manager
  7595. }
  7596. ...
  7597. \endcode
  7598. \sa wolfSSL_CertManagerEnableCRL
  7599. */
  7600. int wolfSSL_CertManagerDisableCRL(WOLFSSL_CERT_MANAGER*);
  7601. /*!
  7602. \ingroup CertManager
  7603. \brief Error checks and passes through to LoadCRL() in order to load the
  7604. cert into the CRL for revocation checking.
  7605. \return SSL_SUCCESS if there is no error in wolfSSL_CertManagerLoadCRL and
  7606. if LoadCRL returns successfully.
  7607. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER struct is NULL.
  7608. \return SSL_FATAL_ERROR if wolfSSL_CertManagerEnableCRL returns anything
  7609. other than SSL_SUCCESS.
  7610. \return BAD_PATH_ERROR if the path is NULL.
  7611. \return MEMORY_E if LoadCRL fails to allocate heap memory.
  7612. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7613. wolfSSL_CertManagerNew().
  7614. \param path a constant char pointer holding the CRL path.
  7615. \param type type of certificate to be loaded.
  7616. \param monitor requests monitoring in LoadCRL().
  7617. _Example_
  7618. \code
  7619. #include <wolfssl/ssl.h>
  7620. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type,
  7621. int monitor);
  7622. wolfSSL_CertManagerLoadCRL(SSL_CM(ssl), path, type, monitor);
  7623. \endcode
  7624. \sa wolfSSL_CertManagerEnableCRL
  7625. \sa wolfSSL_LoadCRL
  7626. */
  7627. int wolfSSL_CertManagerLoadCRL(WOLFSSL_CERT_MANAGER* cm,
  7628. const char* path, int type, int monitor);
  7629. /*!
  7630. \ingroup CertManager
  7631. \brief The function loads the CRL file by calling BufferLoadCRL.
  7632. \return SSL_SUCCESS returned if the function completed without errors.
  7633. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7634. \return SSL_FATAL_ERROR returned if there is an error associated
  7635. with the WOLFSSL_CERT_MANAGER.
  7636. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  7637. \param buff a constant byte type and is the buffer.
  7638. \param sz a long int representing the size of the buffer.
  7639. \param type a long integer that holds the certificate type.
  7640. _Example_
  7641. \code
  7642. #include <wolfssl/ssl.h>
  7643. WOLFSSL_CERT_MANAGER* cm;
  7644. const unsigned char* buff;
  7645. long sz; size of buffer
  7646. int type; cert type
  7647. ...
  7648. int ret = wolfSSL_CertManagerLoadCRLBuffer(cm, buff, sz, type);
  7649. if(ret == SSL_SUCCESS){
  7650. return ret;
  7651. } else {
  7652. Failure case.
  7653. }
  7654. \endcode
  7655. \sa BufferLoadCRL
  7656. \sa wolfSSL_CertManagerEnableCRL
  7657. */
  7658. int wolfSSL_CertManagerLoadCRLBuffer(WOLFSSL_CERT_MANAGER* cm,
  7659. const unsigned char* buff, long sz,
  7660. int type);
  7661. /*!
  7662. \ingroup CertManager
  7663. \brief This function sets the CRL Certificate Manager callback. If
  7664. HAVE_CRL is defined and a matching CRL record is not found then the
  7665. cbMissingCRL is called (set via wolfSSL_CertManagerSetCRL_Cb). This
  7666. allows you to externally retrieve the CRL and load it.
  7667. \return SSL_SUCCESS returned upon successful execution of the function and
  7668. subroutines.
  7669. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  7670. \param cm the WOLFSSL_CERT_MANAGER structure holding the information for
  7671. the certificate.
  7672. \param cb a function pointer to (*CbMissingCRL) that is set to the
  7673. cbMissingCRL member of the WOLFSSL_CERT_MANAGER.
  7674. _Example_
  7675. \code
  7676. #include <wolfssl/ssl.h>
  7677. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7678. WOLFSSL* ssl = wolfSSL_new(ctx);
  7679. void cb(const char* url){
  7680. Function body.
  7681. }
  7682. CbMissingCRL cb = CbMissingCRL;
  7683. if(ctx){
  7684. return wolfSSL_CertManagerSetCRL_Cb(SSL_CM(ssl), cb);
  7685. }
  7686. \endcode
  7687. \sa CbMissingCRL
  7688. \sa wolfSSL_SetCRL_Cb
  7689. */
  7690. int wolfSSL_CertManagerSetCRL_Cb(WOLFSSL_CERT_MANAGER* cm,
  7691. CbMissingCRL cb);
  7692. /*!
  7693. \ingroup CertManager
  7694. \brief The function enables the WOLFSSL_CERT_MANAGER’s member, ocspEnabled
  7695. to signify that the OCSP check option is enabled.
  7696. \return SSL_SUCCESS returned on successful execution of the function. The
  7697. ocspEnabled member of the WOLFSSL_CERT_MANAGER is enabled.
  7698. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  7699. NULL or if an argument value that is not allowed is passed to a subroutine.
  7700. \return MEMORY_E returned if there is an error allocating memory within
  7701. this function or a subroutine.
  7702. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7703. wolfSSL_CertManagerNew().
  7704. \param der a byte pointer to the certificate.
  7705. \param sz an int type representing the size of the DER cert.
  7706. _Example_
  7707. \code
  7708. #import <wolfssl/ssl.h>
  7709. WOLFSSL* ssl = wolfSSL_new(ctx);
  7710. byte* der;
  7711. int sz; size of der
  7712. ...
  7713. if(wolfSSL_CertManagerCheckOCSP(cm, der, sz) != SSL_SUCCESS){
  7714. Failure case.
  7715. }
  7716. \endcode
  7717. \sa ParseCertRelative
  7718. \sa CheckCertOCSP
  7719. */
  7720. int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
  7721. unsigned char* der, int sz);
  7722. /*!
  7723. \ingroup CertManager
  7724. \brief Turns on OCSP if it’s turned off and if compiled with the
  7725. set option available.
  7726. \return SSL_SUCCESS returned if the function call is successful.
  7727. \return BAD_FUNC_ARG if cm struct is NULL.
  7728. \return MEMORY_E if WOLFSSL_OCSP struct value is NULL.
  7729. \return SSL_FAILURE initialization of WOLFSSL_OCSP struct fails
  7730. to initialize.
  7731. \return NOT_COMPILED_IN build not compiled with correct feature enabled.
  7732. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7733. wolfSSL_CertManagerNew().
  7734. \param options used to set values in WOLFSSL_CERT_MANAGER struct.
  7735. _Example_
  7736. \code
  7737. #include <wolfssl/ssl.h>
  7738. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7739. WOLFSSL* ssl = wolfSSL_new(ctx);
  7740. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7741. int options;
  7742. if(wolfSSL_CertManagerEnableOCSP(SSL_CM(ssl), options) != SSL_SUCCESS){
  7743. Failure case.
  7744. }
  7745. \endcode
  7746. \sa wolfSSL_CertManagerNew
  7747. */
  7748. int wolfSSL_CertManagerEnableOCSP(WOLFSSL_CERT_MANAGER* cm,
  7749. int options);
  7750. /*!
  7751. \ingroup CertManager
  7752. \brief Disables OCSP certificate revocation.
  7753. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled the
  7754. crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  7755. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  7756. \param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7757. _Example_
  7758. \code
  7759. #include <wolfssl/ssl.h>
  7760. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(method);
  7761. WOLFSSL* ssl = wolfSSL_new(ctx);
  7762. ...
  7763. if(wolfSSL_CertManagerDisableOCSP(ssl) != SSL_SUCCESS){
  7764. Fail case.
  7765. }
  7766. \endcode
  7767. \sa wolfSSL_DisableCRL
  7768. */
  7769. int wolfSSL_CertManagerDisableOCSP(WOLFSSL_CERT_MANAGER*);
  7770. /*!
  7771. \ingroup CertManager
  7772. \brief The function copies the url to the ocspOverrideURL member of the
  7773. WOLFSSL_CERT_MANAGER structure.
  7774. \return SSL_SUCCESS the function was able to execute as expected.
  7775. \return BAD_FUNC_ARG the WOLFSSL_CERT_MANAGER struct is NULL.
  7776. \return MEMEORY_E Memory was not able to be allocated for the
  7777. ocspOverrideURL member of the certificate manager.
  7778. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7779. _Example_
  7780. \code
  7781. #include <wolfssl/ssl.h>
  7782. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7783. const char* url;
  7784. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url)
  7785. if(wolfSSL_CertManagerSetOCSPOverrideURL(SSL_CM(ssl), url) != SSL_SUCCESS){
  7786. Failure case.
  7787. }
  7788. \endcode
  7789. \sa ocspOverrideURL
  7790. \sa wolfSSL_SetOCSP_OverrideURL
  7791. */
  7792. int wolfSSL_CertManagerSetOCSPOverrideURL(WOLFSSL_CERT_MANAGER* cm,
  7793. const char* url);
  7794. /*!
  7795. \ingroup CertManager
  7796. \brief The function sets the OCSP callback in the WOLFSSL_CERT_MANAGER.
  7797. \return SSL_SUCCESS returned on successful execution. The arguments are
  7798. saved in the WOLFSSL_CERT_MANAGER structure.
  7799. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7800. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  7801. \param ioCb a function pointer of type CbOCSPIO.
  7802. \param respFreeCb - a function pointer of type CbOCSPRespFree.
  7803. \param ioCbCtx - a void pointer variable to the I/O callback user
  7804. registered context.
  7805. _Example_
  7806. \code
  7807. #include <wolfssl/ssl.h>
  7808. wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb,
  7809. CbOCSPRespFree respFreeCb, void* ioCbCtx){
  7810. return wolfSSL_CertManagerSetOCSP_Cb(SSL_CM(ssl), ioCb, respFreeCb, ioCbCtx);
  7811. \endcode
  7812. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  7813. \sa wolfSSL_CertManagerCheckOCSP
  7814. \sa wolfSSL_CertManagerEnableOCSPStapling
  7815. \sa wolfSSL_ENableOCSP
  7816. \sa wolfSSL_DisableOCSP
  7817. \sa wolfSSL_SetOCSP_Cb
  7818. */
  7819. int wolfSSL_CertManagerSetOCSP_Cb(WOLFSSL_CERT_MANAGER* cm,
  7820. CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  7821. void* ioCbCtx);
  7822. /*!
  7823. \ingroup CertManager
  7824. \brief This function turns on OCSP stapling if it is not turned on as well
  7825. as set the options.
  7826. \return SSL_SUCCESS returned if there were no errors and the function
  7827. executed successfully.
  7828. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  7829. NULL or otherwise if there was a unpermitted argument value passed to
  7830. a subroutine.
  7831. \return MEMORY_E returned if there was an issue allocating memory.
  7832. \return SSL_FAILURE returned if the initialization of the OCSP
  7833. structure failed.
  7834. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  7835. HAVE_CERTIFICATE_STATUS_REQUEST option.
  7836. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, a member of the
  7837. WOLFSSL_CTX structure.
  7838. _Example_
  7839. \code
  7840. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX* ctx){
  7841. return wolfSSL_CertManagerEnableOCSPStapling(ctx->cm);
  7842. \endcode
  7843. \sa wolfSSL_CTX_EnableOCSPStapling
  7844. */
  7845. int wolfSSL_CertManagerEnableOCSPStapling(
  7846. WOLFSSL_CERT_MANAGER* cm);
  7847. /*!
  7848. \brief Enables CRL certificate revocation.
  7849. \return SSL_SUCCESS the function and subroutines returned with no errors.
  7850. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  7851. \return MEMORY_E returned if the allocation of memory failed.
  7852. \return SSL_FAILURE returned if the InitCRL function does not return
  7853. successfully.
  7854. \return NOT_COMPILED_IN HAVE_CRL was not enabled during the compiling.
  7855. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7856. \param options an integer that is used to determine the setting of
  7857. crlCheckAll member of the WOLFSSL_CERT_MANAGER structure.
  7858. _Example_
  7859. \code
  7860. WOLFSSL* ssl = wolfSSL_new(ctx);
  7861. if (wolfSSL_EnableCRL(ssl, WOLFSSL_CRL_CHECKALL) != SSL_SUCCESS){
  7862. // Failure case. SSL_SUCCESS was not returned by this function or
  7863. a subroutine
  7864. }
  7865. \endcode
  7866. \sa wolfSSL_CertManagerEnableCRL
  7867. \sa InitCRL
  7868. */
  7869. int wolfSSL_EnableCRL(WOLFSSL* ssl, int options);
  7870. /*!
  7871. \brief Disables CRL certificate revocation.
  7872. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled
  7873. the crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  7874. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  7875. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7876. _Example_
  7877. \code
  7878. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7879. WOLFSSL* ssl = wolfSSL_new(ctx);
  7880. ...
  7881. if(wolfSSL_DisableCRL(ssl) != SSL_SUCCESS){
  7882. // Failure case
  7883. }
  7884. \endcode
  7885. \sa wolfSSL_CertManagerDisableCRL
  7886. \sa wolfSSL_CertManagerDisableOCSP
  7887. */
  7888. int wolfSSL_DisableCRL(WOLFSSL* ssl);
  7889. /*!
  7890. \brief A wrapper function that ends up calling LoadCRL to load the
  7891. certificate for revocation checking.
  7892. \return WOLFSSL_SUCCESS returned if the function and all of the
  7893. subroutines executed without error.
  7894. \return SSL_FATAL_ERROR returned if one of the subroutines does not
  7895. return successfully.
  7896. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER or the WOLFSSL
  7897. structure are NULL.
  7898. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7899. \param path a constant character pointer that holds the path to the
  7900. crl file.
  7901. \param type an integer representing the type of certificate.
  7902. \param monitor an integer variable used to verify the monitor path if
  7903. requested.
  7904. _Example_
  7905. \code
  7906. WOLFSSL* ssl = wolfSSL_new(ctx);
  7907. const char* crlPemDir;
  7908. if(wolfSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, 0) != SSL_SUCCESS){
  7909. // Failure case. Did not return SSL_SUCCESS.
  7910. }
  7911. \endcode
  7912. \sa wolfSSL_CertManagerLoadCRL
  7913. \sa wolfSSL_CertManagerEnableCRL
  7914. \sa LoadCRL
  7915. */
  7916. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type, int monitor);
  7917. /*!
  7918. \brief Sets the CRL callback in the WOLFSSL_CERT_MANAGER structure.
  7919. \return SSL_SUCCESS returned if the function or subroutine executes
  7920. without error. The cbMissingCRL member of the WOLFSSL_CERT_MANAGER is set.
  7921. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  7922. structure is NULL.
  7923. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7924. \param cb a function pointer to CbMissingCRL.
  7925. _Example_
  7926. \code
  7927. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  7928. WOLFSSL* ssl = wolfSSL_new(ctx);
  7929. void cb(const char* url) // required signature
  7930. {
  7931. // Function body
  7932. }
  7933. int crlCb = wolfSSL_SetCRL_Cb(ssl, cb);
  7934. if(crlCb != SSL_SUCCESS){
  7935. // The callback was not set properly
  7936. }
  7937. \endcode
  7938. \sa CbMissingCRL
  7939. \sa wolfSSL_CertManagerSetCRL_Cb
  7940. */
  7941. int wolfSSL_SetCRL_Cb(WOLFSSL* ssl, CbMissingCRL cb);
  7942. /*!
  7943. \brief This function enables OCSP certificate verification.
  7944. \return SSL_SUCCESS returned if the function and subroutines executes
  7945. without errors.
  7946. \return BAD_FUNC_ARG returned if an argument in this function or any
  7947. subroutine receives an invalid argument value.
  7948. \return MEMORY_E returned if there was an error allocating memory for
  7949. a structure or other variable.
  7950. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with the
  7951. HAVE_OCSP option.
  7952. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7953. \param options an integer type passed to wolfSSL_CertMangerENableOCSP()
  7954. used for settings check.
  7955. _Example_
  7956. \code
  7957. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7958. WOLFSSL* ssl = wolfSSL_new(ctx);
  7959. int options; // initialize to option constant
  7960. int ret = wolfSSL_EnableOCSP(ssl, options);
  7961. if(ret != SSL_SUCCESS){
  7962. // OCSP is not enabled
  7963. }
  7964. \endcode
  7965. \sa wolfSSL_CertManagerEnableOCSP
  7966. */
  7967. int wolfSSL_EnableOCSP(WOLFSSL* ssl, int options);
  7968. /*!
  7969. \brief Disables the OCSP certificate revocation option.
  7970. \return SSL_SUCCESS returned if the function and its subroutine return with
  7971. no errors. The ocspEnabled member of the WOLFSSL_CERT_MANAGER structure was
  7972. successfully set.
  7973. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  7974. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7975. _Example_
  7976. \code
  7977. WOLFSSL* ssl = wolfSSL_new(ctx);
  7978. if(wolfSSL_DisableOCSP(ssl) != SSL_SUCCESS){
  7979. // Returned with an error. Failure case in this block.
  7980. }
  7981. \endcode
  7982. \sa wolfSSL_CertManagerDisableOCSP
  7983. */
  7984. int wolfSSL_DisableOCSP(WOLFSSL*);
  7985. /*!
  7986. \brief This function sets the ocspOverrideURL member in the
  7987. WOLFSSL_CERT_MANAGER structure.
  7988. \return SSL_SUCCESS returned on successful execution of the function.
  7989. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if a
  7990. unpermitted argument was passed to a subroutine.
  7991. \return MEMORY_E returned if there was an error allocating memory in the
  7992. subroutine.
  7993. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  7994. \param url a constant char pointer to the url that will be stored in the
  7995. ocspOverrideURL member of the WOLFSSL_CERT_MANAGER structure.
  7996. _Example_
  7997. \code
  7998. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  7999. WOLFSSL* ssl = wolfSSL_new(ctx);
  8000. char url[URLSZ];
  8001. ...
  8002. if(wolfSSL_SetOCSP_OverrideURL(ssl, url)){
  8003. // The override url is set to the new value
  8004. }
  8005. \endcode
  8006. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  8007. */
  8008. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url);
  8009. /*!
  8010. \brief This function sets the OCSP callback in the
  8011. WOLFSSL_CERT_MANAGER structure.
  8012. \return SSL_SUCCESS returned if the function executes without error.
  8013. The ocspIOCb, ocspRespFreeCb, and ocspIOCtx members of the CM are set.
  8014. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  8015. structures are NULL.
  8016. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8017. \param ioCb a function pointer to type CbOCSPIO.
  8018. \param respFreeCb a function pointer to type CbOCSPRespFree which is the
  8019. call to free the response memory.
  8020. \param ioCbCtx a void pointer that will be held in the ocspIOCtx member
  8021. of the CM.
  8022. _Example_
  8023. \code
  8024. WOLFSSL* ssl = wolfSSL_new(ctx);
  8025. int OCSPIO_CB(void* , const char*, int , unsigned char* , int,
  8026. unsigned char**){ // must have this signature
  8027. // Function Body
  8028. }
  8029. void OCSPRespFree_CB(void* , unsigned char* ){ // must have this signature
  8030. // function body
  8031. }
  8032. void* ioCbCtx;
  8033. CbOCSPRespFree CB_OCSPRespFree;
  8034. if(wolfSSL_SetOCSP_Cb(ssl, OCSPIO_CB( pass args ), CB_OCSPRespFree,
  8035. ioCbCtx) != SSL_SUCCESS){
  8036. // Callback not set
  8037. }
  8038. \endcode
  8039. \sa wolfSSL_CertManagerSetOCSP_Cb
  8040. \sa CbOCSPIO
  8041. \sa CbOCSPRespFree
  8042. */
  8043. int wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8044. void* ioCbCtx);
  8045. /*!
  8046. \brief Enables CRL certificate verification through the CTX.
  8047. \return SSL_SUCCESS returned if this function and it’s subroutines
  8048. execute without errors.
  8049. \return BAD_FUNC_ARG returned if the CTX struct is NULL or there
  8050. was otherwise an invalid argument passed in a subroutine.
  8051. \return MEMORY_E returned if there was an error allocating
  8052. memory during execution of the function.
  8053. \return SSL_FAILURE returned if the crl member of the
  8054. WOLFSSL_CERT_MANAGER fails to initialize correctly.
  8055. \return NOT_COMPILED_IN wolfSSL was not compiled with the HAVE_CRL option.
  8056. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8057. _Example_
  8058. \code
  8059. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8060. WOLFSSL* ssl = wolfSSL_new(ctx);
  8061. ...
  8062. if(wolfSSL_CTX_EnableCRL(ssl->ctx, options) != SSL_SUCCESS){
  8063. // The function failed
  8064. }
  8065. \endcode
  8066. \sa wolfSSL_CertManagerEnableCRL
  8067. \sa InitCRL
  8068. \sa wolfSSL_CTX_DisableCRL
  8069. */
  8070. int wolfSSL_CTX_EnableCRL(WOLFSSL_CTX* ctx, int options);
  8071. /*!
  8072. \brief This function disables CRL verification in the CTX structure.
  8073. \return SSL_SUCCESS returned if the function executes without error.
  8074. The crlEnabled member of the WOLFSSL_CERT_MANAGER struct is set to 0.
  8075. \return BAD_FUNC_ARG returned if either the CTX struct or the CM
  8076. struct has a NULL value.
  8077. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8078. wolfSSL_CTX_new().
  8079. _Example_
  8080. \code
  8081. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8082. WOLFSSL* ssl = wolfSSL_new(ctx);
  8083. ...
  8084. if(wolfSSL_CTX_DisableCRL(ssl->ctx) != SSL_SUCCESS){
  8085. // Failure case.
  8086. }
  8087. \endcode
  8088. \sa wolfSSL_CertManagerDisableCRL
  8089. */
  8090. int wolfSSL_CTX_DisableCRL(WOLFSSL_CTX* ctx);
  8091. /*!
  8092. \brief This function loads CRL into the WOLFSSL_CTX structure through
  8093. wolfSSL_CertManagerLoadCRL().
  8094. \return SSL_SUCCESS - returned if the function and its subroutines
  8095. execute without error.
  8096. \return BAD_FUNC_ARG - returned if this function or any subroutines
  8097. are passed NULL structures.
  8098. \return BAD_PATH_ERROR - returned if the path variable opens as NULL.
  8099. \return MEMORY_E - returned if an allocation of memory failed.
  8100. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8101. wolfSSL_CTX_new().
  8102. \param path the path to the certificate.
  8103. \param type an integer variable holding the type of certificate.
  8104. \param monitor an integer variable used to determine if the monitor
  8105. path is requested.
  8106. _Example_
  8107. \code
  8108. WOLFSSL_CTX* ctx;
  8109. const char* path;
  8110. return wolfSSL_CTX_LoadCRL(ctx, path, SSL_FILETYPE_PEM, 0);
  8111. \endcode
  8112. \sa wolfSSL_CertManagerLoadCRL
  8113. \sa LoadCRL
  8114. */
  8115. int wolfSSL_CTX_LoadCRL(WOLFSSL_CTX* ctx, const char* path, int type, int monitor);
  8116. /*!
  8117. \brief This function will set the callback argument to the cbMissingCRL
  8118. member of the WOLFSSL_CERT_MANAGER structure by calling
  8119. wolfSSL_CertManagerSetCRL_Cb.
  8120. \return SSL_SUCCESS returned for a successful execution. The
  8121. WOLFSSL_CERT_MANAGER structure’s member cbMssingCRL was successfully
  8122. set to cb.
  8123. \return BAD_FUNC_ARG returned if WOLFSSL_CTX or WOLFSSL_CERT_MANAGER
  8124. are NULL.
  8125. \param ctx a pointer to a WOLFSSL_CTX structure, created with
  8126. wolfSSL_CTX_new().
  8127. \param cb a pointer to a callback function of type CbMissingCRL.
  8128. Signature requirement:
  8129. void (*CbMissingCRL)(const char* url);
  8130. _Example_
  8131. \code
  8132. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8133. void cb(const char* url) // Required signature
  8134. {
  8135. // Function body
  8136. }
  8137. if (wolfSSL_CTX_SetCRL_Cb(ctx, cb) != SSL_SUCCESS){
  8138. // Failure case, cb was not set correctly.
  8139. }
  8140. \endcode
  8141. \sa wolfSSL_CertManagerSetCRL_Cb
  8142. \sa CbMissingCRL
  8143. */
  8144. int wolfSSL_CTX_SetCRL_Cb(WOLFSSL_CTX* ctx, CbMissingCRL cb);
  8145. /*!
  8146. \brief This function sets options to configure behavior of OCSP
  8147. functionality in wolfSSL. The value of options if formed by or’ing
  8148. one or more of the following options:
  8149. WOLFSSL_OCSP_ENABLE - enable OCSP lookups WOLFSSL_OCSP_URL_OVERRIDE -
  8150. use the override URL instead of the URL in certificates. The override URL
  8151. is specified using the wolfSSL_CTX_SetOCSP_OverrideURL() function. This
  8152. function only sets the OCSP options when wolfSSL has been compiled with
  8153. OCSP support (--enable-ocsp, #define HAVE_OCSP).
  8154. \return SSL_SUCCESS is returned upon success.
  8155. \return SSL_FAILURE is returned upon failure.
  8156. \return NOT_COMPILED_IN is returned when this function has been called,
  8157. but OCSP support was not enabled when wolfSSL was compiled.
  8158. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  8159. \param options value used to set the OCSP options.
  8160. _Example_
  8161. \code
  8162. WOLFSSL_CTX* ctx = 0;
  8163. ...
  8164. wolfSSL_CTX_OCSP_set_options(ctx, WOLFSSL_OCSP_ENABLE);
  8165. \endcode
  8166. \sa wolfSSL_CTX_OCSP_set_override_url
  8167. */
  8168. int wolfSSL_CTX_EnableOCSP(WOLFSSL_CTX* ctx, int options);
  8169. /*!
  8170. \brief This function disables OCSP certificate revocation checking by
  8171. affecting the ocspEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8172. \return SSL_SUCCESS returned if the function executes without error.
  8173. The ocspEnabled member of the CM has been disabled.
  8174. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  8175. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8176. wolfSSL_CTX_new().
  8177. _Example_
  8178. \code
  8179. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8180. WOLFSSL* ssl = wolfSSL_new(ctx);
  8181. ...
  8182. if(!wolfSSL_CTX_DisableOCSP(ssl->ctx)){
  8183. // OCSP is not disabled
  8184. }
  8185. \endcode
  8186. \sa wolfSSL_DisableOCSP
  8187. \sa wolfSSL_CertManagerDisableOCSP
  8188. */
  8189. int wolfSSL_CTX_DisableOCSP(WOLFSSL_CTX*);
  8190. /*!
  8191. \brief This function manually sets the URL for OCSP to use. By default,
  8192. OCSP will use the URL found in the individual certificate unless the
  8193. WOLFSSL_OCSP_URL_OVERRIDE option is set using the wolfSSL_CTX_EnableOCSP.
  8194. \return SSL_SUCCESS is returned upon success.
  8195. \return SSL_FAILURE is returned upon failure.
  8196. \return NOT_COMPILED_IN is returned when this function has been called,
  8197. but OCSP support was not enabled when wolfSSL was compiled.
  8198. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  8199. \param url pointer to the OCSP URL for wolfSSL to use.
  8200. _Example_
  8201. \code
  8202. WOLFSSL_CTX* ctx = 0;
  8203. ...
  8204. wolfSSL_CTX_OCSP_set_override_url(ctx, “custom-url-here”);
  8205. \endcode
  8206. \sa wolfSSL_CTX_OCSP_set_options
  8207. */
  8208. int wolfSSL_CTX_SetOCSP_OverrideURL(WOLFSSL_CTX* ctx, const char* url);
  8209. /*!
  8210. \brief Sets the callback for the OCSP in the WOLFSSL_CTX structure.
  8211. \return SSL_SUCCESS returned if the function executed successfully. The
  8212. ocspIOCb, ocspRespFreeCb, and ocspIOCtx members in the CM were
  8213. successfully set.
  8214. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX or
  8215. WOLFSSL_CERT_MANAGER structure is NULL.
  8216. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8217. \param ioCb a CbOCSPIO type that is a function pointer.
  8218. \param respFreeCb a CbOCSPRespFree type that is a function pointer.
  8219. \param ioCbCtx a void pointer that will be held in the WOLFSSL_CERT_MANAGER.
  8220. _Example_
  8221. \code
  8222. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8223. CbOCSPIO ocspIOCb;
  8224. CbOCSPRespFree ocspRespFreeCb;
  8225. void* ioCbCtx;
  8226. int isSetOCSP = wolfSSL_CTX_SetOCSP_Cb(ctx, ocspIOCb,
  8227. ocspRespFreeCb, ioCbCtx);
  8228. if(isSetOCSP != SSL_SUCCESS){
  8229. // The function did not return successfully.
  8230. }
  8231. \endcode
  8232. \sa wolfSSL_CertManagerSetOCSP_Cb
  8233. \sa CbOCSPIO
  8234. \sa CbOCSPRespFree
  8235. */
  8236. int wolfSSL_CTX_SetOCSP_Cb(WOLFSSL_CTX* ctx,
  8237. CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8238. void* ioCbCtx);
  8239. /*!
  8240. \brief This function enables OCSP stapling by calling
  8241. wolfSSL_CertManagerEnableOCSPStapling().
  8242. \return SSL_SUCCESS returned if there were no errors and the function
  8243. executed successfully.
  8244. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  8245. otherwise if there was a unpermitted argument value passed to a subroutine.
  8246. \return MEMORY_E returned if there was an issue allocating memory.
  8247. \return SSL_FAILURE returned if the initialization of the OCSP
  8248. structure failed.
  8249. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  8250. HAVE_CERTIFICATE_STATUS_REQUEST option.
  8251. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8252. wolfSSL_CTX_new().
  8253. _Example_
  8254. \code
  8255. WOLFSSL* ssl = WOLFSSL_new();
  8256. ssl->method.version; // set to desired protocol
  8257. ...
  8258. if(!wolfSSL_CTX_EnableOCSPStapling(ssl->ctx)){
  8259. // OCSP stapling is not enabled
  8260. }
  8261. \endcode
  8262. \sa wolfSSL_CertManagerEnableOCSPStapling
  8263. \sa InitOCSP
  8264. */
  8265. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX*);
  8266. /*!
  8267. \ingroup CertsKeys
  8268. \brief Normally, at the end of the SSL handshake, wolfSSL frees
  8269. temporary arrays. Calling this function before the handshake begins
  8270. will prevent wolfSSL from freeing temporary arrays. Temporary arrays
  8271. may be needed for things such as wolfSSL_get_keys() or PSK hints.
  8272. When the user is done with temporary arrays, either wolfSSL_FreeArrays()
  8273. may be called to free the resources immediately, or alternatively the
  8274. resources will be freed when the associated SSL object is freed.
  8275. \return none No return.
  8276. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8277. _Example_
  8278. \code
  8279. WOLFSSL* ssl;
  8280. ...
  8281. wolfSSL_KeepArrays(ssl);
  8282. \endcode
  8283. \sa wolfSSL_FreeArrays
  8284. */
  8285. void wolfSSL_KeepArrays(WOLFSSL*);
  8286. /*!
  8287. \ingroup CertsKeys
  8288. \brief Normally, at the end of the SSL handshake, wolfSSL frees temporary
  8289. arrays. If wolfSSL_KeepArrays() has been called before the handshake,
  8290. wolfSSL will not free temporary arrays. This function explicitly frees
  8291. temporary arrays and should be called when the user is done with temporary
  8292. arrays and does not want to wait for the SSL object to be freed to free
  8293. these resources.
  8294. \return none No return.
  8295. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8296. _Example_
  8297. \code
  8298. WOLFSSL* ssl;
  8299. ...
  8300. wolfSSL_FreeArrays(ssl);
  8301. \endcode
  8302. \sa wolfSSL_KeepArrays
  8303. */
  8304. void wolfSSL_FreeArrays(WOLFSSL*);
  8305. /*!
  8306. \brief This function enables the use of Server Name Indication in the SSL
  8307. object passed in the 'ssl' parameter. It means that the SNI extension will
  8308. be sent on ClientHello by wolfSSL client and wolfSSL server will respond
  8309. ClientHello + SNI with either ServerHello + blank SNI or alert fatal in
  8310. case of SNI mismatch.
  8311. \return WOLFSSL_SUCCESS upon success.
  8312. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8313. cases: ssl is NULL, data is NULL, type is a unknown value. (see below)
  8314. \return MEMORY_E is the error returned when there is not enough memory.
  8315. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8316. \param type indicates which type of server name is been passed in data.
  8317. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8318. \param data pointer to the server name data.
  8319. \param size size of the server name data.
  8320. _Example_
  8321. \code
  8322. int ret = 0;
  8323. WOLFSSL_CTX* ctx = 0;
  8324. WOLFSSL* ssl = 0;
  8325. ctx = wolfSSL_CTX_new(method);
  8326. if (ctx == NULL) {
  8327. // context creation failed
  8328. }
  8329. ssl = wolfSSL_new(ctx);
  8330. if (ssl == NULL) {
  8331. // ssl creation failed
  8332. }
  8333. ret = wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8334. strlen("www.yassl.com"));
  8335. if (ret != WOLFSSL_SUCCESS) {
  8336. // sni usage failed
  8337. }
  8338. \endcode
  8339. \sa wolfSSL_new
  8340. \sa wolfSSL_CTX_UseSNI
  8341. */
  8342. int wolfSSL_UseSNI(WOLFSSL* ssl, unsigned char type,
  8343. const void* data, unsigned short size);
  8344. /*!
  8345. \brief This function enables the use of Server Name Indication for SSL
  8346. objects created from the SSL context passed in the 'ctx' parameter. It
  8347. means that the SNI extension will be sent on ClientHello by wolfSSL
  8348. clients and wolfSSL servers will respond ClientHello + SNI with either
  8349. ServerHello + blank SNI or alert fatal in case of SNI mismatch.
  8350. \return WOLFSSL_SUCCESS upon success.
  8351. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8352. cases: ctx is NULL, data is NULL, type is a unknown value. (see below)
  8353. \return MEMORY_E is the error returned when there is not enough memory.
  8354. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8355. \param type indicates which type of server name is been passed in data.
  8356. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8357. \param data pointer to the server name data.
  8358. \param size size of the server name data.
  8359. _Example_
  8360. \code
  8361. int ret = 0;
  8362. WOLFSSL_CTX* ctx = 0;
  8363. ctx = wolfSSL_CTX_new(method);
  8364. if (ctx == NULL) {
  8365. // context creation failed
  8366. }
  8367. ret = wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8368. strlen("www.yassl.com"));
  8369. if (ret != WOLFSSL_SUCCESS) {
  8370. // sni usage failed
  8371. }
  8372. \endcode
  8373. \sa wolfSSL_CTX_new
  8374. \sa wolfSSL_UseSNI
  8375. */
  8376. int wolfSSL_CTX_UseSNI(WOLFSSL_CTX* ctx, unsigned char type,
  8377. const void* data, unsigned short size);
  8378. /*!
  8379. \brief This function is called on the server side to configure the
  8380. behavior of the SSL session using Server Name Indication in the SSL
  8381. object passed in the 'ssl' parameter. The options are explained below.
  8382. \return none No returns.
  8383. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8384. \param type indicates which type of server name is been passed in data.
  8385. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8386. \param options a bitwise semaphore with the chosen options. The available
  8387. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8388. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort the
  8389. handshake by sending a fatal-level unrecognized_name(112) alert if the
  8390. hostname provided by the client mismatch with the servers.
  8391. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the server
  8392. will not send a SNI response instead of aborting the session.
  8393. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH - With this option set, the server
  8394. will send a SNI response as if the host names match instead of aborting
  8395. the session.
  8396. _Example_
  8397. \code
  8398. int ret = 0;
  8399. WOLFSSL_CTX* ctx = 0;
  8400. WOLFSSL* ssl = 0;
  8401. ctx = wolfSSL_CTX_new(method);
  8402. if (ctx == NULL) {
  8403. // context creation failed
  8404. }
  8405. ssl = wolfSSL_new(ctx);
  8406. if (ssl == NULL) {
  8407. // ssl creation failed
  8408. }
  8409. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8410. if (ret != WOLFSSL_SUCCESS) {
  8411. // sni usage failed
  8412. }
  8413. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  8414. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8415. \endcode
  8416. \sa wolfSSL_new
  8417. \sa wolfSSL_UseSNI
  8418. \sa wolfSSL_CTX_SNI_SetOptions
  8419. */
  8420. void wolfSSL_SNI_SetOptions(WOLFSSL* ssl, unsigned char type,
  8421. unsigned char options);
  8422. /*!
  8423. \brief This function is called on the server side to configure the behavior
  8424. of the SSL sessions using Server Name Indication for SSL objects created
  8425. from the SSL context passed in the 'ctx' parameter. The options are
  8426. explained below.
  8427. \return none No returns.
  8428. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8429. \param type indicates which type of server name is been passed in data.
  8430. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8431. \param options a bitwise semaphore with the chosen options. The available
  8432. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8433. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort
  8434. the handshake by sending a fatal-level unrecognized_name(112) alert if the
  8435. hostname provided by the client mismatch with the servers.
  8436. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the
  8437. server will not send a SNI response instead of aborting the session.
  8438. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH With this option set, the server
  8439. will send a SNI response as if the host names match instead of aborting
  8440. the session.
  8441. _Example_
  8442. \code
  8443. int ret = 0;
  8444. WOLFSSL_CTX* ctx = 0;
  8445. ctx = wolfSSL_CTX_new(method);
  8446. if (ctx == NULL) {
  8447. // context creation failed
  8448. }
  8449. ret = wolfSSL_CTX_UseSNI(ctx, 0, "www.yassl.com", strlen("www.yassl.com"));
  8450. if (ret != WOLFSSL_SUCCESS) {
  8451. // sni usage failed
  8452. }
  8453. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  8454. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8455. \endcode
  8456. \sa wolfSSL_CTX_new
  8457. \sa wolfSSL_CTX_UseSNI
  8458. \sa wolfSSL_SNI_SetOptions
  8459. */
  8460. void wolfSSL_CTX_SNI_SetOptions(WOLFSSL_CTX* ctx,
  8461. unsigned char type, unsigned char options);
  8462. /*!
  8463. \brief This function is called on the server side to retrieve the Server
  8464. Name Indication provided by the client from the Client Hello message sent
  8465. by the client to start a session. It does not requires context or session
  8466. setup to retrieve the SNI.
  8467. \return WOLFSSL_SUCCESS upon success.
  8468. \return BAD_FUNC_ARG is the error that will be returned in one of this
  8469. cases: buffer is NULL, bufferSz <= 0, sni is NULL, inOutSz is NULL or <= 0
  8470. \return BUFFER_ERROR is the error returned when there is a malformed
  8471. Client Hello message.
  8472. \return INCOMPLETE_DATA is the error returned when there is not enough
  8473. data to complete the extraction.
  8474. \param buffer pointer to the data provided by the client (Client Hello).
  8475. \param bufferSz size of the Client Hello message.
  8476. \param type indicates which type of server name is been retrieved
  8477. from the buffer. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8478. \param sni pointer to where the output is going to be stored.
  8479. \param inOutSz pointer to the output size, this value will be updated
  8480. to MIN("SNI's length", inOutSz).
  8481. _Example_
  8482. \code
  8483. unsigned char buffer[1024] = {0};
  8484. unsigned char result[32] = {0};
  8485. int length = 32;
  8486. // read Client Hello to buffer...
  8487. ret = wolfSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), 0, result, &length));
  8488. if (ret != WOLFSSL_SUCCESS) {
  8489. // sni retrieve failed
  8490. }
  8491. \endcode
  8492. \sa wolfSSL_UseSNI
  8493. \sa wolfSSL_CTX_UseSNI
  8494. \sa wolfSSL_SNI_GetRequest
  8495. */
  8496. int wolfSSL_SNI_GetFromBuffer(
  8497. const unsigned char* clientHello, unsigned int helloSz,
  8498. unsigned char type, unsigned char* sni, unsigned int* inOutSz);
  8499. /*!
  8500. \ingroup IO
  8501. \brief This function gets the status of an SNI object.
  8502. \return value This function returns the byte value of the SNI struct’s
  8503. status member if the SNI is not NULL.
  8504. \return 0 if the SNI object is NULL.
  8505. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8506. \param type the SNI type.
  8507. _Example_
  8508. \code
  8509. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8510. WOLFSSL* ssl = wolfSSL_new(ctx);
  8511. #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
  8512. Byte type = WOLFSSL_SNI_HOST_NAME;
  8513. char* request = (char*)&type;
  8514. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  8515. \endcode
  8516. \sa TLSX_SNI_Status
  8517. \sa TLSX_SNI_find
  8518. \sa TLSX_Find
  8519. */
  8520. unsigned char wolfSSL_SNI_Status(WOLFSSL* ssl, unsigned char type);
  8521. /*!
  8522. \brief This function is called on the server side to retrieve the
  8523. Server Name Indication provided by the client in a SSL session.
  8524. \return size the size of the provided SNI data.
  8525. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8526. \param type indicates which type of server name is been retrieved in
  8527. data. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8528. \param data pointer to the data provided by the client.
  8529. _Example_
  8530. \code
  8531. int ret = 0;
  8532. WOLFSSL_CTX* ctx = 0;
  8533. WOLFSSL* ssl = 0;
  8534. ctx = wolfSSL_CTX_new(method);
  8535. if (ctx == NULL) {
  8536. // context creation failed
  8537. }
  8538. ssl = wolfSSL_new(ctx);
  8539. if (ssl == NULL) {
  8540. // ssl creation failed
  8541. }
  8542. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8543. if (ret != WOLFSSL_SUCCESS) {
  8544. // sni usage failed
  8545. }
  8546. if (wolfSSL_accept(ssl) == SSL_SUCCESS) {
  8547. void *data = NULL;
  8548. unsigned short size = wolfSSL_SNI_GetRequest(ssl, 0, &data);
  8549. }
  8550. \endcode
  8551. \sa wolfSSL_UseSNI
  8552. \sa wolfSSL_CTX_UseSNI
  8553. */
  8554. unsigned short wolfSSL_SNI_GetRequest(WOLFSSL *ssl,
  8555. unsigned char type, void** data);
  8556. /*!
  8557. \ingroup Setup
  8558. \brief Setup ALPN use for a wolfSSL session.
  8559. \return WOLFSSL_SUCCESS: upon success.
  8560. \return BAD_FUNC_ARG Returned if ssl or protocol_name_list
  8561. is null or protocol_name_listSz is too large or options
  8562. contain something not supported.
  8563. \return MEMORY_ERROR Error allocating memory for protocol list.
  8564. \return SSL_FAILURE upon failure.
  8565. \param ssl The wolfSSL session to use.
  8566. \param protocol_name_list List of protocol names to use.
  8567. Comma delimited string is required.
  8568. \param protocol_name_listSz Size of the list of protocol names.
  8569. \param options WOLFSSL_ALPN_CONTINUE_ON_MISMATCH or
  8570. WOLFSSL_ALPN_FAILED_ON_MISMATCH.
  8571. _Example_
  8572. \code
  8573. wolfSSL_Init();
  8574. WOLFSSL_CTX* ctx;
  8575. WOLFSSL* ssl;
  8576. WOLFSSL_METHOD method = // Some wolfSSL method
  8577. ctx = wolfSSL_CTX_new(method);
  8578. ssl = wolfSSL_new(ctx);
  8579. char alpn_list[] = {};
  8580. if (wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  8581. WOLFSSL_APN_FAILED_ON_MISMATCH) != WOLFSSL_SUCCESS)
  8582. {
  8583. // Error setting session ticket
  8584. }
  8585. \endcode
  8586. \sa TLSX_UseALPN
  8587. */
  8588. int wolfSSL_UseALPN(WOLFSSL* ssl, char *protocol_name_list,
  8589. unsigned int protocol_name_listSz,
  8590. unsigned char options);
  8591. /*!
  8592. \ingroup TLS
  8593. \brief This function gets the protocol name set by the server.
  8594. \return SSL_SUCCESS returned on successful execution where no
  8595. errors were thrown.
  8596. \return SSL_FATAL_ERROR returned if the extension was not found or
  8597. if there was no protocol match with peer. There will also be an
  8598. error thrown if there is more than one protocol name accepted.
  8599. \return SSL_ALPN_NOT_FOUND returned signifying that no protocol
  8600. match with peer was found.
  8601. \return BAD_FUNC_ARG returned if there was a NULL argument passed
  8602. into the function.
  8603. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8604. \param protocol_name a pointer to a char that represents the protocol
  8605. name and will be held in the ALPN structure.
  8606. \param size a word16 type that represents the size of the protocol_name.
  8607. _Example_
  8608. \code
  8609. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  8610. WOLFSSL* ssl = WOLFSSL_new(ctx);
  8611. ...
  8612. int err;
  8613. char* protocol_name = NULL;
  8614. Word16 protocol_nameSz = 0;
  8615. err = wolfSSL_ALPN_GetProtocol(ssl, &protocol_name, &protocol_nameSz);
  8616. if(err == SSL_SUCCESS){
  8617. // Sent ALPN protocol
  8618. }
  8619. \endcode
  8620. \sa TLSX_ALPN_GetRequest
  8621. \sa TLSX_Find
  8622. */
  8623. int wolfSSL_ALPN_GetProtocol(WOLFSSL* ssl, char **protocol_name,
  8624. unsigned short *size);
  8625. /*!
  8626. \ingroup TLS
  8627. \brief This function copies the alpn_client_list data from the SSL
  8628. object to the buffer.
  8629. \return SSL_SUCCESS returned if the function executed without error. The
  8630. alpn_client_list member of the SSL object has been copied to the
  8631. list parameter.
  8632. \return BAD_FUNC_ARG returned if the list or listSz parameter is NULL.
  8633. \return BUFFER_ERROR returned if there will be a problem with the
  8634. list buffer (either it’s NULL or the size is 0).
  8635. \return MEMORY_ERROR returned if there was a problem dynamically
  8636. allocating memory.
  8637. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8638. \param list a pointer to the buffer. The data from the SSL object will
  8639. be copied into it.
  8640. \param listSz the buffer size.
  8641. _Example_
  8642. \code
  8643. #import <wolfssl/ssl.h>
  8644. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method);
  8645. WOLFSSL* ssl = wolfSSL_new(ctx);
  8646. #ifdef HAVE_ALPN
  8647. char* list = NULL;
  8648. word16 listSz = 0;
  8649. err = wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz);
  8650. if(err == SSL_SUCCESS){
  8651. List of protocols names sent by client
  8652. }
  8653. \endcode
  8654. \sa wolfSSL_UseALPN
  8655. */
  8656. int wolfSSL_ALPN_GetPeerProtocol(WOLFSSL* ssl, char **list,
  8657. unsigned short *listSz);
  8658. /*!
  8659. \brief This function is called on the client side to enable the use of
  8660. Maximum Fragment Length in the SSL object passed in the 'ssl' parameter.
  8661. It means that the Maximum Fragment Length extension will be sent on
  8662. ClientHello by wolfSSL clients.
  8663. \return SSL_SUCCESS upon success.
  8664. \return BAD_FUNC_ARG is the error that will be returned in one of
  8665. these cases: ssl is NULL, mfl is out of range.
  8666. \return MEMORY_E is the error returned when there is not enough memory.
  8667. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8668. \param mfl indicates witch is the Maximum Fragment Length requested for the
  8669. session. The available options are: enum { WOLFSSL_MFL_2_9 = 1, 512 bytes
  8670. WOLFSSL_MFL_2_10 = 2, 1024 bytes WOLFSSL_MFL_2_11 = 3, 2048 bytes
  8671. WOLFSSL_MFL_2_12 = 4, 4096 bytes WOLFSSL_MFL_2_13 = 5, 8192
  8672. bytes wolfSSL ONLY!!! };
  8673. _Example_
  8674. \code
  8675. int ret = 0;
  8676. WOLFSSL_CTX* ctx = 0;
  8677. WOLFSSL* ssl = 0;
  8678. ctx = wolfSSL_CTX_new(method);
  8679. if (ctx == NULL) {
  8680. // context creation failed
  8681. }
  8682. ssl = wolfSSL_new(ctx);
  8683. if (ssl == NULL) {
  8684. // ssl creation failed
  8685. }
  8686. ret = wolfSSL_UseMaxFragment(ssl, WOLFSSL_MFL_2_11);
  8687. if (ret != 0) {
  8688. // max fragment usage failed
  8689. }
  8690. \endcode
  8691. \sa wolfSSL_new
  8692. \sa wolfSSL_CTX_UseMaxFragment
  8693. */
  8694. int wolfSSL_UseMaxFragment(WOLFSSL* ssl, unsigned char mfl);
  8695. /*!
  8696. \brief This function is called on the client side to enable the use
  8697. of Maximum Fragment Length for SSL objects created from the SSL context
  8698. passed in the 'ctx' parameter. It means that the Maximum Fragment Length
  8699. extension will be sent on ClientHello by wolfSSL clients.
  8700. \return SSL_SUCCESS upon success.
  8701. \return BAD_FUNC_ARG is the error that will be returned in one of
  8702. these cases: ctx is NULL, mfl is out of range.
  8703. \return MEMORY_E is the error returned when there is not enough memory.
  8704. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8705. \param mfl indicates which is the Maximum Fragment Length requested
  8706. for the session. The available options are:
  8707. enum { WOLFSSL_MFL_2_9 = 1 512 bytes, WOLFSSL_MFL_2_10 = 2 1024 bytes,
  8708. WOLFSSL_MFL_2_11 = 3 2048 bytes WOLFSSL_MFL_2_12 = 4 4096 bytes,
  8709. WOLFSSL_MFL_2_13 = 5 8192 bytes wolfSSL ONLY!!!,
  8710. WOLFSSL_MFL_2_13 = 6 256 bytes wolfSSL ONLY!!!
  8711. };
  8712. _Example_
  8713. \code
  8714. int ret = 0;
  8715. WOLFSSL_CTX* ctx = 0;
  8716. ctx = wolfSSL_CTX_new(method);
  8717. if (ctx == NULL) {
  8718. // context creation failed
  8719. }
  8720. ret = wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11);
  8721. if (ret != 0) {
  8722. // max fragment usage failed
  8723. }
  8724. \endcode
  8725. \sa wolfSSL_CTX_new
  8726. \sa wolfSSL_UseMaxFragment
  8727. */
  8728. int wolfSSL_CTX_UseMaxFragment(WOLFSSL_CTX* ctx, unsigned char mfl);
  8729. /*!
  8730. \brief This function is called on the client side to enable the use of
  8731. Truncated HMAC in the SSL object passed in the 'ssl' parameter. It
  8732. means that the Truncated HMAC extension will be sent on ClientHello
  8733. by wolfSSL clients.
  8734. \return SSL_SUCCESS upon success.
  8735. \return BAD_FUNC_ARG is the error that will be returned in one of
  8736. these cases: ssl is NULL
  8737. \return MEMORY_E is the error returned when there is not enough memory.
  8738. \param ssl pointer to a SSL object, created with wolfSSL_new()
  8739. _Example_
  8740. \code
  8741. int ret = 0;
  8742. WOLFSSL_CTX* ctx = 0;
  8743. WOLFSSL* ssl = 0;
  8744. ctx = wolfSSL_CTX_new(method);
  8745. if (ctx == NULL) {
  8746. // context creation failed
  8747. }
  8748. ssl = wolfSSL_new(ctx);
  8749. if (ssl == NULL) {
  8750. // ssl creation failed
  8751. }
  8752. ret = wolfSSL_UseTruncatedHMAC(ssl);
  8753. if (ret != 0) {
  8754. // truncated HMAC usage failed
  8755. }
  8756. \endcode
  8757. \sa wolfSSL_new
  8758. \sa wolfSSL_CTX_UseMaxFragment
  8759. */
  8760. int wolfSSL_UseTruncatedHMAC(WOLFSSL* ssl);
  8761. /*!
  8762. \brief This function is called on the client side to enable the use of
  8763. Truncated HMAC for SSL objects created from the SSL context passed in
  8764. the 'ctx' parameter. It means that the Truncated HMAC extension will
  8765. be sent on ClientHello by wolfSSL clients.
  8766. \return SSL_SUCCESS upon success.
  8767. \return BAD_FUNC_ARG is the error that will be returned in one of
  8768. these cases: ctx is NULL
  8769. \return MEMORY_E is the error returned when there is not enough memory.
  8770. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8771. _Example_
  8772. \code
  8773. int ret = 0;
  8774. WOLFSSL_CTX* ctx = 0;
  8775. ctx = wolfSSL_CTX_new(method);
  8776. if (ctx == NULL) {
  8777. // context creation failed
  8778. }
  8779. ret = wolfSSL_CTX_UseTruncatedHMAC(ctx);
  8780. if (ret != 0) {
  8781. // truncated HMAC usage failed
  8782. }
  8783. \endcode
  8784. \sa wolfSSL_CTX_new
  8785. \sa wolfSSL_UseMaxFragment
  8786. */
  8787. int wolfSSL_CTX_UseTruncatedHMAC(WOLFSSL_CTX* ctx);
  8788. /*!
  8789. \brief Stapling eliminates the need to contact the CA. Stapling
  8790. lowers the cost of certificate revocation check presented in OCSP.
  8791. \return SSL_SUCCESS returned if TLSX_UseCertificateStatusRequest
  8792. executes without error.
  8793. \return MEMORY_E returned if there is an error with the allocation
  8794. of memory.
  8795. \return BAD_FUNC_ARG returned if there is an argument that has a
  8796. NULL or otherwise unacceptable value passed into the function.
  8797. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8798. \param status_type a byte type that is passed through to
  8799. TLSX_UseCertificateStatusRequest() and stored in the
  8800. CertificateStatusRequest structure.
  8801. \param options a byte type that is passed through to
  8802. TLSX_UseCertificateStatusRequest() and stored in the
  8803. CertificateStatusRequest structure.
  8804. _Example_
  8805. \code
  8806. WOLFSSL* ssl = wolfSSL_new(ctx);
  8807. if (wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  8808. WOLFSSL_CSR2_OCSP_USE_NONCE) != SSL_SUCCESS){
  8809. // Failed case.
  8810. }
  8811. \endcode
  8812. \sa TLSX_UseCertificateStatusRequest
  8813. \sa wolfSSL_CTX_UseOCSPStapling
  8814. */
  8815. int wolfSSL_UseOCSPStapling(WOLFSSL* ssl,
  8816. unsigned char status_type, unsigned char options);
  8817. /*!
  8818. \brief This function requests the certificate status during the handshake.
  8819. \return SSL_SUCCESS returned if the function and subroutines execute
  8820. without error.
  8821. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  8822. otherwise if a unpermitted value is passed to a subroutine.
  8823. \return MEMORY_E returned if the function or subroutine failed to properly
  8824. allocate memory.
  8825. \param ctx a pointer to a WOLFSSL_CTX structure,
  8826. created using wolfSSL_CTX_new().
  8827. \param status_type a byte type that is passed through to
  8828. TLSX_UseCertificateStatusRequest() and stored in the
  8829. CertificateStatusRequest structure.
  8830. \param options a byte type that is passed through to
  8831. TLSX_UseCertificateStatusRequest() and stored in the
  8832. CertificateStatusRequest structure.
  8833. _Example_
  8834. \code
  8835. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8836. WOLFSSL* ssl = wolfSSL_new(ctx);
  8837. byte statusRequest = 0; // Initialize status request
  8838. switch(statusRequest){
  8839. case WOLFSSL_CSR_OCSP:
  8840. if(wolfSSL_CTX_UseOCSPStapling(ssl->ctx, WOLFSSL_CSR_OCSP,
  8841. WOLF_CSR_OCSP_USE_NONCE) != SSL_SUCCESS){
  8842. // UseCertificateStatusRequest failed
  8843. }
  8844. // Continue switch cases
  8845. \endcode
  8846. \sa wolfSSL_UseOCSPStaplingV2
  8847. \sa wolfSSL_UseOCSPStapling
  8848. \sa TLSX_UseCertificateStatusRequest
  8849. */
  8850. int wolfSSL_CTX_UseOCSPStapling(WOLFSSL_CTX* ctx,
  8851. unsigned char status_type, unsigned char options);
  8852. /*!
  8853. \brief The function sets the status type and options for OCSP.
  8854. \return SSL_SUCCESS - returned if the function and subroutines
  8855. executed without error.
  8856. \return MEMORY_E - returned if there was an allocation of memory error.
  8857. \return BAD_FUNC_ARG - returned if a NULL or otherwise unaccepted
  8858. argument was passed to the function or a subroutine.
  8859. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8860. \param status_type a byte type that loads the OCSP status type.
  8861. \param options a byte type that holds the OCSP options, set in
  8862. wolfSSL_SNI_SetOptions() and wolfSSL_CTX_SNI_SetOptions().
  8863. _Example_
  8864. \code
  8865. WOLFSSL* ssl = wolfSSL_new(ctx);
  8866. ...
  8867. if (wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP_MULTI, 0) != SSL_SUCCESS){
  8868. // Did not execute properly. Failure case code block.
  8869. }
  8870. \endcode
  8871. \sa TLSX_UseCertificatStatusRequestV2
  8872. \sa wolfSSL_SNI_SetOptions
  8873. \sa wolfSSL_CTX_SNI_SetOptions
  8874. */
  8875. int wolfSSL_UseOCSPStaplingV2(WOLFSSL* ssl,
  8876. unsigned char status_type, unsigned char options);
  8877. /*!
  8878. \brief Creates and initializes the certificate status request
  8879. for OCSP Stapling.
  8880. \return SSL_SUCCESS if the function and subroutines executed without error.
  8881. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or if
  8882. the side variable is not client side.
  8883. \return MEMORY_E returned if the allocation of memory failed.
  8884. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8885. wolfSSL_CTX_new().
  8886. \param status_type a byte type that is located in the
  8887. CertificatStatusRequest structure and must be either WOLFSSL_CSR2_OCSP
  8888. or WOLFSSL_CSR2_OCSP_MULTI.
  8889. \param options a byte type that will be held in
  8890. CertificateStatusRequestItemV2 struct.
  8891. _Example_
  8892. \code
  8893. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8894. byte status_type;
  8895. byte options;
  8896. ...
  8897. if(wolfSSL_CTX_UseOCSPStaplingV2(ctx, status_type, options); != SSL_SUCCESS){
  8898. // Failure case.
  8899. }
  8900. \endcode
  8901. \sa TLSX_UseCertificateStatusRequestV2
  8902. \sa wc_RNG_GenerateBlock
  8903. \sa TLSX_Push
  8904. */
  8905. int wolfSSL_CTX_UseOCSPStaplingV2(WOLFSSL_CTX* ctx,
  8906. unsigned char status_type, unsigned char options);
  8907. /*!
  8908. \brief This function is called on the client side to enable the use of
  8909. Supported Elliptic Curves Extension in the SSL object passed in the 'ssl'
  8910. parameter. It means that the supported curves enabled will be sent on
  8911. ClientHello by wolfSSL clients. This function can be called more than
  8912. one time to enable multiple curves.
  8913. \return SSL_SUCCESS upon success.
  8914. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8915. cases: ssl is NULL, name is a unknown value. (see below)
  8916. \return MEMORY_E is the error returned when there is not enough memory.
  8917. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8918. \param name indicates which curve will be supported for the session. The
  8919. available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  8920. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  8921. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  8922. WOLFSSL_ECC_SECP521R1 = 0x19 };
  8923. _Example_
  8924. \code
  8925. int ret = 0;
  8926. WOLFSSL_CTX* ctx = 0;
  8927. WOLFSSL* ssl = 0;
  8928. ctx = wolfSSL_CTX_new(method);
  8929. if (ctx == NULL) {
  8930. // context creation failed
  8931. }
  8932. ssl = wolfSSL_new(ctx);
  8933. if (ssl == NULL) {
  8934. // ssl creation failed
  8935. }
  8936. ret = wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1);
  8937. if (ret != 0) {
  8938. // Elliptic Curve Extension usage failed
  8939. }
  8940. \endcode
  8941. \sa wolfSSL_CTX_new
  8942. \sa wolfSSL_CTX_UseSupportedCurve
  8943. */
  8944. int wolfSSL_UseSupportedCurve(WOLFSSL* ssl, word16 name);
  8945. /*!
  8946. \brief This function is called on the client side to enable the use of
  8947. Supported Elliptic Curves Extension for SSL objects created from the SSL
  8948. context passed in the 'ctx' parameter. It means that the supported curves
  8949. enabled will be sent on ClientHello by wolfSSL clients. This function can
  8950. be called more than one time to enable multiple curves.
  8951. \return SSL_SUCCESS upon success.
  8952. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8953. cases: ctx is NULL, name is a unknown value. (see below)
  8954. \return MEMORY_E is the error returned when there is not enough memory.
  8955. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8956. \param name indicates which curve will be supported for the session.
  8957. The available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  8958. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  8959. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  8960. WOLFSSL_ECC_SECP521R1 = 0x19 };
  8961. _Example_
  8962. \code
  8963. int ret = 0;
  8964. WOLFSSL_CTX* ctx = 0;
  8965. ctx = wolfSSL_CTX_new(method);
  8966. if (ctx == NULL) {
  8967. // context creation failed
  8968. }
  8969. ret = wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1);
  8970. if (ret != 0) {
  8971. // Elliptic Curve Extension usage failed
  8972. }
  8973. \endcode
  8974. \sa wolfSSL_CTX_new
  8975. \sa wolfSSL_UseSupportedCurve
  8976. */
  8977. int wolfSSL_CTX_UseSupportedCurve(WOLFSSL_CTX* ctx,
  8978. word16 name);
  8979. /*!
  8980. \ingroup IO
  8981. \brief This function forces secure renegotiation for the supplied
  8982. WOLFSSL structure. This is not recommended.
  8983. \return SSL_SUCCESS Successfully set secure renegotiation.
  8984. \return BAD_FUNC_ARG Returns error if ssl is null.
  8985. \return MEMORY_E Returns error if unable to allocate memory for secure
  8986. renegotiation.
  8987. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8988. _Example_
  8989. \code
  8990. wolfSSL_Init();
  8991. WOLFSSL_CTX* ctx;
  8992. WOLFSSL* ssl;
  8993. WOLFSSL_METHOD method = // Some wolfSSL method
  8994. ctx = wolfSSL_CTX_new(method);
  8995. ssl = wolfSSL_new(ctx);
  8996. if(wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS)
  8997. {
  8998. // Error setting secure renegotiation
  8999. }
  9000. \endcode
  9001. \sa TLSX_Find
  9002. \sa TLSX_UseSecureRenegotiation
  9003. */
  9004. int wolfSSL_UseSecureRenegotiation(WOLFSSL* ssl);
  9005. /*!
  9006. \ingroup IO
  9007. \brief This function executes a secure renegotiation handshake; this is user
  9008. forced as wolfSSL discourages this functionality.
  9009. \return SSL_SUCCESS returned if the function executed without error.
  9010. \return BAD_FUNC_ARG returned if the WOLFSSL structure was NULL or otherwise
  9011. if an unacceptable argument was passed in a subroutine.
  9012. \return SECURE_RENEGOTIATION_E returned if there was an error with
  9013. renegotiating the handshake.
  9014. \return SSL_FATAL_ERROR returned if there was an error with the
  9015. server or client configuration and the renegotiation could
  9016. not be completed. See wolfSSL_negotiate().
  9017. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9018. _Example_
  9019. \code
  9020. WOLFSSL* ssl = wolfSSL_new(ctx);
  9021. ...
  9022. if(wolfSSL_Rehandshake(ssl) != SSL_SUCCESS){
  9023. // There was an error and the rehandshake is not successful.
  9024. }
  9025. \endcode
  9026. \sa wolfSSL_negotiate
  9027. \sa wc_InitSha512
  9028. \sa wc_InitSha384
  9029. \sa wc_InitSha256
  9030. \sa wc_InitSha
  9031. \sa wc_InitMd5
  9032. */
  9033. int wolfSSL_Rehandshake(WOLFSSL* ssl);
  9034. /*!
  9035. \ingroup IO
  9036. \brief Force provided WOLFSSL structure to use session ticket. The
  9037. constant HAVE_SESSION_TICKET should be defined and the constant
  9038. NO_WOLFSSL_CLIENT should not be defined to use this function.
  9039. \return SSL_SUCCESS Successfully set use session ticket.
  9040. \return BAD_FUNC_ARG Returned if ssl is null.
  9041. \return MEMORY_E Error allocating memory for setting session ticket.
  9042. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9043. _Example_
  9044. \code
  9045. wolfSSL_Init();
  9046. WOLFSSL_CTX* ctx;
  9047. WOLFSSL* ssl;
  9048. WOLFSSL_METHOD method = // Some wolfSSL method
  9049. ctx = wolfSSL_CTX_new(method);
  9050. ssl = wolfSSL_new(ctx);
  9051. if(wolfSSL_UseSessionTicket(ssl) != SSL_SUCCESS)
  9052. {
  9053. // Error setting session ticket
  9054. }
  9055. \endcode
  9056. \sa TLSX_UseSessionTicket
  9057. */
  9058. int wolfSSL_UseSessionTicket(WOLFSSL* ssl);
  9059. /*!
  9060. \ingroup Setup
  9061. \brief This function sets wolfSSL context to use a session ticket.
  9062. \return SSL_SUCCESS Function executed successfully.
  9063. \return BAD_FUNC_ARG Returned if ctx is null.
  9064. \return MEMORY_E Error allocating memory in internal function.
  9065. \param ctx The WOLFSSL_CTX structure to use.
  9066. _Example_
  9067. \code
  9068. wolfSSL_Init();
  9069. WOLFSSL_CTX* ctx;
  9070. WOLFSSL_METHOD method = // Some wolfSSL method ;
  9071. ctx = wolfSSL_CTX_new(method);
  9072. if(wolfSSL_CTX_UseSessionTicket(ctx) != SSL_SUCCESS)
  9073. {
  9074. // Error setting session ticket
  9075. }
  9076. \endcode
  9077. \sa TLSX_UseSessionTicket
  9078. */
  9079. int wolfSSL_CTX_UseSessionTicket(WOLFSSL_CTX* ctx);
  9080. /*!
  9081. \ingroup IO
  9082. \brief This function copies the ticket member of the Session structure to
  9083. the buffer.
  9084. \return SSL_SUCCESS returned if the function executed without error.
  9085. \return BAD_FUNC_ARG returned if one of the arguments was NULL or if the
  9086. bufSz argument was 0.
  9087. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9088. \param buf a byte pointer representing the memory buffer.
  9089. \param bufSz a word32 pointer representing the buffer size.
  9090. _Example_
  9091. \code
  9092. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9093. WOLFSSL* ssl = wolfSSL_new(ctx);
  9094. byte* buf;
  9095. word32 bufSz; // Initialize with buf size
  9096. if(wolfSSL_get_SessionTicket(ssl, buf, bufSz) <= 0){
  9097. // Nothing was written to the buffer
  9098. } else {
  9099. // the buffer holds the content from ssl->session->ticket
  9100. }
  9101. \endcode
  9102. \sa wolfSSL_UseSessionTicket
  9103. \sa wolfSSL_set_SessionTicket
  9104. */
  9105. int wolfSSL_get_SessionTicket(WOLFSSL* ssl, unsigned char* buf, word32* bufSz);
  9106. /*!
  9107. \ingroup IO
  9108. \brief This function sets the ticket member of the WOLFSSL_SESSION
  9109. structure within the WOLFSSL struct. The buffer passed into the function
  9110. is copied to memory.
  9111. \return SSL_SUCCESS returned on successful execution of the function.
  9112. The function returned without errors.
  9113. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL. This will
  9114. also be thrown if the buf argument is NULL but the bufSz argument
  9115. is not zero.
  9116. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9117. \param buf a byte pointer that gets loaded into the ticket member
  9118. of the session structure.
  9119. \param bufSz a word32 type that represents the size of the buffer.
  9120. _Example_
  9121. \code
  9122. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9123. WOLFSSL* ssl = wolfSSL_new(ctx);
  9124. byte* buffer; // File to load
  9125. word32 bufSz;
  9126. ...
  9127. if(wolfSSL_KeepArrays(ssl, buffer, bufSz) != SSL_SUCCESS){
  9128. // There was an error loading the buffer to memory.
  9129. }
  9130. \endcode
  9131. \sa wolfSSL_set_SessionTicket_cb
  9132. */
  9133. int wolfSSL_set_SessionTicket(WOLFSSL* ssl, const unsigned char* buf,
  9134. word32 bufSz);
  9135. /*!
  9136. \brief This function sets the session ticket callback. The type
  9137. CallbackSessionTicket is a function pointer with the signature of:
  9138. int (*CallbackSessionTicket)(WOLFSSL*, const unsigned char*, int, void*)
  9139. \return SSL_SUCCESS returned if the function executed without error.
  9140. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  9141. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9142. \param cb a function pointer to the type CallbackSessionTicket.
  9143. \param ctx a void pointer to the session_ticket_ctx member of the
  9144. WOLFSSL structure.
  9145. _Example_
  9146. \code
  9147. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9148. WOLFSSL* ssl = wolfSSL_new(ctx);
  9149. int sessionTicketCB(WOLFSSL* ssl, const unsigned char* ticket, int ticketSz,
  9150. void* ctx){ … }
  9151. wolfSSL_set_SessionTicket_cb(ssl, sessionTicketCB, (void*)”initial session”);
  9152. \endcode
  9153. \sa wolfSSL_get_SessionTicket
  9154. \sa CallbackSessionTicket
  9155. \sa sessionTicketCB
  9156. */
  9157. int wolfSSL_set_SessionTicket_cb(WOLFSSL* ssl,
  9158. CallbackSessionTicket cb, void* ctx);
  9159. /*!
  9160. \brief This function sends a session ticket to the client after a TLS v1.3
  9161. handhsake has been established.
  9162. \return WOLFSSL_SUCCESS returned if a new session ticket was sent.
  9163. \return BAD_FUNC_ARG returned if WOLFSSL structure is NULL, or not using
  9164. TLS v1.3.
  9165. \return SIDE_ERROR returned if not a server.
  9166. \return NOT_READY_ERROR returned if the handshake has not completed.
  9167. \return WOLFSSL_FATAL_ERROR returned if creating or sending message fails.
  9168. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9169. _Example_
  9170. \code
  9171. int ret;
  9172. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9173. WOLFSSL* ssl = wolfSSL_new(ctx);
  9174. ret = wolfSSL_send_SessionTicket(ssl);
  9175. if (ret != WOLFSSL_SUCCESS) {
  9176. // New session ticket not sent.
  9177. }
  9178. \endcode
  9179. \sa wolfSSL_get_SessionTicket
  9180. \sa CallbackSessionTicket
  9181. \sa sessionTicketCB
  9182. */
  9183. int wolfSSL_send_SessionTicket(WOLFSSL* ssl);
  9184. /*!
  9185. \brief This function sets the session ticket key encrypt callback function
  9186. for a server to support session tickets as specified in RFC 5077.
  9187. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9188. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  9189. invalid arguments to the function.
  9190. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  9191. \param cb user callback function to encrypt/decrypt session tickets
  9192. \param ssl(Callback) pointer to the WOLFSSL object, created with
  9193. wolfSSL_new()
  9194. \param key_name(Callback) unique key name for this ticket context, should
  9195. be randomly generated
  9196. \param iv(Callback) unique IV for this ticket, up to 128 bits, should
  9197. be randomly generated
  9198. \param mac(Callback) up to 256 bit mac for this ticket
  9199. \param enc(Callback) if this encrypt parameter is true the user should fill
  9200. in key_name, iv, mac, and encrypt the ticket in-place of length inLen and
  9201. set the resulting output length in *outLen. Returning WOLFSSL_TICKET_RET_OK
  9202. tells wolfSSL that the encryption was successful. If this encrypt parameter
  9203. is false, the user should perform a decrypt of the ticket in-place of length
  9204. inLen using key_name, iv, and mac. The resulting decrypt length should be
  9205. set in *outLen. Returning WOLFSSL_TICKET_RET_OK tells wolfSSL to proceed
  9206. using the decrypted ticket. Returning WOLFSSL_TICKET_RET_CREATE tells
  9207. wolfSSL to use the decrypted ticket but also to generate a new one to
  9208. send to the client, helpful if recently rolled keys and don’t want to
  9209. force a full handshake. Returning WOLFSSL_TICKET_RET_REJECT tells
  9210. wolfSSL to reject this ticket, perform a full handshake, and create
  9211. a new standard session ID for normal session resumption. Returning
  9212. WOLFSSL_TICKET_RET_FATAL tells wolfSSL to end the connection
  9213. attempt with a fatal error.
  9214. \param ticket(Callback) the input/output buffer for the encrypted ticket.
  9215. See the enc parameter
  9216. \param inLen(Callback) the input length of the ticket parameter
  9217. \param outLen(Callback) the resulting output length of the ticket parameter.
  9218. When entering the callback outLen will indicate the maximum size available
  9219. in the ticket buffer.
  9220. \param userCtx(Callback) the user context set with
  9221. wolfSSL_CTX_set_TicketEncCtx()
  9222. _Example_
  9223. \code
  9224. See wolfssl/test.h myTicketEncCb() used by the example
  9225. server and example echoserver.
  9226. \endcode
  9227. \sa wolfSSL_CTX_set_TicketHint
  9228. \sa wolfSSL_CTX_set_TicketEncCtx
  9229. */
  9230. int wolfSSL_CTX_set_TicketEncCb(WOLFSSL_CTX* ctx,
  9231. SessionTicketEncCb);
  9232. /*!
  9233. \brief This function sets the session ticket hint relayed to the client.
  9234. For server side use.
  9235. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9236. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  9237. invalid arguments to the function.
  9238. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  9239. \param hint number of seconds the ticket might be valid for. Hint to client.
  9240. _Example_
  9241. \code
  9242. none
  9243. \endcode
  9244. \sa wolfSSL_CTX_set_TicketEncCb
  9245. */
  9246. int wolfSSL_CTX_set_TicketHint(WOLFSSL_CTX* ctx, int);
  9247. /*!
  9248. \brief This function sets the session ticket encrypt user context for the
  9249. callback. For server side use.
  9250. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9251. \return BAD_FUNC_ARG will be returned on failure. This is caused by
  9252. passing invalid arguments to the function.
  9253. \param ctx pointer to the WOLFSSL_CTX object, created
  9254. with wolfSSL_CTX_new().
  9255. \param userCtx the user context for the callback
  9256. _Example_
  9257. \code
  9258. none
  9259. \endcode
  9260. \sa wolfSSL_CTX_set_TicketEncCb
  9261. */
  9262. int wolfSSL_CTX_set_TicketEncCtx(WOLFSSL_CTX* ctx, void*);
  9263. /*!
  9264. \brief This function gets the session ticket encrypt user context for the
  9265. callback. For server side use.
  9266. \return userCtx will be returned upon successfully getting the session.
  9267. \return NULL will be returned on failure. This is caused by
  9268. passing invalid arguments to the function, or when the user context has
  9269. not been set.
  9270. \param ctx pointer to the WOLFSSL_CTX object, created
  9271. with wolfSSL_CTX_new().
  9272. _Example_
  9273. \code
  9274. none
  9275. \endcode
  9276. \sa wolfSSL_CTX_set_TicketEncCtx
  9277. */
  9278. void* wolfSSL_CTX_get_TicketEncCtx(WOLFSSL_CTX* ctx);
  9279. /*!
  9280. \brief This function sets the handshake done callback. The hsDoneCb and
  9281. hsDoneCtx members of the WOLFSSL structure are set in this function.
  9282. \return SSL_SUCCESS returned if the function executed without an error.
  9283. The hsDoneCb and hsDoneCtx members of the WOLFSSL struct are set.
  9284. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL.
  9285. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9286. \param cb a function pointer of type HandShakeDoneCb with the signature of
  9287. the form: int (*HandShakeDoneCb)(WOLFSSL*, void*);
  9288. \param user_ctx a void pointer to the user registered context.
  9289. _Example_
  9290. \code
  9291. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9292. WOLFSSL* ssl = wolfSSL_new(ctx);
  9293. int myHsDoneCb(WOLFSSL* ssl, void* user_ctx){
  9294. // callback function
  9295. }
  9296. wolfSSL_SetHsDoneCb(ssl, myHsDoneCb, NULL);
  9297. \endcode
  9298. \sa HandShakeDoneCb
  9299. */
  9300. int wolfSSL_SetHsDoneCb(WOLFSSL* ssl, HandShakeDoneCb cb, void* user_ctx);
  9301. /*!
  9302. \ingroup IO
  9303. \brief This function prints the statistics from the session.
  9304. \return SSL_SUCCESS returned if the function and subroutines return without
  9305. error. The session stats have been successfully retrieved and printed.
  9306. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9307. was passed an unacceptable argument.
  9308. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9309. \param none No parameters.
  9310. _Example_
  9311. \code
  9312. // You will need to have a session object to retrieve stats from.
  9313. if(wolfSSL_PrintSessionStats(void) != SSL_SUCCESS ){
  9314. // Did not print session stats
  9315. }
  9316. \endcode
  9317. \sa wolfSSL_get_session_stats
  9318. */
  9319. int wolfSSL_PrintSessionStats(void);
  9320. /*!
  9321. \ingroup IO
  9322. \brief This function gets the statistics for the session.
  9323. \return SSL_SUCCESS returned if the function and subroutines return without
  9324. error. The session stats have been successfully retrieved and printed.
  9325. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9326. was passed an unacceptable argument.
  9327. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9328. \param active a word32 pointer representing the total current sessions.
  9329. \param total a word32 pointer representing the total sessions.
  9330. \param peak a word32 pointer representing the peak sessions.
  9331. \param maxSessions a word32 pointer representing the maximum sessions.
  9332. _Example_
  9333. \code
  9334. int wolfSSL_PrintSessionStats(void){
  9335. ret = wolfSSL_get_session_stats(&totalSessionsNow,
  9336. &totalSessionsSeen, &peak, &maxSessions);
  9337. return ret;
  9338. \endcode
  9339. \sa wolfSSL_PrintSessionStats
  9340. */
  9341. int wolfSSL_get_session_stats(unsigned int* active,
  9342. unsigned int* total,
  9343. unsigned int* peak,
  9344. unsigned int* maxSessions);
  9345. /*!
  9346. \ingroup TLS
  9347. \brief This function copies the values of cr and sr then passes through to
  9348. wc_PRF (pseudo random function) and returns that value.
  9349. \return 0 on success
  9350. \return BUFFER_E returned if there will be an error
  9351. with the size of the buffer.
  9352. \return MEMORY_E returned if a subroutine failed
  9353. to allocate dynamic memory.
  9354. \param ms the master secret held in the Arrays structure.
  9355. \param msLen the length of the master secret.
  9356. \param pms the pre-master secret held in the Arrays structure.
  9357. \param pmsLen the length of the pre-master secret.
  9358. \param cr the client random.
  9359. \param sr the server random.
  9360. \param tls1_2 signifies that the version is at least tls version 1.2.
  9361. \param hash_type signifies the hash type.
  9362. _Example_
  9363. \code
  9364. WOLFSSL* ssl;
  9365. called in MakeTlsMasterSecret and retrieves the necessary
  9366. information as follows:
  9367. int MakeTlsMasterSecret(WOLFSSL* ssl){
  9368. int ret;
  9369. ret = wolfSSL_makeTlsMasterSecret(ssl->arrays->masterSecret, SECRET_LEN,
  9370. ssl->arrays->preMasterSecret, ssl->arrays->preMasterSz,
  9371. ssl->arrays->clientRandom, ssl->arrays->serverRandom,
  9372. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9373. return ret;
  9374. }
  9375. \endcode
  9376. \sa wc_PRF
  9377. \sa MakeTlsMasterSecret
  9378. */
  9379. int wolfSSL_MakeTlsMasterSecret(unsigned char* ms, word32 msLen,
  9380. const unsigned char* pms, word32 pmsLen,
  9381. const unsigned char* cr, const unsigned char* sr,
  9382. int tls1_2, int hash_type);
  9383. /*!
  9384. \ingroup CertsKeys
  9385. \brief An external facing wrapper to derive TLS Keys.
  9386. \return 0 returned on success.
  9387. \return BUFFER_E returned if the sum of labLen and
  9388. seedLen (computes total size) exceeds the maximum size.
  9389. \return MEMORY_E returned if the allocation of memory failed.
  9390. \param key_data a byte pointer that is allocateded in DeriveTlsKeys
  9391. and passed through to wc_PRF to hold the final hash.
  9392. \param keyLen a word32 type that is derived in DeriveTlsKeys
  9393. from the WOLFSSL structure’s specs member.
  9394. \param ms a constant pointer type holding the master secret
  9395. held in the arrays structure within the WOLFSSL structure.
  9396. \param msLen a word32 type that holds the length of the
  9397. master secret in an enumerated define, SECRET_LEN.
  9398. \param sr a constant byte pointer to the serverRandom
  9399. member of the arrays structure within the WOLFSSL structure.
  9400. \param cr a constant byte pointer to the clientRandom
  9401. member of the arrays structure within the WOLFSSL structure.
  9402. \param tls1_2 an integer type returned from IsAtLeastTLSv1_2().
  9403. \param hash_type an integer type held in the WOLFSSL structure.
  9404. _Example_
  9405. \code
  9406. int DeriveTlsKeys(WOLFSSL* ssl){
  9407. int ret;
  9408. ret = wolfSSL_DeriveTlsKeys(key_data, length, ssl->arrays->masterSecret,
  9409. SECRET_LEN, ssl->arrays->clientRandom,
  9410. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9411. }
  9412. \endcode
  9413. \sa wc_PRF
  9414. \sa DeriveTlsKeys
  9415. \sa IsAtLeastTLSv1_2
  9416. */
  9417. int wolfSSL_DeriveTlsKeys(unsigned char* key_data, word32 keyLen,
  9418. const unsigned char* ms, word32 msLen,
  9419. const unsigned char* sr, const unsigned char* cr,
  9420. int tls1_2, int hash_type);
  9421. /*!
  9422. \brief wolfSSL_connect_ex() is an extension that allows
  9423. a HandShake Callback to be set. This can be useful in
  9424. embedded systems for debugging support when a debugger isn’t
  9425. available and sniffing is impractical. The HandShake Callback
  9426. will be called whether or not a handshake error occurred.
  9427. No dynamic memory is used since the maximum number of SSL
  9428. packets is known. Packet names can be accessed through packetNames[].
  9429. The connect extension also allows a Timeout Callback to be set along
  9430. with a timeout value. This is useful if the user doesn’t want
  9431. to wait for the TCP stack to timeout. This extension can be called
  9432. with either, both, or neither callbacks.
  9433. \return SSL_SUCCESS upon success.
  9434. \return GETTIME_ERROR will be returned if gettimeofday()
  9435. encountered an error.
  9436. \return SETITIMER_ERROR will be returned if setitimer()
  9437. encountered an error.
  9438. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9439. \return SSL_FATAL_ERROR will be returned if the underlying SSL_connect()
  9440. call encountered an error.
  9441. \param none No parameters.
  9442. _Example_
  9443. \code
  9444. none
  9445. \endcode
  9446. \sa wolfSSL_accept_ex
  9447. */
  9448. int wolfSSL_connect_ex(WOLFSSL* ssl, HandShakeCallBack hsCb,
  9449. TimeoutCallBack toCb, WOLFSSL_TIMEVAL timeout);
  9450. /*!
  9451. \brief wolfSSL_accept_ex() is an extension that allows a HandShake Callback
  9452. to be set. This can be useful in embedded systems for debugging support
  9453. when a debugger isn’t available and sniffing is impractical. The HandShake
  9454. Callback will be called whether or not a handshake error occurred.
  9455. No dynamic memory is used since the maximum number of SSL packets is known.
  9456. Packet names can be accessed through packetNames[]. The connect extension
  9457. also allows a Timeout Callback to be set along with a timeout value.
  9458. This is useful if the user doesn’t want to wait for the TCP stack to timeout.
  9459. This extension can be called with either, both, or neither callbacks.
  9460. \return SSL_SUCCESS upon success.
  9461. \return GETTIME_ERROR will be returned if gettimeofday()
  9462. encountered an error.
  9463. \return SETITIMER_ERROR will be returned if setitimer()
  9464. encountered an error.
  9465. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9466. \return SSL_FATAL_ERROR will be returned if the underlying
  9467. SSL_accept() call encountered an error.
  9468. \param none No parameters.
  9469. _Example_
  9470. \code
  9471. none
  9472. \endcode
  9473. \sa wolfSSL_connect_ex
  9474. */
  9475. int wolfSSL_accept_ex(WOLFSSL* ssl, HandShakeCallBacki hsCb,
  9476. TimeoutCallBack toCb, WOLFSSL_TIMEVAL timeout);
  9477. /*!
  9478. \ingroup IO
  9479. \brief This is used to set the internal file pointer for a BIO.
  9480. \return SSL_SUCCESS On successfully setting file pointer.
  9481. \return SSL_FAILURE If an error case was encountered.
  9482. \param bio WOLFSSL_BIO structure to set pair.
  9483. \param fp file pointer to set in bio.
  9484. \param c close file behavior flag.
  9485. _Example_
  9486. \code
  9487. WOLFSSL_BIO* bio;
  9488. XFILE fp;
  9489. int ret;
  9490. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9491. ret = wolfSSL_BIO_set_fp(bio, fp, BIO_CLOSE);
  9492. // check ret value
  9493. \endcode
  9494. \sa wolfSSL_BIO_new
  9495. \sa wolfSSL_BIO_s_mem
  9496. \sa wolfSSL_BIO_get_fp
  9497. \sa wolfSSL_BIO_free
  9498. */
  9499. long wolfSSL_BIO_set_fp(WOLFSSL_BIO *bio, XFILE fp, int c);
  9500. /*!
  9501. \ingroup IO
  9502. \brief This is used to get the internal file pointer for a BIO.
  9503. \return SSL_SUCCESS On successfully getting file pointer.
  9504. \return SSL_FAILURE If an error case was encountered.
  9505. \param bio WOLFSSL_BIO structure to set pair.
  9506. \param fp file pointer to set in bio.
  9507. _Example_
  9508. \code
  9509. WOLFSSL_BIO* bio;
  9510. XFILE fp;
  9511. int ret;
  9512. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9513. ret = wolfSSL_BIO_get_fp(bio, &fp);
  9514. // check ret value
  9515. \endcode
  9516. \sa wolfSSL_BIO_new
  9517. \sa wolfSSL_BIO_s_mem
  9518. \sa wolfSSL_BIO_set_fp
  9519. \sa wolfSSL_BIO_free
  9520. */
  9521. long wolfSSL_BIO_get_fp(WOLFSSL_BIO *bio, XFILE* fp);
  9522. /*!
  9523. \ingroup Setup
  9524. \brief This function checks that the private key is a match
  9525. with the certificate being used.
  9526. \return SSL_SUCCESS On successfully match.
  9527. \return SSL_FAILURE If an error case was encountered.
  9528. \return <0 All error cases other than SSL_FAILURE are negative values.
  9529. \param ssl WOLFSSL structure to check.
  9530. _Example_
  9531. \code
  9532. WOLFSSL* ssl;
  9533. int ret;
  9534. // create and set up ssl
  9535. ret = wolfSSL_check_private_key(ssl);
  9536. // check ret value
  9537. \endcode
  9538. \sa wolfSSL_new
  9539. \sa wolfSSL_free
  9540. */
  9541. int wolfSSL_check_private_key(const WOLFSSL* ssl);
  9542. /*!
  9543. \ingroup CertsKeys
  9544. \brief This function looks for and returns the extension index
  9545. matching the passed in NID value.
  9546. \return >= 0 If successful the extension index is returned.
  9547. \return -1 If extension is not found or error is encountered.
  9548. \param x509 certificate to get parse through for extension.
  9549. \param nid extension OID to be found.
  9550. \param lastPos start search from extension after lastPos.
  9551. Set to -1 initially.
  9552. _Example_
  9553. \code
  9554. const WOLFSSL_X509* x509;
  9555. int lastPos = -1;
  9556. int idx;
  9557. idx = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints, lastPos);
  9558. \endcode
  9559. */
  9560. int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509,
  9561. int nid, int lastPos);
  9562. /*!
  9563. \ingroup CertsKeys
  9564. \brief This function looks for and returns the extension
  9565. matching the passed in NID value.
  9566. \return pointer If successful a STACK_OF(WOLFSSL_ASN1_OBJECT)
  9567. pointer is returned.
  9568. \return NULL If extension is not found or error is encountered.
  9569. \param x509 certificate to get parse through for extension.
  9570. \param nid extension OID to be found.
  9571. \param c if not NULL is set to -2 for multiple extensions found -1
  9572. if not found, 0 if found and not critical and 1 if found and critical.
  9573. \param idx if NULL return first extension matched otherwise if not
  9574. stored in x509 start at idx.
  9575. _Example_
  9576. \code
  9577. const WOLFSSL_X509* x509;
  9578. int c;
  9579. int idx = 0;
  9580. STACK_OF(WOLFSSL_ASN1_OBJECT)* sk;
  9581. sk = wolfSSL_X509_get_ext_d2i(x509, NID_basic_constraints, &c, &idx);
  9582. //check sk for NULL and then use it. sk needs freed after done.
  9583. \endcode
  9584. \sa wolfSSL_sk_ASN1_OBJECT_free
  9585. */
  9586. void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509,
  9587. int nid, int* c, int* idx);
  9588. /*!
  9589. \ingroup CertsKeys
  9590. \brief This function returns the hash of the DER certificate.
  9591. \return SSL_SUCCESS On successfully creating a hash.
  9592. \return SSL_FAILURE Returned on bad input or unsuccessful hash.
  9593. \param x509 certificate to get the hash of.
  9594. \param digest the hash algorithm to use.
  9595. \param buf buffer to hold hash.
  9596. \param len length of buffer.
  9597. _Example_
  9598. \code
  9599. WOLFSSL_X509* x509;
  9600. unsigned char buffer[64];
  9601. unsigned int bufferSz;
  9602. int ret;
  9603. ret = wolfSSL_X509_digest(x509, wolfSSL_EVP_sha256(), buffer, &bufferSz);
  9604. //check ret value
  9605. \endcode
  9606. \sa none
  9607. */
  9608. int wolfSSL_X509_digest(const WOLFSSL_X509* x509,
  9609. const WOLFSSL_EVP_MD* digest, unsigned char* buf, unsigned int* len);
  9610. /*!
  9611. \ingroup Setup
  9612. \brief his is used to set the certificate for WOLFSSL structure to use
  9613. during a handshake.
  9614. \return SSL_SUCCESS On successful setting argument.
  9615. \return SSL_FAILURE If a NULL argument passed in.
  9616. \param ssl WOLFSSL structure to set certificate in.
  9617. \param x509 certificate to use.
  9618. _Example_
  9619. \code WOLFSSL* ssl;
  9620. WOLFSSL_X509* x509
  9621. int ret;
  9622. // create ssl object and x509
  9623. ret = wolfSSL_use_certificate(ssl, x509);
  9624. // check ret value
  9625. \endcode
  9626. \sa wolfSSL_new
  9627. \sa wolfSSL_free
  9628. */
  9629. int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509);
  9630. /*!
  9631. \ingroup Setup
  9632. \brief This is used to set the certificate for WOLFSSL structure
  9633. to use during a handshake. A DER formatted buffer is expected.
  9634. \return SSL_SUCCESS On successful setting argument.
  9635. \return SSL_FAILURE If a NULL argument passed in.
  9636. \param ssl WOLFSSL structure to set certificate in.
  9637. \param der DER certificate to use.
  9638. \param derSz size of the DER buffer passed in.
  9639. _Example_
  9640. \code
  9641. WOLFSSL* ssl;
  9642. unsigned char* der;
  9643. int derSz;
  9644. int ret;
  9645. // create ssl object and set DER variables
  9646. ret = wolfSSL_use_certificate_ASN1(ssl, der, derSz);
  9647. // check ret value
  9648. \endcode
  9649. \sa wolfSSL_new
  9650. \sa wolfSSL_free
  9651. */
  9652. int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, unsigned char* der,
  9653. int derSz);
  9654. /*!
  9655. \ingroup CertsKeys
  9656. \brief This is used to set the private key for the WOLFSSL structure.
  9657. \return SSL_SUCCESS On successful setting argument.
  9658. \return SSL_FAILURE If a NULL ssl passed in. All error
  9659. cases will be negative values.
  9660. \param ssl WOLFSSL structure to set argument in.
  9661. \param pkey private key to use.
  9662. _Example_
  9663. \code
  9664. WOLFSSL* ssl;
  9665. WOLFSSL_EVP_PKEY* pkey;
  9666. int ret;
  9667. // create ssl object and set up private key
  9668. ret = wolfSSL_use_PrivateKey(ssl, pkey);
  9669. // check ret value
  9670. \endcode
  9671. \sa wolfSSL_new
  9672. \sa wolfSSL_free
  9673. */
  9674. int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey);
  9675. /*!
  9676. \ingroup CertsKeys
  9677. \brief This is used to set the private key for the WOLFSSL
  9678. structure. A DER formatted key buffer is expected.
  9679. \return SSL_SUCCESS On successful setting parsing and
  9680. setting the private key.
  9681. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  9682. will be negative values.
  9683. \param pri type of private key.
  9684. \param ssl WOLFSSL structure to set argument in.
  9685. \param der buffer holding DER key.
  9686. \param derSz size of der buffer.
  9687. _Example_
  9688. \code
  9689. WOLFSSL* ssl;
  9690. unsigned char* pkey;
  9691. long pkeySz;
  9692. int ret;
  9693. // create ssl object and set up private key
  9694. ret = wolfSSL_use_PrivateKey_ASN1(1, ssl, pkey, pkeySz);
  9695. // check ret value
  9696. \endcode
  9697. \sa wolfSSL_new
  9698. \sa wolfSSL_free
  9699. \sa wolfSSL_use_PrivateKey
  9700. */
  9701. int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl,
  9702. unsigned char* der, long derSz);
  9703. /*!
  9704. \ingroup CertsKeys
  9705. \brief This is used to set the private key for the WOLFSSL
  9706. structure. A DER formatted RSA key buffer is expected.
  9707. \return SSL_SUCCESS On successful setting parsing and setting
  9708. the private key.
  9709. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  9710. will be negative values.
  9711. \param ssl WOLFSSL structure to set argument in.
  9712. \param der buffer holding DER key.
  9713. \param derSz size of der buffer.
  9714. _Example_
  9715. \code
  9716. WOLFSSL* ssl;
  9717. unsigned char* pkey;
  9718. long pkeySz;
  9719. int ret;
  9720. // create ssl object and set up RSA private key
  9721. ret = wolfSSL_use_RSAPrivateKey_ASN1(ssl, pkey, pkeySz);
  9722. // check ret value
  9723. \endcode
  9724. \sa wolfSSL_new
  9725. \sa wolfSSL_free
  9726. \sa wolfSSL_use_PrivateKey
  9727. */
  9728. int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, unsigned char* der,
  9729. long derSz);
  9730. /*!
  9731. \ingroup CertsKeys
  9732. \brief This function duplicates the parameters in dsa to a
  9733. newly created WOLFSSL_DH structure.
  9734. \return WOLFSSL_DH If duplicated returns WOLFSSL_DH structure
  9735. \return NULL upon failure
  9736. \param dsa WOLFSSL_DSA structure to duplicate.
  9737. _Example_
  9738. \code
  9739. WOLFSSL_DH* dh;
  9740. WOLFSSL_DSA* dsa;
  9741. // set up dsa
  9742. dh = wolfSSL_DSA_dup_DH(dsa);
  9743. // check dh is not null
  9744. \endcode
  9745. \sa none
  9746. */
  9747. WOLFSSL_DH *wolfSSL_DSA_dup_DH(const WOLFSSL_DSA *r);
  9748. /*!
  9749. \ingroup Setup
  9750. \brief This is used to get the master key after completing a handshake.
  9751. \return >0 On successfully getting data returns a value greater than 0
  9752. \return 0 If no random data buffer or an error state returns 0
  9753. \return max If outSz passed in is 0 then the maximum buffer
  9754. size needed is returned
  9755. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  9756. \param out buffer to hold data.
  9757. \param outSz size of out buffer passed in. (if 0 function will
  9758. return max buffer size needed)
  9759. _Example_
  9760. \code
  9761. WOLFSSL_SESSION ssl;
  9762. unsigned char* buffer;
  9763. size_t bufferSz;
  9764. size_t ret;
  9765. // complete handshake and get session structure
  9766. bufferSz = wolfSSL_SESSION_get_master_secret(ses, NULL, 0);
  9767. buffer = malloc(bufferSz);
  9768. ret = wolfSSL_SESSION_get_master_secret(ses, buffer, bufferSz);
  9769. // check ret value
  9770. \endcode
  9771. \sa wolfSSL_new
  9772. \sa wolfSSL_free
  9773. */
  9774. int wolfSSL_SESSION_get_master_key(const WOLFSSL_SESSION* ses,
  9775. unsigned char* out, int outSz);
  9776. /*!
  9777. \ingroup Setup
  9778. \brief This is used to get the master secret key length.
  9779. \return size Returns master secret key size.
  9780. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  9781. _Example_
  9782. \code
  9783. WOLFSSL_SESSION ssl;
  9784. unsigned char* buffer;
  9785. size_t bufferSz;
  9786. size_t ret;
  9787. // complete handshake and get session structure
  9788. bufferSz = wolfSSL_SESSION_get_master_secret_length(ses);
  9789. buffer = malloc(bufferSz);
  9790. // check ret value
  9791. \endcode
  9792. \sa wolfSSL_new
  9793. \sa wolfSSL_free
  9794. */
  9795. int wolfSSL_SESSION_get_master_key_length(const WOLFSSL_SESSION* ses);
  9796. /*!
  9797. \ingroup Setup
  9798. \brief This is a setter function for the WOLFSSL_X509_STORE
  9799. structure in ctx.
  9800. \return none No return.
  9801. \param ctx pointer to the WOLFSSL_CTX structure for setting
  9802. cert store pointer.
  9803. \param str pointer to the WOLFSSL_X509_STORE to set in ctx.
  9804. _Example_
  9805. \code
  9806. WOLFSSL_CTX ctx;
  9807. WOLFSSL_X509_STORE* st;
  9808. // setup ctx and st
  9809. st = wolfSSL_CTX_set_cert_store(ctx, st);
  9810. //use st
  9811. \endcode
  9812. \sa wolfSSL_CTX_new
  9813. \sa wolfSSL_CTX_free
  9814. */
  9815. void wolfSSL_CTX_set_cert_store(WOLFSSL_CTX* ctx,
  9816. WOLFSSL_X509_STORE* str);
  9817. /*!
  9818. \ingroup CertsKeys
  9819. \brief This function get the DER buffer from bio and converts it
  9820. to a WOLFSSL_X509 structure.
  9821. \return pointer returns a WOLFSSL_X509 structure pointer on success.
  9822. \return Null returns NULL on failure
  9823. \param bio pointer to the WOLFSSL_BIO structure that has the DER
  9824. certificate buffer.
  9825. \param x509 pointer that get set to new WOLFSSL_X509 structure created.
  9826. _Example_
  9827. \code
  9828. WOLFSSL_BIO* bio;
  9829. WOLFSSL_X509* x509;
  9830. // load DER into bio
  9831. x509 = wolfSSL_d2i_X509_bio(bio, NULL);
  9832. Or
  9833. wolfSSL_d2i_X509_bio(bio, &x509);
  9834. // use x509 returned (check for NULL)
  9835. \endcode
  9836. \sa none
  9837. */
  9838. WOLFSSL_X509* wolfSSL_d2i_X509_bio(WOLFSSL_BIO* bio, WOLFSSL_X509** x509);
  9839. /*!
  9840. \ingroup Setup
  9841. \brief This is a getter function for the WOLFSSL_X509_STORE
  9842. structure in ctx.
  9843. \return WOLFSSL_X509_STORE* On successfully getting the pointer.
  9844. \return NULL Returned if NULL arguments are passed in.
  9845. \param ctx pointer to the WOLFSSL_CTX structure for getting cert
  9846. store pointer.
  9847. _Example_
  9848. \code
  9849. WOLFSSL_CTX ctx;
  9850. WOLFSSL_X509_STORE* st;
  9851. // setup ctx
  9852. st = wolfSSL_CTX_get_cert_store(ctx);
  9853. //use st
  9854. \endcode
  9855. \sa wolfSSL_CTX_new
  9856. \sa wolfSSL_CTX_free
  9857. \sa wolfSSL_CTX_set_cert_store
  9858. */
  9859. WOLFSSL_X509_STORE* wolfSSL_CTX_get_cert_store(WOLFSSL_CTX* ctx);
  9860. /*!
  9861. \ingroup IO
  9862. \brief Gets the number of pending bytes to read. If BIO type is BIO_BIO
  9863. then is the number to read from pair. If BIO contains an SSL object then
  9864. is pending data from SSL object (wolfSSL_pending(ssl)). If is BIO_MEMORY
  9865. type then returns the size of memory buffer.
  9866. \return >=0 number of pending bytes.
  9867. \param bio pointer to the WOLFSSL_BIO structure that has already
  9868. been created.
  9869. _Example_
  9870. \code
  9871. WOLFSSL_BIO* bio;
  9872. int pending;
  9873. bio = wolfSSL_BIO_new();
  9874. pending = wolfSSL_BIO_ctrl_pending(bio);
  9875. \endcode
  9876. \sa wolfSSL_BIO_make_bio_pair
  9877. \sa wolfSSL_BIO_new
  9878. */
  9879. size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *b);
  9880. /*!
  9881. \ingroup Setup
  9882. \brief This is used to get the random data sent by the server
  9883. during the handshake.
  9884. \return >0 On successfully getting data returns a value greater than 0
  9885. \return 0 If no random data buffer or an error state returns 0
  9886. \return max If outSz passed in is 0 then the maximum buffer size
  9887. needed is returned
  9888. \param ssl WOLFSSL structure to get clients random data buffer from.
  9889. \param out buffer to hold random data.
  9890. \param outSz size of out buffer passed in. (if 0 function will return max
  9891. buffer size needed)
  9892. _Example_
  9893. \code
  9894. WOLFSSL ssl;
  9895. unsigned char* buffer;
  9896. size_t bufferSz;
  9897. size_t ret;
  9898. bufferSz = wolfSSL_get_server_random(ssl, NULL, 0);
  9899. buffer = malloc(bufferSz);
  9900. ret = wolfSSL_get_server_random(ssl, buffer, bufferSz);
  9901. // check ret value
  9902. \endcode
  9903. \sa wolfSSL_new
  9904. \sa wolfSSL_free
  9905. */
  9906. size_t wolfSSL_get_server_random(const WOLFSSL *ssl,
  9907. unsigned char *out, size_t outlen);
  9908. /*!
  9909. \ingroup Setup
  9910. \brief This is used to get the random data sent by the client during
  9911. the handshake.
  9912. \return >0 On successfully getting data returns a value greater than 0
  9913. \return 0 If no random data buffer or an error state returns 0
  9914. \return max If outSz passed in is 0 then the maximum buffer size needed
  9915. is returned
  9916. \param ssl WOLFSSL structure to get clients random data buffer from.
  9917. \param out buffer to hold random data.
  9918. \param outSz size of out buffer passed in. (if 0 function will return max
  9919. buffer size needed)
  9920. _Example_
  9921. \code
  9922. WOLFSSL ssl;
  9923. unsigned char* buffer;
  9924. size_t bufferSz;
  9925. size_t ret;
  9926. bufferSz = wolfSSL_get_client_random(ssl, NULL, 0);
  9927. buffer = malloc(bufferSz);
  9928. ret = wolfSSL_get_client_random(ssl, buffer, bufferSz);
  9929. // check ret value
  9930. \endcode
  9931. \sa wolfSSL_new
  9932. \sa wolfSSL_free
  9933. */
  9934. size_t wolfSSL_get_client_random(const WOLFSSL* ssl,
  9935. unsigned char* out, size_t outSz);
  9936. /*!
  9937. \ingroup Setup
  9938. \brief This is a getter function for the password callback set in ctx.
  9939. \return func On success returns the callback function.
  9940. \return NULL If ctx is NULL then NULL is returned.
  9941. \param ctx WOLFSSL_CTX structure to get call back from.
  9942. _Example_
  9943. \code
  9944. WOLFSSL_CTX* ctx;
  9945. wc_pem_password_cb cb;
  9946. // setup ctx
  9947. cb = wolfSSL_CTX_get_default_passwd_cb(ctx);
  9948. //use cb
  9949. \endcode
  9950. \sa wolfSSL_CTX_new
  9951. \sa wolfSSL_CTX_free
  9952. */
  9953. wc_pem_password_cb* wolfSSL_CTX_get_default_passwd_cb(WOLFSSL_CTX*
  9954. ctx);
  9955. /*!
  9956. \ingroup Setup
  9957. \brief This is a getter function for the password callback user
  9958. data set in ctx.
  9959. \return pointer On success returns the user data pointer.
  9960. \return NULL If ctx is NULL then NULL is returned.
  9961. \param ctx WOLFSSL_CTX structure to get user data from.
  9962. _Example_
  9963. \code
  9964. WOLFSSL_CTX* ctx;
  9965. void* data;
  9966. // setup ctx
  9967. data = wolfSSL_CTX_get_default_passwd_cb(ctx);
  9968. //use data
  9969. \endcode
  9970. \sa wolfSSL_CTX_new
  9971. \sa wolfSSL_CTX_free
  9972. */
  9973. void *wolfSSL_CTX_get_default_passwd_cb_userdata(WOLFSSL_CTX *ctx);
  9974. /*!
  9975. \ingroup CertsKeys
  9976. \brief This function behaves the same as wolfSSL_PEM_read_bio_X509.
  9977. AUX signifies containing extra information such as trusted/rejected use
  9978. cases and friendly name for human readability.
  9979. \return WOLFSSL_X509 on successfully parsing the PEM buffer a WOLFSSL_X509
  9980. structure is returned.
  9981. \return Null if failed to parse PEM buffer.
  9982. \param bp WOLFSSL_BIO structure to get PEM buffer from.
  9983. \param x if setting WOLFSSL_X509 by function side effect.
  9984. \param cb password callback.
  9985. \param u NULL terminated user password.
  9986. _Example_
  9987. \code
  9988. WOLFSSL_BIO* bio;
  9989. WOLFSSL_X509* x509;
  9990. // setup bio
  9991. X509 = wolfSSL_PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
  9992. //check x509 is not null and then use it
  9993. \endcode
  9994. \sa wolfSSL_PEM_read_bio_X509
  9995. */
  9996. WOLFSSL_X509 *wolfSSL_PEM_read_bio_X509_AUX
  9997. (WOLFSSL_BIO *bp, WOLFSSL_X509 **x, wc_pem_password_cb *cb, void *u);
  9998. /*!
  9999. \ingroup CertsKeys
  10000. \brief Initializes the WOLFSSL_CTX structure’s dh member with the
  10001. Diffie-Hellman parameters.
  10002. \return SSL_SUCCESS returned if the function executed successfully.
  10003. \return BAD_FUNC_ARG returned if the ctx or dh structures are NULL.
  10004. \return SSL_FATAL_ERROR returned if there was an error setting a
  10005. structure value.
  10006. \return MEMORY_E returned if their was a failure to allocate memory.
  10007. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  10008. wolfSSL_CTX_new().
  10009. \param dh a pointer to a WOLFSSL_DH structure.
  10010. _Example_
  10011. \code
  10012. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10013. WOLFSSL_DH* dh;
  10014. return wolfSSL_CTX_set_tmp_dh(ctx, dh);
  10015. \endcode
  10016. \sa wolfSSL_BN_bn2bin
  10017. */
  10018. long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh);
  10019. /*!
  10020. \ingroup CertsKeys
  10021. \brief This function get the DSA parameters from a PEM buffer in bio.
  10022. \return WOLFSSL_DSA on successfully parsing the PEM buffer a WOLFSSL_DSA
  10023. structure is created and returned.
  10024. \return Null if failed to parse PEM buffer.
  10025. \param bio pointer to the WOLFSSL_BIO structure for getting PEM
  10026. memory pointer.
  10027. \param x pointer to be set to new WOLFSSL_DSA structure.
  10028. \param cb password callback function.
  10029. \param u null terminated password string.
  10030. _Example_
  10031. \code
  10032. WOLFSSL_BIO* bio;
  10033. WOLFSSL_DSA* dsa;
  10034. // setup bio
  10035. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  10036. // check dsa is not NULL and then use dsa
  10037. \endcode
  10038. \sa none
  10039. */
  10040. WOLFSSL_DSA *wolfSSL_PEM_read_bio_DSAparams(WOLFSSL_BIO *bp,
  10041. WOLFSSL_DSA **x, wc_pem_password_cb *cb, void *u);
  10042. /*!
  10043. \ingroup Debug
  10044. \brief This function returns the absolute value of the last error from
  10045. WOLFSSL_ERROR encountered.
  10046. \return error Returns absolute value of last error.
  10047. \param none No parameters.
  10048. _Example_
  10049. \code
  10050. unsigned long err;
  10051. ...
  10052. err = wolfSSL_ERR_peek_last_error();
  10053. // inspect err value
  10054. \endcode
  10055. \sa wolfSSL_ERR_print_errors_fp
  10056. */
  10057. unsigned long wolfSSL_ERR_peek_last_error(void);
  10058. /*!
  10059. \ingroup CertsKeys
  10060. \brief This function gets the peer’s certificate chain.
  10061. \return pointer returns a pointer to the peer’s Certificate stack.
  10062. \return NULL returned if no peer certificate.
  10063. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10064. _Example_
  10065. \code
  10066. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  10067. WOLFSSL* ssl = wolfSSL_new(ctx);
  10068. ...
  10069. wolfSSL_connect(ssl);
  10070. STACK_OF(WOLFSSL_X509)* chain = wolfSSL_get_peer_cert_chain(ssl);
  10071. ifchain){
  10072. // You have a pointer to the peer certificate chain
  10073. }
  10074. \endcode
  10075. \sa wolfSSL_X509_get_issuer_name
  10076. \sa wolfSSL_X509_get_subject_name
  10077. \sa wolfSSL_X509_get_isCA
  10078. */
  10079. WOLF_STACK_OF(WOLFSSL_X509)* wolfSSL_get_peer_cert_chain(const WOLFSSL*);
  10080. /*!
  10081. \ingroup Setup
  10082. \brief This function resets option bits of WOLFSSL_CTX object.
  10083. \return option new option bits
  10084. \param ctx pointer to the SSL context.
  10085. _Example_
  10086. \code
  10087. WOLFSSL_CTX* ctx = 0;
  10088. ...
  10089. wolfSSL_CTX_clear_options(ctx, SSL_OP_NO_TLSv1);
  10090. \endcode
  10091. \sa wolfSSL_CTX_new
  10092. \sa wolfSSL_new
  10093. \sa wolfSSL_free
  10094. */
  10095. long wolfSSL_CTX_clear_options(WOLFSSL_CTX* ctx, long opt);
  10096. /*!
  10097. \ingroup IO
  10098. \brief This function sets the jObjectRef member of the WOLFSSL structure.
  10099. \return SSL_SUCCESS returned if jObjectRef is properly set to objPtr.
  10100. \return SSL_FAILURE returned if the function did not properly execute and
  10101. jObjectRef is not set.
  10102. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10103. \param objPtr a void pointer that will be set to jObjectRef.
  10104. _Example_
  10105. \code
  10106. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10107. WOLFSSL* ssl = WOLFSSL_new();
  10108. void* objPtr = &obj;
  10109. ...
  10110. if(wolfSSL_set_jobject(ssl, objPtr)){
  10111. // The success case
  10112. }
  10113. \endcode
  10114. \sa wolfSSL_get_jobject
  10115. */
  10116. int wolfSSL_set_jobject(WOLFSSL* ssl, void* objPtr);
  10117. /*!
  10118. \ingroup IO
  10119. \brief This function returns the jObjectRef member of the WOLFSSL structure.
  10120. \return value If the WOLFSSL struct is not NULL, the function returns the
  10121. jObjectRef value.
  10122. \return NULL returned if the WOLFSSL struct is NULL.
  10123. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10124. _Example_
  10125. \code
  10126. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10127. WOLFSSL* ssl = wolfSSL(ctx);
  10128. ...
  10129. void* jobject = wolfSSL_get_jobject(ssl);
  10130. if(jobject != NULL){
  10131. // Success case
  10132. }
  10133. \endcode
  10134. \sa wolfSSL_set_jobject
  10135. */
  10136. void* wolfSSL_get_jobject(WOLFSSL* ssl);
  10137. /*!
  10138. \ingroup Setup
  10139. \brief This function sets a callback in the ssl. The callback is to
  10140. observe handshake messages. NULL value of cb resets the callback.
  10141. \return SSL_SUCCESS On success.
  10142. \return SSL_FAILURE If an NULL ssl passed in.
  10143. \param ssl WOLFSSL structure to set callback argument.
  10144. _Example_
  10145. \code
  10146. static cb(int write_p, int version, int content_type,
  10147. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  10148. WOLFSSL* ssl;
  10149. ret = wolfSSL_set_msg_callback(ssl, cb);
  10150. // check ret
  10151. \endcode
  10152. \sa wolfSSL_set_msg_callback_arg
  10153. */
  10154. int wolfSSL_set_msg_callback(WOLFSSL *ssl, SSL_Msg_Cb cb);
  10155. /*!
  10156. \ingroup Setup
  10157. \brief This function sets associated callback context value in the ssl.
  10158. The value is handed over to the callback argument.
  10159. \return none No return.
  10160. \param ssl WOLFSSL structure to set callback argument.
  10161. _Example_
  10162. \code
  10163. static cb(int write_p, int version, int content_type,
  10164. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  10165. WOLFSSL* ssl;
  10166. ret = wolfSSL_set_msg_callback(ssl, cb);
  10167. // check ret
  10168. wolfSSL_set_msg_callback(ssl, arg);
  10169. \endcode
  10170. \sa wolfSSL_set_msg_callback
  10171. */
  10172. int wolfSSL_set_msg_callback_arg(WOLFSSL *ssl, void* arg);
  10173. /*!
  10174. \ingroup CertsKeys
  10175. \brief This function returns the next, if any, altname from the peer certificate.
  10176. \return NULL if there is not a next altname.
  10177. \return cert->altNamesNext->name from the WOLFSSL_X509 structure that is a
  10178. string value from the altName list is returned if it exists.
  10179. \param cert a pointer to the wolfSSL_X509 structure.
  10180. _Example_
  10181. \code
  10182. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  10183. DYNAMIC_TYPE_X509);
  10184. int x509NextAltName = wolfSSL_X509_get_next_altname(x509);
  10185. if(x509NextAltName == NULL){
  10186. //There isn’t another alt name
  10187. }
  10188. \endcode
  10189. \sa wolfSSL_X509_get_issuer_name
  10190. \sa wolfSSL_X509_get_subject_name
  10191. */
  10192. char* wolfSSL_X509_get_next_altname(WOLFSSL_X509*);
  10193. /*!
  10194. \ingroup CertsKeys
  10195. \brief The function checks to see if x509 is NULL and if it’s not, it
  10196. returns the notBefore member of the x509 struct.
  10197. \return pointer to struct with ASN1_TIME to the notBefore
  10198. member of the x509 struct.
  10199. \return NULL the function returns NULL if the x509 structure is NULL.
  10200. \param x509 a pointer to the WOLFSSL_X509 struct.
  10201. _Example_
  10202. \code
  10203. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  10204. DYNAMIC_TYPE_X509) ;
  10205. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notBefore(x509);
  10206. if(notAfter == NULL){
  10207. //The x509 object was NULL
  10208. }
  10209. \endcode
  10210. \sa wolfSSL_X509_get_notAfter
  10211. */
  10212. WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notBefore(WOLFSSL_X509*);
  10213. /*!
  10214. \ingroup IO
  10215. \brief This function is called on the client side and initiates an SSL/TLS
  10216. handshake with a server. When this function is called, the underlying
  10217. communication channel has already been set up.
  10218. wolfSSL_connect() works with both blocking and non-blocking I/O. When the
  10219. underlying I/O is non-blocking, wolfSSL_connect() will return when the
  10220. underlying I/O could not satisfy the needs of wolfSSL_connect to continue
  10221. the handshake. In this case, a call to wolfSSL_get_error() will yield
  10222. either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process
  10223. must then repeat the call to wolfSSL_connect() when the underlying I/O is
  10224. ready and wolfSSL will pick up where it left off. When using a non-blocking
  10225. socket, nothing needs to be done, but select() can be used to check for the
  10226. required condition.
  10227. If the underlying I/O is blocking, wolfSSL_connect() will only return once
  10228. the handshake has been finished or an error occurred.
  10229. wolfSSL takes a different approach to certificate verification than OpenSSL
  10230. does. The default policy for the client is to verify the server, this
  10231. means that if you don't load CAs to verify the server you'll get a connect
  10232. error, unable to verify (-155). It you want to mimic OpenSSL behavior of
  10233. having SSL_connect succeed even if verifying the server fails and reducing
  10234. security you can do this by calling:
  10235. SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling SSL_new();
  10236. Though it's not recommended.
  10237. \return SSL_SUCCESS If successful.
  10238. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10239. more detailed error code, call wolfSSL_get_error().
  10240. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10241. _Example_
  10242. \code
  10243. int ret = 0;
  10244. int err = 0;
  10245. WOLFSSL* ssl;
  10246. char buffer[80];
  10247. ...
  10248. ret = wolfSSL_connect(ssl);
  10249. if (ret != SSL_SUCCESS) {
  10250. err = wolfSSL_get_error(ssl, ret);
  10251. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10252. }
  10253. \endcode
  10254. \sa wolfSSL_get_error
  10255. \sa wolfSSL_accept
  10256. */
  10257. int wolfSSL_connect(WOLFSSL* ssl);
  10258. /*!
  10259. \ingroup Setup
  10260. \brief This function is called on the server side to indicate that a
  10261. HelloRetryRequest message must contain a Cookie.
  10262. The Cookie holds a hash of the current transcript so that another server
  10263. process can handle the ClientHello in reply.
  10264. The secret is used when generting the integrity check on the Cookie data.
  10265. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10266. \param [in] secret a pointer to a buffer holding the secret.
  10267. Passing NULL indicates to generate a new random secret.
  10268. \param [in] secretSz Size of the secret in bytes.
  10269. Passing 0 indicates to use the default size: WC_SHA256_DIGEST_SIZE (or WC_SHA_DIGEST_SIZE when SHA-256 not available).
  10270. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10271. \return SIDE_ERROR if called with a client.
  10272. \return WOLFSSL_SUCCESS if succesful.
  10273. \return MEMORY_ERROR if allocating dynamic memory for storing secret failed.
  10274. \return Another -ve value on internal error.
  10275. _Example_
  10276. \code
  10277. int ret;
  10278. WOLFSSL* ssl;
  10279. char secret[32];
  10280. ...
  10281. ret = wolfSSL__send_hrr_cookie(ssl, secret, sizeof(secret));
  10282. if (ret != WOLFSSL_SUCCESS) {
  10283. // failed to set use of Cookie and secret
  10284. }
  10285. \endcode
  10286. \sa wolfSSL_new
  10287. */
  10288. int wolfSSL_send_hrr_cookie(WOLFSSL* ssl,
  10289. const unsigned char* secret, unsigned int secretSz);
  10290. /*!
  10291. \ingroup Setup
  10292. \brief This function is called on the server to stop it from sending
  10293. a resumption session ticket once the handshake is complete.
  10294. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10295. with wolfSSL_CTX_new().
  10296. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10297. \return SIDE_ERROR if called with a client.
  10298. \return 0 if successful.
  10299. _Example_
  10300. \code
  10301. int ret;
  10302. WOLFSSL_CTX* ctx;
  10303. ...
  10304. ret = wolfSSL_CTX_no_ticket_TLSv13(ctx);
  10305. if (ret != 0) {
  10306. // failed to set no ticket
  10307. }
  10308. \endcode
  10309. \sa wolfSSL_no_ticket_TLSv13
  10310. */
  10311. int wolfSSL_CTX_no_ticket_TLSv13(WOLFSSL_CTX* ctx);
  10312. /*!
  10313. \ingroup Setup
  10314. \brief This function is called on the server to stop it from sending
  10315. a resumption session ticket once the handshake is complete.
  10316. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10317. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10318. \return SIDE_ERROR if called with a client.
  10319. \return 0 if successful.
  10320. _Example_
  10321. \code
  10322. int ret;
  10323. WOLFSSL* ssl;
  10324. ...
  10325. ret = wolfSSL_no_ticket_TLSv13(ssl);
  10326. if (ret != 0) {
  10327. // failed to set no ticket
  10328. }
  10329. \endcode
  10330. \sa wolfSSL_CTX_no_ticket_TLSv13
  10331. */
  10332. int wolfSSL_no_ticket_TLSv13(WOLFSSL* ssl);
  10333. /*!
  10334. \ingroup Setup
  10335. \brief This function is called on a TLS v1.3 wolfSSL context to disallow
  10336. Diffie-Hellman (DH) style key exchanges when handshakes are using
  10337. pre-shared keys for authentication.
  10338. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10339. with wolfSSL_CTX_new().
  10340. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10341. \return 0 if successful.
  10342. _Example_
  10343. \code
  10344. int ret;
  10345. WOLFSSL_CTX* ctx;
  10346. ...
  10347. ret = wolfSSL_CTX_no_dhe_psk(ctx);
  10348. if (ret != 0) {
  10349. // failed to set no DHE for PSK handshakes
  10350. }
  10351. \endcode
  10352. \sa wolfSSL_no_dhe_psk
  10353. */
  10354. int wolfSSL_CTX_no_dhe_psk(WOLFSSL_CTX* ctx);
  10355. /*!
  10356. \ingroup Setup
  10357. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10358. disallow Diffie-Hellman (DH) style key exchanges when handshakes are using
  10359. pre-shared keys for authentication.
  10360. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10361. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10362. \return 0 if successful.
  10363. _Example_
  10364. \code
  10365. int ret;
  10366. WOLFSSL* ssl;
  10367. ...
  10368. ret = wolfSSL_no_dhe_psk(ssl);
  10369. if (ret != 0) {
  10370. // failed to set no DHE for PSK handshakes
  10371. }
  10372. \endcode
  10373. \sa wolfSSL_CTX_no_dhe_psk
  10374. */
  10375. int wolfSSL_no_dhe_psk(WOLFSSL* ssl);
  10376. /*!
  10377. \ingroup IO
  10378. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10379. force the rollover of keys. A KeyUpdate message is sent to the peer and
  10380. new keys are calculated for encryption. The peer will send back a KeyUpdate
  10381. message and the new decryption keys wil then be calculated.
  10382. This function can only be called after a handshake has been completed.
  10383. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10384. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10385. \return WANT_WRITE if the writing is not ready.
  10386. \return WOLFSSL_SUCCESS if successful.
  10387. _Example_
  10388. \code
  10389. int ret;
  10390. WOLFSSL* ssl;
  10391. ...
  10392. ret = wolfSSL_update_keys(ssl);
  10393. if (ret == WANT_WRITE) {
  10394. // need to call again when I/O ready
  10395. }
  10396. else if (ret != WOLFSSL_SUCCESS) {
  10397. // failed to send key update
  10398. }
  10399. \endcode
  10400. \sa wolfSSL_write
  10401. */
  10402. int wolfSSL_update_keys(WOLFSSL* ssl);
  10403. /*!
  10404. \ingroup IO
  10405. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10406. determine whether a rollover of keys is in progress. When
  10407. wolfSSL_update_keys() is called, a KeyUpdate message is sent and the
  10408. encryption key is updated. The decryption key is updated when the response
  10409. is received.
  10410. \param [in] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10411. \param [out] required 0 when no key update response required. 1 when no key update response required.
  10412. \return 0 on successful.
  10413. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10414. _Example_
  10415. \code
  10416. int ret;
  10417. WOLFSSL* ssl;
  10418. int required;
  10419. ...
  10420. ret = wolfSSL_key_update_response(ssl, &required);
  10421. if (ret != 0) {
  10422. // bad parameters
  10423. }
  10424. if (required) {
  10425. // encrypt Key updated, awaiting response to change decrypt key
  10426. }
  10427. \endcode
  10428. \sa wolfSSL_update_keys
  10429. */
  10430. int wolfSSL_key_update_response(WOLFSSL* ssl, int* required);
  10431. /*!
  10432. \ingroup Setup
  10433. \brief This function is called on a TLS v1.3 client wolfSSL context to allow
  10434. a client certifcate to be sent post handshake upon request from server.
  10435. This is useful when connecting to a web server that has some pages that
  10436. require client authentication and others that don't.
  10437. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10438. with wolfSSL_CTX_new().
  10439. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10440. \return SIDE_ERROR if called with a server.
  10441. \return 0 if successful.
  10442. _Example_
  10443. \code
  10444. int ret;
  10445. WOLFSSL_CTX* ctx;
  10446. ...
  10447. ret = wolfSSL_allow_post_handshake_auth(ctx);
  10448. if (ret != 0) {
  10449. // failed to allow post handshake authentication
  10450. }
  10451. \endcode
  10452. \sa wolfSSL_allow_post_handshake_auth
  10453. \sa wolfSSL_request_certificate
  10454. */
  10455. int wolfSSL_CTX_allow_post_handshake_auth(WOLFSSL_CTX* ctx);
  10456. /*!
  10457. \ingroup Setup
  10458. \brief This function is called on a TLS v1.3 client wolfSSL to allow
  10459. a client certifcate to be sent post handshake upon request from server.
  10460. A Post-Handshake Client Authentication extension is sent in the ClientHello.
  10461. This is useful when connecting to a web server that has some pages that
  10462. require client authentication and others that don't.
  10463. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10464. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10465. \return SIDE_ERROR if called with a server.
  10466. \return 0 if successful.
  10467. _Example_
  10468. \code
  10469. int ret;
  10470. WOLFSSL* ssl;
  10471. ...
  10472. ret = wolfSSL_allow_post_handshake_auth(ssl);
  10473. if (ret != 0) {
  10474. // failed to allow post handshake authentication
  10475. }
  10476. \endcode
  10477. \sa wolfSSL_CTX_allow_post_handshake_auth
  10478. \sa wolfSSL_request_certificate
  10479. */
  10480. int wolfSSL_allow_post_handshake_auth(WOLFSSL* ssl);
  10481. /*!
  10482. \ingroup IO
  10483. \brief This function requests a client certificate from the TLS v1.3 client.
  10484. This is useful when a web server is serving some pages that require client
  10485. authentication and others that don't.
  10486. A maximum of 256 requests can be sent on a connection.
  10487. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10488. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10489. \return WANT_WRITE if the writing is not ready.
  10490. \return SIDE_ERROR if called with a client.
  10491. \return NOT_READY_ERROR if called when the handshake is not finished.
  10492. \return POST_HAND_AUTH_ERROR if posthandshake authentication is disallowed.
  10493. \return MEMORY_E if dynamic memory allocation fails.
  10494. \return WOLFSSL_SUCCESS if successful.
  10495. _Example_
  10496. \code
  10497. int ret;
  10498. WOLFSSL* ssl;
  10499. ...
  10500. ret = wolfSSL_request_certificate(ssl);
  10501. if (ret == WANT_WRITE) {
  10502. // need to call again when I/O ready
  10503. }
  10504. else if (ret != WOLFSSL_SUCCESS) {
  10505. // failed to request a client certificate
  10506. }
  10507. \endcode
  10508. \sa wolfSSL_allow_post_handshake_auth
  10509. \sa wolfSSL_write
  10510. */
  10511. int wolfSSL_request_certificate(WOLFSSL* ssl);
  10512. /*!
  10513. \ingroup Setup
  10514. \brief This function sets the list of elliptic curve groups to allow on
  10515. a wolfSSL context in order of preference.
  10516. The list is a null-terminated text string, and a colon-delimited list.
  10517. Call this function to set the key exchange elliptic curve parameters to
  10518. use with the TLS v1.3 connections.
  10519. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10520. with wolfSSL_CTX_new().
  10521. \param [in] list a string that is a colon-delimited list of elliptic curve
  10522. groups.
  10523. \return WOLFSSL_FAILURE if pointer parameters are NULL, there are more than
  10524. WOLFSSL_MAX_GROUP_COUNT groups, a group name is not recognized or not
  10525. using TLS v1.3.
  10526. \return WOLFSSL_SUCCESS if successful.
  10527. _Example_
  10528. \code
  10529. int ret;
  10530. WOLFSSL_CTX* ctx;
  10531. const char* list = "P-384:P-256";
  10532. ...
  10533. ret = wolfSSL_CTX_set1_groups_list(ctx, list);
  10534. if (ret != WOLFSSL_SUCCESS) {
  10535. // failed to set group list
  10536. }
  10537. \endcode
  10538. \sa wolfSSL_set1_groups_list
  10539. \sa wolfSSL_CTX_set_groups
  10540. \sa wolfSSL_set_groups
  10541. \sa wolfSSL_UseKeyShare
  10542. \sa wolfSSL_preferred_group
  10543. */
  10544. int wolfSSL_CTX_set1_groups_list(WOLFSSL_CTX *ctx, char *list);
  10545. /*!
  10546. \ingroup Setup
  10547. \brief This function sets the list of elliptic curve groups to allow on
  10548. a wolfSSL in order of preference.
  10549. The list is a null-terminated text string, and a colon-delimited list.
  10550. Call this function to set the key exchange elliptic curve parameters to
  10551. use with the TLS v1.3 connections.
  10552. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10553. \param [in] list a string that is a colon separated list of key exchange
  10554. groups.
  10555. \return WOLFSSL_FAILURE if pointer parameters are NULL, there are more than
  10556. WOLFSSL_MAX_GROUP_COUNT groups, a group name is not recognized or not
  10557. using TLS v1.3.
  10558. \return WOLFSSL_SUCCESS if successful.
  10559. _Example_
  10560. \code
  10561. int ret;
  10562. WOLFSSL* ssl;
  10563. const char* list = "P-384:P-256";
  10564. ...
  10565. ret = wolfSSL_CTX_set1_groups_list(ssl, list);
  10566. if (ret != WOLFSSL_SUCCESS) {
  10567. // failed to set group list
  10568. }
  10569. \endcode
  10570. \sa wolfSSL_CTX_set1_groups_list
  10571. \sa wolfSSL_CTX_set_groups
  10572. \sa wolfSSL_set_groups
  10573. \sa wolfSSL_UseKeyShare
  10574. \sa wolfSSL_preferred_group
  10575. */
  10576. int wolfSSL_set1_groups_list(WOLFSSL *ssl, char *list);
  10577. /*!
  10578. \ingroup TLS
  10579. \brief This function returns the key exchange group the client prefers to
  10580. use in the TLS v1.3 handshake.
  10581. Call this function to after a handshake is complete to determine which
  10582. group the server prefers so that this information can be used in future
  10583. connections to pre-generate a key pair for key exchange.
  10584. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10585. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10586. \return SIDE_ERROR if called with a server.
  10587. \return NOT_READY_ERROR if called before handshake is complete.
  10588. \return Group identifier if successful.
  10589. _Example_
  10590. \code
  10591. int ret;
  10592. int group;
  10593. WOLFSSL* ssl;
  10594. ...
  10595. ret = wolfSSL_CTX_set1_groups_list(ssl)
  10596. if (ret < 0) {
  10597. // failed to get group
  10598. }
  10599. group = ret;
  10600. \endcode
  10601. \sa wolfSSL_UseKeyShare
  10602. \sa wolfSSL_CTX_set_groups
  10603. \sa wolfSSL_set_groups
  10604. \sa wolfSSL_CTX_set1_groups_list
  10605. \sa wolfSSL_set1_groups_list
  10606. */
  10607. int wolfSSL_preferred_group(WOLFSSL* ssl);
  10608. /*!
  10609. \ingroup Setup
  10610. \brief This function sets the list of elliptic curve groups to allow on
  10611. a wolfSSL context in order of preference.
  10612. The list is an array of group identifiers with the number of identifiers
  10613. specified in count.
  10614. Call this function to set the key exchange elliptic curve parameters to
  10615. use with the TLS v1.3 connections.
  10616. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10617. with wolfSSL_CTX_new().
  10618. \param [in] groups a list of key exhange groups by identifier.
  10619. \param [in] count the number of key exchange groups in groups.
  10620. \return BAD_FUNC_ARG if a pointer parameter is null, the number of groups
  10621. exceeds WOLFSSL_MAX_GROUP_COUNT or not using TLS v1.3.
  10622. \return WOLFSSL_SUCCESS if successful.
  10623. _Example_
  10624. \code
  10625. int ret;
  10626. WOLFSSL_CTX* ctx;
  10627. int* groups = { WOLFSSL_ECC_X25519, WOLFSSL_ECC_SECP256R1 };
  10628. int count = 2;
  10629. ...
  10630. ret = wolfSSL_CTX_set1_groups_list(ctx, groups, count);
  10631. if (ret != WOLFSSL_SUCCESS) {
  10632. // failed to set group list
  10633. }
  10634. \endcode
  10635. \sa wolfSSL_set_groups
  10636. \sa wolfSSL_UseKeyShare
  10637. \sa wolfSSL_CTX_set_groups
  10638. \sa wolfSSL_set_groups
  10639. \sa wolfSSL_CTX_set1_groups_list
  10640. \sa wolfSSL_set1_groups_list
  10641. \sa wolfSSL_preferred_group
  10642. */
  10643. int wolfSSL_CTX_set_groups(WOLFSSL_CTX* ctx, int* groups,
  10644. int count);
  10645. /*!
  10646. \ingroup Setup
  10647. \brief This function sets the list of elliptic curve groups to allow on
  10648. a wolfSSL.
  10649. The list is an array of group identifiers with the number of identifiers
  10650. specified in count.
  10651. Call this function to set the key exchange elliptic curve parameters to
  10652. use with the TLS v1.3 connections.
  10653. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10654. \param [in] groups a list of key exhange groups by identifier.
  10655. \param [in] count the number of key exchange groups in groups.
  10656. \return BAD_FUNC_ARG if a pointer parameter is null, the number of groups
  10657. exceeds WOLFSSL_MAX_GROUP_COUNT, any of the identifiers are unrecognized or
  10658. not using TLS v1.3.
  10659. \return WOLFSSL_SUCCESS if successful.
  10660. _Example_
  10661. \code
  10662. int ret;
  10663. WOLFSSL* ssl;
  10664. int* groups = { WOLFSSL_ECC_X25519, WOLFSSL_ECC_SECP256R1 };
  10665. int count = 2;
  10666. ...
  10667. ret = wolfSSL_set_groups(ssl, groups, count);
  10668. if (ret != WOLFSSL_SUCCESS) {
  10669. // failed to set group list
  10670. }
  10671. \endcode
  10672. \sa wolfSSL_CTX_set_groups
  10673. \sa wolfSSL_UseKeyShare
  10674. \sa wolfSSL_CTX_set_groups
  10675. \sa wolfSSL_set_groups
  10676. \sa wolfSSL_CTX_set1_groups_list
  10677. \sa wolfSSL_set1_groups_list
  10678. \sa wolfSSL_preferred_group
  10679. */
  10680. int wolfSSL_set_groups(WOLFSSL* ssl, int* groups, int count);
  10681. /*!
  10682. \ingroup IO
  10683. \brief This function is called on the client side and initiates a
  10684. TLS v1.3 handshake with a server. When this function is called, the
  10685. underlying communication channel has already been set up.
  10686. wolfSSL_connect() works with both blocking and non-blocking I/O.
  10687. When the underlying I/O is non-blocking, wolfSSL_connect() will return
  10688. when the underlying I/O could not satisfy the needs of wolfSSL_connect
  10689. to continue the handshake. In this case, a call to wolfSSL_get_error()
  10690. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The
  10691. calling process must then repeat the call to wolfSSL_connect() when
  10692. the underlying I/O is ready and wolfSSL will pick up where it left off.
  10693. When using a non-blocking socket, nothing needs to be done, but select()
  10694. can be used to check for the required condition. If the underlying I/O is
  10695. blocking, wolfSSL_connect() will only return once the handshake has been
  10696. finished or an error occurred. wolfSSL takes a different approach to
  10697. certificate verification than OpenSSL does. The default policy for the
  10698. client is to verify the server, this means that if you don't load CAs to
  10699. verify the server you'll get a connect error, unable to verify (-155). It
  10700. you want to mimic OpenSSL behavior of having SSL_connect succeed even if
  10701. verifying the server fails and reducing security you can do this by
  10702. calling: SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling
  10703. SSL_new(); Though it's not recommended.
  10704. \return SSL_SUCCESS upon success.
  10705. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10706. more detailed error code, call wolfSSL_get_error().
  10707. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10708. _Example_
  10709. \code
  10710. int ret = 0;
  10711. int err = 0;
  10712. WOLFSSL* ssl;
  10713. char buffer[80];
  10714. ...
  10715. ret = wolfSSL_connect_TLSv13(ssl);
  10716. if (ret != SSL_SUCCESS) {
  10717. err = wolfSSL_get_error(ssl, ret);
  10718. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10719. }
  10720. \endcode
  10721. \sa wolfSSL_get_error
  10722. \sa wolfSSL_connect
  10723. \sa wolfSSL_accept_TLSv13
  10724. \sa wolfSSL_accept
  10725. */
  10726. int wolfSSL_connect_TLSv13(WOLFSSL*);
  10727. /*!
  10728. \ingroup IO
  10729. \brief This function is called on the server side and waits for a SSL/TLS
  10730. client to initiate the SSL/TLS handshake. When this function is called,
  10731. the underlying communication channel has already been set up.
  10732. wolfSSL_accept() works with both blocking and non-blocking I/O.
  10733. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  10734. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  10735. to continue the handshake. In this case, a call to wolfSSL_get_error()
  10736. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  10737. The calling process must then repeat the call to wolfSSL_accept when
  10738. data is available to read and wolfSSL will pick up where it left off.
  10739. When using a non-blocking socket, nothing needs to be done, but select()
  10740. can be used to check for the required condition. If the underlying I/O
  10741. is blocking, wolfSSL_accept() will only return once the handshake has
  10742. been finished or an error occurred.
  10743. Call this function when expecting a TLS v1.3 connection though older
  10744. version ClientHello messages are supported.
  10745. \return SSL_SUCCESS upon success.
  10746. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10747. more detailed error code, call wolfSSL_get_error().
  10748. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10749. _Example_
  10750. \code
  10751. int ret = 0;
  10752. int err = 0;
  10753. WOLFSSL* ssl;
  10754. char buffer[80];
  10755. ...
  10756. ret = wolfSSL_accept_TLSv13(ssl);
  10757. if (ret != SSL_SUCCESS) {
  10758. err = wolfSSL_get_error(ssl, ret);
  10759. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10760. }
  10761. \endcode
  10762. \sa wolfSSL_get_error
  10763. \sa wolfSSL_connect_TLSv13
  10764. \sa wolfSSL_connect
  10765. \sa wolfSSL_accept_TLSv13
  10766. \sa wolfSSL_accept
  10767. */
  10768. wolfSSL_accept_TLSv13(WOLFSSL* ssl);
  10769. /*!
  10770. \ingroup Setup
  10771. \brief This function sets the maximum amount of early data that will be
  10772. accepted by a TLS v1.3 server using the wolfSSL context.
  10773. Call this function to limit the amount of early data to process to mitigate
  10774. replay attacks. Early data is protected by keys derived from those of the
  10775. connection that the session ticket was sent and therefore will be the same
  10776. every time a session ticket is used in resumption.
  10777. The value is included in the session ticket for resumption.
  10778. A value of zero indicates no early data is to be sent by client using
  10779. session tickets.
  10780. It is recommended that the number of early data bytes be kept as low as
  10781. practically possible in the application.
  10782. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10783. with wolfSSL_CTX_new().
  10784. \param [in] sz the amount of early data to accept in bytes.
  10785. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10786. \return SIDE_ERROR if called with a client.
  10787. \return 0 if successful.
  10788. _Example_
  10789. \code
  10790. int ret;
  10791. WOLFSSL_CTX* ctx;
  10792. ...
  10793. ret = wolfSSL_CTX_set_max_early_data(ctx, 128);
  10794. if (ret != WOLFSSL_SUCCESS) {
  10795. // failed to set group list
  10796. }
  10797. \endcode
  10798. \sa wolfSSL_set_max_early_data
  10799. \sa wolfSSL_write_early_data
  10800. \sa wolfSSL_read_early_data
  10801. */
  10802. int wolfSSL_CTX_set_max_early_data(WOLFSSL_CTX* ctx,
  10803. unsigned int sz);
  10804. /*!
  10805. \ingroup Setup
  10806. \brief This function sets the maximum amount of early data that will be
  10807. accepted by a TLS v1.3 server using the wolfSSL context.
  10808. Call this function to limit the amount of early data to process to mitigate
  10809. replay attacks. Early data is protected by keys derived from those of the
  10810. connection that the session ticket was sent and therefore will be the same
  10811. every time a session ticket is used in resumption.
  10812. The value is included in the session ticket for resumption.
  10813. A value of zero indicates no early data is to be sent by client using
  10814. session tickets.
  10815. It is recommended that the number of early data bytes be kept as low as
  10816. practically possible in the application.
  10817. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10818. \param [in] sz the amount of early data to accept from client in bytes.
  10819. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10820. \return SIDE_ERROR if called with a client.
  10821. \return 0 if successful.
  10822. _Example_
  10823. \code
  10824. int ret;
  10825. WOLFSSL* ssl;
  10826. ...
  10827. ret = wolfSSL_set_max_early_data(ssl, 128);
  10828. if (ret != WOLFSSL_SUCCESS) {
  10829. // failed to set group list
  10830. }
  10831. \endcode
  10832. \sa wolfSSL_CTX_set_max_early_data
  10833. \sa wolfSSL_write_early_data
  10834. \sa wolfSSL_read_early_data
  10835. */
  10836. int wolfSSL_set_max_early_data(WOLFSSL* ssl, unsigned int sz);
  10837. /*!
  10838. \ingroup IO
  10839. \brief This function writes early data to the server on resumption.
  10840. Call this function instead of wolfSSL_connect() or wolfSSL_connect_TLSv13()
  10841. to connect to the server and send the data in the handshake.
  10842. This function is only used with clients.
  10843. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10844. \param [in] data the buffer holding the early data to write to server.
  10845. \param [in] sz the amount of early data to write in bytes.
  10846. \param [out] outSz the amount of early data written in bytes.
  10847. \return BAD_FUNC_ARG if a pointer parameter is NULL, sz is less than 0 or
  10848. not using TLSv1.3.
  10849. \return SIDE_ERROR if called with a server.
  10850. \return WOLFSSL_FATAL_ERROR if the connection is not made.
  10851. \return WOLFSSL_SUCCESS if successful.
  10852. _Example_
  10853. \code
  10854. int ret = 0;
  10855. int err = 0;
  10856. WOLFSSL* ssl;
  10857. byte earlyData[] = { early data };
  10858. int outSz;
  10859. char buffer[80];
  10860. ...
  10861. ret = wolfSSL_write_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
  10862. if (ret != WOLFSSL_SUCCESS) {
  10863. err = wolfSSL_get_error(ssl, ret);
  10864. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10865. goto err_label;
  10866. }
  10867. if (outSz < sizeof(earlyData)) {
  10868. // not all early data was sent
  10869. }
  10870. ret = wolfSSL_connect_TLSv13(ssl);
  10871. if (ret != SSL_SUCCESS) {
  10872. err = wolfSSL_get_error(ssl, ret);
  10873. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10874. }
  10875. \endcode
  10876. \sa wolfSSL_read_early_data
  10877. \sa wolfSSL_connect
  10878. \sa wolfSSL_connect_TLSv13
  10879. */
  10880. int wolfSSL_write_early_data(OLFSSL* ssl, const void* data,
  10881. int sz, int* outSz);
  10882. /*!
  10883. \ingroup IO
  10884. \brief This function reads any early data from a client on resumption.
  10885. Call this function instead of wolfSSL_accept() or wolfSSL_accept_TLSv13()
  10886. to accept a client and read any early data in the handshake.
  10887. If there is no early data than the handshake will be processed as normal.
  10888. This function is only used with servers.
  10889. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10890. \param [out] data a buffer to hold the early data read from client.
  10891. \param [in] sz size of the buffer in bytes.
  10892. \param [out] outSz number of bytes of early data read.
  10893. \return BAD_FUNC_ARG if a pointer parameter is NULL, sz is less than 0 or
  10894. not using TLSv1.3.
  10895. \return SIDE_ERROR if called with a client.
  10896. \return WOLFSSL_FATAL_ERROR if accepting a connection fails.
  10897. \return WOLFSSL_SUCCESS if successful.
  10898. _Example_
  10899. \code
  10900. int ret = 0;
  10901. int err = 0;
  10902. WOLFSSL* ssl;
  10903. byte earlyData[128];
  10904. int outSz;
  10905. char buffer[80];
  10906. ...
  10907. ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
  10908. if (ret != SSL_SUCCESS) {
  10909. err = wolfSSL_get_error(ssl, ret);
  10910. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10911. }
  10912. if (outSz > 0) {
  10913. // early data available
  10914. }
  10915. ret = wolfSSL_accept_TLSv13(ssl);
  10916. if (ret != SSL_SUCCESS) {
  10917. err = wolfSSL_get_error(ssl, ret);
  10918. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10919. }
  10920. \endcode
  10921. \sa wolfSSL_write_early_data
  10922. \sa wolfSSL_accept
  10923. \sa wolfSSL_accept_TLSv13
  10924. */
  10925. int wolfSSL_read_early_data(WOLFSSL* ssl, void* data, int sz,
  10926. int* outSz);
  10927. /*!
  10928. \ingroup Setup
  10929. \brief This function sets the Pre-Shared Key (PSK) client side callback
  10930. for TLS v1.3 connections.
  10931. The callback is used to find a PSK identity and return its key and
  10932. the name of the cipher to use for the handshake.
  10933. The function sets the client_psk_tls13_cb member of the
  10934. WOLFSSL_CTX structure.
  10935. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10936. with wolfSSL_CTX_new().
  10937. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 client.
  10938. _Example_
  10939. \code
  10940. WOLFSSL_CTX* ctx;
  10941. ...
  10942. wolfSSL_CTX_set_psk_client_tls13_callback(ctx, my_psk_client_tls13_cb);
  10943. \endcode
  10944. \sa wolfSSL_set_psk_client_tls13_callback
  10945. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  10946. \sa wolfSSL_set_psk_server_tls13_callback
  10947. */
  10948. void wolfSSL_CTX_set_psk_client_tls13_callback(WOLFSSL_CTX* ctx,
  10949. wc_psk_client_tls13_callback cb);
  10950. /*!
  10951. \ingroup Setup
  10952. \brief This function sets the Pre-Shared Key (PSK) client side callback
  10953. for TLS v1.3 connections.
  10954. The callback is used to find a PSK identity and return its key and
  10955. the name of the cipher to use for the handshake.
  10956. The function sets the client_psk_tls13_cb member of the options field in
  10957. WOLFSSL structure.
  10958. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10959. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 client.
  10960. _Example_
  10961. \code
  10962. WOLFSSL* ssl;
  10963. ...
  10964. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  10965. \endcode
  10966. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  10967. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  10968. \sa wolfSSL_set_psk_server_tls13_callback
  10969. */
  10970. void wolfSSL_set_psk_client_tls13_callback(WOLFSSL* ssl,
  10971. wc_psk_client_tls13_callback cb);
  10972. /*!
  10973. \ingroup Setup
  10974. \brief This function sets the Pre-Shared Key (PSK) server side callback
  10975. for TLS v1.3 connections.
  10976. The callback is used to find a PSK identity and return its key and
  10977. the name of the cipher to use for the handshake.
  10978. The function sets the server_psk_tls13_cb member of the
  10979. WOLFSSL_CTX structure.
  10980. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10981. with wolfSSL_CTX_new().
  10982. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 server.
  10983. _Example_
  10984. \code
  10985. WOLFSSL_CTX* ctx;
  10986. ...
  10987. wolfSSL_CTX_set_psk_server_tls13_callback(ctx, my_psk_client_tls13_cb);
  10988. \endcode
  10989. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  10990. \sa wolfSSL_set_psk_client_tls13_callback
  10991. \sa wolfSSL_set_psk_server_tls13_callback
  10992. */
  10993. void wolfSSL_CTX_set_psk_server_tls13_callback(WOLFSSL_CTX* ctx,
  10994. wc_psk_server_tls13_callback cb);
  10995. /*!
  10996. \ingroup Setup
  10997. \brief This function sets the Pre-Shared Key (PSK) server side callback
  10998. for TLS v1.3 connections.
  10999. The callback is used to find a PSK identity and return its key and
  11000. the name of the cipher to use for the handshake.
  11001. The function sets the server_psk_tls13_cb member of the options field in
  11002. WOLFSSL structure.
  11003. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11004. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 server.
  11005. _Example_
  11006. \code
  11007. WOLFSSL* ssl;
  11008. ...
  11009. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  11010. \endcode
  11011. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11012. \sa wolfSSL_set_psk_client_tls13_callback
  11013. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11014. */
  11015. void wolfSSL_set_psk_server_tls13_callback(WOLFSSL* ssl,
  11016. wc_psk_server_tls13_callback cb);
  11017. /*!
  11018. \ingroup Setup
  11019. \brief This function creates a key share entry from the group including
  11020. generating a key pair.
  11021. The KeyShare extension contains all the generated public keys for key
  11022. exchange. If this function is called, then only the groups specified will
  11023. be included.
  11024. Call this function when a preferred group has been previously established
  11025. for the server.
  11026. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11027. \param [in] group a key exchange group identifier.
  11028. \return BAD_FUNC_ARG if ssl is NULL.
  11029. \return MEMORY_E when dynamic memory allocation fails.
  11030. \return WOLFSSL_SUCCESS if successful.
  11031. _Example_
  11032. \code
  11033. int ret;
  11034. WOLFSSL* ssl;
  11035. ...
  11036. ret = wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_X25519);
  11037. if (ret != WOLFSSL_SUCCESS) {
  11038. // failed to set key share
  11039. }
  11040. \endcode
  11041. \sa wolfSSL_preferred_group
  11042. \sa wolfSSL_CTX_set1_groups_list
  11043. \sa wolfSSL_set1_groups_list
  11044. \sa wolfSSL_CTX_set_groups
  11045. \sa wolfSSL_set_groups
  11046. \sa wolfSSL_NoKeyShares
  11047. */
  11048. int wolfSSL_UseKeyShare(WOLFSSL* ssl, word16 group);
  11049. /*!
  11050. \ingroup Setup
  11051. \brief This function is called to ensure no key shares are sent in the
  11052. ClientHello. This will force the server to respond with a HelloRetryRequest
  11053. if a key exchange is required in the handshake.
  11054. Call this function when the expected key exchange group is not known and
  11055. to avoid the generation of keys unnecessarily.
  11056. Note that an extra round-trip will be required to complete the handshake
  11057. when a key exchange is required.
  11058. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11059. \return BAD_FUNC_ARG if ssl is NULL.
  11060. \return SIDE_ERROR if called with a server.
  11061. \return WOLFSSL_SUCCESS if successful.
  11062. _Example_
  11063. \code
  11064. int ret;
  11065. WOLFSSL* ssl;
  11066. ...
  11067. ret = wolfSSL_NoKeyShares(ssl);
  11068. if (ret != WOLFSSL_SUCCESS) {
  11069. // failed to set no key shares
  11070. }
  11071. \endcode
  11072. \sa wolfSSL_UseKeyShare
  11073. */
  11074. int wolfSSL_NoKeyShares(WOLFSSL* ssl);
  11075. /*!
  11076. \ingroup Setup
  11077. \brief This function is used to indicate
  11078. that the application is a server and will only support the TLS 1.3
  11079. protocol. This function allocates memory for and initializes a new
  11080. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11081. with wolfSSL_CTX_new().
  11082. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11083. \return If successful, the call will return a pointer to the newly
  11084. created WOLFSSL_METHOD structure.
  11085. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11086. value of the underlying malloc() implementation will be returned
  11087. (typically NULL with errno will be set to ENOMEM).
  11088. _Example_
  11089. \code
  11090. #include <wolfssl/ssl.h>
  11091. WOLFSSL_METHOD* method;
  11092. WOLFSSL_CTX* ctx;
  11093. method = wolfTLSv1_3_server_method_ex(NULL);
  11094. if (method == NULL) {
  11095. // unable to get method
  11096. }
  11097. ctx = wolfSSL_CTX_new(method);
  11098. ...
  11099. \endcode
  11100. \sa wolfSSLv3_server_method
  11101. \sa wolfTLSv1_server_method
  11102. \sa wolfTLSv1_1_server_method
  11103. \sa wolfTLSv1_2_server_method
  11104. \sa wolfTLSv1_3_server_method
  11105. \sa wolfDTLSv1_server_method
  11106. \sa wolfSSLv23_server_method
  11107. \sa wolfSSL_CTX_new
  11108. */
  11109. WOLFSSL_METHOD *wolfTLSv1_3_server_method_ex(void* heap);
  11110. /*!
  11111. \ingroup Setup
  11112. \brief This function is used to indicate
  11113. that the application is a client and will only support the TLS 1.3
  11114. protocol. This function allocates memory for and initializes a new
  11115. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11116. with wolfSSL_CTX_new().
  11117. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11118. \return If successful, the call will return a pointer to the newly
  11119. created WOLFSSL_METHOD structure.
  11120. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11121. value of the underlying malloc() implementation will be returned
  11122. (typically NULL with errno will be set to ENOMEM).
  11123. _Example_
  11124. \code
  11125. #include <wolfssl/ssl.h>
  11126. WOLFSSL_METHOD* method;
  11127. WOLFSSL_CTX* ctx;
  11128. method = wolfTLSv1_3_client_method_ex(NULL);
  11129. if (method == NULL) {
  11130. // unable to get method
  11131. }
  11132. ctx = wolfSSL_CTX_new(method);
  11133. ...
  11134. \endcode
  11135. \sa wolfSSLv3_client_method
  11136. \sa wolfTLSv1_client_method
  11137. \sa wolfTLSv1_1_client_method
  11138. \sa wolfTLSv1_2_client_method
  11139. \sa wolfTLSv1_3_client_method
  11140. \sa wolfDTLSv1_client_method
  11141. \sa wolfSSLv23_client_method
  11142. \sa wolfSSL_CTX_new
  11143. */
  11144. WOLFSSL_METHOD *wolfTLSv1_3_client_method_ex(void* heap);
  11145. /*!
  11146. \ingroup Setup
  11147. \brief This function is used to indicate
  11148. that the application is a server and will only support the TLS 1.3
  11149. protocol. This function allocates memory for and initializes a new
  11150. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11151. with wolfSSL_CTX_new().
  11152. \return If successful, the call will return a pointer to the newly
  11153. created WOLFSSL_METHOD structure.
  11154. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11155. value of the underlying malloc() implementation will be returned
  11156. (typically NULL with errno will be set to ENOMEM).
  11157. _Example_
  11158. \code
  11159. #include <wolfssl/ssl.h>
  11160. WOLFSSL_METHOD* method;
  11161. WOLFSSL_CTX* ctx;
  11162. method = wolfTLSv1_3_server_method();
  11163. if (method == NULL) {
  11164. // unable to get method
  11165. }
  11166. ctx = wolfSSL_CTX_new(method);
  11167. ...
  11168. \endcode
  11169. \sa wolfSSLv3_server_method
  11170. \sa wolfTLSv1_server_method
  11171. \sa wolfTLSv1_1_server_method
  11172. \sa wolfTLSv1_2_server_method
  11173. \sa wolfTLSv1_3_server_method_ex
  11174. \sa wolfDTLSv1_server_method
  11175. \sa wolfSSLv23_server_method
  11176. \sa wolfSSL_CTX_new
  11177. */
  11178. WOLFSSL_METHOD *wolfTLSv1_3_server_method(void);
  11179. /*!
  11180. \ingroup Setup
  11181. \brief This function is used to indicate
  11182. that the application is a client and will only support the TLS 1.3
  11183. protocol. This function allocates memory for and initializes a new
  11184. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11185. with wolfSSL_CTX_new().
  11186. \return If successful, the call will return a pointer to the newly
  11187. created WOLFSSL_METHOD structure.
  11188. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11189. value of the underlying malloc() implementation will be returned
  11190. (typically NULL with errno will be set to ENOMEM).
  11191. _Example_
  11192. \code
  11193. #include <wolfssl/ssl.h>
  11194. WOLFSSL_METHOD* method;
  11195. WOLFSSL_CTX* ctx;
  11196. method = wolfTLSv1_3_client_method();
  11197. if (method == NULL) {
  11198. // unable to get method
  11199. }
  11200. ctx = wolfSSL_CTX_new(method);
  11201. ...
  11202. \endcode
  11203. \sa wolfSSLv3_client_method
  11204. \sa wolfTLSv1_client_method
  11205. \sa wolfTLSv1_1_client_method
  11206. \sa wolfTLSv1_2_client_method
  11207. \sa wolfTLSv1_3_client_method_ex
  11208. \sa wolfDTLSv1_client_method
  11209. \sa wolfSSLv23_client_method
  11210. \sa wolfSSL_CTX_new
  11211. */
  11212. WOLFSSL_METHOD *wolfTLSv1_3_client_method(void);
  11213. /*!
  11214. \ingroup Setup
  11215. \brief This function returns a WOLFSSL_METHOD similar to
  11216. wolfTLSv1_3_client_method except that it is not determined
  11217. which side yet (server/client).
  11218. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11219. \return WOLFSSL_METHOD On successful creations returns a WOLFSSL_METHOD
  11220. pointer
  11221. \return NULL Null if memory allocation error or failure to create method
  11222. _Example_
  11223. \code
  11224. WOLFSSL* ctx;
  11225. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method_ex(NULL));
  11226. // check ret value
  11227. \endcode
  11228. \sa wolfSSL_new
  11229. \sa wolfSSL_free
  11230. */
  11231. WOLFSSL_METHOD *wolfTLSv1_3_method_ex(void* heap);
  11232. /*!
  11233. \ingroup Setup
  11234. \brief This function returns a WOLFSSL_METHOD similar to
  11235. wolfTLSv1_3_client_method except that it is not determined
  11236. which side yet (server/client).
  11237. \return WOLFSSL_METHOD On successful creations returns a WOLFSSL_METHOD
  11238. pointer
  11239. \return NULL Null if memory allocation error or failure to create method
  11240. _Example_
  11241. \code
  11242. WOLFSSL* ctx;
  11243. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method());
  11244. // check ret value
  11245. \endcode
  11246. \sa wolfSSL_new
  11247. \sa wolfSSL_free
  11248. */
  11249. WOLFSSL_METHOD *wolfTLSv1_3_method(void);
  11250. /*!
  11251. \ingroup SSL
  11252. \brief This function sets a fixed / static ephemeral key for testing only
  11253. \return 0 Key loaded successfully
  11254. \param ctx A WOLFSSL_CTX context pointer
  11255. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11256. \param key key file path (if keySz == 0) or actual key buffer (PEM or ASN.1)
  11257. \param keySz key size (should be 0 for "key" arg is file path)
  11258. \param format WOLFSSL_FILETYPE_ASN1 or WOLFSSL_FILETYPE_PEM
  11259. \sa wolfSSL_CTX_get_ephemeral_key
  11260. */
  11261. int wolfSSL_CTX_set_ephemeral_key(WOLFSSL_CTX* ctx, int keyAlgo, const char* key, unsigned int keySz, int format);
  11262. /*!
  11263. \ingroup SSL
  11264. \brief This function sets a fixed / static ephemeral key for testing only
  11265. \return 0 Key loaded successfully
  11266. \param ssl A WOLFSSL object pointer
  11267. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11268. \param key key file path (if keySz == 0) or actual key buffer (PEM or ASN.1)
  11269. \param keySz key size (should be 0 for "key" arg is file path)
  11270. \param format WOLFSSL_FILETYPE_ASN1 or WOLFSSL_FILETYPE_PEM
  11271. \sa wolfSSL_get_ephemeral_key
  11272. */
  11273. int wolfSSL_set_ephemeral_key(WOLFSSL* ssl, int keyAlgo, const char* key, unsigned int keySz, int format);
  11274. /*!
  11275. \ingroup SSL
  11276. \brief This function returns pointer to loaded key as ASN.1/DER
  11277. \return 0 Key returned successfully
  11278. \param ctx A WOLFSSL_CTX context pointer
  11279. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11280. \param key key buffer pointer
  11281. \param keySz key size pointer
  11282. \sa wolfSSL_CTX_set_ephemeral_key
  11283. */
  11284. int wolfSSL_CTX_get_ephemeral_key(WOLFSSL_CTX* ctx, int keyAlgo,
  11285. const unsigned char** key, unsigned int* keySz);
  11286. /*!
  11287. \ingroup SSL
  11288. \brief This function returns pointer to loaded key as ASN.1/DER
  11289. \return 0 Key returned successfully
  11290. \param ssl A WOLFSSL object pointer
  11291. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11292. \param key key buffer pointer
  11293. \param keySz key size pointer
  11294. \sa wolfSSL_set_ephemeral_key
  11295. */
  11296. int wolfSSL_get_ephemeral_key(WOLFSSL* ssl, int keyAlgo,
  11297. const unsigned char** key, unsigned int* keySz);
  11298. /*!
  11299. \ingroup SSL
  11300. \brief Sign a message with the chosen message digest, padding, and RSA key
  11301. \return WOLFSSL_SUCCESS on success and WOLFSSL_FAILURE on error
  11302. \param type Hash NID
  11303. \param m Message to sign. Most likely this will be the digest of
  11304. the message to sign
  11305. \param mLen Length of message to sign
  11306. \param sigRet Output buffer
  11307. \param sigLen On Input: length of sigRet buffer
  11308. On Output: length of data written to sigRet
  11309. \param rsa RSA key used to sign the input
  11310. \param flag 1: Output the signature
  11311. 0: Output the value that the unpadded signature should be
  11312. compared to. Note: for RSA_PKCS1_PSS_PADDING the
  11313. wc_RsaPSS_CheckPadding_ex function should be used to check
  11314. the output of a *Verify* function.
  11315. \param padding Padding to use. Only RSA_PKCS1_PSS_PADDING and
  11316. RSA_PKCS1_PADDING are currently supported for signing.
  11317. */
  11318. int wolfSSL_RSA_sign_generic_padding(int type, const unsigned char* m,
  11319. unsigned int mLen, unsigned char* sigRet,
  11320. unsigned int* sigLen, WOLFSSL_RSA* rsa,
  11321. int flag, int padding);