ssl.h 270 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651
  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. * are met:
  63. *
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. *
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in
  69. * the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3. All advertising materials mentioning features or use of this
  73. * software must display the following acknowledgment:
  74. * "This product includes software developed by the OpenSSL Project
  75. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  76. *
  77. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  78. * endorse or promote products derived from this software without
  79. * prior written permission. For written permission, please contact
  80. * openssl-core@openssl.org.
  81. *
  82. * 5. Products derived from this software may not be called "OpenSSL"
  83. * nor may "OpenSSL" appear in their names without prior written
  84. * permission of the OpenSSL Project.
  85. *
  86. * 6. Redistributions of any form whatsoever must retain the following
  87. * acknowledgment:
  88. * "This product includes software developed by the OpenSSL Project
  89. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  90. *
  91. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  92. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  93. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  94. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  95. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  96. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  97. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  98. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  100. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  101. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  102. * OF THE POSSIBILITY OF SUCH DAMAGE.
  103. * ====================================================================
  104. *
  105. * This product includes cryptographic software written by Eric Young
  106. * (eay@cryptsoft.com). This product includes software written by Tim
  107. * Hudson (tjh@cryptsoft.com).
  108. *
  109. */
  110. /* ====================================================================
  111. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  112. * ECC cipher suite support in OpenSSL originally developed by
  113. * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  114. */
  115. /* ====================================================================
  116. * Copyright 2005 Nokia. All rights reserved.
  117. *
  118. * The portions of the attached software ("Contribution") is developed by
  119. * Nokia Corporation and is licensed pursuant to the OpenSSL open source
  120. * license.
  121. *
  122. * The Contribution, originally written by Mika Kousa and Pasi Eronen of
  123. * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
  124. * support (see RFC 4279) to OpenSSL.
  125. *
  126. * No patent licenses or other rights except those expressly stated in
  127. * the OpenSSL open source license shall be deemed granted or received
  128. * expressly, by implication, estoppel, or otherwise.
  129. *
  130. * No assurances are provided by Nokia that the Contribution does not
  131. * infringe the patent or other intellectual property rights of any third
  132. * party or that the license provides you with all the necessary rights
  133. * to make use of the Contribution.
  134. *
  135. * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
  136. * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
  137. * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
  138. * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
  139. * OTHERWISE.
  140. */
  141. #ifndef OPENSSL_HEADER_SSL_H
  142. #define OPENSSL_HEADER_SSL_H
  143. #include <openssl/base.h>
  144. #include <openssl/bio.h>
  145. #include <openssl/buf.h>
  146. #include <openssl/pem.h>
  147. #include <openssl/span.h>
  148. #include <openssl/ssl3.h>
  149. #include <openssl/thread.h>
  150. #include <openssl/tls1.h>
  151. #include <openssl/x509.h>
  152. #if !defined(OPENSSL_WINDOWS)
  153. #include <sys/time.h>
  154. #endif
  155. // NGINX needs this #include. Consider revisiting this after NGINX 1.14.0 has
  156. // been out for a year or so (assuming that they fix it in that release.) See
  157. // https://boringssl-review.googlesource.com/c/boringssl/+/21664.
  158. #include <openssl/hmac.h>
  159. // Forward-declare struct timeval. On Windows, it is defined in winsock2.h and
  160. // Windows headers define too many macros to be included in public headers.
  161. // However, only a forward declaration is needed.
  162. struct timeval;
  163. #if defined(__cplusplus)
  164. extern "C" {
  165. #endif
  166. // SSL implementation.
  167. // SSL contexts.
  168. //
  169. // |SSL_CTX| objects manage shared state and configuration between multiple TLS
  170. // or DTLS connections. Whether the connections are TLS or DTLS is selected by
  171. // an |SSL_METHOD| on creation.
  172. //
  173. // |SSL_CTX| are reference-counted and may be shared by connections across
  174. // multiple threads. Once shared, functions which change the |SSL_CTX|'s
  175. // configuration may not be used.
  176. // TLS_method is the |SSL_METHOD| used for TLS connections.
  177. OPENSSL_EXPORT const SSL_METHOD *TLS_method(void);
  178. // DTLS_method is the |SSL_METHOD| used for DTLS connections.
  179. OPENSSL_EXPORT const SSL_METHOD *DTLS_method(void);
  180. // TLS_with_buffers_method is like |TLS_method|, but avoids all use of
  181. // crypto/x509. All client connections created with |TLS_with_buffers_method|
  182. // will fail unless a certificate verifier is installed with
  183. // |SSL_set_custom_verify| or |SSL_CTX_set_custom_verify|.
  184. OPENSSL_EXPORT const SSL_METHOD *TLS_with_buffers_method(void);
  185. // DTLS_with_buffers_method is like |DTLS_method|, but avoids all use of
  186. // crypto/x509.
  187. OPENSSL_EXPORT const SSL_METHOD *DTLS_with_buffers_method(void);
  188. // SSL_CTX_new returns a newly-allocated |SSL_CTX| with default settings or NULL
  189. // on error.
  190. OPENSSL_EXPORT SSL_CTX *SSL_CTX_new(const SSL_METHOD *method);
  191. // SSL_CTX_up_ref increments the reference count of |ctx|. It returns one.
  192. OPENSSL_EXPORT int SSL_CTX_up_ref(SSL_CTX *ctx);
  193. // SSL_CTX_free releases memory associated with |ctx|.
  194. OPENSSL_EXPORT void SSL_CTX_free(SSL_CTX *ctx);
  195. // SSL connections.
  196. //
  197. // An |SSL| object represents a single TLS or DTLS connection. Although the
  198. // shared |SSL_CTX| is thread-safe, an |SSL| is not thread-safe and may only be
  199. // used on one thread at a time.
  200. // SSL_new returns a newly-allocated |SSL| using |ctx| or NULL on error. The new
  201. // connection inherits settings from |ctx| at the time of creation. Settings may
  202. // also be individually configured on the connection.
  203. //
  204. // On creation, an |SSL| is not configured to be either a client or server. Call
  205. // |SSL_set_connect_state| or |SSL_set_accept_state| to set this.
  206. OPENSSL_EXPORT SSL *SSL_new(SSL_CTX *ctx);
  207. // SSL_free releases memory associated with |ssl|.
  208. OPENSSL_EXPORT void SSL_free(SSL *ssl);
  209. // SSL_get_SSL_CTX returns the |SSL_CTX| associated with |ssl|. If
  210. // |SSL_set_SSL_CTX| is called, it returns the new |SSL_CTX|, not the initial
  211. // one.
  212. OPENSSL_EXPORT SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
  213. // SSL_set_connect_state configures |ssl| to be a client.
  214. OPENSSL_EXPORT void SSL_set_connect_state(SSL *ssl);
  215. // SSL_set_accept_state configures |ssl| to be a server.
  216. OPENSSL_EXPORT void SSL_set_accept_state(SSL *ssl);
  217. // SSL_is_server returns one if |ssl| is configured as a server and zero
  218. // otherwise.
  219. OPENSSL_EXPORT int SSL_is_server(const SSL *ssl);
  220. // SSL_is_dtls returns one if |ssl| is a DTLS connection and zero otherwise.
  221. OPENSSL_EXPORT int SSL_is_dtls(const SSL *ssl);
  222. // SSL_set_bio configures |ssl| to read from |rbio| and write to |wbio|. |ssl|
  223. // takes ownership of the two |BIO|s. If |rbio| and |wbio| are the same, |ssl|
  224. // only takes ownership of one reference.
  225. //
  226. // In DTLS, |rbio| must be non-blocking to properly handle timeouts and
  227. // retransmits.
  228. //
  229. // If |rbio| is the same as the currently configured |BIO| for reading, that
  230. // side is left untouched and is not freed.
  231. //
  232. // If |wbio| is the same as the currently configured |BIO| for writing AND |ssl|
  233. // is not currently configured to read from and write to the same |BIO|, that
  234. // side is left untouched and is not freed. This asymmetry is present for
  235. // historical reasons.
  236. //
  237. // Due to the very complex historical behavior of this function, calling this
  238. // function if |ssl| already has |BIO|s configured is deprecated. Prefer
  239. // |SSL_set0_rbio| and |SSL_set0_wbio| instead.
  240. OPENSSL_EXPORT void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio);
  241. // SSL_set0_rbio configures |ssl| to read from |rbio|. It takes ownership of
  242. // |rbio|.
  243. //
  244. // Note that, although this function and |SSL_set0_wbio| may be called on the
  245. // same |BIO|, each call takes a reference. Use |BIO_up_ref| to balance this.
  246. OPENSSL_EXPORT void SSL_set0_rbio(SSL *ssl, BIO *rbio);
  247. // SSL_set0_wbio configures |ssl| to write to |wbio|. It takes ownership of
  248. // |wbio|.
  249. //
  250. // Note that, although this function and |SSL_set0_rbio| may be called on the
  251. // same |BIO|, each call takes a reference. Use |BIO_up_ref| to balance this.
  252. OPENSSL_EXPORT void SSL_set0_wbio(SSL *ssl, BIO *wbio);
  253. // SSL_get_rbio returns the |BIO| that |ssl| reads from.
  254. OPENSSL_EXPORT BIO *SSL_get_rbio(const SSL *ssl);
  255. // SSL_get_wbio returns the |BIO| that |ssl| writes to.
  256. OPENSSL_EXPORT BIO *SSL_get_wbio(const SSL *ssl);
  257. // SSL_get_fd calls |SSL_get_rfd|.
  258. OPENSSL_EXPORT int SSL_get_fd(const SSL *ssl);
  259. // SSL_get_rfd returns the file descriptor that |ssl| is configured to read
  260. // from. If |ssl|'s read |BIO| is not configured or doesn't wrap a file
  261. // descriptor then it returns -1.
  262. //
  263. // Note: On Windows, this may return either a file descriptor or a socket (cast
  264. // to int), depending on whether |ssl| was configured with a file descriptor or
  265. // socket |BIO|.
  266. OPENSSL_EXPORT int SSL_get_rfd(const SSL *ssl);
  267. // SSL_get_wfd returns the file descriptor that |ssl| is configured to write
  268. // to. If |ssl|'s write |BIO| is not configured or doesn't wrap a file
  269. // descriptor then it returns -1.
  270. //
  271. // Note: On Windows, this may return either a file descriptor or a socket (cast
  272. // to int), depending on whether |ssl| was configured with a file descriptor or
  273. // socket |BIO|.
  274. OPENSSL_EXPORT int SSL_get_wfd(const SSL *ssl);
  275. // SSL_set_fd configures |ssl| to read from and write to |fd|. It returns one
  276. // on success and zero on allocation error. The caller retains ownership of
  277. // |fd|.
  278. //
  279. // On Windows, |fd| is cast to a |SOCKET| and used with Winsock APIs.
  280. OPENSSL_EXPORT int SSL_set_fd(SSL *ssl, int fd);
  281. // SSL_set_rfd configures |ssl| to read from |fd|. It returns one on success and
  282. // zero on allocation error. The caller retains ownership of |fd|.
  283. //
  284. // On Windows, |fd| is cast to a |SOCKET| and used with Winsock APIs.
  285. OPENSSL_EXPORT int SSL_set_rfd(SSL *ssl, int fd);
  286. // SSL_set_wfd configures |ssl| to write to |fd|. It returns one on success and
  287. // zero on allocation error. The caller retains ownership of |fd|.
  288. //
  289. // On Windows, |fd| is cast to a |SOCKET| and used with Winsock APIs.
  290. OPENSSL_EXPORT int SSL_set_wfd(SSL *ssl, int fd);
  291. // SSL_do_handshake continues the current handshake. If there is none or the
  292. // handshake has completed or False Started, it returns one. Otherwise, it
  293. // returns <= 0. The caller should pass the value into |SSL_get_error| to
  294. // determine how to proceed.
  295. //
  296. // In DTLS, the caller must drive retransmissions. Whenever |SSL_get_error|
  297. // signals |SSL_ERROR_WANT_READ|, use |DTLSv1_get_timeout| to determine the
  298. // current timeout. If it expires before the next retry, call
  299. // |DTLSv1_handle_timeout|. Note that DTLS handshake retransmissions use fresh
  300. // sequence numbers, so it is not sufficient to replay packets at the transport.
  301. //
  302. // TODO(davidben): Ensure 0 is only returned on transport EOF.
  303. // https://crbug.com/466303.
  304. OPENSSL_EXPORT int SSL_do_handshake(SSL *ssl);
  305. // SSL_connect configures |ssl| as a client, if unconfigured, and calls
  306. // |SSL_do_handshake|.
  307. OPENSSL_EXPORT int SSL_connect(SSL *ssl);
  308. // SSL_accept configures |ssl| as a server, if unconfigured, and calls
  309. // |SSL_do_handshake|.
  310. OPENSSL_EXPORT int SSL_accept(SSL *ssl);
  311. // SSL_read reads up to |num| bytes from |ssl| into |buf|. It implicitly runs
  312. // any pending handshakes, including renegotiations when enabled. On success, it
  313. // returns the number of bytes read. Otherwise, it returns <= 0. The caller
  314. // should pass the value into |SSL_get_error| to determine how to proceed.
  315. //
  316. // TODO(davidben): Ensure 0 is only returned on transport EOF.
  317. // https://crbug.com/466303.
  318. OPENSSL_EXPORT int SSL_read(SSL *ssl, void *buf, int num);
  319. // SSL_peek behaves like |SSL_read| but does not consume any bytes returned.
  320. OPENSSL_EXPORT int SSL_peek(SSL *ssl, void *buf, int num);
  321. // SSL_pending returns the number of buffered, decrypted bytes available for
  322. // read in |ssl|. It does not read from the transport.
  323. //
  324. // In DTLS, it is possible for this function to return zero while there is
  325. // buffered, undecrypted data from the transport in |ssl|. For example,
  326. // |SSL_read| may read a datagram with two records, decrypt the first, and leave
  327. // the second buffered for a subsequent call to |SSL_read|. Callers that wish to
  328. // detect this case can use |SSL_has_pending|.
  329. OPENSSL_EXPORT int SSL_pending(const SSL *ssl);
  330. // SSL_has_pending returns one if |ssl| has buffered, decrypted bytes available
  331. // for read, or if |ssl| has buffered data from the transport that has not yet
  332. // been decrypted. If |ssl| has neither, this function returns zero.
  333. //
  334. // In TLS, BoringSSL does not implement read-ahead, so this function returns one
  335. // if and only if |SSL_pending| would return a non-zero value. In DTLS, it is
  336. // possible for this function to return one while |SSL_pending| returns zero.
  337. // For example, |SSL_read| may read a datagram with two records, decrypt the
  338. // first, and leave the second buffered for a subsequent call to |SSL_read|.
  339. //
  340. // As a result, if this function returns one, the next call to |SSL_read| may
  341. // still fail, read from the transport, or both. The buffered, undecrypted data
  342. // may be invalid or incomplete.
  343. OPENSSL_EXPORT int SSL_has_pending(const SSL *ssl);
  344. // SSL_write writes up to |num| bytes from |buf| into |ssl|. It implicitly runs
  345. // any pending handshakes, including renegotiations when enabled. On success, it
  346. // returns the number of bytes written. Otherwise, it returns <= 0. The caller
  347. // should pass the value into |SSL_get_error| to determine how to proceed.
  348. //
  349. // In TLS, a non-blocking |SSL_write| differs from non-blocking |write| in that
  350. // a failed |SSL_write| still commits to the data passed in. When retrying, the
  351. // caller must supply the original write buffer (or a larger one containing the
  352. // original as a prefix). By default, retries will fail if they also do not
  353. // reuse the same |buf| pointer. This may be relaxed with
  354. // |SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER|, but the buffer contents still must be
  355. // unchanged.
  356. //
  357. // By default, in TLS, |SSL_write| will not return success until all |num| bytes
  358. // are written. This may be relaxed with |SSL_MODE_ENABLE_PARTIAL_WRITE|. It
  359. // allows |SSL_write| to complete with a partial result when only part of the
  360. // input was written in a single record.
  361. //
  362. // In DTLS, neither |SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER| and
  363. // |SSL_MODE_ENABLE_PARTIAL_WRITE| do anything. The caller may retry with a
  364. // different buffer freely. A single call to |SSL_write| only ever writes a
  365. // single record in a single packet, so |num| must be at most
  366. // |SSL3_RT_MAX_PLAIN_LENGTH|.
  367. //
  368. // TODO(davidben): Ensure 0 is only returned on transport EOF.
  369. // https://crbug.com/466303.
  370. OPENSSL_EXPORT int SSL_write(SSL *ssl, const void *buf, int num);
  371. // SSL_KEY_UPDATE_REQUESTED indicates that the peer should reply to a KeyUpdate
  372. // message with its own, thus updating traffic secrets for both directions on
  373. // the connection.
  374. #define SSL_KEY_UPDATE_REQUESTED 1
  375. // SSL_KEY_UPDATE_NOT_REQUESTED indicates that the peer should not reply with
  376. // it's own KeyUpdate message.
  377. #define SSL_KEY_UPDATE_NOT_REQUESTED 0
  378. // SSL_key_update queues a TLS 1.3 KeyUpdate message to be sent on |ssl|
  379. // if one is not already queued. The |request_type| argument must one of the
  380. // |SSL_KEY_UPDATE_*| values. This function requires that |ssl| have completed a
  381. // TLS >= 1.3 handshake. It returns one on success or zero on error.
  382. //
  383. // Note that this function does not _send_ the message itself. The next call to
  384. // |SSL_write| will cause the message to be sent. |SSL_write| may be called with
  385. // a zero length to flush a KeyUpdate message when no application data is
  386. // pending.
  387. OPENSSL_EXPORT int SSL_key_update(SSL *ssl, int request_type);
  388. // SSL_shutdown shuts down |ssl|. It runs in two stages. First, it sends
  389. // close_notify and returns zero or one on success or -1 on failure. Zero
  390. // indicates that close_notify was sent, but not received, and one additionally
  391. // indicates that the peer's close_notify had already been received.
  392. //
  393. // To then wait for the peer's close_notify, run |SSL_shutdown| to completion a
  394. // second time. This returns 1 on success and -1 on failure. Application data
  395. // is considered a fatal error at this point. To process or discard it, read
  396. // until close_notify with |SSL_read| instead.
  397. //
  398. // In both cases, on failure, pass the return value into |SSL_get_error| to
  399. // determine how to proceed.
  400. //
  401. // Most callers should stop at the first stage. Reading for close_notify is
  402. // primarily used for uncommon protocols where the underlying transport is
  403. // reused after TLS completes. Additionally, DTLS uses an unordered transport
  404. // and is unordered, so the second stage is a no-op in DTLS.
  405. OPENSSL_EXPORT int SSL_shutdown(SSL *ssl);
  406. // SSL_CTX_set_quiet_shutdown sets quiet shutdown on |ctx| to |mode|. If
  407. // enabled, |SSL_shutdown| will not send a close_notify alert or wait for one
  408. // from the peer. It will instead synchronously return one.
  409. OPENSSL_EXPORT void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
  410. // SSL_CTX_get_quiet_shutdown returns whether quiet shutdown is enabled for
  411. // |ctx|.
  412. OPENSSL_EXPORT int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
  413. // SSL_set_quiet_shutdown sets quiet shutdown on |ssl| to |mode|. If enabled,
  414. // |SSL_shutdown| will not send a close_notify alert or wait for one from the
  415. // peer. It will instead synchronously return one.
  416. OPENSSL_EXPORT void SSL_set_quiet_shutdown(SSL *ssl, int mode);
  417. // SSL_get_quiet_shutdown returns whether quiet shutdown is enabled for
  418. // |ssl|.
  419. OPENSSL_EXPORT int SSL_get_quiet_shutdown(const SSL *ssl);
  420. // SSL_get_error returns a |SSL_ERROR_*| value for the most recent operation on
  421. // |ssl|. It should be called after an operation failed to determine whether the
  422. // error was fatal and, if not, when to retry.
  423. OPENSSL_EXPORT int SSL_get_error(const SSL *ssl, int ret_code);
  424. // SSL_ERROR_NONE indicates the operation succeeded.
  425. #define SSL_ERROR_NONE 0
  426. // SSL_ERROR_SSL indicates the operation failed within the library. The caller
  427. // may inspect the error queue for more information.
  428. #define SSL_ERROR_SSL 1
  429. // SSL_ERROR_WANT_READ indicates the operation failed attempting to read from
  430. // the transport. The caller may retry the operation when the transport is ready
  431. // for reading.
  432. //
  433. // If signaled by a DTLS handshake, the caller must also call
  434. // |DTLSv1_get_timeout| and |DTLSv1_handle_timeout| as appropriate. See
  435. // |SSL_do_handshake|.
  436. #define SSL_ERROR_WANT_READ 2
  437. // SSL_ERROR_WANT_WRITE indicates the operation failed attempting to write to
  438. // the transport. The caller may retry the operation when the transport is ready
  439. // for writing.
  440. #define SSL_ERROR_WANT_WRITE 3
  441. // SSL_ERROR_WANT_X509_LOOKUP indicates the operation failed in calling the
  442. // |cert_cb| or |client_cert_cb|. The caller may retry the operation when the
  443. // callback is ready to return a certificate or one has been configured
  444. // externally.
  445. //
  446. // See also |SSL_CTX_set_cert_cb| and |SSL_CTX_set_client_cert_cb|.
  447. #define SSL_ERROR_WANT_X509_LOOKUP 4
  448. // SSL_ERROR_SYSCALL indicates the operation failed externally to the library.
  449. // The caller should consult the system-specific error mechanism. This is
  450. // typically |errno| but may be something custom if using a custom |BIO|. It
  451. // may also be signaled if the transport returned EOF, in which case the
  452. // operation's return value will be zero.
  453. #define SSL_ERROR_SYSCALL 5
  454. // SSL_ERROR_ZERO_RETURN indicates the operation failed because the connection
  455. // was cleanly shut down with a close_notify alert.
  456. #define SSL_ERROR_ZERO_RETURN 6
  457. // SSL_ERROR_WANT_CONNECT indicates the operation failed attempting to connect
  458. // the transport (the |BIO| signaled |BIO_RR_CONNECT|). The caller may retry the
  459. // operation when the transport is ready.
  460. #define SSL_ERROR_WANT_CONNECT 7
  461. // SSL_ERROR_WANT_ACCEPT indicates the operation failed attempting to accept a
  462. // connection from the transport (the |BIO| signaled |BIO_RR_ACCEPT|). The
  463. // caller may retry the operation when the transport is ready.
  464. //
  465. // TODO(davidben): Remove this. It's used by accept BIOs which are bizarre.
  466. #define SSL_ERROR_WANT_ACCEPT 8
  467. // SSL_ERROR_WANT_CHANNEL_ID_LOOKUP is never used.
  468. //
  469. // TODO(davidben): Remove this. Some callers reference it when stringifying
  470. // errors. They should use |SSL_error_description| instead.
  471. #define SSL_ERROR_WANT_CHANNEL_ID_LOOKUP 9
  472. // SSL_ERROR_PENDING_SESSION indicates the operation failed because the session
  473. // lookup callback indicated the session was unavailable. The caller may retry
  474. // the operation when lookup has completed.
  475. //
  476. // See also |SSL_CTX_sess_set_get_cb| and |SSL_magic_pending_session_ptr|.
  477. #define SSL_ERROR_PENDING_SESSION 11
  478. // SSL_ERROR_PENDING_CERTIFICATE indicates the operation failed because the
  479. // early callback indicated certificate lookup was incomplete. The caller may
  480. // retry the operation when lookup has completed.
  481. //
  482. // See also |SSL_CTX_set_select_certificate_cb|.
  483. #define SSL_ERROR_PENDING_CERTIFICATE 12
  484. // SSL_ERROR_WANT_PRIVATE_KEY_OPERATION indicates the operation failed because
  485. // a private key operation was unfinished. The caller may retry the operation
  486. // when the private key operation is complete.
  487. //
  488. // See also |SSL_set_private_key_method| and
  489. // |SSL_CTX_set_private_key_method|.
  490. #define SSL_ERROR_WANT_PRIVATE_KEY_OPERATION 13
  491. // SSL_ERROR_PENDING_TICKET indicates that a ticket decryption is pending. The
  492. // caller may retry the operation when the decryption is ready.
  493. //
  494. // See also |SSL_CTX_set_ticket_aead_method|.
  495. #define SSL_ERROR_PENDING_TICKET 14
  496. // SSL_ERROR_EARLY_DATA_REJECTED indicates that early data was rejected. The
  497. // caller should treat this as a connection failure and retry any operations
  498. // associated with the rejected early data. |SSL_reset_early_data_reject| may be
  499. // used to reuse the underlying connection for the retry.
  500. #define SSL_ERROR_EARLY_DATA_REJECTED 15
  501. // SSL_ERROR_WANT_CERTIFICATE_VERIFY indicates the operation failed because
  502. // certificate verification was incomplete. The caller may retry the operation
  503. // when certificate verification is complete.
  504. //
  505. // See also |SSL_CTX_set_custom_verify|.
  506. #define SSL_ERROR_WANT_CERTIFICATE_VERIFY 16
  507. #define SSL_ERROR_HANDOFF 17
  508. #define SSL_ERROR_HANDBACK 18
  509. // SSL_ERROR_WANT_RENEGOTIATE indicates the operation is pending a response to
  510. // a renegotiation request from the server. The caller may call
  511. // |SSL_renegotiate| to schedule a renegotiation and retry the operation.
  512. //
  513. // See also |ssl_renegotiate_explicit|.
  514. #define SSL_ERROR_WANT_RENEGOTIATE 19
  515. // SSL_ERROR_HANDSHAKE_HINTS_READY indicates the handshake has progressed enough
  516. // for |SSL_serialize_handshake_hints| to be called. See also
  517. // |SSL_request_handshake_hints|.
  518. #define SSL_ERROR_HANDSHAKE_HINTS_READY 20
  519. // SSL_error_description returns a string representation of |err|, where |err|
  520. // is one of the |SSL_ERROR_*| constants returned by |SSL_get_error|, or NULL
  521. // if the value is unrecognized.
  522. OPENSSL_EXPORT const char *SSL_error_description(int err);
  523. // SSL_set_mtu sets the |ssl|'s MTU in DTLS to |mtu|. It returns one on success
  524. // and zero on failure.
  525. OPENSSL_EXPORT int SSL_set_mtu(SSL *ssl, unsigned mtu);
  526. // DTLSv1_set_initial_timeout_duration sets the initial duration for a DTLS
  527. // handshake timeout.
  528. //
  529. // This duration overrides the default of 1 second, which is the strong
  530. // recommendation of RFC 6347 (see section 4.2.4.1). However, there may exist
  531. // situations where a shorter timeout would be beneficial, such as for
  532. // time-sensitive applications.
  533. OPENSSL_EXPORT void DTLSv1_set_initial_timeout_duration(SSL *ssl,
  534. unsigned duration_ms);
  535. // DTLSv1_get_timeout queries the next DTLS handshake timeout. If there is a
  536. // timeout in progress, it sets |*out| to the time remaining and returns one.
  537. // Otherwise, it returns zero.
  538. //
  539. // When the timeout expires, call |DTLSv1_handle_timeout| to handle the
  540. // retransmit behavior.
  541. //
  542. // NOTE: This function must be queried again whenever the handshake state
  543. // machine changes, including when |DTLSv1_handle_timeout| is called.
  544. OPENSSL_EXPORT int DTLSv1_get_timeout(const SSL *ssl, struct timeval *out);
  545. // DTLSv1_handle_timeout is called when a DTLS handshake timeout expires. If no
  546. // timeout had expired, it returns 0. Otherwise, it retransmits the previous
  547. // flight of handshake messages and returns 1. If too many timeouts had expired
  548. // without progress or an error occurs, it returns -1.
  549. //
  550. // The caller's external timer should be compatible with the one |ssl| queries
  551. // within some fudge factor. Otherwise, the call will be a no-op, but
  552. // |DTLSv1_get_timeout| will return an updated timeout.
  553. //
  554. // If the function returns -1, checking if |SSL_get_error| returns
  555. // |SSL_ERROR_WANT_WRITE| may be used to determine if the retransmit failed due
  556. // to a non-fatal error at the write |BIO|. However, the operation may not be
  557. // retried until the next timeout fires.
  558. //
  559. // WARNING: This function breaks the usual return value convention.
  560. //
  561. // TODO(davidben): This |SSL_ERROR_WANT_WRITE| behavior is kind of bizarre.
  562. OPENSSL_EXPORT int DTLSv1_handle_timeout(SSL *ssl);
  563. // Protocol versions.
  564. #define DTLS1_VERSION_MAJOR 0xfe
  565. #define SSL3_VERSION_MAJOR 0x03
  566. #define SSL3_VERSION 0x0300
  567. #define TLS1_VERSION 0x0301
  568. #define TLS1_1_VERSION 0x0302
  569. #define TLS1_2_VERSION 0x0303
  570. #define TLS1_3_VERSION 0x0304
  571. #define DTLS1_VERSION 0xfeff
  572. #define DTLS1_2_VERSION 0xfefd
  573. // SSL_CTX_set_min_proto_version sets the minimum protocol version for |ctx| to
  574. // |version|. If |version| is zero, the default minimum version is used. It
  575. // returns one on success and zero if |version| is invalid.
  576. OPENSSL_EXPORT int SSL_CTX_set_min_proto_version(SSL_CTX *ctx,
  577. uint16_t version);
  578. // SSL_CTX_set_max_proto_version sets the maximum protocol version for |ctx| to
  579. // |version|. If |version| is zero, the default maximum version is used. It
  580. // returns one on success and zero if |version| is invalid.
  581. OPENSSL_EXPORT int SSL_CTX_set_max_proto_version(SSL_CTX *ctx,
  582. uint16_t version);
  583. // SSL_CTX_get_min_proto_version returns the minimum protocol version for |ctx|
  584. OPENSSL_EXPORT uint16_t SSL_CTX_get_min_proto_version(const SSL_CTX *ctx);
  585. // SSL_CTX_get_max_proto_version returns the maximum protocol version for |ctx|
  586. OPENSSL_EXPORT uint16_t SSL_CTX_get_max_proto_version(const SSL_CTX *ctx);
  587. // SSL_set_min_proto_version sets the minimum protocol version for |ssl| to
  588. // |version|. If |version| is zero, the default minimum version is used. It
  589. // returns one on success and zero if |version| is invalid.
  590. OPENSSL_EXPORT int SSL_set_min_proto_version(SSL *ssl, uint16_t version);
  591. // SSL_set_max_proto_version sets the maximum protocol version for |ssl| to
  592. // |version|. If |version| is zero, the default maximum version is used. It
  593. // returns one on success and zero if |version| is invalid.
  594. OPENSSL_EXPORT int SSL_set_max_proto_version(SSL *ssl, uint16_t version);
  595. // SSL_get_min_proto_version returns the minimum protocol version for |ssl|. If
  596. // the connection's configuration has been shed, 0 is returned.
  597. OPENSSL_EXPORT uint16_t SSL_get_min_proto_version(const SSL *ssl);
  598. // SSL_get_max_proto_version returns the maximum protocol version for |ssl|. If
  599. // the connection's configuration has been shed, 0 is returned.
  600. OPENSSL_EXPORT uint16_t SSL_get_max_proto_version(const SSL *ssl);
  601. // SSL_version returns the TLS or DTLS protocol version used by |ssl|, which is
  602. // one of the |*_VERSION| values. (E.g. |TLS1_2_VERSION|.) Before the version
  603. // is negotiated, the result is undefined.
  604. OPENSSL_EXPORT int SSL_version(const SSL *ssl);
  605. // Options.
  606. //
  607. // Options configure protocol behavior.
  608. // SSL_OP_NO_QUERY_MTU, in DTLS, disables querying the MTU from the underlying
  609. // |BIO|. Instead, the MTU is configured with |SSL_set_mtu|.
  610. #define SSL_OP_NO_QUERY_MTU 0x00001000L
  611. // SSL_OP_NO_TICKET disables session ticket support (RFC 5077).
  612. #define SSL_OP_NO_TICKET 0x00004000L
  613. // SSL_OP_CIPHER_SERVER_PREFERENCE configures servers to select ciphers and
  614. // ECDHE curves according to the server's preferences instead of the
  615. // client's.
  616. #define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L
  617. // The following flags toggle individual protocol versions. This is deprecated.
  618. // Use |SSL_CTX_set_min_proto_version| and |SSL_CTX_set_max_proto_version|
  619. // instead.
  620. #define SSL_OP_NO_TLSv1 0x04000000L
  621. #define SSL_OP_NO_TLSv1_2 0x08000000L
  622. #define SSL_OP_NO_TLSv1_1 0x10000000L
  623. #define SSL_OP_NO_TLSv1_3 0x20000000L
  624. #define SSL_OP_NO_DTLSv1 SSL_OP_NO_TLSv1
  625. #define SSL_OP_NO_DTLSv1_2 SSL_OP_NO_TLSv1_2
  626. // SSL_CTX_set_options enables all options set in |options| (which should be one
  627. // or more of the |SSL_OP_*| values, ORed together) in |ctx|. It returns a
  628. // bitmask representing the resulting enabled options.
  629. OPENSSL_EXPORT uint32_t SSL_CTX_set_options(SSL_CTX *ctx, uint32_t options);
  630. // SSL_CTX_clear_options disables all options set in |options| (which should be
  631. // one or more of the |SSL_OP_*| values, ORed together) in |ctx|. It returns a
  632. // bitmask representing the resulting enabled options.
  633. OPENSSL_EXPORT uint32_t SSL_CTX_clear_options(SSL_CTX *ctx, uint32_t options);
  634. // SSL_CTX_get_options returns a bitmask of |SSL_OP_*| values that represent all
  635. // the options enabled for |ctx|.
  636. OPENSSL_EXPORT uint32_t SSL_CTX_get_options(const SSL_CTX *ctx);
  637. // SSL_set_options enables all options set in |options| (which should be one or
  638. // more of the |SSL_OP_*| values, ORed together) in |ssl|. It returns a bitmask
  639. // representing the resulting enabled options.
  640. OPENSSL_EXPORT uint32_t SSL_set_options(SSL *ssl, uint32_t options);
  641. // SSL_clear_options disables all options set in |options| (which should be one
  642. // or more of the |SSL_OP_*| values, ORed together) in |ssl|. It returns a
  643. // bitmask representing the resulting enabled options.
  644. OPENSSL_EXPORT uint32_t SSL_clear_options(SSL *ssl, uint32_t options);
  645. // SSL_get_options returns a bitmask of |SSL_OP_*| values that represent all the
  646. // options enabled for |ssl|.
  647. OPENSSL_EXPORT uint32_t SSL_get_options(const SSL *ssl);
  648. // Modes.
  649. //
  650. // Modes configure API behavior.
  651. // SSL_MODE_ENABLE_PARTIAL_WRITE, in TLS, allows |SSL_write| to complete with a
  652. // partial result when the only part of the input was written in a single
  653. // record. In DTLS, it does nothing.
  654. #define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
  655. // SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER, in TLS, allows retrying an incomplete
  656. // |SSL_write| with a different buffer. However, |SSL_write| still assumes the
  657. // buffer contents are unchanged. This is not the default to avoid the
  658. // misconception that non-blocking |SSL_write| behaves like non-blocking
  659. // |write|. In DTLS, it does nothing.
  660. #define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
  661. // SSL_MODE_NO_AUTO_CHAIN disables automatically building a certificate chain
  662. // before sending certificates to the peer. This flag is set (and the feature
  663. // disabled) by default.
  664. // TODO(davidben): Remove this behavior. https://crbug.com/boringssl/42.
  665. #define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
  666. // SSL_MODE_ENABLE_FALSE_START allows clients to send application data before
  667. // receipt of ChangeCipherSpec and Finished. This mode enables full handshakes
  668. // to 'complete' in one RTT. See RFC 7918.
  669. //
  670. // When False Start is enabled, |SSL_do_handshake| may succeed before the
  671. // handshake has completely finished. |SSL_write| will function at this point,
  672. // and |SSL_read| will transparently wait for the final handshake leg before
  673. // returning application data. To determine if False Start occurred or when the
  674. // handshake is completely finished, see |SSL_in_false_start|, |SSL_in_init|,
  675. // and |SSL_CB_HANDSHAKE_DONE| from |SSL_CTX_set_info_callback|.
  676. #define SSL_MODE_ENABLE_FALSE_START 0x00000080L
  677. // SSL_MODE_CBC_RECORD_SPLITTING causes multi-byte CBC records in TLS 1.0 to be
  678. // split in two: the first record will contain a single byte and the second will
  679. // contain the remainder. This effectively randomises the IV and prevents BEAST
  680. // attacks.
  681. #define SSL_MODE_CBC_RECORD_SPLITTING 0x00000100L
  682. // SSL_MODE_NO_SESSION_CREATION will cause any attempts to create a session to
  683. // fail with SSL_R_SESSION_MAY_NOT_BE_CREATED. This can be used to enforce that
  684. // session resumption is used for a given SSL*.
  685. #define SSL_MODE_NO_SESSION_CREATION 0x00000200L
  686. // SSL_MODE_SEND_FALLBACK_SCSV sends TLS_FALLBACK_SCSV in the ClientHello.
  687. // To be set only by applications that reconnect with a downgraded protocol
  688. // version; see RFC 7507 for details.
  689. //
  690. // DO NOT ENABLE THIS if your application attempts a normal handshake. Only use
  691. // this in explicit fallback retries, following the guidance in RFC 7507.
  692. #define SSL_MODE_SEND_FALLBACK_SCSV 0x00000400L
  693. // SSL_CTX_set_mode enables all modes set in |mode| (which should be one or more
  694. // of the |SSL_MODE_*| values, ORed together) in |ctx|. It returns a bitmask
  695. // representing the resulting enabled modes.
  696. OPENSSL_EXPORT uint32_t SSL_CTX_set_mode(SSL_CTX *ctx, uint32_t mode);
  697. // SSL_CTX_clear_mode disables all modes set in |mode| (which should be one or
  698. // more of the |SSL_MODE_*| values, ORed together) in |ctx|. It returns a
  699. // bitmask representing the resulting enabled modes.
  700. OPENSSL_EXPORT uint32_t SSL_CTX_clear_mode(SSL_CTX *ctx, uint32_t mode);
  701. // SSL_CTX_get_mode returns a bitmask of |SSL_MODE_*| values that represent all
  702. // the modes enabled for |ssl|.
  703. OPENSSL_EXPORT uint32_t SSL_CTX_get_mode(const SSL_CTX *ctx);
  704. // SSL_set_mode enables all modes set in |mode| (which should be one or more of
  705. // the |SSL_MODE_*| values, ORed together) in |ssl|. It returns a bitmask
  706. // representing the resulting enabled modes.
  707. OPENSSL_EXPORT uint32_t SSL_set_mode(SSL *ssl, uint32_t mode);
  708. // SSL_clear_mode disables all modes set in |mode| (which should be one or more
  709. // of the |SSL_MODE_*| values, ORed together) in |ssl|. It returns a bitmask
  710. // representing the resulting enabled modes.
  711. OPENSSL_EXPORT uint32_t SSL_clear_mode(SSL *ssl, uint32_t mode);
  712. // SSL_get_mode returns a bitmask of |SSL_MODE_*| values that represent all the
  713. // modes enabled for |ssl|.
  714. OPENSSL_EXPORT uint32_t SSL_get_mode(const SSL *ssl);
  715. // SSL_CTX_set0_buffer_pool sets a |CRYPTO_BUFFER_POOL| that will be used to
  716. // store certificates. This can allow multiple connections to share
  717. // certificates and thus save memory.
  718. //
  719. // The SSL_CTX does not take ownership of |pool| and the caller must ensure
  720. // that |pool| outlives |ctx| and all objects linked to it, including |SSL|,
  721. // |X509| and |SSL_SESSION| objects. Basically, don't ever free |pool|.
  722. OPENSSL_EXPORT void SSL_CTX_set0_buffer_pool(SSL_CTX *ctx,
  723. CRYPTO_BUFFER_POOL *pool);
  724. // Configuring certificates and private keys.
  725. //
  726. // These functions configure the connection's leaf certificate, private key, and
  727. // certificate chain. The certificate chain is ordered leaf to root (as sent on
  728. // the wire) but does not include the leaf. Both client and server certificates
  729. // use these functions.
  730. //
  731. // Certificates and keys may be configured before the handshake or dynamically
  732. // in the early callback and certificate callback.
  733. // SSL_CTX_use_certificate sets |ctx|'s leaf certificate to |x509|. It returns
  734. // one on success and zero on failure.
  735. OPENSSL_EXPORT int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x509);
  736. // SSL_use_certificate sets |ssl|'s leaf certificate to |x509|. It returns one
  737. // on success and zero on failure.
  738. OPENSSL_EXPORT int SSL_use_certificate(SSL *ssl, X509 *x509);
  739. // SSL_CTX_use_PrivateKey sets |ctx|'s private key to |pkey|. It returns one on
  740. // success and zero on failure.
  741. OPENSSL_EXPORT int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
  742. // SSL_use_PrivateKey sets |ssl|'s private key to |pkey|. It returns one on
  743. // success and zero on failure.
  744. OPENSSL_EXPORT int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
  745. // SSL_CTX_set0_chain sets |ctx|'s certificate chain, excluding the leaf, to
  746. // |chain|. On success, it returns one and takes ownership of |chain|.
  747. // Otherwise, it returns zero.
  748. OPENSSL_EXPORT int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *chain);
  749. // SSL_CTX_set1_chain sets |ctx|'s certificate chain, excluding the leaf, to
  750. // |chain|. It returns one on success and zero on failure. The caller retains
  751. // ownership of |chain| and may release it freely.
  752. OPENSSL_EXPORT int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *chain);
  753. // SSL_set0_chain sets |ssl|'s certificate chain, excluding the leaf, to
  754. // |chain|. On success, it returns one and takes ownership of |chain|.
  755. // Otherwise, it returns zero.
  756. OPENSSL_EXPORT int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *chain);
  757. // SSL_set1_chain sets |ssl|'s certificate chain, excluding the leaf, to
  758. // |chain|. It returns one on success and zero on failure. The caller retains
  759. // ownership of |chain| and may release it freely.
  760. OPENSSL_EXPORT int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *chain);
  761. // SSL_CTX_add0_chain_cert appends |x509| to |ctx|'s certificate chain. On
  762. // success, it returns one and takes ownership of |x509|. Otherwise, it returns
  763. // zero.
  764. OPENSSL_EXPORT int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509);
  765. // SSL_CTX_add1_chain_cert appends |x509| to |ctx|'s certificate chain. It
  766. // returns one on success and zero on failure. The caller retains ownership of
  767. // |x509| and may release it freely.
  768. OPENSSL_EXPORT int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509);
  769. // SSL_add0_chain_cert appends |x509| to |ctx|'s certificate chain. On success,
  770. // it returns one and takes ownership of |x509|. Otherwise, it returns zero.
  771. OPENSSL_EXPORT int SSL_add0_chain_cert(SSL *ssl, X509 *x509);
  772. // SSL_CTX_add_extra_chain_cert calls |SSL_CTX_add0_chain_cert|.
  773. OPENSSL_EXPORT int SSL_CTX_add_extra_chain_cert(SSL_CTX *ctx, X509 *x509);
  774. // SSL_add1_chain_cert appends |x509| to |ctx|'s certificate chain. It returns
  775. // one on success and zero on failure. The caller retains ownership of |x509|
  776. // and may release it freely.
  777. OPENSSL_EXPORT int SSL_add1_chain_cert(SSL *ssl, X509 *x509);
  778. // SSL_CTX_clear_chain_certs clears |ctx|'s certificate chain and returns
  779. // one.
  780. OPENSSL_EXPORT int SSL_CTX_clear_chain_certs(SSL_CTX *ctx);
  781. // SSL_CTX_clear_extra_chain_certs calls |SSL_CTX_clear_chain_certs|.
  782. OPENSSL_EXPORT int SSL_CTX_clear_extra_chain_certs(SSL_CTX *ctx);
  783. // SSL_clear_chain_certs clears |ssl|'s certificate chain and returns one.
  784. OPENSSL_EXPORT int SSL_clear_chain_certs(SSL *ssl);
  785. // SSL_CTX_set_cert_cb sets a callback that is called to select a certificate.
  786. // The callback returns one on success, zero on internal error, and a negative
  787. // number on failure or to pause the handshake. If the handshake is paused,
  788. // |SSL_get_error| will return |SSL_ERROR_WANT_X509_LOOKUP|.
  789. //
  790. // On the client, the callback may call |SSL_get0_certificate_types| and
  791. // |SSL_get_client_CA_list| for information on the server's certificate
  792. // request.
  793. //
  794. // On the server, the callback will be called after extensions have been
  795. // processed, but before the resumption decision has been made. This differs
  796. // from OpenSSL which handles resumption before selecting the certificate.
  797. OPENSSL_EXPORT void SSL_CTX_set_cert_cb(SSL_CTX *ctx,
  798. int (*cb)(SSL *ssl, void *arg),
  799. void *arg);
  800. // SSL_set_cert_cb sets a callback that is called to select a certificate. The
  801. // callback returns one on success, zero on internal error, and a negative
  802. // number on failure or to pause the handshake. If the handshake is paused,
  803. // |SSL_get_error| will return |SSL_ERROR_WANT_X509_LOOKUP|.
  804. //
  805. // On the client, the callback may call |SSL_get0_certificate_types| and
  806. // |SSL_get_client_CA_list| for information on the server's certificate
  807. // request.
  808. //
  809. // On the server, the callback will be called after extensions have been
  810. // processed, but before the resumption decision has been made. This differs
  811. // from OpenSSL which handles resumption before selecting the certificate.
  812. OPENSSL_EXPORT void SSL_set_cert_cb(SSL *ssl, int (*cb)(SSL *ssl, void *arg),
  813. void *arg);
  814. // SSL_get0_certificate_types, for a client, sets |*out_types| to an array
  815. // containing the client certificate types requested by a server. It returns the
  816. // length of the array. Note this list is always empty in TLS 1.3. The server
  817. // will instead send signature algorithms. See
  818. // |SSL_get0_peer_verify_algorithms|.
  819. //
  820. // The behavior of this function is undefined except during the callbacks set by
  821. // by |SSL_CTX_set_cert_cb| and |SSL_CTX_set_client_cert_cb| or when the
  822. // handshake is paused because of them.
  823. OPENSSL_EXPORT size_t SSL_get0_certificate_types(const SSL *ssl,
  824. const uint8_t **out_types);
  825. // SSL_get0_peer_verify_algorithms sets |*out_sigalgs| to an array containing
  826. // the signature algorithms the peer is able to verify. It returns the length of
  827. // the array. Note these values are only sent starting TLS 1.2 and only
  828. // mandatory starting TLS 1.3. If not sent, the empty array is returned. For the
  829. // historical client certificate types list, see |SSL_get0_certificate_types|.
  830. //
  831. // The behavior of this function is undefined except during the callbacks set by
  832. // by |SSL_CTX_set_cert_cb| and |SSL_CTX_set_client_cert_cb| or when the
  833. // handshake is paused because of them.
  834. OPENSSL_EXPORT size_t
  835. SSL_get0_peer_verify_algorithms(const SSL *ssl, const uint16_t **out_sigalgs);
  836. // SSL_get0_peer_delegation_algorithms sets |*out_sigalgs| to an array
  837. // containing the signature algorithms the peer is willing to use with delegated
  838. // credentials. It returns the length of the array. If not sent, the empty
  839. // array is returned.
  840. //
  841. // The behavior of this function is undefined except during the callbacks set by
  842. // by |SSL_CTX_set_cert_cb| and |SSL_CTX_set_client_cert_cb| or when the
  843. // handshake is paused because of them.
  844. OPENSSL_EXPORT size_t
  845. SSL_get0_peer_delegation_algorithms(const SSL *ssl,
  846. const uint16_t **out_sigalgs);
  847. // SSL_certs_clear resets the private key, leaf certificate, and certificate
  848. // chain of |ssl|.
  849. OPENSSL_EXPORT void SSL_certs_clear(SSL *ssl);
  850. // SSL_CTX_check_private_key returns one if the certificate and private key
  851. // configured in |ctx| are consistent and zero otherwise.
  852. OPENSSL_EXPORT int SSL_CTX_check_private_key(const SSL_CTX *ctx);
  853. // SSL_check_private_key returns one if the certificate and private key
  854. // configured in |ssl| are consistent and zero otherwise.
  855. OPENSSL_EXPORT int SSL_check_private_key(const SSL *ssl);
  856. // SSL_CTX_get0_certificate returns |ctx|'s leaf certificate.
  857. OPENSSL_EXPORT X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
  858. // SSL_get_certificate returns |ssl|'s leaf certificate.
  859. OPENSSL_EXPORT X509 *SSL_get_certificate(const SSL *ssl);
  860. // SSL_CTX_get0_privatekey returns |ctx|'s private key.
  861. OPENSSL_EXPORT EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);
  862. // SSL_get_privatekey returns |ssl|'s private key.
  863. OPENSSL_EXPORT EVP_PKEY *SSL_get_privatekey(const SSL *ssl);
  864. // SSL_CTX_get0_chain_certs sets |*out_chain| to |ctx|'s certificate chain and
  865. // returns one.
  866. OPENSSL_EXPORT int SSL_CTX_get0_chain_certs(const SSL_CTX *ctx,
  867. STACK_OF(X509) **out_chain);
  868. // SSL_CTX_get_extra_chain_certs calls |SSL_CTX_get0_chain_certs|.
  869. OPENSSL_EXPORT int SSL_CTX_get_extra_chain_certs(const SSL_CTX *ctx,
  870. STACK_OF(X509) **out_chain);
  871. // SSL_get0_chain_certs sets |*out_chain| to |ssl|'s certificate chain and
  872. // returns one.
  873. OPENSSL_EXPORT int SSL_get0_chain_certs(const SSL *ssl,
  874. STACK_OF(X509) **out_chain);
  875. // SSL_CTX_set_signed_cert_timestamp_list sets the list of signed certificate
  876. // timestamps that is sent to clients that request it. The |list| argument must
  877. // contain one or more SCT structures serialised as a SignedCertificateTimestamp
  878. // List (see https://tools.ietf.org/html/rfc6962#section-3.3) – i.e. each SCT
  879. // is prefixed by a big-endian, uint16 length and the concatenation of one or
  880. // more such prefixed SCTs are themselves also prefixed by a uint16 length. It
  881. // returns one on success and zero on error. The caller retains ownership of
  882. // |list|.
  883. OPENSSL_EXPORT int SSL_CTX_set_signed_cert_timestamp_list(SSL_CTX *ctx,
  884. const uint8_t *list,
  885. size_t list_len);
  886. // SSL_set_signed_cert_timestamp_list sets the list of signed certificate
  887. // timestamps that is sent to clients that request is. The same format as the
  888. // one used for |SSL_CTX_set_signed_cert_timestamp_list| applies. The caller
  889. // retains ownership of |list|.
  890. OPENSSL_EXPORT int SSL_set_signed_cert_timestamp_list(SSL *ctx,
  891. const uint8_t *list,
  892. size_t list_len);
  893. // SSL_CTX_set_ocsp_response sets the OCSP response that is sent to clients
  894. // which request it. It returns one on success and zero on error. The caller
  895. // retains ownership of |response|.
  896. OPENSSL_EXPORT int SSL_CTX_set_ocsp_response(SSL_CTX *ctx,
  897. const uint8_t *response,
  898. size_t response_len);
  899. // SSL_set_ocsp_response sets the OCSP response that is sent to clients which
  900. // request it. It returns one on success and zero on error. The caller retains
  901. // ownership of |response|.
  902. OPENSSL_EXPORT int SSL_set_ocsp_response(SSL *ssl,
  903. const uint8_t *response,
  904. size_t response_len);
  905. // SSL_SIGN_* are signature algorithm values as defined in TLS 1.3.
  906. #define SSL_SIGN_RSA_PKCS1_SHA1 0x0201
  907. #define SSL_SIGN_RSA_PKCS1_SHA256 0x0401
  908. #define SSL_SIGN_RSA_PKCS1_SHA384 0x0501
  909. #define SSL_SIGN_RSA_PKCS1_SHA512 0x0601
  910. #define SSL_SIGN_ECDSA_SHA1 0x0203
  911. #define SSL_SIGN_ECDSA_SECP256R1_SHA256 0x0403
  912. #define SSL_SIGN_ECDSA_SECP384R1_SHA384 0x0503
  913. #define SSL_SIGN_ECDSA_SECP521R1_SHA512 0x0603
  914. #define SSL_SIGN_RSA_PSS_RSAE_SHA256 0x0804
  915. #define SSL_SIGN_RSA_PSS_RSAE_SHA384 0x0805
  916. #define SSL_SIGN_RSA_PSS_RSAE_SHA512 0x0806
  917. #define SSL_SIGN_ED25519 0x0807
  918. // SSL_SIGN_RSA_PKCS1_MD5_SHA1 is an internal signature algorithm used to
  919. // specify raw RSASSA-PKCS1-v1_5 with an MD5/SHA-1 concatenation, as used in TLS
  920. // before TLS 1.2.
  921. #define SSL_SIGN_RSA_PKCS1_MD5_SHA1 0xff01
  922. // SSL_get_signature_algorithm_name returns a human-readable name for |sigalg|,
  923. // or NULL if unknown. If |include_curve| is one, the curve for ECDSA algorithms
  924. // is included as in TLS 1.3. Otherwise, it is excluded as in TLS 1.2.
  925. OPENSSL_EXPORT const char *SSL_get_signature_algorithm_name(uint16_t sigalg,
  926. int include_curve);
  927. // SSL_get_signature_algorithm_key_type returns the key type associated with
  928. // |sigalg| as an |EVP_PKEY_*| constant or |EVP_PKEY_NONE| if unknown.
  929. OPENSSL_EXPORT int SSL_get_signature_algorithm_key_type(uint16_t sigalg);
  930. // SSL_get_signature_algorithm_digest returns the digest function associated
  931. // with |sigalg| or |NULL| if |sigalg| has no prehash (Ed25519) or is unknown.
  932. OPENSSL_EXPORT const EVP_MD *SSL_get_signature_algorithm_digest(
  933. uint16_t sigalg);
  934. // SSL_is_signature_algorithm_rsa_pss returns one if |sigalg| is an RSA-PSS
  935. // signature algorithm and zero otherwise.
  936. OPENSSL_EXPORT int SSL_is_signature_algorithm_rsa_pss(uint16_t sigalg);
  937. // SSL_CTX_set_signing_algorithm_prefs configures |ctx| to use |prefs| as the
  938. // preference list when signing with |ctx|'s private key. It returns one on
  939. // success and zero on error. |prefs| should not include the internal-only value
  940. // |SSL_SIGN_RSA_PKCS1_MD5_SHA1|.
  941. OPENSSL_EXPORT int SSL_CTX_set_signing_algorithm_prefs(SSL_CTX *ctx,
  942. const uint16_t *prefs,
  943. size_t num_prefs);
  944. // SSL_set_signing_algorithm_prefs configures |ssl| to use |prefs| as the
  945. // preference list when signing with |ssl|'s private key. It returns one on
  946. // success and zero on error. |prefs| should not include the internal-only value
  947. // |SSL_SIGN_RSA_PKCS1_MD5_SHA1|.
  948. OPENSSL_EXPORT int SSL_set_signing_algorithm_prefs(SSL *ssl,
  949. const uint16_t *prefs,
  950. size_t num_prefs);
  951. // Certificate and private key convenience functions.
  952. // SSL_CTX_set_chain_and_key sets the certificate chain and private key for a
  953. // TLS client or server. References to the given |CRYPTO_BUFFER| and |EVP_PKEY|
  954. // objects are added as needed. Exactly one of |privkey| or |privkey_method|
  955. // may be non-NULL. Returns one on success and zero on error.
  956. OPENSSL_EXPORT int SSL_CTX_set_chain_and_key(
  957. SSL_CTX *ctx, CRYPTO_BUFFER *const *certs, size_t num_certs,
  958. EVP_PKEY *privkey, const SSL_PRIVATE_KEY_METHOD *privkey_method);
  959. // SSL_set_chain_and_key sets the certificate chain and private key for a TLS
  960. // client or server. References to the given |CRYPTO_BUFFER| and |EVP_PKEY|
  961. // objects are added as needed. Exactly one of |privkey| or |privkey_method|
  962. // may be non-NULL. Returns one on success and zero on error.
  963. OPENSSL_EXPORT int SSL_set_chain_and_key(
  964. SSL *ssl, CRYPTO_BUFFER *const *certs, size_t num_certs, EVP_PKEY *privkey,
  965. const SSL_PRIVATE_KEY_METHOD *privkey_method);
  966. // SSL_CTX_get0_chain returns the list of |CRYPTO_BUFFER|s that were set by
  967. // |SSL_CTX_set_chain_and_key|. Reference counts are not incremented by this
  968. // call. The return value may be |NULL| if no chain has been set.
  969. //
  970. // (Note: if a chain was configured by non-|CRYPTO_BUFFER|-based functions then
  971. // the return value is undefined and, even if not NULL, the stack itself may
  972. // contain nullptrs. Thus you shouldn't mix this function with
  973. // non-|CRYPTO_BUFFER| functions for manipulating the chain.)
  974. //
  975. // There is no |SSL*| version of this function because connections discard
  976. // configuration after handshaking, thus making it of questionable utility.
  977. OPENSSL_EXPORT const STACK_OF(CRYPTO_BUFFER)*
  978. SSL_CTX_get0_chain(const SSL_CTX *ctx);
  979. // SSL_CTX_use_RSAPrivateKey sets |ctx|'s private key to |rsa|. It returns one
  980. // on success and zero on failure.
  981. OPENSSL_EXPORT int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
  982. // SSL_use_RSAPrivateKey sets |ctx|'s private key to |rsa|. It returns one on
  983. // success and zero on failure.
  984. OPENSSL_EXPORT int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
  985. // The following functions configure certificates or private keys but take as
  986. // input DER-encoded structures. They return one on success and zero on
  987. // failure.
  988. OPENSSL_EXPORT int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, size_t der_len,
  989. const uint8_t *der);
  990. OPENSSL_EXPORT int SSL_use_certificate_ASN1(SSL *ssl, const uint8_t *der,
  991. size_t der_len);
  992. OPENSSL_EXPORT int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx,
  993. const uint8_t *der,
  994. size_t der_len);
  995. OPENSSL_EXPORT int SSL_use_PrivateKey_ASN1(int type, SSL *ssl,
  996. const uint8_t *der, size_t der_len);
  997. OPENSSL_EXPORT int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx,
  998. const uint8_t *der,
  999. size_t der_len);
  1000. OPENSSL_EXPORT int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const uint8_t *der,
  1001. size_t der_len);
  1002. // The following functions configure certificates or private keys but take as
  1003. // input files to read from. They return one on success and zero on failure. The
  1004. // |type| parameter is one of the |SSL_FILETYPE_*| values and determines whether
  1005. // the file's contents are read as PEM or DER.
  1006. #define SSL_FILETYPE_PEM 1
  1007. #define SSL_FILETYPE_ASN1 2
  1008. OPENSSL_EXPORT int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx,
  1009. const char *file,
  1010. int type);
  1011. OPENSSL_EXPORT int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file,
  1012. int type);
  1013. OPENSSL_EXPORT int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file,
  1014. int type);
  1015. OPENSSL_EXPORT int SSL_use_certificate_file(SSL *ssl, const char *file,
  1016. int type);
  1017. OPENSSL_EXPORT int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file,
  1018. int type);
  1019. OPENSSL_EXPORT int SSL_use_PrivateKey_file(SSL *ssl, const char *file,
  1020. int type);
  1021. // SSL_CTX_use_certificate_chain_file configures certificates for |ctx|. It
  1022. // reads the contents of |file| as a PEM-encoded leaf certificate followed
  1023. // optionally by the certificate chain to send to the peer. It returns one on
  1024. // success and zero on failure.
  1025. OPENSSL_EXPORT int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx,
  1026. const char *file);
  1027. // SSL_CTX_set_default_passwd_cb sets the password callback for PEM-based
  1028. // convenience functions called on |ctx|.
  1029. OPENSSL_EXPORT void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,
  1030. pem_password_cb *cb);
  1031. // SSL_CTX_get_default_passwd_cb returns the callback set by
  1032. // |SSL_CTX_set_default_passwd_cb|.
  1033. OPENSSL_EXPORT pem_password_cb *SSL_CTX_get_default_passwd_cb(
  1034. const SSL_CTX *ctx);
  1035. // SSL_CTX_set_default_passwd_cb_userdata sets the userdata parameter for
  1036. // |ctx|'s password callback.
  1037. OPENSSL_EXPORT void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,
  1038. void *data);
  1039. // SSL_CTX_get_default_passwd_cb_userdata returns the userdata parameter set by
  1040. // |SSL_CTX_set_default_passwd_cb_userdata|.
  1041. OPENSSL_EXPORT void *SSL_CTX_get_default_passwd_cb_userdata(const SSL_CTX *ctx);
  1042. // Custom private keys.
  1043. enum ssl_private_key_result_t BORINGSSL_ENUM_INT {
  1044. ssl_private_key_success,
  1045. ssl_private_key_retry,
  1046. ssl_private_key_failure,
  1047. };
  1048. // ssl_private_key_method_st (aka |SSL_PRIVATE_KEY_METHOD|) describes private
  1049. // key hooks. This is used to off-load signing operations to a custom,
  1050. // potentially asynchronous, backend. Metadata about the key such as the type
  1051. // and size are parsed out of the certificate.
  1052. //
  1053. // Callers that use this structure should additionally call
  1054. // |SSL_set_signing_algorithm_prefs| or |SSL_CTX_set_signing_algorithm_prefs|
  1055. // with the private key's capabilities. This ensures BoringSSL will select a
  1056. // suitable signature algorithm for the private key.
  1057. struct ssl_private_key_method_st {
  1058. // sign signs the message |in| in using the specified signature algorithm. On
  1059. // success, it returns |ssl_private_key_success| and writes at most |max_out|
  1060. // bytes of signature data to |out| and sets |*out_len| to the number of bytes
  1061. // written. On failure, it returns |ssl_private_key_failure|. If the operation
  1062. // has not completed, it returns |ssl_private_key_retry|. |sign| should
  1063. // arrange for the high-level operation on |ssl| to be retried when the
  1064. // operation is completed. This will result in a call to |complete|.
  1065. //
  1066. // |signature_algorithm| is one of the |SSL_SIGN_*| values, as defined in TLS
  1067. // 1.3. Note that, in TLS 1.2, ECDSA algorithms do not require that curve
  1068. // sizes match hash sizes, so the curve portion of |SSL_SIGN_ECDSA_*| values
  1069. // must be ignored. BoringSSL will internally handle the curve matching logic
  1070. // where appropriate.
  1071. //
  1072. // It is an error to call |sign| while another private key operation is in
  1073. // progress on |ssl|.
  1074. enum ssl_private_key_result_t (*sign)(SSL *ssl, uint8_t *out, size_t *out_len,
  1075. size_t max_out,
  1076. uint16_t signature_algorithm,
  1077. const uint8_t *in, size_t in_len);
  1078. // decrypt decrypts |in_len| bytes of encrypted data from |in|. On success it
  1079. // returns |ssl_private_key_success|, writes at most |max_out| bytes of
  1080. // decrypted data to |out| and sets |*out_len| to the actual number of bytes
  1081. // written. On failure it returns |ssl_private_key_failure|. If the operation
  1082. // has not completed, it returns |ssl_private_key_retry|. The caller should
  1083. // arrange for the high-level operation on |ssl| to be retried when the
  1084. // operation is completed, which will result in a call to |complete|. This
  1085. // function only works with RSA keys and should perform a raw RSA decryption
  1086. // operation with no padding.
  1087. //
  1088. // It is an error to call |decrypt| while another private key operation is in
  1089. // progress on |ssl|.
  1090. enum ssl_private_key_result_t (*decrypt)(SSL *ssl, uint8_t *out,
  1091. size_t *out_len, size_t max_out,
  1092. const uint8_t *in, size_t in_len);
  1093. // complete completes a pending operation. If the operation has completed, it
  1094. // returns |ssl_private_key_success| and writes the result to |out| as in
  1095. // |sign|. Otherwise, it returns |ssl_private_key_failure| on failure and
  1096. // |ssl_private_key_retry| if the operation is still in progress.
  1097. //
  1098. // |complete| may be called arbitrarily many times before completion, but it
  1099. // is an error to call |complete| if there is no pending operation in progress
  1100. // on |ssl|.
  1101. enum ssl_private_key_result_t (*complete)(SSL *ssl, uint8_t *out,
  1102. size_t *out_len, size_t max_out);
  1103. };
  1104. // SSL_set_private_key_method configures a custom private key on |ssl|.
  1105. // |key_method| must remain valid for the lifetime of |ssl|.
  1106. OPENSSL_EXPORT void SSL_set_private_key_method(
  1107. SSL *ssl, const SSL_PRIVATE_KEY_METHOD *key_method);
  1108. // SSL_CTX_set_private_key_method configures a custom private key on |ctx|.
  1109. // |key_method| must remain valid for the lifetime of |ctx|.
  1110. OPENSSL_EXPORT void SSL_CTX_set_private_key_method(
  1111. SSL_CTX *ctx, const SSL_PRIVATE_KEY_METHOD *key_method);
  1112. // SSL_can_release_private_key returns one if |ssl| will no longer call into the
  1113. // private key and zero otherwise. If the function returns one, the caller can
  1114. // release state associated with the private key.
  1115. //
  1116. // NOTE: This function assumes the caller does not use |SSL_clear| to reuse
  1117. // |ssl| for a second connection. If |SSL_clear| is used, BoringSSL may still
  1118. // use the private key on the second connection.
  1119. OPENSSL_EXPORT int SSL_can_release_private_key(const SSL *ssl);
  1120. // Cipher suites.
  1121. //
  1122. // |SSL_CIPHER| objects represent cipher suites.
  1123. DEFINE_CONST_STACK_OF(SSL_CIPHER)
  1124. // SSL_get_cipher_by_value returns the structure representing a TLS cipher
  1125. // suite based on its assigned number, or NULL if unknown. See
  1126. // https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4.
  1127. OPENSSL_EXPORT const SSL_CIPHER *SSL_get_cipher_by_value(uint16_t value);
  1128. // SSL_CIPHER_get_id returns |cipher|'s non-IANA id. This is not its
  1129. // IANA-assigned number, which is called the "value" here, although it may be
  1130. // cast to a |uint16_t| to get it.
  1131. OPENSSL_EXPORT uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *cipher);
  1132. // SSL_CIPHER_get_protocol_id returns |cipher|'s IANA-assigned number.
  1133. OPENSSL_EXPORT uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *cipher);
  1134. // SSL_CIPHER_is_aead returns one if |cipher| uses an AEAD cipher.
  1135. OPENSSL_EXPORT int SSL_CIPHER_is_aead(const SSL_CIPHER *cipher);
  1136. // SSL_CIPHER_is_block_cipher returns one if |cipher| is a block cipher.
  1137. OPENSSL_EXPORT int SSL_CIPHER_is_block_cipher(const SSL_CIPHER *cipher);
  1138. // SSL_CIPHER_get_cipher_nid returns the NID for |cipher|'s bulk
  1139. // cipher. Possible values are |NID_aes_128_gcm|, |NID_aes_256_gcm|,
  1140. // |NID_chacha20_poly1305|, |NID_aes_128_cbc|, |NID_aes_256_cbc|, and
  1141. // |NID_des_ede3_cbc|.
  1142. OPENSSL_EXPORT int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *cipher);
  1143. // SSL_CIPHER_get_digest_nid returns the NID for |cipher|'s HMAC if it is a
  1144. // legacy cipher suite. For modern AEAD-based ciphers (see
  1145. // |SSL_CIPHER_is_aead|), it returns |NID_undef|.
  1146. //
  1147. // Note this function only returns the legacy HMAC digest, not the PRF hash.
  1148. OPENSSL_EXPORT int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *cipher);
  1149. // SSL_CIPHER_get_kx_nid returns the NID for |cipher|'s key exchange. This may
  1150. // be |NID_kx_rsa|, |NID_kx_ecdhe|, or |NID_kx_psk| for TLS 1.2. In TLS 1.3,
  1151. // cipher suites do not specify the key exchange, so this function returns
  1152. // |NID_kx_any|.
  1153. OPENSSL_EXPORT int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *cipher);
  1154. // SSL_CIPHER_get_auth_nid returns the NID for |cipher|'s authentication
  1155. // type. This may be |NID_auth_rsa|, |NID_auth_ecdsa|, or |NID_auth_psk| for TLS
  1156. // 1.2. In TLS 1.3, cipher suites do not specify authentication, so this
  1157. // function returns |NID_auth_any|.
  1158. OPENSSL_EXPORT int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *cipher);
  1159. // SSL_CIPHER_get_prf_nid retuns the NID for |cipher|'s PRF hash. If |cipher| is
  1160. // a pre-TLS-1.2 cipher, it returns |NID_md5_sha1| but note these ciphers use
  1161. // SHA-256 in TLS 1.2. Other return values may be treated uniformly in all
  1162. // applicable versions.
  1163. OPENSSL_EXPORT int SSL_CIPHER_get_prf_nid(const SSL_CIPHER *cipher);
  1164. // SSL_CIPHER_get_min_version returns the minimum protocol version required
  1165. // for |cipher|.
  1166. OPENSSL_EXPORT uint16_t SSL_CIPHER_get_min_version(const SSL_CIPHER *cipher);
  1167. // SSL_CIPHER_get_max_version returns the maximum protocol version that
  1168. // supports |cipher|.
  1169. OPENSSL_EXPORT uint16_t SSL_CIPHER_get_max_version(const SSL_CIPHER *cipher);
  1170. // SSL_CIPHER_standard_name returns the standard IETF name for |cipher|. For
  1171. // example, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256".
  1172. OPENSSL_EXPORT const char *SSL_CIPHER_standard_name(const SSL_CIPHER *cipher);
  1173. // SSL_CIPHER_get_name returns the OpenSSL name of |cipher|. For example,
  1174. // "ECDHE-RSA-AES128-GCM-SHA256". Callers are recommended to use
  1175. // |SSL_CIPHER_standard_name| instead.
  1176. OPENSSL_EXPORT const char *SSL_CIPHER_get_name(const SSL_CIPHER *cipher);
  1177. // SSL_CIPHER_get_kx_name returns a string that describes the key-exchange
  1178. // method used by |cipher|. For example, "ECDHE_ECDSA". TLS 1.3 AEAD-only
  1179. // ciphers return the string "GENERIC".
  1180. OPENSSL_EXPORT const char *SSL_CIPHER_get_kx_name(const SSL_CIPHER *cipher);
  1181. // SSL_CIPHER_get_bits returns the strength, in bits, of |cipher|. If
  1182. // |out_alg_bits| is not NULL, it writes the number of bits consumed by the
  1183. // symmetric algorithm to |*out_alg_bits|.
  1184. OPENSSL_EXPORT int SSL_CIPHER_get_bits(const SSL_CIPHER *cipher,
  1185. int *out_alg_bits);
  1186. // Cipher suite configuration.
  1187. //
  1188. // OpenSSL uses a mini-language to configure cipher suites. The language
  1189. // maintains an ordered list of enabled ciphers, along with an ordered list of
  1190. // disabled but available ciphers. Initially, all ciphers are disabled with a
  1191. // default ordering. The cipher string is then interpreted as a sequence of
  1192. // directives, separated by colons, each of which modifies this state.
  1193. //
  1194. // Most directives consist of a one character or empty opcode followed by a
  1195. // selector which matches a subset of available ciphers.
  1196. //
  1197. // Available opcodes are:
  1198. //
  1199. // The empty opcode enables and appends all matching disabled ciphers to the
  1200. // end of the enabled list. The newly appended ciphers are ordered relative to
  1201. // each other matching their order in the disabled list.
  1202. //
  1203. // |-| disables all matching enabled ciphers and prepends them to the disabled
  1204. // list, with relative order from the enabled list preserved. This means the
  1205. // most recently disabled ciphers get highest preference relative to other
  1206. // disabled ciphers if re-enabled.
  1207. //
  1208. // |+| moves all matching enabled ciphers to the end of the enabled list, with
  1209. // relative order preserved.
  1210. //
  1211. // |!| deletes all matching ciphers, enabled or not, from either list. Deleted
  1212. // ciphers will not matched by future operations.
  1213. //
  1214. // A selector may be a specific cipher (using either the standard or OpenSSL
  1215. // name for the cipher) or one or more rules separated by |+|. The final
  1216. // selector matches the intersection of each rule. For instance, |AESGCM+aECDSA|
  1217. // matches ECDSA-authenticated AES-GCM ciphers.
  1218. //
  1219. // Available cipher rules are:
  1220. //
  1221. // |ALL| matches all ciphers.
  1222. //
  1223. // |kRSA|, |kDHE|, |kECDHE|, and |kPSK| match ciphers using plain RSA, DHE,
  1224. // ECDHE, and plain PSK key exchanges, respectively. Note that ECDHE_PSK is
  1225. // matched by |kECDHE| and not |kPSK|.
  1226. //
  1227. // |aRSA|, |aECDSA|, and |aPSK| match ciphers authenticated by RSA, ECDSA, and
  1228. // a pre-shared key, respectively.
  1229. //
  1230. // |RSA|, |DHE|, |ECDHE|, |PSK|, |ECDSA|, and |PSK| are aliases for the
  1231. // corresponding |k*| or |a*| cipher rule. |RSA| is an alias for |kRSA|, not
  1232. // |aRSA|.
  1233. //
  1234. // |3DES|, |AES128|, |AES256|, |AES|, |AESGCM|, |CHACHA20| match ciphers
  1235. // whose bulk cipher use the corresponding encryption scheme. Note that
  1236. // |AES|, |AES128|, and |AES256| match both CBC and GCM ciphers.
  1237. //
  1238. // |SHA1|, and its alias |SHA|, match legacy cipher suites using HMAC-SHA1.
  1239. //
  1240. // Although implemented, authentication-only ciphers match no rules and must be
  1241. // explicitly selected by name.
  1242. //
  1243. // Deprecated cipher rules:
  1244. //
  1245. // |kEDH|, |EDH|, |kEECDH|, and |EECDH| are legacy aliases for |kDHE|, |DHE|,
  1246. // |kECDHE|, and |ECDHE|, respectively.
  1247. //
  1248. // |HIGH| is an alias for |ALL|.
  1249. //
  1250. // |FIPS| is an alias for |HIGH|.
  1251. //
  1252. // |SSLv3| and |TLSv1| match ciphers available in TLS 1.1 or earlier.
  1253. // |TLSv1_2| matches ciphers new in TLS 1.2. This is confusing and should not
  1254. // be used.
  1255. //
  1256. // Unknown rules are silently ignored by legacy APIs, and rejected by APIs with
  1257. // "strict" in the name, which should be preferred. Cipher lists can be long
  1258. // and it's easy to commit typos. Strict functions will also reject the use of
  1259. // spaces, semi-colons and commas as alternative separators.
  1260. //
  1261. // The special |@STRENGTH| directive will sort all enabled ciphers by strength.
  1262. //
  1263. // The |DEFAULT| directive, when appearing at the front of the string, expands
  1264. // to the default ordering of available ciphers.
  1265. //
  1266. // If configuring a server, one may also configure equal-preference groups to
  1267. // partially respect the client's preferences when
  1268. // |SSL_OP_CIPHER_SERVER_PREFERENCE| is enabled. Ciphers in an equal-preference
  1269. // group have equal priority and use the client order. This may be used to
  1270. // enforce that AEADs are preferred but select AES-GCM vs. ChaCha20-Poly1305
  1271. // based on client preferences. An equal-preference is specified with square
  1272. // brackets, combining multiple selectors separated by |. For example:
  1273. //
  1274. // [TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256]
  1275. //
  1276. // Once an equal-preference group is used, future directives must be
  1277. // opcode-less. Inside an equal-preference group, spaces are not allowed.
  1278. //
  1279. // TLS 1.3 ciphers do not participate in this mechanism and instead have a
  1280. // built-in preference order. Functions to set cipher lists do not affect TLS
  1281. // 1.3, and functions to query the cipher list do not include TLS 1.3
  1282. // ciphers.
  1283. // SSL_DEFAULT_CIPHER_LIST is the default cipher suite configuration. It is
  1284. // substituted when a cipher string starts with 'DEFAULT'.
  1285. #define SSL_DEFAULT_CIPHER_LIST "ALL"
  1286. // SSL_CTX_set_strict_cipher_list configures the cipher list for |ctx|,
  1287. // evaluating |str| as a cipher string and returning error if |str| contains
  1288. // anything meaningless. It returns one on success and zero on failure.
  1289. OPENSSL_EXPORT int SSL_CTX_set_strict_cipher_list(SSL_CTX *ctx,
  1290. const char *str);
  1291. // SSL_CTX_set_cipher_list configures the cipher list for |ctx|, evaluating
  1292. // |str| as a cipher string. It returns one on success and zero on failure.
  1293. //
  1294. // Prefer to use |SSL_CTX_set_strict_cipher_list|. This function tolerates
  1295. // garbage inputs, unless an empty cipher list results.
  1296. OPENSSL_EXPORT int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
  1297. // SSL_set_strict_cipher_list configures the cipher list for |ssl|, evaluating
  1298. // |str| as a cipher string and returning error if |str| contains anything
  1299. // meaningless. It returns one on success and zero on failure.
  1300. OPENSSL_EXPORT int SSL_set_strict_cipher_list(SSL *ssl, const char *str);
  1301. // SSL_set_cipher_list configures the cipher list for |ssl|, evaluating |str| as
  1302. // a cipher string. It returns one on success and zero on failure.
  1303. //
  1304. // Prefer to use |SSL_set_strict_cipher_list|. This function tolerates garbage
  1305. // inputs, unless an empty cipher list results.
  1306. OPENSSL_EXPORT int SSL_set_cipher_list(SSL *ssl, const char *str);
  1307. // SSL_CTX_get_ciphers returns the cipher list for |ctx|, in order of
  1308. // preference.
  1309. OPENSSL_EXPORT STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
  1310. // SSL_CTX_cipher_in_group returns one if the |i|th cipher (see
  1311. // |SSL_CTX_get_ciphers|) is in the same equipreference group as the one
  1312. // following it and zero otherwise.
  1313. OPENSSL_EXPORT int SSL_CTX_cipher_in_group(const SSL_CTX *ctx, size_t i);
  1314. // SSL_get_ciphers returns the cipher list for |ssl|, in order of preference.
  1315. OPENSSL_EXPORT STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *ssl);
  1316. // Connection information.
  1317. // SSL_is_init_finished returns one if |ssl| has completed its initial handshake
  1318. // and has no pending handshake. It returns zero otherwise.
  1319. OPENSSL_EXPORT int SSL_is_init_finished(const SSL *ssl);
  1320. // SSL_in_init returns one if |ssl| has a pending handshake and zero
  1321. // otherwise.
  1322. OPENSSL_EXPORT int SSL_in_init(const SSL *ssl);
  1323. // SSL_in_false_start returns one if |ssl| has a pending handshake that is in
  1324. // False Start. |SSL_write| may be called at this point without waiting for the
  1325. // peer, but |SSL_read| will complete the handshake before accepting application
  1326. // data.
  1327. //
  1328. // See also |SSL_MODE_ENABLE_FALSE_START|.
  1329. OPENSSL_EXPORT int SSL_in_false_start(const SSL *ssl);
  1330. // SSL_get_peer_certificate returns the peer's leaf certificate or NULL if the
  1331. // peer did not use certificates. The caller must call |X509_free| on the
  1332. // result to release it.
  1333. OPENSSL_EXPORT X509 *SSL_get_peer_certificate(const SSL *ssl);
  1334. // SSL_get_peer_cert_chain returns the peer's certificate chain or NULL if
  1335. // unavailable or the peer did not use certificates. This is the unverified list
  1336. // of certificates as sent by the peer, not the final chain built during
  1337. // verification. The caller does not take ownership of the result.
  1338. //
  1339. // WARNING: This function behaves differently between client and server. If
  1340. // |ssl| is a server, the returned chain does not include the leaf certificate.
  1341. // If a client, it does.
  1342. OPENSSL_EXPORT STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *ssl);
  1343. // SSL_get_peer_full_cert_chain returns the peer's certificate chain, or NULL if
  1344. // unavailable or the peer did not use certificates. This is the unverified list
  1345. // of certificates as sent by the peer, not the final chain built during
  1346. // verification. The caller does not take ownership of the result.
  1347. //
  1348. // This is the same as |SSL_get_peer_cert_chain| except that this function
  1349. // always returns the full chain, i.e. the first element of the return value
  1350. // (if any) will be the leaf certificate. In constrast,
  1351. // |SSL_get_peer_cert_chain| returns only the intermediate certificates if the
  1352. // |ssl| is a server.
  1353. OPENSSL_EXPORT STACK_OF(X509) *SSL_get_peer_full_cert_chain(const SSL *ssl);
  1354. // SSL_get0_peer_certificates returns the peer's certificate chain, or NULL if
  1355. // unavailable or the peer did not use certificates. This is the unverified list
  1356. // of certificates as sent by the peer, not the final chain built during
  1357. // verification. The caller does not take ownership of the result.
  1358. //
  1359. // This is the |CRYPTO_BUFFER| variant of |SSL_get_peer_full_cert_chain|.
  1360. OPENSSL_EXPORT const STACK_OF(CRYPTO_BUFFER) *
  1361. SSL_get0_peer_certificates(const SSL *ssl);
  1362. // SSL_get0_signed_cert_timestamp_list sets |*out| and |*out_len| to point to
  1363. // |*out_len| bytes of SCT information from the server. This is only valid if
  1364. // |ssl| is a client. The SCT information is a SignedCertificateTimestampList
  1365. // (including the two leading length bytes).
  1366. // See https://tools.ietf.org/html/rfc6962#section-3.3
  1367. // If no SCT was received then |*out_len| will be zero on return.
  1368. //
  1369. // WARNING: the returned data is not guaranteed to be well formed.
  1370. OPENSSL_EXPORT void SSL_get0_signed_cert_timestamp_list(const SSL *ssl,
  1371. const uint8_t **out,
  1372. size_t *out_len);
  1373. // SSL_get0_ocsp_response sets |*out| and |*out_len| to point to |*out_len|
  1374. // bytes of an OCSP response from the server. This is the DER encoding of an
  1375. // OCSPResponse type as defined in RFC 2560.
  1376. //
  1377. // WARNING: the returned data is not guaranteed to be well formed.
  1378. OPENSSL_EXPORT void SSL_get0_ocsp_response(const SSL *ssl, const uint8_t **out,
  1379. size_t *out_len);
  1380. // SSL_get_tls_unique writes at most |max_out| bytes of the tls-unique value
  1381. // for |ssl| to |out| and sets |*out_len| to the number of bytes written. It
  1382. // returns one on success or zero on error. In general |max_out| should be at
  1383. // least 12.
  1384. //
  1385. // This function will always fail if the initial handshake has not completed.
  1386. // The tls-unique value will change after a renegotiation but, since
  1387. // renegotiations can be initiated by the server at any point, the higher-level
  1388. // protocol must either leave them disabled or define states in which the
  1389. // tls-unique value can be read.
  1390. //
  1391. // The tls-unique value is defined by
  1392. // https://tools.ietf.org/html/rfc5929#section-3.1. Due to a weakness in the
  1393. // TLS protocol, tls-unique is broken for resumed connections unless the
  1394. // Extended Master Secret extension is negotiated. Thus this function will
  1395. // return zero if |ssl| performed session resumption unless EMS was used when
  1396. // negotiating the original session.
  1397. OPENSSL_EXPORT int SSL_get_tls_unique(const SSL *ssl, uint8_t *out,
  1398. size_t *out_len, size_t max_out);
  1399. // SSL_get_extms_support returns one if the Extended Master Secret extension or
  1400. // TLS 1.3 was negotiated. Otherwise, it returns zero.
  1401. OPENSSL_EXPORT int SSL_get_extms_support(const SSL *ssl);
  1402. // SSL_get_current_cipher returns cipher suite used by |ssl|, or NULL if it has
  1403. // not been negotiated yet.
  1404. OPENSSL_EXPORT const SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl);
  1405. // SSL_session_reused returns one if |ssl| performed an abbreviated handshake
  1406. // and zero otherwise.
  1407. //
  1408. // TODO(davidben): Hammer down the semantics of this API while a handshake,
  1409. // initial or renego, is in progress.
  1410. OPENSSL_EXPORT int SSL_session_reused(const SSL *ssl);
  1411. // SSL_get_secure_renegotiation_support returns one if the peer supports secure
  1412. // renegotiation (RFC 5746) or TLS 1.3. Otherwise, it returns zero.
  1413. OPENSSL_EXPORT int SSL_get_secure_renegotiation_support(const SSL *ssl);
  1414. // SSL_export_keying_material exports a value derived from the master secret, as
  1415. // specified in RFC 5705. It writes |out_len| bytes to |out| given a label and
  1416. // optional context. (Since a zero length context is allowed, the |use_context|
  1417. // flag controls whether a context is included.)
  1418. //
  1419. // It returns one on success and zero otherwise.
  1420. OPENSSL_EXPORT int SSL_export_keying_material(
  1421. SSL *ssl, uint8_t *out, size_t out_len, const char *label, size_t label_len,
  1422. const uint8_t *context, size_t context_len, int use_context);
  1423. // Sessions.
  1424. //
  1425. // An |SSL_SESSION| represents an SSL session that may be resumed in an
  1426. // abbreviated handshake. It is reference-counted and immutable. Once
  1427. // established, an |SSL_SESSION| may be shared by multiple |SSL| objects on
  1428. // different threads and must not be modified.
  1429. //
  1430. // Note the TLS notion of "session" is not suitable for application-level
  1431. // session state. It is an optional caching mechanism for the handshake. Not all
  1432. // connections within an application-level session will reuse TLS sessions. TLS
  1433. // sessions may be dropped by the client or ignored by the server at any time.
  1434. DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
  1435. // SSL_SESSION_new returns a newly-allocated blank |SSL_SESSION| or NULL on
  1436. // error. This may be useful when writing tests but should otherwise not be
  1437. // used.
  1438. OPENSSL_EXPORT SSL_SESSION *SSL_SESSION_new(const SSL_CTX *ctx);
  1439. // SSL_SESSION_up_ref increments the reference count of |session| and returns
  1440. // one.
  1441. OPENSSL_EXPORT int SSL_SESSION_up_ref(SSL_SESSION *session);
  1442. // SSL_SESSION_free decrements the reference count of |session|. If it reaches
  1443. // zero, all data referenced by |session| and |session| itself are released.
  1444. OPENSSL_EXPORT void SSL_SESSION_free(SSL_SESSION *session);
  1445. // SSL_SESSION_to_bytes serializes |in| into a newly allocated buffer and sets
  1446. // |*out_data| to that buffer and |*out_len| to its length. The caller takes
  1447. // ownership of the buffer and must call |OPENSSL_free| when done. It returns
  1448. // one on success and zero on error.
  1449. OPENSSL_EXPORT int SSL_SESSION_to_bytes(const SSL_SESSION *in,
  1450. uint8_t **out_data, size_t *out_len);
  1451. // SSL_SESSION_to_bytes_for_ticket serializes |in|, but excludes the session
  1452. // identification information, namely the session ID and ticket.
  1453. OPENSSL_EXPORT int SSL_SESSION_to_bytes_for_ticket(const SSL_SESSION *in,
  1454. uint8_t **out_data,
  1455. size_t *out_len);
  1456. // SSL_SESSION_from_bytes parses |in_len| bytes from |in| as an SSL_SESSION. It
  1457. // returns a newly-allocated |SSL_SESSION| on success or NULL on error.
  1458. OPENSSL_EXPORT SSL_SESSION *SSL_SESSION_from_bytes(
  1459. const uint8_t *in, size_t in_len, const SSL_CTX *ctx);
  1460. // SSL_SESSION_get_version returns a string describing the TLS or DTLS version
  1461. // |session| was established at. For example, "TLSv1.2" or "DTLSv1".
  1462. OPENSSL_EXPORT const char *SSL_SESSION_get_version(const SSL_SESSION *session);
  1463. // SSL_SESSION_get_protocol_version returns the TLS or DTLS version |session|
  1464. // was established at.
  1465. OPENSSL_EXPORT uint16_t
  1466. SSL_SESSION_get_protocol_version(const SSL_SESSION *session);
  1467. // SSL_SESSION_set_protocol_version sets |session|'s TLS or DTLS version to
  1468. // |version|. This may be useful when writing tests but should otherwise not be
  1469. // used. It returns one on success and zero on error.
  1470. OPENSSL_EXPORT int SSL_SESSION_set_protocol_version(SSL_SESSION *session,
  1471. uint16_t version);
  1472. // SSL_MAX_SSL_SESSION_ID_LENGTH is the maximum length of an SSL session ID.
  1473. #define SSL_MAX_SSL_SESSION_ID_LENGTH 32
  1474. // SSL_SESSION_get_id returns a pointer to a buffer containing |session|'s
  1475. // session ID and sets |*out_len| to its length.
  1476. //
  1477. // This function should only be used for implementing a TLS session cache. TLS
  1478. // sessions are not suitable for application-level session state, and a session
  1479. // ID is an implementation detail of the TLS resumption handshake mechanism. Not
  1480. // all resumption flows use session IDs, and not all connections within an
  1481. // application-level session will reuse TLS sessions.
  1482. //
  1483. // To determine if resumption occurred, use |SSL_session_reused| instead.
  1484. // Comparing session IDs will not give the right result in all cases.
  1485. //
  1486. // As a workaround for some broken applications, BoringSSL sometimes synthesizes
  1487. // arbitrary session IDs for non-ID-based sessions. This behavior may be
  1488. // removed in the future.
  1489. OPENSSL_EXPORT const uint8_t *SSL_SESSION_get_id(const SSL_SESSION *session,
  1490. unsigned *out_len);
  1491. // SSL_SESSION_set1_id sets |session|'s session ID to |sid|, It returns one on
  1492. // success and zero on error. This function may be useful in writing tests but
  1493. // otherwise should not be used.
  1494. OPENSSL_EXPORT int SSL_SESSION_set1_id(SSL_SESSION *session, const uint8_t *sid,
  1495. size_t sid_len);
  1496. // SSL_SESSION_get_time returns the time at which |session| was established in
  1497. // seconds since the UNIX epoch.
  1498. OPENSSL_EXPORT uint64_t SSL_SESSION_get_time(const SSL_SESSION *session);
  1499. // SSL_SESSION_get_timeout returns the lifetime of |session| in seconds.
  1500. OPENSSL_EXPORT uint32_t SSL_SESSION_get_timeout(const SSL_SESSION *session);
  1501. // SSL_SESSION_get0_peer returns the peer leaf certificate stored in
  1502. // |session|.
  1503. //
  1504. // TODO(davidben): This should return a const X509 *.
  1505. OPENSSL_EXPORT X509 *SSL_SESSION_get0_peer(const SSL_SESSION *session);
  1506. // SSL_SESSION_get0_peer_certificates returns the peer certificate chain stored
  1507. // in |session|, or NULL if the peer did not use certificates. This is the
  1508. // unverified list of certificates as sent by the peer, not the final chain
  1509. // built during verification. The caller does not take ownership of the result.
  1510. OPENSSL_EXPORT const STACK_OF(CRYPTO_BUFFER) *
  1511. SSL_SESSION_get0_peer_certificates(const SSL_SESSION *session);
  1512. // SSL_SESSION_get0_signed_cert_timestamp_list sets |*out| and |*out_len| to
  1513. // point to |*out_len| bytes of SCT information stored in |session|. This is
  1514. // only valid for client sessions. The SCT information is a
  1515. // SignedCertificateTimestampList (including the two leading length bytes). See
  1516. // https://tools.ietf.org/html/rfc6962#section-3.3 If no SCT was received then
  1517. // |*out_len| will be zero on return.
  1518. //
  1519. // WARNING: the returned data is not guaranteed to be well formed.
  1520. OPENSSL_EXPORT void SSL_SESSION_get0_signed_cert_timestamp_list(
  1521. const SSL_SESSION *session, const uint8_t **out, size_t *out_len);
  1522. // SSL_SESSION_get0_ocsp_response sets |*out| and |*out_len| to point to
  1523. // |*out_len| bytes of an OCSP response from the server. This is the DER
  1524. // encoding of an OCSPResponse type as defined in RFC 2560.
  1525. //
  1526. // WARNING: the returned data is not guaranteed to be well formed.
  1527. OPENSSL_EXPORT void SSL_SESSION_get0_ocsp_response(const SSL_SESSION *session,
  1528. const uint8_t **out,
  1529. size_t *out_len);
  1530. // SSL_MAX_MASTER_KEY_LENGTH is the maximum length of a master secret.
  1531. #define SSL_MAX_MASTER_KEY_LENGTH 48
  1532. // SSL_SESSION_get_master_key writes up to |max_out| bytes of |session|'s secret
  1533. // to |out| and returns the number of bytes written. If |max_out| is zero, it
  1534. // returns the size of the secret.
  1535. OPENSSL_EXPORT size_t SSL_SESSION_get_master_key(const SSL_SESSION *session,
  1536. uint8_t *out, size_t max_out);
  1537. // SSL_SESSION_set_time sets |session|'s creation time to |time| and returns
  1538. // |time|. This function may be useful in writing tests but otherwise should not
  1539. // be used.
  1540. OPENSSL_EXPORT uint64_t SSL_SESSION_set_time(SSL_SESSION *session,
  1541. uint64_t time);
  1542. // SSL_SESSION_set_timeout sets |session|'s timeout to |timeout| and returns
  1543. // one. This function may be useful in writing tests but otherwise should not
  1544. // be used.
  1545. OPENSSL_EXPORT uint32_t SSL_SESSION_set_timeout(SSL_SESSION *session,
  1546. uint32_t timeout);
  1547. // SSL_SESSION_get0_id_context returns a pointer to a buffer containing
  1548. // |session|'s session ID context (see |SSL_CTX_set_session_id_context|) and
  1549. // sets |*out_len| to its length.
  1550. OPENSSL_EXPORT const uint8_t *SSL_SESSION_get0_id_context(
  1551. const SSL_SESSION *session, unsigned *out_len);
  1552. // SSL_SESSION_set1_id_context sets |session|'s session ID context (see
  1553. // |SSL_CTX_set_session_id_context|) to |sid_ctx|. It returns one on success and
  1554. // zero on error. This function may be useful in writing tests but otherwise
  1555. // should not be used.
  1556. OPENSSL_EXPORT int SSL_SESSION_set1_id_context(SSL_SESSION *session,
  1557. const uint8_t *sid_ctx,
  1558. size_t sid_ctx_len);
  1559. // SSL_SESSION_should_be_single_use returns one if |session| should be
  1560. // single-use (TLS 1.3 and later) and zero otherwise.
  1561. //
  1562. // If this function returns one, clients retain multiple sessions and use each
  1563. // only once. This prevents passive observers from correlating connections with
  1564. // tickets. See RFC 8446, appendix C.4. If it returns zero, |session| cannot be
  1565. // used without leaking a correlator.
  1566. OPENSSL_EXPORT int SSL_SESSION_should_be_single_use(const SSL_SESSION *session);
  1567. // SSL_SESSION_is_resumable returns one if |session| is complete and contains a
  1568. // session ID or ticket. It returns zero otherwise. Note this function does not
  1569. // ensure |session| will be resumed. It may be expired, dropped by the server,
  1570. // or associated with incompatible parameters.
  1571. OPENSSL_EXPORT int SSL_SESSION_is_resumable(const SSL_SESSION *session);
  1572. // SSL_SESSION_has_ticket returns one if |session| has a ticket and zero
  1573. // otherwise.
  1574. OPENSSL_EXPORT int SSL_SESSION_has_ticket(const SSL_SESSION *session);
  1575. // SSL_SESSION_get0_ticket sets |*out_ticket| and |*out_len| to |session|'s
  1576. // ticket, or NULL and zero if it does not have one. |out_ticket| may be NULL
  1577. // if only the ticket length is needed.
  1578. OPENSSL_EXPORT void SSL_SESSION_get0_ticket(const SSL_SESSION *session,
  1579. const uint8_t **out_ticket,
  1580. size_t *out_len);
  1581. // SSL_SESSION_set_ticket sets |session|'s ticket to |ticket|. It returns one on
  1582. // success and zero on error. This function may be useful in writing tests but
  1583. // otherwise should not be used.
  1584. OPENSSL_EXPORT int SSL_SESSION_set_ticket(SSL_SESSION *session,
  1585. const uint8_t *ticket,
  1586. size_t ticket_len);
  1587. // SSL_SESSION_get_ticket_lifetime_hint returns ticket lifetime hint of
  1588. // |session| in seconds or zero if none was set.
  1589. OPENSSL_EXPORT uint32_t
  1590. SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *session);
  1591. // SSL_SESSION_get0_cipher returns the cipher negotiated by the connection which
  1592. // established |session|.
  1593. //
  1594. // Note that, in TLS 1.3, there is no guarantee that resumptions with |session|
  1595. // will use that cipher. Prefer calling |SSL_get_current_cipher| on the |SSL|
  1596. // instead.
  1597. OPENSSL_EXPORT const SSL_CIPHER *SSL_SESSION_get0_cipher(
  1598. const SSL_SESSION *session);
  1599. // SSL_SESSION_has_peer_sha256 returns one if |session| has a SHA-256 hash of
  1600. // the peer's certificate retained and zero if the peer did not present a
  1601. // certificate or if this was not enabled when |session| was created. See also
  1602. // |SSL_CTX_set_retain_only_sha256_of_client_certs|.
  1603. OPENSSL_EXPORT int SSL_SESSION_has_peer_sha256(const SSL_SESSION *session);
  1604. // SSL_SESSION_get0_peer_sha256 sets |*out_ptr| and |*out_len| to the SHA-256
  1605. // hash of the peer certificate retained in |session|, or NULL and zero if it
  1606. // does not have one. See also |SSL_CTX_set_retain_only_sha256_of_client_certs|.
  1607. OPENSSL_EXPORT void SSL_SESSION_get0_peer_sha256(const SSL_SESSION *session,
  1608. const uint8_t **out_ptr,
  1609. size_t *out_len);
  1610. // Session caching.
  1611. //
  1612. // Session caching allows connections to be established more efficiently based
  1613. // on saved parameters from a previous connection, called a session (see
  1614. // |SSL_SESSION|). The client offers a saved session, using an opaque identifier
  1615. // from a previous connection. The server may accept the session, if it has the
  1616. // parameters available. Otherwise, it will decline and continue with a full
  1617. // handshake.
  1618. //
  1619. // This requires both the client and the server to retain session state. A
  1620. // client does so with a stateful session cache. A server may do the same or, if
  1621. // supported by both sides, statelessly using session tickets. For more
  1622. // information on the latter, see the next section.
  1623. //
  1624. // For a server, the library implements a built-in internal session cache as an
  1625. // in-memory hash table. Servers may also use |SSL_CTX_sess_set_get_cb| and
  1626. // |SSL_CTX_sess_set_new_cb| to implement a custom external session cache. In
  1627. // particular, this may be used to share a session cache between multiple
  1628. // servers in a large deployment. An external cache may be used in addition to
  1629. // or instead of the internal one. Use |SSL_CTX_set_session_cache_mode| to
  1630. // toggle the internal cache.
  1631. //
  1632. // For a client, the only option is an external session cache. Clients may use
  1633. // |SSL_CTX_sess_set_new_cb| to register a callback for when new sessions are
  1634. // available. These may be cached and, in subsequent compatible connections,
  1635. // configured with |SSL_set_session|.
  1636. //
  1637. // Note that offering or accepting a session short-circuits certificate
  1638. // verification and most parameter negotiation. Resuming sessions across
  1639. // different contexts may result in security failures and surprising
  1640. // behavior. For a typical client, this means sessions for different hosts must
  1641. // be cached under different keys. A client that connects to the same host with,
  1642. // e.g., different cipher suite settings or client certificates should also use
  1643. // separate session caches between those contexts. Servers should also partition
  1644. // session caches between SNI hosts with |SSL_CTX_set_session_id_context|.
  1645. //
  1646. // Note also, in TLS 1.2 and earlier, offering sessions allows passive observers
  1647. // to correlate different client connections. TLS 1.3 and later fix this,
  1648. // provided clients use sessions at most once. Session caches are managed by the
  1649. // caller in BoringSSL, so this must be implemented externally. See
  1650. // |SSL_SESSION_should_be_single_use| for details.
  1651. // SSL_SESS_CACHE_OFF disables all session caching.
  1652. #define SSL_SESS_CACHE_OFF 0x0000
  1653. // SSL_SESS_CACHE_CLIENT enables session caching for a client. The internal
  1654. // cache is never used on a client, so this only enables the callbacks.
  1655. #define SSL_SESS_CACHE_CLIENT 0x0001
  1656. // SSL_SESS_CACHE_SERVER enables session caching for a server.
  1657. #define SSL_SESS_CACHE_SERVER 0x0002
  1658. // SSL_SESS_CACHE_BOTH enables session caching for both client and server.
  1659. #define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_SERVER)
  1660. // SSL_SESS_CACHE_NO_AUTO_CLEAR disables automatically calling
  1661. // |SSL_CTX_flush_sessions| every 255 connections.
  1662. #define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
  1663. // SSL_SESS_CACHE_NO_INTERNAL_LOOKUP, on a server, disables looking up a session
  1664. // from the internal session cache.
  1665. #define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
  1666. // SSL_SESS_CACHE_NO_INTERNAL_STORE, on a server, disables storing sessions in
  1667. // the internal session cache.
  1668. #define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200
  1669. // SSL_SESS_CACHE_NO_INTERNAL, on a server, disables the internal session
  1670. // cache.
  1671. #define SSL_SESS_CACHE_NO_INTERNAL \
  1672. (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP | SSL_SESS_CACHE_NO_INTERNAL_STORE)
  1673. // SSL_CTX_set_session_cache_mode sets the session cache mode bits for |ctx| to
  1674. // |mode|. It returns the previous value.
  1675. OPENSSL_EXPORT int SSL_CTX_set_session_cache_mode(SSL_CTX *ctx, int mode);
  1676. // SSL_CTX_get_session_cache_mode returns the session cache mode bits for
  1677. // |ctx|
  1678. OPENSSL_EXPORT int SSL_CTX_get_session_cache_mode(const SSL_CTX *ctx);
  1679. // SSL_set_session, for a client, configures |ssl| to offer to resume |session|
  1680. // in the initial handshake and returns one. The caller retains ownership of
  1681. // |session|. Note that configuring a session assumes the authentication in the
  1682. // session is valid. For callers that wish to revalidate the session before
  1683. // offering, see |SSL_SESSION_get0_peer_certificates|,
  1684. // |SSL_SESSION_get0_signed_cert_timestamp_list|, and
  1685. // |SSL_SESSION_get0_ocsp_response|.
  1686. //
  1687. // It is an error to call this function after the handshake has begun.
  1688. OPENSSL_EXPORT int SSL_set_session(SSL *ssl, SSL_SESSION *session);
  1689. // SSL_DEFAULT_SESSION_TIMEOUT is the default lifetime, in seconds, of a
  1690. // session in TLS 1.2 or earlier. This is how long we are willing to use the
  1691. // secret to encrypt traffic without fresh key material.
  1692. #define SSL_DEFAULT_SESSION_TIMEOUT (2 * 60 * 60)
  1693. // SSL_DEFAULT_SESSION_PSK_DHE_TIMEOUT is the default lifetime, in seconds, of a
  1694. // session for TLS 1.3 psk_dhe_ke. This is how long we are willing to use the
  1695. // secret as an authenticator.
  1696. #define SSL_DEFAULT_SESSION_PSK_DHE_TIMEOUT (2 * 24 * 60 * 60)
  1697. // SSL_DEFAULT_SESSION_AUTH_TIMEOUT is the default non-renewable lifetime, in
  1698. // seconds, of a TLS 1.3 session. This is how long we are willing to trust the
  1699. // signature in the initial handshake.
  1700. #define SSL_DEFAULT_SESSION_AUTH_TIMEOUT (7 * 24 * 60 * 60)
  1701. // SSL_CTX_set_timeout sets the lifetime, in seconds, of TLS 1.2 (or earlier)
  1702. // sessions created in |ctx| to |timeout|.
  1703. OPENSSL_EXPORT uint32_t SSL_CTX_set_timeout(SSL_CTX *ctx, uint32_t timeout);
  1704. // SSL_CTX_set_session_psk_dhe_timeout sets the lifetime, in seconds, of TLS 1.3
  1705. // sessions created in |ctx| to |timeout|.
  1706. OPENSSL_EXPORT void SSL_CTX_set_session_psk_dhe_timeout(SSL_CTX *ctx,
  1707. uint32_t timeout);
  1708. // SSL_CTX_get_timeout returns the lifetime, in seconds, of TLS 1.2 (or earlier)
  1709. // sessions created in |ctx|.
  1710. OPENSSL_EXPORT uint32_t SSL_CTX_get_timeout(const SSL_CTX *ctx);
  1711. // SSL_MAX_SID_CTX_LENGTH is the maximum length of a session ID context.
  1712. #define SSL_MAX_SID_CTX_LENGTH 32
  1713. // SSL_CTX_set_session_id_context sets |ctx|'s session ID context to |sid_ctx|.
  1714. // It returns one on success and zero on error. The session ID context is an
  1715. // application-defined opaque byte string. A session will not be used in a
  1716. // connection without a matching session ID context.
  1717. //
  1718. // For a server, if |SSL_VERIFY_PEER| is enabled, it is an error to not set a
  1719. // session ID context.
  1720. OPENSSL_EXPORT int SSL_CTX_set_session_id_context(SSL_CTX *ctx,
  1721. const uint8_t *sid_ctx,
  1722. size_t sid_ctx_len);
  1723. // SSL_set_session_id_context sets |ssl|'s session ID context to |sid_ctx|. It
  1724. // returns one on success and zero on error. See also
  1725. // |SSL_CTX_set_session_id_context|.
  1726. OPENSSL_EXPORT int SSL_set_session_id_context(SSL *ssl, const uint8_t *sid_ctx,
  1727. size_t sid_ctx_len);
  1728. // SSL_get0_session_id_context returns a pointer to |ssl|'s session ID context
  1729. // and sets |*out_len| to its length. It returns NULL on error.
  1730. OPENSSL_EXPORT const uint8_t *SSL_get0_session_id_context(const SSL *ssl,
  1731. size_t *out_len);
  1732. // SSL_SESSION_CACHE_MAX_SIZE_DEFAULT is the default maximum size of a session
  1733. // cache.
  1734. #define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024 * 20)
  1735. // SSL_CTX_sess_set_cache_size sets the maximum size of |ctx|'s internal session
  1736. // cache to |size|. It returns the previous value.
  1737. OPENSSL_EXPORT unsigned long SSL_CTX_sess_set_cache_size(SSL_CTX *ctx,
  1738. unsigned long size);
  1739. // SSL_CTX_sess_get_cache_size returns the maximum size of |ctx|'s internal
  1740. // session cache.
  1741. OPENSSL_EXPORT unsigned long SSL_CTX_sess_get_cache_size(const SSL_CTX *ctx);
  1742. // SSL_CTX_sess_number returns the number of sessions in |ctx|'s internal
  1743. // session cache.
  1744. OPENSSL_EXPORT size_t SSL_CTX_sess_number(const SSL_CTX *ctx);
  1745. // SSL_CTX_add_session inserts |session| into |ctx|'s internal session cache. It
  1746. // returns one on success and zero on error or if |session| is already in the
  1747. // cache. The caller retains its reference to |session|.
  1748. OPENSSL_EXPORT int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session);
  1749. // SSL_CTX_remove_session removes |session| from |ctx|'s internal session cache.
  1750. // It returns one on success and zero if |session| was not in the cache.
  1751. OPENSSL_EXPORT int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session);
  1752. // SSL_CTX_flush_sessions removes all sessions from |ctx| which have expired as
  1753. // of time |time|. If |time| is zero, all sessions are removed.
  1754. OPENSSL_EXPORT void SSL_CTX_flush_sessions(SSL_CTX *ctx, uint64_t time);
  1755. // SSL_CTX_sess_set_new_cb sets the callback to be called when a new session is
  1756. // established and ready to be cached. If the session cache is disabled (the
  1757. // appropriate one of |SSL_SESS_CACHE_CLIENT| or |SSL_SESS_CACHE_SERVER| is
  1758. // unset), the callback is not called.
  1759. //
  1760. // The callback is passed a reference to |session|. It returns one if it takes
  1761. // ownership (and then calls |SSL_SESSION_free| when done) and zero otherwise. A
  1762. // consumer which places |session| into an in-memory cache will likely return
  1763. // one, with the cache calling |SSL_SESSION_free|. A consumer which serializes
  1764. // |session| with |SSL_SESSION_to_bytes| may not need to retain |session| and
  1765. // will likely return zero. Returning one is equivalent to calling
  1766. // |SSL_SESSION_up_ref| and then returning zero.
  1767. //
  1768. // Note: For a client, the callback may be called on abbreviated handshakes if a
  1769. // ticket is renewed. Further, it may not be called until some time after
  1770. // |SSL_do_handshake| or |SSL_connect| completes if False Start is enabled. Thus
  1771. // it's recommended to use this callback over calling |SSL_get_session| on
  1772. // handshake completion.
  1773. OPENSSL_EXPORT void SSL_CTX_sess_set_new_cb(
  1774. SSL_CTX *ctx, int (*new_session_cb)(SSL *ssl, SSL_SESSION *session));
  1775. // SSL_CTX_sess_get_new_cb returns the callback set by
  1776. // |SSL_CTX_sess_set_new_cb|.
  1777. OPENSSL_EXPORT int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(
  1778. SSL *ssl, SSL_SESSION *session);
  1779. // SSL_CTX_sess_set_remove_cb sets a callback which is called when a session is
  1780. // removed from the internal session cache.
  1781. //
  1782. // TODO(davidben): What is the point of this callback? It seems useless since it
  1783. // only fires on sessions in the internal cache.
  1784. OPENSSL_EXPORT void SSL_CTX_sess_set_remove_cb(
  1785. SSL_CTX *ctx,
  1786. void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *session));
  1787. // SSL_CTX_sess_get_remove_cb returns the callback set by
  1788. // |SSL_CTX_sess_set_remove_cb|.
  1789. OPENSSL_EXPORT void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(
  1790. SSL_CTX *ctx, SSL_SESSION *session);
  1791. // SSL_CTX_sess_set_get_cb sets a callback to look up a session by ID for a
  1792. // server. The callback is passed the session ID and should return a matching
  1793. // |SSL_SESSION| or NULL if not found. It should set |*out_copy| to zero and
  1794. // return a new reference to the session. This callback is not used for a
  1795. // client.
  1796. //
  1797. // For historical reasons, if |*out_copy| is set to one (default), the SSL
  1798. // library will take a new reference to the returned |SSL_SESSION|, expecting
  1799. // the callback to return a non-owning pointer. This is not recommended. If
  1800. // |ctx| and thus the callback is used on multiple threads, the session may be
  1801. // removed and invalidated before the SSL library calls |SSL_SESSION_up_ref|,
  1802. // whereas the callback may synchronize internally.
  1803. //
  1804. // To look up a session asynchronously, the callback may return
  1805. // |SSL_magic_pending_session_ptr|. See the documentation for that function and
  1806. // |SSL_ERROR_PENDING_SESSION|.
  1807. //
  1808. // If the internal session cache is enabled, the callback is only consulted if
  1809. // the internal cache does not return a match.
  1810. OPENSSL_EXPORT void SSL_CTX_sess_set_get_cb(
  1811. SSL_CTX *ctx, SSL_SESSION *(*get_session_cb)(SSL *ssl, const uint8_t *id,
  1812. int id_len, int *out_copy));
  1813. // SSL_CTX_sess_get_get_cb returns the callback set by
  1814. // |SSL_CTX_sess_set_get_cb|.
  1815. OPENSSL_EXPORT SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(
  1816. SSL *ssl, const uint8_t *id, int id_len, int *out_copy);
  1817. // SSL_magic_pending_session_ptr returns a magic |SSL_SESSION|* which indicates
  1818. // that the session isn't currently unavailable. |SSL_get_error| will then
  1819. // return |SSL_ERROR_PENDING_SESSION| and the handshake can be retried later
  1820. // when the lookup has completed.
  1821. OPENSSL_EXPORT SSL_SESSION *SSL_magic_pending_session_ptr(void);
  1822. // Session tickets.
  1823. //
  1824. // Session tickets, from RFC 5077, allow session resumption without server-side
  1825. // state. The server maintains a secret ticket key and sends the client opaque
  1826. // encrypted session parameters, called a ticket. When offering the session, the
  1827. // client sends the ticket which the server decrypts to recover session state.
  1828. // Session tickets are enabled by default but may be disabled with
  1829. // |SSL_OP_NO_TICKET|.
  1830. //
  1831. // On the client, ticket-based sessions use the same APIs as ID-based tickets.
  1832. // Callers do not need to handle them differently.
  1833. //
  1834. // On the server, tickets are encrypted and authenticated with a secret key.
  1835. // By default, an |SSL_CTX| will manage session ticket encryption keys by
  1836. // generating them internally and rotating every 48 hours. Tickets are minted
  1837. // and processed transparently. The following functions may be used to configure
  1838. // a persistent key or implement more custom behavior, including key rotation
  1839. // and sharing keys between multiple servers in a large deployment. There are
  1840. // three levels of customisation possible:
  1841. //
  1842. // 1) One can simply set the keys with |SSL_CTX_set_tlsext_ticket_keys|.
  1843. // 2) One can configure an |EVP_CIPHER_CTX| and |HMAC_CTX| directly for
  1844. // encryption and authentication.
  1845. // 3) One can configure an |SSL_TICKET_AEAD_METHOD| to have more control
  1846. // and the option of asynchronous decryption.
  1847. //
  1848. // An attacker that compromises a server's session ticket key can impersonate
  1849. // the server and, prior to TLS 1.3, retroactively decrypt all application
  1850. // traffic from sessions using that ticket key. Thus ticket keys must be
  1851. // regularly rotated for forward secrecy. Note the default key is rotated
  1852. // automatically once every 48 hours but manually configured keys are not.
  1853. // SSL_DEFAULT_TICKET_KEY_ROTATION_INTERVAL is the interval with which the
  1854. // default session ticket encryption key is rotated, if in use. If any
  1855. // non-default ticket encryption mechanism is configured, automatic rotation is
  1856. // disabled.
  1857. #define SSL_DEFAULT_TICKET_KEY_ROTATION_INTERVAL (2 * 24 * 60 * 60)
  1858. // SSL_CTX_get_tlsext_ticket_keys writes |ctx|'s session ticket key material to
  1859. // |len| bytes of |out|. It returns one on success and zero if |len| is not
  1860. // 48. If |out| is NULL, it returns 48 instead.
  1861. OPENSSL_EXPORT int SSL_CTX_get_tlsext_ticket_keys(SSL_CTX *ctx, void *out,
  1862. size_t len);
  1863. // SSL_CTX_set_tlsext_ticket_keys sets |ctx|'s session ticket key material to
  1864. // |len| bytes of |in|. It returns one on success and zero if |len| is not
  1865. // 48. If |in| is NULL, it returns 48 instead.
  1866. OPENSSL_EXPORT int SSL_CTX_set_tlsext_ticket_keys(SSL_CTX *ctx, const void *in,
  1867. size_t len);
  1868. // SSL_TICKET_KEY_NAME_LEN is the length of the key name prefix of a session
  1869. // ticket.
  1870. #define SSL_TICKET_KEY_NAME_LEN 16
  1871. // SSL_CTX_set_tlsext_ticket_key_cb sets the ticket callback to |callback| and
  1872. // returns one. |callback| will be called when encrypting a new ticket and when
  1873. // decrypting a ticket from the client.
  1874. //
  1875. // In both modes, |ctx| and |hmac_ctx| will already have been initialized with
  1876. // |EVP_CIPHER_CTX_init| and |HMAC_CTX_init|, respectively. |callback|
  1877. // configures |hmac_ctx| with an HMAC digest and key, and configures |ctx|
  1878. // for encryption or decryption, based on the mode.
  1879. //
  1880. // When encrypting a new ticket, |encrypt| will be one. It writes a public
  1881. // 16-byte key name to |key_name| and a fresh IV to |iv|. The output IV length
  1882. // must match |EVP_CIPHER_CTX_iv_length| of the cipher selected. In this mode,
  1883. // |callback| returns 1 on success and -1 on error.
  1884. //
  1885. // When decrypting a ticket, |encrypt| will be zero. |key_name| will point to a
  1886. // 16-byte key name and |iv| points to an IV. The length of the IV consumed must
  1887. // match |EVP_CIPHER_CTX_iv_length| of the cipher selected. In this mode,
  1888. // |callback| returns -1 to abort the handshake, 0 if decrypting the ticket
  1889. // failed, and 1 or 2 on success. If it returns 2, the ticket will be renewed.
  1890. // This may be used to re-key the ticket.
  1891. //
  1892. // WARNING: |callback| wildly breaks the usual return value convention and is
  1893. // called in two different modes.
  1894. OPENSSL_EXPORT int SSL_CTX_set_tlsext_ticket_key_cb(
  1895. SSL_CTX *ctx, int (*callback)(SSL *ssl, uint8_t *key_name, uint8_t *iv,
  1896. EVP_CIPHER_CTX *ctx, HMAC_CTX *hmac_ctx,
  1897. int encrypt));
  1898. // ssl_ticket_aead_result_t enumerates the possible results from decrypting a
  1899. // ticket with an |SSL_TICKET_AEAD_METHOD|.
  1900. enum ssl_ticket_aead_result_t BORINGSSL_ENUM_INT {
  1901. // ssl_ticket_aead_success indicates that the ticket was successfully
  1902. // decrypted.
  1903. ssl_ticket_aead_success,
  1904. // ssl_ticket_aead_retry indicates that the operation could not be
  1905. // immediately completed and must be reattempted, via |open|, at a later
  1906. // point.
  1907. ssl_ticket_aead_retry,
  1908. // ssl_ticket_aead_ignore_ticket indicates that the ticket should be ignored
  1909. // (i.e. is corrupt or otherwise undecryptable).
  1910. ssl_ticket_aead_ignore_ticket,
  1911. // ssl_ticket_aead_error indicates that a fatal error occured and the
  1912. // handshake should be terminated.
  1913. ssl_ticket_aead_error,
  1914. };
  1915. // ssl_ticket_aead_method_st (aka |SSL_TICKET_AEAD_METHOD|) contains methods
  1916. // for encrypting and decrypting session tickets.
  1917. struct ssl_ticket_aead_method_st {
  1918. // max_overhead returns the maximum number of bytes of overhead that |seal|
  1919. // may add.
  1920. size_t (*max_overhead)(SSL *ssl);
  1921. // seal encrypts and authenticates |in_len| bytes from |in|, writes, at most,
  1922. // |max_out_len| bytes to |out|, and puts the number of bytes written in
  1923. // |*out_len|. The |in| and |out| buffers may be equal but will not otherwise
  1924. // alias. It returns one on success or zero on error.
  1925. int (*seal)(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out_len,
  1926. const uint8_t *in, size_t in_len);
  1927. // open authenticates and decrypts |in_len| bytes from |in|, writes, at most,
  1928. // |max_out_len| bytes of plaintext to |out|, and puts the number of bytes
  1929. // written in |*out_len|. The |in| and |out| buffers may be equal but will
  1930. // not otherwise alias. See |ssl_ticket_aead_result_t| for details of the
  1931. // return values. In the case that a retry is indicated, the caller should
  1932. // arrange for the high-level operation on |ssl| to be retried when the
  1933. // operation is completed, which will result in another call to |open|.
  1934. enum ssl_ticket_aead_result_t (*open)(SSL *ssl, uint8_t *out, size_t *out_len,
  1935. size_t max_out_len, const uint8_t *in,
  1936. size_t in_len);
  1937. };
  1938. // SSL_CTX_set_ticket_aead_method configures a custom ticket AEAD method table
  1939. // on |ctx|. |aead_method| must remain valid for the lifetime of |ctx|.
  1940. OPENSSL_EXPORT void SSL_CTX_set_ticket_aead_method(
  1941. SSL_CTX *ctx, const SSL_TICKET_AEAD_METHOD *aead_method);
  1942. // SSL_process_tls13_new_session_ticket processes an unencrypted TLS 1.3
  1943. // NewSessionTicket message from |buf| and returns a resumable |SSL_SESSION|,
  1944. // or NULL on error. The caller takes ownership of the returned session and
  1945. // must call |SSL_SESSION_free| to free it.
  1946. //
  1947. // |buf| contains |buf_len| bytes that represents a complete NewSessionTicket
  1948. // message including its header, i.e., one byte for the type (0x04) and three
  1949. // bytes for the length. |buf| must contain only one such message.
  1950. //
  1951. // This function may be used to process NewSessionTicket messages in TLS 1.3
  1952. // clients that are handling the record layer externally.
  1953. OPENSSL_EXPORT SSL_SESSION *SSL_process_tls13_new_session_ticket(
  1954. SSL *ssl, const uint8_t *buf, size_t buf_len);
  1955. // SSL_CTX_set_num_tickets configures |ctx| to send |num_tickets| immediately
  1956. // after a successful TLS 1.3 handshake as a server. It returns one. Large
  1957. // values of |num_tickets| will be capped within the library.
  1958. //
  1959. // By default, BoringSSL sends two tickets.
  1960. OPENSSL_EXPORT int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
  1961. // Elliptic curve Diffie-Hellman.
  1962. //
  1963. // Cipher suites using an ECDHE key exchange perform Diffie-Hellman over an
  1964. // elliptic curve negotiated by both endpoints. See RFC 4492. Only named curves
  1965. // are supported. ECDHE is always enabled, but the curve preferences may be
  1966. // configured with these functions.
  1967. //
  1968. // Note that TLS 1.3 renames these from curves to groups. For consistency, we
  1969. // currently use the TLS 1.2 name in the API.
  1970. // SSL_CTX_set1_curves sets the preferred curves for |ctx| to be |curves|. Each
  1971. // element of |curves| should be a curve nid. It returns one on success and
  1972. // zero on failure.
  1973. //
  1974. // Note that this API uses nid values from nid.h and not the |SSL_CURVE_*|
  1975. // values defined below.
  1976. OPENSSL_EXPORT int SSL_CTX_set1_curves(SSL_CTX *ctx, const int *curves,
  1977. size_t curves_len);
  1978. // SSL_set1_curves sets the preferred curves for |ssl| to be |curves|. Each
  1979. // element of |curves| should be a curve nid. It returns one on success and
  1980. // zero on failure.
  1981. //
  1982. // Note that this API uses nid values from nid.h and not the |SSL_CURVE_*|
  1983. // values defined below.
  1984. OPENSSL_EXPORT int SSL_set1_curves(SSL *ssl, const int *curves,
  1985. size_t curves_len);
  1986. // SSL_CTX_set1_curves_list sets the preferred curves for |ctx| to be the
  1987. // colon-separated list |curves|. Each element of |curves| should be a curve
  1988. // name (e.g. P-256, X25519, ...). It returns one on success and zero on
  1989. // failure.
  1990. OPENSSL_EXPORT int SSL_CTX_set1_curves_list(SSL_CTX *ctx, const char *curves);
  1991. // SSL_set1_curves_list sets the preferred curves for |ssl| to be the
  1992. // colon-separated list |curves|. Each element of |curves| should be a curve
  1993. // name (e.g. P-256, X25519, ...). It returns one on success and zero on
  1994. // failure.
  1995. OPENSSL_EXPORT int SSL_set1_curves_list(SSL *ssl, const char *curves);
  1996. // SSL_CURVE_* define TLS curve IDs.
  1997. #define SSL_CURVE_SECP224R1 21
  1998. #define SSL_CURVE_SECP256R1 23
  1999. #define SSL_CURVE_SECP384R1 24
  2000. #define SSL_CURVE_SECP521R1 25
  2001. #define SSL_CURVE_X25519 29
  2002. #define SSL_CURVE_CECPQ2 16696
  2003. // SSL_get_curve_id returns the ID of the curve used by |ssl|'s most recently
  2004. // completed handshake or 0 if not applicable.
  2005. //
  2006. // TODO(davidben): This API currently does not work correctly if there is a
  2007. // renegotiation in progress. Fix this.
  2008. OPENSSL_EXPORT uint16_t SSL_get_curve_id(const SSL *ssl);
  2009. // SSL_get_curve_name returns a human-readable name for the curve specified by
  2010. // the given TLS curve id, or NULL if the curve is unknown.
  2011. OPENSSL_EXPORT const char *SSL_get_curve_name(uint16_t curve_id);
  2012. // Certificate verification.
  2013. //
  2014. // SSL may authenticate either endpoint with an X.509 certificate. Typically
  2015. // this is used to authenticate the server to the client. These functions
  2016. // configure certificate verification.
  2017. //
  2018. // WARNING: By default, certificate verification errors on a client are not
  2019. // fatal. See |SSL_VERIFY_NONE| This may be configured with
  2020. // |SSL_CTX_set_verify|.
  2021. //
  2022. // By default clients are anonymous but a server may request a certificate from
  2023. // the client by setting |SSL_VERIFY_PEER|.
  2024. //
  2025. // Many of these functions use OpenSSL's legacy X.509 stack which is
  2026. // underdocumented and deprecated, but the replacement isn't ready yet. For
  2027. // now, consumers may use the existing stack or bypass it by performing
  2028. // certificate verification externally. This may be done with
  2029. // |SSL_CTX_set_cert_verify_callback| or by extracting the chain with
  2030. // |SSL_get_peer_cert_chain| after the handshake. In the future, functions will
  2031. // be added to use the SSL stack without dependency on any part of the legacy
  2032. // X.509 and ASN.1 stack.
  2033. //
  2034. // To augment certificate verification, a client may also enable OCSP stapling
  2035. // (RFC 6066) and Certificate Transparency (RFC 6962) extensions.
  2036. // SSL_VERIFY_NONE, on a client, verifies the server certificate but does not
  2037. // make errors fatal. The result may be checked with |SSL_get_verify_result|. On
  2038. // a server it does not request a client certificate. This is the default.
  2039. #define SSL_VERIFY_NONE 0x00
  2040. // SSL_VERIFY_PEER, on a client, makes server certificate errors fatal. On a
  2041. // server it requests a client certificate and makes errors fatal. However,
  2042. // anonymous clients are still allowed. See
  2043. // |SSL_VERIFY_FAIL_IF_NO_PEER_CERT|.
  2044. #define SSL_VERIFY_PEER 0x01
  2045. // SSL_VERIFY_FAIL_IF_NO_PEER_CERT configures a server to reject connections if
  2046. // the client declines to send a certificate. This flag must be used together
  2047. // with |SSL_VERIFY_PEER|, otherwise it won't work.
  2048. #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
  2049. // SSL_VERIFY_PEER_IF_NO_OBC configures a server to request a client certificate
  2050. // if and only if Channel ID is not negotiated.
  2051. #define SSL_VERIFY_PEER_IF_NO_OBC 0x04
  2052. // SSL_CTX_set_verify configures certificate verification behavior. |mode| is
  2053. // one of the |SSL_VERIFY_*| values defined above. |callback|, if not NULL, is
  2054. // used to customize certificate verification. See the behavior of
  2055. // |X509_STORE_CTX_set_verify_cb|.
  2056. //
  2057. // The callback may use |SSL_get_ex_data_X509_STORE_CTX_idx| with
  2058. // |X509_STORE_CTX_get_ex_data| to look up the |SSL| from |store_ctx|.
  2059. OPENSSL_EXPORT void SSL_CTX_set_verify(
  2060. SSL_CTX *ctx, int mode, int (*callback)(int ok, X509_STORE_CTX *store_ctx));
  2061. // SSL_set_verify configures certificate verification behavior. |mode| is one of
  2062. // the |SSL_VERIFY_*| values defined above. |callback|, if not NULL, is used to
  2063. // customize certificate verification. See the behavior of
  2064. // |X509_STORE_CTX_set_verify_cb|.
  2065. //
  2066. // The callback may use |SSL_get_ex_data_X509_STORE_CTX_idx| with
  2067. // |X509_STORE_CTX_get_ex_data| to look up the |SSL| from |store_ctx|.
  2068. OPENSSL_EXPORT void SSL_set_verify(SSL *ssl, int mode,
  2069. int (*callback)(int ok,
  2070. X509_STORE_CTX *store_ctx));
  2071. enum ssl_verify_result_t BORINGSSL_ENUM_INT {
  2072. ssl_verify_ok,
  2073. ssl_verify_invalid,
  2074. ssl_verify_retry,
  2075. };
  2076. // SSL_CTX_set_custom_verify configures certificate verification. |mode| is one
  2077. // of the |SSL_VERIFY_*| values defined above. |callback| performs the
  2078. // certificate verification.
  2079. //
  2080. // The callback may call |SSL_get0_peer_certificates| for the certificate chain
  2081. // to validate. The callback should return |ssl_verify_ok| if the certificate is
  2082. // valid. If the certificate is invalid, the callback should return
  2083. // |ssl_verify_invalid| and optionally set |*out_alert| to an alert to send to
  2084. // the peer. Some useful alerts include |SSL_AD_CERTIFICATE_EXPIRED|,
  2085. // |SSL_AD_CERTIFICATE_REVOKED|, |SSL_AD_UNKNOWN_CA|, |SSL_AD_BAD_CERTIFICATE|,
  2086. // |SSL_AD_CERTIFICATE_UNKNOWN|, and |SSL_AD_INTERNAL_ERROR|. See RFC 5246
  2087. // section 7.2.2 for their precise meanings. If unspecified,
  2088. // |SSL_AD_CERTIFICATE_UNKNOWN| will be sent by default.
  2089. //
  2090. // To verify a certificate asynchronously, the callback may return
  2091. // |ssl_verify_retry|. The handshake will then pause with |SSL_get_error|
  2092. // returning |SSL_ERROR_WANT_CERTIFICATE_VERIFY|.
  2093. OPENSSL_EXPORT void SSL_CTX_set_custom_verify(
  2094. SSL_CTX *ctx, int mode,
  2095. enum ssl_verify_result_t (*callback)(SSL *ssl, uint8_t *out_alert));
  2096. // SSL_set_custom_verify behaves like |SSL_CTX_set_custom_verify| but configures
  2097. // an individual |SSL|.
  2098. OPENSSL_EXPORT void SSL_set_custom_verify(
  2099. SSL *ssl, int mode,
  2100. enum ssl_verify_result_t (*callback)(SSL *ssl, uint8_t *out_alert));
  2101. // SSL_CTX_get_verify_mode returns |ctx|'s verify mode, set by
  2102. // |SSL_CTX_set_verify|.
  2103. OPENSSL_EXPORT int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
  2104. // SSL_get_verify_mode returns |ssl|'s verify mode, set by |SSL_CTX_set_verify|
  2105. // or |SSL_set_verify|. It returns -1 on error.
  2106. OPENSSL_EXPORT int SSL_get_verify_mode(const SSL *ssl);
  2107. // SSL_CTX_get_verify_callback returns the callback set by
  2108. // |SSL_CTX_set_verify|.
  2109. OPENSSL_EXPORT int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(
  2110. int ok, X509_STORE_CTX *store_ctx);
  2111. // SSL_get_verify_callback returns the callback set by |SSL_CTX_set_verify| or
  2112. // |SSL_set_verify|.
  2113. OPENSSL_EXPORT int (*SSL_get_verify_callback(const SSL *ssl))(
  2114. int ok, X509_STORE_CTX *store_ctx);
  2115. // SSL_set1_host sets a DNS name that will be required to be present in the
  2116. // verified leaf certificate. It returns one on success and zero on error.
  2117. //
  2118. // Note: unless _some_ name checking is performed, certificate validation is
  2119. // ineffective. Simply checking that a host has some certificate from a CA is
  2120. // rarely meaningful—you have to check that the CA believed that the host was
  2121. // who you expect to be talking to.
  2122. OPENSSL_EXPORT int SSL_set1_host(SSL *ssl, const char *hostname);
  2123. // SSL_CTX_set_verify_depth sets the maximum depth of a certificate chain
  2124. // accepted in verification. This number does not include the leaf, so a depth
  2125. // of 1 allows the leaf and one CA certificate.
  2126. OPENSSL_EXPORT void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
  2127. // SSL_set_verify_depth sets the maximum depth of a certificate chain accepted
  2128. // in verification. This number does not include the leaf, so a depth of 1
  2129. // allows the leaf and one CA certificate.
  2130. OPENSSL_EXPORT void SSL_set_verify_depth(SSL *ssl, int depth);
  2131. // SSL_CTX_get_verify_depth returns the maximum depth of a certificate accepted
  2132. // in verification.
  2133. OPENSSL_EXPORT int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
  2134. // SSL_get_verify_depth returns the maximum depth of a certificate accepted in
  2135. // verification.
  2136. OPENSSL_EXPORT int SSL_get_verify_depth(const SSL *ssl);
  2137. // SSL_CTX_set1_param sets verification parameters from |param|. It returns one
  2138. // on success and zero on failure. The caller retains ownership of |param|.
  2139. OPENSSL_EXPORT int SSL_CTX_set1_param(SSL_CTX *ctx,
  2140. const X509_VERIFY_PARAM *param);
  2141. // SSL_set1_param sets verification parameters from |param|. It returns one on
  2142. // success and zero on failure. The caller retains ownership of |param|.
  2143. OPENSSL_EXPORT int SSL_set1_param(SSL *ssl,
  2144. const X509_VERIFY_PARAM *param);
  2145. // SSL_CTX_get0_param returns |ctx|'s |X509_VERIFY_PARAM| for certificate
  2146. // verification. The caller must not release the returned pointer but may call
  2147. // functions on it to configure it.
  2148. OPENSSL_EXPORT X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx);
  2149. // SSL_get0_param returns |ssl|'s |X509_VERIFY_PARAM| for certificate
  2150. // verification. The caller must not release the returned pointer but may call
  2151. // functions on it to configure it.
  2152. OPENSSL_EXPORT X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);
  2153. // SSL_CTX_set_purpose sets |ctx|'s |X509_VERIFY_PARAM|'s 'purpose' parameter to
  2154. // |purpose|. It returns one on success and zero on error.
  2155. OPENSSL_EXPORT int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose);
  2156. // SSL_set_purpose sets |ssl|'s |X509_VERIFY_PARAM|'s 'purpose' parameter to
  2157. // |purpose|. It returns one on success and zero on error.
  2158. OPENSSL_EXPORT int SSL_set_purpose(SSL *ssl, int purpose);
  2159. // SSL_CTX_set_trust sets |ctx|'s |X509_VERIFY_PARAM|'s 'trust' parameter to
  2160. // |trust|. It returns one on success and zero on error.
  2161. OPENSSL_EXPORT int SSL_CTX_set_trust(SSL_CTX *ctx, int trust);
  2162. // SSL_set_trust sets |ssl|'s |X509_VERIFY_PARAM|'s 'trust' parameter to
  2163. // |trust|. It returns one on success and zero on error.
  2164. OPENSSL_EXPORT int SSL_set_trust(SSL *ssl, int trust);
  2165. // SSL_CTX_set_cert_store sets |ctx|'s certificate store to |store|. It takes
  2166. // ownership of |store|. The store is used for certificate verification.
  2167. //
  2168. // The store is also used for the auto-chaining feature, but this is deprecated.
  2169. // See also |SSL_MODE_NO_AUTO_CHAIN|.
  2170. OPENSSL_EXPORT void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store);
  2171. // SSL_CTX_get_cert_store returns |ctx|'s certificate store.
  2172. OPENSSL_EXPORT X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx);
  2173. // SSL_CTX_set_default_verify_paths loads the OpenSSL system-default trust
  2174. // anchors into |ctx|'s store. It returns one on success and zero on failure.
  2175. OPENSSL_EXPORT int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
  2176. // SSL_CTX_load_verify_locations loads trust anchors into |ctx|'s store from
  2177. // |ca_file| and |ca_dir|, either of which may be NULL. If |ca_file| is passed,
  2178. // it is opened and PEM-encoded CA certificates are read. If |ca_dir| is passed,
  2179. // it is treated as a directory in OpenSSL's hashed directory format. It returns
  2180. // one on success and zero on failure.
  2181. //
  2182. // See
  2183. // https://www.openssl.org/docs/man1.1.0/man3/SSL_CTX_load_verify_locations.html
  2184. // for documentation on the directory format.
  2185. OPENSSL_EXPORT int SSL_CTX_load_verify_locations(SSL_CTX *ctx,
  2186. const char *ca_file,
  2187. const char *ca_dir);
  2188. // SSL_get_verify_result returns the result of certificate verification. It is
  2189. // either |X509_V_OK| or a |X509_V_ERR_*| value.
  2190. OPENSSL_EXPORT long SSL_get_verify_result(const SSL *ssl);
  2191. // SSL_alert_from_verify_result returns the SSL alert code, such as
  2192. // |SSL_AD_CERTIFICATE_EXPIRED|, that corresponds to an |X509_V_ERR_*| value.
  2193. // The return value is always an alert, even when |result| is |X509_V_OK|.
  2194. OPENSSL_EXPORT int SSL_alert_from_verify_result(long result);
  2195. // SSL_get_ex_data_X509_STORE_CTX_idx returns the ex_data index used to look up
  2196. // the |SSL| associated with an |X509_STORE_CTX| in the verify callback.
  2197. OPENSSL_EXPORT int SSL_get_ex_data_X509_STORE_CTX_idx(void);
  2198. // SSL_CTX_set_cert_verify_callback sets a custom callback to be called on
  2199. // certificate verification rather than |X509_verify_cert|. |store_ctx| contains
  2200. // the verification parameters. The callback should return one on success and
  2201. // zero on fatal error. It may use |X509_STORE_CTX_set_error| to set a
  2202. // verification result.
  2203. //
  2204. // The callback may use |SSL_get_ex_data_X509_STORE_CTX_idx| to recover the
  2205. // |SSL| object from |store_ctx|.
  2206. OPENSSL_EXPORT void SSL_CTX_set_cert_verify_callback(
  2207. SSL_CTX *ctx, int (*callback)(X509_STORE_CTX *store_ctx, void *arg),
  2208. void *arg);
  2209. // SSL_enable_signed_cert_timestamps causes |ssl| (which must be the client end
  2210. // of a connection) to request SCTs from the server. See
  2211. // https://tools.ietf.org/html/rfc6962.
  2212. //
  2213. // Call |SSL_get0_signed_cert_timestamp_list| to recover the SCT after the
  2214. // handshake.
  2215. OPENSSL_EXPORT void SSL_enable_signed_cert_timestamps(SSL *ssl);
  2216. // SSL_CTX_enable_signed_cert_timestamps enables SCT requests on all client SSL
  2217. // objects created from |ctx|.
  2218. //
  2219. // Call |SSL_get0_signed_cert_timestamp_list| to recover the SCT after the
  2220. // handshake.
  2221. OPENSSL_EXPORT void SSL_CTX_enable_signed_cert_timestamps(SSL_CTX *ctx);
  2222. // SSL_enable_ocsp_stapling causes |ssl| (which must be the client end of a
  2223. // connection) to request a stapled OCSP response from the server.
  2224. //
  2225. // Call |SSL_get0_ocsp_response| to recover the OCSP response after the
  2226. // handshake.
  2227. OPENSSL_EXPORT void SSL_enable_ocsp_stapling(SSL *ssl);
  2228. // SSL_CTX_enable_ocsp_stapling enables OCSP stapling on all client SSL objects
  2229. // created from |ctx|.
  2230. //
  2231. // Call |SSL_get0_ocsp_response| to recover the OCSP response after the
  2232. // handshake.
  2233. OPENSSL_EXPORT void SSL_CTX_enable_ocsp_stapling(SSL_CTX *ctx);
  2234. // SSL_CTX_set0_verify_cert_store sets an |X509_STORE| that will be used
  2235. // exclusively for certificate verification and returns one. Ownership of
  2236. // |store| is transferred to the |SSL_CTX|.
  2237. OPENSSL_EXPORT int SSL_CTX_set0_verify_cert_store(SSL_CTX *ctx,
  2238. X509_STORE *store);
  2239. // SSL_CTX_set1_verify_cert_store sets an |X509_STORE| that will be used
  2240. // exclusively for certificate verification and returns one. An additional
  2241. // reference to |store| will be taken.
  2242. OPENSSL_EXPORT int SSL_CTX_set1_verify_cert_store(SSL_CTX *ctx,
  2243. X509_STORE *store);
  2244. // SSL_set0_verify_cert_store sets an |X509_STORE| that will be used
  2245. // exclusively for certificate verification and returns one. Ownership of
  2246. // |store| is transferred to the |SSL|.
  2247. OPENSSL_EXPORT int SSL_set0_verify_cert_store(SSL *ssl, X509_STORE *store);
  2248. // SSL_set1_verify_cert_store sets an |X509_STORE| that will be used
  2249. // exclusively for certificate verification and returns one. An additional
  2250. // reference to |store| will be taken.
  2251. OPENSSL_EXPORT int SSL_set1_verify_cert_store(SSL *ssl, X509_STORE *store);
  2252. // SSL_CTX_set_verify_algorithm_prefs configures |ctx| to use |prefs| as the
  2253. // preference list when verifying signatures from the peer's long-term key. It
  2254. // returns one on zero on error. |prefs| should not include the internal-only
  2255. // value |SSL_SIGN_RSA_PKCS1_MD5_SHA1|.
  2256. OPENSSL_EXPORT int SSL_CTX_set_verify_algorithm_prefs(SSL_CTX *ctx,
  2257. const uint16_t *prefs,
  2258. size_t num_prefs);
  2259. // SSL_set_verify_algorithm_prefs configures |ssl| to use |prefs| as the
  2260. // preference list when verifying signatures from the peer's long-term key. It
  2261. // returns one on zero on error. |prefs| should not include the internal-only
  2262. // value |SSL_SIGN_RSA_PKCS1_MD5_SHA1|.
  2263. OPENSSL_EXPORT int SSL_set_verify_algorithm_prefs(SSL *ssl,
  2264. const uint16_t *prefs,
  2265. size_t num_prefs);
  2266. // SSL_set_hostflags calls |X509_VERIFY_PARAM_set_hostflags| on the
  2267. // |X509_VERIFY_PARAM| associated with this |SSL*|. The |flags| argument
  2268. // should be one of the |X509_CHECK_*| constants.
  2269. OPENSSL_EXPORT void SSL_set_hostflags(SSL *ssl, unsigned flags);
  2270. // Client certificate CA list.
  2271. //
  2272. // When requesting a client certificate, a server may advertise a list of
  2273. // certificate authorities which are accepted. These functions may be used to
  2274. // configure this list.
  2275. // SSL_set_client_CA_list sets |ssl|'s client certificate CA list to
  2276. // |name_list|. It takes ownership of |name_list|.
  2277. OPENSSL_EXPORT void SSL_set_client_CA_list(SSL *ssl,
  2278. STACK_OF(X509_NAME) *name_list);
  2279. // SSL_CTX_set_client_CA_list sets |ctx|'s client certificate CA list to
  2280. // |name_list|. It takes ownership of |name_list|.
  2281. OPENSSL_EXPORT void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,
  2282. STACK_OF(X509_NAME) *name_list);
  2283. // SSL_set0_client_CAs sets |ssl|'s client certificate CA list to |name_list|,
  2284. // which should contain DER-encoded distinguished names (RFC 5280). It takes
  2285. // ownership of |name_list|.
  2286. OPENSSL_EXPORT void SSL_set0_client_CAs(SSL *ssl,
  2287. STACK_OF(CRYPTO_BUFFER) *name_list);
  2288. // SSL_CTX_set0_client_CAs sets |ctx|'s client certificate CA list to
  2289. // |name_list|, which should contain DER-encoded distinguished names (RFC 5280).
  2290. // It takes ownership of |name_list|.
  2291. OPENSSL_EXPORT void SSL_CTX_set0_client_CAs(SSL_CTX *ctx,
  2292. STACK_OF(CRYPTO_BUFFER) *name_list);
  2293. // SSL_get_client_CA_list returns |ssl|'s client certificate CA list. If |ssl|
  2294. // has not been configured as a client, this is the list configured by
  2295. // |SSL_CTX_set_client_CA_list|.
  2296. //
  2297. // If configured as a client, it returns the client certificate CA list sent by
  2298. // the server. In this mode, the behavior is undefined except during the
  2299. // callbacks set by |SSL_CTX_set_cert_cb| and |SSL_CTX_set_client_cert_cb| or
  2300. // when the handshake is paused because of them.
  2301. OPENSSL_EXPORT STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *ssl);
  2302. // SSL_get0_server_requested_CAs returns the CAs sent by a server to guide a
  2303. // client in certificate selection. They are a series of DER-encoded X.509
  2304. // names. This function may only be called during a callback set by
  2305. // |SSL_CTX_set_cert_cb| or when the handshake is paused because of it.
  2306. //
  2307. // The returned stack is owned by |ssl|, as are its contents. It should not be
  2308. // used past the point where the handshake is restarted after the callback.
  2309. OPENSSL_EXPORT const STACK_OF(CRYPTO_BUFFER) *
  2310. SSL_get0_server_requested_CAs(const SSL *ssl);
  2311. // SSL_CTX_get_client_CA_list returns |ctx|'s client certificate CA list.
  2312. OPENSSL_EXPORT STACK_OF(X509_NAME) *
  2313. SSL_CTX_get_client_CA_list(const SSL_CTX *ctx);
  2314. // SSL_add_client_CA appends |x509|'s subject to the client certificate CA list.
  2315. // It returns one on success or zero on error. The caller retains ownership of
  2316. // |x509|.
  2317. OPENSSL_EXPORT int SSL_add_client_CA(SSL *ssl, X509 *x509);
  2318. // SSL_CTX_add_client_CA appends |x509|'s subject to the client certificate CA
  2319. // list. It returns one on success or zero on error. The caller retains
  2320. // ownership of |x509|.
  2321. OPENSSL_EXPORT int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x509);
  2322. // SSL_load_client_CA_file opens |file| and reads PEM-encoded certificates from
  2323. // it. It returns a newly-allocated stack of the certificate subjects or NULL
  2324. // on error.
  2325. OPENSSL_EXPORT STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
  2326. // SSL_dup_CA_list makes a deep copy of |list|. It returns the new list on
  2327. // success or NULL on allocation error.
  2328. OPENSSL_EXPORT STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *list);
  2329. // SSL_add_file_cert_subjects_to_stack behaves like |SSL_load_client_CA_file|
  2330. // but appends the result to |out|. It returns one on success or zero on
  2331. // error.
  2332. OPENSSL_EXPORT int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *out,
  2333. const char *file);
  2334. // Server name indication.
  2335. //
  2336. // The server_name extension (RFC 3546) allows the client to advertise the name
  2337. // of the server it is connecting to. This is used in virtual hosting
  2338. // deployments to select one of a several certificates on a single IP. Only the
  2339. // host_name name type is supported.
  2340. #define TLSEXT_NAMETYPE_host_name 0
  2341. // SSL_set_tlsext_host_name, for a client, configures |ssl| to advertise |name|
  2342. // in the server_name extension. It returns one on success and zero on error.
  2343. OPENSSL_EXPORT int SSL_set_tlsext_host_name(SSL *ssl, const char *name);
  2344. // SSL_get_servername, for a server, returns the hostname supplied by the
  2345. // client or NULL if there was none. The |type| argument must be
  2346. // |TLSEXT_NAMETYPE_host_name|.
  2347. OPENSSL_EXPORT const char *SSL_get_servername(const SSL *ssl, const int type);
  2348. // SSL_get_servername_type, for a server, returns |TLSEXT_NAMETYPE_host_name|
  2349. // if the client sent a hostname and -1 otherwise.
  2350. OPENSSL_EXPORT int SSL_get_servername_type(const SSL *ssl);
  2351. // SSL_CTX_set_tlsext_servername_callback configures |callback| to be called on
  2352. // the server after ClientHello extensions have been parsed and returns one.
  2353. // The callback may use |SSL_get_servername| to examine the server_name
  2354. // extension and returns a |SSL_TLSEXT_ERR_*| value. The value of |arg| may be
  2355. // set by calling |SSL_CTX_set_tlsext_servername_arg|.
  2356. //
  2357. // If the callback returns |SSL_TLSEXT_ERR_NOACK|, the server_name extension is
  2358. // not acknowledged in the ServerHello. If the return value is
  2359. // |SSL_TLSEXT_ERR_ALERT_FATAL|, then |*out_alert| is the alert to send,
  2360. // defaulting to |SSL_AD_UNRECOGNIZED_NAME|. |SSL_TLSEXT_ERR_ALERT_WARNING| is
  2361. // ignored and treated as |SSL_TLSEXT_ERR_OK|.
  2362. OPENSSL_EXPORT int SSL_CTX_set_tlsext_servername_callback(
  2363. SSL_CTX *ctx, int (*callback)(SSL *ssl, int *out_alert, void *arg));
  2364. // SSL_CTX_set_tlsext_servername_arg sets the argument to the servername
  2365. // callback and returns one. See |SSL_CTX_set_tlsext_servername_callback|.
  2366. OPENSSL_EXPORT int SSL_CTX_set_tlsext_servername_arg(SSL_CTX *ctx, void *arg);
  2367. // SSL_TLSEXT_ERR_* are values returned by some extension-related callbacks.
  2368. #define SSL_TLSEXT_ERR_OK 0
  2369. #define SSL_TLSEXT_ERR_ALERT_WARNING 1
  2370. #define SSL_TLSEXT_ERR_ALERT_FATAL 2
  2371. #define SSL_TLSEXT_ERR_NOACK 3
  2372. // SSL_set_SSL_CTX changes |ssl|'s |SSL_CTX|. |ssl| will use the
  2373. // certificate-related settings from |ctx|, and |SSL_get_SSL_CTX| will report
  2374. // |ctx|. This function may be used during the callbacks registered by
  2375. // |SSL_CTX_set_select_certificate_cb|,
  2376. // |SSL_CTX_set_tlsext_servername_callback|, and |SSL_CTX_set_cert_cb| or when
  2377. // the handshake is paused from them. It is typically used to switch
  2378. // certificates based on SNI.
  2379. //
  2380. // Note the session cache and related settings will continue to use the initial
  2381. // |SSL_CTX|. Callers should use |SSL_CTX_set_session_id_context| to partition
  2382. // the session cache between different domains.
  2383. //
  2384. // TODO(davidben): Should other settings change after this call?
  2385. OPENSSL_EXPORT SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx);
  2386. // Application-layer protocol negotiation.
  2387. //
  2388. // The ALPN extension (RFC 7301) allows negotiating different application-layer
  2389. // protocols over a single port. This is used, for example, to negotiate
  2390. // HTTP/2.
  2391. // SSL_CTX_set_alpn_protos sets the client ALPN protocol list on |ctx| to
  2392. // |protos|. |protos| must be in wire-format (i.e. a series of non-empty, 8-bit
  2393. // length-prefixed strings), or the empty string to disable ALPN. It returns
  2394. // zero on success and one on failure. Configuring a non-empty string enables
  2395. // ALPN on a client.
  2396. //
  2397. // WARNING: this function is dangerous because it breaks the usual return value
  2398. // convention.
  2399. OPENSSL_EXPORT int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const uint8_t *protos,
  2400. unsigned protos_len);
  2401. // SSL_set_alpn_protos sets the client ALPN protocol list on |ssl| to |protos|.
  2402. // |protos| must be in wire-format (i.e. a series of non-empty, 8-bit
  2403. // length-prefixed strings), or the empty string to disable ALPN. It returns
  2404. // zero on success and one on failure. Configuring a non-empty string enables
  2405. // ALPN on a client.
  2406. //
  2407. // WARNING: this function is dangerous because it breaks the usual return value
  2408. // convention.
  2409. OPENSSL_EXPORT int SSL_set_alpn_protos(SSL *ssl, const uint8_t *protos,
  2410. unsigned protos_len);
  2411. // SSL_CTX_set_alpn_select_cb sets a callback function on |ctx| that is called
  2412. // during ClientHello processing in order to select an ALPN protocol from the
  2413. // client's list of offered protocols.
  2414. //
  2415. // The callback is passed a wire-format (i.e. a series of non-empty, 8-bit
  2416. // length-prefixed strings) ALPN protocol list in |in|. To select a protocol,
  2417. // the callback should set |*out| and |*out_len| to the selected protocol and
  2418. // return |SSL_TLSEXT_ERR_OK| on success. It does not pass ownership of the
  2419. // buffer, so |*out| should point to a static string, a buffer that outlives the
  2420. // callback call, or the corresponding entry in |in|.
  2421. //
  2422. // If the server supports ALPN, but there are no protocols in common, the
  2423. // callback should return |SSL_TLSEXT_ERR_ALERT_FATAL| to abort the connection
  2424. // with a no_application_protocol alert.
  2425. //
  2426. // If the server does not support ALPN, it can return |SSL_TLSEXT_ERR_NOACK| to
  2427. // continue the handshake without negotiating a protocol. This may be useful if
  2428. // multiple server configurations share an |SSL_CTX|, only some of which have
  2429. // ALPN protocols configured.
  2430. //
  2431. // |SSL_TLSEXT_ERR_ALERT_WARNING| is ignored and will be treated as
  2432. // |SSL_TLSEXT_ERR_NOACK|.
  2433. //
  2434. // The callback will only be called if the client supports ALPN. Callers that
  2435. // wish to require ALPN for all clients must check |SSL_get0_alpn_selected|
  2436. // after the handshake. In QUIC connections, this is done automatically.
  2437. //
  2438. // The cipher suite is selected before negotiating ALPN. The callback may use
  2439. // |SSL_get_pending_cipher| to query the cipher suite. This may be used to
  2440. // implement HTTP/2's cipher suite constraints.
  2441. OPENSSL_EXPORT void SSL_CTX_set_alpn_select_cb(
  2442. SSL_CTX *ctx, int (*cb)(SSL *ssl, const uint8_t **out, uint8_t *out_len,
  2443. const uint8_t *in, unsigned in_len, void *arg),
  2444. void *arg);
  2445. // SSL_get0_alpn_selected gets the selected ALPN protocol (if any) from |ssl|.
  2446. // On return it sets |*out_data| to point to |*out_len| bytes of protocol name
  2447. // (not including the leading length-prefix byte). If the server didn't respond
  2448. // with a negotiated protocol then |*out_len| will be zero.
  2449. OPENSSL_EXPORT void SSL_get0_alpn_selected(const SSL *ssl,
  2450. const uint8_t **out_data,
  2451. unsigned *out_len);
  2452. // SSL_CTX_set_allow_unknown_alpn_protos configures client connections on |ctx|
  2453. // to allow unknown ALPN protocols from the server. Otherwise, by default, the
  2454. // client will require that the protocol be advertised in
  2455. // |SSL_CTX_set_alpn_protos|.
  2456. OPENSSL_EXPORT void SSL_CTX_set_allow_unknown_alpn_protos(SSL_CTX *ctx,
  2457. int enabled);
  2458. // Application-layer protocol settings
  2459. //
  2460. // The ALPS extension (draft-vvv-tls-alps) allows exchanging application-layer
  2461. // settings in the TLS handshake for applications negotiated with ALPN. Note
  2462. // that, when ALPS is negotiated, the client and server each advertise their own
  2463. // settings, so there are functions to both configure setting to send and query
  2464. // received settings.
  2465. // SSL_add_application_settings configures |ssl| to enable ALPS with ALPN
  2466. // protocol |proto|, sending an ALPS value of |settings|. It returns one on
  2467. // success and zero on error. If |proto| is negotiated via ALPN and the peer
  2468. // supports ALPS, |settings| will be sent to the peer. The peer's ALPS value can
  2469. // be retrieved with |SSL_get0_peer_application_settings|.
  2470. //
  2471. // On the client, this function should be called before the handshake, once for
  2472. // each supported ALPN protocol which uses ALPS. |proto| must be included in the
  2473. // client's ALPN configuration (see |SSL_CTX_set_alpn_protos| and
  2474. // |SSL_set_alpn_protos|). On the server, ALPS can be preconfigured for each
  2475. // protocol as in the client, or configuration can be deferred to the ALPN
  2476. // callback (see |SSL_CTX_set_alpn_select_cb|), in which case only the selected
  2477. // protocol needs to be configured.
  2478. //
  2479. // ALPS can be independently configured from 0-RTT, however changes in protocol
  2480. // settings will fallback to 1-RTT to negotiate the new value, so it is
  2481. // recommended for |settings| to be relatively stable.
  2482. OPENSSL_EXPORT int SSL_add_application_settings(SSL *ssl, const uint8_t *proto,
  2483. size_t proto_len,
  2484. const uint8_t *settings,
  2485. size_t settings_len);
  2486. // SSL_get0_peer_application_settings sets |*out_data| and |*out_len| to a
  2487. // buffer containing the peer's ALPS value, or the empty string if ALPS was not
  2488. // negotiated. Note an empty string could also indicate the peer sent an empty
  2489. // settings value. Use |SSL_has_application_settings| to check if ALPS was
  2490. // negotiated. The output buffer is owned by |ssl| and is valid until the next
  2491. // time |ssl| is modified.
  2492. OPENSSL_EXPORT void SSL_get0_peer_application_settings(const SSL *ssl,
  2493. const uint8_t **out_data,
  2494. size_t *out_len);
  2495. // SSL_has_application_settings returns one if ALPS was negotiated on this
  2496. // connection and zero otherwise.
  2497. OPENSSL_EXPORT int SSL_has_application_settings(const SSL *ssl);
  2498. // Certificate compression.
  2499. //
  2500. // Certificates in TLS 1.3 can be compressed (RFC 8879). BoringSSL supports this
  2501. // as both a client and a server, but does not link against any specific
  2502. // compression libraries in order to keep dependencies to a minimum. Instead,
  2503. // hooks for compression and decompression can be installed in an |SSL_CTX| to
  2504. // enable support.
  2505. // ssl_cert_compression_func_t is a pointer to a function that performs
  2506. // compression. It must write the compressed representation of |in| to |out|,
  2507. // returning one on success and zero on error. The results of compressing
  2508. // certificates are not cached internally. Implementations may wish to implement
  2509. // their own cache if they expect it to be useful given the certificates that
  2510. // they serve.
  2511. typedef int (*ssl_cert_compression_func_t)(SSL *ssl, CBB *out,
  2512. const uint8_t *in, size_t in_len);
  2513. // ssl_cert_decompression_func_t is a pointer to a function that performs
  2514. // decompression. The compressed data from the peer is passed as |in| and the
  2515. // decompressed result must be exactly |uncompressed_len| bytes long. It returns
  2516. // one on success, in which case |*out| must be set to the result of
  2517. // decompressing |in|, or zero on error. Setting |*out| transfers ownership,
  2518. // i.e. |CRYPTO_BUFFER_free| will be called on |*out| at some point in the
  2519. // future. The results of decompressions are not cached internally.
  2520. // Implementations may wish to implement their own cache if they expect it to be
  2521. // useful.
  2522. typedef int (*ssl_cert_decompression_func_t)(SSL *ssl, CRYPTO_BUFFER **out,
  2523. size_t uncompressed_len,
  2524. const uint8_t *in, size_t in_len);
  2525. // SSL_CTX_add_cert_compression_alg registers a certificate compression
  2526. // algorithm on |ctx| with ID |alg_id|. (The value of |alg_id| should be an IANA
  2527. // assigned value and each can only be registered once.)
  2528. //
  2529. // One of the function pointers may be NULL to avoid having to implement both
  2530. // sides of a compression algorithm if you're only going to use it in one
  2531. // direction. In this case, the unimplemented direction acts like it was never
  2532. // configured.
  2533. //
  2534. // For a server, algorithms are registered in preference order with the most
  2535. // preferable first. It returns one on success or zero on error.
  2536. OPENSSL_EXPORT int SSL_CTX_add_cert_compression_alg(
  2537. SSL_CTX *ctx, uint16_t alg_id, ssl_cert_compression_func_t compress,
  2538. ssl_cert_decompression_func_t decompress);
  2539. // Next protocol negotiation.
  2540. //
  2541. // The NPN extension (draft-agl-tls-nextprotoneg-03) is the predecessor to ALPN
  2542. // and deprecated in favor of it.
  2543. // SSL_CTX_set_next_protos_advertised_cb sets a callback that is called when a
  2544. // TLS server needs a list of supported protocols for Next Protocol
  2545. // Negotiation. The returned list must be in wire format. The list is returned
  2546. // by setting |*out| to point to it and |*out_len| to its length. This memory
  2547. // will not be modified, but one should assume that |ssl| keeps a reference to
  2548. // it.
  2549. //
  2550. // The callback should return |SSL_TLSEXT_ERR_OK| if it wishes to advertise.
  2551. // Otherwise, no such extension will be included in the ServerHello.
  2552. OPENSSL_EXPORT void SSL_CTX_set_next_protos_advertised_cb(
  2553. SSL_CTX *ctx,
  2554. int (*cb)(SSL *ssl, const uint8_t **out, unsigned *out_len, void *arg),
  2555. void *arg);
  2556. // SSL_CTX_set_next_proto_select_cb sets a callback that is called when a client
  2557. // needs to select a protocol from the server's provided list. |*out| must be
  2558. // set to point to the selected protocol (which may be within |in|). The length
  2559. // of the protocol name must be written into |*out_len|. The server's advertised
  2560. // protocols are provided in |in| and |in_len|. The callback can assume that
  2561. // |in| is syntactically valid.
  2562. //
  2563. // The client must select a protocol. It is fatal to the connection if this
  2564. // callback returns a value other than |SSL_TLSEXT_ERR_OK|.
  2565. //
  2566. // Configuring this callback enables NPN on a client.
  2567. OPENSSL_EXPORT void SSL_CTX_set_next_proto_select_cb(
  2568. SSL_CTX *ctx, int (*cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
  2569. const uint8_t *in, unsigned in_len, void *arg),
  2570. void *arg);
  2571. // SSL_get0_next_proto_negotiated sets |*out_data| and |*out_len| to point to
  2572. // the client's requested protocol for this connection. If the client didn't
  2573. // request any protocol, then |*out_data| is set to NULL.
  2574. //
  2575. // Note that the client can request any protocol it chooses. The value returned
  2576. // from this function need not be a member of the list of supported protocols
  2577. // provided by the server.
  2578. OPENSSL_EXPORT void SSL_get0_next_proto_negotiated(const SSL *ssl,
  2579. const uint8_t **out_data,
  2580. unsigned *out_len);
  2581. // SSL_select_next_proto implements the standard protocol selection. It is
  2582. // expected that this function is called from the callback set by
  2583. // |SSL_CTX_set_next_proto_select_cb|.
  2584. //
  2585. // |peer| and |supported| must be vectors of 8-bit, length-prefixed byte strings
  2586. // containing the peer and locally-configured protocols, respectively. The
  2587. // length byte itself is not included in the length. A byte string of length 0
  2588. // is invalid. No byte string may be truncated. |supported| is assumed to be
  2589. // non-empty.
  2590. //
  2591. // This function finds the first protocol in |peer| which is also in
  2592. // |supported|. If one was found, it sets |*out| and |*out_len| to point to it
  2593. // and returns |OPENSSL_NPN_NEGOTIATED|. Otherwise, it returns
  2594. // |OPENSSL_NPN_NO_OVERLAP| and sets |*out| and |*out_len| to the first
  2595. // supported protocol.
  2596. OPENSSL_EXPORT int SSL_select_next_proto(uint8_t **out, uint8_t *out_len,
  2597. const uint8_t *peer, unsigned peer_len,
  2598. const uint8_t *supported,
  2599. unsigned supported_len);
  2600. #define OPENSSL_NPN_UNSUPPORTED 0
  2601. #define OPENSSL_NPN_NEGOTIATED 1
  2602. #define OPENSSL_NPN_NO_OVERLAP 2
  2603. // Channel ID.
  2604. //
  2605. // See draft-balfanz-tls-channelid-01. This is an old, experimental mechanism
  2606. // and should not be used in new code.
  2607. // SSL_CTX_set_tls_channel_id_enabled configures whether connections associated
  2608. // with |ctx| should enable Channel ID as a server.
  2609. OPENSSL_EXPORT void SSL_CTX_set_tls_channel_id_enabled(SSL_CTX *ctx,
  2610. int enabled);
  2611. // SSL_set_tls_channel_id_enabled configures whether |ssl| should enable Channel
  2612. // ID as a server.
  2613. OPENSSL_EXPORT void SSL_set_tls_channel_id_enabled(SSL *ssl, int enabled);
  2614. // SSL_CTX_set1_tls_channel_id configures a TLS client to send a TLS Channel ID
  2615. // to compatible servers. |private_key| must be a P-256 EC key. It returns one
  2616. // on success and zero on error.
  2617. OPENSSL_EXPORT int SSL_CTX_set1_tls_channel_id(SSL_CTX *ctx,
  2618. EVP_PKEY *private_key);
  2619. // SSL_set1_tls_channel_id configures a TLS client to send a TLS Channel ID to
  2620. // compatible servers. |private_key| must be a P-256 EC key. It returns one on
  2621. // success and zero on error.
  2622. OPENSSL_EXPORT int SSL_set1_tls_channel_id(SSL *ssl, EVP_PKEY *private_key);
  2623. // SSL_get_tls_channel_id gets the client's TLS Channel ID from a server |SSL|
  2624. // and copies up to the first |max_out| bytes into |out|. The Channel ID
  2625. // consists of the client's P-256 public key as an (x,y) pair where each is a
  2626. // 32-byte, big-endian field element. It returns 0 if the client didn't offer a
  2627. // Channel ID and the length of the complete Channel ID otherwise. This function
  2628. // always returns zero if |ssl| is a client.
  2629. OPENSSL_EXPORT size_t SSL_get_tls_channel_id(SSL *ssl, uint8_t *out,
  2630. size_t max_out);
  2631. // DTLS-SRTP.
  2632. //
  2633. // See RFC 5764.
  2634. // srtp_protection_profile_st (aka |SRTP_PROTECTION_PROFILE|) is an SRTP
  2635. // profile for use with the use_srtp extension.
  2636. struct srtp_protection_profile_st {
  2637. const char *name;
  2638. unsigned long id;
  2639. } /* SRTP_PROTECTION_PROFILE */;
  2640. DEFINE_CONST_STACK_OF(SRTP_PROTECTION_PROFILE)
  2641. // SRTP_* define constants for SRTP profiles.
  2642. #define SRTP_AES128_CM_SHA1_80 0x0001
  2643. #define SRTP_AES128_CM_SHA1_32 0x0002
  2644. #define SRTP_AES128_F8_SHA1_80 0x0003
  2645. #define SRTP_AES128_F8_SHA1_32 0x0004
  2646. #define SRTP_NULL_SHA1_80 0x0005
  2647. #define SRTP_NULL_SHA1_32 0x0006
  2648. #define SRTP_AEAD_AES_128_GCM 0x0007
  2649. #define SRTP_AEAD_AES_256_GCM 0x0008
  2650. // SSL_CTX_set_srtp_profiles enables SRTP for all SSL objects created from
  2651. // |ctx|. |profile| contains a colon-separated list of profile names. It returns
  2652. // one on success and zero on failure.
  2653. OPENSSL_EXPORT int SSL_CTX_set_srtp_profiles(SSL_CTX *ctx,
  2654. const char *profiles);
  2655. // SSL_set_srtp_profiles enables SRTP for |ssl|. |profile| contains a
  2656. // colon-separated list of profile names. It returns one on success and zero on
  2657. // failure.
  2658. OPENSSL_EXPORT int SSL_set_srtp_profiles(SSL *ssl, const char *profiles);
  2659. // SSL_get_srtp_profiles returns the SRTP profiles supported by |ssl|.
  2660. OPENSSL_EXPORT const STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(
  2661. const SSL *ssl);
  2662. // SSL_get_selected_srtp_profile returns the selected SRTP profile, or NULL if
  2663. // SRTP was not negotiated.
  2664. OPENSSL_EXPORT const SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(
  2665. SSL *ssl);
  2666. // Pre-shared keys.
  2667. //
  2668. // Connections may be configured with PSK (Pre-Shared Key) cipher suites. These
  2669. // authenticate using out-of-band pre-shared keys rather than certificates. See
  2670. // RFC 4279.
  2671. //
  2672. // This implementation uses NUL-terminated C strings for identities and identity
  2673. // hints, so values with a NUL character are not supported. (RFC 4279 does not
  2674. // specify the format of an identity.)
  2675. // PSK_MAX_IDENTITY_LEN is the maximum supported length of a PSK identity,
  2676. // excluding the NUL terminator.
  2677. #define PSK_MAX_IDENTITY_LEN 128
  2678. // PSK_MAX_PSK_LEN is the maximum supported length of a pre-shared key.
  2679. #define PSK_MAX_PSK_LEN 256
  2680. // SSL_CTX_set_psk_client_callback sets the callback to be called when PSK is
  2681. // negotiated on the client. This callback must be set to enable PSK cipher
  2682. // suites on the client.
  2683. //
  2684. // The callback is passed the identity hint in |hint| or NULL if none was
  2685. // provided. It should select a PSK identity and write the identity and the
  2686. // corresponding PSK to |identity| and |psk|, respectively. The identity is
  2687. // written as a NUL-terminated C string of length (excluding the NUL terminator)
  2688. // at most |max_identity_len|. The PSK's length must be at most |max_psk_len|.
  2689. // The callback returns the length of the PSK or 0 if no suitable identity was
  2690. // found.
  2691. OPENSSL_EXPORT void SSL_CTX_set_psk_client_callback(
  2692. SSL_CTX *ctx, unsigned (*cb)(SSL *ssl, const char *hint, char *identity,
  2693. unsigned max_identity_len, uint8_t *psk,
  2694. unsigned max_psk_len));
  2695. // SSL_set_psk_client_callback sets the callback to be called when PSK is
  2696. // negotiated on the client. This callback must be set to enable PSK cipher
  2697. // suites on the client. See also |SSL_CTX_set_psk_client_callback|.
  2698. OPENSSL_EXPORT void SSL_set_psk_client_callback(
  2699. SSL *ssl, unsigned (*cb)(SSL *ssl, const char *hint, char *identity,
  2700. unsigned max_identity_len, uint8_t *psk,
  2701. unsigned max_psk_len));
  2702. // SSL_CTX_set_psk_server_callback sets the callback to be called when PSK is
  2703. // negotiated on the server. This callback must be set to enable PSK cipher
  2704. // suites on the server.
  2705. //
  2706. // The callback is passed the identity in |identity|. It should write a PSK of
  2707. // length at most |max_psk_len| to |psk| and return the number of bytes written
  2708. // or zero if the PSK identity is unknown.
  2709. OPENSSL_EXPORT void SSL_CTX_set_psk_server_callback(
  2710. SSL_CTX *ctx, unsigned (*cb)(SSL *ssl, const char *identity, uint8_t *psk,
  2711. unsigned max_psk_len));
  2712. // SSL_set_psk_server_callback sets the callback to be called when PSK is
  2713. // negotiated on the server. This callback must be set to enable PSK cipher
  2714. // suites on the server. See also |SSL_CTX_set_psk_server_callback|.
  2715. OPENSSL_EXPORT void SSL_set_psk_server_callback(
  2716. SSL *ssl, unsigned (*cb)(SSL *ssl, const char *identity, uint8_t *psk,
  2717. unsigned max_psk_len));
  2718. // SSL_CTX_use_psk_identity_hint configures server connections to advertise an
  2719. // identity hint of |identity_hint|. It returns one on success and zero on
  2720. // error.
  2721. OPENSSL_EXPORT int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx,
  2722. const char *identity_hint);
  2723. // SSL_use_psk_identity_hint configures server connections to advertise an
  2724. // identity hint of |identity_hint|. It returns one on success and zero on
  2725. // error.
  2726. OPENSSL_EXPORT int SSL_use_psk_identity_hint(SSL *ssl,
  2727. const char *identity_hint);
  2728. // SSL_get_psk_identity_hint returns the PSK identity hint advertised for |ssl|
  2729. // or NULL if there is none.
  2730. OPENSSL_EXPORT const char *SSL_get_psk_identity_hint(const SSL *ssl);
  2731. // SSL_get_psk_identity, after the handshake completes, returns the PSK identity
  2732. // that was negotiated by |ssl| or NULL if PSK was not used.
  2733. OPENSSL_EXPORT const char *SSL_get_psk_identity(const SSL *ssl);
  2734. // Delegated credentials.
  2735. //
  2736. // *** EXPERIMENTAL — PRONE TO CHANGE ***
  2737. //
  2738. // draft-ietf-tls-subcerts is a proposed extension for TLS 1.3 and above that
  2739. // allows an end point to use its certificate to delegate credentials for
  2740. // authentication. If the peer indicates support for this extension, then this
  2741. // host may use a delegated credential to sign the handshake. Once issued,
  2742. // credentials can't be revoked. In order to mitigate the damage in case the
  2743. // credential secret key is compromised, the credential is only valid for a
  2744. // short time (days, hours, or even minutes). This library implements draft-03
  2745. // of the protocol spec.
  2746. //
  2747. // The extension ID has not been assigned; we're using 0xff02 for the time
  2748. // being. Currently only the server side is implemented.
  2749. //
  2750. // Servers configure a DC for use in the handshake via
  2751. // |SSL_set1_delegated_credential|. It must be signed by the host's end-entity
  2752. // certificate as defined in draft-ietf-tls-subcerts-03.
  2753. // SSL_set1_delegated_credential configures the delegated credential (DC) that
  2754. // will be sent to the peer for the current connection. |dc| is the DC in wire
  2755. // format, and |pkey| or |key_method| is the corresponding private key.
  2756. // Currently (as of draft-03), only servers may configure a DC to use in the
  2757. // handshake.
  2758. //
  2759. // The DC will only be used if the protocol version is correct and the signature
  2760. // scheme is supported by the peer. If not, the DC will not be negotiated and
  2761. // the handshake will use the private key (or private key method) associated
  2762. // with the certificate.
  2763. OPENSSL_EXPORT int SSL_set1_delegated_credential(
  2764. SSL *ssl, CRYPTO_BUFFER *dc, EVP_PKEY *pkey,
  2765. const SSL_PRIVATE_KEY_METHOD *key_method);
  2766. // SSL_delegated_credential_used returns one if a delegated credential was used
  2767. // and zero otherwise.
  2768. OPENSSL_EXPORT int SSL_delegated_credential_used(const SSL *ssl);
  2769. // QUIC integration.
  2770. //
  2771. // QUIC acts as an underlying transport for the TLS 1.3 handshake. The following
  2772. // functions allow a QUIC implementation to serve as the underlying transport as
  2773. // described in RFC 9001.
  2774. //
  2775. // When configured for QUIC, |SSL_do_handshake| will drive the handshake as
  2776. // before, but it will not use the configured |BIO|. It will call functions on
  2777. // |SSL_QUIC_METHOD| to configure secrets and send data. If data is needed from
  2778. // the peer, it will return |SSL_ERROR_WANT_READ|. As the caller receives data
  2779. // it can decrypt, it calls |SSL_provide_quic_data|. Subsequent
  2780. // |SSL_do_handshake| calls will then consume that data and progress the
  2781. // handshake. After the handshake is complete, the caller should continue to
  2782. // call |SSL_provide_quic_data| for any post-handshake data, followed by
  2783. // |SSL_process_quic_post_handshake| to process it. It is an error to call
  2784. // |SSL_read| and |SSL_write| in QUIC.
  2785. //
  2786. // 0-RTT behaves similarly to |TLS_method|'s usual behavior. |SSL_do_handshake|
  2787. // returns early as soon as the client (respectively, server) is allowed to send
  2788. // 0-RTT (respectively, half-RTT) data. The caller should then call
  2789. // |SSL_do_handshake| again to consume the remaining handshake messages and
  2790. // confirm the handshake. As a client, |SSL_ERROR_EARLY_DATA_REJECTED| and
  2791. // |SSL_reset_early_data_reject| behave as usual.
  2792. //
  2793. // See https://www.rfc-editor.org/rfc/rfc9001.html#section-4.1 for more details.
  2794. //
  2795. // To avoid DoS attacks, the QUIC implementation must limit the amount of data
  2796. // being queued up. The implementation can call
  2797. // |SSL_quic_max_handshake_flight_len| to get the maximum buffer length at each
  2798. // encryption level.
  2799. //
  2800. // QUIC implementations must additionally configure transport parameters with
  2801. // |SSL_set_quic_transport_params|. |SSL_get_peer_quic_transport_params| may be
  2802. // used to query the value received from the peer. BoringSSL handles this
  2803. // extension as an opaque byte string. The caller is responsible for serializing
  2804. // and parsing them. See https://www.rfc-editor.org/rfc/rfc9000#section-7.4 for
  2805. // details.
  2806. //
  2807. // QUIC additionally imposes restrictions on 0-RTT. In particular, the QUIC
  2808. // transport layer requires that if a server accepts 0-RTT data, then the
  2809. // transport parameters sent on the resumed connection must not lower any limits
  2810. // compared to the transport parameters that the server sent on the connection
  2811. // where the ticket for 0-RTT was issued. In effect, the server must remember
  2812. // the transport parameters with the ticket. Application protocols running on
  2813. // QUIC may impose similar restrictions, for example HTTP/3's restrictions on
  2814. // SETTINGS frames.
  2815. //
  2816. // BoringSSL implements this check by doing a byte-for-byte comparison of an
  2817. // opaque context passed in by the server. This context must be the same on the
  2818. // connection where the ticket was issued and the connection where that ticket
  2819. // is used for 0-RTT. If there is a mismatch, or the context was not set,
  2820. // BoringSSL will reject early data (but not reject the resumption attempt).
  2821. // This context is set via |SSL_set_quic_early_data_context| and should cover
  2822. // both transport parameters and any application state.
  2823. // |SSL_set_quic_early_data_context| must be called on the server with a
  2824. // non-empty context if the server is to support 0-RTT in QUIC.
  2825. //
  2826. // BoringSSL does not perform any client-side checks on the transport
  2827. // parameters received from a server that also accepted early data. It is up to
  2828. // the caller to verify that the received transport parameters do not lower any
  2829. // limits, and to close the QUIC connection if that is not the case. The same
  2830. // holds for any application protocol state remembered for 0-RTT, e.g. HTTP/3
  2831. // SETTINGS.
  2832. // ssl_encryption_level_t represents a specific QUIC encryption level used to
  2833. // transmit handshake messages.
  2834. enum ssl_encryption_level_t BORINGSSL_ENUM_INT {
  2835. ssl_encryption_initial = 0,
  2836. ssl_encryption_early_data,
  2837. ssl_encryption_handshake,
  2838. ssl_encryption_application,
  2839. };
  2840. // ssl_quic_method_st (aka |SSL_QUIC_METHOD|) describes custom QUIC hooks.
  2841. struct ssl_quic_method_st {
  2842. // set_read_secret configures the read secret and cipher suite for the given
  2843. // encryption level. It returns one on success and zero to terminate the
  2844. // handshake with an error. It will be called at most once per encryption
  2845. // level.
  2846. //
  2847. // BoringSSL will not release read keys before QUIC may use them. Once a level
  2848. // has been initialized, QUIC may begin processing data from it. Handshake
  2849. // data should be passed to |SSL_provide_quic_data| and application data (if
  2850. // |level| is |ssl_encryption_early_data| or |ssl_encryption_application|) may
  2851. // be processed according to the rules of the QUIC protocol.
  2852. //
  2853. // QUIC ACKs packets at the same encryption level they were received at,
  2854. // except that client |ssl_encryption_early_data| (0-RTT) packets trigger
  2855. // server |ssl_encryption_application| (1-RTT) ACKs. BoringSSL will always
  2856. // install ACK-writing keys with |set_write_secret| before the packet-reading
  2857. // keys with |set_read_secret|. This ensures the caller can always ACK any
  2858. // packet it decrypts. Note this means the server installs 1-RTT write keys
  2859. // before 0-RTT read keys.
  2860. //
  2861. // The converse is not true. An encryption level may be configured with write
  2862. // secrets a roundtrip before the corresponding secrets for reading ACKs is
  2863. // available.
  2864. int (*set_read_secret)(SSL *ssl, enum ssl_encryption_level_t level,
  2865. const SSL_CIPHER *cipher, const uint8_t *secret,
  2866. size_t secret_len);
  2867. // set_write_secret behaves like |set_read_secret| but configures the write
  2868. // secret and cipher suite for the given encryption level. It will be called
  2869. // at most once per encryption level.
  2870. //
  2871. // BoringSSL will not release write keys before QUIC may use them. If |level|
  2872. // is |ssl_encryption_early_data| or |ssl_encryption_application|, QUIC may
  2873. // begin sending application data at |level|. However, note that BoringSSL
  2874. // configures server |ssl_encryption_application| write keys before the client
  2875. // Finished. This allows QUIC to send half-RTT data, but the handshake is not
  2876. // confirmed at this point and, if requesting client certificates, the client
  2877. // is not yet authenticated.
  2878. //
  2879. // See |set_read_secret| for additional invariants between packets and their
  2880. // ACKs.
  2881. //
  2882. // Note that, on 0-RTT reject, the |ssl_encryption_early_data| write secret
  2883. // may use a different cipher suite from the other keys.
  2884. int (*set_write_secret)(SSL *ssl, enum ssl_encryption_level_t level,
  2885. const SSL_CIPHER *cipher, const uint8_t *secret,
  2886. size_t secret_len);
  2887. // add_handshake_data adds handshake data to the current flight at the given
  2888. // encryption level. It returns one on success and zero on error.
  2889. //
  2890. // BoringSSL will pack data from a single encryption level together, but a
  2891. // single handshake flight may include multiple encryption levels. Callers
  2892. // should defer writing data to the network until |flush_flight| to better
  2893. // pack QUIC packets into transport datagrams.
  2894. //
  2895. // If |level| is not |ssl_encryption_initial|, this function will not be
  2896. // called before |level| is initialized with |set_write_secret|.
  2897. int (*add_handshake_data)(SSL *ssl, enum ssl_encryption_level_t level,
  2898. const uint8_t *data, size_t len);
  2899. // flush_flight is called when the current flight is complete and should be
  2900. // written to the transport. Note a flight may contain data at several
  2901. // encryption levels. It returns one on success and zero on error.
  2902. int (*flush_flight)(SSL *ssl);
  2903. // send_alert sends a fatal alert at the specified encryption level. It
  2904. // returns one on success and zero on error.
  2905. //
  2906. // If |level| is not |ssl_encryption_initial|, this function will not be
  2907. // called before |level| is initialized with |set_write_secret|.
  2908. int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level, uint8_t alert);
  2909. };
  2910. // SSL_quic_max_handshake_flight_len returns returns the maximum number of bytes
  2911. // that may be received at the given encryption level. This function should be
  2912. // used to limit buffering in the QUIC implementation.
  2913. //
  2914. // See https://www.rfc-editor.org/rfc/rfc9000#section-7.5
  2915. OPENSSL_EXPORT size_t SSL_quic_max_handshake_flight_len(
  2916. const SSL *ssl, enum ssl_encryption_level_t level);
  2917. // SSL_quic_read_level returns the current read encryption level.
  2918. //
  2919. // TODO(davidben): Is it still necessary to expose this function to callers?
  2920. // QUICHE does not use it.
  2921. OPENSSL_EXPORT enum ssl_encryption_level_t SSL_quic_read_level(const SSL *ssl);
  2922. // SSL_quic_write_level returns the current write encryption level.
  2923. //
  2924. // TODO(davidben): Is it still necessary to expose this function to callers?
  2925. // QUICHE does not use it.
  2926. OPENSSL_EXPORT enum ssl_encryption_level_t SSL_quic_write_level(const SSL *ssl);
  2927. // SSL_provide_quic_data provides data from QUIC at a particular encryption
  2928. // level |level|. It returns one on success and zero on error. Note this
  2929. // function will return zero if the handshake is not expecting data from |level|
  2930. // at this time. The QUIC implementation should then close the connection with
  2931. // an error.
  2932. OPENSSL_EXPORT int SSL_provide_quic_data(SSL *ssl,
  2933. enum ssl_encryption_level_t level,
  2934. const uint8_t *data, size_t len);
  2935. // SSL_process_quic_post_handshake processes any data that QUIC has provided
  2936. // after the handshake has completed. This includes NewSessionTicket messages
  2937. // sent by the server. It returns one on success and zero on error.
  2938. OPENSSL_EXPORT int SSL_process_quic_post_handshake(SSL *ssl);
  2939. // SSL_CTX_set_quic_method configures the QUIC hooks. This should only be
  2940. // configured with a minimum version of TLS 1.3. |quic_method| must remain valid
  2941. // for the lifetime of |ctx|. It returns one on success and zero on error.
  2942. OPENSSL_EXPORT int SSL_CTX_set_quic_method(SSL_CTX *ctx,
  2943. const SSL_QUIC_METHOD *quic_method);
  2944. // SSL_set_quic_method configures the QUIC hooks. This should only be
  2945. // configured with a minimum version of TLS 1.3. |quic_method| must remain valid
  2946. // for the lifetime of |ssl|. It returns one on success and zero on error.
  2947. OPENSSL_EXPORT int SSL_set_quic_method(SSL *ssl,
  2948. const SSL_QUIC_METHOD *quic_method);
  2949. // SSL_set_quic_transport_params configures |ssl| to send |params| (of length
  2950. // |params_len|) in the quic_transport_parameters extension in either the
  2951. // ClientHello or EncryptedExtensions handshake message. It is an error to set
  2952. // transport parameters if |ssl| is not configured for QUIC. The buffer pointed
  2953. // to by |params| only need be valid for the duration of the call to this
  2954. // function. This function returns 1 on success and 0 on failure.
  2955. OPENSSL_EXPORT int SSL_set_quic_transport_params(SSL *ssl,
  2956. const uint8_t *params,
  2957. size_t params_len);
  2958. // SSL_get_peer_quic_transport_params provides the caller with the value of the
  2959. // quic_transport_parameters extension sent by the peer. A pointer to the buffer
  2960. // containing the TransportParameters will be put in |*out_params|, and its
  2961. // length in |*params_len|. This buffer will be valid for the lifetime of the
  2962. // |SSL|. If no params were received from the peer, |*out_params_len| will be 0.
  2963. OPENSSL_EXPORT void SSL_get_peer_quic_transport_params(
  2964. const SSL *ssl, const uint8_t **out_params, size_t *out_params_len);
  2965. // SSL_set_quic_use_legacy_codepoint configures whether to use the legacy QUIC
  2966. // extension codepoint 0xffa5 as opposed to the official value 57. Call with
  2967. // |use_legacy| set to 1 to use 0xffa5 and call with 0 to use 57. By default,
  2968. // the standard code point is used.
  2969. OPENSSL_EXPORT void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);
  2970. // SSL_set_quic_early_data_context configures a context string in QUIC servers
  2971. // for accepting early data. If a resumption connection offers early data, the
  2972. // server will check if the value matches that of the connection which minted
  2973. // the ticket. If not, resumption still succeeds but early data is rejected.
  2974. // This should include all QUIC Transport Parameters except ones specified that
  2975. // the client MUST NOT remember. This should also include any application
  2976. // protocol-specific state. For HTTP/3, this should be the serialized server
  2977. // SETTINGS frame and the QUIC Transport Parameters (except the stateless reset
  2978. // token).
  2979. //
  2980. // This function may be called before |SSL_do_handshake| or during server
  2981. // certificate selection. It returns 1 on success and 0 on failure.
  2982. OPENSSL_EXPORT int SSL_set_quic_early_data_context(SSL *ssl,
  2983. const uint8_t *context,
  2984. size_t context_len);
  2985. // Early data.
  2986. //
  2987. // WARNING: 0-RTT support in BoringSSL is currently experimental and not fully
  2988. // implemented. It may cause interoperability or security failures when used.
  2989. //
  2990. // Early data, or 0-RTT, is a feature in TLS 1.3 which allows clients to send
  2991. // data on the first flight during a resumption handshake. This can save a
  2992. // round-trip in some application protocols.
  2993. //
  2994. // WARNING: A 0-RTT handshake has different security properties from normal
  2995. // handshake, so it is off by default unless opted in. In particular, early data
  2996. // is replayable by a network attacker. Callers must account for this when
  2997. // sending or processing data before the handshake is confirmed. See RFC 8446
  2998. // for more information.
  2999. //
  3000. // As a server, if early data is accepted, |SSL_do_handshake| will complete as
  3001. // soon as the ClientHello is processed and server flight sent. |SSL_write| may
  3002. // be used to send half-RTT data. |SSL_read| will consume early data and
  3003. // transition to 1-RTT data as appropriate. Prior to the transition,
  3004. // |SSL_in_init| will report the handshake is still in progress. Callers may use
  3005. // it or |SSL_in_early_data| to defer or reject requests as needed.
  3006. //
  3007. // Early data as a client is more complex. If the offered session (see
  3008. // |SSL_set_session|) is 0-RTT-capable, the handshake will return after sending
  3009. // the ClientHello. The predicted peer certificates and ALPN protocol will be
  3010. // available via the usual APIs. |SSL_write| will write early data, up to the
  3011. // session's limit. Writes past this limit and |SSL_read| will complete the
  3012. // handshake before continuing. Callers may also call |SSL_do_handshake| again
  3013. // to complete the handshake sooner.
  3014. //
  3015. // If the server accepts early data, the handshake will succeed. |SSL_read| and
  3016. // |SSL_write| will then act as in a 1-RTT handshake. The peer certificates and
  3017. // ALPN protocol will be as predicted and need not be re-queried.
  3018. //
  3019. // If the server rejects early data, |SSL_do_handshake| (and thus |SSL_read| and
  3020. // |SSL_write|) will then fail with |SSL_get_error| returning
  3021. // |SSL_ERROR_EARLY_DATA_REJECTED|. The caller should treat this as a connection
  3022. // error and most likely perform a high-level retry. Note the server may still
  3023. // have processed the early data due to attacker replays.
  3024. //
  3025. // To then continue the handshake on the original connection, use
  3026. // |SSL_reset_early_data_reject|. The connection will then behave as one which
  3027. // had not yet completed the handshake. This allows a faster retry than making a
  3028. // fresh connection. |SSL_do_handshake| will complete the full handshake,
  3029. // possibly resulting in different peer certificates, ALPN protocol, and other
  3030. // properties. The caller must disregard any values from before the reset and
  3031. // query again.
  3032. //
  3033. // Finally, to implement the fallback described in RFC 8446 appendix D.3, retry
  3034. // on a fresh connection without 0-RTT if the handshake fails with
  3035. // |SSL_R_WRONG_VERSION_ON_EARLY_DATA|.
  3036. // SSL_CTX_set_early_data_enabled sets whether early data is allowed to be used
  3037. // with resumptions using |ctx|.
  3038. OPENSSL_EXPORT void SSL_CTX_set_early_data_enabled(SSL_CTX *ctx, int enabled);
  3039. // SSL_set_early_data_enabled sets whether early data is allowed to be used
  3040. // with resumptions using |ssl|. See |SSL_CTX_set_early_data_enabled| for more
  3041. // information.
  3042. OPENSSL_EXPORT void SSL_set_early_data_enabled(SSL *ssl, int enabled);
  3043. // SSL_in_early_data returns one if |ssl| has a pending handshake that has
  3044. // progressed enough to send or receive early data. Clients may call |SSL_write|
  3045. // to send early data, but |SSL_read| will complete the handshake before
  3046. // accepting application data. Servers may call |SSL_read| to read early data
  3047. // and |SSL_write| to send half-RTT data.
  3048. OPENSSL_EXPORT int SSL_in_early_data(const SSL *ssl);
  3049. // SSL_SESSION_early_data_capable returns whether early data would have been
  3050. // attempted with |session| if enabled.
  3051. OPENSSL_EXPORT int SSL_SESSION_early_data_capable(const SSL_SESSION *session);
  3052. // SSL_SESSION_copy_without_early_data returns a copy of |session| with early
  3053. // data disabled. If |session| already does not support early data, it returns
  3054. // |session| with the reference count increased. The caller takes ownership of
  3055. // the result and must release it with |SSL_SESSION_free|.
  3056. //
  3057. // This function may be used on the client to clear early data support from
  3058. // existing sessions when the server rejects early data. In particular,
  3059. // |SSL_R_WRONG_VERSION_ON_EARLY_DATA| requires a fresh connection to retry, and
  3060. // the client would not want 0-RTT enabled for the next connection attempt.
  3061. OPENSSL_EXPORT SSL_SESSION *SSL_SESSION_copy_without_early_data(
  3062. SSL_SESSION *session);
  3063. // SSL_early_data_accepted returns whether early data was accepted on the
  3064. // handshake performed by |ssl|.
  3065. OPENSSL_EXPORT int SSL_early_data_accepted(const SSL *ssl);
  3066. // SSL_reset_early_data_reject resets |ssl| after an early data reject. All
  3067. // 0-RTT state is discarded, including any pending |SSL_write| calls. The caller
  3068. // should treat |ssl| as a logically fresh connection, usually by driving the
  3069. // handshake to completion using |SSL_do_handshake|.
  3070. //
  3071. // It is an error to call this function on an |SSL| object that is not signaling
  3072. // |SSL_ERROR_EARLY_DATA_REJECTED|.
  3073. OPENSSL_EXPORT void SSL_reset_early_data_reject(SSL *ssl);
  3074. // SSL_get_ticket_age_skew returns the difference, in seconds, between the
  3075. // client-sent ticket age and the server-computed value in TLS 1.3 server
  3076. // connections which resumed a session.
  3077. OPENSSL_EXPORT int32_t SSL_get_ticket_age_skew(const SSL *ssl);
  3078. // An ssl_early_data_reason_t describes why 0-RTT was accepted or rejected.
  3079. // These values are persisted to logs. Entries should not be renumbered and
  3080. // numeric values should never be reused.
  3081. enum ssl_early_data_reason_t BORINGSSL_ENUM_INT {
  3082. // The handshake has not progressed far enough for the 0-RTT status to be
  3083. // known.
  3084. ssl_early_data_unknown = 0,
  3085. // 0-RTT is disabled for this connection.
  3086. ssl_early_data_disabled = 1,
  3087. // 0-RTT was accepted.
  3088. ssl_early_data_accepted = 2,
  3089. // The negotiated protocol version does not support 0-RTT.
  3090. ssl_early_data_protocol_version = 3,
  3091. // The peer declined to offer or accept 0-RTT for an unknown reason.
  3092. ssl_early_data_peer_declined = 4,
  3093. // The client did not offer a session.
  3094. ssl_early_data_no_session_offered = 5,
  3095. // The server declined to resume the session.
  3096. ssl_early_data_session_not_resumed = 6,
  3097. // The session does not support 0-RTT.
  3098. ssl_early_data_unsupported_for_session = 7,
  3099. // The server sent a HelloRetryRequest.
  3100. ssl_early_data_hello_retry_request = 8,
  3101. // The negotiated ALPN protocol did not match the session.
  3102. ssl_early_data_alpn_mismatch = 9,
  3103. // The connection negotiated Channel ID, which is incompatible with 0-RTT.
  3104. ssl_early_data_channel_id = 10,
  3105. // Value 11 is reserved. (It has historically |ssl_early_data_token_binding|.)
  3106. // The client and server ticket age were too far apart.
  3107. ssl_early_data_ticket_age_skew = 12,
  3108. // QUIC parameters differ between this connection and the original.
  3109. ssl_early_data_quic_parameter_mismatch = 13,
  3110. // The application settings did not match the session.
  3111. ssl_early_data_alps_mismatch = 14,
  3112. // The value of the largest entry.
  3113. ssl_early_data_reason_max_value = ssl_early_data_alps_mismatch,
  3114. };
  3115. // SSL_get_early_data_reason returns details why 0-RTT was accepted or rejected
  3116. // on |ssl|. This is primarily useful on the server.
  3117. OPENSSL_EXPORT enum ssl_early_data_reason_t SSL_get_early_data_reason(
  3118. const SSL *ssl);
  3119. // SSL_early_data_reason_string returns a string representation for |reason|, or
  3120. // NULL if |reason| is unknown. This function may be used for logging.
  3121. OPENSSL_EXPORT const char *SSL_early_data_reason_string(
  3122. enum ssl_early_data_reason_t reason);
  3123. // Encrypted ClientHello.
  3124. //
  3125. // ECH is a mechanism for encrypting the entire ClientHello message in TLS 1.3.
  3126. // This can prevent observers from seeing cleartext information about the
  3127. // connection, such as the server_name extension.
  3128. //
  3129. // By default, BoringSSL will treat the server name, session ticket, and client
  3130. // certificate as secret, but most other parameters, such as the ALPN protocol
  3131. // list will be treated as public and sent in the cleartext ClientHello. Other
  3132. // APIs may be added for applications with different secrecy requirements.
  3133. //
  3134. // ECH support in BoringSSL is still experimental and under development.
  3135. //
  3136. // See https://tools.ietf.org/html/draft-ietf-tls-esni-13.
  3137. // SSL_set_enable_ech_grease configures whether the client will send a GREASE
  3138. // ECH extension when no supported ECHConfig is available.
  3139. OPENSSL_EXPORT void SSL_set_enable_ech_grease(SSL *ssl, int enable);
  3140. // SSL_set1_ech_config_list configures |ssl| to, as a client, offer ECH with the
  3141. // specified configuration. |ech_config_list| should contain a serialized
  3142. // ECHConfigList structure. It returns one on success and zero on error.
  3143. //
  3144. // This function returns an error if the input is malformed. If the input is
  3145. // valid but none of the ECHConfigs implement supported parameters, it will
  3146. // return success and proceed without ECH.
  3147. //
  3148. // If a supported ECHConfig is found, |ssl| will encrypt the true ClientHello
  3149. // parameters. If the server cannot decrypt it, e.g. due to a key mismatch, ECH
  3150. // has a recovery flow. |ssl| will handshake using the cleartext parameters,
  3151. // including a public name in the ECHConfig. If using
  3152. // |SSL_CTX_set_custom_verify|, callers should use |SSL_get0_ech_name_override|
  3153. // to verify the certificate with the public name. If using the built-in
  3154. // verifier, the |X509_STORE_CTX| will be configured automatically.
  3155. //
  3156. // If no other errors are found in this handshake, it will fail with
  3157. // |SSL_R_ECH_REJECTED|. Since it didn't use the true parameters, the connection
  3158. // cannot be used for application data. Instead, callers should handle this
  3159. // error by calling |SSL_get0_ech_retry_configs| and retrying the connection
  3160. // with updated ECH parameters. If the retry also fails with
  3161. // |SSL_R_ECH_REJECTED|, the caller should report a connection failure.
  3162. OPENSSL_EXPORT int SSL_set1_ech_config_list(SSL *ssl,
  3163. const uint8_t *ech_config_list,
  3164. size_t ech_config_list_len);
  3165. // SSL_get0_ech_name_override, if |ssl| is a client and the server rejected ECH,
  3166. // sets |*out_name| and |*out_name_len| to point to a buffer containing the ECH
  3167. // public name. Otherwise, the buffer will be empty.
  3168. //
  3169. // When offering ECH as a client, this function should be called during the
  3170. // certificate verification callback (see |SSL_CTX_set_custom_verify|). If
  3171. // |*out_name_len| is non-zero, the caller should verify the certificate against
  3172. // the result, interpreted as a DNS name, rather than the true server name. In
  3173. // this case, the handshake will never succeed and is only used to authenticate
  3174. // retry configs. See also |SSL_get0_ech_retry_configs|.
  3175. OPENSSL_EXPORT void SSL_get0_ech_name_override(const SSL *ssl,
  3176. const char **out_name,
  3177. size_t *out_name_len);
  3178. // SSL_get0_ech_retry_configs sets |*out_retry_configs| and
  3179. // |*out_retry_configs_len| to a buffer containing a serialized ECHConfigList.
  3180. // If the server did not provide an ECHConfigList, |*out_retry_configs_len| will
  3181. // be zero.
  3182. //
  3183. // When handling an |SSL_R_ECH_REJECTED| error code as a client, callers should
  3184. // use this function to recover from potential key mismatches. If the result is
  3185. // non-empty, the caller should retry the connection, passing this buffer to
  3186. // |SSL_set1_ech_config_list|. If the result is empty, the server has rolled
  3187. // back ECH support, and the caller should retry without ECH.
  3188. //
  3189. // This function must only be called in response to an |SSL_R_ECH_REJECTED|
  3190. // error code. Calling this function on |ssl|s that have not authenticated the
  3191. // rejection handshake will assert in debug builds and otherwise return an
  3192. // unparsable list.
  3193. OPENSSL_EXPORT void SSL_get0_ech_retry_configs(
  3194. const SSL *ssl, const uint8_t **out_retry_configs,
  3195. size_t *out_retry_configs_len);
  3196. // SSL_marshal_ech_config constructs a new serialized ECHConfig. On success, it
  3197. // sets |*out| to a newly-allocated buffer containing the result and |*out_len|
  3198. // to the size of the buffer. The caller must call |OPENSSL_free| on |*out| to
  3199. // release the memory. On failure, it returns zero.
  3200. //
  3201. // The |config_id| field is a single byte identifer for the ECHConfig. Reusing
  3202. // config IDs is allowed, but if multiple ECHConfigs with the same config ID are
  3203. // active at a time, server load may increase. See
  3204. // |SSL_ECH_KEYS_has_duplicate_config_id|.
  3205. //
  3206. // The public key and KEM algorithm are taken from |key|. |public_name| is the
  3207. // DNS name used to authenticate the recovery flow. |max_name_len| should be the
  3208. // length of the longest name in the ECHConfig's anonymity set and influences
  3209. // client padding decisions.
  3210. OPENSSL_EXPORT int SSL_marshal_ech_config(uint8_t **out, size_t *out_len,
  3211. uint8_t config_id,
  3212. const EVP_HPKE_KEY *key,
  3213. const char *public_name,
  3214. size_t max_name_len);
  3215. // SSL_ECH_KEYS_new returns a newly-allocated |SSL_ECH_KEYS| or NULL on error.
  3216. OPENSSL_EXPORT SSL_ECH_KEYS *SSL_ECH_KEYS_new(void);
  3217. // SSL_ECH_KEYS_up_ref increments the reference count of |keys|.
  3218. OPENSSL_EXPORT void SSL_ECH_KEYS_up_ref(SSL_ECH_KEYS *keys);
  3219. // SSL_ECH_KEYS_free releases memory associated with |keys|.
  3220. OPENSSL_EXPORT void SSL_ECH_KEYS_free(SSL_ECH_KEYS *keys);
  3221. // SSL_ECH_KEYS_add decodes |ech_config| as an ECHConfig and appends it with
  3222. // |key| to |keys|. If |is_retry_config| is non-zero, this config will be
  3223. // returned to the client on configuration mismatch. It returns one on success
  3224. // and zero on error.
  3225. //
  3226. // This function should be called successively to register each ECHConfig in
  3227. // decreasing order of preference. This configuration must be completed before
  3228. // setting |keys| on an |SSL_CTX| with |SSL_CTX_set1_ech_keys|. After that
  3229. // point, |keys| is immutable; no more ECHConfig values may be added.
  3230. //
  3231. // See also |SSL_CTX_set1_ech_keys|.
  3232. OPENSSL_EXPORT int SSL_ECH_KEYS_add(SSL_ECH_KEYS *keys, int is_retry_config,
  3233. const uint8_t *ech_config,
  3234. size_t ech_config_len,
  3235. const EVP_HPKE_KEY *key);
  3236. // SSL_ECH_KEYS_has_duplicate_config_id returns one if |keys| has duplicate
  3237. // config IDs or zero otherwise. Duplicate config IDs still work, but may
  3238. // increase server load due to trial decryption.
  3239. OPENSSL_EXPORT int SSL_ECH_KEYS_has_duplicate_config_id(
  3240. const SSL_ECH_KEYS *keys);
  3241. // SSL_ECH_KEYS_marshal_retry_configs serializes the retry configs in |keys| as
  3242. // an ECHConfigList. On success, it sets |*out| to a newly-allocated buffer
  3243. // containing the result and |*out_len| to the size of the buffer. The caller
  3244. // must call |OPENSSL_free| on |*out| to release the memory. On failure, it
  3245. // returns zero.
  3246. //
  3247. // This output may be advertised to clients in DNS.
  3248. OPENSSL_EXPORT int SSL_ECH_KEYS_marshal_retry_configs(const SSL_ECH_KEYS *keys,
  3249. uint8_t **out,
  3250. size_t *out_len);
  3251. // SSL_CTX_set1_ech_keys configures |ctx| to use |keys| to decrypt encrypted
  3252. // ClientHellos. It returns one on success, and zero on failure. If |keys| does
  3253. // not contain any retry configs, this function will fail. Retry configs are
  3254. // marked as such when they are added to |keys| with |SSL_ECH_KEYS_add|.
  3255. //
  3256. // Once |keys| has been passed to this function, it is immutable. Unlike most
  3257. // |SSL_CTX| configuration functions, this function may be called even if |ctx|
  3258. // already has associated connections on multiple threads. This may be used to
  3259. // rotate keys in a long-lived server process.
  3260. //
  3261. // The configured ECHConfig values should also be advertised out-of-band via DNS
  3262. // (see draft-ietf-dnsop-svcb-https). Before advertising an ECHConfig in DNS,
  3263. // deployments should ensure all instances of the service are configured with
  3264. // the ECHConfig and corresponding private key.
  3265. //
  3266. // Only the most recent fully-deployed ECHConfigs should be advertised in DNS.
  3267. // |keys| may contain a newer set if those ECHConfigs are mid-deployment. It
  3268. // should also contain older sets, until the DNS change has rolled out and the
  3269. // old records have expired from caches.
  3270. //
  3271. // If there is a mismatch, |SSL| objects associated with |ctx| will complete the
  3272. // handshake using the cleartext ClientHello and send updated ECHConfig values
  3273. // to the client. The client will then retry to recover, but with a latency
  3274. // penalty. This recovery flow depends on the public name in the ECHConfig.
  3275. // Before advertising an ECHConfig in DNS, deployments must ensure all instances
  3276. // of the service can present a valid certificate for the public name.
  3277. //
  3278. // BoringSSL negotiates ECH before certificate selection callbacks are called,
  3279. // including |SSL_CTX_set_select_certificate_cb|. If ECH is negotiated, the
  3280. // reported |SSL_CLIENT_HELLO| structure and |SSL_get_servername| function will
  3281. // transparently reflect the inner ClientHello. Callers should select parameters
  3282. // based on these values to correctly handle ECH as well as the recovery flow.
  3283. OPENSSL_EXPORT int SSL_CTX_set1_ech_keys(SSL_CTX *ctx, SSL_ECH_KEYS *keys);
  3284. // SSL_ech_accepted returns one if |ssl| negotiated ECH and zero otherwise.
  3285. OPENSSL_EXPORT int SSL_ech_accepted(const SSL *ssl);
  3286. // Alerts.
  3287. //
  3288. // TLS uses alerts to signal error conditions. Alerts have a type (warning or
  3289. // fatal) and description. OpenSSL internally handles fatal alerts with
  3290. // dedicated error codes (see |SSL_AD_REASON_OFFSET|). Except for close_notify,
  3291. // warning alerts are silently ignored and may only be surfaced with
  3292. // |SSL_CTX_set_info_callback|.
  3293. // SSL_AD_REASON_OFFSET is the offset between error reasons and |SSL_AD_*|
  3294. // values. Any error code under |ERR_LIB_SSL| with an error reason above this
  3295. // value corresponds to an alert description. Consumers may add or subtract
  3296. // |SSL_AD_REASON_OFFSET| to convert between them.
  3297. //
  3298. // make_errors.go reserves error codes above 1000 for manually-assigned errors.
  3299. // This value must be kept in sync with reservedReasonCode in make_errors.h
  3300. #define SSL_AD_REASON_OFFSET 1000
  3301. // SSL_AD_* are alert descriptions.
  3302. #define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
  3303. #define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE
  3304. #define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC
  3305. #define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
  3306. #define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
  3307. #define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE
  3308. #define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE
  3309. #define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE // Legacy SSL 3.0 value
  3310. #define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
  3311. #define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
  3312. #define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
  3313. #define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
  3314. #define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
  3315. #define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER
  3316. #define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA
  3317. #define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED
  3318. #define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR
  3319. #define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
  3320. #define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION
  3321. #define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION
  3322. #define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY
  3323. #define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR
  3324. #define SSL_AD_INAPPROPRIATE_FALLBACK SSL3_AD_INAPPROPRIATE_FALLBACK
  3325. #define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
  3326. #define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
  3327. #define SSL_AD_MISSING_EXTENSION TLS1_AD_MISSING_EXTENSION
  3328. #define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION
  3329. #define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
  3330. #define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME
  3331. #define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE \
  3332. TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
  3333. #define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
  3334. #define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY
  3335. #define SSL_AD_CERTIFICATE_REQUIRED TLS1_AD_CERTIFICATE_REQUIRED
  3336. #define SSL_AD_NO_APPLICATION_PROTOCOL TLS1_AD_NO_APPLICATION_PROTOCOL
  3337. #define SSL_AD_ECH_REQUIRED TLS1_AD_ECH_REQUIRED
  3338. // SSL_alert_type_string_long returns a string description of |value| as an
  3339. // alert type (warning or fatal).
  3340. OPENSSL_EXPORT const char *SSL_alert_type_string_long(int value);
  3341. // SSL_alert_desc_string_long returns a string description of |value| as an
  3342. // alert description or "unknown" if unknown.
  3343. OPENSSL_EXPORT const char *SSL_alert_desc_string_long(int value);
  3344. // SSL_send_fatal_alert sends a fatal alert over |ssl| of the specified type,
  3345. // which should be one of the |SSL_AD_*| constants. It returns one on success
  3346. // and <= 0 on error. The caller should pass the return value into
  3347. // |SSL_get_error| to determine how to proceed. Once this function has been
  3348. // called, future calls to |SSL_write| will fail.
  3349. //
  3350. // If retrying a failed operation due to |SSL_ERROR_WANT_WRITE|, subsequent
  3351. // calls must use the same |alert| parameter.
  3352. OPENSSL_EXPORT int SSL_send_fatal_alert(SSL *ssl, uint8_t alert);
  3353. // ex_data functions.
  3354. //
  3355. // See |ex_data.h| for details.
  3356. OPENSSL_EXPORT int SSL_set_ex_data(SSL *ssl, int idx, void *data);
  3357. OPENSSL_EXPORT void *SSL_get_ex_data(const SSL *ssl, int idx);
  3358. OPENSSL_EXPORT int SSL_get_ex_new_index(long argl, void *argp,
  3359. CRYPTO_EX_unused *unused,
  3360. CRYPTO_EX_dup *dup_unused,
  3361. CRYPTO_EX_free *free_func);
  3362. OPENSSL_EXPORT int SSL_SESSION_set_ex_data(SSL_SESSION *session, int idx,
  3363. void *data);
  3364. OPENSSL_EXPORT void *SSL_SESSION_get_ex_data(const SSL_SESSION *session,
  3365. int idx);
  3366. OPENSSL_EXPORT int SSL_SESSION_get_ex_new_index(long argl, void *argp,
  3367. CRYPTO_EX_unused *unused,
  3368. CRYPTO_EX_dup *dup_unused,
  3369. CRYPTO_EX_free *free_func);
  3370. OPENSSL_EXPORT int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *data);
  3371. OPENSSL_EXPORT void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx);
  3372. OPENSSL_EXPORT int SSL_CTX_get_ex_new_index(long argl, void *argp,
  3373. CRYPTO_EX_unused *unused,
  3374. CRYPTO_EX_dup *dup_unused,
  3375. CRYPTO_EX_free *free_func);
  3376. // Low-level record-layer state.
  3377. // SSL_get_ivs sets |*out_iv_len| to the length of the IVs for the ciphers
  3378. // underlying |ssl| and sets |*out_read_iv| and |*out_write_iv| to point to the
  3379. // current IVs for the read and write directions. This is only meaningful for
  3380. // connections with implicit IVs (i.e. CBC mode with TLS 1.0).
  3381. //
  3382. // It returns one on success or zero on error.
  3383. OPENSSL_EXPORT int SSL_get_ivs(const SSL *ssl, const uint8_t **out_read_iv,
  3384. const uint8_t **out_write_iv,
  3385. size_t *out_iv_len);
  3386. // SSL_get_key_block_len returns the length of |ssl|'s key block. It is an error
  3387. // to call this function during a handshake.
  3388. OPENSSL_EXPORT size_t SSL_get_key_block_len(const SSL *ssl);
  3389. // SSL_generate_key_block generates |out_len| bytes of key material for |ssl|'s
  3390. // current connection state. It is an error to call this function during a
  3391. // handshake.
  3392. OPENSSL_EXPORT int SSL_generate_key_block(const SSL *ssl, uint8_t *out,
  3393. size_t out_len);
  3394. // SSL_get_read_sequence returns, in TLS, the expected sequence number of the
  3395. // next incoming record in the current epoch. In DTLS, it returns the maximum
  3396. // sequence number received in the current epoch and includes the epoch number
  3397. // in the two most significant bytes.
  3398. OPENSSL_EXPORT uint64_t SSL_get_read_sequence(const SSL *ssl);
  3399. // SSL_get_write_sequence returns the sequence number of the next outgoing
  3400. // record in the current epoch. In DTLS, it includes the epoch number in the
  3401. // two most significant bytes.
  3402. OPENSSL_EXPORT uint64_t SSL_get_write_sequence(const SSL *ssl);
  3403. // SSL_CTX_set_record_protocol_version returns whether |version| is zero.
  3404. OPENSSL_EXPORT int SSL_CTX_set_record_protocol_version(SSL_CTX *ctx,
  3405. int version);
  3406. // Handshake hints.
  3407. //
  3408. // *** EXPERIMENTAL — DO NOT USE WITHOUT CHECKING ***
  3409. //
  3410. // Some server deployments make asynchronous RPC calls in both ClientHello
  3411. // dispatch and private key operations. In TLS handshakes where the private key
  3412. // operation occurs in the first round-trip, this results in two consecutive RPC
  3413. // round-trips. Handshake hints allow the RPC service to predicte a signature.
  3414. // If correctly predicted, this can skip the second RPC call.
  3415. //
  3416. // First, the server installs a certificate selection callback (see
  3417. // |SSL_CTX_set_select_certificate_cb|). When that is called, it performs the
  3418. // RPC as before, but includes the ClientHello and a capabilities string from
  3419. // |SSL_serialize_capabilities|.
  3420. //
  3421. // Next, the RPC service creates its own |SSL| object, applies the results of
  3422. // certificate selection, calls |SSL_request_handshake_hints|, and runs the
  3423. // handshake. If this successfully computes handshake hints (see
  3424. // |SSL_serialize_handshake_hints|), the RPC server should send the hints
  3425. // alongside any certificate selection results.
  3426. //
  3427. // Finally, the server calls |SSL_set_handshake_hints| and applies any
  3428. // configuration from the RPC server. It then completes the handshake as before.
  3429. // If the hints apply, BoringSSL will use the predicted signature and skip the
  3430. // private key callbacks. Otherwise, BoringSSL will call private key callbacks
  3431. // to generate a signature as before.
  3432. //
  3433. // Callers should synchronize configuration across the two services.
  3434. // Configuration mismatches and some cases of version skew are not fatal, but
  3435. // may result in the hints not applying. Additionally, some handshake flows use
  3436. // the private key in later round-trips, such as TLS 1.3 HelloRetryRequest. In
  3437. // those cases, BoringSSL will not predict a signature as there is no benefit.
  3438. // Callers must allow for handshakes to complete without a predicted signature.
  3439. //
  3440. // For now, only TLS 1.3 is hinted. TLS 1.2 will work, but the hints will be
  3441. // empty.
  3442. // SSL_serialize_capabilities writes an opaque byte string to |out| describing
  3443. // some of |ssl|'s capabilities. It returns one on success and zero on error.
  3444. //
  3445. // This string is used by BoringSSL internally to reduce the impact of version
  3446. // skew.
  3447. OPENSSL_EXPORT int SSL_serialize_capabilities(const SSL *ssl, CBB *out);
  3448. // SSL_request_handshake_hints configures |ssl| to generate a handshake hint for
  3449. // |client_hello|. It returns one on success and zero on error. |client_hello|
  3450. // should contain a serialized ClientHello structure, from the |client_hello|
  3451. // and |client_hello_len| fields of the |SSL_CLIENT_HELLO| structure.
  3452. // |capabilities| should contain the output of |SSL_serialize_capabilities|.
  3453. //
  3454. // When configured, |ssl| will perform no I/O (so there is no need to configure
  3455. // |BIO|s). For QUIC, the caller should still configure an |SSL_QUIC_METHOD|,
  3456. // but the callbacks themselves will never be called and may be left NULL or
  3457. // report failure. |SSL_provide_quic_data| also should not be called.
  3458. //
  3459. // If hint generation is successful, |SSL_do_handshake| will stop the handshake
  3460. // early with |SSL_get_error| returning |SSL_ERROR_HANDSHAKE_HINTS_READY|. At
  3461. // this point, the caller should run |SSL_serialize_handshake_hints| to extract
  3462. // the resulting hints.
  3463. //
  3464. // Hint generation may fail if, e.g., |ssl| was unable to process the
  3465. // ClientHello. Callers should then complete the certificate selection RPC and
  3466. // continue the original handshake with no hint. It will likely fail, but this
  3467. // reports the correct alert to the client and is more robust in case of
  3468. // mismatch.
  3469. OPENSSL_EXPORT int SSL_request_handshake_hints(SSL *ssl,
  3470. const uint8_t *client_hello,
  3471. size_t client_hello_len,
  3472. const uint8_t *capabilities,
  3473. size_t capabilities_len);
  3474. // SSL_serialize_handshake_hints writes an opaque byte string to |out|
  3475. // containing the handshake hints computed by |out|. It returns one on success
  3476. // and zero on error. This function should only be called if
  3477. // |SSL_request_handshake_hints| was configured and the handshake terminated
  3478. // with |SSL_ERROR_HANDSHAKE_HINTS_READY|.
  3479. //
  3480. // This string may be passed to |SSL_set_handshake_hints| on another |SSL| to
  3481. // avoid an extra signature call.
  3482. OPENSSL_EXPORT int SSL_serialize_handshake_hints(const SSL *ssl, CBB *out);
  3483. // SSL_set_handshake_hints configures |ssl| to use |hints| as handshake hints.
  3484. // It returns one on success and zero on error. The handshake will then continue
  3485. // as before, but apply predicted values from |hints| where applicable.
  3486. //
  3487. // Hints may contain connection and session secrets, so they must not leak and
  3488. // must come from a source trusted to terminate the connection. However, they
  3489. // will not change |ssl|'s configuration. The caller is responsible for
  3490. // serializing and applying options from the RPC server as needed. This ensures
  3491. // |ssl|'s behavior is self-consistent and consistent with the caller's local
  3492. // decisions.
  3493. OPENSSL_EXPORT int SSL_set_handshake_hints(SSL *ssl, const uint8_t *hints,
  3494. size_t hints_len);
  3495. // Obscure functions.
  3496. // SSL_CTX_set_msg_callback installs |cb| as the message callback for |ctx|.
  3497. // This callback will be called when sending or receiving low-level record
  3498. // headers, complete handshake messages, ChangeCipherSpec, and alerts.
  3499. // |write_p| is one for outgoing messages and zero for incoming messages.
  3500. //
  3501. // For each record header, |cb| is called with |version| = 0 and |content_type|
  3502. // = |SSL3_RT_HEADER|. The |len| bytes from |buf| contain the header. Note that
  3503. // this does not include the record body. If the record is sealed, the length
  3504. // in the header is the length of the ciphertext.
  3505. //
  3506. // For each handshake message, ChangeCipherSpec, and alert, |version| is the
  3507. // protocol version and |content_type| is the corresponding record type. The
  3508. // |len| bytes from |buf| contain the handshake message, one-byte
  3509. // ChangeCipherSpec body, and two-byte alert, respectively.
  3510. //
  3511. // In connections that enable ECH, |cb| is additionally called with
  3512. // |content_type| = |SSL3_RT_CLIENT_HELLO_INNER| for each ClientHelloInner that
  3513. // is encrypted or decrypted. The |len| bytes from |buf| contain the
  3514. // ClientHelloInner, including the reconstructed outer extensions and handshake
  3515. // header.
  3516. //
  3517. // For a V2ClientHello, |version| is |SSL2_VERSION|, |content_type| is zero, and
  3518. // the |len| bytes from |buf| contain the V2ClientHello structure.
  3519. OPENSSL_EXPORT void SSL_CTX_set_msg_callback(
  3520. SSL_CTX *ctx, void (*cb)(int is_write, int version, int content_type,
  3521. const void *buf, size_t len, SSL *ssl, void *arg));
  3522. // SSL_CTX_set_msg_callback_arg sets the |arg| parameter of the message
  3523. // callback.
  3524. OPENSSL_EXPORT void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
  3525. // SSL_set_msg_callback installs |cb| as the message callback of |ssl|. See
  3526. // |SSL_CTX_set_msg_callback| for when this callback is called.
  3527. OPENSSL_EXPORT void SSL_set_msg_callback(
  3528. SSL *ssl, void (*cb)(int write_p, int version, int content_type,
  3529. const void *buf, size_t len, SSL *ssl, void *arg));
  3530. // SSL_set_msg_callback_arg sets the |arg| parameter of the message callback.
  3531. OPENSSL_EXPORT void SSL_set_msg_callback_arg(SSL *ssl, void *arg);
  3532. // SSL_CTX_set_keylog_callback configures a callback to log key material. This
  3533. // is intended for debugging use with tools like Wireshark. The |cb| function
  3534. // should log |line| followed by a newline, synchronizing with any concurrent
  3535. // access to the log.
  3536. //
  3537. // The format is described in
  3538. // https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
  3539. OPENSSL_EXPORT void SSL_CTX_set_keylog_callback(
  3540. SSL_CTX *ctx, void (*cb)(const SSL *ssl, const char *line));
  3541. // SSL_CTX_get_keylog_callback returns the callback configured by
  3542. // |SSL_CTX_set_keylog_callback|.
  3543. OPENSSL_EXPORT void (*SSL_CTX_get_keylog_callback(const SSL_CTX *ctx))(
  3544. const SSL *ssl, const char *line);
  3545. // SSL_CTX_set_current_time_cb configures a callback to retrieve the current
  3546. // time, which should be set in |*out_clock|. This can be used for testing
  3547. // purposes; for example, a callback can be configured that returns a time
  3548. // set explicitly by the test. The |ssl| pointer passed to |cb| is always null.
  3549. OPENSSL_EXPORT void SSL_CTX_set_current_time_cb(
  3550. SSL_CTX *ctx, void (*cb)(const SSL *ssl, struct timeval *out_clock));
  3551. // SSL_set_shed_handshake_config allows some of the configuration of |ssl| to be
  3552. // freed after its handshake completes. Once configuration has been shed, APIs
  3553. // that query it may fail. "Configuration" in this context means anything that
  3554. // was set by the caller, as distinct from information derived from the
  3555. // handshake. For example, |SSL_get_ciphers| queries how the |SSL| was
  3556. // configured by the caller, and fails after configuration has been shed,
  3557. // whereas |SSL_get_cipher| queries the result of the handshake, and is
  3558. // unaffected by configuration shedding.
  3559. //
  3560. // If configuration shedding is enabled, it is an error to call |SSL_clear|.
  3561. //
  3562. // Note that configuration shedding as a client additionally depends on
  3563. // renegotiation being disabled (see |SSL_set_renegotiate_mode|). If
  3564. // renegotiation is possible, the configuration will be retained. If
  3565. // configuration shedding is enabled and renegotiation later disabled after the
  3566. // handshake, |SSL_set_renegotiate_mode| will shed configuration then. This may
  3567. // be useful for clients which support renegotiation with some ALPN protocols,
  3568. // such as HTTP/1.1, and not others, such as HTTP/2.
  3569. OPENSSL_EXPORT void SSL_set_shed_handshake_config(SSL *ssl, int enable);
  3570. enum ssl_renegotiate_mode_t BORINGSSL_ENUM_INT {
  3571. ssl_renegotiate_never = 0,
  3572. ssl_renegotiate_once,
  3573. ssl_renegotiate_freely,
  3574. ssl_renegotiate_ignore,
  3575. ssl_renegotiate_explicit,
  3576. };
  3577. // SSL_set_renegotiate_mode configures how |ssl|, a client, reacts to
  3578. // renegotiation attempts by a server. If |ssl| is a server, peer-initiated
  3579. // renegotiations are *always* rejected and this function does nothing.
  3580. //
  3581. // The renegotiation mode defaults to |ssl_renegotiate_never|, but may be set
  3582. // at any point in a connection's lifetime. Set it to |ssl_renegotiate_once| to
  3583. // allow one renegotiation, |ssl_renegotiate_freely| to allow all
  3584. // renegotiations or |ssl_renegotiate_ignore| to ignore HelloRequest messages.
  3585. // Note that ignoring HelloRequest messages may cause the connection to stall
  3586. // if the server waits for the renegotiation to complete.
  3587. //
  3588. // If set to |ssl_renegotiate_explicit|, |SSL_read| and |SSL_peek| calls which
  3589. // encounter a HelloRequest will pause with |SSL_ERROR_WANT_RENEGOTIATE|.
  3590. // |SSL_write| will continue to work while paused. The caller may call
  3591. // |SSL_renegotiate| to begin the renegotiation at a later point. This mode may
  3592. // be used if callers wish to eagerly call |SSL_peek| without triggering a
  3593. // renegotiation.
  3594. //
  3595. // If configuration shedding is enabled (see |SSL_set_shed_handshake_config|),
  3596. // configuration is released if, at any point after the handshake, renegotiation
  3597. // is disabled. It is not possible to switch from disabling renegotiation to
  3598. // enabling it on a given connection. Callers that condition renegotiation on,
  3599. // e.g., ALPN must enable renegotiation before the handshake and conditionally
  3600. // disable it afterwards.
  3601. //
  3602. // There is no support in BoringSSL for initiating renegotiations as a client
  3603. // or server.
  3604. OPENSSL_EXPORT void SSL_set_renegotiate_mode(SSL *ssl,
  3605. enum ssl_renegotiate_mode_t mode);
  3606. // SSL_renegotiate starts a deferred renegotiation on |ssl| if it was configured
  3607. // with |ssl_renegotiate_explicit| and has a pending HelloRequest. It returns
  3608. // one on success and zero on error.
  3609. //
  3610. // This function does not do perform any I/O. On success, a subsequent
  3611. // |SSL_do_handshake| call will run the handshake. |SSL_write| and
  3612. // |SSL_read| will also complete the handshake before sending or receiving
  3613. // application data.
  3614. OPENSSL_EXPORT int SSL_renegotiate(SSL *ssl);
  3615. // SSL_renegotiate_pending returns one if |ssl| is in the middle of a
  3616. // renegotiation.
  3617. OPENSSL_EXPORT int SSL_renegotiate_pending(SSL *ssl);
  3618. // SSL_total_renegotiations returns the total number of renegotiation handshakes
  3619. // performed by |ssl|. This includes the pending renegotiation, if any.
  3620. OPENSSL_EXPORT int SSL_total_renegotiations(const SSL *ssl);
  3621. // SSL_MAX_CERT_LIST_DEFAULT is the default maximum length, in bytes, of a peer
  3622. // certificate chain.
  3623. #define SSL_MAX_CERT_LIST_DEFAULT (1024 * 100)
  3624. // SSL_CTX_get_max_cert_list returns the maximum length, in bytes, of a peer
  3625. // certificate chain accepted by |ctx|.
  3626. OPENSSL_EXPORT size_t SSL_CTX_get_max_cert_list(const SSL_CTX *ctx);
  3627. // SSL_CTX_set_max_cert_list sets the maximum length, in bytes, of a peer
  3628. // certificate chain to |max_cert_list|. This affects how much memory may be
  3629. // consumed during the handshake.
  3630. OPENSSL_EXPORT void SSL_CTX_set_max_cert_list(SSL_CTX *ctx,
  3631. size_t max_cert_list);
  3632. // SSL_get_max_cert_list returns the maximum length, in bytes, of a peer
  3633. // certificate chain accepted by |ssl|.
  3634. OPENSSL_EXPORT size_t SSL_get_max_cert_list(const SSL *ssl);
  3635. // SSL_set_max_cert_list sets the maximum length, in bytes, of a peer
  3636. // certificate chain to |max_cert_list|. This affects how much memory may be
  3637. // consumed during the handshake.
  3638. OPENSSL_EXPORT void SSL_set_max_cert_list(SSL *ssl, size_t max_cert_list);
  3639. // SSL_CTX_set_max_send_fragment sets the maximum length, in bytes, of records
  3640. // sent by |ctx|. Beyond this length, handshake messages and application data
  3641. // will be split into multiple records. It returns one on success or zero on
  3642. // error.
  3643. OPENSSL_EXPORT int SSL_CTX_set_max_send_fragment(SSL_CTX *ctx,
  3644. size_t max_send_fragment);
  3645. // SSL_set_max_send_fragment sets the maximum length, in bytes, of records sent
  3646. // by |ssl|. Beyond this length, handshake messages and application data will
  3647. // be split into multiple records. It returns one on success or zero on
  3648. // error.
  3649. OPENSSL_EXPORT int SSL_set_max_send_fragment(SSL *ssl,
  3650. size_t max_send_fragment);
  3651. // ssl_early_callback_ctx (aka |SSL_CLIENT_HELLO|) is passed to certain
  3652. // callbacks that are called very early on during the server handshake. At this
  3653. // point, much of the SSL* hasn't been filled out and only the ClientHello can
  3654. // be depended on.
  3655. struct ssl_early_callback_ctx {
  3656. SSL *ssl;
  3657. const uint8_t *client_hello;
  3658. size_t client_hello_len;
  3659. uint16_t version;
  3660. const uint8_t *random;
  3661. size_t random_len;
  3662. const uint8_t *session_id;
  3663. size_t session_id_len;
  3664. const uint8_t *cipher_suites;
  3665. size_t cipher_suites_len;
  3666. const uint8_t *compression_methods;
  3667. size_t compression_methods_len;
  3668. const uint8_t *extensions;
  3669. size_t extensions_len;
  3670. } /* SSL_CLIENT_HELLO */;
  3671. // ssl_select_cert_result_t enumerates the possible results from selecting a
  3672. // certificate with |select_certificate_cb|.
  3673. enum ssl_select_cert_result_t BORINGSSL_ENUM_INT {
  3674. // ssl_select_cert_success indicates that the certificate selection was
  3675. // successful.
  3676. ssl_select_cert_success = 1,
  3677. // ssl_select_cert_retry indicates that the operation could not be
  3678. // immediately completed and must be reattempted at a later point.
  3679. ssl_select_cert_retry = 0,
  3680. // ssl_select_cert_error indicates that a fatal error occured and the
  3681. // handshake should be terminated.
  3682. ssl_select_cert_error = -1,
  3683. };
  3684. // SSL_early_callback_ctx_extension_get searches the extensions in
  3685. // |client_hello| for an extension of the given type. If not found, it returns
  3686. // zero. Otherwise it sets |out_data| to point to the extension contents (not
  3687. // including the type and length bytes), sets |out_len| to the length of the
  3688. // extension contents and returns one.
  3689. OPENSSL_EXPORT int SSL_early_callback_ctx_extension_get(
  3690. const SSL_CLIENT_HELLO *client_hello, uint16_t extension_type,
  3691. const uint8_t **out_data, size_t *out_len);
  3692. // SSL_CTX_set_select_certificate_cb sets a callback that is called before most
  3693. // ClientHello processing and before the decision whether to resume a session
  3694. // is made. The callback may inspect the ClientHello and configure the
  3695. // connection. See |ssl_select_cert_result_t| for details of the return values.
  3696. //
  3697. // In the case that a retry is indicated, |SSL_get_error| will return
  3698. // |SSL_ERROR_PENDING_CERTIFICATE| and the caller should arrange for the
  3699. // high-level operation on |ssl| to be retried at a later time, which will
  3700. // result in another call to |cb|.
  3701. //
  3702. // |SSL_get_servername| may be used during this callback.
  3703. //
  3704. // Note: The |SSL_CLIENT_HELLO| is only valid for the duration of the callback
  3705. // and is not valid while the handshake is paused.
  3706. OPENSSL_EXPORT void SSL_CTX_set_select_certificate_cb(
  3707. SSL_CTX *ctx,
  3708. enum ssl_select_cert_result_t (*cb)(const SSL_CLIENT_HELLO *));
  3709. // SSL_CTX_set_dos_protection_cb sets a callback that is called once the
  3710. // resumption decision for a ClientHello has been made. It can return one to
  3711. // allow the handshake to continue or zero to cause the handshake to abort.
  3712. OPENSSL_EXPORT void SSL_CTX_set_dos_protection_cb(
  3713. SSL_CTX *ctx, int (*cb)(const SSL_CLIENT_HELLO *));
  3714. // SSL_CTX_set_reverify_on_resume configures whether the certificate
  3715. // verification callback will be used to reverify stored certificates
  3716. // when resuming a session. This only works with |SSL_CTX_set_custom_verify|.
  3717. // For now, this is incompatible with |SSL_VERIFY_NONE| mode, and is only
  3718. // respected on clients.
  3719. OPENSSL_EXPORT void SSL_CTX_set_reverify_on_resume(SSL_CTX *ctx, int enabled);
  3720. // SSL_set_enforce_rsa_key_usage configures whether the keyUsage extension of
  3721. // RSA leaf certificates will be checked for consistency with the TLS
  3722. // usage. This parameter may be set late; it will not be read until after the
  3723. // certificate verification callback.
  3724. OPENSSL_EXPORT void SSL_set_enforce_rsa_key_usage(SSL *ssl, int enabled);
  3725. // SSL_ST_* are possible values for |SSL_state|, the bitmasks that make them up,
  3726. // and some historical values for compatibility. Only |SSL_ST_INIT| and
  3727. // |SSL_ST_OK| are ever returned.
  3728. #define SSL_ST_CONNECT 0x1000
  3729. #define SSL_ST_ACCEPT 0x2000
  3730. #define SSL_ST_MASK 0x0FFF
  3731. #define SSL_ST_INIT (SSL_ST_CONNECT | SSL_ST_ACCEPT)
  3732. #define SSL_ST_OK 0x03
  3733. #define SSL_ST_RENEGOTIATE (0x04 | SSL_ST_INIT)
  3734. #define SSL_ST_BEFORE (0x05 | SSL_ST_INIT)
  3735. // TLS_ST_* are aliases for |SSL_ST_*| for OpenSSL 1.1.0 compatibility.
  3736. #define TLS_ST_OK SSL_ST_OK
  3737. #define TLS_ST_BEFORE SSL_ST_BEFORE
  3738. // SSL_CB_* are possible values for the |type| parameter in the info
  3739. // callback and the bitmasks that make them up.
  3740. #define SSL_CB_LOOP 0x01
  3741. #define SSL_CB_EXIT 0x02
  3742. #define SSL_CB_READ 0x04
  3743. #define SSL_CB_WRITE 0x08
  3744. #define SSL_CB_ALERT 0x4000
  3745. #define SSL_CB_READ_ALERT (SSL_CB_ALERT | SSL_CB_READ)
  3746. #define SSL_CB_WRITE_ALERT (SSL_CB_ALERT | SSL_CB_WRITE)
  3747. #define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT | SSL_CB_LOOP)
  3748. #define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT | SSL_CB_EXIT)
  3749. #define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT | SSL_CB_LOOP)
  3750. #define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT | SSL_CB_EXIT)
  3751. #define SSL_CB_HANDSHAKE_START 0x10
  3752. #define SSL_CB_HANDSHAKE_DONE 0x20
  3753. // SSL_CTX_set_info_callback configures a callback to be run when various
  3754. // events occur during a connection's lifetime. The |type| argument determines
  3755. // the type of event and the meaning of the |value| argument. Callbacks must
  3756. // ignore unexpected |type| values.
  3757. //
  3758. // |SSL_CB_READ_ALERT| is signaled for each alert received, warning or fatal.
  3759. // The |value| argument is a 16-bit value where the alert level (either
  3760. // |SSL3_AL_WARNING| or |SSL3_AL_FATAL|) is in the most-significant eight bits
  3761. // and the alert type (one of |SSL_AD_*|) is in the least-significant eight.
  3762. //
  3763. // |SSL_CB_WRITE_ALERT| is signaled for each alert sent. The |value| argument
  3764. // is constructed as with |SSL_CB_READ_ALERT|.
  3765. //
  3766. // |SSL_CB_HANDSHAKE_START| is signaled when a handshake begins. The |value|
  3767. // argument is always one.
  3768. //
  3769. // |SSL_CB_HANDSHAKE_DONE| is signaled when a handshake completes successfully.
  3770. // The |value| argument is always one. If a handshake False Starts, this event
  3771. // may be used to determine when the Finished message is received.
  3772. //
  3773. // The following event types expose implementation details of the handshake
  3774. // state machine. Consuming them is deprecated.
  3775. //
  3776. // |SSL_CB_ACCEPT_LOOP| (respectively, |SSL_CB_CONNECT_LOOP|) is signaled when
  3777. // a server (respectively, client) handshake progresses. The |value| argument
  3778. // is always one.
  3779. //
  3780. // |SSL_CB_ACCEPT_EXIT| (respectively, |SSL_CB_CONNECT_EXIT|) is signaled when
  3781. // a server (respectively, client) handshake completes, fails, or is paused.
  3782. // The |value| argument is one if the handshake succeeded and <= 0
  3783. // otherwise.
  3784. OPENSSL_EXPORT void SSL_CTX_set_info_callback(
  3785. SSL_CTX *ctx, void (*cb)(const SSL *ssl, int type, int value));
  3786. // SSL_CTX_get_info_callback returns the callback set by
  3787. // |SSL_CTX_set_info_callback|.
  3788. OPENSSL_EXPORT void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl,
  3789. int type,
  3790. int value);
  3791. // SSL_set_info_callback configures a callback to be run at various events
  3792. // during a connection's lifetime. See |SSL_CTX_set_info_callback|.
  3793. OPENSSL_EXPORT void SSL_set_info_callback(
  3794. SSL *ssl, void (*cb)(const SSL *ssl, int type, int value));
  3795. // SSL_get_info_callback returns the callback set by |SSL_set_info_callback|.
  3796. OPENSSL_EXPORT void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,
  3797. int type,
  3798. int value);
  3799. // SSL_state_string_long returns the current state of the handshake state
  3800. // machine as a string. This may be useful for debugging and logging.
  3801. OPENSSL_EXPORT const char *SSL_state_string_long(const SSL *ssl);
  3802. #define SSL_SENT_SHUTDOWN 1
  3803. #define SSL_RECEIVED_SHUTDOWN 2
  3804. // SSL_get_shutdown returns a bitmask with a subset of |SSL_SENT_SHUTDOWN| and
  3805. // |SSL_RECEIVED_SHUTDOWN| to query whether close_notify was sent or received,
  3806. // respectively.
  3807. OPENSSL_EXPORT int SSL_get_shutdown(const SSL *ssl);
  3808. // SSL_get_peer_signature_algorithm returns the signature algorithm used by the
  3809. // peer. If not applicable, it returns zero.
  3810. OPENSSL_EXPORT uint16_t SSL_get_peer_signature_algorithm(const SSL *ssl);
  3811. // SSL_get_client_random writes up to |max_out| bytes of the most recent
  3812. // handshake's client_random to |out| and returns the number of bytes written.
  3813. // If |max_out| is zero, it returns the size of the client_random.
  3814. OPENSSL_EXPORT size_t SSL_get_client_random(const SSL *ssl, uint8_t *out,
  3815. size_t max_out);
  3816. // SSL_get_server_random writes up to |max_out| bytes of the most recent
  3817. // handshake's server_random to |out| and returns the number of bytes written.
  3818. // If |max_out| is zero, it returns the size of the server_random.
  3819. OPENSSL_EXPORT size_t SSL_get_server_random(const SSL *ssl, uint8_t *out,
  3820. size_t max_out);
  3821. // SSL_get_pending_cipher returns the cipher suite for the current handshake or
  3822. // NULL if one has not been negotiated yet or there is no pending handshake.
  3823. OPENSSL_EXPORT const SSL_CIPHER *SSL_get_pending_cipher(const SSL *ssl);
  3824. // SSL_set_retain_only_sha256_of_client_certs, on a server, sets whether only
  3825. // the SHA-256 hash of peer's certificate should be saved in memory and in the
  3826. // session. This can save memory, ticket size and session cache space. If
  3827. // enabled, |SSL_get_peer_certificate| will return NULL after the handshake
  3828. // completes. See |SSL_SESSION_has_peer_sha256| and
  3829. // |SSL_SESSION_get0_peer_sha256| to query the hash.
  3830. OPENSSL_EXPORT void SSL_set_retain_only_sha256_of_client_certs(SSL *ssl,
  3831. int enable);
  3832. // SSL_CTX_set_retain_only_sha256_of_client_certs, on a server, sets whether
  3833. // only the SHA-256 hash of peer's certificate should be saved in memory and in
  3834. // the session. This can save memory, ticket size and session cache space. If
  3835. // enabled, |SSL_get_peer_certificate| will return NULL after the handshake
  3836. // completes. See |SSL_SESSION_has_peer_sha256| and
  3837. // |SSL_SESSION_get0_peer_sha256| to query the hash.
  3838. OPENSSL_EXPORT void SSL_CTX_set_retain_only_sha256_of_client_certs(SSL_CTX *ctx,
  3839. int enable);
  3840. // SSL_CTX_set_grease_enabled configures whether sockets on |ctx| should enable
  3841. // GREASE. See RFC 8701.
  3842. OPENSSL_EXPORT void SSL_CTX_set_grease_enabled(SSL_CTX *ctx, int enabled);
  3843. // SSL_CTX_set_permute_extensions configures whether sockets on |ctx| should
  3844. // permute extensions. For now, this is only implemented for the ClientHello.
  3845. OPENSSL_EXPORT void SSL_CTX_set_permute_extensions(SSL_CTX *ctx, int enabled);
  3846. // SSL_set_permute_extensions configures whether sockets on |ssl| should
  3847. // permute extensions. For now, this is only implemented for the ClientHello.
  3848. OPENSSL_EXPORT void SSL_set_permute_extensions(SSL *ssl, int enabled);
  3849. // SSL_max_seal_overhead returns the maximum overhead, in bytes, of sealing a
  3850. // record with |ssl|.
  3851. OPENSSL_EXPORT size_t SSL_max_seal_overhead(const SSL *ssl);
  3852. // SSL_CTX_set_false_start_allowed_without_alpn configures whether connections
  3853. // on |ctx| may use False Start (if |SSL_MODE_ENABLE_FALSE_START| is enabled)
  3854. // without negotiating ALPN.
  3855. OPENSSL_EXPORT void SSL_CTX_set_false_start_allowed_without_alpn(SSL_CTX *ctx,
  3856. int allowed);
  3857. // SSL_used_hello_retry_request returns one if the TLS 1.3 HelloRetryRequest
  3858. // message has been either sent by the server or received by the client. It
  3859. // returns zero otherwise.
  3860. OPENSSL_EXPORT int SSL_used_hello_retry_request(const SSL *ssl);
  3861. // SSL_set_jdk11_workaround configures whether to workaround various bugs in
  3862. // JDK 11's TLS 1.3 implementation by disabling TLS 1.3 for such clients.
  3863. //
  3864. // https://bugs.openjdk.java.net/browse/JDK-8211806
  3865. // https://bugs.openjdk.java.net/browse/JDK-8212885
  3866. // https://bugs.openjdk.java.net/browse/JDK-8213202
  3867. OPENSSL_EXPORT void SSL_set_jdk11_workaround(SSL *ssl, int enable);
  3868. // Deprecated functions.
  3869. // SSL_library_init calls |CRYPTO_library_init| and returns one.
  3870. OPENSSL_EXPORT int SSL_library_init(void);
  3871. // SSL_CIPHER_description writes a description of |cipher| into |buf| and
  3872. // returns |buf|. If |buf| is NULL, it returns a newly allocated string, to be
  3873. // freed with |OPENSSL_free|, or NULL on error.
  3874. //
  3875. // The description includes a trailing newline and has the form:
  3876. // AES128-SHA Kx=RSA Au=RSA Enc=AES(128) Mac=SHA1
  3877. //
  3878. // Consider |SSL_CIPHER_standard_name| or |SSL_CIPHER_get_name| instead.
  3879. OPENSSL_EXPORT const char *SSL_CIPHER_description(const SSL_CIPHER *cipher,
  3880. char *buf, int len);
  3881. // SSL_CIPHER_get_version returns the string "TLSv1/SSLv3".
  3882. OPENSSL_EXPORT const char *SSL_CIPHER_get_version(const SSL_CIPHER *cipher);
  3883. // SSL_CIPHER_get_rfc_name returns a newly-allocated string containing the
  3884. // result of |SSL_CIPHER_standard_name| or NULL on error. The caller is
  3885. // responsible for calling |OPENSSL_free| on the result.
  3886. //
  3887. // Use |SSL_CIPHER_standard_name| instead.
  3888. OPENSSL_EXPORT char *SSL_CIPHER_get_rfc_name(const SSL_CIPHER *cipher);
  3889. typedef void COMP_METHOD;
  3890. typedef struct ssl_comp_st SSL_COMP;
  3891. // SSL_COMP_get_compression_methods returns NULL.
  3892. OPENSSL_EXPORT STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
  3893. // SSL_COMP_add_compression_method returns one.
  3894. OPENSSL_EXPORT int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);
  3895. // SSL_COMP_get_name returns NULL.
  3896. OPENSSL_EXPORT const char *SSL_COMP_get_name(const COMP_METHOD *comp);
  3897. // SSL_COMP_get0_name returns the |name| member of |comp|.
  3898. OPENSSL_EXPORT const char *SSL_COMP_get0_name(const SSL_COMP *comp);
  3899. // SSL_COMP_get_id returns the |id| member of |comp|.
  3900. OPENSSL_EXPORT int SSL_COMP_get_id(const SSL_COMP *comp);
  3901. // SSL_COMP_free_compression_methods does nothing.
  3902. OPENSSL_EXPORT void SSL_COMP_free_compression_methods(void);
  3903. // SSLv23_method calls |TLS_method|.
  3904. OPENSSL_EXPORT const SSL_METHOD *SSLv23_method(void);
  3905. // These version-specific methods behave exactly like |TLS_method| and
  3906. // |DTLS_method| except they also call |SSL_CTX_set_min_proto_version| and
  3907. // |SSL_CTX_set_max_proto_version| to lock connections to that protocol
  3908. // version.
  3909. OPENSSL_EXPORT const SSL_METHOD *TLSv1_method(void);
  3910. OPENSSL_EXPORT const SSL_METHOD *TLSv1_1_method(void);
  3911. OPENSSL_EXPORT const SSL_METHOD *TLSv1_2_method(void);
  3912. OPENSSL_EXPORT const SSL_METHOD *DTLSv1_method(void);
  3913. OPENSSL_EXPORT const SSL_METHOD *DTLSv1_2_method(void);
  3914. // These client- and server-specific methods call their corresponding generic
  3915. // methods.
  3916. OPENSSL_EXPORT const SSL_METHOD *TLS_server_method(void);
  3917. OPENSSL_EXPORT const SSL_METHOD *TLS_client_method(void);
  3918. OPENSSL_EXPORT const SSL_METHOD *SSLv23_server_method(void);
  3919. OPENSSL_EXPORT const SSL_METHOD *SSLv23_client_method(void);
  3920. OPENSSL_EXPORT const SSL_METHOD *TLSv1_server_method(void);
  3921. OPENSSL_EXPORT const SSL_METHOD *TLSv1_client_method(void);
  3922. OPENSSL_EXPORT const SSL_METHOD *TLSv1_1_server_method(void);
  3923. OPENSSL_EXPORT const SSL_METHOD *TLSv1_1_client_method(void);
  3924. OPENSSL_EXPORT const SSL_METHOD *TLSv1_2_server_method(void);
  3925. OPENSSL_EXPORT const SSL_METHOD *TLSv1_2_client_method(void);
  3926. OPENSSL_EXPORT const SSL_METHOD *DTLS_server_method(void);
  3927. OPENSSL_EXPORT const SSL_METHOD *DTLS_client_method(void);
  3928. OPENSSL_EXPORT const SSL_METHOD *DTLSv1_server_method(void);
  3929. OPENSSL_EXPORT const SSL_METHOD *DTLSv1_client_method(void);
  3930. OPENSSL_EXPORT const SSL_METHOD *DTLSv1_2_server_method(void);
  3931. OPENSSL_EXPORT const SSL_METHOD *DTLSv1_2_client_method(void);
  3932. // SSL_clear resets |ssl| to allow another connection and returns one on success
  3933. // or zero on failure. It returns most configuration state but releases memory
  3934. // associated with the current connection.
  3935. //
  3936. // Free |ssl| and create a new one instead.
  3937. OPENSSL_EXPORT int SSL_clear(SSL *ssl);
  3938. // SSL_CTX_set_tmp_rsa_callback does nothing.
  3939. OPENSSL_EXPORT void SSL_CTX_set_tmp_rsa_callback(
  3940. SSL_CTX *ctx, RSA *(*cb)(SSL *ssl, int is_export, int keylength));
  3941. // SSL_set_tmp_rsa_callback does nothing.
  3942. OPENSSL_EXPORT void SSL_set_tmp_rsa_callback(SSL *ssl,
  3943. RSA *(*cb)(SSL *ssl, int is_export,
  3944. int keylength));
  3945. // SSL_CTX_sess_connect returns zero.
  3946. OPENSSL_EXPORT int SSL_CTX_sess_connect(const SSL_CTX *ctx);
  3947. // SSL_CTX_sess_connect_good returns zero.
  3948. OPENSSL_EXPORT int SSL_CTX_sess_connect_good(const SSL_CTX *ctx);
  3949. // SSL_CTX_sess_connect_renegotiate returns zero.
  3950. OPENSSL_EXPORT int SSL_CTX_sess_connect_renegotiate(const SSL_CTX *ctx);
  3951. // SSL_CTX_sess_accept returns zero.
  3952. OPENSSL_EXPORT int SSL_CTX_sess_accept(const SSL_CTX *ctx);
  3953. // SSL_CTX_sess_accept_renegotiate returns zero.
  3954. OPENSSL_EXPORT int SSL_CTX_sess_accept_renegotiate(const SSL_CTX *ctx);
  3955. // SSL_CTX_sess_accept_good returns zero.
  3956. OPENSSL_EXPORT int SSL_CTX_sess_accept_good(const SSL_CTX *ctx);
  3957. // SSL_CTX_sess_hits returns zero.
  3958. OPENSSL_EXPORT int SSL_CTX_sess_hits(const SSL_CTX *ctx);
  3959. // SSL_CTX_sess_cb_hits returns zero.
  3960. OPENSSL_EXPORT int SSL_CTX_sess_cb_hits(const SSL_CTX *ctx);
  3961. // SSL_CTX_sess_misses returns zero.
  3962. OPENSSL_EXPORT int SSL_CTX_sess_misses(const SSL_CTX *ctx);
  3963. // SSL_CTX_sess_timeouts returns zero.
  3964. OPENSSL_EXPORT int SSL_CTX_sess_timeouts(const SSL_CTX *ctx);
  3965. // SSL_CTX_sess_cache_full returns zero.
  3966. OPENSSL_EXPORT int SSL_CTX_sess_cache_full(const SSL_CTX *ctx);
  3967. // SSL_cutthrough_complete calls |SSL_in_false_start|.
  3968. OPENSSL_EXPORT int SSL_cutthrough_complete(const SSL *ssl);
  3969. // SSL_num_renegotiations calls |SSL_total_renegotiations|.
  3970. OPENSSL_EXPORT int SSL_num_renegotiations(const SSL *ssl);
  3971. // SSL_CTX_need_tmp_RSA returns zero.
  3972. OPENSSL_EXPORT int SSL_CTX_need_tmp_RSA(const SSL_CTX *ctx);
  3973. // SSL_need_tmp_RSA returns zero.
  3974. OPENSSL_EXPORT int SSL_need_tmp_RSA(const SSL *ssl);
  3975. // SSL_CTX_set_tmp_rsa returns one.
  3976. OPENSSL_EXPORT int SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, const RSA *rsa);
  3977. // SSL_set_tmp_rsa returns one.
  3978. OPENSSL_EXPORT int SSL_set_tmp_rsa(SSL *ssl, const RSA *rsa);
  3979. // SSL_CTX_get_read_ahead returns zero.
  3980. OPENSSL_EXPORT int SSL_CTX_get_read_ahead(const SSL_CTX *ctx);
  3981. // SSL_CTX_set_read_ahead returns one.
  3982. OPENSSL_EXPORT int SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes);
  3983. // SSL_get_read_ahead returns zero.
  3984. OPENSSL_EXPORT int SSL_get_read_ahead(const SSL *ssl);
  3985. // SSL_set_read_ahead returns one.
  3986. OPENSSL_EXPORT int SSL_set_read_ahead(SSL *ssl, int yes);
  3987. // SSL_set_state does nothing.
  3988. OPENSSL_EXPORT void SSL_set_state(SSL *ssl, int state);
  3989. // SSL_get_shared_ciphers writes an empty string to |buf| and returns a
  3990. // pointer to |buf|, or NULL if |len| is less than or equal to zero.
  3991. OPENSSL_EXPORT char *SSL_get_shared_ciphers(const SSL *ssl, char *buf, int len);
  3992. // SSL_get_shared_sigalgs returns zero.
  3993. OPENSSL_EXPORT int SSL_get_shared_sigalgs(SSL *ssl, int idx, int *psign,
  3994. int *phash, int *psignandhash,
  3995. uint8_t *rsig, uint8_t *rhash);
  3996. // SSL_MODE_HANDSHAKE_CUTTHROUGH is the same as SSL_MODE_ENABLE_FALSE_START.
  3997. #define SSL_MODE_HANDSHAKE_CUTTHROUGH SSL_MODE_ENABLE_FALSE_START
  3998. // i2d_SSL_SESSION serializes |in|, as described in |i2d_SAMPLE|.
  3999. //
  4000. // Use |SSL_SESSION_to_bytes| instead.
  4001. OPENSSL_EXPORT int i2d_SSL_SESSION(SSL_SESSION *in, uint8_t **pp);
  4002. // d2i_SSL_SESSION parses a serialized session from the |length| bytes pointed
  4003. // to by |*pp|, as described in |d2i_SAMPLE|.
  4004. //
  4005. // Use |SSL_SESSION_from_bytes| instead.
  4006. OPENSSL_EXPORT SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const uint8_t **pp,
  4007. long length);
  4008. // i2d_SSL_SESSION_bio serializes |session| and writes the result to |bio|. It
  4009. // returns the number of bytes written on success and <= 0 on error.
  4010. OPENSSL_EXPORT int i2d_SSL_SESSION_bio(BIO *bio, const SSL_SESSION *session);
  4011. // d2i_SSL_SESSION_bio reads a serialized |SSL_SESSION| from |bio| and returns a
  4012. // newly-allocated |SSL_SESSION| or NULL on error. If |out| is not NULL, it also
  4013. // frees |*out| and sets |*out| to the new |SSL_SESSION|.
  4014. OPENSSL_EXPORT SSL_SESSION *d2i_SSL_SESSION_bio(BIO *bio, SSL_SESSION **out);
  4015. // ERR_load_SSL_strings does nothing.
  4016. OPENSSL_EXPORT void ERR_load_SSL_strings(void);
  4017. // SSL_load_error_strings does nothing.
  4018. OPENSSL_EXPORT void SSL_load_error_strings(void);
  4019. // SSL_CTX_set_tlsext_use_srtp calls |SSL_CTX_set_srtp_profiles|. It returns
  4020. // zero on success and one on failure.
  4021. //
  4022. // WARNING: this function is dangerous because it breaks the usual return value
  4023. // convention. Use |SSL_CTX_set_srtp_profiles| instead.
  4024. OPENSSL_EXPORT int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx,
  4025. const char *profiles);
  4026. // SSL_set_tlsext_use_srtp calls |SSL_set_srtp_profiles|. It returns zero on
  4027. // success and one on failure.
  4028. //
  4029. // WARNING: this function is dangerous because it breaks the usual return value
  4030. // convention. Use |SSL_set_srtp_profiles| instead.
  4031. OPENSSL_EXPORT int SSL_set_tlsext_use_srtp(SSL *ssl, const char *profiles);
  4032. // SSL_get_current_compression returns NULL.
  4033. OPENSSL_EXPORT const COMP_METHOD *SSL_get_current_compression(SSL *ssl);
  4034. // SSL_get_current_expansion returns NULL.
  4035. OPENSSL_EXPORT const COMP_METHOD *SSL_get_current_expansion(SSL *ssl);
  4036. // SSL_get_server_tmp_key returns zero.
  4037. OPENSSL_EXPORT int SSL_get_server_tmp_key(SSL *ssl, EVP_PKEY **out_key);
  4038. // SSL_CTX_set_tmp_dh returns 1.
  4039. OPENSSL_EXPORT int SSL_CTX_set_tmp_dh(SSL_CTX *ctx, const DH *dh);
  4040. // SSL_set_tmp_dh returns 1.
  4041. OPENSSL_EXPORT int SSL_set_tmp_dh(SSL *ssl, const DH *dh);
  4042. // SSL_CTX_set_tmp_dh_callback does nothing.
  4043. OPENSSL_EXPORT void SSL_CTX_set_tmp_dh_callback(
  4044. SSL_CTX *ctx, DH *(*cb)(SSL *ssl, int is_export, int keylength));
  4045. // SSL_set_tmp_dh_callback does nothing.
  4046. OPENSSL_EXPORT void SSL_set_tmp_dh_callback(SSL *ssl,
  4047. DH *(*cb)(SSL *ssl, int is_export,
  4048. int keylength));
  4049. // SSL_CTX_set1_sigalgs takes |num_values| ints and interprets them as pairs
  4050. // where the first is the nid of a hash function and the second is an
  4051. // |EVP_PKEY_*| value. It configures the signature algorithm preferences for
  4052. // |ctx| based on them and returns one on success or zero on error.
  4053. //
  4054. // This API is compatible with OpenSSL. However, BoringSSL-specific code should
  4055. // prefer |SSL_CTX_set_signing_algorithm_prefs| because it's clearer and it's
  4056. // more convenient to codesearch for specific algorithm values.
  4057. OPENSSL_EXPORT int SSL_CTX_set1_sigalgs(SSL_CTX *ctx, const int *values,
  4058. size_t num_values);
  4059. // SSL_set1_sigalgs takes |num_values| ints and interprets them as pairs where
  4060. // the first is the nid of a hash function and the second is an |EVP_PKEY_*|
  4061. // value. It configures the signature algorithm preferences for |ssl| based on
  4062. // them and returns one on success or zero on error.
  4063. //
  4064. // This API is compatible with OpenSSL. However, BoringSSL-specific code should
  4065. // prefer |SSL_CTX_set_signing_algorithm_prefs| because it's clearer and it's
  4066. // more convenient to codesearch for specific algorithm values.
  4067. OPENSSL_EXPORT int SSL_set1_sigalgs(SSL *ssl, const int *values,
  4068. size_t num_values);
  4069. // SSL_CTX_set1_sigalgs_list takes a textual specification of a set of signature
  4070. // algorithms and configures them on |ctx|. It returns one on success and zero
  4071. // on error. See
  4072. // https://www.openssl.org/docs/man1.1.0/man3/SSL_CTX_set1_sigalgs_list.html for
  4073. // a description of the text format. Also note that TLS 1.3 names (e.g.
  4074. // "rsa_pkcs1_md5_sha1") can also be used (as in OpenSSL, although OpenSSL
  4075. // doesn't document that).
  4076. //
  4077. // This API is compatible with OpenSSL. However, BoringSSL-specific code should
  4078. // prefer |SSL_CTX_set_signing_algorithm_prefs| because it's clearer and it's
  4079. // more convenient to codesearch for specific algorithm values.
  4080. OPENSSL_EXPORT int SSL_CTX_set1_sigalgs_list(SSL_CTX *ctx, const char *str);
  4081. // SSL_set1_sigalgs_list takes a textual specification of a set of signature
  4082. // algorithms and configures them on |ssl|. It returns one on success and zero
  4083. // on error. See
  4084. // https://www.openssl.org/docs/man1.1.0/man3/SSL_CTX_set1_sigalgs_list.html for
  4085. // a description of the text format. Also note that TLS 1.3 names (e.g.
  4086. // "rsa_pkcs1_md5_sha1") can also be used (as in OpenSSL, although OpenSSL
  4087. // doesn't document that).
  4088. //
  4089. // This API is compatible with OpenSSL. However, BoringSSL-specific code should
  4090. // prefer |SSL_CTX_set_signing_algorithm_prefs| because it's clearer and it's
  4091. // more convenient to codesearch for specific algorithm values.
  4092. OPENSSL_EXPORT int SSL_set1_sigalgs_list(SSL *ssl, const char *str);
  4093. #define SSL_set_app_data(s, arg) (SSL_set_ex_data(s, 0, (char *)(arg)))
  4094. #define SSL_get_app_data(s) (SSL_get_ex_data(s, 0))
  4095. #define SSL_SESSION_set_app_data(s, a) \
  4096. (SSL_SESSION_set_ex_data(s, 0, (char *)(a)))
  4097. #define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s, 0))
  4098. #define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx, 0))
  4099. #define SSL_CTX_set_app_data(ctx, arg) \
  4100. (SSL_CTX_set_ex_data(ctx, 0, (char *)(arg)))
  4101. #define OpenSSL_add_ssl_algorithms() SSL_library_init()
  4102. #define SSLeay_add_ssl_algorithms() SSL_library_init()
  4103. #define SSL_get_cipher(ssl) SSL_CIPHER_get_name(SSL_get_current_cipher(ssl))
  4104. #define SSL_get_cipher_bits(ssl, out_alg_bits) \
  4105. SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), out_alg_bits)
  4106. #define SSL_get_cipher_version(ssl) \
  4107. SSL_CIPHER_get_version(SSL_get_current_cipher(ssl))
  4108. #define SSL_get_cipher_name(ssl) \
  4109. SSL_CIPHER_get_name(SSL_get_current_cipher(ssl))
  4110. #define SSL_get_time(session) SSL_SESSION_get_time(session)
  4111. #define SSL_set_time(session, time) SSL_SESSION_set_time((session), (time))
  4112. #define SSL_get_timeout(session) SSL_SESSION_get_timeout(session)
  4113. #define SSL_set_timeout(session, timeout) \
  4114. SSL_SESSION_set_timeout((session), (timeout))
  4115. struct ssl_comp_st {
  4116. int id;
  4117. const char *name;
  4118. char *method;
  4119. };
  4120. DEFINE_STACK_OF(SSL_COMP)
  4121. // The following flags do nothing and are included only to make it easier to
  4122. // compile code with BoringSSL.
  4123. #define SSL_MODE_AUTO_RETRY 0
  4124. #define SSL_MODE_RELEASE_BUFFERS 0
  4125. #define SSL_MODE_SEND_CLIENTHELLO_TIME 0
  4126. #define SSL_MODE_SEND_SERVERHELLO_TIME 0
  4127. #define SSL_OP_ALL 0
  4128. #define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0
  4129. #define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0
  4130. #define SSL_OP_EPHEMERAL_RSA 0
  4131. #define SSL_OP_LEGACY_SERVER_CONNECT 0
  4132. #define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0
  4133. #define SSL_OP_MICROSOFT_SESS_ID_BUG 0
  4134. #define SSL_OP_MSIE_SSLV2_RSA_PADDING 0
  4135. #define SSL_OP_NETSCAPE_CA_DN_BUG 0
  4136. #define SSL_OP_NETSCAPE_CHALLENGE_BUG 0
  4137. #define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0
  4138. #define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0
  4139. #define SSL_OP_NO_COMPRESSION 0
  4140. #define SSL_OP_NO_RENEGOTIATION 0 // ssl_renegotiate_never is the default
  4141. #define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0
  4142. #define SSL_OP_NO_SSLv2 0
  4143. #define SSL_OP_NO_SSLv3 0
  4144. #define SSL_OP_PKCS1_CHECK_1 0
  4145. #define SSL_OP_PKCS1_CHECK_2 0
  4146. #define SSL_OP_SINGLE_DH_USE 0
  4147. #define SSL_OP_SINGLE_ECDH_USE 0
  4148. #define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0
  4149. #define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0
  4150. #define SSL_OP_TLS_BLOCK_PADDING_BUG 0
  4151. #define SSL_OP_TLS_D5_BUG 0
  4152. #define SSL_OP_TLS_ROLLBACK_BUG 0
  4153. #define SSL_VERIFY_CLIENT_ONCE 0
  4154. // SSL_cache_hit calls |SSL_session_reused|.
  4155. OPENSSL_EXPORT int SSL_cache_hit(SSL *ssl);
  4156. // SSL_get_default_timeout returns |SSL_DEFAULT_SESSION_TIMEOUT|.
  4157. OPENSSL_EXPORT long SSL_get_default_timeout(const SSL *ssl);
  4158. // SSL_get_version returns a string describing the TLS version used by |ssl|.
  4159. // For example, "TLSv1.2" or "DTLSv1".
  4160. OPENSSL_EXPORT const char *SSL_get_version(const SSL *ssl);
  4161. // SSL_get_cipher_list returns the name of the |n|th cipher in the output of
  4162. // |SSL_get_ciphers| or NULL if out of range. Use |SSL_get_ciphers| instead.
  4163. OPENSSL_EXPORT const char *SSL_get_cipher_list(const SSL *ssl, int n);
  4164. // SSL_CTX_set_client_cert_cb sets a callback which is called on the client if
  4165. // the server requests a client certificate and none is configured. On success,
  4166. // the callback should return one and set |*out_x509| to |*out_pkey| to a leaf
  4167. // certificate and private key, respectively, passing ownership. It should
  4168. // return zero to send no certificate and -1 to fail or pause the handshake. If
  4169. // the handshake is paused, |SSL_get_error| will return
  4170. // |SSL_ERROR_WANT_X509_LOOKUP|.
  4171. //
  4172. // The callback may call |SSL_get0_certificate_types| and
  4173. // |SSL_get_client_CA_list| for information on the server's certificate request.
  4174. //
  4175. // Use |SSL_CTX_set_cert_cb| instead. Configuring intermediate certificates with
  4176. // this function is confusing. This callback may not be registered concurrently
  4177. // with |SSL_CTX_set_cert_cb| or |SSL_set_cert_cb|.
  4178. OPENSSL_EXPORT void SSL_CTX_set_client_cert_cb(
  4179. SSL_CTX *ctx, int (*cb)(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey));
  4180. #define SSL_NOTHING SSL_ERROR_NONE
  4181. #define SSL_WRITING SSL_ERROR_WANT_WRITE
  4182. #define SSL_READING SSL_ERROR_WANT_READ
  4183. // SSL_want returns one of the above values to determine what the most recent
  4184. // operation on |ssl| was blocked on. Use |SSL_get_error| instead.
  4185. OPENSSL_EXPORT int SSL_want(const SSL *ssl);
  4186. #define SSL_want_read(ssl) (SSL_want(ssl) == SSL_READING)
  4187. #define SSL_want_write(ssl) (SSL_want(ssl) == SSL_WRITING)
  4188. // SSL_get_finished writes up to |count| bytes of the Finished message sent by
  4189. // |ssl| to |buf|. It returns the total untruncated length or zero if none has
  4190. // been sent yet. At TLS 1.3 and later, it returns zero.
  4191. //
  4192. // Use |SSL_get_tls_unique| instead.
  4193. OPENSSL_EXPORT size_t SSL_get_finished(const SSL *ssl, void *buf, size_t count);
  4194. // SSL_get_peer_finished writes up to |count| bytes of the Finished message
  4195. // received from |ssl|'s peer to |buf|. It returns the total untruncated length
  4196. // or zero if none has been received yet. At TLS 1.3 and later, it returns
  4197. // zero.
  4198. //
  4199. // Use |SSL_get_tls_unique| instead.
  4200. OPENSSL_EXPORT size_t SSL_get_peer_finished(const SSL *ssl, void *buf,
  4201. size_t count);
  4202. // SSL_alert_type_string returns "!". Use |SSL_alert_type_string_long|
  4203. // instead.
  4204. OPENSSL_EXPORT const char *SSL_alert_type_string(int value);
  4205. // SSL_alert_desc_string returns "!!". Use |SSL_alert_desc_string_long|
  4206. // instead.
  4207. OPENSSL_EXPORT const char *SSL_alert_desc_string(int value);
  4208. // SSL_state_string returns "!!!!!!". Use |SSL_state_string_long| for a more
  4209. // intelligible string.
  4210. OPENSSL_EXPORT const char *SSL_state_string(const SSL *ssl);
  4211. // SSL_TXT_* expand to strings.
  4212. #define SSL_TXT_MEDIUM "MEDIUM"
  4213. #define SSL_TXT_HIGH "HIGH"
  4214. #define SSL_TXT_FIPS "FIPS"
  4215. #define SSL_TXT_kRSA "kRSA"
  4216. #define SSL_TXT_kDHE "kDHE"
  4217. #define SSL_TXT_kEDH "kEDH"
  4218. #define SSL_TXT_kECDHE "kECDHE"
  4219. #define SSL_TXT_kEECDH "kEECDH"
  4220. #define SSL_TXT_kPSK "kPSK"
  4221. #define SSL_TXT_aRSA "aRSA"
  4222. #define SSL_TXT_aECDSA "aECDSA"
  4223. #define SSL_TXT_aPSK "aPSK"
  4224. #define SSL_TXT_DH "DH"
  4225. #define SSL_TXT_DHE "DHE"
  4226. #define SSL_TXT_EDH "EDH"
  4227. #define SSL_TXT_RSA "RSA"
  4228. #define SSL_TXT_ECDH "ECDH"
  4229. #define SSL_TXT_ECDHE "ECDHE"
  4230. #define SSL_TXT_EECDH "EECDH"
  4231. #define SSL_TXT_ECDSA "ECDSA"
  4232. #define SSL_TXT_PSK "PSK"
  4233. #define SSL_TXT_3DES "3DES"
  4234. #define SSL_TXT_RC4 "RC4"
  4235. #define SSL_TXT_AES128 "AES128"
  4236. #define SSL_TXT_AES256 "AES256"
  4237. #define SSL_TXT_AES "AES"
  4238. #define SSL_TXT_AES_GCM "AESGCM"
  4239. #define SSL_TXT_CHACHA20 "CHACHA20"
  4240. #define SSL_TXT_MD5 "MD5"
  4241. #define SSL_TXT_SHA1 "SHA1"
  4242. #define SSL_TXT_SHA "SHA"
  4243. #define SSL_TXT_SHA256 "SHA256"
  4244. #define SSL_TXT_SHA384 "SHA384"
  4245. #define SSL_TXT_SSLV3 "SSLv3"
  4246. #define SSL_TXT_TLSV1 "TLSv1"
  4247. #define SSL_TXT_TLSV1_1 "TLSv1.1"
  4248. #define SSL_TXT_TLSV1_2 "TLSv1.2"
  4249. #define SSL_TXT_TLSV1_3 "TLSv1.3"
  4250. #define SSL_TXT_ALL "ALL"
  4251. #define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT"
  4252. typedef struct ssl_conf_ctx_st SSL_CONF_CTX;
  4253. // SSL_state returns |SSL_ST_INIT| if a handshake is in progress and |SSL_ST_OK|
  4254. // otherwise.
  4255. //
  4256. // Use |SSL_is_init| instead.
  4257. OPENSSL_EXPORT int SSL_state(const SSL *ssl);
  4258. #define SSL_get_state(ssl) SSL_state(ssl)
  4259. // SSL_set_shutdown causes |ssl| to behave as if the shutdown bitmask (see
  4260. // |SSL_get_shutdown|) were |mode|. This may be used to skip sending or
  4261. // receiving close_notify in |SSL_shutdown| by causing the implementation to
  4262. // believe the events already happened.
  4263. //
  4264. // It is an error to use |SSL_set_shutdown| to unset a bit that has already been
  4265. // set. Doing so will trigger an |assert| in debug builds and otherwise be
  4266. // ignored.
  4267. //
  4268. // Use |SSL_CTX_set_quiet_shutdown| instead.
  4269. OPENSSL_EXPORT void SSL_set_shutdown(SSL *ssl, int mode);
  4270. // SSL_CTX_set_tmp_ecdh calls |SSL_CTX_set1_curves| with a one-element list
  4271. // containing |ec_key|'s curve.
  4272. OPENSSL_EXPORT int SSL_CTX_set_tmp_ecdh(SSL_CTX *ctx, const EC_KEY *ec_key);
  4273. // SSL_set_tmp_ecdh calls |SSL_set1_curves| with a one-element list containing
  4274. // |ec_key|'s curve.
  4275. OPENSSL_EXPORT int SSL_set_tmp_ecdh(SSL *ssl, const EC_KEY *ec_key);
  4276. // SSL_add_dir_cert_subjects_to_stack lists files in directory |dir|. It calls
  4277. // |SSL_add_file_cert_subjects_to_stack| on each file and returns one on success
  4278. // or zero on error. This function is only available from the libdecrepit
  4279. // library.
  4280. OPENSSL_EXPORT int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *out,
  4281. const char *dir);
  4282. // SSL_CTX_enable_tls_channel_id calls |SSL_CTX_set_tls_channel_id_enabled|.
  4283. OPENSSL_EXPORT int SSL_CTX_enable_tls_channel_id(SSL_CTX *ctx);
  4284. // SSL_enable_tls_channel_id calls |SSL_set_tls_channel_id_enabled|.
  4285. OPENSSL_EXPORT int SSL_enable_tls_channel_id(SSL *ssl);
  4286. // BIO_f_ssl returns a |BIO_METHOD| that can wrap an |SSL*| in a |BIO*|. Note
  4287. // that this has quite different behaviour from the version in OpenSSL (notably
  4288. // that it doesn't try to auto renegotiate).
  4289. //
  4290. // IMPORTANT: if you are not curl, don't use this.
  4291. OPENSSL_EXPORT const BIO_METHOD *BIO_f_ssl(void);
  4292. // BIO_set_ssl sets |ssl| as the underlying connection for |bio|, which must
  4293. // have been created using |BIO_f_ssl|. If |take_owership| is true, |bio| will
  4294. // call |SSL_free| on |ssl| when closed. It returns one on success or something
  4295. // other than one on error.
  4296. OPENSSL_EXPORT long BIO_set_ssl(BIO *bio, SSL *ssl, int take_owership);
  4297. // SSL_CTX_set_ecdh_auto returns one.
  4298. #define SSL_CTX_set_ecdh_auto(ctx, onoff) 1
  4299. // SSL_set_ecdh_auto returns one.
  4300. #define SSL_set_ecdh_auto(ssl, onoff) 1
  4301. // SSL_get_session returns a non-owning pointer to |ssl|'s session. For
  4302. // historical reasons, which session it returns depends on |ssl|'s state.
  4303. //
  4304. // Prior to the start of the initial handshake, it returns the session the
  4305. // caller set with |SSL_set_session|. After the initial handshake has finished
  4306. // and if no additional handshakes are in progress, it returns the currently
  4307. // active session. Its behavior is undefined while a handshake is in progress.
  4308. //
  4309. // If trying to add new sessions to an external session cache, use
  4310. // |SSL_CTX_sess_set_new_cb| instead. In particular, using the callback is
  4311. // required as of TLS 1.3. For compatibility, this function will return an
  4312. // unresumable session which may be cached, but will never be resumed.
  4313. //
  4314. // If querying properties of the connection, use APIs on the |SSL| object.
  4315. OPENSSL_EXPORT SSL_SESSION *SSL_get_session(const SSL *ssl);
  4316. // SSL_get0_session is an alias for |SSL_get_session|.
  4317. #define SSL_get0_session SSL_get_session
  4318. // SSL_get1_session acts like |SSL_get_session| but returns a new reference to
  4319. // the session.
  4320. OPENSSL_EXPORT SSL_SESSION *SSL_get1_session(SSL *ssl);
  4321. #define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0
  4322. #define OPENSSL_INIT_LOAD_SSL_STRINGS 0
  4323. #define OPENSSL_INIT_SSL_DEFAULT 0
  4324. // OPENSSL_init_ssl calls |CRYPTO_library_init| and returns one.
  4325. OPENSSL_EXPORT int OPENSSL_init_ssl(uint64_t opts,
  4326. const OPENSSL_INIT_SETTINGS *settings);
  4327. // The following constants are legacy aliases for RSA-PSS with rsaEncryption
  4328. // keys. Use the new names instead.
  4329. #define SSL_SIGN_RSA_PSS_SHA256 SSL_SIGN_RSA_PSS_RSAE_SHA256
  4330. #define SSL_SIGN_RSA_PSS_SHA384 SSL_SIGN_RSA_PSS_RSAE_SHA384
  4331. #define SSL_SIGN_RSA_PSS_SHA512 SSL_SIGN_RSA_PSS_RSAE_SHA512
  4332. // SSL_set_tlsext_status_type configures a client to request OCSP stapling if
  4333. // |type| is |TLSEXT_STATUSTYPE_ocsp| and disables it otherwise. It returns one
  4334. // on success and zero if handshake configuration has already been shed.
  4335. //
  4336. // Use |SSL_enable_ocsp_stapling| instead.
  4337. OPENSSL_EXPORT int SSL_set_tlsext_status_type(SSL *ssl, int type);
  4338. // SSL_get_tlsext_status_type returns |TLSEXT_STATUSTYPE_ocsp| if the client
  4339. // requested OCSP stapling and |TLSEXT_STATUSTYPE_nothing| otherwise. On the
  4340. // client, this reflects whether OCSP stapling was enabled via, e.g.,
  4341. // |SSL_set_tlsext_status_type|. On the server, this is determined during the
  4342. // handshake. It may be queried in callbacks set by |SSL_CTX_set_cert_cb|. The
  4343. // result is undefined after the handshake completes.
  4344. OPENSSL_EXPORT int SSL_get_tlsext_status_type(const SSL *ssl);
  4345. // SSL_set_tlsext_status_ocsp_resp sets the OCSP response. It returns one on
  4346. // success and zero on error. On success, |ssl| takes ownership of |resp|, which
  4347. // must have been allocated by |OPENSSL_malloc|.
  4348. //
  4349. // Use |SSL_set_ocsp_response| instead.
  4350. OPENSSL_EXPORT int SSL_set_tlsext_status_ocsp_resp(SSL *ssl, uint8_t *resp,
  4351. size_t resp_len);
  4352. // SSL_get_tlsext_status_ocsp_resp sets |*out| to point to the OCSP response
  4353. // from the server. It returns the length of the response. If there was no
  4354. // response, it sets |*out| to NULL and returns zero.
  4355. //
  4356. // Use |SSL_get0_ocsp_response| instead.
  4357. //
  4358. // WARNING: the returned data is not guaranteed to be well formed.
  4359. OPENSSL_EXPORT size_t SSL_get_tlsext_status_ocsp_resp(const SSL *ssl,
  4360. const uint8_t **out);
  4361. // SSL_CTX_set_tlsext_status_cb configures the legacy OpenSSL OCSP callback and
  4362. // returns one. Though the type signature is the same, this callback has
  4363. // different behavior for client and server connections:
  4364. //
  4365. // For clients, the callback is called after certificate verification. It should
  4366. // return one for success, zero for a bad OCSP response, and a negative number
  4367. // for internal error. Instead, handle this as part of certificate verification.
  4368. // (Historically, OpenSSL verified certificates just before parsing stapled OCSP
  4369. // responses, but BoringSSL fixes this ordering. All server credentials are
  4370. // available during verification.)
  4371. //
  4372. // Do not use this callback as a server. It is provided for compatibility
  4373. // purposes only. For servers, it is called to configure server credentials. It
  4374. // should return |SSL_TLSEXT_ERR_OK| on success, |SSL_TLSEXT_ERR_NOACK| to
  4375. // ignore OCSP requests, or |SSL_TLSEXT_ERR_ALERT_FATAL| on error. It is usually
  4376. // used to fetch OCSP responses on demand, which is not ideal. Instead, treat
  4377. // OCSP responses like other server credentials, such as certificates or SCT
  4378. // lists. Configure, store, and refresh them eagerly. This avoids downtime if
  4379. // the CA's OCSP responder is briefly offline.
  4380. OPENSSL_EXPORT int SSL_CTX_set_tlsext_status_cb(SSL_CTX *ctx,
  4381. int (*callback)(SSL *ssl,
  4382. void *arg));
  4383. // SSL_CTX_set_tlsext_status_arg sets additional data for
  4384. // |SSL_CTX_set_tlsext_status_cb|'s callback and returns one.
  4385. OPENSSL_EXPORT int SSL_CTX_set_tlsext_status_arg(SSL_CTX *ctx, void *arg);
  4386. // The following symbols are compatibility aliases for reason codes used when
  4387. // receiving an alert from the peer. Use the other names instead, which fit the
  4388. // naming convention.
  4389. //
  4390. // TODO(davidben): Fix references to |SSL_R_TLSV1_CERTIFICATE_REQUIRED| and
  4391. // remove the compatibility value. The others come from OpenSSL.
  4392. #define SSL_R_TLSV1_UNSUPPORTED_EXTENSION \
  4393. SSL_R_TLSV1_ALERT_UNSUPPORTED_EXTENSION
  4394. #define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE \
  4395. SSL_R_TLSV1_ALERT_CERTIFICATE_UNOBTAINABLE
  4396. #define SSL_R_TLSV1_UNRECOGNIZED_NAME SSL_R_TLSV1_ALERT_UNRECOGNIZED_NAME
  4397. #define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE \
  4398. SSL_R_TLSV1_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE
  4399. #define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE \
  4400. SSL_R_TLSV1_ALERT_BAD_CERTIFICATE_HASH_VALUE
  4401. #define SSL_R_TLSV1_CERTIFICATE_REQUIRED SSL_R_TLSV1_ALERT_CERTIFICATE_REQUIRED
  4402. // SSL_CIPHER_get_value calls |SSL_CIPHER_get_protocol_id|.
  4403. //
  4404. // TODO(davidben): |SSL_CIPHER_get_value| was our name for this function, but
  4405. // upstream added it as |SSL_CIPHER_get_protocol_id|. Switch callers to the new
  4406. // name and remove this one.
  4407. OPENSSL_EXPORT uint16_t SSL_CIPHER_get_value(const SSL_CIPHER *cipher);
  4408. // Nodejs compatibility section (hidden).
  4409. //
  4410. // These defines exist for node.js, with the hope that we can eliminate the
  4411. // need for them over time.
  4412. #define SSLerr(function, reason) \
  4413. ERR_put_error(ERR_LIB_SSL, 0, reason, __FILE__, __LINE__)
  4414. // Preprocessor compatibility section (hidden).
  4415. //
  4416. // Historically, a number of APIs were implemented in OpenSSL as macros and
  4417. // constants to 'ctrl' functions. To avoid breaking #ifdefs in consumers, this
  4418. // section defines a number of legacy macros.
  4419. //
  4420. // Although using either the CTRL values or their wrapper macros in #ifdefs is
  4421. // still supported, the CTRL values may not be passed to |SSL_ctrl| and
  4422. // |SSL_CTX_ctrl|. Call the functions (previously wrapper macros) instead.
  4423. //
  4424. // See PORTING.md in the BoringSSL source tree for a table of corresponding
  4425. // functions.
  4426. // https://boringssl.googlesource.com/boringssl/+/master/PORTING.md#Replacements-for-values
  4427. #define DTLS_CTRL_GET_TIMEOUT doesnt_exist
  4428. #define DTLS_CTRL_HANDLE_TIMEOUT doesnt_exist
  4429. #define SSL_CTRL_CHAIN doesnt_exist
  4430. #define SSL_CTRL_CHAIN_CERT doesnt_exist
  4431. #define SSL_CTRL_CHANNEL_ID doesnt_exist
  4432. #define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS doesnt_exist
  4433. #define SSL_CTRL_CLEAR_MODE doesnt_exist
  4434. #define SSL_CTRL_CLEAR_OPTIONS doesnt_exist
  4435. #define SSL_CTRL_EXTRA_CHAIN_CERT doesnt_exist
  4436. #define SSL_CTRL_GET_CHAIN_CERTS doesnt_exist
  4437. #define SSL_CTRL_GET_CHANNEL_ID doesnt_exist
  4438. #define SSL_CTRL_GET_CLIENT_CERT_TYPES doesnt_exist
  4439. #define SSL_CTRL_GET_EXTRA_CHAIN_CERTS doesnt_exist
  4440. #define SSL_CTRL_GET_MAX_CERT_LIST doesnt_exist
  4441. #define SSL_CTRL_GET_NUM_RENEGOTIATIONS doesnt_exist
  4442. #define SSL_CTRL_GET_READ_AHEAD doesnt_exist
  4443. #define SSL_CTRL_GET_RI_SUPPORT doesnt_exist
  4444. #define SSL_CTRL_GET_SERVER_TMP_KEY doesnt_exist
  4445. #define SSL_CTRL_GET_SESSION_REUSED doesnt_exist
  4446. #define SSL_CTRL_GET_SESS_CACHE_MODE doesnt_exist
  4447. #define SSL_CTRL_GET_SESS_CACHE_SIZE doesnt_exist
  4448. #define SSL_CTRL_GET_TLSEXT_TICKET_KEYS doesnt_exist
  4449. #define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS doesnt_exist
  4450. #define SSL_CTRL_MODE doesnt_exist
  4451. #define SSL_CTRL_NEED_TMP_RSA doesnt_exist
  4452. #define SSL_CTRL_OPTIONS doesnt_exist
  4453. #define SSL_CTRL_SESS_NUMBER doesnt_exist
  4454. #define SSL_CTRL_SET_CURVES doesnt_exist
  4455. #define SSL_CTRL_SET_CURVES_LIST doesnt_exist
  4456. #define SSL_CTRL_SET_ECDH_AUTO doesnt_exist
  4457. #define SSL_CTRL_SET_MAX_CERT_LIST doesnt_exist
  4458. #define SSL_CTRL_SET_MAX_SEND_FRAGMENT doesnt_exist
  4459. #define SSL_CTRL_SET_MSG_CALLBACK doesnt_exist
  4460. #define SSL_CTRL_SET_MSG_CALLBACK_ARG doesnt_exist
  4461. #define SSL_CTRL_SET_MTU doesnt_exist
  4462. #define SSL_CTRL_SET_READ_AHEAD doesnt_exist
  4463. #define SSL_CTRL_SET_SESS_CACHE_MODE doesnt_exist
  4464. #define SSL_CTRL_SET_SESS_CACHE_SIZE doesnt_exist
  4465. #define SSL_CTRL_SET_TLSEXT_HOSTNAME doesnt_exist
  4466. #define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG doesnt_exist
  4467. #define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB doesnt_exist
  4468. #define SSL_CTRL_SET_TLSEXT_TICKET_KEYS doesnt_exist
  4469. #define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB doesnt_exist
  4470. #define SSL_CTRL_SET_TMP_DH doesnt_exist
  4471. #define SSL_CTRL_SET_TMP_DH_CB doesnt_exist
  4472. #define SSL_CTRL_SET_TMP_ECDH doesnt_exist
  4473. #define SSL_CTRL_SET_TMP_ECDH_CB doesnt_exist
  4474. #define SSL_CTRL_SET_TMP_RSA doesnt_exist
  4475. #define SSL_CTRL_SET_TMP_RSA_CB doesnt_exist
  4476. // |BORINGSSL_PREFIX| already makes each of these symbols into macros, so there
  4477. // is no need to define conflicting macros.
  4478. #if !defined(BORINGSSL_PREFIX)
  4479. #define DTLSv1_get_timeout DTLSv1_get_timeout
  4480. #define DTLSv1_handle_timeout DTLSv1_handle_timeout
  4481. #define SSL_CTX_add0_chain_cert SSL_CTX_add0_chain_cert
  4482. #define SSL_CTX_add1_chain_cert SSL_CTX_add1_chain_cert
  4483. #define SSL_CTX_add_extra_chain_cert SSL_CTX_add_extra_chain_cert
  4484. #define SSL_CTX_clear_extra_chain_certs SSL_CTX_clear_extra_chain_certs
  4485. #define SSL_CTX_clear_chain_certs SSL_CTX_clear_chain_certs
  4486. #define SSL_CTX_clear_mode SSL_CTX_clear_mode
  4487. #define SSL_CTX_clear_options SSL_CTX_clear_options
  4488. #define SSL_CTX_get0_chain_certs SSL_CTX_get0_chain_certs
  4489. #define SSL_CTX_get_extra_chain_certs SSL_CTX_get_extra_chain_certs
  4490. #define SSL_CTX_get_max_cert_list SSL_CTX_get_max_cert_list
  4491. #define SSL_CTX_get_mode SSL_CTX_get_mode
  4492. #define SSL_CTX_get_options SSL_CTX_get_options
  4493. #define SSL_CTX_get_read_ahead SSL_CTX_get_read_ahead
  4494. #define SSL_CTX_get_session_cache_mode SSL_CTX_get_session_cache_mode
  4495. #define SSL_CTX_get_tlsext_ticket_keys SSL_CTX_get_tlsext_ticket_keys
  4496. #define SSL_CTX_need_tmp_RSA SSL_CTX_need_tmp_RSA
  4497. #define SSL_CTX_sess_get_cache_size SSL_CTX_sess_get_cache_size
  4498. #define SSL_CTX_sess_number SSL_CTX_sess_number
  4499. #define SSL_CTX_sess_set_cache_size SSL_CTX_sess_set_cache_size
  4500. #define SSL_CTX_set0_chain SSL_CTX_set0_chain
  4501. #define SSL_CTX_set1_chain SSL_CTX_set1_chain
  4502. #define SSL_CTX_set1_curves SSL_CTX_set1_curves
  4503. #define SSL_CTX_set_max_cert_list SSL_CTX_set_max_cert_list
  4504. #define SSL_CTX_set_max_send_fragment SSL_CTX_set_max_send_fragment
  4505. #define SSL_CTX_set_mode SSL_CTX_set_mode
  4506. #define SSL_CTX_set_msg_callback_arg SSL_CTX_set_msg_callback_arg
  4507. #define SSL_CTX_set_options SSL_CTX_set_options
  4508. #define SSL_CTX_set_read_ahead SSL_CTX_set_read_ahead
  4509. #define SSL_CTX_set_session_cache_mode SSL_CTX_set_session_cache_mode
  4510. #define SSL_CTX_set_tlsext_servername_arg SSL_CTX_set_tlsext_servername_arg
  4511. #define SSL_CTX_set_tlsext_servername_callback \
  4512. SSL_CTX_set_tlsext_servername_callback
  4513. #define SSL_CTX_set_tlsext_ticket_key_cb SSL_CTX_set_tlsext_ticket_key_cb
  4514. #define SSL_CTX_set_tlsext_ticket_keys SSL_CTX_set_tlsext_ticket_keys
  4515. #define SSL_CTX_set_tmp_dh SSL_CTX_set_tmp_dh
  4516. #define SSL_CTX_set_tmp_ecdh SSL_CTX_set_tmp_ecdh
  4517. #define SSL_CTX_set_tmp_rsa SSL_CTX_set_tmp_rsa
  4518. #define SSL_add0_chain_cert SSL_add0_chain_cert
  4519. #define SSL_add1_chain_cert SSL_add1_chain_cert
  4520. #define SSL_clear_chain_certs SSL_clear_chain_certs
  4521. #define SSL_clear_mode SSL_clear_mode
  4522. #define SSL_clear_options SSL_clear_options
  4523. #define SSL_get0_certificate_types SSL_get0_certificate_types
  4524. #define SSL_get0_chain_certs SSL_get0_chain_certs
  4525. #define SSL_get_max_cert_list SSL_get_max_cert_list
  4526. #define SSL_get_mode SSL_get_mode
  4527. #define SSL_get_options SSL_get_options
  4528. #define SSL_get_secure_renegotiation_support \
  4529. SSL_get_secure_renegotiation_support
  4530. #define SSL_need_tmp_RSA SSL_need_tmp_RSA
  4531. #define SSL_num_renegotiations SSL_num_renegotiations
  4532. #define SSL_session_reused SSL_session_reused
  4533. #define SSL_set0_chain SSL_set0_chain
  4534. #define SSL_set1_chain SSL_set1_chain
  4535. #define SSL_set1_curves SSL_set1_curves
  4536. #define SSL_set_max_cert_list SSL_set_max_cert_list
  4537. #define SSL_set_max_send_fragment SSL_set_max_send_fragment
  4538. #define SSL_set_mode SSL_set_mode
  4539. #define SSL_set_msg_callback_arg SSL_set_msg_callback_arg
  4540. #define SSL_set_mtu SSL_set_mtu
  4541. #define SSL_set_options SSL_set_options
  4542. #define SSL_set_tlsext_host_name SSL_set_tlsext_host_name
  4543. #define SSL_set_tmp_dh SSL_set_tmp_dh
  4544. #define SSL_set_tmp_ecdh SSL_set_tmp_ecdh
  4545. #define SSL_set_tmp_rsa SSL_set_tmp_rsa
  4546. #define SSL_total_renegotiations SSL_total_renegotiations
  4547. #endif // !defined(BORINGSSL_PREFIX)
  4548. #if defined(__cplusplus)
  4549. } // extern C
  4550. #if !defined(BORINGSSL_NO_CXX)
  4551. extern "C++" {
  4552. BSSL_NAMESPACE_BEGIN
  4553. BORINGSSL_MAKE_DELETER(SSL, SSL_free)
  4554. BORINGSSL_MAKE_DELETER(SSL_CTX, SSL_CTX_free)
  4555. BORINGSSL_MAKE_UP_REF(SSL_CTX, SSL_CTX_up_ref)
  4556. BORINGSSL_MAKE_DELETER(SSL_ECH_KEYS, SSL_ECH_KEYS_free)
  4557. BORINGSSL_MAKE_UP_REF(SSL_ECH_KEYS, SSL_ECH_KEYS_up_ref)
  4558. BORINGSSL_MAKE_DELETER(SSL_SESSION, SSL_SESSION_free)
  4559. BORINGSSL_MAKE_UP_REF(SSL_SESSION, SSL_SESSION_up_ref)
  4560. enum class OpenRecordResult {
  4561. kOK,
  4562. kDiscard,
  4563. kIncompleteRecord,
  4564. kAlertCloseNotify,
  4565. kError,
  4566. };
  4567. // *** EXPERIMENTAL -- DO NOT USE ***
  4568. //
  4569. // OpenRecord decrypts the first complete SSL record from |in| in-place, sets
  4570. // |out| to the decrypted application data, and |out_record_len| to the length
  4571. // of the encrypted record. Returns:
  4572. // - kOK if an application-data record was successfully decrypted and verified.
  4573. // - kDiscard if a record was sucessfully processed, but should be discarded.
  4574. // - kIncompleteRecord if |in| did not contain a complete record.
  4575. // - kAlertCloseNotify if a record was successfully processed but is a
  4576. // close_notify alert.
  4577. // - kError if an error occurred or the record is invalid. |*out_alert| will be
  4578. // set to an alert to emit, or zero if no alert should be emitted.
  4579. OPENSSL_EXPORT OpenRecordResult OpenRecord(SSL *ssl, Span<uint8_t> *out,
  4580. size_t *out_record_len,
  4581. uint8_t *out_alert,
  4582. Span<uint8_t> in);
  4583. OPENSSL_EXPORT size_t SealRecordPrefixLen(const SSL *ssl, size_t plaintext_len);
  4584. // SealRecordSuffixLen returns the length of the suffix written by |SealRecord|.
  4585. //
  4586. // |plaintext_len| must be equal to the size of the plaintext passed to
  4587. // |SealRecord|.
  4588. //
  4589. // |plaintext_len| must not exceed |SSL3_RT_MAX_PLAINTEXT_LENGTH|. The returned
  4590. // suffix length will not exceed |SSL3_RT_MAX_ENCRYPTED_OVERHEAD|.
  4591. OPENSSL_EXPORT size_t SealRecordSuffixLen(const SSL *ssl, size_t plaintext_len);
  4592. // *** EXPERIMENTAL -- DO NOT USE ***
  4593. //
  4594. // SealRecord encrypts the cleartext of |in| and scatters the resulting TLS
  4595. // application data record between |out_prefix|, |out|, and |out_suffix|. It
  4596. // returns true on success or false if an error occurred.
  4597. //
  4598. // The length of |out_prefix| must equal |SealRecordPrefixLen|. The length of
  4599. // |out| must equal the length of |in|, which must not exceed
  4600. // |SSL3_RT_MAX_PLAINTEXT_LENGTH|. The length of |out_suffix| must equal
  4601. // |SealRecordSuffixLen|.
  4602. //
  4603. // If enabled, |SealRecord| may perform TLS 1.0 CBC 1/n-1 record splitting.
  4604. // |SealRecordPrefixLen| accounts for the required overhead if that is the case.
  4605. //
  4606. // |out| may equal |in| to encrypt in-place but may not otherwise alias.
  4607. // |out_prefix| and |out_suffix| may not alias anything.
  4608. OPENSSL_EXPORT bool SealRecord(SSL *ssl, Span<uint8_t> out_prefix,
  4609. Span<uint8_t> out, Span<uint8_t> out_suffix,
  4610. Span<const uint8_t> in);
  4611. // *** EXPERIMENTAL — DO NOT USE WITHOUT CHECKING ***
  4612. //
  4613. // Split handshakes.
  4614. //
  4615. // Split handshakes allows the handshake part of a TLS connection to be
  4616. // performed in a different process (or on a different machine) than the data
  4617. // exchange. This only applies to servers.
  4618. //
  4619. // In the first part of a split handshake, an |SSL| (where the |SSL_CTX| has
  4620. // been configured with |SSL_CTX_set_handoff_mode|) is used normally. Once the
  4621. // ClientHello message has been received, the handshake will stop and
  4622. // |SSL_get_error| will indicate |SSL_ERROR_HANDOFF|. At this point (and only
  4623. // at this point), |SSL_serialize_handoff| can be called to write the “handoff”
  4624. // state of the connection.
  4625. //
  4626. // Elsewhere, a fresh |SSL| can be used with |SSL_apply_handoff| to continue
  4627. // the connection. The connection from the client is fed into this |SSL|, and
  4628. // the handshake resumed. When the handshake stops again and |SSL_get_error|
  4629. // indicates |SSL_ERROR_HANDBACK|, |SSL_serialize_handback| should be called to
  4630. // serialize the state of the handshake again.
  4631. //
  4632. // Back at the first location, a fresh |SSL| can be used with
  4633. // |SSL_apply_handback|. Then the client's connection can be processed mostly
  4634. // as normal.
  4635. //
  4636. // Lastly, when a connection is in the handoff state, whether or not
  4637. // |SSL_serialize_handoff| is called, |SSL_decline_handoff| will move it back
  4638. // into a normal state where the connection can proceed without impact.
  4639. //
  4640. // WARNING: Currently only works with TLS 1.0–1.2.
  4641. // WARNING: The serialisation formats are not yet stable: version skew may be
  4642. // fatal.
  4643. // WARNING: The handback data contains sensitive key material and must be
  4644. // protected.
  4645. // WARNING: Some calls on the final |SSL| will not work. Just as an example,
  4646. // calls like |SSL_get0_session_id_context| and |SSL_get_privatekey| won't
  4647. // work because the certificate used for handshaking isn't available.
  4648. // WARNING: |SSL_apply_handoff| may trigger “msg” callback calls.
  4649. OPENSSL_EXPORT void SSL_CTX_set_handoff_mode(SSL_CTX *ctx, bool on);
  4650. OPENSSL_EXPORT void SSL_set_handoff_mode(SSL *SSL, bool on);
  4651. OPENSSL_EXPORT bool SSL_serialize_handoff(const SSL *ssl, CBB *out,
  4652. SSL_CLIENT_HELLO *out_hello);
  4653. OPENSSL_EXPORT bool SSL_decline_handoff(SSL *ssl);
  4654. OPENSSL_EXPORT bool SSL_apply_handoff(SSL *ssl, Span<const uint8_t> handoff);
  4655. OPENSSL_EXPORT bool SSL_serialize_handback(const SSL *ssl, CBB *out);
  4656. OPENSSL_EXPORT bool SSL_apply_handback(SSL *ssl, Span<const uint8_t> handback);
  4657. // SSL_get_traffic_secrets sets |*out_read_traffic_secret| and
  4658. // |*out_write_traffic_secret| to reference the TLS 1.3 traffic secrets for
  4659. // |ssl|. This function is only valid on TLS 1.3 connections that have
  4660. // completed the handshake. It returns true on success and false on error.
  4661. OPENSSL_EXPORT bool SSL_get_traffic_secrets(
  4662. const SSL *ssl, Span<const uint8_t> *out_read_traffic_secret,
  4663. Span<const uint8_t> *out_write_traffic_secret);
  4664. BSSL_NAMESPACE_END
  4665. } // extern C++
  4666. #endif // !defined(BORINGSSL_NO_CXX)
  4667. #endif
  4668. #define SSL_R_APP_DATA_IN_HANDSHAKE 100
  4669. #define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 101
  4670. #define SSL_R_BAD_ALERT 102
  4671. #define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
  4672. #define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 104
  4673. #define SSL_R_BAD_DH_P_LENGTH 105
  4674. #define SSL_R_BAD_DIGEST_LENGTH 106
  4675. #define SSL_R_BAD_ECC_CERT 107
  4676. #define SSL_R_BAD_ECPOINT 108
  4677. #define SSL_R_BAD_HANDSHAKE_RECORD 109
  4678. #define SSL_R_BAD_HELLO_REQUEST 110
  4679. #define SSL_R_BAD_LENGTH 111
  4680. #define SSL_R_BAD_PACKET_LENGTH 112
  4681. #define SSL_R_BAD_RSA_ENCRYPT 113
  4682. #define SSL_R_BAD_SIGNATURE 114
  4683. #define SSL_R_BAD_SRTP_MKI_VALUE 115
  4684. #define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST 116
  4685. #define SSL_R_BAD_SSL_FILETYPE 117
  4686. #define SSL_R_BAD_WRITE_RETRY 118
  4687. #define SSL_R_BIO_NOT_SET 119
  4688. #define SSL_R_BN_LIB 120
  4689. #define SSL_R_BUFFER_TOO_SMALL 121
  4690. #define SSL_R_CA_DN_LENGTH_MISMATCH 122
  4691. #define SSL_R_CA_DN_TOO_LONG 123
  4692. #define SSL_R_CCS_RECEIVED_EARLY 124
  4693. #define SSL_R_CERTIFICATE_VERIFY_FAILED 125
  4694. #define SSL_R_CERT_CB_ERROR 126
  4695. #define SSL_R_CERT_LENGTH_MISMATCH 127
  4696. #define SSL_R_CHANNEL_ID_NOT_P256 128
  4697. #define SSL_R_CHANNEL_ID_SIGNATURE_INVALID 129
  4698. #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 130
  4699. #define SSL_R_CLIENTHELLO_PARSE_FAILED 131
  4700. #define SSL_R_CLIENTHELLO_TLSEXT 132
  4701. #define SSL_R_CONNECTION_REJECTED 133
  4702. #define SSL_R_CONNECTION_TYPE_NOT_SET 134
  4703. #define SSL_R_CUSTOM_EXTENSION_ERROR 135
  4704. #define SSL_R_DATA_LENGTH_TOO_LONG 136
  4705. #define SSL_R_DECODE_ERROR 137
  4706. #define SSL_R_DECRYPTION_FAILED 138
  4707. #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 139
  4708. #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 140
  4709. #define SSL_R_DH_P_TOO_LONG 141
  4710. #define SSL_R_DIGEST_CHECK_FAILED 142
  4711. #define SSL_R_DTLS_MESSAGE_TOO_BIG 143
  4712. #define SSL_R_ECC_CERT_NOT_FOR_SIGNING 144
  4713. #define SSL_R_EMS_STATE_INCONSISTENT 145
  4714. #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 146
  4715. #define SSL_R_ERROR_ADDING_EXTENSION 147
  4716. #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 148
  4717. #define SSL_R_ERROR_PARSING_EXTENSION 149
  4718. #define SSL_R_EXCESSIVE_MESSAGE_SIZE 150
  4719. #define SSL_R_EXTRA_DATA_IN_MESSAGE 151
  4720. #define SSL_R_FRAGMENT_MISMATCH 152
  4721. #define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION 153
  4722. #define SSL_R_HANDSHAKE_FAILURE_ON_CLIENT_HELLO 154
  4723. #define SSL_R_HTTPS_PROXY_REQUEST 155
  4724. #define SSL_R_HTTP_REQUEST 156
  4725. #define SSL_R_INAPPROPRIATE_FALLBACK 157
  4726. #define SSL_R_INVALID_COMMAND 158
  4727. #define SSL_R_INVALID_MESSAGE 159
  4728. #define SSL_R_INVALID_SSL_SESSION 160
  4729. #define SSL_R_INVALID_TICKET_KEYS_LENGTH 161
  4730. #define SSL_R_LENGTH_MISMATCH 162
  4731. #define SSL_R_MISSING_EXTENSION 164
  4732. #define SSL_R_MISSING_RSA_CERTIFICATE 165
  4733. #define SSL_R_MISSING_TMP_DH_KEY 166
  4734. #define SSL_R_MISSING_TMP_ECDH_KEY 167
  4735. #define SSL_R_MIXED_SPECIAL_OPERATOR_WITH_GROUPS 168
  4736. #define SSL_R_MTU_TOO_SMALL 169
  4737. #define SSL_R_NEGOTIATED_BOTH_NPN_AND_ALPN 170
  4738. #define SSL_R_NESTED_GROUP 171
  4739. #define SSL_R_NO_CERTIFICATES_RETURNED 172
  4740. #define SSL_R_NO_CERTIFICATE_ASSIGNED 173
  4741. #define SSL_R_NO_CERTIFICATE_SET 174
  4742. #define SSL_R_NO_CIPHERS_AVAILABLE 175
  4743. #define SSL_R_NO_CIPHERS_PASSED 176
  4744. #define SSL_R_NO_CIPHER_MATCH 177
  4745. #define SSL_R_NO_COMPRESSION_SPECIFIED 178
  4746. #define SSL_R_NO_METHOD_SPECIFIED 179
  4747. #define SSL_R_NO_P256_SUPPORT 180
  4748. #define SSL_R_NO_PRIVATE_KEY_ASSIGNED 181
  4749. #define SSL_R_NO_RENEGOTIATION 182
  4750. #define SSL_R_NO_REQUIRED_DIGEST 183
  4751. #define SSL_R_NO_SHARED_CIPHER 184
  4752. #define SSL_R_NULL_SSL_CTX 185
  4753. #define SSL_R_NULL_SSL_METHOD_PASSED 186
  4754. #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 187
  4755. #define SSL_R_OLD_SESSION_VERSION_NOT_RETURNED 188
  4756. #define SSL_R_OUTPUT_ALIASES_INPUT 189
  4757. #define SSL_R_PARSE_TLSEXT 190
  4758. #define SSL_R_PATH_TOO_LONG 191
  4759. #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 192
  4760. #define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 193
  4761. #define SSL_R_PROTOCOL_IS_SHUTDOWN 194
  4762. #define SSL_R_PSK_IDENTITY_NOT_FOUND 195
  4763. #define SSL_R_PSK_NO_CLIENT_CB 196
  4764. #define SSL_R_PSK_NO_SERVER_CB 197
  4765. #define SSL_R_READ_TIMEOUT_EXPIRED 198
  4766. #define SSL_R_RECORD_LENGTH_MISMATCH 199
  4767. #define SSL_R_RECORD_TOO_LARGE 200
  4768. #define SSL_R_RENEGOTIATION_ENCODING_ERR 201
  4769. #define SSL_R_RENEGOTIATION_MISMATCH 202
  4770. #define SSL_R_REQUIRED_CIPHER_MISSING 203
  4771. #define SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION 204
  4772. #define SSL_R_RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION 205
  4773. #define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING 206
  4774. #define SSL_R_SERVERHELLO_TLSEXT 207
  4775. #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 208
  4776. #define SSL_R_SESSION_MAY_NOT_BE_CREATED 209
  4777. #define SSL_R_SIGNATURE_ALGORITHMS_EXTENSION_SENT_BY_SERVER 210
  4778. #define SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES 211
  4779. #define SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE 212
  4780. #define SSL_R_SSL3_EXT_INVALID_SERVERNAME 213
  4781. #define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 214
  4782. #define SSL_R_SSL_HANDSHAKE_FAILURE 215
  4783. #define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 216
  4784. #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 217
  4785. #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 218
  4786. #define SSL_R_TOO_MANY_EMPTY_FRAGMENTS 219
  4787. #define SSL_R_TOO_MANY_WARNING_ALERTS 220
  4788. #define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 221
  4789. #define SSL_R_UNEXPECTED_EXTENSION 222
  4790. #define SSL_R_UNEXPECTED_MESSAGE 223
  4791. #define SSL_R_UNEXPECTED_OPERATOR_IN_GROUP 224
  4792. #define SSL_R_UNEXPECTED_RECORD 225
  4793. #define SSL_R_UNINITIALIZED 226
  4794. #define SSL_R_UNKNOWN_ALERT_TYPE 227
  4795. #define SSL_R_UNKNOWN_CERTIFICATE_TYPE 228
  4796. #define SSL_R_UNKNOWN_CIPHER_RETURNED 229
  4797. #define SSL_R_UNKNOWN_CIPHER_TYPE 230
  4798. #define SSL_R_UNKNOWN_DIGEST 231
  4799. #define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 232
  4800. #define SSL_R_UNKNOWN_PROTOCOL 233
  4801. #define SSL_R_UNKNOWN_SSL_VERSION 234
  4802. #define SSL_R_UNKNOWN_STATE 235
  4803. #define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED 236
  4804. #define SSL_R_UNSUPPORTED_CIPHER 237
  4805. #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 238
  4806. #define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 239
  4807. #define SSL_R_UNSUPPORTED_PROTOCOL 240
  4808. #define SSL_R_WRONG_CERTIFICATE_TYPE 241
  4809. #define SSL_R_WRONG_CIPHER_RETURNED 242
  4810. #define SSL_R_WRONG_CURVE 243
  4811. #define SSL_R_WRONG_MESSAGE_TYPE 244
  4812. #define SSL_R_WRONG_SIGNATURE_TYPE 245
  4813. #define SSL_R_WRONG_SSL_VERSION 246
  4814. #define SSL_R_WRONG_VERSION_NUMBER 247
  4815. #define SSL_R_X509_LIB 248
  4816. #define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 249
  4817. #define SSL_R_SHUTDOWN_WHILE_IN_INIT 250
  4818. #define SSL_R_INVALID_OUTER_RECORD_TYPE 251
  4819. #define SSL_R_UNSUPPORTED_PROTOCOL_FOR_CUSTOM_KEY 252
  4820. #define SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS 253
  4821. #define SSL_R_DOWNGRADE_DETECTED 254
  4822. #define SSL_R_EXCESS_HANDSHAKE_DATA 255
  4823. #define SSL_R_INVALID_COMPRESSION_LIST 256
  4824. #define SSL_R_DUPLICATE_EXTENSION 257
  4825. #define SSL_R_MISSING_KEY_SHARE 258
  4826. #define SSL_R_INVALID_ALPN_PROTOCOL 259
  4827. #define SSL_R_TOO_MANY_KEY_UPDATES 260
  4828. #define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 261
  4829. #define SSL_R_NO_CIPHERS_SPECIFIED 262
  4830. #define SSL_R_RENEGOTIATION_EMS_MISMATCH 263
  4831. #define SSL_R_DUPLICATE_KEY_SHARE 264
  4832. #define SSL_R_NO_GROUPS_SPECIFIED 265
  4833. #define SSL_R_NO_SHARED_GROUP 266
  4834. #define SSL_R_PRE_SHARED_KEY_MUST_BE_LAST 267
  4835. #define SSL_R_OLD_SESSION_PRF_HASH_MISMATCH 268
  4836. #define SSL_R_INVALID_SCT_LIST 269
  4837. #define SSL_R_TOO_MUCH_SKIPPED_EARLY_DATA 270
  4838. #define SSL_R_PSK_IDENTITY_BINDER_COUNT_MISMATCH 271
  4839. #define SSL_R_CANNOT_PARSE_LEAF_CERT 272
  4840. #define SSL_R_SERVER_CERT_CHANGED 273
  4841. #define SSL_R_CERTIFICATE_AND_PRIVATE_KEY_MISMATCH 274
  4842. #define SSL_R_CANNOT_HAVE_BOTH_PRIVKEY_AND_METHOD 275
  4843. #define SSL_R_TICKET_ENCRYPTION_FAILED 276
  4844. #define SSL_R_ALPN_MISMATCH_ON_EARLY_DATA 277
  4845. #define SSL_R_WRONG_VERSION_ON_EARLY_DATA 278
  4846. #define SSL_R_UNEXPECTED_EXTENSION_ON_EARLY_DATA 279
  4847. #define SSL_R_NO_SUPPORTED_VERSIONS_ENABLED 280
  4848. #define SSL_R_APPLICATION_DATA_INSTEAD_OF_HANDSHAKE 281
  4849. #define SSL_R_EMPTY_HELLO_RETRY_REQUEST 282
  4850. #define SSL_R_EARLY_DATA_NOT_IN_USE 283
  4851. #define SSL_R_HANDSHAKE_NOT_COMPLETE 284
  4852. #define SSL_R_NEGOTIATED_TB_WITHOUT_EMS_OR_RI 285
  4853. #define SSL_R_SERVER_ECHOED_INVALID_SESSION_ID 286
  4854. #define SSL_R_PRIVATE_KEY_OPERATION_FAILED 287
  4855. #define SSL_R_SECOND_SERVERHELLO_VERSION_MISMATCH 288
  4856. #define SSL_R_OCSP_CB_ERROR 289
  4857. #define SSL_R_SSL_SESSION_ID_TOO_LONG 290
  4858. #define SSL_R_APPLICATION_DATA_ON_SHUTDOWN 291
  4859. #define SSL_R_CERT_DECOMPRESSION_FAILED 292
  4860. #define SSL_R_UNCOMPRESSED_CERT_TOO_LARGE 293
  4861. #define SSL_R_UNKNOWN_CERT_COMPRESSION_ALG 294
  4862. #define SSL_R_INVALID_SIGNATURE_ALGORITHM 295
  4863. #define SSL_R_DUPLICATE_SIGNATURE_ALGORITHM 296
  4864. #define SSL_R_TLS13_DOWNGRADE 297
  4865. #define SSL_R_QUIC_INTERNAL_ERROR 298
  4866. #define SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED 299
  4867. #define SSL_R_TOO_MUCH_READ_EARLY_DATA 300
  4868. #define SSL_R_INVALID_DELEGATED_CREDENTIAL 301
  4869. #define SSL_R_KEY_USAGE_BIT_INCORRECT 302
  4870. #define SSL_R_INCONSISTENT_CLIENT_HELLO 303
  4871. #define SSL_R_CIPHER_MISMATCH_ON_EARLY_DATA 304
  4872. #define SSL_R_QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED 305
  4873. #define SSL_R_UNEXPECTED_COMPATIBILITY_MODE 306
  4874. #define SSL_R_NO_APPLICATION_PROTOCOL 307
  4875. #define SSL_R_NEGOTIATED_ALPS_WITHOUT_ALPN 308
  4876. #define SSL_R_ALPS_MISMATCH_ON_EARLY_DATA 309
  4877. #define SSL_R_ECH_SERVER_CONFIG_AND_PRIVATE_KEY_MISMATCH 310
  4878. #define SSL_R_ECH_SERVER_CONFIG_UNSUPPORTED_EXTENSION 311
  4879. #define SSL_R_UNSUPPORTED_ECH_SERVER_CONFIG 312
  4880. #define SSL_R_ECH_SERVER_WOULD_HAVE_NO_RETRY_CONFIGS 313
  4881. #define SSL_R_INVALID_CLIENT_HELLO_INNER 314
  4882. #define SSL_R_INVALID_ALPN_PROTOCOL_LIST 315
  4883. #define SSL_R_COULD_NOT_PARSE_HINTS 316
  4884. #define SSL_R_INVALID_ECH_PUBLIC_NAME 317
  4885. #define SSL_R_INVALID_ECH_CONFIG_LIST 318
  4886. #define SSL_R_ECH_REJECTED 319
  4887. #define SSL_R_INVALID_OUTER_EXTENSION 320
  4888. #define SSL_R_INCONSISTENT_ECH_NEGOTIATION 321
  4889. #define SSL_R_SSLV3_ALERT_CLOSE_NOTIFY 1000
  4890. #define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
  4891. #define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
  4892. #define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
  4893. #define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
  4894. #define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
  4895. #define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
  4896. #define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
  4897. #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
  4898. #define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
  4899. #define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
  4900. #define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
  4901. #define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
  4902. #define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
  4903. #define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
  4904. #define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
  4905. #define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
  4906. #define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
  4907. #define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
  4908. #define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
  4909. #define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
  4910. #define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
  4911. #define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086
  4912. #define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
  4913. #define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
  4914. #define SSL_R_TLSV1_ALERT_UNSUPPORTED_EXTENSION 1110
  4915. #define SSL_R_TLSV1_ALERT_CERTIFICATE_UNOBTAINABLE 1111
  4916. #define SSL_R_TLSV1_ALERT_UNRECOGNIZED_NAME 1112
  4917. #define SSL_R_TLSV1_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE 1113
  4918. #define SSL_R_TLSV1_ALERT_BAD_CERTIFICATE_HASH_VALUE 1114
  4919. #define SSL_R_TLSV1_ALERT_UNKNOWN_PSK_IDENTITY 1115
  4920. #define SSL_R_TLSV1_ALERT_CERTIFICATE_REQUIRED 1116
  4921. #define SSL_R_TLSV1_ALERT_NO_APPLICATION_PROTOCOL 1120
  4922. #define SSL_R_TLSV1_ALERT_ECH_REQUIRED 1121
  4923. #endif // OPENSSL_HEADER_SSL_H