ssl.h 449 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513
  1. /*!
  2. \brief This function initializes the DTLS v1.2 client method.
  3. \return pointer This function returns a pointer to a new
  4. WOLFSSL_METHOD structure.
  5. \param none No parameters.
  6. _Example_
  7. \code
  8. wolfSSL_Init();
  9. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method());
  10. WOLFSSL* ssl = wolfSSL_new(ctx);
  11. \endcode
  12. \sa wolfSSL_Init
  13. \sa wolfSSL_CTX_new
  14. */
  15. WOLFSSL_METHOD *wolfDTLSv1_2_client_method_ex(void* heap);
  16. /*!
  17. \ingroup Setup
  18. \brief This function returns a WOLFSSL_METHOD similar to
  19. wolfSSLv23_client_method except that it is not determined
  20. which side yet (server/client).
  21. \return WOLFSSL_METHOD* On successful creations returns a WOLFSSL_METHOD
  22. pointer
  23. \return NULL Null if memory allocation error or failure to create method
  24. \param none No parameters.
  25. _Example_
  26. \code
  27. WOLFSSL* ctx;
  28. ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  29. // check ret value
  30. \endcode
  31. \sa wolfSSL_new
  32. \sa wolfSSL_free
  33. */
  34. WOLFSSL_METHOD *wolfSSLv23_method(void);
  35. /*!
  36. \ingroup Setup
  37. \brief The wolfSSLv3_server_method() function is used to indicate
  38. that the application is a server and will only support the SSL 3.0
  39. protocol. This function allocates memory for and initializes a new
  40. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  41. with wolfSSL_CTX_new().
  42. \return * If successful, the call will return a pointer to the newly
  43. created WOLFSSL_METHOD structure.
  44. \return FAIL If memory allocation fails when calling XMALLOC, the
  45. failure value of the underlying malloc() implementation will be returned
  46. (typically NULL with errno will be set to ENOMEM).
  47. \param none No parameters.
  48. _Example_
  49. \code
  50. #include <wolfssl/ssl.h>
  51. WOLFSSL_METHOD* method;
  52. WOLFSSL_CTX* ctx;
  53. method = wolfSSLv3_server_method();
  54. if (method == NULL) {
  55. unable to get method
  56. }
  57. ctx = wolfSSL_CTX_new(method);
  58. ...
  59. \endcode
  60. \sa wolfTLSv1_server_method
  61. \sa wolfTLSv1_1_server_method
  62. \sa wolfTLSv1_2_server_method
  63. \sa wolfTLSv1_3_server_method
  64. \sa wolfDTLSv1_server_method
  65. \sa wolfSSLv23_server_method
  66. \sa wolfSSL_CTX_new
  67. */
  68. WOLFSSL_METHOD *wolfSSLv3_server_method(void);
  69. /*!
  70. \ingroup Setup
  71. \brief The wolfSSLv3_client_method() function is used to indicate
  72. that the application is a client and will only support the SSL 3.0
  73. protocol. This function allocates memory for and initializes a
  74. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  75. context with wolfSSL_CTX_new().
  76. \return * If successful, the call will return a pointer to the newly
  77. created WOLFSSL_METHOD structure.
  78. \return FAIL If memory allocation fails when calling XMALLOC, the
  79. failure value of the underlying malloc() implementation will be
  80. returned (typically NULL with errno will be set to ENOMEM).
  81. \param none No parameters.
  82. _Example_
  83. \code
  84. #include <wolfssl/ssl.h>
  85. WOLFSSL_METHOD* method;
  86. WOLFSSL_CTX* ctx;
  87. method = wolfSSLv3_client_method();
  88. if (method == NULL) {
  89. unable to get method
  90. }
  91. ctx = wolfSSL_CTX_new(method);
  92. ...
  93. \endcode
  94. \sa wolfTLSv1_client_method
  95. \sa wolfTLSv1_1_client_method
  96. \sa wolfTLSv1_2_client_method
  97. \sa wolfTLSv1_3_client_method
  98. \sa wolfDTLSv1_client_method
  99. \sa wolfSSLv23_client_method
  100. \sa wolfSSL_CTX_new
  101. */
  102. WOLFSSL_METHOD *wolfSSLv3_client_method(void);
  103. /*!
  104. \ingroup Setup
  105. \brief The wolfTLSv1_server_method() function is used to indicate that the
  106. application is a server and will only support the TLS 1.0 protocol. This
  107. function allocates memory for and initializes a new wolfSSL_METHOD
  108. structure to be used when creating the SSL/TLS context with
  109. wolfSSL_CTX_new().
  110. \return * If successful, the call will return a pointer to the newly
  111. created WOLFSSL_METHOD structure.
  112. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  113. value of the underlying malloc() implementation will be returned
  114. (typically NULL with errno will be set to ENOMEM).
  115. \param none No parameters.
  116. _Example_
  117. \code
  118. #include <wolfssl/ssl.h>
  119. WOLFSSL_METHOD* method;
  120. WOLFSSL_CTX* ctx;
  121. method = wolfTLSv1_server_method();
  122. if (method == NULL) {
  123. unable to get method
  124. }
  125. ctx = wolfSSL_CTX_new(method);
  126. ...
  127. \endcode
  128. \sa wolfSSLv3_server_method
  129. \sa wolfTLSv1_1_server_method
  130. \sa wolfTLSv1_2_server_method
  131. \sa wolfTLSv1_3_server_method
  132. \sa wolfDTLSv1_server_method
  133. \sa wolfSSLv23_server_method
  134. \sa wolfSSL_CTX_new
  135. */
  136. WOLFSSL_METHOD *wolfTLSv1_server_method(void);
  137. /*!
  138. \ingroup Setup
  139. \brief The wolfTLSv1_client_method() function is used to indicate
  140. that the application is a client and will only support the TLS 1.0
  141. protocol. This function allocates memory for and initializes a new
  142. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  143. with wolfSSL_CTX_new().
  144. \return * If successful, the call will return a pointer to the newly
  145. created WOLFSSL_METHOD structure.
  146. \return FAIL If memory allocation fails when calling XMALLOC,
  147. the failure value of the underlying malloc() implementation
  148. will be returned (typically NULL with errno will be set to ENOMEM).
  149. \param none No parameters.
  150. _Example_
  151. \code
  152. #include <wolfssl/ssl.h>
  153. WOLFSSL_METHOD* method;
  154. WOLFSSL_CTX* ctx;
  155. method = wolfTLSv1_client_method();
  156. if (method == NULL) {
  157. unable to get method
  158. }
  159. ctx = wolfSSL_CTX_new(method);
  160. ...
  161. \endcode
  162. \sa wolfSSLv3_client_method
  163. \sa wolfTLSv1_1_client_method
  164. \sa wolfTLSv1_2_client_method
  165. \sa wolfTLSv1_3_client_method
  166. \sa wolfDTLSv1_client_method
  167. \sa wolfSSLv23_client_method
  168. \sa wolfSSL_CTX_new
  169. */
  170. WOLFSSL_METHOD *wolfTLSv1_client_method(void);
  171. /*!
  172. \ingroup Setup
  173. \brief The wolfTLSv1_1_server_method() function is used to indicate
  174. that the application is a server and will only support the TLS 1.1
  175. protocol. This function allocates memory for and initializes a new
  176. wolfSSL_METHOD structure to be used when creating the SSL/TLS
  177. context with wolfSSL_CTX_new().
  178. \return * If successful, the call will return a pointer to the newly
  179. created WOLFSSL_METHOD structure.
  180. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  181. value of the underlying malloc() implementation will be returned
  182. (typically NULL with errno will be set to ENOMEM).
  183. \param none No parameters.
  184. _Example_
  185. \code
  186. #include <wolfssl/ssl.h>
  187. WOLFSSL_METHOD* method;
  188. WOLFSSL_CTX* ctx;
  189. method = wolfTLSv1_1_server_method();
  190. if (method == NULL) {
  191. // unable to get method
  192. }
  193. ctx = wolfSSL_CTX_new(method);
  194. ...
  195. \endcode
  196. \sa wolfSSLv3_server_method
  197. \sa wolfTLSv1_server_method
  198. \sa wolfTLSv1_2_server_method
  199. \sa wolfTLSv1_3_server_method
  200. \sa wolfDTLSv1_server_method
  201. \sa wolfSSLv23_server_method
  202. \sa wolfSSL_CTX_new
  203. */
  204. WOLFSSL_METHOD *wolfTLSv1_1_server_method(void);
  205. /*!
  206. \ingroup Setup
  207. \brief The wolfTLSv1_1_client_method() function is used to indicate
  208. that the application is a client and will only support the TLS 1.0
  209. protocol. This function allocates memory for and initializes a
  210. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  211. context with wolfSSL_CTX_new().
  212. \return * If successful, the call will return a pointer to the
  213. newly created WOLFSSL_METHOD structure.
  214. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  215. value of the underlying malloc() implementation will be returned
  216. (typically NULL with errno will be set to ENOMEM).
  217. \param none No parameters.
  218. _Example_
  219. \code
  220. #include <wolfssl/ssl.h>
  221. WOLFSSL_METHOD* method;
  222. WOLFSSL_CTX* ctx;
  223. method = wolfTLSv1_1_client_method();
  224. if (method == NULL) {
  225. // unable to get method
  226. }
  227. ctx = wolfSSL_CTX_new(method);
  228. ...
  229. \endcode
  230. \sa wolfSSLv3_client_method
  231. \sa wolfTLSv1_client_method
  232. \sa wolfTLSv1_2_client_method
  233. \sa wolfTLSv1_3_client_method
  234. \sa wolfDTLSv1_client_method
  235. \sa wolfSSLv23_client_method
  236. \sa wolfSSL_CTX_new
  237. */
  238. WOLFSSL_METHOD *wolfTLSv1_1_client_method(void);
  239. /*!
  240. \ingroup Setup
  241. \brief The wolfTLSv1_2_server_method() function is used to indicate
  242. that the application is a server and will only support the TLS 1.2
  243. protocol. This function allocates memory for and initializes a new
  244. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  245. with wolfSSL_CTX_new().
  246. \return * If successful, the call will return a pointer to the newly
  247. created WOLFSSL_METHOD structure.
  248. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  249. value of the underlying malloc() implementation will be returned
  250. (typically NULL with errno will be set to ENOMEM).
  251. \param none No parameters.
  252. _Example_
  253. \code
  254. #include <wolfssl/ssl.h>
  255. WOLFSSL_METHOD* method;
  256. WOLFSSL_CTX* ctx;
  257. method = wolfTLSv1_2_server_method();
  258. if (method == NULL) {
  259. // unable to get method
  260. }
  261. ctx = wolfSSL_CTX_new(method);
  262. ...
  263. \endcode
  264. \sa wolfSSLv3_server_method
  265. \sa wolfTLSv1_server_method
  266. \sa wolfTLSv1_1_server_method
  267. \sa wolfTLSv1_3_server_method
  268. \sa wolfDTLSv1_server_method
  269. \sa wolfSSLv23_server_method
  270. \sa wolfSSL_CTX_new
  271. */
  272. WOLFSSL_METHOD *wolfTLSv1_2_server_method(void);
  273. /*!
  274. \ingroup Setup
  275. \brief The wolfTLSv1_2_client_method() function is used to indicate
  276. that the application is a client and will only support the TLS 1.2
  277. protocol. This function allocates memory for and initializes a new
  278. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  279. with wolfSSL_CTX_new().
  280. \return * If successful, the call will return a pointer to the newly
  281. created WOLFSSL_METHOD structure.
  282. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  283. value of the underlying malloc() implementation will be returned
  284. (typically NULL with errno will be set to ENOMEM).
  285. \param none No parameters.
  286. _Example_
  287. \code
  288. #include <wolfssl/ssl.h>
  289. WOLFSSL_METHOD* method;
  290. WOLFSSL_CTX* ctx;
  291. method = wolfTLSv1_2_client_method();
  292. if (method == NULL) {
  293. // unable to get method
  294. }
  295. ctx = wolfSSL_CTX_new(method);
  296. ...
  297. \endcode
  298. \sa wolfSSLv3_client_method
  299. \sa wolfTLSv1_client_method
  300. \sa wolfTLSv1_1_client_method
  301. \sa wolfTLSv1_3_client_method
  302. \sa wolfDTLSv1_client_method
  303. \sa wolfSSLv23_client_method
  304. \sa wolfSSL_CTX_new
  305. */
  306. WOLFSSL_METHOD *wolfTLSv1_2_client_method(void);
  307. /*!
  308. \ingroup Setup
  309. \brief The wolfDTLSv1_client_method() function is used to indicate that
  310. the application is a client and will only support the DTLS 1.0 protocol.
  311. This function allocates memory for and initializes a new
  312. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  313. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  314. been compiled with DTLS support (--enable-dtls,
  315. or by defining wolfSSL_DTLS).
  316. \return * If successful, the call will return a pointer to the newly
  317. created WOLFSSL_METHOD structure.
  318. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  319. value of the underlying malloc() implementation will be returned
  320. (typically NULL with errno will be set to ENOMEM).
  321. \param none No parameters.
  322. _Example_
  323. \code
  324. WOLFSSL_METHOD* method;
  325. WOLFSSL_CTX* ctx;
  326. method = wolfDTLSv1_client_method();
  327. if (method == NULL) {
  328. // unable to get method
  329. }
  330. ctx = wolfSSL_CTX_new(method);
  331. ...
  332. \endcode
  333. \sa wolfSSLv3_client_method
  334. \sa wolfTLSv1_client_method
  335. \sa wolfTLSv1_1_client_method
  336. \sa wolfTLSv1_2_client_method
  337. \sa wolfTLSv1_3_client_method
  338. \sa wolfSSLv23_client_method
  339. \sa wolfSSL_CTX_new
  340. */
  341. WOLFSSL_METHOD *wolfDTLSv1_client_method(void);
  342. /*!
  343. \ingroup Setup
  344. \brief The wolfDTLSv1_server_method() function is used to indicate
  345. that the application is a server and will only support the DTLS 1.0
  346. protocol. This function allocates memory for and initializes a
  347. new wolfSSL_METHOD structure to be used when creating the SSL/TLS
  348. context with wolfSSL_CTX_new(). This function is only available
  349. when wolfSSL has been compiled with DTLS support (--enable-dtls,
  350. or by defining wolfSSL_DTLS).
  351. \return * If successful, the call will return a pointer to the newly
  352. created WOLFSSL_METHOD structure.
  353. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  354. value of the underlying malloc() implementation will be returned
  355. (typically NULL with errno will be set to ENOMEM).
  356. \param none No parameters.
  357. _Example_
  358. \code
  359. WOLFSSL_METHOD* method;
  360. WOLFSSL_CTX* ctx;
  361. method = wolfDTLSv1_server_method();
  362. if (method == NULL) {
  363. // unable to get method
  364. }
  365. ctx = wolfSSL_CTX_new(method);
  366. ...
  367. \endcode
  368. \sa wolfSSLv3_server_method
  369. \sa wolfTLSv1_server_method
  370. \sa wolfTLSv1_1_server_method
  371. \sa wolfTLSv1_2_server_method
  372. \sa wolfTLSv1_3_server_method
  373. \sa wolfSSLv23_server_method
  374. \sa wolfSSL_CTX_new
  375. */
  376. WOLFSSL_METHOD *wolfDTLSv1_server_method(void);
  377. /*!
  378. \ingroup Setup
  379. \brief The wolfDTLSv1_3_server_method() function is used to indicate that
  380. the application is a server and will only support the DTLS 1.3
  381. protocol. This function allocates memory for and initializes a new
  382. wolfSSL_METHOD structure to be used when creating the SSL/TLS context with
  383. wolfSSL_CTX_new(). This function is only available when wolfSSL has been
  384. compiled with DTLSv1.3 support (--enable-dtls13, or by defining
  385. wolfSSL_DTLS13).
  386. \return * If successful, the call will return a pointer to the newly
  387. created WOLFSSL_METHOD structure.
  388. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  389. value of the underlying malloc() implementation will be returned
  390. (typically NULL with errno will be set to ENOMEM).
  391. \param none No parameters.
  392. _Example_
  393. \code
  394. WOLFSSL_METHOD* method;
  395. WOLFSSL_CTX* ctx;
  396. method = wolfDTLSv1_3_server_method();
  397. if (method == NULL) {
  398. // unable to get method
  399. }
  400. ctx = wolfSSL_CTX_new(method);
  401. ...
  402. \endcode
  403. \sa wolfDTLSv1_3_client_method
  404. */
  405. WOLFSSL_METHOD *wolfDTLSv1_3_server_method(void);
  406. /*!
  407. \ingroup Setup
  408. \brief The wolfDTLSv1_3_client_method() function is used to indicate that
  409. the application is a client and will only support the DTLS 1.3
  410. protocol. This function allocates memory for and initializes a new
  411. wolfSSL_METHOD structure to be used when creating the SSL/TLS context with
  412. wolfSSL_CTX_new(). This function is only available when wolfSSL has been
  413. compiled with DTLSv1.3 support (--enable-dtls13, or by defining
  414. wolfSSL_DTLS13).
  415. \return * If successful, the call will return a pointer to the newly
  416. created WOLFSSL_METHOD structure.
  417. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  418. value of the underlying malloc() implementation will be returned
  419. (typically NULL with errno will be set to ENOMEM).
  420. \param none No parameters.
  421. _Example_
  422. \code
  423. WOLFSSL_METHOD* method;
  424. WOLFSSL_CTX* ctx;
  425. method = wolfDTLSv1_3_client_method();
  426. if (method == NULL) {
  427. // unable to get method
  428. }
  429. ctx = wolfSSL_CTX_new(method);
  430. ...
  431. \endcode
  432. \sa wolfDTLSv1_3_server_method
  433. */
  434. WOLFSSL_METHOD* wolfDTLSv1_3_client_method(void);
  435. /*!
  436. \ingroup Setup
  437. \brief The wolfDTLS_server_method() function is used to indicate that the
  438. application is a server and will support the highest version of DTLS
  439. available and all the version up to the minimum version allowed. The
  440. default minimum version allowed is based on the define
  441. WOLFSSL_MIN_DTLS_DOWNGRADE and can be changed at runtime using
  442. wolfSSL_SetMinVersion(). This function allocates memory for and initializes
  443. a new wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  444. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  445. been compiled with DTLS support (--enable-dtls, or by defining
  446. wolfSSL_DTLS).
  447. \return * If successful, the call will return a pointer to the newly
  448. created WOLFSSL_METHOD structure.
  449. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  450. value of the underlying malloc() implementation will be returned
  451. (typically NULL with errno will be set to ENOMEM).
  452. \param none No parameters.
  453. _Example_
  454. \code
  455. WOLFSSL_METHOD* method;
  456. WOLFSSL_CTX* ctx;
  457. method = wolfDTLS_server_method();
  458. if (method == NULL) {
  459. // unable to get method
  460. }
  461. ctx = wolfSSL_CTX_new(method);
  462. ...
  463. \endcode
  464. \sa wolfDTLS_client_method
  465. \sa wolfSSL_SetMinVersion
  466. */
  467. WOLFSSL_METHOD *wolfDTLS_server_method(void);
  468. /*!
  469. \ingroup Setup
  470. \brief The wolfDTLS_client_method() function is used to indicate that the
  471. application is a client and will support the highest version of DTLS
  472. available and all the version up to the minimum version allowed. The
  473. default minimum version allowed is based on the define
  474. WOLFSSL_MIN_DTLS_DOWNGRADE and can be changed at runtime using
  475. wolfSSL_SetMinVersion(). This function allocates memory for and initializes
  476. a new wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  477. with wolfSSL_CTX_new(). This function is only available when wolfSSL has
  478. been compiled with DTLS support (--enable-dtls, or by defining
  479. wolfSSL_DTLS).
  480. \return * If successful, the call will return a pointer to the newly
  481. created WOLFSSL_METHOD structure.
  482. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  483. value of the underlying malloc() implementation will be returned
  484. (typically NULL with errno will be set to ENOMEM).
  485. \param none No parameters.
  486. _Example_
  487. \code
  488. WOLFSSL_METHOD* method;
  489. WOLFSSL_CTX* ctx;
  490. method = wolfDTLS_client_method();
  491. if (method == NULL) {
  492. // unable to get method
  493. }
  494. ctx = wolfSSL_CTX_new(method);
  495. ...
  496. \endcode
  497. \sa wolfDTLS_server_method
  498. \sa wolfSSL_SetMinVersion
  499. */
  500. WOLFSSL_METHOD *wolfDTLS_client_method(void);
  501. /*!
  502. \brief This function creates and initializes a WOLFSSL_METHOD for the
  503. server side.
  504. \return This function returns a WOLFSSL_METHOD pointer.
  505. \param none No parameters.
  506. _Example_
  507. \code
  508. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  509. WOLFSSL* ssl = WOLFSSL_new(ctx);
  510. \endcode
  511. \sa wolfSSL_CTX_new
  512. */
  513. WOLFSSL_METHOD *wolfDTLSv1_2_server_method(void);
  514. /*!
  515. \ingroup Setup
  516. \brief Since there is some differences between the first release and
  517. newer versions of chacha-poly AEAD construction we have added an option
  518. to communicate with servers/clients using the older version. By default
  519. wolfSSL uses the new version.
  520. \return 0 upon success
  521. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  522. \param value whether or not to use the older version of setting up the
  523. information for poly1305. Passing a flag value of 1 indicates yes use the
  524. old poly AEAD, to switch back to using the new version pass a flag value
  525. of 0.
  526. _Example_
  527. \code
  528. int ret = 0;
  529. WOLFSSL* ssl;
  530. ...
  531. ret = wolfSSL_use_old_poly(ssl, 1);
  532. if (ret != 0) {
  533. // failed to set poly1305 AEAD version
  534. }
  535. \endcode
  536. \sa none
  537. */
  538. int wolfSSL_use_old_poly(WOLFSSL* ssl, int value);
  539. /*!
  540. \brief The wolfSSL_dtls_import() function is used to parse in a serialized
  541. session state. This allows for picking up the connection after the
  542. handshake has been completed.
  543. \return Success If successful, the amount of the buffer read will be
  544. returned.
  545. \return Failure All unsuccessful return values will be less than 0.
  546. \return VERSION_ERROR If a version mismatch is found ie DTLS v1 and ctx
  547. was set up for DTLS v1.2 then VERSION_ERROR is returned.
  548. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  549. \param buf serialized session to import.
  550. \param sz size of serialized session buffer.
  551. _Example_
  552. \code
  553. WOLFSSL* ssl;
  554. int ret;
  555. unsigned char buf[MAX];
  556. bufSz = MAX;
  557. ...
  558. //get information sent from wc_dtls_export function and place it in buf
  559. fread(buf, 1, bufSz, input);
  560. ret = wolfSSL_dtls_import(ssl, buf, bufSz);
  561. if (ret < 0) {
  562. // handle error case
  563. }
  564. // no wolfSSL_accept needed since handshake was already done
  565. ...
  566. ret = wolfSSL_write(ssl) and wolfSSL_read(ssl);
  567. ...
  568. \endcode
  569. \sa wolfSSL_new
  570. \sa wolfSSL_CTX_new
  571. \sa wolfSSL_CTX_dtls_set_export
  572. */
  573. int wolfSSL_dtls_import(WOLFSSL* ssl, unsigned char* buf,
  574. unsigned int sz);
  575. /*!
  576. \brief Used to import a serialized TLS session. This function is for
  577. importing the state of the connection.
  578. WARNING: buf contains sensitive information about the state and is best to
  579. be encrypted before storing if stored.
  580. Additional debug info can be displayed with the macro
  581. WOLFSSL_SESSION_EXPORT_DEBUG defined.
  582. \return the number of bytes read from buffer 'buf'
  583. \param ssl WOLFSSL structure to import the session into
  584. \param buf serialized session
  585. \param sz size of buffer 'buf'
  586. \sa wolfSSL_dtls_import
  587. \sa wolfSSL_tls_export
  588. */
  589. int wolfSSL_tls_import(WOLFSSL* ssl, const unsigned char* buf,
  590. unsigned int sz);
  591. /*!
  592. \brief The wolfSSL_CTX_dtls_set_export() function is used to set
  593. the callback function for exporting a session. It is allowed to
  594. pass in NULL as the parameter func to clear the export function
  595. previously stored. Used on the server side and is called immediately
  596. after handshake is completed.
  597. \return SSL_SUCCESS upon success.
  598. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  599. \param ctx a pointer to a WOLFSSL_CTX structure, created
  600. with wolfSSL_CTX_new().
  601. \param func wc_dtls_export function to use when exporting a session.
  602. _Example_
  603. \code
  604. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  605. // body of send session (wc_dtls_export) that passses
  606. // buf (serialized session) to destination
  607. WOLFSSL_CTX* ctx;
  608. int ret;
  609. ...
  610. ret = wolfSSL_CTX_dtls_set_export(ctx, send_session);
  611. if (ret != SSL_SUCCESS) {
  612. // handle error case
  613. }
  614. ...
  615. ret = wolfSSL_accept(ssl);
  616. ...
  617. \endcode
  618. \sa wolfSSL_new
  619. \sa wolfSSL_CTX_new
  620. \sa wolfSSL_dtls_set_export
  621. \sa Static buffer use
  622. */
  623. int wolfSSL_CTX_dtls_set_export(WOLFSSL_CTX* ctx,
  624. wc_dtls_export func);
  625. /*!
  626. \brief The wolfSSL_dtls_set_export() function is used to set the callback
  627. function for exporting a session. It is allowed to pass in NULL as the
  628. parameter func to clear the export function previously stored. Used on
  629. the server side and is called immediately after handshake is completed.
  630. \return SSL_SUCCESS upon success.
  631. \return BAD_FUNC_ARG If null or not expected arguments are passed in
  632. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  633. \param func wc_dtls_export function to use when exporting a session.
  634. _Example_
  635. \code
  636. int send_session(WOLFSSL* ssl, byte* buf, word32 sz, void* userCtx);
  637. // body of send session (wc_dtls_export) that passses
  638. // buf (serialized session) to destination
  639. WOLFSSL* ssl;
  640. int ret;
  641. ...
  642. ret = wolfSSL_dtls_set_export(ssl, send_session);
  643. if (ret != SSL_SUCCESS) {
  644. // handle error case
  645. }
  646. ...
  647. ret = wolfSSL_accept(ssl);
  648. ...
  649. \endcode
  650. \sa wolfSSL_new
  651. \sa wolfSSL_CTX_new
  652. \sa wolfSSL_CTX_dtls_set_export
  653. */
  654. int wolfSSL_dtls_set_export(WOLFSSL* ssl, wc_dtls_export func);
  655. /*!
  656. \brief The wolfSSL_dtls_export() function is used to serialize a
  657. WOLFSSL session into the provided buffer. Allows for less memory
  658. overhead than using a function callback for sending a session and
  659. choice over when the session is serialized. If buffer is NULL when
  660. passed to function then sz will be set to the size of buffer needed
  661. for serializing the WOLFSSL session.
  662. \return Success If successful, the amount of the buffer used will
  663. be returned.
  664. \return Failure All unsuccessful return values will be less than 0.
  665. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  666. \param buf buffer to hold serialized session.
  667. \param sz size of buffer.
  668. _Example_
  669. \code
  670. WOLFSSL* ssl;
  671. int ret;
  672. unsigned char buf[MAX];
  673. bufSz = MAX;
  674. ...
  675. ret = wolfSSL_dtls_export(ssl, buf, bufSz);
  676. if (ret < 0) {
  677. // handle error case
  678. }
  679. ...
  680. \endcode
  681. \sa wolfSSL_new
  682. \sa wolfSSL_CTX_new
  683. \sa wolfSSL_CTX_dtls_set_export
  684. \sa wolfSSL_dtls_import
  685. */
  686. int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf,
  687. unsigned int* sz);
  688. /*!
  689. \brief Used to export a serialized TLS session. This function is for
  690. importing a serialized state of the connection.
  691. In most cases wolfSSL_get1_session should be used instead of
  692. wolfSSL_tls_export.
  693. Additional debug info can be displayed with the macro
  694. WOLFSSL_SESSION_EXPORT_DEBUG defined.
  695. WARNING: buf contains sensitive information about the state and is best to
  696. be encrypted before storing if stored.
  697. \return the number of bytes written into buffer 'buf'
  698. \param ssl WOLFSSL structure to export the session from
  699. \param buf output of serialized session
  700. \param sz size in bytes set in 'buf'
  701. \sa wolfSSL_dtls_import
  702. \sa wolfSSL_tls_import
  703. */
  704. int wolfSSL_tls_export(WOLFSSL* ssl, unsigned char* buf,
  705. unsigned int* sz);
  706. /*!
  707. \brief This function is used to set aside static memory for a CTX. Memory
  708. set aside is then used for the CTX’s lifetime and for any SSL objects
  709. created from the CTX. By passing in a NULL ctx pointer and a
  710. wolfSSL_method_func function the creation of the CTX itself will also
  711. use static memory. wolfSSL_method_func has the function signature of
  712. WOLFSSL_METHOD* (*wolfSSL_method_func)(void* heap);. Passing in 0 for max
  713. makes it behave as if not set and no max concurrent use restrictions is
  714. in place. The flag value passed in determines how the memory is used and
  715. behavior while operating. Available flags are the following: 0 - default
  716. general memory, WOLFMEM_IO_POOL - used for input/output buffer when
  717. sending receiving messages and overrides general memory, so all memory
  718. in buffer passed in is used for IO, WOLFMEM_IO_FIXED - same as
  719. WOLFMEM_IO_POOL but each SSL now keeps two buffers to themselves for
  720. their lifetime, WOLFMEM_TRACK_STATS - each SSL keeps track of memory
  721. stats while running.
  722. \return SSL_SUCCESS upon success.
  723. \return SSL_FAILURE upon failure.
  724. \param ctx address of pointer to a WOLFSSL_CTX structure.
  725. \param method function to create protocol. (should be NULL if ctx is not
  726. also NULL)
  727. \param buf memory to use for all operations.
  728. \param sz size of memory buffer being passed in.
  729. \param flag type of memory.
  730. \param max max concurrent operations.
  731. _Example_
  732. \code
  733. WOLFSSL_CTX* ctx;
  734. WOLFSSL* ssl;
  735. int ret;
  736. unsigned char memory[MAX];
  737. int memorySz = MAX;
  738. unsigned char IO[MAX];
  739. int IOSz = MAX;
  740. int flag = WOLFMEM_IO_FIXED | WOLFMEM_TRACK_STATS;
  741. ...
  742. // create ctx also using static memory, start with general memory to use
  743. ctx = NULL:
  744. ret = wolfSSL_CTX_load_static_memory(&ctx, wolfSSLv23_server_method_ex,
  745. memory, memorySz, 0, MAX_CONCURRENT_HANDSHAKES);
  746. if (ret != SSL_SUCCESS) {
  747. // handle error case
  748. }
  749. // load in memory for use with IO
  750. ret = wolfSSL_CTX_load_static_memory(&ctx, NULL, IO, IOSz, flag,
  751. MAX_CONCURRENT_IO);
  752. if (ret != SSL_SUCCESS) {
  753. // handle error case
  754. }
  755. ...
  756. \endcode
  757. \sa wolfSSL_CTX_new
  758. \sa wolfSSL_CTX_is_static_memory
  759. \sa wolfSSL_is_static_memory
  760. */
  761. int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx,
  762. wolfSSL_method_func method,
  763. unsigned char* buf, unsigned int sz,
  764. int flag, int max);
  765. /*!
  766. \brief This function does not change any of the connections behavior
  767. and is used only for gathering information about the static memory usage.
  768. \return 1 is returned if using static memory for the CTX is true.
  769. \return 0 is returned if not using static memory.
  770. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  771. wolfSSL_CTX_new().
  772. \param mem_stats structure to hold information about static memory usage.
  773. _Example_
  774. \code
  775. WOLFSSL_CTX* ctx;
  776. int ret;
  777. WOLFSSL_MEM_STATS mem_stats;
  778. ...
  779. //get information about static memory with CTX
  780. ret = wolfSSL_CTX_is_static_memory(ctx, &mem_stats);
  781. if (ret == 1) {
  782. // handle case of is using static memory
  783. // print out or inspect elements of mem_stats
  784. }
  785. if (ret == 0) {
  786. //handle case of ctx not using static memory
  787. }
  788. \endcode
  789. \sa wolfSSL_CTX_new
  790. \sa wolfSSL_CTX_load_static_memory
  791. \sa wolfSSL_is_static_memory
  792. */
  793. int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX* ctx,
  794. WOLFSSL_MEM_STATS* mem_stats);
  795. /*!
  796. \brief wolfSSL_is_static_memory is used to gather information about
  797. a SSL’s static memory usage. The return value indicates if static
  798. memory is being used and WOLFSSL_MEM_CONN_STATS will be filled out
  799. if and only if the flag WOLFMEM_TRACK_STATS was passed to the parent
  800. CTX when loading in static memory.
  801. \return 1 is returned if using static memory for the CTX is true.
  802. \return 0 is returned if not using static memory.
  803. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  804. \param mem_stats structure to contain static memory usage.
  805. _Example_
  806. \code
  807. WOLFSSL* ssl;
  808. int ret;
  809. WOLFSSL_MEM_CONN_STATS mem_stats;
  810. ...
  811. ret = wolfSSL_is_static_memory(ssl, mem_stats);
  812. if (ret == 1) {
  813. // handle case when is static memory
  814. // investigate elements in mem_stats if WOLFMEM_TRACK_STATS flag
  815. }
  816. ...
  817. \endcode
  818. \sa wolfSSL_new
  819. \sa wolfSSL_CTX_is_static_memory
  820. */
  821. int wolfSSL_is_static_memory(WOLFSSL* ssl,
  822. WOLFSSL_MEM_CONN_STATS* mem_stats);
  823. /*!
  824. \ingroup CertsKeys
  825. \brief This function loads a certificate file into the SSL context
  826. (WOLFSSL_CTX). The file is provided by the file argument. The
  827. format argument specifies the format type of the file, either
  828. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please see the examples
  829. for proper usage.
  830. \return SSL_SUCCESS upon success.
  831. \return SSL_FAILURE If the function call fails, possible causes might
  832. include the file is in the wrong format, or the wrong format has been
  833. given using the “format” argument, file doesn’t exist, can’t be read,
  834. or is corrupted, an out of memory condition occurs, Base16 decoding
  835. fails on the file.
  836. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  837. wolfSSL_CTX_new()
  838. \param file a pointer to the name of the file containing the certificate
  839. to be loaded into the wolfSSL SSL context.
  840. \param format - format of the certificates pointed to by file. Possible
  841. options are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  842. _Example_
  843. \code
  844. int ret = 0;
  845. WOLFSSL_CTX* ctx;
  846. ...
  847. ret = wolfSSL_CTX_use_certificate_file(ctx, “./client-cert.pem”,
  848. SSL_FILETYPE_PEM);
  849. if (ret != SSL_SUCCESS) {
  850. // error loading cert file
  851. }
  852. ...
  853. \endcode
  854. \sa wolfSSL_CTX_use_certificate_buffer
  855. \sa wolfSSL_use_certificate_file
  856. \sa wolfSSL_use_certificate_buffer
  857. */
  858. int wolfSSL_CTX_use_certificate_file(WOLFSSL_CTX* ctx, const char* file,
  859. int format);
  860. /*!
  861. \ingroup CertsKeys
  862. \brief This function loads a private key file into the SSL context
  863. (WOLFSSL_CTX). The file is provided by the file argument. The format
  864. argument specifies the format type of the file - SSL_FILETYPE_ASN1or
  865. SSL_FILETYPE_PEM. Please see the examples for proper usage.
  866. If using an external key store and do not have the private key you can
  867. instead provide the public key and register the crypro callback to handle
  868. the signing. For this you can build with either build with crypto callbacks
  869. or PK callbacks. To enable crypto callbacks use --enable-cryptocb
  870. or WOLF_CRYPTO_CB and register a crypto callback using
  871. wc_CryptoCb_RegisterDevice and set the associated devId using
  872. wolfSSL_CTX_SetDevId.
  873. \return SSL_SUCCESS upon success.
  874. \return SSL_FAILURE The file is in the wrong format, or the wrong format
  875. has been given using the “format” argument. The file doesn’t exist, can’t
  876. be read, or is corrupted. An out of memory condition occurs. Base16
  877. decoding fails on the file. The key file is encrypted but no password
  878. is provided.
  879. \param none No parameters.
  880. _Example_
  881. \code
  882. int ret = 0;
  883. WOLFSSL_CTX* ctx;
  884. ...
  885. ret = wolfSSL_CTX_use_PrivateKey_file(ctx, “./server-key.pem”,
  886. SSL_FILETYPE_PEM);
  887. if (ret != SSL_SUCCESS) {
  888. // error loading key file
  889. }
  890. ...
  891. \endcode
  892. \sa wolfSSL_CTX_use_PrivateKey_buffer
  893. \sa wolfSSL_use_PrivateKey_file
  894. \sa wolfSSL_use_PrivateKey_buffer
  895. \sa wc_CryptoCb_RegisterDevice
  896. \sa wolfSSL_CTX_SetDevId
  897. */
  898. int wolfSSL_CTX_use_PrivateKey_file(WOLFSSL_CTX* ctx, const char* file, int format);
  899. /*!
  900. \ingroup CertsKeys
  901. \brief This function loads PEM-formatted CA certificate files into the SSL
  902. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  903. certificates and used to verify certs received from peers during the SSL
  904. handshake. The root certificate file, provided by the file argument, may
  905. be a single certificate or a file containing multiple certificates.
  906. If multiple CA certs are included in the same file, wolfSSL will load them
  907. in the same order they are presented in the file. The path argument is
  908. a pointer to the name of a directory that contains certificates of
  909. trusted root CAs. If the value of file is not NULL, path may be specified
  910. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  911. defined when building the library, wolfSSL will load all CA certificates
  912. located in the given directory. This function will attempt to load all
  913. files in the directory. This function expects PEM formatted CERT_TYPE
  914. file with header “-----BEGIN CERTIFICATE-----”.
  915. \return SSL_SUCCESS up success.
  916. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  917. path are NULL.
  918. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  919. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  920. read, or is corrupted.
  921. \return MEMORY_E will be returned if an out of memory condition occurs.
  922. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  923. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  924. before date.
  925. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  926. after date.
  927. \return BUFFER_E will be returned if a chain buffer is bigger than the
  928. receiving buffer.
  929. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  930. to open path.
  931. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  932. \param file pointer to name of the file containing PEM-formatted CA
  933. certificates.
  934. \param path pointer to the name of a directory to load PEM-formatted
  935. certificates from.
  936. _Example_
  937. \code
  938. int ret = 0;
  939. WOLFSSL_CTX* ctx;
  940. ...
  941. ret = wolfSSL_CTX_load_verify_locations(ctx, “./ca-cert.pem”, NULL);
  942. if (ret != WOLFSSL_SUCCESS) {
  943. // error loading CA certs
  944. }
  945. ...
  946. \endcode
  947. \sa wolfSSL_CTX_load_verify_locations_ex
  948. \sa wolfSSL_CTX_load_verify_buffer
  949. \sa wolfSSL_CTX_use_certificate_file
  950. \sa wolfSSL_CTX_use_PrivateKey_file
  951. \sa wolfSSL_CTX_use_certificate_chain_file
  952. \sa wolfSSL_use_certificate_file
  953. \sa wolfSSL_use_PrivateKey_file
  954. \sa wolfSSL_use_certificate_chain_file
  955. */
  956. int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
  957. const char* format);
  958. /*!
  959. \ingroup CertsKeys
  960. \brief This function loads PEM-formatted CA certificate files into the SSL
  961. context (WOLFSSL_CTX). These certificates will be treated as trusted root
  962. certificates and used to verify certs received from peers during the SSL
  963. handshake. The root certificate file, provided by the file argument, may
  964. be a single certificate or a file containing multiple certificates.
  965. If multiple CA certs are included in the same file, wolfSSL will load them
  966. in the same order they are presented in the file. The path argument is
  967. a pointer to the name of a directory that contains certificates of
  968. trusted root CAs. If the value of file is not NULL, path may be specified
  969. as NULL if not needed. If path is specified and NO_WOLFSSL_DIR was not
  970. defined when building the library, wolfSSL will load all CA certificates
  971. located in the given directory. This function will attempt to load all
  972. files in the directory based on flags specified. This function expects PEM
  973. formatted CERT_TYPE files with header “-----BEGIN CERTIFICATE-----”.
  974. \return SSL_SUCCESS up success.
  975. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  976. path are NULL. This will also be returned if at least one cert is loaded
  977. successfully but there is one or more that failed. Check error stack for reason.
  978. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  979. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  980. read, or is corrupted.
  981. \return MEMORY_E will be returned if an out of memory condition occurs.
  982. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  983. \return BUFFER_E will be returned if a chain buffer is bigger than the
  984. receiving buffer.
  985. \return BAD_PATH_ERROR will be returned if opendir() fails when trying
  986. to open path.
  987. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  988. \param file pointer to name of the file containing PEM-formatted CA
  989. certificates.
  990. \param path pointer to the name of a directory to load PEM-formatted
  991. certificates from.
  992. \param flags possible mask values are: WOLFSSL_LOAD_FLAG_IGNORE_ERR,
  993. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY and WOLFSSL_LOAD_FLAG_PEM_CA_ONLY
  994. _Example_
  995. \code
  996. int ret = 0;
  997. WOLFSSL_CTX* ctx;
  998. ...
  999. ret = wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, “./certs/external",
  1000. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY);
  1001. if (ret != WOLFSSL_SUCCESS) {
  1002. // error loading CA certs
  1003. }
  1004. ...
  1005. \endcode
  1006. \sa wolfSSL_CTX_load_verify_locations
  1007. \sa wolfSSL_CTX_load_verify_buffer
  1008. \sa wolfSSL_CTX_use_certificate_file
  1009. \sa wolfSSL_CTX_use_PrivateKey_file
  1010. \sa wolfSSL_CTX_use_certificate_chain_file
  1011. \sa wolfSSL_use_certificate_file
  1012. \sa wolfSSL_use_PrivateKey_file
  1013. \sa wolfSSL_use_certificate_chain_file
  1014. */
  1015. int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
  1016. const char* path, unsigned int flags);
  1017. /*!
  1018. \ingroup Setup
  1019. \brief This function loads a certificate to use for verifying a peer
  1020. when performing a TLS/SSL handshake. The peer certificate sent during the
  1021. handshake is compared by using the SKID when available and the signature.
  1022. If these two things do not match then any loaded CAs are used. Feature is
  1023. enabled by defining the macro WOLFSSL_TRUST_PEER_CERT. Please see the
  1024. examples for proper usage.
  1025. \return SSL_SUCCES upon success.
  1026. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  1027. type are invalid.
  1028. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  1029. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  1030. read, or is corrupted.
  1031. \return MEMORY_E will be returned if an out of memory condition occurs.
  1032. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  1033. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1034. \param file pointer to name of the file containing certificates
  1035. \param type type of certificate being loaded ie SSL_FILETYPE_ASN1
  1036. or SSL_FILETYPE_PEM.
  1037. _Example_
  1038. \code
  1039. int ret = 0;
  1040. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1041. ...
  1042. ret = wolfSSL_CTX_trust_peer_cert(ctx, “./peer-cert.pem”,
  1043. SSL_FILETYPE_PEM);
  1044. if (ret != SSL_SUCCESS) {
  1045. // error loading trusted peer cert
  1046. }
  1047. ...
  1048. \endcode
  1049. \sa wolfSSL_CTX_load_verify_buffer
  1050. \sa wolfSSL_CTX_use_certificate_file
  1051. \sa wolfSSL_CTX_use_PrivateKey_file
  1052. \sa wolfSSL_CTX_use_certificate_chain_file
  1053. \sa wolfSSL_CTX_trust_peer_buffer
  1054. \sa wolfSSL_CTX_Unload_trust_peers
  1055. \sa wolfSSL_use_certificate_file
  1056. \sa wolfSSL_use_PrivateKey_file
  1057. \sa wolfSSL_use_certificate_chain_file
  1058. */
  1059. int wolfSSL_CTX_trust_peer_cert(WOLFSSL_CTX* ctx, const char* file, int type);
  1060. /*!
  1061. \ingroup CertsKeys
  1062. \brief This function loads a chain of certificates into the SSL
  1063. context (WOLFSSL_CTX). The file containing the certificate chain
  1064. is provided by the file argument, and must contain PEM-formatted
  1065. certificates. This function will process up to MAX_CHAIN_DEPTH
  1066. (default = 9, defined in internal.h) certificates, plus the subject cert.
  1067. \return SSL_SUCCESS upon success
  1068. \return SSL_FAILURE If the function call fails, possible causes might
  1069. include the file is in the wrong format, or the wrong format has been
  1070. given using the “format” argument, file doesn’t exist, can’t be read,
  1071. or is corrupted, an out of memory condition occurs.
  1072. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1073. wolfSSL_CTX_new()
  1074. \param file a pointer to the name of the file containing the chain of
  1075. certificates to be loaded into the wolfSSL SSL context. Certificates
  1076. must be in PEM format.
  1077. _Example_
  1078. \code
  1079. int ret = 0;
  1080. WOLFSSL_CTX* ctx;
  1081. ...
  1082. ret = wolfSSL_CTX_use_certificate_chain_file(ctx, “./cert-chain.pem”);
  1083. if (ret != SSL_SUCCESS) {
  1084. // error loading cert file
  1085. }
  1086. ...
  1087. \endcode
  1088. \sa wolfSSL_CTX_use_certificate_file
  1089. \sa wolfSSL_CTX_use_certificate_buffer
  1090. \sa wolfSSL_use_certificate_file
  1091. \sa wolfSSL_use_certificate_buffer
  1092. */
  1093. int wolfSSL_CTX_use_certificate_chain_file(WOLFSSL_CTX *ctx,
  1094. const char *file);
  1095. /*!
  1096. \ingroup openSSL
  1097. \brief This function loads the private RSA key used in the SSL connection
  1098. into the SSL context (WOLFSSL_CTX). This function is only available when
  1099. wolfSSL has been compiled with the OpenSSL compatibility layer enabled
  1100. (--enable-opensslExtra, #define OPENSSL_EXTRA), and is identical to the
  1101. more-typically used wolfSSL_CTX_use_PrivateKey_file() function. The file
  1102. argument contains a pointer to the RSA private key file, in the format
  1103. specified by format.
  1104. \return SSL_SUCCESS upon success.
  1105. \return SSL_FAILURE If the function call fails, possible causes might
  1106. include: The input key file is in the wrong format, or the wrong format
  1107. has been given using the “format” argument, file doesn’t exist, can’t
  1108. be read, or is corrupted, an out of memory condition occurs.
  1109. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1110. wolfSSL_CTX_new()
  1111. \param file a pointer to the name of the file containing the RSA private
  1112. key to be loaded into the wolfSSL SSL context, with format as specified
  1113. by format.
  1114. \param format the encoding type of the RSA private key specified by file.
  1115. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1116. _Example_
  1117. \code
  1118. int ret = 0;
  1119. WOLFSSL_CTX* ctx;
  1120. ...
  1121. ret = wolfSSL_CTX_use_RSAPrivateKey_file(ctx, “./server-key.pem”,
  1122. SSL_FILETYPE_PEM);
  1123. if (ret != SSL_SUCCESS) {
  1124. // error loading private key file
  1125. }
  1126. ...
  1127. \endcode
  1128. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1129. \sa wolfSSL_CTX_use_PrivateKey_file
  1130. \sa wolfSSL_use_RSAPrivateKey_file
  1131. \sa wolfSSL_use_PrivateKey_buffer
  1132. \sa wolfSSL_use_PrivateKey_file
  1133. */
  1134. int wolfSSL_CTX_use_RSAPrivateKey_file(WOLFSSL_CTX* ctx, const char* file, int format);
  1135. /*!
  1136. \ingroup IO
  1137. \brief This function returns the maximum chain depth allowed, which is 9 by
  1138. default, for a valid session i.e. there is a non-null session object (ssl).
  1139. \return MAX_CHAIN_DEPTH returned if the WOLFSSL_CTX structure is not
  1140. NULL. By default the value is 9.
  1141. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  1142. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1143. _Example_
  1144. \code
  1145. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1146. WOLFSSL* ssl = wolfSSL_new(ctx);
  1147. ...
  1148. long sslDep = wolfSSL_get_verify_depth(ssl);
  1149. if(sslDep > EXPECTED){
  1150. // The verified depth is greater than what was expected
  1151. } else {
  1152. // The verified depth is smaller or equal to the expected value
  1153. }
  1154. \endcode
  1155. \sa wolfSSL_CTX_get_verify_depth
  1156. */
  1157. long wolfSSL_get_verify_depth(WOLFSSL* ssl);
  1158. /*!
  1159. \ingroup Setup
  1160. \brief This function gets the certificate chaining depth using the
  1161. CTX structure.
  1162. \return MAX_CHAIN_DEPTH returned if the CTX struct is not NULL. The
  1163. constant representation of the max certificate chain peer depth.
  1164. \return BAD_FUNC_ARG returned if the CTX structure is NULL.
  1165. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1166. wolfSSL_CTX_new().
  1167. _Example_
  1168. \code
  1169. WOLFSSL_METHOD method; // protocol method
  1170. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  1171. long ret = wolfSSL_CTX_get_verify_depth(ctx);
  1172. if(ret == EXPECTED){
  1173. // You have the expected value
  1174. } else {
  1175. // Handle an unexpected depth
  1176. }
  1177. \endcode
  1178. \sa wolfSSL_CTX_use_certificate_chain_file
  1179. \sa wolfSSL_get_verify_depth
  1180. */
  1181. long wolfSSL_CTX_get_verify_depth(WOLFSSL_CTX* ctx);
  1182. /*!
  1183. \ingroup openSSL
  1184. \brief This function loads a certificate file into the SSL session
  1185. (WOLFSSL structure). The certificate file is provided by the file
  1186. argument. The format argument specifies the format type of the file -
  1187. either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1188. \return SSL_SUCCESS upon success
  1189. \return SSL_FAILURE If the function call fails, possible causes might
  1190. include: The file is in the wrong format, or the wrong format has been
  1191. given using the “format” argument, file doesn’t exist, can’t be read,
  1192. or is corrupted, an out of memory condition occurs, Base16 decoding
  1193. fails on the file
  1194. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1195. \param file a pointer to the name of the file containing the certificate to
  1196. be loaded into the wolfSSL SSL session, with format as specified by format.
  1197. \param format the encoding type of the certificate specified by file.
  1198. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1199. _Example_
  1200. \code
  1201. int ret = 0;
  1202. WOLFSSL* ssl;
  1203. ...
  1204. ret = wolfSSL_use_certificate_file(ssl, “./client-cert.pem”,
  1205. SSL_FILETYPE_PEM);
  1206. if (ret != SSL_SUCCESS) {
  1207. // error loading cert file
  1208. }
  1209. ...
  1210. \endcode
  1211. \sa wolfSSL_CTX_use_certificate_buffer
  1212. \sa wolfSSL_CTX_use_certificate_file
  1213. \sa wolfSSL_use_certificate_buffer
  1214. */
  1215. int wolfSSL_use_certificate_file(WOLFSSL* ssl, const char* file, int format);
  1216. /*!
  1217. \ingroup openSSL
  1218. \brief This function loads a private key file into the SSL session
  1219. (WOLFSSL structure). The key file is provided by the file argument.
  1220. The format argument specifies the format type of the file -
  1221. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  1222. If using an external key store and do not have the private key you can
  1223. instead provide the public key and register the crypro callback to handle
  1224. the signing. For this you can build with either build with crypto callbacks
  1225. or PK callbacks. To enable crypto callbacks use --enable-cryptocb or
  1226. WOLF_CRYPTO_CB and register a crypto callback using
  1227. wc_CryptoCb_RegisterDevice and set the associated devId using
  1228. wolfSSL_SetDevId.
  1229. \return SSL_SUCCESS upon success.
  1230. \return SSL_FAILURE If the function call fails, possible causes might
  1231. include: The file is in the wrong format, or the wrong format has been
  1232. given using the “format” argument, The file doesn’t exist, can’t be read,
  1233. or is corrupted, An out of memory condition occurs, Base16 decoding
  1234. fails on the file, The key file is encrypted but no password is provided
  1235. \param ssl a pointer to a WOLFSSL structure, created with wolfSSL_new().
  1236. \param file a pointer to the name of the file containing the key file to
  1237. be loaded into the wolfSSL SSL session, with format as specified by format.
  1238. \param format the encoding type of the key specified by file. Possible
  1239. values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1240. _Example_
  1241. \code
  1242. int ret = 0;
  1243. WOLFSSL* ssl;
  1244. ...
  1245. ret = wolfSSL_use_PrivateKey_file(ssl, “./server-key.pem”,
  1246. SSL_FILETYPE_PEM);
  1247. if (ret != SSL_SUCCESS) {
  1248. // error loading key file
  1249. }
  1250. ...
  1251. \endcode
  1252. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1253. \sa wolfSSL_CTX_use_PrivateKey_file
  1254. \sa wolfSSL_use_PrivateKey_buffer
  1255. \sa wc_CryptoCb_RegisterDevice
  1256. \sa wolfSSL_SetDevId
  1257. */
  1258. int wolfSSL_use_PrivateKey_file(WOLFSSL* ssl, const char* file, int format);
  1259. /*!
  1260. \ingroup openSSL
  1261. \brief This function loads a chain of certificates into the SSL
  1262. session (WOLFSSL structure). The file containing the certificate
  1263. chain is provided by the file argument, and must contain PEM-formatted
  1264. certificates. This function will process up to MAX_CHAIN_DEPTH
  1265. (default = 9, defined in internal.h) certificates, plus the
  1266. subject certificate.
  1267. \return SSL_SUCCESS upon success.
  1268. \return SSL_FAILURE If the function call fails, possible causes
  1269. might include: The file is in the wrong format, or the wrong format
  1270. has been given using the “format” argument, file doesn’t exist,
  1271. can’t be read, or is corrupted, an out of memory condition occurs
  1272. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1273. \param file a pointer to the name of the file containing the chain
  1274. of certificates to be loaded into the wolfSSL SSL session.
  1275. Certificates must be in PEM format.
  1276. _Example_
  1277. \code
  1278. int ret = 0;
  1279. WOLFSSL* ctx;
  1280. ...
  1281. ret = wolfSSL_use_certificate_chain_file(ssl, “./cert-chain.pem”);
  1282. if (ret != SSL_SUCCESS) {
  1283. // error loading cert file
  1284. }
  1285. ...
  1286. \endcode
  1287. \sa wolfSSL_CTX_use_certificate_chain_file
  1288. \sa wolfSSL_CTX_use_certificate_chain_buffer
  1289. \sa wolfSSL_use_certificate_chain_buffer
  1290. */
  1291. int wolfSSL_use_certificate_chain_file(WOLFSSL* ssl, const char *file);
  1292. /*!
  1293. \ingroup openSSL
  1294. \brief This function loads the private RSA key used in the SSL
  1295. connection into the SSL session (WOLFSSL structure). This
  1296. function is only available when wolfSSL has been compiled with
  1297. the OpenSSL compatibility layer enabled (--enable-opensslExtra,
  1298. #define OPENSSL_EXTRA), and is identical to the more-typically
  1299. used wolfSSL_use_PrivateKey_file() function. The file argument
  1300. contains a pointer to the RSA private key file, in the format
  1301. specified by format.
  1302. \return SSL_SUCCESS upon success
  1303. \return SSL_FAILURE If the function call fails, possible causes might
  1304. include: The input key file is in the wrong format, or the wrong format
  1305. has been given using the “format” argument, file doesn’t exist, can’t
  1306. be read, or is corrupted, an out of memory condition occurs
  1307. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new()
  1308. \param file a pointer to the name of the file containing the RSA private
  1309. key to be loaded into the wolfSSL SSL session, with format as specified
  1310. by format.
  1311. \parm format the encoding type of the RSA private key specified by file.
  1312. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1313. _Example_
  1314. \code
  1315. int ret = 0;
  1316. WOLFSSL* ssl;
  1317. ...
  1318. ret = wolfSSL_use_RSAPrivateKey_file(ssl, “./server-key.pem”,
  1319. SSL_FILETYPE_PEM);
  1320. if (ret != SSL_SUCCESS) {
  1321. // error loading private key file
  1322. }
  1323. ...
  1324. \endcode
  1325. \sa wolfSSL_CTX_use_RSAPrivateKey_file
  1326. \sa wolfSSL_CTX_use_PrivateKey_buffer
  1327. \sa wolfSSL_CTX_use_PrivateKey_file
  1328. \sa wolfSSL_use_PrivateKey_buffer
  1329. \sa wolfSSL_use_PrivateKey_file
  1330. */
  1331. int wolfSSL_use_RSAPrivateKey_file(WOLFSSL* ssl, const char* file, int format);
  1332. /*!
  1333. \ingroup CertsKeys
  1334. \brief This function is similar to wolfSSL_CTX_load_verify_locations,
  1335. but allows the loading of DER-formatted CA files into the SSL context
  1336. (WOLFSSL_CTX). It may still be used to load PEM-formatted CA files as
  1337. well. These certificates will be treated as trusted root certificates
  1338. and used to verify certs received from peers during the SSL handshake.
  1339. The root certificate file, provided by the file argument, may be a single
  1340. certificate or a file containing multiple certificates. If multiple CA
  1341. certs are included in the same file, wolfSSL will load them in the same
  1342. order they are presented in the file. The format argument specifies the
  1343. format which the certificates are in either, SSL_FILETYPE_PEM or
  1344. SSL_FILETYPE_ASN1 (DER). Unlike wolfSSL_CTX_load_verify_locations,
  1345. this function does not allow the loading of CA certificates from a given
  1346. directory path. Note that this function is only available when the wolfSSL
  1347. library was compiled with WOLFSSL_DER_LOAD defined.
  1348. \return SSL_SUCCESS upon success.
  1349. \return SSL_FAILURE upon failure.
  1350. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  1351. wolfSSL_CTX_new()
  1352. \param file a pointer to the name of the file containing the CA
  1353. certificates to be loaded into the wolfSSL SSL context, with format
  1354. as specified by format.
  1355. \param format the encoding type of the certificates specified by file.
  1356. Possible values include SSL_FILETYPE_PEM and SSL_FILETYPE_ASN1.
  1357. _Example_
  1358. \code
  1359. int ret = 0;
  1360. WOLFSSL_CTX* ctx;
  1361. ...
  1362. ret = wolfSSL_CTX_der_load_verify_locations(ctx, “./ca-cert.der”,
  1363. SSL_FILETYPE_ASN1);
  1364. if (ret != SSL_SUCCESS) {
  1365. // error loading CA certs
  1366. }
  1367. ...
  1368. \endcode
  1369. \sa wolfSSL_CTX_load_verify_locations
  1370. \sa wolfSSL_CTX_load_verify_buffer
  1371. */
  1372. int wolfSSL_CTX_der_load_verify_locations(WOLFSSL_CTX* ctx,
  1373. const char* file, int format);
  1374. /*!
  1375. \ingroup Setup
  1376. \brief This function creates a new SSL context, taking a desired
  1377. SSL/TLS protocol method for input.
  1378. \return pointer If successful the call will return a pointer to the
  1379. newly-created WOLFSSL_CTX.
  1380. \return NULL upon failure.
  1381. \param method pointer to the desired WOLFSSL_METHOD to use for the SSL
  1382. context. This is created using one of the wolfSSLvXX_XXXX_method()
  1383. functions to specify SSL/TLS/DTLS protocol level.
  1384. _Example_
  1385. \code
  1386. WOLFSSL_CTX* ctx = 0;
  1387. WOLFSSL_METHOD* method = 0;
  1388. method = wolfSSLv3_client_method();
  1389. if (method == NULL) {
  1390. // unable to get method
  1391. }
  1392. ctx = wolfSSL_CTX_new(method);
  1393. if (ctx == NULL) {
  1394. // context creation failed
  1395. }
  1396. \endcode
  1397. \sa wolfSSL_new
  1398. */
  1399. WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*);
  1400. /*!
  1401. \ingroup Setup
  1402. \brief This function creates a new SSL session, taking an already
  1403. created SSL context as input.
  1404. \return * If successful the call will return a pointer to the
  1405. newly-created wolfSSL structure.
  1406. \return NULL Upon failure.
  1407. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1408. _Example_
  1409. \code
  1410. #include <wolfssl/ssl.h>
  1411. WOLFSSL* ssl = NULL;
  1412. WOLFSSL_CTX* ctx = 0;
  1413. ctx = wolfSSL_CTX_new(method);
  1414. if (ctx == NULL) {
  1415. // context creation failed
  1416. }
  1417. ssl = wolfSSL_new(ctx);
  1418. if (ssl == NULL) {
  1419. // SSL object creation failed
  1420. }
  1421. \endcode
  1422. \sa wolfSSL_CTX_new
  1423. */
  1424. WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
  1425. /*!
  1426. \ingroup Setup
  1427. \brief This function assigns a file descriptor (fd) as the
  1428. input/output facility for the SSL connection. Typically this will be
  1429. a socket file descriptor.
  1430. \return SSL_SUCCESS upon success.
  1431. \return Bad_FUNC_ARG upon failure.
  1432. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1433. \param fd file descriptor to use with SSL/TLS connection.
  1434. _Example_
  1435. \code
  1436. int sockfd;
  1437. WOLFSSL* ssl = 0;
  1438. ...
  1439. ret = wolfSSL_set_fd(ssl, sockfd);
  1440. if (ret != SSL_SUCCESS) {
  1441. // failed to set SSL file descriptor
  1442. }
  1443. \endcode
  1444. \sa wolfSSL_CTX_SetIOSend
  1445. \sa wolfSSL_CTX_SetIORecv
  1446. \sa wolfSSL_SetIOReadCtx
  1447. \sa wolfSSL_SetIOWriteCtx
  1448. */
  1449. int wolfSSL_set_fd(WOLFSSL* ssl, int fd);
  1450. /*!
  1451. \ingroup Setup
  1452. \brief This function assigns a file descriptor (fd) as the
  1453. input/output facility for the SSL connection. Typically this will be
  1454. a socket file descriptor. This is a DTLS specific API because it marks that
  1455. the socket is connected. recvfrom and sendto calls on this fd will have the
  1456. addr and addr_len parameters set to NULL.
  1457. \return SSL_SUCCESS upon success.
  1458. \return Bad_FUNC_ARG upon failure.
  1459. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1460. \param fd file descriptor to use with SSL/TLS connection.
  1461. _Example_
  1462. \code
  1463. int sockfd;
  1464. WOLFSSL* ssl = 0;
  1465. ...
  1466. if (connect(sockfd, peer_addr, peer_addr_len) != 0) {
  1467. // handle connect error
  1468. }
  1469. ...
  1470. ret = wolfSSL_set_dtls_fd_connected(ssl, sockfd);
  1471. if (ret != SSL_SUCCESS) {
  1472. // failed to set SSL file descriptor
  1473. }
  1474. \endcode
  1475. \sa wolfSSL_CTX_SetIOSend
  1476. \sa wolfSSL_CTX_SetIORecv
  1477. \sa wolfSSL_SetIOReadCtx
  1478. \sa wolfSSL_SetIOWriteCtx
  1479. \sa wolfDTLS_SetChGoodCb
  1480. */
  1481. int wolfSSL_set_dtls_fd_connected(WOLFSSL* ssl, int fd)
  1482. /*!
  1483. \ingroup Setup
  1484. \brief Allows setting a callback for a correctly processed and verified DTLS
  1485. client hello. When using a cookie exchange mechanism (either the
  1486. HelloVerifyRequest in DTLS 1.2 or the HelloRetryRequest with a cookie
  1487. extension in DTLS 1.3) this callback is called after the cookie
  1488. exchange has succeeded. This is useful to use one WOLFSSL object as
  1489. the listener for new connections and being able to isolate the
  1490. WOLFSSL object once the ClientHello is verified (either through a
  1491. cookie exchange or just checking if the ClientHello had the correct
  1492. format).
  1493. DTLS 1.2:
  1494. https://datatracker.ietf.org/doc/html/rfc6347#section-4.2.1
  1495. DTLS 1.3:
  1496. https://www.rfc-editor.org/rfc/rfc8446#section-4.2.2
  1497. \return SSL_SUCCESS upon success.
  1498. \return BAD_FUNC_ARG upon failure.
  1499. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1500. \param fd file descriptor to use with SSL/TLS connection.
  1501. _Example_
  1502. \code
  1503. // Called when we have verified a connection
  1504. static int chGoodCb(WOLFSSL* ssl, void* arg)
  1505. {
  1506. // setup peer and file descriptors
  1507. }
  1508. if (wolfDTLS_SetChGoodCb(ssl, chGoodCb, NULL) != WOLFSSL_SUCCESS) {
  1509. // error setting callback
  1510. }
  1511. \endcode
  1512. \sa wolfSSL_set_dtls_fd_connected
  1513. */
  1514. int wolfDTLS_SetChGoodCb(WOLFSSL* ssl, ClientHelloGoodCb cb, void* user_ctx);
  1515. /*!
  1516. \ingroup IO
  1517. \brief Get the name of cipher at priority level passed in.
  1518. \return string Success
  1519. \return 0 Priority is either out of bounds or not valid.
  1520. \param priority Integer representing the priority level of a cipher.
  1521. _Example_
  1522. \code
  1523. printf("The cipher at 1 is %s", wolfSSL_get_cipher_list(1));
  1524. \endcode
  1525. \sa wolfSSL_CIPHER_get_name
  1526. \sa wolfSSL_get_current_cipher
  1527. */
  1528. char* wolfSSL_get_cipher_list(int priority);
  1529. /*!
  1530. \ingroup IO
  1531. \brief This function gets the ciphers enabled in wolfSSL.
  1532. \return SSL_SUCCESS returned if the function executed without error.
  1533. \return BAD_FUNC_ARG returned if the buf parameter was NULL or if the
  1534. len argument was less than or equal to zero.
  1535. \return BUFFER_E returned if the buffer is not large enough and
  1536. will overflow.
  1537. \param buf a char pointer representing the buffer.
  1538. \param len the length of the buffer.
  1539. _Example_
  1540. \code
  1541. static void ShowCiphers(void){
  1542. char* ciphers;
  1543. int ret = wolfSSL_get_ciphers(ciphers, (int)sizeof(ciphers));
  1544. if(ret == SSL_SUCCES){
  1545. printf(“%s\n”, ciphers);
  1546. }
  1547. }
  1548. \endcode
  1549. \sa GetCipherNames
  1550. \sa wolfSSL_get_cipher_list
  1551. \sa ShowCiphers
  1552. */
  1553. int wolfSSL_get_ciphers(char* buf, int len);
  1554. /*!
  1555. \ingroup IO
  1556. \brief This function gets the cipher name in the format DHE-RSA by
  1557. passing through argument to wolfSSL_get_cipher_name_internal.
  1558. \return string This function returns the string representation of the
  1559. cipher suite that was matched.
  1560. \return NULL error or cipher not found.
  1561. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1562. _Example_
  1563. \code
  1564. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  1565. WOLFSSL* ssl = wolfSSL_new(ctx);
  1566. char* cipherS = wolfSSL_get_cipher_name(ssl);
  1567. if(cipher == NULL){
  1568. // There was not a cipher suite matched
  1569. } else {
  1570. // There was a cipher suite matched
  1571. printf(“%s\n”, cipherS);
  1572. }
  1573. \endcode
  1574. \sa wolfSSL_CIPHER_get_name
  1575. \sa wolfSSL_get_current_cipher
  1576. \sa wolfSSL_get_cipher_name_internal
  1577. */
  1578. const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);
  1579. /*!
  1580. \ingroup IO
  1581. \brief This function returns the file descriptor (fd) used as the
  1582. input/output facility for the SSL connection. Typically this
  1583. will be a socket file descriptor.
  1584. \return fd If successful the call will return the SSL session file
  1585. descriptor.
  1586. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1587. _Example_
  1588. \code
  1589. int sockfd;
  1590. WOLFSSL* ssl = 0;
  1591. ...
  1592. sockfd = wolfSSL_get_fd(ssl);
  1593. ...
  1594. \endcode
  1595. \sa wolfSSL_set_fd
  1596. */
  1597. int wolfSSL_get_fd(const WOLFSSL*);
  1598. /*!
  1599. \ingroup Setup
  1600. \brief This function informs the WOLFSSL object that the underlying
  1601. I/O is non-blocking. After an application creates a WOLFSSL object,
  1602. if it will be used with a non-blocking socket, call
  1603. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1604. that receiving EWOULDBLOCK means that the recvfrom call would
  1605. block rather than that it timed out.
  1606. \return none No return.
  1607. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1608. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  1609. Use 1 to specify non-blocking, otherwise 0.
  1610. _Example_
  1611. \code
  1612. WOLFSSL* ssl = 0;
  1613. ...
  1614. wolfSSL_set_using_nonblock(ssl, 1);
  1615. \endcode
  1616. \sa wolfSSL_get_using_nonblock
  1617. \sa wolfSSL_dtls_got_timeout
  1618. \sa wolfSSL_dtls_get_current_timeout
  1619. */
  1620. void wolfSSL_set_using_nonblock(WOLFSSL* ssl, int nonblock);
  1621. /*!
  1622. \ingroup IO
  1623. \brief This function allows the application to determine if wolfSSL is
  1624. using non-blocking I/O. If wolfSSL is using non-blocking I/O, this
  1625. function will return 1, otherwise 0. After an application creates a
  1626. WOLFSSL object, if it will be used with a non-blocking socket, call
  1627. wolfSSL_set_using_nonblock() on it. This lets the WOLFSSL object know
  1628. that receiving EWOULDBLOCK means that the recvfrom call would block
  1629. rather than that it timed out.
  1630. \return 0 underlying I/O is blocking.
  1631. \return 1 underlying I/O is non-blocking.
  1632. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1633. _Example_
  1634. \code
  1635. int ret = 0;
  1636. WOLFSSL* ssl = 0;
  1637. ...
  1638. ret = wolfSSL_get_using_nonblock(ssl);
  1639. if (ret == 1) {
  1640. // underlying I/O is non-blocking
  1641. }
  1642. ...
  1643. \endcode
  1644. \sa wolfSSL_set_session
  1645. */
  1646. int wolfSSL_get_using_nonblock(WOLFSSL*);
  1647. /*!
  1648. \ingroup IO
  1649. \brief This function writes sz bytes from the buffer, data, to the SSL
  1650. connection, ssl. If necessary, wolfSSL_write() will negotiate an SSL/TLS
  1651. session if the handshake has not already been performed yet by
  1652. wolfSSL_connect() or wolfSSL_accept(). wolfSSL_write() works with both
  1653. blocking and non-blocking I/O. When the underlying I/O is non-blocking,
  1654. wolfSSL_write() will return when the underlying I/O could not satisfy the
  1655. needs of wolfSSL_write() to continue. In this case, a call to
  1656. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1657. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call to
  1658. wolfSSL_write() when the underlying I/O is ready. If the underlying I/O
  1659. is blocking, wolfSSL_write() will only return once the buffer data of
  1660. size sz has been completely written or an error occurred.
  1661. \return >0 the number of bytes written upon success.
  1662. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1663. the specific error code.
  1664. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1665. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1666. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1667. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  1668. error code.
  1669. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1670. \param data data buffer which will be sent to peer.
  1671. \param sz size, in bytes, of data to send to the peer (data).
  1672. _Example_
  1673. \code
  1674. WOLFSSL* ssl = 0;
  1675. char msg[64] = “hello wolfssl!”;
  1676. int msgSz = (int)strlen(msg);
  1677. int flags;
  1678. int ret;
  1679. ...
  1680. ret = wolfSSL_write(ssl, msg, msgSz);
  1681. if (ret <= 0) {
  1682. // wolfSSL_write() failed, call wolfSSL_get_error()
  1683. }
  1684. \endcode
  1685. \sa wolfSSL_send
  1686. \sa wolfSSL_read
  1687. \sa wolfSSL_recv
  1688. */
  1689. int wolfSSL_write(WOLFSSL* ssl, const void* data, int sz);
  1690. /*!
  1691. \ingroup IO
  1692. \brief This function reads sz bytes from the SSL session (ssl)
  1693. internal read buffer into the buffer data. The bytes read are removed
  1694. from the internal receive buffer. If necessary wolfSSL_read() will
  1695. negotiate an SSL/TLS session if the handshake has not already been
  1696. performed yet by wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS
  1697. protocol uses SSL records which have a maximum size of 16kB (the max
  1698. record size can be controlled by the MAX_RECORD_SIZE define in
  1699. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1700. entire SSL record internally before it is able to process and decrypt the
  1701. record. Because of this, a call to wolfSSL_read() will only be able to
  1702. return the maximum buffer size which has been decrypted at the time of
  1703. calling. There may be additional not-yet-decrypted data waiting in the
  1704. internal wolfSSL receive buffer which will be retrieved and decrypted with
  1705. the next call to wolfSSL_read(). If sz is larger than the number of bytes
  1706. in the internal read buffer, SSL_read() will return the bytes available in
  1707. the internal read buffer. If no bytes are buffered in the internal read
  1708. buffer yet, a call to wolfSSL_read() will trigger processing of the next
  1709. record.
  1710. \return >0 the number of bytes read upon success.
  1711. \return 0 will be returned upon failure. This may be caused by a either a
  1712. clean (close notify alert) shutdown or just that the peer closed the
  1713. connection. Call wolfSSL_get_error() for the specific error code.
  1714. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1715. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1716. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1717. call wolfSSL_read() again. Use wolfSSL_get_error() to get a specific
  1718. error code.
  1719. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1720. \param data buffer where wolfSSL_read() will place data read.
  1721. \param sz number of bytes to read into data.
  1722. _Example_
  1723. \code
  1724. WOLFSSL* ssl = 0;
  1725. char reply[1024];
  1726. ...
  1727. input = wolfSSL_read(ssl, reply, sizeof(reply));
  1728. if (input > 0) {
  1729. // “input” number of bytes returned into buffer “reply”
  1730. }
  1731. See wolfSSL examples (client, server, echoclient, echoserver) for more
  1732. complete examples of wolfSSL_read().
  1733. \endcode
  1734. \sa wolfSSL_recv
  1735. \sa wolfSSL_write
  1736. \sa wolfSSL_peek
  1737. \sa wolfSSL_pending
  1738. */
  1739. int wolfSSL_read(WOLFSSL* ssl, void* data, int sz);
  1740. /*!
  1741. \ingroup IO
  1742. \brief This function copies sz bytes from the SSL session (ssl) internal
  1743. read buffer into the buffer data. This function is identical to
  1744. wolfSSL_read() except that the data in the internal SSL session
  1745. receive buffer is not removed or modified. If necessary, like
  1746. wolfSSL_read(), wolfSSL_peek() will negotiate an SSL/TLS session if
  1747. the handshake has not already been performed yet by wolfSSL_connect()
  1748. or wolfSSL_accept(). The SSL/TLS protocol uses SSL records which have a
  1749. maximum size of 16kB (the max record size can be controlled by the
  1750. MAX_RECORD_SIZE define in <wolfssl_root>/wolfssl/internal.h). As such,
  1751. wolfSSL needs to read an entire SSL record internally before it is able
  1752. to process and decrypt the record. Because of this, a call to
  1753. wolfSSL_peek() will only be able to return the maximum buffer size which
  1754. has been decrypted at the time of calling. There may be additional
  1755. not-yet-decrypted data waiting in the internal wolfSSL receive buffer
  1756. which will be retrieved and decrypted with the next call to
  1757. wolfSSL_peek() / wolfSSL_read(). If sz is larger than the number of bytes
  1758. in the internal read buffer, SSL_peek() will return the bytes available
  1759. in the internal read buffer. If no bytes are buffered in the internal
  1760. read buffer yet, a call to wolfSSL_peek() will trigger processing of the
  1761. next record.
  1762. \return >0 the number of bytes read upon success.
  1763. \return 0 will be returned upon failure. This may be caused by a either
  1764. a clean (close notify alert) shutdown or just that the peer closed the
  1765. connection. Call wolfSSL_get_error() for the specific error code.
  1766. \return SSL_FATAL_ERROR will be returned upon failure when either an
  1767. error occurred or, when using non-blocking sockets, the
  1768. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE error was received and and
  1769. the application needs to call wolfSSL_peek() again. Use
  1770. wolfSSL_get_error() to get a specific error code.
  1771. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1772. \param data buffer where wolfSSL_peek() will place data read.
  1773. \param sz number of bytes to read into data.
  1774. _Example_
  1775. \code
  1776. WOLFSSL* ssl = 0;
  1777. char reply[1024];
  1778. ...
  1779. input = wolfSSL_peek(ssl, reply, sizeof(reply));
  1780. if (input > 0) {
  1781. // “input” number of bytes returned into buffer “reply”
  1782. }
  1783. \endcode
  1784. \sa wolfSSL_read
  1785. */
  1786. int wolfSSL_peek(WOLFSSL* ssl, void* data, int sz);
  1787. /*!
  1788. \ingroup IO
  1789. \brief This function is called on the server side and waits for an SSL
  1790. client to initiate the SSL/TLS handshake. When this function is called,
  1791. the underlying communication channel has already been set up.
  1792. wolfSSL_accept() works with both blocking and non-blocking I/O.
  1793. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  1794. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  1795. to continue the handshake. In this case, a call to wolfSSL_get_error()
  1796. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1797. The calling process must then repeat the call to wolfSSL_accept when
  1798. data is available to read and wolfSSL will pick up where it left off.
  1799. When using a non-blocking socket, nothing needs to be done, but select()
  1800. can be used to check for the required condition. If the underlying I/O
  1801. is blocking, wolfSSL_accept() will only return once the handshake has
  1802. been finished or an error occurred.
  1803. \return SSL_SUCCESS upon success.
  1804. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  1805. more detailed error code, call wolfSSL_get_error().
  1806. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  1807. _Example_
  1808. \code
  1809. int ret = 0;
  1810. int err = 0;
  1811. WOLFSSL* ssl;
  1812. char buffer[80];
  1813. ...
  1814. ret = wolfSSL_accept(ssl);
  1815. if (ret != SSL_SUCCESS) {
  1816. err = wolfSSL_get_error(ssl, ret);
  1817. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  1818. }
  1819. \endcode
  1820. \sa wolfSSL_get_error
  1821. \sa wolfSSL_connect
  1822. */
  1823. int wolfSSL_accept(WOLFSSL*);
  1824. /*!
  1825. \ingroup Setup
  1826. \brief This function frees an allocated WOLFSSL_CTX object. This
  1827. function decrements the CTX reference count and only frees the context
  1828. when the reference count has reached 0.
  1829. \return none No return.
  1830. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  1831. _Example_
  1832. \code
  1833. WOLFSSL_CTX* ctx = 0;
  1834. ...
  1835. wolfSSL_CTX_free(ctx);
  1836. \endcode
  1837. \sa wolfSSL_CTX_new
  1838. \sa wolfSSL_new
  1839. \sa wolfSSL_free
  1840. */
  1841. void wolfSSL_CTX_free(WOLFSSL_CTX*);
  1842. /*!
  1843. \ingroup Setup
  1844. \brief This function frees an allocated wolfSSL object.
  1845. \return none No return.
  1846. \param ssl pointer to the SSL object, created with wolfSSL_new().
  1847. _Example_
  1848. \code
  1849. #include <wolfssl/ssl.h>
  1850. WOLFSSL* ssl = 0;
  1851. ...
  1852. wolfSSL_free(ssl);
  1853. \endcode
  1854. \sa wolfSSL_CTX_new
  1855. \sa wolfSSL_new
  1856. \sa wolfSSL_CTX_free
  1857. */
  1858. void wolfSSL_free(WOLFSSL*);
  1859. /*!
  1860. \ingroup TLS
  1861. \brief This function shuts down an active SSL/TLS connection using
  1862. the SSL session, ssl. This function will try to send a “close notify”
  1863. alert to the peer. The calling application can choose to wait for the
  1864. peer to send its “close notify” alert in response or just go ahead
  1865. and shut down the underlying connection after directly calling
  1866. wolfSSL_shutdown (to save resources). Either option is allowed by
  1867. the TLS specification. If the underlying connection will be used
  1868. again in the future, the complete two-directional shutdown procedure
  1869. must be performed to keep synchronization intact between the peers.
  1870. wolfSSL_shutdown() works with both blocking and non-blocking I/O.
  1871. When the underlying I/O is non-blocking, wolfSSL_shutdown() will
  1872. return an error if the underlying I/O could not satisfy the needs of
  1873. wolfSSL_shutdown() to continue. In this case, a call to
  1874. wolfSSL_get_error() will yield either SSL_ERROR_WANT_READ or
  1875. SSL_ERROR_WANT_WRITE. The calling process must then repeat the call
  1876. to wolfSSL_shutdown() when the underlying I/O is ready.
  1877. \return SSL_SUCCESS will be returned upon success.
  1878. \return SSL_SHUTDOWN_NOT_DONE will be returned when shutdown has not
  1879. finished, and the function should be called again.
  1880. \return SSL_FATAL_ERROR will be returned upon failure. Call
  1881. wolfSSL_get_error() for a more specific error code.
  1882. \param ssl pointer to the SSL session created with wolfSSL_new().
  1883. _Example_
  1884. \code
  1885. #include <wolfssl/ssl.h>
  1886. int ret = 0;
  1887. WOLFSSL* ssl = 0;
  1888. ...
  1889. ret = wolfSSL_shutdown(ssl);
  1890. if (ret != 0) {
  1891. // failed to shut down SSL connection
  1892. }
  1893. \endcode
  1894. \sa wolfSSL_free
  1895. \sa wolfSSL_CTX_free
  1896. */
  1897. int wolfSSL_shutdown(WOLFSSL*);
  1898. /*!
  1899. \ingroup IO
  1900. \brief This function writes sz bytes from the buffer, data, to the SSL
  1901. connection, ssl, using the specified flags for the underlying write
  1902. operation. If necessary wolfSSL_send() will negotiate an SSL/TLS session
  1903. if the handshake has not already been performed yet by wolfSSL_connect()
  1904. or wolfSSL_accept(). wolfSSL_send() works with both blocking and
  1905. non-blocking I/O. When the underlying I/O is non-blocking, wolfSSL_send()
  1906. will return when the underlying I/O could not satisfy the needs of
  1907. wolfSSL_send to continue. In this case, a call to wolfSSL_get_error()
  1908. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  1909. The calling process must then repeat the call to wolfSSL_send() when
  1910. the underlying I/O is ready. If the underlying I/O is blocking,
  1911. wolfSSL_send() will only return once the buffer data of size sz has
  1912. been completely written or an error occurred.
  1913. \return >0 the number of bytes written upon success.
  1914. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  1915. the specific error code.
  1916. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1917. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1918. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1919. call wolfSSL_send() again. Use wolfSSL_get_error() to get a specific
  1920. error code.
  1921. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1922. \param data data buffer to send to peer.
  1923. \param sz size, in bytes, of data to be sent to peer.
  1924. \param flags the send flags to use for the underlying send operation.
  1925. _Example_
  1926. \code
  1927. WOLFSSL* ssl = 0;
  1928. char msg[64] = “hello wolfssl!”;
  1929. int msgSz = (int)strlen(msg);
  1930. int flags = ... ;
  1931. ...
  1932. input = wolfSSL_send(ssl, msg, msgSz, flags);
  1933. if (input != msgSz) {
  1934. // wolfSSL_send() failed
  1935. }
  1936. \endcode
  1937. \sa wolfSSL_write
  1938. \sa wolfSSL_read
  1939. \sa wolfSSL_recv
  1940. */
  1941. int wolfSSL_send(WOLFSSL* ssl, const void* data, int sz, int flags);
  1942. /*!
  1943. \ingroup IO
  1944. \brief This function reads sz bytes from the SSL session (ssl) internal
  1945. read buffer into the buffer data using the specified flags for the
  1946. underlying recv operation. The bytes read are removed from the internal
  1947. receive buffer. This function is identical to wolfSSL_read() except
  1948. that it allows the application to set the recv flags for the underlying
  1949. read operation. If necessary wolfSSL_recv() will negotiate an SSL/TLS
  1950. session if the handshake has not already been performed yet by
  1951. wolfSSL_connect() or wolfSSL_accept(). The SSL/TLS protocol uses
  1952. SSL records which have a maximum size of 16kB (the max record size
  1953. can be controlled by the MAX_RECORD_SIZE define in
  1954. <wolfssl_root>/wolfssl/internal.h). As such, wolfSSL needs to read an
  1955. entire SSL record internally before it is able to process and decrypt
  1956. the record. Because of this, a call to wolfSSL_recv() will only be
  1957. able to return the maximum buffer size which has been decrypted at
  1958. the time of calling. There may be additional not-yet-decrypted data
  1959. waiting in the internal wolfSSL receive buffer which will be
  1960. retrieved and decrypted with the next call to wolfSSL_recv(). If sz
  1961. is larger than the number of bytes in the internal read buffer,
  1962. SSL_recv() will return the bytes available in the internal read buffer.
  1963. If no bytes are buffered in the internal read buffer yet, a call to
  1964. wolfSSL_recv() will trigger processing of the next record.
  1965. \return >0 the number of bytes read upon success.
  1966. \return 0 will be returned upon failure. This may be caused by a either
  1967. a clean (close notify alert) shutdown or just that the peer closed the
  1968. connection. Call wolfSSL_get_error() for the specific error code.
  1969. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  1970. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  1971. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  1972. call wolfSSL_recv() again. Use wolfSSL_get_error() to get a specific
  1973. error code.
  1974. \param ssl pointer to the SSL session, created with wolfSSL_new().
  1975. \param data buffer where wolfSSL_recv() will place data read.
  1976. \param sz number of bytes to read into data.
  1977. \param flags the recv flags to use for the underlying recv operation.
  1978. _Example_
  1979. \code
  1980. WOLFSSL* ssl = 0;
  1981. char reply[1024];
  1982. int flags = ... ;
  1983. ...
  1984. input = wolfSSL_recv(ssl, reply, sizeof(reply), flags);
  1985. if (input > 0) {
  1986. // “input” number of bytes returned into buffer “reply”
  1987. }
  1988. \endcode
  1989. \sa wolfSSL_read
  1990. \sa wolfSSL_write
  1991. \sa wolfSSL_peek
  1992. \sa wolfSSL_pending
  1993. */
  1994. int wolfSSL_recv(WOLFSSL* ssl, void* data, int sz, int flags);
  1995. /*!
  1996. \ingroup Debug
  1997. \brief This function returns a unique error code describing why the
  1998. previous API function call (wolfSSL_connect, wolfSSL_accept, wolfSSL_read,
  1999. wolfSSL_write, etc.) resulted in an error return code (SSL_FAILURE).
  2000. The return value of the previous function is passed to wolfSSL_get_error
  2001. through ret. After wolfSSL_get_error is called and returns the unique
  2002. error code, wolfSSL_ERR_error_string() may be called to get a
  2003. human-readable error string. See wolfSSL_ERR_error_string() for more
  2004. information.
  2005. \return On successful completion, this function will return the
  2006. unique error code describing why the previous API function failed.
  2007. \return SSL_ERROR_NONE will be returned if ret > 0. For ret <= 0, there are
  2008. some cases when this value can also be returned when a previous API appeared
  2009. to return an error code but no error actually occurred. An example is
  2010. calling wolfSSL_read() with a zero sz parameter. A 0 return from
  2011. wolfSSL_read() usually indicates an error but in this case no error
  2012. occurred. If wolfSSL_get_error() is called afterwards, SSL_ERROR_NONE will
  2013. be returned.
  2014. \param ssl pointer to the SSL object, created with wolfSSL_new().
  2015. \param ret return value of the previous function that resulted in an error
  2016. return code.
  2017. _Example_
  2018. \code
  2019. int err = 0;
  2020. WOLFSSL* ssl;
  2021. char buffer[80];
  2022. ...
  2023. err = wolfSSL_get_error(ssl, 0);
  2024. wolfSSL_ERR_error_string(err, buffer);
  2025. printf(“err = %d, %s\n”, err, buffer);
  2026. \endcode
  2027. \sa wolfSSL_ERR_error_string
  2028. \sa wolfSSL_ERR_error_string_n
  2029. \sa wolfSSL_ERR_print_errors_fp
  2030. \sa wolfSSL_load_error_strings
  2031. */
  2032. int wolfSSL_get_error(WOLFSSL* ssl, int ret);
  2033. /*!
  2034. \ingroup IO
  2035. \brief This function gets the alert history.
  2036. \return SSL_SUCCESS returned when the function completed successfully.
  2037. Either there was alert history or there wasn’t, either way, the
  2038. return value is SSL_SUCCESS.
  2039. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2040. \param h a pointer to a WOLFSSL_ALERT_HISTORY structure that will hold the
  2041. WOLFSSL struct’s alert_history member’s value.
  2042. _Example_
  2043. \code
  2044. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  2045. WOLFSSL* ssl = wolfSSL_new(ctx);
  2046. WOLFSSL_ALERT_HISTORY* h;
  2047. ...
  2048. wolfSSL_get_alert_history(ssl, h);
  2049. // h now has a copy of the ssl->alert_history contents
  2050. \endcode
  2051. \sa wolfSSL_get_error
  2052. */
  2053. int wolfSSL_get_alert_history(WOLFSSL* ssl, WOLFSSL_ALERT_HISTORY *h);
  2054. /*!
  2055. \ingroup Setup
  2056. \brief This function sets the session to be used when the SSL object,
  2057. ssl, is used to establish a SSL/TLS connection. For session resumption,
  2058. before calling wolfSSL_shutdown() with your session object, an application
  2059. should save the session ID from the object with a call to
  2060. wolfSSL_get1_session(), which returns a pointer to the session.
  2061. Later, the application should create a new WOLFSSL object and assign
  2062. the saved session with wolfSSL_set_session(). At this point, the
  2063. application may call wolfSSL_connect() and wolfSSL will try to resume
  2064. the session. The wolfSSL server code allows session resumption by default.
  2065. The object returned by wolfSSL_get1_session() needs to be freed after the
  2066. application is done with it by calling wolfSSL_SESSION_free() on it.
  2067. \return SSL_SUCCESS will be returned upon successfully setting the session.
  2068. \return SSL_FAILURE will be returned on failure. This could be caused
  2069. by the session cache being disabled, or if the session has timed out.
  2070. \return When OPENSSL_EXTRA and WOLFSSL_ERROR_CODE_OPENSSL are defined,
  2071. SSL_SUCCESS will be returned even if the session has timed out.
  2072. \param ssl pointer to the SSL object, created with wolfSSL_new().
  2073. \param session pointer to the WOLFSSL_SESSION used to set the session
  2074. for ssl.
  2075. _Example_
  2076. \code
  2077. int ret;
  2078. WOLFSSL* ssl;
  2079. WOLFSSL_SESSION* session;
  2080. ...
  2081. session = wolfSSL_get1_session(ssl);
  2082. if (session == NULL) {
  2083. // failed to get session object from ssl object
  2084. }
  2085. ...
  2086. ret = wolfSSL_set_session(ssl, session);
  2087. if (ret != SSL_SUCCESS) {
  2088. // failed to set the SSL session
  2089. }
  2090. wolfSSL_SESSION_free(session);
  2091. ...
  2092. \endcode
  2093. \sa wolfSSL_get1_session
  2094. */
  2095. int wolfSSL_set_session(WOLFSSL* ssl, WOLFSSL_SESSION* session);
  2096. /*!
  2097. \ingroup IO
  2098. \brief When NO_SESSION_CACHE_REF is defined this function returns a pointer
  2099. to the current session (WOLFSSL_SESSION) used in ssl. This function returns
  2100. a non-persistent pointer to the WOLFSSL_SESSION object. The pointer returned
  2101. will be freed when wolfSSL_free is called. This call should only be used to
  2102. inspect or modify the current session. For session resumption it is
  2103. recommended to use wolfSSL_get1_session(). For backwards compatibility when
  2104. NO_SESSION_CACHE_REF is not defined this function returns a persistent
  2105. session object pointer that is stored in the local cache. The cache size is
  2106. finite and there is a risk that the session object will be overwritten by
  2107. another ssl connection by the time the application calls
  2108. wolfSSL_set_session() on it. It is recommended to define
  2109. NO_SESSION_CACHE_REF in your application and to use wolfSSL_get1_session()
  2110. for session resumption.
  2111. \return pointer If successful the call will return a pointer to the the
  2112. current SSL session object.
  2113. \return NULL will be returned if ssl is NULL, the SSL session cache is
  2114. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  2115. functions fail.
  2116. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2117. _Example_
  2118. \code
  2119. WOLFSSL* ssl;
  2120. WOLFSSL_SESSION* session;
  2121. ...
  2122. session = wolfSSL_get_session(ssl);
  2123. if (session == NULL) {
  2124. // failed to get session pointer
  2125. }
  2126. ...
  2127. \endcode
  2128. \sa wolfSSL_get1_session
  2129. \sa wolfSSL_set_session
  2130. */
  2131. WOLFSSL_SESSION* wolfSSL_get_session(WOLFSSL* ssl);
  2132. /*!
  2133. \ingroup IO
  2134. \brief This function flushes session from the session cache which
  2135. have expired. The time, tm, is used for the time comparison. Note
  2136. that wolfSSL currently uses a static table for sessions, so no flushing
  2137. is needed. As such, this function is currently just a stub. This
  2138. function provides OpenSSL compatibility (SSL_flush_sessions) when
  2139. wolfSSL is compiled with the OpenSSL compatibility layer.
  2140. \return none No returns.
  2141. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  2142. wolfSSL_CTX_new().
  2143. \param tm time used in session expiration comparison.
  2144. _Example_
  2145. \code
  2146. WOLFSSL_CTX* ssl;
  2147. ...
  2148. wolfSSL_flush_sessions(ctx, time(0));
  2149. \endcode
  2150. \sa wolfSSL_get1_session
  2151. \sa wolfSSL_set_session
  2152. */
  2153. void wolfSSL_flush_sessions(WOLFSSL_CTX* ctx, long tm);
  2154. /*!
  2155. \ingroup TLS
  2156. \brief This function associates the client session with the server id.
  2157. If the newSession flag is on, an existing session won’t be reused.
  2158. \return SSL_SUCCESS returned if the function executed without error.
  2159. \return BAD_FUNC_ARG returned if the WOLFSSL struct or id parameter
  2160. is NULL or if len is not greater than zero.
  2161. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2162. \param id a constant byte pointer that will be copied to the
  2163. serverID member of the WOLFSSL_SESSION structure.
  2164. \param len an int type representing the length of the session id parameter.
  2165. \param newSession an int type representing the flag to denote whether
  2166. to reuse a session or not.
  2167. _Example_
  2168. \code
  2169. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol );
  2170. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2171. const byte id[MAX_SIZE]; // or dynamically create space
  2172. int len = 0; // initialize length
  2173. int newSession = 0; // flag to allow
  2174. int ret = wolfSSL_SetServerID(ssl, id, len, newSession);
  2175. if (ret == WOLFSSL_SUCCESS) {
  2176. // The Id was successfully set
  2177. }
  2178. \endcode
  2179. \sa wolfSSL_set_session
  2180. */
  2181. int wolfSSL_SetServerID(WOLFSSL* ssl, const unsigned char* id,
  2182. int len, int newSession);
  2183. /*!
  2184. \ingroup IO
  2185. \brief This function gets the session index of the WOLFSSL structure.
  2186. \return int The function returns an int type representing the
  2187. sessionIndex within the WOLFSSL struct.
  2188. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2189. _Example_
  2190. \code
  2191. WOLFSSL_CTX_new( protocol method );
  2192. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2193. ...
  2194. int sesIdx = wolfSSL_GetSessionIndex(ssl);
  2195. if(sesIdx < 0 || sesIdx > sizeof(ssl->sessionIndex)/sizeof(int)){
  2196. // You have an out of bounds index number and something is not right.
  2197. }
  2198. \endcode
  2199. \sa wolfSSL_GetSessionAtIndex
  2200. */
  2201. int wolfSSL_GetSessionIndex(WOLFSSL* ssl);
  2202. /*!
  2203. \ingroup IO
  2204. \brief This function gets the session at specified index of the session
  2205. cache and copies it into memory. The WOLFSSL_SESSION structure holds
  2206. the session information.
  2207. \return SSL_SUCCESS returned if the function executed successfully and
  2208. no errors were thrown.
  2209. \return BAD_MUTEX_E returned if there was an unlock or lock mutex error.
  2210. \return SSL_FAILURE returned if the function did not execute successfully.
  2211. \param idx an int type representing the session index.
  2212. \param session a pointer to the WOLFSSL_SESSION structure.
  2213. _Example_
  2214. \code
  2215. int idx; // The index to locate the session.
  2216. WOLFSSL_SESSION* session; // Buffer to copy to.
  2217. ...
  2218. if(wolfSSL_GetSessionAtIndex(idx, session) != SSL_SUCCESS){
  2219. // Failure case.
  2220. }
  2221. \endcode
  2222. \sa UnLockMutex
  2223. \sa LockMutex
  2224. \sa wolfSSL_GetSessionIndex
  2225. */
  2226. int wolfSSL_GetSessionAtIndex(int index, WOLFSSL_SESSION* session);
  2227. /*!
  2228. \ingroup IO
  2229. \brief Returns the peer certificate chain from the WOLFSSL_SESSION struct.
  2230. \return pointer A pointer to a WOLFSSL_X509_CHAIN structure that
  2231. contains the peer certification chain.
  2232. \param session a pointer to a WOLFSSL_SESSION structure.
  2233. _Example_
  2234. \code
  2235. WOLFSSL_SESSION* session;
  2236. WOLFSSL_X509_CHAIN* chain;
  2237. ...
  2238. chain = wolfSSL_SESSION_get_peer_chain(session);
  2239. if(!chain){
  2240. // There was no chain. Failure case.
  2241. }
  2242. \endcode
  2243. \sa wolfSSL_GetSessionAtIndex
  2244. \sa wolfSSL_GetSessionIndex
  2245. \sa AddSession
  2246. */
  2247. WOLFSSL_X509_CHAIN* wolfSSL_SESSION_get_peer_chain(WOLFSSL_SESSION* session);
  2248. /*!
  2249. \ingroup Setup
  2250. \brief This function sets the verification method for remote peers and
  2251. also allows a verify callback to be registered with the SSL context.
  2252. The verify callback will be called only when a verification failure has
  2253. occurred. If no verify callback is desired, the NULL pointer can be used
  2254. for verify_callback. The verification mode of peer certificates is a
  2255. logically OR’d list of flags. The possible flag values include:
  2256. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2257. received from the server and the handshake will continue as normal.
  2258. Server mode: the server will not send a certificate request to the client.
  2259. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2260. mode: the client will verify the certificate received from the server
  2261. during the handshake. This is turned on by default in wolfSSL, therefore,
  2262. using this option has no effect. Server mode: the server will send a
  2263. certificate request to the client and verify the client certificate
  2264. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2265. used on the client side. Server mode: the verification will fail on the
  2266. server side if the client fails to send a certificate when requested to
  2267. do so (when using SSL_VERIFY_PEER on the SSL server).
  2268. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2269. side. Server mode: the verification is the same as
  2270. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2271. If a PSK connection is being made then the connection will go through
  2272. without a peer cert.
  2273. \return none No return.
  2274. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2275. \param mode session timeout value in seconds
  2276. \param verify_callback callback to be called when verification fails.
  2277. If no callback is desired, the NULL pointer can be used for
  2278. verify_callback.
  2279. _Example_
  2280. \code
  2281. WOLFSSL_CTX* ctx = 0;
  2282. ...
  2283. wolfSSL_CTX_set_verify(ctx, (WOLFSSL_VERIFY_PEER |
  2284. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT), NULL);
  2285. \endcode
  2286. \sa wolfSSL_set_verify
  2287. */
  2288. void wolfSSL_CTX_set_verify(WOLFSSL_CTX* ctx, int mode,
  2289. VerifyCallback verify_callback);
  2290. /*!
  2291. \ingroup Setup
  2292. \brief This function sets the verification method for remote peers and
  2293. also allows a verify callback to be registered with the SSL session.
  2294. The verify callback will be called only when a verification failure has
  2295. occurred. If no verify callback is desired, the NULL pointer can be used
  2296. for verify_callback. The verification mode of peer certificates is a
  2297. logically OR’d list of flags. The possible flag values include:
  2298. SSL_VERIFY_NONE Client mode: the client will not verify the certificate
  2299. received from the server and the handshake will continue as normal. Server
  2300. mode: the server will not send a certificate request to the client.
  2301. As such, client verification will not be enabled. SSL_VERIFY_PEER Client
  2302. mode: the client will verify the certificate received from the server
  2303. during the handshake. This is turned on by default in wolfSSL, therefore,
  2304. using this option has no effect. Server mode: the server will send a
  2305. certificate request to the client and verify the client certificate
  2306. received. SSL_VERIFY_FAIL_IF_NO_PEER_CERT Client mode: no effect when
  2307. used on the client side. Server mode: the verification will fail on the
  2308. server side if the client fails to send a certificate when requested to do
  2309. so (when using SSL_VERIFY_PEER on the SSL server).
  2310. SSL_VERIFY_FAIL_EXCEPT_PSK Client mode: no effect when used on the client
  2311. side. Server mode: the verification is the same as
  2312. SSL_VERIFY_FAIL_IF_NO_PEER_CERT except in the case of a PSK connection.
  2313. If a PSK connection is being made then the connection will go through
  2314. without a peer cert.
  2315. \return none No return.
  2316. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2317. \param mode session timeout value in seconds.
  2318. \param verify_callback callback to be called when verification fails.
  2319. If no callback is desired, the NULL pointer can
  2320. be used for verify_callback.
  2321. _Example_
  2322. \code
  2323. WOLFSSL* ssl = 0;
  2324. ...
  2325. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  2326. \endcode
  2327. \sa wolfSSL_CTX_set_verify
  2328. */
  2329. void wolfSSL_set_verify(WOLFSSL* ssl, int mode, VerifyCallback verify_callback);
  2330. /*!
  2331. \ingroup CertsKeys
  2332. \brief This function stores user CTX object information for verify callback.
  2333. \return none No return.
  2334. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2335. \param ctx a void pointer that is set to WOLFSSL structure’s verifyCbCtx
  2336. member’s value.
  2337. _Example_
  2338. \code
  2339. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2340. WOLFSSL* ssl = wolfSSL_new(ctx);
  2341. (void*)ctx;
  2342. ...
  2343. if(ssl != NULL){
  2344. wolfSSL_SetCertCbCtx(ssl, ctx);
  2345. } else {
  2346. // Error case, the SSL is not initialized properly.
  2347. }
  2348. \endcode
  2349. \sa wolfSSL_CTX_save_cert_cache
  2350. \sa wolfSSL_CTX_restore_cert_cache
  2351. \sa wolfSSL_CTX_set_verify
  2352. */
  2353. void wolfSSL_SetCertCbCtx(WOLFSSL* ssl, void* ctx);
  2354. /*!
  2355. \ingroup CertsKeys
  2356. \brief This function stores user CTX object information for verify callback.
  2357. \return none No return.
  2358. \param ctx a pointer to a WOLFSSL_CTX structure.
  2359. \param userCtx a void pointer that is used to set WOLFSSL_CTX structure’s
  2360. verifyCbCtx member’s value.
  2361. _Example_
  2362. \code
  2363. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2364. void* userCtx = NULL; // Assign some user defined context
  2365. ...
  2366. if(ctx != NULL){
  2367. wolfSSL_SetCertCbCtx(ctx, userCtx);
  2368. } else {
  2369. // Error case, the SSL is not initialized properly.
  2370. }
  2371. \endcode
  2372. \sa wolfSSL_CTX_save_cert_cache
  2373. \sa wolfSSL_CTX_restore_cert_cache
  2374. \sa wolfSSL_CTX_set_verify
  2375. */
  2376. void wolfSSL_CTX_SetCertCbCtx(WOLFSSL_CTX* ctx, void* userCtx);
  2377. /*!
  2378. \ingroup IO
  2379. \brief This function returns the number of bytes which are buffered and
  2380. available in the SSL object to be read by wolfSSL_read().
  2381. \return int This function returns the number of bytes pending.
  2382. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2383. _Example_
  2384. \code
  2385. int pending = 0;
  2386. WOLFSSL* ssl = 0;
  2387. ...
  2388. pending = wolfSSL_pending(ssl);
  2389. printf(“There are %d bytes buffered and available for reading”, pending);
  2390. \endcode
  2391. \sa wolfSSL_recv
  2392. \sa wolfSSL_read
  2393. \sa wolfSSL_peek
  2394. */
  2395. int wolfSSL_pending(WOLFSSL*);
  2396. /*!
  2397. \ingroup Debug
  2398. \brief This function is for OpenSSL compatibility (SSL_load_error_string)
  2399. only and takes no action.
  2400. \return none No returns.
  2401. \param none No parameters.
  2402. _Example_
  2403. \code
  2404. wolfSSL_load_error_strings();
  2405. \endcode
  2406. \sa wolfSSL_get_error
  2407. \sa wolfSSL_ERR_error_string
  2408. \sa wolfSSL_ERR_error_string_n
  2409. \sa wolfSSL_ERR_print_errors_fp
  2410. \sa wolfSSL_load_error_strings
  2411. */
  2412. void wolfSSL_load_error_strings(void);
  2413. /*!
  2414. \ingroup TLS
  2415. \brief This function is called internally in wolfSSL_CTX_new(). This
  2416. function is a wrapper around wolfSSL_Init() and exists for OpenSSL
  2417. compatibility (SSL_library_init) when wolfSSL has been compiled with
  2418. OpenSSL compatibility layer. wolfSSL_Init() is the more typically-used
  2419. wolfSSL initialization function.
  2420. \return SSL_SUCCESS If successful the call will return.
  2421. \return SSL_FATAL_ERROR is returned upon failure.
  2422. \param none No parameters.
  2423. _Example_
  2424. \code
  2425. int ret = 0;
  2426. ret = wolfSSL_library_init();
  2427. if (ret != SSL_SUCCESS) {
  2428. failed to initialize wolfSSL
  2429. }
  2430. ...
  2431. \endcode
  2432. \sa wolfSSL_Init
  2433. \sa wolfSSL_Cleanup
  2434. */
  2435. int wolfSSL_library_init(void);
  2436. /*!
  2437. \brief This function sets the Device Id at the WOLFSSL session level.
  2438. \return WOLFSSL_SUCCESS upon success.
  2439. \return BAD_FUNC_ARG if ssl is NULL.
  2440. \param ssl pointer to a SSL object, created with wolfSSL_new().
  2441. \param devId ID to use with async hardware
  2442. _Example_
  2443. \code
  2444. WOLFSSL* ssl;
  2445. int DevId = -2;
  2446. wolfSSL_SetDevId(ssl, devId);
  2447. \endcode
  2448. \sa wolfSSL_CTX_SetDevId
  2449. \sa wolfSSL_CTX_GetDevId
  2450. */
  2451. int wolfSSL_SetDevId(WOLFSSL* ssl, int devId);
  2452. /*!
  2453. \brief This function sets the Device Id at the WOLFSSL_CTX context level.
  2454. \return WOLFSSL_SUCCESS upon success.
  2455. \return BAD_FUNC_ARG if ssl is NULL.
  2456. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2457. \param devId ID to use with async hardware
  2458. _Example_
  2459. \code
  2460. WOLFSSL_CTX* ctx;
  2461. int DevId = -2;
  2462. wolfSSL_CTX_SetDevId(ctx, devId);
  2463. \endcode
  2464. \sa wolfSSL_SetDevId
  2465. \sa wolfSSL_CTX_GetDevId
  2466. */
  2467. int wolfSSL_CTX_SetDevId(WOLFSSL_CTX* ctx, int devId);
  2468. /*!
  2469. \brief This function retrieves the Device Id.
  2470. \return devId upon success.
  2471. \return INVALID_DEVID if both ssl and ctx are NULL.
  2472. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2473. \param ssl pointer to a SSL object, created with wolfSSL_new().
  2474. _Example_
  2475. \code
  2476. WOLFSSL_CTX* ctx;
  2477. wolfSSL_CTX_GetDevId(ctx, ssl);
  2478. \endcode
  2479. \sa wolfSSL_SetDevId
  2480. \sa wolfSSL_CTX_SetDevId
  2481. */
  2482. int wolfSSL_CTX_GetDevId(WOLFSSL_CTX* ctx, WOLFSSL* ssl);
  2483. /*!
  2484. \ingroup Setup
  2485. \brief This function enables or disables SSL session caching.
  2486. Behavior depends on the value used for mode. The following values
  2487. for mode are available: SSL_SESS_CACHE_OFF- disable session caching.
  2488. Session caching is turned on by default. SSL_SESS_CACHE_NO_AUTO_CLEAR -
  2489. Disable auto-flushing of the session cache. Auto-flushing is turned on
  2490. by default.
  2491. \return SSL_SUCCESS will be returned upon success.
  2492. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2493. \param mode modifier used to change behavior of the session cache.
  2494. _Example_
  2495. \code
  2496. WOLFSSL_CTX* ctx = 0;
  2497. ...
  2498. ret = wolfSSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
  2499. if (ret != SSL_SUCCESS) {
  2500. // failed to turn SSL session caching off
  2501. }
  2502. \endcode
  2503. \sa wolfSSL_flush_sessions
  2504. \sa wolfSSL_get1_session
  2505. \sa wolfSSL_set_session
  2506. \sa wolfSSL_get_sessionID
  2507. \sa wolfSSL_CTX_set_timeout
  2508. */
  2509. long wolfSSL_CTX_set_session_cache_mode(WOLFSSL_CTX* ctx, long mode);
  2510. /*!
  2511. \brief This function sets the session secret callback function. The
  2512. SessionSecretCb type has the signature: int (*SessionSecretCb)(WOLFSSL* ssl,
  2513. void* secret, int* secretSz, void* ctx). The sessionSecretCb member of
  2514. the WOLFSSL struct is set to the parameter cb.
  2515. \return SSL_SUCCESS returned if the execution of the function did not
  2516. return an error.
  2517. \return SSL_FATAL_ERROR returned if the WOLFSSL structure is NULL.
  2518. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2519. \param cb a SessionSecretCb type that is a function pointer with the above
  2520. signature.
  2521. _Example_
  2522. \code
  2523. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2524. WOLFSSL* ssl = wolfSSL_new(ctx);
  2525. // Signature of SessionSecretCb
  2526. int SessionSecretCB (WOLFSSL* ssl, void* secret, int* secretSz,
  2527. void* ctx) = SessionSecretCb;
  2528. int wolfSSL_set_session_secret_cb(ssl, SessionSecretCB, (void*)ssl->ctx){
  2529. // Function body.
  2530. }
  2531. \endcode
  2532. \sa SessionSecretCb
  2533. */
  2534. int wolfSSL_set_session_secret_cb(WOLFSSL* ssl, SessionSecretCb cb, void* ctx);
  2535. /*!
  2536. \ingroup IO
  2537. \brief This function persists the session cache to file. It doesn’t use
  2538. memsave because of additional memory use.
  2539. \return SSL_SUCCESS returned if the function executed without error.
  2540. The session cache has been written to a file.
  2541. \return SSL_BAD_FILE returned if fname cannot be opened or is otherwise
  2542. corrupt.
  2543. \return FWRITE_ERROR returned if XFWRITE failed to write to the file.
  2544. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2545. \param name is a constant char pointer that points to a file for writing.
  2546. _Example_
  2547. \code
  2548. const char* fname;
  2549. ...
  2550. if(wolfSSL_save_session_cache(fname) != SSL_SUCCESS){
  2551. // Fail to write to file.
  2552. }
  2553. \endcode
  2554. \sa XFWRITE
  2555. \sa wolfSSL_restore_session_cache
  2556. \sa wolfSSL_memrestore_session_cache
  2557. */
  2558. int wolfSSL_save_session_cache(const char*);
  2559. /*!
  2560. \ingroup IO
  2561. \brief This function restores the persistent session cache from file. It
  2562. does not use memstore because of additional memory use.
  2563. \return SSL_SUCCESS returned if the function executed without error.
  2564. \return SSL_BAD_FILE returned if the file passed into the function was
  2565. corrupted and could not be opened by XFOPEN.
  2566. \return FREAD_ERROR returned if the file had a read error from XFREAD.
  2567. \return CACHE_MATCH_ERROR returned if the session cache header match
  2568. failed.
  2569. \return BAD_MUTEX_E returned if there was a mutex lock failure.
  2570. \param fname a constant char pointer file input that will be read.
  2571. _Example_
  2572. \code
  2573. const char *fname;
  2574. ...
  2575. if(wolfSSL_restore_session_cache(fname) != SSL_SUCCESS){
  2576. // Failure case. The function did not return SSL_SUCCESS.
  2577. }
  2578. \endcode
  2579. \sa XFREAD
  2580. \sa XFOPEN
  2581. */
  2582. int wolfSSL_restore_session_cache(const char*);
  2583. /*!
  2584. \ingroup IO
  2585. \brief This function persists session cache to memory.
  2586. \return SSL_SUCCESS returned if the function executed without error.
  2587. The session cache has been successfully persisted to memory.
  2588. \return BAD_MUTEX_E returned if there was a mutex lock error.
  2589. \return BUFFER_E returned if the buffer size was too small.
  2590. \param mem a void pointer representing the destination for the memory
  2591. copy, XMEMCPY().
  2592. \param sz an int type representing the size of mem.
  2593. _Example_
  2594. \code
  2595. void* mem;
  2596. int sz; // Max size of the memory buffer.
  2597. if(wolfSSL_memsave_session_cache(mem, sz) != SSL_SUCCESS){
  2598. // Failure case, you did not persist the session cache to memory
  2599. }
  2600. \endcode
  2601. \sa XMEMCPY
  2602. \sa wolfSSL_get_session_cache_memsize
  2603. */
  2604. int wolfSSL_memsave_session_cache(void* mem, int sz);
  2605. /*!
  2606. \ingroup IO
  2607. \brief This function restores the persistent session cache from memory.
  2608. \return SSL_SUCCESS returned if the function executed without an error.
  2609. \return BUFFER_E returned if the memory buffer is too small.
  2610. \return BAD_MUTEX_E returned if the session cache mutex lock failed.
  2611. \return CACHE_MATCH_ERROR returned if the session cache header match
  2612. failed.
  2613. \param mem a constant void pointer containing the source of the
  2614. restoration.
  2615. \param sz an integer representing the size of the memory buffer.
  2616. _Example_
  2617. \code
  2618. const void* memoryFile;
  2619. int szMf;
  2620. ...
  2621. if(wolfSSL_memrestore_session_cache(memoryFile, szMf) != SSL_SUCCESS){
  2622. // Failure case. SSL_SUCCESS was not returned.
  2623. }
  2624. \endcode
  2625. \sa wolfSSL_save_session_cache
  2626. */
  2627. int wolfSSL_memrestore_session_cache(const void* mem, int sz);
  2628. /*!
  2629. \ingroup IO
  2630. \brief This function returns how large the session cache save buffer
  2631. should be.
  2632. \return int This function returns an integer that represents the size of
  2633. the session cache save buffer.
  2634. \param none No parameters.
  2635. _Example_
  2636. \code
  2637. int sz = // Minimum size for error checking;
  2638. ...
  2639. if(sz < wolfSSL_get_session_cache_memsize()){
  2640. // Memory buffer is too small
  2641. }
  2642. \endcode
  2643. \sa wolfSSL_memrestore_session_cache
  2644. */
  2645. int wolfSSL_get_session_cache_memsize(void);
  2646. /*!
  2647. \ingroup CertsKeys
  2648. \brief This function writes the cert cache from memory to file.
  2649. \return SSL_SUCCESS if CM_SaveCertCache exits normally.
  2650. \return BAD_FUNC_ARG is returned if either of the arguments are NULL.
  2651. \return SSL_BAD_FILE if the cert cache save file could not be opened.
  2652. \return BAD_MUTEX_E if the lock mutex failed.
  2653. \return MEMORY_E the allocation of memory failed.
  2654. \return FWRITE_ERROR Certificate cache file write failed.
  2655. \param ctx a pointer to a WOLFSSL_CTX structure, holding the
  2656. certificate information.
  2657. \param fname the cert cache buffer.
  2658. _Example_
  2659. \code
  2660. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  2661. const char* fname;
  2662. ...
  2663. if(wolfSSL_CTX_save_cert_cache(ctx, fname)){
  2664. // file was written.
  2665. }
  2666. \endcode
  2667. \sa CM_SaveCertCache
  2668. \sa DoMemSaveCertCache
  2669. */
  2670. int wolfSSL_CTX_save_cert_cache(WOLFSSL_CTX* ctx, const char* fname);
  2671. /*!
  2672. \ingroup CertsKeys
  2673. \brief This function persistes certificate cache from a file.
  2674. \return SSL_SUCCESS returned if the function, CM_RestoreCertCache,
  2675. executes normally.
  2676. \return SSL_BAD_FILE returned if XFOPEN returns XBADFILE. The file is
  2677. corrupted.
  2678. \return MEMORY_E returned if the allocated memory for the temp buffer
  2679. fails.
  2680. \return BAD_FUNC_ARG returned if fname or ctx have a NULL value.
  2681. \param ctx a pointer to a WOLFSSL_CTX structure, holding the certificate
  2682. information.
  2683. \param fname the cert cache buffer.
  2684. _Example_
  2685. \code
  2686. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  2687. WOLFSSL* ssl = wolfSSL_new(ctx);
  2688. const char* fname = "path to file";
  2689. ...
  2690. if(wolfSSL_CTX_restore_cert_cache(ctx, fname)){
  2691. // check to see if the execution was successful
  2692. }
  2693. \endcode
  2694. \sa CM_RestoreCertCache
  2695. \sa XFOPEN
  2696. */
  2697. int wolfSSL_CTX_restore_cert_cache(WOLFSSL_CTX* ctx, const char* fname);
  2698. /*!
  2699. \ingroup CertsKeys
  2700. \brief This function persists the certificate cache to memory.
  2701. \return SSL_SUCCESS returned on successful execution of the function.
  2702. No errors were thrown.
  2703. \return BAD_MUTEX_E mutex error where the WOLFSSL_CERT_MANAGER member
  2704. caLock was not 0 (zero).
  2705. \return BAD_FUNC_ARG returned if ctx, mem, or used is NULL or if sz
  2706. is less than or equal to 0 (zero).
  2707. \return BUFFER_E output buffer mem was too small.
  2708. \param ctx a pointer to a WOLFSSL_CTX structure, created
  2709. using wolfSSL_CTX_new().
  2710. \param mem a void pointer to the destination (output buffer).
  2711. \param sz the size of the output buffer.
  2712. \param used a pointer to size of the cert cache header.
  2713. _Example_
  2714. \code
  2715. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  2716. void* mem;
  2717. int sz;
  2718. int* used;
  2719. ...
  2720. if(wolfSSL_CTX_memsave_cert_cache(ctx, mem, sz, used) != SSL_SUCCESS){
  2721. // The function returned with an error
  2722. }
  2723. \endcode
  2724. \sa DoMemSaveCertCache
  2725. \sa GetCertCacheMemSize
  2726. \sa CM_MemRestoreCertCache
  2727. \sa CM_GetCertCacheMemSize
  2728. */
  2729. int wolfSSL_CTX_memsave_cert_cache(WOLFSSL_CTX* ctx, void* mem, int sz, int* used);
  2730. /*!
  2731. \ingroup Setup
  2732. \brief This function restores the certificate cache from memory.
  2733. \return SSL_SUCCESS returned if the function and subroutines
  2734. executed without an error.
  2735. \return BAD_FUNC_ARG returned if the ctx or mem parameters are
  2736. NULL or if the sz parameter is less than or equal to zero.
  2737. \return BUFFER_E returned if the cert cache memory buffer is too small.
  2738. \return CACHE_MATCH_ERROR returned if there was a cert cache
  2739. header mismatch.
  2740. \return BAD_MUTEX_E returned if the lock mutex on failed.
  2741. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  2742. wolfSSL_CTX_new().
  2743. \param mem a void pointer with a value that will be restored to
  2744. the certificate cache.
  2745. \param sz an int type that represents the size of the mem parameter.
  2746. _Example_
  2747. \code
  2748. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  2749. WOLFSSL* ssl = WOLFSSL_new(ctx);
  2750. void* mem;
  2751. int sz = (*int) sizeof(mem);
  2752. if(wolfSSL_CTX_memrestore_cert_cache(ssl->ctx, mem, sz)){
  2753. // The success case
  2754. }
  2755. \endcode
  2756. \sa CM_MemRestoreCertCache
  2757. */
  2758. int wolfSSL_CTX_memrestore_cert_cache(WOLFSSL_CTX* ctx, const void* mem, int sz);
  2759. /*!
  2760. \ingroup CertsKeys
  2761. \brief Returns the size the certificate cache save buffer needs to be.
  2762. \return int integer value returned representing the memory size
  2763. upon success.
  2764. \return BAD_FUNC_ARG is returned if the WOLFSSL_CTX struct is NULL.
  2765. \return BAD_MUTEX_E - returned if there was a mutex lock error.
  2766. \param ctx a pointer to a wolfSSL_CTX structure, created using
  2767. wolfSSL_CTX_new().
  2768. _Example_
  2769. \code
  2770. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol);
  2771. ...
  2772. int certCacheSize = wolfSSL_CTX_get_cert_cache_memsize(ctx);
  2773. if(certCacheSize != BAD_FUNC_ARG || certCacheSize != BAD_MUTEX_E){
  2774. // Successfully retrieved the memory size.
  2775. }
  2776. \endcode
  2777. \sa CM_GetCertCacheMemSize
  2778. */
  2779. int wolfSSL_CTX_get_cert_cache_memsize(WOLFSSL_CTX*);
  2780. /*!
  2781. \ingroup Setup
  2782. \brief This function sets cipher suite list for a given WOLFSSL_CTX.
  2783. This cipher suite list becomes the default list for any new SSL sessions
  2784. (WOLFSSL) created using this context. The ciphers in the list should be
  2785. sorted in order of preference from highest to lowest. Each call to
  2786. wolfSSL_CTX_set_cipher_list() resets the cipher suite list for the
  2787. specific SSL context to the provided list each time the function is
  2788. called. The cipher suite list, list, is a null-terminated text string,
  2789. and a colon-delimited list. For example, one value for list may be
  2790. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256" Valid cipher
  2791. values are the full name values from the cipher_names[] array in
  2792. src/internal.c (for a definite list of valid cipher values check
  2793. src/internal.c)
  2794. \return SSL_SUCCESS will be returned upon successful function completion.
  2795. \return SSL_FAILURE will be returned on failure.
  2796. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  2797. \param list null-terminated text string and a colon-delimited list of
  2798. cipher suites to use with the specified SSL context.
  2799. _Example_
  2800. \code
  2801. WOLFSSL_CTX* ctx = 0;
  2802. ...
  2803. ret = wolfSSL_CTX_set_cipher_list(ctx,
  2804. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2805. if (ret != SSL_SUCCESS) {
  2806. // failed to set cipher suite list
  2807. }
  2808. \endcode
  2809. \sa wolfSSL_set_cipher_list
  2810. \sa wolfSSL_CTX_new
  2811. */
  2812. int wolfSSL_CTX_set_cipher_list(WOLFSSL_CTX* ctx, const char* list);
  2813. /*!
  2814. \ingroup Setup
  2815. \brief This function sets cipher suite list for a given WOLFSSL object
  2816. (SSL session). The ciphers in the list should be sorted in order of
  2817. preference from highest to lowest. Each call to wolfSSL_set_cipher_list()
  2818. resets the cipher suite list for the specific SSL session to the provided
  2819. list each time the function is called. The cipher suite list, list, is a
  2820. null-terminated text string, and a colon-delimited list. For example, one
  2821. value for list may be
  2822. "DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256".
  2823. Valid cipher values are the full name values from the cipher_names[]
  2824. array in src/internal.c (for a definite list of valid cipher values
  2825. check src/internal.c)
  2826. \return SSL_SUCCESS will be returned upon successful function completion.
  2827. \return SSL_FAILURE will be returned on failure.
  2828. \param ssl pointer to the SSL session, created with wolfSSL_new().
  2829. \param list null-terminated text string and a colon-delimited list of
  2830. cipher suites to use with the specified SSL session.
  2831. _Example_
  2832. \code
  2833. int ret = 0;
  2834. WOLFSSL* ssl = 0;
  2835. ...
  2836. ret = wolfSSL_set_cipher_list(ssl,
  2837. “DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:AES256-SHA256”);
  2838. if (ret != SSL_SUCCESS) {
  2839. // failed to set cipher suite list
  2840. }
  2841. \endcode
  2842. \sa wolfSSL_CTX_set_cipher_list
  2843. \sa wolfSSL_new
  2844. */
  2845. int wolfSSL_set_cipher_list(WOLFSSL* ssl, const char* list);
  2846. /*!
  2847. \brief This function informs the WOLFSSL DTLS object that the underlying
  2848. UDP I/O is non-blocking. After an application creates a WOLFSSL object,
  2849. if it will be used with a non-blocking UDP socket, call
  2850. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2851. that receiving EWOULDBLOCK means that the recvfrom call would
  2852. block rather than that it timed out.
  2853. \return none No return.
  2854. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2855. \param nonblock value used to set non-blocking flag on WOLFSSL object.
  2856. Use 1 to specify non-blocking, otherwise 0.
  2857. _Example_
  2858. \code
  2859. WOLFSSL* ssl = 0;
  2860. ...
  2861. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  2862. \endcode
  2863. \sa wolfSSL_dtls_get_using_nonblock
  2864. \sa wolfSSL_dtls_got_timeout
  2865. \sa wolfSSL_dtls_get_current_timeout
  2866. */
  2867. void wolfSSL_dtls_set_using_nonblock(WOLFSSL* ssl, int nonblock);
  2868. /*!
  2869. \brief This function allows the application to determine if wolfSSL is
  2870. using non-blocking I/O with UDP. If wolfSSL is using non-blocking I/O, this
  2871. function will return 1, otherwise 0. After an application creates a
  2872. WOLFSSL object, if it will be used with a non-blocking UDP socket, call
  2873. wolfSSL_dtls_set_using_nonblock() on it. This lets the WOLFSSL object know
  2874. that receiving EWOULDBLOCK means that the recvfrom call would block
  2875. rather than that it timed out. This function is only meaningful to DTLS
  2876. sessions.
  2877. \return 0 underlying I/O is blocking.
  2878. \return 1 underlying I/O is non-blocking.
  2879. \param ssl pointer to the DTLS session, created with wolfSSL_new().
  2880. _Example_
  2881. \code
  2882. int ret = 0;
  2883. WOLFSSL* ssl = 0;
  2884. ...
  2885. ret = wolfSSL_dtls_get_using_nonblock(ssl);
  2886. if (ret == 1) {
  2887. // underlying I/O is non-blocking
  2888. }
  2889. ...
  2890. \endcode
  2891. \sa wolfSSL_dtls_set_using_nonblock
  2892. \sa wolfSSL_dtls_got_timeout
  2893. \sa wolfSSL_dtls_set_using_nonblock
  2894. */
  2895. int wolfSSL_dtls_get_using_nonblock(WOLFSSL*);
  2896. /*!
  2897. \brief This function returns the current timeout value in seconds for
  2898. the WOLFSSL object. When using non-blocking sockets, something in the user
  2899. code needs to decide when to check for available recv data and how long
  2900. it has been waiting. The value returned by this function indicates how
  2901. long the application should wait.
  2902. \return seconds The current DTLS timeout value in seconds
  2903. \return NOT_COMPILED_IN if wolfSSL was not built with DTLS support.
  2904. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2905. _Example_
  2906. \code
  2907. int timeout = 0;
  2908. WOLFSSL* ssl;
  2909. ...
  2910. timeout = wolfSSL_get_dtls_current_timeout(ssl);
  2911. printf(“DTLS timeout (sec) = %d\n”, timeout);
  2912. \endcode
  2913. \sa wolfSSL_dtls
  2914. \sa wolfSSL_dtls_get_peer
  2915. \sa wolfSSL_dtls_got_timeout
  2916. \sa wolfSSL_dtls_set_peer
  2917. */
  2918. int wolfSSL_dtls_get_current_timeout(WOLFSSL* ssl);
  2919. /*!
  2920. \brief This function returns true if the application should setup a quicker
  2921. timeout. When using non-blocking sockets, something in the user code needs
  2922. to decide when to check for available data and how long it needs to wait. If
  2923. this function returns true, it means that the library already detected some
  2924. disruption in the communication, but it wants to wait for a little longer in
  2925. case some messages from the other peers are still in flight. Is up to the
  2926. application to fine tune the value of this timer, a good one may be
  2927. dtls_get_current_timeout() / 4.
  2928. \return true if the application code should setup a quicker timeout
  2929. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2930. \sa wolfSSL_dtls
  2931. \sa wolfSSL_dtls_get_peer
  2932. \sa wolfSSL_dtls_got_timeout
  2933. \sa wolfSSL_dtls_set_peer
  2934. \sa wolfSSL_dtls13_set_send_more_acks
  2935. */
  2936. int wolfSSL_dtls13_use_quick_timeout(WOLFSSL *ssl);
  2937. /*!
  2938. \ingroup Setup
  2939. \brief This function sets whether the library should send ACKs to the other
  2940. peer immediately when detecting disruption or not. Sending ACKs immediately
  2941. assures minimum latency but it may consume more bandwidth than necessary. If
  2942. the application manages the timer by itself and this option is set to 0 then
  2943. application code can use wolfSSL_dtls13_use_quick_timeout() to determine if
  2944. it should setup a quicker timeout to send those delayed ACKs.
  2945. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2946. \param value 1 to set the option, 0 to disable the option
  2947. \sa wolfSSL_dtls
  2948. \sa wolfSSL_dtls_get_peer
  2949. \sa wolfSSL_dtls_got_timeout
  2950. \sa wolfSSL_dtls_set_peer
  2951. \sa wolfSSL_dtls13_use_quick_timeout
  2952. */
  2953. void wolfSSL_dtls13_set_send_more_acks(WOLFSSL *ssl, int value);
  2954. /*!
  2955. \ingroup Setup
  2956. \brief This function sets the dtls timeout.
  2957. \return SSL_SUCCESS returned if the function executes without an error.
  2958. The dtls_timeout_init and the dtls_timeout members of SSL have been set.
  2959. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  2960. the timeout is not greater than 0. It will also return if the timeout
  2961. argument exceeds the maximum value allowed.
  2962. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2963. \param timeout an int type that will be set to the dtls_timeout_init
  2964. member of the WOLFSSL structure.
  2965. _Example_
  2966. \code
  2967. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2968. WOLFSSL* ssl = wolfSSL_new(ctx);
  2969. int timeout = TIMEOUT;
  2970. ...
  2971. if(wolfSSL_dtls_set_timeout_init(ssl, timeout)){
  2972. // the dtls timeout was set
  2973. } else {
  2974. // Failed to set DTLS timeout.
  2975. }
  2976. \endcode
  2977. \sa wolfSSL_dtls_set_timeout_max
  2978. \sa wolfSSL_dtls_got_timeout
  2979. */
  2980. int wolfSSL_dtls_set_timeout_init(WOLFSSL* ssl, int);
  2981. /*!
  2982. \brief This function sets the maximum dtls timeout.
  2983. \return SSL_SUCCESS returned if the function executed without an error.
  2984. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  2985. the timeout argument is not greater than zero or is less than the
  2986. dtls_timeout_init member of the WOLFSSL structure.
  2987. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  2988. \param timeout an int type representing the dtls maximum timeout.
  2989. _Example_
  2990. \code
  2991. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  2992. WOLFSSL* ssl = wolfSSL_new(ctx);
  2993. int timeout = TIMEOUTVAL;
  2994. ...
  2995. int ret = wolfSSL_dtls_set_timeout_max(ssl);
  2996. if(!ret){
  2997. // Failed to set the max timeout
  2998. }
  2999. \endcode
  3000. \sa wolfSSL_dtls_set_timeout_init
  3001. \sa wolfSSL_dtls_got_timeout
  3002. */
  3003. int wolfSSL_dtls_set_timeout_max(WOLFSSL* ssl, int);
  3004. /*!
  3005. \brief When using non-blocking sockets with DTLS, this function should
  3006. be called on the WOLFSSL object when the controlling code thinks the
  3007. transmission has timed out. It performs the actions needed to retry
  3008. the last transmit, including adjusting the timeout value. If it
  3009. has been too long, this will return a failure.
  3010. \return SSL_SUCCESS will be returned upon success
  3011. \return SSL_FATAL_ERROR will be returned if there have been too many
  3012. retransmissions/timeouts without getting a response from the peer.
  3013. \return NOT_COMPILED_IN will be returned if wolfSSL was not compiled with
  3014. DTLS support.
  3015. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3016. _Example_
  3017. \code
  3018. See the following files for usage examples:
  3019. <wolfssl_root>/examples/client/client.c
  3020. <wolfssl_root>/examples/server/server.c
  3021. \endcode
  3022. \sa wolfSSL_dtls_get_current_timeout
  3023. \sa wolfSSL_dtls_get_peer
  3024. \sa wolfSSL_dtls_set_peer
  3025. \sa wolfSSL_dtls
  3026. */
  3027. int wolfSSL_dtls_got_timeout(WOLFSSL* ssl);
  3028. /*!
  3029. \brief When using non-blocking sockets with DTLS, this function retransmits
  3030. the last handshake flight ignoring the expected timeout value and
  3031. retransmit count. It is useful for applications that are using DTLS and
  3032. need to manage even the timeout and retry count.
  3033. \return SSL_SUCCESS will be returned upon success
  3034. \return SSL_FATAL_ERROR will be returned if there have been too many
  3035. retransmissions/timeouts without getting a response from the peer.
  3036. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3037. _Example_
  3038. \code
  3039. int ret = 0;
  3040. WOLFSSL* ssl;
  3041. ...
  3042. ret = wolfSSL_dtls_retransmit(ssl);
  3043. \endcode
  3044. \sa wolfSSL_dtls_get_current_timeout
  3045. \sa wolfSSL_dtls_got_timeout
  3046. \sa wolfSSL_dtls
  3047. */
  3048. int wolfSSL_dtls_retransmit(WOLFSSL* ssl);
  3049. /*!
  3050. \brief This function is used to determine if the SSL session has been
  3051. configured to use DTLS.
  3052. \return 1 If the SSL session (ssl) has been configured to use DTLS, this
  3053. function will return 1.
  3054. \return 0 otherwise.
  3055. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3056. _Example_
  3057. \code
  3058. int ret = 0;
  3059. WOLFSSL* ssl;
  3060. ...
  3061. ret = wolfSSL_dtls(ssl);
  3062. if (ret) {
  3063. // SSL session has been configured to use DTLS
  3064. }
  3065. \endcode
  3066. \sa wolfSSL_dtls_get_current_timeout
  3067. \sa wolfSSL_dtls_get_peer
  3068. \sa wolfSSL_dtls_got_timeout
  3069. \sa wolfSSL_dtls_set_peer
  3070. */
  3071. int wolfSSL_dtls(WOLFSSL* ssl);
  3072. /*!
  3073. \brief This function sets the DTLS peer, peer (sockaddr_in) with size of
  3074. peerSz.
  3075. \return SSL_SUCCESS will be returned upon success.
  3076. \return SSL_FAILURE will be returned upon failure.
  3077. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  3078. with DTLS support.
  3079. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3080. \param peer pointer to peer’s sockaddr_in structure. If NULL then the peer
  3081. information in ssl is cleared.
  3082. \param peerSz size of the sockaddr_in structure pointed to by peer. If 0
  3083. then the peer information in ssl is cleared.
  3084. _Example_
  3085. \code
  3086. int ret = 0;
  3087. WOLFSSL* ssl;
  3088. sockaddr_in addr;
  3089. ...
  3090. ret = wolfSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
  3091. if (ret != SSL_SUCCESS) {
  3092. // failed to set DTLS peer
  3093. }
  3094. \endcode
  3095. \sa wolfSSL_dtls_get_current_timeout
  3096. \sa wolfSSL_dtls_get_peer
  3097. \sa wolfSSL_dtls_got_timeout
  3098. \sa wolfSSL_dtls
  3099. */
  3100. int wolfSSL_dtls_set_peer(WOLFSSL* ssl, void* peer, unsigned int peerSz);
  3101. /*!
  3102. \brief This function gets the sockaddr_in (of size peerSz) of the current
  3103. DTLS peer. The function will compare peerSz to the actual DTLS peer size
  3104. stored in the SSL session. If the peer will fit into peer, the peer’s
  3105. sockaddr_in will be copied into peer, with peerSz set to the size of peer.
  3106. \return SSL_SUCCESS will be returned upon success.
  3107. \return SSL_FAILURE will be returned upon failure.
  3108. \return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled
  3109. with DTLS support.
  3110. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3111. \param peer pointer to memory location to store peer’s sockaddr_in
  3112. structure.
  3113. \param peerSz input/output size. As input, the size of the allocated memory
  3114. pointed to by peer. As output, the size of the actual sockaddr_in structure
  3115. pointed to by peer.
  3116. _Example_
  3117. \code
  3118. int ret = 0;
  3119. WOLFSSL* ssl;
  3120. sockaddr_in addr;
  3121. ...
  3122. ret = wolfSSL_dtls_get_peer(ssl, &addr, sizeof(addr));
  3123. if (ret != SSL_SUCCESS) {
  3124. // failed to get DTLS peer
  3125. }
  3126. \endcode
  3127. \sa wolfSSL_dtls_get_current_timeout
  3128. \sa wolfSSL_dtls_got_timeout
  3129. \sa wolfSSL_dtls_set_peer
  3130. \sa wolfSSL_dtls
  3131. */
  3132. int wolfSSL_dtls_get_peer(WOLFSSL* ssl, void* peer, unsigned int* peerSz);
  3133. /*!
  3134. \ingroup Debug
  3135. \brief This function converts an error code returned by
  3136. wolfSSL_get_error() into a more human-readable error string.
  3137. errNumber is the error code returned by wolfSSL_get_error() and data
  3138. is the storage buffer which the error string will be placed in.
  3139. The maximum length of data is 80 characters by default, as defined by
  3140. MAX_ERROR_SZ is wolfssl/wolfcrypt/error.h.
  3141. \return success On successful completion, this function returns the same
  3142. string as is returned in data.
  3143. \return failure Upon failure, this function returns a string with the
  3144. appropriate failure reason, msg.
  3145. \param errNumber error code returned by wolfSSL_get_error().
  3146. \param data output buffer containing human-readable error string matching
  3147. errNumber.
  3148. _Example_
  3149. \code
  3150. int err = 0;
  3151. WOLFSSL* ssl;
  3152. char buffer[80];
  3153. ...
  3154. err = wolfSSL_get_error(ssl, 0);
  3155. wolfSSL_ERR_error_string(err, buffer);
  3156. printf(“err = %d, %s\n”, err, buffer);
  3157. \endcode
  3158. \sa wolfSSL_get_error
  3159. \sa wolfSSL_ERR_error_string_n
  3160. \sa wolfSSL_ERR_print_errors_fp
  3161. \sa wolfSSL_load_error_strings
  3162. */
  3163. char* wolfSSL_ERR_error_string(unsigned long,char*);
  3164. /*!
  3165. \ingroup Debug
  3166. \brief This function is a version of wolfSSL_ERR_error_string() where
  3167. len specifies the maximum number of characters that may be written to buf.
  3168. Like wolfSSL_ERR_error_string(), this function converts an error code
  3169. returned from wolfSSL_get_error() into a more human-readable error string.
  3170. The human-readable string is placed in buf.
  3171. \return none No returns.
  3172. \param e error code returned by wolfSSL_get_error().
  3173. \param buff output buffer containing human-readable error string matching e.
  3174. \param len maximum length in characters which may be written to buf.
  3175. _Example_
  3176. \code
  3177. int err = 0;
  3178. WOLFSSL* ssl;
  3179. char buffer[80];
  3180. ...
  3181. err = wolfSSL_get_error(ssl, 0);
  3182. wolfSSL_ERR_error_string_n(err, buffer, 80);
  3183. printf(“err = %d, %s\n”, err, buffer);
  3184. \endcode
  3185. \sa wolfSSL_get_error
  3186. \sa wolfSSL_ERR_error_string
  3187. \sa wolfSSL_ERR_print_errors_fp
  3188. \sa wolfSSL_load_error_strings
  3189. */
  3190. void wolfSSL_ERR_error_string_n(unsigned long e, char* buf,
  3191. unsigned long sz);
  3192. /*!
  3193. \ingroup TLS
  3194. \brief This function checks the shutdown conditions in closeNotify or
  3195. connReset or sentNotify members of the Options structure. The Options
  3196. structure is within the WOLFSSL structure.
  3197. \return 1 SSL_SENT_SHUTDOWN is returned.
  3198. \return 2 SS_RECEIVED_SHUTDOWN is returned.
  3199. \param ssl a constant pointer to a WOLFSSL structure, created using
  3200. wolfSSL_new().
  3201. _Example_
  3202. \code
  3203. #include <wolfssl/ssl.h>
  3204. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  3205. WOLFSSL* ssl = WOLFSSL_new(ctx);
  3206. int ret;
  3207. ret = wolfSSL_get_shutdown(ssl);
  3208. if(ret == 1){
  3209. SSL_SENT_SHUTDOWN
  3210. } else if(ret == 2){
  3211. SSL_RECEIVED_SHUTDOWN
  3212. } else {
  3213. Fatal error.
  3214. }
  3215. \endcode
  3216. \sa wolfSSL_SESSION_free
  3217. */
  3218. int wolfSSL_get_shutdown(const WOLFSSL*);
  3219. /*!
  3220. \ingroup IO
  3221. \brief This function returns the resuming member of the options struct. The
  3222. flag indicates whether or not to reuse a session. If not, a new session must
  3223. be established.
  3224. \return This function returns an int type held in the Options structure
  3225. representing the flag for session reuse.
  3226. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3227. _Example_
  3228. \code
  3229. WOLFSSL* ssl = wolfSSL_new(ctx);
  3230. if(!wolfSSL_session_reused(sslResume)){
  3231. // No session reuse allowed.
  3232. }
  3233. \endcode
  3234. \sa wolfSSL_SESSION_free
  3235. \sa wolfSSL_GetSessionIndex
  3236. \sa wolfSSL_memsave_session_cache
  3237. */
  3238. int wolfSSL_session_reused(WOLFSSL*);
  3239. /*!
  3240. \ingroup TLS
  3241. \brief This function checks to see if the connection is established.
  3242. \return 0 returned if the connection is not established, i.e. the WOLFSSL
  3243. struct is NULL or the handshake is not done.
  3244. \return 1 returned if the connection is not established i.e. the WOLFSSL
  3245. struct is null or the handshake is not done.
  3246. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3247. _EXAMPLE_
  3248. \code
  3249. #include <wolfssl/ssl.h>
  3250. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3251. WOLFSSL* ssl = wolfSSL_new(ctx);
  3252. ...
  3253. if(wolfSSL_is_init_finished(ssl)){
  3254. Handshake is done and connection is established
  3255. }
  3256. \endcode
  3257. \sa wolfSSL_set_accept_state
  3258. \sa wolfSSL_get_keys
  3259. \sa wolfSSL_set_shutdown
  3260. */
  3261. int wolfSSL_is_init_finished(WOLFSSL*);
  3262. /*!
  3263. \ingroup IO
  3264. \brief Returns the SSL version being used as a string.
  3265. \return "SSLv3" Using SSLv3
  3266. \return "TLSv1" Using TLSv1
  3267. \return "TLSv1.1" Using TLSv1.1
  3268. \return "TLSv1.2" Using TLSv1.2
  3269. \return "TLSv1.3" Using TLSv1.3
  3270. \return "DTLS": Using DTLS
  3271. \return "DTLSv1.2" Using DTLSv1.2
  3272. \return "unknown" There was a problem determining which version of TLS
  3273. being used.
  3274. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3275. _Example_
  3276. \code
  3277. wolfSSL_Init();
  3278. WOLFSSL_CTX* ctx;
  3279. WOLFSSL* ssl;
  3280. WOLFSSL_METHOD method = // Some wolfSSL method
  3281. ctx = wolfSSL_CTX_new(method);
  3282. ssl = wolfSSL_new(ctx);
  3283. printf(wolfSSL_get_version("Using version: %s", ssl));
  3284. \endcode
  3285. \sa wolfSSL_lib_version
  3286. */
  3287. const char* wolfSSL_get_version(WOLFSSL*);
  3288. /*!
  3289. \ingroup IO
  3290. \brief Returns the current cipher suit an ssl session is using.
  3291. \return ssl->options.cipherSuite An integer representing the current
  3292. cipher suite.
  3293. \return 0 The ssl session provided is null.
  3294. \param ssl The SSL session to check.
  3295. _Example_
  3296. \code
  3297. wolfSSL_Init();
  3298. WOLFSSL_CTX* ctx;
  3299. WOLFSSL* ssl;
  3300. WOLFSSL_METHOD method = // Some wolfSSL method
  3301. ctx = wolfSSL_CTX_new(method);
  3302. ssl = wolfSSL_new(ctx);
  3303. if(wolfSSL_get_current_cipher_suite(ssl) == 0)
  3304. {
  3305. // Error getting cipher suite
  3306. }
  3307. \endcode
  3308. \sa wolfSSL_CIPHER_get_name
  3309. \sa wolfSSL_get_current_cipher
  3310. \sa wolfSSL_get_cipher_list
  3311. */
  3312. int wolfSSL_get_current_cipher_suite(WOLFSSL* ssl);
  3313. /*!
  3314. \ingroup IO
  3315. \brief This function returns a pointer to the current cipher in the
  3316. ssl session.
  3317. \return The function returns the address of the cipher member of the
  3318. WOLFSSL struct. This is a pointer to the WOLFSSL_CIPHER structure.
  3319. \return NULL returned if the WOLFSSL structure is NULL.
  3320. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3321. _Example_
  3322. \code
  3323. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  3324. WOLFSSL* ssl = wolfSSL_new(ctx);
  3325. WOLFSSL_CIPHER* cipherCurr = wolfSSL_get_current_cipher;
  3326. if(!cipherCurr){
  3327. // Failure case.
  3328. } else {
  3329. // The cipher was returned to cipherCurr
  3330. }
  3331. \endcode
  3332. \sa wolfSSL_get_cipher
  3333. \sa wolfSSL_get_cipher_name_internal
  3334. \sa wolfSSL_get_cipher_name
  3335. */
  3336. WOLFSSL_CIPHER* wolfSSL_get_current_cipher(WOLFSSL*);
  3337. /*!
  3338. \ingroup IO
  3339. \brief This function matches the cipher suite in the SSL object with
  3340. the available suites and returns the string representation.
  3341. \return string This function returns the string representation of the
  3342. matched cipher suite.
  3343. \return none It will return “None” if there are no suites matched.
  3344. \param cipher a constant pointer to a WOLFSSL_CIPHER structure.
  3345. _Example_
  3346. \code
  3347. // gets cipher name in the format DHE_RSA ...
  3348. const char* wolfSSL_get_cipher_name_internal(WOLFSSL* ssl){
  3349. WOLFSSL_CIPHER* cipher;
  3350. const char* fullName;
  3351. cipher = wolfSSL_get_curent_cipher(ssl);
  3352. fullName = wolfSSL_CIPHER_get_name(cipher);
  3353. if(fullName){
  3354. // sanity check on returned cipher
  3355. }
  3356. \endcode
  3357. \sa wolfSSL_get_cipher
  3358. \sa wolfSSL_get_current_cipher
  3359. \sa wolfSSL_get_cipher_name_internal
  3360. \sa wolfSSL_get_cipher_name
  3361. */
  3362. const char* wolfSSL_CIPHER_get_name(const WOLFSSL_CIPHER* cipher);
  3363. /*!
  3364. \ingroup IO
  3365. \brief This function matches the cipher suite in the SSL object with
  3366. the available suites.
  3367. \return This function returns the string value of the suite matched. It
  3368. will return “None” if there are no suites matched.
  3369. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3370. _Example_
  3371. \code
  3372. #ifdef WOLFSSL_DTLS
  3373. // make sure a valid suite is used
  3374. if(wolfSSL_get_cipher(ssl) == NULL){
  3375. WOLFSSL_MSG(“Can not match cipher suite imported”);
  3376. return MATCH_SUITE_ERROR;
  3377. }
  3378. #endif // WOLFSSL_DTLS
  3379. \endcode
  3380. \sa wolfSSL_CIPHER_get_name
  3381. \sa wolfSSL_get_current_cipher
  3382. */
  3383. const char* wolfSSL_get_cipher(WOLFSSL*);
  3384. /*!
  3385. \ingroup Setup
  3386. \brief This function returns the WOLFSSL_SESSION from the WOLFSSL structure
  3387. as a reference type. This requires calling wolfSSL_SESSION_free to release
  3388. the session reference. The WOLFSSL_SESSION pointed to contains all the
  3389. necessary information required to perform a session resumption and
  3390. reestablish the connection without a new handshake. For
  3391. session resumption, before calling wolfSSL_shutdown() with your session
  3392. object, an application should save the session ID from the object with a
  3393. call to wolfSSL_get1_session(), which returns a pointer to the session.
  3394. Later, the application should create a new WOLFSSL object and assign the
  3395. saved session with wolfSSL_set_session(). At this point, the application
  3396. may call wolfSSL_connect() and wolfSSL will try to resume the session.
  3397. The wolfSSL server code allows session resumption by default. The object
  3398. returned by wolfSSL_get1_session() needs to be freed after the application
  3399. is done with it by calling wolfSSL_SESSION_free() on it.
  3400. \return WOLFSSL_SESSION On success return session pointer.
  3401. \return NULL will be returned if ssl is NULL, the SSL session cache is
  3402. disabled, wolfSSL doesn’t have the Session ID available, or mutex
  3403. functions fail.
  3404. \param ssl WOLFSSL structure to get session from.
  3405. _Example_
  3406. \code
  3407. WOLFSSL* ssl;
  3408. WOLFSSL_SESSION* ses;
  3409. // attempt/complete handshake
  3410. wolfSSL_connect(ssl);
  3411. ses = wolfSSL_get1_session(ssl);
  3412. // check ses information
  3413. // disconnect / setup new SSL instance
  3414. wolfSSL_set_session(ssl, ses);
  3415. // attempt/resume handshake
  3416. wolfSSL_SESSION_free(ses);
  3417. \endcode
  3418. \sa wolfSSL_new
  3419. \sa wolfSSL_free
  3420. \sa wolfSSL_SESSION_free
  3421. */
  3422. WOLFSSL_SESSION* wolfSSL_get1_session(WOLFSSL* ssl);
  3423. /*!
  3424. \ingroup Setup
  3425. \brief The wolfSSLv23_client_method() function is used to indicate that
  3426. the application is a client and will support the highest protocol
  3427. version supported by the server between SSL 3.0 - TLS 1.3. This function
  3428. allocates memory for and initializes a new WOLFSSL_METHOD structure
  3429. to be used when creating the SSL/TLS context with wolfSSL_CTX_new().
  3430. Both wolfSSL clients and servers have robust version downgrade capability.
  3431. If a specific protocol version method is used on either side, then only
  3432. that version will be negotiated or an error will be returned. For
  3433. example, a client that uses TLSv1 and tries to connect to a SSLv3 only
  3434. server will fail, likewise connecting to a TLSv1.1 will fail as well.
  3435. To resolve this issue, a client that uses the wolfSSLv23_client_method()
  3436. function will use the highest protocol version supported by the server and
  3437. downgrade to SSLv3 if needed. In this case, the client will be able to
  3438. connect to a server running SSLv3 - TLSv1.3.
  3439. \return pointer upon success a pointer to a WOLFSSL_METHOD.
  3440. \return Failure If memory allocation fails when calling XMALLOC,
  3441. the failure value of the underlying malloc() implementation will be
  3442. returned (typically NULL with errno will be set to ENOMEM).
  3443. \param none No parameters
  3444. _Example_
  3445. \code
  3446. WOLFSSL_METHOD* method;
  3447. WOLFSSL_CTX* ctx;
  3448. method = wolfSSLv23_client_method();
  3449. if (method == NULL) {
  3450. // unable to get method
  3451. }
  3452. ctx = wolfSSL_CTX_new(method);
  3453. ...
  3454. \endcode
  3455. \sa wolfSSLv3_client_method
  3456. \sa wolfTLSv1_client_method
  3457. \sa wolfTLSv1_1_client_method
  3458. \sa wolfTLSv1_2_client_method
  3459. \sa wolfTLSv1_3_client_method
  3460. \sa wolfDTLSv1_client_method
  3461. \sa wolfSSL_CTX_new
  3462. */
  3463. WOLFSSL_METHOD* wolfSSLv23_client_method(void);
  3464. /*!
  3465. \ingroup IO
  3466. \brief This is used to set a byte pointer to the start of the
  3467. internal memory buffer.
  3468. \return size On success the size of the buffer is returned
  3469. \return SSL_FATAL_ERROR If an error case was encountered.
  3470. \param bio WOLFSSL_BIO structure to get memory buffer of.
  3471. \param p byte pointer to set to memory buffer.
  3472. _Example_
  3473. \code
  3474. WOLFSSL_BIO* bio;
  3475. const byte* p;
  3476. int ret;
  3477. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3478. ret = wolfSSL_BIO_get_mem_data(bio, &p);
  3479. // check ret value
  3480. \endcode
  3481. \sa wolfSSL_BIO_new
  3482. \sa wolfSSL_BIO_s_mem
  3483. \sa wolfSSL_BIO_set_fp
  3484. \sa wolfSSL_BIO_free
  3485. */
  3486. int wolfSSL_BIO_get_mem_data(WOLFSSL_BIO* bio,void* p);
  3487. /*!
  3488. \ingroup IO
  3489. \brief Sets the file descriptor for bio to use.
  3490. \return SSL_SUCCESS(1) upon success.
  3491. \param bio WOLFSSL_BIO structure to set fd.
  3492. \param fd file descriptor to use.
  3493. \param closeF flag for behavior when closing fd.
  3494. _Example_
  3495. \code
  3496. WOLFSSL_BIO* bio;
  3497. int fd;
  3498. // setup bio
  3499. wolfSSL_BIO_set_fd(bio, fd, BIO_NOCLOSE);
  3500. \endcode
  3501. \sa wolfSSL_BIO_new
  3502. \sa wolfSSL_BIO_free
  3503. */
  3504. long wolfSSL_BIO_set_fd(WOLFSSL_BIO* b, int fd, int flag);
  3505. /*!
  3506. \ingroup IO
  3507. \brief Sets the close flag, used to indicate that the i/o stream should be
  3508. closed when the BIO is freed
  3509. \return SSL_SUCCESS(1) upon success.
  3510. \param bio WOLFSSL_BIO structure.
  3511. \param flag flag for behavior when closing i/o stream.
  3512. _Example_
  3513. \code
  3514. WOLFSSL_BIO* bio;
  3515. // setup bio
  3516. wolfSSL_BIO_set_close(bio, BIO_NOCLOSE);
  3517. \endcode
  3518. \sa wolfSSL_BIO_new
  3519. \sa wolfSSL_BIO_free
  3520. */
  3521. int wolfSSL_BIO_set_close(WOLFSSL_BIO *b, long flag);
  3522. /*!
  3523. \ingroup IO
  3524. \brief This is used to get a BIO_SOCKET type WOLFSSL_BIO_METHOD.
  3525. \return WOLFSSL_BIO_METHOD pointer to a WOLFSSL_BIO_METHOD structure
  3526. that is a socket type
  3527. \param none No parameters.
  3528. _Example_
  3529. \code
  3530. WOLFSSL_BIO* bio;
  3531. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket);
  3532. \endcode
  3533. \sa wolfSSL_BIO_new
  3534. \sa wolfSSL_BIO_s_mem
  3535. */
  3536. WOLFSSL_BIO_METHOD *wolfSSL_BIO_s_socket(void);
  3537. /*!
  3538. \ingroup IO
  3539. \brief This is used to set the size of write buffer for a
  3540. WOLFSSL_BIO. If write buffer has been previously set this
  3541. function will free it when resetting the size. It is similar to
  3542. wolfSSL_BIO_reset in that it resets read and write indexes to 0.
  3543. \return SSL_SUCCESS On successfully setting the write buffer.
  3544. \return SSL_FAILURE If an error case was encountered.
  3545. \param bio WOLFSSL_BIO structure to set fd.
  3546. \param size size of buffer to allocate.
  3547. _Example_
  3548. \code
  3549. WOLFSSL_BIO* bio;
  3550. int ret;
  3551. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3552. ret = wolfSSL_BIO_set_write_buf_size(bio, 15000);
  3553. // check return value
  3554. \endcode
  3555. \sa wolfSSL_BIO_new
  3556. \sa wolfSSL_BIO_s_mem
  3557. \sa wolfSSL_BIO_free
  3558. */
  3559. int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *b, long size);
  3560. /*!
  3561. \ingroup IO
  3562. \brief This is used to pair two bios together. A pair of bios acts
  3563. similar to a two way pipe writing to one can be read by the other
  3564. and vice versa. It is expected that both bios be in the same thread,
  3565. this function is not thread safe. Freeing one of the two bios removes
  3566. both from being paired. If a write buffer size was not previously
  3567. set for either of the bios it is set to a default size of 17000
  3568. (WOLFSSL_BIO_SIZE) before being paired.
  3569. \return SSL_SUCCESS On successfully pairing the two bios.
  3570. \return SSL_FAILURE If an error case was encountered.
  3571. \param b1 WOLFSSL_BIO structure to set pair.
  3572. \param b2 second WOLFSSL_BIO structure to complete pair.
  3573. _Example_
  3574. \code
  3575. WOLFSSL_BIO* bio;
  3576. WOLFSSL_BIO* bio2;
  3577. int ret;
  3578. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3579. bio2 = wolfSSL_BIO_new(wolfSSL_BIO_s_bio());
  3580. ret = wolfSSL_BIO_make_bio_pair(bio, bio2);
  3581. // check ret value
  3582. \endcode
  3583. \sa wolfSSL_BIO_new
  3584. \sa wolfSSL_BIO_s_mem
  3585. \sa wolfSSL_BIO_free
  3586. */
  3587. int wolfSSL_BIO_make_bio_pair(WOLFSSL_BIO *b1, WOLFSSL_BIO *b2);
  3588. /*!
  3589. \ingroup IO
  3590. \brief This is used to set the read request flag back to 0.
  3591. \return SSL_SUCCESS On successfully setting value.
  3592. \return SSL_FAILURE If an error case was encountered.
  3593. \param bio WOLFSSL_BIO structure to set read request flag.
  3594. _Example_
  3595. \code
  3596. WOLFSSL_BIO* bio;
  3597. int ret;
  3598. ...
  3599. ret = wolfSSL_BIO_ctrl_reset_read_request(bio);
  3600. // check ret value
  3601. \endcode
  3602. \sa wolfSSL_BIO_new, wolfSSL_BIO_s_mem
  3603. \sa wolfSSL_BIO_new, wolfSSL_BIO_free
  3604. */
  3605. int wolfSSL_BIO_ctrl_reset_read_request(WOLFSSL_BIO *b);
  3606. /*!
  3607. \ingroup IO
  3608. \brief This is used to get a buffer pointer for reading from. Unlike
  3609. wolfSSL_BIO_nread the internal read index is not advanced by the number
  3610. returned from the function call. Reading past the value returned can
  3611. result in reading out of array bounds.
  3612. \return >=0 on success return the number of bytes to read
  3613. \param bio WOLFSSL_BIO structure to read from.
  3614. \param buf pointer to set at beginning of read array.
  3615. _Example_
  3616. \code
  3617. WOLFSSL_BIO* bio;
  3618. char* bufPt;
  3619. int ret;
  3620. // set up bio
  3621. ret = wolfSSL_BIO_nread0(bio, &bufPt); // read as many bytes as possible
  3622. // handle negative ret check
  3623. // read ret bytes from bufPt
  3624. \endcode
  3625. \sa wolfSSL_BIO_new
  3626. \sa wolfSSL_BIO_nwrite0
  3627. */
  3628. int wolfSSL_BIO_nread0(WOLFSSL_BIO *bio, char **buf);
  3629. /*!
  3630. \ingroup IO
  3631. \brief This is used to get a buffer pointer for reading from. The internal
  3632. read index is advanced by the number returned from the function call with
  3633. buf being pointed to the beginning of the buffer to read from. In the
  3634. case that less bytes are in the read buffer than the value requested with
  3635. num the lesser value is returned. Reading past the value returned can
  3636. result in reading out of array bounds.
  3637. \return >=0 on success return the number of bytes to read
  3638. \return WOLFSSL_BIO_ERROR(-1) on error case with nothing to read return -1
  3639. \param bio WOLFSSL_BIO structure to read from.
  3640. \param buf pointer to set at beginning of read array.
  3641. \param num number of bytes to try and read.
  3642. _Example_
  3643. \code
  3644. WOLFSSL_BIO* bio;
  3645. char* bufPt;
  3646. int ret;
  3647. // set up bio
  3648. ret = wolfSSL_BIO_nread(bio, &bufPt, 10); // try to read 10 bytes
  3649. // handle negative ret check
  3650. // read ret bytes from bufPt
  3651. \endcode
  3652. \sa wolfSSL_BIO_new
  3653. \sa wolfSSL_BIO_nwrite
  3654. */
  3655. int wolfSSL_BIO_nread(WOLFSSL_BIO *bio, char **buf, int num);
  3656. /*!
  3657. \ingroup IO
  3658. \brief Gets a pointer to the buffer for writing as many bytes as returned by
  3659. the function. Writing more bytes to the pointer returned then the value
  3660. returned can result in writing out of bounds.
  3661. \return int Returns the number of bytes that can be written to the buffer
  3662. pointer returned.
  3663. \return WOLFSSL_BIO_UNSET(-2) in the case that is not part of a bio pair
  3664. \return WOLFSSL_BIO_ERROR(-1) in the case that there is no more room to
  3665. write to
  3666. \param bio WOLFSSL_BIO structure to write to.
  3667. \param buf pointer to buffer to write to.
  3668. \param num number of bytes desired to be written.
  3669. _Example_
  3670. \code
  3671. WOLFSSL_BIO* bio;
  3672. char* bufPt;
  3673. int ret;
  3674. // set up bio
  3675. ret = wolfSSL_BIO_nwrite(bio, &bufPt, 10); // try to write 10 bytes
  3676. // handle negative ret check
  3677. // write ret bytes to bufPt
  3678. \endcode
  3679. \sa wolfSSL_BIO_new
  3680. \sa wolfSSL_BIO_free
  3681. \sa wolfSSL_BIO_nread
  3682. */
  3683. int wolfSSL_BIO_nwrite(WOLFSSL_BIO *bio, char **buf, int num);
  3684. /*!
  3685. \ingroup IO
  3686. \brief Resets bio to an initial state. As an example for type BIO_BIO
  3687. this resets the read and write index.
  3688. \return 0 On successfully resetting the bio.
  3689. \return WOLFSSL_BIO_ERROR(-1) Returned on bad input or unsuccessful reset.
  3690. \param bio WOLFSSL_BIO structure to reset.
  3691. _Example_
  3692. \code
  3693. WOLFSSL_BIO* bio;
  3694. // setup bio
  3695. wolfSSL_BIO_reset(bio);
  3696. //use pt
  3697. \endcode
  3698. \sa wolfSSL_BIO_new
  3699. \sa wolfSSL_BIO_free
  3700. */
  3701. int wolfSSL_BIO_reset(WOLFSSL_BIO *bio);
  3702. /*!
  3703. \ingroup IO
  3704. \brief This function adjusts the file pointer to the offset given. This
  3705. is the offset from the head of the file.
  3706. \return 0 On successfully seeking.
  3707. \return -1 If an error case was encountered.
  3708. \param bio WOLFSSL_BIO structure to set.
  3709. \param ofs offset into file.
  3710. _Example_
  3711. \code
  3712. WOLFSSL_BIO* bio;
  3713. XFILE fp;
  3714. int ret;
  3715. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3716. ret = wolfSSL_BIO_set_fp(bio, &fp);
  3717. // check ret value
  3718. ret = wolfSSL_BIO_seek(bio, 3);
  3719. // check ret value
  3720. \endcode
  3721. \sa wolfSSL_BIO_new
  3722. \sa wolfSSL_BIO_s_mem
  3723. \sa wolfSSL_BIO_set_fp
  3724. \sa wolfSSL_BIO_free
  3725. */
  3726. int wolfSSL_BIO_seek(WOLFSSL_BIO *bio, int ofs);
  3727. /*!
  3728. \ingroup IO
  3729. \brief This is used to set and write to a file. WIll overwrite any data
  3730. currently in the file and is set to close the file when the bio is freed.
  3731. \return SSL_SUCCESS On successfully opening and setting file.
  3732. \return SSL_FAILURE If an error case was encountered.
  3733. \param bio WOLFSSL_BIO structure to set file.
  3734. \param name name of file to write to.
  3735. _Example_
  3736. \code
  3737. WOLFSSL_BIO* bio;
  3738. int ret;
  3739. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  3740. ret = wolfSSL_BIO_write_filename(bio, “test.txt”);
  3741. // check ret value
  3742. \endcode
  3743. \sa wolfSSL_BIO_new
  3744. \sa wolfSSL_BIO_s_file
  3745. \sa wolfSSL_BIO_set_fp
  3746. \sa wolfSSL_BIO_free
  3747. */
  3748. int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name);
  3749. /*!
  3750. \ingroup IO
  3751. \brief This is used to set the end of file value. Common value is -1 so
  3752. as not to get confused with expected positive values.
  3753. \return 0 returned on completion
  3754. \param bio WOLFSSL_BIO structure to set end of file value.
  3755. \param v value to set in bio.
  3756. _Example_
  3757. \code
  3758. WOLFSSL_BIO* bio;
  3759. int ret;
  3760. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  3761. ret = wolfSSL_BIO_set_mem_eof_return(bio, -1);
  3762. // check ret value
  3763. \endcode
  3764. \sa wolfSSL_BIO_new
  3765. \sa wolfSSL_BIO_s_mem
  3766. \sa wolfSSL_BIO_set_fp
  3767. \sa wolfSSL_BIO_free
  3768. */
  3769. long wolfSSL_BIO_set_mem_eof_return(WOLFSSL_BIO *bio, int v);
  3770. /*!
  3771. \ingroup IO
  3772. \brief This is a getter function for WOLFSSL_BIO memory pointer.
  3773. \return SSL_SUCCESS On successfully getting the pointer SSL_SUCCESS is
  3774. returned (currently value of 1).
  3775. \return SSL_FAILURE Returned if NULL arguments are passed in (currently
  3776. value of 0).
  3777. \param bio pointer to the WOLFSSL_BIO structure for getting memory pointer.
  3778. \param ptr structure that is currently a char*. Is set to point to
  3779. bio’s memory.
  3780. _Example_
  3781. \code
  3782. WOLFSSL_BIO* bio;
  3783. WOLFSSL_BUF_MEM* pt;
  3784. // setup bio
  3785. wolfSSL_BIO_get_mem_ptr(bio, &pt);
  3786. //use pt
  3787. \endcode
  3788. \sa wolfSSL_BIO_new
  3789. \sa wolfSSL_BIO_s_mem
  3790. */
  3791. long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **m);
  3792. /*!
  3793. \ingroup CertsKeys
  3794. \brief This function copies the name of the x509 into a buffer.
  3795. \return A char pointer to the buffer with the WOLFSSL_X509_NAME structures
  3796. name member’s data is returned if the function executed normally.
  3797. \param name a pointer to a WOLFSSL_X509 structure.
  3798. \param in a buffer to hold the name copied from the
  3799. WOLFSSL_X509_NAME structure.
  3800. \param sz the maximum size of the buffer.
  3801. _Example_
  3802. \code
  3803. WOLFSSL_X509 x509;
  3804. char* name;
  3805. ...
  3806. name = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3807. if(name <= 0){
  3808. // There’s nothing in the buffer.
  3809. }
  3810. \endcode
  3811. \sa wolfSSL_X509_get_subject_name
  3812. \sa wolfSSL_X509_get_issuer_name
  3813. \sa wolfSSL_X509_get_isCA
  3814. \sa wolfSSL_get_peer_certificate
  3815. \sa wolfSSL_X509_version
  3816. */
  3817. char* wolfSSL_X509_NAME_oneline(WOLFSSL_X509_NAME* name, char* in, int sz);
  3818. /*!
  3819. \ingroup CertsKeys
  3820. \brief This function returns the name of the certificate issuer.
  3821. \return point a pointer to the WOLFSSL_X509 struct’s issuer member is
  3822. returned.
  3823. \return NULL if the cert passed in is NULL.
  3824. \param cert a pointer to a WOLFSSL_X509 structure.
  3825. _Example_
  3826. \code
  3827. WOLFSSL_X509* x509;
  3828. WOLFSSL_X509_NAME issuer;
  3829. ...
  3830. issuer = wolfSSL_X509_NAME_oneline(wolfSSL_X509_get_issuer_name(x509), 0, 0);
  3831. if(!issuer){
  3832. // NULL was returned
  3833. } else {
  3834. // issuer hods the name of the certificate issuer.
  3835. }
  3836. \endcode
  3837. \sa wolfSSL_X509_get_subject_name
  3838. \sa wolfSSL_X509_get_isCA
  3839. \sa wolfSSL_get_peer_certificate
  3840. \sa wolfSSL_X509_NAME_oneline
  3841. */
  3842. WOLFSSL_X509_NAME* wolfSSL_X509_get_issuer_name(WOLFSSL_X509*);
  3843. /*!
  3844. \ingroup CertsKeys
  3845. \brief This function returns the subject member of the WOLFSSL_X509
  3846. structure.
  3847. \return pointer a pointer to the WOLFSSL_X509_NAME structure. The pointer
  3848. may be NULL if the WOLFSSL_X509 struct is NULL or if the subject member of
  3849. the structure is NULL.
  3850. \param cert a pointer to a WOLFSSL_X509 structure.
  3851. _Example_
  3852. \code
  3853. WOLFSSL_X509* cert;
  3854. WOLFSSL_X509_NAME name;
  3855. name = wolfSSL_X509_get_subject_name(cert);
  3856. if(name == NULL){
  3857. // Deal with the NULL cacse
  3858. }
  3859. \endcode
  3860. \sa wolfSSL_X509_get_issuer_name
  3861. \sa wolfSSL_X509_get_isCA
  3862. \sa wolfSSL_get_peer_certificate
  3863. */
  3864. WOLFSSL_X509_NAME* wolfSSL_X509_get_subject_name(WOLFSSL_X509*);
  3865. /*!
  3866. \ingroup CertsKeys
  3867. \brief Checks the isCa member of the WOLFSSL_X509 structure and returns
  3868. the value.
  3869. \return isCA returns the value in the isCA member of the WOLFSSL_X509
  3870. structure is returned.
  3871. \return 0 returned if there is not a valid x509 structure passed in.
  3872. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3873. _Example_
  3874. \code
  3875. WOLFSSL* ssl;
  3876. ...
  3877. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  3878. WOLFSSL* ssl = wolfSSL_new(ctx);
  3879. ...
  3880. if(wolfSSL_X509_get_isCA(ssl)){
  3881. // This is the CA
  3882. }else {
  3883. // Failure case
  3884. }
  3885. \endcode
  3886. \sa wolfSSL_X509_get_issuer_name
  3887. \sa wolfSSL_X509_get_isCA
  3888. */
  3889. int wolfSSL_X509_get_isCA(WOLFSSL_X509*);
  3890. /*!
  3891. \ingroup CertsKeys
  3892. \brief This function gets the text related to the passed in NID value.
  3893. \return int returns the size of the text buffer.
  3894. \param name WOLFSSL_X509_NAME to search for text.
  3895. \param nid NID to search for.
  3896. \param buf buffer to hold text when found.
  3897. \param len length of buffer.
  3898. _Example_
  3899. \code
  3900. WOLFSSL_X509_NAME* name;
  3901. char buffer[100];
  3902. int bufferSz;
  3903. int ret;
  3904. // get WOLFSSL_X509_NAME
  3905. ret = wolfSSL_X509_NAME_get_text_by_NID(name, NID_commonName,
  3906. buffer, bufferSz);
  3907. //check ret value
  3908. \endcode
  3909. \sa none
  3910. */
  3911. int wolfSSL_X509_NAME_get_text_by_NID(WOLFSSL_X509_NAME* name, int nid,
  3912. char* buf, int len);
  3913. /*!
  3914. \ingroup CertsKeys
  3915. \brief This function returns the value stored in the sigOID
  3916. member of the WOLFSSL_X509 structure.
  3917. \return 0 returned if the WOLFSSL_X509 structure is NULL.
  3918. \return int an integer value is returned which was retrieved from
  3919. the x509 object.
  3920. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  3921. _Example_
  3922. \code
  3923. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  3924. DYNAMIC_TYPE_X509);
  3925. ...
  3926. int x509SigType = wolfSSL_X509_get_signature_type(x509);
  3927. if(x509SigType != EXPECTED){
  3928. // Deal with an unexpected value
  3929. }
  3930. \endcode
  3931. \sa wolfSSL_X509_get_signature
  3932. \sa wolfSSL_X509_version
  3933. \sa wolfSSL_X509_get_der
  3934. \sa wolfSSL_X509_get_serial_number
  3935. \sa wolfSSL_X509_notBefore
  3936. \sa wolfSSL_X509_notAfter
  3937. \sa wolfSSL_X509_free
  3938. */
  3939. int wolfSSL_X509_get_signature_type(WOLFSSL_X509*);
  3940. /*!
  3941. \brief This function frees a WOLFSSL_X509 structure.
  3942. \param x509 a pointer to the WOLFSSL_X509 struct.
  3943. _Example_
  3944. \code
  3945. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALOC(sizeof(WOLFSSL_X509), NULL,
  3946. DYNAMIC_TYPE_X509) ;
  3947. wolfSSL_X509_free(x509);
  3948. \endcode
  3949. \sa wolfSSL_X509_get_signature
  3950. \sa wolfSSL_X509_version
  3951. \sa wolfSSL_X509_get_der
  3952. \sa wolfSSL_X509_get_serial_number
  3953. \sa wolfSSL_X509_notBefore
  3954. \sa wolfSSL_X509_notAfter
  3955. */
  3956. void wolfSSL_X509_free(WOLFSSL_X509* x509);
  3957. /*!
  3958. \ingroup CertsKeys
  3959. \brief Gets the X509 signature and stores it in the buffer.
  3960. \return SSL_SUCCESS returned if the function successfully executes.
  3961. The signature is loaded into the buffer.
  3962. \return SSL_FATAL_ERRROR returns if the x509 struct or the bufSz member
  3963. is NULL. There is also a check for the length member of the sig structure
  3964. (sig is a member of x509).
  3965. \param x509 pointer to a WOLFSSL_X509 structure.
  3966. \param buf a char pointer to the buffer.
  3967. \param bufSz an integer pointer to the size of the buffer.
  3968. _Example_
  3969. \code
  3970. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  3971. DYNAMIC_TYPE_X509);
  3972. unsigned char* buf; // Initialize
  3973. int* bufSz = sizeof(buf)/sizeof(unsigned char);
  3974. ...
  3975. if(wolfSSL_X509_get_signature(x509, buf, bufSz) != SSL_SUCCESS){
  3976. // The function did not execute successfully.
  3977. } else{
  3978. // The buffer was written to correctly.
  3979. }
  3980. \endcode
  3981. \sa wolfSSL_X509_get_serial_number
  3982. \sa wolfSSL_X509_get_signature_type
  3983. \sa wolfSSL_X509_get_device_type
  3984. */
  3985. int wolfSSL_X509_get_signature(WOLFSSL_X509* x509, unsigned char* buf, int* bufSz);
  3986. /*!
  3987. \ingroup CertsKeys
  3988. \brief This function adds a certificate to the WOLFSSL_X509_STRE structure.
  3989. \return SSL_SUCCESS If certificate is added successfully.
  3990. \return SSL_FATAL_ERROR: If certificate is not added successfully.
  3991. \param str certificate store to add the certificate to.
  3992. \param x509 certificate to add.
  3993. _Example_
  3994. \code
  3995. WOLFSSL_X509_STORE* str;
  3996. WOLFSSL_X509* x509;
  3997. int ret;
  3998. ret = wolfSSL_X509_STORE_add_cert(str, x509);
  3999. //check ret value
  4000. \endcode
  4001. \sa wolfSSL_X509_free
  4002. */
  4003. int wolfSSL_X509_STORE_add_cert(WOLFSSL_X509_STORE* store, WOLFSSL_X509* x509);
  4004. /*!
  4005. \ingroup CertsKeys
  4006. \brief This function is a getter function for chain variable
  4007. in WOLFSSL_X509_STORE_CTX structure. Currently chain is not populated.
  4008. \return pointer if successful returns WOLFSSL_STACK
  4009. (same as STACK_OF(WOLFSSL_X509)) pointer
  4010. \return Null upon failure
  4011. \param ctx certificate store ctx to get parse chain from.
  4012. _Example_
  4013. \code
  4014. WOLFSSL_STACK* sk;
  4015. WOLFSSL_X509_STORE_CTX* ctx;
  4016. sk = wolfSSL_X509_STORE_CTX_get_chain(ctx);
  4017. //check sk for NULL and then use it. sk needs freed after done.
  4018. \endcode
  4019. \sa wolfSSL_sk_X509_free
  4020. */
  4021. WOLFSSL_STACK* wolfSSL_X509_STORE_CTX_get_chain(
  4022. WOLFSSL_X509_STORE_CTX* ctx);
  4023. /*!
  4024. \ingroup CertsKeys
  4025. \brief This function takes in a flag to change the behavior of the
  4026. WOLFSSL_X509_STORE structure passed in. An example of a flag used
  4027. is WOLFSSL_CRL_CHECK.
  4028. \return SSL_SUCCESS If no errors were encountered when setting the flag.
  4029. \return <0 a negative value will be returned upon failure.
  4030. \param str certificate store to set flag in.
  4031. \param flag flag for behavior.
  4032. _Example_
  4033. \code
  4034. WOLFSSL_X509_STORE* str;
  4035. int ret;
  4036. // create and set up str
  4037. ret = wolfSSL_X509_STORE_set_flags(str, WOLFSSL_CRL_CHECKALL);
  4038. If (ret != SSL_SUCCESS) {
  4039. //check ret value and handle error case
  4040. }
  4041. \endcode
  4042. \sa wolfSSL_X509_STORE_new
  4043. \sa wolfSSL_X509_STORE_free
  4044. */
  4045. int wolfSSL_X509_STORE_set_flags(WOLFSSL_X509_STORE* store,
  4046. unsigned long flag);
  4047. /*!
  4048. \ingroup CertsKeys
  4049. \brief This function the certificate "not before" validity encoded as
  4050. a byte array.
  4051. \return NULL returned if the WOLFSSL_X509 structure is NULL.
  4052. \return byte is returned that contains the notBeforeData.
  4053. \param x509 pointer to a WOLFSSL_X509 structure.
  4054. _Example_
  4055. \code
  4056. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4057. DYNAMIC_TYPE_X509);
  4058. ...
  4059. byte* notBeforeData = wolfSSL_X509_notBefore(x509);
  4060. \endcode
  4061. \sa wolfSSL_X509_get_signature
  4062. \sa wolfSSL_X509_version
  4063. \sa wolfSSL_X509_get_der
  4064. \sa wolfSSL_X509_get_serial_number
  4065. \sa wolfSSL_X509_notAfter
  4066. \sa wolfSSL_X509_free
  4067. */
  4068. const byte* wolfSSL_X509_notBefore(WOLFSSL_X509* x509);
  4069. /*!
  4070. \ingroup CertsKeys
  4071. \brief This function the certificate "not after" validity encoded as
  4072. a byte array.
  4073. \return NULL returned if the WOLFSSL_X509 structure is NULL.
  4074. \return byte is returned that contains the notAfterData.
  4075. \param x509 pointer to a WOLFSSL_X509 structure.
  4076. _Example_
  4077. \code
  4078. WOLFSSL_X509* x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  4079. DYNAMIC_TYPE_X509);
  4080. ...
  4081. byte* notAfterData = wolfSSL_X509_notAfter(x509);
  4082. \endcode
  4083. \sa wolfSSL_X509_get_signature
  4084. \sa wolfSSL_X509_version
  4085. \sa wolfSSL_X509_get_der
  4086. \sa wolfSSL_X509_get_serial_number
  4087. \sa wolfSSL_X509_notBefore
  4088. \sa wolfSSL_X509_free
  4089. */
  4090. const byte* wolfSSL_X509_notAfter(WOLFSSL_X509* x509);
  4091. /*!
  4092. \ingroup Setup
  4093. \brief This function is used to copy a WOLFSSL_ASN1_INTEGER
  4094. value to a WOLFSSL_BIGNUM structure.
  4095. \return pointer On successfully copying the WOLFSSL_ASN1_INTEGER
  4096. value a WOLFSSL_BIGNUM pointer is returned.
  4097. \return Null upon failure.
  4098. \param ai WOLFSSL_ASN1_INTEGER structure to copy from.
  4099. \param bn if wanting to copy into an already existing
  4100. WOLFSSL_BIGNUM struct then pass in a pointer to it.
  4101. Optionally this can be NULL and a new WOLFSSL_BIGNUM
  4102. structure will be created.
  4103. _Example_
  4104. \code
  4105. WOLFSSL_ASN1_INTEGER* ai;
  4106. WOLFSSL_BIGNUM* bn;
  4107. // create ai
  4108. bn = wolfSSL_ASN1_INTEGER_to_BN(ai, NULL);
  4109. // or if having already created bn and wanting to reuse structure
  4110. // wolfSSL_ASN1_INTEGER_to_BN(ai, bn);
  4111. // check bn is or return value is not NULL
  4112. \endcode
  4113. \sa none
  4114. */
  4115. WOLFSSL_BIGNUM *wolfSSL_ASN1_INTEGER_to_BN(const WOLFSSL_ASN1_INTEGER *ai,
  4116. WOLFSSL_BIGNUM *bn);
  4117. /*!
  4118. \ingroup Setup
  4119. \brief This function adds the certificate to the internal chain
  4120. being built in the WOLFSSL_CTX structure.
  4121. \return SSL_SUCCESS after successfully adding the certificate.
  4122. \return SSL_FAILURE if failing to add the certificate to the chain.
  4123. \param ctx WOLFSSL_CTX structure to add certificate to.
  4124. \param x509 certificate to add to the chain.
  4125. _Example_
  4126. \code
  4127. WOLFSSL_CTX* ctx;
  4128. WOLFSSL_X509* x509;
  4129. int ret;
  4130. // create ctx
  4131. ret = wolfSSL_CTX_add_extra_chain_cert(ctx, x509);
  4132. // check ret value
  4133. \endcode
  4134. \sa wolfSSL_CTX_new
  4135. \sa wolfSSL_CTX_free
  4136. */
  4137. long wolfSSL_CTX_add_extra_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509);
  4138. /*!
  4139. \ingroup Setup
  4140. \brief This function returns the get read ahead flag from a
  4141. WOLFSSL_CTX structure.
  4142. \return flag On success returns the read ahead flag.
  4143. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  4144. \param ctx WOLFSSL_CTX structure to get read ahead flag from.
  4145. _Example_
  4146. \code
  4147. WOLFSSL_CTX* ctx;
  4148. int flag;
  4149. // setup ctx
  4150. flag = wolfSSL_CTX_get_read_ahead(ctx);
  4151. //check flag
  4152. \endcode
  4153. \sa wolfSSL_CTX_new
  4154. \sa wolfSSL_CTX_free
  4155. \sa wolfSSL_CTX_set_read_ahead
  4156. */
  4157. int wolfSSL_CTX_get_read_ahead(WOLFSSL_CTX*);
  4158. /*!
  4159. \ingroup Setup
  4160. \brief This function sets the read ahead flag in the WOLFSSL_CTX structure.
  4161. \return SSL_SUCCESS If ctx read ahead flag set.
  4162. \return SSL_FAILURE If ctx is NULL then SSL_FAILURE is returned.
  4163. \param ctx WOLFSSL_CTX structure to set read ahead flag.
  4164. _Example_
  4165. \code
  4166. WOLFSSL_CTX* ctx;
  4167. int flag;
  4168. int ret;
  4169. // setup ctx
  4170. ret = wolfSSL_CTX_set_read_ahead(ctx, flag);
  4171. // check return value
  4172. \endcode
  4173. \sa wolfSSL_CTX_new
  4174. \sa wolfSSL_CTX_free
  4175. \sa wolfSSL_CTX_get_read_ahead
  4176. */
  4177. int wolfSSL_CTX_set_read_ahead(WOLFSSL_CTX* ctx, int v);
  4178. /*!
  4179. \ingroup Setup
  4180. \brief This function sets the options argument to use with OCSP.
  4181. \return SSL_FAILURE If ctx or it’s cert manager is NULL.
  4182. \return SSL_SUCCESS If successfully set.
  4183. \param ctx WOLFSSL_CTX structure to set user argument.
  4184. \param arg user argument.
  4185. _Example_
  4186. \code
  4187. WOLFSSL_CTX* ctx;
  4188. void* data;
  4189. int ret;
  4190. // setup ctx
  4191. ret = wolfSSL_CTX_set_tlsext_status_arg(ctx, data);
  4192. //check ret value
  4193. \endcode
  4194. \sa wolfSSL_CTX_new
  4195. \sa wolfSSL_CTX_free
  4196. */
  4197. long wolfSSL_CTX_set_tlsext_status_arg(WOLFSSL_CTX* ctx, void* arg);
  4198. /*!
  4199. \ingroup Setup
  4200. \brief This function sets the optional argument to be passed to
  4201. the PRF callback.
  4202. \return SSL_FAILURE If ctx is NULL.
  4203. \return SSL_SUCCESS If successfully set.
  4204. \param ctx WOLFSSL_CTX structure to set user argument.
  4205. \param arg user argument.
  4206. _Example_
  4207. \code
  4208. WOLFSSL_CTX* ctx;
  4209. void* data;
  4210. int ret;
  4211. // setup ctx
  4212. ret = wolfSSL_CTX_set_tlsext_opaques_prf_input_callback_arg(ctx, data);
  4213. //check ret value
  4214. \endcode
  4215. \sa wolfSSL_CTX_new
  4216. \sa wolfSSL_CTX_free
  4217. */
  4218. long wolfSSL_CTX_set_tlsext_opaque_prf_input_callback_arg(
  4219. WOLFSSL_CTX* ctx, void* arg);
  4220. /*!
  4221. \ingroup Setup
  4222. \brief This function sets the options mask in the ssl.
  4223. Some valid options are, SSL_OP_ALL, SSL_OP_COOKIE_EXCHANGE,
  4224. SSL_OP_NO_SSLv2, SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1,
  4225. SSL_OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_2, SSL_OP_NO_COMPRESSION.
  4226. \return val Returns the updated options mask value stored in ssl.
  4227. \param s WOLFSSL structure to set options mask.
  4228. \param op This function sets the options mask in the ssl.
  4229. Some valid options are:
  4230. SSL_OP_ALL
  4231. SSL_OP_COOKIE_EXCHANGE
  4232. SSL_OP_NO_SSLv2
  4233. SSL_OP_NO_SSLv3
  4234. SSL_OP_NO_TLSv1
  4235. SSL_OP_NO_TLSv1_1
  4236. SSL_OP_NO_TLSv1_2
  4237. SSL_OP_NO_COMPRESSION
  4238. _Example_
  4239. \code
  4240. WOLFSSL* ssl;
  4241. unsigned long mask;
  4242. mask = SSL_OP_NO_TLSv1
  4243. mask = wolfSSL_set_options(ssl, mask);
  4244. // check mask
  4245. \endcode
  4246. \sa wolfSSL_new
  4247. \sa wolfSSL_free
  4248. \sa wolfSSL_get_options
  4249. */
  4250. long wolfSSL_set_options(WOLFSSL *s, long op);
  4251. /*!
  4252. \ingroup Setup
  4253. \brief This function returns the current options mask.
  4254. \return val Returns the mask value stored in ssl.
  4255. \param ssl WOLFSSL structure to get options mask from.
  4256. _Example_
  4257. \code
  4258. WOLFSSL* ssl;
  4259. unsigned long mask;
  4260. mask = wolfSSL_get_options(ssl);
  4261. // check mask
  4262. \endcode
  4263. \sa wolfSSL_new
  4264. \sa wolfSSL_free
  4265. \sa wolfSSL_set_options
  4266. */
  4267. long wolfSSL_get_options(const WOLFSSL *s);
  4268. /*!
  4269. \ingroup Setup
  4270. \brief This is used to set the debug argument passed around.
  4271. \return SSL_SUCCESS On successful setting argument.
  4272. \return SSL_FAILURE If an NULL ssl passed in.
  4273. \param ssl WOLFSSL structure to set argument in.
  4274. \param arg argument to use.
  4275. _Example_
  4276. \code
  4277. WOLFSSL* ssl;
  4278. void* args;
  4279. int ret;
  4280. // create ssl object
  4281. ret = wolfSSL_set_tlsext_debug_arg(ssl, args);
  4282. // check ret value
  4283. \endcode
  4284. \sa wolfSSL_new
  4285. \sa wolfSSL_free
  4286. */
  4287. long wolfSSL_set_tlsext_debug_arg(WOLFSSL *s, void *arg);
  4288. /*!
  4289. \ingroup openSSL
  4290. \brief This function is called when the client application request
  4291. that a server send back an OCSP status response (also known as
  4292. OCSP stapling).Currently, the only supported type is
  4293. TLSEXT_STATUSTYPE_ocsp.
  4294. \return 1 upon success.
  4295. \return 0 upon error.
  4296. \param s pointer to WolfSSL struct which is created by SSL_new() function
  4297. \param type ssl extension type which TLSEXT_STATUSTYPE_ocsp is
  4298. only supported.
  4299. _Example_
  4300. \code
  4301. WOLFSSL *ssl;
  4302. WOLFSSL_CTX *ctx;
  4303. int ret;
  4304. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4305. ssl = wolfSSL_new(ctx);
  4306. ret = WolfSSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp);
  4307. wolfSSL_free(ssl);
  4308. wolfSSL_CTX_free(ctx);
  4309. \endcode
  4310. \sa wolfSSL_new
  4311. \sa wolfSSL_CTX_new
  4312. \sa wolfSSL_free
  4313. \sa wolfSSL_CTX_free
  4314. */
  4315. long wolfSSL_set_tlsext_status_type(WOLFSSL *s, int type);
  4316. /*!
  4317. \ingroup Setup
  4318. \brief This is used to get the results after trying to verify the peer's
  4319. certificate.
  4320. \return X509_V_OK On successful verification.
  4321. \return SSL_FAILURE If an NULL ssl passed in.
  4322. \param ssl WOLFSSL structure to get verification results from.
  4323. _Example_
  4324. \code
  4325. WOLFSSL* ssl;
  4326. long ret;
  4327. // attempt/complete handshake
  4328. ret = wolfSSL_get_verify_result(ssl);
  4329. // check ret value
  4330. \endcode
  4331. \sa wolfSSL_new
  4332. \sa wolfSSL_free
  4333. */
  4334. long wolfSSL_get_verify_result(const WOLFSSL *ssl);
  4335. /*!
  4336. \ingroup Debug
  4337. \brief This function converts an error code returned by
  4338. wolfSSL_get_error() into a more human-readable error string
  4339. and prints that string to the output file - fp. err is the
  4340. error code returned by wolfSSL_get_error() and fp is the
  4341. file which the error string will be placed in.
  4342. \return none No returns.
  4343. \param fp output file for human-readable error string to be written to.
  4344. \param err error code returned by wolfSSL_get_error().
  4345. _Example_
  4346. \code
  4347. int err = 0;
  4348. WOLFSSL* ssl;
  4349. FILE* fp = ...
  4350. ...
  4351. err = wolfSSL_get_error(ssl, 0);
  4352. wolfSSL_ERR_print_errors_fp(fp, err);
  4353. \endcode
  4354. \sa wolfSSL_get_error
  4355. \sa wolfSSL_ERR_error_string
  4356. \sa wolfSSL_ERR_error_string_n
  4357. \sa wolfSSL_load_error_strings
  4358. */
  4359. void wolfSSL_ERR_print_errors_fp(XFILE fp, int err);
  4360. /*!
  4361. \ingroup Debug
  4362. \brief This function uses the provided callback to handle error reporting.
  4363. The callback function is executed for each error line. The string, length,
  4364. and userdata are passed into the callback parameters.
  4365. \return none No returns.
  4366. \param cb the callback function.
  4367. \param u userdata to pass into the callback function.
  4368. _Example_
  4369. \code
  4370. int error_cb(const char *str, size_t len, void *u)
  4371. { fprintf((FILE*)u, "%-*.*s\n", (int)len, (int)len, str); return 0; }
  4372. ...
  4373. FILE* fp = ...
  4374. wolfSSL_ERR_print_errors_cb(error_cb, fp);
  4375. \endcode
  4376. \sa wolfSSL_get_error
  4377. \sa wolfSSL_ERR_error_string
  4378. \sa wolfSSL_ERR_error_string_n
  4379. \sa wolfSSL_load_error_strings
  4380. */
  4381. void wolfSSL_ERR_print_errors_cb (
  4382. int (*cb)(const char *str, size_t len, void *u), void *u);
  4383. /*!
  4384. \brief The function sets the client_psk_cb member of the
  4385. WOLFSSL_CTX structure.
  4386. \return none No returns.
  4387. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4388. wolfSSL_CTX_new().
  4389. \param cb wc_psk_client_callback is a function pointer that will be
  4390. stored in the WOLFSSL_CTX structure. Return value is the key length on
  4391. success or zero on error.
  4392. unsigned int (*wc_psk_client_callback)
  4393. PSK client callback parameters:
  4394. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4395. const char* hint - A stored string that could be displayed to provide a
  4396. hint to the user.
  4397. char* identity - The ID will be stored here.
  4398. unsigned int id_max_len - Size of the ID buffer.
  4399. unsigned char* key - The key will be stored here.
  4400. unsigned int key_max_len - The max size of the key.
  4401. _Example_
  4402. \code
  4403. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol def );
  4404. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4405. char* identity, unsigned int id_max_len, unsigned char* key,
  4406. Unsigned int key_max_len){
  4407. wolfSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
  4408. \endcode
  4409. \sa wolfSSL_set_psk_client_callback
  4410. \sa wolfSSL_set_psk_server_callback
  4411. \sa wolfSSL_CTX_set_psk_server_callback
  4412. \sa wolfSSL_CTX_set_psk_client_callback
  4413. */
  4414. void wolfSSL_CTX_set_psk_client_callback(WOLFSSL_CTX* ctx,
  4415. wc_psk_client_callback);
  4416. /*!
  4417. \brief Sets the PSK client side callback.
  4418. \return none No returns.
  4419. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4420. \param cb a function pointer to type wc_psk_client_callback. Return value
  4421. is the key length on success or zero on error.
  4422. unsigned int (*wc_psk_client_callback)
  4423. PSK client callback parameters:
  4424. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4425. const char* hint - A stored string that could be displayed to provide a
  4426. hint to the user.
  4427. char* identity - The ID will be stored here.
  4428. unsigned int id_max_len - Size of the ID buffer.
  4429. unsigned char* key - The key will be stored here.
  4430. unsigned int key_max_len - The max size of the key.
  4431. _Example_
  4432. \code
  4433. WOLFSSL* ssl;
  4434. static WC_INLINE unsigned int my_psk_client_cb(WOLFSSL* ssl, const char* hint,
  4435. char* identity, unsigned int id_max_len, unsigned char* key,
  4436. Unsigned int key_max_len){
  4437. if(ssl){
  4438. wolfSSL_set_psk_client_callback(ssl, my_psk_client_cb);
  4439. } else {
  4440. // could not set callback
  4441. }
  4442. \endcode
  4443. \sa wolfSSL_CTX_set_psk_client_callback
  4444. \sa wolfSSL_CTX_set_psk_server_callback
  4445. \sa wolfSSL_set_psk_server_callback
  4446. */
  4447. void wolfSSL_set_psk_client_callback(WOLFSSL* ssl,
  4448. wc_psk_client_callback);
  4449. /*!
  4450. \ingroup CertsKeys
  4451. \brief This function returns the psk identity hint.
  4452. \return pointer a const char pointer to the value that was stored in
  4453. the arrays member of the WOLFSSL structure is returned.
  4454. \return NULL returned if the WOLFSSL or Arrays structures are NULL.
  4455. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4456. _Example_
  4457. \code
  4458. WOLFSSL* ssl = wolfSSL_new(ctx);
  4459. char* idHint;
  4460. ...
  4461. idHint = wolfSSL_get_psk_identity_hint(ssl);
  4462. if(idHint){
  4463. // The hint was retrieved
  4464. return idHint;
  4465. } else {
  4466. // Hint wasn’t successfully retrieved
  4467. }
  4468. \endcode
  4469. \sa wolfSSL_get_psk_identity
  4470. */
  4471. const char* wolfSSL_get_psk_identity_hint(const WOLFSSL*);
  4472. /*!
  4473. \ingroup CertsKeys
  4474. \brief The function returns a constant pointer to the client_identity
  4475. member of the Arrays structure.
  4476. \return string the string value of the client_identity member of the
  4477. Arrays structure.
  4478. \return NULL if the WOLFSSL structure is NULL or if the Arrays member of
  4479. the WOLFSSL structure is NULL.
  4480. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4481. _Example_
  4482. \code
  4483. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4484. WOLFSSL* ssl = wolfSSL_new(ctx);
  4485. const char* pskID;
  4486. ...
  4487. pskID = wolfSSL_get_psk_identity(ssl);
  4488. if(pskID == NULL){
  4489. // There is not a value in pskID
  4490. }
  4491. \endcode
  4492. \sa wolfSSL_get_psk_identity_hint
  4493. \sa wolfSSL_use_psk_identity_hint
  4494. */
  4495. const char* wolfSSL_get_psk_identity(const WOLFSSL*);
  4496. /*!
  4497. \ingroup CertsKeys
  4498. \brief This function stores the hint argument in the server_hint
  4499. member of the WOLFSSL_CTX structure.
  4500. \return SSL_SUCCESS returned for successful execution of the function.
  4501. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4502. wolfSSL_CTX_new().
  4503. \param hint a constant char pointer that will be copied to the
  4504. WOLFSSL_CTX structure.
  4505. _Example_
  4506. \code
  4507. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4508. const char* hint;
  4509. int ret;
  4510. ret = wolfSSL_CTX_use_psk_identity_hint(ctx, hint);
  4511. if(ret == SSL_SUCCESS){
  4512. // Function was successful.
  4513. return ret;
  4514. } else {
  4515. // Failure case.
  4516. }
  4517. \endcode
  4518. \sa wolfSSL_use_psk_identity_hint
  4519. */
  4520. int wolfSSL_CTX_use_psk_identity_hint(WOLFSSL_CTX* ctx, const char* hint);
  4521. /*!
  4522. \ingroup CertsKeys
  4523. \brief This function stores the hint argument in the server_hint member
  4524. of the Arrays structure within the WOLFSSL structure.
  4525. \return SSL_SUCCESS returned if the hint was successfully stored in the
  4526. WOLFSSL structure.
  4527. \return SSL_FAILURE returned if the WOLFSSL or Arrays structures are NULL.
  4528. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4529. \param hint a constant character pointer that holds the hint to be saved
  4530. in memory.
  4531. _Example_
  4532. \code
  4533. WOLFSSL* ssl = wolfSSL_new(ctx);
  4534. const char* hint;
  4535. ...
  4536. if(wolfSSL_use_psk_identity_hint(ssl, hint) != SSL_SUCCESS){
  4537. // Handle failure case.
  4538. }
  4539. \endcode
  4540. \sa wolfSSL_CTX_use_psk_identity_hint
  4541. */
  4542. int wolfSSL_use_psk_identity_hint(WOLFSSL* ssl, const char* hint);
  4543. /*!
  4544. \brief This function sets the psk callback for the server side in
  4545. the WOLFSSL_CTX structure.
  4546. \return none No returns.
  4547. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4548. \param cb a function pointer for the callback and will be stored in
  4549. the WOLFSSL_CTX structure. Return value is the key length on success or
  4550. zero on error.
  4551. unsigned int (*wc_psk_server_callback)
  4552. PSK server callback parameters
  4553. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4554. char* identity - The ID will be stored here.
  4555. unsigned char* key - The key will be stored here.
  4556. unsigned int key_max_len - The max size of the key.
  4557. _Example_
  4558. \code
  4559. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4560. WOLFSSL* ssl = wolfSSL_new(ctx);
  4561. static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
  4562. unsigned char* key, unsigned int key_max_len)
  4563. {
  4564. // Function body.
  4565. }
  4566. if(ctx != NULL){
  4567. wolfSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
  4568. } else {
  4569. // The CTX object was not properly initialized.
  4570. }
  4571. \endcode
  4572. \sa wc_psk_server_callback
  4573. \sa wolfSSL_set_psk_client_callback
  4574. \sa wolfSSL_set_psk_server_callback
  4575. \sa wolfSSL_CTX_set_psk_client_callback
  4576. */
  4577. void wolfSSL_CTX_set_psk_server_callback(WOLFSSL_CTX* ctx,
  4578. wc_psk_server_callback cb);
  4579. /*!
  4580. \brief Sets the psk callback for the server side by setting the
  4581. WOLFSSL structure options members.
  4582. \return none No returns.
  4583. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4584. \param cb a function pointer for the callback and will be stored in
  4585. the WOLFSSL structure. Return value is the key length on success or zero
  4586. on error.
  4587. unsigned int (*wc_psk_server_callback)
  4588. PSK server callback parameters
  4589. WOLFSSL* ssl - Pointer to the wolfSSL structure
  4590. char* identity - The ID will be stored here.
  4591. unsigned char* key - The key will be stored here.
  4592. unsigned int key_max_len - The max size of the key.
  4593. _Example_
  4594. \code
  4595. WOLFSSL_CTX* ctx;
  4596. WOLFSSL* ssl;
  4597. static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
  4598. unsigned char* key, unsigned int key_max_len)
  4599. {
  4600. // Function body.
  4601. }
  4602. if(ssl != NULL && cb != NULL){
  4603. wolfSSL_set_psk_server_callback(ssl, my_psk_server_cb);
  4604. }
  4605. \endcode
  4606. \sa wolfSSL_set_psk_client_callback
  4607. \sa wolfSSL_CTX_set_psk_server_callback
  4608. \sa wolfSSL_CTX_set_psk_client_callback
  4609. \sa wolfSSL_get_psk_identity_hint
  4610. \sa wc_psk_server_callback
  4611. \sa InitSuites
  4612. */
  4613. void wolfSSL_set_psk_server_callback(WOLFSSL* ssl,
  4614. wc_psk_server_callback cb);
  4615. /*!
  4616. \brief Sets a PSK user context in the WOLFSSL structure options member.
  4617. \return WOLFSSL_SUCCESS or WOLFSSL_FAILURE
  4618. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4619. \param psk_ctx void pointer to user PSK context
  4620. \sa wolfSSL_get_psk_callback_ctx
  4621. \sa wolfSSL_CTX_set_psk_callback_ctx
  4622. \sa wolfSSL_CTX_get_psk_callback_ctx
  4623. */
  4624. int wolfSSL_set_psk_callback_ctx(WOLFSSL* ssl, void* psk_ctx);
  4625. /*!
  4626. \brief Sets a PSK user context in the WOLFSSL_CTX structure.
  4627. \return WOLFSSL_SUCCESS or WOLFSSL_FAILURE
  4628. \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
  4629. \param psk_ctx void pointer to user PSK context
  4630. \sa wolfSSL_set_psk_callback_ctx
  4631. \sa wolfSSL_get_psk_callback_ctx
  4632. \sa wolfSSL_CTX_get_psk_callback_ctx
  4633. */
  4634. int wolfSSL_CTX_set_psk_callback_ctx(WOLFSSL_CTX* ctx, void* psk_ctx);
  4635. /*!
  4636. \brief Get a PSK user context in the WOLFSSL structure options member.
  4637. \return void pointer to user PSK context
  4638. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4639. \sa wolfSSL_set_psk_callback_ctx
  4640. \sa wolfSSL_CTX_set_psk_callback_ctx
  4641. \sa wolfSSL_CTX_get_psk_callback_ctx
  4642. */
  4643. void* wolfSSL_get_psk_callback_ctx(WOLFSSL* ssl);
  4644. /*!
  4645. \brief Get a PSK user context in the WOLFSSL_CTX structure.
  4646. \return void pointer to user PSK context
  4647. \param ctx a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
  4648. \sa wolfSSL_CTX_set_psk_callback_ctx
  4649. \sa wolfSSL_set_psk_callback_ctx
  4650. \sa wolfSSL_get_psk_callback_ctx
  4651. */
  4652. void* wolfSSL_CTX_get_psk_callback_ctx(WOLFSSL_CTX* ctx);
  4653. /*!
  4654. \ingroup Setup
  4655. \brief This function enables the havAnon member of the CTX structure if
  4656. HAVE_ANON is defined during compilation.
  4657. \return SSL_SUCCESS returned if the function executed successfully and the
  4658. haveAnnon member of the CTX is set to 1.
  4659. \return SSL_FAILURE returned if the CTX structure was NULL.
  4660. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  4661. wolfSSL_CTX_new().
  4662. _Example_
  4663. \code
  4664. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  4665. WOLFSSL* ssl = wolfSSL_new(ctx);
  4666. ...
  4667. #ifdef HAVE_ANON
  4668. if(cipherList == NULL){
  4669. wolfSSL_CTX_allow_anon_cipher(ctx);
  4670. if(wolfSSL_CTX_set_cipher_list(ctx, “ADH_AES128_SHA”) != SSL_SUCCESS){
  4671. // failure case
  4672. }
  4673. }
  4674. #endif
  4675. \endcode
  4676. \sa none
  4677. */
  4678. int wolfSSL_CTX_allow_anon_cipher(WOLFSSL_CTX*);
  4679. /*!
  4680. \ingroup Setup
  4681. \brief The wolfSSLv23_server_method() function is used to indicate
  4682. that the application is a server and will support clients connecting
  4683. with protocol version from SSL 3.0 - TLS 1.3. This function allocates
  4684. memory for and initializes a new WOLFSSL_METHOD structure to be used when
  4685. creating the SSL/TLS context with wolfSSL_CTX_new().
  4686. \return pointer If successful, the call will return a pointer to the newly
  4687. created WOLFSSL_METHOD structure.
  4688. \return Failure If memory allocation fails when calling XMALLOC, the
  4689. failure value of the underlying malloc() implementation will be returned
  4690. (typically NULL with errno will be set to ENOMEM).
  4691. \param none No parameters
  4692. _Example_
  4693. \code
  4694. WOLFSSL_METHOD* method;
  4695. WOLFSSL_CTX* ctx;
  4696. method = wolfSSLv23_server_method();
  4697. if (method == NULL) {
  4698. // unable to get method
  4699. }
  4700. ctx = wolfSSL_CTX_new(method);
  4701. ...
  4702. \endcode
  4703. \sa wolfSSLv3_server_method
  4704. \sa wolfTLSv1_server_method
  4705. \sa wolfTLSv1_1_server_method
  4706. \sa wolfTLSv1_2_server_method
  4707. \sa wolfTLSv1_3_server_method
  4708. \sa wolfDTLSv1_server_method
  4709. \sa wolfSSL_CTX_new
  4710. */
  4711. WOLFSSL_METHOD *wolfSSLv23_server_method(void);
  4712. /*!
  4713. \ingroup Setup
  4714. \brief This is used to get the internal error state of the WOLFSSL structure.
  4715. \return wolfssl_error returns ssl error state, usually a negative
  4716. \return BAD_FUNC_ARG if ssl is NULL.
  4717. \return ssl WOLFSSL structure to get state from.
  4718. _Example_
  4719. \code
  4720. WOLFSSL* ssl;
  4721. int ret;
  4722. // create ssl object
  4723. ret = wolfSSL_state(ssl);
  4724. // check ret value
  4725. \endcode
  4726. \sa wolfSSL_new
  4727. \sa wolfSSL_free
  4728. */
  4729. int wolfSSL_state(WOLFSSL* ssl);
  4730. /*!
  4731. \ingroup CertsKeys
  4732. \brief This function gets the peer’s certificate.
  4733. \return pointer a pointer to the peerCert member of the WOLFSSL_X509
  4734. structure if it exists.
  4735. \return 0 returned if the peer certificate issuer size is not defined.
  4736. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4737. _Example_
  4738. \code
  4739. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  4740. WOLFSSL* ssl = wolfSSL_new(ctx);
  4741. ...
  4742. WOLFSSL_X509* peerCert = wolfSSL_get_peer_certificate(ssl);
  4743. if(peerCert){
  4744. // You have a pointer peerCert to the peer certification
  4745. }
  4746. \endcode
  4747. \sa wolfSSL_X509_get_issuer_name
  4748. \sa wolfSSL_X509_get_subject_name
  4749. \sa wolfSSL_X509_get_isCA
  4750. */
  4751. WOLFSSL_X509* wolfSSL_get_peer_certificate(WOLFSSL* ssl);
  4752. /*!
  4753. \ingroup Debug
  4754. \brief This function is similar to calling wolfSSL_get_error() and
  4755. getting SSL_ERROR_WANT_READ in return. If the underlying error state
  4756. is SSL_ERROR_WANT_READ, this function will return 1, otherwise, 0.
  4757. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_READ, the
  4758. underlying I/O has data available for reading.
  4759. \return 0 There is no SSL_ERROR_WANT_READ error state.
  4760. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4761. _Example_
  4762. \code
  4763. int ret;
  4764. WOLFSSL* ssl = 0;
  4765. ...
  4766. ret = wolfSSL_want_read(ssl);
  4767. if (ret == 1) {
  4768. // underlying I/O has data available for reading (SSL_ERROR_WANT_READ)
  4769. }
  4770. \endcode
  4771. \sa wolfSSL_want_write
  4772. \sa wolfSSL_get_error
  4773. */
  4774. int wolfSSL_want_read(WOLFSSL*);
  4775. /*!
  4776. \ingroup Debug
  4777. \brief This function is similar to calling wolfSSL_get_error() and getting
  4778. SSL_ERROR_WANT_WRITE in return. If the underlying error state is
  4779. SSL_ERROR_WANT_WRITE, this function will return 1, otherwise, 0.
  4780. \return 1 wolfSSL_get_error() would return SSL_ERROR_WANT_WRITE, the
  4781. underlying I/O needs data to be written in order for progress to be
  4782. made in the underlying SSL connection.
  4783. \return 0 There is no SSL_ERROR_WANT_WRITE error state.
  4784. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4785. _Example_
  4786. \code
  4787. int ret;
  4788. WOLFSSL* ssl = 0;
  4789. ...
  4790. ret = wolfSSL_want_write(ssl);
  4791. if (ret == 1) {
  4792. // underlying I/O needs data to be written (SSL_ERROR_WANT_WRITE)
  4793. }
  4794. \endcode
  4795. \sa wolfSSL_want_read
  4796. \sa wolfSSL_get_error
  4797. */
  4798. int wolfSSL_want_write(WOLFSSL*);
  4799. /*!
  4800. \ingroup Setup
  4801. \brief wolfSSL by default checks the peer certificate for a valid date
  4802. range and a verified signature. Calling this function before
  4803. wolfSSL_connect() or wolfSSL_accept() will add a domain name check to
  4804. the list of checks to perform. dn holds the domain name to check
  4805. against the peer certificate when it’s received.
  4806. \return SSL_SUCCESS upon success.
  4807. \return SSL_FAILURE will be returned if a memory error was encountered.
  4808. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  4809. \param dn domain name to check against the peer certificate when received.
  4810. _Example_
  4811. \code
  4812. int ret = 0;
  4813. WOLFSSL* ssl;
  4814. char* domain = (char*) “www.yassl.com”;
  4815. ...
  4816. ret = wolfSSL_check_domain_name(ssl, domain);
  4817. if (ret != SSL_SUCCESS) {
  4818. // failed to enable domain name check
  4819. }
  4820. \endcode
  4821. \sa none
  4822. */
  4823. int wolfSSL_check_domain_name(WOLFSSL* ssl, const char* dn);
  4824. /*!
  4825. \ingroup TLS
  4826. \brief Initializes the wolfSSL library for use. Must be called once per
  4827. application and before any other call to the library.
  4828. \return SSL_SUCCESS If successful the call will return.
  4829. \return BAD_MUTEX_E is an error that may be returned.
  4830. \return WC_INIT_E wolfCrypt initialization error returned.
  4831. _Example_
  4832. \code
  4833. int ret = 0;
  4834. ret = wolfSSL_Init();
  4835. if (ret != SSL_SUCCESS) {
  4836. failed to initialize wolfSSL library
  4837. }
  4838. \endcode
  4839. \sa wolfSSL_Cleanup
  4840. */
  4841. int wolfSSL_Init(void);
  4842. /*!
  4843. \ingroup TLS
  4844. \brief Un-initializes the wolfSSL library from further use. Doesn’t have
  4845. to be called, though it will free any resources used by the library.
  4846. \return SSL_SUCCESS return no errors.
  4847. \return BAD_MUTEX_E a mutex error return.]
  4848. _Example_
  4849. \code
  4850. wolfSSL_Cleanup();
  4851. \endcode
  4852. \sa wolfSSL_Init
  4853. */
  4854. int wolfSSL_Cleanup(void);
  4855. /*!
  4856. \ingroup IO
  4857. \brief This function returns the current library version.
  4858. \return LIBWOLFSSL_VERSION_STRING a const char pointer defining the
  4859. version.
  4860. \param none No parameters.
  4861. _Example_
  4862. \code
  4863. char version[MAXSIZE];
  4864. version = wolfSSL_KeepArrays();
  4865. if(version != ExpectedVersion){
  4866. // Handle the mismatch case
  4867. }
  4868. \endcode
  4869. \sa word32_wolfSSL_lib_version_hex
  4870. */
  4871. const char* wolfSSL_lib_version(void);
  4872. /*!
  4873. \ingroup IO
  4874. \brief This function returns the current library version in hexadecimal
  4875. notation.
  4876. \return LILBWOLFSSL_VERSION_HEX returns the hexadecimal version defined in
  4877. wolfssl/version.h.
  4878. \param none No parameters.
  4879. _Example_
  4880. \code
  4881. word32 libV;
  4882. libV = wolfSSL_lib_version_hex();
  4883. if(libV != EXPECTED_HEX){
  4884. // How to handle an unexpected value
  4885. } else {
  4886. // The expected result for libV
  4887. }
  4888. \endcode
  4889. \sa wolfSSL_lib_version
  4890. */
  4891. word32 wolfSSL_lib_version_hex(void);
  4892. /*!
  4893. \ingroup IO
  4894. \brief Performs the actual connect or accept based on the side of the SSL
  4895. method. If called from the client side then an wolfSSL_connect() is done
  4896. while a wolfSSL_accept() is performed if called from the server side.
  4897. \return SSL_SUCCESS will be returned if successful. (Note, older versions
  4898. will return 0.)
  4899. \return SSL_FATAL_ERROR will be returned if the underlying call resulted
  4900. in an error. Use wolfSSL_get_error() to get a specific error code.
  4901. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4902. _Example_
  4903. \code
  4904. int ret = SSL_FATAL_ERROR;
  4905. WOLFSSL* ssl = 0;
  4906. ...
  4907. ret = wolfSSL_negotiate(ssl);
  4908. if (ret == SSL_FATAL_ERROR) {
  4909. // SSL establishment failed
  4910. int error_code = wolfSSL_get_error(ssl);
  4911. ...
  4912. }
  4913. ...
  4914. \endcode
  4915. \sa SSL_connect
  4916. \sa SSL_accept
  4917. */
  4918. int wolfSSL_negotiate(WOLFSSL* ssl);
  4919. /*!
  4920. \ingroup Setup
  4921. \brief Turns on the ability to use compression for the SSL connection.
  4922. Both sides must have compression turned on otherwise compression will not be
  4923. used. The zlib library performs the actual data compression. To compile
  4924. into the library use --with-libz for the configure system and define
  4925. HAVE_LIBZ otherwise. Keep in mind that while compressing data before
  4926. sending decreases the actual size of the messages being sent and received,
  4927. the amount of data saved by compression usually takes longer in time to
  4928. analyze than it does to send it raw on all but the slowest of networks.
  4929. \return SSL_SUCCESS upon success.
  4930. \return NOT_COMPILED_IN will be returned if compression support wasn’t
  4931. built into the library.
  4932. \param ssl pointer to the SSL session, created with wolfSSL_new().
  4933. _Example_
  4934. \code
  4935. int ret = 0;
  4936. WOLFSSL* ssl = 0;
  4937. ...
  4938. ret = wolfSSL_set_compression(ssl);
  4939. if (ret == SSL_SUCCESS) {
  4940. // successfully enabled compression for SSL session
  4941. }
  4942. \endcode
  4943. \sa none
  4944. */
  4945. int wolfSSL_set_compression(WOLFSSL* ssl);
  4946. /*!
  4947. \ingroup Setup
  4948. \brief This function sets the SSL session timeout value in seconds.
  4949. \return SSL_SUCCESS will be returned upon successfully setting the session.
  4950. \return BAD_FUNC_ARG will be returned if ssl is NULL.
  4951. \param ssl pointer to the SSL object, created with wolfSSL_new().
  4952. \param to value, in seconds, used to set the SSL session timeout.
  4953. _Example_
  4954. \code
  4955. int ret = 0;
  4956. WOLFSSL* ssl = 0;
  4957. ...
  4958. ret = wolfSSL_set_timeout(ssl, 500);
  4959. if (ret != SSL_SUCCESS) {
  4960. // failed to set session timeout value
  4961. }
  4962. ...
  4963. \endcode
  4964. \sa wolfSSL_get1_session
  4965. \sa wolfSSL_set_session
  4966. */
  4967. int wolfSSL_set_timeout(WOLFSSL* ssl, unsigned int to);
  4968. /*!
  4969. \ingroup Setup
  4970. \brief This function sets the timeout value for SSL sessions, in seconds,
  4971. for the specified SSL context.
  4972. \return the previous timeout value, if WOLFSSL_ERROR_CODE_OPENSSL is
  4973. \return defined on success. If not defined, SSL_SUCCESS will be returned.
  4974. \return BAD_FUNC_ARG will be returned when the input context (ctx) is null.
  4975. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  4976. \param to session timeout value in seconds.
  4977. _Example_
  4978. \code
  4979. WOLFSSL_CTX* ctx = 0;
  4980. ...
  4981. ret = wolfSSL_CTX_set_timeout(ctx, 500);
  4982. if (ret != SSL_SUCCESS) {
  4983. // failed to set session timeout value
  4984. }
  4985. \endcode
  4986. \sa wolfSSL_flush_sessions
  4987. \sa wolfSSL_get1_session
  4988. \sa wolfSSL_set_session
  4989. \sa wolfSSL_get_sessionID
  4990. \sa wolfSSL_CTX_set_session_cache_mode
  4991. */
  4992. int wolfSSL_CTX_set_timeout(WOLFSSL_CTX* ctx, unsigned int to);
  4993. /*!
  4994. \ingroup openSSL
  4995. \brief Retrieves the peer’s certificate chain.
  4996. \return chain If successful the call will return the peer’s
  4997. certificate chain.
  4998. \return 0 will be returned if an invalid WOLFSSL pointer is passed to the
  4999. function.
  5000. \param ssl pointer to a valid WOLFSSL structure.
  5001. _Example_
  5002. \code
  5003. none
  5004. \endcode
  5005. \sa wolfSSL_get_chain_count
  5006. \sa wolfSSL_get_chain_length
  5007. \sa wolfSSL_get_chain_cert
  5008. \sa wolfSSL_get_chain_cert_pem
  5009. */
  5010. WOLFSSL_X509_CHAIN* wolfSSL_get_peer_chain(WOLFSSL* ssl);
  5011. /*!
  5012. \ingroup openSSL
  5013. \brief Retrieve's the peers certificate chain count.
  5014. \return Success If successful the call will return the peer’s certificate
  5015. chain count.
  5016. \return 0 will be returned if an invalid chain pointer is passed to
  5017. the function.
  5018. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5019. _Example_
  5020. \code
  5021. none
  5022. \endcode
  5023. \sa wolfSSL_get_peer_chain
  5024. \sa wolfSSL_get_chain_length
  5025. \sa wolfSSL_get_chain_cert
  5026. \sa wolfSSL_get_chain_cert_pem
  5027. */
  5028. int wolfSSL_get_chain_count(WOLFSSL_X509_CHAIN* chain);
  5029. /*!
  5030. \ingroup openSSL
  5031. \brief Retrieves the peer’s ASN1.DER certificate length in bytes
  5032. at index (idx).
  5033. \return Success If successful the call will return the peer’s
  5034. certificate length in bytes by index.
  5035. \return 0 will be returned if an invalid chain pointer is passed
  5036. to the function.
  5037. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5038. \param idx index to start of chain.
  5039. _Example_
  5040. \code
  5041. none
  5042. \endcode
  5043. \sa wolfSSL_get_peer_chain
  5044. \sa wolfSSL_get_chain_count
  5045. \sa wolfSSL_get_chain_cert
  5046. \sa wolfSSL_get_chain_cert_pem
  5047. */
  5048. int wolfSSL_get_chain_length(WOLFSSL_X509_CHAIN* chain, int idx);
  5049. /*!
  5050. \ingroup openSSL
  5051. \brief Retrieves the peer’s ASN1.DER certificate at index (idx).
  5052. \return Success If successful the call will return the peer’s
  5053. certificate by index.
  5054. \return 0 will be returned if an invalid chain pointer is passed
  5055. to the function.
  5056. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5057. \param idx index to start of chain.
  5058. _Example_
  5059. \code
  5060. none
  5061. \endcode
  5062. \sa wolfSSL_get_peer_chain
  5063. \sa wolfSSL_get_chain_count
  5064. \sa wolfSSL_get_chain_length
  5065. \sa wolfSSL_get_chain_cert_pem
  5066. */
  5067. unsigned char* wolfSSL_get_chain_cert(WOLFSSL_X509_CHAIN* chain, int idx);
  5068. /*!
  5069. \ingroup CertsKeys
  5070. \brief This function gets the peer’s wolfSSL_X509_certificate at
  5071. index (idx) from the chain of certificates.
  5072. \return pointer returns a pointer to a WOLFSSL_X509 structure.
  5073. \param chain a pointer to the WOLFSSL_X509_CHAIN used for no dynamic
  5074. memory SESSION_CACHE.
  5075. \param idx the index of the WOLFSSL_X509 certificate.
  5076. _Example_
  5077. \code
  5078. WOLFSSL_X509_CHAIN* chain = &session->chain;
  5079. int idx = 999; // set idx
  5080. ...
  5081. WOLFSSL_X509_CHAIN ptr;
  5082. prt = wolfSSL_get_chain_X509(chain, idx);
  5083. if(ptr != NULL){
  5084. //ptr contains the cert at the index specified
  5085. } else {
  5086. // ptr is NULL
  5087. }
  5088. \endcode
  5089. \sa InitDecodedCert
  5090. \sa ParseCertRelative
  5091. \sa CopyDecodedToX509
  5092. */
  5093. WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx);
  5094. /*!
  5095. \ingroup openSSL
  5096. \brief Retrieves the peer’s PEM certificate at index (idx).
  5097. \return Success If successful the call will return the peer’s
  5098. certificate by index.
  5099. \return 0 will be returned if an invalid chain pointer is passed to
  5100. the function.
  5101. \param chain pointer to a valid WOLFSSL_X509_CHAIN structure.
  5102. \param idx indexto start of chain.
  5103. _Example_
  5104. \code
  5105. none
  5106. \endcode
  5107. \sa wolfSSL_get_peer_chain
  5108. \sa wolfSSL_get_chain_count
  5109. \sa wolfSSL_get_chain_length
  5110. \sa wolfSSL_get_chain_cert
  5111. */
  5112. int wolfSSL_get_chain_cert_pem(WOLFSSL_X509_CHAIN* chain, int idx,
  5113. unsigned char* buf, int inLen, int* outLen);
  5114. /*!
  5115. \ingroup openSSL
  5116. \brief Retrieves the session’s ID. The session ID is always 32 bytes long.
  5117. \return id The session ID.
  5118. \param session pointer to a valid wolfssl session.
  5119. _Example_
  5120. \code
  5121. none
  5122. \endcode
  5123. \sa SSL_get_session
  5124. */
  5125. const unsigned char* wolfSSL_get_sessionID(const WOLFSSL_SESSION* s);
  5126. /*!
  5127. \ingroup openSSL
  5128. \brief Retrieves the peer’s certificate serial number. The serial
  5129. number buffer (in) should be at least 32 bytes long and be provided
  5130. as the *inOutSz argument as input. After calling the function *inOutSz
  5131. will hold the actual length in bytes written to the in buffer.
  5132. \return SSL_SUCCESS upon success.
  5133. \return BAD_FUNC_ARG will be returned if a bad function argument
  5134. was encountered.
  5135. \param in The serial number buffer and should be at least 32 bytes long
  5136. \param inOutSz will hold the actual length in bytes written to the
  5137. in buffer.
  5138. _Example_
  5139. \code
  5140. none
  5141. \endcode
  5142. \sa SSL_get_peer_certificate
  5143. */
  5144. int wolfSSL_X509_get_serial_number(WOLFSSL_X509* x509, unsigned char* in,
  5145. int* inOutSz);
  5146. /*!
  5147. \ingroup CertsKeys
  5148. \brief Returns the common name of the subject from the certificate.
  5149. \return NULL returned if the x509 structure is null
  5150. \return string a string representation of the subject's common
  5151. name is returned upon success
  5152. \param x509 a pointer to a WOLFSSL_X509 structure containing
  5153. certificate information.
  5154. _Example_
  5155. \code
  5156. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5157. DYNAMIC_TYPE_X509);
  5158. ...
  5159. int x509Cn = wolfSSL_X509_get_subjectCN(x509);
  5160. if(x509Cn == NULL){
  5161. // Deal with NULL case
  5162. } else {
  5163. // x509Cn contains the common name
  5164. }
  5165. \endcode
  5166. \sa wolfSSL_X509_Name_get_entry
  5167. \sa wolfSSL_X509_get_next_altname
  5168. \sa wolfSSL_X509_get_issuer_name
  5169. \sa wolfSSL_X509_get_subject_name
  5170. */
  5171. char* wolfSSL_X509_get_subjectCN(WOLFSSL_X509*);
  5172. /*!
  5173. \ingroup CertsKeys
  5174. \brief This function gets the DER encoded certificate in the
  5175. WOLFSSL_X509 struct.
  5176. \return buffer This function returns the DerBuffer structure’s
  5177. buffer member, which is of type byte.
  5178. \return NULL returned if the x509 or outSz parameter is NULL.
  5179. \param x509 a pointer to a WOLFSSL_X509 structure containing
  5180. certificate information.
  5181. \param outSz length of the derBuffer member of the WOLFSSL_X509 struct.
  5182. _Example_
  5183. \code
  5184. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5185. DYNAMIC_TYPE_X509);
  5186. int* outSz; // initialize
  5187. ...
  5188. byte* x509Der = wolfSSL_X509_get_der(x509, outSz);
  5189. if(x509Der == NULL){
  5190. // Failure case one of the parameters was NULL
  5191. }
  5192. \endcode
  5193. \sa wolfSSL_X509_version
  5194. \sa wolfSSL_X509_Name_get_entry
  5195. \sa wolfSSL_X509_get_next_altname
  5196. \sa wolfSSL_X509_get_issuer_name
  5197. \sa wolfSSL_X509_get_subject_name
  5198. */
  5199. const unsigned char* wolfSSL_X509_get_der(WOLFSSL_X509* x509, int* outSz);
  5200. /*!
  5201. \ingroup CertsKeys
  5202. \brief This function checks to see if x509 is NULL and if it’s not,
  5203. it returns the notAfter member of the x509 struct.
  5204. \return pointer to struct with ASN1_TIME to the notAfter
  5205. member of the x509 struct.
  5206. \return NULL returned if the x509 object is NULL.
  5207. \param x509 a pointer to the WOLFSSL_X509 struct.
  5208. _Example_
  5209. \code
  5210. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  5211. DYNAMIC_TYPE_X509) ;
  5212. ...
  5213. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notAfter(x509);
  5214. if(notAfter == NULL){
  5215. // Failure case, the x509 object is null.
  5216. }
  5217. \endcode
  5218. \sa wolfSSL_X509_get_notBefore
  5219. */
  5220. WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notAfter(WOLFSSL_X509*);
  5221. /*!
  5222. \ingroup CertsKeys
  5223. \brief This function retrieves the version of the X509 certificate.
  5224. \return 0 returned if the x509 structure is NULL.
  5225. \return version the version stored in the x509 structure will be returned.
  5226. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5227. _Example_
  5228. \code
  5229. WOLFSSL_X509* x509;
  5230. int version;
  5231. ...
  5232. version = wolfSSL_X509_version(x509);
  5233. if(!version){
  5234. // The function returned 0, failure case.
  5235. }
  5236. \endcode
  5237. \sa wolfSSL_X509_get_subject_name
  5238. \sa wolfSSL_X509_get_issuer_name
  5239. \sa wolfSSL_X509_get_isCA
  5240. \sa wolfSSL_get_peer_certificate
  5241. */
  5242. int wolfSSL_X509_version(WOLFSSL_X509*);
  5243. /*!
  5244. \ingroup CertsKeys
  5245. \brief If NO_STDIO_FILESYSTEM is defined this function will allocate
  5246. heap memory, initialize a WOLFSSL_X509 structure and return a pointer to it.
  5247. \return *WOLFSSL_X509 WOLFSSL_X509 structure pointer is returned if
  5248. the function executes successfully.
  5249. \return NULL if the call to XFTELL macro returns a negative value.
  5250. \param x509 a pointer to a WOLFSSL_X509 pointer.
  5251. \param file a defined type that is a pointer to a FILE.
  5252. _Example_
  5253. \code
  5254. WOLFSSL_X509* x509a = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  5255. DYNAMIC_TYPE_X509);
  5256. WOLFSSL_X509** x509 = x509a;
  5257. XFILE file; (mapped to struct fs_file*)
  5258. ...
  5259. WOLFSSL_X509* newX509 = wolfSSL_X509_d2i_fp(x509, file);
  5260. if(newX509 == NULL){
  5261. // The function returned NULL
  5262. }
  5263. \endcode
  5264. \sa wolfSSL_X509_d2i
  5265. \sa XFTELL
  5266. \sa XREWIND
  5267. \sa XFSEEK
  5268. */
  5269. WOLFSSL_X509*
  5270. wolfSSL_X509_d2i_fp(WOLFSSL_X509** x509, FILE* file);
  5271. /*!
  5272. \ingroup CertsKeys
  5273. \brief The function loads the x509 certificate into memory.
  5274. \return pointer a successful execution returns pointer to a
  5275. WOLFSSL_X509 structure.
  5276. \return NULL returned if the certificate was not able to be written.
  5277. \param fname the certificate file to be loaded.
  5278. \param format the format of the certificate.
  5279. _Example_
  5280. \code
  5281. #define cliCert “certs/client-cert.pem”
  5282. X509* x509;
  5283. x509 = wolfSSL_X509_load_certificate_file(cliCert, SSL_FILETYPE_PEM);
  5284. AssertNotNull(x509);
  5285. \endcode
  5286. \sa InitDecodedCert
  5287. \sa PemToDer
  5288. \sa wolfSSL_get_certificate
  5289. \sa AssertNotNull
  5290. */
  5291. WOLFSSL_X509*
  5292. wolfSSL_X509_load_certificate_file(const char* fname, int format);
  5293. /*!
  5294. \ingroup CertsKeys
  5295. \brief This function copies the device type from the x509 structure
  5296. to the buffer.
  5297. \return pointer returns a byte pointer holding the device type from
  5298. the x509 structure.
  5299. \return NULL returned if the buffer size is NULL.
  5300. \param x509 pointer to a WOLFSSL_X509 structure, created with
  5301. WOLFSSL_X509_new().
  5302. \param in a pointer to a byte type that will hold the device type
  5303. (the buffer).
  5304. \param inOutSz the minimum of either the parameter inOutSz or the
  5305. deviceTypeSz member of the x509 structure.
  5306. _Example_
  5307. \code
  5308. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALOC(sizeof(WOLFSSL_X509), NULL,
  5309. DYNAMIC_TYPE_X509);
  5310. byte* in;
  5311. int* inOutSz;
  5312. ...
  5313. byte* deviceType = wolfSSL_X509_get_device_type(x509, in, inOutSz);
  5314. if(!deviceType){
  5315. // Failure case, NULL was returned.
  5316. }
  5317. \endcode
  5318. \sa wolfSSL_X509_get_hw_type
  5319. \sa wolfSSL_X509_get_hw_serial_number
  5320. \sa wolfSSL_X509_d2i
  5321. */
  5322. unsigned char*
  5323. wolfSSL_X509_get_device_type(WOLFSSL_X509* x509, unsigned char* in,
  5324. int* inOutSz);
  5325. /*!
  5326. \ingroup CertsKeys
  5327. \brief The function copies the hwType member of the WOLFSSL_X509
  5328. structure to the buffer.
  5329. \return byte The function returns a byte type of the data previously held
  5330. in the hwType member of the WOLFSSL_X509 structure.
  5331. \return NULL returned if inOutSz is NULL.
  5332. \param x509 a pointer to a WOLFSSL_X509 structure containing certificate
  5333. information.
  5334. \param in pointer to type byte that represents the buffer.
  5335. \param inOutSz pointer to type int that represents the size of the buffer.
  5336. _Example_
  5337. \code
  5338. WOLFSSL_X509* x509; // X509 certificate
  5339. byte* in; // initialize the buffer
  5340. int* inOutSz; // holds the size of the buffer
  5341. ...
  5342. byte* hwType = wolfSSL_X509_get_hw_type(x509, in, inOutSz);
  5343. if(hwType == NULL){
  5344. // Failure case function returned NULL.
  5345. }
  5346. \endcode
  5347. \sa wolfSSL_X509_get_hw_serial_number
  5348. \sa wolfSSL_X509_get_device_type
  5349. */
  5350. unsigned char*
  5351. wolfSSL_X509_get_hw_type(WOLFSSL_X509* x509, unsigned char* in,
  5352. int* inOutSz);
  5353. /*!
  5354. \ingroup CertsKeys
  5355. \brief This function returns the hwSerialNum member of the x509 object.
  5356. \return pointer the function returns a byte pointer to the in buffer that
  5357. will contain the serial number loaded from the x509 object.
  5358. \param x509 pointer to a WOLFSSL_X509 structure containing certificate
  5359. information.
  5360. \param in a pointer to the buffer that will be copied to.
  5361. \param inOutSz a pointer to the size of the buffer.
  5362. _Example_
  5363. \code
  5364. char* serial;
  5365. byte* in;
  5366. int* inOutSz;
  5367. WOLFSSL_X509 x509;
  5368. ...
  5369. serial = wolfSSL_X509_get_hw_serial_number(x509, in, inOutSz);
  5370. if(serial == NULL || serial <= 0){
  5371. // Failure case
  5372. }
  5373. \endcode
  5374. \sa wolfSSL_X509_get_subject_name
  5375. \sa wolfSSL_X509_get_issuer_name
  5376. \sa wolfSSL_X509_get_isCA
  5377. \sa wolfSSL_get_peer_certificate
  5378. \sa wolfSSL_X509_version
  5379. */
  5380. unsigned char*
  5381. wolfSSL_X509_get_hw_serial_number(WOLFSSL_X509* x509,
  5382. unsigned char* in, int* inOutSz);
  5383. /*!
  5384. \ingroup IO
  5385. \brief This function is called on the client side and initiates an
  5386. SSL/TLS handshake with a server only long enough to get the peer’s
  5387. certificate chain. When this function is called, the underlying
  5388. communication channel has already been set up. wolfSSL_connect_cert()
  5389. works with both blocking and non-blocking I/O. When the underlying I/O
  5390. is non-blocking, wolfSSL_connect_cert() will return when the underlying
  5391. I/O could not satisfy the needs of wolfSSL_connect_cert() to continue the
  5392. handshake. In this case, a call to wolfSSL_get_error() will yield either
  5393. SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process must then
  5394. repeat the call to wolfSSL_connect_cert() when the underlying I/O is ready
  5395. and wolfSSL will pick up where it left off. When using a non-blocking
  5396. socket, nothing needs to be done, but select() can be used to check for
  5397. the required condition. If the underlying I/O is blocking,
  5398. wolfSSL_connect_cert() will only return once the peer’s certificate chain
  5399. has been received.
  5400. \return SSL_SUCCESS upon success.
  5401. \return SSL_FAILURE will be returned if the SSL session parameter is NULL.
  5402. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a more
  5403. detailed error code, call wolfSSL_get_error().
  5404. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5405. _Example_
  5406. \code
  5407. int ret = 0;
  5408. int err = 0;
  5409. WOLFSSL* ssl;
  5410. char buffer[80];
  5411. ...
  5412. ret = wolfSSL_connect_cert(ssl);
  5413. if (ret != SSL_SUCCESS) {
  5414. err = wolfSSL_get_error(ssl, ret);
  5415. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  5416. }
  5417. \endcode
  5418. \sa wolfSSL_get_error
  5419. \sa wolfSSL_connect
  5420. \sa wolfSSL_accept
  5421. */
  5422. int wolfSSL_connect_cert(WOLFSSL* ssl);
  5423. /*!
  5424. \ingroup openSSL
  5425. \brief wolfSSL_d2i_PKCS12_bio (d2i_PKCS12_bio) copies in the PKCS12
  5426. information from WOLFSSL_BIO to the structure WC_PKCS12. The information
  5427. is divided up in the structure as a list of Content Infos along with a
  5428. structure to hold optional MAC information. After the information has been
  5429. divided into chunks (but not decrypted) in the structure WC_PKCS12, it can
  5430. then be parsed and decrypted by calling.
  5431. \return WC_PKCS12 pointer to a WC_PKCS12 structure.
  5432. \return Failure If function failed it will return NULL.
  5433. \param bio WOLFSSL_BIO structure to read PKCS12 buffer from.
  5434. \param pkcs12 WC_PKCS12 structure pointer for new PKCS12 structure created.
  5435. Can be NULL
  5436. _Example_
  5437. \code
  5438. WC_PKCS12* pkcs;
  5439. WOLFSSL_BIO* bio;
  5440. WOLFSSL_X509* cert;
  5441. WOLFSSL_EVP_PKEY* pkey;
  5442. STACK_OF(X509) certs;
  5443. //bio loads in PKCS12 file
  5444. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5445. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5446. wc_PKCS12_free(pkcs)
  5447. //use cert, pkey, and optionally certs stack
  5448. \endcode
  5449. \sa wolfSSL_PKCS12_parse
  5450. \sa wc_PKCS12_free
  5451. */
  5452. WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio,
  5453. WC_PKCS12** pkcs12);
  5454. /*!
  5455. \ingroup openSSL
  5456. \brief wolfSSL_i2d_PKCS12_bio (i2d_PKCS12_bio) copies in the cert
  5457. information from the structure WC_PKCS12 to WOLFSSL_BIO.
  5458. \return 1 for success.
  5459. \return Failure 0.
  5460. \param bio WOLFSSL_BIO structure to write PKCS12 buffer to.
  5461. \param pkcs12 WC_PKCS12 structure for PKCS12 structure as input.
  5462. _Example_
  5463. \code
  5464. WC_PKCS12 pkcs12;
  5465. FILE *f;
  5466. byte buffer[5300];
  5467. char file[] = "./test.p12";
  5468. int bytes;
  5469. WOLFSSL_BIO* bio;
  5470. pkcs12 = wc_PKCS12_new();
  5471. f = fopen(file, "rb");
  5472. bytes = (int)fread(buffer, 1, sizeof(buffer), f);
  5473. fclose(f);
  5474. //convert the DER file into an internal structure
  5475. wc_d2i_PKCS12(buffer, bytes, pkcs12);
  5476. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  5477. //convert PKCS12 structure into bio
  5478. wolfSSL_i2d_PKCS12_bio(bio, pkcs12);
  5479. wc_PKCS12_free(pkcs)
  5480. //use bio
  5481. \endcode
  5482. \sa wolfSSL_PKCS12_parse
  5483. \sa wc_PKCS12_free
  5484. */
  5485. WC_PKCS12* wolfSSL_i2d_PKCS12_bio(WOLFSSL_BIO* bio,
  5486. WC_PKCS12* pkcs12);
  5487. /*!
  5488. \ingroup openSSL
  5489. \brief PKCS12 can be enabled with adding –enable-opensslextra to the
  5490. configure command. It can use triple DES and RC4 for decryption so would
  5491. recommend also enabling these features when enabling opensslextra
  5492. (--enable-des3 –enable-arc4). wolfSSL does not currently support RC2 so
  5493. decryption with RC2 is currently not available. This may be noticeable
  5494. with default encryption schemes used by OpenSSL command line to create
  5495. .p12 files. wolfSSL_PKCS12_parse (PKCS12_parse). The first thing this
  5496. function does is check the MAC is correct if present. If the MAC fails
  5497. then the function returns and does not try to decrypt any of the stored
  5498. Content Infos. This function then parses through each Content Info
  5499. looking for a bag type, if the bag type is known it is decrypted as
  5500. needed and either stored in the list of certificates being built or as
  5501. a key found. After parsing through all bags the key found is then
  5502. compared with the certificate list until a matching pair is found.
  5503. This matching pair is then returned as the key and certificate,
  5504. optionally the certificate list found is returned as a STACK_OF
  5505. certificates. At the moment a CRL, Secret or SafeContents bag will be
  5506. skipped over and not parsed. It can be seen if these or other “Unknown”
  5507. bags are skipped over by viewing the debug print out. Additional attributes
  5508. such as friendly name are skipped over when parsing a PKCS12 file.
  5509. \return SSL_SUCCESS On successfully parsing PKCS12.
  5510. \return SSL_FAILURE If an error case was encountered.
  5511. \param pkcs12 WC_PKCS12 structure to parse.
  5512. \param paswd password for decrypting PKCS12.
  5513. \param pkey structure to hold private key decoded from PKCS12.
  5514. \param cert structure to hold certificate decoded from PKCS12.
  5515. \param stack optional stack of extra certificates.
  5516. _Example_
  5517. \code
  5518. WC_PKCS12* pkcs;
  5519. WOLFSSL_BIO* bio;
  5520. WOLFSSL_X509* cert;
  5521. WOLFSSL_EVP_PKEY* pkey;
  5522. STACK_OF(X509) certs;
  5523. //bio loads in PKCS12 file
  5524. wolfSSL_d2i_PKCS12_bio(bio, &pkcs);
  5525. wolfSSL_PKCS12_parse(pkcs, “a password”, &pkey, &cert, &certs)
  5526. wc_PKCS12_free(pkcs)
  5527. //use cert, pkey, and optionally certs stack
  5528. \endcode
  5529. \sa wolfSSL_d2i_PKCS12_bio
  5530. \sa wc_PKCS12_free
  5531. */
  5532. int wolfSSL_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
  5533. WOLFSSL_EVP_PKEY** pkey, WOLFSSL_X509** cert, WOLF_STACK_OF(WOLFSSL_X509)** ca);
  5534. /*!
  5535. \ingroup CertsKeys
  5536. \brief Server Diffie-Hellman Ephemeral parameters setting. This function
  5537. sets up the group parameters to be used if the server negotiates a cipher
  5538. suite that uses DHE.
  5539. \return SSL_SUCCESS upon success.
  5540. \return MEMORY_ERROR will be returned if a memory error was encountered.
  5541. \return SIDE_ERROR will be returned if this function is called on an SSL
  5542. client instead of an SSL server.
  5543. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5544. \param p Diffie-Hellman prime number parameter.
  5545. \param pSz size of p.
  5546. \param g Diffie-Hellman “generator” parameter.
  5547. \param gSz size of g.
  5548. _Example_
  5549. \code
  5550. WOLFSSL* ssl;
  5551. static unsigned char p[] = {...};
  5552. static unsigned char g[] = {...};
  5553. ...
  5554. wolfSSL_SetTmpDH(ssl, p, sizeof(p), g, sizeof(g));
  5555. \endcode
  5556. \sa SSL_accept
  5557. */
  5558. int wolfSSL_SetTmpDH(WOLFSSL* ssl, const unsigned char* p, int pSz,
  5559. const unsigned char* g, int gSz);
  5560. /*!
  5561. \ingroup CertsKeys
  5562. \brief The function calls the wolfSSL_SetTMpDH_buffer_wrapper,
  5563. which is a wrapper for Diffie-Hellman parameters.
  5564. \return SSL_SUCCESS on successful execution.
  5565. \return SSL_BAD_FILETYPE if the file type is not PEM and is not
  5566. ASN.1. It will also be returned if the wc_DhParamsLoad does not
  5567. return normally.
  5568. \return SSL_NO_PEM_HEADER returns from PemToDer if there is not
  5569. a PEM header.
  5570. \return SSL_BAD_FILE returned if there is a file error in PemToDer.
  5571. \return SSL_FATAL_ERROR returned from PemToDer if there was a copy error.
  5572. \return MEMORY_E - if there was a memory allocation error.
  5573. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if
  5574. there was otherwise a NULL argument passed to a subroutine.
  5575. \return DH_KEY_SIZE_E is returned if their is a key size error in
  5576. wolfSSL_SetTmpDH() or in wolfSSL_CTX_SetTmpDH().
  5577. \return SIDE_ERROR returned if it is not the server side
  5578. in wolfSSL_SetTmpDH.
  5579. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5580. \param buf allocated buffer passed in from wolfSSL_SetTMpDH_file_wrapper.
  5581. \param sz a long int that holds the size of the file
  5582. (fname within wolfSSL_SetTmpDH_file_wrapper).
  5583. \param format an integer type passed through from
  5584. wolfSSL_SetTmpDH_file_wrapper() that is a representation of the certificate
  5585. format.
  5586. _Example_
  5587. \code
  5588. Static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5589. Const char* fname, int format);
  5590. long sz = 0;
  5591. byte* myBuffer = staticBuffer[FILE_BUFFER_SIZE];
  5592. if(ssl)
  5593. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5594. \endcode
  5595. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5596. \sa wc_DhParamsLoad
  5597. \sa wolfSSL_SetTmpDH
  5598. \sa PemToDer
  5599. \sa wolfSSL_CTX_SetTmpDH
  5600. \sa wolfSSL_CTX_SetTmpDH_file
  5601. */
  5602. int wolfSSL_SetTmpDH_buffer(WOLFSSL* ssl, const unsigned char* b, long sz,
  5603. int format);
  5604. /*!
  5605. \ingroup CertsKeys
  5606. \brief This function calls wolfSSL_SetTmpDH_file_wrapper to set server
  5607. Diffie-Hellman parameters.
  5608. \return SSL_SUCCESS returned on successful completion of this function
  5609. and its subroutines.
  5610. \return MEMORY_E returned if a memory allocation failed in this function
  5611. or a subroutine.
  5612. \return SIDE_ERROR if the side member of the Options structure found
  5613. in the WOLFSSL struct is not the server side.
  5614. \return SSL_BAD_FILETYPE returns if the certificate fails a set of checks.
  5615. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5616. the value of the minDhKeySz member in the WOLFSSL struct.
  5617. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5618. than the value of the maxDhKeySz member in the WOLFSSL struct.
  5619. \return BAD_FUNC_ARG returns if an argument value is NULL that is not
  5620. permitted such as, the WOLFSSL structure.
  5621. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5622. \param fname a constant char pointer holding the certificate.
  5623. \param format an integer type that holds the format of the certification.
  5624. _Example_
  5625. \code
  5626. WOLFSSL* ssl = wolfSSL_new(ctx);
  5627. const char* dhParam;
  5628. AssertIntNE(SSL_SUCCESS,
  5629. wolfSSL_SetTmpDH_file(ssl, dhParam, SSL_FILETYPE_PEM));
  5630. \endcode
  5631. \sa wolfSSL_CTX_SetTmpDH_file
  5632. \sa wolfSSL_SetTmpDH_file_wrapper
  5633. \sa wolfSSL_SetTmpDH_buffer
  5634. \sa wolfSSL_CTX_SetTmpDH_buffer
  5635. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5636. \sa wolfSSL_SetTmpDH
  5637. \sa wolfSSL_CTX_SetTmpDH
  5638. */
  5639. int wolfSSL_SetTmpDH_file(WOLFSSL* ssl, const char* f, int format);
  5640. /*!
  5641. \ingroup CertsKeys
  5642. \brief Sets the parameters for the server CTX Diffie-Hellman.
  5643. \return SSL_SUCCESS returned if the function and all subroutines
  5644. return without error.
  5645. \return BAD_FUNC_ARG returned if the CTX, p or g parameters are NULL.
  5646. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5647. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5648. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5649. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5650. \return MEMORY_E returned if the allocation of memory failed in this
  5651. function or a subroutine.
  5652. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5653. wolfSSL_CTX_new().
  5654. \param p a constant unsigned char pointer loaded into the buffer
  5655. member of the serverDH_P struct.
  5656. \param pSz an int type representing the size of p, initialized
  5657. to MAX_DH_SIZE.
  5658. \param g a constant unsigned char pointer loaded into the buffer
  5659. member of the serverDH_G struct.
  5660. \param gSz an int type representing the size of g, initialized ot
  5661. MAX_DH_SIZE.
  5662. _Exmaple_
  5663. \code
  5664. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol );
  5665. byte* p;
  5666. byte* g;
  5667. word32 pSz = (word32)sizeof(p)/sizeof(byte);
  5668. word32 gSz = (word32)sizeof(g)/sizeof(byte);
  5669. int ret = wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz);
  5670. if(ret != SSL_SUCCESS){
  5671. // Failure case
  5672. }
  5673. \endcode
  5674. \sa wolfSSL_SetTmpDH
  5675. \sa wc_DhParamsLoad
  5676. */
  5677. int wolfSSL_CTX_SetTmpDH(WOLFSSL_CTX* ctx, const unsigned char* p,
  5678. int pSz, const unsigned char* g, int gSz);
  5679. /*!
  5680. \ingroup CertsKeys
  5681. \brief A wrapper function that calls wolfSSL_SetTmpDH_buffer_wrapper
  5682. \return 0 returned for a successful execution.
  5683. \return BAD_FUNC_ARG returned if the ctx or buf parameters are NULL.
  5684. \return MEMORY_E if there is a memory allocation error.
  5685. \return SSL_BAD_FILETYPE returned if format is not correct.
  5686. \param ctx a pointer to a WOLFSSL structure, created using
  5687. wolfSSL_CTX_new().
  5688. \param buf a pointer to a constant unsigned char type that is
  5689. allocated as the buffer and passed through to
  5690. wolfSSL_SetTmpDH_buffer_wrapper.
  5691. \param sz a long integer type that is derived from the fname parameter
  5692. in wolfSSL_SetTmpDH_file_wrapper().
  5693. \param format an integer type passed through from
  5694. wolfSSL_SetTmpDH_file_wrapper().
  5695. _Example_
  5696. \code
  5697. static int wolfSSL_SetTmpDH_file_wrapper(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
  5698. Const char* fname, int format);
  5699. #ifdef WOLFSSL_SMALL_STACK
  5700. byte staticBuffer[1]; // force heap usage
  5701. #else
  5702. byte* staticBuffer;
  5703. long sz = 0;
  5704. if(ssl){
  5705. ret = wolfSSL_SetTmpDH_buffer(ssl, myBuffer, sz, format);
  5706. } else {
  5707. ret = wolfSSL_CTX_SetTmpDH_buffer(ctx, myBuffer, sz, format);
  5708. }
  5709. \endcode
  5710. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5711. \sa wolfSSL_SetTMpDH_buffer
  5712. \sa wolfSSL_SetTmpDH_file_wrapper
  5713. \sa wolfSSL_CTX_SetTmpDH_file
  5714. */
  5715. int wolfSSL_CTX_SetTmpDH_buffer(WOLFSSL_CTX* ctx, const unsigned char* b,
  5716. long sz, int format);
  5717. /*!
  5718. \ingroup CertsKeys
  5719. \brief The function calls wolfSSL_SetTmpDH_file_wrapper to set the server
  5720. Diffie-Hellman parameters.
  5721. \return SSL_SUCCESS returned if the wolfSSL_SetTmpDH_file_wrapper or any
  5722. of its subroutines return successfully.
  5723. \return MEMORY_E returned if an allocation of dynamic memory fails in a
  5724. subroutine.
  5725. \return BAD_FUNC_ARG returned if the ctx or fname parameters are NULL or
  5726. if
  5727. a subroutine is passed a NULL argument.
  5728. \return SSL_BAD_FILE returned if the certificate file is unable to open or
  5729. if the a set of checks on the file fail from wolfSSL_SetTmpDH_file_wrapper.
  5730. \return SSL_BAD_FILETYPE returned if the format is not PEM or ASN.1 from
  5731. wolfSSL_SetTmpDH_buffer_wrapper().
  5732. \return DH_KEY_SIZE_E returned if the DH parameter's key size is less than
  5733. the value of the minDhKeySz member of the WOLFSSL_CTX struct.
  5734. \return DH_KEY_SIZE_E returned if the DH parameter's key size is greater
  5735. than the value of the maxDhKeySz member of the WOLFSSL_CTX struct.
  5736. \return SIDE_ERROR returned in wolfSSL_SetTmpDH() if the side is not the
  5737. server end.
  5738. \return SSL_NO_PEM_HEADER returned from PemToDer if there is no PEM header.
  5739. \return SSL_FATAL_ERROR returned from PemToDer if there is a memory copy
  5740. failure.
  5741. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5742. wolfSSL_CTX_new().
  5743. \param fname a constant character pointer to a certificate file.
  5744. \param format an integer type passed through from
  5745. wolfSSL_SetTmpDH_file_wrapper() that is a representation of
  5746. the certificate format.
  5747. _Example_
  5748. \code
  5749. #define dhParam “certs/dh2048.pem”
  5750. #DEFINE aSSERTiNTne(x, y) AssertInt(x, y, !=, ==)
  5751. WOLFSSL_CTX* ctx;
  5752. AssertNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  5753. AssertIntNE(SSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL, dhParam,
  5754. SSL_FILETYPE_PEM));
  5755. \endcode
  5756. \sa wolfSSL_SetTmpDH_buffer_wrapper
  5757. \sa wolfSSL_SetTmpDH
  5758. \sa wolfSSL_CTX_SetTmpDH
  5759. \sa wolfSSL_SetTmpDH_buffer
  5760. \sa wolfSSL_CTX_SetTmpDH_buffer
  5761. \sa wolfSSL_SetTmpDH_file_wrapper
  5762. \sa AllocDer
  5763. \sa PemToDer
  5764. */
  5765. int wolfSSL_CTX_SetTmpDH_file(WOLFSSL_CTX* ctx, const char* f,
  5766. int format);
  5767. /*!
  5768. \ingroup CertsKeys
  5769. \brief This function sets the minimum size (in bits) of the Diffie Hellman
  5770. key size by accessing the minDhKeySz member in the WOLFSSL_CTX structure.
  5771. \return SSL_SUCCESS returned if the function completes successfully.
  5772. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5773. the keySz_bits is greater than 16,000 or not divisible by 8.
  5774. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5775. \param keySz_bits a word16 type used to set the minimum DH key size in bits.
  5776. The WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5777. _Example_
  5778. \code
  5779. public static int CTX_SetMinDhKey_Sz(IntPtr ctx, short minDhKey){
  5780. return wolfSSL_CTX_SetMinDhKey_Sz(local_ctx, minDhKeyBits);
  5781. \endcode
  5782. \sa wolfSSL_SetMinDhKey_Sz
  5783. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5784. \sa wolfSSL_SetMaxDhKey_Sz
  5785. \sa wolfSSL_GetDhKey_Sz
  5786. \sa wolfSSL_CTX_SetTMpDH_file
  5787. */
  5788. int wolfSSL_CTX_SetMinDhKey_Sz(WOLFSSL_CTX* ctx, word16);
  5789. /*!
  5790. \ingroup CertsKeys
  5791. \brief Sets the minimum size (in bits) for a Diffie-Hellman key in the
  5792. WOLFSSL structure.
  5793. \return SSL_SUCCESS the minimum size was successfully set.
  5794. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or if the keySz_bits is
  5795. greater than 16,000 or not divisible by 8.
  5796. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5797. \param keySz_bits a word16 type used to set the minimum DH key size in bits.
  5798. The WOLFSSL_CTX struct holds this information in the minDhKeySz member.
  5799. _Example_
  5800. \code
  5801. WOLFSSL* ssl = wolfSSL_new(ctx);
  5802. word16 keySz_bits;
  5803. ...
  5804. if(wolfSSL_SetMinDhKey_Sz(ssl, keySz_bits) != SSL_SUCCESS){
  5805. // Failed to set.
  5806. }
  5807. \endcode
  5808. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5809. \sa wolfSSL_GetDhKey_Sz
  5810. */
  5811. int wolfSSL_SetMinDhKey_Sz(WOLFSSL* ssl, word16 keySz_bits);
  5812. /*!
  5813. \ingroup CertsKeys
  5814. \brief This function sets the maximum size (in bits) of the Diffie Hellman
  5815. key size by accessing the maxDhKeySz member in the WOLFSSL_CTX structure.
  5816. \return SSL_SUCCESS returned if the function completes successfully.
  5817. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5818. the keySz_bits is greater than 16,000 or not divisible by 8.
  5819. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5820. \param keySz_bits a word16 type used to set the maximum DH key size in bits.
  5821. The WOLFSSL_CTX struct holds this information in the maxDhKeySz member.
  5822. _Example_
  5823. \code
  5824. public static int CTX_SetMaxDhKey_Sz(IntPtr ctx, short maxDhKey){
  5825. return wolfSSL_CTX_SetMaxDhKey_Sz(local_ctx, keySz_bits);
  5826. \endcode
  5827. \sa wolfSSL_SetMinDhKey_Sz
  5828. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5829. \sa wolfSSL_SetMaxDhKey_Sz
  5830. \sa wolfSSL_GetDhKey_Sz
  5831. \sa wolfSSL_CTX_SetTMpDH_file
  5832. */
  5833. int wolfSSL_CTX_SetMaxDhKey_Sz(WOLFSSL_CTX* ctx, word16 keySz_bits);
  5834. /*!
  5835. \ingroup CertsKeys
  5836. \brief Sets the maximum size (in bits) for a Diffie-Hellman key in the
  5837. WOLFSSL structure.
  5838. \return SSL_SUCCESS the maximum size was successfully set.
  5839. \return BAD_FUNC_ARG the WOLFSSL structure was NULL or the keySz parameter
  5840. was greater than the allowable size or not divisible by 8.
  5841. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5842. \param keySz a word16 type representing the bit size of the maximum DH key.
  5843. _Example_
  5844. \code
  5845. WOLFSSL* ssl = wolfSSL_new(ctx);
  5846. word16 keySz;
  5847. ...
  5848. if(wolfSSL_SetMaxDhKey(ssl, keySz) != SSL_SUCCESS){
  5849. // Failed to set.
  5850. }
  5851. \endcode
  5852. \sa wolfSSL_CTX_SetMaxDhKey_Sz
  5853. \sa wolfSSL_GetDhKey_Sz
  5854. */
  5855. int wolfSSL_SetMaxDhKey_Sz(WOLFSSL* ssl, word16 keySz_bits);
  5856. /*!
  5857. \ingroup CertsKeys
  5858. \brief Returns the value of dhKeySz (in bits) that is a member of the
  5859. options structure. This value represents the Diffie-Hellman key size in
  5860. bytes.
  5861. \return dhKeySz returns the value held in ssl->options.dhKeySz which is an
  5862. integer value representing a size in bits.
  5863. \return BAD_FUNC_ARG returns if the WOLFSSL struct is NULL.
  5864. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5865. _Example_
  5866. \code
  5867. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5868. WOLFSSL* ssl = wolfSSL_new(ctx);
  5869. int dhKeySz;
  5870. ...
  5871. dhKeySz = wolfSSL_GetDhKey_Sz(ssl);
  5872. if(dhKeySz == BAD_FUNC_ARG || dhKeySz <= 0){
  5873. // Failure case
  5874. } else {
  5875. // dhKeySz holds the size of the key.
  5876. }
  5877. \endcode
  5878. \sa wolfSSL_SetMinDhKey_sz
  5879. \sa wolfSSL_CTX_SetMinDhKey_Sz
  5880. \sa wolfSSL_CTX_SetTmpDH
  5881. \sa wolfSSL_SetTmpDH
  5882. \sa wolfSSL_CTX_SetTmpDH_file
  5883. */
  5884. int wolfSSL_GetDhKey_Sz(WOLFSSL*);
  5885. /*!
  5886. \ingroup CertsKeys
  5887. \brief Sets the minimum RSA key size in both the WOLFSSL_CTX structure
  5888. and the WOLFSSL_CERT_MANAGER structure.
  5889. \return SSL_SUCCESS returned on successful execution of the function.
  5890. \return BAD_FUNC_ARG returned if the ctx structure is NULL or the keySz
  5891. is less than zero or not divisible by 8.
  5892. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5893. wolfSSL_CTX_new().
  5894. \param keySz a short integer type stored in minRsaKeySz in the ctx
  5895. structure and the cm structure converted to bytes.
  5896. _Example_
  5897. \code
  5898. WOLFSSL_CTX* ctx = SSL_CTX_new(method);
  5899. (void)minDhKeyBits;
  5900. ourCert = myoptarg;
  5901. minDhKeyBits = atoi(myoptarg);
  5902. if(wolfSSL_CTX_SetMinRsaKey_Sz(ctx, minRsaKeyBits) != SSL_SUCCESS){
  5903. \endcode
  5904. \sa wolfSSL_SetMinRsaKey_Sz
  5905. */
  5906. int wolfSSL_CTX_SetMinRsaKey_Sz(WOLFSSL_CTX* ctx, short keySz);
  5907. /*!
  5908. \ingroup CertsKeys
  5909. \brief Sets the minimum allowable key size in bits for RSA located in the
  5910. WOLFSSL structure.
  5911. \return SSL_SUCCESS the minimum was set successfully.
  5912. \return BAD_FUNC_ARG returned if the ssl structure is NULL or if the ksySz
  5913. is less than zero or not divisible by 8.
  5914. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5915. \param keySz a short integer value representing the the minimum key in bits.
  5916. _Example_
  5917. \code
  5918. WOLFSSL* ssl = wolfSSL_new(ctx);
  5919. short keySz;
  5920. int isSet = wolfSSL_SetMinRsaKey_Sz(ssl, keySz);
  5921. if(isSet != SSL_SUCCESS){
  5922. Failed to set.
  5923. }
  5924. \endcode
  5925. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5926. */
  5927. int wolfSSL_SetMinRsaKey_Sz(WOLFSSL* ssl, short keySz);
  5928. /*!
  5929. \ingroup CertsKeys
  5930. \brief Sets the minimum size in bits for the ECC key in the WOLF_CTX
  5931. structure and the WOLFSSL_CERT_MANAGER structure.
  5932. \return SSL_SUCCESS returned for a successful execution and the minEccKeySz
  5933. member is set.
  5934. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or if
  5935. the keySz is negative or not divisible by 8.
  5936. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  5937. wolfSSL_CTX_new().
  5938. \param keySz a short integer type that represents the minimum ECC key
  5939. size in bits.
  5940. _Example_
  5941. \code
  5942. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  5943. short keySz; // minimum key size
  5944. if(wolfSSL_CTX_SetMinEccKey(ctx, keySz) != SSL_SUCCESS){
  5945. // Failed to set min key size
  5946. }
  5947. \endcode
  5948. \sa wolfSSL_SetMinEccKey_Sz
  5949. */
  5950. int wolfSSL_CTX_SetMinEccKey_Sz(WOLFSSL_CTX* ssl, short keySz);
  5951. /*!
  5952. \ingroup CertsKeys
  5953. \brief Sets the value of the minEccKeySz member of the options structure.
  5954. The options struct is a member of the WOLFSSL structure and is
  5955. accessed through the ssl parameter.
  5956. \return SSL_SUCCESS if the function successfully set the minEccKeySz
  5957. member of the options structure.
  5958. \return BAD_FUNC_ARG if the WOLFSSL_CTX structure is NULL or if the
  5959. key size (keySz) is less than 0 (zero) or not divisible by 8.
  5960. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5961. \param keySz value used to set the minimum ECC key size. Sets
  5962. value in the options structure.
  5963. _Example_
  5964. \code
  5965. WOLFSSL* ssl = wolfSSL_new(ctx); // New session
  5966. short keySz = 999; // should be set to min key size allowable
  5967. ...
  5968. if(wolfSSL_SetMinEccKey_Sz(ssl, keySz) != SSL_SUCCESS){
  5969. // Failure case.
  5970. }
  5971. \endcode
  5972. \sa wolfSSL_CTX_SetMinEccKey_Sz
  5973. \sa wolfSSL_CTX_SetMinRsaKey_Sz
  5974. \sa wolfSSL_SetMinRsaKey_Sz
  5975. */
  5976. int wolfSSL_SetMinEccKey_Sz(WOLFSSL* ssl, short keySz);
  5977. /*!
  5978. \ingroup CertsKeys
  5979. \brief This function is used by EAP_TLS and EAP-TTLS to derive
  5980. keying material from the master secret.
  5981. \return BUFFER_E returned if the actual size of the buffer exceeds
  5982. the maximum size allowable.
  5983. \return MEMORY_E returned if there is an error with memory allocation.
  5984. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  5985. \param msk a void pointer variable that will hold the result
  5986. of the p_hash function.
  5987. \param len an unsigned integer that represents the length of
  5988. the msk variable.
  5989. \param label a constant char pointer that is copied from in wc_PRF().
  5990. _Example_
  5991. \code
  5992. WOLFSSL* ssl = wolfSSL_new(ctx);;
  5993. void* msk;
  5994. unsigned int len;
  5995. const char* label;
  5996. return wolfSSL_make_eap_keys(ssl, msk, len, label);
  5997. \endcode
  5998. \sa wc_PRF
  5999. \sa wc_HmacFinal
  6000. \sa wc_HmacUpdate
  6001. */
  6002. int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
  6003. const char* label);
  6004. /*!
  6005. \ingroup IO
  6006. \brief Simulates writev semantics but doesn’t actually do block at a time
  6007. because of SSL_write() behavior and because front adds may be small.
  6008. Makes porting into software that uses writev easier.
  6009. \return >0 the number of bytes written upon success.
  6010. \return 0 will be returned upon failure. Call wolfSSL_get_error() for
  6011. the specific error code.
  6012. \return MEMORY_ERROR will be returned if a memory error was encountered.
  6013. \return SSL_FATAL_ERROR will be returned upon failure when either an error
  6014. occurred or, when using non-blocking sockets, the SSL_ERROR_WANT_READ or
  6015. SSL_ERROR_WANT_WRITE error was received and and the application needs to
  6016. call wolfSSL_write() again. Use wolfSSL_get_error() to get a specific
  6017. error code.
  6018. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6019. \param iov array of I/O vectors to write
  6020. \param iovcnt number of vectors in iov array.
  6021. _Example_
  6022. \code
  6023. WOLFSSL* ssl = 0;
  6024. char *bufA = “hello\n”;
  6025. char *bufB = “hello world\n”;
  6026. int iovcnt;
  6027. struct iovec iov[2];
  6028. iov[0].iov_base = buffA;
  6029. iov[0].iov_len = strlen(buffA);
  6030. iov[1].iov_base = buffB;
  6031. iov[1].iov_len = strlen(buffB);
  6032. iovcnt = 2;
  6033. ...
  6034. ret = wolfSSL_writev(ssl, iov, iovcnt);
  6035. // wrote “ret” bytes, or error if <= 0.
  6036. \endcode
  6037. \sa wolfSSL_write
  6038. */
  6039. int wolfSSL_writev(WOLFSSL* ssl, const struct iovec* iov,
  6040. int iovcnt);
  6041. /*!
  6042. \ingroup Setup
  6043. \brief This function unloads the CA signer list and frees
  6044. the whole signer table.
  6045. \return SSL_SUCCESS returned on successful execution of the function.
  6046. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or there
  6047. are otherwise unpermitted argument values passed in a subroutine.
  6048. \return BAD_MUTEX_E returned if there was a mutex error. The LockMutex()
  6049. did not return 0.
  6050. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6051. wolfSSL_CTX_new().
  6052. _Example_
  6053. \code
  6054. WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
  6055. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
  6056. if(!wolfSSL_CTX_UnloadCAs(ctx)){
  6057. // The function did not unload CAs
  6058. }
  6059. \endcode
  6060. \sa wolfSSL_CertManagerUnloadCAs
  6061. \sa LockMutex
  6062. \sa FreeSignerTable
  6063. \sa UnlockMutex
  6064. */
  6065. int wolfSSL_CTX_UnloadCAs(WOLFSSL_CTX*);
  6066. /*!
  6067. \ingroup Setup
  6068. \brief This function is used to unload all previously loaded trusted peer
  6069. certificates. Feature is enabled by defining the macro
  6070. WOLFSSL_TRUST_PEER_CERT.
  6071. \return SSL_SUCCESS upon success.
  6072. \return BAD_FUNC_ARG will be returned if ctx is NULL.
  6073. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6074. can’t be read, or is corrupted.
  6075. \return MEMORY_E will be returned if an out of memory condition occurs.
  6076. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6077. _Example_
  6078. \code
  6079. int ret = 0;
  6080. WOLFSSL_CTX* ctx;
  6081. ...
  6082. ret = wolfSSL_CTX_Unload_trust_peers(ctx);
  6083. if (ret != SSL_SUCCESS) {
  6084. // error unloading trusted peer certs
  6085. }
  6086. ...
  6087. \endcode
  6088. \sa wolfSSL_CTX_trust_peer_buffer
  6089. \sa wolfSSL_CTX_trust_peer_cert
  6090. */
  6091. int wolfSSL_CTX_Unload_trust_peers(WOLFSSL_CTX*);
  6092. /*!
  6093. \ingroup Setup
  6094. \brief This function loads a certificate to use for verifying a peer
  6095. when performing a TLS/SSL handshake. The peer certificate sent during
  6096. the handshake is compared by using the SKID when available and the
  6097. signature. If these two things do not match then any loaded CAs are used.
  6098. Is the same functionality as wolfSSL_CTX_trust_peer_cert except is from
  6099. a buffer instead of a file. Feature is enabled by defining the macro
  6100. WOLFSSL_TRUST_PEER_CERT Please see the examples for proper usage.
  6101. \return SSL_SUCCESS upon success
  6102. \return SSL_FAILURE will be returned if ctx is NULL, or if both file and
  6103. type are invalid.
  6104. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6105. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6106. read, or is corrupted.
  6107. \return MEMORY_E will be returned if an out of memory condition occurs.
  6108. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6109. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6110. \param buffer pointer to the buffer containing certificates.
  6111. \param sz length of the buffer input.
  6112. \param type type of certificate being loaded i.e. SSL_FILETYPE_ASN1 or
  6113. SSL_FILETYPE_PEM.
  6114. _Example_
  6115. \code
  6116. int ret = 0;
  6117. WOLFSSL_CTX* ctx;
  6118. ...
  6119. ret = wolfSSL_CTX_trust_peer_buffer(ctx, bufferPtr, bufferSz,
  6120. SSL_FILETYPE_PEM);
  6121. if (ret != SSL_SUCCESS) {
  6122. // error loading trusted peer cert
  6123. }
  6124. ...
  6125. \endcode
  6126. \sa wolfSSL_CTX_load_verify_buffer
  6127. \sa wolfSSL_CTX_use_certificate_file
  6128. \sa wolfSSL_CTX_use_PrivateKey_file
  6129. \sa wolfSSL_CTX_use_certificate_chain_file
  6130. \sa wolfSSL_CTX_trust_peer_cert
  6131. \sa wolfSSL_CTX_Unload_trust_peers
  6132. \sa wolfSSL_use_certificate_file
  6133. \sa wolfSSL_use_PrivateKey_file
  6134. \sa wolfSSL_use_certificate_chain_file
  6135. */
  6136. int wolfSSL_CTX_trust_peer_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
  6137. long sz, int format);
  6138. /*!
  6139. \ingroup CertsKeys
  6140. \brief This function loads a CA certificate buffer into the WOLFSSL
  6141. Context. It behaves like the non-buffered version, only differing in
  6142. its ability to be called with a buffer as input instead of a file.
  6143. The buffer is provided by the in argument of size sz. format specifies
  6144. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6145. More than one CA certificate may be loaded per buffer as long as the
  6146. format is in PEM. Please see the examples for proper usage.
  6147. \return SSL_SUCCESS upon success
  6148. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6149. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6150. can’t be read, or is corrupted.
  6151. \return MEMORY_E will be returned if an out of memory condition occurs.
  6152. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6153. \return BUFFER_E will be returned if a chain buffer is bigger than
  6154. the receiving buffer.
  6155. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6156. \param in pointer to the CA certificate buffer.
  6157. \param sz size of the input CA certificate buffer, in.
  6158. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6159. or SSL_FILETYPE_PEM.
  6160. _Example_
  6161. \code
  6162. int ret = 0;
  6163. int sz = 0;
  6164. WOLFSSL_CTX* ctx;
  6165. byte certBuff[...];
  6166. ...
  6167. ret = wolfSSL_CTX_load_verify_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  6168. if (ret != SSL_SUCCESS) {
  6169. // error loading CA certs from buffer
  6170. }
  6171. ...
  6172. \endcode
  6173. \sa wolfSSL_CTX_load_verify_locations
  6174. \sa wolfSSL_CTX_use_certificate_buffer
  6175. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6176. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6177. \sa wolfSSL_use_certificate_buffer
  6178. \sa wolfSSL_use_PrivateKey_buffer
  6179. \sa wolfSSL_use_certificate_chain_buffer
  6180. */
  6181. int wolfSSL_CTX_load_verify_buffer(WOLFSSL_CTX* ctx, const unsigned char* in,
  6182. long sz, int format);
  6183. /*!
  6184. \ingroup CertsKeys
  6185. \brief This function loads a CA certificate buffer into the WOLFSSL
  6186. Context. It behaves like the non-buffered version, only differing in
  6187. its ability to be called with a buffer as input instead of a file.
  6188. The buffer is provided by the in argument of size sz. format specifies
  6189. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6190. More than one CA certificate may be loaded per buffer as long as the
  6191. format is in PEM. The _ex version was added in PR 2413 and supports
  6192. additional arguments for userChain and flags.
  6193. \return SSL_SUCCESS upon success
  6194. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6195. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6196. can’t be read, or is corrupted.
  6197. \return MEMORY_E will be returned if an out of memory condition occurs.
  6198. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6199. \return BUFFER_E will be returned if a chain buffer is bigger than
  6200. the receiving buffer.
  6201. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6202. \param in pointer to the CA certificate buffer.
  6203. \param sz size of the input CA certificate buffer, in.
  6204. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6205. or SSL_FILETYPE_PEM.
  6206. \param userChain If using format WOLFSSL_FILETYPE_ASN1 this set to non-zero
  6207. indicates a chain of DER's is being presented.
  6208. \param flags: See ssl.h around WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS.
  6209. _Example_
  6210. \code
  6211. int ret = 0;
  6212. int sz = 0;
  6213. WOLFSSL_CTX* ctx;
  6214. byte certBuff[...];
  6215. ...
  6216. // Example for force loading an expired certificate
  6217. ret = wolfSSL_CTX_load_verify_buffer_ex(ctx, certBuff, sz, SSL_FILETYPE_PEM,
  6218. 0, (WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY));
  6219. if (ret != SSL_SUCCESS) {
  6220. // error loading CA certs from buffer
  6221. }
  6222. ...
  6223. \endcode
  6224. \sa wolfSSL_CTX_load_verify_buffer
  6225. \sa wolfSSL_CTX_load_verify_locations
  6226. \sa wolfSSL_CTX_use_certificate_buffer
  6227. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6228. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6229. \sa wolfSSL_use_certificate_buffer
  6230. \sa wolfSSL_use_PrivateKey_buffer
  6231. \sa wolfSSL_use_certificate_chain_buffer
  6232. */
  6233. int wolfSSL_CTX_load_verify_buffer_ex(WOLFSSL_CTX* ctx,
  6234. const unsigned char* in, long sz,
  6235. int format, int userChain, word32 flags);
  6236. /*!
  6237. \ingroup CertsKeys
  6238. \brief This function loads a CA certificate chain buffer into the WOLFSSL
  6239. Context. It behaves like the non-buffered version, only differing in
  6240. its ability to be called with a buffer as input instead of a file.
  6241. The buffer is provided by the in argument of size sz. format specifies
  6242. the format type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6243. More than one CA certificate may be loaded per buffer as long as the
  6244. format is in PEM. Please see the examples for proper usage.
  6245. \return SSL_SUCCESS upon success
  6246. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6247. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6248. can’t be read, or is corrupted.
  6249. \return MEMORY_E will be returned if an out of memory condition occurs.
  6250. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6251. \return BUFFER_E will be returned if a chain buffer is bigger than
  6252. the receiving buffer.
  6253. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6254. \param in pointer to the CA certificate buffer.
  6255. \param sz size of the input CA certificate buffer, in.
  6256. \param format format of the buffer certificate, either SSL_FILETYPE_ASN1
  6257. or SSL_FILETYPE_PEM.
  6258. _Example_
  6259. \code
  6260. int ret = 0;
  6261. int sz = 0;
  6262. WOLFSSL_CTX* ctx;
  6263. byte certBuff[...];
  6264. ...
  6265. ret = wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  6266. certBuff, sz, WOLFSSL_FILETYPE_ASN1);
  6267. if (ret != SSL_SUCCESS) {
  6268. // error loading CA certs from buffer
  6269. }
  6270. ...
  6271. \endcode
  6272. \sa wolfSSL_CTX_load_verify_locations
  6273. \sa wolfSSL_CTX_use_certificate_buffer
  6274. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6275. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6276. \sa wolfSSL_use_certificate_buffer
  6277. \sa wolfSSL_use_PrivateKey_buffer
  6278. \sa wolfSSL_use_certificate_chain_buffer
  6279. */
  6280. int wolfSSL_CTX_load_verify_chain_buffer_format(WOLFSSL_CTX* ctx,
  6281. const unsigned char* in,
  6282. long sz, int format);
  6283. /*!
  6284. \ingroup CertsKeys
  6285. \brief This function loads a certificate buffer into the WOLFSSL Context.
  6286. It behaves like the non-buffered version, only differing in its ability
  6287. to be called with a buffer as input instead of a file. The buffer is
  6288. provided by the in argument of size sz. format specifies the format
  6289. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  6290. see the examples for proper usage.
  6291. \return SSL_SUCCESS upon success
  6292. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6293. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6294. can’t be read, or is corrupted.
  6295. \return MEMORY_E will be returned if an out of memory condition occurs.
  6296. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6297. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6298. \param in the input buffer containing the certificate to be loaded.
  6299. \param sz the size of the input buffer.
  6300. \param format the format of the certificate located in the input
  6301. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6302. _Example_
  6303. \code
  6304. int ret = 0;
  6305. int sz = 0;
  6306. WOLFSSL_CTX* ctx;
  6307. byte certBuff[...];
  6308. ...
  6309. ret = wolfSSL_CTX_use_certificate_buffer(ctx, certBuff, sz, SSL_FILETYPE_PEM);
  6310. if (ret != SSL_SUCCESS) {
  6311. // error loading certificate from buffer
  6312. }
  6313. ...
  6314. \endcode
  6315. \sa wolfSSL_CTX_load_verify_buffer
  6316. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6317. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6318. \sa wolfSSL_use_certificate_buffer
  6319. \sa wolfSSL_use_PrivateKey_buffer
  6320. \sa wolfSSL_use_certificate_chain_buffer
  6321. */
  6322. int wolfSSL_CTX_use_certificate_buffer(WOLFSSL_CTX* ctx,
  6323. const unsigned char* in, long sz,
  6324. int format);
  6325. /*!
  6326. \ingroup CertsKeys
  6327. \brief This function loads a private key buffer into the SSL Context.
  6328. It behaves like the non-buffered version, only differing in its ability
  6329. to be called with a buffer as input instead of a file. The buffer is
  6330. provided by the in argument of size sz. format specifies the format type
  6331. of the buffer; SSL_FILETYPE_ASN1or SSL_FILETYPE_PEM. Please see the
  6332. examples for proper usage.
  6333. \return SSL_SUCCESS upon success
  6334. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6335. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6336. read, or is corrupted.
  6337. \return MEMORY_E will be returned if an out of memory condition occurs.
  6338. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6339. \return NO_PASSWORD will be returned if the key file is encrypted but no
  6340. password is provided.
  6341. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6342. \param in the input buffer containing the private key to be loaded.
  6343. \param sz the size of the input buffer.
  6344. \param format the format of the private key located in the input
  6345. buffer (in). Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6346. _Example_
  6347. \code
  6348. int ret = 0;
  6349. int sz = 0;
  6350. WOLFSSL_CTX* ctx;
  6351. byte keyBuff[...];
  6352. ...
  6353. ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, keyBuff, sz, SSL_FILETYPE_PEM);
  6354. if (ret != SSL_SUCCESS) {
  6355. // error loading private key from buffer
  6356. }
  6357. ...
  6358. \endcode
  6359. \sa wolfSSL_CTX_load_verify_buffer
  6360. \sa wolfSSL_CTX_use_certificate_buffer
  6361. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6362. \sa wolfSSL_use_certificate_buffer
  6363. \sa wolfSSL_use_PrivateKey_buffer
  6364. \sa wolfSSL_use_certificate_chain_buffer
  6365. */
  6366. int wolfSSL_CTX_use_PrivateKey_buffer(WOLFSSL_CTX* ctx,
  6367. const unsigned char* in, long sz,
  6368. int format);
  6369. /*!
  6370. \ingroup CertsKeys
  6371. \brief This function loads a certificate chain buffer into the WOLFSSL
  6372. Context. It behaves like the non-buffered version, only differing in
  6373. its ability to be called with a buffer as input instead of a file.
  6374. The buffer is provided by the in argument of size sz. The buffer must
  6375. be in PEM format and start with the subject’s certificate, ending with
  6376. the root certificate. Please see the examples for proper usage.
  6377. \return SSL_SUCCESS upon success
  6378. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6379. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6380. can’t be read, or is corrupted.
  6381. \return MEMORY_E will be returned if an out of memory condition occurs.
  6382. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6383. \return BUFFER_E will be returned if a chain buffer is bigger than
  6384. the receiving buffer.
  6385. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6386. \param in the input buffer containing the PEM-formatted certificate
  6387. chain to be loaded.
  6388. \param sz the size of the input buffer.
  6389. _Example_
  6390. \code
  6391. int ret = 0;
  6392. int sz = 0;
  6393. WOLFSSL_CTX* ctx;
  6394. byte certChainBuff[...];
  6395. ...
  6396. ret = wolfSSL_CTX_use_certificate_chain_buffer(ctx, certChainBuff, sz);
  6397. if (ret != SSL_SUCCESS) {
  6398. // error loading certificate chain from buffer
  6399. }
  6400. ...
  6401. \endcode
  6402. \sa wolfSSL_CTX_load_verify_buffer
  6403. \sa wolfSSL_CTX_use_certificate_buffer
  6404. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6405. \sa wolfSSL_use_certificate_buffer
  6406. \sa wolfSSL_use_PrivateKey_buffer
  6407. \sa wolfSSL_use_certificate_chain_buffer
  6408. */
  6409. int wolfSSL_CTX_use_certificate_chain_buffer(WOLFSSL_CTX* ctx,
  6410. const unsigned char* in, long sz);
  6411. /*!
  6412. \ingroup CertsKeys
  6413. \brief This function loads a certificate buffer into the WOLFSSL object.
  6414. It behaves like the non-buffered version, only differing in its ability
  6415. to be called with a buffer as input instead of a file. The buffer
  6416. is provided by the in argument of size sz. format specifies the format
  6417. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6418. Please see the examples for proper usage.
  6419. \return SSL_SUCCESS upon success.
  6420. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6421. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  6422. be read, or is corrupted.
  6423. \return MEMORY_E will be returned if an out of memory condition occurs.
  6424. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6425. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6426. \param in buffer containing certificate to load.
  6427. \param sz size of the certificate located in buffer.
  6428. \param format format of the certificate to be loaded.
  6429. Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6430. _Example_
  6431. \code
  6432. int buffSz;
  6433. int ret;
  6434. byte certBuff[...];
  6435. WOLFSSL* ssl = 0;
  6436. ...
  6437. ret = wolfSSL_use_certificate_buffer(ssl, certBuff, buffSz, SSL_FILETYPE_PEM);
  6438. if (ret != SSL_SUCCESS) {
  6439. // failed to load certificate from buffer
  6440. }
  6441. \endcode
  6442. \sa wolfSSL_CTX_load_verify_buffer
  6443. \sa wolfSSL_CTX_use_certificate_buffer
  6444. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6445. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6446. \sa wolfSSL_use_PrivateKey_buffer
  6447. \sa wolfSSL_use_certificate_chain_buffer
  6448. */
  6449. int wolfSSL_use_certificate_buffer(WOLFSSL* ssl, const unsigned char* in,
  6450. long sz, int format);
  6451. /*!
  6452. \ingroup CertsKeys
  6453. \brief This function loads a private key buffer into the WOLFSSL object.
  6454. It behaves like the non-buffered version, only differing in its ability
  6455. to be called with a buffer as input instead of a file. The buffer is
  6456. provided by the in argument of size sz. format specifies the format
  6457. type of the buffer; SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. Please
  6458. see the examples for proper usage.
  6459. \return SSL_SUCCESS upon success.
  6460. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6461. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  6462. read, or is corrupted.
  6463. \return MEMORY_E will be returned if an out of memory condition occurs.
  6464. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6465. \return NO_PASSWORD will be returned if the key file is encrypted but no
  6466. password is provided.
  6467. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6468. \param in buffer containing private key to load.
  6469. \param sz size of the private key located in buffer.
  6470. \param format format of the private key to be loaded. Possible values are
  6471. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  6472. _Example_
  6473. \code
  6474. int buffSz;
  6475. int ret;
  6476. byte keyBuff[...];
  6477. WOLFSSL* ssl = 0;
  6478. ...
  6479. ret = wolfSSL_use_PrivateKey_buffer(ssl, keyBuff, buffSz, SSL_FILETYPE_PEM);
  6480. if (ret != SSL_SUCCESS) {
  6481. // failed to load private key from buffer
  6482. }
  6483. \endcode
  6484. \sa wolfSSL_use_PrivateKey
  6485. \sa wolfSSL_CTX_load_verify_buffer
  6486. \sa wolfSSL_CTX_use_certificate_buffer
  6487. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6488. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6489. \sa wolfSSL_use_certificate_buffer
  6490. \sa wolfSSL_use_certificate_chain_buffer
  6491. */
  6492. int wolfSSL_use_PrivateKey_buffer(WOLFSSL* ssl, const unsigned char* in,
  6493. long sz, int format);
  6494. /*!
  6495. \ingroup CertsKeys
  6496. \brief This function loads a certificate chain buffer into the WOLFSSL
  6497. object. It behaves like the non-buffered version, only differing in its
  6498. ability to be called with a buffer as input instead of a file. The buffer
  6499. is provided by the in argument of size sz. The buffer must be in PEM format
  6500. and start with the subject’s certificate, ending with the root certificate.
  6501. Please see the examples for proper usage.
  6502. \return SSL_SUCCES upon success.
  6503. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  6504. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  6505. can’t be read, or is corrupted.
  6506. \return MEMORY_E will be returned if an out of memory condition occurs.
  6507. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  6508. \return BUFFER_E will be returned if a chain buffer is bigger than
  6509. the receiving buffer.
  6510. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6511. \param in buffer containing certificate to load.
  6512. \param sz size of the certificate located in buffer.
  6513. _Example_
  6514. \code
  6515. int buffSz;
  6516. int ret;
  6517. byte certChainBuff[...];
  6518. WOLFSSL* ssl = 0;
  6519. ...
  6520. ret = wolfSSL_use_certificate_chain_buffer(ssl, certChainBuff, buffSz);
  6521. if (ret != SSL_SUCCESS) {
  6522. // failed to load certificate chain from buffer
  6523. }
  6524. \endcode
  6525. \sa wolfSSL_CTX_load_verify_buffer
  6526. \sa wolfSSL_CTX_use_certificate_buffer
  6527. \sa wolfSSL_CTX_use_PrivateKey_buffer
  6528. \sa wolfSSL_CTX_use_certificate_chain_buffer
  6529. \sa wolfSSL_use_certificate_buffer
  6530. \sa wolfSSL_use_PrivateKey_buffer
  6531. */
  6532. int wolfSSL_use_certificate_chain_buffer(WOLFSSL* ssl,
  6533. const unsigned char* in, long sz);
  6534. /*!
  6535. \ingroup CertsKeys
  6536. \brief This function unloads any certificates or keys that SSL owns.
  6537. \return SSL_SUCCESS - returned if the function executed successfully.
  6538. \return BAD_FUNC_ARG - returned if the WOLFSSL object is NULL.
  6539. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6540. _Example_
  6541. \code
  6542. WOLFSSL* ssl = wolfSSL_new(ctx);
  6543. ...
  6544. int unloadKeys = wolfSSL_UnloadCertsKeys(ssl);
  6545. if(unloadKeys != SSL_SUCCESS){
  6546. // Failure case.
  6547. }
  6548. \endcode
  6549. \sa wolfSSL_CTX_UnloadCAs
  6550. */
  6551. int wolfSSL_UnloadCertsKeys(WOLFSSL*);
  6552. /*!
  6553. \ingroup Setup
  6554. \brief This function turns on grouping of handshake messages where possible.
  6555. \return SSL_SUCCESS will be returned upon success.
  6556. \return BAD_FUNC_ARG will be returned if the input context is null.
  6557. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  6558. _Example_
  6559. \code
  6560. WOLFSSL_CTX* ctx = 0;
  6561. ...
  6562. ret = wolfSSL_CTX_set_group_messages(ctx);
  6563. if (ret != SSL_SUCCESS) {
  6564. // failed to set handshake message grouping
  6565. }
  6566. \endcode
  6567. \sa wolfSSL_set_group_messages
  6568. \sa wolfSSL_CTX_new
  6569. */
  6570. int wolfSSL_CTX_set_group_messages(WOLFSSL_CTX*);
  6571. /*!
  6572. \ingroup Setup
  6573. \brief This function turns on grouping of handshake messages where possible.
  6574. \return SSL_SUCCESS will be returned upon success.
  6575. \return BAD_FUNC_ARG will be returned if the input context is null.
  6576. \param ssl pointer to the SSL session, created with wolfSSL_new().
  6577. _Example_
  6578. \code
  6579. WOLFSSL* ssl = 0;
  6580. ...
  6581. ret = wolfSSL_set_group_messages(ssl);
  6582. if (ret != SSL_SUCCESS) {
  6583. // failed to set handshake message grouping
  6584. }
  6585. \endcode
  6586. \sa wolfSSL_CTX_set_group_messages
  6587. \sa wolfSSL_new
  6588. */
  6589. int wolfSSL_set_group_messages(WOLFSSL*);
  6590. /*!
  6591. \brief This function sets the fuzzer callback.
  6592. \return none No returns.
  6593. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6594. \param cbf a CallbackFuzzer type that is a function pointer of the form:
  6595. int (*CallbackFuzzer)(WOLFSSL* ssl, const unsigned char* buf, int sz, int
  6596. type, void* fuzzCtx);
  6597. \param fCtx a void pointer type that will be set to the fuzzerCtx member of
  6598. the WOLFSSL structure.
  6599. _Example_
  6600. \code
  6601. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6602. WOLFSSL* ssl = wolfSSL_new(ctx);
  6603. void* fCtx;
  6604. int callbackFuzzerCB(WOLFSSL* ssl, const unsigned char* buf, int sz,
  6605. int type, void* fuzzCtx){
  6606. // function definition
  6607. }
  6608. wolfSSL_SetFuzzerCb(ssl, callbackFuzzerCB, fCtx);
  6609. \endcode
  6610. \sa CallbackFuzzer
  6611. */
  6612. void wolfSSL_SetFuzzerCb(WOLFSSL* ssl, CallbackFuzzer cbf, void* fCtx);
  6613. /*!
  6614. \brief This function sets a new dtls cookie secret.
  6615. \return 0 returned if the function executed without an error.
  6616. \return BAD_FUNC_ARG returned if there was an argument passed
  6617. to the function with an unacceptable value.
  6618. \return COOKIE_SECRET_SZ returned if the secret size is 0.
  6619. \return MEMORY_ERROR returned if there was a problem allocating
  6620. memory for a new cookie secret.
  6621. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6622. \param secret a constant byte pointer representing the secret buffer.
  6623. \param secretSz the size of the buffer.
  6624. _Example_
  6625. \code
  6626. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6627. WOLFSSL* ssl = wolfSSL_new(ctx);
  6628. const* byte secret;
  6629. word32 secretSz; // size of secret
  6630. if(!wolfSSL_DTLS_SetCookieSecret(ssl, secret, secretSz)){
  6631. // Code block for failure to set DTLS cookie secret
  6632. } else {
  6633. // Success! Cookie secret is set.
  6634. }
  6635. \endcode
  6636. \sa ForceZero
  6637. \sa wc_RNG_GenerateBlock
  6638. */
  6639. int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
  6640. const unsigned char* secret,
  6641. unsigned int secretSz);
  6642. /*!
  6643. \brief This function retrieves the random number.
  6644. \return rng upon success.
  6645. \return NULL if ssl is NULL.
  6646. \param ssl pointer to a SSL object, created with wolfSSL_new().
  6647. _Example_
  6648. \code
  6649. WOLFSSL* ssl;
  6650. wolfSSL_GetRNG(ssl);
  6651. \endcode
  6652. \sa wolfSSL_CTX_new_rng
  6653. */
  6654. WC_RNG* wolfSSL_GetRNG(WOLFSSL* ssl);
  6655. /*!
  6656. \ingroup Setup
  6657. \brief This function sets the minimum downgrade version allowed.
  6658. Applicable only when the connection allows downgrade using
  6659. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6660. \return SSL_SUCCESS returned if the function returned without
  6661. error and the minimum version is set.
  6662. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure was
  6663. NULL or if the minimum version is not supported.
  6664. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  6665. wolfSSL_CTX_new().
  6666. \param version an integer representation of the version to be set as the
  6667. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6668. WOLFSSL_TLSV1_2 = 3.
  6669. _Example_
  6670. \code
  6671. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  6672. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6673. int version; // macrop representation
  6674. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6675. // Failed to set min version
  6676. }
  6677. \endcode
  6678. \sa SetMinVersionHelper
  6679. */
  6680. int wolfSSL_CTX_SetMinVersion(WOLFSSL_CTX* ctx, int version);
  6681. /*!
  6682. \ingroup TLS
  6683. \brief This function sets the minimum downgrade version allowed.
  6684. Applicable only when the connection allows downgrade using
  6685. (wolfSSLv23_client_method or wolfSSLv23_server_method).
  6686. \return SSL_SUCCESS returned if this function and its subroutine executes
  6687. without error.
  6688. \return BAD_FUNC_ARG returned if the SSL object is NULL. In
  6689. the subroutine this error is thrown if there is not a good version match.
  6690. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6691. \param version an integer representation of the version to be set as the
  6692. minimum: WOLFSSL_SSLV3 = 0, WOLFSSL_TLSV1 = 1, WOLFSSL_TLSV1_1 = 2 or
  6693. WOLFSSL_TLSV1_2 = 3.
  6694. _Example_
  6695. \code
  6696. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(protocol method);
  6697. WOLFSSL* ssl = WOLFSSL_new(ctx);
  6698. int version; macro representation
  6699. if(wolfSSL_CTX_SetMinVersion(ssl->ctx, version) != SSL_SUCCESS){
  6700. Failed to set min version
  6701. }
  6702. \endcode
  6703. \sa SetMinVersionHelper
  6704. */
  6705. int wolfSSL_SetMinVersion(WOLFSSL* ssl, int version);
  6706. /*!
  6707. \brief This function returns the size of the WOLFSSL object and will be
  6708. dependent on build options and settings. If SHOW_SIZES has been defined
  6709. when building wolfSSL, this function will also print the sizes of individual
  6710. objects within the WOLFSSL object (Suites, Ciphers, etc.) to stdout.
  6711. \return size This function returns the size of the WOLFSSL object.
  6712. \param none No parameters.
  6713. _Example_
  6714. \code
  6715. int size = 0;
  6716. size = wolfSSL_GetObjectSize();
  6717. printf(“sizeof(WOLFSSL) = %d\n”, size);
  6718. \endcode
  6719. \sa wolfSSL_new
  6720. */
  6721. int wolfSSL_GetObjectSize(void); /* object size based on build */
  6722. /*!
  6723. \brief Returns the record layer size of the plaintext input. This is helpful
  6724. when an application wants to know how many bytes will be sent across the
  6725. Transport layer, given a specified plaintext input size. This function
  6726. must be called after the SSL/TLS handshake has been completed.
  6727. \return size Upon success, the requested size will be returned
  6728. \return INPUT_SIZE_E will be returned if the input size is greater than the
  6729. maximum TLS fragment size (see wolfSSL_GetMaxOutputSize())
  6730. \return BAD_FUNC_ARG will be returned upon invalid function argument, or if
  6731. the SSL/TLS handshake has not been completed yet
  6732. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6733. \param inSz size of plaintext data.
  6734. _Example_
  6735. \code
  6736. none
  6737. \endcode
  6738. \sa wolfSSL_GetMaxOutputSize
  6739. */
  6740. int wolfSSL_GetOutputSize(WOLFSSL* ssl, int inSz);
  6741. /*!
  6742. \brief Returns the maximum record layer size for plaintext data. This
  6743. will correspond to either the maximum SSL/TLS record size as specified
  6744. by the protocol standard, the maximum TLS fragment size as set by the
  6745. TLS Max Fragment Length extension. This function is helpful when the
  6746. application has called wolfSSL_GetOutputSize() and received a INPUT_SIZE_E
  6747. error. This function must be called after the SSL/TLS handshake has been
  6748. completed.
  6749. \return size Upon success, the maximum output size will be returned
  6750. \return BAD_FUNC_ARG will be returned upon invalid function argument,
  6751. or if the SSL/TLS handshake has not been completed yet.
  6752. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6753. _Example_
  6754. \code
  6755. none
  6756. \endcode
  6757. \sa wolfSSL_GetOutputSize
  6758. */
  6759. int wolfSSL_GetMaxOutputSize(WOLFSSL*);
  6760. /*!
  6761. \ingroup Setup
  6762. \brief This function sets the SSL/TLS protocol version for the specified
  6763. SSL session (WOLFSSL object) using the version as specified by version.
  6764. This will override the protocol setting for the SSL session (ssl) -
  6765. originally defined and set by the SSL context (wolfSSL_CTX_new())
  6766. method type.
  6767. \return SSL_SUCCESS upon success.
  6768. \return BAD_FUNC_ARG will be returned if the input SSL object is
  6769. NULL or an incorrect protocol version is given for version.
  6770. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6771. \param version SSL/TLS protocol version. Possible values include
  6772. WOLFSSL_SSLV3, WOLFSSL_TLSV1, WOLFSSL_TLSV1_1, WOLFSSL_TLSV1_2.
  6773. _Example_
  6774. \code
  6775. int ret = 0;
  6776. WOLFSSL* ssl;
  6777. ...
  6778. ret = wolfSSL_SetVersion(ssl, WOLFSSL_TLSV1);
  6779. if (ret != SSL_SUCCESS) {
  6780. // failed to set SSL session protocol version
  6781. }
  6782. \endcode
  6783. \sa wolfSSL_CTX_new
  6784. */
  6785. int wolfSSL_SetVersion(WOLFSSL* ssl, int version);
  6786. /*!
  6787. \brief Allows caller to set the Atomic User Record Processing
  6788. Mac/Encrypt Callback. The callback should return 0 for success
  6789. or < 0 for an error. The ssl and ctx pointers are available
  6790. for the user’s convenience. macOut is the output buffer where
  6791. the result of the mac should be stored. macIn is the mac input
  6792. buffer and macInSz notes the size of the buffer. macContent
  6793. and macVerify are needed for wolfSSL_SetTlsHmacInner() and be
  6794. passed along as is. encOut is the output buffer where the result
  6795. on the encryption should be stored. encIn is the input buffer to
  6796. encrypt while encSz is the size of the input. An example callback
  6797. can be found wolfssl/test.h myMacEncryptCb().
  6798. \return none No return.
  6799. \param No parameters.
  6800. _Example_
  6801. \code
  6802. none
  6803. \endcode
  6804. \sa wolfSSL_SetMacEncryptCtx
  6805. \sa wolfSSL_GetMacEncryptCtx
  6806. */
  6807. void wolfSSL_CTX_SetMacEncryptCb(WOLFSSL_CTX* ctx, CallbackMacEncrypti cb);
  6808. /*!
  6809. \brief Allows caller to set the Atomic User Record Processing Mac/Encrypt
  6810. Callback Context to ctx.
  6811. \return none No return.
  6812. \param none No parameters.
  6813. _Example_
  6814. \code
  6815. none
  6816. \endcode
  6817. \sa wolfSSL_CTX_SetMacEncryptCb
  6818. \sa wolfSSL_GetMacEncryptCtx
  6819. */
  6820. void wolfSSL_SetMacEncryptCtx(WOLFSSL* ssl, void *ctx);
  6821. /*!
  6822. \brief Allows caller to retrieve the Atomic User Record Processing
  6823. Mac/Encrypt Callback Context previously stored with
  6824. wolfSSL_SetMacEncryptCtx().
  6825. \return pointer If successful the call will return a valid pointer
  6826. to the context.
  6827. \return NULL will be returned for a blank context.
  6828. \param none No parameters.
  6829. _Example_
  6830. \code
  6831. none
  6832. \endcode
  6833. \sa wolfSSL_CTX_SetMacEncryptCb
  6834. \sa wolfSSL_SetMacEncryptCtx
  6835. */
  6836. void* wolfSSL_GetMacEncryptCtx(WOLFSSL* ssl);
  6837. /*!
  6838. \brief Allows caller to set the Atomic User Record Processing
  6839. Decrypt/Verify Callback. The callback should return 0 for success
  6840. or < 0 for an error. The ssl and ctx pointers are available for
  6841. the user’s convenience. decOut is the output buffer where the result
  6842. of the decryption should be stored. decIn is the encrypted input
  6843. buffer and decInSz notes the size of the buffer. content and verify
  6844. are needed for wolfSSL_SetTlsHmacInner() and be passed along as is.
  6845. padSz is an output variable that should be set with the total value
  6846. of the padding. That is, the mac size plus any padding and pad bytes.
  6847. An example callback can be found wolfssl/test.h myDecryptVerifyCb().
  6848. \return none No returns.
  6849. \param none No parameters.
  6850. _Example_
  6851. \code
  6852. none
  6853. \endcode
  6854. \sa wolfSSL_SetMacEncryptCtx
  6855. \sa wolfSSL_GetMacEncryptCtx
  6856. */
  6857. void wolfSSL_CTX_SetDecryptVerifyCb(WOLFSSL_CTX* ctx,
  6858. CallbackDecryptVerify cb);
  6859. /*!
  6860. \brief Allows caller to set the Atomic User Record Processing
  6861. Decrypt/Verify Callback Context to ctx.
  6862. \return none No returns.
  6863. \param none No parameters.
  6864. _Example_
  6865. \code
  6866. none
  6867. \endcode
  6868. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6869. \sa wolfSSL_GetDecryptVerifyCtx
  6870. */
  6871. void wolfSSL_SetDecryptVerifyCtx(WOLFSSL* ssl, void *ctx);
  6872. /*!
  6873. \brief Allows caller to retrieve the Atomic User Record Processing
  6874. Decrypt/Verify Callback Context previously stored with
  6875. wolfSSL_SetDecryptVerifyCtx().
  6876. \return pointer If successful the call will return a valid pointer to the
  6877. context.
  6878. \return NULL will be returned for a blank context.
  6879. \param none No parameters.
  6880. _Example_
  6881. \code
  6882. none
  6883. \endcode
  6884. \sa wolfSSL_CTX_SetDecryptVerifyCb
  6885. \sa wolfSSL_SetDecryptVerifyCtx
  6886. */
  6887. void* wolfSSL_GetDecryptVerifyCtx(WOLFSSL* ssl);
  6888. /*!
  6889. \brief Allows retrieval of the Hmac/Mac secret from the handshake process.
  6890. The verify parameter specifies whether this is for verification of a
  6891. peer message.
  6892. \return pointer If successful the call will return a valid pointer to the
  6893. secret. The size of the secret can be obtained from wolfSSL_GetHmacSize().
  6894. \return NULL will be returned for an error state.
  6895. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6896. \param verify specifies whether this is for verification of a peer message.
  6897. _Example_
  6898. \code
  6899. none
  6900. \endcode
  6901. \sa wolfSSL_GetHmacSize
  6902. */
  6903. const unsigned char* wolfSSL_GetMacSecret(WOLFSSL* ssl, int verify);
  6904. /*!
  6905. \brief Allows retrieval of the client write key from the handshake process.
  6906. \return pointer If successful the call will return a valid pointer to the
  6907. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  6908. \return NULL will be returned for an error state.
  6909. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6910. _Example_
  6911. \code
  6912. none
  6913. \endcode
  6914. \sa wolfSSL_GetKeySize
  6915. \sa wolfSSL_GetClientWriteIV
  6916. */
  6917. const unsigned char* wolfSSL_GetClientWriteKey(WOLFSSL*);
  6918. /*!
  6919. \brief Allows retrieval of the client write IV (initialization vector)
  6920. from the handshake process.
  6921. \return pointer If successful the call will return a valid pointer to the
  6922. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  6923. \return NULL will be returned for an error state.
  6924. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6925. _Example_
  6926. \code
  6927. none
  6928. \endcode
  6929. \sa wolfSSL_GetCipherBlockSize()
  6930. \sa wolfSSL_GetClientWriteKey()
  6931. */
  6932. const unsigned char* wolfSSL_GetClientWriteIV(WOLFSSL*);
  6933. /*!
  6934. \brief Allows retrieval of the server write key from the handshake process.
  6935. \return pointer If successful the call will return a valid pointer to the
  6936. key. The size of the key can be obtained from wolfSSL_GetKeySize().
  6937. \return NULL will be returned for an error state.
  6938. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6939. _Example_
  6940. \code
  6941. none
  6942. \endcode
  6943. \sa wolfSSL_GetKeySize
  6944. \sa wolfSSL_GetServerWriteIV
  6945. */
  6946. const unsigned char* wolfSSL_GetServerWriteKey(WOLFSSL*);
  6947. /*!
  6948. \brief Allows retrieval of the server write IV (initialization vector)
  6949. from the handshake process.
  6950. \return pointer If successful the call will return a valid pointer to the
  6951. IV. The size of the IV can be obtained from wolfSSL_GetCipherBlockSize().
  6952. \return NULL will be returned for an error state.
  6953. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6954. \sa wolfSSL_GetCipherBlockSize
  6955. \sa wolfSSL_GetClientWriteKey
  6956. */
  6957. const unsigned char* wolfSSL_GetServerWriteIV(WOLFSSL*);
  6958. /*!
  6959. \brief Allows retrieval of the key size from the handshake process.
  6960. \return size If successful the call will return the key size in bytes.
  6961. \return BAD_FUNC_ARG will be returned for an error state.
  6962. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  6963. _Example_
  6964. \code
  6965. none
  6966. \endcode
  6967. \sa wolfSSL_GetClientWriteKey
  6968. \sa wolfSSL_GetServerWriteKey
  6969. */
  6970. int wolfSSL_GetKeySize(WOLFSSL*);
  6971. /*!
  6972. \ingroup CertsKeys
  6973. \brief Returns the iv_size member of the specs structure
  6974. held in the WOLFSSL struct.
  6975. \return iv_size returns the value held in ssl->specs.iv_size.
  6976. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  6977. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  6978. _Example_
  6979. \code
  6980. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  6981. WOLFSSL* ssl = wolfSSL_new(ctx);
  6982. int ivSize;
  6983. ...
  6984. ivSize = wolfSSL_GetIVSize(ssl);
  6985. if(ivSize > 0){
  6986. // ivSize holds the specs.iv_size value.
  6987. }
  6988. \endcode
  6989. \sa wolfSSL_GetKeySize
  6990. \sa wolfSSL_GetClientWriteIV
  6991. \sa wolfSSL_GetServerWriteIV
  6992. */
  6993. int wolfSSL_GetIVSize(WOLFSSL*);
  6994. /*!
  6995. \brief Allows retrieval of the side of this WOLFSSL connection.
  6996. \return success If successful the call will return either
  6997. WOLFSSL_SERVER_END or WOLFSSL_CLIENT_END depending on the
  6998. side of WOLFSSL object.
  6999. \return BAD_FUNC_ARG will be returned for an error state.
  7000. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7001. _Example_
  7002. \code
  7003. none
  7004. \endcode
  7005. \sa wolfSSL_GetClientWriteKey
  7006. \sa wolfSSL_GetServerWriteKey
  7007. */
  7008. int wolfSSL_GetSide(WOLFSSL*);
  7009. /*!
  7010. \brief Allows caller to determine if the negotiated protocol version
  7011. is at least TLS version 1.1 or greater.
  7012. \return true/false If successful the call will return 1 for true or
  7013. 0 for false.
  7014. \return BAD_FUNC_ARG will be returned for an error state.
  7015. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7016. _Example_
  7017. \code
  7018. none
  7019. \endcode
  7020. \sa wolfSSL_GetSide
  7021. */
  7022. int wolfSSL_IsTLSv1_1(WOLFSSL*);
  7023. /*!
  7024. \brief Allows caller to determine the negotiated bulk cipher algorithm
  7025. from the handshake.
  7026. \return If successful the call will return one of the following:
  7027. wolfssl_cipher_null, wolfssl_des, wolfssl_triple_des, wolfssl_aes,
  7028. wolfssl_aes_gcm, wolfssl_aes_ccm, wolfssl_camellia.
  7029. \return BAD_FUNC_ARG will be returned for an error state.
  7030. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7031. _Example_
  7032. \code
  7033. none
  7034. \endcode
  7035. \sa wolfSSL_GetCipherBlockSize
  7036. \sa wolfSSL_GetKeySize
  7037. */
  7038. int wolfSSL_GetBulkCipher(WOLFSSL*);
  7039. /*!
  7040. \brief Allows caller to determine the negotiated cipher block size from
  7041. the handshake.
  7042. \return size If successful the call will return the size in bytes of the
  7043. cipher block size.
  7044. \return BAD_FUNC_ARG will be returned for an error state.
  7045. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7046. _Example_
  7047. \code
  7048. none
  7049. \endcode
  7050. \sa wolfSSL_GetBulkCipher
  7051. \sa wolfSSL_GetKeySize
  7052. */
  7053. int wolfSSL_GetCipherBlockSize(WOLFSSL*);
  7054. /*!
  7055. \brief Allows caller to determine the negotiated aead mac size from the
  7056. handshake. For cipher type WOLFSSL_AEAD_TYPE.
  7057. \return size If successful the call will return the size in bytes of the
  7058. aead mac size.
  7059. \return BAD_FUNC_ARG will be returned for an error state.
  7060. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7061. _Example_
  7062. \code
  7063. none
  7064. \endcode
  7065. \sa wolfSSL_GetBulkCipher
  7066. \sa wolfSSL_GetKeySize
  7067. */
  7068. int wolfSSL_GetAeadMacSize(WOLFSSL*);
  7069. /*!
  7070. \brief Allows caller to determine the negotiated (h)mac size from the
  7071. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  7072. \return size If successful the call will return the size in bytes of
  7073. the (h)mac size.
  7074. \return BAD_FUNC_ARG will be returned for an error state.
  7075. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7076. _Example_
  7077. \code
  7078. none
  7079. \endcode
  7080. \sa wolfSSL_GetBulkCipher
  7081. \sa wolfSSL_GetHmacType
  7082. */
  7083. int wolfSSL_GetHmacSize(WOLFSSL*);
  7084. /*!
  7085. \brief Allows caller to determine the negotiated (h)mac type from the
  7086. handshake. For cipher types except WOLFSSL_AEAD_TYPE.
  7087. \return If successful the call will return one of the following:
  7088. MD5, SHA, SHA256, SHA384.
  7089. \return BAD_FUNC_ARG may be returned for an error state.
  7090. \return SSL_FATAL_ERROR may also be returned for an error state.
  7091. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7092. _Example_
  7093. \code
  7094. none
  7095. \endcode
  7096. \sa wolfSSL_GetBulkCipher
  7097. \sa wolfSSL_GetHmacSize
  7098. */
  7099. int wolfSSL_GetHmacType(WOLFSSL*);
  7100. /*!
  7101. \brief Allows caller to determine the negotiated cipher type
  7102. from the handshake.
  7103. \return If successful the call will return one of the following:
  7104. WOLFSSL_BLOCK_TYPE, WOLFSSL_STREAM_TYPE, WOLFSSL_AEAD_TYPE.
  7105. \return BAD_FUNC_ARG will be returned for an error state.
  7106. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7107. _Example_
  7108. \code
  7109. none
  7110. \endcode
  7111. \sa wolfSSL_GetBulkCipher
  7112. \sa wolfSSL_GetHmacType
  7113. */
  7114. int wolfSSL_GetCipherType(WOLFSSL*);
  7115. /*!
  7116. \brief Allows caller to set the Hmac Inner vector for message
  7117. sending/receiving. The result is written to inner which should
  7118. be at least wolfSSL_GetHmacSize() bytes. The size of the message
  7119. is specified by sz, content is the type of message, and verify
  7120. specifies whether this is a verification of a peer message. Valid
  7121. for cipher types excluding WOLFSSL_AEAD_TYPE.
  7122. \return 1 upon success.
  7123. \return BAD_FUNC_ARG will be returned for an error state.
  7124. \param none No parameters.
  7125. _Example_
  7126. \code
  7127. none
  7128. \endcode
  7129. \sa wolfSSL_GetBulkCipher
  7130. \sa wolfSSL_GetHmacType
  7131. */
  7132. int wolfSSL_SetTlsHmacInner(WOLFSSL* ssl, byte* inner,
  7133. word32 sz, int content, int verify);
  7134. /*!
  7135. \brief Allows caller to set the Public Key Callback for ECC Signing.
  7136. The callback should return 0 for success or < 0 for an error.
  7137. The ssl and ctx pointers are available for the user’s convenience.
  7138. in is the input buffer to sign while inSz denotes the length of the input.
  7139. out is the output buffer where the result of the signature should be stored.
  7140. outSz is an input/output variable that specifies the size of the output
  7141. buffer upon invocation and the actual size of the signature should be stored
  7142. there before returning. keyDer is the ECC Private key in ASN1 format and
  7143. keySz is the length of the key in bytes. An example callback can be found
  7144. wolfssl/test.h myEccSign().
  7145. \return none No returns.
  7146. \param none No parameters.
  7147. _Example_
  7148. \code
  7149. none
  7150. \endcode
  7151. \sa wolfSSL_SetEccSignCtx
  7152. \sa wolfSSL_GetEccSignCtx
  7153. */
  7154. void wolfSSL_CTX_SetEccSignCb(WOLFSSL_CTX* ctx, CallbackEccSign cb);
  7155. /*!
  7156. \brief Allows caller to set the Public Key Ecc Signing Callback
  7157. Context to ctx.
  7158. \return none No returns.
  7159. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7160. \param ctx a pointer to the user context to be stored
  7161. _Example_
  7162. \code
  7163. none
  7164. \endcode
  7165. \sa wolfSSL_CTX_SetEccSignCb
  7166. \sa wolfSSL_GetEccSignCtx
  7167. */
  7168. void wolfSSL_SetEccSignCtx(WOLFSSL* ssl, void *ctx);
  7169. /*!
  7170. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  7171. Context previously stored with wolfSSL_SetEccSignCtx().
  7172. \return pointer If successful the call will return a valid pointer
  7173. to the context.
  7174. \return NULL will be returned for a blank context.
  7175. \param ssl a pointer to a WOLFSSL object, created using wolfSSL_new().
  7176. _Example_
  7177. \code
  7178. none
  7179. \endcode
  7180. \sa wolfSSL_CTX_SetEccSignCb
  7181. \sa wolfSSL_SetEccSignCtx
  7182. */
  7183. void* wolfSSL_GetEccSignCtx(WOLFSSL* ssl);
  7184. /*!
  7185. \brief Allows caller to set the Public Key Ecc Signing Callback
  7186. Context to ctx.
  7187. \return none No returns.
  7188. \param ctx a pointer to a WOLFSSL_CTX structure, created
  7189. with wolfSSL_CTX_new().
  7190. \param ctx a pointer to the user context to be stored
  7191. _Example_
  7192. \code
  7193. none
  7194. \endcode
  7195. \sa wolfSSL_CTX_SetEccSignCb
  7196. \sa wolfSSL_CTX_GetEccSignCtx
  7197. */
  7198. void wolfSSL_CTX_SetEccSignCtx(WOLFSSL_CTX* ctx, void *userCtx);
  7199. /*!
  7200. \brief Allows caller to retrieve the Public Key Ecc Signing Callback
  7201. Context previously stored with wolfSSL_SetEccSignCtx().
  7202. \return pointer If successful the call will return a valid pointer
  7203. to the context.
  7204. \return NULL will be returned for a blank context.
  7205. \param ctx a pointer to a WOLFSSL_CTX structure, created
  7206. with wolfSSL_CTX_new().
  7207. _Example_
  7208. \code
  7209. none
  7210. \endcode
  7211. \sa wolfSSL_CTX_SetEccSignCb
  7212. \sa wolfSSL_CTX_SetEccSignCtx
  7213. */
  7214. void* wolfSSL_CTX_GetEccSignCtx(WOLFSSL_CTX* ctx);
  7215. /*!
  7216. \brief Allows caller to set the Public Key Callback for ECC Verification.
  7217. The callback should return 0 for success or < 0 for an error.
  7218. The ssl and ctx pointers are available for the user’s convenience.
  7219. sig is the signature to verify and sigSz denotes the length of the
  7220. signature. hash is an input buffer containing the digest of the message
  7221. and hashSz denotes the length in bytes of the hash. result is an output
  7222. variable where the result of the verification should be stored, 1 for
  7223. success and 0 for failure. keyDer is the ECC Private key in ASN1
  7224. format and keySz is the length of the key in bytes. An example
  7225. callback can be found wolfssl/test.h myEccVerify().
  7226. \return none No returns.
  7227. \param none No parameters.
  7228. _Example_
  7229. \code
  7230. none
  7231. \endcode
  7232. \sa wolfSSL_SetEccVerifyCtx
  7233. \sa wolfSSL_GetEccVerifyCtx
  7234. */
  7235. void wolfSSL_CTX_SetEccVerifyCb(WOLFSSL_CTX* ctx, CallbackEccVerify cb);
  7236. /*!
  7237. \brief Allows caller to set the Public Key Ecc Verification Callback
  7238. Context to ctx.
  7239. \return none No returns.
  7240. \param none No parameters.
  7241. _Example_
  7242. \code
  7243. none
  7244. \endcode
  7245. \sa wolfSSL_CTX_SetEccVerifyCb
  7246. \sa wolfSSL_GetEccVerifyCtx
  7247. */
  7248. void wolfSSL_SetEccVerifyCtx(WOLFSSL* ssl, void *ctx);
  7249. /*!
  7250. \brief Allows caller to retrieve the Public Key Ecc Verification Callback
  7251. Context previously stored with wolfSSL_SetEccVerifyCtx().
  7252. \return pointer If successful the call will return a valid pointer to the
  7253. context.
  7254. \return NULL will be returned for a blank context.
  7255. \param none No parameters.
  7256. _Example_
  7257. \code
  7258. none
  7259. \endcode
  7260. \sa wolfSSL_CTX_SetEccVerifyCb
  7261. \sa wolfSSL_SetEccVerifyCtx
  7262. */
  7263. void* wolfSSL_GetEccVerifyCtx(WOLFSSL* ssl);
  7264. /*!
  7265. \brief Allows caller to set the Public Key Callback for RSA Signing.
  7266. The callback should return 0 for success or < 0 for an error.
  7267. The ssl and ctx pointers are available for the user’s convenience.
  7268. in is the input buffer to sign while inSz denotes the length of the input.
  7269. out is the output buffer where the result of the signature should be stored.
  7270. outSz is an input/output variable that specifies the size of the output
  7271. buffer upon invocation and the actual size of the signature should be
  7272. stored there before returning. keyDer is the RSA Private key in ASN1 format
  7273. and keySz is the length of the key in bytes. An example callback can be
  7274. found wolfssl/test.h myRsaSign().
  7275. \return none No returns.
  7276. \param none No parameters.
  7277. _Example_
  7278. \code
  7279. none
  7280. \endcode
  7281. \sa wolfSSL_SetRsaSignCtx
  7282. \sa wolfSSL_GetRsaSignCtx
  7283. */
  7284. void wolfSSL_CTX_SetRsaSignCb(WOLFSSL_CTX* ctx, CallbackRsaSign cb);
  7285. /*!
  7286. \brief Allows caller to set the Public Key RSA Signing Callback Context
  7287. to ctx.
  7288. \return none No Returns.
  7289. \param none No parameters.
  7290. _Example_
  7291. \code
  7292. none
  7293. \endcode
  7294. \sa wolfSSL_CTX_SetRsaSignCb
  7295. \sa wolfSSL_GetRsaSignCtx
  7296. */
  7297. void wolfSSL_SetRsaSignCtx(WOLFSSL* ssl, void *ctx);
  7298. /*!
  7299. \brief Allows caller to retrieve the Public Key RSA Signing Callback
  7300. Context previously stored with wolfSSL_SetRsaSignCtx().
  7301. \return pointer If successful the call will return a valid pointer to the
  7302. context.
  7303. \return NULL will be returned for a blank context.
  7304. \param none No parameters.
  7305. \param none No parameters.
  7306. _Example_
  7307. \code
  7308. none
  7309. \endcode
  7310. \sa wolfSSL_CTX_SetRsaSignCb
  7311. \sa wolfSSL_SetRsaSignCtx
  7312. */
  7313. void* wolfSSL_GetRsaSignCtx(WOLFSSL* ssl);
  7314. /*!
  7315. \brief Allows caller to set the Public Key Callback for RSA Verification.
  7316. The callback should return the number of plaintext bytes for success or
  7317. < 0 for an error. The ssl and ctx pointers are available for the user’s
  7318. convenience. sig is the signature to verify and sigSz denotes the length
  7319. of the signature. out should be set to the beginning of the verification
  7320. buffer after the decryption process and any padding. keyDer is the RSA
  7321. Public key in ASN1 format and keySz is the length of the key in bytes.
  7322. An example callback can be found wolfssl/test.h myRsaVerify().
  7323. \return none No returns.
  7324. \param none No parameters.
  7325. \sa wolfSSL_SetRsaVerifyCtx
  7326. \sa wolfSSL_GetRsaVerifyCtx
  7327. */
  7328. void wolfSSL_CTX_SetRsaVerifyCb(WOLFSSL_CTX* ctx, CallbackRsaVerify cb);
  7329. /*!
  7330. \brief Allows caller to set the Public Key RSA Verification Callback
  7331. Context to ctx.
  7332. \return none No returns.
  7333. \param none No parameters.
  7334. _Example_
  7335. \code
  7336. none
  7337. \endcode
  7338. \sa wolfSSL_CTX_SetRsaVerifyCb
  7339. \sa wolfSSL_GetRsaVerifyCtx
  7340. */
  7341. void wolfSSL_SetRsaVerifyCtx(WOLFSSL* ssl, void *ctx);
  7342. /*!
  7343. \brief Allows caller to retrieve the Public Key RSA Verification Callback
  7344. Context previously stored with wolfSSL_SetRsaVerifyCtx().
  7345. \return pointer If successful the call will return a valid pointer to
  7346. the context.
  7347. \return NULL will be returned for a blank context.
  7348. \param none No parameters.
  7349. _Example_
  7350. \code
  7351. none
  7352. \endcode
  7353. \sa wolfSSL_CTX_SetRsaVerifyCb
  7354. \sa wolfSSL_SetRsaVerifyCtx
  7355. */
  7356. void* wolfSSL_GetRsaVerifyCtx(WOLFSSL* ssl);
  7357. /*!
  7358. \brief Allows caller to set the Public Key Callback for RSA Public
  7359. Encrypt. The callback should return 0 for success or < 0 for an error.
  7360. The ssl and ctx pointers are available for the user’s convenience.
  7361. in is the input buffer to encrypt while inSz denotes the length of
  7362. the input. out is the output buffer where the result of the encryption
  7363. should be stored. outSz is an input/output variable that specifies
  7364. the size of the output buffer upon invocation and the actual size of
  7365. the encryption should be stored there before returning. keyDer is the
  7366. RSA Public key in ASN1 format and keySz is the length of the key in
  7367. bytes. An example callback can be found wolfssl/test.h myRsaEnc().
  7368. \return none No returns.
  7369. \param none No parameters.
  7370. _Examples_
  7371. \code
  7372. none
  7373. \endcode
  7374. \sa wolfSSL_SetRsaEncCtx
  7375. \sa wolfSSL_GetRsaEncCtx
  7376. */
  7377. void wolfSSL_CTX_SetRsaEncCb(WOLFSSL_CTX* ctx, CallbackRsaEnc cb);
  7378. /*!
  7379. \brief Allows caller to set the Public Key RSA Public Encrypt
  7380. Callback Context to ctx.
  7381. \return none No returns.
  7382. \param none No parameters.
  7383. _Example_
  7384. \code
  7385. none
  7386. \endcode
  7387. \sa wolfSSL_CTX_SetRsaEncCb
  7388. \sa wolfSSL_GetRsaEncCtx
  7389. */
  7390. void wolfSSL_SetRsaEncCtx(WOLFSSL* ssl, void *ctx);
  7391. /*!
  7392. \brief Allows caller to retrieve the Public Key RSA Public Encrypt
  7393. Callback Context previously stored with wolfSSL_SetRsaEncCtx().
  7394. \return pointer If successful the call will return a valid pointer
  7395. to the context.
  7396. \return NULL will be returned for a blank context.
  7397. \param none No parameters.
  7398. _Example_
  7399. \code
  7400. none
  7401. \endcode
  7402. \sa wolfSSL_CTX_SetRsaEncCb
  7403. \sa wolfSSL_SetRsaEncCtx
  7404. */
  7405. void* wolfSSL_GetRsaEncCtx(WOLFSSL* ssl);
  7406. /*!
  7407. \brief Allows caller to set the Public Key Callback for RSA Private
  7408. Decrypt. The callback should return the number of plaintext bytes
  7409. for success or < 0 for an error. The ssl and ctx pointers are available
  7410. for the user’s convenience. in is the input buffer to decrypt and inSz
  7411. denotes the length of the input. out should be set to the beginning
  7412. of the decryption buffer after the decryption process and any padding.
  7413. keyDer is the RSA Private key in ASN1 format and keySz is the length
  7414. of the key in bytes. An example callback can be found
  7415. wolfssl/test.h myRsaDec().
  7416. \return none No returns.
  7417. \param none No parameters.
  7418. _Example_
  7419. \code
  7420. none
  7421. \endcode
  7422. \sa wolfSSL_SetRsaDecCtx
  7423. \sa wolfSSL_GetRsaDecCtx
  7424. */
  7425. void wolfSSL_CTX_SetRsaDecCb(WOLFSSL_CTX* ctx, CallbackRsaDec cb);
  7426. /*!
  7427. \brief Allows caller to set the Public Key RSA Private Decrypt
  7428. Callback Context to ctx.
  7429. \return none No returns.
  7430. \param none No parameters.
  7431. _Example_
  7432. \code
  7433. none
  7434. \endcode
  7435. \sa wolfSSL_CTX_SetRsaDecCb
  7436. \sa wolfSSL_GetRsaDecCtx
  7437. */
  7438. void wolfSSL_SetRsaDecCtx(WOLFSSL* ssl, void *ctx);
  7439. /*!
  7440. \brief Allows caller to retrieve the Public Key RSA Private Decrypt
  7441. Callback Context previously stored with wolfSSL_SetRsaDecCtx().
  7442. \return pointer If successful the call will return a valid pointer
  7443. to the context.
  7444. \return NULL will be returned for a blank context.
  7445. \param none No parameters.
  7446. _Example_
  7447. \code
  7448. none
  7449. \endcode
  7450. \sa wolfSSL_CTX_SetRsaDecCb
  7451. \sa wolfSSL_SetRsaDecCtx
  7452. */
  7453. void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl);
  7454. /*!
  7455. \brief This function registers a callback with the SSL context
  7456. (WOLFSSL_CTX) to be called when a new CA certificate is loaded
  7457. into wolfSSL. The callback is given a buffer with the DER-encoded
  7458. certificate.
  7459. \return none No return.
  7460. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  7461. \param callback function to be registered as the CA callback for the
  7462. wolfSSL context, ctx. The signature of this function must follow that
  7463. as shown above in the Synopsis section.
  7464. _Example_
  7465. \code
  7466. WOLFSSL_CTX* ctx = 0;
  7467. // CA callback prototype
  7468. int MyCACallback(unsigned char *der, int sz, int type);
  7469. // Register the custom CA callback with the SSL context
  7470. wolfSSL_CTX_SetCACb(ctx, MyCACallback);
  7471. int MyCACallback(unsigned char* der, int sz, int type)
  7472. {
  7473. // custom CA callback function, DER-encoded cert
  7474. // located in “der” of size “sz” with type “type”
  7475. }
  7476. \endcode
  7477. \sa wolfSSL_CTX_load_verify_locations
  7478. */
  7479. void wolfSSL_CTX_SetCACb(WOLFSSL_CTX* ctx, CallbackCACache cb);
  7480. /*!
  7481. \ingroup CertManager
  7482. \brief Allocates and initializes a new Certificate Manager context.
  7483. This context may be used independent of SSL needs. It may be used to
  7484. load certificates, verify certificates, and check the revocation status.
  7485. \return WOLFSSL_CERT_MANAGER If successful the call will return a valid
  7486. WOLFSSL_CERT_MANAGER pointer.
  7487. \return NULL will be returned for an error state.
  7488. \param none No parameters.
  7489. \sa wolfSSL_CertManagerFree
  7490. */
  7491. WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew_ex(void* heap);
  7492. /*!
  7493. \ingroup CertManager
  7494. \brief Allocates and initializes a new Certificate Manager context.
  7495. This context may be used independent of SSL needs. It may be used to
  7496. load certificates, verify certificates, and check the revocation status.
  7497. \return WOLFSSL_CERT_MANAGER If successful the call will return a
  7498. valid WOLFSSL_CERT_MANAGER pointer.
  7499. \return NULL will be returned for an error state.
  7500. \param none No parameters.
  7501. _Example_
  7502. \code
  7503. #import <wolfssl/ssl.h>
  7504. WOLFSSL_CERT_MANAGER* cm;
  7505. cm = wolfSSL_CertManagerNew();
  7506. if (cm == NULL) {
  7507. // error creating new cert manager
  7508. }
  7509. \endcode
  7510. \sa wolfSSL_CertManagerFree
  7511. */
  7512. WOLFSSL_CERT_MANAGER* wolfSSL_CertManagerNew(void);
  7513. /*!
  7514. \ingroup CertManager
  7515. \brief Frees all resources associated with the Certificate Manager
  7516. context. Call this when you no longer need to use the Certificate Manager.
  7517. \return none
  7518. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7519. wolfSSL_CertManagerNew().
  7520. _Example_
  7521. \code
  7522. #include <wolfssl/ssl.h>
  7523. WOLFSSL_CERT_MANAGER* cm;
  7524. ...
  7525. wolfSSL_CertManagerFree(cm);
  7526. \endcode
  7527. \sa wolfSSL_CertManagerNew
  7528. */
  7529. void wolfSSL_CertManagerFree(WOLFSSL_CERT_MANAGER*);
  7530. /*!
  7531. \ingroup CertManager
  7532. \brief Specifies the locations for CA certificate loading into the
  7533. manager context. The PEM certificate CAfile may contain several
  7534. trusted CA certificates. If CApath is not NULL it specifies a
  7535. directory containing CA certificates in PEM format.
  7536. \return SSL_SUCCESS If successful the call will return.
  7537. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7538. \return SSL_BAD_FILE will be returned if the file doesn’t exist,
  7539. can’t be read, or is corrupted.
  7540. \return MEMORY_E will be returned if an out of memory condition occurs.
  7541. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7542. \return BAD_FUNC_ARG is the error that will be returned if a
  7543. pointer is not provided.
  7544. \return SSL_FATAL_ERROR - will be returned upon failure.
  7545. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created
  7546. using wolfSSL_CertManagerNew().
  7547. \param file pointer to the name of the file containing CA
  7548. certificates to load.
  7549. \param path pointer to the name of a directory path containing CA c
  7550. ertificates to load. The NULL pointer may be used if no
  7551. certificate directory is desired.
  7552. _Example_
  7553. \code
  7554. #include <wolfssl/ssl.h>
  7555. int ret = 0;
  7556. WOLFSSL_CERT_MANAGER* cm;
  7557. ...
  7558. ret = wolfSSL_CertManagerLoadCA(cm, “path/to/cert-file.pem”, 0);
  7559. if (ret != SSL_SUCCESS) {
  7560. // error loading CA certs into cert manager
  7561. }
  7562. \endcode
  7563. \sa wolfSSL_CertManagerVerify
  7564. */
  7565. int wolfSSL_CertManagerLoadCA(WOLFSSL_CERT_MANAGER* cm, const char* f,
  7566. const char* d);
  7567. /*!
  7568. \ingroup CertManager
  7569. \brief Loads the CA Buffer by calling wolfSSL_CTX_load_verify_buffer and
  7570. returning that result using a temporary cm so as not to lose the information
  7571. in the cm passed into the function.
  7572. \return SSL_FATAL_ERROR is returned if the WOLFSSL_CERT_MANAGER struct is
  7573. NULL or if wolfSSL_CTX_new() returns NULL.
  7574. \return SSL_SUCCESS is returned for a successful execution.
  7575. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7576. wolfSSL_CertManagerNew().
  7577. \param in buffer for cert information.
  7578. \param sz length of the buffer.
  7579. \param format certificate format, either PEM or DER.
  7580. _Example_
  7581. \code
  7582. WOLFSSL_CERT_MANAGER* cm = (WOLFSSL_CERT_MANAGER*)vp;
  7583. const unsigned char* in;
  7584. long sz;
  7585. int format;
  7586. if(wolfSSL_CertManagerLoadCABuffer(vp, sz, format) != SSL_SUCCESS){
  7587. Error returned. Failure case code block.
  7588. }
  7589. \endcode
  7590. \sa wolfSSL_CTX_load_verify_buffer
  7591. \sa ProcessChainBuffer
  7592. \sa ProcessBuffer
  7593. \sa cm_pick_method
  7594. */
  7595. int wolfSSL_CertManagerLoadCABuffer(WOLFSSL_CERT_MANAGER* cm,
  7596. const unsigned char* in, long sz, int format);
  7597. /*!
  7598. \ingroup CertManager
  7599. \brief This function unloads the CA signer list.
  7600. \return SSL_SUCCESS returned on successful execution of the function.
  7601. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7602. \return BAD_MUTEX_E returned if there was a mutex error.
  7603. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure,
  7604. created using wolfSSL_CertManagerNew().
  7605. _Example_
  7606. \code
  7607. #include <wolfssl/ssl.h>
  7608. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7609. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7610. ...
  7611. if(wolfSSL_CertManagerUnloadCAs(ctx->cm) != SSL_SUCCESS){
  7612. Failure case.
  7613. }
  7614. \endcode
  7615. \sa FreeSignerTable
  7616. \sa UnlockMutex
  7617. */
  7618. int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm);
  7619. /*!
  7620. \ingroup CertManager
  7621. \brief The function will free the Trusted Peer linked list and unlocks
  7622. the trusted peer list.
  7623. \return SSL_SUCCESS if the function completed normally.
  7624. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7625. \return BAD_MUTEX_E mutex error if tpLock, a member of the
  7626. WOLFSSL_CERT_MANAGER struct, is 0 (nill).
  7627. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7628. wolfSSL_CertManagerNew().
  7629. _Example_
  7630. \code
  7631. #include <wolfssl/ssl.h>
  7632. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7633. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7634. ...
  7635. if(wolfSSL_CertManagerUnload_trust_peers(cm) != SSL_SUCCESS){
  7636. The function did not execute successfully.
  7637. }
  7638. \endcode
  7639. \sa UnLockMutex
  7640. */
  7641. int wolfSSL_CertManagerUnload_trust_peers(WOLFSSL_CERT_MANAGER* cm);
  7642. /*!
  7643. \ingroup CertManager
  7644. \brief Specifies the certificate to verify with the Certificate Manager
  7645. context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7646. \return SSL_SUCCESS If successful.
  7647. \return ASN_SIG_CONFIRM_E will be returned if the signature could not be
  7648. verified.
  7649. \return ASN_SIG_OID_E will be returned if the signature type is not
  7650. supported.
  7651. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7652. has been revoked.
  7653. \return CRL_MISSING is an error that is returned if a current issuer CRL is
  7654. not available.
  7655. \return ASN_BEFORE_DATE_E will be returned if the current date is before the
  7656. before date.
  7657. \return ASN_AFTER_DATE_E will be returned if the current date is after the
  7658. after date.
  7659. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7660. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t be
  7661. read, or is corrupted.
  7662. \return MEMORY_E will be returned if an out of memory condition occurs.
  7663. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7664. \return BAD_FUNC_ARG is the error that will be returned if a pointer is
  7665. not provided.
  7666. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7667. wolfSSL_CertManagerNew().
  7668. \param fname pointer to the name of the file containing the certificates
  7669. to verify.
  7670. \param format format of the certificate to verify - either
  7671. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7672. _Example_
  7673. \code
  7674. int ret = 0;
  7675. WOLFSSL_CERT_MANAGER* cm;
  7676. ...
  7677. ret = wolfSSL_CertManagerVerify(cm, “path/to/cert-file.pem”,
  7678. SSL_FILETYPE_PEM);
  7679. if (ret != SSL_SUCCESS) {
  7680. error verifying certificate
  7681. }
  7682. \endcode
  7683. \sa wolfSSL_CertManagerLoadCA
  7684. \sa wolfSSL_CertManagerVerifyBuffer
  7685. */
  7686. int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER* cm, const char* f,
  7687. int format);
  7688. /*!
  7689. \ingroup CertManager
  7690. \brief Specifies the certificate buffer to verify with the Certificate
  7691. Manager context. The format can be SSL_FILETYPE_PEM or SSL_FILETYPE_ASN1.
  7692. \return SSL_SUCCESS If successful.
  7693. \return ASN_SIG_CONFIRM_E will be returned if the signature could not
  7694. be verified.
  7695. \return ASN_SIG_OID_E will be returned if the signature type is not
  7696. supported.
  7697. \return CRL_CERT_REVOKED is an error that is returned if this certificate
  7698. has been revoked.
  7699. \return CRL_MISSING is an error that is returned if a current issuer CRL
  7700. is not available.
  7701. \return ASN_BEFORE_DATE_E will be returned if the current date is before
  7702. the before date.
  7703. \return ASN_AFTER_DATE_E will be returned if the current date is after
  7704. the after date.
  7705. \return SSL_BAD_FILETYPE will be returned if the file is the wrong format.
  7706. \return SSL_BAD_FILE will be returned if the file doesn’t exist, can’t
  7707. be read, or is corrupted.
  7708. \return MEMORY_E will be returned if an out of memory condition occurs.
  7709. \return ASN_INPUT_E will be returned if Base16 decoding fails on the file.
  7710. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7711. is not provided.
  7712. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7713. wolfSSL_CertManagerNew().
  7714. \param buff buffer containing the certificates to verify.
  7715. \param sz size of the buffer, buf.
  7716. \param format format of the certificate to verify, located in buf - either
  7717. SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
  7718. _Example_
  7719. \code
  7720. #include <wolfssl/ssl.h>
  7721. int ret = 0;
  7722. int sz = 0;
  7723. WOLFSSL_CERT_MANAGER* cm;
  7724. byte certBuff[...];
  7725. ...
  7726. ret = wolfSSL_CertManagerVerifyBuffer(cm, certBuff, sz, SSL_FILETYPE_PEM);
  7727. if (ret != SSL_SUCCESS) {
  7728. error verifying certificate
  7729. }
  7730. \endcode
  7731. \sa wolfSSL_CertManagerLoadCA
  7732. \sa wolfSSL_CertManagerVerify
  7733. */
  7734. int wolfSSL_CertManagerVerifyBuffer(WOLFSSL_CERT_MANAGER* cm,
  7735. const unsigned char* buff, long sz, int format);
  7736. /*!
  7737. \ingroup CertManager
  7738. \brief The function sets the verifyCallback function in the Certificate
  7739. Manager. If present, it will be called for each cert loaded. If there is
  7740. a verification error, the verify callback can be used to over-ride the
  7741. error.
  7742. \return none No return.
  7743. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7744. wolfSSL_CertManagerNew().
  7745. \param vc a VerifyCallback function pointer to the callback routine
  7746. _Example_
  7747. \code
  7748. #include <wolfssl/ssl.h>
  7749. int myVerify(int preverify, WOLFSSL_X509_STORE_CTX* store)
  7750. { // do custom verification of certificate }
  7751. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(Protocol define);
  7752. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7753. ...
  7754. wolfSSL_CertManagerSetVerify(cm, myVerify);
  7755. \endcode
  7756. \sa wolfSSL_CertManagerVerify
  7757. */
  7758. void wolfSSL_CertManagerSetVerify(WOLFSSL_CERT_MANAGER* cm,
  7759. VerifyCallback vc);
  7760. /*!
  7761. \brief Check CRL if the option is enabled and compares the cert to the
  7762. CRL list.
  7763. \return SSL_SUCCESS returns if the function returned as expected. If
  7764. the crlEnabled member of the WOLFSSL_CERT_MANAGER struct is turned on.
  7765. \return MEMORY_E returns if the allocated memory failed.
  7766. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER is NULL.
  7767. \param cm a pointer to a WOLFSSL_CERT_MANAGER struct.
  7768. \param der pointer to a DER formatted certificate.
  7769. \param sz size of the certificate.
  7770. _Example_
  7771. \code
  7772. WOLFSSL_CERT_MANAGER* cm;
  7773. byte* der;
  7774. int sz; // size of der
  7775. ...
  7776. if(wolfSSL_CertManagerCheckCRL(cm, der, sz) != SSL_SUCCESS){
  7777. // Error returned. Deal with failure case.
  7778. }
  7779. \endcode
  7780. \sa CheckCertCRL
  7781. \sa ParseCertRelative
  7782. \sa wolfSSL_CertManagerSetCRL_CB
  7783. \sa InitDecodedCert
  7784. */
  7785. int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
  7786. unsigned char* der, int sz);
  7787. /*!
  7788. \ingroup CertManager
  7789. \brief Turns on Certificate Revocation List checking when verifying
  7790. certificates with the Certificate Manager. By default, CRL checking
  7791. is off. options include WOLFSSL_CRL_CHECKALL which performs CRL
  7792. checking on each certificate in the chain versus the Leaf certificate
  7793. only which is the default.
  7794. \return SSL_SUCCESS If successful the call will return.
  7795. \return NOT_COMPILED_IN will be returned if wolfSSL was not built with
  7796. CRL enabled.
  7797. \return MEMORY_E will be returned if an out of memory condition occurs.
  7798. \return BAD_FUNC_ARG is the error that will be returned if a pointer
  7799. is not provided.
  7800. \return SSL_FAILURE will be returned if the CRL context cannot be
  7801. initialized properly.
  7802. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7803. wolfSSL_CertManagerNew().
  7804. \param options options to use when enabling the Certification Manager, cm.
  7805. _Example_
  7806. \code
  7807. #include <wolfssl/ssl.h>
  7808. int ret = 0;
  7809. WOLFSSL_CERT_MANAGER* cm;
  7810. ...
  7811. ret = wolfSSL_CertManagerEnableCRL(cm, 0);
  7812. if (ret != SSL_SUCCESS) {
  7813. error enabling cert manager
  7814. }
  7815. ...
  7816. \endcode
  7817. \sa wolfSSL_CertManagerDisableCRL
  7818. */
  7819. int wolfSSL_CertManagerEnableCRL(WOLFSSL_CERT_MANAGER* cm,
  7820. int options);
  7821. /*!
  7822. \ingroup CertManager
  7823. \brief Turns off Certificate Revocation List checking when verifying
  7824. certificates with the Certificate Manager. By default, CRL checking is
  7825. off. You can use this function to temporarily or permanently disable CRL
  7826. checking with this Certificate Manager context that previously had CRL
  7827. checking enabled.
  7828. \return SSL_SUCCESS If successful the call will return.
  7829. \return BAD_FUNC_ARG is the error that will be returned if a function
  7830. pointer is not provided.
  7831. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7832. wolfSSL_CertManagerNew().
  7833. _Example_
  7834. \code
  7835. #include <wolfssl/ssl.h>
  7836. int ret = 0;
  7837. WOLFSSL_CERT_MANAGER* cm;
  7838. ...
  7839. ret = wolfSSL_CertManagerDisableCRL(cm);
  7840. if (ret != SSL_SUCCESS) {
  7841. error disabling cert manager
  7842. }
  7843. ...
  7844. \endcode
  7845. \sa wolfSSL_CertManagerEnableCRL
  7846. */
  7847. int wolfSSL_CertManagerDisableCRL(WOLFSSL_CERT_MANAGER*);
  7848. /*!
  7849. \ingroup CertManager
  7850. \brief Error checks and passes through to LoadCRL() in order to load the
  7851. cert into the CRL for revocation checking.
  7852. \return SSL_SUCCESS if there is no error in wolfSSL_CertManagerLoadCRL and
  7853. if LoadCRL returns successfully.
  7854. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER struct is NULL.
  7855. \return SSL_FATAL_ERROR if wolfSSL_CertManagerEnableCRL returns anything
  7856. other than SSL_SUCCESS.
  7857. \return BAD_PATH_ERROR if the path is NULL.
  7858. \return MEMORY_E if LoadCRL fails to allocate heap memory.
  7859. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7860. wolfSSL_CertManagerNew().
  7861. \param path a constant char pointer holding the CRL path.
  7862. \param type type of certificate to be loaded.
  7863. \param monitor requests monitoring in LoadCRL().
  7864. _Example_
  7865. \code
  7866. #include <wolfssl/ssl.h>
  7867. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type,
  7868. int monitor);
  7869. wolfSSL_CertManagerLoadCRL(SSL_CM(ssl), path, type, monitor);
  7870. \endcode
  7871. \sa wolfSSL_CertManagerEnableCRL
  7872. \sa wolfSSL_LoadCRL
  7873. */
  7874. int wolfSSL_CertManagerLoadCRL(WOLFSSL_CERT_MANAGER* cm,
  7875. const char* path, int type, int monitor);
  7876. /*!
  7877. \ingroup CertManager
  7878. \brief The function loads the CRL file by calling BufferLoadCRL.
  7879. \return SSL_SUCCESS returned if the function completed without errors.
  7880. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  7881. \return SSL_FATAL_ERROR returned if there is an error associated
  7882. with the WOLFSSL_CERT_MANAGER.
  7883. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  7884. \param buff a constant byte type and is the buffer.
  7885. \param sz a long int representing the size of the buffer.
  7886. \param type a long integer that holds the certificate type.
  7887. _Example_
  7888. \code
  7889. #include <wolfssl/ssl.h>
  7890. WOLFSSL_CERT_MANAGER* cm;
  7891. const unsigned char* buff;
  7892. long sz; size of buffer
  7893. int type; cert type
  7894. ...
  7895. int ret = wolfSSL_CertManagerLoadCRLBuffer(cm, buff, sz, type);
  7896. if(ret == SSL_SUCCESS){
  7897. return ret;
  7898. } else {
  7899. Failure case.
  7900. }
  7901. \endcode
  7902. \sa BufferLoadCRL
  7903. \sa wolfSSL_CertManagerEnableCRL
  7904. */
  7905. int wolfSSL_CertManagerLoadCRLBuffer(WOLFSSL_CERT_MANAGER* cm,
  7906. const unsigned char* buff, long sz,
  7907. int type);
  7908. /*!
  7909. \ingroup CertManager
  7910. \brief This function sets the CRL Certificate Manager callback. If
  7911. HAVE_CRL is defined and a matching CRL record is not found then the
  7912. cbMissingCRL is called (set via wolfSSL_CertManagerSetCRL_Cb). This
  7913. allows you to externally retrieve the CRL and load it.
  7914. \return SSL_SUCCESS returned upon successful execution of the function and
  7915. subroutines.
  7916. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is NULL.
  7917. \param cm the WOLFSSL_CERT_MANAGER structure holding the information for
  7918. the certificate.
  7919. \param cb a function pointer to (*CbMissingCRL) that is set to the
  7920. cbMissingCRL member of the WOLFSSL_CERT_MANAGER.
  7921. _Example_
  7922. \code
  7923. #include <wolfssl/ssl.h>
  7924. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7925. WOLFSSL* ssl = wolfSSL_new(ctx);
  7926. void cb(const char* url){
  7927. Function body.
  7928. }
  7929. CbMissingCRL cb = CbMissingCRL;
  7930. if(ctx){
  7931. return wolfSSL_CertManagerSetCRL_Cb(SSL_CM(ssl), cb);
  7932. }
  7933. \endcode
  7934. \sa CbMissingCRL
  7935. \sa wolfSSL_SetCRL_Cb
  7936. */
  7937. int wolfSSL_CertManagerSetCRL_Cb(WOLFSSL_CERT_MANAGER* cm,
  7938. CbMissingCRL cb);
  7939. /*!
  7940. \ingroup CertManager
  7941. \brief The function enables the WOLFSSL_CERT_MANAGER’s member, ocspEnabled
  7942. to signify that the OCSP check option is enabled.
  7943. \return SSL_SUCCESS returned on successful execution of the function. The
  7944. ocspEnabled member of the WOLFSSL_CERT_MANAGER is enabled.
  7945. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  7946. NULL or if an argument value that is not allowed is passed to a subroutine.
  7947. \return MEMORY_E returned if there is an error allocating memory within
  7948. this function or a subroutine.
  7949. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7950. wolfSSL_CertManagerNew().
  7951. \param der a byte pointer to the certificate.
  7952. \param sz an int type representing the size of the DER cert.
  7953. _Example_
  7954. \code
  7955. #import <wolfssl/ssl.h>
  7956. WOLFSSL* ssl = wolfSSL_new(ctx);
  7957. byte* der;
  7958. int sz; size of der
  7959. ...
  7960. if(wolfSSL_CertManagerCheckOCSP(cm, der, sz) != SSL_SUCCESS){
  7961. Failure case.
  7962. }
  7963. \endcode
  7964. \sa ParseCertRelative
  7965. \sa CheckCertOCSP
  7966. */
  7967. int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
  7968. unsigned char* der, int sz);
  7969. /*!
  7970. \ingroup CertManager
  7971. \brief Turns on OCSP if it’s turned off and if compiled with the
  7972. set option available.
  7973. \return SSL_SUCCESS returned if the function call is successful.
  7974. \return BAD_FUNC_ARG if cm struct is NULL.
  7975. \return MEMORY_E if WOLFSSL_OCSP struct value is NULL.
  7976. \return SSL_FAILURE initialization of WOLFSSL_OCSP struct fails
  7977. to initialize.
  7978. \return NOT_COMPILED_IN build not compiled with correct feature enabled.
  7979. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, created using
  7980. wolfSSL_CertManagerNew().
  7981. \param options used to set values in WOLFSSL_CERT_MANAGER struct.
  7982. _Example_
  7983. \code
  7984. #include <wolfssl/ssl.h>
  7985. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
  7986. WOLFSSL* ssl = wolfSSL_new(ctx);
  7987. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  7988. int options;
  7989. if(wolfSSL_CertManagerEnableOCSP(SSL_CM(ssl), options) != SSL_SUCCESS){
  7990. Failure case.
  7991. }
  7992. \endcode
  7993. \sa wolfSSL_CertManagerNew
  7994. */
  7995. int wolfSSL_CertManagerEnableOCSP(WOLFSSL_CERT_MANAGER* cm,
  7996. int options);
  7997. /*!
  7998. \ingroup CertManager
  7999. \brief Disables OCSP certificate revocation.
  8000. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled the
  8001. crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8002. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  8003. \param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8004. _Example_
  8005. \code
  8006. #include <wolfssl/ssl.h>
  8007. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(method);
  8008. WOLFSSL* ssl = wolfSSL_new(ctx);
  8009. ...
  8010. if(wolfSSL_CertManagerDisableOCSP(ssl) != SSL_SUCCESS){
  8011. Fail case.
  8012. }
  8013. \endcode
  8014. \sa wolfSSL_DisableCRL
  8015. */
  8016. int wolfSSL_CertManagerDisableOCSP(WOLFSSL_CERT_MANAGER*);
  8017. /*!
  8018. \ingroup CertManager
  8019. \brief The function copies the url to the ocspOverrideURL member of the
  8020. WOLFSSL_CERT_MANAGER structure.
  8021. \return SSL_SUCCESS the function was able to execute as expected.
  8022. \return BAD_FUNC_ARG the WOLFSSL_CERT_MANAGER struct is NULL.
  8023. \return MEMEORY_E Memory was not able to be allocated for the
  8024. ocspOverrideURL member of the certificate manager.
  8025. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8026. _Example_
  8027. \code
  8028. #include <wolfssl/ssl.h>
  8029. WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
  8030. const char* url;
  8031. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url)
  8032. if(wolfSSL_CertManagerSetOCSPOverrideURL(SSL_CM(ssl), url) != SSL_SUCCESS){
  8033. Failure case.
  8034. }
  8035. \endcode
  8036. \sa ocspOverrideURL
  8037. \sa wolfSSL_SetOCSP_OverrideURL
  8038. */
  8039. int wolfSSL_CertManagerSetOCSPOverrideURL(WOLFSSL_CERT_MANAGER* cm,
  8040. const char* url);
  8041. /*!
  8042. \ingroup CertManager
  8043. \brief The function sets the OCSP callback in the WOLFSSL_CERT_MANAGER.
  8044. \return SSL_SUCCESS returned on successful execution. The arguments are
  8045. saved in the WOLFSSL_CERT_MANAGER structure.
  8046. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
  8047. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure.
  8048. \param ioCb a function pointer of type CbOCSPIO.
  8049. \param respFreeCb - a function pointer of type CbOCSPRespFree.
  8050. \param ioCbCtx - a void pointer variable to the I/O callback user
  8051. registered context.
  8052. _Example_
  8053. \code
  8054. #include <wolfssl/ssl.h>
  8055. wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb,
  8056. CbOCSPRespFree respFreeCb, void* ioCbCtx){
  8057. return wolfSSL_CertManagerSetOCSP_Cb(SSL_CM(ssl), ioCb, respFreeCb, ioCbCtx);
  8058. \endcode
  8059. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  8060. \sa wolfSSL_CertManagerCheckOCSP
  8061. \sa wolfSSL_CertManagerEnableOCSPStapling
  8062. \sa wolfSSL_ENableOCSP
  8063. \sa wolfSSL_DisableOCSP
  8064. \sa wolfSSL_SetOCSP_Cb
  8065. */
  8066. int wolfSSL_CertManagerSetOCSP_Cb(WOLFSSL_CERT_MANAGER* cm,
  8067. CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8068. void* ioCbCtx);
  8069. /*!
  8070. \ingroup CertManager
  8071. \brief This function turns on OCSP stapling if it is not turned on as well
  8072. as set the options.
  8073. \return SSL_SUCCESS returned if there were no errors and the function
  8074. executed successfully.
  8075. \return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER structure is
  8076. NULL or otherwise if there was a unpermitted argument value passed to
  8077. a subroutine.
  8078. \return MEMORY_E returned if there was an issue allocating memory.
  8079. \return SSL_FAILURE returned if the initialization of the OCSP
  8080. structure failed.
  8081. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  8082. HAVE_CERTIFICATE_STATUS_REQUEST option.
  8083. \param cm a pointer to a WOLFSSL_CERT_MANAGER structure, a member of the
  8084. WOLFSSL_CTX structure.
  8085. _Example_
  8086. \code
  8087. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX* ctx){
  8088. return wolfSSL_CertManagerEnableOCSPStapling(ctx->cm);
  8089. \endcode
  8090. \sa wolfSSL_CTX_EnableOCSPStapling
  8091. */
  8092. int wolfSSL_CertManagerEnableOCSPStapling(
  8093. WOLFSSL_CERT_MANAGER* cm);
  8094. /*!
  8095. \brief Enables CRL certificate revocation.
  8096. \return SSL_SUCCESS the function and subroutines returned with no errors.
  8097. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  8098. \return MEMORY_E returned if the allocation of memory failed.
  8099. \return SSL_FAILURE returned if the InitCRL function does not return
  8100. successfully.
  8101. \return NOT_COMPILED_IN HAVE_CRL was not enabled during the compiling.
  8102. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8103. \param options an integer that is used to determine the setting of
  8104. crlCheckAll member of the WOLFSSL_CERT_MANAGER structure.
  8105. _Example_
  8106. \code
  8107. WOLFSSL* ssl = wolfSSL_new(ctx);
  8108. if (wolfSSL_EnableCRL(ssl, WOLFSSL_CRL_CHECKALL) != SSL_SUCCESS){
  8109. // Failure case. SSL_SUCCESS was not returned by this function or
  8110. a subroutine
  8111. }
  8112. \endcode
  8113. \sa wolfSSL_CertManagerEnableCRL
  8114. \sa InitCRL
  8115. */
  8116. int wolfSSL_EnableCRL(WOLFSSL* ssl, int options);
  8117. /*!
  8118. \brief Disables CRL certificate revocation.
  8119. \return SSL_SUCCESS wolfSSL_CertMangerDisableCRL successfully disabled
  8120. the crlEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8121. \return BAD_FUNC_ARG the WOLFSSL structure was NULL.
  8122. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8123. _Example_
  8124. \code
  8125. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8126. WOLFSSL* ssl = wolfSSL_new(ctx);
  8127. ...
  8128. if(wolfSSL_DisableCRL(ssl) != SSL_SUCCESS){
  8129. // Failure case
  8130. }
  8131. \endcode
  8132. \sa wolfSSL_CertManagerDisableCRL
  8133. \sa wolfSSL_CertManagerDisableOCSP
  8134. */
  8135. int wolfSSL_DisableCRL(WOLFSSL* ssl);
  8136. /*!
  8137. \brief A wrapper function that ends up calling LoadCRL to load the
  8138. certificate for revocation checking.
  8139. \return WOLFSSL_SUCCESS returned if the function and all of the
  8140. subroutines executed without error.
  8141. \return SSL_FATAL_ERROR returned if one of the subroutines does not
  8142. return successfully.
  8143. \return BAD_FUNC_ARG if the WOLFSSL_CERT_MANAGER or the WOLFSSL
  8144. structure are NULL.
  8145. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8146. \param path a constant character pointer that holds the path to the
  8147. crl file.
  8148. \param type an integer representing the type of certificate.
  8149. \param monitor an integer variable used to verify the monitor path if
  8150. requested.
  8151. _Example_
  8152. \code
  8153. WOLFSSL* ssl = wolfSSL_new(ctx);
  8154. const char* crlPemDir;
  8155. if(wolfSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, 0) != SSL_SUCCESS){
  8156. // Failure case. Did not return SSL_SUCCESS.
  8157. }
  8158. \endcode
  8159. \sa wolfSSL_CertManagerLoadCRL
  8160. \sa wolfSSL_CertManagerEnableCRL
  8161. \sa LoadCRL
  8162. */
  8163. int wolfSSL_LoadCRL(WOLFSSL* ssl, const char* path, int type, int monitor);
  8164. /*!
  8165. \brief Sets the CRL callback in the WOLFSSL_CERT_MANAGER structure.
  8166. \return SSL_SUCCESS returned if the function or subroutine executes
  8167. without error. The cbMissingCRL member of the WOLFSSL_CERT_MANAGER is set.
  8168. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  8169. structure is NULL.
  8170. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8171. \param cb a function pointer to CbMissingCRL.
  8172. _Example_
  8173. \code
  8174. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8175. WOLFSSL* ssl = wolfSSL_new(ctx);
  8176. void cb(const char* url) // required signature
  8177. {
  8178. // Function body
  8179. }
  8180. int crlCb = wolfSSL_SetCRL_Cb(ssl, cb);
  8181. if(crlCb != SSL_SUCCESS){
  8182. // The callback was not set properly
  8183. }
  8184. \endcode
  8185. \sa CbMissingCRL
  8186. \sa wolfSSL_CertManagerSetCRL_Cb
  8187. */
  8188. int wolfSSL_SetCRL_Cb(WOLFSSL* ssl, CbMissingCRL cb);
  8189. /*!
  8190. \brief This function enables OCSP certificate verification.
  8191. \return SSL_SUCCESS returned if the function and subroutines executes
  8192. without errors.
  8193. \return BAD_FUNC_ARG returned if an argument in this function or any
  8194. subroutine receives an invalid argument value.
  8195. \return MEMORY_E returned if there was an error allocating memory for
  8196. a structure or other variable.
  8197. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with the
  8198. HAVE_OCSP option.
  8199. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8200. \param options an integer type passed to wolfSSL_CertMangerENableOCSP()
  8201. used for settings check.
  8202. _Example_
  8203. \code
  8204. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8205. WOLFSSL* ssl = wolfSSL_new(ctx);
  8206. int options; // initialize to option constant
  8207. int ret = wolfSSL_EnableOCSP(ssl, options);
  8208. if(ret != SSL_SUCCESS){
  8209. // OCSP is not enabled
  8210. }
  8211. \endcode
  8212. \sa wolfSSL_CertManagerEnableOCSP
  8213. */
  8214. int wolfSSL_EnableOCSP(WOLFSSL* ssl, int options);
  8215. /*!
  8216. \brief Disables the OCSP certificate revocation option.
  8217. \return SSL_SUCCESS returned if the function and its subroutine return with
  8218. no errors. The ocspEnabled member of the WOLFSSL_CERT_MANAGER structure was
  8219. successfully set.
  8220. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  8221. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8222. _Example_
  8223. \code
  8224. WOLFSSL* ssl = wolfSSL_new(ctx);
  8225. if(wolfSSL_DisableOCSP(ssl) != SSL_SUCCESS){
  8226. // Returned with an error. Failure case in this block.
  8227. }
  8228. \endcode
  8229. \sa wolfSSL_CertManagerDisableOCSP
  8230. */
  8231. int wolfSSL_DisableOCSP(WOLFSSL*);
  8232. /*!
  8233. \brief This function sets the ocspOverrideURL member in the
  8234. WOLFSSL_CERT_MANAGER structure.
  8235. \return SSL_SUCCESS returned on successful execution of the function.
  8236. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL or if a
  8237. unpermitted argument was passed to a subroutine.
  8238. \return MEMORY_E returned if there was an error allocating memory in the
  8239. subroutine.
  8240. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8241. \param url a constant char pointer to the url that will be stored in the
  8242. ocspOverrideURL member of the WOLFSSL_CERT_MANAGER structure.
  8243. _Example_
  8244. \code
  8245. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8246. WOLFSSL* ssl = wolfSSL_new(ctx);
  8247. char url[URLSZ];
  8248. ...
  8249. if(wolfSSL_SetOCSP_OverrideURL(ssl, url)){
  8250. // The override url is set to the new value
  8251. }
  8252. \endcode
  8253. \sa wolfSSL_CertManagerSetOCSPOverrideURL
  8254. */
  8255. int wolfSSL_SetOCSP_OverrideURL(WOLFSSL* ssl, const char* url);
  8256. /*!
  8257. \brief This function sets the OCSP callback in the
  8258. WOLFSSL_CERT_MANAGER structure.
  8259. \return SSL_SUCCESS returned if the function executes without error.
  8260. The ocspIOCb, ocspRespFreeCb, and ocspIOCtx members of the CM are set.
  8261. \return BAD_FUNC_ARG returned if the WOLFSSL or WOLFSSL_CERT_MANAGER
  8262. structures are NULL.
  8263. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8264. \param ioCb a function pointer to type CbOCSPIO.
  8265. \param respFreeCb a function pointer to type CbOCSPRespFree which is the
  8266. call to free the response memory.
  8267. \param ioCbCtx a void pointer that will be held in the ocspIOCtx member
  8268. of the CM.
  8269. _Example_
  8270. \code
  8271. WOLFSSL* ssl = wolfSSL_new(ctx);
  8272. int OCSPIO_CB(void* , const char*, int , unsigned char* , int,
  8273. unsigned char**){ // must have this signature
  8274. // Function Body
  8275. }
  8276. void OCSPRespFree_CB(void* , unsigned char* ){ // must have this signature
  8277. // function body
  8278. }
  8279. void* ioCbCtx;
  8280. CbOCSPRespFree CB_OCSPRespFree;
  8281. if(wolfSSL_SetOCSP_Cb(ssl, OCSPIO_CB( pass args ), CB_OCSPRespFree,
  8282. ioCbCtx) != SSL_SUCCESS){
  8283. // Callback not set
  8284. }
  8285. \endcode
  8286. \sa wolfSSL_CertManagerSetOCSP_Cb
  8287. \sa CbOCSPIO
  8288. \sa CbOCSPRespFree
  8289. */
  8290. int wolfSSL_SetOCSP_Cb(WOLFSSL* ssl, CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8291. void* ioCbCtx);
  8292. /*!
  8293. \brief Enables CRL certificate verification through the CTX.
  8294. \return SSL_SUCCESS returned if this function and it’s subroutines
  8295. execute without errors.
  8296. \return BAD_FUNC_ARG returned if the CTX struct is NULL or there
  8297. was otherwise an invalid argument passed in a subroutine.
  8298. \return MEMORY_E returned if there was an error allocating
  8299. memory during execution of the function.
  8300. \return SSL_FAILURE returned if the crl member of the
  8301. WOLFSSL_CERT_MANAGER fails to initialize correctly.
  8302. \return NOT_COMPILED_IN wolfSSL was not compiled with the HAVE_CRL option.
  8303. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8304. _Example_
  8305. \code
  8306. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8307. WOLFSSL* ssl = wolfSSL_new(ctx);
  8308. ...
  8309. if(wolfSSL_CTX_EnableCRL(ssl->ctx, options) != SSL_SUCCESS){
  8310. // The function failed
  8311. }
  8312. \endcode
  8313. \sa wolfSSL_CertManagerEnableCRL
  8314. \sa InitCRL
  8315. \sa wolfSSL_CTX_DisableCRL
  8316. */
  8317. int wolfSSL_CTX_EnableCRL(WOLFSSL_CTX* ctx, int options);
  8318. /*!
  8319. \brief This function disables CRL verification in the CTX structure.
  8320. \return SSL_SUCCESS returned if the function executes without error.
  8321. The crlEnabled member of the WOLFSSL_CERT_MANAGER struct is set to 0.
  8322. \return BAD_FUNC_ARG returned if either the CTX struct or the CM
  8323. struct has a NULL value.
  8324. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8325. wolfSSL_CTX_new().
  8326. _Example_
  8327. \code
  8328. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8329. WOLFSSL* ssl = wolfSSL_new(ctx);
  8330. ...
  8331. if(wolfSSL_CTX_DisableCRL(ssl->ctx) != SSL_SUCCESS){
  8332. // Failure case.
  8333. }
  8334. \endcode
  8335. \sa wolfSSL_CertManagerDisableCRL
  8336. */
  8337. int wolfSSL_CTX_DisableCRL(WOLFSSL_CTX* ctx);
  8338. /*!
  8339. \brief This function loads CRL into the WOLFSSL_CTX structure through
  8340. wolfSSL_CertManagerLoadCRL().
  8341. \return SSL_SUCCESS - returned if the function and its subroutines
  8342. execute without error.
  8343. \return BAD_FUNC_ARG - returned if this function or any subroutines
  8344. are passed NULL structures.
  8345. \return BAD_PATH_ERROR - returned if the path variable opens as NULL.
  8346. \return MEMORY_E - returned if an allocation of memory failed.
  8347. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8348. wolfSSL_CTX_new().
  8349. \param path the path to the certificate.
  8350. \param type an integer variable holding the type of certificate.
  8351. \param monitor an integer variable used to determine if the monitor
  8352. path is requested.
  8353. _Example_
  8354. \code
  8355. WOLFSSL_CTX* ctx;
  8356. const char* path;
  8357. return wolfSSL_CTX_LoadCRL(ctx, path, SSL_FILETYPE_PEM, 0);
  8358. \endcode
  8359. \sa wolfSSL_CertManagerLoadCRL
  8360. \sa LoadCRL
  8361. */
  8362. int wolfSSL_CTX_LoadCRL(WOLFSSL_CTX* ctx, const char* path, int type, int monitor);
  8363. /*!
  8364. \brief This function will set the callback argument to the cbMissingCRL
  8365. member of the WOLFSSL_CERT_MANAGER structure by calling
  8366. wolfSSL_CertManagerSetCRL_Cb.
  8367. \return SSL_SUCCESS returned for a successful execution. The
  8368. WOLFSSL_CERT_MANAGER structure’s member cbMssingCRL was successfully
  8369. set to cb.
  8370. \return BAD_FUNC_ARG returned if WOLFSSL_CTX or WOLFSSL_CERT_MANAGER
  8371. are NULL.
  8372. \param ctx a pointer to a WOLFSSL_CTX structure, created with
  8373. wolfSSL_CTX_new().
  8374. \param cb a pointer to a callback function of type CbMissingCRL.
  8375. Signature requirement:
  8376. void (*CbMissingCRL)(const char* url);
  8377. _Example_
  8378. \code
  8379. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8380. void cb(const char* url) // Required signature
  8381. {
  8382. // Function body
  8383. }
  8384. if (wolfSSL_CTX_SetCRL_Cb(ctx, cb) != SSL_SUCCESS){
  8385. // Failure case, cb was not set correctly.
  8386. }
  8387. \endcode
  8388. \sa wolfSSL_CertManagerSetCRL_Cb
  8389. \sa CbMissingCRL
  8390. */
  8391. int wolfSSL_CTX_SetCRL_Cb(WOLFSSL_CTX* ctx, CbMissingCRL cb);
  8392. /*!
  8393. \brief This function sets options to configure behavior of OCSP
  8394. functionality in wolfSSL. The value of options if formed by or’ing
  8395. one or more of the following options:
  8396. WOLFSSL_OCSP_ENABLE - enable OCSP lookups WOLFSSL_OCSP_URL_OVERRIDE -
  8397. use the override URL instead of the URL in certificates. The override URL
  8398. is specified using the wolfSSL_CTX_SetOCSP_OverrideURL() function. This
  8399. function only sets the OCSP options when wolfSSL has been compiled with
  8400. OCSP support (--enable-ocsp, #define HAVE_OCSP).
  8401. \return SSL_SUCCESS is returned upon success.
  8402. \return SSL_FAILURE is returned upon failure.
  8403. \return NOT_COMPILED_IN is returned when this function has been called,
  8404. but OCSP support was not enabled when wolfSSL was compiled.
  8405. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  8406. \param options value used to set the OCSP options.
  8407. _Example_
  8408. \code
  8409. WOLFSSL_CTX* ctx = 0;
  8410. ...
  8411. wolfSSL_CTX_OCSP_set_options(ctx, WOLFSSL_OCSP_ENABLE);
  8412. \endcode
  8413. \sa wolfSSL_CTX_OCSP_set_override_url
  8414. */
  8415. int wolfSSL_CTX_EnableOCSP(WOLFSSL_CTX* ctx, int options);
  8416. /*!
  8417. \brief This function disables OCSP certificate revocation checking by
  8418. affecting the ocspEnabled member of the WOLFSSL_CERT_MANAGER structure.
  8419. \return SSL_SUCCESS returned if the function executes without error.
  8420. The ocspEnabled member of the CM has been disabled.
  8421. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL.
  8422. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8423. wolfSSL_CTX_new().
  8424. _Example_
  8425. \code
  8426. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  8427. WOLFSSL* ssl = wolfSSL_new(ctx);
  8428. ...
  8429. if(!wolfSSL_CTX_DisableOCSP(ssl->ctx)){
  8430. // OCSP is not disabled
  8431. }
  8432. \endcode
  8433. \sa wolfSSL_DisableOCSP
  8434. \sa wolfSSL_CertManagerDisableOCSP
  8435. */
  8436. int wolfSSL_CTX_DisableOCSP(WOLFSSL_CTX*);
  8437. /*!
  8438. \brief This function manually sets the URL for OCSP to use. By default,
  8439. OCSP will use the URL found in the individual certificate unless the
  8440. WOLFSSL_OCSP_URL_OVERRIDE option is set using the wolfSSL_CTX_EnableOCSP.
  8441. \return SSL_SUCCESS is returned upon success.
  8442. \return SSL_FAILURE is returned upon failure.
  8443. \return NOT_COMPILED_IN is returned when this function has been called,
  8444. but OCSP support was not enabled when wolfSSL was compiled.
  8445. \param ctx pointer to the SSL context, created with wolfSSL_CTX_new().
  8446. \param url pointer to the OCSP URL for wolfSSL to use.
  8447. _Example_
  8448. \code
  8449. WOLFSSL_CTX* ctx = 0;
  8450. ...
  8451. wolfSSL_CTX_OCSP_set_override_url(ctx, “custom-url-here”);
  8452. \endcode
  8453. \sa wolfSSL_CTX_OCSP_set_options
  8454. */
  8455. int wolfSSL_CTX_SetOCSP_OverrideURL(WOLFSSL_CTX* ctx, const char* url);
  8456. /*!
  8457. \brief Sets the callback for the OCSP in the WOLFSSL_CTX structure.
  8458. \return SSL_SUCCESS returned if the function executed successfully. The
  8459. ocspIOCb, ocspRespFreeCb, and ocspIOCtx members in the CM were
  8460. successfully set.
  8461. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX or
  8462. WOLFSSL_CERT_MANAGER structure is NULL.
  8463. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8464. \param ioCb a CbOCSPIO type that is a function pointer.
  8465. \param respFreeCb a CbOCSPRespFree type that is a function pointer.
  8466. \param ioCbCtx a void pointer that will be held in the WOLFSSL_CERT_MANAGER.
  8467. _Example_
  8468. \code
  8469. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8470. CbOCSPIO ocspIOCb;
  8471. CbOCSPRespFree ocspRespFreeCb;
  8472. void* ioCbCtx;
  8473. int isSetOCSP = wolfSSL_CTX_SetOCSP_Cb(ctx, ocspIOCb,
  8474. ocspRespFreeCb, ioCbCtx);
  8475. if(isSetOCSP != SSL_SUCCESS){
  8476. // The function did not return successfully.
  8477. }
  8478. \endcode
  8479. \sa wolfSSL_CertManagerSetOCSP_Cb
  8480. \sa CbOCSPIO
  8481. \sa CbOCSPRespFree
  8482. */
  8483. int wolfSSL_CTX_SetOCSP_Cb(WOLFSSL_CTX* ctx,
  8484. CbOCSPIO ioCb, CbOCSPRespFree respFreeCb,
  8485. void* ioCbCtx);
  8486. /*!
  8487. \brief This function enables OCSP stapling by calling
  8488. wolfSSL_CertManagerEnableOCSPStapling().
  8489. \return SSL_SUCCESS returned if there were no errors and the function
  8490. executed successfully.
  8491. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  8492. otherwise if there was a unpermitted argument value passed to a subroutine.
  8493. \return MEMORY_E returned if there was an issue allocating memory.
  8494. \return SSL_FAILURE returned if the initialization of the OCSP
  8495. structure failed.
  8496. \return NOT_COMPILED_IN returned if wolfSSL was not compiled with
  8497. HAVE_CERTIFICATE_STATUS_REQUEST option.
  8498. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  8499. wolfSSL_CTX_new().
  8500. _Example_
  8501. \code
  8502. WOLFSSL* ssl = WOLFSSL_new();
  8503. ssl->method.version; // set to desired protocol
  8504. ...
  8505. if(!wolfSSL_CTX_EnableOCSPStapling(ssl->ctx)){
  8506. // OCSP stapling is not enabled
  8507. }
  8508. \endcode
  8509. \sa wolfSSL_CertManagerEnableOCSPStapling
  8510. \sa InitOCSP
  8511. */
  8512. int wolfSSL_CTX_EnableOCSPStapling(WOLFSSL_CTX*);
  8513. /*!
  8514. \ingroup CertsKeys
  8515. \brief Normally, at the end of the SSL handshake, wolfSSL frees
  8516. temporary arrays. Calling this function before the handshake begins
  8517. will prevent wolfSSL from freeing temporary arrays. Temporary arrays
  8518. may be needed for things such as wolfSSL_get_keys() or PSK hints.
  8519. When the user is done with temporary arrays, either wolfSSL_FreeArrays()
  8520. may be called to free the resources immediately, or alternatively the
  8521. resources will be freed when the associated SSL object is freed.
  8522. \return none No return.
  8523. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8524. _Example_
  8525. \code
  8526. WOLFSSL* ssl;
  8527. ...
  8528. wolfSSL_KeepArrays(ssl);
  8529. \endcode
  8530. \sa wolfSSL_FreeArrays
  8531. */
  8532. void wolfSSL_KeepArrays(WOLFSSL*);
  8533. /*!
  8534. \ingroup CertsKeys
  8535. \brief Normally, at the end of the SSL handshake, wolfSSL frees temporary
  8536. arrays. If wolfSSL_KeepArrays() has been called before the handshake,
  8537. wolfSSL will not free temporary arrays. This function explicitly frees
  8538. temporary arrays and should be called when the user is done with temporary
  8539. arrays and does not want to wait for the SSL object to be freed to free
  8540. these resources.
  8541. \return none No return.
  8542. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8543. _Example_
  8544. \code
  8545. WOLFSSL* ssl;
  8546. ...
  8547. wolfSSL_FreeArrays(ssl);
  8548. \endcode
  8549. \sa wolfSSL_KeepArrays
  8550. */
  8551. void wolfSSL_FreeArrays(WOLFSSL*);
  8552. /*!
  8553. \brief This function enables the use of Server Name Indication in the SSL
  8554. object passed in the 'ssl' parameter. It means that the SNI extension will
  8555. be sent on ClientHello by wolfSSL client and wolfSSL server will respond
  8556. ClientHello + SNI with either ServerHello + blank SNI or alert fatal in
  8557. case of SNI mismatch.
  8558. \return WOLFSSL_SUCCESS upon success.
  8559. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8560. cases: ssl is NULL, data is NULL, type is a unknown value. (see below)
  8561. \return MEMORY_E is the error returned when there is not enough memory.
  8562. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8563. \param type indicates which type of server name is been passed in data.
  8564. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8565. \param data pointer to the server name data.
  8566. \param size size of the server name data.
  8567. _Example_
  8568. \code
  8569. int ret = 0;
  8570. WOLFSSL_CTX* ctx = 0;
  8571. WOLFSSL* ssl = 0;
  8572. ctx = wolfSSL_CTX_new(method);
  8573. if (ctx == NULL) {
  8574. // context creation failed
  8575. }
  8576. ssl = wolfSSL_new(ctx);
  8577. if (ssl == NULL) {
  8578. // ssl creation failed
  8579. }
  8580. ret = wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8581. strlen("www.yassl.com"));
  8582. if (ret != WOLFSSL_SUCCESS) {
  8583. // sni usage failed
  8584. }
  8585. \endcode
  8586. \sa wolfSSL_new
  8587. \sa wolfSSL_CTX_UseSNI
  8588. */
  8589. int wolfSSL_UseSNI(WOLFSSL* ssl, unsigned char type,
  8590. const void* data, unsigned short size);
  8591. /*!
  8592. \brief This function enables the use of Server Name Indication for SSL
  8593. objects created from the SSL context passed in the 'ctx' parameter. It
  8594. means that the SNI extension will be sent on ClientHello by wolfSSL
  8595. clients and wolfSSL servers will respond ClientHello + SNI with either
  8596. ServerHello + blank SNI or alert fatal in case of SNI mismatch.
  8597. \return WOLFSSL_SUCCESS upon success.
  8598. \return BAD_FUNC_ARG is the error that will be returned in one of these
  8599. cases: ctx is NULL, data is NULL, type is a unknown value. (see below)
  8600. \return MEMORY_E is the error returned when there is not enough memory.
  8601. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8602. \param type indicates which type of server name is been passed in data.
  8603. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8604. \param data pointer to the server name data.
  8605. \param size size of the server name data.
  8606. _Example_
  8607. \code
  8608. int ret = 0;
  8609. WOLFSSL_CTX* ctx = 0;
  8610. ctx = wolfSSL_CTX_new(method);
  8611. if (ctx == NULL) {
  8612. // context creation failed
  8613. }
  8614. ret = wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.yassl.com",
  8615. strlen("www.yassl.com"));
  8616. if (ret != WOLFSSL_SUCCESS) {
  8617. // sni usage failed
  8618. }
  8619. \endcode
  8620. \sa wolfSSL_CTX_new
  8621. \sa wolfSSL_UseSNI
  8622. */
  8623. int wolfSSL_CTX_UseSNI(WOLFSSL_CTX* ctx, unsigned char type,
  8624. const void* data, unsigned short size);
  8625. /*!
  8626. \brief This function is called on the server side to configure the
  8627. behavior of the SSL session using Server Name Indication in the SSL
  8628. object passed in the 'ssl' parameter. The options are explained below.
  8629. \return none No returns.
  8630. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8631. \param type indicates which type of server name is been passed in data.
  8632. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8633. \param options a bitwise semaphore with the chosen options. The available
  8634. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8635. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort the
  8636. handshake by sending a fatal-level unrecognized_name(112) alert if the
  8637. hostname provided by the client mismatch with the servers.
  8638. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the server
  8639. will not send a SNI response instead of aborting the session.
  8640. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH - With this option set, the server
  8641. will send a SNI response as if the host names match instead of aborting
  8642. the session.
  8643. _Example_
  8644. \code
  8645. int ret = 0;
  8646. WOLFSSL_CTX* ctx = 0;
  8647. WOLFSSL* ssl = 0;
  8648. ctx = wolfSSL_CTX_new(method);
  8649. if (ctx == NULL) {
  8650. // context creation failed
  8651. }
  8652. ssl = wolfSSL_new(ctx);
  8653. if (ssl == NULL) {
  8654. // ssl creation failed
  8655. }
  8656. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8657. if (ret != WOLFSSL_SUCCESS) {
  8658. // sni usage failed
  8659. }
  8660. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  8661. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8662. \endcode
  8663. \sa wolfSSL_new
  8664. \sa wolfSSL_UseSNI
  8665. \sa wolfSSL_CTX_SNI_SetOptions
  8666. */
  8667. void wolfSSL_SNI_SetOptions(WOLFSSL* ssl, unsigned char type,
  8668. unsigned char options);
  8669. /*!
  8670. \brief This function is called on the server side to configure the behavior
  8671. of the SSL sessions using Server Name Indication for SSL objects created
  8672. from the SSL context passed in the 'ctx' parameter. The options are
  8673. explained below.
  8674. \return none No returns.
  8675. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8676. \param type indicates which type of server name is been passed in data.
  8677. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8678. \param options a bitwise semaphore with the chosen options. The available
  8679. options are: enum { WOLFSSL_SNI_CONTINUE_ON_MISMATCH = 0x01,
  8680. WOLFSSL_SNI_ANSWER_ON_MISMATCH = 0x02 }; Normally the server will abort
  8681. the handshake by sending a fatal-level unrecognized_name(112) alert if the
  8682. hostname provided by the client mismatch with the servers.
  8683. \param WOLFSSL_SNI_CONTINUE_ON_MISMATCH With this option set, the
  8684. server will not send a SNI response instead of aborting the session.
  8685. \param WOLFSSL_SNI_ANSWER_ON_MISMATCH With this option set, the server
  8686. will send a SNI response as if the host names match instead of aborting
  8687. the session.
  8688. _Example_
  8689. \code
  8690. int ret = 0;
  8691. WOLFSSL_CTX* ctx = 0;
  8692. ctx = wolfSSL_CTX_new(method);
  8693. if (ctx == NULL) {
  8694. // context creation failed
  8695. }
  8696. ret = wolfSSL_CTX_UseSNI(ctx, 0, "www.yassl.com", strlen("www.yassl.com"));
  8697. if (ret != WOLFSSL_SUCCESS) {
  8698. // sni usage failed
  8699. }
  8700. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  8701. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  8702. \endcode
  8703. \sa wolfSSL_CTX_new
  8704. \sa wolfSSL_CTX_UseSNI
  8705. \sa wolfSSL_SNI_SetOptions
  8706. */
  8707. void wolfSSL_CTX_SNI_SetOptions(WOLFSSL_CTX* ctx,
  8708. unsigned char type, unsigned char options);
  8709. /*!
  8710. \brief This function is called on the server side to retrieve the Server
  8711. Name Indication provided by the client from the Client Hello message sent
  8712. by the client to start a session. It does not requires context or session
  8713. setup to retrieve the SNI.
  8714. \return WOLFSSL_SUCCESS upon success.
  8715. \return BAD_FUNC_ARG is the error that will be returned in one of this
  8716. cases: buffer is NULL, bufferSz <= 0, sni is NULL, inOutSz is NULL or <= 0
  8717. \return BUFFER_ERROR is the error returned when there is a malformed
  8718. Client Hello message.
  8719. \return INCOMPLETE_DATA is the error returned when there is not enough
  8720. data to complete the extraction.
  8721. \param buffer pointer to the data provided by the client (Client Hello).
  8722. \param bufferSz size of the Client Hello message.
  8723. \param type indicates which type of server name is been retrieved
  8724. from the buffer. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8725. \param sni pointer to where the output is going to be stored.
  8726. \param inOutSz pointer to the output size, this value will be updated
  8727. to MIN("SNI's length", inOutSz).
  8728. _Example_
  8729. \code
  8730. unsigned char buffer[1024] = {0};
  8731. unsigned char result[32] = {0};
  8732. int length = 32;
  8733. // read Client Hello to buffer...
  8734. ret = wolfSSL_SNI_GetFromBuffer(buffer, sizeof(buffer), 0, result, &length));
  8735. if (ret != WOLFSSL_SUCCESS) {
  8736. // sni retrieve failed
  8737. }
  8738. \endcode
  8739. \sa wolfSSL_UseSNI
  8740. \sa wolfSSL_CTX_UseSNI
  8741. \sa wolfSSL_SNI_GetRequest
  8742. */
  8743. int wolfSSL_SNI_GetFromBuffer(
  8744. const unsigned char* clientHello, unsigned int helloSz,
  8745. unsigned char type, unsigned char* sni, unsigned int* inOutSz);
  8746. /*!
  8747. \ingroup IO
  8748. \brief This function gets the status of an SNI object.
  8749. \return value This function returns the byte value of the SNI struct’s
  8750. status member if the SNI is not NULL.
  8751. \return 0 if the SNI object is NULL.
  8752. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8753. \param type the SNI type.
  8754. _Example_
  8755. \code
  8756. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  8757. WOLFSSL* ssl = wolfSSL_new(ctx);
  8758. #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
  8759. Byte type = WOLFSSL_SNI_HOST_NAME;
  8760. char* request = (char*)&type;
  8761. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  8762. \endcode
  8763. \sa TLSX_SNI_Status
  8764. \sa TLSX_SNI_find
  8765. \sa TLSX_Find
  8766. */
  8767. unsigned char wolfSSL_SNI_Status(WOLFSSL* ssl, unsigned char type);
  8768. /*!
  8769. \brief This function is called on the server side to retrieve the
  8770. Server Name Indication provided by the client in a SSL session.
  8771. \return size the size of the provided SNI data.
  8772. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8773. \param type indicates which type of server name is been retrieved in
  8774. data. The known types are: enum { WOLFSSL_SNI_HOST_NAME = 0 };
  8775. \param data pointer to the data provided by the client.
  8776. _Example_
  8777. \code
  8778. int ret = 0;
  8779. WOLFSSL_CTX* ctx = 0;
  8780. WOLFSSL* ssl = 0;
  8781. ctx = wolfSSL_CTX_new(method);
  8782. if (ctx == NULL) {
  8783. // context creation failed
  8784. }
  8785. ssl = wolfSSL_new(ctx);
  8786. if (ssl == NULL) {
  8787. // ssl creation failed
  8788. }
  8789. ret = wolfSSL_UseSNI(ssl, 0, "www.yassl.com", strlen("www.yassl.com"));
  8790. if (ret != WOLFSSL_SUCCESS) {
  8791. // sni usage failed
  8792. }
  8793. if (wolfSSL_accept(ssl) == SSL_SUCCESS) {
  8794. void *data = NULL;
  8795. unsigned short size = wolfSSL_SNI_GetRequest(ssl, 0, &data);
  8796. }
  8797. \endcode
  8798. \sa wolfSSL_UseSNI
  8799. \sa wolfSSL_CTX_UseSNI
  8800. */
  8801. unsigned short wolfSSL_SNI_GetRequest(WOLFSSL *ssl,
  8802. unsigned char type, void** data);
  8803. /*!
  8804. \ingroup Setup
  8805. \brief Setup ALPN use for a wolfSSL session.
  8806. \return WOLFSSL_SUCCESS: upon success.
  8807. \return BAD_FUNC_ARG Returned if ssl or protocol_name_list
  8808. is null or protocol_name_listSz is too large or options
  8809. contain something not supported.
  8810. \return MEMORY_ERROR Error allocating memory for protocol list.
  8811. \return SSL_FAILURE upon failure.
  8812. \param ssl The wolfSSL session to use.
  8813. \param protocol_name_list List of protocol names to use.
  8814. Comma delimited string is required.
  8815. \param protocol_name_listSz Size of the list of protocol names.
  8816. \param options WOLFSSL_ALPN_CONTINUE_ON_MISMATCH or
  8817. WOLFSSL_ALPN_FAILED_ON_MISMATCH.
  8818. _Example_
  8819. \code
  8820. wolfSSL_Init();
  8821. WOLFSSL_CTX* ctx;
  8822. WOLFSSL* ssl;
  8823. WOLFSSL_METHOD method = // Some wolfSSL method
  8824. ctx = wolfSSL_CTX_new(method);
  8825. ssl = wolfSSL_new(ctx);
  8826. char alpn_list[] = {};
  8827. if (wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  8828. WOLFSSL_APN_FAILED_ON_MISMATCH) != WOLFSSL_SUCCESS)
  8829. {
  8830. // Error setting session ticket
  8831. }
  8832. \endcode
  8833. \sa TLSX_UseALPN
  8834. */
  8835. int wolfSSL_UseALPN(WOLFSSL* ssl, char *protocol_name_list,
  8836. unsigned int protocol_name_listSz,
  8837. unsigned char options);
  8838. /*!
  8839. \ingroup TLS
  8840. \brief This function gets the protocol name set by the server.
  8841. \return SSL_SUCCESS returned on successful execution where no
  8842. errors were thrown.
  8843. \return SSL_FATAL_ERROR returned if the extension was not found or
  8844. if there was no protocol match with peer. There will also be an
  8845. error thrown if there is more than one protocol name accepted.
  8846. \return SSL_ALPN_NOT_FOUND returned signifying that no protocol
  8847. match with peer was found.
  8848. \return BAD_FUNC_ARG returned if there was a NULL argument passed
  8849. into the function.
  8850. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8851. \param protocol_name a pointer to a char that represents the protocol
  8852. name and will be held in the ALPN structure.
  8853. \param size a word16 type that represents the size of the protocol_name.
  8854. _Example_
  8855. \code
  8856. WOLFSSL_CTX* ctx = WOLFSSL_CTX_new( protocol method );
  8857. WOLFSSL* ssl = WOLFSSL_new(ctx);
  8858. ...
  8859. int err;
  8860. char* protocol_name = NULL;
  8861. Word16 protocol_nameSz = 0;
  8862. err = wolfSSL_ALPN_GetProtocol(ssl, &protocol_name, &protocol_nameSz);
  8863. if(err == SSL_SUCCESS){
  8864. // Sent ALPN protocol
  8865. }
  8866. \endcode
  8867. \sa TLSX_ALPN_GetRequest
  8868. \sa TLSX_Find
  8869. */
  8870. int wolfSSL_ALPN_GetProtocol(WOLFSSL* ssl, char **protocol_name,
  8871. unsigned short *size);
  8872. /*!
  8873. \ingroup TLS
  8874. \brief This function copies the alpn_client_list data from the SSL
  8875. object to the buffer.
  8876. \return SSL_SUCCESS returned if the function executed without error. The
  8877. alpn_client_list member of the SSL object has been copied to the
  8878. list parameter.
  8879. \return BAD_FUNC_ARG returned if the list or listSz parameter is NULL.
  8880. \return BUFFER_ERROR returned if there will be a problem with the
  8881. list buffer (either it’s NULL or the size is 0).
  8882. \return MEMORY_ERROR returned if there was a problem dynamically
  8883. allocating memory.
  8884. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  8885. \param list a pointer to the buffer. The data from the SSL object will
  8886. be copied into it.
  8887. \param listSz the buffer size.
  8888. _Example_
  8889. \code
  8890. #import <wolfssl/ssl.h>
  8891. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method);
  8892. WOLFSSL* ssl = wolfSSL_new(ctx);
  8893. #ifdef HAVE_ALPN
  8894. char* list = NULL;
  8895. word16 listSz = 0;
  8896. err = wolfSSL_ALPN_GetPeerProtocol(ssl, &list, &listSz);
  8897. if(err == SSL_SUCCESS){
  8898. List of protocols names sent by client
  8899. }
  8900. \endcode
  8901. \sa wolfSSL_UseALPN
  8902. */
  8903. int wolfSSL_ALPN_GetPeerProtocol(WOLFSSL* ssl, char **list,
  8904. unsigned short *listSz);
  8905. /*!
  8906. \brief This function is called on the client side to enable the use of
  8907. Maximum Fragment Length in the SSL object passed in the 'ssl' parameter.
  8908. It means that the Maximum Fragment Length extension will be sent on
  8909. ClientHello by wolfSSL clients.
  8910. \return SSL_SUCCESS upon success.
  8911. \return BAD_FUNC_ARG is the error that will be returned in one of
  8912. these cases: ssl is NULL, mfl is out of range.
  8913. \return MEMORY_E is the error returned when there is not enough memory.
  8914. \param ssl pointer to a SSL object, created with wolfSSL_new().
  8915. \param mfl indicates witch is the Maximum Fragment Length requested for the
  8916. session. The available options are: enum { WOLFSSL_MFL_2_9 = 1, 512 bytes
  8917. WOLFSSL_MFL_2_10 = 2, 1024 bytes WOLFSSL_MFL_2_11 = 3, 2048 bytes
  8918. WOLFSSL_MFL_2_12 = 4, 4096 bytes WOLFSSL_MFL_2_13 = 5, 8192
  8919. bytes wolfSSL ONLY!!! };
  8920. _Example_
  8921. \code
  8922. int ret = 0;
  8923. WOLFSSL_CTX* ctx = 0;
  8924. WOLFSSL* ssl = 0;
  8925. ctx = wolfSSL_CTX_new(method);
  8926. if (ctx == NULL) {
  8927. // context creation failed
  8928. }
  8929. ssl = wolfSSL_new(ctx);
  8930. if (ssl == NULL) {
  8931. // ssl creation failed
  8932. }
  8933. ret = wolfSSL_UseMaxFragment(ssl, WOLFSSL_MFL_2_11);
  8934. if (ret != 0) {
  8935. // max fragment usage failed
  8936. }
  8937. \endcode
  8938. \sa wolfSSL_new
  8939. \sa wolfSSL_CTX_UseMaxFragment
  8940. */
  8941. int wolfSSL_UseMaxFragment(WOLFSSL* ssl, unsigned char mfl);
  8942. /*!
  8943. \brief This function is called on the client side to enable the use
  8944. of Maximum Fragment Length for SSL objects created from the SSL context
  8945. passed in the 'ctx' parameter. It means that the Maximum Fragment Length
  8946. extension will be sent on ClientHello by wolfSSL clients.
  8947. \return SSL_SUCCESS upon success.
  8948. \return BAD_FUNC_ARG is the error that will be returned in one of
  8949. these cases: ctx is NULL, mfl is out of range.
  8950. \return MEMORY_E is the error returned when there is not enough memory.
  8951. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  8952. \param mfl indicates which is the Maximum Fragment Length requested
  8953. for the session. The available options are:
  8954. enum { WOLFSSL_MFL_2_9 = 1 512 bytes, WOLFSSL_MFL_2_10 = 2 1024 bytes,
  8955. WOLFSSL_MFL_2_11 = 3 2048 bytes WOLFSSL_MFL_2_12 = 4 4096 bytes,
  8956. WOLFSSL_MFL_2_13 = 5 8192 bytes wolfSSL ONLY!!!,
  8957. WOLFSSL_MFL_2_13 = 6 256 bytes wolfSSL ONLY!!!
  8958. };
  8959. _Example_
  8960. \code
  8961. int ret = 0;
  8962. WOLFSSL_CTX* ctx = 0;
  8963. ctx = wolfSSL_CTX_new(method);
  8964. if (ctx == NULL) {
  8965. // context creation failed
  8966. }
  8967. ret = wolfSSL_CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11);
  8968. if (ret != 0) {
  8969. // max fragment usage failed
  8970. }
  8971. \endcode
  8972. \sa wolfSSL_CTX_new
  8973. \sa wolfSSL_UseMaxFragment
  8974. */
  8975. int wolfSSL_CTX_UseMaxFragment(WOLFSSL_CTX* ctx, unsigned char mfl);
  8976. /*!
  8977. \brief This function is called on the client side to enable the use of
  8978. Truncated HMAC in the SSL object passed in the 'ssl' parameter. It
  8979. means that the Truncated HMAC extension will be sent on ClientHello
  8980. by wolfSSL clients.
  8981. \return SSL_SUCCESS upon success.
  8982. \return BAD_FUNC_ARG is the error that will be returned in one of
  8983. these cases: ssl is NULL
  8984. \return MEMORY_E is the error returned when there is not enough memory.
  8985. \param ssl pointer to a SSL object, created with wolfSSL_new()
  8986. _Example_
  8987. \code
  8988. int ret = 0;
  8989. WOLFSSL_CTX* ctx = 0;
  8990. WOLFSSL* ssl = 0;
  8991. ctx = wolfSSL_CTX_new(method);
  8992. if (ctx == NULL) {
  8993. // context creation failed
  8994. }
  8995. ssl = wolfSSL_new(ctx);
  8996. if (ssl == NULL) {
  8997. // ssl creation failed
  8998. }
  8999. ret = wolfSSL_UseTruncatedHMAC(ssl);
  9000. if (ret != 0) {
  9001. // truncated HMAC usage failed
  9002. }
  9003. \endcode
  9004. \sa wolfSSL_new
  9005. \sa wolfSSL_CTX_UseMaxFragment
  9006. */
  9007. int wolfSSL_UseTruncatedHMAC(WOLFSSL* ssl);
  9008. /*!
  9009. \brief This function is called on the client side to enable the use of
  9010. Truncated HMAC for SSL objects created from the SSL context passed in
  9011. the 'ctx' parameter. It means that the Truncated HMAC extension will
  9012. be sent on ClientHello by wolfSSL clients.
  9013. \return SSL_SUCCESS upon success.
  9014. \return BAD_FUNC_ARG is the error that will be returned in one of
  9015. these cases: ctx is NULL
  9016. \return MEMORY_E is the error returned when there is not enough memory.
  9017. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  9018. _Example_
  9019. \code
  9020. int ret = 0;
  9021. WOLFSSL_CTX* ctx = 0;
  9022. ctx = wolfSSL_CTX_new(method);
  9023. if (ctx == NULL) {
  9024. // context creation failed
  9025. }
  9026. ret = wolfSSL_CTX_UseTruncatedHMAC(ctx);
  9027. if (ret != 0) {
  9028. // truncated HMAC usage failed
  9029. }
  9030. \endcode
  9031. \sa wolfSSL_CTX_new
  9032. \sa wolfSSL_UseMaxFragment
  9033. */
  9034. int wolfSSL_CTX_UseTruncatedHMAC(WOLFSSL_CTX* ctx);
  9035. /*!
  9036. \brief Stapling eliminates the need to contact the CA. Stapling
  9037. lowers the cost of certificate revocation check presented in OCSP.
  9038. \return SSL_SUCCESS returned if TLSX_UseCertificateStatusRequest
  9039. executes without error.
  9040. \return MEMORY_E returned if there is an error with the allocation
  9041. of memory.
  9042. \return BAD_FUNC_ARG returned if there is an argument that has a
  9043. NULL or otherwise unacceptable value passed into the function.
  9044. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9045. \param status_type a byte type that is passed through to
  9046. TLSX_UseCertificateStatusRequest() and stored in the
  9047. CertificateStatusRequest structure.
  9048. \param options a byte type that is passed through to
  9049. TLSX_UseCertificateStatusRequest() and stored in the
  9050. CertificateStatusRequest structure.
  9051. _Example_
  9052. \code
  9053. WOLFSSL* ssl = wolfSSL_new(ctx);
  9054. if (wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  9055. WOLFSSL_CSR2_OCSP_USE_NONCE) != SSL_SUCCESS){
  9056. // Failed case.
  9057. }
  9058. \endcode
  9059. \sa TLSX_UseCertificateStatusRequest
  9060. \sa wolfSSL_CTX_UseOCSPStapling
  9061. */
  9062. int wolfSSL_UseOCSPStapling(WOLFSSL* ssl,
  9063. unsigned char status_type, unsigned char options);
  9064. /*!
  9065. \brief This function requests the certificate status during the handshake.
  9066. \return SSL_SUCCESS returned if the function and subroutines execute
  9067. without error.
  9068. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or
  9069. otherwise if a unpermitted value is passed to a subroutine.
  9070. \return MEMORY_E returned if the function or subroutine failed to properly
  9071. allocate memory.
  9072. \param ctx a pointer to a WOLFSSL_CTX structure,
  9073. created using wolfSSL_CTX_new().
  9074. \param status_type a byte type that is passed through to
  9075. TLSX_UseCertificateStatusRequest() and stored in the
  9076. CertificateStatusRequest structure.
  9077. \param options a byte type that is passed through to
  9078. TLSX_UseCertificateStatusRequest() and stored in the
  9079. CertificateStatusRequest structure.
  9080. _Example_
  9081. \code
  9082. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9083. WOLFSSL* ssl = wolfSSL_new(ctx);
  9084. byte statusRequest = 0; // Initialize status request
  9085. switch(statusRequest){
  9086. case WOLFSSL_CSR_OCSP:
  9087. if(wolfSSL_CTX_UseOCSPStapling(ssl->ctx, WOLFSSL_CSR_OCSP,
  9088. WOLF_CSR_OCSP_USE_NONCE) != SSL_SUCCESS){
  9089. // UseCertificateStatusRequest failed
  9090. }
  9091. // Continue switch cases
  9092. \endcode
  9093. \sa wolfSSL_UseOCSPStaplingV2
  9094. \sa wolfSSL_UseOCSPStapling
  9095. \sa TLSX_UseCertificateStatusRequest
  9096. */
  9097. int wolfSSL_CTX_UseOCSPStapling(WOLFSSL_CTX* ctx,
  9098. unsigned char status_type, unsigned char options);
  9099. /*!
  9100. \brief The function sets the status type and options for OCSP.
  9101. \return SSL_SUCCESS - returned if the function and subroutines
  9102. executed without error.
  9103. \return MEMORY_E - returned if there was an allocation of memory error.
  9104. \return BAD_FUNC_ARG - returned if a NULL or otherwise unaccepted
  9105. argument was passed to the function or a subroutine.
  9106. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9107. \param status_type a byte type that loads the OCSP status type.
  9108. \param options a byte type that holds the OCSP options, set in
  9109. wolfSSL_SNI_SetOptions() and wolfSSL_CTX_SNI_SetOptions().
  9110. _Example_
  9111. \code
  9112. WOLFSSL* ssl = wolfSSL_new(ctx);
  9113. ...
  9114. if (wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP_MULTI, 0) != SSL_SUCCESS){
  9115. // Did not execute properly. Failure case code block.
  9116. }
  9117. \endcode
  9118. \sa TLSX_UseCertificatStatusRequestV2
  9119. \sa wolfSSL_SNI_SetOptions
  9120. \sa wolfSSL_CTX_SNI_SetOptions
  9121. */
  9122. int wolfSSL_UseOCSPStaplingV2(WOLFSSL* ssl,
  9123. unsigned char status_type, unsigned char options);
  9124. /*!
  9125. \brief Creates and initializes the certificate status request
  9126. for OCSP Stapling.
  9127. \return SSL_SUCCESS if the function and subroutines executed without error.
  9128. \return BAD_FUNC_ARG returned if the WOLFSSL_CTX structure is NULL or if
  9129. the side variable is not client side.
  9130. \return MEMORY_E returned if the allocation of memory failed.
  9131. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  9132. wolfSSL_CTX_new().
  9133. \param status_type a byte type that is located in the
  9134. CertificatStatusRequest structure and must be either WOLFSSL_CSR2_OCSP
  9135. or WOLFSSL_CSR2_OCSP_MULTI.
  9136. \param options a byte type that will be held in
  9137. CertificateStatusRequestItemV2 struct.
  9138. _Example_
  9139. \code
  9140. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9141. byte status_type;
  9142. byte options;
  9143. ...
  9144. if(wolfSSL_CTX_UseOCSPStaplingV2(ctx, status_type, options); != SSL_SUCCESS){
  9145. // Failure case.
  9146. }
  9147. \endcode
  9148. \sa TLSX_UseCertificateStatusRequestV2
  9149. \sa wc_RNG_GenerateBlock
  9150. \sa TLSX_Push
  9151. */
  9152. int wolfSSL_CTX_UseOCSPStaplingV2(WOLFSSL_CTX* ctx,
  9153. unsigned char status_type, unsigned char options);
  9154. /*!
  9155. \brief This function is called on the client side to enable the use of
  9156. Supported Elliptic Curves Extension in the SSL object passed in the 'ssl'
  9157. parameter. It means that the supported curves enabled will be sent on
  9158. ClientHello by wolfSSL clients. This function can be called more than
  9159. one time to enable multiple curves.
  9160. \return SSL_SUCCESS upon success.
  9161. \return BAD_FUNC_ARG is the error that will be returned in one of these
  9162. cases: ssl is NULL, name is a unknown value. (see below)
  9163. \return MEMORY_E is the error returned when there is not enough memory.
  9164. \param ssl pointer to a SSL object, created with wolfSSL_new().
  9165. \param name indicates which curve will be supported for the session. The
  9166. available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  9167. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  9168. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  9169. WOLFSSL_ECC_SECP521R1 = 0x19 };
  9170. _Example_
  9171. \code
  9172. int ret = 0;
  9173. WOLFSSL_CTX* ctx = 0;
  9174. WOLFSSL* ssl = 0;
  9175. ctx = wolfSSL_CTX_new(method);
  9176. if (ctx == NULL) {
  9177. // context creation failed
  9178. }
  9179. ssl = wolfSSL_new(ctx);
  9180. if (ssl == NULL) {
  9181. // ssl creation failed
  9182. }
  9183. ret = wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1);
  9184. if (ret != 0) {
  9185. // Elliptic Curve Extension usage failed
  9186. }
  9187. \endcode
  9188. \sa wolfSSL_CTX_new
  9189. \sa wolfSSL_CTX_UseSupportedCurve
  9190. */
  9191. int wolfSSL_UseSupportedCurve(WOLFSSL* ssl, word16 name);
  9192. /*!
  9193. \brief This function is called on the client side to enable the use of
  9194. Supported Elliptic Curves Extension for SSL objects created from the SSL
  9195. context passed in the 'ctx' parameter. It means that the supported curves
  9196. enabled will be sent on ClientHello by wolfSSL clients. This function can
  9197. be called more than one time to enable multiple curves.
  9198. \return SSL_SUCCESS upon success.
  9199. \return BAD_FUNC_ARG is the error that will be returned in one of these
  9200. cases: ctx is NULL, name is a unknown value. (see below)
  9201. \return MEMORY_E is the error returned when there is not enough memory.
  9202. \param ctx pointer to a SSL context, created with wolfSSL_CTX_new().
  9203. \param name indicates which curve will be supported for the session.
  9204. The available options are: enum { WOLFSSL_ECC_SECP160R1 = 0x10,
  9205. WOLFSSL_ECC_SECP192R1 = 0x13, WOLFSSL_ECC_SECP224R1 = 0x15,
  9206. WOLFSSL_ECC_SECP256R1 = 0x17, WOLFSSL_ECC_SECP384R1 = 0x18,
  9207. WOLFSSL_ECC_SECP521R1 = 0x19 };
  9208. _Example_
  9209. \code
  9210. int ret = 0;
  9211. WOLFSSL_CTX* ctx = 0;
  9212. ctx = wolfSSL_CTX_new(method);
  9213. if (ctx == NULL) {
  9214. // context creation failed
  9215. }
  9216. ret = wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1);
  9217. if (ret != 0) {
  9218. // Elliptic Curve Extension usage failed
  9219. }
  9220. \endcode
  9221. \sa wolfSSL_CTX_new
  9222. \sa wolfSSL_UseSupportedCurve
  9223. */
  9224. int wolfSSL_CTX_UseSupportedCurve(WOLFSSL_CTX* ctx,
  9225. word16 name);
  9226. /*!
  9227. \ingroup IO
  9228. \brief This function forces secure renegotiation for the supplied
  9229. WOLFSSL structure. This is not recommended.
  9230. \return SSL_SUCCESS Successfully set secure renegotiation.
  9231. \return BAD_FUNC_ARG Returns error if ssl is null.
  9232. \return MEMORY_E Returns error if unable to allocate memory for secure
  9233. renegotiation.
  9234. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9235. _Example_
  9236. \code
  9237. wolfSSL_Init();
  9238. WOLFSSL_CTX* ctx;
  9239. WOLFSSL* ssl;
  9240. WOLFSSL_METHOD method = // Some wolfSSL method
  9241. ctx = wolfSSL_CTX_new(method);
  9242. ssl = wolfSSL_new(ctx);
  9243. if(wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS)
  9244. {
  9245. // Error setting secure renegotiation
  9246. }
  9247. \endcode
  9248. \sa TLSX_Find
  9249. \sa TLSX_UseSecureRenegotiation
  9250. */
  9251. int wolfSSL_UseSecureRenegotiation(WOLFSSL* ssl);
  9252. /*!
  9253. \ingroup IO
  9254. \brief This function executes a secure renegotiation handshake; this is user
  9255. forced as wolfSSL discourages this functionality.
  9256. \return SSL_SUCCESS returned if the function executed without error.
  9257. \return BAD_FUNC_ARG returned if the WOLFSSL structure was NULL or otherwise
  9258. if an unacceptable argument was passed in a subroutine.
  9259. \return SECURE_RENEGOTIATION_E returned if there was an error with
  9260. renegotiating the handshake.
  9261. \return SSL_FATAL_ERROR returned if there was an error with the
  9262. server or client configuration and the renegotiation could
  9263. not be completed. See wolfSSL_negotiate().
  9264. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9265. _Example_
  9266. \code
  9267. WOLFSSL* ssl = wolfSSL_new(ctx);
  9268. ...
  9269. if(wolfSSL_Rehandshake(ssl) != SSL_SUCCESS){
  9270. // There was an error and the rehandshake is not successful.
  9271. }
  9272. \endcode
  9273. \sa wolfSSL_negotiate
  9274. \sa wc_InitSha512
  9275. \sa wc_InitSha384
  9276. \sa wc_InitSha256
  9277. \sa wc_InitSha
  9278. \sa wc_InitMd5
  9279. */
  9280. int wolfSSL_Rehandshake(WOLFSSL* ssl);
  9281. /*!
  9282. \ingroup IO
  9283. \brief Force provided WOLFSSL structure to use session ticket. The
  9284. constant HAVE_SESSION_TICKET should be defined and the constant
  9285. NO_WOLFSSL_CLIENT should not be defined to use this function.
  9286. \return SSL_SUCCESS Successfully set use session ticket.
  9287. \return BAD_FUNC_ARG Returned if ssl is null.
  9288. \return MEMORY_E Error allocating memory for setting session ticket.
  9289. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9290. _Example_
  9291. \code
  9292. wolfSSL_Init();
  9293. WOLFSSL_CTX* ctx;
  9294. WOLFSSL* ssl;
  9295. WOLFSSL_METHOD method = // Some wolfSSL method
  9296. ctx = wolfSSL_CTX_new(method);
  9297. ssl = wolfSSL_new(ctx);
  9298. if(wolfSSL_UseSessionTicket(ssl) != SSL_SUCCESS)
  9299. {
  9300. // Error setting session ticket
  9301. }
  9302. \endcode
  9303. \sa TLSX_UseSessionTicket
  9304. */
  9305. int wolfSSL_UseSessionTicket(WOLFSSL* ssl);
  9306. /*!
  9307. \ingroup Setup
  9308. \brief This function sets wolfSSL context to use a session ticket.
  9309. \return SSL_SUCCESS Function executed successfully.
  9310. \return BAD_FUNC_ARG Returned if ctx is null.
  9311. \return MEMORY_E Error allocating memory in internal function.
  9312. \param ctx The WOLFSSL_CTX structure to use.
  9313. _Example_
  9314. \code
  9315. wolfSSL_Init();
  9316. WOLFSSL_CTX* ctx;
  9317. WOLFSSL_METHOD method = // Some wolfSSL method ;
  9318. ctx = wolfSSL_CTX_new(method);
  9319. if(wolfSSL_CTX_UseSessionTicket(ctx) != SSL_SUCCESS)
  9320. {
  9321. // Error setting session ticket
  9322. }
  9323. \endcode
  9324. \sa TLSX_UseSessionTicket
  9325. */
  9326. int wolfSSL_CTX_UseSessionTicket(WOLFSSL_CTX* ctx);
  9327. /*!
  9328. \ingroup IO
  9329. \brief This function copies the ticket member of the Session structure to
  9330. the buffer.
  9331. \return SSL_SUCCESS returned if the function executed without error.
  9332. \return BAD_FUNC_ARG returned if one of the arguments was NULL or if the
  9333. bufSz argument was 0.
  9334. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9335. \param buf a byte pointer representing the memory buffer.
  9336. \param bufSz a word32 pointer representing the buffer size.
  9337. _Example_
  9338. \code
  9339. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9340. WOLFSSL* ssl = wolfSSL_new(ctx);
  9341. byte* buf;
  9342. word32 bufSz; // Initialize with buf size
  9343. if(wolfSSL_get_SessionTicket(ssl, buf, bufSz) <= 0){
  9344. // Nothing was written to the buffer
  9345. } else {
  9346. // the buffer holds the content from ssl->session->ticket
  9347. }
  9348. \endcode
  9349. \sa wolfSSL_UseSessionTicket
  9350. \sa wolfSSL_set_SessionTicket
  9351. */
  9352. int wolfSSL_get_SessionTicket(WOLFSSL* ssl, unsigned char* buf, word32* bufSz);
  9353. /*!
  9354. \ingroup IO
  9355. \brief This function sets the ticket member of the WOLFSSL_SESSION
  9356. structure within the WOLFSSL struct. The buffer passed into the function
  9357. is copied to memory.
  9358. \return SSL_SUCCESS returned on successful execution of the function.
  9359. The function returned without errors.
  9360. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL. This will
  9361. also be thrown if the buf argument is NULL but the bufSz argument
  9362. is not zero.
  9363. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9364. \param buf a byte pointer that gets loaded into the ticket member
  9365. of the session structure.
  9366. \param bufSz a word32 type that represents the size of the buffer.
  9367. _Example_
  9368. \code
  9369. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  9370. WOLFSSL* ssl = wolfSSL_new(ctx);
  9371. byte* buffer; // File to load
  9372. word32 bufSz;
  9373. ...
  9374. if(wolfSSL_KeepArrays(ssl, buffer, bufSz) != SSL_SUCCESS){
  9375. // There was an error loading the buffer to memory.
  9376. }
  9377. \endcode
  9378. \sa wolfSSL_set_SessionTicket_cb
  9379. */
  9380. int wolfSSL_set_SessionTicket(WOLFSSL* ssl, const unsigned char* buf,
  9381. word32 bufSz);
  9382. /*!
  9383. \brief This function sets the session ticket callback. The type
  9384. CallbackSessionTicket is a function pointer with the signature of:
  9385. int (*CallbackSessionTicket)(WOLFSSL*, const unsigned char*, int, void*)
  9386. \return SSL_SUCCESS returned if the function executed without error.
  9387. \return BAD_FUNC_ARG returned if the WOLFSSL structure is NULL.
  9388. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9389. \param cb a function pointer to the type CallbackSessionTicket.
  9390. \param ctx a void pointer to the session_ticket_ctx member of the
  9391. WOLFSSL structure.
  9392. _Example_
  9393. \code
  9394. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9395. WOLFSSL* ssl = wolfSSL_new(ctx);
  9396. int sessionTicketCB(WOLFSSL* ssl, const unsigned char* ticket, int ticketSz,
  9397. void* ctx){ … }
  9398. wolfSSL_set_SessionTicket_cb(ssl, sessionTicketCB, (void*)”initial session”);
  9399. \endcode
  9400. \sa wolfSSL_get_SessionTicket
  9401. \sa CallbackSessionTicket
  9402. \sa sessionTicketCB
  9403. */
  9404. int wolfSSL_set_SessionTicket_cb(WOLFSSL* ssl,
  9405. CallbackSessionTicket cb, void* ctx);
  9406. /*!
  9407. \brief This function sends a session ticket to the client after a TLS v1.3
  9408. handhsake has been established.
  9409. \return WOLFSSL_SUCCESS returned if a new session ticket was sent.
  9410. \return BAD_FUNC_ARG returned if WOLFSSL structure is NULL, or not using
  9411. TLS v1.3.
  9412. \return SIDE_ERROR returned if not a server.
  9413. \return NOT_READY_ERROR returned if the handshake has not completed.
  9414. \return WOLFSSL_FATAL_ERROR returned if creating or sending message fails.
  9415. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9416. _Example_
  9417. \code
  9418. int ret;
  9419. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9420. WOLFSSL* ssl = wolfSSL_new(ctx);
  9421. ret = wolfSSL_send_SessionTicket(ssl);
  9422. if (ret != WOLFSSL_SUCCESS) {
  9423. // New session ticket not sent.
  9424. }
  9425. \endcode
  9426. \sa wolfSSL_get_SessionTicket
  9427. \sa CallbackSessionTicket
  9428. \sa sessionTicketCB
  9429. */
  9430. int wolfSSL_send_SessionTicket(WOLFSSL* ssl);
  9431. /*!
  9432. \brief This function sets the session ticket key encrypt callback function
  9433. for a server to support session tickets as specified in RFC 5077.
  9434. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9435. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  9436. invalid arguments to the function.
  9437. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  9438. \param cb user callback function to encrypt/decrypt session tickets
  9439. \param ssl(Callback) pointer to the WOLFSSL object, created with
  9440. wolfSSL_new()
  9441. \param key_name(Callback) unique key name for this ticket context, should
  9442. be randomly generated
  9443. \param iv(Callback) unique IV for this ticket, up to 128 bits, should
  9444. be randomly generated
  9445. \param mac(Callback) up to 256 bit mac for this ticket
  9446. \param enc(Callback) if this encrypt parameter is true the user should fill
  9447. in key_name, iv, mac, and encrypt the ticket in-place of length inLen and
  9448. set the resulting output length in *outLen. Returning WOLFSSL_TICKET_RET_OK
  9449. tells wolfSSL that the encryption was successful. If this encrypt parameter
  9450. is false, the user should perform a decrypt of the ticket in-place of length
  9451. inLen using key_name, iv, and mac. The resulting decrypt length should be
  9452. set in *outLen. Returning WOLFSSL_TICKET_RET_OK tells wolfSSL to proceed
  9453. using the decrypted ticket. Returning WOLFSSL_TICKET_RET_CREATE tells
  9454. wolfSSL to use the decrypted ticket but also to generate a new one to
  9455. send to the client, helpful if recently rolled keys and don’t want to
  9456. force a full handshake. Returning WOLFSSL_TICKET_RET_REJECT tells
  9457. wolfSSL to reject this ticket, perform a full handshake, and create
  9458. a new standard session ID for normal session resumption. Returning
  9459. WOLFSSL_TICKET_RET_FATAL tells wolfSSL to end the connection
  9460. attempt with a fatal error.
  9461. \param ticket(Callback) the input/output buffer for the encrypted ticket.
  9462. See the enc parameter
  9463. \param inLen(Callback) the input length of the ticket parameter
  9464. \param outLen(Callback) the resulting output length of the ticket parameter.
  9465. When entering the callback outLen will indicate the maximum size available
  9466. in the ticket buffer.
  9467. \param userCtx(Callback) the user context set with
  9468. wolfSSL_CTX_set_TicketEncCtx()
  9469. _Example_
  9470. \code
  9471. See wolfssl/test.h myTicketEncCb() used by the example
  9472. server and example echoserver.
  9473. \endcode
  9474. \sa wolfSSL_CTX_set_TicketHint
  9475. \sa wolfSSL_CTX_set_TicketEncCtx
  9476. */
  9477. int wolfSSL_CTX_set_TicketEncCb(WOLFSSL_CTX* ctx,
  9478. SessionTicketEncCb);
  9479. /*!
  9480. \brief This function sets the session ticket hint relayed to the client.
  9481. For server side use.
  9482. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9483. \return BAD_FUNC_ARG will be returned on failure. This is caused by passing
  9484. invalid arguments to the function.
  9485. \param ctx pointer to the WOLFSSL_CTX object, created with wolfSSL_CTX_new().
  9486. \param hint number of seconds the ticket might be valid for. Hint to client.
  9487. _Example_
  9488. \code
  9489. none
  9490. \endcode
  9491. \sa wolfSSL_CTX_set_TicketEncCb
  9492. */
  9493. int wolfSSL_CTX_set_TicketHint(WOLFSSL_CTX* ctx, int);
  9494. /*!
  9495. \brief This function sets the session ticket encrypt user context for the
  9496. callback. For server side use.
  9497. \return SSL_SUCCESS will be returned upon successfully setting the session.
  9498. \return BAD_FUNC_ARG will be returned on failure. This is caused by
  9499. passing invalid arguments to the function.
  9500. \param ctx pointer to the WOLFSSL_CTX object, created
  9501. with wolfSSL_CTX_new().
  9502. \param userCtx the user context for the callback
  9503. _Example_
  9504. \code
  9505. none
  9506. \endcode
  9507. \sa wolfSSL_CTX_set_TicketEncCb
  9508. */
  9509. int wolfSSL_CTX_set_TicketEncCtx(WOLFSSL_CTX* ctx, void*);
  9510. /*!
  9511. \brief This function gets the session ticket encrypt user context for the
  9512. callback. For server side use.
  9513. \return userCtx will be returned upon successfully getting the session.
  9514. \return NULL will be returned on failure. This is caused by
  9515. passing invalid arguments to the function, or when the user context has
  9516. not been set.
  9517. \param ctx pointer to the WOLFSSL_CTX object, created
  9518. with wolfSSL_CTX_new().
  9519. _Example_
  9520. \code
  9521. none
  9522. \endcode
  9523. \sa wolfSSL_CTX_set_TicketEncCtx
  9524. */
  9525. void* wolfSSL_CTX_get_TicketEncCtx(WOLFSSL_CTX* ctx);
  9526. /*!
  9527. \brief This function sets the handshake done callback. The hsDoneCb and
  9528. hsDoneCtx members of the WOLFSSL structure are set in this function.
  9529. \return SSL_SUCCESS returned if the function executed without an error.
  9530. The hsDoneCb and hsDoneCtx members of the WOLFSSL struct are set.
  9531. \return BAD_FUNC_ARG returned if the WOLFSSL struct is NULL.
  9532. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  9533. \param cb a function pointer of type HandShakeDoneCb with the signature of
  9534. the form: int (*HandShakeDoneCb)(WOLFSSL*, void*);
  9535. \param user_ctx a void pointer to the user registered context.
  9536. _Example_
  9537. \code
  9538. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  9539. WOLFSSL* ssl = wolfSSL_new(ctx);
  9540. int myHsDoneCb(WOLFSSL* ssl, void* user_ctx){
  9541. // callback function
  9542. }
  9543. wolfSSL_SetHsDoneCb(ssl, myHsDoneCb, NULL);
  9544. \endcode
  9545. \sa HandShakeDoneCb
  9546. */
  9547. int wolfSSL_SetHsDoneCb(WOLFSSL* ssl, HandShakeDoneCb cb, void* user_ctx);
  9548. /*!
  9549. \ingroup IO
  9550. \brief This function prints the statistics from the session.
  9551. \return SSL_SUCCESS returned if the function and subroutines return without
  9552. error. The session stats have been successfully retrieved and printed.
  9553. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9554. was passed an unacceptable argument.
  9555. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9556. \param none No parameters.
  9557. _Example_
  9558. \code
  9559. // You will need to have a session object to retrieve stats from.
  9560. if(wolfSSL_PrintSessionStats(void) != SSL_SUCCESS ){
  9561. // Did not print session stats
  9562. }
  9563. \endcode
  9564. \sa wolfSSL_get_session_stats
  9565. */
  9566. int wolfSSL_PrintSessionStats(void);
  9567. /*!
  9568. \ingroup IO
  9569. \brief This function gets the statistics for the session.
  9570. \return SSL_SUCCESS returned if the function and subroutines return without
  9571. error. The session stats have been successfully retrieved and printed.
  9572. \return BAD_FUNC_ARG returned if the subroutine wolfSSL_get_session_stats()
  9573. was passed an unacceptable argument.
  9574. \return BAD_MUTEX_E returned if there was a mutex error in the subroutine.
  9575. \param active a word32 pointer representing the total current sessions.
  9576. \param total a word32 pointer representing the total sessions.
  9577. \param peak a word32 pointer representing the peak sessions.
  9578. \param maxSessions a word32 pointer representing the maximum sessions.
  9579. _Example_
  9580. \code
  9581. int wolfSSL_PrintSessionStats(void){
  9582. ret = wolfSSL_get_session_stats(&totalSessionsNow,
  9583. &totalSessionsSeen, &peak, &maxSessions);
  9584. return ret;
  9585. \endcode
  9586. \sa wolfSSL_PrintSessionStats
  9587. */
  9588. int wolfSSL_get_session_stats(unsigned int* active,
  9589. unsigned int* total,
  9590. unsigned int* peak,
  9591. unsigned int* maxSessions);
  9592. /*!
  9593. \ingroup TLS
  9594. \brief This function copies the values of cr and sr then passes through to
  9595. wc_PRF (pseudo random function) and returns that value.
  9596. \return 0 on success
  9597. \return BUFFER_E returned if there will be an error
  9598. with the size of the buffer.
  9599. \return MEMORY_E returned if a subroutine failed
  9600. to allocate dynamic memory.
  9601. \param ms the master secret held in the Arrays structure.
  9602. \param msLen the length of the master secret.
  9603. \param pms the pre-master secret held in the Arrays structure.
  9604. \param pmsLen the length of the pre-master secret.
  9605. \param cr the client random.
  9606. \param sr the server random.
  9607. \param tls1_2 signifies that the version is at least tls version 1.2.
  9608. \param hash_type signifies the hash type.
  9609. _Example_
  9610. \code
  9611. WOLFSSL* ssl;
  9612. called in MakeTlsMasterSecret and retrieves the necessary
  9613. information as follows:
  9614. int MakeTlsMasterSecret(WOLFSSL* ssl){
  9615. int ret;
  9616. ret = wolfSSL_makeTlsMasterSecret(ssl->arrays->masterSecret, SECRET_LEN,
  9617. ssl->arrays->preMasterSecret, ssl->arrays->preMasterSz,
  9618. ssl->arrays->clientRandom, ssl->arrays->serverRandom,
  9619. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9620. return ret;
  9621. }
  9622. \endcode
  9623. \sa wc_PRF
  9624. \sa MakeTlsMasterSecret
  9625. */
  9626. int wolfSSL_MakeTlsMasterSecret(unsigned char* ms, word32 msLen,
  9627. const unsigned char* pms, word32 pmsLen,
  9628. const unsigned char* cr, const unsigned char* sr,
  9629. int tls1_2, int hash_type);
  9630. /*!
  9631. \ingroup CertsKeys
  9632. \brief An external facing wrapper to derive TLS Keys.
  9633. \return 0 returned on success.
  9634. \return BUFFER_E returned if the sum of labLen and
  9635. seedLen (computes total size) exceeds the maximum size.
  9636. \return MEMORY_E returned if the allocation of memory failed.
  9637. \param key_data a byte pointer that is allocateded in DeriveTlsKeys
  9638. and passed through to wc_PRF to hold the final hash.
  9639. \param keyLen a word32 type that is derived in DeriveTlsKeys
  9640. from the WOLFSSL structure’s specs member.
  9641. \param ms a constant pointer type holding the master secret
  9642. held in the arrays structure within the WOLFSSL structure.
  9643. \param msLen a word32 type that holds the length of the
  9644. master secret in an enumerated define, SECRET_LEN.
  9645. \param sr a constant byte pointer to the serverRandom
  9646. member of the arrays structure within the WOLFSSL structure.
  9647. \param cr a constant byte pointer to the clientRandom
  9648. member of the arrays structure within the WOLFSSL structure.
  9649. \param tls1_2 an integer type returned from IsAtLeastTLSv1_2().
  9650. \param hash_type an integer type held in the WOLFSSL structure.
  9651. _Example_
  9652. \code
  9653. int DeriveTlsKeys(WOLFSSL* ssl){
  9654. int ret;
  9655. ret = wolfSSL_DeriveTlsKeys(key_data, length, ssl->arrays->masterSecret,
  9656. SECRET_LEN, ssl->arrays->clientRandom,
  9657. IsAtLeastTLSv1_2(ssl), ssl->specs.mac_algorithm);
  9658. }
  9659. \endcode
  9660. \sa wc_PRF
  9661. \sa DeriveTlsKeys
  9662. \sa IsAtLeastTLSv1_2
  9663. */
  9664. int wolfSSL_DeriveTlsKeys(unsigned char* key_data, word32 keyLen,
  9665. const unsigned char* ms, word32 msLen,
  9666. const unsigned char* sr, const unsigned char* cr,
  9667. int tls1_2, int hash_type);
  9668. /*!
  9669. \brief wolfSSL_connect_ex() is an extension that allows
  9670. a HandShake Callback to be set. This can be useful in
  9671. embedded systems for debugging support when a debugger isn’t
  9672. available and sniffing is impractical. The HandShake Callback
  9673. will be called whether or not a handshake error occurred.
  9674. No dynamic memory is used since the maximum number of SSL
  9675. packets is known. Packet names can be accessed through packetNames[].
  9676. The connect extension also allows a Timeout Callback to be set along
  9677. with a timeout value. This is useful if the user doesn’t want
  9678. to wait for the TCP stack to timeout. This extension can be called
  9679. with either, both, or neither callbacks.
  9680. \return SSL_SUCCESS upon success.
  9681. \return GETTIME_ERROR will be returned if gettimeofday()
  9682. encountered an error.
  9683. \return SETITIMER_ERROR will be returned if setitimer()
  9684. encountered an error.
  9685. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9686. \return SSL_FATAL_ERROR will be returned if the underlying SSL_connect()
  9687. call encountered an error.
  9688. \param none No parameters.
  9689. _Example_
  9690. \code
  9691. none
  9692. \endcode
  9693. \sa wolfSSL_accept_ex
  9694. */
  9695. int wolfSSL_connect_ex(WOLFSSL* ssl, HandShakeCallBack hsCb,
  9696. TimeoutCallBack toCb, WOLFSSL_TIMEVAL timeout);
  9697. /*!
  9698. \brief wolfSSL_accept_ex() is an extension that allows a HandShake Callback
  9699. to be set. This can be useful in embedded systems for debugging support
  9700. when a debugger isn’t available and sniffing is impractical. The HandShake
  9701. Callback will be called whether or not a handshake error occurred.
  9702. No dynamic memory is used since the maximum number of SSL packets is known.
  9703. Packet names can be accessed through packetNames[]. The connect extension
  9704. also allows a Timeout Callback to be set along with a timeout value.
  9705. This is useful if the user doesn’t want to wait for the TCP stack to timeout.
  9706. This extension can be called with either, both, or neither callbacks.
  9707. \return SSL_SUCCESS upon success.
  9708. \return GETTIME_ERROR will be returned if gettimeofday()
  9709. encountered an error.
  9710. \return SETITIMER_ERROR will be returned if setitimer()
  9711. encountered an error.
  9712. \return SIGACT_ERROR will be returned if sigaction() encountered an error.
  9713. \return SSL_FATAL_ERROR will be returned if the underlying
  9714. SSL_accept() call encountered an error.
  9715. \param none No parameters.
  9716. _Example_
  9717. \code
  9718. none
  9719. \endcode
  9720. \sa wolfSSL_connect_ex
  9721. */
  9722. int wolfSSL_accept_ex(WOLFSSL* ssl, HandShakeCallBacki hsCb,
  9723. TimeoutCallBack toCb, WOLFSSL_TIMEVAL timeout);
  9724. /*!
  9725. \ingroup IO
  9726. \brief This is used to set the internal file pointer for a BIO.
  9727. \return SSL_SUCCESS On successfully setting file pointer.
  9728. \return SSL_FAILURE If an error case was encountered.
  9729. \param bio WOLFSSL_BIO structure to set pair.
  9730. \param fp file pointer to set in bio.
  9731. \param c close file behavior flag.
  9732. _Example_
  9733. \code
  9734. WOLFSSL_BIO* bio;
  9735. XFILE fp;
  9736. int ret;
  9737. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9738. ret = wolfSSL_BIO_set_fp(bio, fp, BIO_CLOSE);
  9739. // check ret value
  9740. \endcode
  9741. \sa wolfSSL_BIO_new
  9742. \sa wolfSSL_BIO_s_mem
  9743. \sa wolfSSL_BIO_get_fp
  9744. \sa wolfSSL_BIO_free
  9745. */
  9746. long wolfSSL_BIO_set_fp(WOLFSSL_BIO *bio, XFILE fp, int c);
  9747. /*!
  9748. \ingroup IO
  9749. \brief This is used to get the internal file pointer for a BIO.
  9750. \return SSL_SUCCESS On successfully getting file pointer.
  9751. \return SSL_FAILURE If an error case was encountered.
  9752. \param bio WOLFSSL_BIO structure to set pair.
  9753. \param fp file pointer to set in bio.
  9754. _Example_
  9755. \code
  9756. WOLFSSL_BIO* bio;
  9757. XFILE fp;
  9758. int ret;
  9759. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  9760. ret = wolfSSL_BIO_get_fp(bio, &fp);
  9761. // check ret value
  9762. \endcode
  9763. \sa wolfSSL_BIO_new
  9764. \sa wolfSSL_BIO_s_mem
  9765. \sa wolfSSL_BIO_set_fp
  9766. \sa wolfSSL_BIO_free
  9767. */
  9768. long wolfSSL_BIO_get_fp(WOLFSSL_BIO *bio, XFILE* fp);
  9769. /*!
  9770. \ingroup Setup
  9771. \brief This function checks that the private key is a match
  9772. with the certificate being used.
  9773. \return SSL_SUCCESS On successfully match.
  9774. \return SSL_FAILURE If an error case was encountered.
  9775. \return <0 All error cases other than SSL_FAILURE are negative values.
  9776. \param ssl WOLFSSL structure to check.
  9777. _Example_
  9778. \code
  9779. WOLFSSL* ssl;
  9780. int ret;
  9781. // create and set up ssl
  9782. ret = wolfSSL_check_private_key(ssl);
  9783. // check ret value
  9784. \endcode
  9785. \sa wolfSSL_new
  9786. \sa wolfSSL_free
  9787. */
  9788. int wolfSSL_check_private_key(const WOLFSSL* ssl);
  9789. /*!
  9790. \ingroup CertsKeys
  9791. \brief This function looks for and returns the extension index
  9792. matching the passed in NID value.
  9793. \return >= 0 If successful the extension index is returned.
  9794. \return -1 If extension is not found or error is encountered.
  9795. \param x509 certificate to get parse through for extension.
  9796. \param nid extension OID to be found.
  9797. \param lastPos start search from extension after lastPos.
  9798. Set to -1 initially.
  9799. _Example_
  9800. \code
  9801. const WOLFSSL_X509* x509;
  9802. int lastPos = -1;
  9803. int idx;
  9804. idx = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints, lastPos);
  9805. \endcode
  9806. */
  9807. int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509,
  9808. int nid, int lastPos);
  9809. /*!
  9810. \ingroup CertsKeys
  9811. \brief This function looks for and returns the extension
  9812. matching the passed in NID value.
  9813. \return pointer If successful a STACK_OF(WOLFSSL_ASN1_OBJECT)
  9814. pointer is returned.
  9815. \return NULL If extension is not found or error is encountered.
  9816. \param x509 certificate to get parse through for extension.
  9817. \param nid extension OID to be found.
  9818. \param c if not NULL is set to -2 for multiple extensions found -1
  9819. if not found, 0 if found and not critical and 1 if found and critical.
  9820. \param idx if NULL return first extension matched otherwise if not
  9821. stored in x509 start at idx.
  9822. _Example_
  9823. \code
  9824. const WOLFSSL_X509* x509;
  9825. int c;
  9826. int idx = 0;
  9827. STACK_OF(WOLFSSL_ASN1_OBJECT)* sk;
  9828. sk = wolfSSL_X509_get_ext_d2i(x509, NID_basic_constraints, &c, &idx);
  9829. //check sk for NULL and then use it. sk needs freed after done.
  9830. \endcode
  9831. \sa wolfSSL_sk_ASN1_OBJECT_free
  9832. */
  9833. void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509,
  9834. int nid, int* c, int* idx);
  9835. /*!
  9836. \ingroup CertsKeys
  9837. \brief This function returns the hash of the DER certificate.
  9838. \return SSL_SUCCESS On successfully creating a hash.
  9839. \return SSL_FAILURE Returned on bad input or unsuccessful hash.
  9840. \param x509 certificate to get the hash of.
  9841. \param digest the hash algorithm to use.
  9842. \param buf buffer to hold hash.
  9843. \param len length of buffer.
  9844. _Example_
  9845. \code
  9846. WOLFSSL_X509* x509;
  9847. unsigned char buffer[64];
  9848. unsigned int bufferSz;
  9849. int ret;
  9850. ret = wolfSSL_X509_digest(x509, wolfSSL_EVP_sha256(), buffer, &bufferSz);
  9851. //check ret value
  9852. \endcode
  9853. \sa none
  9854. */
  9855. int wolfSSL_X509_digest(const WOLFSSL_X509* x509,
  9856. const WOLFSSL_EVP_MD* digest, unsigned char* buf, unsigned int* len);
  9857. /*!
  9858. \ingroup Setup
  9859. \brief his is used to set the certificate for WOLFSSL structure to use
  9860. during a handshake.
  9861. \return SSL_SUCCESS On successful setting argument.
  9862. \return SSL_FAILURE If a NULL argument passed in.
  9863. \param ssl WOLFSSL structure to set certificate in.
  9864. \param x509 certificate to use.
  9865. _Example_
  9866. \code WOLFSSL* ssl;
  9867. WOLFSSL_X509* x509
  9868. int ret;
  9869. // create ssl object and x509
  9870. ret = wolfSSL_use_certificate(ssl, x509);
  9871. // check ret value
  9872. \endcode
  9873. \sa wolfSSL_new
  9874. \sa wolfSSL_free
  9875. */
  9876. int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509);
  9877. /*!
  9878. \ingroup Setup
  9879. \brief This is used to set the certificate for WOLFSSL structure
  9880. to use during a handshake. A DER formatted buffer is expected.
  9881. \return SSL_SUCCESS On successful setting argument.
  9882. \return SSL_FAILURE If a NULL argument passed in.
  9883. \param ssl WOLFSSL structure to set certificate in.
  9884. \param der DER certificate to use.
  9885. \param derSz size of the DER buffer passed in.
  9886. _Example_
  9887. \code
  9888. WOLFSSL* ssl;
  9889. unsigned char* der;
  9890. int derSz;
  9891. int ret;
  9892. // create ssl object and set DER variables
  9893. ret = wolfSSL_use_certificate_ASN1(ssl, der, derSz);
  9894. // check ret value
  9895. \endcode
  9896. \sa wolfSSL_new
  9897. \sa wolfSSL_free
  9898. */
  9899. int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, unsigned char* der,
  9900. int derSz);
  9901. /*!
  9902. \ingroup CertsKeys
  9903. \brief This is used to set the private key for the WOLFSSL structure.
  9904. \return SSL_SUCCESS On successful setting argument.
  9905. \return SSL_FAILURE If a NULL ssl passed in. All error
  9906. cases will be negative values.
  9907. \param ssl WOLFSSL structure to set argument in.
  9908. \param pkey private key to use.
  9909. _Example_
  9910. \code
  9911. WOLFSSL* ssl;
  9912. WOLFSSL_EVP_PKEY* pkey;
  9913. int ret;
  9914. // create ssl object and set up private key
  9915. ret = wolfSSL_use_PrivateKey(ssl, pkey);
  9916. // check ret value
  9917. \endcode
  9918. \sa wolfSSL_new
  9919. \sa wolfSSL_free
  9920. */
  9921. int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey);
  9922. /*!
  9923. \ingroup CertsKeys
  9924. \brief This is used to set the private key for the WOLFSSL
  9925. structure. A DER formatted key buffer is expected.
  9926. \return SSL_SUCCESS On successful setting parsing and
  9927. setting the private key.
  9928. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  9929. will be negative values.
  9930. \param pri type of private key.
  9931. \param ssl WOLFSSL structure to set argument in.
  9932. \param der buffer holding DER key.
  9933. \param derSz size of der buffer.
  9934. _Example_
  9935. \code
  9936. WOLFSSL* ssl;
  9937. unsigned char* pkey;
  9938. long pkeySz;
  9939. int ret;
  9940. // create ssl object and set up private key
  9941. ret = wolfSSL_use_PrivateKey_ASN1(1, ssl, pkey, pkeySz);
  9942. // check ret value
  9943. \endcode
  9944. \sa wolfSSL_new
  9945. \sa wolfSSL_free
  9946. \sa wolfSSL_use_PrivateKey
  9947. */
  9948. int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl,
  9949. unsigned char* der, long derSz);
  9950. /*!
  9951. \ingroup CertsKeys
  9952. \brief This is used to set the private key for the WOLFSSL
  9953. structure. A DER formatted RSA key buffer is expected.
  9954. \return SSL_SUCCESS On successful setting parsing and setting
  9955. the private key.
  9956. \return SSL_FAILURE If an NULL ssl passed in. All error cases
  9957. will be negative values.
  9958. \param ssl WOLFSSL structure to set argument in.
  9959. \param der buffer holding DER key.
  9960. \param derSz size of der buffer.
  9961. _Example_
  9962. \code
  9963. WOLFSSL* ssl;
  9964. unsigned char* pkey;
  9965. long pkeySz;
  9966. int ret;
  9967. // create ssl object and set up RSA private key
  9968. ret = wolfSSL_use_RSAPrivateKey_ASN1(ssl, pkey, pkeySz);
  9969. // check ret value
  9970. \endcode
  9971. \sa wolfSSL_new
  9972. \sa wolfSSL_free
  9973. \sa wolfSSL_use_PrivateKey
  9974. */
  9975. int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, unsigned char* der,
  9976. long derSz);
  9977. /*!
  9978. \ingroup CertsKeys
  9979. \brief This function duplicates the parameters in dsa to a
  9980. newly created WOLFSSL_DH structure.
  9981. \return WOLFSSL_DH If duplicated returns WOLFSSL_DH structure
  9982. \return NULL upon failure
  9983. \param dsa WOLFSSL_DSA structure to duplicate.
  9984. _Example_
  9985. \code
  9986. WOLFSSL_DH* dh;
  9987. WOLFSSL_DSA* dsa;
  9988. // set up dsa
  9989. dh = wolfSSL_DSA_dup_DH(dsa);
  9990. // check dh is not null
  9991. \endcode
  9992. \sa none
  9993. */
  9994. WOLFSSL_DH *wolfSSL_DSA_dup_DH(const WOLFSSL_DSA *r);
  9995. /*!
  9996. \ingroup Setup
  9997. \brief This is used to get the master key after completing a handshake.
  9998. \return >0 On successfully getting data returns a value greater than 0
  9999. \return 0 If no random data buffer or an error state returns 0
  10000. \return max If outSz passed in is 0 then the maximum buffer
  10001. size needed is returned
  10002. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  10003. \param out buffer to hold data.
  10004. \param outSz size of out buffer passed in. (if 0 function will
  10005. return max buffer size needed)
  10006. _Example_
  10007. \code
  10008. WOLFSSL_SESSION ssl;
  10009. unsigned char* buffer;
  10010. size_t bufferSz;
  10011. size_t ret;
  10012. // complete handshake and get session structure
  10013. bufferSz = wolfSSL_SESSION_get_master_secret(ses, NULL, 0);
  10014. buffer = malloc(bufferSz);
  10015. ret = wolfSSL_SESSION_get_master_secret(ses, buffer, bufferSz);
  10016. // check ret value
  10017. \endcode
  10018. \sa wolfSSL_new
  10019. \sa wolfSSL_free
  10020. */
  10021. int wolfSSL_SESSION_get_master_key(const WOLFSSL_SESSION* ses,
  10022. unsigned char* out, int outSz);
  10023. /*!
  10024. \ingroup Setup
  10025. \brief This is used to get the master secret key length.
  10026. \return size Returns master secret key size.
  10027. \param ses WOLFSSL_SESSION structure to get master secret buffer from.
  10028. _Example_
  10029. \code
  10030. WOLFSSL_SESSION ssl;
  10031. unsigned char* buffer;
  10032. size_t bufferSz;
  10033. size_t ret;
  10034. // complete handshake and get session structure
  10035. bufferSz = wolfSSL_SESSION_get_master_secret_length(ses);
  10036. buffer = malloc(bufferSz);
  10037. // check ret value
  10038. \endcode
  10039. \sa wolfSSL_new
  10040. \sa wolfSSL_free
  10041. */
  10042. int wolfSSL_SESSION_get_master_key_length(const WOLFSSL_SESSION* ses);
  10043. /*!
  10044. \ingroup Setup
  10045. \brief This is a setter function for the WOLFSSL_X509_STORE
  10046. structure in ctx.
  10047. \return none No return.
  10048. \param ctx pointer to the WOLFSSL_CTX structure for setting
  10049. cert store pointer.
  10050. \param str pointer to the WOLFSSL_X509_STORE to set in ctx.
  10051. _Example_
  10052. \code
  10053. WOLFSSL_CTX ctx;
  10054. WOLFSSL_X509_STORE* st;
  10055. // setup ctx and st
  10056. st = wolfSSL_CTX_set_cert_store(ctx, st);
  10057. //use st
  10058. \endcode
  10059. \sa wolfSSL_CTX_new
  10060. \sa wolfSSL_CTX_free
  10061. */
  10062. void wolfSSL_CTX_set_cert_store(WOLFSSL_CTX* ctx,
  10063. WOLFSSL_X509_STORE* str);
  10064. /*!
  10065. \ingroup CertsKeys
  10066. \brief This function get the DER buffer from bio and converts it
  10067. to a WOLFSSL_X509 structure.
  10068. \return pointer returns a WOLFSSL_X509 structure pointer on success.
  10069. \return Null returns NULL on failure
  10070. \param bio pointer to the WOLFSSL_BIO structure that has the DER
  10071. certificate buffer.
  10072. \param x509 pointer that get set to new WOLFSSL_X509 structure created.
  10073. _Example_
  10074. \code
  10075. WOLFSSL_BIO* bio;
  10076. WOLFSSL_X509* x509;
  10077. // load DER into bio
  10078. x509 = wolfSSL_d2i_X509_bio(bio, NULL);
  10079. Or
  10080. wolfSSL_d2i_X509_bio(bio, &x509);
  10081. // use x509 returned (check for NULL)
  10082. \endcode
  10083. \sa none
  10084. */
  10085. WOLFSSL_X509* wolfSSL_d2i_X509_bio(WOLFSSL_BIO* bio, WOLFSSL_X509** x509);
  10086. /*!
  10087. \ingroup Setup
  10088. \brief This is a getter function for the WOLFSSL_X509_STORE
  10089. structure in ctx.
  10090. \return WOLFSSL_X509_STORE* On successfully getting the pointer.
  10091. \return NULL Returned if NULL arguments are passed in.
  10092. \param ctx pointer to the WOLFSSL_CTX structure for getting cert
  10093. store pointer.
  10094. _Example_
  10095. \code
  10096. WOLFSSL_CTX ctx;
  10097. WOLFSSL_X509_STORE* st;
  10098. // setup ctx
  10099. st = wolfSSL_CTX_get_cert_store(ctx);
  10100. //use st
  10101. \endcode
  10102. \sa wolfSSL_CTX_new
  10103. \sa wolfSSL_CTX_free
  10104. \sa wolfSSL_CTX_set_cert_store
  10105. */
  10106. WOLFSSL_X509_STORE* wolfSSL_CTX_get_cert_store(WOLFSSL_CTX* ctx);
  10107. /*!
  10108. \ingroup IO
  10109. \brief Gets the number of pending bytes to read. If BIO type is BIO_BIO
  10110. then is the number to read from pair. If BIO contains an SSL object then
  10111. is pending data from SSL object (wolfSSL_pending(ssl)). If is BIO_MEMORY
  10112. type then returns the size of memory buffer.
  10113. \return >=0 number of pending bytes.
  10114. \param bio pointer to the WOLFSSL_BIO structure that has already
  10115. been created.
  10116. _Example_
  10117. \code
  10118. WOLFSSL_BIO* bio;
  10119. int pending;
  10120. bio = wolfSSL_BIO_new();
  10121. pending = wolfSSL_BIO_ctrl_pending(bio);
  10122. \endcode
  10123. \sa wolfSSL_BIO_make_bio_pair
  10124. \sa wolfSSL_BIO_new
  10125. */
  10126. size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *b);
  10127. /*!
  10128. \ingroup Setup
  10129. \brief This is used to get the random data sent by the server
  10130. during the handshake.
  10131. \return >0 On successfully getting data returns a value greater than 0
  10132. \return 0 If no random data buffer or an error state returns 0
  10133. \return max If outSz passed in is 0 then the maximum buffer size
  10134. needed is returned
  10135. \param ssl WOLFSSL structure to get clients random data buffer from.
  10136. \param out buffer to hold random data.
  10137. \param outSz size of out buffer passed in. (if 0 function will return max
  10138. buffer size needed)
  10139. _Example_
  10140. \code
  10141. WOLFSSL ssl;
  10142. unsigned char* buffer;
  10143. size_t bufferSz;
  10144. size_t ret;
  10145. bufferSz = wolfSSL_get_server_random(ssl, NULL, 0);
  10146. buffer = malloc(bufferSz);
  10147. ret = wolfSSL_get_server_random(ssl, buffer, bufferSz);
  10148. // check ret value
  10149. \endcode
  10150. \sa wolfSSL_new
  10151. \sa wolfSSL_free
  10152. */
  10153. size_t wolfSSL_get_server_random(const WOLFSSL *ssl,
  10154. unsigned char *out, size_t outlen);
  10155. /*!
  10156. \ingroup Setup
  10157. \brief This is used to get the random data sent by the client during
  10158. the handshake.
  10159. \return >0 On successfully getting data returns a value greater than 0
  10160. \return 0 If no random data buffer or an error state returns 0
  10161. \return max If outSz passed in is 0 then the maximum buffer size needed
  10162. is returned
  10163. \param ssl WOLFSSL structure to get clients random data buffer from.
  10164. \param out buffer to hold random data.
  10165. \param outSz size of out buffer passed in. (if 0 function will return max
  10166. buffer size needed)
  10167. _Example_
  10168. \code
  10169. WOLFSSL ssl;
  10170. unsigned char* buffer;
  10171. size_t bufferSz;
  10172. size_t ret;
  10173. bufferSz = wolfSSL_get_client_random(ssl, NULL, 0);
  10174. buffer = malloc(bufferSz);
  10175. ret = wolfSSL_get_client_random(ssl, buffer, bufferSz);
  10176. // check ret value
  10177. \endcode
  10178. \sa wolfSSL_new
  10179. \sa wolfSSL_free
  10180. */
  10181. size_t wolfSSL_get_client_random(const WOLFSSL* ssl,
  10182. unsigned char* out, size_t outSz);
  10183. /*!
  10184. \ingroup Setup
  10185. \brief This is a getter function for the password callback set in ctx.
  10186. \return func On success returns the callback function.
  10187. \return NULL If ctx is NULL then NULL is returned.
  10188. \param ctx WOLFSSL_CTX structure to get call back from.
  10189. _Example_
  10190. \code
  10191. WOLFSSL_CTX* ctx;
  10192. wc_pem_password_cb cb;
  10193. // setup ctx
  10194. cb = wolfSSL_CTX_get_default_passwd_cb(ctx);
  10195. //use cb
  10196. \endcode
  10197. \sa wolfSSL_CTX_new
  10198. \sa wolfSSL_CTX_free
  10199. */
  10200. wc_pem_password_cb* wolfSSL_CTX_get_default_passwd_cb(WOLFSSL_CTX*
  10201. ctx);
  10202. /*!
  10203. \ingroup Setup
  10204. \brief This is a getter function for the password callback user
  10205. data set in ctx.
  10206. \return pointer On success returns the user data pointer.
  10207. \return NULL If ctx is NULL then NULL is returned.
  10208. \param ctx WOLFSSL_CTX structure to get user data from.
  10209. _Example_
  10210. \code
  10211. WOLFSSL_CTX* ctx;
  10212. void* data;
  10213. // setup ctx
  10214. data = wolfSSL_CTX_get_default_passwd_cb(ctx);
  10215. //use data
  10216. \endcode
  10217. \sa wolfSSL_CTX_new
  10218. \sa wolfSSL_CTX_free
  10219. */
  10220. void *wolfSSL_CTX_get_default_passwd_cb_userdata(WOLFSSL_CTX *ctx);
  10221. /*!
  10222. \ingroup CertsKeys
  10223. \brief This function behaves the same as wolfSSL_PEM_read_bio_X509.
  10224. AUX signifies containing extra information such as trusted/rejected use
  10225. cases and friendly name for human readability.
  10226. \return WOLFSSL_X509 on successfully parsing the PEM buffer a WOLFSSL_X509
  10227. structure is returned.
  10228. \return Null if failed to parse PEM buffer.
  10229. \param bp WOLFSSL_BIO structure to get PEM buffer from.
  10230. \param x if setting WOLFSSL_X509 by function side effect.
  10231. \param cb password callback.
  10232. \param u NULL terminated user password.
  10233. _Example_
  10234. \code
  10235. WOLFSSL_BIO* bio;
  10236. WOLFSSL_X509* x509;
  10237. // setup bio
  10238. X509 = wolfSSL_PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
  10239. //check x509 is not null and then use it
  10240. \endcode
  10241. \sa wolfSSL_PEM_read_bio_X509
  10242. */
  10243. WOLFSSL_X509 *wolfSSL_PEM_read_bio_X509_AUX
  10244. (WOLFSSL_BIO *bp, WOLFSSL_X509 **x, wc_pem_password_cb *cb, void *u);
  10245. /*!
  10246. \ingroup CertsKeys
  10247. \brief Initializes the WOLFSSL_CTX structure’s dh member with the
  10248. Diffie-Hellman parameters.
  10249. \return SSL_SUCCESS returned if the function executed successfully.
  10250. \return BAD_FUNC_ARG returned if the ctx or dh structures are NULL.
  10251. \return SSL_FATAL_ERROR returned if there was an error setting a
  10252. structure value.
  10253. \return MEMORY_E returned if their was a failure to allocate memory.
  10254. \param ctx a pointer to a WOLFSSL_CTX structure, created using
  10255. wolfSSL_CTX_new().
  10256. \param dh a pointer to a WOLFSSL_DH structure.
  10257. _Example_
  10258. \code
  10259. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10260. WOLFSSL_DH* dh;
  10261. return wolfSSL_CTX_set_tmp_dh(ctx, dh);
  10262. \endcode
  10263. \sa wolfSSL_BN_bn2bin
  10264. */
  10265. long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh);
  10266. /*!
  10267. \ingroup CertsKeys
  10268. \brief This function get the DSA parameters from a PEM buffer in bio.
  10269. \return WOLFSSL_DSA on successfully parsing the PEM buffer a WOLFSSL_DSA
  10270. structure is created and returned.
  10271. \return Null if failed to parse PEM buffer.
  10272. \param bio pointer to the WOLFSSL_BIO structure for getting PEM
  10273. memory pointer.
  10274. \param x pointer to be set to new WOLFSSL_DSA structure.
  10275. \param cb password callback function.
  10276. \param u null terminated password string.
  10277. _Example_
  10278. \code
  10279. WOLFSSL_BIO* bio;
  10280. WOLFSSL_DSA* dsa;
  10281. // setup bio
  10282. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  10283. // check dsa is not NULL and then use dsa
  10284. \endcode
  10285. \sa none
  10286. */
  10287. WOLFSSL_DSA *wolfSSL_PEM_read_bio_DSAparams(WOLFSSL_BIO *bp,
  10288. WOLFSSL_DSA **x, wc_pem_password_cb *cb, void *u);
  10289. /*!
  10290. \ingroup Debug
  10291. \brief This function returns the absolute value of the last error from
  10292. WOLFSSL_ERROR encountered.
  10293. \return error Returns absolute value of last error.
  10294. \param none No parameters.
  10295. _Example_
  10296. \code
  10297. unsigned long err;
  10298. ...
  10299. err = wolfSSL_ERR_peek_last_error();
  10300. // inspect err value
  10301. \endcode
  10302. \sa wolfSSL_ERR_print_errors_fp
  10303. */
  10304. unsigned long wolfSSL_ERR_peek_last_error(void);
  10305. /*!
  10306. \ingroup CertsKeys
  10307. \brief This function gets the peer’s certificate chain.
  10308. \return pointer returns a pointer to the peer’s Certificate stack.
  10309. \return NULL returned if no peer certificate.
  10310. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10311. _Example_
  10312. \code
  10313. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
  10314. WOLFSSL* ssl = wolfSSL_new(ctx);
  10315. ...
  10316. wolfSSL_connect(ssl);
  10317. STACK_OF(WOLFSSL_X509)* chain = wolfSSL_get_peer_cert_chain(ssl);
  10318. ifchain){
  10319. // You have a pointer to the peer certificate chain
  10320. }
  10321. \endcode
  10322. \sa wolfSSL_X509_get_issuer_name
  10323. \sa wolfSSL_X509_get_subject_name
  10324. \sa wolfSSL_X509_get_isCA
  10325. */
  10326. WOLF_STACK_OF(WOLFSSL_X509)* wolfSSL_get_peer_cert_chain(const WOLFSSL*);
  10327. /*!
  10328. \ingroup Setup
  10329. \brief This function resets option bits of WOLFSSL_CTX object.
  10330. \return option new option bits
  10331. \param ctx pointer to the SSL context.
  10332. _Example_
  10333. \code
  10334. WOLFSSL_CTX* ctx = 0;
  10335. ...
  10336. wolfSSL_CTX_clear_options(ctx, SSL_OP_NO_TLSv1);
  10337. \endcode
  10338. \sa wolfSSL_CTX_new
  10339. \sa wolfSSL_new
  10340. \sa wolfSSL_free
  10341. */
  10342. long wolfSSL_CTX_clear_options(WOLFSSL_CTX* ctx, long opt);
  10343. /*!
  10344. \ingroup IO
  10345. \brief This function sets the jObjectRef member of the WOLFSSL structure.
  10346. \return SSL_SUCCESS returned if jObjectRef is properly set to objPtr.
  10347. \return SSL_FAILURE returned if the function did not properly execute and
  10348. jObjectRef is not set.
  10349. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10350. \param objPtr a void pointer that will be set to jObjectRef.
  10351. _Example_
  10352. \code
  10353. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10354. WOLFSSL* ssl = WOLFSSL_new();
  10355. void* objPtr = &obj;
  10356. ...
  10357. if(wolfSSL_set_jobject(ssl, objPtr)){
  10358. // The success case
  10359. }
  10360. \endcode
  10361. \sa wolfSSL_get_jobject
  10362. */
  10363. int wolfSSL_set_jobject(WOLFSSL* ssl, void* objPtr);
  10364. /*!
  10365. \ingroup IO
  10366. \brief This function returns the jObjectRef member of the WOLFSSL structure.
  10367. \return value If the WOLFSSL struct is not NULL, the function returns the
  10368. jObjectRef value.
  10369. \return NULL returned if the WOLFSSL struct is NULL.
  10370. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10371. _Example_
  10372. \code
  10373. WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
  10374. WOLFSSL* ssl = wolfSSL(ctx);
  10375. ...
  10376. void* jobject = wolfSSL_get_jobject(ssl);
  10377. if(jobject != NULL){
  10378. // Success case
  10379. }
  10380. \endcode
  10381. \sa wolfSSL_set_jobject
  10382. */
  10383. void* wolfSSL_get_jobject(WOLFSSL* ssl);
  10384. /*!
  10385. \ingroup Setup
  10386. \brief This function sets a callback in the ssl. The callback is to
  10387. observe handshake messages. NULL value of cb resets the callback.
  10388. \return SSL_SUCCESS On success.
  10389. \return SSL_FAILURE If an NULL ssl passed in.
  10390. \param ssl WOLFSSL structure to set callback argument.
  10391. _Example_
  10392. \code
  10393. static cb(int write_p, int version, int content_type,
  10394. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  10395. WOLFSSL* ssl;
  10396. ret = wolfSSL_set_msg_callback(ssl, cb);
  10397. // check ret
  10398. \endcode
  10399. \sa wolfSSL_set_msg_callback_arg
  10400. */
  10401. int wolfSSL_set_msg_callback(WOLFSSL *ssl, SSL_Msg_Cb cb);
  10402. /*!
  10403. \ingroup Setup
  10404. \brief This function sets associated callback context value in the ssl.
  10405. The value is handed over to the callback argument.
  10406. \return none No return.
  10407. \param ssl WOLFSSL structure to set callback argument.
  10408. _Example_
  10409. \code
  10410. static cb(int write_p, int version, int content_type,
  10411. const void *buf, size_t len, WOLFSSL *ssl, void *arg)
  10412. WOLFSSL* ssl;
  10413. ret = wolfSSL_set_msg_callback(ssl, cb);
  10414. // check ret
  10415. wolfSSL_set_msg_callback(ssl, arg);
  10416. \endcode
  10417. \sa wolfSSL_set_msg_callback
  10418. */
  10419. int wolfSSL_set_msg_callback_arg(WOLFSSL *ssl, void* arg);
  10420. /*!
  10421. \ingroup CertsKeys
  10422. \brief This function returns the next, if any, altname from the peer certificate.
  10423. \return NULL if there is not a next altname.
  10424. \return cert->altNamesNext->name from the WOLFSSL_X509 structure that is a
  10425. string value from the altName list is returned if it exists.
  10426. \param cert a pointer to the wolfSSL_X509 structure.
  10427. _Example_
  10428. \code
  10429. WOLFSSL_X509 x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  10430. DYNAMIC_TYPE_X509);
  10431. int x509NextAltName = wolfSSL_X509_get_next_altname(x509);
  10432. if(x509NextAltName == NULL){
  10433. //There isn’t another alt name
  10434. }
  10435. \endcode
  10436. \sa wolfSSL_X509_get_issuer_name
  10437. \sa wolfSSL_X509_get_subject_name
  10438. */
  10439. char* wolfSSL_X509_get_next_altname(WOLFSSL_X509*);
  10440. /*!
  10441. \ingroup CertsKeys
  10442. \brief The function checks to see if x509 is NULL and if it’s not, it
  10443. returns the notBefore member of the x509 struct.
  10444. \return pointer to struct with ASN1_TIME to the notBefore
  10445. member of the x509 struct.
  10446. \return NULL the function returns NULL if the x509 structure is NULL.
  10447. \param x509 a pointer to the WOLFSSL_X509 struct.
  10448. _Example_
  10449. \code
  10450. WOLFSSL_X509* x509 = (WOLFSSL_X509)XMALLOC(sizeof(WOLFSSL_X509), NULL,
  10451. DYNAMIC_TYPE_X509) ;
  10452. const WOLFSSL_ASN1_TIME* notAfter = wolfSSL_X509_get_notBefore(x509);
  10453. if(notAfter == NULL){
  10454. //The x509 object was NULL
  10455. }
  10456. \endcode
  10457. \sa wolfSSL_X509_get_notAfter
  10458. */
  10459. WOLFSSL_ASN1_TIME* wolfSSL_X509_get_notBefore(WOLFSSL_X509*);
  10460. /*!
  10461. \ingroup IO
  10462. \brief This function is called on the client side and initiates an SSL/TLS
  10463. handshake with a server. When this function is called, the underlying
  10464. communication channel has already been set up.
  10465. wolfSSL_connect() works with both blocking and non-blocking I/O. When the
  10466. underlying I/O is non-blocking, wolfSSL_connect() will return when the
  10467. underlying I/O could not satisfy the needs of wolfSSL_connect to continue
  10468. the handshake. In this case, a call to wolfSSL_get_error() will yield
  10469. either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The calling process
  10470. must then repeat the call to wolfSSL_connect() when the underlying I/O is
  10471. ready and wolfSSL will pick up where it left off. When using a non-blocking
  10472. socket, nothing needs to be done, but select() can be used to check for the
  10473. required condition.
  10474. If the underlying I/O is blocking, wolfSSL_connect() will only return once
  10475. the handshake has been finished or an error occurred.
  10476. wolfSSL takes a different approach to certificate verification than OpenSSL
  10477. does. The default policy for the client is to verify the server, this
  10478. means that if you don't load CAs to verify the server you'll get a connect
  10479. error, unable to verify (-155). It you want to mimic OpenSSL behavior of
  10480. having SSL_connect succeed even if verifying the server fails and reducing
  10481. security you can do this by calling:
  10482. SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling SSL_new();
  10483. Though it's not recommended.
  10484. \return SSL_SUCCESS If successful.
  10485. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10486. more detailed error code, call wolfSSL_get_error().
  10487. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10488. _Example_
  10489. \code
  10490. int ret = 0;
  10491. int err = 0;
  10492. WOLFSSL* ssl;
  10493. char buffer[80];
  10494. ...
  10495. ret = wolfSSL_connect(ssl);
  10496. if (ret != SSL_SUCCESS) {
  10497. err = wolfSSL_get_error(ssl, ret);
  10498. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10499. }
  10500. \endcode
  10501. \sa wolfSSL_get_error
  10502. \sa wolfSSL_accept
  10503. */
  10504. int wolfSSL_connect(WOLFSSL* ssl);
  10505. /*!
  10506. \ingroup Setup
  10507. \brief This function is called on the server side to indicate that a
  10508. HelloRetryRequest message must contain a Cookie.
  10509. The Cookie holds a hash of the current transcript so that another server
  10510. process can handle the ClientHello in reply.
  10511. The secret is used when generting the integrity check on the Cookie data.
  10512. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10513. \param [in] secret a pointer to a buffer holding the secret.
  10514. Passing NULL indicates to generate a new random secret.
  10515. \param [in] secretSz Size of the secret in bytes.
  10516. Passing 0 indicates to use the default size: WC_SHA256_DIGEST_SIZE (or WC_SHA_DIGEST_SIZE when SHA-256 not available).
  10517. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10518. \return SIDE_ERROR if called with a client.
  10519. \return WOLFSSL_SUCCESS if succesful.
  10520. \return MEMORY_ERROR if allocating dynamic memory for storing secret failed.
  10521. \return Another -ve value on internal error.
  10522. _Example_
  10523. \code
  10524. int ret;
  10525. WOLFSSL* ssl;
  10526. char secret[32];
  10527. ...
  10528. ret = wolfSSL__send_hrr_cookie(ssl, secret, sizeof(secret));
  10529. if (ret != WOLFSSL_SUCCESS) {
  10530. // failed to set use of Cookie and secret
  10531. }
  10532. \endcode
  10533. \sa wolfSSL_new
  10534. */
  10535. int wolfSSL_send_hrr_cookie(WOLFSSL* ssl,
  10536. const unsigned char* secret, unsigned int secretSz);
  10537. /*!
  10538. \ingroup Setup
  10539. \brief This function is called on the server to stop it from sending
  10540. a resumption session ticket once the handshake is complete.
  10541. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10542. with wolfSSL_CTX_new().
  10543. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10544. \return SIDE_ERROR if called with a client.
  10545. \return 0 if successful.
  10546. _Example_
  10547. \code
  10548. int ret;
  10549. WOLFSSL_CTX* ctx;
  10550. ...
  10551. ret = wolfSSL_CTX_no_ticket_TLSv13(ctx);
  10552. if (ret != 0) {
  10553. // failed to set no ticket
  10554. }
  10555. \endcode
  10556. \sa wolfSSL_no_ticket_TLSv13
  10557. */
  10558. int wolfSSL_CTX_no_ticket_TLSv13(WOLFSSL_CTX* ctx);
  10559. /*!
  10560. \ingroup Setup
  10561. \brief This function is called on the server to stop it from sending
  10562. a resumption session ticket once the handshake is complete.
  10563. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10564. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10565. \return SIDE_ERROR if called with a client.
  10566. \return 0 if successful.
  10567. _Example_
  10568. \code
  10569. int ret;
  10570. WOLFSSL* ssl;
  10571. ...
  10572. ret = wolfSSL_no_ticket_TLSv13(ssl);
  10573. if (ret != 0) {
  10574. // failed to set no ticket
  10575. }
  10576. \endcode
  10577. \sa wolfSSL_CTX_no_ticket_TLSv13
  10578. */
  10579. int wolfSSL_no_ticket_TLSv13(WOLFSSL* ssl);
  10580. /*!
  10581. \ingroup Setup
  10582. \brief This function is called on a TLS v1.3 wolfSSL context to disallow
  10583. Diffie-Hellman (DH) style key exchanges when handshakes are using
  10584. pre-shared keys for authentication.
  10585. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10586. with wolfSSL_CTX_new().
  10587. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10588. \return 0 if successful.
  10589. _Example_
  10590. \code
  10591. int ret;
  10592. WOLFSSL_CTX* ctx;
  10593. ...
  10594. ret = wolfSSL_CTX_no_dhe_psk(ctx);
  10595. if (ret != 0) {
  10596. // failed to set no DHE for PSK handshakes
  10597. }
  10598. \endcode
  10599. \sa wolfSSL_no_dhe_psk
  10600. */
  10601. int wolfSSL_CTX_no_dhe_psk(WOLFSSL_CTX* ctx);
  10602. /*!
  10603. \ingroup Setup
  10604. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10605. disallow Diffie-Hellman (DH) style key exchanges when handshakes are using
  10606. pre-shared keys for authentication.
  10607. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10608. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10609. \return 0 if successful.
  10610. _Example_
  10611. \code
  10612. int ret;
  10613. WOLFSSL* ssl;
  10614. ...
  10615. ret = wolfSSL_no_dhe_psk(ssl);
  10616. if (ret != 0) {
  10617. // failed to set no DHE for PSK handshakes
  10618. }
  10619. \endcode
  10620. \sa wolfSSL_CTX_no_dhe_psk
  10621. */
  10622. int wolfSSL_no_dhe_psk(WOLFSSL* ssl);
  10623. /*!
  10624. \ingroup IO
  10625. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10626. force the rollover of keys. A KeyUpdate message is sent to the peer and
  10627. new keys are calculated for encryption. The peer will send back a KeyUpdate
  10628. message and the new decryption keys wil then be calculated.
  10629. This function can only be called after a handshake has been completed.
  10630. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10631. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10632. \return WANT_WRITE if the writing is not ready.
  10633. \return WOLFSSL_SUCCESS if successful.
  10634. _Example_
  10635. \code
  10636. int ret;
  10637. WOLFSSL* ssl;
  10638. ...
  10639. ret = wolfSSL_update_keys(ssl);
  10640. if (ret == WANT_WRITE) {
  10641. // need to call again when I/O ready
  10642. }
  10643. else if (ret != WOLFSSL_SUCCESS) {
  10644. // failed to send key update
  10645. }
  10646. \endcode
  10647. \sa wolfSSL_write
  10648. */
  10649. int wolfSSL_update_keys(WOLFSSL* ssl);
  10650. /*!
  10651. \ingroup IO
  10652. \brief This function is called on a TLS v1.3 client or server wolfSSL to
  10653. determine whether a rollover of keys is in progress. When
  10654. wolfSSL_update_keys() is called, a KeyUpdate message is sent and the
  10655. encryption key is updated. The decryption key is updated when the response
  10656. is received.
  10657. \param [in] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10658. \param [out] required 0 when no key update response required. 1 when no key update response required.
  10659. \return 0 on successful.
  10660. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10661. _Example_
  10662. \code
  10663. int ret;
  10664. WOLFSSL* ssl;
  10665. int required;
  10666. ...
  10667. ret = wolfSSL_key_update_response(ssl, &required);
  10668. if (ret != 0) {
  10669. // bad parameters
  10670. }
  10671. if (required) {
  10672. // encrypt Key updated, awaiting response to change decrypt key
  10673. }
  10674. \endcode
  10675. \sa wolfSSL_update_keys
  10676. */
  10677. int wolfSSL_key_update_response(WOLFSSL* ssl, int* required);
  10678. /*!
  10679. \ingroup Setup
  10680. \brief This function is called on a TLS v1.3 client wolfSSL context to allow
  10681. a client certifcate to be sent post handshake upon request from server.
  10682. This is useful when connecting to a web server that has some pages that
  10683. require client authentication and others that don't.
  10684. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10685. with wolfSSL_CTX_new().
  10686. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  10687. \return SIDE_ERROR if called with a server.
  10688. \return 0 if successful.
  10689. _Example_
  10690. \code
  10691. int ret;
  10692. WOLFSSL_CTX* ctx;
  10693. ...
  10694. ret = wolfSSL_allow_post_handshake_auth(ctx);
  10695. if (ret != 0) {
  10696. // failed to allow post handshake authentication
  10697. }
  10698. \endcode
  10699. \sa wolfSSL_allow_post_handshake_auth
  10700. \sa wolfSSL_request_certificate
  10701. */
  10702. int wolfSSL_CTX_allow_post_handshake_auth(WOLFSSL_CTX* ctx);
  10703. /*!
  10704. \ingroup Setup
  10705. \brief This function is called on a TLS v1.3 client wolfSSL to allow
  10706. a client certifcate to be sent post handshake upon request from server.
  10707. A Post-Handshake Client Authentication extension is sent in the ClientHello.
  10708. This is useful when connecting to a web server that has some pages that
  10709. require client authentication and others that don't.
  10710. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10711. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10712. \return SIDE_ERROR if called with a server.
  10713. \return 0 if successful.
  10714. _Example_
  10715. \code
  10716. int ret;
  10717. WOLFSSL* ssl;
  10718. ...
  10719. ret = wolfSSL_allow_post_handshake_auth(ssl);
  10720. if (ret != 0) {
  10721. // failed to allow post handshake authentication
  10722. }
  10723. \endcode
  10724. \sa wolfSSL_CTX_allow_post_handshake_auth
  10725. \sa wolfSSL_request_certificate
  10726. */
  10727. int wolfSSL_allow_post_handshake_auth(WOLFSSL* ssl);
  10728. /*!
  10729. \ingroup IO
  10730. \brief This function requests a client certificate from the TLS v1.3 client.
  10731. This is useful when a web server is serving some pages that require client
  10732. authentication and others that don't.
  10733. A maximum of 256 requests can be sent on a connection.
  10734. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10735. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10736. \return WANT_WRITE if the writing is not ready.
  10737. \return SIDE_ERROR if called with a client.
  10738. \return NOT_READY_ERROR if called when the handshake is not finished.
  10739. \return POST_HAND_AUTH_ERROR if posthandshake authentication is disallowed.
  10740. \return MEMORY_E if dynamic memory allocation fails.
  10741. \return WOLFSSL_SUCCESS if successful.
  10742. _Example_
  10743. \code
  10744. int ret;
  10745. WOLFSSL* ssl;
  10746. ...
  10747. ret = wolfSSL_request_certificate(ssl);
  10748. if (ret == WANT_WRITE) {
  10749. // need to call again when I/O ready
  10750. }
  10751. else if (ret != WOLFSSL_SUCCESS) {
  10752. // failed to request a client certificate
  10753. }
  10754. \endcode
  10755. \sa wolfSSL_allow_post_handshake_auth
  10756. \sa wolfSSL_write
  10757. */
  10758. int wolfSSL_request_certificate(WOLFSSL* ssl);
  10759. /*!
  10760. \ingroup Setup
  10761. \brief This function sets the list of elliptic curve groups to allow on
  10762. a wolfSSL context in order of preference.
  10763. The list is a null-terminated text string, and a colon-delimited list.
  10764. Call this function to set the key exchange elliptic curve parameters to
  10765. use with the TLS v1.3 connections.
  10766. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10767. with wolfSSL_CTX_new().
  10768. \param [in] list a string that is a colon-delimited list of elliptic curve
  10769. groups.
  10770. \return WOLFSSL_FAILURE if pointer parameters are NULL, there are more than
  10771. WOLFSSL_MAX_GROUP_COUNT groups, a group name is not recognized or not
  10772. using TLS v1.3.
  10773. \return WOLFSSL_SUCCESS if successful.
  10774. _Example_
  10775. \code
  10776. int ret;
  10777. WOLFSSL_CTX* ctx;
  10778. const char* list = "P-384:P-256";
  10779. ...
  10780. ret = wolfSSL_CTX_set1_groups_list(ctx, list);
  10781. if (ret != WOLFSSL_SUCCESS) {
  10782. // failed to set group list
  10783. }
  10784. \endcode
  10785. \sa wolfSSL_set1_groups_list
  10786. \sa wolfSSL_CTX_set_groups
  10787. \sa wolfSSL_set_groups
  10788. \sa wolfSSL_UseKeyShare
  10789. \sa wolfSSL_preferred_group
  10790. */
  10791. int wolfSSL_CTX_set1_groups_list(WOLFSSL_CTX *ctx, char *list);
  10792. /*!
  10793. \ingroup Setup
  10794. \brief This function sets the list of elliptic curve groups to allow on
  10795. a wolfSSL in order of preference.
  10796. The list is a null-terminated text string, and a colon-delimited list.
  10797. Call this function to set the key exchange elliptic curve parameters to
  10798. use with the TLS v1.3 connections.
  10799. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10800. \param [in] list a string that is a colon separated list of key exchange
  10801. groups.
  10802. \return WOLFSSL_FAILURE if pointer parameters are NULL, there are more than
  10803. WOLFSSL_MAX_GROUP_COUNT groups, a group name is not recognized or not
  10804. using TLS v1.3.
  10805. \return WOLFSSL_SUCCESS if successful.
  10806. _Example_
  10807. \code
  10808. int ret;
  10809. WOLFSSL* ssl;
  10810. const char* list = "P-384:P-256";
  10811. ...
  10812. ret = wolfSSL_CTX_set1_groups_list(ssl, list);
  10813. if (ret != WOLFSSL_SUCCESS) {
  10814. // failed to set group list
  10815. }
  10816. \endcode
  10817. \sa wolfSSL_CTX_set1_groups_list
  10818. \sa wolfSSL_CTX_set_groups
  10819. \sa wolfSSL_set_groups
  10820. \sa wolfSSL_UseKeyShare
  10821. \sa wolfSSL_preferred_group
  10822. */
  10823. int wolfSSL_set1_groups_list(WOLFSSL *ssl, char *list);
  10824. /*!
  10825. \ingroup TLS
  10826. \brief This function returns the key exchange group the client prefers to
  10827. use in the TLS v1.3 handshake.
  10828. Call this function to after a handshake is complete to determine which
  10829. group the server prefers so that this information can be used in future
  10830. connections to pre-generate a key pair for key exchange.
  10831. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10832. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  10833. \return SIDE_ERROR if called with a server.
  10834. \return NOT_READY_ERROR if called before handshake is complete.
  10835. \return Group identifier if successful.
  10836. _Example_
  10837. \code
  10838. int ret;
  10839. int group;
  10840. WOLFSSL* ssl;
  10841. ...
  10842. ret = wolfSSL_CTX_set1_groups_list(ssl)
  10843. if (ret < 0) {
  10844. // failed to get group
  10845. }
  10846. group = ret;
  10847. \endcode
  10848. \sa wolfSSL_UseKeyShare
  10849. \sa wolfSSL_CTX_set_groups
  10850. \sa wolfSSL_set_groups
  10851. \sa wolfSSL_CTX_set1_groups_list
  10852. \sa wolfSSL_set1_groups_list
  10853. */
  10854. int wolfSSL_preferred_group(WOLFSSL* ssl);
  10855. /*!
  10856. \ingroup Setup
  10857. \brief This function sets the list of elliptic curve groups to allow on
  10858. a wolfSSL context in order of preference.
  10859. The list is an array of group identifiers with the number of identifiers
  10860. specified in count.
  10861. Call this function to set the key exchange elliptic curve parameters to
  10862. use with the TLS v1.3 connections.
  10863. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  10864. with wolfSSL_CTX_new().
  10865. \param [in] groups a list of key exhange groups by identifier.
  10866. \param [in] count the number of key exchange groups in groups.
  10867. \return BAD_FUNC_ARG if a pointer parameter is null, the number of groups
  10868. exceeds WOLFSSL_MAX_GROUP_COUNT or not using TLS v1.3.
  10869. \return WOLFSSL_SUCCESS if successful.
  10870. _Example_
  10871. \code
  10872. int ret;
  10873. WOLFSSL_CTX* ctx;
  10874. int* groups = { WOLFSSL_ECC_X25519, WOLFSSL_ECC_SECP256R1 };
  10875. int count = 2;
  10876. ...
  10877. ret = wolfSSL_CTX_set1_groups_list(ctx, groups, count);
  10878. if (ret != WOLFSSL_SUCCESS) {
  10879. // failed to set group list
  10880. }
  10881. \endcode
  10882. \sa wolfSSL_set_groups
  10883. \sa wolfSSL_UseKeyShare
  10884. \sa wolfSSL_CTX_set_groups
  10885. \sa wolfSSL_set_groups
  10886. \sa wolfSSL_CTX_set1_groups_list
  10887. \sa wolfSSL_set1_groups_list
  10888. \sa wolfSSL_preferred_group
  10889. */
  10890. int wolfSSL_CTX_set_groups(WOLFSSL_CTX* ctx, int* groups,
  10891. int count);
  10892. /*!
  10893. \ingroup Setup
  10894. \brief This function sets the list of elliptic curve groups to allow on
  10895. a wolfSSL.
  10896. The list is an array of group identifiers with the number of identifiers
  10897. specified in count.
  10898. Call this function to set the key exchange elliptic curve parameters to
  10899. use with the TLS v1.3 connections.
  10900. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10901. \param [in] groups a list of key exhange groups by identifier.
  10902. \param [in] count the number of key exchange groups in groups.
  10903. \return BAD_FUNC_ARG if a pointer parameter is null, the number of groups
  10904. exceeds WOLFSSL_MAX_GROUP_COUNT, any of the identifiers are unrecognized or
  10905. not using TLS v1.3.
  10906. \return WOLFSSL_SUCCESS if successful.
  10907. _Example_
  10908. \code
  10909. int ret;
  10910. WOLFSSL* ssl;
  10911. int* groups = { WOLFSSL_ECC_X25519, WOLFSSL_ECC_SECP256R1 };
  10912. int count = 2;
  10913. ...
  10914. ret = wolfSSL_set_groups(ssl, groups, count);
  10915. if (ret != WOLFSSL_SUCCESS) {
  10916. // failed to set group list
  10917. }
  10918. \endcode
  10919. \sa wolfSSL_CTX_set_groups
  10920. \sa wolfSSL_UseKeyShare
  10921. \sa wolfSSL_CTX_set_groups
  10922. \sa wolfSSL_set_groups
  10923. \sa wolfSSL_CTX_set1_groups_list
  10924. \sa wolfSSL_set1_groups_list
  10925. \sa wolfSSL_preferred_group
  10926. */
  10927. int wolfSSL_set_groups(WOLFSSL* ssl, int* groups, int count);
  10928. /*!
  10929. \ingroup IO
  10930. \brief This function is called on the client side and initiates a
  10931. TLS v1.3 handshake with a server. When this function is called, the
  10932. underlying communication channel has already been set up.
  10933. wolfSSL_connect() works with both blocking and non-blocking I/O.
  10934. When the underlying I/O is non-blocking, wolfSSL_connect() will return
  10935. when the underlying I/O could not satisfy the needs of wolfSSL_connect
  10936. to continue the handshake. In this case, a call to wolfSSL_get_error()
  10937. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. The
  10938. calling process must then repeat the call to wolfSSL_connect() when
  10939. the underlying I/O is ready and wolfSSL will pick up where it left off.
  10940. When using a non-blocking socket, nothing needs to be done, but select()
  10941. can be used to check for the required condition. If the underlying I/O is
  10942. blocking, wolfSSL_connect() will only return once the handshake has been
  10943. finished or an error occurred. wolfSSL takes a different approach to
  10944. certificate verification than OpenSSL does. The default policy for the
  10945. client is to verify the server, this means that if you don't load CAs to
  10946. verify the server you'll get a connect error, unable to verify (-155). It
  10947. you want to mimic OpenSSL behavior of having SSL_connect succeed even if
  10948. verifying the server fails and reducing security you can do this by
  10949. calling: SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling
  10950. SSL_new(); Though it's not recommended.
  10951. \return SSL_SUCCESS upon success.
  10952. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10953. more detailed error code, call wolfSSL_get_error().
  10954. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10955. _Example_
  10956. \code
  10957. int ret = 0;
  10958. int err = 0;
  10959. WOLFSSL* ssl;
  10960. char buffer[80];
  10961. ...
  10962. ret = wolfSSL_connect_TLSv13(ssl);
  10963. if (ret != SSL_SUCCESS) {
  10964. err = wolfSSL_get_error(ssl, ret);
  10965. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  10966. }
  10967. \endcode
  10968. \sa wolfSSL_get_error
  10969. \sa wolfSSL_connect
  10970. \sa wolfSSL_accept_TLSv13
  10971. \sa wolfSSL_accept
  10972. */
  10973. int wolfSSL_connect_TLSv13(WOLFSSL*);
  10974. /*!
  10975. \ingroup IO
  10976. \brief This function is called on the server side and waits for a SSL/TLS
  10977. client to initiate the SSL/TLS handshake. When this function is called,
  10978. the underlying communication channel has already been set up.
  10979. wolfSSL_accept() works with both blocking and non-blocking I/O.
  10980. When the underlying I/O is non-blocking, wolfSSL_accept() will return
  10981. when the underlying I/O could not satisfy the needs of wolfSSL_accept
  10982. to continue the handshake. In this case, a call to wolfSSL_get_error()
  10983. will yield either SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
  10984. The calling process must then repeat the call to wolfSSL_accept when
  10985. data is available to read and wolfSSL will pick up where it left off.
  10986. When using a non-blocking socket, nothing needs to be done, but select()
  10987. can be used to check for the required condition. If the underlying I/O
  10988. is blocking, wolfSSL_accept() will only return once the handshake has
  10989. been finished or an error occurred.
  10990. Call this function when expecting a TLS v1.3 connection though older
  10991. version ClientHello messages are supported.
  10992. \return SSL_SUCCESS upon success.
  10993. \return SSL_FATAL_ERROR will be returned if an error occurred. To get a
  10994. more detailed error code, call wolfSSL_get_error().
  10995. \param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  10996. _Example_
  10997. \code
  10998. int ret = 0;
  10999. int err = 0;
  11000. WOLFSSL* ssl;
  11001. char buffer[80];
  11002. ...
  11003. ret = wolfSSL_accept_TLSv13(ssl);
  11004. if (ret != SSL_SUCCESS) {
  11005. err = wolfSSL_get_error(ssl, ret);
  11006. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11007. }
  11008. \endcode
  11009. \sa wolfSSL_get_error
  11010. \sa wolfSSL_connect_TLSv13
  11011. \sa wolfSSL_connect
  11012. \sa wolfSSL_accept_TLSv13
  11013. \sa wolfSSL_accept
  11014. */
  11015. wolfSSL_accept_TLSv13(WOLFSSL* ssl);
  11016. /*!
  11017. \ingroup Setup
  11018. \brief This function sets the maximum amount of early data that will be
  11019. accepted by a TLS v1.3 server using the wolfSSL context.
  11020. Call this function to limit the amount of early data to process to mitigate
  11021. replay attacks. Early data is protected by keys derived from those of the
  11022. connection that the session ticket was sent and therefore will be the same
  11023. every time a session ticket is used in resumption.
  11024. The value is included in the session ticket for resumption.
  11025. A value of zero indicates no early data is to be sent by client using
  11026. session tickets.
  11027. It is recommended that the number of early data bytes be kept as low as
  11028. practically possible in the application.
  11029. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11030. with wolfSSL_CTX_new().
  11031. \param [in] sz the amount of early data to accept in bytes.
  11032. \return BAD_FUNC_ARG if ctx is NULL or not using TLS v1.3.
  11033. \return SIDE_ERROR if called with a client.
  11034. \return 0 if successful.
  11035. _Example_
  11036. \code
  11037. int ret;
  11038. WOLFSSL_CTX* ctx;
  11039. ...
  11040. ret = wolfSSL_CTX_set_max_early_data(ctx, 128);
  11041. if (ret != WOLFSSL_SUCCESS) {
  11042. // failed to set group list
  11043. }
  11044. \endcode
  11045. \sa wolfSSL_set_max_early_data
  11046. \sa wolfSSL_write_early_data
  11047. \sa wolfSSL_read_early_data
  11048. */
  11049. int wolfSSL_CTX_set_max_early_data(WOLFSSL_CTX* ctx,
  11050. unsigned int sz);
  11051. /*!
  11052. \ingroup Setup
  11053. \brief This function sets the maximum amount of early data that will be
  11054. accepted by a TLS v1.3 server using the wolfSSL context.
  11055. Call this function to limit the amount of early data to process to mitigate
  11056. replay attacks. Early data is protected by keys derived from those of the
  11057. connection that the session ticket was sent and therefore will be the same
  11058. every time a session ticket is used in resumption.
  11059. The value is included in the session ticket for resumption.
  11060. A value of zero indicates no early data is to be sent by client using
  11061. session tickets.
  11062. It is recommended that the number of early data bytes be kept as low as
  11063. practically possible in the application.
  11064. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11065. \param [in] sz the amount of early data to accept from client in bytes.
  11066. \return BAD_FUNC_ARG if ssl is NULL or not using TLS v1.3.
  11067. \return SIDE_ERROR if called with a client.
  11068. \return 0 if successful.
  11069. _Example_
  11070. \code
  11071. int ret;
  11072. WOLFSSL* ssl;
  11073. ...
  11074. ret = wolfSSL_set_max_early_data(ssl, 128);
  11075. if (ret != WOLFSSL_SUCCESS) {
  11076. // failed to set group list
  11077. }
  11078. \endcode
  11079. \sa wolfSSL_CTX_set_max_early_data
  11080. \sa wolfSSL_write_early_data
  11081. \sa wolfSSL_read_early_data
  11082. */
  11083. int wolfSSL_set_max_early_data(WOLFSSL* ssl, unsigned int sz);
  11084. /*!
  11085. \ingroup IO
  11086. \brief This function writes early data to the server on resumption.
  11087. Call this function instead of wolfSSL_connect() or wolfSSL_connect_TLSv13()
  11088. to connect to the server and send the data in the handshake.
  11089. This function is only used with clients.
  11090. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11091. \param [in] data the buffer holding the early data to write to server.
  11092. \param [in] sz the amount of early data to write in bytes.
  11093. \param [out] outSz the amount of early data written in bytes.
  11094. \return BAD_FUNC_ARG if a pointer parameter is NULL, sz is less than 0 or
  11095. not using TLSv1.3.
  11096. \return SIDE_ERROR if called with a server.
  11097. \return WOLFSSL_FATAL_ERROR if the connection is not made.
  11098. \return WOLFSSL_SUCCESS if successful.
  11099. _Example_
  11100. \code
  11101. int ret = 0;
  11102. int err = 0;
  11103. WOLFSSL* ssl;
  11104. byte earlyData[] = { early data };
  11105. int outSz;
  11106. char buffer[80];
  11107. ...
  11108. ret = wolfSSL_write_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
  11109. if (ret != WOLFSSL_SUCCESS) {
  11110. err = wolfSSL_get_error(ssl, ret);
  11111. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11112. goto err_label;
  11113. }
  11114. if (outSz < sizeof(earlyData)) {
  11115. // not all early data was sent
  11116. }
  11117. ret = wolfSSL_connect_TLSv13(ssl);
  11118. if (ret != SSL_SUCCESS) {
  11119. err = wolfSSL_get_error(ssl, ret);
  11120. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11121. }
  11122. \endcode
  11123. \sa wolfSSL_read_early_data
  11124. \sa wolfSSL_connect
  11125. \sa wolfSSL_connect_TLSv13
  11126. */
  11127. int wolfSSL_write_early_data(OLFSSL* ssl, const void* data,
  11128. int sz, int* outSz);
  11129. /*!
  11130. \ingroup IO
  11131. \brief This function reads any early data from a client on resumption.
  11132. Call this function instead of wolfSSL_accept() or wolfSSL_accept_TLSv13()
  11133. to accept a client and read any early data in the handshake.
  11134. If there is no early data than the handshake will be processed as normal.
  11135. This function is only used with servers.
  11136. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11137. \param [out] data a buffer to hold the early data read from client.
  11138. \param [in] sz size of the buffer in bytes.
  11139. \param [out] outSz number of bytes of early data read.
  11140. \return BAD_FUNC_ARG if a pointer parameter is NULL, sz is less than 0 or
  11141. not using TLSv1.3.
  11142. \return SIDE_ERROR if called with a client.
  11143. \return WOLFSSL_FATAL_ERROR if accepting a connection fails.
  11144. \return WOLFSSL_SUCCESS if successful.
  11145. _Example_
  11146. \code
  11147. int ret = 0;
  11148. int err = 0;
  11149. WOLFSSL* ssl;
  11150. byte earlyData[128];
  11151. int outSz;
  11152. char buffer[80];
  11153. ...
  11154. ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
  11155. if (ret != SSL_SUCCESS) {
  11156. err = wolfSSL_get_error(ssl, ret);
  11157. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11158. }
  11159. if (outSz > 0) {
  11160. // early data available
  11161. }
  11162. ret = wolfSSL_accept_TLSv13(ssl);
  11163. if (ret != SSL_SUCCESS) {
  11164. err = wolfSSL_get_error(ssl, ret);
  11165. printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
  11166. }
  11167. \endcode
  11168. \sa wolfSSL_write_early_data
  11169. \sa wolfSSL_accept
  11170. \sa wolfSSL_accept_TLSv13
  11171. */
  11172. int wolfSSL_read_early_data(WOLFSSL* ssl, void* data, int sz,
  11173. int* outSz);
  11174. /*!
  11175. \ingroup Setup
  11176. \brief This function sets the Pre-Shared Key (PSK) client side callback
  11177. for TLS v1.3 connections.
  11178. The callback is used to find a PSK identity and return its key and
  11179. the name of the cipher to use for the handshake.
  11180. The function sets the client_psk_tls13_cb member of the
  11181. WOLFSSL_CTX structure.
  11182. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11183. with wolfSSL_CTX_new().
  11184. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 client.
  11185. _Example_
  11186. \code
  11187. WOLFSSL_CTX* ctx;
  11188. ...
  11189. wolfSSL_CTX_set_psk_client_tls13_callback(ctx, my_psk_client_tls13_cb);
  11190. \endcode
  11191. \sa wolfSSL_set_psk_client_tls13_callback
  11192. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11193. \sa wolfSSL_set_psk_server_tls13_callback
  11194. */
  11195. void wolfSSL_CTX_set_psk_client_tls13_callback(WOLFSSL_CTX* ctx,
  11196. wc_psk_client_tls13_callback cb);
  11197. /*!
  11198. \ingroup Setup
  11199. \brief This function sets the Pre-Shared Key (PSK) client side callback
  11200. for TLS v1.3 connections.
  11201. The callback is used to find a PSK identity and return its key and
  11202. the name of the cipher to use for the handshake.
  11203. The function sets the client_psk_tls13_cb member of the options field in
  11204. WOLFSSL structure.
  11205. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11206. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 client.
  11207. _Example_
  11208. \code
  11209. WOLFSSL* ssl;
  11210. ...
  11211. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  11212. \endcode
  11213. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11214. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11215. \sa wolfSSL_set_psk_server_tls13_callback
  11216. */
  11217. void wolfSSL_set_psk_client_tls13_callback(WOLFSSL* ssl,
  11218. wc_psk_client_tls13_callback cb);
  11219. /*!
  11220. \ingroup Setup
  11221. \brief This function sets the Pre-Shared Key (PSK) server side callback
  11222. for TLS v1.3 connections.
  11223. The callback is used to find a PSK identity and return its key and
  11224. the name of the cipher to use for the handshake.
  11225. The function sets the server_psk_tls13_cb member of the
  11226. WOLFSSL_CTX structure.
  11227. \param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created
  11228. with wolfSSL_CTX_new().
  11229. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 server.
  11230. _Example_
  11231. \code
  11232. WOLFSSL_CTX* ctx;
  11233. ...
  11234. wolfSSL_CTX_set_psk_server_tls13_callback(ctx, my_psk_client_tls13_cb);
  11235. \endcode
  11236. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11237. \sa wolfSSL_set_psk_client_tls13_callback
  11238. \sa wolfSSL_set_psk_server_tls13_callback
  11239. */
  11240. void wolfSSL_CTX_set_psk_server_tls13_callback(WOLFSSL_CTX* ctx,
  11241. wc_psk_server_tls13_callback cb);
  11242. /*!
  11243. \ingroup Setup
  11244. \brief This function sets the Pre-Shared Key (PSK) server side callback
  11245. for TLS v1.3 connections.
  11246. The callback is used to find a PSK identity and return its key and
  11247. the name of the cipher to use for the handshake.
  11248. The function sets the server_psk_tls13_cb member of the options field in
  11249. WOLFSSL structure.
  11250. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11251. \param [in] cb a Pre-Shared Key (PSK) callback for a TLS 1.3 server.
  11252. _Example_
  11253. \code
  11254. WOLFSSL* ssl;
  11255. ...
  11256. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  11257. \endcode
  11258. \sa wolfSSL_CTX_set_psk_client_tls13_callback
  11259. \sa wolfSSL_set_psk_client_tls13_callback
  11260. \sa wolfSSL_CTX_set_psk_server_tls13_callback
  11261. */
  11262. void wolfSSL_set_psk_server_tls13_callback(WOLFSSL* ssl,
  11263. wc_psk_server_tls13_callback cb);
  11264. /*!
  11265. \ingroup Setup
  11266. \brief This function creates a key share entry from the group including
  11267. generating a key pair.
  11268. The KeyShare extension contains all the generated public keys for key
  11269. exchange. If this function is called, then only the groups specified will
  11270. be included.
  11271. Call this function when a preferred group has been previously established
  11272. for the server.
  11273. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11274. \param [in] group a key exchange group identifier.
  11275. \return BAD_FUNC_ARG if ssl is NULL.
  11276. \return MEMORY_E when dynamic memory allocation fails.
  11277. \return WOLFSSL_SUCCESS if successful.
  11278. _Example_
  11279. \code
  11280. int ret;
  11281. WOLFSSL* ssl;
  11282. ...
  11283. ret = wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_X25519);
  11284. if (ret != WOLFSSL_SUCCESS) {
  11285. // failed to set key share
  11286. }
  11287. \endcode
  11288. \sa wolfSSL_preferred_group
  11289. \sa wolfSSL_CTX_set1_groups_list
  11290. \sa wolfSSL_set1_groups_list
  11291. \sa wolfSSL_CTX_set_groups
  11292. \sa wolfSSL_set_groups
  11293. \sa wolfSSL_NoKeyShares
  11294. */
  11295. int wolfSSL_UseKeyShare(WOLFSSL* ssl, word16 group);
  11296. /*!
  11297. \ingroup Setup
  11298. \brief This function is called to ensure no key shares are sent in the
  11299. ClientHello. This will force the server to respond with a HelloRetryRequest
  11300. if a key exchange is required in the handshake.
  11301. Call this function when the expected key exchange group is not known and
  11302. to avoid the generation of keys unnecessarily.
  11303. Note that an extra round-trip will be required to complete the handshake
  11304. when a key exchange is required.
  11305. \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
  11306. \return BAD_FUNC_ARG if ssl is NULL.
  11307. \return SIDE_ERROR if called with a server.
  11308. \return WOLFSSL_SUCCESS if successful.
  11309. _Example_
  11310. \code
  11311. int ret;
  11312. WOLFSSL* ssl;
  11313. ...
  11314. ret = wolfSSL_NoKeyShares(ssl);
  11315. if (ret != WOLFSSL_SUCCESS) {
  11316. // failed to set no key shares
  11317. }
  11318. \endcode
  11319. \sa wolfSSL_UseKeyShare
  11320. */
  11321. int wolfSSL_NoKeyShares(WOLFSSL* ssl);
  11322. /*!
  11323. \ingroup Setup
  11324. \brief This function is used to indicate
  11325. that the application is a server and will only support the TLS 1.3
  11326. protocol. This function allocates memory for and initializes a new
  11327. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11328. with wolfSSL_CTX_new().
  11329. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11330. \return If successful, the call will return a pointer to the newly
  11331. created WOLFSSL_METHOD structure.
  11332. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11333. value of the underlying malloc() implementation will be returned
  11334. (typically NULL with errno will be set to ENOMEM).
  11335. _Example_
  11336. \code
  11337. #include <wolfssl/ssl.h>
  11338. WOLFSSL_METHOD* method;
  11339. WOLFSSL_CTX* ctx;
  11340. method = wolfTLSv1_3_server_method_ex(NULL);
  11341. if (method == NULL) {
  11342. // unable to get method
  11343. }
  11344. ctx = wolfSSL_CTX_new(method);
  11345. ...
  11346. \endcode
  11347. \sa wolfSSLv3_server_method
  11348. \sa wolfTLSv1_server_method
  11349. \sa wolfTLSv1_1_server_method
  11350. \sa wolfTLSv1_2_server_method
  11351. \sa wolfTLSv1_3_server_method
  11352. \sa wolfDTLSv1_server_method
  11353. \sa wolfSSLv23_server_method
  11354. \sa wolfSSL_CTX_new
  11355. */
  11356. WOLFSSL_METHOD *wolfTLSv1_3_server_method_ex(void* heap);
  11357. /*!
  11358. \ingroup Setup
  11359. \brief This function is used to indicate
  11360. that the application is a client and will only support the TLS 1.3
  11361. protocol. This function allocates memory for and initializes a new
  11362. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11363. with wolfSSL_CTX_new().
  11364. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11365. \return If successful, the call will return a pointer to the newly
  11366. created WOLFSSL_METHOD structure.
  11367. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11368. value of the underlying malloc() implementation will be returned
  11369. (typically NULL with errno will be set to ENOMEM).
  11370. _Example_
  11371. \code
  11372. #include <wolfssl/ssl.h>
  11373. WOLFSSL_METHOD* method;
  11374. WOLFSSL_CTX* ctx;
  11375. method = wolfTLSv1_3_client_method_ex(NULL);
  11376. if (method == NULL) {
  11377. // unable to get method
  11378. }
  11379. ctx = wolfSSL_CTX_new(method);
  11380. ...
  11381. \endcode
  11382. \sa wolfSSLv3_client_method
  11383. \sa wolfTLSv1_client_method
  11384. \sa wolfTLSv1_1_client_method
  11385. \sa wolfTLSv1_2_client_method
  11386. \sa wolfTLSv1_3_client_method
  11387. \sa wolfDTLSv1_client_method
  11388. \sa wolfSSLv23_client_method
  11389. \sa wolfSSL_CTX_new
  11390. */
  11391. WOLFSSL_METHOD *wolfTLSv1_3_client_method_ex(void* heap);
  11392. /*!
  11393. \ingroup Setup
  11394. \brief This function is used to indicate
  11395. that the application is a server and will only support the TLS 1.3
  11396. protocol. This function allocates memory for and initializes a new
  11397. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11398. with wolfSSL_CTX_new().
  11399. \return If successful, the call will return a pointer to the newly
  11400. created WOLFSSL_METHOD structure.
  11401. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11402. value of the underlying malloc() implementation will be returned
  11403. (typically NULL with errno will be set to ENOMEM).
  11404. _Example_
  11405. \code
  11406. #include <wolfssl/ssl.h>
  11407. WOLFSSL_METHOD* method;
  11408. WOLFSSL_CTX* ctx;
  11409. method = wolfTLSv1_3_server_method();
  11410. if (method == NULL) {
  11411. // unable to get method
  11412. }
  11413. ctx = wolfSSL_CTX_new(method);
  11414. ...
  11415. \endcode
  11416. \sa wolfSSLv3_server_method
  11417. \sa wolfTLSv1_server_method
  11418. \sa wolfTLSv1_1_server_method
  11419. \sa wolfTLSv1_2_server_method
  11420. \sa wolfTLSv1_3_server_method_ex
  11421. \sa wolfDTLSv1_server_method
  11422. \sa wolfSSLv23_server_method
  11423. \sa wolfSSL_CTX_new
  11424. */
  11425. WOLFSSL_METHOD *wolfTLSv1_3_server_method(void);
  11426. /*!
  11427. \ingroup Setup
  11428. \brief This function is used to indicate
  11429. that the application is a client and will only support the TLS 1.3
  11430. protocol. This function allocates memory for and initializes a new
  11431. wolfSSL_METHOD structure to be used when creating the SSL/TLS context
  11432. with wolfSSL_CTX_new().
  11433. \return If successful, the call will return a pointer to the newly
  11434. created WOLFSSL_METHOD structure.
  11435. \return FAIL If memory allocation fails when calling XMALLOC, the failure
  11436. value of the underlying malloc() implementation will be returned
  11437. (typically NULL with errno will be set to ENOMEM).
  11438. _Example_
  11439. \code
  11440. #include <wolfssl/ssl.h>
  11441. WOLFSSL_METHOD* method;
  11442. WOLFSSL_CTX* ctx;
  11443. method = wolfTLSv1_3_client_method();
  11444. if (method == NULL) {
  11445. // unable to get method
  11446. }
  11447. ctx = wolfSSL_CTX_new(method);
  11448. ...
  11449. \endcode
  11450. \sa wolfSSLv3_client_method
  11451. \sa wolfTLSv1_client_method
  11452. \sa wolfTLSv1_1_client_method
  11453. \sa wolfTLSv1_2_client_method
  11454. \sa wolfTLSv1_3_client_method_ex
  11455. \sa wolfDTLSv1_client_method
  11456. \sa wolfSSLv23_client_method
  11457. \sa wolfSSL_CTX_new
  11458. */
  11459. WOLFSSL_METHOD *wolfTLSv1_3_client_method(void);
  11460. /*!
  11461. \ingroup Setup
  11462. \brief This function returns a WOLFSSL_METHOD similar to
  11463. wolfTLSv1_3_client_method except that it is not determined
  11464. which side yet (server/client).
  11465. \param [in] heap a pointer to a buffer that the static memory allocator will use during dynamic memory allocation.
  11466. \return WOLFSSL_METHOD On successful creations returns a WOLFSSL_METHOD
  11467. pointer
  11468. \return NULL Null if memory allocation error or failure to create method
  11469. _Example_
  11470. \code
  11471. WOLFSSL* ctx;
  11472. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method_ex(NULL));
  11473. // check ret value
  11474. \endcode
  11475. \sa wolfSSL_new
  11476. \sa wolfSSL_free
  11477. */
  11478. WOLFSSL_METHOD *wolfTLSv1_3_method_ex(void* heap);
  11479. /*!
  11480. \ingroup Setup
  11481. \brief This function returns a WOLFSSL_METHOD similar to
  11482. wolfTLSv1_3_client_method except that it is not determined
  11483. which side yet (server/client).
  11484. \return WOLFSSL_METHOD On successful creations returns a WOLFSSL_METHOD
  11485. pointer
  11486. \return NULL Null if memory allocation error or failure to create method
  11487. _Example_
  11488. \code
  11489. WOLFSSL* ctx;
  11490. ctx = wolfSSL_CTX_new(wolfTLSv1_3_method());
  11491. // check ret value
  11492. \endcode
  11493. \sa wolfSSL_new
  11494. \sa wolfSSL_free
  11495. */
  11496. WOLFSSL_METHOD *wolfTLSv1_3_method(void);
  11497. /*!
  11498. \ingroup SSL
  11499. \brief This function sets a fixed / static ephemeral key for testing only
  11500. \return 0 Key loaded successfully
  11501. \param ctx A WOLFSSL_CTX context pointer
  11502. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11503. \param key key file path (if keySz == 0) or actual key buffer (PEM or ASN.1)
  11504. \param keySz key size (should be 0 for "key" arg is file path)
  11505. \param format WOLFSSL_FILETYPE_ASN1 or WOLFSSL_FILETYPE_PEM
  11506. \sa wolfSSL_CTX_get_ephemeral_key
  11507. */
  11508. int wolfSSL_CTX_set_ephemeral_key(WOLFSSL_CTX* ctx, int keyAlgo, const char* key, unsigned int keySz, int format);
  11509. /*!
  11510. \ingroup SSL
  11511. \brief This function sets a fixed / static ephemeral key for testing only
  11512. \return 0 Key loaded successfully
  11513. \param ssl A WOLFSSL object pointer
  11514. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11515. \param key key file path (if keySz == 0) or actual key buffer (PEM or ASN.1)
  11516. \param keySz key size (should be 0 for "key" arg is file path)
  11517. \param format WOLFSSL_FILETYPE_ASN1 or WOLFSSL_FILETYPE_PEM
  11518. \sa wolfSSL_get_ephemeral_key
  11519. */
  11520. int wolfSSL_set_ephemeral_key(WOLFSSL* ssl, int keyAlgo, const char* key, unsigned int keySz, int format);
  11521. /*!
  11522. \ingroup SSL
  11523. \brief This function returns pointer to loaded key as ASN.1/DER
  11524. \return 0 Key returned successfully
  11525. \param ctx A WOLFSSL_CTX context pointer
  11526. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11527. \param key key buffer pointer
  11528. \param keySz key size pointer
  11529. \sa wolfSSL_CTX_set_ephemeral_key
  11530. */
  11531. int wolfSSL_CTX_get_ephemeral_key(WOLFSSL_CTX* ctx, int keyAlgo,
  11532. const unsigned char** key, unsigned int* keySz);
  11533. /*!
  11534. \ingroup SSL
  11535. \brief This function returns pointer to loaded key as ASN.1/DER
  11536. \return 0 Key returned successfully
  11537. \param ssl A WOLFSSL object pointer
  11538. \param keyAlgo enum wc_PkType like WC_PK_TYPE_DH and WC_PK_TYPE_ECDH
  11539. \param key key buffer pointer
  11540. \param keySz key size pointer
  11541. \sa wolfSSL_set_ephemeral_key
  11542. */
  11543. int wolfSSL_get_ephemeral_key(WOLFSSL* ssl, int keyAlgo,
  11544. const unsigned char** key, unsigned int* keySz);
  11545. /*!
  11546. \ingroup SSL
  11547. \brief Sign a message with the chosen message digest, padding, and RSA key
  11548. \return WOLFSSL_SUCCESS on success and WOLFSSL_FAILURE on error
  11549. \param type Hash NID
  11550. \param m Message to sign. Most likely this will be the digest of
  11551. the message to sign
  11552. \param mLen Length of message to sign
  11553. \param sigRet Output buffer
  11554. \param sigLen On Input: length of sigRet buffer
  11555. On Output: length of data written to sigRet
  11556. \param rsa RSA key used to sign the input
  11557. \param flag 1: Output the signature
  11558. 0: Output the value that the unpadded signature should be
  11559. compared to. Note: for RSA_PKCS1_PSS_PADDING the
  11560. wc_RsaPSS_CheckPadding_ex function should be used to check
  11561. the output of a *Verify* function.
  11562. \param padding Padding to use. Only RSA_PKCS1_PSS_PADDING and
  11563. RSA_PKCS1_PADDING are currently supported for signing.
  11564. */
  11565. int wolfSSL_RSA_sign_generic_padding(int type, const unsigned char* m,
  11566. unsigned int mLen, unsigned char* sigRet,
  11567. unsigned int* sigLen, WOLFSSL_RSA* rsa,
  11568. int flag, int padding);
  11569. /*!
  11570. \brief checks if DTLSv1.3 stack has some messages sent but not yet acknowledged
  11571. by the other peer
  11572. \return 1 if there are pending messages, 0 otherwise
  11573. \param ssl A WOLFSSL object pointer
  11574. */
  11575. int wolfSSL_dtls13_has_pending_msg(WOLFSSL *ssl);
  11576. /*!
  11577. \ingroup SSL
  11578. \brief Get the maximum size of Early Data from a session.
  11579. \param [in] s the WOLFSSL_SESSION instance.
  11580. \return the value of max_early_data that was configured in the WOLFSSL* the session
  11581. was derived from.
  11582. \sa wolfSSL_set_max_early_data
  11583. \sa wolfSSL_write_early_data
  11584. \sa wolfSSL_read_early_data
  11585. */
  11586. unsigned int wolfSSL_SESSION_get_max_early_data(const WOLFSSL_SESSION *s);
  11587. /*!
  11588. \ingroup SSL
  11589. \brief Get a new index for external data. This entry applies also for the
  11590. following API:
  11591. - wolfSSL_CTX_get_ex_new_index
  11592. - wolfSSL_get_ex_new_index
  11593. - wolfSSL_SESSION_get_ex_new_index
  11594. - wolfSSL_X509_get_ex_new_index
  11595. \param [in] All input parameters are ignored. The callback functions are not
  11596. supported with wolfSSL.
  11597. \return The new index value to be used with the external data API for this
  11598. object class.
  11599. */
  11600. int wolfSSL_CRYPTO_get_ex_new_index(int, void*, void*, void*, void*);
  11601. /*!
  11602. \brief Enable use of ConnectionID extensions for the SSL object. See RFC 9146
  11603. and RFC 9147
  11604. \return WOLFSSL_SUCCESS on success, error code otherwise
  11605. \param ssl A WOLFSSL object pointer
  11606. \sa wolfSSL_dtls_cid_is_enabled
  11607. \sa wolfSSL_dtls_cid_set
  11608. \sa wolfSSL_dtls_cid_get_rx_size
  11609. \sa wolfSSL_dtls_cid_get_rx
  11610. \sa wolfSSL_dtls_cid_get_tx_size
  11611. \sa wolfSSL_dtls_cid_get_tx
  11612. */
  11613. int wolfSSL_dtls_cid_use(WOLFSSL* ssl);
  11614. /*!
  11615. \brief If invoked after the handshake is complete it checks if ConnectionID was
  11616. successfully negotiated for the SSL object. See RFC 9146 and RFC 9147
  11617. \return 1 if ConnectionID was correctly negotiated, 0 otherwise
  11618. \param ssl A WOLFSSL object pointer
  11619. \sa wolfSSL_dtls_cid_use
  11620. \sa wolfSSL_dtls_cid_set
  11621. \sa wolfSSL_dtls_cid_get_rx_size
  11622. \sa wolfSSL_dtls_cid_get_rx
  11623. \sa wolfSSL_dtls_cid_get_tx_size
  11624. \sa wolfSSL_dtls_cid_get_tx
  11625. */
  11626. int wolfSSL_dtls_cid_is_enabled(WOLFSSL* ssl);
  11627. /*!
  11628. \brief Set the ConnectionID used by the other peer to send records in this
  11629. connection. See RFC 9146 and RFC 9147. The ConnectionID must be at maximum
  11630. DTLS_CID_MAX_SIZE, that is an tunable compile time define, and it can't
  11631. never be bigger than 255 bytes.
  11632. \return WOLFSSL_SUCCESS if ConnectionID was correctly set, error code otherwise
  11633. \param ssl A WOLFSSL object pointern
  11634. \param cid the ConnectionID to be used
  11635. \param size of the ConnectionID provided
  11636. \sa wolfSSL_dtls_cid_use
  11637. \sa wolfSSL_dtls_cid_is_enabled
  11638. \sa wolfSSL_dtls_cid_get_rx_size
  11639. \sa wolfSSL_dtls_cid_get_rx
  11640. \sa wolfSSL_dtls_cid_get_tx_size
  11641. \sa wolfSSL_dtls_cid_get_tx
  11642. */
  11643. int wolfSSL_dtls_cid_set(WOLFSSL* ssl, unsigned char* cid,
  11644. unsigned int size);
  11645. /*!
  11646. \brief Get the size of the ConnectionID used by the other peer to send records
  11647. in this connection. See RFC 9146 and RFC 9147. The size is stored in the
  11648. parameter size.
  11649. \return WOLFSSL_SUCCESS if ConnectionID was correctly negotiated, error code
  11650. otherwise
  11651. \param ssl A WOLFSSL object pointern
  11652. \param size a pointer to an unsigned int where the size will be stored
  11653. \sa wolfSSL_dtls_cid_use
  11654. \sa wolfSSL_dtls_cid_is_enabled
  11655. \sa wolfSSL_dtls_cid_set
  11656. \sa wolfSSL_dtls_cid_get_rx
  11657. \sa wolfSSL_dtls_cid_get_tx_size
  11658. \sa wolfSSL_dtls_cid_get_tx
  11659. */
  11660. int wolfSSL_dtls_cid_get_rx_size(WOLFSSL* ssl,
  11661. unsigned int* size);
  11662. /*!
  11663. \brief Copy the ConnectionID used by the other peer to send records in this
  11664. connection into the buffer pointed by the parameter buffer. See RFC 9146 and RFC
  11665. 9147. The available space in the buffer need to be provided in bufferSz.
  11666. \return WOLFSSL_SUCCESS if ConnectionID was correctly copied, error code
  11667. otherwise
  11668. \param ssl A WOLFSSL object pointern
  11669. \param buffer A buffer where the ConnectionID will be copied
  11670. \param bufferSz available space in buffer
  11671. \sa wolfSSL_dtls_cid_use
  11672. \sa wolfSSL_dtls_cid_is_enabled
  11673. \sa wolfSSL_dtls_cid_set
  11674. \sa wolfSSL_dtls_cid_get_rx_size
  11675. \sa wolfSSL_dtls_cid_get_tx_size
  11676. \sa wolfSSL_dtls_cid_get_tx
  11677. */
  11678. int wolfSSL_dtls_cid_get_rx(WOLFSSL* ssl, unsigned char* buffer,
  11679. unsigned int bufferSz);
  11680. /*!
  11681. \brief Get the size of the ConnectionID used to send records in this
  11682. connection. See RFC 9146 and RFC 9147. The size is stored in the parameter size.
  11683. \return WOLFSSL_SUCCESS if ConnectionID size was correctly stored, error
  11684. code otherwise
  11685. \param ssl A WOLFSSL object pointern
  11686. \param size a pointer to an unsigned int where the size will be stored
  11687. \sa wolfSSL_dtls_cid_use
  11688. \sa wolfSSL_dtls_cid_is_enabled
  11689. \sa wolfSSL_dtls_cid_set
  11690. \sa wolfSSL_dtls_cid_get_rx_size
  11691. \sa wolfSSL_dtls_cid_get_rx
  11692. \sa wolfSSL_dtls_cid_get_tx
  11693. */
  11694. int wolfSSL_dtls_cid_get_tx_size(WOLFSSL* ssl, unsigned int* size);
  11695. /*!
  11696. \brief Copy the ConnectionID used when sending records in this connection into
  11697. the buffer pointer by the parameter buffer. See RFC 9146 and RFC 9147. The
  11698. available size need to be provided in bufferSz.
  11699. \return WOLFSSL_SUCCESS if ConnectionID was correctly copied, error code
  11700. otherwise
  11701. \param ssl A WOLFSSL object pointern
  11702. \param buffer A buffer where the ConnectionID will be copied
  11703. \param bufferSz available space in buffer
  11704. \sa wolfSSL_dtls_cid_use
  11705. \sa wolfSSL_dtls_cid_is_enabled
  11706. \sa wolfSSL_dtls_cid_set
  11707. \sa wolfSSL_dtls_cid_get_rx_size
  11708. \sa wolfSSL_dtls_cid_get_rx
  11709. \sa wolfSSL_dtls_cid_get_tx_size
  11710. */
  11711. int wolfSSL_dtls_cid_get_tx(WOLFSSL* ssl, unsigned char* buffer,
  11712. unsigned int bufferSz);