WinCrypt.h 626 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043
  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992-1999.
  5. //
  6. // File: wincrypt.h
  7. //
  8. // Contents: Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __WINCRYPT_H__
  12. #define __WINCRYPT_H__
  13. #if defined (_MSC_VER)
  14. #if ( _MSC_VER >= 800 )
  15. #if _MSC_VER >= 1200
  16. #pragma warning(push)
  17. #endif
  18. #pragma warning(disable:4201) /* Nameless struct/union */
  19. #endif
  20. #if (_MSC_VER > 1020)
  21. #pragma once
  22. #endif
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef _HRESULT_DEFINED
  28. #define _HRESULT_DEFINED
  29. typedef LONG HRESULT;
  30. #endif // !_HRESULT_DEFINED
  31. #ifndef WINADVAPI
  32. #define WINADVAPI
  33. #endif
  34. #ifndef WINAPI
  35. #define WINAPI __stdcall
  36. #endif
  37. #ifndef CALLBACK
  38. #define CALLBACK __stdcall
  39. #endif
  40. #ifndef DECLSPEC_IMPORT
  41. #define DECLSPEC_IMPORT
  42. #endif
  43. #ifndef CONST
  44. #define CONST const
  45. #endif
  46. #ifndef IN
  47. #define IN
  48. #endif
  49. #ifndef OUT
  50. #define OUT
  51. #endif
  52. #ifndef OPTIONAL
  53. #define OPTIONAL
  54. #endif
  55. #if !defined(_CRYPT32_)
  56. #define WINCRYPT32API DECLSPEC_IMPORT
  57. #else
  58. #define WINCRYPT32API
  59. #endif
  60. #if !defined(_CRYPT32STRING_)
  61. # define WINCRYPT32STRINGAPI WINCRYPT32API
  62. #else
  63. # define WINCRYPT32STRINGAPI
  64. #endif
  65. //
  66. // Algorithm IDs and Flags
  67. //
  68. // ALG_ID crackers
  69. #define GET_ALG_CLASS(x) (x & (7 << 13))
  70. #define GET_ALG_TYPE(x) (x & (15 << 9))
  71. #define GET_ALG_SID(x) (x & (511))
  72. // Algorithm classes
  73. #define ALG_CLASS_ANY (0)
  74. #define ALG_CLASS_SIGNATURE (1 << 13)
  75. #define ALG_CLASS_MSG_ENCRYPT (2 << 13)
  76. #define ALG_CLASS_DATA_ENCRYPT (3 << 13)
  77. #define ALG_CLASS_HASH (4 << 13)
  78. #define ALG_CLASS_KEY_EXCHANGE (5 << 13)
  79. #define ALG_CLASS_ALL (7 << 13)
  80. // Algorithm types
  81. #define ALG_TYPE_ANY (0)
  82. #define ALG_TYPE_DSS (1 << 9)
  83. #define ALG_TYPE_RSA (2 << 9)
  84. #define ALG_TYPE_BLOCK (3 << 9)
  85. #define ALG_TYPE_STREAM (4 << 9)
  86. #define ALG_TYPE_DH (5 << 9)
  87. #define ALG_TYPE_SECURECHANNEL (6 << 9)
  88. // Generic sub-ids
  89. #define ALG_SID_ANY (0)
  90. // Some RSA sub-ids
  91. #define ALG_SID_RSA_ANY 0
  92. #define ALG_SID_RSA_PKCS 1
  93. #define ALG_SID_RSA_MSATWORK 2
  94. #define ALG_SID_RSA_ENTRUST 3
  95. #define ALG_SID_RSA_PGP 4
  96. // Some DSS sub-ids
  97. //
  98. #define ALG_SID_DSS_ANY 0
  99. #define ALG_SID_DSS_PKCS 1
  100. #define ALG_SID_DSS_DMS 2
  101. // Block cipher sub ids
  102. // DES sub_ids
  103. #define ALG_SID_DES 1
  104. #define ALG_SID_3DES 3
  105. #define ALG_SID_DESX 4
  106. #define ALG_SID_IDEA 5
  107. #define ALG_SID_CAST 6
  108. #define ALG_SID_SAFERSK64 7
  109. #define ALG_SID_SAFERSK128 8
  110. #define ALG_SID_3DES_112 9
  111. #define ALG_SID_CYLINK_MEK 12
  112. #define ALG_SID_RC5 13
  113. #define ALG_SID_AES_128 14
  114. #define ALG_SID_AES_192 15
  115. #define ALG_SID_AES_256 16
  116. #define ALG_SID_AES 17
  117. // Fortezza sub-ids
  118. #define ALG_SID_SKIPJACK 10
  119. #define ALG_SID_TEK 11
  120. // KP_MODE
  121. #define CRYPT_MODE_CBCI 6 // ANSI CBC Interleaved
  122. #define CRYPT_MODE_CFBP 7 // ANSI CFB Pipelined
  123. #define CRYPT_MODE_OFBP 8 // ANSI OFB Pipelined
  124. #define CRYPT_MODE_CBCOFM 9 // ANSI CBC + OF Masking
  125. #define CRYPT_MODE_CBCOFMI 10 // ANSI CBC + OFM Interleaved
  126. // RC2 sub-ids
  127. #define ALG_SID_RC2 2
  128. // Stream cipher sub-ids
  129. #define ALG_SID_RC4 1
  130. #define ALG_SID_SEAL 2
  131. // Diffie-Hellman sub-ids
  132. #define ALG_SID_DH_SANDF 1
  133. #define ALG_SID_DH_EPHEM 2
  134. #define ALG_SID_AGREED_KEY_ANY 3
  135. #define ALG_SID_KEA 4
  136. // Hash sub ids
  137. #define ALG_SID_MD2 1
  138. #define ALG_SID_MD4 2
  139. #define ALG_SID_MD5 3
  140. #define ALG_SID_SHA 4
  141. #define ALG_SID_SHA1 4
  142. #define ALG_SID_MAC 5
  143. #define ALG_SID_RIPEMD 6
  144. #define ALG_SID_RIPEMD160 7
  145. #define ALG_SID_SSL3SHAMD5 8
  146. #define ALG_SID_HMAC 9
  147. #define ALG_SID_TLS1PRF 10
  148. #define ALG_SID_HASH_REPLACE_OWF 11
  149. // secure channel sub ids
  150. #define ALG_SID_SSL3_MASTER 1
  151. #define ALG_SID_SCHANNEL_MASTER_HASH 2
  152. #define ALG_SID_SCHANNEL_MAC_KEY 3
  153. #define ALG_SID_PCT1_MASTER 4
  154. #define ALG_SID_SSL2_MASTER 5
  155. #define ALG_SID_TLS1_MASTER 6
  156. #define ALG_SID_SCHANNEL_ENC_KEY 7
  157. // Our silly example sub-id
  158. #define ALG_SID_EXAMPLE 80
  159. #ifndef ALGIDDEF
  160. #define ALGIDDEF
  161. typedef unsigned int ALG_ID;
  162. #endif
  163. // algorithm identifier definitions
  164. #define CALG_MD2 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  165. #define CALG_MD4 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  166. #define CALG_MD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  167. #define CALG_SHA (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  168. #define CALG_SHA1 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  169. #define CALG_MAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  170. #define CALG_RSA_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  171. #define CALG_DSS_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  172. #define CALG_NO_SIGN (ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | ALG_SID_ANY)
  173. #define CALG_RSA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  174. #define CALG_DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  175. #define CALG_3DES_112 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  176. #define CALG_3DES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  177. #define CALG_DESX (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DESX)
  178. #define CALG_RC2 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  179. #define CALG_RC4 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  180. #define CALG_SEAL (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  181. #define CALG_DH_SF (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  182. #define CALG_DH_EPHEM (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  183. #define CALG_AGREEDKEY_ANY (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  184. #define CALG_KEA_KEYX (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  185. #define CALG_HUGHES_MD5 (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  186. #define CALG_SKIPJACK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  187. #define CALG_TEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  188. #define CALG_CYLINK_MEK (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  189. #define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  190. #define CALG_SSL3_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  191. #define CALG_SCHANNEL_MASTER_HASH (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  192. #define CALG_SCHANNEL_MAC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  193. #define CALG_SCHANNEL_ENC_KEY (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  194. #define CALG_PCT1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  195. #define CALG_SSL2_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  196. #define CALG_TLS1_MASTER (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  197. #define CALG_RC5 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  198. #define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  199. #define CALG_TLS1PRF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_TLS1PRF)
  200. #define CALG_HASH_REPLACE_OWF (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HASH_REPLACE_OWF)
  201. #define CALG_AES_128 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_128)
  202. #define CALG_AES_192 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_192)
  203. #define CALG_AES_256 (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
  204. #define CALG_AES (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES)
  205. typedef ULONG_PTR HCRYPTPROV;
  206. typedef ULONG_PTR HCRYPTKEY;
  207. typedef ULONG_PTR HCRYPTHASH;
  208. // dwFlags definitions for CryptAcquireContext
  209. #define CRYPT_VERIFYCONTEXT 0xF0000000
  210. #define CRYPT_NEWKEYSET 0x00000008
  211. #define CRYPT_DELETEKEYSET 0x00000010
  212. #define CRYPT_MACHINE_KEYSET 0x00000020
  213. #define CRYPT_SILENT 0x00000040
  214. // dwFlag definitions for CryptGenKey
  215. #define CRYPT_EXPORTABLE 0x00000001
  216. #define CRYPT_USER_PROTECTED 0x00000002
  217. #define CRYPT_CREATE_SALT 0x00000004
  218. #define CRYPT_UPDATE_KEY 0x00000008
  219. #define CRYPT_NO_SALT 0x00000010
  220. #define CRYPT_PREGEN 0x00000040
  221. #define CRYPT_RECIPIENT 0x00000010
  222. #define CRYPT_INITIATOR 0x00000040
  223. #define CRYPT_ONLINE 0x00000080
  224. #define CRYPT_SF 0x00000100
  225. #define CRYPT_CREATE_IV 0x00000200
  226. #define CRYPT_KEK 0x00000400
  227. #define CRYPT_DATA_KEY 0x00000800
  228. #define CRYPT_VOLATILE 0x00001000
  229. #define CRYPT_SGCKEY 0x00002000
  230. #define CRYPT_ARCHIVABLE 0x00004000
  231. #define RSA1024BIT_KEY 0x04000000
  232. // dwFlags definitions for CryptDeriveKey
  233. #define CRYPT_SERVER 0x00000400
  234. #define KEY_LENGTH_MASK 0xFFFF0000
  235. // dwFlag definitions for CryptExportKey
  236. #define CRYPT_Y_ONLY 0x00000001
  237. #define CRYPT_SSL2_FALLBACK 0x00000002
  238. #define CRYPT_DESTROYKEY 0x00000004
  239. #define CRYPT_OAEP 0x00000040 // used with RSA encryptions/decryptions
  240. // CryptExportKey, CryptImportKey,
  241. // CryptEncrypt and CryptDecrypt
  242. #define CRYPT_BLOB_VER3 0x00000080 // export version 3 of a blob type
  243. #define CRYPT_IPSEC_HMAC_KEY 0x00000100 // CryptImportKey only
  244. // dwFlags definitions for CryptCreateHash
  245. #define CRYPT_SECRETDIGEST 0x00000001
  246. // dwFlags definitions for CryptHashData
  247. #define CRYPT_OWF_REPL_LM_HASH 0x00000001 // this is only for the OWF replacement CSP
  248. // dwFlags definitions for CryptHashSessionKey
  249. #define CRYPT_LITTLE_ENDIAN 0x00000001
  250. // dwFlags definitions for CryptSignHash and CryptVerifySignature
  251. #define CRYPT_NOHASHOID 0x00000001
  252. #define CRYPT_TYPE2_FORMAT 0x00000002
  253. #define CRYPT_X931_FORMAT 0x00000004
  254. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  255. #define CRYPT_MACHINE_DEFAULT 0x00000001
  256. #define CRYPT_USER_DEFAULT 0x00000002
  257. #define CRYPT_DELETE_DEFAULT 0x00000004
  258. // exported key blob definitions
  259. #define SIMPLEBLOB 0x1
  260. #define PUBLICKEYBLOB 0x6
  261. #define PRIVATEKEYBLOB 0x7
  262. #define PLAINTEXTKEYBLOB 0x8
  263. #define OPAQUEKEYBLOB 0x9
  264. #define PUBLICKEYBLOBEX 0xA
  265. #define SYMMETRICWRAPKEYBLOB 0xB
  266. #define AT_KEYEXCHANGE 1
  267. #define AT_SIGNATURE 2
  268. #define CRYPT_USERDATA 1
  269. // dwParam
  270. #define KP_IV 1 // Initialization vector
  271. #define KP_SALT 2 // Salt value
  272. #define KP_PADDING 3 // Padding values
  273. #define KP_MODE 4 // Mode of the cipher
  274. #define KP_MODE_BITS 5 // Number of bits to feedback
  275. #define KP_PERMISSIONS 6 // Key permissions DWORD
  276. #define KP_ALGID 7 // Key algorithm
  277. #define KP_BLOCKLEN 8 // Block size of the cipher
  278. #define KP_KEYLEN 9 // Length of key in bits
  279. #define KP_SALT_EX 10 // Length of salt in bytes
  280. #define KP_P 11 // DSS/Diffie-Hellman P value
  281. #define KP_G 12 // DSS/Diffie-Hellman G value
  282. #define KP_Q 13 // DSS Q value
  283. #define KP_X 14 // Diffie-Hellman X value
  284. #define KP_Y 15 // Y value
  285. #define KP_RA 16 // Fortezza RA value
  286. #define KP_RB 17 // Fortezza RB value
  287. #define KP_INFO 18 // for putting information into an RSA envelope
  288. #define KP_EFFECTIVE_KEYLEN 19 // setting and getting RC2 effective key length
  289. #define KP_SCHANNEL_ALG 20 // for setting the Secure Channel algorithms
  290. #define KP_CLIENT_RANDOM 21 // for setting the Secure Channel client random data
  291. #define KP_SERVER_RANDOM 22 // for setting the Secure Channel server random data
  292. #define KP_RP 23
  293. #define KP_PRECOMP_MD5 24
  294. #define KP_PRECOMP_SHA 25
  295. #define KP_CERTIFICATE 26 // for setting Secure Channel certificate data (PCT1)
  296. #define KP_CLEAR_KEY 27 // for setting Secure Channel clear key data (PCT1)
  297. #define KP_PUB_EX_LEN 28
  298. #define KP_PUB_EX_VAL 29
  299. #define KP_KEYVAL 30
  300. #define KP_ADMIN_PIN 31
  301. #define KP_KEYEXCHANGE_PIN 32
  302. #define KP_SIGNATURE_PIN 33
  303. #define KP_PREHASH 34
  304. #define KP_OAEP_PARAMS 36 // for setting OAEP params on RSA keys
  305. #define KP_CMS_KEY_INFO 37
  306. #define KP_CMS_DH_KEY_INFO 38
  307. #define KP_PUB_PARAMS 39 // for setting public parameters
  308. #define KP_VERIFY_PARAMS 40 // for verifying DSA and DH parameters
  309. #define KP_HIGHEST_VERSION 41 // for TLS protocol version setting
  310. // KP_PADDING
  311. #define PKCS5_PADDING 1 // PKCS 5 (sec 6.2) padding method
  312. #define RANDOM_PADDING 2
  313. #define ZERO_PADDING 3
  314. // KP_MODE
  315. #define CRYPT_MODE_CBC 1 // Cipher block chaining
  316. #define CRYPT_MODE_ECB 2 // Electronic code book
  317. #define CRYPT_MODE_OFB 3 // Output feedback mode
  318. #define CRYPT_MODE_CFB 4 // Cipher feedback mode
  319. #define CRYPT_MODE_CTS 5 // Ciphertext stealing mode
  320. // KP_PERMISSIONS
  321. #define CRYPT_ENCRYPT 0x0001 // Allow encryption
  322. #define CRYPT_DECRYPT 0x0002 // Allow decryption
  323. #define CRYPT_EXPORT 0x0004 // Allow key to be exported
  324. #define CRYPT_READ 0x0008 // Allow parameters to be read
  325. #define CRYPT_WRITE 0x0010 // Allow parameters to be set
  326. #define CRYPT_MAC 0x0020 // Allow MACs to be used with key
  327. #define CRYPT_EXPORT_KEY 0x0040 // Allow key to be used for exporting keys
  328. #define CRYPT_IMPORT_KEY 0x0080 // Allow key to be used for importing keys
  329. #define CRYPT_ARCHIVE 0x0100 // Allow key to be exported at creation only
  330. #define HP_ALGID 0x0001 // Hash algorithm
  331. #define HP_HASHVAL 0x0002 // Hash value
  332. #define HP_HASHSIZE 0x0004 // Hash value size
  333. #define HP_HMAC_INFO 0x0005 // information for creating an HMAC
  334. #define HP_TLS1PRF_LABEL 0x0006 // label for TLS1 PRF
  335. #define HP_TLS1PRF_SEED 0x0007 // seed for TLS1 PRF
  336. #define CRYPT_FAILED FALSE
  337. #define CRYPT_SUCCEED TRUE
  338. #define RCRYPT_SUCCEEDED(rt) ((rt) == CRYPT_SUCCEED)
  339. #define RCRYPT_FAILED(rt) ((rt) == CRYPT_FAILED)
  340. //
  341. // CryptGetProvParam
  342. //
  343. #define PP_ENUMALGS 1
  344. #define PP_ENUMCONTAINERS 2
  345. #define PP_IMPTYPE 3
  346. #define PP_NAME 4
  347. #define PP_VERSION 5
  348. #define PP_CONTAINER 6
  349. #define PP_CHANGE_PASSWORD 7
  350. #define PP_KEYSET_SEC_DESCR 8 // get/set security descriptor of keyset
  351. #define PP_CERTCHAIN 9 // for retrieving certificates from tokens
  352. #define PP_KEY_TYPE_SUBTYPE 10
  353. #define PP_PROVTYPE 16
  354. #define PP_KEYSTORAGE 17
  355. #define PP_APPLI_CERT 18
  356. #define PP_SYM_KEYSIZE 19
  357. #define PP_SESSION_KEYSIZE 20
  358. #define PP_UI_PROMPT 21
  359. #define PP_ENUMALGS_EX 22
  360. #define PP_ENUMMANDROOTS 25
  361. #define PP_ENUMELECTROOTS 26
  362. #define PP_KEYSET_TYPE 27
  363. #define PP_ADMIN_PIN 31
  364. #define PP_KEYEXCHANGE_PIN 32
  365. #define PP_SIGNATURE_PIN 33
  366. #define PP_SIG_KEYSIZE_INC 34
  367. #define PP_KEYX_KEYSIZE_INC 35
  368. #define PP_UNIQUE_CONTAINER 36
  369. #define PP_SGC_INFO 37
  370. #define PP_USE_HARDWARE_RNG 38
  371. #define PP_KEYSPEC 39
  372. #define PP_ENUMEX_SIGNING_PROT 40
  373. #define CRYPT_FIRST 1
  374. #define CRYPT_NEXT 2
  375. #define CRYPT_SGC_ENUM 4
  376. #define CRYPT_IMPL_HARDWARE 1
  377. #define CRYPT_IMPL_SOFTWARE 2
  378. #define CRYPT_IMPL_MIXED 3
  379. #define CRYPT_IMPL_UNKNOWN 4
  380. #define CRYPT_IMPL_REMOVABLE 8
  381. // key storage flags
  382. #define CRYPT_SEC_DESCR 0x00000001
  383. #define CRYPT_PSTORE 0x00000002
  384. #define CRYPT_UI_PROMPT 0x00000004
  385. // protocol flags
  386. #define CRYPT_FLAG_PCT1 0x0001
  387. #define CRYPT_FLAG_SSL2 0x0002
  388. #define CRYPT_FLAG_SSL3 0x0004
  389. #define CRYPT_FLAG_TLS1 0x0008
  390. #define CRYPT_FLAG_IPSEC 0x0010
  391. #define CRYPT_FLAG_SIGNING 0x0020
  392. // SGC flags
  393. #define CRYPT_SGC 0x0001
  394. #define CRYPT_FASTSGC 0x0002
  395. //
  396. // CryptSetProvParam
  397. //
  398. #define PP_CLIENT_HWND 1
  399. #define PP_CONTEXT_INFO 11
  400. #define PP_KEYEXCHANGE_KEYSIZE 12
  401. #define PP_SIGNATURE_KEYSIZE 13
  402. #define PP_KEYEXCHANGE_ALG 14
  403. #define PP_SIGNATURE_ALG 15
  404. #define PP_DELETEKEY 24
  405. #define PROV_RSA_FULL 1
  406. #define PROV_RSA_SIG 2
  407. #define PROV_DSS 3
  408. #define PROV_FORTEZZA 4
  409. #define PROV_MS_EXCHANGE 5
  410. #define PROV_SSL 6
  411. #define PROV_RSA_SCHANNEL 12
  412. #define PROV_DSS_DH 13
  413. #define PROV_EC_ECDSA_SIG 14
  414. #define PROV_EC_ECNRA_SIG 15
  415. #define PROV_EC_ECDSA_FULL 16
  416. #define PROV_EC_ECNRA_FULL 17
  417. #define PROV_DH_SCHANNEL 18
  418. #define PROV_SPYRUS_LYNKS 20
  419. #define PROV_RNG 21
  420. #define PROV_INTEL_SEC 22
  421. #define PROV_REPLACE_OWF 23
  422. #define PROV_RSA_AES 24
  423. //
  424. // STT defined Providers
  425. //
  426. #define PROV_STT_MER 7
  427. #define PROV_STT_ACQ 8
  428. #define PROV_STT_BRND 9
  429. #define PROV_STT_ROOT 10
  430. #define PROV_STT_ISS 11
  431. //
  432. // Provider friendly names
  433. //
  434. #define MS_DEF_PROV_A "Microsoft Base Cryptographic Provider v1.0"
  435. #define MS_DEF_PROV_W L"Microsoft Base Cryptographic Provider v1.0"
  436. #ifdef UNICODE
  437. #define MS_DEF_PROV MS_DEF_PROV_W
  438. #else
  439. #define MS_DEF_PROV MS_DEF_PROV_A
  440. #endif
  441. #define MS_ENHANCED_PROV_A "Microsoft Enhanced Cryptographic Provider v1.0"
  442. #define MS_ENHANCED_PROV_W L"Microsoft Enhanced Cryptographic Provider v1.0"
  443. #ifdef UNICODE
  444. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_W
  445. #else
  446. #define MS_ENHANCED_PROV MS_ENHANCED_PROV_A
  447. #endif
  448. #define MS_STRONG_PROV_A "Microsoft Strong Cryptographic Provider"
  449. #define MS_STRONG_PROV_W L"Microsoft Strong Cryptographic Provider"
  450. #ifdef UNICODE
  451. #define MS_STRONG_PROV MS_STRONG_PROV_W
  452. #else
  453. #define MS_STRONG_PROV MS_STRONG_PROV_A
  454. #endif
  455. #define MS_DEF_RSA_SIG_PROV_A "Microsoft RSA Signature Cryptographic Provider"
  456. #define MS_DEF_RSA_SIG_PROV_W L"Microsoft RSA Signature Cryptographic Provider"
  457. #ifdef UNICODE
  458. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_W
  459. #else
  460. #define MS_DEF_RSA_SIG_PROV MS_DEF_RSA_SIG_PROV_A
  461. #endif
  462. #define MS_DEF_RSA_SCHANNEL_PROV_A "Microsoft RSA SChannel Cryptographic Provider"
  463. #define MS_DEF_RSA_SCHANNEL_PROV_W L"Microsoft RSA SChannel Cryptographic Provider"
  464. #ifdef UNICODE
  465. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_W
  466. #else
  467. #define MS_DEF_RSA_SCHANNEL_PROV MS_DEF_RSA_SCHANNEL_PROV_A
  468. #endif
  469. #define MS_DEF_DSS_PROV_A "Microsoft Base DSS Cryptographic Provider"
  470. #define MS_DEF_DSS_PROV_W L"Microsoft Base DSS Cryptographic Provider"
  471. #ifdef UNICODE
  472. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_W
  473. #else
  474. #define MS_DEF_DSS_PROV MS_DEF_DSS_PROV_A
  475. #endif
  476. #define MS_DEF_DSS_DH_PROV_A "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  477. #define MS_DEF_DSS_DH_PROV_W L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  478. #ifdef UNICODE
  479. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_W
  480. #else
  481. #define MS_DEF_DSS_DH_PROV MS_DEF_DSS_DH_PROV_A
  482. #endif
  483. #define MS_ENH_DSS_DH_PROV_A "Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  484. #define MS_ENH_DSS_DH_PROV_W L"Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider"
  485. #ifdef UNICODE
  486. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_W
  487. #else
  488. #define MS_ENH_DSS_DH_PROV MS_ENH_DSS_DH_PROV_A
  489. #endif
  490. #define MS_DEF_DH_SCHANNEL_PROV_A "Microsoft DH SChannel Cryptographic Provider"
  491. #define MS_DEF_DH_SCHANNEL_PROV_W L"Microsoft DH SChannel Cryptographic Provider"
  492. #ifdef UNICODE
  493. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_W
  494. #else
  495. #define MS_DEF_DH_SCHANNEL_PROV MS_DEF_DH_SCHANNEL_PROV_A
  496. #endif
  497. #define MS_SCARD_PROV_A "Microsoft Base Smart Card Crypto Provider"
  498. #define MS_SCARD_PROV_W L"Microsoft Base Smart Card Crypto Provider"
  499. #ifdef UNICODE
  500. #define MS_SCARD_PROV MS_SCARD_PROV_W
  501. #else
  502. #define MS_SCARD_PROV MS_SCARD_PROV_A
  503. #endif
  504. #define MS_ENH_RSA_AES_PROV_A "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
  505. #define MS_ENH_RSA_AES_PROV_W L"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
  506. #ifdef UNICODE
  507. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_W
  508. #else
  509. #define MS_ENH_RSA_AES_PROV MS_ENH_RSA_AES_PROV_A
  510. #endif
  511. #define MAXUIDLEN 64
  512. // Exponentiation Offload Reg Location
  513. #define EXPO_OFFLOAD_REG_VALUE "ExpoOffload"
  514. #define EXPO_OFFLOAD_FUNC_NAME "OffloadModExpo"
  515. //
  516. // Registry key in which the following private key-related
  517. // values are created.
  518. //
  519. #define szKEY_CRYPTOAPI_PRIVATE_KEY_OPTIONS \
  520. "Software\\Policies\\Microsoft\\Cryptography"
  521. //
  522. // Registry value for controlling Data Protection API (DPAPI) UI settings.
  523. //
  524. #define szFORCE_KEY_PROTECTION "ForceKeyProtection"
  525. #define dwFORCE_KEY_PROTECTION_DISABLED 0x0
  526. #define dwFORCE_KEY_PROTECTION_USER_SELECT 0x1
  527. #define dwFORCE_KEY_PROTECTION_HIGH 0x2
  528. //
  529. // Registry values for enabling and controlling the caching (and timeout)
  530. // of private keys. This feature is useful only for UI-protected private
  531. // of private keys. This feature is intended for UI-protected private
  532. // keys.
  533. //
  534. // Note that in Windows 2000 and later, private keys, once read from storage,
  535. // are cached in the associated HCRYPTPROV structure for subsequent use.
  536. //
  537. // In .NET Server and XP SP1, new key caching behavior is available. Keys
  538. // In Server 2003 and XP SP1, new key caching behavior is available. Keys
  539. // that have been read from storage and cached may now be considered "stale"
  540. // if a period of time has elapsed since the key was last used. This forces
  541. // the key to be re-read from storage (which will make the DPAPI UI appear
  542. // again).
  543. //
  544. // Optional Key Timeouts:
  545. //
  546. // In Windows Server 2003, XP SP1, and later, new key caching behavior is
  547. // available. Keys that have been read from storage and cached per-context
  548. // may now be considered "stale" if a period of time has elapsed since the
  549. // key was last used. This forces the key to be re-read from storage (which
  550. // will make the Data Protection API dialog appear again if the key is
  551. // UI-protected).
  552. //
  553. // To enable the new behavior, create the registry DWORD value
  554. // szKEY_CACHE_ENABLED and set it to 1. The registry DWORD value
  555. // szKEY_CACHE_SECONDS must also be created and set to the number of seconds
  556. // that a cached private key may still be considered usable.
  557. //
  558. #define szKEY_CACHE_ENABLED "CachePrivateKeys"
  559. #define szKEY_CACHE_SECONDS "PrivateKeyLifetimeSeconds"
  560. //
  561. // In platforms later than (and not including) Windows Server 2003, including
  562. // XP SP2, private keys are always cached for a period of time per-process,
  563. // even when not being used in any context.
  564. //
  565. // The differences between the process-wide caching settings described below
  566. // and the Optional Key Timeouts described above are subtle.
  567. //
  568. // - The Optional Key Timeout policy is applied only when an attempt is made
  569. // to use a specific private key with an open context handle (HCRYPTPROV).
  570. // If szKEY_CACHE_SECONDS have elapsed since the key was last used, the
  571. // private key will be re-read from storage.
  572. //
  573. // - The Cache Purge Interval policy, below, is applied whenever any
  574. // non-ephemeral private key is used or read from storage. If
  575. // szPRIV_KEY_CACHE_PURGE_INTERVAL_SECONDS have elapsed since the last
  576. // purge occurred, all cached keys that have not been referenced since the
  577. // last purge will be removed from the cache.
  578. //
  579. // If a private key that is purged from the cache is currently
  580. // referenced in an open context, then the key will be re-read from storage
  581. // the next time an attempt is made to use it (via any context).
  582. //
  583. // The following two registry DWORD values control this behavior.
  584. //
  585. //
  586. // Registry value for controlling the maximum number of persisted
  587. // (non-ephemeral) private keys that can be cached per-process. If the cache
  588. // fills up, keys will be replaced on a least-recently-used basis. If the
  589. // maximum number of cached keys is set to zero, no keys will be globally
  590. // cached.
  591. //
  592. #define szPRIV_KEY_CACHE_MAX_ITEMS "PrivKeyCacheMaxItems"
  593. #define cPRIV_KEY_CACHE_MAX_ITEMS_DEFAULT 20
  594. //
  595. // Registry value for controlling the interval at which the private key
  596. // cache is proactively purged of outdated keys.
  597. //
  598. #define szPRIV_KEY_CACHE_PURGE_INTERVAL_SECONDS "PrivKeyCachePurgeIntervalSeconds"
  599. #define cPRIV_KEY_CACHE_PURGE_INTERVAL_SECONDS_DEFAULT 86400 // 1 day
  600. #define CUR_BLOB_VERSION 2
  601. // structure for use with CryptSetKeyParam for CMS keys
  602. // DO NOT USE THIS STRUCTURE!!!!!
  603. typedef struct _CMS_KEY_INFO {
  604. DWORD dwVersion; // sizeof(CMS_KEY_INFO)
  605. ALG_ID Algid; // algorithmm id for the key to be converted
  606. BYTE *pbOID; // pointer to OID to hash in with Z
  607. DWORD cbOID; // length of OID to hash in with Z
  608. } CMS_KEY_INFO, *PCMS_KEY_INFO;
  609. // structure for use with CryptSetHashParam with CALG_HMAC
  610. typedef struct _HMAC_Info {
  611. ALG_ID HashAlgid;
  612. BYTE *pbInnerString;
  613. DWORD cbInnerString;
  614. BYTE *pbOuterString;
  615. DWORD cbOuterString;
  616. } HMAC_INFO, *PHMAC_INFO;
  617. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  618. typedef struct _SCHANNEL_ALG {
  619. DWORD dwUse;
  620. ALG_ID Algid;
  621. DWORD cBits;
  622. DWORD dwFlags;
  623. DWORD dwReserved;
  624. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  625. // uses of algortihms for SCHANNEL_ALG structure
  626. #define SCHANNEL_MAC_KEY 0x00000000
  627. #define SCHANNEL_ENC_KEY 0x00000001
  628. // uses of dwFlags SCHANNEL_ALG structure
  629. #define INTERNATIONAL_USAGE 0x00000001
  630. typedef struct _PROV_ENUMALGS {
  631. ALG_ID aiAlgid;
  632. DWORD dwBitLen;
  633. DWORD dwNameLen;
  634. CHAR szName[20];
  635. } PROV_ENUMALGS;
  636. typedef struct _PROV_ENUMALGS_EX {
  637. ALG_ID aiAlgid;
  638. DWORD dwDefaultLen;
  639. DWORD dwMinLen;
  640. DWORD dwMaxLen;
  641. DWORD dwProtocols;
  642. DWORD dwNameLen;
  643. CHAR szName[20];
  644. DWORD dwLongNameLen;
  645. CHAR szLongName[40];
  646. } PROV_ENUMALGS_EX;
  647. typedef struct _PUBLICKEYSTRUC {
  648. BYTE bType;
  649. BYTE bVersion;
  650. WORD reserved;
  651. ALG_ID aiKeyAlg;
  652. } BLOBHEADER, PUBLICKEYSTRUC;
  653. typedef struct _RSAPUBKEY {
  654. DWORD magic; // Has to be RSA1
  655. DWORD bitlen; // # of bits in modulus
  656. DWORD pubexp; // public exponent
  657. // Modulus data follows
  658. } RSAPUBKEY;
  659. typedef struct _PUBKEY {
  660. DWORD magic;
  661. DWORD bitlen; // # of bits in modulus
  662. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  663. typedef struct _DSSSEED {
  664. DWORD counter;
  665. BYTE seed[20];
  666. } DSSSEED;
  667. typedef struct _PUBKEYVER3 {
  668. DWORD magic;
  669. DWORD bitlenP; // # of bits in prime modulus
  670. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  671. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  672. DSSSEED DSSSeed;
  673. } DHPUBKEY_VER3, DSSPUBKEY_VER3;
  674. typedef struct _PRIVKEYVER3 {
  675. DWORD magic;
  676. DWORD bitlenP; // # of bits in prime modulus
  677. DWORD bitlenQ; // # of bits in prime q, 0 if not available
  678. DWORD bitlenJ; // # of bits in (p-1)/q, 0 if not available
  679. DWORD bitlenX; // # of bits in X
  680. DSSSEED DSSSeed;
  681. } DHPRIVKEY_VER3, DSSPRIVKEY_VER3;
  682. typedef struct _KEY_TYPE_SUBTYPE {
  683. DWORD dwKeySpec;
  684. GUID Type;
  685. GUID Subtype;
  686. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  687. typedef struct _CERT_FORTEZZA_DATA_PROP {
  688. unsigned char SerialNumber[8];
  689. int CertIndex;
  690. unsigned char CertLabel[36];
  691. } CERT_FORTEZZA_DATA_PROP;
  692. //+-------------------------------------------------------------------------
  693. // CRYPTOAPI BLOB definitions
  694. //--------------------------------------------------------------------------
  695. typedef struct _CRYPTOAPI_BLOB {
  696. DWORD cbData;
  697. BYTE *pbData;
  698. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  699. CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  700. CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  701. CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  702. CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  703. CERT_BLOB, *PCERT_BLOB,
  704. CRL_BLOB, *PCRL_BLOB,
  705. DATA_BLOB, *PDATA_BLOB,
  706. CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  707. CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  708. CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  709. CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  710. CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  711. // structure for use with CryptSetKeyParam for CMS keys
  712. typedef struct _CMS_DH_KEY_INFO {
  713. DWORD dwVersion; // sizeof(CMS_DH_KEY_INFO)
  714. ALG_ID Algid; // algorithmm id for the key to be converted
  715. LPSTR pszContentEncObjId; // pointer to OID to hash in with Z
  716. CRYPT_DATA_BLOB PubInfo; // OPTIONAL - public information
  717. void *pReserved; // reserved - should be NULL
  718. } CMS_DH_KEY_INFO, *PCMS_DH_KEY_INFO;
  719. WINADVAPI
  720. BOOL
  721. WINAPI
  722. CryptAcquireContextA(
  723. HCRYPTPROV *phProv,
  724. LPCSTR szContainer,
  725. LPCSTR szProvider,
  726. DWORD dwProvType,
  727. DWORD dwFlags
  728. );
  729. WINADVAPI
  730. BOOL
  731. WINAPI
  732. CryptAcquireContextW(
  733. HCRYPTPROV *phProv,
  734. LPCWSTR szContainer,
  735. LPCWSTR szProvider,
  736. DWORD dwProvType,
  737. DWORD dwFlags
  738. );
  739. #ifdef UNICODE
  740. #define CryptAcquireContext CryptAcquireContextW
  741. #else
  742. #define CryptAcquireContext CryptAcquireContextA
  743. #endif // !UNICODE
  744. WINADVAPI
  745. BOOL
  746. WINAPI
  747. CryptReleaseContext(
  748. HCRYPTPROV hProv,
  749. DWORD dwFlags
  750. );
  751. WINADVAPI
  752. BOOL
  753. WINAPI
  754. CryptGenKey(
  755. HCRYPTPROV hProv,
  756. ALG_ID Algid,
  757. DWORD dwFlags,
  758. HCRYPTKEY *phKey
  759. );
  760. WINADVAPI
  761. BOOL
  762. WINAPI
  763. CryptDeriveKey(
  764. HCRYPTPROV hProv,
  765. ALG_ID Algid,
  766. HCRYPTHASH hBaseData,
  767. DWORD dwFlags,
  768. HCRYPTKEY *phKey
  769. );
  770. WINADVAPI
  771. BOOL
  772. WINAPI
  773. CryptDestroyKey(
  774. HCRYPTKEY hKey
  775. );
  776. WINADVAPI
  777. BOOL
  778. WINAPI
  779. CryptSetKeyParam(
  780. HCRYPTKEY hKey,
  781. DWORD dwParam,
  782. CONST BYTE *pbData,
  783. DWORD dwFlags
  784. );
  785. WINADVAPI
  786. BOOL
  787. WINAPI
  788. CryptGetKeyParam(
  789. HCRYPTKEY hKey,
  790. DWORD dwParam,
  791. BYTE *pbData,
  792. DWORD *pdwDataLen,
  793. DWORD dwFlags
  794. );
  795. WINADVAPI
  796. BOOL
  797. WINAPI
  798. CryptSetHashParam(
  799. HCRYPTHASH hHash,
  800. DWORD dwParam,
  801. CONST BYTE *pbData,
  802. DWORD dwFlags
  803. );
  804. WINADVAPI
  805. BOOL
  806. WINAPI
  807. CryptGetHashParam(
  808. HCRYPTHASH hHash,
  809. DWORD dwParam,
  810. BYTE *pbData,
  811. DWORD *pdwDataLen,
  812. DWORD dwFlags
  813. );
  814. WINADVAPI
  815. BOOL
  816. WINAPI
  817. CryptSetProvParam(
  818. HCRYPTPROV hProv,
  819. DWORD dwParam,
  820. CONST BYTE *pbData,
  821. DWORD dwFlags
  822. );
  823. WINADVAPI
  824. BOOL
  825. WINAPI
  826. CryptGetProvParam(
  827. HCRYPTPROV hProv,
  828. DWORD dwParam,
  829. BYTE *pbData,
  830. DWORD *pdwDataLen,
  831. DWORD dwFlags
  832. );
  833. WINADVAPI
  834. BOOL
  835. WINAPI
  836. CryptGenRandom(
  837. HCRYPTPROV hProv,
  838. DWORD dwLen,
  839. BYTE *pbBuffer
  840. );
  841. WINADVAPI
  842. BOOL
  843. WINAPI
  844. CryptGetUserKey(
  845. HCRYPTPROV hProv,
  846. DWORD dwKeySpec,
  847. HCRYPTKEY *phUserKey
  848. );
  849. WINADVAPI
  850. BOOL
  851. WINAPI
  852. CryptExportKey(
  853. HCRYPTKEY hKey,
  854. HCRYPTKEY hExpKey,
  855. DWORD dwBlobType,
  856. DWORD dwFlags,
  857. BYTE *pbData,
  858. DWORD *pdwDataLen
  859. );
  860. WINADVAPI
  861. BOOL
  862. WINAPI
  863. CryptImportKey(
  864. HCRYPTPROV hProv,
  865. CONST BYTE *pbData,
  866. DWORD dwDataLen,
  867. HCRYPTKEY hPubKey,
  868. DWORD dwFlags,
  869. HCRYPTKEY *phKey
  870. );
  871. WINADVAPI
  872. BOOL
  873. WINAPI
  874. CryptEncrypt(
  875. HCRYPTKEY hKey,
  876. HCRYPTHASH hHash,
  877. BOOL Final,
  878. DWORD dwFlags,
  879. BYTE *pbData,
  880. DWORD *pdwDataLen,
  881. DWORD dwBufLen
  882. );
  883. WINADVAPI
  884. BOOL
  885. WINAPI
  886. CryptDecrypt(
  887. HCRYPTKEY hKey,
  888. HCRYPTHASH hHash,
  889. BOOL Final,
  890. DWORD dwFlags,
  891. BYTE *pbData,
  892. DWORD *pdwDataLen
  893. );
  894. WINADVAPI
  895. BOOL
  896. WINAPI
  897. CryptCreateHash(
  898. HCRYPTPROV hProv,
  899. ALG_ID Algid,
  900. HCRYPTKEY hKey,
  901. DWORD dwFlags,
  902. HCRYPTHASH *phHash
  903. );
  904. WINADVAPI
  905. BOOL
  906. WINAPI
  907. CryptHashData(
  908. HCRYPTHASH hHash,
  909. CONST BYTE *pbData,
  910. DWORD dwDataLen,
  911. DWORD dwFlags
  912. );
  913. WINADVAPI
  914. BOOL
  915. WINAPI
  916. CryptHashSessionKey(
  917. HCRYPTHASH hHash,
  918. HCRYPTKEY hKey,
  919. DWORD dwFlags
  920. );
  921. WINADVAPI
  922. BOOL
  923. WINAPI
  924. CryptDestroyHash(
  925. HCRYPTHASH hHash
  926. );
  927. WINADVAPI
  928. BOOL
  929. WINAPI
  930. CryptSignHashA(
  931. HCRYPTHASH hHash,
  932. DWORD dwKeySpec,
  933. LPCSTR szDescription,
  934. DWORD dwFlags,
  935. BYTE *pbSignature,
  936. DWORD *pdwSigLen
  937. );
  938. WINADVAPI
  939. BOOL
  940. WINAPI
  941. CryptSignHashW(
  942. HCRYPTHASH hHash,
  943. DWORD dwKeySpec,
  944. LPCWSTR szDescription,
  945. DWORD dwFlags,
  946. BYTE *pbSignature,
  947. DWORD *pdwSigLen
  948. );
  949. #ifdef UNICODE
  950. #define CryptSignHash CryptSignHashW
  951. #else
  952. #define CryptSignHash CryptSignHashA
  953. #endif // !UNICODE
  954. WINADVAPI
  955. BOOL
  956. WINAPI
  957. CryptVerifySignatureA(
  958. HCRYPTHASH hHash,
  959. CONST BYTE *pbSignature,
  960. DWORD dwSigLen,
  961. HCRYPTKEY hPubKey,
  962. LPCSTR szDescription,
  963. DWORD dwFlags
  964. );
  965. WINADVAPI
  966. BOOL
  967. WINAPI
  968. CryptVerifySignatureW(
  969. HCRYPTHASH hHash,
  970. CONST BYTE *pbSignature,
  971. DWORD dwSigLen,
  972. HCRYPTKEY hPubKey,
  973. LPCWSTR szDescription,
  974. DWORD dwFlags
  975. );
  976. #ifdef UNICODE
  977. #define CryptVerifySignature CryptVerifySignatureW
  978. #else
  979. #define CryptVerifySignature CryptVerifySignatureA
  980. #endif // !UNICODE
  981. WINADVAPI
  982. BOOL
  983. WINAPI
  984. CryptSetProviderA(
  985. LPCSTR pszProvName,
  986. DWORD dwProvType
  987. );
  988. WINADVAPI
  989. BOOL
  990. WINAPI
  991. CryptSetProviderW(
  992. LPCWSTR pszProvName,
  993. DWORD dwProvType
  994. );
  995. #ifdef UNICODE
  996. #define CryptSetProvider CryptSetProviderW
  997. #else
  998. #define CryptSetProvider CryptSetProviderA
  999. #endif // !UNICODE
  1000. WINADVAPI
  1001. BOOL
  1002. WINAPI
  1003. CryptSetProviderExA(
  1004. LPCSTR pszProvName,
  1005. DWORD dwProvType,
  1006. DWORD *pdwReserved,
  1007. DWORD dwFlags
  1008. );
  1009. WINADVAPI
  1010. BOOL
  1011. WINAPI
  1012. CryptSetProviderExW(
  1013. LPCWSTR pszProvName,
  1014. DWORD dwProvType,
  1015. DWORD *pdwReserved,
  1016. DWORD dwFlags
  1017. );
  1018. #ifdef UNICODE
  1019. #define CryptSetProviderEx CryptSetProviderExW
  1020. #else
  1021. #define CryptSetProviderEx CryptSetProviderExA
  1022. #endif // !UNICODE
  1023. WINADVAPI
  1024. BOOL
  1025. WINAPI
  1026. CryptGetDefaultProviderA(
  1027. DWORD dwProvType,
  1028. DWORD *pdwReserved,
  1029. DWORD dwFlags,
  1030. LPSTR pszProvName,
  1031. DWORD *pcbProvName
  1032. );
  1033. WINADVAPI
  1034. BOOL
  1035. WINAPI
  1036. CryptGetDefaultProviderW(
  1037. DWORD dwProvType,
  1038. DWORD *pdwReserved,
  1039. DWORD dwFlags,
  1040. LPWSTR pszProvName,
  1041. DWORD *pcbProvName
  1042. );
  1043. #ifdef UNICODE
  1044. #define CryptGetDefaultProvider CryptGetDefaultProviderW
  1045. #else
  1046. #define CryptGetDefaultProvider CryptGetDefaultProviderA
  1047. #endif // !UNICODE
  1048. WINADVAPI
  1049. BOOL
  1050. WINAPI
  1051. CryptEnumProviderTypesA(
  1052. DWORD dwIndex,
  1053. DWORD *pdwReserved,
  1054. DWORD dwFlags,
  1055. DWORD *pdwProvType,
  1056. LPSTR szTypeName,
  1057. DWORD *pcbTypeName
  1058. );
  1059. WINADVAPI
  1060. BOOL
  1061. WINAPI
  1062. CryptEnumProviderTypesW(
  1063. DWORD dwIndex,
  1064. DWORD *pdwReserved,
  1065. DWORD dwFlags,
  1066. DWORD *pdwProvType,
  1067. LPWSTR szTypeName,
  1068. DWORD *pcbTypeName
  1069. );
  1070. #ifdef UNICODE
  1071. #define CryptEnumProviderTypes CryptEnumProviderTypesW
  1072. #else
  1073. #define CryptEnumProviderTypes CryptEnumProviderTypesA
  1074. #endif // !UNICODE
  1075. WINADVAPI
  1076. BOOL
  1077. WINAPI
  1078. CryptEnumProvidersA(
  1079. DWORD dwIndex,
  1080. DWORD *pdwReserved,
  1081. DWORD dwFlags,
  1082. DWORD *pdwProvType,
  1083. LPSTR szProvName,
  1084. DWORD *pcbProvName
  1085. );
  1086. WINADVAPI
  1087. BOOL
  1088. WINAPI
  1089. CryptEnumProvidersW(
  1090. DWORD dwIndex,
  1091. DWORD *pdwReserved,
  1092. DWORD dwFlags,
  1093. DWORD *pdwProvType,
  1094. LPWSTR szProvName,
  1095. DWORD *pcbProvName
  1096. );
  1097. #ifdef UNICODE
  1098. #define CryptEnumProviders CryptEnumProvidersW
  1099. #else
  1100. #define CryptEnumProviders CryptEnumProvidersA
  1101. #endif // !UNICODE
  1102. WINADVAPI
  1103. BOOL
  1104. WINAPI
  1105. CryptContextAddRef(
  1106. HCRYPTPROV hProv,
  1107. DWORD *pdwReserved,
  1108. DWORD dwFlags
  1109. );
  1110. WINADVAPI
  1111. BOOL
  1112. WINAPI
  1113. CryptDuplicateKey(
  1114. HCRYPTKEY hKey,
  1115. DWORD *pdwReserved,
  1116. DWORD dwFlags,
  1117. HCRYPTKEY *phKey
  1118. );
  1119. WINADVAPI
  1120. BOOL
  1121. WINAPI
  1122. CryptDuplicateHash(
  1123. HCRYPTHASH hHash,
  1124. DWORD *pdwReserved,
  1125. DWORD dwFlags,
  1126. HCRYPTHASH *phHash
  1127. );
  1128. typedef struct {
  1129. DWORD dwVersion;
  1130. ALG_ID algId;
  1131. DWORD dwMinKeyLength;
  1132. DWORD dwMaxKeyLength;
  1133. DWORD dwRequiredFlags;
  1134. DWORD dwDisallowedFlags;
  1135. } _CRYPT_KEY_LIMITS_V01;
  1136. typedef _CRYPT_KEY_LIMITS_V01 CRYPT_KEY_LIMITS, *PCRYPT_KEY_LIMITS;
  1137. // Request Flag definitions
  1138. #define CRYPTLIMIT_USING_PCT 0x0001
  1139. #define CRYPTLIMIT_USING_SGC 0x0002
  1140. WINADVAPI
  1141. BOOL
  1142. WINAPI
  1143. CryptGetLocalKeyLimits(
  1144. IN ALG_ID algId,
  1145. IN DWORD dwFlags,
  1146. OUT PCRYPT_KEY_LIMITS pLimits,
  1147. IN OUT LPDWORD cbLimitLength);
  1148. //+-------------------------------------------------------------------------
  1149. // In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  1150. // overall bit length is cbData * 8 - cUnusedBits.
  1151. //--------------------------------------------------------------------------
  1152. typedef struct _CRYPT_BIT_BLOB {
  1153. DWORD cbData;
  1154. BYTE *pbData;
  1155. DWORD cUnusedBits;
  1156. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  1157. //+-------------------------------------------------------------------------
  1158. // Type used for any algorithm
  1159. //
  1160. // Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  1161. // algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  1162. //--------------------------------------------------------------------------
  1163. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  1164. LPSTR pszObjId;
  1165. CRYPT_OBJID_BLOB Parameters;
  1166. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  1167. // Following are the definitions of various algorithm object identifiers
  1168. // RSA
  1169. #define szOID_RSA "1.2.840.113549"
  1170. #define szOID_PKCS "1.2.840.113549.1"
  1171. #define szOID_RSA_HASH "1.2.840.113549.2"
  1172. #define szOID_RSA_ENCRYPT "1.2.840.113549.3"
  1173. #define szOID_PKCS_1 "1.2.840.113549.1.1"
  1174. #define szOID_PKCS_2 "1.2.840.113549.1.2"
  1175. #define szOID_PKCS_3 "1.2.840.113549.1.3"
  1176. #define szOID_PKCS_4 "1.2.840.113549.1.4"
  1177. #define szOID_PKCS_5 "1.2.840.113549.1.5"
  1178. #define szOID_PKCS_6 "1.2.840.113549.1.6"
  1179. #define szOID_PKCS_7 "1.2.840.113549.1.7"
  1180. #define szOID_PKCS_8 "1.2.840.113549.1.8"
  1181. #define szOID_PKCS_9 "1.2.840.113549.1.9"
  1182. #define szOID_PKCS_10 "1.2.840.113549.1.10"
  1183. #define szOID_PKCS_12 "1.2.840.113549.1.12"
  1184. #define szOID_RSA_RSA "1.2.840.113549.1.1.1"
  1185. #define szOID_RSA_MD2RSA "1.2.840.113549.1.1.2"
  1186. #define szOID_RSA_MD4RSA "1.2.840.113549.1.1.3"
  1187. #define szOID_RSA_MD5RSA "1.2.840.113549.1.1.4"
  1188. #define szOID_RSA_SHA1RSA "1.2.840.113549.1.1.5"
  1189. #define szOID_RSA_SETOAEP_RSA "1.2.840.113549.1.1.6"
  1190. #define szOID_RSA_DH "1.2.840.113549.1.3.1"
  1191. #define szOID_RSA_data "1.2.840.113549.1.7.1"
  1192. #define szOID_RSA_signedData "1.2.840.113549.1.7.2"
  1193. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  1194. #define szOID_RSA_signEnvData "1.2.840.113549.1.7.4"
  1195. #define szOID_RSA_digestedData "1.2.840.113549.1.7.5"
  1196. #define szOID_RSA_hashedData "1.2.840.113549.1.7.5"
  1197. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  1198. #define szOID_RSA_emailAddr "1.2.840.113549.1.9.1"
  1199. #define szOID_RSA_unstructName "1.2.840.113549.1.9.2"
  1200. #define szOID_RSA_contentType "1.2.840.113549.1.9.3"
  1201. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  1202. #define szOID_RSA_signingTime "1.2.840.113549.1.9.5"
  1203. #define szOID_RSA_counterSign "1.2.840.113549.1.9.6"
  1204. #define szOID_RSA_challengePwd "1.2.840.113549.1.9.7"
  1205. #define szOID_RSA_unstructAddr "1.2.840.113549.1.9.8"
  1206. #define szOID_RSA_extCertAttrs "1.2.840.113549.1.9.9"
  1207. #define szOID_RSA_certExtensions "1.2.840.113549.1.9.14"
  1208. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  1209. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  1210. #define szOID_RSA_SMIMEalg "1.2.840.113549.1.9.16.3"
  1211. #define szOID_RSA_SMIMEalgESDH "1.2.840.113549.1.9.16.3.5"
  1212. #define szOID_RSA_SMIMEalgCMS3DESwrap "1.2.840.113549.1.9.16.3.6"
  1213. #define szOID_RSA_SMIMEalgCMSRC2wrap "1.2.840.113549.1.9.16.3.7"
  1214. #define szOID_RSA_MD2 "1.2.840.113549.2.2"
  1215. #define szOID_RSA_MD4 "1.2.840.113549.2.4"
  1216. #define szOID_RSA_MD5 "1.2.840.113549.2.5"
  1217. #define szOID_RSA_RC2CBC "1.2.840.113549.3.2"
  1218. #define szOID_RSA_RC4 "1.2.840.113549.3.4"
  1219. #define szOID_RSA_DES_EDE3_CBC "1.2.840.113549.3.7"
  1220. #define szOID_RSA_RC5_CBCPad "1.2.840.113549.3.9"
  1221. #define szOID_ANSI_X942 "1.2.840.10046"
  1222. #define szOID_ANSI_X942_DH "1.2.840.10046.2.1"
  1223. #define szOID_X957 "1.2.840.10040"
  1224. #define szOID_X957_DSA "1.2.840.10040.4.1"
  1225. #define szOID_X957_SHA1DSA "1.2.840.10040.4.3"
  1226. // ITU-T UsefulDefinitions
  1227. #define szOID_DS "2.5"
  1228. #define szOID_DSALG "2.5.8"
  1229. #define szOID_DSALG_CRPT "2.5.8.1"
  1230. #define szOID_DSALG_HASH "2.5.8.2"
  1231. #define szOID_DSALG_SIGN "2.5.8.3"
  1232. #define szOID_DSALG_RSA "2.5.8.1.1"
  1233. // NIST OSE Implementors' Workshop (OIW)
  1234. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1235. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1236. #define szOID_OIW "1.3.14"
  1237. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1238. #define szOID_OIWSEC "1.3.14.3.2"
  1239. #define szOID_OIWSEC_md4RSA "1.3.14.3.2.2"
  1240. #define szOID_OIWSEC_md5RSA "1.3.14.3.2.3"
  1241. #define szOID_OIWSEC_md4RSA2 "1.3.14.3.2.4"
  1242. #define szOID_OIWSEC_desECB "1.3.14.3.2.6"
  1243. #define szOID_OIWSEC_desCBC "1.3.14.3.2.7"
  1244. #define szOID_OIWSEC_desOFB "1.3.14.3.2.8"
  1245. #define szOID_OIWSEC_desCFB "1.3.14.3.2.9"
  1246. #define szOID_OIWSEC_desMAC "1.3.14.3.2.10"
  1247. #define szOID_OIWSEC_rsaSign "1.3.14.3.2.11"
  1248. #define szOID_OIWSEC_dsa "1.3.14.3.2.12"
  1249. #define szOID_OIWSEC_shaDSA "1.3.14.3.2.13"
  1250. #define szOID_OIWSEC_mdc2RSA "1.3.14.3.2.14"
  1251. #define szOID_OIWSEC_shaRSA "1.3.14.3.2.15"
  1252. #define szOID_OIWSEC_dhCommMod "1.3.14.3.2.16"
  1253. #define szOID_OIWSEC_desEDE "1.3.14.3.2.17"
  1254. #define szOID_OIWSEC_sha "1.3.14.3.2.18"
  1255. #define szOID_OIWSEC_mdc2 "1.3.14.3.2.19"
  1256. #define szOID_OIWSEC_dsaComm "1.3.14.3.2.20"
  1257. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1258. #define szOID_OIWSEC_rsaXchg "1.3.14.3.2.22"
  1259. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1260. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1261. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1262. #define szOID_OIWSEC_sha1 "1.3.14.3.2.26"
  1263. #define szOID_OIWSEC_dsaSHA1 "1.3.14.3.2.27"
  1264. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1265. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1266. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1267. #define szOID_OIWDIR "1.3.14.7.2"
  1268. #define szOID_OIWDIR_CRPT "1.3.14.7.2.1"
  1269. #define szOID_OIWDIR_HASH "1.3.14.7.2.2"
  1270. #define szOID_OIWDIR_SIGN "1.3.14.7.2.3"
  1271. #define szOID_OIWDIR_md2 "1.3.14.7.2.2.1"
  1272. #define szOID_OIWDIR_md2RSA "1.3.14.7.2.3.1"
  1273. // INFOSEC Algorithms
  1274. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1275. #define szOID_INFOSEC "2.16.840.1.101.2.1"
  1276. #define szOID_INFOSEC_sdnsSignature "2.16.840.1.101.2.1.1.1"
  1277. #define szOID_INFOSEC_mosaicSignature "2.16.840.1.101.2.1.1.2"
  1278. #define szOID_INFOSEC_sdnsConfidentiality "2.16.840.1.101.2.1.1.3"
  1279. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1280. #define szOID_INFOSEC_sdnsIntegrity "2.16.840.1.101.2.1.1.5"
  1281. #define szOID_INFOSEC_mosaicIntegrity "2.16.840.1.101.2.1.1.6"
  1282. #define szOID_INFOSEC_sdnsTokenProtection "2.16.840.1.101.2.1.1.7"
  1283. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1284. #define szOID_INFOSEC_sdnsKeyManagement "2.16.840.1.101.2.1.1.9"
  1285. #define szOID_INFOSEC_mosaicKeyManagement "2.16.840.1.101.2.1.1.10"
  1286. #define szOID_INFOSEC_sdnsKMandSig "2.16.840.1.101.2.1.1.11"
  1287. #define szOID_INFOSEC_mosaicKMandSig "2.16.840.1.101.2.1.1.12"
  1288. #define szOID_INFOSEC_SuiteASignature "2.16.840.1.101.2.1.1.13"
  1289. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1290. #define szOID_INFOSEC_SuiteAIntegrity "2.16.840.1.101.2.1.1.15"
  1291. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1292. #define szOID_INFOSEC_SuiteAKeyManagement "2.16.840.1.101.2.1.1.17"
  1293. #define szOID_INFOSEC_SuiteAKMandSig "2.16.840.1.101.2.1.1.18"
  1294. #define szOID_INFOSEC_mosaicUpdatedSig "2.16.840.1.101.2.1.1.19"
  1295. #define szOID_INFOSEC_mosaicKMandUpdSig "2.16.840.1.101.2.1.1.20"
  1296. #define szOID_INFOSEC_mosaicUpdatedInteg "2.16.840.1.101.2.1.1.21"
  1297. typedef struct _CRYPT_OBJID_TABLE {
  1298. DWORD dwAlgId;
  1299. LPCSTR pszObjId;
  1300. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1301. //+-------------------------------------------------------------------------
  1302. // PKCS #1 HashInfo (DigestInfo)
  1303. //--------------------------------------------------------------------------
  1304. typedef struct _CRYPT_HASH_INFO {
  1305. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  1306. CRYPT_HASH_BLOB Hash;
  1307. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1308. //+-------------------------------------------------------------------------
  1309. // Type used for an extension to an encoded content
  1310. //
  1311. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1312. //--------------------------------------------------------------------------
  1313. typedef struct _CERT_EXTENSION {
  1314. LPSTR pszObjId;
  1315. BOOL fCritical;
  1316. CRYPT_OBJID_BLOB Value;
  1317. } CERT_EXTENSION, *PCERT_EXTENSION;
  1318. //+-------------------------------------------------------------------------
  1319. // AttributeTypeValue
  1320. //
  1321. // Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1322. //--------------------------------------------------------------------------
  1323. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1324. LPSTR pszObjId;
  1325. CRYPT_OBJID_BLOB Value;
  1326. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1327. //+-------------------------------------------------------------------------
  1328. // Attributes
  1329. //
  1330. // Where the Value's PATTR_BLOBs are in their encoded representation.
  1331. //--------------------------------------------------------------------------
  1332. typedef struct _CRYPT_ATTRIBUTE {
  1333. LPSTR pszObjId;
  1334. DWORD cValue;
  1335. PCRYPT_ATTR_BLOB rgValue;
  1336. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1337. typedef struct _CRYPT_ATTRIBUTES {
  1338. IN DWORD cAttr;
  1339. IN PCRYPT_ATTRIBUTE rgAttr;
  1340. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1341. //+-------------------------------------------------------------------------
  1342. // Attributes making up a Relative Distinguished Name (CERT_RDN)
  1343. //
  1344. // The interpretation of the Value depends on the dwValueType.
  1345. // See below for a list of the types.
  1346. //--------------------------------------------------------------------------
  1347. typedef struct _CERT_RDN_ATTR {
  1348. LPSTR pszObjId;
  1349. DWORD dwValueType;
  1350. CERT_RDN_VALUE_BLOB Value;
  1351. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1352. //+-------------------------------------------------------------------------
  1353. // CERT_RDN attribute Object Identifiers
  1354. //--------------------------------------------------------------------------
  1355. // Labeling attribute types:
  1356. #define szOID_COMMON_NAME "2.5.4.3" // case-ignore string
  1357. #define szOID_SUR_NAME "2.5.4.4" // case-ignore string
  1358. #define szOID_DEVICE_SERIAL_NUMBER "2.5.4.5" // printable string
  1359. // Geographic attribute types:
  1360. #define szOID_COUNTRY_NAME "2.5.4.6" // printable 2char string
  1361. #define szOID_LOCALITY_NAME "2.5.4.7" // case-ignore string
  1362. #define szOID_STATE_OR_PROVINCE_NAME "2.5.4.8" // case-ignore string
  1363. #define szOID_STREET_ADDRESS "2.5.4.9" // case-ignore string
  1364. // Organizational attribute types:
  1365. #define szOID_ORGANIZATION_NAME "2.5.4.10" // case-ignore string
  1366. #define szOID_ORGANIZATIONAL_UNIT_NAME "2.5.4.11" // case-ignore string
  1367. #define szOID_TITLE "2.5.4.12" // case-ignore string
  1368. // Explanatory attribute types:
  1369. #define szOID_DESCRIPTION "2.5.4.13" // case-ignore string
  1370. #define szOID_SEARCH_GUIDE "2.5.4.14"
  1371. #define szOID_BUSINESS_CATEGORY "2.5.4.15" // case-ignore string
  1372. // Postal addressing attribute types:
  1373. #define szOID_POSTAL_ADDRESS "2.5.4.16"
  1374. #define szOID_POSTAL_CODE "2.5.4.17" // case-ignore string
  1375. #define szOID_POST_OFFICE_BOX "2.5.4.18" // case-ignore string
  1376. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1377. // Telecommunications addressing attribute types:
  1378. #define szOID_TELEPHONE_NUMBER "2.5.4.20" // telephone number
  1379. #define szOID_TELEX_NUMBER "2.5.4.21"
  1380. #define szOID_TELETEXT_TERMINAL_IDENTIFIER "2.5.4.22"
  1381. #define szOID_FACSIMILE_TELEPHONE_NUMBER "2.5.4.23"
  1382. #define szOID_X21_ADDRESS "2.5.4.24" // numeric string
  1383. #define szOID_INTERNATIONAL_ISDN_NUMBER "2.5.4.25" // numeric string
  1384. #define szOID_REGISTERED_ADDRESS "2.5.4.26"
  1385. #define szOID_DESTINATION_INDICATOR "2.5.4.27" // printable string
  1386. // Preference attribute types:
  1387. #define szOID_PREFERRED_DELIVERY_METHOD "2.5.4.28"
  1388. // OSI application attribute types:
  1389. #define szOID_PRESENTATION_ADDRESS "2.5.4.29"
  1390. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1391. // Relational application attribute types:
  1392. #define szOID_MEMBER "2.5.4.31"
  1393. #define szOID_OWNER "2.5.4.32"
  1394. #define szOID_ROLE_OCCUPANT "2.5.4.33"
  1395. #define szOID_SEE_ALSO "2.5.4.34"
  1396. // Security attribute types:
  1397. #define szOID_USER_PASSWORD "2.5.4.35"
  1398. #define szOID_USER_CERTIFICATE "2.5.4.36"
  1399. #define szOID_CA_CERTIFICATE "2.5.4.37"
  1400. #define szOID_AUTHORITY_REVOCATION_LIST "2.5.4.38"
  1401. #define szOID_CERTIFICATE_REVOCATION_LIST "2.5.4.39"
  1402. #define szOID_CROSS_CERTIFICATE_PAIR "2.5.4.40"
  1403. // Undocumented attribute types???
  1404. //#define szOID_??? "2.5.4.41"
  1405. #define szOID_GIVEN_NAME "2.5.4.42" // case-ignore string
  1406. #define szOID_INITIALS "2.5.4.43" // case-ignore string
  1407. // The DN Qualifier attribute type specifies disambiguating information to add
  1408. // to the relative distinguished name of an entry. It is intended to be used
  1409. // for entries held in multiple DSAs which would otherwise have the same name,
  1410. // and that its value be the same in a given DSA for all entries to which
  1411. // the information has been added.
  1412. #define szOID_DN_QUALIFIER "2.5.4.46"
  1413. // Pilot user attribute types:
  1414. #define szOID_DOMAIN_COMPONENT "0.9.2342.19200300.100.1.25" // IA5, UTF8 string
  1415. // used for PKCS 12 attributes
  1416. #define szOID_PKCS_12_FRIENDLY_NAME_ATTR "1.2.840.113549.1.9.20"
  1417. #define szOID_PKCS_12_LOCAL_KEY_ID "1.2.840.113549.1.9.21"
  1418. #define szOID_PKCS_12_KEY_PROVIDER_NAME_ATTR "1.3.6.1.4.1.311.17.1"
  1419. #define szOID_LOCAL_MACHINE_KEYSET "1.3.6.1.4.1.311.17.2"
  1420. //+-------------------------------------------------------------------------
  1421. // Microsoft CERT_RDN attribute Object Identifiers
  1422. //--------------------------------------------------------------------------
  1423. // Special RDN containing the KEY_ID. Its value type is CERT_RDN_OCTET_STRING.
  1424. #define szOID_KEYID_RDN "1.3.6.1.4.1.311.10.7.1"
  1425. //+-------------------------------------------------------------------------
  1426. // CERT_RDN Attribute Value Types
  1427. //
  1428. // For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1429. // representation. Otherwise, its an array of bytes.
  1430. //
  1431. // For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1432. // necessarily the number of elements in the string. For instance,
  1433. // RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1434. // RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1435. //
  1436. // A RDN_UTF8_STRING is an array of UNICODE characters (cbData == charCnt *2).
  1437. // These UNICODE characters are encoded as UTF8 8 bit characters.
  1438. //
  1439. // For CertDecodeName, two 0 bytes are always appended to the end of the
  1440. // string (ensures a CHAR or WCHAR string is null terminated).
  1441. // These added 0 bytes are't included in the BLOB.cbData.
  1442. //--------------------------------------------------------------------------
  1443. #define CERT_RDN_ANY_TYPE 0
  1444. #define CERT_RDN_ENCODED_BLOB 1
  1445. #define CERT_RDN_OCTET_STRING 2
  1446. #define CERT_RDN_NUMERIC_STRING 3
  1447. #define CERT_RDN_PRINTABLE_STRING 4
  1448. #define CERT_RDN_TELETEX_STRING 5
  1449. #define CERT_RDN_T61_STRING 5
  1450. #define CERT_RDN_VIDEOTEX_STRING 6
  1451. #define CERT_RDN_IA5_STRING 7
  1452. #define CERT_RDN_GRAPHIC_STRING 8
  1453. #define CERT_RDN_VISIBLE_STRING 9
  1454. #define CERT_RDN_ISO646_STRING 9
  1455. #define CERT_RDN_GENERAL_STRING 10
  1456. #define CERT_RDN_UNIVERSAL_STRING 11
  1457. #define CERT_RDN_INT4_STRING 11
  1458. #define CERT_RDN_BMP_STRING 12
  1459. #define CERT_RDN_UNICODE_STRING 12
  1460. #define CERT_RDN_UTF8_STRING 13
  1461. #define CERT_RDN_TYPE_MASK 0x000000FF
  1462. #define CERT_RDN_FLAGS_MASK 0xFF000000
  1463. //+-------------------------------------------------------------------------
  1464. // Flags that can be or'ed with the above Value Type when encoding/decoding
  1465. //--------------------------------------------------------------------------
  1466. // For encoding: when set, CERT_RDN_T61_STRING is selected instead of
  1467. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1468. #define CERT_RDN_ENABLE_T61_UNICODE_FLAG 0x80000000
  1469. // For encoding: when set, CERT_RDN_UTF8_STRING is selected instead of
  1470. // CERT_RDN_UNICODE_STRING.
  1471. #define CERT_RDN_ENABLE_UTF8_UNICODE_FLAG 0x20000000
  1472. // For encoding: when set, the characters aren't checked to see if they
  1473. // are valid for the Value Type.
  1474. #define CERT_RDN_DISABLE_CHECK_TYPE_FLAG 0x40000000
  1475. // For decoding: by default, CERT_RDN_T61_STRING values are initially decoded
  1476. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  1477. // Setting this flag skips the initial attempt to decode as UTF8.
  1478. #define CERT_RDN_DISABLE_IE4_UTF8_FLAG 0x01000000
  1479. // Macro to check that the dwValueType is a character string and not an
  1480. // encoded blob or octet string
  1481. #define IS_CERT_RDN_CHAR_STRING(X) \
  1482. (((X) & CERT_RDN_TYPE_MASK) >= CERT_RDN_NUMERIC_STRING)
  1483. //+-------------------------------------------------------------------------
  1484. // A CERT_RDN consists of an array of the above attributes
  1485. //--------------------------------------------------------------------------
  1486. typedef struct _CERT_RDN {
  1487. DWORD cRDNAttr;
  1488. PCERT_RDN_ATTR rgRDNAttr;
  1489. } CERT_RDN, *PCERT_RDN;
  1490. //+-------------------------------------------------------------------------
  1491. // Information stored in a subject's or issuer's name. The information
  1492. // is represented as an array of the above RDNs.
  1493. //--------------------------------------------------------------------------
  1494. typedef struct _CERT_NAME_INFO {
  1495. DWORD cRDN;
  1496. PCERT_RDN rgRDN;
  1497. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1498. //+-------------------------------------------------------------------------
  1499. // Name attribute value without the Object Identifier
  1500. //
  1501. // The interpretation of the Value depends on the dwValueType.
  1502. // See above for a list of the types.
  1503. //--------------------------------------------------------------------------
  1504. typedef struct _CERT_NAME_VALUE {
  1505. DWORD dwValueType;
  1506. CERT_RDN_VALUE_BLOB Value;
  1507. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1508. //+-------------------------------------------------------------------------
  1509. // Public Key Info
  1510. //
  1511. // The PublicKey is the encoded representation of the information as it is
  1512. // stored in the bit string
  1513. //--------------------------------------------------------------------------
  1514. typedef struct _CERT_PUBLIC_KEY_INFO {
  1515. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1516. CRYPT_BIT_BLOB PublicKey;
  1517. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1518. #define CERT_RSA_PUBLIC_KEY_OBJID szOID_RSA_RSA
  1519. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN szOID_RSA_RSA
  1520. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG szOID_RSA_RSA
  1521. //+-------------------------------------------------------------------------
  1522. // structure that contains all the information in a PKCS#8 PrivateKeyInfo
  1523. //--------------------------------------------------------------------------
  1524. typedef struct _CRYPT_PRIVATE_KEY_INFO{
  1525. DWORD Version;
  1526. CRYPT_ALGORITHM_IDENTIFIER Algorithm;
  1527. CRYPT_DER_BLOB PrivateKey;
  1528. PCRYPT_ATTRIBUTES pAttributes;
  1529. } CRYPT_PRIVATE_KEY_INFO, *PCRYPT_PRIVATE_KEY_INFO;
  1530. //+-------------------------------------------------------------------------
  1531. // structure that contains all the information in a PKCS#8
  1532. // EncryptedPrivateKeyInfo
  1533. //--------------------------------------------------------------------------
  1534. typedef struct _CRYPT_ENCRYPTED_PRIVATE_KEY_INFO{
  1535. CRYPT_ALGORITHM_IDENTIFIER EncryptionAlgorithm;
  1536. CRYPT_DATA_BLOB EncryptedPrivateKey;
  1537. } CRYPT_ENCRYPTED_PRIVATE_KEY_INFO, *PCRYPT_ENCRYPTED_PRIVATE_KEY_INFO;
  1538. //+-------------------------------------------------------------------------
  1539. // this callback is given when an EncryptedProvateKeyInfo structure is
  1540. // encountered during ImportPKCS8. the caller is then expected to decrypt
  1541. // the private key and hand back the decrypted contents.
  1542. //
  1543. // the parameters are:
  1544. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1545. // EncryptedPrivateKey - the encrypted private key blob
  1546. // pClearTextKey - a buffer to receive the clear text
  1547. // cbClearTextKey - the number of bytes of the pClearTextKey buffer
  1548. // note the if this is zero then this should be
  1549. // filled in with the size required to decrypt the
  1550. // key into, and pClearTextKey should be ignored
  1551. // pVoidDecryptFunc - this is the pVoid that was passed into the call
  1552. // and is preserved and passed back as context
  1553. //+-------------------------------------------------------------------------
  1554. typedef BOOL (CALLBACK *PCRYPT_DECRYPT_PRIVATE_KEY_FUNC)(
  1555. CRYPT_ALGORITHM_IDENTIFIER Algorithm,
  1556. CRYPT_DATA_BLOB EncryptedPrivateKey,
  1557. BYTE *pbClearTextKey,
  1558. DWORD *pcbClearTextKey,
  1559. LPVOID pVoidDecryptFunc);
  1560. //+-------------------------------------------------------------------------
  1561. // this callback is given when creating a PKCS8 EncryptedPrivateKeyInfo.
  1562. // The caller is then expected to encrypt the private key and hand back
  1563. // the encrypted contents.
  1564. //
  1565. // the parameters are:
  1566. // Algorithm - the algorithm used to encrypt the PrivateKeyInfo
  1567. // pClearTextPrivateKey - the cleartext private key to be encrypted
  1568. // pbEncryptedKey - the output encrypted private key blob
  1569. // cbEncryptedKey - the number of bytes of the pbEncryptedKey buffer
  1570. // note the if this is zero then this should be
  1571. // filled in with the size required to encrypt the
  1572. // key into, and pbEncryptedKey should be ignored
  1573. // pVoidEncryptFunc - this is the pVoid that was passed into the call
  1574. // and is preserved and passed back as context
  1575. //+-------------------------------------------------------------------------
  1576. typedef BOOL (CALLBACK *PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC)(
  1577. CRYPT_ALGORITHM_IDENTIFIER* pAlgorithm,
  1578. CRYPT_DATA_BLOB* pClearTextPrivateKey,
  1579. BYTE *pbEncryptedKey,
  1580. DWORD *pcbEncryptedKey,
  1581. LPVOID pVoidEncryptFunc);
  1582. //+-------------------------------------------------------------------------
  1583. // this callback is given from the context of a ImportPKCS8 calls. the caller
  1584. // is then expected to hand back an HCRYPTPROV to receive the key being imported
  1585. //
  1586. // the parameters are:
  1587. // pPrivateKeyInfo - pointer to a CRYPT_PRIVATE_KEY_INFO structure which
  1588. // describes the key being imported
  1589. // EncryptedPrivateKey - the encrypted private key blob
  1590. // phCryptProv - a pointer to a HCRRYPTPROV to be filled in
  1591. // pVoidResolveFunc - this is the pVoidResolveFunc passed in by the caller in the
  1592. // CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS struct
  1593. //+-------------------------------------------------------------------------
  1594. typedef BOOL (CALLBACK *PCRYPT_RESOLVE_HCRYPTPROV_FUNC)(
  1595. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo,
  1596. HCRYPTPROV *phCryptProv,
  1597. LPVOID pVoidResolveFunc);
  1598. //+-------------------------------------------------------------------------
  1599. // this struct contains a PKCS8 private key and two pointers to callback
  1600. // functions, with a corresponding pVoids. the first callback is used to give
  1601. // the caller the opportunity to specify where the key is imported to. the callback
  1602. // passes the caller the algoroithm OID and key size to use in making the decision.
  1603. // the other callback is used to decrypt the private key if the PKCS8 contains an
  1604. // EncryptedPrivateKeyInfo. both pVoids are preserved and passed back to the caller
  1605. // in the respective callback
  1606. //+-------------------------------------------------------------------------
  1607. typedef struct _CRYPT_PKCS8_IMPORT_PARAMS{
  1608. CRYPT_DIGEST_BLOB PrivateKey; // PKCS8 blob
  1609. PCRYPT_RESOLVE_HCRYPTPROV_FUNC pResolvehCryptProvFunc; // optional
  1610. LPVOID pVoidResolveFunc; // optional
  1611. PCRYPT_DECRYPT_PRIVATE_KEY_FUNC pDecryptPrivateKeyFunc;
  1612. LPVOID pVoidDecryptFunc;
  1613. } CRYPT_PKCS8_IMPORT_PARAMS, *PCRYPT_PKCS8_IMPORT_PARAMS, CRYPT_PRIVATE_KEY_BLOB_AND_PARAMS, *PCRYPT_PRIVATE_KEY_BLOB_AND_PARAMS;
  1614. //+-------------------------------------------------------------------------
  1615. // this struct contains information identifying a private key and a pointer
  1616. // to a callback function, with a corresponding pVoid. The callback is used
  1617. // to encrypt the private key. If the pEncryptPrivateKeyFunc is NULL, the
  1618. // key will not be encrypted and an EncryptedPrivateKeyInfo will not be generated.
  1619. // The pVoid is preserved and passed back to the caller in the respective callback
  1620. //+-------------------------------------------------------------------------
  1621. typedef struct _CRYPT_PKCS8_EXPORT_PARAMS{
  1622. HCRYPTPROV hCryptProv;
  1623. DWORD dwKeySpec;
  1624. LPSTR pszPrivateKeyObjId;
  1625. PCRYPT_ENCRYPT_PRIVATE_KEY_FUNC pEncryptPrivateKeyFunc;
  1626. LPVOID pVoidEncryptFunc;
  1627. } CRYPT_PKCS8_EXPORT_PARAMS, *PCRYPT_PKCS8_EXPORT_PARAMS;
  1628. //+-------------------------------------------------------------------------
  1629. // Information stored in a certificate
  1630. //
  1631. // The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1632. // encoded representation of the information.
  1633. //--------------------------------------------------------------------------
  1634. typedef struct _CERT_INFO {
  1635. DWORD dwVersion;
  1636. CRYPT_INTEGER_BLOB SerialNumber;
  1637. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1638. CERT_NAME_BLOB Issuer;
  1639. FILETIME NotBefore;
  1640. FILETIME NotAfter;
  1641. CERT_NAME_BLOB Subject;
  1642. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1643. CRYPT_BIT_BLOB IssuerUniqueId;
  1644. CRYPT_BIT_BLOB SubjectUniqueId;
  1645. DWORD cExtension;
  1646. PCERT_EXTENSION rgExtension;
  1647. } CERT_INFO, *PCERT_INFO;
  1648. //+-------------------------------------------------------------------------
  1649. // Certificate versions
  1650. //--------------------------------------------------------------------------
  1651. #define CERT_V1 0
  1652. #define CERT_V2 1
  1653. #define CERT_V3 2
  1654. //+-------------------------------------------------------------------------
  1655. // Certificate Information Flags
  1656. //--------------------------------------------------------------------------
  1657. #define CERT_INFO_VERSION_FLAG 1
  1658. #define CERT_INFO_SERIAL_NUMBER_FLAG 2
  1659. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG 3
  1660. #define CERT_INFO_ISSUER_FLAG 4
  1661. #define CERT_INFO_NOT_BEFORE_FLAG 5
  1662. #define CERT_INFO_NOT_AFTER_FLAG 6
  1663. #define CERT_INFO_SUBJECT_FLAG 7
  1664. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG 8
  1665. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG 9
  1666. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG 10
  1667. #define CERT_INFO_EXTENSION_FLAG 11
  1668. //+-------------------------------------------------------------------------
  1669. // An entry in a CRL
  1670. //
  1671. // The Extension BLOBs are the encoded representation of the information.
  1672. //--------------------------------------------------------------------------
  1673. typedef struct _CRL_ENTRY {
  1674. CRYPT_INTEGER_BLOB SerialNumber;
  1675. FILETIME RevocationDate;
  1676. DWORD cExtension;
  1677. PCERT_EXTENSION rgExtension;
  1678. } CRL_ENTRY, *PCRL_ENTRY;
  1679. //+-------------------------------------------------------------------------
  1680. // Information stored in a CRL
  1681. //
  1682. // The Issuer, Algorithm and Extension BLOBs are the encoded
  1683. // representation of the information.
  1684. //--------------------------------------------------------------------------
  1685. typedef struct _CRL_INFO {
  1686. DWORD dwVersion;
  1687. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1688. CERT_NAME_BLOB Issuer;
  1689. FILETIME ThisUpdate;
  1690. FILETIME NextUpdate;
  1691. DWORD cCRLEntry;
  1692. PCRL_ENTRY rgCRLEntry;
  1693. DWORD cExtension;
  1694. PCERT_EXTENSION rgExtension;
  1695. } CRL_INFO, *PCRL_INFO;
  1696. //+-------------------------------------------------------------------------
  1697. // CRL versions
  1698. //--------------------------------------------------------------------------
  1699. #define CRL_V1 0
  1700. #define CRL_V2 1
  1701. //+-------------------------------------------------------------------------
  1702. // Information stored in a certificate request
  1703. //
  1704. // The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1705. // representation of the information.
  1706. //--------------------------------------------------------------------------
  1707. typedef struct _CERT_REQUEST_INFO {
  1708. DWORD dwVersion;
  1709. CERT_NAME_BLOB Subject;
  1710. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1711. DWORD cAttribute;
  1712. PCRYPT_ATTRIBUTE rgAttribute;
  1713. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1714. //+-------------------------------------------------------------------------
  1715. // Certificate Request versions
  1716. //--------------------------------------------------------------------------
  1717. #define CERT_REQUEST_V1 0
  1718. //+-------------------------------------------------------------------------
  1719. // Information stored in Netscape's Keygen request
  1720. //--------------------------------------------------------------------------
  1721. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1722. DWORD dwVersion;
  1723. CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
  1724. LPWSTR pwszChallengeString; // encoded as IA5
  1725. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1726. #define CERT_KEYGEN_REQUEST_V1 0
  1727. //+-------------------------------------------------------------------------
  1728. // Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1729. //
  1730. // The "to be signed" encoded content plus its signature. The ToBeSigned
  1731. // is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1732. // CERT_KEYGEN_REQUEST_INFO.
  1733. //--------------------------------------------------------------------------
  1734. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1735. CRYPT_DER_BLOB ToBeSigned;
  1736. CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
  1737. CRYPT_BIT_BLOB Signature;
  1738. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1739. //+-------------------------------------------------------------------------
  1740. // Certificate Trust List (CTL)
  1741. //--------------------------------------------------------------------------
  1742. //+-------------------------------------------------------------------------
  1743. // CTL Usage. Also used for EnhancedKeyUsage extension.
  1744. //--------------------------------------------------------------------------
  1745. typedef struct _CTL_USAGE {
  1746. DWORD cUsageIdentifier;
  1747. LPSTR *rgpszUsageIdentifier; // array of pszObjId
  1748. } CTL_USAGE, *PCTL_USAGE,
  1749. CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1750. //+-------------------------------------------------------------------------
  1751. // An entry in a CTL
  1752. //--------------------------------------------------------------------------
  1753. typedef struct _CTL_ENTRY {
  1754. CRYPT_DATA_BLOB SubjectIdentifier; // For example, its hash
  1755. DWORD cAttribute;
  1756. PCRYPT_ATTRIBUTE rgAttribute; // OPTIONAL
  1757. } CTL_ENTRY, *PCTL_ENTRY;
  1758. //+-------------------------------------------------------------------------
  1759. // Information stored in a CTL
  1760. //--------------------------------------------------------------------------
  1761. typedef struct _CTL_INFO {
  1762. DWORD dwVersion;
  1763. CTL_USAGE SubjectUsage;
  1764. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  1765. CRYPT_INTEGER_BLOB SequenceNumber; // OPTIONAL
  1766. FILETIME ThisUpdate;
  1767. FILETIME NextUpdate; // OPTIONAL
  1768. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  1769. DWORD cCTLEntry;
  1770. PCTL_ENTRY rgCTLEntry; // OPTIONAL
  1771. DWORD cExtension;
  1772. PCERT_EXTENSION rgExtension; // OPTIONAL
  1773. } CTL_INFO, *PCTL_INFO;
  1774. //+-------------------------------------------------------------------------
  1775. // CTL versions
  1776. //--------------------------------------------------------------------------
  1777. #define CTL_V1 0
  1778. //+-------------------------------------------------------------------------
  1779. // TimeStamp Request
  1780. //
  1781. // The pszTimeStamp is the OID for the Time type requested
  1782. // The pszContentType is the Content Type OID for the content, usually DATA
  1783. // The Content is a un-decoded blob
  1784. //--------------------------------------------------------------------------
  1785. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1786. LPSTR pszTimeStampAlgorithm; // pszObjId
  1787. LPSTR pszContentType; // pszObjId
  1788. CRYPT_OBJID_BLOB Content;
  1789. DWORD cAttribute;
  1790. PCRYPT_ATTRIBUTE rgAttribute;
  1791. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1792. //+-------------------------------------------------------------------------
  1793. // Name Value Attribute
  1794. //--------------------------------------------------------------------------
  1795. typedef struct _CRYPT_ENROLLMENT_NAME_VALUE_PAIR {
  1796. LPWSTR pwszName;
  1797. LPWSTR pwszValue;
  1798. } CRYPT_ENROLLMENT_NAME_VALUE_PAIR, * PCRYPT_ENROLLMENT_NAME_VALUE_PAIR;
  1799. //+-------------------------------------------------------------------------
  1800. // CSP Provider
  1801. //--------------------------------------------------------------------------
  1802. typedef struct _CRYPT_CSP_PROVIDER {
  1803. DWORD dwKeySpec;
  1804. LPWSTR pwszProviderName;
  1805. CRYPT_BIT_BLOB Signature;
  1806. } CRYPT_CSP_PROVIDER, * PCRYPT_CSP_PROVIDER;
  1807. //+-------------------------------------------------------------------------
  1808. // Certificate and Message encoding types
  1809. //
  1810. // The encoding type is a DWORD containing both the certificate and message
  1811. // encoding types. The certificate encoding type is stored in the LOWORD.
  1812. // The message encoding type is stored in the HIWORD. Some functions or
  1813. // structure fields require only one of the encoding types. The following
  1814. // naming convention is used to indicate which encoding type(s) are
  1815. // required:
  1816. // dwEncodingType (both encoding types are required)
  1817. // dwMsgAndCertEncodingType (both encoding types are required)
  1818. // dwMsgEncodingType (only msg encoding type is required)
  1819. // dwCertEncodingType (only cert encoding type is required)
  1820. //
  1821. // Its always acceptable to specify both.
  1822. //--------------------------------------------------------------------------
  1823. #define CERT_ENCODING_TYPE_MASK 0x0000FFFF
  1824. #define CMSG_ENCODING_TYPE_MASK 0xFFFF0000
  1825. #define GET_CERT_ENCODING_TYPE(X) (X & CERT_ENCODING_TYPE_MASK)
  1826. #define GET_CMSG_ENCODING_TYPE(X) (X & CMSG_ENCODING_TYPE_MASK)
  1827. #define CRYPT_ASN_ENCODING 0x00000001
  1828. #define CRYPT_NDR_ENCODING 0x00000002
  1829. #define X509_ASN_ENCODING 0x00000001
  1830. #define X509_NDR_ENCODING 0x00000002
  1831. #define PKCS_7_ASN_ENCODING 0x00010000
  1832. #define PKCS_7_NDR_ENCODING 0x00020000
  1833. //+-------------------------------------------------------------------------
  1834. // format the specified data structure according to the certificate
  1835. // encoding type.
  1836. //
  1837. // The default behavior of CryptFormatObject is to return single line
  1838. // display of the encoded data, that is, each subfield will be concatenated with
  1839. // a ", " on one line. If user prefers to display the data in multiple line,
  1840. // set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed
  1841. // on a seperate line.
  1842. //
  1843. // If there is no formatting routine installed or registered
  1844. // for the lpszStructType, the hex dump of the encoded BLOB will be returned.
  1845. // User can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.
  1846. //--------------------------------------------------------------------------
  1847. WINCRYPT32API
  1848. BOOL
  1849. WINAPI
  1850. CryptFormatObject(
  1851. IN DWORD dwCertEncodingType,
  1852. IN DWORD dwFormatType,
  1853. IN DWORD dwFormatStrType,
  1854. IN void *pFormatStruct,
  1855. IN LPCSTR lpszStructType,
  1856. IN const BYTE *pbEncoded,
  1857. IN DWORD cbEncoded,
  1858. OUT void *pbFormat,
  1859. IN OUT DWORD *pcbFormat
  1860. );
  1861. //-------------------------------------------------------------------------
  1862. // constants for dwFormatStrType of function CryptFormatObject
  1863. //-------------------------------------------------------------------------
  1864. #define CRYPT_FORMAT_STR_MULTI_LINE 0x0001
  1865. #define CRYPT_FORMAT_STR_NO_HEX 0x0010
  1866. //-------------------------------------------------------------------------
  1867. // constants for dwFormatType of function CryptFormatObject
  1868. // when format X509_NAME or X509_UNICODE_NAME
  1869. //-------------------------------------------------------------------------
  1870. // Just get the simple string
  1871. #define CRYPT_FORMAT_SIMPLE 0x0001
  1872. //Put an attribute name infront of the attribute
  1873. //such as "O=Microsoft,DN=xiaohs"
  1874. #define CRYPT_FORMAT_X509 0x0002
  1875. //Put an OID infront of the simple string, such as
  1876. //"2.5.4.22=Microsoft,2.5.4.3=xiaohs"
  1877. #define CRYPT_FORMAT_OID 0x0004
  1878. //Put a ";" between each RDN. The default is ","
  1879. #define CRYPT_FORMAT_RDN_SEMICOLON 0x0100
  1880. //Put a "\n" between each RDN.
  1881. #define CRYPT_FORMAT_RDN_CRLF 0x0200
  1882. //Unquote the DN value, which is quoated by default va the following
  1883. //rules: if the DN contains leading or trailing
  1884. //white space or one of the following characters: ",", "+", "=",
  1885. //""", "\n", "<", ">", "#" or ";". The quoting character is ".
  1886. //If the DN Value contains a " it is double quoted ("").
  1887. #define CRYPT_FORMAT_RDN_UNQUOTE 0x0400
  1888. //reverse the order of the RDNs before converting to the string
  1889. #define CRYPT_FORMAT_RDN_REVERSE 0x0800
  1890. //-------------------------------------------------------------------------
  1891. // contants dwFormatType of function CryptFormatObject when format a DN.:
  1892. //
  1893. // The following three values are defined in the section above:
  1894. // CRYPT_FORMAT_SIMPLE: Just a simple string
  1895. // such as "Microsoft+xiaohs+NT"
  1896. // CRYPT_FORMAT_X509 Put an attribute name infront of the attribute
  1897. // such as "O=Microsoft+xiaohs+NT"
  1898. //
  1899. // CRYPT_FORMAT_OID Put an OID infront of the simple string,
  1900. // such as "2.5.4.22=Microsoft+xiaohs+NT"
  1901. //
  1902. // Additional values are defined as following:
  1903. //----------------------------------------------------------------------------
  1904. //Put a "," between each value. Default is "+"
  1905. #define CRYPT_FORMAT_COMMA 0x1000
  1906. //Put a ";" between each value
  1907. #define CRYPT_FORMAT_SEMICOLON CRYPT_FORMAT_RDN_SEMICOLON
  1908. //Put a "\n" between each value
  1909. #define CRYPT_FORMAT_CRLF CRYPT_FORMAT_RDN_CRLF
  1910. //+-------------------------------------------------------------------------
  1911. // Encode / decode the specified data structure according to the certificate
  1912. // encoding type.
  1913. //
  1914. // See below for a list of the predefined data structures.
  1915. //--------------------------------------------------------------------------
  1916. typedef LPVOID (WINAPI *PFN_CRYPT_ALLOC)(
  1917. IN size_t cbSize
  1918. );
  1919. typedef VOID (WINAPI *PFN_CRYPT_FREE)(
  1920. IN LPVOID pv
  1921. );
  1922. typedef struct _CRYPT_ENCODE_PARA {
  1923. DWORD cbSize;
  1924. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1925. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1926. } CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
  1927. WINCRYPT32API
  1928. BOOL
  1929. WINAPI
  1930. CryptEncodeObjectEx(
  1931. IN DWORD dwCertEncodingType,
  1932. IN LPCSTR lpszStructType,
  1933. IN const void *pvStructInfo,
  1934. IN DWORD dwFlags,
  1935. IN OPTIONAL PCRYPT_ENCODE_PARA pEncodePara,
  1936. OUT void *pvEncoded,
  1937. IN OUT DWORD *pcbEncoded
  1938. );
  1939. WINCRYPT32API
  1940. BOOL
  1941. WINAPI
  1942. CryptEncodeObject(
  1943. IN DWORD dwCertEncodingType,
  1944. IN LPCSTR lpszStructType,
  1945. IN const void *pvStructInfo,
  1946. OUT BYTE *pbEncoded,
  1947. IN OUT DWORD *pcbEncoded
  1948. );
  1949. // By default the signature bytes are reversed. The following flag can
  1950. // be set to inhibit the byte reversal.
  1951. //
  1952. // This flag is applicable to
  1953. // X509_CERT_TO_BE_SIGNED
  1954. #define CRYPT_ENCODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  1955. // When the following flag is set the called encode function allocates
  1956. // memory for the encoded bytes. A pointer to the allocated bytes
  1957. // is returned in pvEncoded. If pEncodePara or pEncodePara->pfnAlloc is
  1958. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  1959. // be called to do the free. Otherwise, pEncodePara->pfnAlloc is called
  1960. // for the allocation.
  1961. //
  1962. // *pcbEncoded is ignored on input and updated with the length of the
  1963. // allocated, encoded bytes.
  1964. //
  1965. // If pfnAlloc is set, then, pfnFree should also be set.
  1966. #define CRYPT_ENCODE_ALLOC_FLAG 0x8000
  1967. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1968. // When set, CERT_RDN_T61_STRING is selected instead of
  1969. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF
  1970. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG \
  1971. CERT_RDN_ENABLE_T61_UNICODE_FLAG
  1972. // The following flag is applicable when encoding X509_UNICODE_NAME.
  1973. // When set, CERT_RDN_UTF8_STRING is selected instead of
  1974. // CERT_RDN_UNICODE_STRING.
  1975. #define CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG \
  1976. CERT_RDN_ENABLE_UTF8_UNICODE_FLAG
  1977. // The following flag is applicable when encoding X509_UNICODE_NAME,
  1978. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  1979. // When set, the characters aren't checked to see if they
  1980. // are valid for the specified Value Type.
  1981. #define CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG \
  1982. CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  1983. // The following flag is applicable when encoding the PKCS_SORTED_CTL. This
  1984. // flag should be set if the identifier for the TrustedSubjects is a hash,
  1985. // such as, MD5 or SHA1.
  1986. #define CRYPT_SORTED_CTL_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x10000
  1987. typedef struct _CRYPT_DECODE_PARA {
  1988. DWORD cbSize;
  1989. PFN_CRYPT_ALLOC pfnAlloc; // OPTIONAL
  1990. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  1991. } CRYPT_DECODE_PARA, *PCRYPT_DECODE_PARA;
  1992. WINCRYPT32API
  1993. BOOL
  1994. WINAPI
  1995. CryptDecodeObjectEx(
  1996. IN DWORD dwCertEncodingType,
  1997. IN LPCSTR lpszStructType,
  1998. IN const BYTE *pbEncoded,
  1999. IN DWORD cbEncoded,
  2000. IN DWORD dwFlags,
  2001. IN OPTIONAL PCRYPT_DECODE_PARA pDecodePara,
  2002. OUT OPTIONAL void *pvStructInfo,
  2003. IN OUT DWORD *pcbStructInfo
  2004. );
  2005. WINCRYPT32API
  2006. BOOL
  2007. WINAPI
  2008. CryptDecodeObject(
  2009. IN DWORD dwCertEncodingType,
  2010. IN LPCSTR lpszStructType,
  2011. IN const BYTE *pbEncoded,
  2012. IN DWORD cbEncoded,
  2013. IN DWORD dwFlags,
  2014. OUT void *pvStructInfo,
  2015. IN OUT DWORD *pcbStructInfo
  2016. );
  2017. // When the following flag is set the nocopy optimization is enabled.
  2018. // This optimization where appropriate, updates the pvStructInfo fields
  2019. // to point to content residing within pbEncoded instead of making a copy
  2020. // of and appending to pvStructInfo.
  2021. //
  2022. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  2023. #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  2024. // For CryptDecodeObject(), by default the pbEncoded is the "to be signed"
  2025. // plus its signature. Set the following flag, if pbEncoded points to only
  2026. // the "to be signed".
  2027. //
  2028. // This flag is applicable to
  2029. // X509_CERT_TO_BE_SIGNED
  2030. // X509_CERT_CRL_TO_BE_SIGNED
  2031. // X509_CERT_REQUEST_TO_BE_SIGNED
  2032. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2033. #define CRYPT_DECODE_TO_BE_SIGNED_FLAG 0x2
  2034. // When the following flag is set, the OID strings are allocated in
  2035. // crypt32.dll and shared instead of being copied into the returned
  2036. // data structure. This flag may be set if crypt32.dll isn't unloaded
  2037. // before the caller is unloaded.
  2038. #define CRYPT_DECODE_SHARE_OID_STRING_FLAG 0x4
  2039. // By default the signature bytes are reversed. The following flag can
  2040. // be set to inhibit the byte reversal.
  2041. //
  2042. // This flag is applicable to
  2043. // X509_CERT_TO_BE_SIGNED
  2044. #define CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG 0x8
  2045. // When the following flag is set the called decode function allocates
  2046. // memory for the decoded structure. A pointer to the allocated structure
  2047. // is returned in pvStructInfo. If pDecodePara or pDecodePara->pfnAlloc is
  2048. // NULL, then, LocalAlloc is called for the allocation and LocalFree must
  2049. // be called to do the free. Otherwise, pDecodePara->pfnAlloc is called
  2050. // for the allocation.
  2051. //
  2052. // *pcbStructInfo is ignored on input and updated with the length of the
  2053. // allocated, decoded structure.
  2054. //
  2055. // This flag may also be set in the CryptDecodeObject API. Since
  2056. // CryptDecodeObject doesn't take a pDecodePara, LocalAlloc is always
  2057. // called for the allocation which must be freed by calling LocalFree.
  2058. #define CRYPT_DECODE_ALLOC_FLAG 0x8000
  2059. // The following flag is applicable when decoding X509_UNICODE_NAME,
  2060. // X509_UNICODE_NAME_VALUE or X509_UNICODE_ANY_STRING.
  2061. // By default, CERT_RDN_T61_STRING values are initially decoded
  2062. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2063. // Setting this flag skips the initial attempt to decode as UTF8.
  2064. #define CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG \
  2065. CERT_RDN_DISABLE_IE4_UTF8_FLAG
  2066. //+-------------------------------------------------------------------------
  2067. // Predefined X509 certificate data structures that can be encoded / decoded.
  2068. //--------------------------------------------------------------------------
  2069. #define CRYPT_ENCODE_DECODE_NONE 0
  2070. #define X509_CERT ((LPCSTR) 1)
  2071. #define X509_CERT_TO_BE_SIGNED ((LPCSTR) 2)
  2072. #define X509_CERT_CRL_TO_BE_SIGNED ((LPCSTR) 3)
  2073. #define X509_CERT_REQUEST_TO_BE_SIGNED ((LPCSTR) 4)
  2074. #define X509_EXTENSIONS ((LPCSTR) 5)
  2075. #define X509_NAME_VALUE ((LPCSTR) 6)
  2076. #define X509_NAME ((LPCSTR) 7)
  2077. #define X509_PUBLIC_KEY_INFO ((LPCSTR) 8)
  2078. //+-------------------------------------------------------------------------
  2079. // Predefined X509 certificate extension data structures that can be
  2080. // encoded / decoded.
  2081. //--------------------------------------------------------------------------
  2082. #define X509_AUTHORITY_KEY_ID ((LPCSTR) 9)
  2083. #define X509_KEY_ATTRIBUTES ((LPCSTR) 10)
  2084. #define X509_KEY_USAGE_RESTRICTION ((LPCSTR) 11)
  2085. #define X509_ALTERNATE_NAME ((LPCSTR) 12)
  2086. #define X509_BASIC_CONSTRAINTS ((LPCSTR) 13)
  2087. #define X509_KEY_USAGE ((LPCSTR) 14)
  2088. #define X509_BASIC_CONSTRAINTS2 ((LPCSTR) 15)
  2089. #define X509_CERT_POLICIES ((LPCSTR) 16)
  2090. //+-------------------------------------------------------------------------
  2091. // Additional predefined data structures that can be encoded / decoded.
  2092. //--------------------------------------------------------------------------
  2093. #define PKCS_UTC_TIME ((LPCSTR) 17)
  2094. #define PKCS_TIME_REQUEST ((LPCSTR) 18)
  2095. #define RSA_CSP_PUBLICKEYBLOB ((LPCSTR) 19)
  2096. #define X509_UNICODE_NAME ((LPCSTR) 20)
  2097. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED ((LPCSTR) 21)
  2098. #define PKCS_ATTRIBUTE ((LPCSTR) 22)
  2099. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY ((LPCSTR) 23)
  2100. //+-------------------------------------------------------------------------
  2101. // Predefined primitive data structures that can be encoded / decoded.
  2102. //--------------------------------------------------------------------------
  2103. #define X509_UNICODE_NAME_VALUE ((LPCSTR) 24)
  2104. #define X509_ANY_STRING X509_NAME_VALUE
  2105. #define X509_UNICODE_ANY_STRING X509_UNICODE_NAME_VALUE
  2106. #define X509_OCTET_STRING ((LPCSTR) 25)
  2107. #define X509_BITS ((LPCSTR) 26)
  2108. #define X509_INTEGER ((LPCSTR) 27)
  2109. #define X509_MULTI_BYTE_INTEGER ((LPCSTR) 28)
  2110. #define X509_ENUMERATED ((LPCSTR) 29)
  2111. #define X509_CHOICE_OF_TIME ((LPCSTR) 30)
  2112. //+-------------------------------------------------------------------------
  2113. // More predefined X509 certificate extension data structures that can be
  2114. // encoded / decoded.
  2115. //--------------------------------------------------------------------------
  2116. #define X509_AUTHORITY_KEY_ID2 ((LPCSTR) 31)
  2117. #define X509_AUTHORITY_INFO_ACCESS ((LPCSTR) 32)
  2118. #define X509_CRL_REASON_CODE X509_ENUMERATED
  2119. #define PKCS_CONTENT_INFO ((LPCSTR) 33)
  2120. #define X509_SEQUENCE_OF_ANY ((LPCSTR) 34)
  2121. #define X509_CRL_DIST_POINTS ((LPCSTR) 35)
  2122. #define X509_ENHANCED_KEY_USAGE ((LPCSTR) 36)
  2123. #define PKCS_CTL ((LPCSTR) 37)
  2124. #define X509_MULTI_BYTE_UINT ((LPCSTR) 38)
  2125. #define X509_DSS_PUBLICKEY X509_MULTI_BYTE_UINT
  2126. #define X509_DSS_PARAMETERS ((LPCSTR) 39)
  2127. #define X509_DSS_SIGNATURE ((LPCSTR) 40)
  2128. #define PKCS_RC2_CBC_PARAMETERS ((LPCSTR) 41)
  2129. #define PKCS_SMIME_CAPABILITIES ((LPCSTR) 42)
  2130. //+-------------------------------------------------------------------------
  2131. // data structures for private keys
  2132. //--------------------------------------------------------------------------
  2133. #define PKCS_RSA_PRIVATE_KEY ((LPCSTR) 43)
  2134. #define PKCS_PRIVATE_KEY_INFO ((LPCSTR) 44)
  2135. #define PKCS_ENCRYPTED_PRIVATE_KEY_INFO ((LPCSTR) 45)
  2136. //+-------------------------------------------------------------------------
  2137. // certificate policy qualifier
  2138. //--------------------------------------------------------------------------
  2139. #define X509_PKIX_POLICY_QUALIFIER_USERNOTICE ((LPCSTR) 46)
  2140. //+-------------------------------------------------------------------------
  2141. // Diffie-Hellman Key Exchange
  2142. //--------------------------------------------------------------------------
  2143. #define X509_DH_PUBLICKEY X509_MULTI_BYTE_UINT
  2144. #define X509_DH_PARAMETERS ((LPCSTR) 47)
  2145. #define PKCS_ATTRIBUTES ((LPCSTR) 48)
  2146. #define PKCS_SORTED_CTL ((LPCSTR) 49)
  2147. //+-------------------------------------------------------------------------
  2148. // X942 Diffie-Hellman
  2149. //--------------------------------------------------------------------------
  2150. #define X942_DH_PARAMETERS ((LPCSTR) 50)
  2151. //+-------------------------------------------------------------------------
  2152. // The following is the same as X509_BITS, except before encoding,
  2153. // the bit length is decremented to exclude trailing zero bits.
  2154. //--------------------------------------------------------------------------
  2155. #define X509_BITS_WITHOUT_TRAILING_ZEROES ((LPCSTR) 51)
  2156. //+-------------------------------------------------------------------------
  2157. // X942 Diffie-Hellman Other Info
  2158. //--------------------------------------------------------------------------
  2159. #define X942_OTHER_INFO ((LPCSTR) 52)
  2160. #define X509_CERT_PAIR ((LPCSTR) 53)
  2161. #define X509_ISSUING_DIST_POINT ((LPCSTR) 54)
  2162. #define X509_NAME_CONSTRAINTS ((LPCSTR) 55)
  2163. #define X509_POLICY_MAPPINGS ((LPCSTR) 56)
  2164. #define X509_POLICY_CONSTRAINTS ((LPCSTR) 57)
  2165. #define X509_CROSS_CERT_DIST_POINTS ((LPCSTR) 58)
  2166. //+-------------------------------------------------------------------------
  2167. // Certificate Management Messages over CMS (CMC) Data Structures
  2168. //--------------------------------------------------------------------------
  2169. #define CMC_DATA ((LPCSTR) 59)
  2170. #define CMC_RESPONSE ((LPCSTR) 60)
  2171. #define CMC_STATUS ((LPCSTR) 61)
  2172. #define CMC_ADD_EXTENSIONS ((LPCSTR) 62)
  2173. #define CMC_ADD_ATTRIBUTES ((LPCSTR) 63)
  2174. //+-------------------------------------------------------------------------
  2175. // Certificate Template
  2176. //--------------------------------------------------------------------------
  2177. #define X509_CERTIFICATE_TEMPLATE ((LPCSTR) 64)
  2178. //+-------------------------------------------------------------------------
  2179. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2180. //--------------------------------------------------------------------------
  2181. #define PKCS7_SIGNER_INFO ((LPCSTR) 500)
  2182. //+-------------------------------------------------------------------------
  2183. // Predefined PKCS #7 data structures that can be encoded / decoded.
  2184. //--------------------------------------------------------------------------
  2185. #define CMS_SIGNER_INFO ((LPCSTR) 501)
  2186. //+-------------------------------------------------------------------------
  2187. // Predefined Software Publishing Credential (SPC) data structures that
  2188. // can be encoded / decoded.
  2189. //
  2190. // Predefined values: 2000 .. 2999
  2191. //
  2192. // See spc.h for value and data structure definitions.
  2193. //--------------------------------------------------------------------------
  2194. //+-------------------------------------------------------------------------
  2195. // Extension Object Identifiers
  2196. //--------------------------------------------------------------------------
  2197. #define szOID_AUTHORITY_KEY_IDENTIFIER "2.5.29.1"
  2198. #define szOID_KEY_ATTRIBUTES "2.5.29.2"
  2199. #define szOID_CERT_POLICIES_95 "2.5.29.3"
  2200. #define szOID_KEY_USAGE_RESTRICTION "2.5.29.4"
  2201. #define szOID_SUBJECT_ALT_NAME "2.5.29.7"
  2202. #define szOID_ISSUER_ALT_NAME "2.5.29.8"
  2203. #define szOID_BASIC_CONSTRAINTS "2.5.29.10"
  2204. #define szOID_KEY_USAGE "2.5.29.15"
  2205. #define szOID_PRIVATEKEY_USAGE_PERIOD "2.5.29.16"
  2206. #define szOID_BASIC_CONSTRAINTS2 "2.5.29.19"
  2207. #define szOID_CERT_POLICIES "2.5.29.32"
  2208. #define szOID_ANY_CERT_POLICY "2.5.29.32.0"
  2209. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  2210. #define szOID_SUBJECT_KEY_IDENTIFIER "2.5.29.14"
  2211. #define szOID_SUBJECT_ALT_NAME2 "2.5.29.17"
  2212. #define szOID_ISSUER_ALT_NAME2 "2.5.29.18"
  2213. #define szOID_CRL_REASON_CODE "2.5.29.21"
  2214. #define szOID_REASON_CODE_HOLD "2.5.29.23"
  2215. #define szOID_CRL_DIST_POINTS "2.5.29.31"
  2216. #define szOID_ENHANCED_KEY_USAGE "2.5.29.37"
  2217. // szOID_CRL_NUMBER -- Base CRLs only. Monotonically increasing sequence
  2218. // number for each CRL issued by a CA.
  2219. #define szOID_CRL_NUMBER "2.5.29.20"
  2220. // szOID_DELTA_CRL_INDICATOR -- Delta CRLs only. Marked critical.
  2221. // Contains the minimum base CRL Number that can be used with a delta CRL.
  2222. #define szOID_DELTA_CRL_INDICATOR "2.5.29.27"
  2223. #define szOID_ISSUING_DIST_POINT "2.5.29.28"
  2224. // szOID_FRESHEST_CRL -- Base CRLs only. Formatted identically to a CDP
  2225. // extension that holds URLs to fetch the delta CRL.
  2226. #define szOID_FRESHEST_CRL "2.5.29.46"
  2227. #define szOID_NAME_CONSTRAINTS "2.5.29.30"
  2228. // Note on 1/1/2000 szOID_POLICY_MAPPINGS was changed from "2.5.29.5"
  2229. #define szOID_POLICY_MAPPINGS "2.5.29.33"
  2230. #define szOID_LEGACY_POLICY_MAPPINGS "2.5.29.5"
  2231. #define szOID_POLICY_CONSTRAINTS "2.5.29.36"
  2232. // Microsoft PKCS10 Attributes
  2233. #define szOID_RENEWAL_CERTIFICATE "1.3.6.1.4.1.311.13.1"
  2234. #define szOID_ENROLLMENT_NAME_VALUE_PAIR "1.3.6.1.4.1.311.13.2.1"
  2235. #define szOID_ENROLLMENT_CSP_PROVIDER "1.3.6.1.4.1.311.13.2.2"
  2236. #define szOID_OS_VERSION "1.3.6.1.4.1.311.13.2.3"
  2237. //
  2238. // Extension contain certificate type
  2239. #define szOID_ENROLLMENT_AGENT "1.3.6.1.4.1.311.20.2.1"
  2240. // Internet Public Key Infrastructure (PKIX)
  2241. #define szOID_PKIX "1.3.6.1.5.5.7"
  2242. #define szOID_PKIX_PE "1.3.6.1.5.5.7.1"
  2243. #define szOID_AUTHORITY_INFO_ACCESS "1.3.6.1.5.5.7.1.1"
  2244. // Microsoft extensions or attributes
  2245. #define szOID_CERT_EXTENSIONS "1.3.6.1.4.1.311.2.1.14"
  2246. #define szOID_NEXT_UPDATE_LOCATION "1.3.6.1.4.1.311.10.2"
  2247. #define szOID_REMOVE_CERTIFICATE "1.3.6.1.4.1.311.10.8.1"
  2248. #define szOID_CROSS_CERT_DIST_POINTS "1.3.6.1.4.1.311.10.9.1"
  2249. // Microsoft PKCS #7 ContentType Object Identifiers
  2250. #define szOID_CTL "1.3.6.1.4.1.311.10.1"
  2251. // Microsoft Sorted CTL Extension Object Identifier
  2252. #define szOID_SORTED_CTL "1.3.6.1.4.1.311.10.1.1"
  2253. // serialized serial numbers for PRS
  2254. #ifndef szOID_SERIALIZED
  2255. #define szOID_SERIALIZED "1.3.6.1.4.1.311.10.3.3.1"
  2256. #endif
  2257. // UPN principal name in SubjectAltName
  2258. #ifndef szOID_NT_PRINCIPAL_NAME
  2259. #define szOID_NT_PRINCIPAL_NAME "1.3.6.1.4.1.311.20.2.3"
  2260. #endif
  2261. // Windows product update unauthenticated attribute
  2262. #ifndef szOID_PRODUCT_UPDATE
  2263. #define szOID_PRODUCT_UPDATE "1.3.6.1.4.1.311.31.1"
  2264. #endif
  2265. // CryptUI
  2266. #define szOID_ANY_APPLICATION_POLICY "1.3.6.1.4.1.311.10.12.1"
  2267. //+-------------------------------------------------------------------------
  2268. // Object Identifiers for use with Auto Enrollment
  2269. //--------------------------------------------------------------------------
  2270. #define szOID_AUTO_ENROLL_CTL_USAGE "1.3.6.1.4.1.311.20.1"
  2271. // Extension contain certificate type
  2272. #define szOID_ENROLL_CERTTYPE_EXTENSION "1.3.6.1.4.1.311.20.2"
  2273. #define szOID_CERT_MANIFOLD "1.3.6.1.4.1.311.20.3"
  2274. //+-------------------------------------------------------------------------
  2275. // Object Identifiers for use with the MS Certificate Server
  2276. //--------------------------------------------------------------------------
  2277. #ifndef szOID_CERTSRV_CA_VERSION
  2278. #define szOID_CERTSRV_CA_VERSION "1.3.6.1.4.1.311.21.1"
  2279. #endif
  2280. // szOID_CERTSRV_PREVIOUS_CERT_HASH -- Contains the sha1 hash of the previous
  2281. // version of the CA certificate.
  2282. #define szOID_CERTSRV_PREVIOUS_CERT_HASH "1.3.6.1.4.1.311.21.2"
  2283. // szOID_CRL_VIRTUAL_BASE -- Delta CRLs only. Contains the base CRL Number
  2284. // of the corresponding base CRL.
  2285. #define szOID_CRL_VIRTUAL_BASE "1.3.6.1.4.1.311.21.3"
  2286. // szOID_CRL_NEXT_PUBLISH -- Contains the time when the next CRL is expected
  2287. // to be published. This may be sooner than the CRL's NextUpdate field.
  2288. #define szOID_CRL_NEXT_PUBLISH "1.3.6.1.4.1.311.21.4"
  2289. // Enhanced Key Usage for CA encryption certificate
  2290. #define szOID_KP_CA_EXCHANGE "1.3.6.1.4.1.311.21.5"
  2291. // Enhanced Key Usage for key recovery agent certificate
  2292. #define szOID_KP_KEY_RECOVERY_AGENT "1.3.6.1.4.1.311.21.6"
  2293. // Certificate template extension (v2)
  2294. #define szOID_CERTIFICATE_TEMPLATE "1.3.6.1.4.1.311.21.7"
  2295. // The root oid for all enterprise specific oids
  2296. #define szOID_ENTERPRISE_OID_ROOT "1.3.6.1.4.1.311.21.8"
  2297. // Dummy signing Subject RDN
  2298. #define szOID_RDN_DUMMY_SIGNER "1.3.6.1.4.1.311.21.9"
  2299. // Application Policies extension -- same encoding as szOID_CERT_POLICIES
  2300. #define szOID_APPLICATION_CERT_POLICIES "1.3.6.1.4.1.311.21.10"
  2301. // Application Policy Mappings -- same encoding as szOID_POLICY_MAPPINGS
  2302. #define szOID_APPLICATION_POLICY_MAPPINGS "1.3.6.1.4.1.311.21.11"
  2303. // Application Policy Constraints -- same encoding as szOID_POLICY_CONSTRAINTS
  2304. #define szOID_APPLICATION_POLICY_CONSTRAINTS "1.3.6.1.4.1.311.21.12"
  2305. #define szOID_ARCHIVED_KEY_ATTR "1.3.6.1.4.1.311.21.13"
  2306. #define szOID_CRL_SELF_CDP "1.3.6.1.4.1.311.21.14"
  2307. // Requires all certificates below the root to have a non-empty intersecting
  2308. // issuance certificate policy usage.
  2309. #define szOID_REQUIRE_CERT_CHAIN_POLICY "1.3.6.1.4.1.311.21.15"
  2310. #define szOID_ARCHIVED_KEY_CERT_HASH "1.3.6.1.4.1.311.21.16"
  2311. #define szOID_ISSUED_CERT_HASH "1.3.6.1.4.1.311.21.17"
  2312. // Enhanced key usage for DS email replication
  2313. #define szOID_DS_EMAIL_REPLICATION "1.3.6.1.4.1.311.21.19"
  2314. #define szOID_REQUEST_CLIENT_INFO "1.3.6.1.4.1.311.21.20"
  2315. #define szOID_ENCRYPTED_KEY_HASH "1.3.6.1.4.1.311.21.21"
  2316. #define szOID_CERTSRV_CROSSCA_VERSION "1.3.6.1.4.1.311.21.22"
  2317. //+-------------------------------------------------------------------------
  2318. // Object Identifiers for use with the MS Directory Service
  2319. //--------------------------------------------------------------------------
  2320. #define szOID_NTDS_REPLICATION "1.3.6.1.4.1.311.25.1"
  2321. //+-------------------------------------------------------------------------
  2322. // Extension Object Identifiers (currently not implemented)
  2323. //--------------------------------------------------------------------------
  2324. #define szOID_SUBJECT_DIR_ATTRS "2.5.29.9"
  2325. //+-------------------------------------------------------------------------
  2326. // Enhanced Key Usage (Purpose) Object Identifiers
  2327. //--------------------------------------------------------------------------
  2328. #define szOID_PKIX_KP "1.3.6.1.5.5.7.3"
  2329. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  2330. // or KEY_AGREEMENT
  2331. #define szOID_PKIX_KP_SERVER_AUTH "1.3.6.1.5.5.7.3.1"
  2332. // Consistent key usage bits: DIGITAL_SIGNATURE
  2333. #define szOID_PKIX_KP_CLIENT_AUTH "1.3.6.1.5.5.7.3.2"
  2334. // Consistent key usage bits: DIGITAL_SIGNATURE
  2335. #define szOID_PKIX_KP_CODE_SIGNING "1.3.6.1.5.5.7.3.3"
  2336. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  2337. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2338. #define szOID_PKIX_KP_EMAIL_PROTECTION "1.3.6.1.5.5.7.3.4"
  2339. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2340. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2341. #define szOID_PKIX_KP_IPSEC_END_SYSTEM "1.3.6.1.5.5.7.3.5"
  2342. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2343. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2344. #define szOID_PKIX_KP_IPSEC_TUNNEL "1.3.6.1.5.5.7.3.6"
  2345. // Consistent key usage bits: DIGITAL_SIGNATURE and/or
  2346. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  2347. #define szOID_PKIX_KP_IPSEC_USER "1.3.6.1.5.5.7.3.7"
  2348. // Consistent key usage bits: DIGITAL_SIGNATURE or NON_REPUDIATION
  2349. #define szOID_PKIX_KP_TIMESTAMP_SIGNING "1.3.6.1.5.5.7.3.8"
  2350. // IKE (Internet Key Exchange) Intermediate KP for an IPsec end entity.
  2351. // Defined in draft-ietf-ipsec-pki-req-04.txt, December 14, 1999.
  2352. #define szOID_IPSEC_KP_IKE_INTERMEDIATE "1.3.6.1.5.5.8.2.2"
  2353. //+-------------------------------------------------------------------------
  2354. // Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  2355. //+-------------------------------------------------------------------------
  2356. // Signer of CTLs
  2357. #define szOID_KP_CTL_USAGE_SIGNING "1.3.6.1.4.1.311.10.3.1"
  2358. // Signer of TimeStamps
  2359. #define szOID_KP_TIME_STAMP_SIGNING "1.3.6.1.4.1.311.10.3.2"
  2360. #ifndef szOID_SERVER_GATED_CRYPTO
  2361. #define szOID_SERVER_GATED_CRYPTO "1.3.6.1.4.1.311.10.3.3"
  2362. #endif
  2363. #ifndef szOID_SGC_NETSCAPE
  2364. #define szOID_SGC_NETSCAPE "2.16.840.1.113730.4.1"
  2365. #endif
  2366. #define szOID_KP_EFS "1.3.6.1.4.1.311.10.3.4"
  2367. #define szOID_EFS_RECOVERY "1.3.6.1.4.1.311.10.3.4.1"
  2368. // Can use Windows Hardware Compatible (WHQL)
  2369. #define szOID_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.5"
  2370. // Signed by the NT5 build lab
  2371. #define szOID_NT5_CRYPTO "1.3.6.1.4.1.311.10.3.6"
  2372. // Signed by and OEM of WHQL
  2373. #define szOID_OEM_WHQL_CRYPTO "1.3.6.1.4.1.311.10.3.7"
  2374. // Signed by the Embedded NT
  2375. #define szOID_EMBEDDED_NT_CRYPTO "1.3.6.1.4.1.311.10.3.8"
  2376. // Signer of a CTL containing trusted roots
  2377. #define szOID_ROOT_LIST_SIGNER "1.3.6.1.4.1.311.10.3.9"
  2378. // Can sign cross-cert and subordinate CA requests with qualified
  2379. // subordination (name constraints, policy mapping, etc.)
  2380. #define szOID_KP_QUALIFIED_SUBORDINATION "1.3.6.1.4.1.311.10.3.10"
  2381. // Can be used to encrypt/recover escrowed keys
  2382. #define szOID_KP_KEY_RECOVERY "1.3.6.1.4.1.311.10.3.11"
  2383. // Signer of documents
  2384. #define szOID_KP_DOCUMENT_SIGNING "1.3.6.1.4.1.311.10.3.12"
  2385. // The default WinVerifyTrust Authenticode policy is to treat all time stamped
  2386. // signatures as being valid forever. This OID limits the valid lifetime of the
  2387. // signature to the lifetime of the certificate. This allows timestamped
  2388. // signatures to expire. Normally this OID will be used in conjunction with
  2389. // szOID_PKIX_KP_CODE_SIGNING to indicate new time stamp semantics should be
  2390. // used. Support for this OID was added in WXP.
  2391. #define szOID_KP_LIFETIME_SIGNING "1.3.6.1.4.1.311.10.3.13"
  2392. #define szOID_KP_MOBILE_DEVICE_SOFTWARE "1.3.6.1.4.1.311.10.3.14"
  2393. #ifndef szOID_DRM
  2394. #define szOID_DRM "1.3.6.1.4.1.311.10.5.1"
  2395. #endif
  2396. // Microsoft DRM EKU
  2397. #ifndef szOID_DRM_INDIVIDUALIZATION
  2398. #define szOID_DRM_INDIVIDUALIZATION "1.3.6.1.4.1.311.10.5.2"
  2399. #endif
  2400. #ifndef szOID_LICENSES
  2401. #define szOID_LICENSES "1.3.6.1.4.1.311.10.6.1"
  2402. #endif
  2403. #ifndef szOID_LICENSE_SERVER
  2404. #define szOID_LICENSE_SERVER "1.3.6.1.4.1.311.10.6.2"
  2405. #endif
  2406. #ifndef szOID_KP_SMARTCARD_LOGON
  2407. #define szOID_KP_SMARTCARD_LOGON "1.3.6.1.4.1.311.20.2.2"
  2408. #endif
  2409. //+-------------------------------------------------------------------------
  2410. // Microsoft Attribute Object Identifiers
  2411. //+-------------------------------------------------------------------------
  2412. #define szOID_YESNO_TRUST_ATTR "1.3.6.1.4.1.311.10.4.1"
  2413. //+-------------------------------------------------------------------------
  2414. // Qualifiers that may be part of the szOID_CERT_POLICIES and
  2415. // szOID_CERT_POLICIES95 extensions
  2416. //+-------------------------------------------------------------------------
  2417. #define szOID_PKIX_POLICY_QUALIFIER_CPS "1.3.6.1.5.5.7.2.1"
  2418. #define szOID_PKIX_POLICY_QUALIFIER_USERNOTICE "1.3.6.1.5.5.7.2.2"
  2419. // OID for old qualifer
  2420. #define szOID_CERT_POLICIES_95_QUALIFIER1 "2.16.840.1.113733.1.7.1.1"
  2421. //+-------------------------------------------------------------------------
  2422. // X509_CERT
  2423. //
  2424. // The "to be signed" encoded content plus its signature. The ToBeSigned
  2425. // content is the CryptEncodeObject() output for one of the following:
  2426. // X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  2427. // X509_CERT_REQUEST_TO_BE_SIGNED.
  2428. //
  2429. // pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  2430. //--------------------------------------------------------------------------
  2431. //+-------------------------------------------------------------------------
  2432. // X509_CERT_TO_BE_SIGNED
  2433. //
  2434. // pvStructInfo points to CERT_INFO.
  2435. //
  2436. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2437. // signature (output of a X509_CERT CryptEncodeObject()).
  2438. //
  2439. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2440. //--------------------------------------------------------------------------
  2441. //+-------------------------------------------------------------------------
  2442. // X509_CERT_CRL_TO_BE_SIGNED
  2443. //
  2444. // pvStructInfo points to CRL_INFO.
  2445. //
  2446. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2447. // signature (output of a X509_CERT CryptEncodeObject()).
  2448. //
  2449. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2450. //--------------------------------------------------------------------------
  2451. //+-------------------------------------------------------------------------
  2452. // X509_CERT_REQUEST_TO_BE_SIGNED
  2453. //
  2454. // pvStructInfo points to CERT_REQUEST_INFO.
  2455. //
  2456. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2457. // signature (output of a X509_CERT CryptEncodeObject()).
  2458. //
  2459. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2460. //--------------------------------------------------------------------------
  2461. //+-------------------------------------------------------------------------
  2462. // X509_EXTENSIONS
  2463. // szOID_CERT_EXTENSIONS
  2464. //
  2465. // pvStructInfo points to following CERT_EXTENSIONS.
  2466. //--------------------------------------------------------------------------
  2467. typedef struct _CERT_EXTENSIONS {
  2468. DWORD cExtension;
  2469. PCERT_EXTENSION rgExtension;
  2470. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  2471. //+-------------------------------------------------------------------------
  2472. // X509_NAME_VALUE
  2473. // X509_ANY_STRING
  2474. //
  2475. // pvStructInfo points to CERT_NAME_VALUE.
  2476. //--------------------------------------------------------------------------
  2477. //+-------------------------------------------------------------------------
  2478. // X509_UNICODE_NAME_VALUE
  2479. // X509_UNICODE_ANY_STRING
  2480. //
  2481. // pvStructInfo points to CERT_NAME_VALUE.
  2482. //
  2483. // The name values are unicode strings.
  2484. //
  2485. // For CryptEncodeObject:
  2486. // Value.pbData points to the unicode string.
  2487. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2488. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2489. // is twice the character count.
  2490. //
  2491. // If the unicode string contains an invalid character for the specified
  2492. // dwValueType, then, *pcbEncoded is updated with the unicode character
  2493. // index of the first invalid character. LastError is set to:
  2494. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2495. // CRYPT_E_INVALID_IA5_STRING.
  2496. //
  2497. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2498. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2499. // in dwFlags passed to CryptEncodeObjectEx.
  2500. //
  2501. // The unicode string is converted before being encoded according to
  2502. // the specified dwValueType. If dwValueType is set to 0, LastError
  2503. // is set to E_INVALIDARG.
  2504. //
  2505. // If the dwValueType isn't one of the character strings (its a
  2506. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  2507. // will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  2508. //
  2509. // For CryptDecodeObject:
  2510. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2511. // contains the byte count of the unicode string excluding the NULL
  2512. // terminator. dwValueType contains the type used in the encoded object.
  2513. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2514. // converted to the unicode string according to the dwValueType.
  2515. //
  2516. // If the encoded object isn't one of the character string types, then,
  2517. // CryptDecodeObject will return FALSE with LastError set to
  2518. // CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  2519. // X509_NAME_VALUE or X509_ANY_STRING.
  2520. //
  2521. // By default, CERT_RDN_T61_STRING values are initially decoded
  2522. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2523. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2524. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2525. // skip the initial attempt to decode as UTF8.
  2526. //--------------------------------------------------------------------------
  2527. //+-------------------------------------------------------------------------
  2528. // X509_NAME
  2529. //
  2530. // pvStructInfo points to CERT_NAME_INFO.
  2531. //--------------------------------------------------------------------------
  2532. //+-------------------------------------------------------------------------
  2533. // X509_UNICODE_NAME
  2534. //
  2535. // pvStructInfo points to CERT_NAME_INFO.
  2536. //
  2537. // The RDN attribute values are unicode strings except for the dwValueTypes of
  2538. // CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  2539. // the same as for a X509_NAME. Their values aren't converted to/from unicode.
  2540. //
  2541. // For CryptEncodeObject:
  2542. // Value.pbData points to the unicode string.
  2543. // If Value.cbData = 0, then, the unicode string is NULL terminated.
  2544. // Otherwise, Value.cbData is the unicode string byte count. The byte count
  2545. // is twice the character count.
  2546. //
  2547. // If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  2548. // an acceptable dwValueType. If the unicode string contains an
  2549. // invalid character for the found or specified dwValueType, then,
  2550. // *pcbEncoded is updated with the error location of the invalid character.
  2551. // See below for details. LastError is set to:
  2552. // CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  2553. // CRYPT_E_INVALID_IA5_STRING.
  2554. //
  2555. // To disable the above check, either set CERT_RDN_DISABLE_CHECK_TYPE_FLAG
  2556. // in dwValueType or set CRYPT_UNICODE_NAME_ENCODE_DISABLE_CHECK_TYPE_FLAG
  2557. // in dwFlags passed to CryptEncodeObjectEx.
  2558. //
  2559. // Set CERT_RDN_UNICODE_STRING in dwValueType or set
  2560. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_T61_UNICODE_FLAG in dwFlags passed
  2561. // to CryptEncodeObjectEx to select CERT_RDN_T61_STRING instead of
  2562. // CERT_RDN_UNICODE_STRING if all the unicode characters are <= 0xFF.
  2563. //
  2564. // Set CERT_RDN_ENABLE_UTF8_UNICODE_STRING in dwValueType or set
  2565. // CRYPT_UNICODE_NAME_ENCODE_ENABLE_UTF8_UNICODE_FLAG in dwFlags passed
  2566. // to CryptEncodeObjectEx to select CERT_RDN_UTF8_STRING instead of
  2567. // CERT_RDN_UNICODE_STRING.
  2568. //
  2569. // The unicode string is converted before being encoded according to
  2570. // the specified or ObjId matching dwValueType.
  2571. //
  2572. // For CryptDecodeObject:
  2573. // Value.pbData points to a NULL terminated unicode string. Value.cbData
  2574. // contains the byte count of the unicode string excluding the NULL
  2575. // terminator. dwValueType contains the type used in the encoded object.
  2576. // Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  2577. // converted to the unicode string according to the dwValueType.
  2578. //
  2579. // If the dwValueType of the encoded value isn't a character string
  2580. // type, then, it isn't converted to UNICODE. Use the
  2581. // IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  2582. // that Value.pbData points to a converted unicode string.
  2583. //
  2584. // By default, CERT_RDN_T61_STRING values are initially decoded
  2585. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  2586. // Set CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG in dwFlags
  2587. // passed to either CryptDecodeObject or CryptDecodeObjectEx to
  2588. // skip the initial attempt to decode as UTF8.
  2589. //--------------------------------------------------------------------------
  2590. //+-------------------------------------------------------------------------
  2591. // Unicode Name Value Error Location Definitions
  2592. //
  2593. // Error location is returned in *pcbEncoded by
  2594. // CryptEncodeObject(X509_UNICODE_NAME)
  2595. //
  2596. // Error location consists of:
  2597. // RDN_INDEX - 10 bits << 22
  2598. // ATTR_INDEX - 6 bits << 16
  2599. // VALUE_INDEX - 16 bits (unicode character index)
  2600. //--------------------------------------------------------------------------
  2601. #define CERT_UNICODE_RDN_ERR_INDEX_MASK 0x3FF
  2602. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT 22
  2603. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK 0x003F
  2604. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT 16
  2605. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2606. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT 0
  2607. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X) \
  2608. ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  2609. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X) \
  2610. ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  2611. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  2612. (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  2613. //+-------------------------------------------------------------------------
  2614. // X509_PUBLIC_KEY_INFO
  2615. //
  2616. // pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  2617. //--------------------------------------------------------------------------
  2618. //+-------------------------------------------------------------------------
  2619. // X509_AUTHORITY_KEY_ID
  2620. // szOID_AUTHORITY_KEY_IDENTIFIER
  2621. //
  2622. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  2623. //--------------------------------------------------------------------------
  2624. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  2625. CRYPT_DATA_BLOB KeyId;
  2626. CERT_NAME_BLOB CertIssuer;
  2627. CRYPT_INTEGER_BLOB CertSerialNumber;
  2628. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  2629. //+-------------------------------------------------------------------------
  2630. // X509_KEY_ATTRIBUTES
  2631. // szOID_KEY_ATTRIBUTES
  2632. //
  2633. // pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  2634. //--------------------------------------------------------------------------
  2635. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  2636. FILETIME NotBefore;
  2637. FILETIME NotAfter;
  2638. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  2639. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  2640. CRYPT_DATA_BLOB KeyId;
  2641. CRYPT_BIT_BLOB IntendedKeyUsage;
  2642. PCERT_PRIVATE_KEY_VALIDITY pPrivateKeyUsagePeriod; // OPTIONAL
  2643. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  2644. // Byte[0]
  2645. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE 0x80
  2646. #define CERT_NON_REPUDIATION_KEY_USAGE 0x40
  2647. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE 0x20
  2648. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE 0x10
  2649. #define CERT_KEY_AGREEMENT_KEY_USAGE 0x08
  2650. #define CERT_KEY_CERT_SIGN_KEY_USAGE 0x04
  2651. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE 0x02
  2652. #define CERT_CRL_SIGN_KEY_USAGE 0x02
  2653. #define CERT_ENCIPHER_ONLY_KEY_USAGE 0x01
  2654. // Byte[1]
  2655. #define CERT_DECIPHER_ONLY_KEY_USAGE 0x80
  2656. //+-------------------------------------------------------------------------
  2657. // X509_KEY_USAGE_RESTRICTION
  2658. // szOID_KEY_USAGE_RESTRICTION
  2659. //
  2660. // pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  2661. //--------------------------------------------------------------------------
  2662. typedef struct _CERT_POLICY_ID {
  2663. DWORD cCertPolicyElementId;
  2664. LPSTR *rgpszCertPolicyElementId; // pszObjId
  2665. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  2666. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  2667. DWORD cCertPolicyId;
  2668. PCERT_POLICY_ID rgCertPolicyId;
  2669. CRYPT_BIT_BLOB RestrictedKeyUsage;
  2670. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  2671. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  2672. //+-------------------------------------------------------------------------
  2673. // X509_ALTERNATE_NAME
  2674. // szOID_SUBJECT_ALT_NAME
  2675. // szOID_ISSUER_ALT_NAME
  2676. // szOID_SUBJECT_ALT_NAME2
  2677. // szOID_ISSUER_ALT_NAME2
  2678. //
  2679. // pvStructInfo points to following CERT_ALT_NAME_INFO.
  2680. //--------------------------------------------------------------------------
  2681. typedef struct _CERT_OTHER_NAME {
  2682. LPSTR pszObjId;
  2683. CRYPT_OBJID_BLOB Value;
  2684. } CERT_OTHER_NAME, *PCERT_OTHER_NAME;
  2685. typedef struct _CERT_ALT_NAME_ENTRY {
  2686. DWORD dwAltNameChoice;
  2687. union {
  2688. PCERT_OTHER_NAME pOtherName; // 1
  2689. LPWSTR pwszRfc822Name; // 2 (encoded IA5)
  2690. LPWSTR pwszDNSName; // 3 (encoded IA5)
  2691. // Not implemented x400Address; // 4
  2692. CERT_NAME_BLOB DirectoryName; // 5
  2693. // Not implemented pEdiPartyName; // 6
  2694. LPWSTR pwszURL; // 7 (encoded IA5)
  2695. CRYPT_DATA_BLOB IPAddress; // 8 (Octet String)
  2696. LPSTR pszRegisteredID; // 9 (Object Identifer)
  2697. };
  2698. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  2699. #define CERT_ALT_NAME_OTHER_NAME 1
  2700. #define CERT_ALT_NAME_RFC822_NAME 2
  2701. #define CERT_ALT_NAME_DNS_NAME 3
  2702. #define CERT_ALT_NAME_X400_ADDRESS 4
  2703. #define CERT_ALT_NAME_DIRECTORY_NAME 5
  2704. #define CERT_ALT_NAME_EDI_PARTY_NAME 6
  2705. #define CERT_ALT_NAME_URL 7
  2706. #define CERT_ALT_NAME_IP_ADDRESS 8
  2707. #define CERT_ALT_NAME_REGISTERED_ID 9
  2708. typedef struct _CERT_ALT_NAME_INFO {
  2709. DWORD cAltEntry;
  2710. PCERT_ALT_NAME_ENTRY rgAltEntry;
  2711. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2712. //+-------------------------------------------------------------------------
  2713. // Alternate name IA5 Error Location Definitions for
  2714. // CRYPT_E_INVALID_IA5_STRING.
  2715. //
  2716. // Error location is returned in *pcbEncoded by
  2717. // CryptEncodeObject(X509_ALTERNATE_NAME)
  2718. //
  2719. // Error location consists of:
  2720. // ENTRY_INDEX - 8 bits << 16
  2721. // VALUE_INDEX - 16 bits (unicode character index)
  2722. //--------------------------------------------------------------------------
  2723. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK 0xFF
  2724. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2725. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK 0x0000FFFF
  2726. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2727. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X) \
  2728. ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2729. CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2730. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2731. (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2732. //+-------------------------------------------------------------------------
  2733. // X509_BASIC_CONSTRAINTS
  2734. // szOID_BASIC_CONSTRAINTS
  2735. //
  2736. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2737. //--------------------------------------------------------------------------
  2738. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2739. CRYPT_BIT_BLOB SubjectType;
  2740. BOOL fPathLenConstraint;
  2741. DWORD dwPathLenConstraint;
  2742. DWORD cSubtreesConstraint;
  2743. CERT_NAME_BLOB *rgSubtreesConstraint;
  2744. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2745. #define CERT_CA_SUBJECT_FLAG 0x80
  2746. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2747. //+-------------------------------------------------------------------------
  2748. // X509_BASIC_CONSTRAINTS2
  2749. // szOID_BASIC_CONSTRAINTS2
  2750. //
  2751. // pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2752. //--------------------------------------------------------------------------
  2753. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2754. BOOL fCA;
  2755. BOOL fPathLenConstraint;
  2756. DWORD dwPathLenConstraint;
  2757. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2758. //+-------------------------------------------------------------------------
  2759. // X509_KEY_USAGE
  2760. // szOID_KEY_USAGE
  2761. //
  2762. // pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2763. // CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2764. //--------------------------------------------------------------------------
  2765. //+-------------------------------------------------------------------------
  2766. // X509_CERT_POLICIES
  2767. // szOID_CERT_POLICIES
  2768. // szOID_CERT_POLICIES_95 NOTE--Only allowed for decoding!!!
  2769. //
  2770. // pvStructInfo points to following CERT_POLICIES_INFO.
  2771. //
  2772. // NOTE: when decoding using szOID_CERT_POLICIES_95 the pszPolicyIdentifier
  2773. // may contain an empty string
  2774. //--------------------------------------------------------------------------
  2775. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2776. LPSTR pszPolicyQualifierId; // pszObjId
  2777. CRYPT_OBJID_BLOB Qualifier; // optional
  2778. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2779. typedef struct _CERT_POLICY_INFO {
  2780. LPSTR pszPolicyIdentifier; // pszObjId
  2781. DWORD cPolicyQualifier; // optional
  2782. CERT_POLICY_QUALIFIER_INFO *rgPolicyQualifier;
  2783. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2784. typedef struct _CERT_POLICIES_INFO {
  2785. DWORD cPolicyInfo;
  2786. CERT_POLICY_INFO *rgPolicyInfo;
  2787. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2788. //+-------------------------------------------------------------------------
  2789. // X509_PKIX_POLICY_QUALIFIER_USERNOTICE
  2790. // szOID_PKIX_POLICY_QUALIFIER_USERNOTICE
  2791. //
  2792. // pvStructInfo points to following CERT_POLICY_QUALIFIER_USER_NOTICE.
  2793. //
  2794. //--------------------------------------------------------------------------
  2795. typedef struct _CERT_POLICY_QUALIFIER_NOTICE_REFERENCE {
  2796. LPSTR pszOrganization;
  2797. DWORD cNoticeNumbers;
  2798. int *rgNoticeNumbers;
  2799. } CERT_POLICY_QUALIFIER_NOTICE_REFERENCE, *PCERT_POLICY_QUALIFIER_NOTICE_REFERENCE;
  2800. typedef struct _CERT_POLICY_QUALIFIER_USER_NOTICE {
  2801. CERT_POLICY_QUALIFIER_NOTICE_REFERENCE *pNoticeReference; // optional
  2802. LPWSTR pszDisplayText; // optional
  2803. } CERT_POLICY_QUALIFIER_USER_NOTICE, *PCERT_POLICY_QUALIFIER_USER_NOTICE;
  2804. //+-------------------------------------------------------------------------
  2805. // szOID_CERT_POLICIES_95_QUALIFIER1 - Decode Only!!!!
  2806. //
  2807. // pvStructInfo points to following CERT_POLICY95_QUALIFIER1.
  2808. //
  2809. //--------------------------------------------------------------------------
  2810. typedef struct _CPS_URLS {
  2811. LPWSTR pszURL;
  2812. CRYPT_ALGORITHM_IDENTIFIER *pAlgorithm; // optional
  2813. CRYPT_DATA_BLOB *pDigest; // optional
  2814. } CPS_URLS, *PCPS_URLS;
  2815. typedef struct _CERT_POLICY95_QUALIFIER1 {
  2816. LPWSTR pszPracticesReference; // optional
  2817. LPSTR pszNoticeIdentifier; // optional
  2818. LPSTR pszNSINoticeIdentifier; // optional
  2819. DWORD cCPSURLs;
  2820. CPS_URLS *rgCPSURLs; // optional
  2821. } CERT_POLICY95_QUALIFIER1, *PCERT_POLICY95_QUALIFIER1;
  2822. //+-------------------------------------------------------------------------
  2823. // X509_POLICY_MAPPINGS
  2824. // szOID_POLICY_MAPPINGS
  2825. // szOID_LEGACY_POLICY_MAPPINGS
  2826. //
  2827. // pvStructInfo points to following CERT_POLICY_MAPPINGS_INFO.
  2828. //--------------------------------------------------------------------------
  2829. typedef struct _CERT_POLICY_MAPPING {
  2830. LPSTR pszIssuerDomainPolicy; // pszObjId
  2831. LPSTR pszSubjectDomainPolicy; // pszObjId
  2832. } CERT_POLICY_MAPPING, *PCERT_POLICY_MAPPING;
  2833. typedef struct _CERT_POLICY_MAPPINGS_INFO {
  2834. DWORD cPolicyMapping;
  2835. PCERT_POLICY_MAPPING rgPolicyMapping;
  2836. } CERT_POLICY_MAPPINGS_INFO, *PCERT_POLICY_MAPPINGS_INFO;
  2837. //+-------------------------------------------------------------------------
  2838. // X509_POLICY_CONSTRAINTS
  2839. // szOID_POLICY_CONSTRAINTS
  2840. //
  2841. // pvStructInfo points to following CERT_POLICY_CONSTRAINTS_INFO.
  2842. //--------------------------------------------------------------------------
  2843. typedef struct _CERT_POLICY_CONSTRAINTS_INFO {
  2844. BOOL fRequireExplicitPolicy;
  2845. DWORD dwRequireExplicitPolicySkipCerts;
  2846. BOOL fInhibitPolicyMapping;
  2847. DWORD dwInhibitPolicyMappingSkipCerts;
  2848. } CERT_POLICY_CONSTRAINTS_INFO, *PCERT_POLICY_CONSTRAINTS_INFO;
  2849. //+-------------------------------------------------------------------------
  2850. // RSA_CSP_PUBLICKEYBLOB
  2851. //
  2852. // pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2853. // RSAPUBKEY and the modulus bytes.
  2854. //
  2855. // CryptExportKey outputs the above StructInfo for a dwBlobType of
  2856. // PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2857. // importing a public key.
  2858. //
  2859. // For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2860. // encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2861. // modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2862. // as being a unsigned integer. When decoded, if the modulus was encoded
  2863. // as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2864. // converting to the CSP modulus bytes.
  2865. //
  2866. // For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2867. // CALG_RSA_KEYX.
  2868. //--------------------------------------------------------------------------
  2869. //+-------------------------------------------------------------------------
  2870. // X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2871. //
  2872. // pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2873. //
  2874. // For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2875. // signature (output of a X509_CERT CryptEncodeObject()).
  2876. //
  2877. // For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2878. //--------------------------------------------------------------------------
  2879. //+-------------------------------------------------------------------------
  2880. // PKCS_ATTRIBUTE data structure
  2881. //
  2882. // pvStructInfo points to a CRYPT_ATTRIBUTE.
  2883. //--------------------------------------------------------------------------
  2884. //+-------------------------------------------------------------------------
  2885. // PKCS_ATTRIBUTES data structure
  2886. //
  2887. // pvStructInfo points to a CRYPT_ATTRIBUTES.
  2888. //--------------------------------------------------------------------------
  2889. //+-------------------------------------------------------------------------
  2890. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  2891. //
  2892. // pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  2893. //
  2894. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  2895. // a sequence of ANY. The value of the contentType field is pszObjId,
  2896. // while the content field is the following structure:
  2897. // SequenceOfAny ::= SEQUENCE OF ANY
  2898. //
  2899. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2900. //--------------------------------------------------------------------------
  2901. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  2902. LPSTR pszObjId;
  2903. DWORD cValue;
  2904. PCRYPT_DER_BLOB rgValue;
  2905. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  2906. //+-------------------------------------------------------------------------
  2907. // PKCS_CONTENT_INFO data structure
  2908. //
  2909. // pvStructInfo points to following CRYPT_CONTENT_INFO.
  2910. //
  2911. // For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  2912. // The CRYPT_DER_BLOB points to the already encoded ANY content.
  2913. //--------------------------------------------------------------------------
  2914. typedef struct _CRYPT_CONTENT_INFO {
  2915. LPSTR pszObjId;
  2916. CRYPT_DER_BLOB Content;
  2917. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  2918. //+-------------------------------------------------------------------------
  2919. // X509_OCTET_STRING data structure
  2920. //
  2921. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2922. //--------------------------------------------------------------------------
  2923. //+-------------------------------------------------------------------------
  2924. // X509_BITS data structure
  2925. //
  2926. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2927. //--------------------------------------------------------------------------
  2928. //+-------------------------------------------------------------------------
  2929. // X509_BITS_WITHOUT_TRAILING_ZEROES data structure
  2930. //
  2931. // pvStructInfo points to a CRYPT_BIT_BLOB.
  2932. //
  2933. // The same as X509_BITS, except before encoding, the bit length is
  2934. // decremented to exclude trailing zero bits.
  2935. //--------------------------------------------------------------------------
  2936. //+-------------------------------------------------------------------------
  2937. // X509_INTEGER data structure
  2938. //
  2939. // pvStructInfo points to an int.
  2940. //--------------------------------------------------------------------------
  2941. //+-------------------------------------------------------------------------
  2942. // X509_MULTI_BYTE_INTEGER data structure
  2943. //
  2944. // pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2945. //--------------------------------------------------------------------------
  2946. //+-------------------------------------------------------------------------
  2947. // X509_ENUMERATED data structure
  2948. //
  2949. // pvStructInfo points to an int containing the enumerated value
  2950. //--------------------------------------------------------------------------
  2951. //+-------------------------------------------------------------------------
  2952. // X509_CHOICE_OF_TIME data structure
  2953. //
  2954. // pvStructInfo points to a FILETIME.
  2955. //--------------------------------------------------------------------------
  2956. //+-------------------------------------------------------------------------
  2957. // X509_SEQUENCE_OF_ANY data structure
  2958. //
  2959. // pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2960. //
  2961. // The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2962. //--------------------------------------------------------------------------
  2963. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  2964. DWORD cValue;
  2965. PCRYPT_DER_BLOB rgValue;
  2966. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  2967. //+-------------------------------------------------------------------------
  2968. // X509_AUTHORITY_KEY_ID2
  2969. // szOID_AUTHORITY_KEY_IDENTIFIER2
  2970. //
  2971. // pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2972. //
  2973. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2974. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2975. //
  2976. // See X509_ALTERNATE_NAME for error location defines.
  2977. //--------------------------------------------------------------------------
  2978. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  2979. CRYPT_DATA_BLOB KeyId;
  2980. CERT_ALT_NAME_INFO AuthorityCertIssuer; // Optional, set cAltEntry
  2981. // to 0 to omit.
  2982. CRYPT_INTEGER_BLOB AuthorityCertSerialNumber;
  2983. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  2984. //+-------------------------------------------------------------------------
  2985. // szOID_SUBJECT_KEY_IDENTIFIER
  2986. //
  2987. // pvStructInfo points to a CRYPT_DATA_BLOB.
  2988. //--------------------------------------------------------------------------
  2989. //+-------------------------------------------------------------------------
  2990. // X509_AUTHORITY_INFO_ACCESS
  2991. // szOID_AUTHORITY_INFO_ACCESS
  2992. //
  2993. // pvStructInfo points to following CERT_AUTHORITY_INFO_ACCESS.
  2994. //
  2995. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2996. // *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_INFO_ACCESS)
  2997. //
  2998. // Error location consists of:
  2999. // ENTRY_INDEX - 8 bits << 16
  3000. // VALUE_INDEX - 16 bits (unicode character index)
  3001. //
  3002. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3003. // defines.
  3004. //--------------------------------------------------------------------------
  3005. typedef struct _CERT_ACCESS_DESCRIPTION {
  3006. LPSTR pszAccessMethod; // pszObjId
  3007. CERT_ALT_NAME_ENTRY AccessLocation;
  3008. } CERT_ACCESS_DESCRIPTION, *PCERT_ACCESS_DESCRIPTION;
  3009. typedef struct _CERT_AUTHORITY_INFO_ACCESS {
  3010. DWORD cAccDescr;
  3011. PCERT_ACCESS_DESCRIPTION rgAccDescr;
  3012. } CERT_AUTHORITY_INFO_ACCESS, *PCERT_AUTHORITY_INFO_ACCESS;
  3013. //+-------------------------------------------------------------------------
  3014. // PKIX Access Description: Access Method Object Identifiers
  3015. //--------------------------------------------------------------------------
  3016. #define szOID_PKIX_ACC_DESCR "1.3.6.1.5.5.7.48"
  3017. #define szOID_PKIX_OCSP "1.3.6.1.5.5.7.48.1"
  3018. #define szOID_PKIX_CA_ISSUERS "1.3.6.1.5.5.7.48.2"
  3019. //+-------------------------------------------------------------------------
  3020. // X509_CRL_REASON_CODE
  3021. // szOID_CRL_REASON_CODE
  3022. //
  3023. // pvStructInfo points to an int which can be set to one of the following
  3024. // enumerated values:
  3025. //--------------------------------------------------------------------------
  3026. #define CRL_REASON_UNSPECIFIED 0
  3027. #define CRL_REASON_KEY_COMPROMISE 1
  3028. #define CRL_REASON_CA_COMPROMISE 2
  3029. #define CRL_REASON_AFFILIATION_CHANGED 3
  3030. #define CRL_REASON_SUPERSEDED 4
  3031. #define CRL_REASON_CESSATION_OF_OPERATION 5
  3032. #define CRL_REASON_CERTIFICATE_HOLD 6
  3033. #define CRL_REASON_REMOVE_FROM_CRL 8
  3034. //+-------------------------------------------------------------------------
  3035. // X509_CRL_DIST_POINTS
  3036. // szOID_CRL_DIST_POINTS
  3037. //
  3038. // pvStructInfo points to following CRL_DIST_POINTS_INFO.
  3039. //
  3040. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3041. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  3042. //
  3043. // Error location consists of:
  3044. // CRL_ISSUER_BIT - 1 bit << 31 (0 for FullName, 1 for CRLIssuer)
  3045. // POINT_INDEX - 7 bits << 24
  3046. // ENTRY_INDEX - 8 bits << 16
  3047. // VALUE_INDEX - 16 bits (unicode character index)
  3048. //
  3049. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3050. // defines.
  3051. //--------------------------------------------------------------------------
  3052. typedef struct _CRL_DIST_POINT_NAME {
  3053. DWORD dwDistPointNameChoice;
  3054. union {
  3055. CERT_ALT_NAME_INFO FullName; // 1
  3056. // Not implemented IssuerRDN; // 2
  3057. };
  3058. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  3059. #define CRL_DIST_POINT_NO_NAME 0
  3060. #define CRL_DIST_POINT_FULL_NAME 1
  3061. #define CRL_DIST_POINT_ISSUER_RDN_NAME 2
  3062. typedef struct _CRL_DIST_POINT {
  3063. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  3064. CRYPT_BIT_BLOB ReasonFlags; // OPTIONAL
  3065. CERT_ALT_NAME_INFO CRLIssuer; // OPTIONAL
  3066. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  3067. #define CRL_REASON_UNUSED_FLAG 0x80
  3068. #define CRL_REASON_KEY_COMPROMISE_FLAG 0x40
  3069. #define CRL_REASON_CA_COMPROMISE_FLAG 0x20
  3070. #define CRL_REASON_AFFILIATION_CHANGED_FLAG 0x10
  3071. #define CRL_REASON_SUPERSEDED_FLAG 0x08
  3072. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG 0x04
  3073. #define CRL_REASON_CERTIFICATE_HOLD_FLAG 0x02
  3074. typedef struct _CRL_DIST_POINTS_INFO {
  3075. DWORD cDistPoint;
  3076. PCRL_DIST_POINT rgDistPoint;
  3077. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  3078. #define CRL_DIST_POINT_ERR_INDEX_MASK 0x7F
  3079. #define CRL_DIST_POINT_ERR_INDEX_SHIFT 24
  3080. #define GET_CRL_DIST_POINT_ERR_INDEX(X) \
  3081. ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  3082. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT 0x80000000L
  3083. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X) \
  3084. (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  3085. //+-------------------------------------------------------------------------
  3086. // X509_CROSS_CERT_DIST_POINTS
  3087. // szOID_CROSS_CERT_DIST_POINTS
  3088. //
  3089. // pvStructInfo points to following CROSS_CERT_DIST_POINTS_INFO.
  3090. //
  3091. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3092. // *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  3093. //
  3094. // Error location consists of:
  3095. // POINT_INDEX - 8 bits << 24
  3096. // ENTRY_INDEX - 8 bits << 16
  3097. // VALUE_INDEX - 16 bits (unicode character index)
  3098. //
  3099. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3100. // defines.
  3101. //--------------------------------------------------------------------------
  3102. typedef struct _CROSS_CERT_DIST_POINTS_INFO {
  3103. // Seconds between syncs. 0 implies use client default.
  3104. DWORD dwSyncDeltaTime;
  3105. DWORD cDistPoint;
  3106. PCERT_ALT_NAME_INFO rgDistPoint;
  3107. } CROSS_CERT_DIST_POINTS_INFO, *PCROSS_CERT_DIST_POINTS_INFO;
  3108. #define CROSS_CERT_DIST_POINT_ERR_INDEX_MASK 0xFF
  3109. #define CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT 24
  3110. #define GET_CROSS_CERT_DIST_POINT_ERR_INDEX(X) \
  3111. ((X >> CROSS_CERT_DIST_POINT_ERR_INDEX_SHIFT) & \
  3112. CROSS_CERT_DIST_POINT_ERR_INDEX_MASK)
  3113. //+-------------------------------------------------------------------------
  3114. // X509_ENHANCED_KEY_USAGE
  3115. // szOID_ENHANCED_KEY_USAGE
  3116. //
  3117. // pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  3118. //--------------------------------------------------------------------------
  3119. //+-------------------------------------------------------------------------
  3120. // X509_CERT_PAIR
  3121. //
  3122. // pvStructInfo points to the following CERT_PAIR.
  3123. //--------------------------------------------------------------------------
  3124. typedef struct _CERT_PAIR {
  3125. CERT_BLOB Forward; // OPTIONAL, if Forward.cbData == 0, omitted
  3126. CERT_BLOB Reverse; // OPTIONAL, if Reverse.cbData == 0, omitted
  3127. } CERT_PAIR, *PCERT_PAIR;
  3128. //+-------------------------------------------------------------------------
  3129. // szOID_CRL_NUMBER
  3130. //
  3131. // pvStructInfo points to an int.
  3132. //--------------------------------------------------------------------------
  3133. //+-------------------------------------------------------------------------
  3134. // szOID_DELTA_CRL_INDICATOR
  3135. //
  3136. // pvStructInfo points to an int.
  3137. //--------------------------------------------------------------------------
  3138. //+-------------------------------------------------------------------------
  3139. // szOID_ISSUING_DIST_POINT
  3140. // X509_ISSUING_DIST_POINT
  3141. //
  3142. // pvStructInfo points to the following CRL_ISSUING_DIST_POINT.
  3143. //
  3144. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3145. // *pcbEncoded by CryptEncodeObject(X509_ISSUING_DIST_POINT)
  3146. //
  3147. // Error location consists of:
  3148. // ENTRY_INDEX - 8 bits << 16
  3149. // VALUE_INDEX - 16 bits (unicode character index)
  3150. //
  3151. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3152. // defines.
  3153. //--------------------------------------------------------------------------
  3154. typedef struct _CRL_ISSUING_DIST_POINT {
  3155. CRL_DIST_POINT_NAME DistPointName; // OPTIONAL
  3156. BOOL fOnlyContainsUserCerts;
  3157. BOOL fOnlyContainsCACerts;
  3158. CRYPT_BIT_BLOB OnlySomeReasonFlags; // OPTIONAL
  3159. BOOL fIndirectCRL;
  3160. } CRL_ISSUING_DIST_POINT, *PCRL_ISSUING_DIST_POINT;
  3161. //+-------------------------------------------------------------------------
  3162. // szOID_FRESHEST_CRL
  3163. //
  3164. // pvStructInfo points to CRL_DIST_POINTS_INFO.
  3165. //--------------------------------------------------------------------------
  3166. //+-------------------------------------------------------------------------
  3167. // szOID_NAME_CONSTRAINTS
  3168. // X509_NAME_CONSTRAINTS
  3169. //
  3170. // pvStructInfo points to the following CERT_NAME_CONSTRAINTS_INFO
  3171. //
  3172. // For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  3173. // *pcbEncoded by CryptEncodeObject(X509_NAME_CONSTRAINTS)
  3174. //
  3175. // Error location consists of:
  3176. // EXCLUDED_SUBTREE_BIT - 1 bit << 31 (0 for permitted, 1 for excluded)
  3177. // ENTRY_INDEX - 8 bits << 16
  3178. // VALUE_INDEX - 16 bits (unicode character index)
  3179. //
  3180. // See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  3181. // defines.
  3182. //--------------------------------------------------------------------------
  3183. typedef struct _CERT_GENERAL_SUBTREE {
  3184. CERT_ALT_NAME_ENTRY Base;
  3185. DWORD dwMinimum;
  3186. BOOL fMaximum;
  3187. DWORD dwMaximum;
  3188. } CERT_GENERAL_SUBTREE, *PCERT_GENERAL_SUBTREE;
  3189. typedef struct _CERT_NAME_CONSTRAINTS_INFO {
  3190. DWORD cPermittedSubtree;
  3191. PCERT_GENERAL_SUBTREE rgPermittedSubtree;
  3192. DWORD cExcludedSubtree;
  3193. PCERT_GENERAL_SUBTREE rgExcludedSubtree;
  3194. } CERT_NAME_CONSTRAINTS_INFO, *PCERT_NAME_CONSTRAINTS_INFO;
  3195. #define CERT_EXCLUDED_SUBTREE_BIT 0x80000000L
  3196. #define IS_CERT_EXCLUDED_SUBTREE(X) \
  3197. (0 != (X & CERT_EXCLUDED_SUBTREE_BIT))
  3198. //+-------------------------------------------------------------------------
  3199. // szOID_NEXT_UPDATE_LOCATION
  3200. //
  3201. // pvStructInfo points to a CERT_ALT_NAME_INFO.
  3202. //--------------------------------------------------------------------------
  3203. //+-------------------------------------------------------------------------
  3204. // szOID_REMOVE_CERTIFICATE
  3205. //
  3206. // pvStructInfo points to an int which can be set to one of the following
  3207. // 0 - Add certificate
  3208. // 1 - Remove certificate
  3209. //--------------------------------------------------------------------------
  3210. //+-------------------------------------------------------------------------
  3211. // PKCS_CTL
  3212. // szOID_CTL
  3213. //
  3214. // pvStructInfo points to a CTL_INFO.
  3215. //--------------------------------------------------------------------------
  3216. //+-------------------------------------------------------------------------
  3217. // PKCS_SORTED_CTL
  3218. //
  3219. // pvStructInfo points to a CTL_INFO.
  3220. //
  3221. // Same as for PKCS_CTL, except, the CTL entries are sorted. The following
  3222. // extension containing the sort information is inserted as the first
  3223. // extension in the encoded CTL.
  3224. //
  3225. // Only supported for Encoding. CRYPT_ENCODE_ALLOC_FLAG flag must be
  3226. // set.
  3227. //--------------------------------------------------------------------------
  3228. //+-------------------------------------------------------------------------
  3229. // Sorted CTL TrustedSubjects extension
  3230. //
  3231. // Array of little endian DWORDs:
  3232. // [0] - Flags
  3233. // [1] - Count of HashBucket entry offsets
  3234. // [2] - Maximum HashBucket entry collision count
  3235. // [3 ..] (Count + 1) HashBucket entry offsets
  3236. //
  3237. // When this extension is present in the CTL,
  3238. // the ASN.1 encoded sequence of TrustedSubjects are HashBucket ordered.
  3239. //
  3240. // The entry offsets point to the start of the first encoded TrustedSubject
  3241. // sequence for the HashBucket. The encoded TrustedSubjects for a HashBucket
  3242. // continue until the encoded offset of the next HashBucket. A HashBucket has
  3243. // no entries if HashBucket[N] == HashBucket[N + 1].
  3244. //
  3245. // The HashBucket offsets are from the start of the ASN.1 encoded CTL_INFO.
  3246. //--------------------------------------------------------------------------
  3247. #define SORTED_CTL_EXT_FLAGS_OFFSET (0*4)
  3248. #define SORTED_CTL_EXT_COUNT_OFFSET (1*4)
  3249. #define SORTED_CTL_EXT_MAX_COLLISION_OFFSET (2*4)
  3250. #define SORTED_CTL_EXT_HASH_BUCKET_OFFSET (3*4)
  3251. // If the SubjectIdentifiers are a MD5 or SHA1 hash, the following flag is
  3252. // set. When set, the first 4 bytes of the SubjectIdentifier are used as
  3253. // the dwhash. Otherwise, the SubjectIdentifier bytes are hashed into dwHash.
  3254. // In either case the HashBucket index = dwHash % cHashBucket.
  3255. #define SORTED_CTL_EXT_HASHED_SUBJECT_IDENTIFIER_FLAG 0x1
  3256. //+-------------------------------------------------------------------------
  3257. // X509_MULTI_BYTE_UINT
  3258. //
  3259. // pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  3260. // leading 0x00. After decoding, removes a leading 0x00.
  3261. //--------------------------------------------------------------------------
  3262. //+-------------------------------------------------------------------------
  3263. // X509_DSS_PUBLICKEY
  3264. //
  3265. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3266. //--------------------------------------------------------------------------
  3267. //+-------------------------------------------------------------------------
  3268. // X509_DSS_PARAMETERS
  3269. //
  3270. // pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  3271. //--------------------------------------------------------------------------
  3272. typedef struct _CERT_DSS_PARAMETERS {
  3273. CRYPT_UINT_BLOB p;
  3274. CRYPT_UINT_BLOB q;
  3275. CRYPT_UINT_BLOB g;
  3276. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  3277. //+-------------------------------------------------------------------------
  3278. // X509_DSS_SIGNATURE
  3279. //
  3280. // pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  3281. // bytes are ordered as output by the DSS CSP's CryptSignHash().
  3282. //--------------------------------------------------------------------------
  3283. #define CERT_DSS_R_LEN 20
  3284. #define CERT_DSS_S_LEN 20
  3285. #define CERT_DSS_SIGNATURE_LEN (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  3286. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  3287. // 0x00 to make the integer unsigned)
  3288. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN (2 + 2*(2 + 20 +1))
  3289. //+-------------------------------------------------------------------------
  3290. // X509_DH_PUBLICKEY
  3291. //
  3292. // pvStructInfo points to a CRYPT_UINT_BLOB.
  3293. //--------------------------------------------------------------------------
  3294. //+-------------------------------------------------------------------------
  3295. // X509_DH_PARAMETERS
  3296. //
  3297. // pvStructInfo points to following CERT_DH_PARAMETERS data structure.
  3298. //--------------------------------------------------------------------------
  3299. typedef struct _CERT_DH_PARAMETERS {
  3300. CRYPT_UINT_BLOB p;
  3301. CRYPT_UINT_BLOB g;
  3302. } CERT_DH_PARAMETERS, *PCERT_DH_PARAMETERS;
  3303. //+-------------------------------------------------------------------------
  3304. // X942_DH_PARAMETERS
  3305. //
  3306. // pvStructInfo points to following CERT_X942_DH_PARAMETERS data structure.
  3307. //
  3308. // If q.cbData == 0, then, the following fields are zero'ed.
  3309. //--------------------------------------------------------------------------
  3310. typedef struct _CERT_X942_DH_VALIDATION_PARAMS {
  3311. CRYPT_BIT_BLOB seed;
  3312. DWORD pgenCounter;
  3313. } CERT_X942_DH_VALIDATION_PARAMS, *PCERT_X942_DH_VALIDATION_PARAMS;
  3314. typedef struct _CERT_X942_DH_PARAMETERS {
  3315. CRYPT_UINT_BLOB p; // odd prime, p = jq + 1
  3316. CRYPT_UINT_BLOB g; // generator, g
  3317. CRYPT_UINT_BLOB q; // factor of p - 1, OPTIONAL
  3318. CRYPT_UINT_BLOB j; // subgroup factor, OPTIONAL
  3319. PCERT_X942_DH_VALIDATION_PARAMS pValidationParams; // OPTIONAL
  3320. } CERT_X942_DH_PARAMETERS, *PCERT_X942_DH_PARAMETERS;
  3321. //+-------------------------------------------------------------------------
  3322. // X942_OTHER_INFO
  3323. //
  3324. // pvStructInfo points to following CRYPT_X942_OTHER_INFO data structure.
  3325. //
  3326. // rgbCounter and rgbKeyLength are in Little Endian order.
  3327. //--------------------------------------------------------------------------
  3328. #define CRYPT_X942_COUNTER_BYTE_LENGTH 4
  3329. #define CRYPT_X942_KEY_LENGTH_BYTE_LENGTH 4
  3330. #define CRYPT_X942_PUB_INFO_BYTE_LENGTH (512/8)
  3331. typedef struct _CRYPT_X942_OTHER_INFO {
  3332. LPSTR pszContentEncryptionObjId;
  3333. BYTE rgbCounter[CRYPT_X942_COUNTER_BYTE_LENGTH];
  3334. BYTE rgbKeyLength[CRYPT_X942_KEY_LENGTH_BYTE_LENGTH];
  3335. CRYPT_DATA_BLOB PubInfo; // OPTIONAL
  3336. } CRYPT_X942_OTHER_INFO, *PCRYPT_X942_OTHER_INFO;
  3337. //+-------------------------------------------------------------------------
  3338. // PKCS_RC2_CBC_PARAMETERS
  3339. // szOID_RSA_RC2CBC
  3340. //
  3341. // pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  3342. //--------------------------------------------------------------------------
  3343. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  3344. DWORD dwVersion;
  3345. BOOL fIV; // set if has following IV
  3346. BYTE rgbIV[8];
  3347. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  3348. #define CRYPT_RC2_40BIT_VERSION 160
  3349. #define CRYPT_RC2_56BIT_VERSION 52
  3350. #define CRYPT_RC2_64BIT_VERSION 120
  3351. #define CRYPT_RC2_128BIT_VERSION 58
  3352. //+-------------------------------------------------------------------------
  3353. // PKCS_SMIME_CAPABILITIES
  3354. // szOID_RSA_SMIMECapabilities
  3355. //
  3356. // pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  3357. //
  3358. // Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  3359. // causes the encoded parameters to be omitted and not encoded as a NULL
  3360. // (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  3361. // is per the SMIME specification for encoding capabilities.
  3362. //--------------------------------------------------------------------------
  3363. typedef struct _CRYPT_SMIME_CAPABILITY {
  3364. LPSTR pszObjId;
  3365. CRYPT_OBJID_BLOB Parameters;
  3366. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  3367. typedef struct _CRYPT_SMIME_CAPABILITIES {
  3368. DWORD cCapability;
  3369. PCRYPT_SMIME_CAPABILITY rgCapability;
  3370. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  3371. //+-------------------------------------------------------------------------
  3372. // PKCS7_SIGNER_INFO
  3373. //
  3374. // pvStructInfo points to CMSG_SIGNER_INFO.
  3375. //--------------------------------------------------------------------------
  3376. //+-------------------------------------------------------------------------
  3377. // CMS_SIGNER_INFO
  3378. //
  3379. // pvStructInfo points to CMSG_CMS_SIGNER_INFO.
  3380. //--------------------------------------------------------------------------
  3381. //+-------------------------------------------------------------------------
  3382. // Verisign Certificate Extension Object Identifiers
  3383. //--------------------------------------------------------------------------
  3384. // Octet String containing Boolean
  3385. #define szOID_VERISIGN_PRIVATE_6_9 "2.16.840.1.113733.1.6.9"
  3386. // Octet String containing IA5 string: lower case 32 char hex string
  3387. #define szOID_VERISIGN_ONSITE_JURISDICTION_HASH "2.16.840.1.113733.1.6.11"
  3388. // Octet String containing Bit string
  3389. #define szOID_VERISIGN_BITSTRING_6_13 "2.16.840.1.113733.1.6.13"
  3390. // EKU
  3391. #define szOID_VERISIGN_ISS_STRONG_CRYPTO "2.16.840.1.113733.1.8.1"
  3392. //+-------------------------------------------------------------------------
  3393. // Netscape Certificate Extension Object Identifiers
  3394. //--------------------------------------------------------------------------
  3395. #define szOID_NETSCAPE "2.16.840.1.113730"
  3396. #define szOID_NETSCAPE_CERT_EXTENSION "2.16.840.1.113730.1"
  3397. #define szOID_NETSCAPE_CERT_TYPE "2.16.840.1.113730.1.1"
  3398. #define szOID_NETSCAPE_BASE_URL "2.16.840.1.113730.1.2"
  3399. #define szOID_NETSCAPE_REVOCATION_URL "2.16.840.1.113730.1.3"
  3400. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  3401. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  3402. #define szOID_NETSCAPE_CA_POLICY_URL "2.16.840.1.113730.1.8"
  3403. #define szOID_NETSCAPE_SSL_SERVER_NAME "2.16.840.1.113730.1.12"
  3404. #define szOID_NETSCAPE_COMMENT "2.16.840.1.113730.1.13"
  3405. //+-------------------------------------------------------------------------
  3406. // Netscape Certificate Data Type Object Identifiers
  3407. //--------------------------------------------------------------------------
  3408. #define szOID_NETSCAPE_DATA_TYPE "2.16.840.1.113730.2"
  3409. #define szOID_NETSCAPE_CERT_SEQUENCE "2.16.840.1.113730.2.5"
  3410. //+-------------------------------------------------------------------------
  3411. // szOID_NETSCAPE_CERT_TYPE extension
  3412. //
  3413. // Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  3414. // X509_BITS or X509_BITS_WITHOUT_TRAILING_ZEROES.
  3415. //
  3416. // The following bits are defined:
  3417. //--------------------------------------------------------------------------
  3418. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE 0x80
  3419. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE 0x40
  3420. #define NETSCAPE_SMIME_CERT_TYPE 0x20
  3421. #define NETSCAPE_SIGN_CERT_TYPE 0x10
  3422. #define NETSCAPE_SSL_CA_CERT_TYPE 0x04
  3423. #define NETSCAPE_SMIME_CA_CERT_TYPE 0x02
  3424. #define NETSCAPE_SIGN_CA_CERT_TYPE 0x01
  3425. //+-------------------------------------------------------------------------
  3426. // szOID_NETSCAPE_BASE_URL extension
  3427. //
  3428. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3429. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3430. // dwValueType = CERT_RDN_IA5_STRING.
  3431. //
  3432. // When present this string is added to the beginning of all relative URLs
  3433. // in the certificate. This extension can be considered an optimization
  3434. // to reduce the size of the URL extensions.
  3435. //--------------------------------------------------------------------------
  3436. //+-------------------------------------------------------------------------
  3437. // szOID_NETSCAPE_REVOCATION_URL extension
  3438. //
  3439. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3440. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3441. // dwValueType = CERT_RDN_IA5_STRING.
  3442. //
  3443. // It is a relative or absolute URL that can be used to check the
  3444. // revocation status of a certificate. The revocation check will be
  3445. // performed as an HTTP GET method using a url that is the concatenation of
  3446. // revocation-url and certificate-serial-number.
  3447. // Where the certificate-serial-number is encoded as a string of
  3448. // ascii hexadecimal digits. For example, if the netscape-base-url is
  3449. // https://www.certs-r-us.com/, the netscape-revocation-url is
  3450. // cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  3451. // the resulting URL would be:
  3452. // https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  3453. //
  3454. // The server should return a document with a Content-Type of
  3455. // application/x-netscape-revocation. The document should contain
  3456. // a single ascii digit, '1' if the certificate is not curently valid,
  3457. // and '0' if it is curently valid.
  3458. //
  3459. // Note: for all of the URLs that include the certificate serial number,
  3460. // the serial number will be encoded as a string which consists of an even
  3461. // number of hexadecimal digits. If the number of significant digits is odd,
  3462. // the string will have a single leading zero to ensure an even number of
  3463. // digits is generated.
  3464. //--------------------------------------------------------------------------
  3465. //+-------------------------------------------------------------------------
  3466. // szOID_NETSCAPE_CA_REVOCATION_URL extension
  3467. //
  3468. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3469. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3470. // dwValueType = CERT_RDN_IA5_STRING.
  3471. //
  3472. // It is a relative or absolute URL that can be used to check the
  3473. // revocation status of any certificates that are signed by the CA that
  3474. // this certificate belongs to. This extension is only valid in CA
  3475. // certificates. The use of this extension is the same as the above
  3476. // szOID_NETSCAPE_REVOCATION_URL extension.
  3477. //--------------------------------------------------------------------------
  3478. //+-------------------------------------------------------------------------
  3479. // szOID_NETSCAPE_CERT_RENEWAL_URL extension
  3480. //
  3481. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3482. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3483. // dwValueType = CERT_RDN_IA5_STRING.
  3484. //
  3485. // It is a relative or absolute URL that points to a certificate renewal
  3486. // form. The renewal form will be accessed with an HTTP GET method using a
  3487. // url that is the concatenation of renewal-url and
  3488. // certificate-serial-number. Where the certificate-serial-number is
  3489. // encoded as a string of ascii hexadecimal digits. For example, if the
  3490. // netscape-base-url is https://www.certs-r-us.com/, the
  3491. // netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  3492. // certificate serial number is 173420, the resulting URL would be:
  3493. // https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  3494. // The document returned should be an HTML form that will allow the user
  3495. // to request a renewal of their certificate.
  3496. //--------------------------------------------------------------------------
  3497. //+-------------------------------------------------------------------------
  3498. // szOID_NETSCAPE_CA_POLICY_URL extension
  3499. //
  3500. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3501. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3502. // dwValueType = CERT_RDN_IA5_STRING.
  3503. //
  3504. // It is a relative or absolute URL that points to a web page that
  3505. // describes the policies under which the certificate was issued.
  3506. //--------------------------------------------------------------------------
  3507. //+-------------------------------------------------------------------------
  3508. // szOID_NETSCAPE_SSL_SERVER_NAME extension
  3509. //
  3510. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3511. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3512. // dwValueType = CERT_RDN_IA5_STRING.
  3513. //
  3514. // It is a "shell expression" that can be used to match the hostname of the
  3515. // SSL server that is using this certificate. It is recommended that if
  3516. // the server's hostname does not match this pattern the user be notified
  3517. // and given the option to terminate the SSL connection. If this extension
  3518. // is not present then the CommonName in the certificate subject's
  3519. // distinguished name is used for the same purpose.
  3520. //--------------------------------------------------------------------------
  3521. //+-------------------------------------------------------------------------
  3522. // szOID_NETSCAPE_COMMENT extension
  3523. //
  3524. // Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  3525. // X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  3526. // dwValueType = CERT_RDN_IA5_STRING.
  3527. //
  3528. // It is a comment that may be displayed to the user when the certificate
  3529. // is viewed.
  3530. //--------------------------------------------------------------------------
  3531. //+-------------------------------------------------------------------------
  3532. // szOID_NETSCAPE_CERT_SEQUENCE
  3533. //
  3534. // Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  3535. // certificates. The value of the contentType field is
  3536. // szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  3537. // structure:
  3538. // CertificateSequence ::= SEQUENCE OF Certificate.
  3539. //
  3540. // CryptDecodeObject/CryptEncodeObject using
  3541. // PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  3542. // pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  3543. // to encoded X509 certificates.
  3544. //--------------------------------------------------------------------------
  3545. //+=========================================================================
  3546. // Certificate Management Messages over CMS (CMC) Data Structures
  3547. //==========================================================================
  3548. // Content Type (request)
  3549. #define szOID_CT_PKI_DATA "1.3.6.1.5.5.7.12.2"
  3550. // Content Type (response)
  3551. #define szOID_CT_PKI_RESPONSE "1.3.6.1.5.5.7.12.3"
  3552. // Signature value that only contains the hash octets. The parameters for
  3553. // this algorithm must be present and must be encoded as NULL.
  3554. #define szOID_PKIX_NO_SIGNATURE "1.3.6.1.5.5.7.6.2"
  3555. #define szOID_CMC "1.3.6.1.5.5.7.7"
  3556. #define szOID_CMC_STATUS_INFO "1.3.6.1.5.5.7.7.1"
  3557. #define szOID_CMC_IDENTIFICATION "1.3.6.1.5.5.7.7.2"
  3558. #define szOID_CMC_IDENTITY_PROOF "1.3.6.1.5.5.7.7.3"
  3559. #define szOID_CMC_DATA_RETURN "1.3.6.1.5.5.7.7.4"
  3560. // Transaction Id (integer)
  3561. #define szOID_CMC_TRANSACTION_ID "1.3.6.1.5.5.7.7.5"
  3562. // Sender Nonce (octet string)
  3563. #define szOID_CMC_SENDER_NONCE "1.3.6.1.5.5.7.7.6"
  3564. // Recipient Nonce (octet string)
  3565. #define szOID_CMC_RECIPIENT_NONCE "1.3.6.1.5.5.7.7.7"
  3566. #define szOID_CMC_ADD_EXTENSIONS "1.3.6.1.5.5.7.7.8"
  3567. #define szOID_CMC_ENCRYPTED_POP "1.3.6.1.5.5.7.7.9"
  3568. #define szOID_CMC_DECRYPTED_POP "1.3.6.1.5.5.7.7.10"
  3569. #define szOID_CMC_LRA_POP_WITNESS "1.3.6.1.5.5.7.7.11"
  3570. // Issuer Name + Serial
  3571. #define szOID_CMC_GET_CERT "1.3.6.1.5.5.7.7.15"
  3572. // Issuer Name [+ CRL Name] + Time [+ Reasons]
  3573. #define szOID_CMC_GET_CRL "1.3.6.1.5.5.7.7.16"
  3574. // Issuer Name + Serial [+ Reason] [+ Effective Time] [+ Secret] [+ Comment]
  3575. #define szOID_CMC_REVOKE_REQUEST "1.3.6.1.5.5.7.7.17"
  3576. // (octet string) URL-style parameter list (IA5?)
  3577. #define szOID_CMC_REG_INFO "1.3.6.1.5.5.7.7.18"
  3578. #define szOID_CMC_RESPONSE_INFO "1.3.6.1.5.5.7.7.19"
  3579. // (octet string)
  3580. #define szOID_CMC_QUERY_PENDING "1.3.6.1.5.5.7.7.21"
  3581. #define szOID_CMC_ID_POP_LINK_RANDOM "1.3.6.1.5.5.7.7.22"
  3582. #define szOID_CMC_ID_POP_LINK_WITNESS "1.3.6.1.5.5.7.7.23"
  3583. // optional Name + Integer
  3584. #define szOID_CMC_ID_CONFIRM_CERT_ACCEPTANCE "1.3.6.1.5.5.7.7.24"
  3585. #define szOID_CMC_ADD_ATTRIBUTES "1.3.6.1.4.1.311.10.10.1"
  3586. //+-------------------------------------------------------------------------
  3587. // CMC_DATA
  3588. // CMC_RESPONSE
  3589. //
  3590. // Certificate Management Messages over CMS (CMC) PKIData and Response
  3591. // messages.
  3592. //
  3593. // For CMC_DATA, pvStructInfo points to a CMC_DATA_INFO.
  3594. // CMC_DATA_INFO contains optional arrays of tagged attributes, requests,
  3595. // content info and/or arbitrary other messages.
  3596. //
  3597. // For CMC_RESPONSE, pvStructInfo points to a CMC_RESPONSE_INFO.
  3598. // CMC_RESPONSE_INFO is the same as CMC_DATA_INFO without the tagged
  3599. // requests.
  3600. //--------------------------------------------------------------------------
  3601. typedef struct _CMC_TAGGED_ATTRIBUTE {
  3602. DWORD dwBodyPartID;
  3603. CRYPT_ATTRIBUTE Attribute;
  3604. } CMC_TAGGED_ATTRIBUTE, *PCMC_TAGGED_ATTRIBUTE;
  3605. typedef struct _CMC_TAGGED_CERT_REQUEST {
  3606. DWORD dwBodyPartID;
  3607. CRYPT_DER_BLOB SignedCertRequest;
  3608. } CMC_TAGGED_CERT_REQUEST, *PCMC_TAGGED_CERT_REQUEST;
  3609. typedef struct _CMC_TAGGED_REQUEST {
  3610. DWORD dwTaggedRequestChoice;
  3611. union {
  3612. // CMC_TAGGED_CERT_REQUEST_CHOICE
  3613. PCMC_TAGGED_CERT_REQUEST pTaggedCertRequest;
  3614. };
  3615. } CMC_TAGGED_REQUEST, *PCMC_TAGGED_REQUEST;
  3616. #define CMC_TAGGED_CERT_REQUEST_CHOICE 1
  3617. typedef struct _CMC_TAGGED_CONTENT_INFO {
  3618. DWORD dwBodyPartID;
  3619. CRYPT_DER_BLOB EncodedContentInfo;
  3620. } CMC_TAGGED_CONTENT_INFO, *PCMC_TAGGED_CONTENT_INFO;
  3621. typedef struct _CMC_TAGGED_OTHER_MSG {
  3622. DWORD dwBodyPartID;
  3623. LPSTR pszObjId;
  3624. CRYPT_OBJID_BLOB Value;
  3625. } CMC_TAGGED_OTHER_MSG, *PCMC_TAGGED_OTHER_MSG;
  3626. // All the tagged arrays are optional
  3627. typedef struct _CMC_DATA_INFO {
  3628. DWORD cTaggedAttribute;
  3629. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3630. DWORD cTaggedRequest;
  3631. PCMC_TAGGED_REQUEST rgTaggedRequest;
  3632. DWORD cTaggedContentInfo;
  3633. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3634. DWORD cTaggedOtherMsg;
  3635. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3636. } CMC_DATA_INFO, *PCMC_DATA_INFO;
  3637. // All the tagged arrays are optional
  3638. typedef struct _CMC_RESPONSE_INFO {
  3639. DWORD cTaggedAttribute;
  3640. PCMC_TAGGED_ATTRIBUTE rgTaggedAttribute;
  3641. DWORD cTaggedContentInfo;
  3642. PCMC_TAGGED_CONTENT_INFO rgTaggedContentInfo;
  3643. DWORD cTaggedOtherMsg;
  3644. PCMC_TAGGED_OTHER_MSG rgTaggedOtherMsg;
  3645. } CMC_RESPONSE_INFO, *PCMC_RESPONSE_INFO;
  3646. //+-------------------------------------------------------------------------
  3647. // CMC_STATUS
  3648. //
  3649. // Certificate Management Messages over CMS (CMC) Status.
  3650. //
  3651. // pvStructInfo points to a CMC_STATUS_INFO.
  3652. //--------------------------------------------------------------------------
  3653. typedef struct _CMC_PEND_INFO {
  3654. CRYPT_DATA_BLOB PendToken;
  3655. FILETIME PendTime;
  3656. } CMC_PEND_INFO, *PCMC_PEND_INFO;
  3657. typedef struct _CMC_STATUS_INFO {
  3658. DWORD dwStatus;
  3659. DWORD cBodyList;
  3660. DWORD *rgdwBodyList;
  3661. LPWSTR pwszStatusString; // OPTIONAL
  3662. DWORD dwOtherInfoChoice;
  3663. union {
  3664. // CMC_OTHER_INFO_NO_CHOICE
  3665. // none
  3666. // CMC_OTHER_INFO_FAIL_CHOICE
  3667. DWORD dwFailInfo;
  3668. // CMC_OTHER_INFO_PEND_CHOICE
  3669. PCMC_PEND_INFO pPendInfo;
  3670. };
  3671. } CMC_STATUS_INFO, *PCMC_STATUS_INFO;
  3672. #define CMC_OTHER_INFO_NO_CHOICE 0
  3673. #define CMC_OTHER_INFO_FAIL_CHOICE 1
  3674. #define CMC_OTHER_INFO_PEND_CHOICE 2
  3675. //
  3676. // dwStatus values
  3677. //
  3678. // Request was granted
  3679. #define CMC_STATUS_SUCCESS 0
  3680. // Request failed, more information elsewhere in the message
  3681. #define CMC_STATUS_FAILED 2
  3682. // The request body part has not yet been processed. Requester is responsible
  3683. // to poll back. May only be returned for certificate request operations.
  3684. #define CMC_STATUS_PENDING 3
  3685. // The requested operation is not supported
  3686. #define CMC_STATUS_NO_SUPPORT 4
  3687. // Confirmation using the idConfirmCertAcceptance control is required
  3688. // before use of certificate
  3689. #define CMC_STATUS_CONFIRM_REQUIRED 5
  3690. //
  3691. // dwFailInfo values
  3692. //
  3693. // Unrecognized or unsupported algorithm
  3694. #define CMC_FAIL_BAD_ALG 0
  3695. // Integrity check failed
  3696. #define CMC_FAIL_BAD_MESSAGE_CHECK 1
  3697. // Transaction not permitted or supported
  3698. #define CMC_FAIL_BAD_REQUEST 2
  3699. // Message time field was not sufficiently close to the system time
  3700. #define CMC_FAIL_BAD_TIME 3
  3701. // No certificate could be identified matching the provided criteria
  3702. #define CMC_FAIL_BAD_CERT_ID 4
  3703. // A requested X.509 extension is not supported by the recipient CA.
  3704. #define CMC_FAIL_UNSUPORTED_EXT 5
  3705. // Private key material must be supplied
  3706. #define CMC_FAIL_MUST_ARCHIVE_KEYS 6
  3707. // Identification Attribute failed to verify
  3708. #define CMC_FAIL_BAD_IDENTITY 7
  3709. // Server requires a POP proof before issuing certificate
  3710. #define CMC_FAIL_POP_REQUIRED 8
  3711. // POP processing failed
  3712. #define CMC_FAIL_POP_FAILED 9
  3713. // Server policy does not allow key re-use
  3714. #define CMC_FAIL_NO_KEY_REUSE 10
  3715. #define CMC_FAIL_INTERNAL_CA_ERROR 11
  3716. #define CMC_FAIL_TRY_LATER 12
  3717. //+-------------------------------------------------------------------------
  3718. // CMC_ADD_EXTENSIONS
  3719. //
  3720. // Certificate Management Messages over CMS (CMC) Add Extensions control
  3721. // attribute.
  3722. //
  3723. // pvStructInfo points to a CMC_ADD_EXTENSIONS_INFO.
  3724. //--------------------------------------------------------------------------
  3725. typedef struct _CMC_ADD_EXTENSIONS_INFO {
  3726. DWORD dwCmcDataReference;
  3727. DWORD cCertReference;
  3728. DWORD *rgdwCertReference;
  3729. DWORD cExtension;
  3730. PCERT_EXTENSION rgExtension;
  3731. } CMC_ADD_EXTENSIONS_INFO, *PCMC_ADD_EXTENSIONS_INFO;
  3732. //+-------------------------------------------------------------------------
  3733. // CMC_ADD_ATTRIBUTES
  3734. //
  3735. // Certificate Management Messages over CMS (CMC) Add Attributes control
  3736. // attribute.
  3737. //
  3738. // pvStructInfo points to a CMC_ADD_ATTRIBUTES_INFO.
  3739. //--------------------------------------------------------------------------
  3740. typedef struct _CMC_ADD_ATTRIBUTES_INFO {
  3741. DWORD dwCmcDataReference;
  3742. DWORD cCertReference;
  3743. DWORD *rgdwCertReference;
  3744. DWORD cAttribute;
  3745. PCRYPT_ATTRIBUTE rgAttribute;
  3746. } CMC_ADD_ATTRIBUTES_INFO, *PCMC_ADD_ATTRIBUTES_INFO;
  3747. //+-------------------------------------------------------------------------
  3748. // X509_CERTIFICATE_TEMPLATE
  3749. // szOID_CERTIFICATE_TEMPLATE
  3750. //
  3751. // pvStructInfo points to following CERT_TEMPLATE_EXT data structure.
  3752. //
  3753. //--------------------------------------------------------------------------
  3754. typedef struct _CERT_TEMPLATE_EXT {
  3755. LPSTR pszObjId;
  3756. DWORD dwMajorVersion;
  3757. BOOL fMinorVersion; // TRUE for a minor version
  3758. DWORD dwMinorVersion;
  3759. } CERT_TEMPLATE_EXT, *PCERT_TEMPLATE_EXT;
  3760. //+=========================================================================
  3761. // Object IDentifier (OID) Installable Functions: Data Structures and APIs
  3762. //==========================================================================
  3763. typedef void *HCRYPTOIDFUNCSET;
  3764. typedef void *HCRYPTOIDFUNCADDR;
  3765. // Predefined OID Function Names
  3766. #define CRYPT_OID_ENCODE_OBJECT_FUNC "CryptDllEncodeObject"
  3767. #define CRYPT_OID_DECODE_OBJECT_FUNC "CryptDllDecodeObject"
  3768. #define CRYPT_OID_ENCODE_OBJECT_EX_FUNC "CryptDllEncodeObjectEx"
  3769. #define CRYPT_OID_DECODE_OBJECT_EX_FUNC "CryptDllDecodeObjectEx"
  3770. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC "CryptDllCreateCOMObject"
  3771. #define CRYPT_OID_VERIFY_REVOCATION_FUNC "CertDllVerifyRevocation"
  3772. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC "CertDllVerifyCTLUsage"
  3773. #define CRYPT_OID_FORMAT_OBJECT_FUNC "CryptDllFormatObject"
  3774. #define CRYPT_OID_FIND_OID_INFO_FUNC "CryptDllFindOIDInfo"
  3775. #define CRYPT_OID_FIND_LOCALIZED_NAME_FUNC "CryptDllFindLocalizedName"
  3776. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  3777. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  3778. // CryptDllEncodeObjectEx has same function signature as CryptEncodeObjectEx.
  3779. // The Ex version MUST support the CRYPT_ENCODE_ALLOC_FLAG option.
  3780. //
  3781. // If an Ex function isn't installed or registered, then, attempts to find
  3782. // a non-EX version. If the ALLOC flag is set, then, CryptEncodeObjectEx,
  3783. // does the allocation and calls the non-EX version twice.
  3784. // CryptDllDecodeObjectEx has same function signature as CryptDecodeObjectEx.
  3785. // The Ex version MUST support the CRYPT_DECODE_ALLOC_FLAG option.
  3786. //
  3787. // If an Ex function isn't installed or registered, then, attempts to find
  3788. // a non-EX version. If the ALLOC flag is set, then, CryptDecodeObjectEx,
  3789. // does the allocation and calls the non-EX version twice.
  3790. // CryptDllCreateCOMObject has the following signature:
  3791. // BOOL WINAPI CryptDllCreateCOMObject(
  3792. // IN DWORD dwEncodingType,
  3793. // IN LPCSTR pszOID,
  3794. // IN PCRYPT_DATA_BLOB pEncodedContent,
  3795. // IN DWORD dwFlags,
  3796. // IN REFIID riid,
  3797. // OUT void **ppvObj);
  3798. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  3799. // (See CertVerifyRevocation for details on when called)
  3800. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  3801. // CryptDllFindOIDInfo currently is only used to store values used by
  3802. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  3803. // CryptDllFindLocalizedName is only used to store localized string
  3804. // values used by CryptFindLocalizedName. See CryptFindLocalizedName() for
  3805. // more details.
  3806. // Example of a complete OID Function Registry Name:
  3807. // HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  3808. // Encoding Type 1\CryptDllEncodeObject\1.2.3
  3809. //
  3810. // The key's L"Dll" value contains the name of the Dll.
  3811. // The key's L"FuncName" value overrides the default function name
  3812. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  3813. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX "EncodingType "
  3814. #define CRYPT_OID_REG_DLL_VALUE_NAME L"Dll"
  3815. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME L"FuncName"
  3816. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  3817. // CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG can be set in the key's L"CryptFlags"
  3818. // value to register the functions before the installed functions.
  3819. //
  3820. // CryptSetOIDFunctionValue must be called to set this value. L"CryptFlags"
  3821. // must be set using a dwValueType of REG_DWORD.
  3822. #define CRYPT_OID_REG_FLAGS_VALUE_NAME L"CryptFlags"
  3823. // OID used for Default OID functions
  3824. #define CRYPT_DEFAULT_OID "DEFAULT"
  3825. typedef struct _CRYPT_OID_FUNC_ENTRY {
  3826. LPCSTR pszOID;
  3827. void *pvFuncAddr;
  3828. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  3829. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG 1
  3830. //+-------------------------------------------------------------------------
  3831. // Install a set of callable OID function addresses.
  3832. //
  3833. // By default the functions are installed at end of the list.
  3834. // Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  3835. //
  3836. // hModule should be updated with the hModule passed to DllMain to prevent
  3837. // the Dll containing the function addresses from being unloaded by
  3838. // CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  3839. // case when the Dll has also regsvr32'ed OID functions via
  3840. // CryptRegisterOIDFunction.
  3841. //
  3842. // DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  3843. // CRYPT_DEFAULT_OID.
  3844. //--------------------------------------------------------------------------
  3845. WINCRYPT32API
  3846. BOOL
  3847. WINAPI
  3848. CryptInstallOIDFunctionAddress(
  3849. IN HMODULE hModule, // hModule passed to DllMain
  3850. IN DWORD dwEncodingType,
  3851. IN LPCSTR pszFuncName,
  3852. IN DWORD cFuncEntry,
  3853. IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  3854. IN DWORD dwFlags
  3855. );
  3856. //+-------------------------------------------------------------------------
  3857. // Initialize and return handle to the OID function set identified by its
  3858. // function name.
  3859. //
  3860. // If the set already exists, a handle to the existing set is returned.
  3861. //--------------------------------------------------------------------------
  3862. WINCRYPT32API
  3863. HCRYPTOIDFUNCSET
  3864. WINAPI
  3865. CryptInitOIDFunctionSet(
  3866. IN LPCSTR pszFuncName,
  3867. IN DWORD dwFlags
  3868. );
  3869. //+-------------------------------------------------------------------------
  3870. // Search the list of installed functions for an encoding type and OID match.
  3871. // If not found, search the registry.
  3872. //
  3873. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3874. // address and *phFuncAddr updated with the function address's handle.
  3875. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3876. // be called to release it.
  3877. //
  3878. // For a registry match, the Dll containing the function is loaded.
  3879. //
  3880. // By default, both the registered and installed function lists are searched.
  3881. // Set CRYPT_GET_INSTALLED_OID_FUNC_FLAG to only search the installed list
  3882. // of functions. This flag would be set by a registered function to get
  3883. // the address of a pre-installed function it was replacing. For example,
  3884. // the registered function might handle a new special case and call the
  3885. // pre-installed function to handle the remaining cases.
  3886. //--------------------------------------------------------------------------
  3887. WINCRYPT32API
  3888. BOOL
  3889. WINAPI
  3890. CryptGetOIDFunctionAddress(
  3891. IN HCRYPTOIDFUNCSET hFuncSet,
  3892. IN DWORD dwEncodingType,
  3893. IN LPCSTR pszOID,
  3894. IN DWORD dwFlags,
  3895. OUT void **ppvFuncAddr,
  3896. OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3897. );
  3898. #define CRYPT_GET_INSTALLED_OID_FUNC_FLAG 0x1
  3899. //+-------------------------------------------------------------------------
  3900. // Get the list of registered default Dll entries for the specified
  3901. // function set and encoding type.
  3902. //
  3903. // The returned list consists of none, one or more null terminated Dll file
  3904. // names. The list is terminated with an empty (L"\0") Dll file name.
  3905. // For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  3906. //--------------------------------------------------------------------------
  3907. WINCRYPT32API
  3908. BOOL
  3909. WINAPI
  3910. CryptGetDefaultOIDDllList(
  3911. IN HCRYPTOIDFUNCSET hFuncSet,
  3912. IN DWORD dwEncodingType,
  3913. OUT LPWSTR pwszDllList,
  3914. IN OUT DWORD *pcchDllList
  3915. );
  3916. //+-------------------------------------------------------------------------
  3917. // Either: get the first or next installed DEFAULT function OR
  3918. // load the Dll containing the DEFAULT function.
  3919. //
  3920. // If pwszDll is NULL, search the list of installed DEFAULT functions.
  3921. // *phFuncAddr must be set to NULL to get the first installed function.
  3922. // Successive installed functions are returned by setting *phFuncAddr
  3923. // to the hFuncAddr returned by the previous call.
  3924. //
  3925. // If pwszDll is NULL, the input *phFuncAddr
  3926. // is always CryptFreeOIDFunctionAddress'ed by this function, even for
  3927. // an error.
  3928. //
  3929. // If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  3930. // function. *phFuncAddr is ignored upon entry and isn't
  3931. // CryptFreeOIDFunctionAddress'ed.
  3932. //
  3933. // For success, returns TRUE with *ppvFuncAddr updated with the function's
  3934. // address and *phFuncAddr updated with the function address's handle.
  3935. // The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  3936. // be called to release it or CryptGetDefaultOIDFunctionAddress can also
  3937. // be called for a NULL pwszDll.
  3938. //--------------------------------------------------------------------------
  3939. WINCRYPT32API
  3940. BOOL
  3941. WINAPI
  3942. CryptGetDefaultOIDFunctionAddress(
  3943. IN HCRYPTOIDFUNCSET hFuncSet,
  3944. IN DWORD dwEncodingType,
  3945. IN OPTIONAL LPCWSTR pwszDll,
  3946. IN DWORD dwFlags,
  3947. OUT void **ppvFuncAddr,
  3948. IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  3949. );
  3950. //+-------------------------------------------------------------------------
  3951. // Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  3952. // or CryptGetDefaultOIDFunctionAddress.
  3953. //
  3954. // If a Dll was loaded for the function its unloaded. However, before doing
  3955. // the unload, the DllCanUnloadNow function exported by the loaded Dll is
  3956. // called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  3957. // the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  3958. //
  3959. // DllCanUnloadNow has the following signature:
  3960. // STDAPI DllCanUnloadNow(void);
  3961. //--------------------------------------------------------------------------
  3962. WINCRYPT32API
  3963. BOOL
  3964. WINAPI
  3965. CryptFreeOIDFunctionAddress(
  3966. IN HCRYPTOIDFUNCADDR hFuncAddr,
  3967. IN DWORD dwFlags
  3968. );
  3969. //+-------------------------------------------------------------------------
  3970. // Register the Dll containing the function to be called for the specified
  3971. // encoding type, function name and OID.
  3972. //
  3973. // pwszDll may contain environment-variable strings
  3974. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  3975. //
  3976. // In addition to registering the DLL, you may override the
  3977. // name of the function to be called. For example,
  3978. // pszFuncName = "CryptDllEncodeObject",
  3979. // pszOverrideFuncName = "MyEncodeXyz".
  3980. // This allows a Dll to export multiple OID functions for the same
  3981. // function name without needing to interpose its own OID dispatcher function.
  3982. //--------------------------------------------------------------------------
  3983. WINCRYPT32API
  3984. BOOL
  3985. WINAPI
  3986. CryptRegisterOIDFunction(
  3987. IN DWORD dwEncodingType,
  3988. IN LPCSTR pszFuncName,
  3989. IN LPCSTR pszOID,
  3990. IN OPTIONAL LPCWSTR pwszDll,
  3991. IN OPTIONAL LPCSTR pszOverrideFuncName
  3992. );
  3993. //+-------------------------------------------------------------------------
  3994. // Unregister the Dll containing the function to be called for the specified
  3995. // encoding type, function name and OID.
  3996. //--------------------------------------------------------------------------
  3997. WINCRYPT32API
  3998. BOOL
  3999. WINAPI
  4000. CryptUnregisterOIDFunction(
  4001. IN DWORD dwEncodingType,
  4002. IN LPCSTR pszFuncName,
  4003. IN LPCSTR pszOID
  4004. );
  4005. //+-------------------------------------------------------------------------
  4006. // Register the Dll containing the default function to be called for the
  4007. // specified encoding type and function name.
  4008. //
  4009. // Unlike CryptRegisterOIDFunction, you can't override the function name
  4010. // needing to be exported by the Dll.
  4011. //
  4012. // The Dll is inserted before the entry specified by dwIndex.
  4013. // dwIndex == 0, inserts at the beginning.
  4014. // dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  4015. //
  4016. // pwszDll may contain environment-variable strings
  4017. // which are ExpandEnvironmentStrings()'ed before loading the Dll.
  4018. //--------------------------------------------------------------------------
  4019. WINCRYPT32API
  4020. BOOL
  4021. WINAPI
  4022. CryptRegisterDefaultOIDFunction(
  4023. IN DWORD dwEncodingType,
  4024. IN LPCSTR pszFuncName,
  4025. IN DWORD dwIndex,
  4026. IN LPCWSTR pwszDll
  4027. );
  4028. #define CRYPT_REGISTER_FIRST_INDEX 0
  4029. #define CRYPT_REGISTER_LAST_INDEX 0xFFFFFFFF
  4030. //+-------------------------------------------------------------------------
  4031. // Unregister the Dll containing the default function to be called for
  4032. // the specified encoding type and function name.
  4033. //--------------------------------------------------------------------------
  4034. WINCRYPT32API
  4035. BOOL
  4036. WINAPI
  4037. CryptUnregisterDefaultOIDFunction(
  4038. IN DWORD dwEncodingType,
  4039. IN LPCSTR pszFuncName,
  4040. IN LPCWSTR pwszDll
  4041. );
  4042. //+-------------------------------------------------------------------------
  4043. // Set the value for the specified encoding type, function name, OID and
  4044. // value name.
  4045. //
  4046. // See RegSetValueEx for the possible value types.
  4047. //
  4048. // String types are UNICODE.
  4049. //--------------------------------------------------------------------------
  4050. WINCRYPT32API
  4051. BOOL
  4052. WINAPI
  4053. CryptSetOIDFunctionValue(
  4054. IN DWORD dwEncodingType,
  4055. IN LPCSTR pszFuncName,
  4056. IN LPCSTR pszOID,
  4057. IN LPCWSTR pwszValueName,
  4058. IN DWORD dwValueType,
  4059. IN const BYTE *pbValueData,
  4060. IN DWORD cbValueData
  4061. );
  4062. //+-------------------------------------------------------------------------
  4063. // Get the value for the specified encoding type, function name, OID and
  4064. // value name.
  4065. //
  4066. // See RegEnumValue for the possible value types.
  4067. //
  4068. // String types are UNICODE.
  4069. //--------------------------------------------------------------------------
  4070. WINCRYPT32API
  4071. BOOL
  4072. WINAPI
  4073. CryptGetOIDFunctionValue(
  4074. IN DWORD dwEncodingType,
  4075. IN LPCSTR pszFuncName,
  4076. IN LPCSTR pszOID,
  4077. IN LPCWSTR pwszValueName,
  4078. OUT DWORD *pdwValueType,
  4079. OUT BYTE *pbValueData,
  4080. IN OUT DWORD *pcbValueData
  4081. );
  4082. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  4083. IN DWORD dwEncodingType,
  4084. IN LPCSTR pszFuncName,
  4085. IN LPCSTR pszOID,
  4086. IN DWORD cValue,
  4087. IN const DWORD rgdwValueType[],
  4088. IN LPCWSTR const rgpwszValueName[],
  4089. IN const BYTE * const rgpbValueData[],
  4090. IN const DWORD rgcbValueData[],
  4091. IN void *pvArg
  4092. );
  4093. //+-------------------------------------------------------------------------
  4094. // Enumerate the OID functions identified by their encoding type,
  4095. // function name and OID.
  4096. //
  4097. // pfnEnumOIDFunc is called for each registry key matching the input
  4098. // parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  4099. // any. Setting pszFuncName or pszOID to NULL matches any.
  4100. //
  4101. // Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  4102. // DEFAULT functions
  4103. //
  4104. // String types are UNICODE.
  4105. //--------------------------------------------------------------------------
  4106. WINCRYPT32API
  4107. BOOL
  4108. WINAPI
  4109. CryptEnumOIDFunction(
  4110. IN DWORD dwEncodingType,
  4111. IN OPTIONAL LPCSTR pszFuncName,
  4112. IN OPTIONAL LPCSTR pszOID,
  4113. IN DWORD dwFlags,
  4114. IN void *pvArg,
  4115. IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  4116. );
  4117. #define CRYPT_MATCH_ANY_ENCODING_TYPE 0xFFFFFFFF
  4118. //+=========================================================================
  4119. // Object IDentifier (OID) Information: Data Structures and APIs
  4120. //==========================================================================
  4121. //+-------------------------------------------------------------------------
  4122. // OID Information
  4123. //--------------------------------------------------------------------------
  4124. typedef struct _CRYPT_OID_INFO {
  4125. DWORD cbSize;
  4126. LPCSTR pszOID;
  4127. LPCWSTR pwszName;
  4128. DWORD dwGroupId;
  4129. union {
  4130. DWORD dwValue;
  4131. ALG_ID Algid;
  4132. DWORD dwLength;
  4133. };
  4134. CRYPT_DATA_BLOB ExtraInfo;
  4135. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  4136. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  4137. //+-------------------------------------------------------------------------
  4138. // OID Group IDs
  4139. //--------------------------------------------------------------------------
  4140. #define CRYPT_HASH_ALG_OID_GROUP_ID 1
  4141. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID 2
  4142. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID 3
  4143. #define CRYPT_SIGN_ALG_OID_GROUP_ID 4
  4144. #define CRYPT_RDN_ATTR_OID_GROUP_ID 5
  4145. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID 6
  4146. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID 7
  4147. #define CRYPT_POLICY_OID_GROUP_ID 8
  4148. #define CRYPT_TEMPLATE_OID_GROUP_ID 9
  4149. #define CRYPT_LAST_OID_GROUP_ID 9
  4150. #define CRYPT_FIRST_ALG_OID_GROUP_ID CRYPT_HASH_ALG_OID_GROUP_ID
  4151. #define CRYPT_LAST_ALG_OID_GROUP_ID CRYPT_SIGN_ALG_OID_GROUP_ID
  4152. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  4153. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  4154. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID, CRYPT_POLICY_OID_GROUP_ID or
  4155. // CRYPT_TEMPLATE_OID_GROUP_ID don't have a dwValue.
  4156. //
  4157. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4158. // DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  4159. // inhibit the reformatting of the signature before
  4160. // CryptVerifySignature is called or after CryptSignHash
  4161. // is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  4162. // be set to include the public key algorithm's parameters
  4163. // in the PKCS7's digestEncryptionAlgorithm's parameters.
  4164. // CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG can be set to omit
  4165. // NULL parameters when encoding.
  4166. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG 0x1
  4167. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG 0x2
  4168. #define CRYPT_OID_NO_NULL_ALGORITHM_PARA_FLAG 0x4
  4169. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  4170. // DWORD[0] - Public Key Algid.
  4171. // DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  4172. // DWORD[2] - Optional CryptAcquireContext(CRYPT_VERIFYCONTEXT)'s dwProvType.
  4173. // If omitted or 0, uses Public Key Algid to select
  4174. // appropriate dwProvType for signature verification.
  4175. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  4176. // Array of DWORDs:
  4177. // [0 ..] - Null terminated list of acceptable RDN attribute
  4178. // value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  4179. // CERT_RDN_UNICODE_STRING, 0.
  4180. //+-------------------------------------------------------------------------
  4181. // Find OID information. Returns NULL if unable to find any information
  4182. // for the specified key and group. Note, returns a pointer to a constant
  4183. // data structure. The returned pointer MUST NOT be freed.
  4184. //
  4185. // dwKeyType's:
  4186. // CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  4187. // CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  4188. // CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  4189. // CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  4190. // ALG_ID[0] - Hash Algid
  4191. // ALG_ID[1] - PubKey Algid
  4192. //
  4193. // Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  4194. // Otherwise, only the dwGroupId is searched.
  4195. //--------------------------------------------------------------------------
  4196. WINCRYPT32API
  4197. PCCRYPT_OID_INFO
  4198. WINAPI
  4199. CryptFindOIDInfo(
  4200. IN DWORD dwKeyType,
  4201. IN void *pvKey,
  4202. IN DWORD dwGroupId
  4203. );
  4204. #define CRYPT_OID_INFO_OID_KEY 1
  4205. #define CRYPT_OID_INFO_NAME_KEY 2
  4206. #define CRYPT_OID_INFO_ALGID_KEY 3
  4207. #define CRYPT_OID_INFO_SIGN_KEY 4
  4208. //+-------------------------------------------------------------------------
  4209. // Register OID information. The OID information specified in the
  4210. // CCRYPT_OID_INFO structure is persisted to the registry.
  4211. //
  4212. // crypt32.dll contains information for the commonly known OIDs. This function
  4213. // allows applications to augment crypt32.dll's OID information. During
  4214. // CryptFindOIDInfo's first call, the registered OID information is installed.
  4215. //
  4216. // By default the registered OID information is installed after crypt32.dll's
  4217. // OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  4218. //--------------------------------------------------------------------------
  4219. WINCRYPT32API
  4220. BOOL
  4221. WINAPI
  4222. CryptRegisterOIDInfo(
  4223. IN PCCRYPT_OID_INFO pInfo,
  4224. IN DWORD dwFlags
  4225. );
  4226. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG 1
  4227. //+-------------------------------------------------------------------------
  4228. // Unregister OID information. Only the pszOID and dwGroupId fields are
  4229. // used to identify the OID information to be unregistered.
  4230. //--------------------------------------------------------------------------
  4231. WINCRYPT32API
  4232. BOOL
  4233. WINAPI
  4234. CryptUnregisterOIDInfo(
  4235. IN PCCRYPT_OID_INFO pInfo
  4236. );
  4237. // If the callback returns FALSE, stops the enumeration.
  4238. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_INFO)(
  4239. IN PCCRYPT_OID_INFO pInfo,
  4240. IN void *pvArg
  4241. );
  4242. //+-------------------------------------------------------------------------
  4243. // Enumerate the OID information.
  4244. //
  4245. // pfnEnumOIDInfo is called for each OID information entry.
  4246. //
  4247. // Setting dwGroupId to 0 matches all groups. Otherwise, only enumerates
  4248. // entries in the specified group.
  4249. //
  4250. // dwFlags currently isn't used and must be set to 0.
  4251. //--------------------------------------------------------------------------
  4252. WINCRYPT32API
  4253. BOOL
  4254. WINAPI
  4255. CryptEnumOIDInfo(
  4256. IN DWORD dwGroupId,
  4257. IN DWORD dwFlags,
  4258. IN void *pvArg,
  4259. IN PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo
  4260. );
  4261. //+-------------------------------------------------------------------------
  4262. // Find the localized name for the specified name. For example, find the
  4263. // localized name for the "Root" system store name. A case insensitive
  4264. // string comparison is done.
  4265. //
  4266. // Returns NULL if unable to find the the specified name.
  4267. //
  4268. // Localized names for the predefined system stores ("Root", "My") and
  4269. // predefined physical stores (".Default", ".LocalMachine") are pre-installed
  4270. // as resource strings in crypt32.dll. CryptSetOIDFunctionValue can be called
  4271. // as follows to register additional localized strings:
  4272. // dwEncodingType = CRYPT_LOCALIZED_NAME_ENCODING_TYPE
  4273. // pszFuncName = CRYPT_OID_FIND_LOCALIZED_NAME_FUNC
  4274. // pszOID = CRYPT_LOCALIZED_NAME_OID
  4275. // pwszValueName = Name to be localized, for example, L"ApplicationStore"
  4276. // dwValueType = REG_SZ
  4277. // pbValueData = pointer to the UNICODE localized string
  4278. // cbValueData = (wcslen(UNICODE localized string) + 1) * sizeof(WCHAR)
  4279. //
  4280. // To unregister, set pbValueData to NULL and cbValueData to 0.
  4281. //
  4282. // The registered names are searched before the pre-installed names.
  4283. //--------------------------------------------------------------------------
  4284. WINCRYPT32API
  4285. LPCWSTR
  4286. WINAPI
  4287. CryptFindLocalizedName(
  4288. IN LPCWSTR pwszCryptName
  4289. );
  4290. #define CRYPT_LOCALIZED_NAME_ENCODING_TYPE 0
  4291. #define CRYPT_LOCALIZED_NAME_OID "LocalizedNames"
  4292. //+=========================================================================
  4293. // Low Level Cryptographic Message Data Structures and APIs
  4294. //==========================================================================
  4295. typedef void *HCRYPTMSG;
  4296. #define szOID_PKCS_7_DATA "1.2.840.113549.1.7.1"
  4297. #define szOID_PKCS_7_SIGNED "1.2.840.113549.1.7.2"
  4298. #define szOID_PKCS_7_ENVELOPED "1.2.840.113549.1.7.3"
  4299. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  4300. #define szOID_PKCS_7_DIGESTED "1.2.840.113549.1.7.5"
  4301. #define szOID_PKCS_7_ENCRYPTED "1.2.840.113549.1.7.6"
  4302. #define szOID_PKCS_9_CONTENT_TYPE "1.2.840.113549.1.9.3"
  4303. #define szOID_PKCS_9_MESSAGE_DIGEST "1.2.840.113549.1.9.4"
  4304. //+-------------------------------------------------------------------------
  4305. // Message types
  4306. //--------------------------------------------------------------------------
  4307. #define CMSG_DATA 1
  4308. #define CMSG_SIGNED 2
  4309. #define CMSG_ENVELOPED 3
  4310. #define CMSG_SIGNED_AND_ENVELOPED 4
  4311. #define CMSG_HASHED 5
  4312. #define CMSG_ENCRYPTED 6
  4313. //+-------------------------------------------------------------------------
  4314. // Message Type Bit Flags
  4315. //--------------------------------------------------------------------------
  4316. #define CMSG_ALL_FLAGS (~0UL)
  4317. #define CMSG_DATA_FLAG (1 << CMSG_DATA)
  4318. #define CMSG_SIGNED_FLAG (1 << CMSG_SIGNED)
  4319. #define CMSG_ENVELOPED_FLAG (1 << CMSG_ENVELOPED)
  4320. #define CMSG_SIGNED_AND_ENVELOPED_FLAG (1 << CMSG_SIGNED_AND_ENVELOPED)
  4321. #define CMSG_HASHED_FLAG (1 << CMSG_HASHED)
  4322. #define CMSG_ENCRYPTED_FLAG (1 << CMSG_ENCRYPTED)
  4323. //+-------------------------------------------------------------------------
  4324. // Certificate Issuer and SerialNumber
  4325. //--------------------------------------------------------------------------
  4326. typedef struct _CERT_ISSUER_SERIAL_NUMBER {
  4327. CERT_NAME_BLOB Issuer;
  4328. CRYPT_INTEGER_BLOB SerialNumber;
  4329. } CERT_ISSUER_SERIAL_NUMBER, *PCERT_ISSUER_SERIAL_NUMBER;
  4330. //+-------------------------------------------------------------------------
  4331. // Certificate Identifier
  4332. //--------------------------------------------------------------------------
  4333. typedef struct _CERT_ID {
  4334. DWORD dwIdChoice;
  4335. union {
  4336. // CERT_ID_ISSUER_SERIAL_NUMBER
  4337. CERT_ISSUER_SERIAL_NUMBER IssuerSerialNumber;
  4338. // CERT_ID_KEY_IDENTIFIER
  4339. CRYPT_HASH_BLOB KeyId;
  4340. // CERT_ID_SHA1_HASH
  4341. CRYPT_HASH_BLOB HashId;
  4342. };
  4343. } CERT_ID, *PCERT_ID;
  4344. #define CERT_ID_ISSUER_SERIAL_NUMBER 1
  4345. #define CERT_ID_KEY_IDENTIFIER 2
  4346. #define CERT_ID_SHA1_HASH 3
  4347. //+-------------------------------------------------------------------------
  4348. // The message encode information (pvMsgEncodeInfo) is message type dependent
  4349. //--------------------------------------------------------------------------
  4350. //+-------------------------------------------------------------------------
  4351. // CMSG_DATA: pvMsgEncodeInfo = NULL
  4352. //--------------------------------------------------------------------------
  4353. //+-------------------------------------------------------------------------
  4354. // CMSG_SIGNED
  4355. //
  4356. // The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  4357. // and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  4358. // specifies the HashEncryptionAlgorithm to be used.
  4359. //
  4360. // If the SignerId is present with a nonzero dwIdChoice its used instead
  4361. // of the Issuer and SerialNumber in pCertInfo.
  4362. //
  4363. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4364. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4365. //
  4366. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  4367. // the PublicKeyInfo.Algorithm.
  4368. //
  4369. // Note, for RSA, the hash encryption algorithm is normally the same as
  4370. // the public key algorithm. For DSA, the hash encryption algorithm is
  4371. // normally a DSS signature algorithm.
  4372. //
  4373. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  4374. // present in the data structure.
  4375. //
  4376. // The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  4377. // == 0, then, defaults to AT_SIGNATURE.
  4378. //
  4379. // If the HashEncryptionAlgorithm is set to szOID_PKIX_NO_SIGNATURE, then,
  4380. // the signature value only contains the hash octets. hCryptProv must still
  4381. // be specified. However, since a private key isn't used the hCryptProv can be
  4382. // acquired using CRYPT_VERIFYCONTEXT.
  4383. //
  4384. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4385. // passed to CryptMsgOpenToEncode(), the signer hCryptProv's are released.
  4386. //
  4387. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4388. //
  4389. // CMS signed messages allow the inclusion of Attribute Certs.
  4390. //--------------------------------------------------------------------------
  4391. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  4392. DWORD cbSize;
  4393. PCERT_INFO pCertInfo;
  4394. HCRYPTPROV hCryptProv;
  4395. DWORD dwKeySpec;
  4396. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4397. void *pvHashAuxInfo;
  4398. DWORD cAuthAttr;
  4399. PCRYPT_ATTRIBUTE rgAuthAttr;
  4400. DWORD cUnauthAttr;
  4401. PCRYPT_ATTRIBUTE rgUnauthAttr;
  4402. #ifdef CMSG_SIGNER_ENCODE_INFO_HAS_CMS_FIELDS
  4403. CERT_ID SignerId;
  4404. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  4405. void *pvHashEncryptionAuxInfo;
  4406. #endif
  4407. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  4408. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  4409. DWORD cbSize;
  4410. DWORD cSigners;
  4411. PCMSG_SIGNER_ENCODE_INFO rgSigners;
  4412. DWORD cCertEncoded;
  4413. PCERT_BLOB rgCertEncoded;
  4414. DWORD cCrlEncoded;
  4415. PCRL_BLOB rgCrlEncoded;
  4416. #ifdef CMSG_SIGNED_ENCODE_INFO_HAS_CMS_FIELDS
  4417. DWORD cAttrCertEncoded;
  4418. PCERT_BLOB rgAttrCertEncoded;
  4419. #endif
  4420. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  4421. //+-------------------------------------------------------------------------
  4422. // CMSG_ENVELOPED
  4423. //
  4424. // The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  4425. // and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  4426. // specifies the KeyEncryptionAlgorithm to be used.
  4427. //
  4428. // The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  4429. // encryption key for the recipient.
  4430. //
  4431. // hCryptProv is used to do the content encryption, recipient key encryption
  4432. // and export. The hCryptProv's private keys aren't used. If hCryptProv
  4433. // is NULL, a default hCryptProv is chosen according to the
  4434. // ContentEncryptionAlgorithm and the first recipient KeyEncryptionAlgorithm.
  4435. //
  4436. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4437. // passed to CryptMsgOpenToEncode(), the envelope's hCryptProv is released.
  4438. //
  4439. // Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  4440. // per provider. This will need to be fixed.
  4441. //
  4442. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  4443. // algorithms. Otherwise, its not used and must be set to NULL.
  4444. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  4445. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  4446. //
  4447. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  4448. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  4449. //
  4450. // To enable the CMS envelope enhancements, rgpRecipients must be set to
  4451. // NULL, and rgCmsRecipients updated to point to an array of
  4452. // CMSG_RECIPIENT_ENCODE_INFO's.
  4453. //
  4454. // Also, CMS envelope enhancements support the inclusion of a bag of
  4455. // Certs, CRLs, Attribute Certs and/or Unprotected Attributes.
  4456. //--------------------------------------------------------------------------
  4457. typedef struct _CMSG_RECIPIENT_ENCODE_INFO CMSG_RECIPIENT_ENCODE_INFO,
  4458. *PCMSG_RECIPIENT_ENCODE_INFO;
  4459. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  4460. DWORD cbSize;
  4461. HCRYPTPROV hCryptProv;
  4462. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4463. void *pvEncryptionAuxInfo;
  4464. DWORD cRecipients;
  4465. // The following array may only be used for transport recipients identified
  4466. // by their IssuereAndSerialNumber. If rgpRecipients != NULL, then,
  4467. // the rgCmsRecipients must be NULL.
  4468. PCERT_INFO *rgpRecipients;
  4469. #ifdef CMSG_ENVELOPED_ENCODE_INFO_HAS_CMS_FIELDS
  4470. // If rgCmsRecipients != NULL, then, the above rgpRecipients must be
  4471. // NULL.
  4472. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  4473. DWORD cCertEncoded;
  4474. PCERT_BLOB rgCertEncoded;
  4475. DWORD cCrlEncoded;
  4476. PCRL_BLOB rgCrlEncoded;
  4477. DWORD cAttrCertEncoded;
  4478. PCERT_BLOB rgAttrCertEncoded;
  4479. DWORD cUnprotectedAttr;
  4480. PCRYPT_ATTRIBUTE rgUnprotectedAttr;
  4481. #endif
  4482. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  4483. //+-------------------------------------------------------------------------
  4484. // Key Transport Recipient Encode Info
  4485. //
  4486. // hCryptProv is used to do the recipient key encryption
  4487. // and export. The hCryptProv's private keys aren't used.
  4488. //
  4489. // If hCryptProv is NULL, then, the hCryptProv specified in
  4490. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4491. //
  4492. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4493. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4494. //
  4495. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs. PKCS #7
  4496. // version 1.5 only supports the ISSUER_SERIAL_NUMBER CERT_ID choice.
  4497. //--------------------------------------------------------------------------
  4498. typedef struct _CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO {
  4499. DWORD cbSize;
  4500. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4501. void *pvKeyEncryptionAuxInfo;
  4502. HCRYPTPROV hCryptProv;
  4503. CRYPT_BIT_BLOB RecipientPublicKey;
  4504. CERT_ID RecipientId;
  4505. } CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO;
  4506. //+-------------------------------------------------------------------------
  4507. // Key Agreement Recipient Encode Info
  4508. //
  4509. // If hCryptProv is NULL, then, the hCryptProv specified in
  4510. // CMSG_ENVELOPED_ENCODE_INFO is used.
  4511. //
  4512. // For the CMSG_KEY_AGREE_STATIC_KEY_CHOICE, both the hCryptProv and
  4513. // dwKeySpec must be specified to select the sender's private key.
  4514. //
  4515. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4516. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4517. //
  4518. // CMS supports the KEY_IDENTIFIER and ISSUER_SERIAL_NUMBER CERT_IDs.
  4519. //
  4520. // There is 1 key choice, ephemeral originator. The originator's ephemeral
  4521. // key is generated using the public key algorithm parameters shared
  4522. // amongst all the recipients.
  4523. //
  4524. // There are 2 key choices: ephemeral originator or static sender. The
  4525. // originator's ephemeral key is generated using the public key algorithm
  4526. // parameters shared amongst all the recipients. For the static sender its
  4527. // private key is used. The hCryptProv and dwKeySpec specify the private key.
  4528. // The pSenderId identifies the certificate containing the sender's public key.
  4529. //
  4530. // Currently, pvKeyEncryptionAuxInfo isn't used and must be set to NULL.
  4531. //
  4532. // If KeyEncryptionAlgorithm.Parameters.cbData == 0, then, its Parameters
  4533. // are updated with the encoded KeyWrapAlgorithm.
  4534. //
  4535. // Currently, pvKeyWrapAuxInfo is only defined for algorithms with
  4536. // RC2. Otherwise, its not used and must be set to NULL.
  4537. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4538. // the RC2 effective key length.
  4539. //
  4540. // Note, key agreement recipients are not supported in PKCS #7 version 1.5.
  4541. //--------------------------------------------------------------------------
  4542. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO {
  4543. DWORD cbSize;
  4544. CRYPT_BIT_BLOB RecipientPublicKey;
  4545. CERT_ID RecipientId;
  4546. // Following fields are optional and only applicable to KEY_IDENTIFIER
  4547. // CERT_IDs.
  4548. FILETIME Date;
  4549. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4550. } CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO,
  4551. *PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO;
  4552. typedef struct _CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO {
  4553. DWORD cbSize;
  4554. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4555. void *pvKeyEncryptionAuxInfo;
  4556. CRYPT_ALGORITHM_IDENTIFIER KeyWrapAlgorithm;
  4557. void *pvKeyWrapAuxInfo;
  4558. // The following hCryptProv and dwKeySpec must be specified for the
  4559. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE.
  4560. //
  4561. // For CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE, dwKeySpec isn't applicable
  4562. // and hCryptProv is optional.
  4563. HCRYPTPROV hCryptProv;
  4564. DWORD dwKeySpec;
  4565. DWORD dwKeyChoice;
  4566. union {
  4567. // CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE
  4568. //
  4569. // The ephemeral public key algorithm and parameters.
  4570. PCRYPT_ALGORITHM_IDENTIFIER pEphemeralAlgorithm;
  4571. // CMSG_KEY_AGREE_STATIC_KEY_CHOICE
  4572. //
  4573. // The CertId of the sender's certificate
  4574. PCERT_ID pSenderId;
  4575. };
  4576. CRYPT_DATA_BLOB UserKeyingMaterial; // OPTIONAL
  4577. DWORD cRecipientEncryptedKeys;
  4578. PCMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO *rgpRecipientEncryptedKeys;
  4579. } CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO, *PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO;
  4580. #define CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE 1
  4581. #define CMSG_KEY_AGREE_STATIC_KEY_CHOICE 2
  4582. //+-------------------------------------------------------------------------
  4583. // Mail List Recipient Encode Info
  4584. //
  4585. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  4586. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  4587. // handle isn't destroyed.
  4588. //
  4589. // Note, even if CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4590. // passed to CryptMsgOpenToEncode(), this hCryptProv isn't released.
  4591. //
  4592. // Currently, pvKeyEncryptionAuxInfo is only defined for RC2 key wrap
  4593. // algorithms. Otherwise, its not used and must be set to NULL.
  4594. // When set for RC2 algorithms, points to a CMSG_RC2_AUX_INFO containing
  4595. // the RC2 effective key length.
  4596. //
  4597. // Note, mail list recipients are not supported in PKCS #7 version 1.5.
  4598. //--------------------------------------------------------------------------
  4599. typedef struct _CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO {
  4600. DWORD cbSize;
  4601. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  4602. void *pvKeyEncryptionAuxInfo;
  4603. HCRYPTPROV hCryptProv;
  4604. DWORD dwKeyChoice;
  4605. union {
  4606. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  4607. HCRYPTKEY hKeyEncryptionKey;
  4608. // Reserve space for a potential pointer choice
  4609. void *pvKeyEncryptionKey;
  4610. };
  4611. CRYPT_DATA_BLOB KeyId;
  4612. // Following fields are optional.
  4613. FILETIME Date;
  4614. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  4615. } CMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO, *PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO;
  4616. #define CMSG_MAIL_LIST_HANDLE_KEY_CHOICE 1
  4617. //+-------------------------------------------------------------------------
  4618. // Recipient Encode Info
  4619. //
  4620. // Note, only key transport recipients are supported in PKCS #7 version 1.5.
  4621. //--------------------------------------------------------------------------
  4622. struct _CMSG_RECIPIENT_ENCODE_INFO {
  4623. DWORD dwRecipientChoice;
  4624. union {
  4625. // CMSG_KEY_TRANS_RECIPIENT
  4626. PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTrans;
  4627. // CMSG_KEY_AGREE_RECIPIENT
  4628. PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgree;
  4629. // CMSG_MAIL_LIST_RECIPIENT
  4630. PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailList;
  4631. };
  4632. };
  4633. #define CMSG_KEY_TRANS_RECIPIENT 1
  4634. #define CMSG_KEY_AGREE_RECIPIENT 2
  4635. #define CMSG_MAIL_LIST_RECIPIENT 3
  4636. //+-------------------------------------------------------------------------
  4637. // CMSG_RC2_AUX_INFO
  4638. //
  4639. // AuxInfo for RC2 encryption algorithms. The pvEncryptionAuxInfo field
  4640. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4641. // structure. If not specified, defaults to 40 bit.
  4642. //
  4643. // Note, this AuxInfo is only used when, the ContentEncryptionAlgorithm's
  4644. // Parameter.cbData is zero. Otherwise, the Parameters is decoded to
  4645. // get the bit length.
  4646. //
  4647. // If CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwBitLen, then, SP3
  4648. // compatible encryption is done and the bit length is ignored.
  4649. //--------------------------------------------------------------------------
  4650. typedef struct _CMSG_RC2_AUX_INFO {
  4651. DWORD cbSize;
  4652. DWORD dwBitLen;
  4653. } CMSG_RC2_AUX_INFO, *PCMSG_RC2_AUX_INFO;
  4654. //+-------------------------------------------------------------------------
  4655. // CMSG_SP3_COMPATIBLE_AUX_INFO
  4656. //
  4657. // AuxInfo for enabling SP3 compatible encryption.
  4658. //
  4659. // The CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG is set in dwFlags to enable SP3
  4660. // compatible encryption. When set, uses zero salt instead of no salt,
  4661. // the encryption algorithm parameters are NULL instead of containing the
  4662. // encoded RC2 parameters or encoded IV octet string and the encrypted
  4663. // symmetric key is encoded little endian instead of big endian.
  4664. //--------------------------------------------------------------------------
  4665. typedef struct _CMSG_SP3_COMPATIBLE_AUX_INFO {
  4666. DWORD cbSize;
  4667. DWORD dwFlags;
  4668. } CMSG_SP3_COMPATIBLE_AUX_INFO, *PCMSG_SP3_COMPATIBLE_AUX_INFO;
  4669. #define CMSG_SP3_COMPATIBLE_ENCRYPT_FLAG 0x80000000
  4670. //+-------------------------------------------------------------------------
  4671. // CMSG_RC4_AUX_INFO
  4672. //
  4673. // AuxInfo for RC4 encryption algorithms. The pvEncryptionAuxInfo field
  4674. // in CMSG_ENCRYPTED_ENCODE_INFO should be updated to point to this
  4675. // structure. If not specified, uses the CSP's default bit length with no
  4676. // salt. Note, the base CSP has a 40 bit default and the enhanced CSP has
  4677. // a 128 bit default.
  4678. //
  4679. // If CMSG_RC4_NO_SALT_FLAG is set in dwBitLen, then, no salt is generated.
  4680. // Otherwise, (128 - dwBitLen)/8 bytes of salt are generated and encoded
  4681. // as an OCTET STRING in the algorithm parameters field.
  4682. //--------------------------------------------------------------------------
  4683. typedef struct _CMSG_RC4_AUX_INFO {
  4684. DWORD cbSize;
  4685. DWORD dwBitLen;
  4686. } CMSG_RC4_AUX_INFO, *PCMSG_RC4_AUX_INFO;
  4687. #define CMSG_RC4_NO_SALT_FLAG 0x40000000
  4688. //+-------------------------------------------------------------------------
  4689. // CMSG_SIGNED_AND_ENVELOPED
  4690. //
  4691. // For PKCS #7, a signed and enveloped message doesn't have the
  4692. // signer's authenticated or unauthenticated attributes. Otherwise, a
  4693. // combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  4694. //--------------------------------------------------------------------------
  4695. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  4696. DWORD cbSize;
  4697. CMSG_SIGNED_ENCODE_INFO SignedInfo;
  4698. CMSG_ENVELOPED_ENCODE_INFO EnvelopedInfo;
  4699. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  4700. //+-------------------------------------------------------------------------
  4701. // CMSG_HASHED
  4702. //
  4703. // hCryptProv is used to do the hash. Doesn't need to use a private key.
  4704. //
  4705. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags
  4706. // passed to CryptMsgOpenToEncode(), the hCryptProv is released.
  4707. //
  4708. // If fDetachedHash is set, then, the encoded message doesn't contain
  4709. // any content (its treated as NULL Data)
  4710. //
  4711. // pvHashAuxInfo currently isn't used and must be set to NULL.
  4712. //--------------------------------------------------------------------------
  4713. typedef struct _CMSG_HASHED_ENCODE_INFO {
  4714. DWORD cbSize;
  4715. HCRYPTPROV hCryptProv;
  4716. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  4717. void *pvHashAuxInfo;
  4718. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  4719. //+-------------------------------------------------------------------------
  4720. // CMSG_ENCRYPTED
  4721. //
  4722. // The key used to encrypt the message is identified outside of the message
  4723. // content (for example, password).
  4724. //
  4725. // The content input to CryptMsgUpdate has already been encrypted.
  4726. //
  4727. // pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  4728. //--------------------------------------------------------------------------
  4729. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  4730. DWORD cbSize;
  4731. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  4732. void *pvEncryptionAuxInfo;
  4733. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  4734. //+-------------------------------------------------------------------------
  4735. // This parameter allows messages to be of variable length with streamed
  4736. // output.
  4737. //
  4738. // By default, messages are of a definite length and
  4739. // CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  4740. // called to get the cryptographically processed content. Until closed,
  4741. // the handle keeps a copy of the processed content.
  4742. //
  4743. // With streamed output, the processed content can be freed as its streamed.
  4744. //
  4745. // If the length of the content to be updated is known at the time of the
  4746. // open, then, ContentLength should be set to that length. Otherwise, it
  4747. // should be set to CMSG_INDEFINITE_LENGTH.
  4748. //--------------------------------------------------------------------------
  4749. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  4750. IN const void *pvArg,
  4751. IN BYTE *pbData,
  4752. IN DWORD cbData,
  4753. IN BOOL fFinal
  4754. );
  4755. #define CMSG_INDEFINITE_LENGTH (0xFFFFFFFF)
  4756. typedef struct _CMSG_STREAM_INFO {
  4757. DWORD cbContent;
  4758. PFN_CMSG_STREAM_OUTPUT pfnStreamOutput;
  4759. void *pvArg;
  4760. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  4761. //+-------------------------------------------------------------------------
  4762. // Open dwFlags
  4763. //--------------------------------------------------------------------------
  4764. #define CMSG_BARE_CONTENT_FLAG 0x00000001
  4765. #define CMSG_LENGTH_ONLY_FLAG 0x00000002
  4766. #define CMSG_DETACHED_FLAG 0x00000004
  4767. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG 0x00000008
  4768. #define CMSG_CONTENTS_OCTETS_FLAG 0x00000010
  4769. #define CMSG_MAX_LENGTH_FLAG 0x00000020
  4770. // When set, nonData type inner content is encapsulated within an
  4771. // OCTET STRING. Applicable to both Signed and Enveloped messages.
  4772. #define CMSG_CMS_ENCAPSULATED_CONTENT_FLAG 0x00000040
  4773. // If set, then, the hCryptProv passed to CryptMsgOpenToEncode or
  4774. // CryptMsgOpenToDecode is released on the final CryptMsgClose.
  4775. // Not released if CryptMsgOpenToEncode or CryptMsgOpenToDecode fails.
  4776. //
  4777. // Note, the envelope recipient hCryptProv's aren't released.
  4778. #define CMSG_CRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  4779. //+-------------------------------------------------------------------------
  4780. // Open a cryptographic message for encoding
  4781. //
  4782. // If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  4783. // the streamed output will not have an outer ContentInfo wrapper. This
  4784. // makes it suitable to be streamed into an enclosing message.
  4785. //
  4786. // The pStreamInfo parameter needs to be set to stream the encoded message
  4787. // output.
  4788. //--------------------------------------------------------------------------
  4789. WINCRYPT32API
  4790. HCRYPTMSG
  4791. WINAPI
  4792. CryptMsgOpenToEncode(
  4793. IN DWORD dwMsgEncodingType,
  4794. IN DWORD dwFlags,
  4795. IN DWORD dwMsgType,
  4796. IN void const *pvMsgEncodeInfo,
  4797. IN OPTIONAL LPSTR pszInnerContentObjID,
  4798. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4799. );
  4800. //+-------------------------------------------------------------------------
  4801. // Calculate the length of an encoded cryptographic message.
  4802. //
  4803. // Calculates the length of the encoded message given the
  4804. // message type, encoding parameters and total length of
  4805. // the data to be updated. Note, this might not be the exact length. However,
  4806. // it will always be greater than or equal to the actual length.
  4807. //--------------------------------------------------------------------------
  4808. WINCRYPT32API
  4809. DWORD
  4810. WINAPI
  4811. CryptMsgCalculateEncodedLength(
  4812. IN DWORD dwMsgEncodingType,
  4813. IN DWORD dwFlags,
  4814. IN DWORD dwMsgType,
  4815. IN void const *pvMsgEncodeInfo,
  4816. IN OPTIONAL LPSTR pszInnerContentObjID,
  4817. IN DWORD cbData
  4818. );
  4819. //+-------------------------------------------------------------------------
  4820. // Open a cryptographic message for decoding
  4821. //
  4822. // hCryptProv specifies the crypto provider to use for hashing and/or
  4823. // decrypting the message. If hCryptProv is NULL, a default crypt provider
  4824. // is used.
  4825. //
  4826. // Currently pRecipientInfo isn't used and should be set to NULL.
  4827. //
  4828. // The pStreamInfo parameter needs to be set to stream the decoded content
  4829. // output.
  4830. //--------------------------------------------------------------------------
  4831. WINCRYPT32API
  4832. HCRYPTMSG
  4833. WINAPI
  4834. CryptMsgOpenToDecode(
  4835. IN DWORD dwMsgEncodingType,
  4836. IN DWORD dwFlags,
  4837. IN DWORD dwMsgType,
  4838. IN HCRYPTPROV hCryptProv,
  4839. IN OPTIONAL PCERT_INFO pRecipientInfo,
  4840. IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  4841. );
  4842. //+-------------------------------------------------------------------------
  4843. // Duplicate a cryptographic message handle
  4844. //--------------------------------------------------------------------------
  4845. WINCRYPT32API
  4846. HCRYPTMSG
  4847. WINAPI
  4848. CryptMsgDuplicate(
  4849. IN HCRYPTMSG hCryptMsg
  4850. );
  4851. //+-------------------------------------------------------------------------
  4852. // Close a cryptographic message handle
  4853. //
  4854. // LastError is preserved unless FALSE is returned.
  4855. //--------------------------------------------------------------------------
  4856. WINCRYPT32API
  4857. BOOL
  4858. WINAPI
  4859. CryptMsgClose(
  4860. IN HCRYPTMSG hCryptMsg
  4861. );
  4862. //+-------------------------------------------------------------------------
  4863. // Update the content of a cryptographic message. Depending on how the
  4864. // message was opened, the content is either encoded or decoded.
  4865. //
  4866. // This function is repetitively called to append to the message content.
  4867. // fFinal is set to identify the last update. On fFinal, the encode/decode
  4868. // is completed. The encoded/decoded content and the decoded parameters
  4869. // are valid until the open and all duplicated handles are closed.
  4870. //--------------------------------------------------------------------------
  4871. WINCRYPT32API
  4872. BOOL
  4873. WINAPI
  4874. CryptMsgUpdate(
  4875. IN HCRYPTMSG hCryptMsg,
  4876. IN const BYTE *pbData,
  4877. IN DWORD cbData,
  4878. IN BOOL fFinal
  4879. );
  4880. //+-------------------------------------------------------------------------
  4881. // Get a parameter after encoding/decoding a cryptographic message. Called
  4882. // after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  4883. // CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  4884. //
  4885. // For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  4886. // before any CryptMsgUpdates to get its length.
  4887. //
  4888. // The pvData type definition depends on the dwParamType value.
  4889. //
  4890. // Elements pointed to by fields in the pvData structure follow the
  4891. // structure. Therefore, *pcbData may exceed the size of the structure.
  4892. //
  4893. // Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  4894. // of the data and the pvData parameter is ignored.
  4895. //
  4896. // Upon return, *pcbData is updated with the length of the data.
  4897. //
  4898. // The OBJID BLOBs returned in the pvData structures point to
  4899. // their still encoded representation. The appropriate functions
  4900. // must be called to decode the information.
  4901. //
  4902. // See below for a list of the parameters to get.
  4903. //--------------------------------------------------------------------------
  4904. WINCRYPT32API
  4905. BOOL
  4906. WINAPI
  4907. CryptMsgGetParam(
  4908. IN HCRYPTMSG hCryptMsg,
  4909. IN DWORD dwParamType,
  4910. IN DWORD dwIndex,
  4911. OUT void *pvData,
  4912. IN OUT DWORD *pcbData
  4913. );
  4914. //+-------------------------------------------------------------------------
  4915. // Get parameter types and their corresponding data structure definitions.
  4916. //--------------------------------------------------------------------------
  4917. #define CMSG_TYPE_PARAM 1
  4918. #define CMSG_CONTENT_PARAM 2
  4919. #define CMSG_BARE_CONTENT_PARAM 3
  4920. #define CMSG_INNER_CONTENT_TYPE_PARAM 4
  4921. #define CMSG_SIGNER_COUNT_PARAM 5
  4922. #define CMSG_SIGNER_INFO_PARAM 6
  4923. #define CMSG_SIGNER_CERT_INFO_PARAM 7
  4924. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM 8
  4925. #define CMSG_SIGNER_AUTH_ATTR_PARAM 9
  4926. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM 10
  4927. #define CMSG_CERT_COUNT_PARAM 11
  4928. #define CMSG_CERT_PARAM 12
  4929. #define CMSG_CRL_COUNT_PARAM 13
  4930. #define CMSG_CRL_PARAM 14
  4931. #define CMSG_ENVELOPE_ALGORITHM_PARAM 15
  4932. #define CMSG_RECIPIENT_COUNT_PARAM 17
  4933. #define CMSG_RECIPIENT_INDEX_PARAM 18
  4934. #define CMSG_RECIPIENT_INFO_PARAM 19
  4935. #define CMSG_HASH_ALGORITHM_PARAM 20
  4936. #define CMSG_HASH_DATA_PARAM 21
  4937. #define CMSG_COMPUTED_HASH_PARAM 22
  4938. #define CMSG_ENCRYPT_PARAM 26
  4939. #define CMSG_ENCRYPTED_DIGEST 27
  4940. #define CMSG_ENCODED_SIGNER 28
  4941. #define CMSG_ENCODED_MESSAGE 29
  4942. #define CMSG_VERSION_PARAM 30
  4943. #define CMSG_ATTR_CERT_COUNT_PARAM 31
  4944. #define CMSG_ATTR_CERT_PARAM 32
  4945. #define CMSG_CMS_RECIPIENT_COUNT_PARAM 33
  4946. #define CMSG_CMS_RECIPIENT_INDEX_PARAM 34
  4947. #define CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM 35
  4948. #define CMSG_CMS_RECIPIENT_INFO_PARAM 36
  4949. #define CMSG_UNPROTECTED_ATTR_PARAM 37
  4950. #define CMSG_SIGNER_CERT_ID_PARAM 38
  4951. #define CMSG_CMS_SIGNER_INFO_PARAM 39
  4952. //+-------------------------------------------------------------------------
  4953. // CMSG_TYPE_PARAM
  4954. //
  4955. // The type of the decoded message.
  4956. //
  4957. // pvData points to a DWORD
  4958. //--------------------------------------------------------------------------
  4959. //+-------------------------------------------------------------------------
  4960. // CMSG_CONTENT_PARAM
  4961. //
  4962. // The encoded content of a cryptographic message. Depending on how the
  4963. // message was opened, the content is either the whole PKCS#7
  4964. // message (opened to encode) or the inner content (opened to decode).
  4965. // In the decode case, the decrypted content is returned, if enveloped.
  4966. // If not enveloped, and if the inner content is of type DATA, the returned
  4967. // data is the contents octets of the inner content.
  4968. //
  4969. // pvData points to the buffer receiving the content bytes
  4970. //--------------------------------------------------------------------------
  4971. //+-------------------------------------------------------------------------
  4972. // CMSG_BARE_CONTENT_PARAM
  4973. //
  4974. // The encoded content of an encoded cryptographic message, without the
  4975. // outer layer of ContentInfo. That is, only the encoding of the
  4976. // ContentInfo.content field is returned.
  4977. //
  4978. // pvData points to the buffer receiving the content bytes
  4979. //--------------------------------------------------------------------------
  4980. //+-------------------------------------------------------------------------
  4981. // CMSG_INNER_CONTENT_TYPE_PARAM
  4982. //
  4983. // The type of the inner content of a decoded cryptographic message,
  4984. // in the form of a NULL-terminated object identifier string
  4985. // (eg. "1.2.840.113549.1.7.1").
  4986. //
  4987. // pvData points to the buffer receiving the object identifier string
  4988. //--------------------------------------------------------------------------
  4989. //+-------------------------------------------------------------------------
  4990. // CMSG_SIGNER_COUNT_PARAM
  4991. //
  4992. // Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  4993. //
  4994. // pvData points to a DWORD
  4995. //--------------------------------------------------------------------------
  4996. //+-------------------------------------------------------------------------
  4997. // CMSG_SIGNER_CERT_INFO_PARAM
  4998. //
  4999. // To get all the signers, repetitively call CryptMsgGetParam, with
  5000. // dwIndex set to 0 .. SignerCount - 1.
  5001. //
  5002. // pvData points to a CERT_INFO struct.
  5003. //
  5004. // Only the following fields have been updated in the CERT_INFO struct:
  5005. // Issuer and SerialNumber.
  5006. //
  5007. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  5008. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  5009. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  5010. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5011. // CertGetSubjectCertificateFromStore and
  5012. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5013. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  5014. //--------------------------------------------------------------------------
  5015. //+-------------------------------------------------------------------------
  5016. // CMSG_SIGNER_INFO_PARAM
  5017. //
  5018. // To get all the signers, repetitively call CryptMsgGetParam, with
  5019. // dwIndex set to 0 .. SignerCount - 1.
  5020. //
  5021. // pvData points to a CMSG_SIGNER_INFO struct.
  5022. //
  5023. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  5024. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  5025. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  5026. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5027. // CertGetSubjectCertificateFromStore and
  5028. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5029. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  5030. //--------------------------------------------------------------------------
  5031. typedef struct _CMSG_SIGNER_INFO {
  5032. DWORD dwVersion;
  5033. CERT_NAME_BLOB Issuer;
  5034. CRYPT_INTEGER_BLOB SerialNumber;
  5035. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  5036. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  5037. CRYPT_DATA_BLOB EncryptedHash;
  5038. CRYPT_ATTRIBUTES AuthAttrs;
  5039. CRYPT_ATTRIBUTES UnauthAttrs;
  5040. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  5041. //+-------------------------------------------------------------------------
  5042. // CMSG_SIGNER_CERT_ID_PARAM
  5043. //
  5044. // To get all the signers, repetitively call CryptMsgGetParam, with
  5045. // dwIndex set to 0 .. SignerCount - 1.
  5046. //
  5047. // pvData points to a CERT_ID struct.
  5048. //--------------------------------------------------------------------------
  5049. //+-------------------------------------------------------------------------
  5050. // CMSG_CMS_SIGNER_INFO_PARAM
  5051. //
  5052. // Same as CMSG_SIGNER_INFO_PARAM, except, contains SignerId instead of
  5053. // Issuer and SerialNumber.
  5054. //
  5055. // To get all the signers, repetitively call CryptMsgGetParam, with
  5056. // dwIndex set to 0 .. SignerCount - 1.
  5057. //
  5058. // pvData points to a CMSG_CMS_SIGNER_INFO struct.
  5059. //--------------------------------------------------------------------------
  5060. typedef struct _CMSG_CMS_SIGNER_INFO {
  5061. DWORD dwVersion;
  5062. CERT_ID SignerId;
  5063. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  5064. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  5065. CRYPT_DATA_BLOB EncryptedHash;
  5066. CRYPT_ATTRIBUTES AuthAttrs;
  5067. CRYPT_ATTRIBUTES UnauthAttrs;
  5068. } CMSG_CMS_SIGNER_INFO, *PCMSG_CMS_SIGNER_INFO;
  5069. //+-------------------------------------------------------------------------
  5070. // CMSG_SIGNER_HASH_ALGORITHM_PARAM
  5071. //
  5072. // This parameter specifies the HashAlgorithm that was used for the signer.
  5073. //
  5074. // Set dwIndex to iterate through all the signers.
  5075. //
  5076. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5077. //--------------------------------------------------------------------------
  5078. //+-------------------------------------------------------------------------
  5079. // CMSG_SIGNER_AUTH_ATTR_PARAM
  5080. //
  5081. // The authenticated attributes for the signer.
  5082. //
  5083. // Set dwIndex to iterate through all the signers.
  5084. //
  5085. // pvData points to a CMSG_ATTR struct.
  5086. //--------------------------------------------------------------------------
  5087. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  5088. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  5089. //+-------------------------------------------------------------------------
  5090. // CMSG_SIGNER_UNAUTH_ATTR_PARAM
  5091. //
  5092. // The unauthenticated attributes for the signer.
  5093. //
  5094. // Set dwIndex to iterate through all the signers.
  5095. //
  5096. // pvData points to a CMSG_ATTR struct.
  5097. //--------------------------------------------------------------------------
  5098. //+-------------------------------------------------------------------------
  5099. // CMSG_CERT_COUNT_PARAM
  5100. //
  5101. // Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  5102. //
  5103. // CMS, also supports certificates in an ENVELOPED message.
  5104. //
  5105. // pvData points to a DWORD
  5106. //--------------------------------------------------------------------------
  5107. //+-------------------------------------------------------------------------
  5108. // CMSG_CERT_PARAM
  5109. //
  5110. // To get all the certificates, repetitively call CryptMsgGetParam, with
  5111. // dwIndex set to 0 .. CertCount - 1.
  5112. //
  5113. // pvData points to an array of the certificate's encoded bytes.
  5114. //--------------------------------------------------------------------------
  5115. //+-------------------------------------------------------------------------
  5116. // CMSG_CRL_COUNT_PARAM
  5117. //
  5118. // Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  5119. //
  5120. // CMS, also supports CRLs in an ENVELOPED message.
  5121. //
  5122. // pvData points to a DWORD
  5123. //--------------------------------------------------------------------------
  5124. //+-------------------------------------------------------------------------
  5125. // CMSG_CRL_PARAM
  5126. //
  5127. // To get all the CRLs, repetitively call CryptMsgGetParam, with
  5128. // dwIndex set to 0 .. CrlCount - 1.
  5129. //
  5130. // pvData points to an array of the CRL's encoded bytes.
  5131. //--------------------------------------------------------------------------
  5132. //+-------------------------------------------------------------------------
  5133. // CMSG_ENVELOPE_ALGORITHM_PARAM
  5134. //
  5135. // The ContentEncryptionAlgorithm that was used in
  5136. // an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5137. //
  5138. // For streaming you must be able to successfully get this parameter before
  5139. // doing a CryptMsgControl decrypt.
  5140. //
  5141. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5142. //--------------------------------------------------------------------------
  5143. //+-------------------------------------------------------------------------
  5144. // CMSG_RECIPIENT_COUNT_PARAM
  5145. //
  5146. // Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  5147. //
  5148. // Count of key transport recepients.
  5149. //
  5150. // The CMSG_CMS_RECIPIENT_COUNT_PARAM has the total count of
  5151. // recipients (it also includes key agree and mail list recipients).
  5152. //
  5153. // pvData points to a DWORD
  5154. //--------------------------------------------------------------------------
  5155. //+-------------------------------------------------------------------------
  5156. // CMSG_RECIPIENT_INDEX_PARAM
  5157. //
  5158. // Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  5159. // message.
  5160. //
  5161. // Index of a key transport recipient. If a non key transport
  5162. // recipient was used to decrypt, fails with LastError set to
  5163. // CRYPT_E_INVALID_INDEX.
  5164. //
  5165. // pvData points to a DWORD
  5166. //--------------------------------------------------------------------------
  5167. //+-------------------------------------------------------------------------
  5168. // CMSG_RECIPIENT_INFO_PARAM
  5169. //
  5170. // To get all the recipients, repetitively call CryptMsgGetParam, with
  5171. // dwIndex set to 0 .. RecipientCount - 1.
  5172. //
  5173. // Only returns the key transport recepients.
  5174. //
  5175. // The CMSG_CMS_RECIPIENT_INFO_PARAM returns all recipients.
  5176. //
  5177. // pvData points to a CERT_INFO struct.
  5178. //
  5179. // Only the following fields have been updated in the CERT_INFO struct:
  5180. // Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  5181. // specifies the KeyEncryptionAlgorithm that was used.
  5182. //
  5183. // Note, if the KEYID choice was selected for a key transport recipient, then,
  5184. // the SerialNumber is 0 and the Issuer is encoded containing a single RDN
  5185. // with a single Attribute whose OID is szOID_KEYID_RDN, value type is
  5186. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  5187. // CertGetSubjectCertificateFromStore and
  5188. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  5189. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  5190. //--------------------------------------------------------------------------
  5191. //+-------------------------------------------------------------------------
  5192. // CMSG_HASH_ALGORITHM_PARAM
  5193. //
  5194. // The HashAlgorithm in a HASHED message.
  5195. //
  5196. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5197. //--------------------------------------------------------------------------
  5198. //+-------------------------------------------------------------------------
  5199. // CMSG_HASH_DATA_PARAM
  5200. //
  5201. // The hash in a HASHED message.
  5202. //
  5203. // pvData points to an array of bytes.
  5204. //--------------------------------------------------------------------------
  5205. //+-------------------------------------------------------------------------
  5206. // CMSG_COMPUTED_HASH_PARAM
  5207. //
  5208. // The computed hash for a HASHED message.
  5209. // This may be called for either an encoded or decoded message.
  5210. //
  5211. // Also, the computed hash for one of the signer's in a SIGNED message.
  5212. // It may be called for either an encoded or decoded message after the
  5213. // final update. Set dwIndex to iterate through all the signers.
  5214. //
  5215. // pvData points to an array of bytes.
  5216. //--------------------------------------------------------------------------
  5217. //+-------------------------------------------------------------------------
  5218. // CMSG_ENCRYPT_PARAM
  5219. //
  5220. // The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  5221. //
  5222. // pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  5223. //--------------------------------------------------------------------------
  5224. //+-------------------------------------------------------------------------
  5225. // CMSG_ENCODED_MESSAGE
  5226. //
  5227. // The full encoded message. This is useful in the case of a decoded
  5228. // message which has been modified (eg. a signed-data or
  5229. // signed-and-enveloped-data message which has been countersigned).
  5230. //
  5231. // pvData points to an array of the message's encoded bytes.
  5232. //--------------------------------------------------------------------------
  5233. //+-------------------------------------------------------------------------
  5234. // CMSG_VERSION_PARAM
  5235. //
  5236. // The version of the decoded message.
  5237. //
  5238. // pvData points to a DWORD
  5239. //--------------------------------------------------------------------------
  5240. #define CMSG_SIGNED_DATA_V1 1
  5241. #define CMSG_SIGNED_DATA_V3 3
  5242. #define CMSG_SIGNED_DATA_PKCS_1_5_VERSION CMSG_SIGNED_DATA_V1
  5243. #define CMSG_SIGNED_DATA_CMS_VERSION CMSG_SIGNED_DATA_V3
  5244. #define CMSG_SIGNER_INFO_V1 1
  5245. #define CMSG_SIGNER_INFO_V3 3
  5246. #define CMSG_SIGNER_INFO_PKCS_1_5_VERSION CMSG_SIGNER_INFO_V1
  5247. #define CMSG_SIGNER_INFO_CMS_VERSION CMSG_SIGNER_INFO_V3
  5248. #define CMSG_HASHED_DATA_V0 0
  5249. #define CMSG_HASHED_DATA_V2 2
  5250. #define CMSG_HASHED_DATA_PKCS_1_5_VERSION CMSG_HASHED_DATA_V0
  5251. #define CMSG_HASHED_DATA_CMS_VERSION CMSG_HASHED_DATA_V2
  5252. #define CMSG_ENVELOPED_DATA_V0 0
  5253. #define CMSG_ENVELOPED_DATA_V2 2
  5254. #define CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION CMSG_ENVELOPED_DATA_V0
  5255. #define CMSG_ENVELOPED_DATA_CMS_VERSION CMSG_ENVELOPED_DATA_V2
  5256. //+-------------------------------------------------------------------------
  5257. // CMSG_ATTR_CERT_COUNT_PARAM
  5258. //
  5259. // Count of attribute certificates in a SIGNED or ENVELOPED message.
  5260. //
  5261. // pvData points to a DWORD
  5262. //--------------------------------------------------------------------------
  5263. //+-------------------------------------------------------------------------
  5264. // CMSG_ATTR_CERT_PARAM
  5265. //
  5266. // To get all the attribute certificates, repetitively call CryptMsgGetParam,
  5267. // with dwIndex set to 0 .. AttrCertCount - 1.
  5268. //
  5269. // pvData points to an array of the attribute certificate's encoded bytes.
  5270. //--------------------------------------------------------------------------
  5271. //+-------------------------------------------------------------------------
  5272. // CMSG_CMS_RECIPIENT_COUNT_PARAM
  5273. //
  5274. // Count of all CMS recipients in an ENVELOPED message.
  5275. //
  5276. // pvData points to a DWORD
  5277. //--------------------------------------------------------------------------
  5278. //+-------------------------------------------------------------------------
  5279. // CMSG_CMS_RECIPIENT_INDEX_PARAM
  5280. //
  5281. // Index of the CMS recipient used to decrypt an ENVELOPED message.
  5282. //
  5283. // pvData points to a DWORD
  5284. //--------------------------------------------------------------------------
  5285. //+-------------------------------------------------------------------------
  5286. // CMSG_CMS_RECIPIENT_ENCRYPTED_KEY_INDEX_PARAM
  5287. //
  5288. // For a CMS key agreement recipient, the index of the encrypted key
  5289. // used to decrypt an ENVELOPED message.
  5290. //
  5291. // pvData points to a DWORD
  5292. //--------------------------------------------------------------------------
  5293. //+-------------------------------------------------------------------------
  5294. // CMSG_CMS_RECIPIENT_INFO_PARAM
  5295. //
  5296. // To get all the CMS recipients, repetitively call CryptMsgGetParam, with
  5297. // dwIndex set to 0 .. CmsRecipientCount - 1.
  5298. //
  5299. // pvData points to a CMSG_CMS_RECIPIENT_INFO struct.
  5300. //--------------------------------------------------------------------------
  5301. typedef struct _CMSG_KEY_TRANS_RECIPIENT_INFO {
  5302. DWORD dwVersion;
  5303. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5304. CERT_ID RecipientId;
  5305. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5306. CRYPT_DATA_BLOB EncryptedKey;
  5307. } CMSG_KEY_TRANS_RECIPIENT_INFO, *PCMSG_KEY_TRANS_RECIPIENT_INFO;
  5308. typedef struct _CMSG_RECIPIENT_ENCRYPTED_KEY_INFO {
  5309. // Currently, only ISSUER_SERIAL_NUMBER or KEYID choices
  5310. CERT_ID RecipientId;
  5311. CRYPT_DATA_BLOB EncryptedKey;
  5312. // The following optional fields are only applicable to KEYID choice
  5313. FILETIME Date;
  5314. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5315. } CMSG_RECIPIENT_ENCRYPTED_KEY_INFO, *PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO;
  5316. typedef struct _CMSG_KEY_AGREE_RECIPIENT_INFO {
  5317. DWORD dwVersion;
  5318. DWORD dwOriginatorChoice;
  5319. union {
  5320. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5321. CERT_ID OriginatorCertId;
  5322. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5323. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5324. };
  5325. CRYPT_DATA_BLOB UserKeyingMaterial;
  5326. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5327. DWORD cRecipientEncryptedKeys;
  5328. PCMSG_RECIPIENT_ENCRYPTED_KEY_INFO *rgpRecipientEncryptedKeys;
  5329. } CMSG_KEY_AGREE_RECIPIENT_INFO, *PCMSG_KEY_AGREE_RECIPIENT_INFO;
  5330. #define CMSG_KEY_AGREE_ORIGINATOR_CERT 1
  5331. #define CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY 2
  5332. typedef struct _CMSG_MAIL_LIST_RECIPIENT_INFO {
  5333. DWORD dwVersion;
  5334. CRYPT_DATA_BLOB KeyId;
  5335. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5336. CRYPT_DATA_BLOB EncryptedKey;
  5337. // The following fields are optional
  5338. FILETIME Date;
  5339. PCRYPT_ATTRIBUTE_TYPE_VALUE pOtherAttr;
  5340. } CMSG_MAIL_LIST_RECIPIENT_INFO, *PCMSG_MAIL_LIST_RECIPIENT_INFO;
  5341. typedef struct _CMSG_CMS_RECIPIENT_INFO {
  5342. DWORD dwRecipientChoice;
  5343. union {
  5344. // CMSG_KEY_TRANS_RECIPIENT
  5345. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5346. // CMSG_KEY_AGREE_RECIPIENT
  5347. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5348. // CMSG_MAIL_LIST_RECIPIENT
  5349. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5350. };
  5351. } CMSG_CMS_RECIPIENT_INFO, *PCMSG_CMS_RECIPIENT_INFO;
  5352. // dwVersion numbers for the KeyTrans, KeyAgree and MailList recipients
  5353. #define CMSG_ENVELOPED_RECIPIENT_V0 0
  5354. #define CMSG_ENVELOPED_RECIPIENT_V2 2
  5355. #define CMSG_ENVELOPED_RECIPIENT_V3 3
  5356. #define CMSG_ENVELOPED_RECIPIENT_V4 4
  5357. #define CMSG_KEY_TRANS_PKCS_1_5_VERSION CMSG_ENVELOPED_RECIPIENT_V0
  5358. #define CMSG_KEY_TRANS_CMS_VERSION CMSG_ENVELOPED_RECIPIENT_V2
  5359. #define CMSG_KEY_AGREE_VERSION CMSG_ENVELOPED_RECIPIENT_V3
  5360. #define CMSG_MAIL_LIST_VERSION CMSG_ENVELOPED_RECIPIENT_V4
  5361. //+-------------------------------------------------------------------------
  5362. // CMSG_UNPROTECTED_ATTR_PARAM
  5363. //
  5364. // The unprotected attributes in the envelped message.
  5365. //
  5366. // pvData points to a CMSG_ATTR struct.
  5367. //--------------------------------------------------------------------------
  5368. //+-------------------------------------------------------------------------
  5369. // Perform a special "control" function after the final CryptMsgUpdate of a
  5370. // encoded/decoded cryptographic message.
  5371. //
  5372. // The dwCtrlType parameter specifies the type of operation to be performed.
  5373. //
  5374. // The pvCtrlPara definition depends on the dwCtrlType value.
  5375. //
  5376. // See below for a list of the control operations and their pvCtrlPara
  5377. // type definition.
  5378. //--------------------------------------------------------------------------
  5379. WINCRYPT32API
  5380. BOOL
  5381. WINAPI
  5382. CryptMsgControl(
  5383. IN HCRYPTMSG hCryptMsg,
  5384. IN DWORD dwFlags,
  5385. IN DWORD dwCtrlType,
  5386. IN void const *pvCtrlPara
  5387. );
  5388. //+-------------------------------------------------------------------------
  5389. // Message control types
  5390. //--------------------------------------------------------------------------
  5391. #define CMSG_CTRL_VERIFY_SIGNATURE 1
  5392. #define CMSG_CTRL_DECRYPT 2
  5393. #define CMSG_CTRL_VERIFY_HASH 5
  5394. #define CMSG_CTRL_ADD_SIGNER 6
  5395. #define CMSG_CTRL_DEL_SIGNER 7
  5396. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  5397. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  5398. #define CMSG_CTRL_ADD_CERT 10
  5399. #define CMSG_CTRL_DEL_CERT 11
  5400. #define CMSG_CTRL_ADD_CRL 12
  5401. #define CMSG_CTRL_DEL_CRL 13
  5402. #define CMSG_CTRL_ADD_ATTR_CERT 14
  5403. #define CMSG_CTRL_DEL_ATTR_CERT 15
  5404. #define CMSG_CTRL_KEY_TRANS_DECRYPT 16
  5405. #define CMSG_CTRL_KEY_AGREE_DECRYPT 17
  5406. #define CMSG_CTRL_MAIL_LIST_DECRYPT 18
  5407. #define CMSG_CTRL_VERIFY_SIGNATURE_EX 19
  5408. #define CMSG_CTRL_ADD_CMS_SIGNER_INFO 20
  5409. //+-------------------------------------------------------------------------
  5410. // CMSG_CTRL_VERIFY_SIGNATURE
  5411. //
  5412. // Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  5413. // message after it has been decoded.
  5414. //
  5415. // For a SIGNED_AND_ENVELOPED message, called after
  5416. // CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  5417. // with a NULL pRecipientInfo.
  5418. //
  5419. // pvCtrlPara points to a CERT_INFO struct.
  5420. //
  5421. // The CERT_INFO contains the Issuer and SerialNumber identifying
  5422. // the Signer of the message. The CERT_INFO also contains the
  5423. // PublicKeyInfo
  5424. // used to verify the signature. The cryptographic provider specified
  5425. // in CryptMsgOpenToDecode is used.
  5426. //
  5427. // Note, if the message contains CMS signers identified by KEYID, then,
  5428. // the CERT_INFO's Issuer and SerialNumber is ignored and only the public
  5429. // key is used to find a signer whose signature verifies.
  5430. //
  5431. // The following CMSG_CTRL_VERIFY_SIGNATURE_EX should be used instead.
  5432. //--------------------------------------------------------------------------
  5433. //+-------------------------------------------------------------------------
  5434. // CMSG_CTRL_VERIFY_SIGNATURE_EX
  5435. //
  5436. // Verify the signature of a SIGNED message after it has been decoded.
  5437. //
  5438. // pvCtrlPara points to the following CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA.
  5439. //
  5440. // If hCryptProv is NULL, uses the cryptographic provider specified in
  5441. // CryptMsgOpenToDecode. If CryptMsgOpenToDecode's hCryptProv is also NULL,
  5442. // gets default provider according to the signer's public key OID.
  5443. //
  5444. // dwSignerIndex is the index of the signer to use to verify the signature.
  5445. //
  5446. // The signer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  5447. // context or a chain context.
  5448. //
  5449. // If the signer's HashEncryptionAlgorithm is szOID_PKIX_NO_SIGNATURE, then,
  5450. // the signature is expected to contain the hash octets. Only dwSignerType
  5451. // of CMSG_VERIFY_SIGNER_NULL may be specified to verify this no signature
  5452. // case.
  5453. //--------------------------------------------------------------------------
  5454. typedef struct _CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA {
  5455. DWORD cbSize;
  5456. HCRYPTPROV hCryptProv;
  5457. DWORD dwSignerIndex;
  5458. DWORD dwSignerType;
  5459. void *pvSigner;
  5460. } CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA, *PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA;
  5461. // Signer Types
  5462. #define CMSG_VERIFY_SIGNER_PUBKEY 1
  5463. // pvSigner :: PCERT_PUBLIC_KEY_INFO
  5464. #define CMSG_VERIFY_SIGNER_CERT 2
  5465. // pvSigner :: PCCERT_CONTEXT
  5466. #define CMSG_VERIFY_SIGNER_CHAIN 3
  5467. // pvSigner :: PCCERT_CHAIN_CONTEXT
  5468. #define CMSG_VERIFY_SIGNER_NULL 4
  5469. // pvSigner :: NULL
  5470. //+-------------------------------------------------------------------------
  5471. // CMSG_CTRL_DECRYPT
  5472. //
  5473. // Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  5474. // decoded.
  5475. //
  5476. // This decrypt is only applicable to key transport recipients.
  5477. //
  5478. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5479. // 0, defaults to AT_KEYEXCHANGE.
  5480. //
  5481. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5482. // to CryptMsgControl, then, the hCryptProv is released on the final
  5483. // CryptMsgClose. Not released if CryptMsgControl fails.
  5484. //
  5485. // dwRecipientIndex is the index of the recipient in the message associated
  5486. // with the hCryptProv's private key.
  5487. //
  5488. // The dwRecipientIndex is the index of a key transport recipient.
  5489. //
  5490. // Note, the message can only be decrypted once.
  5491. //--------------------------------------------------------------------------
  5492. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  5493. DWORD cbSize;
  5494. HCRYPTPROV hCryptProv;
  5495. DWORD dwKeySpec;
  5496. DWORD dwRecipientIndex;
  5497. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  5498. //+-------------------------------------------------------------------------
  5499. // CMSG_CTRL_KEY_TRANS_DECRYPT
  5500. //
  5501. // Decrypt an ENVELOPED message after it has been decoded for a key
  5502. // transport recipient.
  5503. //
  5504. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5505. // 0, defaults to AT_KEYEXCHANGE.
  5506. //
  5507. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5508. // to CryptMsgControl, then, the hCryptProv is released on the final
  5509. // CryptMsgClose. Not released if CryptMsgControl fails.
  5510. //
  5511. // pKeyTrans points to the CMSG_KEY_TRANS_RECIPIENT_INFO obtained via
  5512. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM)
  5513. //
  5514. // dwRecipientIndex is the index of the recipient in the message associated
  5515. // with the hCryptProv's private key.
  5516. //
  5517. // Note, the message can only be decrypted once.
  5518. //--------------------------------------------------------------------------
  5519. typedef struct _CMSG_CTRL_KEY_TRANS_DECRYPT_PARA {
  5520. DWORD cbSize;
  5521. HCRYPTPROV hCryptProv;
  5522. DWORD dwKeySpec;
  5523. PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans;
  5524. DWORD dwRecipientIndex;
  5525. } CMSG_CTRL_KEY_TRANS_DECRYPT_PARA, *PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA;
  5526. //+-------------------------------------------------------------------------
  5527. // CMSG_CTRL_KEY_AGREE_DECRYPT
  5528. //
  5529. // Decrypt an ENVELOPED message after it has been decoded for a key
  5530. // agreement recipient.
  5531. //
  5532. // hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  5533. // 0, defaults to AT_KEYEXCHANGE.
  5534. //
  5535. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5536. // to CryptMsgControl, then, the hCryptProv is released on the final
  5537. // CryptMsgClose. Not released if CryptMsgControl fails.
  5538. //
  5539. // pKeyAgree points to the CMSG_KEY_AGREE_RECIPIENT_INFO obtained via
  5540. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5541. //
  5542. // dwRecipientIndex, dwRecipientEncryptedKeyIndex are the indices of the
  5543. // recipient's encrypted key in the message associated with the hCryptProv's
  5544. // private key.
  5545. //
  5546. // OriginatorPublicKey is the originator's public key obtained from either
  5547. // the originator's certificate or the CMSG_KEY_AGREE_RECIPIENT_INFO obtained
  5548. // via the CMSG_CMS_RECIPIENT_INFO_PARAM.
  5549. //
  5550. // Note, the message can only be decrypted once.
  5551. //--------------------------------------------------------------------------
  5552. typedef struct _CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
  5553. DWORD cbSize;
  5554. HCRYPTPROV hCryptProv;
  5555. DWORD dwKeySpec;
  5556. PCMSG_KEY_AGREE_RECIPIENT_INFO pKeyAgree;
  5557. DWORD dwRecipientIndex;
  5558. DWORD dwRecipientEncryptedKeyIndex;
  5559. CRYPT_BIT_BLOB OriginatorPublicKey;
  5560. } CMSG_CTRL_KEY_AGREE_DECRYPT_PARA, *PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
  5561. //+-------------------------------------------------------------------------
  5562. // CMSG_CTRL_MAIL_LIST_DECRYPT
  5563. //
  5564. // Decrypt an ENVELOPED message after it has been decoded for a mail
  5565. // list recipient.
  5566. //
  5567. // pMailList points to the CMSG_MAIL_LIST_RECIPIENT_INFO obtained via
  5568. // CryptMsgGetParam(CMSG_CMS_RECIPIENT_INFO_PARAM) for dwRecipientIndex.
  5569. //
  5570. // There is 1 choice for the KeyEncryptionKey: an already created CSP key
  5571. // handle. For the key handle choice, hCryptProv must be nonzero. This key
  5572. // handle isn't destroyed.
  5573. //
  5574. // If CMSG_CRYPT_RELEASE_CONTEXT_FLAG is set in the dwFlags passed
  5575. // to CryptMsgControl, then, the hCryptProv is released on the final
  5576. // CryptMsgClose. Not released if CryptMsgControl fails.
  5577. //
  5578. // For RC2 wrap, the effective key length is obtained from the
  5579. // KeyEncryptionAlgorithm parameters and set on the hKeyEncryptionKey before
  5580. // decrypting.
  5581. //
  5582. // Note, the message can only be decrypted once.
  5583. //--------------------------------------------------------------------------
  5584. typedef struct _CMSG_CTRL_MAIL_LIST_DECRYPT_PARA {
  5585. DWORD cbSize;
  5586. HCRYPTPROV hCryptProv;
  5587. PCMSG_MAIL_LIST_RECIPIENT_INFO pMailList;
  5588. DWORD dwRecipientIndex;
  5589. DWORD dwKeyChoice;
  5590. union {
  5591. // CMSG_MAIL_LIST_HANDLE_KEY_CHOICE
  5592. HCRYPTKEY hKeyEncryptionKey;
  5593. // Reserve space for a potential pointer choice
  5594. void *pvKeyEncryptionKey;
  5595. };
  5596. } CMSG_CTRL_MAIL_LIST_DECRYPT_PARA, *PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA;
  5597. //+-------------------------------------------------------------------------
  5598. // CMSG_CTRL_VERIFY_HASH
  5599. //
  5600. // Verify the hash of a HASHED message after it has been decoded.
  5601. //
  5602. // Only the hCryptMsg parameter is used, to specify the message whose
  5603. // hash is being verified.
  5604. //--------------------------------------------------------------------------
  5605. //+-------------------------------------------------------------------------
  5606. // CMSG_CTRL_ADD_SIGNER
  5607. //
  5608. // Add a signer to a signed-data message.
  5609. //
  5610. // pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  5611. //--------------------------------------------------------------------------
  5612. //+-------------------------------------------------------------------------
  5613. // CMSG_CTRL_ADD_CMS_SIGNER_INFO
  5614. //
  5615. // Add a signer to a signed-data message.
  5616. //
  5617. // Differs from the above, CMSG_CTRL_ADD_SIGNER, wherein, the signer info
  5618. // already contains the signature.
  5619. //
  5620. // pvCtrlPara points to a CMSG_CMS_SIGNER_INFO.
  5621. //--------------------------------------------------------------------------
  5622. //+-------------------------------------------------------------------------
  5623. // CMSG_CTRL_DEL_SIGNER
  5624. //
  5625. // Remove a signer from a signed-data or signed-and-enveloped-data message.
  5626. //
  5627. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5628. // signer to be removed.
  5629. //--------------------------------------------------------------------------
  5630. //+-------------------------------------------------------------------------
  5631. // CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  5632. //
  5633. // Add an unauthenticated attribute to the SignerInfo of a signed-data or
  5634. // signed-and-enveloped-data message.
  5635. //
  5636. // The unauthenticated attribute is input in the form of an encoded blob.
  5637. //--------------------------------------------------------------------------
  5638. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  5639. DWORD cbSize;
  5640. DWORD dwSignerIndex;
  5641. CRYPT_DATA_BLOB blob;
  5642. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  5643. //+-------------------------------------------------------------------------
  5644. // CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  5645. //
  5646. // Delete an unauthenticated attribute from the SignerInfo of a signed-data
  5647. // or signed-and-enveloped-data message.
  5648. //
  5649. // The unauthenticated attribute to be removed is specified by
  5650. // a 0-based index.
  5651. //--------------------------------------------------------------------------
  5652. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  5653. DWORD cbSize;
  5654. DWORD dwSignerIndex;
  5655. DWORD dwUnauthAttrIndex;
  5656. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  5657. //+-------------------------------------------------------------------------
  5658. // CMSG_CTRL_ADD_CERT
  5659. //
  5660. // Add a certificate to a signed-data or signed-and-enveloped-data message.
  5661. //
  5662. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  5663. // encoded bytes.
  5664. //--------------------------------------------------------------------------
  5665. //+-------------------------------------------------------------------------
  5666. // CMSG_CTRL_DEL_CERT
  5667. //
  5668. // Delete a certificate from a signed-data or signed-and-enveloped-data
  5669. // message.
  5670. //
  5671. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5672. // certificate to be removed.
  5673. //--------------------------------------------------------------------------
  5674. //+-------------------------------------------------------------------------
  5675. // CMSG_CTRL_ADD_CRL
  5676. //
  5677. // Add a CRL to a signed-data or signed-and-enveloped-data message.
  5678. //
  5679. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  5680. // encoded bytes.
  5681. //--------------------------------------------------------------------------
  5682. //+-------------------------------------------------------------------------
  5683. // CMSG_CTRL_DEL_CRL
  5684. //
  5685. // Delete a CRL from a signed-data or signed-and-enveloped-data message.
  5686. //
  5687. // pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  5688. // to be removed.
  5689. //--------------------------------------------------------------------------
  5690. //+-------------------------------------------------------------------------
  5691. // CMSG_CTRL_ADD_ATTR_CERT
  5692. //
  5693. // Add an attribute certificate to a signed-data message.
  5694. //
  5695. // pvCtrlPara points to a CRYPT_DATA_BLOB containing the attribute
  5696. // certificate's encoded bytes.
  5697. //--------------------------------------------------------------------------
  5698. //+-------------------------------------------------------------------------
  5699. // CMSG_CTRL_DEL_ATTR_CERT
  5700. //
  5701. // Delete an attribute certificate from a signed-data message.
  5702. //
  5703. // pvCtrlPara points to a DWORD containing the 0-based index of the
  5704. // attribute certificate to be removed.
  5705. //--------------------------------------------------------------------------
  5706. //+-------------------------------------------------------------------------
  5707. // Verify a countersignature, at the SignerInfo level.
  5708. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5709. // hash of the encryptedDigest field of pbSignerInfo.
  5710. //
  5711. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5712. // The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  5713. // and SubjectPublicKeyInfo.
  5714. //--------------------------------------------------------------------------
  5715. BOOL
  5716. WINAPI
  5717. CryptMsgVerifyCountersignatureEncoded(
  5718. IN HCRYPTPROV hCryptProv,
  5719. IN DWORD dwEncodingType,
  5720. IN PBYTE pbSignerInfo,
  5721. IN DWORD cbSignerInfo,
  5722. IN PBYTE pbSignerInfoCountersignature,
  5723. IN DWORD cbSignerInfoCountersignature,
  5724. IN PCERT_INFO pciCountersigner
  5725. );
  5726. //+-------------------------------------------------------------------------
  5727. // Verify a countersignature, at the SignerInfo level.
  5728. // ie. verify that pbSignerInfoCountersignature contains the encrypted
  5729. // hash of the encryptedDigest field of pbSignerInfo.
  5730. //
  5731. // hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  5732. //
  5733. // The signer can be a CERT_PUBLIC_KEY_INFO, certificate context or a
  5734. // chain context.
  5735. //--------------------------------------------------------------------------
  5736. BOOL
  5737. WINAPI
  5738. CryptMsgVerifyCountersignatureEncodedEx(
  5739. IN HCRYPTPROV hCryptProv,
  5740. IN DWORD dwEncodingType,
  5741. IN PBYTE pbSignerInfo,
  5742. IN DWORD cbSignerInfo,
  5743. IN PBYTE pbSignerInfoCountersignature,
  5744. IN DWORD cbSignerInfoCountersignature,
  5745. IN DWORD dwSignerType,
  5746. IN void *pvSigner,
  5747. IN DWORD dwFlags,
  5748. IN OPTIONAL void *pvReserved
  5749. );
  5750. // See CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA for dwSignerType definitions
  5751. //+-------------------------------------------------------------------------
  5752. // Countersign an already-existing signature in a message
  5753. //
  5754. // dwIndex is a zero-based index of the SignerInfo to be countersigned.
  5755. //--------------------------------------------------------------------------
  5756. BOOL
  5757. WINAPI
  5758. CryptMsgCountersign(
  5759. IN OUT HCRYPTMSG hCryptMsg,
  5760. IN DWORD dwIndex,
  5761. IN DWORD cCountersigners,
  5762. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  5763. );
  5764. //+-------------------------------------------------------------------------
  5765. // Countersign an already-existing signature (encoded SignerInfo).
  5766. // Output an encoded SignerInfo blob, suitable for use as a countersignature
  5767. // attribute in the unauthenticated attributes of a signed-data or
  5768. // signed-and-enveloped-data message.
  5769. //--------------------------------------------------------------------------
  5770. BOOL
  5771. WINAPI
  5772. CryptMsgCountersignEncoded(
  5773. IN DWORD dwEncodingType,
  5774. IN PBYTE pbSignerInfo,
  5775. IN DWORD cbSignerInfo,
  5776. IN DWORD cCountersigners,
  5777. IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  5778. OUT PBYTE pbCountersignature,
  5779. IN OUT PDWORD pcbCountersignature
  5780. );
  5781. //+-------------------------------------------------------------------------
  5782. // CryptMsg OID installable functions
  5783. //--------------------------------------------------------------------------
  5784. typedef void * (WINAPI *PFN_CMSG_ALLOC) (
  5785. IN size_t cb
  5786. );
  5787. typedef void (WINAPI *PFN_CMSG_FREE)(
  5788. IN void *pv
  5789. );
  5790. // Note, the following 3 installable functions are obsolete and have been
  5791. // replaced with GenContentEncryptKey, ExportKeyTrans, ExportKeyAgree,
  5792. // ExportMailList, ImportKeyTrans, ImportKeyAgree and ImportMailList
  5793. // installable functions.
  5794. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  5795. // function should acquire a default provider and return. Note, its up
  5796. // to the installable function to release at process detach.
  5797. //
  5798. // If paiEncrypt->Parameters.cbData is 0, then, the callback may optionally
  5799. // return default encoded parameters in *ppbEncryptParameters and
  5800. // *pcbEncryptParameters. pfnAlloc must be called for the allocation.
  5801. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC "CryptMsgDllGenEncryptKey"
  5802. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  5803. IN OUT HCRYPTPROV *phCryptProv,
  5804. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5805. IN PVOID pvEncryptAuxInfo,
  5806. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5807. IN PFN_CMSG_ALLOC pfnAlloc,
  5808. OUT HCRYPTKEY *phEncryptKey,
  5809. OUT PBYTE *ppbEncryptParameters,
  5810. OUT PDWORD pcbEncryptParameters
  5811. );
  5812. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC "CryptMsgDllExportEncryptKey"
  5813. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  5814. IN HCRYPTPROV hCryptProv,
  5815. IN HCRYPTKEY hEncryptKey,
  5816. IN PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  5817. OUT PBYTE pbData,
  5818. IN OUT PDWORD pcbData
  5819. );
  5820. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC "CryptMsgDllImportEncryptKey"
  5821. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  5822. IN HCRYPTPROV hCryptProv,
  5823. IN DWORD dwKeySpec,
  5824. IN PCRYPT_ALGORITHM_IDENTIFIER paiEncrypt,
  5825. IN PCRYPT_ALGORITHM_IDENTIFIER paiPubKey,
  5826. IN PBYTE pbEncodedKey,
  5827. IN DWORD cbEncodedKey,
  5828. OUT HCRYPTKEY *phEncryptKey
  5829. );
  5830. // To get the default installable function for GenContentEncryptKey,
  5831. // ExportKeyTrans, ExportKeyAgree, ExportMailList, ImportKeyTrans,
  5832. // ImportKeyAgree or ImportMailList call CryptGetOIDFunctionAddress()
  5833. // with the pszOID argument set to the following constant. dwEncodingType
  5834. // should be set to CRYPT_ASN_ENCODING or X509_ASN_ENCODING.
  5835. #define CMSG_DEFAULT_INSTALLABLE_FUNC_OID ((LPCSTR) 1)
  5836. //+-------------------------------------------------------------------------
  5837. // Content Encrypt Info
  5838. //
  5839. // The following data structure contains the information shared between
  5840. // the GenContentEncryptKey and the ExportKeyTrans, ExportKeyAgree and
  5841. // ExportMailList installable functions.
  5842. //--------------------------------------------------------------------------
  5843. typedef struct _CMSG_CONTENT_ENCRYPT_INFO {
  5844. DWORD cbSize;
  5845. HCRYPTPROV hCryptProv;
  5846. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  5847. void *pvEncryptionAuxInfo;
  5848. DWORD cRecipients;
  5849. PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients;
  5850. PFN_CMSG_ALLOC pfnAlloc;
  5851. PFN_CMSG_FREE pfnFree;
  5852. DWORD dwEncryptFlags;
  5853. HCRYPTKEY hContentEncryptKey;
  5854. DWORD dwFlags;
  5855. } CMSG_CONTENT_ENCRYPT_INFO, *PCMSG_CONTENT_ENCRYPT_INFO;
  5856. #define CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG 0x00000001
  5857. #define CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5858. #define CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG 0x00008000
  5859. //+-------------------------------------------------------------------------
  5860. // Upon input, ContentEncryptInfo has been initialized from the
  5861. // EnvelopedEncodeInfo.
  5862. //
  5863. // Note, if rgpRecipients instead of rgCmsRecipients are set in the
  5864. // EnvelopedEncodeInfo, then, the rgpRecipients have been converted
  5865. // to rgCmsRecipients in the ContentEncryptInfo.
  5866. //
  5867. // The following fields may be changed in ContentEncryptInfo:
  5868. // hContentEncryptKey
  5869. // hCryptProv
  5870. // ContentEncryptionAlgorithm.Parameters
  5871. // dwFlags
  5872. //
  5873. // All other fields in the ContentEncryptInfo are READONLY.
  5874. //
  5875. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  5876. // in dwEncryptFlags, then, any potentially variable length encoded
  5877. // output should be padded with zeroes to always obtain the
  5878. // same maximum encoded length. This is necessary for
  5879. // CryptMsgCalculateEncodedLength() or CryptMsgOpenToEncode() with
  5880. // definite length streaming.
  5881. //
  5882. // The hContentEncryptKey must be updated.
  5883. //
  5884. // If hCryptProv is NULL upon input, then, it must be updated.
  5885. // If a HCRYPTPROV is acquired that must be released, then, the
  5886. // CMSG_CONTENT_ENCRYPT_RELEASE_CONTEXT_FLAG must be set in dwFlags.
  5887. //
  5888. // If ContentEncryptionAlgorithm.Parameters is updated, then, the
  5889. // CMSG_CONTENT_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags. pfnAlloc and
  5890. // pfnFree must be used for doing the allocation.
  5891. //
  5892. // ContentEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5893. //--------------------------------------------------------------------------
  5894. #define CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC "CryptMsgDllGenContentEncryptKey"
  5895. typedef BOOL (WINAPI *PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY) (
  5896. IN OUT PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5897. IN DWORD dwFlags,
  5898. IN OPTIONAL void *pvReserved
  5899. );
  5900. //+-------------------------------------------------------------------------
  5901. // Key Transport Encrypt Info
  5902. //
  5903. // The following data structure contains the information updated by the
  5904. // ExportKeyTrans installable function.
  5905. //--------------------------------------------------------------------------
  5906. typedef struct _CMSG_KEY_TRANS_ENCRYPT_INFO {
  5907. DWORD cbSize;
  5908. DWORD dwRecipientIndex;
  5909. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5910. CRYPT_DATA_BLOB EncryptedKey;
  5911. DWORD dwFlags;
  5912. } CMSG_KEY_TRANS_ENCRYPT_INFO, *PCMSG_KEY_TRANS_ENCRYPT_INFO;
  5913. #define CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5914. //+-------------------------------------------------------------------------
  5915. // Upon input, KeyTransEncryptInfo has been initialized from the
  5916. // KeyTransEncodeInfo.
  5917. //
  5918. // The following fields may be changed in KeyTransEncryptInfo:
  5919. // EncryptedKey
  5920. // KeyEncryptionAlgorithm.Parameters
  5921. // dwFlags
  5922. //
  5923. // All other fields in the KeyTransEncryptInfo are READONLY.
  5924. //
  5925. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  5926. // ContentEncryptInfo must be used for doing the allocation.
  5927. //
  5928. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5929. // CMSG_KEY_TRANS_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5930. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5931. // for doing the allocation.
  5932. //
  5933. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  5934. //--------------------------------------------------------------------------
  5935. #define CMSG_OID_EXPORT_KEY_TRANS_FUNC "CryptMsgDllExportKeyTrans"
  5936. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_TRANS) (
  5937. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  5938. IN PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
  5939. IN OUT PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
  5940. IN DWORD dwFlags,
  5941. IN OPTIONAL void *pvReserved
  5942. );
  5943. //+-------------------------------------------------------------------------
  5944. // Key Agree Key Encrypt Info
  5945. //
  5946. // The following data structure contains the information updated by the
  5947. // ExportKeyAgree installable function for each encrypted key agree
  5948. // recipient.
  5949. //--------------------------------------------------------------------------
  5950. typedef struct _CMSG_KEY_AGREE_KEY_ENCRYPT_INFO {
  5951. DWORD cbSize;
  5952. CRYPT_DATA_BLOB EncryptedKey;
  5953. } CMSG_KEY_AGREE_KEY_ENCRYPT_INFO, *PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO;
  5954. //+-------------------------------------------------------------------------
  5955. // Key Agree Encrypt Info
  5956. //
  5957. // The following data structure contains the information applicable to
  5958. // all recipients. Its updated by the ExportKeyAgree installable function.
  5959. //--------------------------------------------------------------------------
  5960. typedef struct _CMSG_KEY_AGREE_ENCRYPT_INFO {
  5961. DWORD cbSize;
  5962. DWORD dwRecipientIndex;
  5963. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  5964. CRYPT_DATA_BLOB UserKeyingMaterial;
  5965. DWORD dwOriginatorChoice;
  5966. union {
  5967. // CMSG_KEY_AGREE_ORIGINATOR_CERT
  5968. CERT_ID OriginatorCertId;
  5969. // CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY
  5970. CERT_PUBLIC_KEY_INFO OriginatorPublicKeyInfo;
  5971. };
  5972. DWORD cKeyAgreeKeyEncryptInfo;
  5973. PCMSG_KEY_AGREE_KEY_ENCRYPT_INFO *rgpKeyAgreeKeyEncryptInfo;
  5974. DWORD dwFlags;
  5975. } CMSG_KEY_AGREE_ENCRYPT_INFO, *PCMSG_KEY_AGREE_ENCRYPT_INFO;
  5976. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG 0x00000001
  5977. #define CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG 0x00000002
  5978. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_ALG_FLAG 0x00000004
  5979. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_PARA_FLAG 0x00000008
  5980. #define CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_BITS_FLAG 0x00000010
  5981. //+-------------------------------------------------------------------------
  5982. // Upon input, KeyAgreeEncryptInfo has been initialized from the
  5983. // KeyAgreeEncodeInfo.
  5984. //
  5985. // The following fields may be changed in KeyAgreeEncryptInfo:
  5986. // KeyEncryptionAlgorithm.Parameters
  5987. // UserKeyingMaterial
  5988. // dwOriginatorChoice
  5989. // OriginatorCertId
  5990. // OriginatorPublicKeyInfo
  5991. // dwFlags
  5992. //
  5993. // All other fields in the KeyAgreeEncryptInfo are READONLY.
  5994. //
  5995. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  5996. // CMSG_KEY_AGREE_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  5997. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  5998. // for doing the allocation.
  5999. //
  6000. // If the UserKeyingMaterial is updated, then, the
  6001. // CMSG_KEY_AGREE_ENCRYPT_FREE_MATERIAL_FLAG must be set in dwFlags.
  6002. // pfnAlloc and pfnFree must be used for doing the allocation.
  6003. //
  6004. // The dwOriginatorChoice must be updated to either
  6005. // CMSG_KEY_AGREE_ORIGINATOR_CERT or CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY.
  6006. //
  6007. // If the OriginatorPublicKeyInfo is updated, then, the appropriate
  6008. // CMSG_KEY_AGREE_ENCRYPT_FREE_PUBKEY_*_FLAG must be set in dwFlags and
  6009. // pfnAlloc and pfnFree must be used for doing the allocation.
  6010. //
  6011. // If CMSG_CONTENT_ENCRYPT_PAD_ENCODED_LEN_FLAG is set upon entry
  6012. // in pContentEncryptInfo->dwEncryptFlags, then, the OriginatorPublicKeyInfo's
  6013. // Ephemeral PublicKey should be padded with zeroes to always obtain the
  6014. // same maximum encoded length. Note, the length of the generated ephemeral Y
  6015. // public key can vary depending on the number of leading zero bits.
  6016. //
  6017. // Upon input, the array of *rgpKeyAgreeKeyEncryptInfo has been initialized.
  6018. // The EncryptedKey must be updated for each recipient key.
  6019. // The pfnAlloc and pfnFree specified in
  6020. // ContentEncryptInfo must be used for doing the allocation.
  6021. //
  6022. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6023. //--------------------------------------------------------------------------
  6024. #define CMSG_OID_EXPORT_KEY_AGREE_FUNC "CryptMsgDllExportKeyAgree"
  6025. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_KEY_AGREE) (
  6026. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6027. IN PCMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO pKeyAgreeEncodeInfo,
  6028. IN OUT PCMSG_KEY_AGREE_ENCRYPT_INFO pKeyAgreeEncryptInfo,
  6029. IN DWORD dwFlags,
  6030. IN OPTIONAL void *pvReserved
  6031. );
  6032. //+-------------------------------------------------------------------------
  6033. // Mail List Encrypt Info
  6034. //
  6035. // The following data structure contains the information updated by the
  6036. // ExportMailList installable function.
  6037. //--------------------------------------------------------------------------
  6038. typedef struct _CMSG_MAIL_LIST_ENCRYPT_INFO {
  6039. DWORD cbSize;
  6040. DWORD dwRecipientIndex;
  6041. CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm;
  6042. CRYPT_DATA_BLOB EncryptedKey;
  6043. DWORD dwFlags;
  6044. } CMSG_MAIL_LIST_ENCRYPT_INFO, *PCMSG_MAIL_LIST_ENCRYPT_INFO;
  6045. #define CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG 0x00000001
  6046. //+-------------------------------------------------------------------------
  6047. // Upon input, MailListEncryptInfo has been initialized from the
  6048. // MailListEncodeInfo.
  6049. //
  6050. // The following fields may be changed in MailListEncryptInfo:
  6051. // EncryptedKey
  6052. // KeyEncryptionAlgorithm.Parameters
  6053. // dwFlags
  6054. //
  6055. // All other fields in the MailListEncryptInfo are READONLY.
  6056. //
  6057. // The EncryptedKey must be updated. The pfnAlloc and pfnFree specified in
  6058. // ContentEncryptInfo must be used for doing the allocation.
  6059. //
  6060. // If the KeyEncryptionAlgorithm.Parameters is updated, then, the
  6061. // CMSG_MAIL_LIST_ENCRYPT_FREE_PARA_FLAG must be set in dwFlags.
  6062. // The pfnAlloc and pfnFree specified in ContentEncryptInfo must be used
  6063. // for doing the allocation.
  6064. //
  6065. // KeyEncryptionAlgorithm.pszObjId is used to get the OIDFunctionAddress.
  6066. //--------------------------------------------------------------------------
  6067. #define CMSG_OID_EXPORT_MAIL_LIST_FUNC "CryptMsgDllExportMailList"
  6068. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_MAIL_LIST) (
  6069. IN PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
  6070. IN PCMSG_MAIL_LIST_RECIPIENT_ENCODE_INFO pMailListEncodeInfo,
  6071. IN OUT PCMSG_MAIL_LIST_ENCRYPT_INFO pMailListEncryptInfo,
  6072. IN DWORD dwFlags,
  6073. IN OPTIONAL void *pvReserved
  6074. );
  6075. //+-------------------------------------------------------------------------
  6076. // OID Installable functions for importing an encoded and encrypted content
  6077. // encryption key.
  6078. //
  6079. // There's a different installable function for each CMS Recipient choice:
  6080. // ImportKeyTrans
  6081. // ImportKeyAgree
  6082. // ImportMailList
  6083. //
  6084. // Iterates through the following OIDs to get the OID installable function:
  6085. // KeyEncryptionOID!ContentEncryptionOID
  6086. // KeyEncryptionOID
  6087. // ContentEncryptionOID
  6088. //
  6089. // If the OID installable function doesn't support the specified
  6090. // KeyEncryption and ContentEncryption OIDs, then, return FALSE with
  6091. // LastError set to E_NOTIMPL.
  6092. //--------------------------------------------------------------------------
  6093. #define CMSG_OID_IMPORT_KEY_TRANS_FUNC "CryptMsgDllImportKeyTrans"
  6094. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_TRANS) (
  6095. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6096. IN PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara,
  6097. IN DWORD dwFlags,
  6098. IN OPTIONAL void *pvReserved,
  6099. OUT HCRYPTKEY *phContentEncryptKey
  6100. );
  6101. #define CMSG_OID_IMPORT_KEY_AGREE_FUNC "CryptMsgDllImportKeyAgree"
  6102. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_KEY_AGREE) (
  6103. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6104. IN PCMSG_CTRL_KEY_AGREE_DECRYPT_PARA pKeyAgreeDecryptPara,
  6105. IN DWORD dwFlags,
  6106. IN OPTIONAL void *pvReserved,
  6107. OUT HCRYPTKEY *phContentEncryptKey
  6108. );
  6109. #define CMSG_OID_IMPORT_MAIL_LIST_FUNC "CryptMsgDllImportMailList"
  6110. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_MAIL_LIST) (
  6111. IN PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
  6112. IN PCMSG_CTRL_MAIL_LIST_DECRYPT_PARA pMailListDecryptPara,
  6113. IN DWORD dwFlags,
  6114. IN OPTIONAL void *pvReserved,
  6115. OUT HCRYPTKEY *phContentEncryptKey
  6116. );
  6117. //+=========================================================================
  6118. // Certificate Store Data Structures and APIs
  6119. //==========================================================================
  6120. //+-------------------------------------------------------------------------
  6121. // In its most basic implementation, a cert store is simply a
  6122. // collection of certificates and/or CRLs. This is the case when
  6123. // a cert store is opened with all of its certificates and CRLs
  6124. // coming from a PKCS #7 encoded cryptographic message.
  6125. //
  6126. // Nonetheless, all cert stores have the following properties:
  6127. // - A public key may have more than one certificate in the store.
  6128. // For example, a private/public key used for signing may have a
  6129. // certificate issued for VISA and another issued for
  6130. // Mastercard. Also, when a certificate is renewed there might
  6131. // be more than one certificate with the same subject and
  6132. // issuer.
  6133. // - However, each certificate in the store is uniquely
  6134. // identified by its Issuer and SerialNumber.
  6135. // - There's an issuer of subject certificate relationship. A
  6136. // certificate's issuer is found by doing a match of
  6137. // pSubjectCert->Issuer with pIssuerCert->Subject.
  6138. // The relationship is verified by using
  6139. // the issuer's public key to verify the subject certificate's
  6140. // signature. Note, there might be X.509 v3 extensions
  6141. // to assist in finding the issuer certificate.
  6142. // - Since issuer certificates might be renewed, a subject
  6143. // certificate might have more than one issuer certificate.
  6144. // - There's an issuer of CRL relationship. An
  6145. // issuer's CRL is found by doing a match of
  6146. // pIssuerCert->Subject with pCrl->Issuer.
  6147. // The relationship is verified by using
  6148. // the issuer's public key to verify the CRL's
  6149. // signature. Note, there might be X.509 v3 extensions
  6150. // to assist in finding the CRL.
  6151. // - Since some issuers might support the X.509 v3 delta CRL
  6152. // extensions, an issuer might have more than one CRL.
  6153. // - The store shouldn't have any redundant certificates or
  6154. // CRLs. There shouldn't be two certificates with the same
  6155. // Issuer and SerialNumber. There shouldn't be two CRLs with
  6156. // the same Issuer, ThisUpdate and NextUpdate.
  6157. // - The store has NO policy or trust information. No
  6158. // certificates are tagged as being "root". Its up to
  6159. // the application to maintain a list of CertIds (Issuer +
  6160. // SerialNumber) for certificates it trusts.
  6161. // - The store might contain bad certificates and/or CRLs.
  6162. // The issuer's signature of a subject certificate or CRL may
  6163. // not verify. Certificates or CRLs may not satisfy their
  6164. // time validity requirements. Certificates may be
  6165. // revoked.
  6166. //
  6167. // In addition to the certificates and CRLs, properties can be
  6168. // stored. There are two predefined property IDs for a user
  6169. // certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  6170. // CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  6171. // is a HCRYPTPROV handle to the private key assoicated
  6172. // with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  6173. // information to be used to call
  6174. // CryptAcquireContext and CryptSetProvParam to get a handle
  6175. // to the private key associated with the certificate.
  6176. //
  6177. // There exists two more predefined property IDs for certificates
  6178. // and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  6179. // If these properties don't already exist, then, a hash of the
  6180. // content is computed. (CERT_HASH_PROP_ID maps to the default
  6181. // hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  6182. //
  6183. // There are additional APIs for creating certificate and CRL
  6184. // contexts not in a store (CertCreateCertificateContext and
  6185. // CertCreateCRLContext).
  6186. //
  6187. //--------------------------------------------------------------------------
  6188. typedef void *HCERTSTORE;
  6189. //+-------------------------------------------------------------------------
  6190. // Certificate context.
  6191. //
  6192. // A certificate context contains both the encoded and decoded representation
  6193. // of a certificate. A certificate context returned by a cert store function
  6194. // must be freed by calling the CertFreeCertificateContext function. The
  6195. // CertDuplicateCertificateContext function can be called to make a duplicate
  6196. // copy (which also must be freed by calling CertFreeCertificateContext).
  6197. //--------------------------------------------------------------------------
  6198. typedef struct _CERT_CONTEXT {
  6199. DWORD dwCertEncodingType;
  6200. BYTE *pbCertEncoded;
  6201. DWORD cbCertEncoded;
  6202. PCERT_INFO pCertInfo;
  6203. HCERTSTORE hCertStore;
  6204. } CERT_CONTEXT, *PCERT_CONTEXT;
  6205. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  6206. //+-------------------------------------------------------------------------
  6207. // CRL context.
  6208. //
  6209. // A CRL context contains both the encoded and decoded representation
  6210. // of a CRL. A CRL context returned by a cert store function
  6211. // must be freed by calling the CertFreeCRLContext function. The
  6212. // CertDuplicateCRLContext function can be called to make a duplicate
  6213. // copy (which also must be freed by calling CertFreeCRLContext).
  6214. //--------------------------------------------------------------------------
  6215. typedef struct _CRL_CONTEXT {
  6216. DWORD dwCertEncodingType;
  6217. BYTE *pbCrlEncoded;
  6218. DWORD cbCrlEncoded;
  6219. PCRL_INFO pCrlInfo;
  6220. HCERTSTORE hCertStore;
  6221. } CRL_CONTEXT, *PCRL_CONTEXT;
  6222. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  6223. //+-------------------------------------------------------------------------
  6224. // Certificate Trust List (CTL) context.
  6225. //
  6226. // A CTL context contains both the encoded and decoded representation
  6227. // of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  6228. // cryptographic signed message containing the CTL_INFO as its inner content.
  6229. // pbCtlContent is the encoded inner content of the signed message.
  6230. //
  6231. // The CryptMsg APIs can be used to extract additional signer information.
  6232. //--------------------------------------------------------------------------
  6233. typedef struct _CTL_CONTEXT {
  6234. DWORD dwMsgAndCertEncodingType;
  6235. BYTE *pbCtlEncoded;
  6236. DWORD cbCtlEncoded;
  6237. PCTL_INFO pCtlInfo;
  6238. HCERTSTORE hCertStore;
  6239. HCRYPTMSG hCryptMsg;
  6240. BYTE *pbCtlContent;
  6241. DWORD cbCtlContent;
  6242. } CTL_CONTEXT, *PCTL_CONTEXT;
  6243. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  6244. //+-------------------------------------------------------------------------
  6245. // Certificate, CRL and CTL property IDs
  6246. //
  6247. // See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  6248. // for usage information.
  6249. //--------------------------------------------------------------------------
  6250. #define CERT_KEY_PROV_HANDLE_PROP_ID 1
  6251. #define CERT_KEY_PROV_INFO_PROP_ID 2
  6252. #define CERT_SHA1_HASH_PROP_ID 3
  6253. #define CERT_MD5_HASH_PROP_ID 4
  6254. #define CERT_HASH_PROP_ID CERT_SHA1_HASH_PROP_ID
  6255. #define CERT_KEY_CONTEXT_PROP_ID 5
  6256. #define CERT_KEY_SPEC_PROP_ID 6
  6257. #define CERT_IE30_RESERVED_PROP_ID 7
  6258. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID 8
  6259. #define CERT_ENHKEY_USAGE_PROP_ID 9
  6260. #define CERT_CTL_USAGE_PROP_ID CERT_ENHKEY_USAGE_PROP_ID
  6261. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID 10
  6262. #define CERT_FRIENDLY_NAME_PROP_ID 11
  6263. #define CERT_PVK_FILE_PROP_ID 12
  6264. #define CERT_DESCRIPTION_PROP_ID 13
  6265. #define CERT_ACCESS_STATE_PROP_ID 14
  6266. #define CERT_SIGNATURE_HASH_PROP_ID 15
  6267. #define CERT_SMART_CARD_DATA_PROP_ID 16
  6268. #define CERT_EFS_PROP_ID 17
  6269. #define CERT_FORTEZZA_DATA_PROP_ID 18
  6270. #define CERT_ARCHIVED_PROP_ID 19
  6271. #define CERT_KEY_IDENTIFIER_PROP_ID 20
  6272. #define CERT_AUTO_ENROLL_PROP_ID 21
  6273. #define CERT_PUBKEY_ALG_PARA_PROP_ID 22
  6274. #define CERT_CROSS_CERT_DIST_POINTS_PROP_ID 23
  6275. #define CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID 24
  6276. #define CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID 25
  6277. #define CERT_ENROLLMENT_PROP_ID 26
  6278. #define CERT_DATE_STAMP_PROP_ID 27
  6279. #define CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID 28
  6280. #define CERT_SUBJECT_NAME_MD5_HASH_PROP_ID 29
  6281. #define CERT_EXTENDED_ERROR_INFO_PROP_ID 30
  6282. // Note, 32 - 35 are reserved for the CERT, CRL, CTL and KeyId file element IDs.
  6283. // 36 - 63 are reserved for future element IDs.
  6284. #define CERT_RENEWAL_PROP_ID 64
  6285. #define CERT_ARCHIVED_KEY_HASH_PROP_ID 65
  6286. #define CERT_AUTO_ENROLL_RETRY_PROP_ID 66
  6287. #define CERT_AIA_URL_RETRIEVED_PROP_ID 67
  6288. #define CERT_FIRST_RESERVED_PROP_ID 68
  6289. #define CERT_LAST_RESERVED_PROP_ID 0x00007FFF
  6290. #define CERT_FIRST_USER_PROP_ID 0x00008000
  6291. #define CERT_LAST_USER_PROP_ID 0x0000FFFF
  6292. #define IS_CERT_HASH_PROP_ID(X) (CERT_SHA1_HASH_PROP_ID == (X) || \
  6293. CERT_MD5_HASH_PROP_ID == (X) || \
  6294. CERT_SIGNATURE_HASH_PROP_ID == (X))
  6295. #define IS_PUBKEY_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6296. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X))
  6297. #define IS_CHAIN_HASH_PROP_ID(X) (CERT_ISSUER_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6298. CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID == (X) || \
  6299. CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID == (X) || \
  6300. CERT_SUBJECT_NAME_MD5_HASH_PROP_ID == (X))
  6301. //+-------------------------------------------------------------------------
  6302. // Property OIDs
  6303. //--------------------------------------------------------------------------
  6304. // The OID component following the prefix contains the PROP_ID (decimal)
  6305. #define szOID_CERT_PROP_ID_PREFIX "1.3.6.1.4.1.311.10.11."
  6306. #define szOID_CERT_KEY_IDENTIFIER_PROP_ID "1.3.6.1.4.1.311.10.11.20"
  6307. #define szOID_CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID \
  6308. "1.3.6.1.4.1.311.10.11.28"
  6309. #define szOID_CERT_SUBJECT_NAME_MD5_HASH_PROP_ID \
  6310. "1.3.6.1.4.1.311.10.11.29"
  6311. //+-------------------------------------------------------------------------
  6312. // Access State flags returned by CERT_ACCESS_STATE_PROP_ID. Note,
  6313. // CERT_ACCESS_PROP_ID is read only.
  6314. //--------------------------------------------------------------------------
  6315. // Set if context property writes are persisted. For instance, not set for
  6316. // memory store contexts. Set for registry based stores opened as read or write.
  6317. // Not set for registry based stores opened as read only.
  6318. #define CERT_ACCESS_STATE_WRITE_PERSIST_FLAG 0x1
  6319. // Set if context resides in a SYSTEM or SYSTEM_REGISTRY store.
  6320. #define CERT_ACCESS_STATE_SYSTEM_STORE_FLAG 0x2
  6321. // Set if context resides in a LocalMachine SYSTEM or SYSTEM_REGISTRY store.
  6322. #define CERT_ACCESS_STATE_LM_SYSTEM_STORE_FLAG 0x4
  6323. //+-------------------------------------------------------------------------
  6324. // Cryptographic Key Provider Information
  6325. //
  6326. // CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  6327. //
  6328. // The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  6329. // to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  6330. // passed to CryptSetProvParam to further initialize the provider.
  6331. //
  6332. // The dwKeySpec field identifies the private key to use from the container
  6333. // For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  6334. //--------------------------------------------------------------------------
  6335. typedef struct _CRYPT_KEY_PROV_PARAM {
  6336. DWORD dwParam;
  6337. BYTE *pbData;
  6338. DWORD cbData;
  6339. DWORD dwFlags;
  6340. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  6341. typedef struct _CRYPT_KEY_PROV_INFO {
  6342. LPWSTR pwszContainerName;
  6343. LPWSTR pwszProvName;
  6344. DWORD dwProvType;
  6345. DWORD dwFlags;
  6346. DWORD cProvParam;
  6347. PCRYPT_KEY_PROV_PARAM rgProvParam;
  6348. DWORD dwKeySpec;
  6349. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  6350. //+-------------------------------------------------------------------------
  6351. // The following flag should be set in the above dwFlags to enable
  6352. // a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  6353. // CryptAcquireContext is done in the Sign or Decrypt Message functions.
  6354. //
  6355. // The following define must not collide with any of the
  6356. // CryptAcquireContext dwFlag defines.
  6357. //--------------------------------------------------------------------------
  6358. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID 0x00000001
  6359. #define CERT_SET_KEY_CONTEXT_PROP_ID 0x00000001
  6360. //+-------------------------------------------------------------------------
  6361. // Certificate Key Context
  6362. //
  6363. // CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  6364. //--------------------------------------------------------------------------
  6365. typedef struct _CERT_KEY_CONTEXT {
  6366. DWORD cbSize; // sizeof(CERT_KEY_CONTEXT)
  6367. HCRYPTPROV hCryptProv;
  6368. DWORD dwKeySpec;
  6369. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  6370. //+-------------------------------------------------------------------------
  6371. // Certificate Store Provider Types
  6372. //--------------------------------------------------------------------------
  6373. #define CERT_STORE_PROV_MSG ((LPCSTR) 1)
  6374. #define CERT_STORE_PROV_MEMORY ((LPCSTR) 2)
  6375. #define CERT_STORE_PROV_FILE ((LPCSTR) 3)
  6376. #define CERT_STORE_PROV_REG ((LPCSTR) 4)
  6377. #define CERT_STORE_PROV_PKCS7 ((LPCSTR) 5)
  6378. #define CERT_STORE_PROV_SERIALIZED ((LPCSTR) 6)
  6379. #define CERT_STORE_PROV_FILENAME_A ((LPCSTR) 7)
  6380. #define CERT_STORE_PROV_FILENAME_W ((LPCSTR) 8)
  6381. #define CERT_STORE_PROV_FILENAME CERT_STORE_PROV_FILENAME_W
  6382. #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR) 9)
  6383. #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR) 10)
  6384. #define CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
  6385. #define CERT_STORE_PROV_COLLECTION ((LPCSTR) 11)
  6386. #define CERT_STORE_PROV_SYSTEM_REGISTRY_A ((LPCSTR) 12)
  6387. #define CERT_STORE_PROV_SYSTEM_REGISTRY_W ((LPCSTR) 13)
  6388. #define CERT_STORE_PROV_SYSTEM_REGISTRY CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6389. #define CERT_STORE_PROV_PHYSICAL_W ((LPCSTR) 14)
  6390. #define CERT_STORE_PROV_PHYSICAL CERT_STORE_PROV_PHYSICAL_W
  6391. #define CERT_STORE_PROV_SMART_CARD_W ((LPCSTR) 15)
  6392. #define CERT_STORE_PROV_SMART_CARD CERT_STORE_PROV_SMART_CARD_W
  6393. #define CERT_STORE_PROV_LDAP_W ((LPCSTR) 16)
  6394. #define CERT_STORE_PROV_LDAP CERT_STORE_PROV_LDAP_W
  6395. #define sz_CERT_STORE_PROV_MEMORY "Memory"
  6396. #define sz_CERT_STORE_PROV_FILENAME_W "File"
  6397. #define sz_CERT_STORE_PROV_FILENAME sz_CERT_STORE_PROV_FILENAME_W
  6398. #define sz_CERT_STORE_PROV_SYSTEM_W "System"
  6399. #define sz_CERT_STORE_PROV_SYSTEM sz_CERT_STORE_PROV_SYSTEM_W
  6400. #define sz_CERT_STORE_PROV_PKCS7 "PKCS7"
  6401. #define sz_CERT_STORE_PROV_SERIALIZED "Serialized"
  6402. #define sz_CERT_STORE_PROV_COLLECTION "Collection"
  6403. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W "SystemRegistry"
  6404. #define sz_CERT_STORE_PROV_SYSTEM_REGISTRY sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6405. #define sz_CERT_STORE_PROV_PHYSICAL_W "Physical"
  6406. #define sz_CERT_STORE_PROV_PHYSICAL sz_CERT_STORE_PROV_PHYSICAL_W
  6407. #define sz_CERT_STORE_PROV_SMART_CARD_W "SmartCard"
  6408. #define sz_CERT_STORE_PROV_SMART_CARD sz_CERT_STORE_PROV_SMART_CARD_W
  6409. #define sz_CERT_STORE_PROV_LDAP_W "Ldap"
  6410. #define sz_CERT_STORE_PROV_LDAP sz_CERT_STORE_PROV_LDAP_W
  6411. //+-------------------------------------------------------------------------
  6412. // Certificate Store verify/results flags
  6413. //--------------------------------------------------------------------------
  6414. #define CERT_STORE_SIGNATURE_FLAG 0x00000001
  6415. #define CERT_STORE_TIME_VALIDITY_FLAG 0x00000002
  6416. #define CERT_STORE_REVOCATION_FLAG 0x00000004
  6417. #define CERT_STORE_NO_CRL_FLAG 0x00010000
  6418. #define CERT_STORE_NO_ISSUER_FLAG 0x00020000
  6419. #define CERT_STORE_BASE_CRL_FLAG 0x00000100
  6420. #define CERT_STORE_DELTA_CRL_FLAG 0x00000200
  6421. //+-------------------------------------------------------------------------
  6422. // Certificate Store open/property flags
  6423. //--------------------------------------------------------------------------
  6424. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG 0x00000001
  6425. #define CERT_STORE_SET_LOCALIZED_NAME_FLAG 0x00000002
  6426. #define CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG 0x00000004
  6427. #define CERT_STORE_DELETE_FLAG 0x00000010
  6428. #define CERT_STORE_UNSAFE_PHYSICAL_FLAG 0x00000020
  6429. #define CERT_STORE_SHARE_STORE_FLAG 0x00000040
  6430. #define CERT_STORE_SHARE_CONTEXT_FLAG 0x00000080
  6431. #define CERT_STORE_MANIFOLD_FLAG 0x00000100
  6432. #define CERT_STORE_ENUM_ARCHIVED_FLAG 0x00000200
  6433. #define CERT_STORE_UPDATE_KEYID_FLAG 0x00000400
  6434. #define CERT_STORE_BACKUP_RESTORE_FLAG 0x00000800
  6435. #define CERT_STORE_READONLY_FLAG 0x00008000
  6436. #define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
  6437. #define CERT_STORE_CREATE_NEW_FLAG 0x00002000
  6438. #define CERT_STORE_MAXIMUM_ALLOWED_FLAG 0x00001000
  6439. //+-------------------------------------------------------------------------
  6440. // Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  6441. //--------------------------------------------------------------------------
  6442. //+-------------------------------------------------------------------------
  6443. // Certificate System Store Flag Values
  6444. //--------------------------------------------------------------------------
  6445. // Includes flags and location
  6446. #define CERT_SYSTEM_STORE_MASK 0xFFFF0000
  6447. // Set if pvPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA structure
  6448. #define CERT_SYSTEM_STORE_RELOCATE_FLAG 0x80000000
  6449. typedef struct _CERT_SYSTEM_STORE_RELOCATE_PARA {
  6450. union {
  6451. HKEY hKeyBase;
  6452. void *pvBase;
  6453. };
  6454. union {
  6455. void *pvSystemStore;
  6456. LPCSTR pszSystemStore;
  6457. LPCWSTR pwszSystemStore;
  6458. };
  6459. } CERT_SYSTEM_STORE_RELOCATE_PARA, *PCERT_SYSTEM_STORE_RELOCATE_PARA;
  6460. // By default, when the CurrentUser "Root" store is opened, any SystemRegistry
  6461. // roots not also on the protected root list are deleted from the cache before
  6462. // CertOpenStore() returns. Set the following flag to return all the roots
  6463. // in the SystemRegistry without checking the protected root list.
  6464. #define CERT_SYSTEM_STORE_UNPROTECTED_FLAG 0x40000000
  6465. // Location of the system store:
  6466. #define CERT_SYSTEM_STORE_LOCATION_MASK 0x00FF0000
  6467. #define CERT_SYSTEM_STORE_LOCATION_SHIFT 16
  6468. // Registry: HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  6469. #define CERT_SYSTEM_STORE_CURRENT_USER_ID 1
  6470. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ID 2
  6471. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Services
  6472. #define CERT_SYSTEM_STORE_CURRENT_SERVICE_ID 4
  6473. #define CERT_SYSTEM_STORE_SERVICES_ID 5
  6474. // Registry: HKEY_USERS
  6475. #define CERT_SYSTEM_STORE_USERS_ID 6
  6476. // Registry: HKEY_CURRENT_USER\Software\Policies\Microsoft\SystemCertificates
  6477. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID 7
  6478. // Registry: HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates
  6479. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID 8
  6480. // Registry: HKEY_LOCAL_MACHINE\Software\Microsoft\EnterpriseCertificates
  6481. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID 9
  6482. #define CERT_SYSTEM_STORE_CURRENT_USER \
  6483. (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6484. #define CERT_SYSTEM_STORE_LOCAL_MACHINE \
  6485. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6486. #define CERT_SYSTEM_STORE_CURRENT_SERVICE \
  6487. (CERT_SYSTEM_STORE_CURRENT_SERVICE_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6488. #define CERT_SYSTEM_STORE_SERVICES \
  6489. (CERT_SYSTEM_STORE_SERVICES_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6490. #define CERT_SYSTEM_STORE_USERS \
  6491. (CERT_SYSTEM_STORE_USERS_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6492. #define CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY \
  6493. (CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID << \
  6494. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6495. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY \
  6496. (CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID << \
  6497. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6498. #define CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE \
  6499. (CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID << \
  6500. CERT_SYSTEM_STORE_LOCATION_SHIFT)
  6501. //+-------------------------------------------------------------------------
  6502. // Group Policy Store Defines
  6503. //--------------------------------------------------------------------------
  6504. // Registry path to the Group Policy system stores
  6505. #define CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH \
  6506. L"Software\\Policies\\Microsoft\\SystemCertificates"
  6507. //+-------------------------------------------------------------------------
  6508. // EFS Defines
  6509. //--------------------------------------------------------------------------
  6510. // Registry path to the EFS EFSBlob SubKey - Value type is REG_BINARY
  6511. #define CERT_EFSBLOB_REGPATH \
  6512. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\EFS"
  6513. #define CERT_EFSBLOB_VALUE_NAME L"EFSBlob"
  6514. //+-------------------------------------------------------------------------
  6515. // Protected Root Defines
  6516. //--------------------------------------------------------------------------
  6517. // Registry path to the Protected Roots Flags SubKey
  6518. #define CERT_PROT_ROOT_FLAGS_REGPATH \
  6519. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\Root\\ProtectedRoots"
  6520. #define CERT_PROT_ROOT_FLAGS_VALUE_NAME L"Flags"
  6521. // Set the following flag to inhibit the opening of the CurrentUser's
  6522. // .Default physical store when opening the CurrentUser's "Root" system store.
  6523. // The .Default physical store open's the CurrentUser SystemRegistry "Root"
  6524. // store.
  6525. #define CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG 0x1
  6526. // Set the following flag to inhibit the adding of roots from the
  6527. // CurrentUser SystemRegistry "Root" store to the protected root list
  6528. // when the "Root" store is initially protected.
  6529. #define CERT_PROT_ROOT_INHIBIT_ADD_AT_INIT_FLAG 0x2
  6530. // Set the following flag to inhibit the purging of protected roots from the
  6531. // CurrentUser SystemRegistry "Root" store that are
  6532. // also in the LocalMachine SystemRegistry "Root" store. Note, when not
  6533. // disabled, the purging is done silently without UI.
  6534. #define CERT_PROT_ROOT_INHIBIT_PURGE_LM_FLAG 0x4
  6535. // Set the following flag to inhibit the opening of the LocalMachine's
  6536. // .AuthRoot physical store when opening the LocalMachine's "Root" system store.
  6537. // The .AuthRoot physical store open's the LocalMachine SystemRegistry
  6538. // "AuthRoot" store. The "AuthRoot" store contains the pre-installed
  6539. // SSL ServerAuth and the ActiveX Authenticode "root" certificates.
  6540. #define CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG 0x8
  6541. // The semantics for the following legacy definition has been changed to be
  6542. // the same as for the CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG.
  6543. #define CERT_PROT_ROOT_ONLY_LM_GPT_FLAG 0x8
  6544. // Set the following flag to disable the requiring of the issuing CA
  6545. // certificate being in the "NTAuth" system registry store found in the
  6546. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  6547. //
  6548. // When set, CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_NT_AUTH)
  6549. // will check that the chain has a valid name constraint for all name
  6550. // spaces, including UPN if the issuing CA isn't in the "NTAuth" store.
  6551. #define CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG 0x10
  6552. // Set the following flag to disable checking for not defined name
  6553. // constraints.
  6554. //
  6555. // When set, CertGetCertificateChain won't check for or set the following
  6556. // dwErrorStatus: CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT.
  6557. #define CERT_PROT_ROOT_DISABLE_NOT_DEFINED_NAME_CONSTRAINT_FLAG 0x20
  6558. //+-------------------------------------------------------------------------
  6559. // Trusted Publisher Definitions
  6560. //--------------------------------------------------------------------------
  6561. // Registry path to the trusted publisher "Safer" group policy subkey
  6562. #define CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH \
  6563. CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6564. // Registry path to the Local Machine system stores
  6565. #define CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH \
  6566. L"Software\\Microsoft\\SystemCertificates"
  6567. // Registry path to the trusted publisher "Safer" local machine subkey
  6568. #define CERT_TRUST_PUB_SAFER_LOCAL_MACHINE_REGPATH \
  6569. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\TrustedPublisher\\Safer"
  6570. // "Safer" subkey value names. All values are DWORDs.
  6571. #define CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME L"AuthenticodeFlags"
  6572. // AuthenticodeFlags definitions
  6573. // Definition of who is allowed to trust publishers
  6574. //
  6575. // Setting allowed trust to MACHINE_ADMIN or ENTERPRISE_ADMIN disables UI,
  6576. // only trusts publishers in the "TrustedPublisher" system store and
  6577. // inhibits the opening of the CurrentUser's .Default physical store when
  6578. // opening the CurrentUsers's "TrustedPublisher" system store.
  6579. //
  6580. // The .Default physical store open's the CurrentUser SystemRegistry
  6581. // "TrustedPublisher" store.
  6582. //
  6583. // Setting allowed trust to ENTERPRISE_ADMIN only opens the
  6584. // LocalMachine's .GroupPolicy and .Enterprise physical stores when opening
  6585. // the CurrentUser's "TrustedPublisher" system store or when opening the
  6586. // LocalMachine's "TrustedPublisher" system store.
  6587. #define CERT_TRUST_PUB_ALLOW_TRUST_MASK 0x00000003
  6588. #define CERT_TRUST_PUB_ALLOW_END_USER_TRUST 0x00000000
  6589. #define CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST 0x00000001
  6590. #define CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST 0x00000002
  6591. // Set the following flag to enable revocation checking of the publisher
  6592. // chain.
  6593. #define CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG 0x00000100
  6594. // Set the following flag to enable revocation checking of the time stamp
  6595. // chain.
  6596. #define CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG 0x00000200
  6597. //+-------------------------------------------------------------------------
  6598. // OCM Subcomponents Definitions
  6599. //--------------------------------------------------------------------------
  6600. // Registry path to the OCM Subcomponents local machine subkey
  6601. #define CERT_OCM_SUBCOMPONENTS_LOCAL_MACHINE_REGPATH \
  6602. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OC Manager\\Subcomponents"
  6603. // REG_DWORD, 1 is installed, 0 is NOT installed
  6604. #define CERT_OCM_SUBCOMPONENTS_ROOT_AUTO_UPDATE_VALUE_NAME L"RootAutoUpdate"
  6605. //+-------------------------------------------------------------------------
  6606. // AuthRoot Auto Update Definitions
  6607. //--------------------------------------------------------------------------
  6608. // Registry path to the AuthRoot "Auto Update" local machine subkey
  6609. #define CERT_AUTH_ROOT_AUTO_UPDATE_LOCAL_MACHINE_REGPATH \
  6610. CERT_LOCAL_MACHINE_SYSTEM_STORE_REGPATH L"\\AuthRoot\\AutoUpdate"
  6611. // AuthRoot Auto Update subkey value names.
  6612. // REG_SZ, URL to the directory containing the AuthRoots, CTL and Seq files
  6613. #define CERT_AUTH_ROOT_AUTO_UPDATE_ROOT_DIR_URL_VALUE_NAME L"RootDirUrl"
  6614. // REG_DWORD, seconds between syncs. 0 implies use default.
  6615. #define CERT_AUTH_ROOT_AUTO_UPDATE_SYNC_DELTA_TIME_VALUE_NAME L"SyncDeltaTime"
  6616. // REG_DWORD, misc flags
  6617. #define CERT_AUTH_ROOT_AUTO_UPDATE_FLAGS_VALUE_NAME L"Flags"
  6618. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_UNTRUSTED_ROOT_LOGGING_FLAG 0x1
  6619. #define CERT_AUTH_ROOT_AUTO_UPDATE_DISABLE_PARTIAL_CHAIN_LOGGING_FLAG 0x2
  6620. // AuthRoot Auto Update filenames
  6621. // CTL containing the list of certs in the AuthRoot store
  6622. #define CERT_AUTH_ROOT_CTL_FILENAME L"authroot.stl"
  6623. #define CERT_AUTH_ROOT_CTL_FILENAME_A "authroot.stl"
  6624. // Cab containing the above CTL
  6625. #define CERT_AUTH_ROOT_CAB_FILENAME L"authrootstl.cab"
  6626. // SequenceNumber (Formatted as big endian ascii hex)
  6627. #define CERT_AUTH_ROOT_SEQ_FILENAME L"authrootseq.txt"
  6628. // Root certs extension
  6629. #define CERT_AUTH_ROOT_CERT_EXT L".crt"
  6630. //+-------------------------------------------------------------------------
  6631. // Certificate Registry Store Flag Values (CERT_STORE_REG)
  6632. //--------------------------------------------------------------------------
  6633. // Set this flag if the HKEY passed in pvPara points to a remote computer
  6634. // registry key.
  6635. #define CERT_REGISTRY_STORE_REMOTE_FLAG 0x10000
  6636. // Set this flag if the contexts are to be persisted as a single serialized
  6637. // store in the registry. Mainly used for stores downloaded from the GPT.
  6638. // Such as the CurrentUserGroupPolicy or LocalMachineGroupPolicy stores.
  6639. #define CERT_REGISTRY_STORE_SERIALIZED_FLAG 0x20000
  6640. // The following flags are for internal use. When set, the
  6641. // pvPara parameter passed to CertOpenStore is a pointer to the following
  6642. // data structure and not the HKEY. The above CERT_REGISTRY_STORE_REMOTE_FLAG
  6643. // is also set if hKeyBase was obtained via RegConnectRegistry().
  6644. #define CERT_REGISTRY_STORE_CLIENT_GPT_FLAG 0x80000000
  6645. #define CERT_REGISTRY_STORE_LM_GPT_FLAG 0x01000000
  6646. typedef struct _CERT_REGISTRY_STORE_CLIENT_GPT_PARA {
  6647. HKEY hKeyBase;
  6648. LPWSTR pwszRegPath;
  6649. } CERT_REGISTRY_STORE_CLIENT_GPT_PARA, *PCERT_REGISTRY_STORE_CLIENT_GPT_PARA;
  6650. // The following flag is for internal use. When set, the contexts are
  6651. // persisted into roaming files instead of the registry. Such as, the
  6652. // CurrentUser "My" store. When this flag is set, the following data structure
  6653. // is passed to CertOpenStore instead of HKEY.
  6654. #define CERT_REGISTRY_STORE_ROAMING_FLAG 0x40000
  6655. // hKey may be NULL or non-NULL. When non-NULL, existing contexts are
  6656. // moved from the registry to roaming files.
  6657. typedef struct _CERT_REGISTRY_STORE_ROAMING_PARA {
  6658. HKEY hKey;
  6659. LPWSTR pwszStoreDirectory;
  6660. } CERT_REGISTRY_STORE_ROAMING_PARA, *PCERT_REGISTRY_STORE_ROAMING_PARA;
  6661. // The following flag is for internal use. When set, the "My" DWORD value
  6662. // at HKLM\Software\Microsoft\Cryptography\IEDirtyFlags is set to 0x1
  6663. // whenever a certificate is added to the registry store.
  6664. //
  6665. // Legacy definition, no longer supported after 01-May-02 (.Net Server)
  6666. #define CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG 0x80000
  6667. // Registry path to the subkey containing the "My" DWORD value to be set
  6668. //
  6669. // Legacy definition, no longer supported after 01-May-02 (.Net Server)
  6670. #define CERT_IE_DIRTY_FLAGS_REGPATH \
  6671. L"Software\\Microsoft\\Cryptography\\IEDirtyFlags"
  6672. //+-------------------------------------------------------------------------
  6673. // Certificate File Store Flag Values for the providers:
  6674. // CERT_STORE_PROV_FILE
  6675. // CERT_STORE_PROV_FILENAME
  6676. // CERT_STORE_PROV_FILENAME_A
  6677. // CERT_STORE_PROV_FILENAME_W
  6678. // sz_CERT_STORE_PROV_FILENAME_W
  6679. //--------------------------------------------------------------------------
  6680. // Set this flag if any store changes are to be committed to the file.
  6681. // The changes are committed at CertCloseStore or by calling
  6682. // CertControlStore(CERT_STORE_CTRL_COMMIT).
  6683. //
  6684. // The open fails with E_INVALIDARG if both CERT_FILE_STORE_COMMIT_ENABLE_FLAG
  6685. // and CERT_STORE_READONLY_FLAG are set in dwFlags.
  6686. //
  6687. // For the FILENAME providers: if the file contains an X509 encoded
  6688. // certificate, the open fails with ERROR_ACCESS_DENIED.
  6689. //
  6690. // For the FILENAME providers: if CERT_STORE_CREATE_NEW_FLAG is set, the
  6691. // CreateFile uses CREATE_NEW. If CERT_STORE_OPEN_EXISTING is set, uses
  6692. // OPEN_EXISTING. Otherwise, defaults to OPEN_ALWAYS.
  6693. //
  6694. // For the FILENAME providers: the file is committed as either a PKCS7 or
  6695. // serialized store depending on the type read at open. However, if the
  6696. // file is empty then, if the filename has either a ".p7c" or ".spc"
  6697. // extension its committed as a PKCS7. Otherwise, its committed as a
  6698. // serialized store.
  6699. //
  6700. // For CERT_STORE_PROV_FILE, the file handle is duplicated. Its always
  6701. // committed as a serialized store.
  6702. //
  6703. #define CERT_FILE_STORE_COMMIT_ENABLE_FLAG 0x10000
  6704. //+-------------------------------------------------------------------------
  6705. // Certificate LDAP Store Flag Values for the providers:
  6706. // CERT_STORE_PROV_LDAP
  6707. // CERT_STORE_PROV_LDAP_W
  6708. // sz_CERT_STORE_PROV_LDAP_W
  6709. // sz_CERT_STORE_PROV_LDAP
  6710. //--------------------------------------------------------------------------
  6711. // Set this flag to digitally sign all of the ldap traffic to and from a
  6712. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  6713. // This feature provides integrity required by some applications.
  6714. //
  6715. #define CERT_LDAP_STORE_SIGN_FLAG 0x10000
  6716. // Performs an A-Record only DNS lookup on the supplied host string.
  6717. // This prevents bogus DNS queries from being generated when resolving host
  6718. // names. Use this flag whenever passing a hostname as opposed to a
  6719. // domain name for the hostname parameter.
  6720. //
  6721. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  6722. #define CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG 0x20000
  6723. // Set this flag if the LDAP session handle has already been opened. When
  6724. // set, pvPara points to the following CERT_LDAP_STORE_OPENED_PARA structure.
  6725. #define CERT_LDAP_STORE_OPENED_FLAG 0x40000
  6726. typedef struct _CERT_LDAP_STORE_OPENED_PARA {
  6727. void *pvLdapSessionHandle; // The (LDAP *) handle returned by
  6728. // ldap_init
  6729. LPCWSTR pwszLdapUrl;
  6730. } CERT_LDAP_STORE_OPENED_PARA, *PCERT_LDAP_STORE_OPENED_PARA;
  6731. // Set this flag if the above CERT_LDAP_STORE_OPENED_FLAG is set and
  6732. // you want an ldap_unbind() of the above pvLdapSessionHandle when the
  6733. // store is closed. Note, if CertOpenStore() fails, then, ldap_unbind()
  6734. // isn't called.
  6735. #define CERT_LDAP_STORE_UNBIND_FLAG 0x80000
  6736. //+-------------------------------------------------------------------------
  6737. // Open the cert store using the specified store provider.
  6738. //
  6739. // If CERT_STORE_DELETE_FLAG is set, then, the store is deleted. NULL is
  6740. // returned for both success and failure. However, GetLastError() returns 0
  6741. // for success and nonzero for failure.
  6742. //
  6743. // If CERT_STORE_SET_LOCALIZED_NAME_FLAG is set, then, if supported, the
  6744. // provider sets the store's CERT_STORE_LOCALIZED_NAME_PROP_ID property.
  6745. // The store's localized name can be retrieved by calling
  6746. // CertSetStoreProperty(dwPropID = CERT_STORE_LOCALIZED_NAME_PROP_ID).
  6747. // This flag is supported by the following providers (and their sz_
  6748. // equivalent):
  6749. // CERT_STORE_PROV_FILENAME_A
  6750. // CERT_STORE_PROV_FILENAME_W
  6751. // CERT_STORE_PROV_SYSTEM_A
  6752. // CERT_STORE_PROV_SYSTEM_W
  6753. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6754. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6755. // CERT_STORE_PROV_PHYSICAL_W
  6756. //
  6757. // If CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG is set, then, the
  6758. // closing of the store's provider is deferred until all certificate,
  6759. // CRL and CTL contexts obtained from the store are freed. Also,
  6760. // if a non NULL HCRYPTPROV was passed, then, it will continue to be used.
  6761. // By default, the store's provider is closed on the final CertCloseStore.
  6762. // If this flag isn't set, then, any property changes made to previously
  6763. // duplicated contexts after the final CertCloseStore will not be persisted.
  6764. // By setting this flag, property changes made
  6765. // after the CertCloseStore will be persisted. Note, setting this flag
  6766. // causes extra overhead in doing context duplicates and frees.
  6767. // If CertCloseStore is called with CERT_CLOSE_STORE_FORCE_FLAG, then,
  6768. // the CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG flag is ignored.
  6769. //
  6770. // CERT_STORE_MANIFOLD_FLAG can be set to check for certificates having the
  6771. // manifold extension and archive the "older" certificates with the same
  6772. // manifold extension value. A certificate is archived by setting the
  6773. // CERT_ARCHIVED_PROP_ID.
  6774. //
  6775. // By default, contexts having the CERT_ARCHIVED_PROP_ID, are skipped
  6776. // during enumeration. CERT_STORE_ENUM_ARCHIVED_FLAG can be set to include
  6777. // archived contexts when enumerating. Note, contexts having the
  6778. // CERT_ARCHIVED_PROP_ID are still found for explicit finds, such as,
  6779. // finding a context with a specific hash or finding a certificate having
  6780. // a specific issuer and serial number.
  6781. //
  6782. // CERT_STORE_UPDATE_KEYID_FLAG can be set to also update the Key Identifier's
  6783. // CERT_KEY_PROV_INFO_PROP_ID property whenever a certificate's
  6784. // CERT_KEY_IDENTIFIER_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID property is set
  6785. // and the other property already exists. If the Key Identifier's
  6786. // CERT_KEY_PROV_INFO_PROP_ID already exists, it isn't updated. Any
  6787. // errors encountered are silently ignored.
  6788. //
  6789. // By default, this flag is implicitly set for the "My\.Default" CurrentUser
  6790. // and LocalMachine physical stores.
  6791. //
  6792. // CERT_STORE_READONLY_FLAG can be set to open the store as read only.
  6793. // Otherwise, the store is opened as read/write.
  6794. //
  6795. // CERT_STORE_OPEN_EXISTING_FLAG can be set to only open an existing
  6796. // store. CERT_STORE_CREATE_NEW_FLAG can be set to create a new store and
  6797. // fail if the store already exists. Otherwise, the default is to open
  6798. // an existing store or create a new store if it doesn't already exist.
  6799. //
  6800. // hCryptProv specifies the crypto provider to use to create the hash
  6801. // properties or verify the signature of a subject certificate or CRL.
  6802. // The store doesn't need to use a private
  6803. // key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  6804. // CryptReleaseContext'ed on the final CertCloseStore.
  6805. //
  6806. // Note, if the open fails, hCryptProv is released if it would have been
  6807. // released when the store was closed.
  6808. //
  6809. // If hCryptProv is zero, then, the default provider and container for the
  6810. // PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  6811. // CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  6812. // the first create hash or verify signature. In addition, once acquired,
  6813. // the default provider isn't released until process exit when crypt32.dll
  6814. // is unloaded. The acquired default provider is shared across all stores
  6815. // and threads.
  6816. //
  6817. // After initializing the store's data structures and optionally acquiring a
  6818. // default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  6819. // get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  6820. // lpszStoreProvider. Since a store can contain certificates with different
  6821. // encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  6822. // set to 0 and not the dwEncodingType passed to CertOpenStore.
  6823. // PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  6824. // open function. This provider open function is called to load the
  6825. // store's certificates and CRLs. Optionally, the provider may return an
  6826. // array of functions called before a certificate or CRL is added or deleted
  6827. // or has a property that is set.
  6828. //
  6829. // Use of the dwEncodingType parameter is provider dependent. The type
  6830. // definition for pvPara also depends on the provider.
  6831. //
  6832. // Store providers are installed or registered via
  6833. // CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  6834. // dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  6835. //
  6836. // Here's a list of the predefined provider types (implemented in crypt32.dll):
  6837. //
  6838. // CERT_STORE_PROV_MSG:
  6839. // Gets the certificates and CRLs from the specified cryptographic message.
  6840. // dwEncodingType contains the message and certificate encoding types.
  6841. // The message's handle is passed in pvPara. Given,
  6842. // HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  6843. //
  6844. // CERT_STORE_PROV_MEMORY
  6845. // sz_CERT_STORE_PROV_MEMORY:
  6846. // Opens a store without any initial certificates or CRLs. pvPara
  6847. // isn't used.
  6848. //
  6849. // CERT_STORE_PROV_FILE:
  6850. // Reads the certificates and CRLs from the specified file. The file's
  6851. // handle is passed in pvPara. Given,
  6852. // HANDLE hFile; pvPara = (const void *) hFile;
  6853. //
  6854. // For a successful open, the file pointer is advanced past
  6855. // the certificates and CRLs and their properties read from the file.
  6856. // Note, only expects a serialized store and not a file containing
  6857. // either a PKCS #7 signed message or a single encoded certificate.
  6858. //
  6859. // The hFile isn't closed.
  6860. //
  6861. // CERT_STORE_PROV_REG:
  6862. // Reads the certificates and CRLs from the registry. The registry's
  6863. // key handle is passed in pvPara. Given,
  6864. // HKEY hKey; pvPara = (const void *) hKey;
  6865. //
  6866. // The input hKey isn't closed by the provider. Before returning, the
  6867. // provider opens it own copy of the hKey.
  6868. //
  6869. // If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  6870. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  6871. // are RegCreateKey'ed with KEY_ALL_ACCESS.
  6872. //
  6873. // This provider returns the array of functions for reading, writing,
  6874. // deleting and property setting certificates and CRLs.
  6875. // Any changes to the opened store are immediately pushed through to
  6876. // the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  6877. // writing, deleting or property setting results in a
  6878. // SetLastError(E_ACCESSDENIED).
  6879. //
  6880. // Note, all the certificates and CRLs are read from the registry
  6881. // when the store is opened. The opened store serves as a write through
  6882. // cache.
  6883. //
  6884. // If CERT_REGISTRY_STORE_SERIALIZED_FLAG is set, then, the
  6885. // contexts are persisted as a single serialized store subkey in the
  6886. // registry.
  6887. //
  6888. // CERT_STORE_PROV_PKCS7:
  6889. // sz_CERT_STORE_PROV_PKCS7:
  6890. // Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  6891. // dwEncodingType specifies the message and certificate encoding types.
  6892. // The pointer to the encoded message's blob is passed in pvPara. Given,
  6893. // CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  6894. //
  6895. // Note, also supports the IE3.0 special version of a
  6896. // PKCS #7 signed message referred to as a "SPC" formatted message.
  6897. //
  6898. // CERT_STORE_PROV_SERIALIZED:
  6899. // sz_CERT_STORE_PROV_SERIALIZED:
  6900. // Gets the certificates and CRLs from memory containing a serialized
  6901. // store. The pointer to the serialized memory blob is passed in pvPara.
  6902. // Given,
  6903. // CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  6904. //
  6905. // CERT_STORE_PROV_FILENAME_A:
  6906. // CERT_STORE_PROV_FILENAME_W:
  6907. // CERT_STORE_PROV_FILENAME:
  6908. // sz_CERT_STORE_PROV_FILENAME_W:
  6909. // sz_CERT_STORE_PROV_FILENAME:
  6910. // Opens the file and first attempts to read as a serialized store. Then,
  6911. // as a PKCS #7 signed message. Finally, as a single encoded certificate.
  6912. // The filename is passed in pvPara. The filename is UNICODE for the
  6913. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6914. // LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  6915. // For "_A": given,
  6916. // LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  6917. //
  6918. // Note, the default (without "_A" or "_W") is unicode.
  6919. //
  6920. // Note, also supports the reading of the IE3.0 special version of a
  6921. // PKCS #7 signed message file referred to as a "SPC" formatted file.
  6922. //
  6923. // CERT_STORE_PROV_SYSTEM_A:
  6924. // CERT_STORE_PROV_SYSTEM_W:
  6925. // CERT_STORE_PROV_SYSTEM:
  6926. // sz_CERT_STORE_PROV_SYSTEM_W:
  6927. // sz_CERT_STORE_PROV_SYSTEM:
  6928. // Opens the specified logical "System" store. The upper word of the
  6929. // dwFlags parameter is used to specify the location of the system store.
  6930. //
  6931. // A "System" store is a collection consisting of one or more "Physical"
  6932. // stores. A "Physical" store is registered via the
  6933. // CertRegisterPhysicalStore API. Each of the registered physical stores
  6934. // is CertStoreOpen'ed and added to the collection via
  6935. // CertAddStoreToCollection.
  6936. //
  6937. // The CERT_SYSTEM_STORE_CURRENT_USER, CERT_SYSTEM_STORE_LOCAL_MACHINE,
  6938. // CERT_SYSTEM_STORE_CURRENT_SERVICE, CERT_SYSTEM_STORE_SERVICES,
  6939. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY,
  6940. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY and
  6941. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRSE
  6942. // system stores by default have a "SystemRegistry" store that is
  6943. // opened and added to the collection.
  6944. //
  6945. // The system store name is passed in pvPara. The name is UNICODE for the
  6946. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  6947. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  6948. // For "_A": given,
  6949. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  6950. //
  6951. // Note, the default (without "_A" or "_W") is UNICODE.
  6952. //
  6953. // The system store name can't contain any backslashes.
  6954. //
  6955. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  6956. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  6957. // of pointing to a null terminated UNICODE or ASCII string.
  6958. // Sibling physical stores are also opened as relocated using
  6959. // pvPara's hKeyBase.
  6960. //
  6961. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system
  6962. // store name must be prefixed with the ServiceName or UserName.
  6963. // For example, "ServiceName\Trust".
  6964. //
  6965. // Stores on remote computers can be accessed for the
  6966. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  6967. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  6968. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  6969. // locations by prepending the computer name. For example, a remote
  6970. // local machine store is accessed via "\\ComputerName\Trust" or
  6971. // "ComputerName\Trust". A remote service store is accessed via
  6972. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  6973. // optional in the ComputerName.
  6974. //
  6975. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  6976. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  6977. // RegCreateKey'ed with KEY_ALL_ACCESS.
  6978. //
  6979. // The "root" store is treated differently from the other system
  6980. // stores. Before a certificate is added to or deleted from the "root"
  6981. // store, a pop up message box is displayed. The certificate's subject,
  6982. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  6983. // displayed. The user is given the option to do the add or delete.
  6984. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  6985. //
  6986. // CERT_STORE_PROV_SYSTEM_REGISTRY_A
  6987. // CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6988. // CERT_STORE_PROV_SYSTEM_REGISTRY
  6989. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY_W
  6990. // sz_CERT_STORE_PROV_SYSTEM_REGISTRY
  6991. // Opens the "System" store's default "Physical" store residing in the
  6992. // registry. The upper word of the dwFlags
  6993. // parameter is used to specify the location of the system store.
  6994. //
  6995. // After opening the registry key associated with the system name,
  6996. // the CERT_STORE_PROV_REG provider is called to complete the open.
  6997. //
  6998. // The system store name is passed in pvPara. The name is UNICODE for the
  6999. // "_W" provider and ASCII for the "_A" provider. For "_W": given,
  7000. // LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  7001. // For "_A": given,
  7002. // LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  7003. //
  7004. // Note, the default (without "_A" or "_W") is UNICODE.
  7005. //
  7006. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  7007. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  7008. // of pointing to a null terminated UNICODE or ASCII string.
  7009. //
  7010. // See above for details on prepending a ServiceName and/or ComputerName
  7011. // to the store name.
  7012. //
  7013. // If CERT_STORE_READONLY_FLAG is set, then, the registry is
  7014. // RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  7015. // RegCreateKey'ed with KEY_ALL_ACCESS.
  7016. //
  7017. // The "root" store is treated differently from the other system
  7018. // stores. Before a certificate is added to or deleted from the "root"
  7019. // store, a pop up message box is displayed. The certificate's subject,
  7020. // issuer, serial number, time validity, sha1 and md5 thumbprints are
  7021. // displayed. The user is given the option to do the add or delete.
  7022. // If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  7023. //
  7024. // CERT_STORE_PROV_PHYSICAL_W
  7025. // CERT_STORE_PROV_PHYSICAL
  7026. // sz_CERT_STORE_PROV_PHYSICAL_W
  7027. // sz_CERT_STORE_PROV_PHYSICAL
  7028. // Opens the specified "Physical" store in the "System" store.
  7029. //
  7030. // Both the system store and physical names are passed in pvPara. The
  7031. // names are separated with an intervening "\". For example,
  7032. // "Root\.Default". The string is UNICODE.
  7033. //
  7034. // The system and physical store names can't contain any backslashes.
  7035. //
  7036. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvPara
  7037. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure instead
  7038. // of pointing to a null terminated UNICODE string.
  7039. // The specified physical store is opened as relocated using pvPara's
  7040. // hKeyBase.
  7041. //
  7042. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  7043. // the system and physical store names
  7044. // must be prefixed with the ServiceName or UserName. For example,
  7045. // "ServiceName\Root\.Default".
  7046. //
  7047. // Physical stores on remote computers can be accessed for the
  7048. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  7049. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  7050. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  7051. // locations by prepending the computer name. For example, a remote
  7052. // local machine store is accessed via "\\ComputerName\Root\.Default"
  7053. // or "ComputerName\Root\.Default". A remote service store is
  7054. // accessed via "\\ComputerName\ServiceName\Root\.Default". The
  7055. // leading "\\" backslashes are optional in the ComputerName.
  7056. //
  7057. // CERT_STORE_PROV_COLLECTION
  7058. // sz_CERT_STORE_PROV_COLLECTION
  7059. // Opens a store that is a collection of other stores. Stores are
  7060. // added or removed to/from the collection via the CertAddStoreToCollection
  7061. // and CertRemoveStoreFromCollection APIs.
  7062. //
  7063. // CERT_STORE_PROV_SMART_CARD_W
  7064. // CERT_STORE_PROV_SMART_CARD
  7065. // sz_CERT_STORE_PROV_SMART_CARD_W
  7066. // sz_CERT_STORE_PROV_SMART_CARD
  7067. // Opens a store instantiated over a particular smart card storage. pvPara
  7068. // identifies where on the card the store is located and is of the
  7069. // following format:
  7070. //
  7071. // Card Name\Provider Name\Provider Type[\Container Name]
  7072. //
  7073. // Container Name is optional and if NOT specified the Card Name is used
  7074. // as the Container Name. Future versions of the provider will support
  7075. // instantiating the store over the entire card in which case just
  7076. // Card Name ( or id ) will be sufficient.
  7077. //
  7078. // Here's a list of the predefined provider types (implemented in
  7079. // cryptnet.dll):
  7080. //
  7081. // CERT_STORE_PROV_LDAP_W
  7082. // CERT_STORE_PROV_LDAP
  7083. // sz_CERT_STORE_PROV_LDAP_W
  7084. // sz_CERT_STORE_PROV_LDAP
  7085. // Opens a store over the results of the query specified by and LDAP
  7086. // URL which is passed in via pvPara. In order to do writes to the
  7087. // store the URL must specify a BASE query, no filter and a single
  7088. // attribute.
  7089. //
  7090. //--------------------------------------------------------------------------
  7091. WINCRYPT32API
  7092. HCERTSTORE
  7093. WINAPI
  7094. CertOpenStore(
  7095. IN LPCSTR lpszStoreProvider,
  7096. IN DWORD dwEncodingType,
  7097. IN HCRYPTPROV hCryptProv,
  7098. IN DWORD dwFlags,
  7099. IN const void *pvPara
  7100. );
  7101. //+-------------------------------------------------------------------------
  7102. // OID Installable Certificate Store Provider Data Structures
  7103. //--------------------------------------------------------------------------
  7104. // Handle returned by the store provider when opened.
  7105. typedef void *HCERTSTOREPROV;
  7106. // Store Provider OID function's pszFuncName.
  7107. #define CRYPT_OID_OPEN_STORE_PROV_FUNC "CertDllOpenStoreProv"
  7108. // Note, the Store Provider OID function's dwEncodingType is always 0.
  7109. // The following information is returned by the provider when opened. Its
  7110. // zeroed with cbSize set before the provider is called. If the provider
  7111. // doesn't need to be called again after the open it doesn't need to
  7112. // make any updates to the CERT_STORE_PROV_INFO.
  7113. typedef struct _CERT_STORE_PROV_INFO {
  7114. DWORD cbSize;
  7115. DWORD cStoreProvFunc;
  7116. void **rgpvStoreProvFunc;
  7117. HCERTSTOREPROV hStoreProv;
  7118. DWORD dwStoreProvFlags;
  7119. HCRYPTOIDFUNCADDR hStoreProvFuncAddr2;
  7120. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  7121. // Definition of the store provider's open function.
  7122. //
  7123. // *pStoreProvInfo has been zeroed before the call.
  7124. //
  7125. // Note, pStoreProvInfo->cStoreProvFunc should be set last. Once set,
  7126. // all subsequent store calls, such as CertAddSerializedElementToStore will
  7127. // call the appropriate provider callback function.
  7128. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  7129. IN LPCSTR lpszStoreProvider,
  7130. IN DWORD dwEncodingType,
  7131. IN HCRYPTPROV hCryptProv,
  7132. IN DWORD dwFlags,
  7133. IN const void *pvPara,
  7134. IN HCERTSTORE hCertStore,
  7135. IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  7136. );
  7137. // The open callback sets the following flag, if it maintains its
  7138. // contexts externally and not in the cached store.
  7139. #define CERT_STORE_PROV_EXTERNAL_FLAG 0x1
  7140. // The open callback sets the following flag for a successful delete.
  7141. // When set, the close callback isn't called.
  7142. #define CERT_STORE_PROV_DELETED_FLAG 0x2
  7143. // The open callback sets the following flag if it doesn't persist store
  7144. // changes.
  7145. #define CERT_STORE_PROV_NO_PERSIST_FLAG 0x4
  7146. // The open callback sets the following flag if the contexts are persisted
  7147. // to a system store.
  7148. #define CERT_STORE_PROV_SYSTEM_STORE_FLAG 0x8
  7149. // The open callback sets the following flag if the contexts are persisted
  7150. // to a LocalMachine system store.
  7151. #define CERT_STORE_PROV_LM_SYSTEM_STORE_FLAG 0x10
  7152. // Indices into the store provider's array of callback functions.
  7153. //
  7154. // The provider can implement any subset of the following functions. It
  7155. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  7156. // preceding not implemented functions to NULL.
  7157. #define CERT_STORE_PROV_CLOSE_FUNC 0
  7158. #define CERT_STORE_PROV_READ_CERT_FUNC 1
  7159. #define CERT_STORE_PROV_WRITE_CERT_FUNC 2
  7160. #define CERT_STORE_PROV_DELETE_CERT_FUNC 3
  7161. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC 4
  7162. #define CERT_STORE_PROV_READ_CRL_FUNC 5
  7163. #define CERT_STORE_PROV_WRITE_CRL_FUNC 6
  7164. #define CERT_STORE_PROV_DELETE_CRL_FUNC 7
  7165. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC 8
  7166. #define CERT_STORE_PROV_READ_CTL_FUNC 9
  7167. #define CERT_STORE_PROV_WRITE_CTL_FUNC 10
  7168. #define CERT_STORE_PROV_DELETE_CTL_FUNC 11
  7169. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC 12
  7170. #define CERT_STORE_PROV_CONTROL_FUNC 13
  7171. #define CERT_STORE_PROV_FIND_CERT_FUNC 14
  7172. #define CERT_STORE_PROV_FREE_FIND_CERT_FUNC 15
  7173. #define CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC 16
  7174. #define CERT_STORE_PROV_FIND_CRL_FUNC 17
  7175. #define CERT_STORE_PROV_FREE_FIND_CRL_FUNC 18
  7176. #define CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC 19
  7177. #define CERT_STORE_PROV_FIND_CTL_FUNC 20
  7178. #define CERT_STORE_PROV_FREE_FIND_CTL_FUNC 21
  7179. #define CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC 22
  7180. // Called by CertCloseStore when the store's reference count is
  7181. // decremented to 0.
  7182. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  7183. IN HCERTSTOREPROV hStoreProv,
  7184. IN DWORD dwFlags
  7185. );
  7186. // Currently not called directly by the store APIs. However, may be exported
  7187. // to support other providers based on it.
  7188. //
  7189. // Reads the provider's copy of the certificate context. If it exists,
  7190. // creates a new certificate context.
  7191. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  7192. IN HCERTSTOREPROV hStoreProv,
  7193. IN PCCERT_CONTEXT pStoreCertContext,
  7194. IN DWORD dwFlags,
  7195. OUT PCCERT_CONTEXT *ppProvCertContext
  7196. );
  7197. #define CERT_STORE_PROV_WRITE_ADD_FLAG 0x1
  7198. // Called by CertAddEncodedCertificateToStore,
  7199. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  7200. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7201. // addition to the encoded certificate, the added pCertContext might also
  7202. // have properties.
  7203. //
  7204. // Returns TRUE if its OK to update the the store.
  7205. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  7206. IN HCERTSTOREPROV hStoreProv,
  7207. IN PCCERT_CONTEXT pCertContext,
  7208. IN DWORD dwFlags
  7209. );
  7210. // Called by CertDeleteCertificateFromStore before deleting from the
  7211. // store.
  7212. //
  7213. // Returns TRUE if its OK to delete from the store.
  7214. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  7215. IN HCERTSTOREPROV hStoreProv,
  7216. IN PCCERT_CONTEXT pCertContext,
  7217. IN DWORD dwFlags
  7218. );
  7219. // Called by CertSetCertificateContextProperty before setting the
  7220. // certificate's property. Also called by CertGetCertificateContextProperty,
  7221. // when getting a hash property that needs to be created and then persisted
  7222. // via the set.
  7223. //
  7224. // Upon input, the property hasn't been set for the pCertContext parameter.
  7225. //
  7226. // Returns TRUE if its OK to set the property.
  7227. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  7228. IN HCERTSTOREPROV hStoreProv,
  7229. IN PCCERT_CONTEXT pCertContext,
  7230. IN DWORD dwPropId,
  7231. IN DWORD dwFlags,
  7232. IN const void *pvData
  7233. );
  7234. // Currently not called directly by the store APIs. However, may be exported
  7235. // to support other providers based on it.
  7236. //
  7237. // Reads the provider's copy of the CRL context. If it exists,
  7238. // creates a new CRL context.
  7239. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  7240. IN HCERTSTOREPROV hStoreProv,
  7241. IN PCCRL_CONTEXT pStoreCrlContext,
  7242. IN DWORD dwFlags,
  7243. OUT PCCRL_CONTEXT *ppProvCrlContext
  7244. );
  7245. // Called by CertAddEncodedCRLToStore,
  7246. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  7247. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7248. // addition to the encoded CRL, the added pCertContext might also
  7249. // have properties.
  7250. //
  7251. // Returns TRUE if its OK to update the the store.
  7252. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  7253. IN HCERTSTOREPROV hStoreProv,
  7254. IN PCCRL_CONTEXT pCrlContext,
  7255. IN DWORD dwFlags
  7256. );
  7257. // Called by CertDeleteCRLFromStore before deleting from the store.
  7258. //
  7259. // Returns TRUE if its OK to delete from the store.
  7260. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  7261. IN HCERTSTOREPROV hStoreProv,
  7262. IN PCCRL_CONTEXT pCrlContext,
  7263. IN DWORD dwFlags
  7264. );
  7265. // Called by CertSetCRLContextProperty before setting the
  7266. // CRL's property. Also called by CertGetCRLContextProperty,
  7267. // when getting a hash property that needs to be created and then persisted
  7268. // via the set.
  7269. //
  7270. // Upon input, the property hasn't been set for the pCrlContext parameter.
  7271. //
  7272. // Returns TRUE if its OK to set the property.
  7273. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  7274. IN HCERTSTOREPROV hStoreProv,
  7275. IN PCCRL_CONTEXT pCrlContext,
  7276. IN DWORD dwPropId,
  7277. IN DWORD dwFlags,
  7278. IN const void *pvData
  7279. );
  7280. // Currently not called directly by the store APIs. However, may be exported
  7281. // to support other providers based on it.
  7282. //
  7283. // Reads the provider's copy of the CTL context. If it exists,
  7284. // creates a new CTL context.
  7285. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  7286. IN HCERTSTOREPROV hStoreProv,
  7287. IN PCCTL_CONTEXT pStoreCtlContext,
  7288. IN DWORD dwFlags,
  7289. OUT PCCTL_CONTEXT *ppProvCtlContext
  7290. );
  7291. // Called by CertAddEncodedCTLToStore,
  7292. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  7293. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  7294. // addition to the encoded CTL, the added pCertContext might also
  7295. // have properties.
  7296. //
  7297. // Returns TRUE if its OK to update the the store.
  7298. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  7299. IN HCERTSTOREPROV hStoreProv,
  7300. IN PCCTL_CONTEXT pCtlContext,
  7301. IN DWORD dwFlags
  7302. );
  7303. // Called by CertDeleteCTLFromStore before deleting from the store.
  7304. //
  7305. // Returns TRUE if its OK to delete from the store.
  7306. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  7307. IN HCERTSTOREPROV hStoreProv,
  7308. IN PCCTL_CONTEXT pCtlContext,
  7309. IN DWORD dwFlags
  7310. );
  7311. // Called by CertSetCTLContextProperty before setting the
  7312. // CTL's property. Also called by CertGetCTLContextProperty,
  7313. // when getting a hash property that needs to be created and then persisted
  7314. // via the set.
  7315. //
  7316. // Upon input, the property hasn't been set for the pCtlContext parameter.
  7317. //
  7318. // Returns TRUE if its OK to set the property.
  7319. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  7320. IN HCERTSTOREPROV hStoreProv,
  7321. IN PCCTL_CONTEXT pCtlContext,
  7322. IN DWORD dwPropId,
  7323. IN DWORD dwFlags,
  7324. IN const void *pvData
  7325. );
  7326. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_CONTROL)(
  7327. IN HCERTSTOREPROV hStoreProv,
  7328. IN DWORD dwFlags,
  7329. IN DWORD dwCtrlType,
  7330. IN void const *pvCtrlPara
  7331. );
  7332. typedef struct _CERT_STORE_PROV_FIND_INFO {
  7333. DWORD cbSize;
  7334. DWORD dwMsgAndCertEncodingType;
  7335. DWORD dwFindFlags;
  7336. DWORD dwFindType;
  7337. const void *pvFindPara;
  7338. } CERT_STORE_PROV_FIND_INFO, *PCERT_STORE_PROV_FIND_INFO;
  7339. typedef const CERT_STORE_PROV_FIND_INFO CCERT_STORE_PROV_FIND_INFO,
  7340. *PCCERT_STORE_PROV_FIND_INFO;
  7341. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CERT)(
  7342. IN HCERTSTOREPROV hStoreProv,
  7343. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7344. IN PCCERT_CONTEXT pPrevCertContext,
  7345. IN DWORD dwFlags,
  7346. IN OUT void **ppvStoreProvFindInfo,
  7347. OUT PCCERT_CONTEXT *ppProvCertContext
  7348. );
  7349. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CERT)(
  7350. IN HCERTSTOREPROV hStoreProv,
  7351. IN PCCERT_CONTEXT pCertContext,
  7352. IN void *pvStoreProvFindInfo,
  7353. IN DWORD dwFlags
  7354. );
  7355. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CERT_PROPERTY)(
  7356. IN HCERTSTOREPROV hStoreProv,
  7357. IN PCCERT_CONTEXT pCertContext,
  7358. IN DWORD dwPropId,
  7359. IN DWORD dwFlags,
  7360. OUT void *pvData,
  7361. IN OUT DWORD *pcbData
  7362. );
  7363. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CRL)(
  7364. IN HCERTSTOREPROV hStoreProv,
  7365. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7366. IN PCCRL_CONTEXT pPrevCrlContext,
  7367. IN DWORD dwFlags,
  7368. IN OUT void **ppvStoreProvFindInfo,
  7369. OUT PCCRL_CONTEXT *ppProvCrlContext
  7370. );
  7371. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CRL)(
  7372. IN HCERTSTOREPROV hStoreProv,
  7373. IN PCCRL_CONTEXT pCrlContext,
  7374. IN void *pvStoreProvFindInfo,
  7375. IN DWORD dwFlags
  7376. );
  7377. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CRL_PROPERTY)(
  7378. IN HCERTSTOREPROV hStoreProv,
  7379. IN PCCRL_CONTEXT pCrlContext,
  7380. IN DWORD dwPropId,
  7381. IN DWORD dwFlags,
  7382. OUT void *pvData,
  7383. IN OUT DWORD *pcbData
  7384. );
  7385. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FIND_CTL)(
  7386. IN HCERTSTOREPROV hStoreProv,
  7387. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  7388. IN PCCTL_CONTEXT pPrevCtlContext,
  7389. IN DWORD dwFlags,
  7390. IN OUT void **ppvStoreProvFindInfo,
  7391. OUT PCCTL_CONTEXT *ppProvCtlContext
  7392. );
  7393. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_FREE_FIND_CTL)(
  7394. IN HCERTSTOREPROV hStoreProv,
  7395. IN PCCTL_CONTEXT pCtlContext,
  7396. IN void *pvStoreProvFindInfo,
  7397. IN DWORD dwFlags
  7398. );
  7399. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_GET_CTL_PROPERTY)(
  7400. IN HCERTSTOREPROV hStoreProv,
  7401. IN PCCTL_CONTEXT pCtlContext,
  7402. IN DWORD dwPropId,
  7403. IN DWORD dwFlags,
  7404. OUT void *pvData,
  7405. IN OUT DWORD *pcbData
  7406. );
  7407. //+-------------------------------------------------------------------------
  7408. // Duplicate a cert store handle
  7409. //--------------------------------------------------------------------------
  7410. WINCRYPT32API
  7411. HCERTSTORE
  7412. WINAPI
  7413. CertDuplicateStore(
  7414. IN HCERTSTORE hCertStore
  7415. );
  7416. #define CERT_STORE_SAVE_AS_STORE 1
  7417. #define CERT_STORE_SAVE_AS_PKCS7 2
  7418. #define CERT_STORE_SAVE_TO_FILE 1
  7419. #define CERT_STORE_SAVE_TO_MEMORY 2
  7420. #define CERT_STORE_SAVE_TO_FILENAME_A 3
  7421. #define CERT_STORE_SAVE_TO_FILENAME_W 4
  7422. #define CERT_STORE_SAVE_TO_FILENAME CERT_STORE_SAVE_TO_FILENAME_W
  7423. //+-------------------------------------------------------------------------
  7424. // Save the cert store. Extended version with lots of options.
  7425. //
  7426. // According to the dwSaveAs parameter, the store can be saved as a
  7427. // serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  7428. // addition to encoded certificates, CRLs and CTLs or the store can be saved
  7429. // as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  7430. // include the properties or CTLs.
  7431. //
  7432. // Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  7433. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  7434. // a serialized store.
  7435. //
  7436. // For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  7437. // encoding type. The dwEncodingType parameter isn't used for
  7438. // CERT_STORE_SAVE_AS_STORE.
  7439. //
  7440. // The dwFlags parameter currently isn't used and should be set to 0.
  7441. //
  7442. // The dwSaveTo and pvSaveToPara parameters specify where to save the
  7443. // store as follows:
  7444. // CERT_STORE_SAVE_TO_FILE:
  7445. // Saves to the specified file. The file's handle is passed in
  7446. // pvSaveToPara. Given,
  7447. // HANDLE hFile; pvSaveToPara = (void *) hFile;
  7448. //
  7449. // For a successful save, the file pointer is positioned after the
  7450. // last write.
  7451. //
  7452. // CERT_STORE_SAVE_TO_MEMORY:
  7453. // Saves to the specified memory blob. The pointer to
  7454. // the memory blob is passed in pvSaveToPara. Given,
  7455. // CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  7456. // Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  7457. // Upon return, cbData is updated with the actual length.
  7458. // For a length only calculation, pbData should be set to NULL. If
  7459. // pbData is non-NULL and cbData isn't large enough, FALSE is returned
  7460. // with a last error of ERRROR_MORE_DATA.
  7461. //
  7462. // CERT_STORE_SAVE_TO_FILENAME_A:
  7463. // CERT_STORE_SAVE_TO_FILENAME_W:
  7464. // CERT_STORE_SAVE_TO_FILENAME:
  7465. // Opens the file and saves to it. The filename is passed in pvSaveToPara.
  7466. // The filename is UNICODE for the "_W" option and ASCII for the "_A"
  7467. // option. For "_W": given,
  7468. // LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  7469. // For "_A": given,
  7470. // LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  7471. //
  7472. // Note, the default (without "_A" or "_W") is UNICODE.
  7473. //
  7474. //--------------------------------------------------------------------------
  7475. WINCRYPT32API
  7476. BOOL
  7477. WINAPI
  7478. CertSaveStore(
  7479. IN HCERTSTORE hCertStore,
  7480. IN DWORD dwEncodingType,
  7481. IN DWORD dwSaveAs,
  7482. IN DWORD dwSaveTo,
  7483. IN OUT void *pvSaveToPara,
  7484. IN DWORD dwFlags
  7485. );
  7486. //+-------------------------------------------------------------------------
  7487. // Certificate Store close flags
  7488. //--------------------------------------------------------------------------
  7489. #define CERT_CLOSE_STORE_FORCE_FLAG 0x00000001
  7490. #define CERT_CLOSE_STORE_CHECK_FLAG 0x00000002
  7491. //+-------------------------------------------------------------------------
  7492. // Close a cert store handle.
  7493. //
  7494. // There needs to be a corresponding close for each open and duplicate.
  7495. //
  7496. // Even on the final close, the cert store isn't freed until all of its
  7497. // certificate and CRL contexts have also been freed.
  7498. //
  7499. // On the final close, the hCryptProv passed to CertStoreOpen is
  7500. // CryptReleaseContext'ed.
  7501. //
  7502. // To force the closure of the store with all of its memory freed, set the
  7503. // CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  7504. // its own reference counting and wants everything to vanish.
  7505. //
  7506. // To check if all the store's certificates and CRLs have been freed and that
  7507. // this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  7508. // set and certs, CRLs or stores still need to be freed/closed, FALSE is
  7509. // returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  7510. // the store is still closed. This is a diagnostic flag.
  7511. //
  7512. // LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  7513. // is returned.
  7514. //--------------------------------------------------------------------------
  7515. WINCRYPT32API
  7516. BOOL
  7517. WINAPI
  7518. CertCloseStore(
  7519. IN HCERTSTORE hCertStore,
  7520. DWORD dwFlags
  7521. );
  7522. //+-------------------------------------------------------------------------
  7523. // Get the subject certificate context uniquely identified by its Issuer and
  7524. // SerialNumber from the store.
  7525. //
  7526. // If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  7527. // a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  7528. // CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  7529. // duplicate.
  7530. //
  7531. // The returned certificate might not be valid. Normally, it would be
  7532. // verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  7533. //--------------------------------------------------------------------------
  7534. WINCRYPT32API
  7535. PCCERT_CONTEXT
  7536. WINAPI
  7537. CertGetSubjectCertificateFromStore(
  7538. IN HCERTSTORE hCertStore,
  7539. IN DWORD dwCertEncodingType,
  7540. IN PCERT_INFO pCertId // Only the Issuer and SerialNumber
  7541. // fields are used
  7542. );
  7543. //+-------------------------------------------------------------------------
  7544. // Enumerate the certificate contexts in the store.
  7545. //
  7546. // If a certificate isn't found, NULL is returned.
  7547. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7548. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7549. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7550. // can be called to make a duplicate.
  7551. //
  7552. // pPrevCertContext MUST BE NULL to enumerate the first
  7553. // certificate in the store. Successive certificates are enumerated by setting
  7554. // pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  7555. //
  7556. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7557. // this function, even for an error.
  7558. //--------------------------------------------------------------------------
  7559. WINCRYPT32API
  7560. PCCERT_CONTEXT
  7561. WINAPI
  7562. CertEnumCertificatesInStore(
  7563. IN HCERTSTORE hCertStore,
  7564. IN PCCERT_CONTEXT pPrevCertContext
  7565. );
  7566. //+-------------------------------------------------------------------------
  7567. // Find the first or next certificate context in the store.
  7568. //
  7569. // The certificate is found according to the dwFindType and its pvFindPara.
  7570. // See below for a list of the find types and its parameters.
  7571. //
  7572. // Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  7573. // CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  7574. //
  7575. // Usage of dwCertEncodingType depends on the dwFindType.
  7576. //
  7577. // If the first or next certificate isn't found, NULL is returned.
  7578. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7579. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7580. // pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  7581. // can be called to make a duplicate.
  7582. //
  7583. // pPrevCertContext MUST BE NULL on the first
  7584. // call to find the certificate. To find the next certificate, the
  7585. // pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  7586. //
  7587. // NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  7588. // this function, even for an error.
  7589. //--------------------------------------------------------------------------
  7590. WINCRYPT32API
  7591. PCCERT_CONTEXT
  7592. WINAPI
  7593. CertFindCertificateInStore(
  7594. IN HCERTSTORE hCertStore,
  7595. IN DWORD dwCertEncodingType,
  7596. IN DWORD dwFindFlags,
  7597. IN DWORD dwFindType,
  7598. IN const void *pvFindPara,
  7599. IN PCCERT_CONTEXT pPrevCertContext
  7600. );
  7601. //+-------------------------------------------------------------------------
  7602. // Certificate comparison functions
  7603. //--------------------------------------------------------------------------
  7604. #define CERT_COMPARE_MASK 0xFFFF
  7605. #define CERT_COMPARE_SHIFT 16
  7606. #define CERT_COMPARE_ANY 0
  7607. #define CERT_COMPARE_SHA1_HASH 1
  7608. #define CERT_COMPARE_NAME 2
  7609. #define CERT_COMPARE_ATTR 3
  7610. #define CERT_COMPARE_MD5_HASH 4
  7611. #define CERT_COMPARE_PROPERTY 5
  7612. #define CERT_COMPARE_PUBLIC_KEY 6
  7613. #define CERT_COMPARE_HASH CERT_COMPARE_SHA1_HASH
  7614. #define CERT_COMPARE_NAME_STR_A 7
  7615. #define CERT_COMPARE_NAME_STR_W 8
  7616. #define CERT_COMPARE_KEY_SPEC 9
  7617. #define CERT_COMPARE_ENHKEY_USAGE 10
  7618. #define CERT_COMPARE_CTL_USAGE CERT_COMPARE_ENHKEY_USAGE
  7619. #define CERT_COMPARE_SUBJECT_CERT 11
  7620. #define CERT_COMPARE_ISSUER_OF 12
  7621. #define CERT_COMPARE_EXISTING 13
  7622. #define CERT_COMPARE_SIGNATURE_HASH 14
  7623. #define CERT_COMPARE_KEY_IDENTIFIER 15
  7624. #define CERT_COMPARE_CERT_ID 16
  7625. #define CERT_COMPARE_CROSS_CERT_DIST_POINTS 17
  7626. #define CERT_COMPARE_PUBKEY_MD5_HASH 18
  7627. //+-------------------------------------------------------------------------
  7628. // dwFindType
  7629. //
  7630. // The dwFindType definition consists of two components:
  7631. // - comparison function
  7632. // - certificate information flag
  7633. //--------------------------------------------------------------------------
  7634. #define CERT_FIND_ANY (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  7635. #define CERT_FIND_SHA1_HASH (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  7636. #define CERT_FIND_MD5_HASH (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  7637. #define CERT_FIND_SIGNATURE_HASH (CERT_COMPARE_SIGNATURE_HASH << CERT_COMPARE_SHIFT)
  7638. #define CERT_FIND_KEY_IDENTIFIER (CERT_COMPARE_KEY_IDENTIFIER << CERT_COMPARE_SHIFT)
  7639. #define CERT_FIND_HASH CERT_FIND_SHA1_HASH
  7640. #define CERT_FIND_PROPERTY (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  7641. #define CERT_FIND_PUBLIC_KEY (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  7642. #define CERT_FIND_SUBJECT_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7643. CERT_INFO_SUBJECT_FLAG)
  7644. #define CERT_FIND_SUBJECT_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7645. CERT_INFO_SUBJECT_FLAG)
  7646. #define CERT_FIND_ISSUER_NAME (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  7647. CERT_INFO_ISSUER_FLAG)
  7648. #define CERT_FIND_ISSUER_ATTR (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  7649. CERT_INFO_ISSUER_FLAG)
  7650. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7651. CERT_INFO_SUBJECT_FLAG)
  7652. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7653. CERT_INFO_SUBJECT_FLAG)
  7654. #define CERT_FIND_SUBJECT_STR CERT_FIND_SUBJECT_STR_W
  7655. #define CERT_FIND_ISSUER_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  7656. CERT_INFO_ISSUER_FLAG)
  7657. #define CERT_FIND_ISSUER_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  7658. CERT_INFO_ISSUER_FLAG)
  7659. #define CERT_FIND_ISSUER_STR CERT_FIND_ISSUER_STR_W
  7660. #define CERT_FIND_KEY_SPEC (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  7661. #define CERT_FIND_ENHKEY_USAGE (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  7662. #define CERT_FIND_CTL_USAGE CERT_FIND_ENHKEY_USAGE
  7663. #define CERT_FIND_SUBJECT_CERT (CERT_COMPARE_SUBJECT_CERT << CERT_COMPARE_SHIFT)
  7664. #define CERT_FIND_ISSUER_OF (CERT_COMPARE_ISSUER_OF << CERT_COMPARE_SHIFT)
  7665. #define CERT_FIND_EXISTING (CERT_COMPARE_EXISTING << CERT_COMPARE_SHIFT)
  7666. #define CERT_FIND_CERT_ID (CERT_COMPARE_CERT_ID << CERT_COMPARE_SHIFT)
  7667. #define CERT_FIND_CROSS_CERT_DIST_POINTS \
  7668. (CERT_COMPARE_CROSS_CERT_DIST_POINTS << CERT_COMPARE_SHIFT)
  7669. #define CERT_FIND_PUBKEY_MD5_HASH \
  7670. (CERT_COMPARE_PUBKEY_MD5_HASH << CERT_COMPARE_SHIFT)
  7671. //+-------------------------------------------------------------------------
  7672. // CERT_FIND_ANY
  7673. //
  7674. // Find any certificate.
  7675. //
  7676. // pvFindPara isn't used.
  7677. //--------------------------------------------------------------------------
  7678. //+-------------------------------------------------------------------------
  7679. // CERT_FIND_HASH
  7680. //
  7681. // Find a certificate with the specified hash.
  7682. //
  7683. // pvFindPara points to a CRYPT_HASH_BLOB.
  7684. //--------------------------------------------------------------------------
  7685. //+-------------------------------------------------------------------------
  7686. // CERT_FIND_KEY_IDENTIFIER
  7687. //
  7688. // Find a certificate with the specified KeyIdentifier. Gets the
  7689. // CERT_KEY_IDENTIFIER_PROP_ID property and compares with the input
  7690. // CRYPT_HASH_BLOB.
  7691. //
  7692. // pvFindPara points to a CRYPT_HASH_BLOB.
  7693. //--------------------------------------------------------------------------
  7694. //+-------------------------------------------------------------------------
  7695. // CERT_FIND_PROPERTY
  7696. //
  7697. // Find a certificate having the specified property.
  7698. //
  7699. // pvFindPara points to a DWORD containing the PROP_ID
  7700. //--------------------------------------------------------------------------
  7701. //+-------------------------------------------------------------------------
  7702. // CERT_FIND_PUBLIC_KEY
  7703. //
  7704. // Find a certificate matching the specified public key.
  7705. //
  7706. // pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  7707. //--------------------------------------------------------------------------
  7708. //+-------------------------------------------------------------------------
  7709. // CERT_FIND_SUBJECT_NAME
  7710. // CERT_FIND_ISSUER_NAME
  7711. //
  7712. // Find a certificate with the specified subject/issuer name. Does an exact
  7713. // match of the entire name.
  7714. //
  7715. // Restricts search to certificates matching the dwCertEncodingType.
  7716. //
  7717. // pvFindPara points to a CERT_NAME_BLOB.
  7718. //--------------------------------------------------------------------------
  7719. //+-------------------------------------------------------------------------
  7720. // CERT_FIND_SUBJECT_ATTR
  7721. // CERT_FIND_ISSUER_ATTR
  7722. //
  7723. // Find a certificate with the specified subject/issuer attributes.
  7724. //
  7725. // Compares the attributes in the subject/issuer name with the
  7726. // Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  7727. // pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  7728. // for an attribute match in any of the subject/issuer's RDNs.
  7729. //
  7730. // The CERT_RDN_ATTR fields can have the following special values:
  7731. // pszObjId == NULL - ignore the attribute object identifier
  7732. // dwValueType == RDN_ANY_TYPE - ignore the value type
  7733. // Value.pbData == NULL - match any value
  7734. //
  7735. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags to do
  7736. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  7737. // match.
  7738. //
  7739. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  7740. // initialized with unicode strings as for
  7741. // CryptEncodeObject(X509_UNICODE_NAME).
  7742. //
  7743. // Restricts search to certificates matching the dwCertEncodingType.
  7744. //
  7745. // pvFindPara points to a CERT_RDN (defined in wincert.h).
  7746. //--------------------------------------------------------------------------
  7747. //+-------------------------------------------------------------------------
  7748. // CERT_FIND_SUBJECT_STR_A
  7749. // CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  7750. // CERT_FIND_ISSUER_STR_A
  7751. // CERT_FIND_ISSUER_STR_W | CERT_FIND_ISSUER_STR
  7752. //
  7753. // Find a certificate containing the specified subject/issuer name string.
  7754. //
  7755. // First, the certificate's subject/issuer is converted to a name string
  7756. // via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  7757. // case insensitive substring within string match is performed.
  7758. //
  7759. // Restricts search to certificates matching the dwCertEncodingType.
  7760. //
  7761. // For *_STR_A, pvFindPara points to a null terminated character string.
  7762. // For *_STR_W, pvFindPara points to a null terminated wide character string.
  7763. //--------------------------------------------------------------------------
  7764. //+-------------------------------------------------------------------------
  7765. // CERT_FIND_KEY_SPEC
  7766. //
  7767. // Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  7768. // the specified KeySpec.
  7769. //
  7770. // pvFindPara points to a DWORD containing the KeySpec.
  7771. //--------------------------------------------------------------------------
  7772. //+-------------------------------------------------------------------------
  7773. // CERT_FIND_ENHKEY_USAGE
  7774. //
  7775. // Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  7776. // the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  7777. //
  7778. // pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  7779. // is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  7780. // certificate having enhanced key usage.
  7781. //
  7782. // If the CERT_FIND_VALID_ENHKEY_USAGE_FLAG is set, then, only does a match
  7783. // for certificates that are valid for the specified usages. By default,
  7784. // the ceriticate must be valid for all usages. CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7785. // can be set, if the certificate only needs to be valid for one of the
  7786. // specified usages. Note, CertGetValidUsages() is called to get the
  7787. // certificate's list of valid usages. Only the CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7788. // is applicable when this flag is set.
  7789. //
  7790. // The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  7791. // also match a certificate without either the extension or property.
  7792. //
  7793. // If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  7794. // certificates without the key usage extension or property. Setting this
  7795. // flag takes precedence over pvFindPara being NULL.
  7796. //
  7797. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7798. // using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  7799. // 0, finds certificates having the extension. If
  7800. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7801. // without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7802. // certificates without the extension.
  7803. //
  7804. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  7805. // using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  7806. // 0, finds certificates having the property. If
  7807. // CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  7808. // without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  7809. // certificates without the property.
  7810. //
  7811. // If CERT_FIND_OR_ENHKEY_USAGE_FLAG is set, does an "OR" match of any of
  7812. // the specified pszUsageIdentifiers. If not set, then, does an "AND" match
  7813. // of all of the specified pszUsageIdentifiers.
  7814. //--------------------------------------------------------------------------
  7815. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG 0x1
  7816. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG 0x2
  7817. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  7818. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG 0x8
  7819. #define CERT_FIND_OR_ENHKEY_USAGE_FLAG 0x10
  7820. #define CERT_FIND_VALID_ENHKEY_USAGE_FLAG 0x20
  7821. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  7822. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  7823. CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  7824. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  7825. CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  7826. #define CERT_FIND_NO_CTL_USAGE_FLAG CERT_FIND_NO_ENHKEY_USAGE_FLAG
  7827. #define CERT_FIND_OR_CTL_USAGE_FLAG CERT_FIND_OR_ENHKEY_USAGE_FLAG
  7828. #define CERT_FIND_VALID_CTL_USAGE_FLAG CERT_FIND_VALID_ENHKEY_USAGE_FLAG
  7829. //+-------------------------------------------------------------------------
  7830. // CERT_FIND_CERT_ID
  7831. //
  7832. // Find a certificate with the specified CERT_ID.
  7833. //
  7834. // pvFindPara points to a CERT_ID.
  7835. //--------------------------------------------------------------------------
  7836. //+-------------------------------------------------------------------------
  7837. // CERT_FIND_CROSS_CERT_DIST_POINTS
  7838. //
  7839. // Find a certificate having either a cross certificate distribution
  7840. // point extension or property.
  7841. //
  7842. // pvFindPara isn't used.
  7843. //--------------------------------------------------------------------------
  7844. //+-------------------------------------------------------------------------
  7845. // Get the certificate context from the store for the first or next issuer
  7846. // of the specified subject certificate. Perform the enabled
  7847. // verification checks on the subject. (Note, the checks are on the subject
  7848. // using the returned issuer certificate.)
  7849. //
  7850. // If the first or next issuer certificate isn't found, NULL is returned.
  7851. // Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  7852. // must be freed by calling CertFreeCertificateContext or is freed when passed as the
  7853. // pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  7854. // can be called to make a duplicate.
  7855. //
  7856. // For a self signed subject certificate, NULL is returned with LastError set
  7857. // to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  7858. //
  7859. // The pSubjectContext may have been obtained from this store, another store
  7860. // or created by the caller application. When created by the caller, the
  7861. // CertCreateCertificateContext function must have been called.
  7862. //
  7863. // An issuer may have multiple certificates. This may occur when the validity
  7864. // period is about to change. pPrevIssuerContext MUST BE NULL on the first
  7865. // call to get the issuer. To get the next certificate for the issuer, the
  7866. // pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  7867. //
  7868. // NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  7869. // this function, even for an error.
  7870. //
  7871. // The following flags can be set in *pdwFlags to enable verification checks
  7872. // on the subject certificate context:
  7873. // CERT_STORE_SIGNATURE_FLAG - use the public key in the returned
  7874. // issuer certificate to verify the
  7875. // signature on the subject certificate.
  7876. // Note, if pSubjectContext->hCertStore ==
  7877. // hCertStore, the store provider might
  7878. // be able to eliminate a redo of
  7879. // the signature verify.
  7880. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  7881. // its within the subject certificate's
  7882. // validity period
  7883. // CERT_STORE_REVOCATION_FLAG - check if the subject certificate is on
  7884. // the issuer's revocation list
  7885. //
  7886. // If an enabled verification check fails, then, its flag is set upon return.
  7887. // If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  7888. // CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  7889. // the CERT_STORE_REVOCATION_FLAG.
  7890. //
  7891. // If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  7892. // CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  7893. // in the store.
  7894. //
  7895. // For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  7896. // is still returned and SetLastError isn't updated.
  7897. //--------------------------------------------------------------------------
  7898. WINCRYPT32API
  7899. PCCERT_CONTEXT
  7900. WINAPI
  7901. CertGetIssuerCertificateFromStore(
  7902. IN HCERTSTORE hCertStore,
  7903. IN PCCERT_CONTEXT pSubjectContext,
  7904. IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  7905. IN OUT DWORD *pdwFlags
  7906. );
  7907. //+-------------------------------------------------------------------------
  7908. // Perform the enabled verification checks on the subject certificate
  7909. // using the issuer. Same checks and flags definitions as for the above
  7910. // CertGetIssuerCertificateFromStore.
  7911. //
  7912. // If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  7913. // issuer can be NULL.
  7914. //
  7915. // For a verification check failure, SUCCESS is still returned.
  7916. //--------------------------------------------------------------------------
  7917. WINCRYPT32API
  7918. BOOL
  7919. WINAPI
  7920. CertVerifySubjectCertificateContext(
  7921. IN PCCERT_CONTEXT pSubject,
  7922. IN OPTIONAL PCCERT_CONTEXT pIssuer,
  7923. IN OUT DWORD *pdwFlags
  7924. );
  7925. //+-------------------------------------------------------------------------
  7926. // Duplicate a certificate context
  7927. //--------------------------------------------------------------------------
  7928. WINCRYPT32API
  7929. PCCERT_CONTEXT
  7930. WINAPI
  7931. CertDuplicateCertificateContext(
  7932. IN PCCERT_CONTEXT pCertContext
  7933. );
  7934. //+-------------------------------------------------------------------------
  7935. // Create a certificate context from the encoded certificate. The created
  7936. // context isn't put in a store.
  7937. //
  7938. // Makes a copy of the encoded certificate in the created context.
  7939. //
  7940. // If unable to decode and create the certificate context, NULL is returned.
  7941. // Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  7942. // CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  7943. // CertDuplicateCertificateContext can be called to make a duplicate.
  7944. //
  7945. // CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  7946. // to store properties for the certificate.
  7947. //--------------------------------------------------------------------------
  7948. WINCRYPT32API
  7949. PCCERT_CONTEXT
  7950. WINAPI
  7951. CertCreateCertificateContext(
  7952. IN DWORD dwCertEncodingType,
  7953. IN const BYTE *pbCertEncoded,
  7954. IN DWORD cbCertEncoded
  7955. );
  7956. //+-------------------------------------------------------------------------
  7957. // Free a certificate context
  7958. //
  7959. // There needs to be a corresponding free for each context obtained by a
  7960. // get, find, duplicate or create.
  7961. //--------------------------------------------------------------------------
  7962. WINCRYPT32API
  7963. BOOL
  7964. WINAPI
  7965. CertFreeCertificateContext(
  7966. IN PCCERT_CONTEXT pCertContext
  7967. );
  7968. //+-------------------------------------------------------------------------
  7969. // Set the property for the specified certificate context.
  7970. //
  7971. // The type definition for pvData depends on the dwPropId value. There are
  7972. // five predefined types:
  7973. // CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  7974. // private key is passed in pvData. Updates the hCryptProv field
  7975. // of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  7976. // doesn't exist, its created with all the other fields zeroed out. If
  7977. // CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  7978. // released when either the property is set to NULL or on the final
  7979. // free of the CertContext.
  7980. //
  7981. // CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  7982. // private key is passed in pvData.
  7983. //
  7984. // CERT_SHA1_HASH_PROP_ID -
  7985. // CERT_MD5_HASH_PROP_ID -
  7986. // CERT_SIGNATURE_HASH_PROP_ID - normally, a hash property is implicitly
  7987. // set by doing a CertGetCertificateContextProperty. pvData points to a
  7988. // CRYPT_HASH_BLOB.
  7989. //
  7990. // CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  7991. // private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  7992. // hCryptProv and dwKeySpec for the private key.
  7993. // See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  7994. // the hCryptProv field and dwFlags settings. Note, more fields may
  7995. // be added for this property. The cbSize field value will be adjusted
  7996. // accordingly.
  7997. //
  7998. // CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  7999. // points to a DWORD containing the KeySpec
  8000. //
  8001. // CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  8002. // certificate. pvData points to a CRYPT_DATA_BLOB containing an
  8003. // ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  8004. // CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  8005. //
  8006. // CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  8007. // Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  8008. // containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  8009. // CryptEncodeObject(X509_ALTERNATE_NAME)).
  8010. //
  8011. // CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  8012. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  8013. // terminated unicode, wide character string.
  8014. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  8015. //
  8016. // CERT_DESCRIPTION_PROP_ID - description for the cert, CRL or CTL.
  8017. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  8018. // terminated unicode, wide character string.
  8019. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  8020. //
  8021. // CERT_ARCHIVED_PROP_ID - when this property is set, the certificate
  8022. // is skipped during enumeration. Note, certificates having this property
  8023. // are still found for explicit finds, such as, finding a certificate
  8024. // with a specific hash or finding a certificate having a specific issuer
  8025. // and serial number. pvData points to a CRYPT_DATA_BLOB. This blob
  8026. // can be NULL (pbData = NULL, cbData = 0).
  8027. //
  8028. // CERT_PUBKEY_ALG_PARA_PROP_ID - for public keys supporting
  8029. // algorithm parameter inheritance. pvData points to a CRYPT_OBJID_BLOB
  8030. // containing the ASN.1 encoded PublicKey Algorithm Parameters. For
  8031. // DSS this would be the parameters encoded via
  8032. // CryptEncodeObject(X509_DSS_PARAMETERS). This property may be set
  8033. // by CryptVerifyCertificateSignatureEx().
  8034. //
  8035. // CERT_CROSS_CERT_DIST_POINTS_PROP_ID - location of the cross certs.
  8036. // Currently only applicable to certs. pvData points to a CRYPT_DATA_BLOB
  8037. // containing an ASN.1 encoded CROSS_CERT_DIST_POINTS_INFO (encoded via
  8038. // CryptEncodeObject(X509_CROSS_CERT_DIST_POINTS)).
  8039. //
  8040. // CERT_ENROLLMENT_PROP_ID - enrollment information of the pending request.
  8041. // It contains RequestID, CADNSName, CAName, and FriendlyName.
  8042. // The data format is defined as, the first 4 bytes - pending request ID,
  8043. // next 4 bytes - CADNSName size in characters including null-terminator
  8044. // followed by CADNSName string with null-terminator,
  8045. // next 4 bytes - CAName size in characters including null-terminator
  8046. // followed by CAName string with null-terminator,
  8047. // next 4 bytes - FriendlyName size in characters including null-terminator
  8048. // followed by FriendlyName string with null-terminator.
  8049. //
  8050. // CERT_DATE_STAMP_PROP_ID - contains the time when added to the store
  8051. // by an admin tool. pvData points to a CRYPT_DATA_BLOB containing
  8052. // the FILETIME.
  8053. //
  8054. // CERT_RENEWAL_PROP_ID - contains the hash of renewed certificate
  8055. //
  8056. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  8057. //
  8058. // If the property already exists, then, the old value is deleted and silently
  8059. // replaced. Setting, pvData to NULL, deletes the property.
  8060. //
  8061. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG can be set to ignore any
  8062. // provider write errors and always update the cached context's property.
  8063. //--------------------------------------------------------------------------
  8064. WINCRYPT32API
  8065. BOOL
  8066. WINAPI
  8067. CertSetCertificateContextProperty(
  8068. IN PCCERT_CONTEXT pCertContext,
  8069. IN DWORD dwPropId,
  8070. IN DWORD dwFlags,
  8071. IN const void *pvData
  8072. );
  8073. // Set this flag to ignore any store provider write errors and always update
  8074. // the cached context's property
  8075. #define CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG 0x80000000
  8076. // Set this flag to inhibit the persisting of this property
  8077. #define CERT_SET_PROPERTY_INHIBIT_PERSIST_FLAG 0x40000000
  8078. //+-------------------------------------------------------------------------
  8079. // Get the property for the specified certificate context.
  8080. //
  8081. // For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  8082. //
  8083. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  8084. // Elements pointed to by fields in the pvData structure follow the
  8085. // structure. Therefore, *pcbData may exceed the size of the structure.
  8086. //
  8087. // For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  8088. //
  8089. // For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  8090. // If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  8091. // Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  8092. // of the KeySpec.
  8093. //
  8094. // For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  8095. // doesn't already exist, then, its computed via CryptHashCertificate()
  8096. // and then set. pvData points to the computed hash. Normally, the length
  8097. // is 20 bytes for SHA and 16 for MD5.
  8098. //
  8099. // For CERT_SIGNATURE_HASH_PROP_ID, if the hash
  8100. // doesn't already exist, then, its computed via CryptHashToBeSigned()
  8101. // and then set. pvData points to the computed hash. Normally, the length
  8102. // is 20 bytes for SHA and 16 for MD5.
  8103. //
  8104. // For CERT_ACCESS_STATE_PROP_ID, pvData points to a DWORD containing the
  8105. // access state flags. The appropriate CERT_ACCESS_STATE_*_FLAG's are set
  8106. // in the returned DWORD. See the CERT_ACCESS_STATE_*_FLAG definitions
  8107. // above. Note, this property is read only. It can't be set.
  8108. //
  8109. // For CERT_KEY_IDENTIFIER_PROP_ID, if property doesn't already exist,
  8110. // first searches for the szOID_SUBJECT_KEY_IDENTIFIER extension. Next,
  8111. // does SHA1 hash of the certficate's SubjectPublicKeyInfo. pvData
  8112. // points to the key identifier bytes. Normally, the length is 20 bytes.
  8113. //
  8114. // For CERT_PUBKEY_ALG_PARA_PROP_ID, pvPara points to the ASN.1 encoded
  8115. // PublicKey Algorithm Parameters. This property will only be set
  8116. // for public keys supporting algorithm parameter inheritance and when the
  8117. // parameters have been omitted from the encoded and signed certificate.
  8118. //
  8119. // For CERT_DATE_STAMP_PROP_ID, pvPara points to a FILETIME updated by
  8120. // an admin tool to indicate when the certificate was added to the store.
  8121. //
  8122. // For all other PROP_IDs, pvData points to an encoded array of bytes.
  8123. //--------------------------------------------------------------------------
  8124. WINCRYPT32API
  8125. BOOL
  8126. WINAPI
  8127. CertGetCertificateContextProperty(
  8128. IN PCCERT_CONTEXT pCertContext,
  8129. IN DWORD dwPropId,
  8130. OUT void *pvData,
  8131. IN OUT DWORD *pcbData
  8132. );
  8133. //+-------------------------------------------------------------------------
  8134. // Enumerate the properties for the specified certificate context.
  8135. //
  8136. // To get the first property, set dwPropId to 0. The ID of the first
  8137. // property is returned. To get the next property, set dwPropId to the
  8138. // ID returned by the last call. To enumerate all the properties continue
  8139. // until 0 is returned.
  8140. //
  8141. // CertGetCertificateContextProperty is called to get the property's data.
  8142. //
  8143. // Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  8144. // properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  8145. // property, they aren't enumerated individually.
  8146. //--------------------------------------------------------------------------
  8147. WINCRYPT32API
  8148. DWORD
  8149. WINAPI
  8150. CertEnumCertificateContextProperties(
  8151. IN PCCERT_CONTEXT pCertContext,
  8152. IN DWORD dwPropId
  8153. );
  8154. //+-------------------------------------------------------------------------
  8155. // Creates a CTL entry whose attributes are the certificate context's
  8156. // properties.
  8157. //
  8158. // The SubjectIdentifier in the CTL entry is the SHA1 hash of the certificate.
  8159. //
  8160. // The certificate properties are added as attributes. The property attribute
  8161. // OID is the decimal PROP_ID preceded by szOID_CERT_PROP_ID_PREFIX. Each
  8162. // property value is copied as a single attribute value.
  8163. //
  8164. // Any additional attributes to be included in the CTL entry can be passed
  8165. // in via the cOptAttr and rgOptAttr parameters.
  8166. //
  8167. // CTL_ENTRY_FROM_PROP_CHAIN_FLAG can be set in dwFlags, to force the
  8168. // inclusion of the chain building hash properties as attributes.
  8169. //--------------------------------------------------------------------------
  8170. WINCRYPT32API
  8171. BOOL
  8172. WINAPI
  8173. CertCreateCTLEntryFromCertificateContextProperties(
  8174. IN PCCERT_CONTEXT pCertContext,
  8175. IN DWORD cOptAttr,
  8176. IN OPTIONAL PCRYPT_ATTRIBUTE rgOptAttr,
  8177. IN DWORD dwFlags,
  8178. IN OPTIONAL void *pvReserved,
  8179. OUT OPTIONAL PCTL_ENTRY pCtlEntry,
  8180. IN OUT DWORD *pcbCtlEntry
  8181. );
  8182. // Set this flag to get and include the chain building hash properties
  8183. // as attributes in the CTL entry
  8184. #define CTL_ENTRY_FROM_PROP_CHAIN_FLAG 0x1
  8185. //+-------------------------------------------------------------------------
  8186. // Sets properties on the certificate context using the attributes in
  8187. // the CTL entry.
  8188. //
  8189. // The property attribute OID is the decimal PROP_ID preceded by
  8190. // szOID_CERT_PROP_ID_PREFIX. Only attributes containing such an OID are
  8191. // copied.
  8192. //
  8193. // CERT_SET_PROPERTY_IGNORE_PERSIST_ERROR_FLAG may be set in dwFlags.
  8194. //--------------------------------------------------------------------------
  8195. WINCRYPT32API
  8196. BOOL
  8197. WINAPI
  8198. CertSetCertificateContextPropertiesFromCTLEntry(
  8199. IN PCCERT_CONTEXT pCertContext,
  8200. IN PCTL_ENTRY pCtlEntry,
  8201. IN DWORD dwFlags
  8202. );
  8203. //+-------------------------------------------------------------------------
  8204. // Get the first or next CRL context from the store for the specified
  8205. // issuer certificate. Perform the enabled verification checks on the CRL.
  8206. //
  8207. // If the first or next CRL isn't found, NULL is returned.
  8208. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8209. // must be freed by calling CertFreeCRLContext. However, the free must be
  8210. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8211. // can be called to make a duplicate.
  8212. //
  8213. // The pIssuerContext may have been obtained from this store, another store
  8214. // or created by the caller application. When created by the caller, the
  8215. // CertCreateCertificateContext function must have been called.
  8216. //
  8217. // If pIssuerContext == NULL, finds all the CRLs in the store.
  8218. //
  8219. // An issuer may have multiple CRLs. For example, it generates delta CRLs
  8220. // using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  8221. // call to get the CRL. To get the next CRL for the issuer, the
  8222. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8223. //
  8224. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8225. // this function, even for an error.
  8226. //
  8227. // The following flags can be set in *pdwFlags to enable verification checks
  8228. // on the returned CRL:
  8229. // CERT_STORE_SIGNATURE_FLAG - use the public key in the
  8230. // issuer's certificate to verify the
  8231. // signature on the returned CRL.
  8232. // Note, if pIssuerContext->hCertStore ==
  8233. // hCertStore, the store provider might
  8234. // be able to eliminate a redo of
  8235. // the signature verify.
  8236. // CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  8237. // its within the CRL's ThisUpdate and
  8238. // NextUpdate validity period.
  8239. // CERT_STORE_BASE_CRL_FLAG - get base CRL.
  8240. // CERT_STORE_DELTA_CRL_FLAG - get delta CRL.
  8241. //
  8242. // If only one of CERT_STORE_BASE_CRL_FLAG or CERT_STORE_DELTA_CRL_FLAG is
  8243. // set, then, only returns either a base or delta CRL. In any case, the
  8244. // appropriate base or delta flag will be cleared upon returned. If both
  8245. // flags are set, then, only one of flags will be cleared.
  8246. //
  8247. // If an enabled verification check fails, then, its flag is set upon return.
  8248. //
  8249. // If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  8250. // always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  8251. //
  8252. // For a verification check failure, a pointer to the first or next
  8253. // CRL_CONTEXT is still returned and SetLastError isn't updated.
  8254. //--------------------------------------------------------------------------
  8255. WINCRYPT32API
  8256. PCCRL_CONTEXT
  8257. WINAPI
  8258. CertGetCRLFromStore(
  8259. IN HCERTSTORE hCertStore,
  8260. IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  8261. IN PCCRL_CONTEXT pPrevCrlContext,
  8262. IN OUT DWORD *pdwFlags
  8263. );
  8264. //+-------------------------------------------------------------------------
  8265. // Enumerate the CRL contexts in the store.
  8266. //
  8267. // If a CRL isn't found, NULL is returned.
  8268. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8269. // must be freed by calling CertFreeCRLContext or is freed when passed as the
  8270. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8271. // can be called to make a duplicate.
  8272. //
  8273. // pPrevCrlContext MUST BE NULL to enumerate the first
  8274. // CRL in the store. Successive CRLs are enumerated by setting
  8275. // pPrevCrlContext to the CRL_CONTEXT returned by a previous call.
  8276. //
  8277. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8278. // this function, even for an error.
  8279. //--------------------------------------------------------------------------
  8280. WINCRYPT32API
  8281. PCCRL_CONTEXT
  8282. WINAPI
  8283. CertEnumCRLsInStore(
  8284. IN HCERTSTORE hCertStore,
  8285. IN PCCRL_CONTEXT pPrevCrlContext
  8286. );
  8287. //+-------------------------------------------------------------------------
  8288. // Find the first or next CRL context in the store.
  8289. //
  8290. // The CRL is found according to the dwFindType and its pvFindPara.
  8291. // See below for a list of the find types and its parameters.
  8292. //
  8293. // Currently dwFindFlags isn't used and must be set to 0.
  8294. //
  8295. // Usage of dwCertEncodingType depends on the dwFindType.
  8296. //
  8297. // If the first or next CRL isn't found, NULL is returned.
  8298. // Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  8299. // must be freed by calling CertFreeCRLContext or is freed when passed as the
  8300. // pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  8301. // can be called to make a duplicate.
  8302. //
  8303. // pPrevCrlContext MUST BE NULL on the first
  8304. // call to find the CRL. To find the next CRL, the
  8305. // pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  8306. //
  8307. // NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  8308. // this function, even for an error.
  8309. //--------------------------------------------------------------------------
  8310. WINCRYPT32API
  8311. PCCRL_CONTEXT
  8312. WINAPI
  8313. CertFindCRLInStore(
  8314. IN HCERTSTORE hCertStore,
  8315. IN DWORD dwCertEncodingType,
  8316. IN DWORD dwFindFlags,
  8317. IN DWORD dwFindType,
  8318. IN const void *pvFindPara,
  8319. IN PCCRL_CONTEXT pPrevCrlContext
  8320. );
  8321. #define CRL_FIND_ANY 0
  8322. #define CRL_FIND_ISSUED_BY 1
  8323. #define CRL_FIND_EXISTING 2
  8324. #define CRL_FIND_ISSUED_FOR 3
  8325. //+-------------------------------------------------------------------------
  8326. // CRL_FIND_ANY
  8327. //
  8328. // Find any CRL.
  8329. //
  8330. // pvFindPara isn't used.
  8331. //--------------------------------------------------------------------------
  8332. //+-------------------------------------------------------------------------
  8333. // CRL_FIND_ISSUED_BY
  8334. //
  8335. // Find CRL matching the specified issuer.
  8336. //
  8337. // pvFindPara is the PCCERT_CONTEXT of the CRL issuer. May be NULL to
  8338. // match any issuer.
  8339. //
  8340. // By default, only does issuer name matching. The following flags can be
  8341. // set in dwFindFlags to do additional filtering.
  8342. //
  8343. // If CRL_FIND_ISSUED_BY_AKI_FLAG is set in dwFindFlags, then, checks if the
  8344. // CRL has an Authority Key Identifier (AKI) extension. If the CRL has an
  8345. // AKI, then, only returns a CRL whose AKI matches the issuer.
  8346. //
  8347. // Note, the AKI extension has the following OID:
  8348. // szOID_AUTHORITY_KEY_IDENTIFIER2 and its corresponding data structure.
  8349. //
  8350. // If CRL_FIND_ISSUED_BY_SIGNATURE_FLAG is set in dwFindFlags, then,
  8351. // uses the public key in the issuer's certificate to verify the
  8352. // signature on the CRL. Only returns a CRL having a valid signature.
  8353. //
  8354. // If CRL_FIND_ISSUED_BY_DELTA_FLAG is set in dwFindFlags, then, only
  8355. // returns a delta CRL.
  8356. //
  8357. // If CRL_FIND_ISSUED_BY_BASE_FLAG is set in dwFindFlags, then, only
  8358. // returns a base CRL.
  8359. //--------------------------------------------------------------------------
  8360. #define CRL_FIND_ISSUED_BY_AKI_FLAG 0x1
  8361. #define CRL_FIND_ISSUED_BY_SIGNATURE_FLAG 0x2
  8362. #define CRL_FIND_ISSUED_BY_DELTA_FLAG 0x4
  8363. #define CRL_FIND_ISSUED_BY_BASE_FLAG 0x8
  8364. //+-------------------------------------------------------------------------
  8365. // CRL_FIND_EXISTING
  8366. //
  8367. // Find existing CRL in the store.
  8368. //
  8369. // pvFindPara is the PCCRL_CONTEXT of the CRL to check if it already
  8370. // exists in the store.
  8371. //--------------------------------------------------------------------------
  8372. //+-------------------------------------------------------------------------
  8373. // CRL_FIND_ISSUED_FOR
  8374. //
  8375. // Find CRL for the specified subject and its issuer.
  8376. //
  8377. // pvFindPara points to the following CRL_FIND_ISSUED_FOR_PARA which contains
  8378. // both the subject and issuer certificates. Not optional.
  8379. //
  8380. // The subject's issuer name is used to match the CRL's issuer name. Otherwise,
  8381. // the issuer's certificate is used the same as in the above
  8382. // CRL_FIND_ISSUED_BY.
  8383. //
  8384. // Note, when cross certificates are used, the subject name in the issuer's
  8385. // certificate may not match the issuer name in the subject certificate and
  8386. // its corresponding CRL.
  8387. //
  8388. // All of the above CRL_FIND_ISSUED_BY_*_FLAGS apply to this find type.
  8389. //--------------------------------------------------------------------------
  8390. typedef struct _CRL_FIND_ISSUED_FOR_PARA {
  8391. PCCERT_CONTEXT pSubjectCert;
  8392. PCCERT_CONTEXT pIssuerCert;
  8393. } CRL_FIND_ISSUED_FOR_PARA, *PCRL_FIND_ISSUED_FOR_PARA;
  8394. //+-------------------------------------------------------------------------
  8395. // Duplicate a CRL context
  8396. //--------------------------------------------------------------------------
  8397. WINCRYPT32API
  8398. PCCRL_CONTEXT
  8399. WINAPI
  8400. CertDuplicateCRLContext(
  8401. IN PCCRL_CONTEXT pCrlContext
  8402. );
  8403. //+-------------------------------------------------------------------------
  8404. // Create a CRL context from the encoded CRL. The created
  8405. // context isn't put in a store.
  8406. //
  8407. // Makes a copy of the encoded CRL in the created context.
  8408. //
  8409. // If unable to decode and create the CRL context, NULL is returned.
  8410. // Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  8411. // CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  8412. // CertDuplicateCRLContext can be called to make a duplicate.
  8413. //
  8414. // CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  8415. // to store properties for the CRL.
  8416. //--------------------------------------------------------------------------
  8417. WINCRYPT32API
  8418. PCCRL_CONTEXT
  8419. WINAPI
  8420. CertCreateCRLContext(
  8421. IN DWORD dwCertEncodingType,
  8422. IN const BYTE *pbCrlEncoded,
  8423. IN DWORD cbCrlEncoded
  8424. );
  8425. //+-------------------------------------------------------------------------
  8426. // Free a CRL context
  8427. //
  8428. // There needs to be a corresponding free for each context obtained by a
  8429. // get, duplicate or create.
  8430. //--------------------------------------------------------------------------
  8431. WINCRYPT32API
  8432. BOOL
  8433. WINAPI
  8434. CertFreeCRLContext(
  8435. IN PCCRL_CONTEXT pCrlContext
  8436. );
  8437. //+-------------------------------------------------------------------------
  8438. // Set the property for the specified CRL context.
  8439. //
  8440. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8441. //--------------------------------------------------------------------------
  8442. WINCRYPT32API
  8443. BOOL
  8444. WINAPI
  8445. CertSetCRLContextProperty(
  8446. IN PCCRL_CONTEXT pCrlContext,
  8447. IN DWORD dwPropId,
  8448. IN DWORD dwFlags,
  8449. IN const void *pvData
  8450. );
  8451. //+-------------------------------------------------------------------------
  8452. // Get the property for the specified CRL context.
  8453. //
  8454. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8455. //
  8456. // CERT_SHA1_HASH_PROP_ID, CERT_MD5_HASH_PROP_ID or
  8457. // CERT_SIGNATURE_HASH_PROP_ID is the predefined property of most interest.
  8458. //--------------------------------------------------------------------------
  8459. WINCRYPT32API
  8460. BOOL
  8461. WINAPI
  8462. CertGetCRLContextProperty(
  8463. IN PCCRL_CONTEXT pCrlContext,
  8464. IN DWORD dwPropId,
  8465. OUT void *pvData,
  8466. IN OUT DWORD *pcbData
  8467. );
  8468. //+-------------------------------------------------------------------------
  8469. // Enumerate the properties for the specified CRL context.
  8470. //
  8471. // To get the first property, set dwPropId to 0. The ID of the first
  8472. // property is returned. To get the next property, set dwPropId to the
  8473. // ID returned by the last call. To enumerate all the properties continue
  8474. // until 0 is returned.
  8475. //
  8476. // CertGetCRLContextProperty is called to get the property's data.
  8477. //--------------------------------------------------------------------------
  8478. WINCRYPT32API
  8479. DWORD
  8480. WINAPI
  8481. CertEnumCRLContextProperties(
  8482. IN PCCRL_CONTEXT pCrlContext,
  8483. IN DWORD dwPropId
  8484. );
  8485. //+-------------------------------------------------------------------------
  8486. // Search the CRL's list of entries for the specified certificate.
  8487. //
  8488. // TRUE is returned if we were able to search the list. Otherwise, FALSE is
  8489. // returned,
  8490. //
  8491. // For success, if the certificate was found in the list, *ppCrlEntry is
  8492. // updated with a pointer to the entry. Otherwise, *ppCrlEntry is set to NULL.
  8493. // The returned entry isn't allocated and must not be freed.
  8494. //
  8495. // dwFlags and pvReserved currently aren't used and must be set to 0 or NULL.
  8496. //--------------------------------------------------------------------------
  8497. WINCRYPT32API
  8498. BOOL
  8499. WINAPI
  8500. CertFindCertificateInCRL(
  8501. IN PCCERT_CONTEXT pCert,
  8502. IN PCCRL_CONTEXT pCrlContext,
  8503. IN DWORD dwFlags,
  8504. IN OPTIONAL void *pvReserved,
  8505. OUT PCRL_ENTRY *ppCrlEntry
  8506. );
  8507. //+-------------------------------------------------------------------------
  8508. // Is the specified CRL valid for the certificate.
  8509. //
  8510. // Returns TRUE if the CRL's list of entries would contain the certificate
  8511. // if it was revoked. Note, doesn't check that the certificate is in the
  8512. // list of entries.
  8513. //
  8514. // If the CRL has an Issuing Distribution Point (IDP) extension, checks
  8515. // that it's valid for the subject certificate.
  8516. //
  8517. // dwFlags and pvReserved currently aren't used and must be set to 0 and NULL.
  8518. //--------------------------------------------------------------------------
  8519. WINCRYPT32API
  8520. BOOL
  8521. WINAPI
  8522. CertIsValidCRLForCertificate(
  8523. IN PCCERT_CONTEXT pCert,
  8524. IN PCCRL_CONTEXT pCrl,
  8525. IN DWORD dwFlags,
  8526. IN void *pvReserved
  8527. );
  8528. //+-------------------------------------------------------------------------
  8529. // Add certificate/CRL, encoded, context or element disposition values.
  8530. //--------------------------------------------------------------------------
  8531. #define CERT_STORE_ADD_NEW 1
  8532. #define CERT_STORE_ADD_USE_EXISTING 2
  8533. #define CERT_STORE_ADD_REPLACE_EXISTING 3
  8534. #define CERT_STORE_ADD_ALWAYS 4
  8535. #define CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES 5
  8536. #define CERT_STORE_ADD_NEWER 6
  8537. #define CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES 7
  8538. //+-------------------------------------------------------------------------
  8539. // Add the encoded certificate to the store according to the specified
  8540. // disposition action.
  8541. //
  8542. // Makes a copy of the encoded certificate before adding to the store.
  8543. //
  8544. // dwAddDispostion specifies the action to take if the certificate
  8545. // already exists in the store. This parameter must be one of the following
  8546. // values:
  8547. // CERT_STORE_ADD_NEW
  8548. // Fails if the certificate already exists in the store. LastError
  8549. // is set to CRYPT_E_EXISTS.
  8550. // CERT_STORE_ADD_USE_EXISTING
  8551. // If the certifcate already exists, then, its used and if ppCertContext
  8552. // is non-NULL, the existing context is duplicated.
  8553. // CERT_STORE_ADD_REPLACE_EXISTING
  8554. // If the certificate already exists, then, the existing certificate
  8555. // context is deleted before creating and adding the new context.
  8556. // CERT_STORE_ADD_ALWAYS
  8557. // No check is made to see if the certificate already exists. A
  8558. // new certificate context is always created. This may lead to
  8559. // duplicates in the store.
  8560. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8561. // If the certificate already exists, then, its used.
  8562. // CERT_STORE_ADD_NEWER
  8563. // Fails if the certificate already exists in the store AND the NotBefore
  8564. // time of the existing certificate is equal to or greater than the
  8565. // NotBefore time of the new certificate being added. LastError
  8566. // is set to CRYPT_E_EXISTS.
  8567. //
  8568. // If an older certificate is replaced, same as
  8569. // CERT_STORE_ADD_REPLACE_EXISTING.
  8570. //
  8571. // For CRLs or CTLs compares the ThisUpdate times.
  8572. //
  8573. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8574. // Same as CERT_STORE_ADD_NEWER. However, if an older certificate is
  8575. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8576. //
  8577. // CertGetSubjectCertificateFromStore is called to determine if the
  8578. // certificate already exists in the store.
  8579. //
  8580. // ppCertContext can be NULL, indicating the caller isn't interested
  8581. // in getting the CERT_CONTEXT of the added or existing certificate.
  8582. //--------------------------------------------------------------------------
  8583. WINCRYPT32API
  8584. BOOL
  8585. WINAPI
  8586. CertAddEncodedCertificateToStore(
  8587. IN HCERTSTORE hCertStore,
  8588. IN DWORD dwCertEncodingType,
  8589. IN const BYTE *pbCertEncoded,
  8590. IN DWORD cbCertEncoded,
  8591. IN DWORD dwAddDisposition,
  8592. OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  8593. );
  8594. //+-------------------------------------------------------------------------
  8595. // Add the certificate context to the store according to the specified
  8596. // disposition action.
  8597. //
  8598. // In addition to the encoded certificate, the context's properties are
  8599. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8600. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8601. //
  8602. // Makes a copy of the certificate context before adding to the store.
  8603. //
  8604. // dwAddDispostion specifies the action to take if the certificate
  8605. // already exists in the store. This parameter must be one of the following
  8606. // values:
  8607. // CERT_STORE_ADD_NEW
  8608. // Fails if the certificate already exists in the store. LastError
  8609. // is set to CRYPT_E_EXISTS.
  8610. // CERT_STORE_ADD_USE_EXISTING
  8611. // If the certifcate already exists, then, its used and if ppStoreContext
  8612. // is non-NULL, the existing context is duplicated. Iterates
  8613. // through pCertContext's properties and only copies the properties
  8614. // that don't already exist. The SHA1 and MD5 hash properties aren't
  8615. // copied.
  8616. // CERT_STORE_ADD_REPLACE_EXISTING
  8617. // If the certificate already exists, then, the existing certificate
  8618. // context is deleted before creating and adding a new context.
  8619. // Properties are copied before doing the add.
  8620. // CERT_STORE_ADD_ALWAYS
  8621. // No check is made to see if the certificate already exists. A
  8622. // new certificate context is always created and added. This may lead to
  8623. // duplicates in the store. Properties are
  8624. // copied before doing the add.
  8625. // CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES
  8626. // If the certificate already exists, then, the existing certificate
  8627. // context is used. Properties from the added context are copied and
  8628. // replace existing properties. However, any existing properties not
  8629. // in the added context remain and aren't deleted.
  8630. // CERT_STORE_ADD_NEWER
  8631. // Fails if the certificate already exists in the store AND the NotBefore
  8632. // time of the existing context is equal to or greater than the
  8633. // NotBefore time of the new context being added. LastError
  8634. // is set to CRYPT_E_EXISTS.
  8635. //
  8636. // If an older context is replaced, same as
  8637. // CERT_STORE_ADD_REPLACE_EXISTING.
  8638. //
  8639. // For CRLs or CTLs compares the ThisUpdate times.
  8640. //
  8641. // CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES
  8642. // Same as CERT_STORE_ADD_NEWER. However, if an older context is
  8643. // replaced, same as CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES.
  8644. //
  8645. // CertGetSubjectCertificateFromStore is called to determine if the
  8646. // certificate already exists in the store.
  8647. //
  8648. // ppStoreContext can be NULL, indicating the caller isn't interested
  8649. // in getting the CERT_CONTEXT of the added or existing certificate.
  8650. //--------------------------------------------------------------------------
  8651. WINCRYPT32API
  8652. BOOL
  8653. WINAPI
  8654. CertAddCertificateContextToStore(
  8655. IN HCERTSTORE hCertStore,
  8656. IN PCCERT_CONTEXT pCertContext,
  8657. IN DWORD dwAddDisposition,
  8658. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  8659. );
  8660. //+-------------------------------------------------------------------------
  8661. // Certificate Store Context Types
  8662. //--------------------------------------------------------------------------
  8663. #define CERT_STORE_CERTIFICATE_CONTEXT 1
  8664. #define CERT_STORE_CRL_CONTEXT 2
  8665. #define CERT_STORE_CTL_CONTEXT 3
  8666. //+-------------------------------------------------------------------------
  8667. // Certificate Store Context Bit Flags
  8668. //--------------------------------------------------------------------------
  8669. #define CERT_STORE_ALL_CONTEXT_FLAG (~0UL)
  8670. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG \
  8671. (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  8672. #define CERT_STORE_CRL_CONTEXT_FLAG \
  8673. (1 << CERT_STORE_CRL_CONTEXT)
  8674. #define CERT_STORE_CTL_CONTEXT_FLAG \
  8675. (1 << CERT_STORE_CTL_CONTEXT)
  8676. //+-------------------------------------------------------------------------
  8677. // Add the serialized certificate or CRL element to the store.
  8678. //
  8679. // The serialized element contains the encoded certificate, CRL or CTL and
  8680. // its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  8681. //
  8682. // If hCertStore is NULL, creates a certificate, CRL or CTL context not
  8683. // residing in any store.
  8684. //
  8685. // dwAddDispostion specifies the action to take if the certificate or CRL
  8686. // already exists in the store. See CertAddCertificateContextToStore for a
  8687. // list of and actions taken.
  8688. //
  8689. // dwFlags currently isn't used and should be set to 0.
  8690. //
  8691. // dwContextTypeFlags specifies the set of allowable contexts. For example, to
  8692. // add either a certificate or CRL, set dwContextTypeFlags to:
  8693. // CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  8694. //
  8695. // *pdwContextType is updated with the type of the context returned in
  8696. // *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  8697. // caller isn't interested in getting the output. If *ppvContext is
  8698. // returned it must be freed by calling CertFreeCertificateContext or
  8699. // CertFreeCRLContext.
  8700. //--------------------------------------------------------------------------
  8701. WINCRYPT32API
  8702. BOOL
  8703. WINAPI
  8704. CertAddSerializedElementToStore(
  8705. IN HCERTSTORE hCertStore,
  8706. IN const BYTE *pbElement,
  8707. IN DWORD cbElement,
  8708. IN DWORD dwAddDisposition,
  8709. IN DWORD dwFlags,
  8710. IN DWORD dwContextTypeFlags,
  8711. OUT OPTIONAL DWORD *pdwContextType,
  8712. OUT OPTIONAL const void **ppvContext
  8713. );
  8714. //+-------------------------------------------------------------------------
  8715. // Delete the specified certificate from the store.
  8716. //
  8717. // All subsequent gets or finds for the certificate will fail. However,
  8718. // memory allocated for the certificate isn't freed until all of its contexts
  8719. // have also been freed.
  8720. //
  8721. // The pCertContext is obtained from a get, enum, find or duplicate.
  8722. //
  8723. // Some store provider implementations might also delete the issuer's CRLs
  8724. // if this is the last certificate for the issuer in the store.
  8725. //
  8726. // NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  8727. // this function, even for an error.
  8728. //--------------------------------------------------------------------------
  8729. WINCRYPT32API
  8730. BOOL
  8731. WINAPI
  8732. CertDeleteCertificateFromStore(
  8733. IN PCCERT_CONTEXT pCertContext
  8734. );
  8735. //+-------------------------------------------------------------------------
  8736. // Add the encoded CRL to the store according to the specified
  8737. // disposition option.
  8738. //
  8739. // Makes a copy of the encoded CRL before adding to the store.
  8740. //
  8741. // dwAddDispostion specifies the action to take if the CRL
  8742. // already exists in the store. See CertAddEncodedCertificateToStore for a
  8743. // list of and actions taken.
  8744. //
  8745. // Compares the CRL's Issuer to determine if the CRL already exists in the
  8746. // store.
  8747. //
  8748. // ppCrlContext can be NULL, indicating the caller isn't interested
  8749. // in getting the CRL_CONTEXT of the added or existing CRL.
  8750. //--------------------------------------------------------------------------
  8751. WINCRYPT32API
  8752. BOOL
  8753. WINAPI
  8754. CertAddEncodedCRLToStore(
  8755. IN HCERTSTORE hCertStore,
  8756. IN DWORD dwCertEncodingType,
  8757. IN const BYTE *pbCrlEncoded,
  8758. IN DWORD cbCrlEncoded,
  8759. IN DWORD dwAddDisposition,
  8760. OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  8761. );
  8762. //+-------------------------------------------------------------------------
  8763. // Add the CRL context to the store according to the specified
  8764. // disposition option.
  8765. //
  8766. // In addition to the encoded CRL, the context's properties are
  8767. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  8768. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  8769. //
  8770. // Makes a copy of the encoded CRL before adding to the store.
  8771. //
  8772. // dwAddDispostion specifies the action to take if the CRL
  8773. // already exists in the store. See CertAddCertificateContextToStore for a
  8774. // list of and actions taken.
  8775. //
  8776. // Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  8777. // if the CRL already exists in the store.
  8778. //
  8779. // ppStoreContext can be NULL, indicating the caller isn't interested
  8780. // in getting the CRL_CONTEXT of the added or existing CRL.
  8781. //--------------------------------------------------------------------------
  8782. WINCRYPT32API
  8783. BOOL
  8784. WINAPI
  8785. CertAddCRLContextToStore(
  8786. IN HCERTSTORE hCertStore,
  8787. IN PCCRL_CONTEXT pCrlContext,
  8788. IN DWORD dwAddDisposition,
  8789. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  8790. );
  8791. //+-------------------------------------------------------------------------
  8792. // Delete the specified CRL from the store.
  8793. //
  8794. // All subsequent gets for the CRL will fail. However,
  8795. // memory allocated for the CRL isn't freed until all of its contexts
  8796. // have also been freed.
  8797. //
  8798. // The pCrlContext is obtained from a get or duplicate.
  8799. //
  8800. // NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  8801. // this function, even for an error.
  8802. //--------------------------------------------------------------------------
  8803. WINCRYPT32API
  8804. BOOL
  8805. WINAPI
  8806. CertDeleteCRLFromStore(
  8807. IN PCCRL_CONTEXT pCrlContext
  8808. );
  8809. //+-------------------------------------------------------------------------
  8810. // Serialize the certificate context's encoded certificate and its
  8811. // properties.
  8812. //--------------------------------------------------------------------------
  8813. WINCRYPT32API
  8814. BOOL
  8815. WINAPI
  8816. CertSerializeCertificateStoreElement(
  8817. IN PCCERT_CONTEXT pCertContext,
  8818. IN DWORD dwFlags,
  8819. OUT BYTE *pbElement,
  8820. IN OUT DWORD *pcbElement
  8821. );
  8822. //+-------------------------------------------------------------------------
  8823. // Serialize the CRL context's encoded CRL and its properties.
  8824. //--------------------------------------------------------------------------
  8825. WINCRYPT32API
  8826. BOOL
  8827. WINAPI
  8828. CertSerializeCRLStoreElement(
  8829. IN PCCRL_CONTEXT pCrlContext,
  8830. IN DWORD dwFlags,
  8831. OUT BYTE *pbElement,
  8832. IN OUT DWORD *pcbElement
  8833. );
  8834. //+=========================================================================
  8835. // Certificate Trust List (CTL) Store Data Structures and APIs
  8836. //==========================================================================
  8837. //+-------------------------------------------------------------------------
  8838. // Duplicate a CTL context
  8839. //--------------------------------------------------------------------------
  8840. WINCRYPT32API
  8841. PCCTL_CONTEXT
  8842. WINAPI
  8843. CertDuplicateCTLContext(
  8844. IN PCCTL_CONTEXT pCtlContext
  8845. );
  8846. //+-------------------------------------------------------------------------
  8847. // Create a CTL context from the encoded CTL. The created
  8848. // context isn't put in a store.
  8849. //
  8850. // Makes a copy of the encoded CTL in the created context.
  8851. //
  8852. // If unable to decode and create the CTL context, NULL is returned.
  8853. // Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  8854. // CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  8855. // CertDuplicateCTLContext can be called to make a duplicate.
  8856. //
  8857. // CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  8858. // to store properties for the CTL.
  8859. //--------------------------------------------------------------------------
  8860. WINCRYPT32API
  8861. PCCTL_CONTEXT
  8862. WINAPI
  8863. CertCreateCTLContext(
  8864. IN DWORD dwMsgAndCertEncodingType,
  8865. IN const BYTE *pbCtlEncoded,
  8866. IN DWORD cbCtlEncoded
  8867. );
  8868. //+-------------------------------------------------------------------------
  8869. // Free a CTL context
  8870. //
  8871. // There needs to be a corresponding free for each context obtained by a
  8872. // get, duplicate or create.
  8873. //--------------------------------------------------------------------------
  8874. WINCRYPT32API
  8875. BOOL
  8876. WINAPI
  8877. CertFreeCTLContext(
  8878. IN PCCTL_CONTEXT pCtlContext
  8879. );
  8880. //+-------------------------------------------------------------------------
  8881. // Set the property for the specified CTL context.
  8882. //
  8883. // Same Property Ids and semantics as CertSetCertificateContextProperty.
  8884. //--------------------------------------------------------------------------
  8885. WINCRYPT32API
  8886. BOOL
  8887. WINAPI
  8888. CertSetCTLContextProperty(
  8889. IN PCCTL_CONTEXT pCtlContext,
  8890. IN DWORD dwPropId,
  8891. IN DWORD dwFlags,
  8892. IN const void *pvData
  8893. );
  8894. //+-------------------------------------------------------------------------
  8895. // Get the property for the specified CTL context.
  8896. //
  8897. // Same Property Ids and semantics as CertGetCertificateContextProperty.
  8898. //
  8899. // CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  8900. // predefined properties of most interest.
  8901. //--------------------------------------------------------------------------
  8902. WINCRYPT32API
  8903. BOOL
  8904. WINAPI
  8905. CertGetCTLContextProperty(
  8906. IN PCCTL_CONTEXT pCtlContext,
  8907. IN DWORD dwPropId,
  8908. OUT void *pvData,
  8909. IN OUT DWORD *pcbData
  8910. );
  8911. //+-------------------------------------------------------------------------
  8912. // Enumerate the properties for the specified CTL context.
  8913. //--------------------------------------------------------------------------
  8914. WINCRYPT32API
  8915. DWORD
  8916. WINAPI
  8917. CertEnumCTLContextProperties(
  8918. IN PCCTL_CONTEXT pCtlContext,
  8919. IN DWORD dwPropId
  8920. );
  8921. //+-------------------------------------------------------------------------
  8922. // Enumerate the CTL contexts in the store.
  8923. //
  8924. // If a CTL isn't found, NULL is returned.
  8925. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8926. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8927. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8928. // can be called to make a duplicate.
  8929. //
  8930. // pPrevCtlContext MUST BE NULL to enumerate the first
  8931. // CTL in the store. Successive CTLs are enumerated by setting
  8932. // pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  8933. //
  8934. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  8935. // this function, even for an error.
  8936. //--------------------------------------------------------------------------
  8937. WINCRYPT32API
  8938. PCCTL_CONTEXT
  8939. WINAPI
  8940. CertEnumCTLsInStore(
  8941. IN HCERTSTORE hCertStore,
  8942. IN PCCTL_CONTEXT pPrevCtlContext
  8943. );
  8944. //+-------------------------------------------------------------------------
  8945. // Attempt to find the specified subject in the CTL.
  8946. //
  8947. // For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  8948. // SubjectAlgorithm is examined to determine the representation of the
  8949. // subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  8950. // The appropriate hash property is obtained from the CERT_CONTEXT.
  8951. //
  8952. // For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  8953. // structure which contains the SubjectAlgorithm to be matched in the CTL
  8954. // and the SubjectIdentifer to be matched in one of the CTL entries.
  8955. //
  8956. // The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  8957. // is used as the key in searching the subject entries. A binary
  8958. // memory comparison is done between the key and the entry's SubjectIdentifer.
  8959. //
  8960. // dwEncodingType isn't used for either of the above SubjectTypes.
  8961. //--------------------------------------------------------------------------
  8962. WINCRYPT32API
  8963. PCTL_ENTRY
  8964. WINAPI
  8965. CertFindSubjectInCTL(
  8966. IN DWORD dwEncodingType,
  8967. IN DWORD dwSubjectType,
  8968. IN void *pvSubject,
  8969. IN PCCTL_CONTEXT pCtlContext,
  8970. IN DWORD dwFlags
  8971. );
  8972. // Subject Types:
  8973. // CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  8974. // CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  8975. #define CTL_ANY_SUBJECT_TYPE 1
  8976. #define CTL_CERT_SUBJECT_TYPE 2
  8977. typedef struct _CTL_ANY_SUBJECT_INFO {
  8978. CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
  8979. CRYPT_DATA_BLOB SubjectIdentifier;
  8980. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  8981. //+-------------------------------------------------------------------------
  8982. // Find the first or next CTL context in the store.
  8983. //
  8984. // The CTL is found according to the dwFindType and its pvFindPara.
  8985. // See below for a list of the find types and its parameters.
  8986. //
  8987. // Currently dwFindFlags isn't used and must be set to 0.
  8988. //
  8989. // Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  8990. //
  8991. // If the first or next CTL isn't found, NULL is returned.
  8992. // Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  8993. // must be freed by calling CertFreeCTLContext or is freed when passed as the
  8994. // pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  8995. // can be called to make a duplicate.
  8996. //
  8997. // pPrevCtlContext MUST BE NULL on the first
  8998. // call to find the CTL. To find the next CTL, the
  8999. // pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  9000. //
  9001. // NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  9002. // this function, even for an error.
  9003. //--------------------------------------------------------------------------
  9004. WINCRYPT32API
  9005. PCCTL_CONTEXT
  9006. WINAPI
  9007. CertFindCTLInStore(
  9008. IN HCERTSTORE hCertStore,
  9009. IN DWORD dwMsgAndCertEncodingType,
  9010. IN DWORD dwFindFlags,
  9011. IN DWORD dwFindType,
  9012. IN const void *pvFindPara,
  9013. IN PCCTL_CONTEXT pPrevCtlContext
  9014. );
  9015. #define CTL_FIND_ANY 0
  9016. #define CTL_FIND_SHA1_HASH 1
  9017. #define CTL_FIND_MD5_HASH 2
  9018. #define CTL_FIND_USAGE 3
  9019. #define CTL_FIND_SUBJECT 4
  9020. #define CTL_FIND_EXISTING 5
  9021. typedef struct _CTL_FIND_USAGE_PARA {
  9022. DWORD cbSize;
  9023. CTL_USAGE SubjectUsage; // optional
  9024. CRYPT_DATA_BLOB ListIdentifier; // optional
  9025. PCERT_INFO pSigner; // optional
  9026. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  9027. #define CTL_FIND_NO_LIST_ID_CBDATA 0xFFFFFFFF
  9028. #define CTL_FIND_NO_SIGNER_PTR ((PCERT_INFO) -1)
  9029. #define CTL_FIND_SAME_USAGE_FLAG 0x1
  9030. typedef struct _CTL_FIND_SUBJECT_PARA {
  9031. DWORD cbSize;
  9032. PCTL_FIND_USAGE_PARA pUsagePara; // optional
  9033. DWORD dwSubjectType;
  9034. void *pvSubject;
  9035. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  9036. //+-------------------------------------------------------------------------
  9037. // CTL_FIND_ANY
  9038. //
  9039. // Find any CTL.
  9040. //
  9041. // pvFindPara isn't used.
  9042. //--------------------------------------------------------------------------
  9043. //+-------------------------------------------------------------------------
  9044. // CTL_FIND_SHA1_HASH
  9045. // CTL_FIND_MD5_HASH
  9046. //
  9047. // Find a CTL with the specified hash.
  9048. //
  9049. // pvFindPara points to a CRYPT_HASH_BLOB.
  9050. //--------------------------------------------------------------------------
  9051. //+-------------------------------------------------------------------------
  9052. // CTL_FIND_USAGE
  9053. //
  9054. // Find a CTL having the specified usage identifiers, list identifier or
  9055. // signer. The CertEncodingType of the signer is obtained from the
  9056. // dwMsgAndCertEncodingType parameter.
  9057. //
  9058. // pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  9059. // SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  9060. // ListIdentifier.cbData can be 0 to match any list identifier. To only match
  9061. // CTLs without a ListIdentifier, cbData must be set to
  9062. // CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  9063. // the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  9064. // To only match CTLs without a signer, pSigner must be set to
  9065. // CTL_FIND_NO_SIGNER_PTR.
  9066. //
  9067. // The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  9068. // only match CTLs with the same usage identifiers. CTLs having additional
  9069. // usage identifiers aren't matched. For example, if only "1.2.3" is specified
  9070. // in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  9071. // "1.2.3" and not any additional usage identifers.
  9072. //--------------------------------------------------------------------------
  9073. //+-------------------------------------------------------------------------
  9074. // CTL_FIND_SUBJECT
  9075. //
  9076. // Find a CTL having the specified subject. CertFindSubjectInCTL can be
  9077. // called to get a pointer to the subject's entry in the CTL. pUsagePara can
  9078. // optionally be set to enable the above CTL_FIND_USAGE matching.
  9079. //
  9080. // pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  9081. //--------------------------------------------------------------------------
  9082. //+-------------------------------------------------------------------------
  9083. // Add the encoded CTL to the store according to the specified
  9084. // disposition option.
  9085. //
  9086. // Makes a copy of the encoded CTL before adding to the store.
  9087. //
  9088. // dwAddDispostion specifies the action to take if the CTL
  9089. // already exists in the store. See CertAddEncodedCertificateToStore for a
  9090. // list of and actions taken.
  9091. //
  9092. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9093. // to determine if the CTL already exists in the store.
  9094. //
  9095. // ppCtlContext can be NULL, indicating the caller isn't interested
  9096. // in getting the CTL_CONTEXT of the added or existing CTL.
  9097. //--------------------------------------------------------------------------
  9098. WINCRYPT32API
  9099. BOOL
  9100. WINAPI
  9101. CertAddEncodedCTLToStore(
  9102. IN HCERTSTORE hCertStore,
  9103. IN DWORD dwMsgAndCertEncodingType,
  9104. IN const BYTE *pbCtlEncoded,
  9105. IN DWORD cbCtlEncoded,
  9106. IN DWORD dwAddDisposition,
  9107. OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  9108. );
  9109. //+-------------------------------------------------------------------------
  9110. // Add the CTL context to the store according to the specified
  9111. // disposition option.
  9112. //
  9113. // In addition to the encoded CTL, the context's properties are
  9114. // also copied. Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  9115. // CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  9116. //
  9117. // Makes a copy of the encoded CTL before adding to the store.
  9118. //
  9119. // dwAddDispostion specifies the action to take if the CTL
  9120. // already exists in the store. See CertAddCertificateContextToStore for a
  9121. // list of and actions taken.
  9122. //
  9123. // Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  9124. // to determine if the CTL already exists in the store.
  9125. //
  9126. // ppStoreContext can be NULL, indicating the caller isn't interested
  9127. // in getting the CTL_CONTEXT of the added or existing CTL.
  9128. //--------------------------------------------------------------------------
  9129. WINCRYPT32API
  9130. BOOL
  9131. WINAPI
  9132. CertAddCTLContextToStore(
  9133. IN HCERTSTORE hCertStore,
  9134. IN PCCTL_CONTEXT pCtlContext,
  9135. IN DWORD dwAddDisposition,
  9136. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9137. );
  9138. //+-------------------------------------------------------------------------
  9139. // Serialize the CTL context's encoded CTL and its properties.
  9140. //--------------------------------------------------------------------------
  9141. WINCRYPT32API
  9142. BOOL
  9143. WINAPI
  9144. CertSerializeCTLStoreElement(
  9145. IN PCCTL_CONTEXT pCtlContext,
  9146. IN DWORD dwFlags,
  9147. OUT BYTE *pbElement,
  9148. IN OUT DWORD *pcbElement
  9149. );
  9150. //+-------------------------------------------------------------------------
  9151. // Delete the specified CTL from the store.
  9152. //
  9153. // All subsequent gets for the CTL will fail. However,
  9154. // memory allocated for the CTL isn't freed until all of its contexts
  9155. // have also been freed.
  9156. //
  9157. // The pCtlContext is obtained from a get or duplicate.
  9158. //
  9159. // NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  9160. // this function, even for an error.
  9161. //--------------------------------------------------------------------------
  9162. WINCRYPT32API
  9163. BOOL
  9164. WINAPI
  9165. CertDeleteCTLFromStore(
  9166. IN PCCTL_CONTEXT pCtlContext
  9167. );
  9168. WINCRYPT32API
  9169. BOOL
  9170. WINAPI
  9171. CertAddCertificateLinkToStore(
  9172. IN HCERTSTORE hCertStore,
  9173. IN PCCERT_CONTEXT pCertContext,
  9174. IN DWORD dwAddDisposition,
  9175. OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  9176. );
  9177. WINCRYPT32API
  9178. BOOL
  9179. WINAPI
  9180. CertAddCRLLinkToStore(
  9181. IN HCERTSTORE hCertStore,
  9182. IN PCCRL_CONTEXT pCrlContext,
  9183. IN DWORD dwAddDisposition,
  9184. OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  9185. );
  9186. WINCRYPT32API
  9187. BOOL
  9188. WINAPI
  9189. CertAddCTLLinkToStore(
  9190. IN HCERTSTORE hCertStore,
  9191. IN PCCTL_CONTEXT pCtlContext,
  9192. IN DWORD dwAddDisposition,
  9193. OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  9194. );
  9195. WINCRYPT32API
  9196. BOOL
  9197. WINAPI
  9198. CertAddStoreToCollection(
  9199. IN HCERTSTORE hCollectionStore,
  9200. IN OPTIONAL HCERTSTORE hSiblingStore,
  9201. IN DWORD dwUpdateFlags,
  9202. IN DWORD dwPriority
  9203. );
  9204. WINCRYPT32API
  9205. void
  9206. WINAPI
  9207. CertRemoveStoreFromCollection(
  9208. IN HCERTSTORE hCollectionStore,
  9209. IN HCERTSTORE hSiblingStore
  9210. );
  9211. WINCRYPT32API
  9212. BOOL
  9213. WINAPI
  9214. CertControlStore(
  9215. IN HCERTSTORE hCertStore,
  9216. IN DWORD dwFlags,
  9217. IN DWORD dwCtrlType,
  9218. IN void const *pvCtrlPara
  9219. );
  9220. //+-------------------------------------------------------------------------
  9221. // Certificate Store control types
  9222. //--------------------------------------------------------------------------
  9223. #define CERT_STORE_CTRL_RESYNC 1
  9224. #define CERT_STORE_CTRL_NOTIFY_CHANGE 2
  9225. #define CERT_STORE_CTRL_COMMIT 3
  9226. #define CERT_STORE_CTRL_AUTO_RESYNC 4
  9227. #define CERT_STORE_CTRL_CANCEL_NOTIFY 5
  9228. #define CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG 0x1
  9229. //+-------------------------------------------------------------------------
  9230. // CERT_STORE_CTRL_RESYNC
  9231. //
  9232. // Re-synchronize the store.
  9233. //
  9234. // The pvCtrlPara points to the event HANDLE to be signaled on
  9235. // the next store change. Normally, this would be the same
  9236. // event HANDLE passed to CERT_STORE_CTRL_NOTIFY_CHANGE during initialization.
  9237. //
  9238. // If pvCtrlPara is NULL, no events are re-armed.
  9239. //
  9240. // By default the event HANDLE is DuplicateHandle'd.
  9241. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9242. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9243. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9244. // called for this event HANDLE before closing the hCertStore.
  9245. //--------------------------------------------------------------------------
  9246. //+-------------------------------------------------------------------------
  9247. // CERT_STORE_CTRL_NOTIFY_CHANGE
  9248. //
  9249. // Signal the event when the underlying store is changed.
  9250. //
  9251. // pvCtrlPara points to the event HANDLE to be signaled.
  9252. //
  9253. // pvCtrlPara can be NULL to inform the store of a subsequent
  9254. // CERT_STORE_CTRL_RESYNC and allow it to optimize by only doing a resync
  9255. // if the store has changed. For the registry based stores, an internal
  9256. // notify change event is created and registered to be signaled.
  9257. //
  9258. // Recommend calling CERT_STORE_CTRL_NOTIFY_CHANGE once for each event to
  9259. // be passed to CERT_STORE_CTRL_RESYNC. This should only happen after
  9260. // the event has been created. Not after each time the event is signaled.
  9261. //
  9262. // By default the event HANDLE is DuplicateHandle'd.
  9263. // CERT_STORE_CTRL_INHIBIT_DUPLICATE_HANDLE_FLAG can be set in dwFlags
  9264. // to inhibit a DupicateHandle of the event HANDLE. If this flag
  9265. // is set, then, CertControlStore(CERT_STORE_CTRL_CANCEL_NOTIFY) must be
  9266. // called for this event HANDLE before closing the hCertStore.
  9267. //--------------------------------------------------------------------------
  9268. //+-------------------------------------------------------------------------
  9269. // CERT_STORE_CTRL_CANCEL_NOTIFY
  9270. //
  9271. // Cancel notification signaling of the event HANDLE passed in a previous
  9272. // CERT_STORE_CTRL_NOTIFY_CHANGE or CERT_STORE_CTRL_RESYNC.
  9273. //
  9274. // pvCtrlPara points to the event HANDLE to be canceled.
  9275. //--------------------------------------------------------------------------
  9276. //+-------------------------------------------------------------------------
  9277. // CERT_STORE_CTRL_AUTO_RESYNC
  9278. //
  9279. // At the start of every enumeration or find store API call, check if the
  9280. // underlying store has changed. If it has changed, re-synchronize.
  9281. //
  9282. // This check is only done in the enumeration or find APIs when the
  9283. // pPrevContext is NULL.
  9284. //
  9285. // The pvCtrlPara isn't used and must be set to NULL.
  9286. //--------------------------------------------------------------------------
  9287. //+-------------------------------------------------------------------------
  9288. // CERT_STORE_CTRL_COMMIT
  9289. //
  9290. // If any changes have been to the cached store, they are committed to
  9291. // persisted storage. If no changes have been made since the store was
  9292. // opened or the last commit, this call is ignored. May also be ignored by
  9293. // store providers that persist changes immediately.
  9294. //
  9295. // CERT_STORE_CTRL_COMMIT_FORCE_FLAG can be set to force the store
  9296. // to be committed even if it hasn't been touched.
  9297. //
  9298. // CERT_STORE_CTRL_COMMIT_CLEAR_FLAG can be set to inhibit a commit on
  9299. // store close.
  9300. //--------------------------------------------------------------------------
  9301. #define CERT_STORE_CTRL_COMMIT_FORCE_FLAG 0x1
  9302. #define CERT_STORE_CTRL_COMMIT_CLEAR_FLAG 0x2
  9303. //+=========================================================================
  9304. // Cert Store Property Defines and APIs
  9305. //==========================================================================
  9306. //+-------------------------------------------------------------------------
  9307. // Store property IDs. This is a property applicable to the entire store.
  9308. // Its not a property on an individual certificate, CRL or CTL context.
  9309. //
  9310. // Currently, no store properties are persisted. (This differs from
  9311. // most context properties which are persisted.)
  9312. //
  9313. // See CertSetStoreProperty or CertGetStoreProperty for usage information.
  9314. //
  9315. // Note, the range for predefined store properties should be outside
  9316. // the range of predefined context properties. We will start at 4096.
  9317. //--------------------------------------------------------------------------
  9318. #define CERT_STORE_LOCALIZED_NAME_PROP_ID 0x1000
  9319. //+-------------------------------------------------------------------------
  9320. // Set a store property.
  9321. //
  9322. // The type definition for pvData depends on the dwPropId value.
  9323. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9324. // pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  9325. // terminated unicode, wide character string.
  9326. // cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  9327. //
  9328. // For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  9329. //
  9330. // If the property already exists, then, the old value is deleted and silently
  9331. // replaced. Setting, pvData to NULL, deletes the property.
  9332. //--------------------------------------------------------------------------
  9333. WINCRYPT32API
  9334. BOOL
  9335. WINAPI
  9336. CertSetStoreProperty(
  9337. IN HCERTSTORE hCertStore,
  9338. IN DWORD dwPropId,
  9339. IN DWORD dwFlags,
  9340. IN const void *pvData
  9341. );
  9342. //+-------------------------------------------------------------------------
  9343. // Get a store property.
  9344. //
  9345. // The type definition for pvData depends on the dwPropId value.
  9346. // CERT_STORE_LOCALIZED_NAME_PROP_ID - localized name of the store.
  9347. // pvData points to a NULL terminated unicode, wide character string.
  9348. // cbData = (wcslen((LPWSTR) pvData) + 1) * sizeof(WCHAR).
  9349. //
  9350. // For all other PROP_IDs, pvData points to an array of bytes.
  9351. //
  9352. // If the property doesn't exist, returns FALSE and sets LastError to
  9353. // CRYPT_E_NOT_FOUND.
  9354. //--------------------------------------------------------------------------
  9355. WINCRYPT32API
  9356. BOOL
  9357. WINAPI
  9358. CertGetStoreProperty(
  9359. IN HCERTSTORE hCertStore,
  9360. IN DWORD dwPropId,
  9361. OUT void *pvData,
  9362. IN OUT DWORD *pcbData
  9363. );
  9364. typedef struct _CERT_CREATE_CONTEXT_PARA {
  9365. DWORD cbSize;
  9366. PFN_CRYPT_FREE pfnFree; // OPTIONAL
  9367. void *pvFree; // OPTIONAL
  9368. } CERT_CREATE_CONTEXT_PARA, *PCERT_CREATE_CONTEXT_PARA;
  9369. //+-------------------------------------------------------------------------
  9370. // Creates the specified context from the encoded bytes. The created
  9371. // context isn't put in a store.
  9372. //
  9373. // dwContextType values:
  9374. // CERT_STORE_CERTIFICATE_CONTEXT
  9375. // CERT_STORE_CRL_CONTEXT
  9376. // CERT_STORE_CTL_CONTEXT
  9377. //
  9378. // If CERT_CREATE_CONTEXT_NOCOPY_FLAG is set, the created context points
  9379. // directly to the pbEncoded instead of an allocated copy. See flag
  9380. // definition for more details.
  9381. //
  9382. // If CERT_CREATE_CONTEXT_SORTED_FLAG is set, the context is created
  9383. // with sorted entries. This flag may only be set for CERT_STORE_CTL_CONTEXT.
  9384. // Setting this flag implicitly sets CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG and
  9385. // CERT_CREATE_CONTEXT_NO_ENTRY_FLAG. See flag definition for
  9386. // more details.
  9387. //
  9388. // If CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG is set, the context is created
  9389. // without creating a HCRYPTMSG handle for the context. This flag may only be
  9390. // set for CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9391. //
  9392. // If CERT_CREATE_CONTEXT_NO_ENTRY_FLAG is set, the context is created
  9393. // without decoding the entries. This flag may only be set for
  9394. // CERT_STORE_CTL_CONTEXT. See flag definition for more details.
  9395. //
  9396. // If unable to decode and create the context, NULL is returned.
  9397. // Otherwise, a pointer to a read only CERT_CONTEXT, CRL_CONTEXT or
  9398. // CTL_CONTEXT is returned. The context must be freed by the appropriate
  9399. // free context API. The context can be duplicated by calling the
  9400. // appropriate duplicate context API.
  9401. //--------------------------------------------------------------------------
  9402. WINCRYPT32API
  9403. const void *
  9404. WINAPI
  9405. CertCreateContext(
  9406. IN DWORD dwContextType,
  9407. IN DWORD dwEncodingType,
  9408. IN const BYTE *pbEncoded,
  9409. IN DWORD cbEncoded,
  9410. IN DWORD dwFlags,
  9411. IN OPTIONAL PCERT_CREATE_CONTEXT_PARA pCreatePara
  9412. );
  9413. // When the following flag is set, the created context points directly to the
  9414. // pbEncoded instead of an allocated copy. If pCreatePara and
  9415. // pCreatePara->pfnFree are non-NULL, then, pfnFree is called to free
  9416. // the pbEncoded when the context is last freed. Otherwise, no attempt is
  9417. // made to free the pbEncoded. If pCreatePara->pvFree is non-NULL, then its
  9418. // passed to pfnFree instead of pbEncoded.
  9419. //
  9420. // Note, if CertCreateContext fails, pfnFree is still called.
  9421. #define CERT_CREATE_CONTEXT_NOCOPY_FLAG 0x1
  9422. // When the following flag is set, a context with sorted entries is created.
  9423. // Currently only applicable to a CTL context.
  9424. //
  9425. // For CTLs: the cCTLEntry in the returned CTL_INFO is always
  9426. // 0. CertFindSubjectInSortedCTL and CertEnumSubjectInSortedCTL must be called
  9427. // to find or enumerate the CTL entries.
  9428. //
  9429. // The Sorted CTL TrustedSubjects extension isn't returned in the created
  9430. // context's CTL_INFO.
  9431. #define CERT_CREATE_CONTEXT_SORTED_FLAG 0x2
  9432. // By default when a CTL context is created, a HCRYPTMSG handle to its
  9433. // SignedData message is created. This flag can be set to improve performance
  9434. // by not creating the HCRYPTMSG handle.
  9435. //
  9436. // This flag is only applicable to a CTL context.
  9437. #define CERT_CREATE_CONTEXT_NO_HCRYPTMSG_FLAG 0x4
  9438. // By default when a CTL context is created, its entries are decoded.
  9439. // This flag can be set to improve performance by not decoding the
  9440. // entries.
  9441. //
  9442. // This flag is only applicable to a CTL context.
  9443. #define CERT_CREATE_CONTEXT_NO_ENTRY_FLAG 0x8
  9444. //+=========================================================================
  9445. // Certificate System Store Data Structures and APIs
  9446. //==========================================================================
  9447. //+-------------------------------------------------------------------------
  9448. // System Store Information
  9449. //
  9450. // Currently, no system store information is persisted.
  9451. //--------------------------------------------------------------------------
  9452. typedef struct _CERT_SYSTEM_STORE_INFO {
  9453. DWORD cbSize;
  9454. } CERT_SYSTEM_STORE_INFO, *PCERT_SYSTEM_STORE_INFO;
  9455. //+-------------------------------------------------------------------------
  9456. // Physical Store Information
  9457. //
  9458. // The Open fields are passed directly to CertOpenStore() to open
  9459. // the physical store.
  9460. //
  9461. // By default all system stores located in the registry have an
  9462. // implicit SystemRegistry physical store that is opened. To disable the
  9463. // opening of this store, the SystemRegistry
  9464. // physical store corresponding to the System store must be registered with
  9465. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags. Alternatively,
  9466. // a physical store with the name of ".Default" may be registered.
  9467. //
  9468. // Depending on the store location and store name, additional predefined
  9469. // physical stores may be opened. For example, system stores in
  9470. // CURRENT_USER have the predefined physical store, .LocalMachine.
  9471. // To disable the opening of these predefined physical stores, the
  9472. // corresponding physical store must be registered with
  9473. // CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG set in dwFlags.
  9474. //
  9475. // The CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG must be set in dwFlags
  9476. // to enable the adding of a context to the store.
  9477. //
  9478. // When a system store is opened via the SERVICES or USERS store location,
  9479. // the ServiceName\ is prepended to the OpenParameters
  9480. // for CERT_SYSTEM_STORE_CURRENT_USER or CERT_SYSTEM_STORE_CURRENT_SERVICE
  9481. // physical stores and the dwOpenFlags store location is changed to
  9482. // CERT_SYSTEM_STORE_USERS or CERT_SYSTEM_STORE_SERVICES.
  9483. //
  9484. // By default the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider
  9485. // stores are also opened remotely when the outer system store is opened.
  9486. // The CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG may be set in dwFlags
  9487. // to disable remote opens.
  9488. //
  9489. // When opened remotely, the \\ComputerName is implicitly prepended to the
  9490. // OpenParameters for the SYSTEM, SYSTEM_REGISTRY and PHYSICAL provider types.
  9491. // To also prepend the \\ComputerName to other provider types, set the
  9492. // CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG in dwFlags.
  9493. //
  9494. // When the system store is opened, its physical stores are ordered
  9495. // according to the dwPriority. A larger dwPriority indicates higher priority.
  9496. //--------------------------------------------------------------------------
  9497. typedef struct _CERT_PHYSICAL_STORE_INFO {
  9498. DWORD cbSize;
  9499. LPSTR pszOpenStoreProvider; // REG_SZ
  9500. DWORD dwOpenEncodingType; // REG_DWORD
  9501. DWORD dwOpenFlags; // REG_DWORD
  9502. CRYPT_DATA_BLOB OpenParameters; // REG_BINARY
  9503. DWORD dwFlags; // REG_DWORD
  9504. DWORD dwPriority; // REG_DWORD
  9505. } CERT_PHYSICAL_STORE_INFO, *PCERT_PHYSICAL_STORE_INFO;
  9506. //+-------------------------------------------------------------------------
  9507. // Physical Store Information dwFlags
  9508. //--------------------------------------------------------------------------
  9509. #define CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG 0x1
  9510. #define CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG 0x2
  9511. #define CERT_PHYSICAL_STORE_REMOTE_OPEN_DISABLE_FLAG 0x4
  9512. #define CERT_PHYSICAL_STORE_INSERT_COMPUTER_NAME_ENABLE_FLAG 0x8
  9513. //+-------------------------------------------------------------------------
  9514. // Register a system store.
  9515. //
  9516. // The upper word of the dwFlags parameter is used to specify the location of
  9517. // the system store.
  9518. //
  9519. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9520. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9521. // pvSystemStore points to a null terminated UNICODE string.
  9522. //
  9523. // The CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS system store
  9524. // name must be prefixed with the ServiceName or UserName. For example,
  9525. // "ServiceName\Trust".
  9526. //
  9527. // Stores on remote computers can be registered for the
  9528. // CERT_SYSTEM_STORE_LOCAL_MACHINE, CERT_SYSTEM_STORE_SERVICES,
  9529. // CERT_SYSTEM_STORE_USERS, CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY
  9530. // or CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE
  9531. // locations by prepending the computer name. For example, a remote
  9532. // local machine store is registered via "\\ComputerName\Trust" or
  9533. // "ComputerName\Trust". A remote service store is registered via
  9534. // "\\ComputerName\ServiceName\Trust". The leading "\\" backslashes are
  9535. // optional in the ComputerName.
  9536. //
  9537. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the system store
  9538. // already exists in the store location.
  9539. //--------------------------------------------------------------------------
  9540. WINCRYPT32API
  9541. BOOL
  9542. WINAPI
  9543. CertRegisterSystemStore(
  9544. IN const void *pvSystemStore,
  9545. IN DWORD dwFlags,
  9546. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9547. IN OPTIONAL void *pvReserved
  9548. );
  9549. //+-------------------------------------------------------------------------
  9550. // Register a physical store for the specified system store.
  9551. //
  9552. // The upper word of the dwFlags parameter is used to specify the location of
  9553. // the system store.
  9554. //
  9555. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9556. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9557. // pvSystemStore points to a null terminated UNICODE string.
  9558. //
  9559. // See CertRegisterSystemStore for details on prepending a ServiceName
  9560. // and/or ComputerName to the system store name.
  9561. //
  9562. // Set CERT_STORE_CREATE_NEW_FLAG to cause a failure if the physical store
  9563. // already exists in the system store.
  9564. //--------------------------------------------------------------------------
  9565. WINCRYPT32API
  9566. BOOL
  9567. WINAPI
  9568. CertRegisterPhysicalStore(
  9569. IN const void *pvSystemStore,
  9570. IN DWORD dwFlags,
  9571. IN LPCWSTR pwszStoreName,
  9572. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9573. IN OPTIONAL void *pvReserved
  9574. );
  9575. //+-------------------------------------------------------------------------
  9576. // Unregister the specified system store.
  9577. //
  9578. // The upper word of the dwFlags parameter is used to specify the location of
  9579. // the system store.
  9580. //
  9581. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9582. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9583. // pvSystemStore points to a null terminated UNICODE string.
  9584. //
  9585. // See CertRegisterSystemStore for details on prepending a ServiceName
  9586. // and/or ComputerName to the system store name.
  9587. //
  9588. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9589. //--------------------------------------------------------------------------
  9590. WINCRYPT32API
  9591. BOOL
  9592. WINAPI
  9593. CertUnregisterSystemStore(
  9594. IN const void *pvSystemStore,
  9595. IN DWORD dwFlags
  9596. );
  9597. //+-------------------------------------------------------------------------
  9598. // Unregister the physical store from the specified system store.
  9599. //
  9600. // The upper word of the dwFlags parameter is used to specify the location of
  9601. // the system store.
  9602. //
  9603. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9604. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9605. // pvSystemStore points to a null terminated UNICODE string.
  9606. //
  9607. // See CertRegisterSystemStore for details on prepending a ServiceName
  9608. // and/or ComputerName to the system store name.
  9609. //
  9610. // CERT_STORE_DELETE_FLAG can optionally be set in dwFlags.
  9611. //--------------------------------------------------------------------------
  9612. WINCRYPT32API
  9613. BOOL
  9614. WINAPI
  9615. CertUnregisterPhysicalStore(
  9616. IN const void *pvSystemStore,
  9617. IN DWORD dwFlags,
  9618. IN LPCWSTR pwszStoreName
  9619. );
  9620. //+-------------------------------------------------------------------------
  9621. // Enum callbacks
  9622. //
  9623. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter
  9624. // specifies the location of the system store
  9625. //
  9626. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9627. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9628. // pvSystemStore points to a null terminated UNICODE string.
  9629. //
  9630. // The callback returns FALSE and sets LAST_ERROR to stop the enumeration.
  9631. // The LAST_ERROR is returned to the caller of the enumeration.
  9632. //
  9633. // The pvSystemStore passed to the callback has leading ComputerName and/or
  9634. // ServiceName prefixes where appropriate.
  9635. //--------------------------------------------------------------------------
  9636. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE_LOCATION)(
  9637. IN LPCWSTR pwszStoreLocation,
  9638. IN DWORD dwFlags,
  9639. IN OPTIONAL void *pvReserved,
  9640. IN OPTIONAL void *pvArg
  9641. );
  9642. typedef BOOL (WINAPI *PFN_CERT_ENUM_SYSTEM_STORE)(
  9643. IN const void *pvSystemStore,
  9644. IN DWORD dwFlags,
  9645. IN PCERT_SYSTEM_STORE_INFO pStoreInfo,
  9646. IN OPTIONAL void *pvReserved,
  9647. IN OPTIONAL void *pvArg
  9648. );
  9649. typedef BOOL (WINAPI *PFN_CERT_ENUM_PHYSICAL_STORE)(
  9650. IN const void *pvSystemStore,
  9651. IN DWORD dwFlags,
  9652. IN LPCWSTR pwszStoreName,
  9653. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  9654. IN OPTIONAL void *pvReserved,
  9655. IN OPTIONAL void *pvArg
  9656. );
  9657. // In the PFN_CERT_ENUM_PHYSICAL_STORE callback the following flag is
  9658. // set if the physical store wasn't registered and is an implicitly created
  9659. // predefined physical store.
  9660. #define CERT_PHYSICAL_STORE_PREDEFINED_ENUM_FLAG 0x1
  9661. // Names of implicitly created predefined physical stores
  9662. #define CERT_PHYSICAL_STORE_DEFAULT_NAME L".Default"
  9663. #define CERT_PHYSICAL_STORE_GROUP_POLICY_NAME L".GroupPolicy"
  9664. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_NAME L".LocalMachine"
  9665. #define CERT_PHYSICAL_STORE_DS_USER_CERTIFICATE_NAME L".UserCertificate"
  9666. #define CERT_PHYSICAL_STORE_LOCAL_MACHINE_GROUP_POLICY_NAME \
  9667. L".LocalMachineGroupPolicy"
  9668. #define CERT_PHYSICAL_STORE_ENTERPRISE_NAME L".Enterprise"
  9669. #define CERT_PHYSICAL_STORE_AUTH_ROOT_NAME L".AuthRoot"
  9670. //+-------------------------------------------------------------------------
  9671. // Enumerate the system store locations.
  9672. //--------------------------------------------------------------------------
  9673. WINCRYPT32API
  9674. BOOL
  9675. WINAPI
  9676. CertEnumSystemStoreLocation(
  9677. IN DWORD dwFlags,
  9678. IN void *pvArg,
  9679. IN PFN_CERT_ENUM_SYSTEM_STORE_LOCATION pfnEnum
  9680. );
  9681. //+-------------------------------------------------------------------------
  9682. // Enumerate the system stores.
  9683. //
  9684. // The upper word of the dwFlags parameter is used to specify the location of
  9685. // the system store.
  9686. //
  9687. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags,
  9688. // pvSystemStoreLocationPara points to a CERT_SYSTEM_STORE_RELOCATE_PARA
  9689. // data structure. Otherwise, pvSystemStoreLocationPara points to a null
  9690. // terminated UNICODE string.
  9691. //
  9692. // For CERT_SYSTEM_STORE_LOCAL_MACHINE,
  9693. // CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY or
  9694. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, pvSystemStoreLocationPara can
  9695. // optionally be set to a unicode computer name for enumerating local machine
  9696. // stores on a remote computer. For example, "\\ComputerName" or
  9697. // "ComputerName". The leading "\\" backslashes are optional in the
  9698. // ComputerName.
  9699. //
  9700. // For CERT_SYSTEM_STORE_SERVICES or CERT_SYSTEM_STORE_USERS,
  9701. // if pvSystemStoreLocationPara is NULL, then,
  9702. // enumerates both the service/user names and the stores for each service/user
  9703. // name. Otherwise, pvSystemStoreLocationPara is a unicode string specifying a
  9704. // remote computer name and/or service/user name. For example:
  9705. // "ServiceName"
  9706. // "\\ComputerName" or "ComputerName\"
  9707. // "ComputerName\ServiceName"
  9708. // Note, if only the ComputerName is specified, then, it must have either
  9709. // the leading "\\" backslashes or a trailing backslash. Otherwise, its
  9710. // interpretted as the ServiceName or UserName.
  9711. //--------------------------------------------------------------------------
  9712. WINCRYPT32API
  9713. BOOL
  9714. WINAPI
  9715. CertEnumSystemStore(
  9716. IN DWORD dwFlags,
  9717. IN OPTIONAL void *pvSystemStoreLocationPara,
  9718. IN void *pvArg,
  9719. IN PFN_CERT_ENUM_SYSTEM_STORE pfnEnum
  9720. );
  9721. //+-------------------------------------------------------------------------
  9722. // Enumerate the physical stores for the specified system store.
  9723. //
  9724. // The upper word of the dwFlags parameter is used to specify the location of
  9725. // the system store.
  9726. //
  9727. // If CERT_SYSTEM_STORE_RELOCATE_FLAG is set in dwFlags, pvSystemStore
  9728. // points to a CERT_SYSTEM_STORE_RELOCATE_PARA data structure. Otherwise,
  9729. // pvSystemStore points to a null terminated UNICODE string.
  9730. //
  9731. // See CertRegisterSystemStore for details on prepending a ServiceName
  9732. // and/or ComputerName to the system store name.
  9733. //
  9734. // If the system store location only supports system stores and doesn't
  9735. // support physical stores, LastError is set to ERROR_CALL_NOT_IMPLEMENTED.
  9736. //--------------------------------------------------------------------------
  9737. WINCRYPT32API
  9738. BOOL
  9739. WINAPI
  9740. CertEnumPhysicalStore(
  9741. IN const void *pvSystemStore,
  9742. IN DWORD dwFlags,
  9743. IN void *pvArg,
  9744. IN PFN_CERT_ENUM_PHYSICAL_STORE pfnEnum
  9745. );
  9746. //+-------------------------------------------------------------------------
  9747. // Certificate System Store Installable Functions
  9748. //
  9749. // The CERT_SYSTEM_STORE_LOCATION_MASK bits in the dwFlags parameter passed
  9750. // to the CertOpenStore(for "System", "SystemRegistry" or "Physical"
  9751. // Provider), CertRegisterSystemStore,
  9752. // CertUnregisterSystemStore, CertEnumSystemStore, CertRegisterPhysicalStore,
  9753. // CertUnregisterPhysicalStore and CertEnumPhysicalStore APIs is used as the
  9754. // constant pszOID value passed to the OID installable functions.
  9755. // Therefore, the pszOID is restricted to a constant <= (LPCSTR) 0x0FFF.
  9756. //
  9757. // The EncodingType is 0.
  9758. //--------------------------------------------------------------------------
  9759. // Installable System Store Provider OID pszFuncNames.
  9760. #define CRYPT_OID_OPEN_SYSTEM_STORE_PROV_FUNC "CertDllOpenSystemStoreProv"
  9761. #define CRYPT_OID_REGISTER_SYSTEM_STORE_FUNC "CertDllRegisterSystemStore"
  9762. #define CRYPT_OID_UNREGISTER_SYSTEM_STORE_FUNC "CertDllUnregisterSystemStore"
  9763. #define CRYPT_OID_ENUM_SYSTEM_STORE_FUNC "CertDllEnumSystemStore"
  9764. #define CRYPT_OID_REGISTER_PHYSICAL_STORE_FUNC "CertDllRegisterPhysicalStore"
  9765. #define CRYPT_OID_UNREGISTER_PHYSICAL_STORE_FUNC "CertDllUnregisterPhysicalStore"
  9766. #define CRYPT_OID_ENUM_PHYSICAL_STORE_FUNC "CertDllEnumPhysicalStore"
  9767. // CertDllOpenSystemStoreProv has the same function signature as the
  9768. // installable "CertDllOpenStoreProv" function. See CertOpenStore for
  9769. // more details.
  9770. // CertDllRegisterSystemStore has the same function signature as
  9771. // CertRegisterSystemStore.
  9772. //
  9773. // The "SystemStoreLocation" REG_SZ value must also be set for registered
  9774. // CertDllEnumSystemStore OID functions.
  9775. #define CRYPT_OID_SYSTEM_STORE_LOCATION_VALUE_NAME L"SystemStoreLocation"
  9776. // The remaining Register, Enum and Unregister OID installable functions
  9777. // have the same signature as their Cert Store API counterpart.
  9778. //+=========================================================================
  9779. // Enhanced Key Usage Helper Functions
  9780. //==========================================================================
  9781. //+-------------------------------------------------------------------------
  9782. // Get the enhanced key usage extension or property from the certificate
  9783. // and decode.
  9784. //
  9785. // If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9786. // extension.
  9787. //
  9788. // If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  9789. // property.
  9790. //--------------------------------------------------------------------------
  9791. WINCRYPT32API
  9792. BOOL
  9793. WINAPI
  9794. CertGetEnhancedKeyUsage(
  9795. IN PCCERT_CONTEXT pCertContext,
  9796. IN DWORD dwFlags,
  9797. OUT PCERT_ENHKEY_USAGE pUsage,
  9798. IN OUT DWORD *pcbUsage
  9799. );
  9800. //+-------------------------------------------------------------------------
  9801. // Set the enhanced key usage property for the certificate.
  9802. //--------------------------------------------------------------------------
  9803. WINCRYPT32API
  9804. BOOL
  9805. WINAPI
  9806. CertSetEnhancedKeyUsage(
  9807. IN PCCERT_CONTEXT pCertContext,
  9808. IN PCERT_ENHKEY_USAGE pUsage
  9809. );
  9810. //+-------------------------------------------------------------------------
  9811. // Add the usage identifier to the certificate's enhanced key usage property.
  9812. //--------------------------------------------------------------------------
  9813. WINCRYPT32API
  9814. BOOL
  9815. WINAPI
  9816. CertAddEnhancedKeyUsageIdentifier(
  9817. IN PCCERT_CONTEXT pCertContext,
  9818. IN LPCSTR pszUsageIdentifier
  9819. );
  9820. //+-------------------------------------------------------------------------
  9821. // Remove the usage identifier from the certificate's enhanced key usage
  9822. // property.
  9823. //--------------------------------------------------------------------------
  9824. WINCRYPT32API
  9825. BOOL
  9826. WINAPI
  9827. CertRemoveEnhancedKeyUsageIdentifier(
  9828. IN PCCERT_CONTEXT pCertContext,
  9829. IN LPCSTR pszUsageIdentifier
  9830. );
  9831. //+---------------------------------------------------------------------------
  9832. //
  9833. //
  9834. // Takes an array of certs and returns an array of usages
  9835. // which consists of the intersection of the valid usages for each cert.
  9836. // If each cert is good for all possible usages then the cNumOIDs is set to -1.
  9837. //
  9838. //----------------------------------------------------------------------------
  9839. WINCRYPT32API
  9840. BOOL
  9841. WINAPI
  9842. CertGetValidUsages(
  9843. IN DWORD cCerts,
  9844. IN PCCERT_CONTEXT *rghCerts,
  9845. OUT int *cNumOIDs,
  9846. OUT LPSTR *rghOIDs,
  9847. IN OUT DWORD *pcbOIDs);
  9848. //+=========================================================================
  9849. // Cryptographic Message helper functions for verifying and signing a
  9850. // CTL.
  9851. //==========================================================================
  9852. //+-------------------------------------------------------------------------
  9853. // Get and verify the signer of a cryptographic message.
  9854. //
  9855. // To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  9856. // hCryptMsg field.
  9857. //
  9858. // If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  9859. // trusted and only search them to find the certificate corresponding to the
  9860. // signer's issuer and serial number. Otherwise, the SignerStores are
  9861. // optionally provided to supplement the message's store of certificates.
  9862. // If a signer certificate is found, its public key is used to verify
  9863. // the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  9864. // return the signer without doing the signature verify.
  9865. //
  9866. // If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  9867. // by *pdwSignerIndex. Otherwise, iterate through all the signers
  9868. // until a signer verifies or no more signers.
  9869. //
  9870. // For a verified signature, *ppSigner is updated with certificate context
  9871. // of the signer and *pdwSignerIndex is updated with the index of the signer.
  9872. // ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  9873. // interested in getting the CertContext and/or index of the signer.
  9874. //--------------------------------------------------------------------------
  9875. WINCRYPT32API
  9876. BOOL
  9877. WINAPI
  9878. CryptMsgGetAndVerifySigner(
  9879. IN HCRYPTMSG hCryptMsg,
  9880. IN DWORD cSignerStore,
  9881. IN OPTIONAL HCERTSTORE *rghSignerStore,
  9882. IN DWORD dwFlags,
  9883. OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  9884. IN OUT OPTIONAL DWORD *pdwSignerIndex
  9885. );
  9886. #define CMSG_TRUSTED_SIGNER_FLAG 0x1
  9887. #define CMSG_SIGNER_ONLY_FLAG 0x2
  9888. #define CMSG_USE_SIGNER_INDEX_FLAG 0x4
  9889. //+-------------------------------------------------------------------------
  9890. // Sign an encoded CTL.
  9891. //
  9892. // The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  9893. // field or via a CryptEncodeObject(PKCS_CTL or PKCS_SORTED_CTL).
  9894. //
  9895. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9896. // V3 SignedData message.
  9897. //--------------------------------------------------------------------------
  9898. WINCRYPT32API
  9899. BOOL
  9900. WINAPI
  9901. CryptMsgSignCTL(
  9902. IN DWORD dwMsgEncodingType,
  9903. IN BYTE *pbCtlContent,
  9904. IN DWORD cbCtlContent,
  9905. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9906. IN DWORD dwFlags,
  9907. OUT BYTE *pbEncoded,
  9908. IN OUT DWORD *pcbEncoded
  9909. );
  9910. // When set, CTL inner content is encapsulated within an OCTET STRING
  9911. #define CMSG_CMS_ENCAPSULATED_CTL_FLAG 0x00008000
  9912. //+-------------------------------------------------------------------------
  9913. // Encode the CTL and create a signed message containing the encoded CTL.
  9914. //
  9915. // Set CMSG_ENCODE_SORTED_CTL_FLAG if the CTL entries are to be sorted
  9916. // before encoding. This flag should be set, if the
  9917. // CertFindSubjectInSortedCTL or CertEnumSubjectInSortedCTL APIs will
  9918. // be called. If the identifier for the CTL entries is a hash, such as,
  9919. // MD5 or SHA1, then, CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG should
  9920. // also be set.
  9921. //
  9922. // CMSG_CMS_ENCAPSULATED_CTL_FLAG can be set to encode a CMS compatible
  9923. // V3 SignedData message.
  9924. //--------------------------------------------------------------------------
  9925. WINCRYPT32API
  9926. BOOL
  9927. WINAPI
  9928. CryptMsgEncodeAndSignCTL(
  9929. IN DWORD dwMsgEncodingType,
  9930. IN PCTL_INFO pCtlInfo,
  9931. IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  9932. IN DWORD dwFlags,
  9933. OUT BYTE *pbEncoded,
  9934. IN OUT DWORD *pcbEncoded
  9935. );
  9936. // The following flag is set if the CTL is to be encoded with sorted
  9937. // trusted subjects and the szOID_SORTED_CTL extension is inserted containing
  9938. // sorted offsets to the encoded subjects.
  9939. #define CMSG_ENCODE_SORTED_CTL_FLAG 0x1
  9940. // If the above sorted flag is set, then, the following flag should also
  9941. // be set if the identifier for the TrustedSubjects is a hash,
  9942. // such as, MD5 or SHA1.
  9943. #define CMSG_ENCODE_HASHED_SUBJECT_IDENTIFIER_FLAG 0x2
  9944. //+-------------------------------------------------------------------------
  9945. // Returns TRUE if the SubjectIdentifier exists in the CTL. Optionally
  9946. // returns a pointer to and byte count of the Subject's encoded attributes.
  9947. //--------------------------------------------------------------------------
  9948. WINCRYPT32API
  9949. BOOL
  9950. WINAPI
  9951. CertFindSubjectInSortedCTL(
  9952. IN PCRYPT_DATA_BLOB pSubjectIdentifier,
  9953. IN PCCTL_CONTEXT pCtlContext,
  9954. IN DWORD dwFlags,
  9955. IN void *pvReserved,
  9956. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9957. );
  9958. //+-------------------------------------------------------------------------
  9959. // Enumerates through the sequence of TrustedSubjects in a CTL context
  9960. // created with CERT_CREATE_CONTEXT_SORTED_FLAG set.
  9961. //
  9962. // To start the enumeration, *ppvNextSubject must be NULL. Upon return,
  9963. // *ppvNextSubject is updated to point to the next TrustedSubject in
  9964. // the encoded sequence.
  9965. //
  9966. // Returns FALSE for no more subjects or invalid arguments.
  9967. //
  9968. // Note, the returned DER_BLOBs point directly into the encoded
  9969. // bytes (not allocated, and must not be freed).
  9970. //--------------------------------------------------------------------------
  9971. WINCRYPT32API
  9972. BOOL
  9973. WINAPI
  9974. CertEnumSubjectInSortedCTL(
  9975. IN PCCTL_CONTEXT pCtlContext,
  9976. IN OUT void **ppvNextSubject,
  9977. OUT OPTIONAL PCRYPT_DER_BLOB pSubjectIdentifier,
  9978. OUT OPTIONAL PCRYPT_DER_BLOB pEncodedAttributes
  9979. );
  9980. //+=========================================================================
  9981. // Certificate Verify CTL Usage Data Structures and APIs
  9982. //==========================================================================
  9983. typedef struct _CTL_VERIFY_USAGE_PARA {
  9984. DWORD cbSize;
  9985. CRYPT_DATA_BLOB ListIdentifier; // OPTIONAL
  9986. DWORD cCtlStore;
  9987. HCERTSTORE *rghCtlStore; // OPTIONAL
  9988. DWORD cSignerStore;
  9989. HCERTSTORE *rghSignerStore; // OPTIONAL
  9990. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  9991. typedef struct _CTL_VERIFY_USAGE_STATUS {
  9992. DWORD cbSize;
  9993. DWORD dwError;
  9994. DWORD dwFlags;
  9995. PCCTL_CONTEXT *ppCtl; // IN OUT OPTIONAL
  9996. DWORD dwCtlEntryIndex;
  9997. PCCERT_CONTEXT *ppSigner; // IN OUT OPTIONAL
  9998. DWORD dwSignerIndex;
  9999. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  10000. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG 0x1
  10001. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG 0x2
  10002. #define CERT_VERIFY_NO_TIME_CHECK_FLAG 0x4
  10003. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG 0x8
  10004. #define CERT_VERIFY_UPDATED_CTL_FLAG 0x1
  10005. //+-------------------------------------------------------------------------
  10006. // Verify that a subject is trusted for the specified usage by finding a
  10007. // signed and time valid CTL with the usage identifiers and containing the
  10008. // the subject. A subject can be identified by either its certificate context
  10009. // or any identifier such as its SHA1 hash.
  10010. //
  10011. // See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  10012. // parameters.
  10013. //
  10014. // Via pVerifyUsagePara, the caller can specify the stores to be searched
  10015. // to find the CTL. The caller can also specify the stores containing
  10016. // acceptable CTL signers. By setting the ListIdentifier, the caller
  10017. // can also restrict to a particular signer CTL list.
  10018. //
  10019. // Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  10020. // index into the CTL's array of entries, and the signer of the CTL
  10021. // are returned. If the caller is not interested, ppCtl and ppSigner can be set
  10022. // to NULL. Returned contexts must be freed via the store's free context APIs.
  10023. //
  10024. // If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  10025. // invalid CTL in one of the CtlStores may be replaced. When replaced, the
  10026. // CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  10027. //
  10028. // If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  10029. // SignerStores specified in pVerifyUsageStatus are searched to find
  10030. // the signer. Otherwise, the SignerStores provide additional sources
  10031. // to find the signer's certificate.
  10032. //
  10033. // If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  10034. // for time validity.
  10035. //
  10036. // If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  10037. // additional usage identifiers than specified by pSubjectUsage. Otherwise,
  10038. // the found CTL will contain the same usage identifers and no more.
  10039. //
  10040. // CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  10041. // functions. First, it will try to find an OID function matching the first
  10042. // usage object identifier in the pUsage sequence. Next, it will dispatch
  10043. // to the default CertDllVerifyCTLUsage functions.
  10044. //
  10045. // If the subject is trusted for the specified usage, then, TRUE is
  10046. // returned. Otherwise, FALSE is returned with dwError set to one of the
  10047. // following:
  10048. // CRYPT_E_NO_VERIFY_USAGE_DLL
  10049. // CRYPT_E_NO_VERIFY_USAGE_CHECK
  10050. // CRYPT_E_VERIFY_USAGE_OFFLINE
  10051. // CRYPT_E_NOT_IN_CTL
  10052. // CRYPT_E_NO_TRUSTED_SIGNER
  10053. //--------------------------------------------------------------------------
  10054. WINCRYPT32API
  10055. BOOL
  10056. WINAPI
  10057. CertVerifyCTLUsage(
  10058. IN DWORD dwEncodingType,
  10059. IN DWORD dwSubjectType,
  10060. IN void *pvSubject,
  10061. IN PCTL_USAGE pSubjectUsage,
  10062. IN DWORD dwFlags,
  10063. IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  10064. IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  10065. );
  10066. //+=========================================================================
  10067. // Certificate Revocation Data Structures and APIs
  10068. //==========================================================================
  10069. //+-------------------------------------------------------------------------
  10070. // This data structure is updated by a CRL revocation type handler
  10071. // with the base and possibly the delta CRL used.
  10072. //--------------------------------------------------------------------------
  10073. typedef struct _CERT_REVOCATION_CRL_INFO {
  10074. DWORD cbSize;
  10075. PCCRL_CONTEXT pBaseCrlContext;
  10076. PCCRL_CONTEXT pDeltaCrlContext;
  10077. // When revoked, points to entry in either of the above CRL contexts.
  10078. // Don't free.
  10079. PCRL_ENTRY pCrlEntry;
  10080. BOOL fDeltaCrlEntry; // TRUE if in pDeltaCrlContext
  10081. } CERT_REVOCATION_CRL_INFO, *PCERT_REVOCATION_CRL_INFO;
  10082. //+-------------------------------------------------------------------------
  10083. // The following data structure may be passed to CertVerifyRevocation to
  10084. // assist in finding the issuer of the context to be verified.
  10085. //
  10086. // When pIssuerCert is specified, pIssuerCert is the issuer of
  10087. // rgpvContext[cContext - 1].
  10088. //
  10089. // When cCertStore and rgCertStore are specified, these stores may contain
  10090. // an issuer certificate.
  10091. //
  10092. // When hCrlStore is specified then a handler which uses CRLs can search this
  10093. // store for them
  10094. //
  10095. // When pftTimeToUse is specified then the handler (if possible) must determine
  10096. // revocation status relative to the time given otherwise the answer may be
  10097. // independent of time or relative to current time
  10098. //--------------------------------------------------------------------------
  10099. typedef struct _CERT_REVOCATION_PARA {
  10100. DWORD cbSize;
  10101. PCCERT_CONTEXT pIssuerCert;
  10102. DWORD cCertStore;
  10103. HCERTSTORE *rgCertStore;
  10104. HCERTSTORE hCrlStore;
  10105. LPFILETIME pftTimeToUse;
  10106. #ifdef CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS
  10107. // Note, if you #define CERT_REVOCATION_PARA_HAS_EXTRA_FIELDS, then, you
  10108. // must zero all unused fields in this data structure.
  10109. // More fields could be added in a future release.
  10110. // 0 uses revocation handler's default timeout.
  10111. DWORD dwUrlRetrievalTimeout; // milliseconds
  10112. // When set, checks and attempts to retrieve a CRL where
  10113. // ThisUpdate >= (CurrentTime - dwFreshnessTime). Otherwise, defaults
  10114. // to using the CRL's NextUpdate.
  10115. BOOL fCheckFreshnessTime;
  10116. DWORD dwFreshnessTime; // seconds
  10117. // If NULL, revocation handler gets the current time
  10118. LPFILETIME pftCurrentTime;
  10119. // If nonNULL, a CRL revocation type handler updates with the base and
  10120. // possibly the delta CRL used. Note, *pCrlInfo must be initialized
  10121. // by the caller. Any nonNULL CRL contexts are freed. Any updated
  10122. // CRL contexts must be freed by the caller.
  10123. //
  10124. // The CRL info is only applicable to the last context checked. If
  10125. // interested in this information, then, CertVerifyRevocation should be
  10126. // called with cContext = 1.
  10127. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  10128. #endif
  10129. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  10130. //+-------------------------------------------------------------------------
  10131. // The following data structure is returned by CertVerifyRevocation to
  10132. // specify the status of the revoked or unchecked context. Review the
  10133. // following CertVerifyRevocation comments for details.
  10134. //
  10135. // Upon input to CertVerifyRevocation, cbSize must be set to a size
  10136. // >= (offsetof(CERT_REVOCATION_STATUS, dwReason) + sizeof(DWORD) ).
  10137. // Otherwise, CertVerifyRevocation returns FALSE and sets LastError to
  10138. // E_INVALIDARG.
  10139. //
  10140. // Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  10141. // functions, the dwIndex, dwError and dwReason have been zero'ed.
  10142. // If present, fHasFreshnessTime and dwFreshnessTime have been zero'ed.
  10143. //--------------------------------------------------------------------------
  10144. typedef struct _CERT_REVOCATION_STATUS {
  10145. DWORD cbSize;
  10146. DWORD dwIndex;
  10147. DWORD dwError;
  10148. DWORD dwReason;
  10149. // Depending on cbSize, the following fields may optionally be returned.
  10150. // The Freshness time is only applicable to the last context checked. If
  10151. // interested in this information, then, CertVerifyRevocation should be
  10152. // called with cContext = 1.
  10153. //
  10154. // fHasFreshnessTime is only set if we are able to retrieve revocation
  10155. // information. For a CRL its CurrentTime - ThisUpdate.
  10156. BOOL fHasFreshnessTime;
  10157. DWORD dwFreshnessTime; // seconds
  10158. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  10159. //+-------------------------------------------------------------------------
  10160. // Verifies the array of contexts for revocation. The dwRevType parameter
  10161. // indicates the type of the context data structure passed in rgpvContext.
  10162. // Currently only the revocation of certificates is defined.
  10163. //
  10164. // If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  10165. // is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  10166. // of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  10167. // about the order of the contexts.
  10168. //
  10169. // To assist in finding the issuer, the pRevPara may optionally be set. See
  10170. // the CERT_REVOCATION_PARA data structure for details.
  10171. //
  10172. // The contexts must contain enough information to allow the
  10173. // installable or registered revocation DLLs to find the revocation server. For
  10174. // certificates, this information would normally be conveyed in an
  10175. // extension such as the IETF's AuthorityInfoAccess extension.
  10176. //
  10177. // CertVerifyRevocation returns TRUE if all of the contexts were successfully
  10178. // checked and none were revoked. Otherwise, returns FALSE and updates the
  10179. // returned pRevStatus data structure as follows:
  10180. // dwIndex
  10181. // Index of the first context that was revoked or unable to
  10182. // be checked for revocation
  10183. // dwError
  10184. // Error status. LastError is also set to this error status.
  10185. // dwError can be set to one of the following error codes defined
  10186. // in winerror.h:
  10187. // ERROR_SUCCESS - good context
  10188. // CRYPT_E_REVOKED - context was revoked. dwReason contains the
  10189. // reason for revocation
  10190. // CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  10191. // revocation server
  10192. // CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  10193. // was not found in the revocation server's database.
  10194. // CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  10195. // wasn't able to do a revocation check on the context
  10196. // CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  10197. // found to verify revocation
  10198. // dwReason
  10199. // The dwReason is currently only set for CRYPT_E_REVOKED and contains
  10200. // the reason why the context was revoked. May be one of the following
  10201. // CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  10202. // CRL_REASON_UNSPECIFIED 0
  10203. // CRL_REASON_KEY_COMPROMISE 1
  10204. // CRL_REASON_CA_COMPROMISE 2
  10205. // CRL_REASON_AFFILIATION_CHANGED 3
  10206. // CRL_REASON_SUPERSEDED 4
  10207. // CRL_REASON_CESSATION_OF_OPERATION 5
  10208. // CRL_REASON_CERTIFICATE_HOLD 6
  10209. //
  10210. // For each entry in rgpvContext, CertVerifyRevocation iterates
  10211. // through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  10212. // function set's list of installed DEFAULT functions.
  10213. // CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  10214. // installed functions are found capable of doing the revocation verification,
  10215. // CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  10216. // list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  10217. // get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  10218. //
  10219. // The called functions have the same signature as CertVerifyRevocation. A
  10220. // called function returns TRUE if it was able to successfully check all of
  10221. // the contexts and none were revoked. Otherwise, the called function returns
  10222. // FALSE and updates pRevStatus. dwIndex is set to the index of
  10223. // the first context that was found to be revoked or unable to be checked.
  10224. // dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  10225. // is updated. Upon input to the called function, dwIndex, dwError and
  10226. // dwReason have been zero'ed. cbSize has been checked to be >=
  10227. // sizeof(CERT_REVOCATION_STATUS).
  10228. //
  10229. // If the called function returns FALSE, and dwError isn't set to
  10230. // CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  10231. // next DLL in the list for a returned dwIndex of 0 or for a returned
  10232. // dwIndex > 0, restarts the process of finding a verify function by
  10233. // advancing the start of the context array to the returned dwIndex and
  10234. // decrementing the count of remaining contexts.
  10235. //--------------------------------------------------------------------------
  10236. WINCRYPT32API
  10237. BOOL
  10238. WINAPI
  10239. CertVerifyRevocation(
  10240. IN DWORD dwEncodingType,
  10241. IN DWORD dwRevType,
  10242. IN DWORD cContext,
  10243. IN PVOID rgpvContext[],
  10244. IN DWORD dwFlags,
  10245. IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  10246. IN OUT PCERT_REVOCATION_STATUS pRevStatus
  10247. );
  10248. //+-------------------------------------------------------------------------
  10249. // Revocation types
  10250. //--------------------------------------------------------------------------
  10251. #define CERT_CONTEXT_REVOCATION_TYPE 1
  10252. //+-------------------------------------------------------------------------
  10253. // When the following flag is set, rgpvContext[] consists of a chain
  10254. // of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  10255. //--------------------------------------------------------------------------
  10256. #define CERT_VERIFY_REV_CHAIN_FLAG 0x00000001
  10257. //+-------------------------------------------------------------------------
  10258. // CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION prevents the revocation handler from
  10259. // accessing any network based resources for revocation checking
  10260. //--------------------------------------------------------------------------
  10261. #define CERT_VERIFY_CACHE_ONLY_BASED_REVOCATION 0x00000002
  10262. //+-------------------------------------------------------------------------
  10263. // By default, the dwUrlRetrievalTimeout in pRevPara is the timeout used
  10264. // for each URL wire retrieval. When the following flag is set,
  10265. // dwUrlRetrievalTimeout is the accumulative timeout across all URL wire
  10266. // retrievals.
  10267. //--------------------------------------------------------------------------
  10268. #define CERT_VERIFY_REV_ACCUMULATIVE_TIMEOUT_FLAG 0x00000004
  10269. //+-------------------------------------------------------------------------
  10270. // CERT_CONTEXT_REVOCATION_TYPE
  10271. //
  10272. // pvContext points to a const CERT_CONTEXT.
  10273. //--------------------------------------------------------------------------
  10274. //+=========================================================================
  10275. // Certificate Helper APIs
  10276. //==========================================================================
  10277. //+-------------------------------------------------------------------------
  10278. // Compare two multiple byte integer blobs to see if they are identical.
  10279. //
  10280. // Before doing the comparison, leading zero bytes are removed from a
  10281. // positive number and leading 0xFF bytes are removed from a negative
  10282. // number.
  10283. //
  10284. // The multiple byte integers are treated as Little Endian. pbData[0] is the
  10285. // least significant byte and pbData[cbData - 1] is the most significant
  10286. // byte.
  10287. //
  10288. // Returns TRUE if the integer blobs are identical after removing leading
  10289. // 0 or 0xFF bytes.
  10290. //--------------------------------------------------------------------------
  10291. BOOL
  10292. WINAPI
  10293. CertCompareIntegerBlob(
  10294. IN PCRYPT_INTEGER_BLOB pInt1,
  10295. IN PCRYPT_INTEGER_BLOB pInt2
  10296. );
  10297. //+-------------------------------------------------------------------------
  10298. // Compare two certificates to see if they are identical.
  10299. //
  10300. // Since a certificate is uniquely identified by its Issuer and SerialNumber,
  10301. // these are the only fields needing to be compared.
  10302. //
  10303. // Returns TRUE if the certificates are identical.
  10304. //--------------------------------------------------------------------------
  10305. WINCRYPT32API
  10306. BOOL
  10307. WINAPI
  10308. CertCompareCertificate(
  10309. IN DWORD dwCertEncodingType,
  10310. IN PCERT_INFO pCertId1,
  10311. IN PCERT_INFO pCertId2
  10312. );
  10313. //+-------------------------------------------------------------------------
  10314. // Compare two certificate names to see if they are identical.
  10315. //
  10316. // Returns TRUE if the names are identical.
  10317. //--------------------------------------------------------------------------
  10318. WINCRYPT32API
  10319. BOOL
  10320. WINAPI
  10321. CertCompareCertificateName(
  10322. IN DWORD dwCertEncodingType,
  10323. IN PCERT_NAME_BLOB pCertName1,
  10324. IN PCERT_NAME_BLOB pCertName2
  10325. );
  10326. //+-------------------------------------------------------------------------
  10327. // Compare the attributes in the certificate name with the specified
  10328. // Relative Distinguished Name's (CERT_RDN) array of attributes.
  10329. // The comparison iterates through the CERT_RDN attributes and looks for an
  10330. // attribute match in any of the certificate name's RDNs.
  10331. // Returns TRUE if all the attributes are found and match.
  10332. //
  10333. // The CERT_RDN_ATTR fields can have the following special values:
  10334. // pszObjId == NULL - ignore the attribute object identifier
  10335. // dwValueType == RDN_ANY_TYPE - ignore the value type
  10336. //
  10337. // CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG should be set to do
  10338. // a case insensitive match. Otherwise, defaults to an exact, case sensitive
  10339. // match.
  10340. //
  10341. // CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  10342. // with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  10343. //--------------------------------------------------------------------------
  10344. WINCRYPT32API
  10345. BOOL
  10346. WINAPI
  10347. CertIsRDNAttrsInCertificateName(
  10348. IN DWORD dwCertEncodingType,
  10349. IN DWORD dwFlags,
  10350. IN PCERT_NAME_BLOB pCertName,
  10351. IN PCERT_RDN pRDN
  10352. );
  10353. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG 0x1
  10354. #define CERT_CASE_INSENSITIVE_IS_RDN_ATTRS_FLAG 0x2
  10355. //+-------------------------------------------------------------------------
  10356. // Compare two public keys to see if they are identical.
  10357. //
  10358. // Returns TRUE if the keys are identical.
  10359. //--------------------------------------------------------------------------
  10360. WINCRYPT32API
  10361. BOOL
  10362. WINAPI
  10363. CertComparePublicKeyInfo(
  10364. IN DWORD dwCertEncodingType,
  10365. IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  10366. IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  10367. );
  10368. //+-------------------------------------------------------------------------
  10369. // Get the public/private key's bit length.
  10370. //
  10371. // Returns 0 if unable to determine the key's length.
  10372. //--------------------------------------------------------------------------
  10373. WINCRYPT32API
  10374. DWORD
  10375. WINAPI
  10376. CertGetPublicKeyLength(
  10377. IN DWORD dwCertEncodingType,
  10378. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10379. );
  10380. //+-------------------------------------------------------------------------
  10381. // Verify the signature of a subject certificate or a CRL using the
  10382. // public key info
  10383. //
  10384. // Returns TRUE for a valid signature.
  10385. //
  10386. // hCryptProv specifies the crypto provider to use to verify the signature.
  10387. // It doesn't need to use a private key.
  10388. //--------------------------------------------------------------------------
  10389. WINCRYPT32API
  10390. BOOL
  10391. WINAPI
  10392. CryptVerifyCertificateSignature(
  10393. IN HCRYPTPROV hCryptProv,
  10394. IN DWORD dwCertEncodingType,
  10395. IN const BYTE * pbEncoded,
  10396. IN DWORD cbEncoded,
  10397. IN PCERT_PUBLIC_KEY_INFO pPublicKey
  10398. );
  10399. //+-------------------------------------------------------------------------
  10400. // Verify the signature of a subject certificate, CRL, certificate request
  10401. // or keygen request using the issuer's public key.
  10402. //
  10403. // Returns TRUE for a valid signature.
  10404. //
  10405. // The subject can be an encoded blob or a context for a certificate or CRL.
  10406. // For a subject certificate context, if the certificate is missing
  10407. // inheritable PublicKey Algorithm Parameters, the context's
  10408. // CERT_PUBKEY_ALG_PARA_PROP_ID is updated with the issuer's public key
  10409. // algorithm parameters for a valid signature.
  10410. //
  10411. // The issuer can be a pointer to a CERT_PUBLIC_KEY_INFO, certificate
  10412. // context or a chain context.
  10413. //
  10414. // hCryptProv specifies the crypto provider to use to verify the signature.
  10415. // Its private key isn't used. If hCryptProv is NULL, a default
  10416. // provider is picked according to the PublicKey Algorithm OID.
  10417. //
  10418. // If the signature algorithm is a hashing algorithm, then, the
  10419. // signature is expected to contain the hash octets. Only dwIssuerType
  10420. // of CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL may be specified
  10421. // to verify this no signature case. If any other dwIssuerType is
  10422. // specified, the verify will fail with LastError set to E_INVALIDARG.
  10423. //--------------------------------------------------------------------------
  10424. WINCRYPT32API
  10425. BOOL
  10426. WINAPI
  10427. CryptVerifyCertificateSignatureEx(
  10428. IN OPTIONAL HCRYPTPROV hCryptProv,
  10429. IN DWORD dwCertEncodingType,
  10430. IN DWORD dwSubjectType,
  10431. IN void *pvSubject,
  10432. IN DWORD dwIssuerType,
  10433. IN void *pvIssuer,
  10434. IN DWORD dwFlags,
  10435. IN OPTIONAL void *pvReserved
  10436. );
  10437. // Subject Types
  10438. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB 1
  10439. // pvSubject :: PCRYPT_DATA_BLOB
  10440. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT 2
  10441. // pvSubject :: PCCERT_CONTEXT
  10442. #define CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL 3
  10443. // pvSubject :: PCCRL_CONTEXT
  10444. // Issuer Types
  10445. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY 1
  10446. // pvIssuer :: PCERT_PUBLIC_KEY_INFO
  10447. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT 2
  10448. // pvIssuer :: PCCERT_CONTEXT
  10449. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN 3
  10450. // pvIssuer :: PCCERT_CHAIN_CONTEXT
  10451. #define CRYPT_VERIFY_CERT_SIGN_ISSUER_NULL 4
  10452. // pvIssuer :: NULL
  10453. //+-------------------------------------------------------------------------
  10454. // Compute the hash of the "to be signed" information in the encoded
  10455. // signed content (CERT_SIGNED_CONTENT_INFO).
  10456. //
  10457. // hCryptProv specifies the crypto provider to use to compute the hash.
  10458. // It doesn't need to use a private key.
  10459. //--------------------------------------------------------------------------
  10460. WINCRYPT32API
  10461. BOOL
  10462. WINAPI
  10463. CryptHashToBeSigned(
  10464. IN HCRYPTPROV hCryptProv,
  10465. IN DWORD dwCertEncodingType,
  10466. IN const BYTE *pbEncoded,
  10467. IN DWORD cbEncoded,
  10468. OUT BYTE *pbComputedHash,
  10469. IN OUT DWORD *pcbComputedHash
  10470. );
  10471. //+-------------------------------------------------------------------------
  10472. // Hash the encoded content.
  10473. //
  10474. // hCryptProv specifies the crypto provider to use to compute the hash.
  10475. // It doesn't need to use a private key.
  10476. //
  10477. // Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  10478. // default hash algorithm (currently SHA1) is used.
  10479. //--------------------------------------------------------------------------
  10480. WINCRYPT32API
  10481. BOOL
  10482. WINAPI
  10483. CryptHashCertificate(
  10484. IN HCRYPTPROV hCryptProv,
  10485. IN ALG_ID Algid,
  10486. IN DWORD dwFlags,
  10487. IN const BYTE *pbEncoded,
  10488. IN DWORD cbEncoded,
  10489. OUT BYTE *pbComputedHash,
  10490. IN OUT DWORD *pcbComputedHash
  10491. );
  10492. //+-------------------------------------------------------------------------
  10493. // Sign the "to be signed" information in the encoded signed content.
  10494. //
  10495. // hCryptProv specifies the crypto provider to use to do the signature.
  10496. // It uses the specified private key.
  10497. //
  10498. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10499. // contains the hash octets. A private key isn't used to encrypt the hash.
  10500. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10501. // default provider will be used for hashing.
  10502. //--------------------------------------------------------------------------
  10503. WINCRYPT32API
  10504. BOOL
  10505. WINAPI
  10506. CryptSignCertificate(
  10507. IN HCRYPTPROV hCryptProv,
  10508. IN DWORD dwKeySpec,
  10509. IN DWORD dwCertEncodingType,
  10510. IN const BYTE *pbEncodedToBeSigned,
  10511. IN DWORD cbEncodedToBeSigned,
  10512. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10513. IN OPTIONAL const void *pvHashAuxInfo,
  10514. OUT BYTE *pbSignature,
  10515. IN OUT DWORD *pcbSignature
  10516. );
  10517. //+-------------------------------------------------------------------------
  10518. // Encode the "to be signed" information. Sign the encoded "to be signed".
  10519. // Encode the "to be signed" and the signature.
  10520. //
  10521. // hCryptProv specifies the crypto provider to use to do the signature.
  10522. // It uses the specified private key.
  10523. //
  10524. // If the SignatureAlgorithm is a hash algorithm, then, the signature
  10525. // contains the hash octets. A private key isn't used to encrypt the hash.
  10526. // dwKeySpec isn't used and hCryptProv can be NULL where an appropriate
  10527. // default provider will be used for hashing.
  10528. //--------------------------------------------------------------------------
  10529. WINCRYPT32API
  10530. BOOL
  10531. WINAPI
  10532. CryptSignAndEncodeCertificate(
  10533. IN HCRYPTPROV hCryptProv,
  10534. IN DWORD dwKeySpec,
  10535. IN DWORD dwCertEncodingType,
  10536. IN LPCSTR lpszStructType, // "to be signed"
  10537. IN const void *pvStructInfo,
  10538. IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  10539. IN OPTIONAL const void *pvHashAuxInfo,
  10540. OUT PBYTE pbEncoded,
  10541. IN OUT DWORD *pcbEncoded
  10542. );
  10543. //+-------------------------------------------------------------------------
  10544. // Verify the time validity of a certificate.
  10545. //
  10546. // Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  10547. // a valid certificate
  10548. //
  10549. // If pTimeToVerify is NULL, uses the current time.
  10550. //--------------------------------------------------------------------------
  10551. WINCRYPT32API
  10552. LONG
  10553. WINAPI
  10554. CertVerifyTimeValidity(
  10555. IN LPFILETIME pTimeToVerify,
  10556. IN PCERT_INFO pCertInfo
  10557. );
  10558. //+-------------------------------------------------------------------------
  10559. // Verify the time validity of a CRL.
  10560. //
  10561. // Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  10562. // a valid CRL
  10563. //
  10564. // If pTimeToVerify is NULL, uses the current time.
  10565. //--------------------------------------------------------------------------
  10566. WINCRYPT32API
  10567. LONG
  10568. WINAPI
  10569. CertVerifyCRLTimeValidity(
  10570. IN LPFILETIME pTimeToVerify,
  10571. IN PCRL_INFO pCrlInfo
  10572. );
  10573. //+-------------------------------------------------------------------------
  10574. // Verify that the subject's time validity nests within the issuer's time
  10575. // validity.
  10576. //
  10577. // Returns TRUE if it nests. Otherwise, returns FALSE.
  10578. //--------------------------------------------------------------------------
  10579. WINCRYPT32API
  10580. BOOL
  10581. WINAPI
  10582. CertVerifyValidityNesting(
  10583. IN PCERT_INFO pSubjectInfo,
  10584. IN PCERT_INFO pIssuerInfo
  10585. );
  10586. //+-------------------------------------------------------------------------
  10587. // Verify that the subject certificate isn't on its issuer CRL.
  10588. //
  10589. // Returns true if the certificate isn't on the CRL.
  10590. //--------------------------------------------------------------------------
  10591. WINCRYPT32API
  10592. BOOL
  10593. WINAPI
  10594. CertVerifyCRLRevocation(
  10595. IN DWORD dwCertEncodingType,
  10596. IN PCERT_INFO pCertId, // Only the Issuer and SerialNumber
  10597. // fields are used
  10598. IN DWORD cCrlInfo,
  10599. IN PCRL_INFO rgpCrlInfo[]
  10600. );
  10601. //+-------------------------------------------------------------------------
  10602. // Convert the CAPI AlgId to the ASN.1 Object Identifier string
  10603. //
  10604. // Returns NULL if there isn't an ObjId corresponding to the AlgId.
  10605. //--------------------------------------------------------------------------
  10606. WINCRYPT32API
  10607. LPCSTR
  10608. WINAPI
  10609. CertAlgIdToOID(
  10610. IN DWORD dwAlgId
  10611. );
  10612. //+-------------------------------------------------------------------------
  10613. // Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  10614. //
  10615. // Returns 0 if there isn't an AlgId corresponding to the ObjId.
  10616. //--------------------------------------------------------------------------
  10617. WINCRYPT32API
  10618. DWORD
  10619. WINAPI
  10620. CertOIDToAlgId(
  10621. IN LPCSTR pszObjId
  10622. );
  10623. //+-------------------------------------------------------------------------
  10624. // Find an extension identified by its Object Identifier.
  10625. //
  10626. // If found, returns pointer to the extension. Otherwise, returns NULL.
  10627. //--------------------------------------------------------------------------
  10628. WINCRYPT32API
  10629. PCERT_EXTENSION
  10630. WINAPI
  10631. CertFindExtension(
  10632. IN LPCSTR pszObjId,
  10633. IN DWORD cExtensions,
  10634. IN CERT_EXTENSION rgExtensions[]
  10635. );
  10636. //+-------------------------------------------------------------------------
  10637. // Find the first attribute identified by its Object Identifier.
  10638. //
  10639. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10640. //--------------------------------------------------------------------------
  10641. WINCRYPT32API
  10642. PCRYPT_ATTRIBUTE
  10643. WINAPI
  10644. CertFindAttribute(
  10645. IN LPCSTR pszObjId,
  10646. IN DWORD cAttr,
  10647. IN CRYPT_ATTRIBUTE rgAttr[]
  10648. );
  10649. //+-------------------------------------------------------------------------
  10650. // Find the first CERT_RDN attribute identified by its Object Identifier in
  10651. // the name's list of Relative Distinguished Names.
  10652. //
  10653. // If found, returns pointer to the attribute. Otherwise, returns NULL.
  10654. //--------------------------------------------------------------------------
  10655. WINCRYPT32API
  10656. PCERT_RDN_ATTR
  10657. WINAPI
  10658. CertFindRDNAttr(
  10659. IN LPCSTR pszObjId,
  10660. IN PCERT_NAME_INFO pName
  10661. );
  10662. //+-------------------------------------------------------------------------
  10663. // Get the intended key usage bytes from the certificate.
  10664. //
  10665. // If the certificate doesn't have any intended key usage bytes, returns FALSE
  10666. // and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  10667. // cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  10668. // bytes are zeroed.
  10669. //--------------------------------------------------------------------------
  10670. WINCRYPT32API
  10671. BOOL
  10672. WINAPI
  10673. CertGetIntendedKeyUsage(
  10674. IN DWORD dwCertEncodingType,
  10675. IN PCERT_INFO pCertInfo,
  10676. OUT BYTE *pbKeyUsage,
  10677. IN DWORD cbKeyUsage
  10678. );
  10679. typedef void *HCRYPTDEFAULTCONTEXT;
  10680. //+-------------------------------------------------------------------------
  10681. // Install a previously CryptAcquiredContext'ed HCRYPTPROV to be used as
  10682. // a default context.
  10683. //
  10684. // dwDefaultType and pvDefaultPara specify where the default context is used.
  10685. // For example, install the HCRYPTPROV to be used to verify certificate's
  10686. // having szOID_OIWSEC_md5RSA signatures.
  10687. //
  10688. // By default, the installed HCRYPTPROV is only applicable to the current
  10689. // thread. Set CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG to allow the HCRYPTPROV
  10690. // to be used by all threads in the current process.
  10691. //
  10692. // For a successful install, TRUE is returned and *phDefaultContext is
  10693. // updated with the HANDLE to be passed to CryptUninstallDefaultContext.
  10694. //
  10695. // The installed HCRYPTPROVs are stack ordered (the last installed
  10696. // HCRYPTPROV is checked first). All thread installed HCRYPTPROVs are
  10697. // checked before any process HCRYPTPROVs.
  10698. //
  10699. // The installed HCRYPTPROV remains available for default usage until
  10700. // CryptUninstallDefaultContext is called or the thread or process exits.
  10701. //
  10702. // If CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG is set, then, the HCRYPTPROV
  10703. // is CryptReleaseContext'ed at thread or process exit. However,
  10704. // not CryptReleaseContext'ed if CryptUninstallDefaultContext is
  10705. // called.
  10706. //--------------------------------------------------------------------------
  10707. WINCRYPT32API
  10708. BOOL
  10709. WINAPI
  10710. CryptInstallDefaultContext(
  10711. IN HCRYPTPROV hCryptProv,
  10712. IN DWORD dwDefaultType,
  10713. IN const void *pvDefaultPara,
  10714. IN DWORD dwFlags,
  10715. IN void *pvReserved,
  10716. OUT HCRYPTDEFAULTCONTEXT *phDefaultContext
  10717. );
  10718. // dwFlags
  10719. #define CRYPT_DEFAULT_CONTEXT_AUTO_RELEASE_FLAG 0x00000001
  10720. #define CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG 0x00000002
  10721. // List of dwDefaultType's
  10722. #define CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID 1
  10723. #define CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID 2
  10724. //+-------------------------------------------------------------------------
  10725. // CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID
  10726. //
  10727. // Install a default HCRYPTPROV used to verify a certificate
  10728. // signature. pvDefaultPara points to the szOID of the certificate
  10729. // signature algorithm, for example, szOID_OIWSEC_md5RSA. If
  10730. // pvDefaultPara is NULL, then, the HCRYPTPROV is used to verify all
  10731. // certificate signatures. Note, pvDefaultPara can't be NULL when
  10732. // CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG is set.
  10733. //--------------------------------------------------------------------------
  10734. //+-------------------------------------------------------------------------
  10735. // CRYPT_DEFAULT_CONTEXT_MULTI_CERT_SIGN_OID
  10736. //
  10737. // Same as CRYPT_DEFAULT_CONTEXT_CERT_SIGN_OID. However, the default
  10738. // HCRYPTPROV is to be used for multiple signature szOIDs. pvDefaultPara
  10739. // points to a CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA structure containing
  10740. // an array of szOID pointers.
  10741. //--------------------------------------------------------------------------
  10742. typedef struct _CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA {
  10743. DWORD cOID;
  10744. LPSTR *rgpszOID;
  10745. } CRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA, *PCRYPT_DEFAULT_CONTEXT_MULTI_OID_PARA;
  10746. //+-------------------------------------------------------------------------
  10747. // Uninstall a default context previously installed by
  10748. // CryptInstallDefaultContext.
  10749. //
  10750. // For a default context installed with CRYPT_DEFAULT_CONTEXT_PROCESS_FLAG
  10751. // set, if any other threads are currently using this context,
  10752. // this function will block until they finish.
  10753. //--------------------------------------------------------------------------
  10754. WINCRYPT32API
  10755. BOOL
  10756. WINAPI
  10757. CryptUninstallDefaultContext(
  10758. HCRYPTDEFAULTCONTEXT hDefaultContext,
  10759. IN DWORD dwFlags,
  10760. IN void *pvReserved
  10761. );
  10762. //+-------------------------------------------------------------------------
  10763. // Export the public key info associated with the provider's corresponding
  10764. // private key.
  10765. //
  10766. // Calls CryptExportPublicKeyInfoEx with pszPublicKeyObjId = NULL,
  10767. // dwFlags = 0 and pvAuxInfo = NULL.
  10768. //--------------------------------------------------------------------------
  10769. WINCRYPT32API
  10770. BOOL
  10771. WINAPI
  10772. CryptExportPublicKeyInfo(
  10773. IN HCRYPTPROV hCryptProv,
  10774. IN DWORD dwKeySpec,
  10775. IN DWORD dwCertEncodingType,
  10776. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10777. IN OUT DWORD *pcbInfo
  10778. );
  10779. //+-------------------------------------------------------------------------
  10780. // Export the public key info associated with the provider's corresponding
  10781. // private key.
  10782. //
  10783. // Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  10784. // installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10785. // has the same signature as CryptExportPublicKeyInfoEx.
  10786. //
  10787. // If unable to find an installable OID function for the pszPublicKeyObjId,
  10788. // attempts to export as a RSA Public Key (szOID_RSA_RSA).
  10789. //
  10790. // The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  10791. //--------------------------------------------------------------------------
  10792. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC "CryptDllExportPublicKeyInfoEx"
  10793. WINCRYPT32API
  10794. BOOL
  10795. WINAPI
  10796. CryptExportPublicKeyInfoEx(
  10797. IN HCRYPTPROV hCryptProv,
  10798. IN DWORD dwKeySpec,
  10799. IN DWORD dwCertEncodingType,
  10800. IN LPSTR pszPublicKeyObjId,
  10801. IN DWORD dwFlags,
  10802. IN OPTIONAL void *pvAuxInfo,
  10803. OUT PCERT_PUBLIC_KEY_INFO pInfo,
  10804. IN OUT DWORD *pcbInfo
  10805. );
  10806. //+-------------------------------------------------------------------------
  10807. // Convert and import the public key info into the provider and return a
  10808. // handle to the public key.
  10809. //
  10810. // Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  10811. // pvAuxInfo = NULL.
  10812. //--------------------------------------------------------------------------
  10813. WINCRYPT32API
  10814. BOOL
  10815. WINAPI
  10816. CryptImportPublicKeyInfo(
  10817. IN HCRYPTPROV hCryptProv,
  10818. IN DWORD dwCertEncodingType,
  10819. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10820. OUT HCRYPTKEY *phKey
  10821. );
  10822. //+-------------------------------------------------------------------------
  10823. // Convert and import the public key info into the provider and return a
  10824. // handle to the public key.
  10825. //
  10826. // Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  10827. // installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  10828. // has the same signature as CryptImportPublicKeyInfoEx.
  10829. //
  10830. // If unable to find an installable OID function for the pszObjId,
  10831. // attempts to import as a RSA Public Key (szOID_RSA_RSA).
  10832. //
  10833. // For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  10834. // Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  10835. //--------------------------------------------------------------------------
  10836. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC "CryptDllImportPublicKeyInfoEx"
  10837. WINCRYPT32API
  10838. BOOL
  10839. WINAPI
  10840. CryptImportPublicKeyInfoEx(
  10841. IN HCRYPTPROV hCryptProv,
  10842. IN DWORD dwCertEncodingType,
  10843. IN PCERT_PUBLIC_KEY_INFO pInfo,
  10844. IN ALG_ID aiKeyAlg,
  10845. IN DWORD dwFlags,
  10846. IN OPTIONAL void *pvAuxInfo,
  10847. OUT HCRYPTKEY *phKey
  10848. );
  10849. //+-------------------------------------------------------------------------
  10850. // Acquire a HCRYPTPROV handle and dwKeySpec for the specified certificate
  10851. // context. Uses the certificate's CERT_KEY_PROV_INFO_PROP_ID property.
  10852. // The returned HCRYPTPROV handle may optionally be cached using the
  10853. // certificate's CERT_KEY_CONTEXT_PROP_ID property.
  10854. //
  10855. // If CRYPT_ACQUIRE_CACHE_FLAG is set, then, if an already acquired and
  10856. // cached HCRYPTPROV exists for the certificate, its returned. Otherwise,
  10857. // a HCRYPTPROV is acquired and then cached via the certificate's
  10858. // CERT_KEY_CONTEXT_PROP_ID.
  10859. //
  10860. // The CRYPT_ACQUIRE_USE_PROV_INFO_FLAG can be set to use the dwFlags field of
  10861. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property's CRYPT_KEY_PROV_INFO
  10862. // data structure to determine if the returned HCRYPTPROV should be cached.
  10863. // HCRYPTPROV caching is enabled if the CERT_SET_KEY_CONTEXT_PROP_ID flag was
  10864. // set.
  10865. //
  10866. // If CRYPT_ACQUIRE_COMPARE_KEY_FLAG is set, then,
  10867. // the public key in the certificate is compared with the public
  10868. // key returned by the cryptographic provider. If the keys don't match, the
  10869. // acquire fails and LastError is set to NTE_BAD_PUBLIC_KEY. Note, if
  10870. // a cached HCRYPTPROV is returned, the comparison isn't done. We assume the
  10871. // comparison was done on the initial acquire.
  10872. //
  10873. // The CRYPT_ACQUIRE_SILENT_FLAG can be set to suppress any UI by the CSP.
  10874. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10875. //
  10876. // *pfCallerFreeProv is returned set to FALSE for:
  10877. // - Acquire or public key comparison fails.
  10878. // - CRYPT_ACQUIRE_CACHE_FLAG is set.
  10879. // - CRYPT_ACQUIRE_USE_PROV_INFO_FLAG is set AND
  10880. // CERT_SET_KEY_CONTEXT_PROP_ID flag is set in the dwFlags field of the
  10881. // certificate's CERT_KEY_PROV_INFO_PROP_ID property's
  10882. // CRYPT_KEY_PROV_INFO data structure.
  10883. // When *pfCallerFreeProv is FALSE, the caller must not release. The
  10884. // returned HCRYPTPROV will be released on the last free of the certificate
  10885. // context.
  10886. //
  10887. // Otherwise, *pfCallerFreeProv is TRUE and the returned HCRYPTPROV must
  10888. // be released by the caller by calling CryptReleaseContext.
  10889. //--------------------------------------------------------------------------
  10890. WINCRYPT32API
  10891. BOOL
  10892. WINAPI
  10893. CryptAcquireCertificatePrivateKey(
  10894. IN PCCERT_CONTEXT pCert,
  10895. IN DWORD dwFlags,
  10896. IN void *pvReserved,
  10897. OUT HCRYPTPROV *phCryptProv,
  10898. OUT OPTIONAL DWORD *pdwKeySpec,
  10899. OUT OPTIONAL BOOL *pfCallerFreeProv
  10900. );
  10901. #define CRYPT_ACQUIRE_CACHE_FLAG 0x00000001
  10902. #define CRYPT_ACQUIRE_USE_PROV_INFO_FLAG 0x00000002
  10903. #define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004
  10904. #define CRYPT_ACQUIRE_SILENT_FLAG 0x00000040
  10905. //+-------------------------------------------------------------------------
  10906. // Enumerates the cryptographic providers and their containers to find the
  10907. // private key corresponding to the certificate's public key. For a match,
  10908. // the certificate's CERT_KEY_PROV_INFO_PROP_ID property is updated.
  10909. //
  10910. // If the CERT_KEY_PROV_INFO_PROP_ID is already set, then, its checked to
  10911. // see if it matches the provider's public key. For a match, the above
  10912. // enumeration is skipped.
  10913. //
  10914. // By default both the user and machine key containers are searched.
  10915. // The CRYPT_FIND_USER_KEYSET_FLAG or CRYPT_FIND_MACHINE_KEYSET_FLAG
  10916. // can be set in dwFlags to restrict the search to either of the containers.
  10917. //
  10918. // The CRYPT_FIND_SILENT_KEYSET_FLAG can be set to suppress any UI by the CSP.
  10919. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  10920. //
  10921. // If a container isn't found, returns FALSE with LastError set to
  10922. // NTE_NO_KEY.
  10923. //--------------------------------------------------------------------------
  10924. WINCRYPT32API
  10925. BOOL
  10926. WINAPI
  10927. CryptFindCertificateKeyProvInfo(
  10928. IN PCCERT_CONTEXT pCert,
  10929. IN DWORD dwFlags,
  10930. IN void *pvReserved
  10931. );
  10932. #define CRYPT_FIND_USER_KEYSET_FLAG 0x00000001
  10933. #define CRYPT_FIND_MACHINE_KEYSET_FLAG 0x00000002
  10934. #define CRYPT_FIND_SILENT_KEYSET_FLAG 0x00000040
  10935. //+-------------------------------------------------------------------------
  10936. // This is the prototype for the installable function which is called to
  10937. // actually import a key into a CSP. an installable of this type is called
  10938. // from CryptImportPKCS8. the algorithm OID of the private key is used
  10939. // to look up the proper installable function to call.
  10940. //
  10941. // hCryptProv - the provider to import the key to
  10942. // pPrivateKeyInfo - describes the key to be imported
  10943. // dwFlags - The available flags are:
  10944. // CRYPT_EXPORTABLE
  10945. // this flag is used when importing private keys, for a full
  10946. // explanation please see the documentation for CryptImportKey.
  10947. // pvAuxInfo - reserved for future, must be NULL
  10948. //--------------------------------------------------------------------------
  10949. typedef BOOL (WINAPI *PFN_IMPORT_PRIV_KEY_FUNC) (
  10950. HCRYPTPROV hCryptProv, // in
  10951. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // in
  10952. DWORD dwFlags, // in, optional
  10953. void *pvAuxInfo // in, optional
  10954. );
  10955. #define CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC "CryptDllImportPrivateKeyInfoEx"
  10956. //+-------------------------------------------------------------------------
  10957. // Convert (from PKCS8 format) and import the private key into a provider
  10958. // and return a handle to the provider as well as the KeySpec used to import to.
  10959. //
  10960. // This function will call the PRESOLVE_HCRYPTPROV_FUNC in the
  10961. // privateKeyAndParams to obtain a handle of provider to import the key to.
  10962. // if the PRESOLVE_HCRYPTPROV_FUNC is NULL then the default provider will be used.
  10963. //
  10964. // privateKeyAndParams - private key blob and corresponding parameters
  10965. // dwFlags - The available flags are:
  10966. // CRYPT_EXPORTABLE
  10967. // this flag is used when importing private keys, for a full
  10968. // explanation please see the documentation for CryptImportKey.
  10969. // phCryptProv - filled in with the handle of the provider the key was
  10970. // imported to, the caller is responsible for freeing it
  10971. // pvAuxInfo - This parameter is reserved for future use and should be set
  10972. // to NULL in the interim.
  10973. //--------------------------------------------------------------------------
  10974. WINCRYPT32API
  10975. BOOL
  10976. WINAPI
  10977. CryptImportPKCS8(
  10978. CRYPT_PKCS8_IMPORT_PARAMS sImportParams, // in
  10979. DWORD dwFlags, // in, optional
  10980. HCRYPTPROV *phCryptProv, // out, optional
  10981. void *pvAuxInfo // in, optional
  10982. );
  10983. //+-------------------------------------------------------------------------
  10984. // this is the prototype for installable functions for exporting the private key
  10985. //--------------------------------------------------------------------------
  10986. typedef BOOL (WINAPI *PFN_EXPORT_PRIV_KEY_FUNC) (
  10987. HCRYPTPROV hCryptProv, // in
  10988. DWORD dwKeySpec, // in
  10989. LPSTR pszPrivateKeyObjId, // in
  10990. DWORD dwFlags, // in
  10991. void *pvAuxInfo, // in
  10992. CRYPT_PRIVATE_KEY_INFO *pPrivateKeyInfo, // out
  10993. DWORD *pcbPrivateKeyBlob // in, out
  10994. );
  10995. #define CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC "CryptDllExportPrivateKeyInfoEx"
  10996. #define CRYPT_DELETE_KEYSET 0x0001
  10997. //+-------------------------------------------------------------------------
  10998. // CryptExportPKCS8 -- superseded by CryptExportPKCS8Ex
  10999. //
  11000. // Export the private key in PKCS8 format
  11001. //--------------------------------------------------------------------------
  11002. WINCRYPT32API
  11003. BOOL
  11004. WINAPI
  11005. CryptExportPKCS8(
  11006. HCRYPTPROV hCryptProv, // in
  11007. DWORD dwKeySpec, // in
  11008. LPSTR pszPrivateKeyObjId, // in
  11009. DWORD dwFlags, // in
  11010. void *pvAuxInfo, // in
  11011. BYTE *pbPrivateKeyBlob, // out
  11012. DWORD *pcbPrivateKeyBlob // in, out
  11013. );
  11014. //+-------------------------------------------------------------------------
  11015. // CryptExportPKCS8Ex
  11016. //
  11017. // Export the private key in PKCS8 format
  11018. //
  11019. //
  11020. // Uses the pszPrivateKeyObjId to call the
  11021. // installable CRYPT_OID_EXPORT_PRIVATE_KEY_INFO_FUNC. The called function
  11022. // has the signature defined by PFN_EXPORT_PRIV_KEY_FUNC.
  11023. //
  11024. // If unable to find an installable OID function for the pszPrivateKeyObjId,
  11025. // attempts to export as a RSA Private Key (szOID_RSA_RSA).
  11026. //
  11027. // psExportParams - specifies information about the key to export
  11028. // dwFlags - The flag values. None currently supported
  11029. // pvAuxInfo - This parameter is reserved for future use and should be set to
  11030. // NULL in the interim.
  11031. // pbPrivateKeyBlob - A pointer to the private key blob. It will be encoded
  11032. // as a PKCS8 PrivateKeyInfo.
  11033. // pcbPrivateKeyBlob - A pointer to a DWORD that contains the size, in bytes,
  11034. // of the private key blob being exported.
  11035. //+-------------------------------------------------------------------------
  11036. WINCRYPT32API
  11037. BOOL
  11038. WINAPI
  11039. CryptExportPKCS8Ex(
  11040. CRYPT_PKCS8_EXPORT_PARAMS* psExportParams, // in
  11041. DWORD dwFlags, // in
  11042. void *pvAuxInfo, // in
  11043. BYTE *pbPrivateKeyBlob, // out
  11044. DWORD *pcbPrivateKeyBlob // in, out
  11045. );
  11046. //+-------------------------------------------------------------------------
  11047. // Compute the hash of the encoded public key info.
  11048. //
  11049. // The public key info is encoded and then hashed.
  11050. //--------------------------------------------------------------------------
  11051. WINCRYPT32API
  11052. BOOL
  11053. WINAPI
  11054. CryptHashPublicKeyInfo(
  11055. IN HCRYPTPROV hCryptProv,
  11056. IN ALG_ID Algid,
  11057. IN DWORD dwFlags,
  11058. IN DWORD dwCertEncodingType,
  11059. IN PCERT_PUBLIC_KEY_INFO pInfo,
  11060. OUT BYTE *pbComputedHash,
  11061. IN OUT DWORD *pcbComputedHash
  11062. );
  11063. //+-------------------------------------------------------------------------
  11064. // Convert a Name Value to a null terminated char string
  11065. //
  11066. // Returns the number of characters converted including the terminating null
  11067. // character. If psz is NULL or csz is 0, returns the required size of the
  11068. // destination string (including the terminating null char).
  11069. //
  11070. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11071. //
  11072. // Note: csz includes the NULL char.
  11073. //--------------------------------------------------------------------------
  11074. WINCRYPT32API
  11075. DWORD
  11076. WINAPI
  11077. CertRDNValueToStrA(
  11078. IN DWORD dwValueType,
  11079. IN PCERT_RDN_VALUE_BLOB pValue,
  11080. OUT OPTIONAL LPSTR psz,
  11081. IN DWORD csz
  11082. );
  11083. //+-------------------------------------------------------------------------
  11084. // Convert a Name Value to a null terminated char string
  11085. //
  11086. // Returns the number of characters converted including the terminating null
  11087. // character. If psz is NULL or csz is 0, returns the required size of the
  11088. // destination string (including the terminating null char).
  11089. //
  11090. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11091. //
  11092. // Note: csz includes the NULL char.
  11093. //--------------------------------------------------------------------------
  11094. WINCRYPT32API
  11095. DWORD
  11096. WINAPI
  11097. CertRDNValueToStrW(
  11098. IN DWORD dwValueType,
  11099. IN PCERT_RDN_VALUE_BLOB pValue,
  11100. OUT OPTIONAL LPWSTR psz,
  11101. IN DWORD csz
  11102. );
  11103. #ifdef UNICODE
  11104. #define CertRDNValueToStr CertRDNValueToStrW
  11105. #else
  11106. #define CertRDNValueToStr CertRDNValueToStrA
  11107. #endif // !UNICODE
  11108. //+-------------------------------------------------------------------------
  11109. // Convert the certificate name blob to a null terminated char string.
  11110. //
  11111. // Follows the string representation of distinguished names specified in
  11112. // RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  11113. // empty strings and don't quote strings containing consecutive spaces).
  11114. // RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  11115. // formatted in hexadecimal (e.g. #0A56CF).
  11116. //
  11117. // The name string is formatted according to the dwStrType:
  11118. // CERT_SIMPLE_NAME_STR
  11119. // The object identifiers are discarded. CERT_RDN entries are separated
  11120. // by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  11121. // For example:
  11122. // Microsoft, Joe Cool + Programmer
  11123. // CERT_OID_NAME_STR
  11124. // The object identifiers are included with a "=" separator from their
  11125. // attribute value. CERT_RDN entries are separated by ", ".
  11126. // Multiple attributes per CERT_RDN are separated by " + ". For example:
  11127. // 2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  11128. // CERT_X500_NAME_STR
  11129. // The object identifiers are converted to their X500 key name. Otherwise,
  11130. // same as CERT_OID_NAME_STR. If the object identifier doesn't have
  11131. // a corresponding X500 key name, then, the object identifier is used with
  11132. // a "OID." prefix. For example:
  11133. // OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  11134. //
  11135. // We quote the RDN value if it contains leading or trailing whitespace
  11136. // or one of the following characters: ",", "+", "=", """, "\n", "<", ">",
  11137. // "#" or ";". The quoting character is ". If the the RDN Value contains
  11138. // a " it is double quoted (""). For example:
  11139. // OU=" Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  11140. //
  11141. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  11142. // the ", " separator with a "; " separator.
  11143. //
  11144. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  11145. // the ", " separator with a "\r\n" separator.
  11146. //
  11147. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  11148. // " + " separator with a single space, " ".
  11149. //
  11150. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11151. // the above quoting.
  11152. //
  11153. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11154. // order of the RDNs before converting to the string.
  11155. //
  11156. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11157. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11158. // CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG can be or'ed into dwStrType to
  11159. // skip the initial attempt to decode as UTF8.
  11160. //
  11161. // Returns the number of characters converted including the terminating null
  11162. // character. If psz is NULL or csz is 0, returns the required size of the
  11163. // destination string (including the terminating null char).
  11164. //
  11165. // If psz != NULL && csz != 0, returned psz is always NULL terminated.
  11166. //
  11167. // Note: csz includes the NULL char.
  11168. //--------------------------------------------------------------------------
  11169. //+-------------------------------------------------------------------------
  11170. //--------------------------------------------------------------------------
  11171. WINCRYPT32API
  11172. DWORD
  11173. WINAPI
  11174. CertNameToStrA(
  11175. IN DWORD dwCertEncodingType,
  11176. IN PCERT_NAME_BLOB pName,
  11177. IN DWORD dwStrType,
  11178. OUT OPTIONAL LPSTR psz,
  11179. IN DWORD csz
  11180. );
  11181. //+-------------------------------------------------------------------------
  11182. //--------------------------------------------------------------------------
  11183. WINCRYPT32API
  11184. DWORD
  11185. WINAPI
  11186. CertNameToStrW(
  11187. IN DWORD dwCertEncodingType,
  11188. IN PCERT_NAME_BLOB pName,
  11189. IN DWORD dwStrType,
  11190. OUT OPTIONAL LPWSTR psz,
  11191. IN DWORD csz
  11192. );
  11193. #ifdef UNICODE
  11194. #define CertNameToStr CertNameToStrW
  11195. #else
  11196. #define CertNameToStr CertNameToStrA
  11197. #endif // !UNICODE
  11198. //+-------------------------------------------------------------------------
  11199. // Certificate name string types
  11200. //--------------------------------------------------------------------------
  11201. #define CERT_SIMPLE_NAME_STR 1
  11202. #define CERT_OID_NAME_STR 2
  11203. #define CERT_X500_NAME_STR 3
  11204. //+-------------------------------------------------------------------------
  11205. // Certificate name string type flags OR'ed with the above types
  11206. //--------------------------------------------------------------------------
  11207. #define CERT_NAME_STR_SEMICOLON_FLAG 0x40000000
  11208. #define CERT_NAME_STR_NO_PLUS_FLAG 0x20000000
  11209. #define CERT_NAME_STR_NO_QUOTING_FLAG 0x10000000
  11210. #define CERT_NAME_STR_CRLF_FLAG 0x08000000
  11211. #define CERT_NAME_STR_COMMA_FLAG 0x04000000
  11212. #define CERT_NAME_STR_REVERSE_FLAG 0x02000000
  11213. #define CERT_NAME_STR_DISABLE_IE4_UTF8_FLAG 0x00010000
  11214. #define CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG 0x00020000
  11215. #define CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG 0x00040000
  11216. //+-------------------------------------------------------------------------
  11217. // Convert the null terminated X500 string to an encoded certificate name.
  11218. //
  11219. // The input string is expected to be formatted the same as the output
  11220. // from the above CertNameToStr API.
  11221. //
  11222. // The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  11223. // is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  11224. // case insensitive X500 key (CN=), case insensitive "OID." prefixed
  11225. // object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  11226. //
  11227. // If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  11228. // separators and "+" as the multiple RDN value separator. Quoting is
  11229. // supported. A quote may be included in a quoted value by double quoting,
  11230. // for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  11231. // as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  11232. // is skipped (1.2.3 = # AB CD 01 is the same as 1.2.3=#ABCD01).
  11233. //
  11234. // Whitespace surrounding the keys, object identifers and values is removed.
  11235. //
  11236. // CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  11237. // "," as the RDN separator.
  11238. //
  11239. // CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  11240. // ";" as the RDN separator.
  11241. //
  11242. // CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  11243. // "\r" or "\n" as the RDN separator.
  11244. //
  11245. // CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  11246. // as a separator and not allow multiple values per RDN.
  11247. //
  11248. // CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  11249. // quoting.
  11250. //
  11251. // CERT_NAME_STR_REVERSE_FLAG can be or'ed into dwStrType to reverse the
  11252. // order of the RDNs after converting from the string and before encoding.
  11253. //
  11254. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG can be or'ed into dwStrType to
  11255. // to select the CERT_RDN_T61_STRING encoded value type instead of
  11256. // CERT_RDN_UNICODE_STRING if all the UNICODE characters are <= 0xFF.
  11257. //
  11258. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG can be or'ed into dwStrType to
  11259. // to select the CERT_RDN_UTF8_STRING encoded value type instead of
  11260. // CERT_RDN_UNICODE_STRING.
  11261. //
  11262. // Support the following X500 Keys:
  11263. //
  11264. // Key Object Identifier RDN Value Type(s)
  11265. // --- ----------------- -----------------
  11266. // CN szOID_COMMON_NAME Printable, Unicode
  11267. // L szOID_LOCALITY_NAME Printable, Unicode
  11268. // O szOID_ORGANIZATION_NAME Printable, Unicode
  11269. // OU szOID_ORGANIZATIONAL_UNIT_NAME Printable, Unicode
  11270. // E szOID_RSA_emailAddr Only IA5
  11271. // Email szOID_RSA_emailAddr Only IA5
  11272. // C szOID_COUNTRY_NAME Only Printable
  11273. // S szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11274. // ST szOID_STATE_OR_PROVINCE_NAME Printable, Unicode
  11275. // STREET szOID_STREET_ADDRESS Printable, Unicode
  11276. // T szOID_TITLE Printable, Unicode
  11277. // Title szOID_TITLE Printable, Unicode
  11278. // G szOID_GIVEN_NAME Printable, Unicode
  11279. // GivenName szOID_GIVEN_NAME Printable, Unicode
  11280. // I szOID_INITIALS Printable, Unicode
  11281. // Initials szOID_INITIALS Printable, Unicode
  11282. // SN szOID_SUR_NAME Printable, Unicode
  11283. // DC szOID_DOMAIN_COMPONENT IA5, UTF8
  11284. //
  11285. // Note, T61 is selected instead of Unicode if
  11286. // CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG is set and all the unicode
  11287. // characters are <= 0xFF.
  11288. //
  11289. // Note, UTF8 is selected instead of Unicode if
  11290. // CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG is set.
  11291. //
  11292. // Returns TRUE if successfully parsed the input string and encoded
  11293. // the name.
  11294. //
  11295. // If the input string is detected to be invalid, *ppszError is updated
  11296. // to point to the beginning of the invalid character sequence. Otherwise,
  11297. // *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  11298. // for the following errors:
  11299. // CRYPT_E_INVALID_X500_STRING
  11300. // CRYPT_E_INVALID_NUMERIC_STRING
  11301. // CRYPT_E_INVALID_PRINTABLE_STRING
  11302. // CRYPT_E_INVALID_IA5_STRING
  11303. //
  11304. // ppszError can be set to NULL if not interested in getting a pointer
  11305. // to the invalid character sequence.
  11306. //--------------------------------------------------------------------------
  11307. //+-------------------------------------------------------------------------
  11308. //--------------------------------------------------------------------------
  11309. WINCRYPT32API
  11310. BOOL
  11311. WINAPI
  11312. CertStrToNameA(
  11313. IN DWORD dwCertEncodingType,
  11314. IN LPCSTR pszX500,
  11315. IN DWORD dwStrType,
  11316. IN OPTIONAL void *pvReserved,
  11317. OUT BYTE *pbEncoded,
  11318. IN OUT DWORD *pcbEncoded,
  11319. OUT OPTIONAL LPCSTR *ppszError
  11320. );
  11321. //+-------------------------------------------------------------------------
  11322. //--------------------------------------------------------------------------
  11323. WINCRYPT32API
  11324. BOOL
  11325. WINAPI
  11326. CertStrToNameW(
  11327. IN DWORD dwCertEncodingType,
  11328. IN LPCWSTR pszX500,
  11329. IN DWORD dwStrType,
  11330. IN OPTIONAL void *pvReserved,
  11331. OUT BYTE *pbEncoded,
  11332. IN OUT DWORD *pcbEncoded,
  11333. OUT OPTIONAL LPCWSTR *ppszError
  11334. );
  11335. #ifdef UNICODE
  11336. #define CertStrToName CertStrToNameW
  11337. #else
  11338. #define CertStrToName CertStrToNameA
  11339. #endif // !UNICODE
  11340. //+-------------------------------------------------------------------------
  11341. // Get the subject or issuer name from the certificate and
  11342. // according to the specified format type, convert to a null terminated
  11343. // character string.
  11344. //
  11345. // CERT_NAME_ISSUER_FLAG can be set to get the issuer's name. Otherwise,
  11346. // gets the subject's name.
  11347. //
  11348. // By default, CERT_RDN_T61_STRING encoded values are initially decoded
  11349. // as UTF8. If the UTF8 decoding fails, then, decoded as 8 bit characters.
  11350. // CERT_NAME_DISABLE_IE4_UTF8_FLAG can be set in dwFlags to
  11351. // skip the initial attempt to decode as UTF8.
  11352. //
  11353. // The name string is formatted according to the dwType:
  11354. // CERT_NAME_EMAIL_TYPE
  11355. // If the certificate has a Subject Alternative Name extension (for
  11356. // issuer, Issuer Alternative Name), searches for first rfc822Name choice.
  11357. // If the rfc822Name choice isn't found in the extension, searches the
  11358. // Subject Name field for the Email OID, "1.2.840.113549.1.9.1".
  11359. // If the rfc822Name or Email OID is found, returns the string. Otherwise,
  11360. // returns an empty string (returned character count is 1).
  11361. // CERT_NAME_DNS_TYPE
  11362. // If the certificate has a Subject Alternative Name extension (for
  11363. // issuer, Issuer Alternative Name), searches for first DNSName choice.
  11364. // If the DNSName choice isn't found in the extension, searches the
  11365. // Subject Name field for the CN OID, "2.5.4.3".
  11366. // If the DNSName or CN OID is found, returns the string. Otherwise,
  11367. // returns an empty string.
  11368. // CERT_NAME_URL_TYPE
  11369. // If the certificate has a Subject Alternative Name extension (for
  11370. // issuer, Issuer Alternative Name), searches for first URL choice.
  11371. // If the URL choice is found, returns the string. Otherwise,
  11372. // returns an empty string.
  11373. // CERT_NAME_UPN_TYPE
  11374. // If the certificate has a Subject Alternative Name extension,
  11375. // searches the OtherName choices looking for a
  11376. // pszObjId == szOID_NT_PRINCIPAL_NAME, "1.3.6.1.4.1.311.20.2.3".
  11377. // If the UPN OID is found, the blob is decoded as a
  11378. // X509_UNICODE_ANY_STRING and the decoded string is returned.
  11379. // Otherwise, returns an empty string.
  11380. // CERT_NAME_RDN_TYPE
  11381. // Converts the Subject Name blob by calling CertNameToStr. pvTypePara
  11382. // points to a DWORD containing the dwStrType passed to CertNameToStr.
  11383. // If the Subject Name field is empty and the certificate has a
  11384. // Subject Alternative Name extension, searches for and converts
  11385. // the first directoryName choice.
  11386. // CERT_NAME_ATTR_TYPE
  11387. // pvTypePara points to the Object Identifier specifying the name attribute
  11388. // to be returned. For example, to get the CN,
  11389. // pvTypePara = szOID_COMMON_NAME ("2.5.4.3"). Searches, the Subject Name
  11390. // field for the attribute.
  11391. // If the Subject Name field is empty and the certificate has a
  11392. // Subject Alternative Name extension, checks for
  11393. // the first directoryName choice and searches it.
  11394. //
  11395. // Note, searches the RDNs in reverse order.
  11396. //
  11397. // CERT_NAME_SIMPLE_DISPLAY_TYPE
  11398. // Iterates through the following list of name attributes and searches
  11399. // the Subject Name and then the Subject Alternative Name extension
  11400. // for the first occurrence of:
  11401. // szOID_COMMON_NAME ("2.5.4.3")
  11402. // szOID_ORGANIZATIONAL_UNIT_NAME ("2.5.4.11")
  11403. // szOID_ORGANIZATION_NAME ("2.5.4.10")
  11404. // szOID_RSA_emailAddr ("1.2.840.113549.1.9.1")
  11405. //
  11406. // If none of the above attributes is found, then, searches the
  11407. // Subject Alternative Name extension for a rfc822Name choice.
  11408. //
  11409. // If still no match, then, returns the first attribute.
  11410. //
  11411. // Note, like CERT_NAME_ATTR_TYPE, searches the RDNs in reverse order.
  11412. //
  11413. // CERT_NAME_FRIENDLY_DISPLAY_TYPE
  11414. // First checks if the certificate has a CERT_FRIENDLY_NAME_PROP_ID
  11415. // property. If it does, then, this property is returned. Otherwise,
  11416. // returns the above CERT_NAME_SIMPLE_DISPLAY_TYPE.
  11417. //
  11418. // Returns the number of characters converted including the terminating null
  11419. // character. If pwszNameString is NULL or cchNameString is 0, returns the
  11420. // required size of the destination string (including the terminating null
  11421. // char). If the specified name type isn't found. returns an empty string
  11422. // with a returned character count of 1.
  11423. //
  11424. // If pwszNameString != NULL && cwszNameString != 0, returned pwszNameString
  11425. // is always NULL terminated.
  11426. //
  11427. // Note: cchNameString includes the NULL char.
  11428. //--------------------------------------------------------------------------
  11429. //+-------------------------------------------------------------------------
  11430. //--------------------------------------------------------------------------
  11431. WINCRYPT32API
  11432. DWORD
  11433. WINAPI
  11434. CertGetNameStringA(
  11435. IN PCCERT_CONTEXT pCertContext,
  11436. IN DWORD dwType,
  11437. IN DWORD dwFlags,
  11438. IN void *pvTypePara,
  11439. OUT OPTIONAL LPSTR pszNameString,
  11440. IN DWORD cchNameString
  11441. );
  11442. //+-------------------------------------------------------------------------
  11443. //--------------------------------------------------------------------------
  11444. WINCRYPT32API
  11445. DWORD
  11446. WINAPI
  11447. CertGetNameStringW(
  11448. IN PCCERT_CONTEXT pCertContext,
  11449. IN DWORD dwType,
  11450. IN DWORD dwFlags,
  11451. IN void *pvTypePara,
  11452. OUT OPTIONAL LPWSTR pszNameString,
  11453. IN DWORD cchNameString
  11454. );
  11455. #ifdef UNICODE
  11456. #define CertGetNameString CertGetNameStringW
  11457. #else
  11458. #define CertGetNameString CertGetNameStringA
  11459. #endif // !UNICODE
  11460. //+-------------------------------------------------------------------------
  11461. // Certificate name types
  11462. //--------------------------------------------------------------------------
  11463. #define CERT_NAME_EMAIL_TYPE 1
  11464. #define CERT_NAME_RDN_TYPE 2
  11465. #define CERT_NAME_ATTR_TYPE 3
  11466. #define CERT_NAME_SIMPLE_DISPLAY_TYPE 4
  11467. #define CERT_NAME_FRIENDLY_DISPLAY_TYPE 5
  11468. #define CERT_NAME_DNS_TYPE 6
  11469. #define CERT_NAME_URL_TYPE 7
  11470. #define CERT_NAME_UPN_TYPE 8
  11471. //+-------------------------------------------------------------------------
  11472. // Certificate name flags
  11473. //--------------------------------------------------------------------------
  11474. #define CERT_NAME_ISSUER_FLAG 0x1
  11475. #define CERT_NAME_DISABLE_IE4_UTF8_FLAG 0x00010000
  11476. //+=========================================================================
  11477. // Simplified Cryptographic Message Data Structures and APIs
  11478. //==========================================================================
  11479. //+-------------------------------------------------------------------------
  11480. // Conventions for the *pb and *pcb output parameters:
  11481. //
  11482. // Upon entry to the function:
  11483. // if pcb is OPTIONAL && pcb == NULL, then,
  11484. // No output is returned
  11485. // else if pb == NULL && pcb != NULL, then,
  11486. // Length only determination. No length error is
  11487. // returned.
  11488. // otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  11489. // Output is returned. If *pcb isn't big enough a
  11490. // length error is returned. In all cases *pcb is updated
  11491. // with the actual length needed/returned.
  11492. //--------------------------------------------------------------------------
  11493. //+-------------------------------------------------------------------------
  11494. // Type definitions of the parameters used for doing the cryptographic
  11495. // operations.
  11496. //--------------------------------------------------------------------------
  11497. //+-------------------------------------------------------------------------
  11498. // Callback to get and verify the signer's certificate.
  11499. //
  11500. // Passed the CertId of the signer (its Issuer and SerialNumber) and a
  11501. // handle to its cryptographic signed message's cert store.
  11502. //
  11503. // For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  11504. //
  11505. // For a valid signer certificate, returns a pointer to a read only
  11506. // CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  11507. // cert store or was created via CertCreateCertificateContext. For either case,
  11508. // its freed via CertFreeCertificateContext.
  11509. //
  11510. // If a valid certificate isn't found, this callback returns NULL with
  11511. // LastError set via SetLastError().
  11512. //
  11513. // The NULL implementation tries to get the Signer certificate from the
  11514. // message cert store. It doesn't verify the certificate.
  11515. //
  11516. // Note, if the KEYID choice was selected for a CMS SignerId, then, the
  11517. // SerialNumber is 0 and the Issuer is encoded containing a single RDN with a
  11518. // single Attribute whose OID is szOID_KEYID_RDN, value type is
  11519. // CERT_RDN_OCTET_STRING and value is the KEYID. When the
  11520. // CertGetSubjectCertificateFromStore and
  11521. // CertFindCertificateInStore(CERT_FIND_SUBJECT_CERT) APIs see this
  11522. // special KEYID Issuer and SerialNumber, they do a KEYID match.
  11523. //--------------------------------------------------------------------------
  11524. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  11525. IN void *pvGetArg,
  11526. IN DWORD dwCertEncodingType,
  11527. IN PCERT_INFO pSignerId, // Only the Issuer and SerialNumber
  11528. // fields have been updated
  11529. IN HCERTSTORE hMsgCertStore
  11530. );
  11531. //+-------------------------------------------------------------------------
  11532. // The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  11533. // specified signing certificate context.
  11534. //
  11535. // Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  11536. // be set for each rgpSigningCert[]. Either one specifies the private
  11537. // signature key to use.
  11538. //
  11539. // If any certificates and/or CRLs are to be included in the signed message,
  11540. // then, the MsgCert and MsgCrl parameters need to be updated. If the
  11541. // rgpSigningCerts are to be included, then, they must also be in the
  11542. // rgpMsgCert array.
  11543. //
  11544. // cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  11545. // LastError will be updated with E_INVALIDARG.
  11546. //
  11547. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11548. //
  11549. // dwFlags normally is set to 0. However, if the encoded output
  11550. // is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  11551. // such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11552. // should be set. If not set, then it would be encoded as an inner content
  11553. // type of CMSG_DATA.
  11554. //
  11555. // dwInnerContentType is normally set to 0. It needs to be set if the
  11556. // ToBeSigned input is the encoded output of another cryptographic
  11557. // message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  11558. // message types, for example, CMSG_ENVELOPED.
  11559. //
  11560. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11561. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11562. //
  11563. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11564. // set to encapsulate nonData inner content within an OCTET STRING.
  11565. //
  11566. // For CMS messages, CRYPT_MESSAGE_KEYID_SIGNER_FLAG may be set to identify
  11567. // signers by their Key Identifier and not their Issuer and Serial Number.
  11568. //
  11569. // The CRYPT_MESSAGE_SILENT_KEYSET_FLAG can be set to suppress any UI by the
  11570. // CSP. See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11571. //
  11572. // If HashEncryptionAlgorithm is present and not NULL its used instead of
  11573. // the SigningCert's PublicKeyInfo.Algorithm.
  11574. //
  11575. // Note, for RSA, the hash encryption algorithm is normally the same as
  11576. // the public key algorithm. For DSA, the hash encryption algorithm is
  11577. // normally a DSS signature algorithm.
  11578. //
  11579. // pvHashEncryptionAuxInfo currently isn't used and must be set to NULL if
  11580. // present in the data structure.
  11581. //--------------------------------------------------------------------------
  11582. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  11583. DWORD cbSize;
  11584. DWORD dwMsgEncodingType;
  11585. PCCERT_CONTEXT pSigningCert;
  11586. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11587. void *pvHashAuxInfo;
  11588. DWORD cMsgCert;
  11589. PCCERT_CONTEXT *rgpMsgCert;
  11590. DWORD cMsgCrl;
  11591. PCCRL_CONTEXT *rgpMsgCrl;
  11592. DWORD cAuthAttr;
  11593. PCRYPT_ATTRIBUTE rgAuthAttr;
  11594. DWORD cUnauthAttr;
  11595. PCRYPT_ATTRIBUTE rgUnauthAttr;
  11596. DWORD dwFlags;
  11597. DWORD dwInnerContentType;
  11598. #ifdef CRYPT_SIGN_MESSAGE_PARA_HAS_CMS_FIELDS
  11599. CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
  11600. void *pvHashEncryptionAuxInfo;
  11601. #endif
  11602. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  11603. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG 0x00000001
  11604. // When set, nonData type inner content is encapsulated within an
  11605. // OCTET STRING
  11606. #define CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG 0x00000002
  11607. // When set, signers are identified by their Key Identifier and not
  11608. // their Issuer and Serial Number.
  11609. #define CRYPT_MESSAGE_KEYID_SIGNER_FLAG 0x00000004
  11610. // When set, suppresses any UI by the CSP.
  11611. // See CryptAcquireContext's CRYPT_SILENT flag for more details.
  11612. #define CRYPT_MESSAGE_SILENT_KEYSET_FLAG 0x00000040
  11613. //+-------------------------------------------------------------------------
  11614. // The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  11615. //
  11616. // hCryptProv is used to do hashing and signature verification.
  11617. //
  11618. // The dwCertEncodingType specifies the encoding type of the certificates
  11619. // and/or CRLs in the message.
  11620. //
  11621. // pfnGetSignerCertificate is called to get and verify the message signer's
  11622. // certificate.
  11623. //
  11624. // cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  11625. // LastError will be updated with E_INVALIDARG.
  11626. //--------------------------------------------------------------------------
  11627. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  11628. DWORD cbSize;
  11629. DWORD dwMsgAndCertEncodingType;
  11630. HCRYPTPROV hCryptProv;
  11631. PFN_CRYPT_GET_SIGNER_CERTIFICATE pfnGetSignerCertificate;
  11632. void *pvGetArg;
  11633. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  11634. //+-------------------------------------------------------------------------
  11635. // The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  11636. //
  11637. // hCryptProv is used to do content encryption, recipient key
  11638. // encryption, and recipient key export. Its private key
  11639. // isn't used.
  11640. //
  11641. // Currently, pvEncryptionAuxInfo is only defined for RC2 or RC4 encryption
  11642. // algorithms. Otherwise, its not used and must be set to NULL.
  11643. // See CMSG_RC2_AUX_INFO for the RC2 encryption algorithms.
  11644. // See CMSG_RC4_AUX_INFO for the RC4 encryption algorithms.
  11645. //
  11646. // To enable SP3 compatible encryption, pvEncryptionAuxInfo should point to
  11647. // a CMSG_SP3_COMPATIBLE_AUX_INFO data structure.
  11648. //
  11649. // cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  11650. // LastError will be updated with E_INVALIDARG.
  11651. //
  11652. // dwFlags normally is set to 0. However, if the encoded output
  11653. // is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  11654. // such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  11655. // should be set. If not set, then it would be encoded as an inner content
  11656. // type of CMSG_DATA.
  11657. //
  11658. // dwInnerContentType is normally set to 0. It needs to be set if the
  11659. // ToBeEncrypted input is the encoded output of another cryptographic
  11660. // message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  11661. // message types, for example, CMSG_SIGNED.
  11662. //
  11663. // If the inner content of a nested cryptographic message is data (CMSG_DATA
  11664. // the default), then, neither dwFlags or dwInnerContentType need to be set.
  11665. //
  11666. // For CMS messages, CRYPT_MESSAGE_ENCAPSULATED_CONTENT_OUT_FLAG may be
  11667. // set to encapsulate nonData inner content within an OCTET STRING before
  11668. // encrypting.
  11669. //
  11670. // For CMS messages, CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG may be set to identify
  11671. // recipients by their Key Identifier and not their Issuer and Serial Number.
  11672. //--------------------------------------------------------------------------
  11673. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  11674. DWORD cbSize;
  11675. DWORD dwMsgEncodingType;
  11676. HCRYPTPROV hCryptProv;
  11677. CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
  11678. void *pvEncryptionAuxInfo;
  11679. DWORD dwFlags;
  11680. DWORD dwInnerContentType;
  11681. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  11682. // When set, recipients are identified by their Key Identifier and not
  11683. // their Issuer and Serial Number.
  11684. #define CRYPT_MESSAGE_KEYID_RECIPIENT_FLAG 0x4
  11685. //+-------------------------------------------------------------------------
  11686. // The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  11687. //
  11688. // The CertContext to use for decrypting a message is obtained from one
  11689. // of the specified cert stores. An encrypted message can have one or
  11690. // more recipients. The recipients are identified by their CertId (Issuer
  11691. // and SerialNumber). The cert stores are searched to find the CertContext
  11692. // corresponding to the CertId.
  11693. //
  11694. // For CMS, the recipients may also be identified by their KeyId.
  11695. // CMS also allows Key Agreement (Diffie Hellman) in addition to
  11696. // Key Transport (RSA) recipients.
  11697. //
  11698. // Only CertContexts in the store with either
  11699. // the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  11700. // can be used. Either property specifies the private exchange key to use.
  11701. //
  11702. // cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  11703. // LastError will be updated with E_INVALIDARG.
  11704. //--------------------------------------------------------------------------
  11705. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  11706. DWORD cbSize;
  11707. DWORD dwMsgAndCertEncodingType;
  11708. DWORD cCertStore;
  11709. HCERTSTORE *rghCertStore;
  11710. #ifdef CRYPT_DECRYPT_MESSAGE_PARA_HAS_EXTRA_FIELDS
  11711. // The above defined, CRYPT_MESSAGE_SILENT_KEYSET_FLAG, can be set to
  11712. // suppress UI by the CSP. See CryptAcquireContext's CRYPT_SILENT
  11713. // flag for more details.
  11714. DWORD dwFlags;
  11715. #endif
  11716. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  11717. //+-------------------------------------------------------------------------
  11718. // The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  11719. // messages.
  11720. //
  11721. // hCryptProv is used to compute the hash.
  11722. //
  11723. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11724. //
  11725. // cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  11726. // LastError will be updated with E_INVALIDARG.
  11727. //--------------------------------------------------------------------------
  11728. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  11729. DWORD cbSize;
  11730. DWORD dwMsgEncodingType;
  11731. HCRYPTPROV hCryptProv;
  11732. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11733. void *pvHashAuxInfo;
  11734. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  11735. //+-------------------------------------------------------------------------
  11736. // The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  11737. // certificate has been created for the signature key.
  11738. //
  11739. // pvHashAuxInfo currently isn't used and must be set to NULL.
  11740. //
  11741. // If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  11742. //
  11743. // cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  11744. // LastError will be updated with E_INVALIDARG.
  11745. //--------------------------------------------------------------------------
  11746. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  11747. DWORD cbSize;
  11748. DWORD dwMsgAndCertEncodingType;
  11749. HCRYPTPROV hCryptProv;
  11750. DWORD dwKeySpec;
  11751. CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
  11752. void *pvHashAuxInfo;
  11753. CRYPT_ALGORITHM_IDENTIFIER PubKeyAlgorithm;
  11754. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  11755. //+-------------------------------------------------------------------------
  11756. // The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  11757. // a certificate for the signer.
  11758. //
  11759. // Normally used until a certificate has been created for the key.
  11760. //
  11761. // hCryptProv is used to do hashing and signature verification.
  11762. //
  11763. // cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  11764. // LastError will be updated with E_INVALIDARG.
  11765. //--------------------------------------------------------------------------
  11766. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  11767. DWORD cbSize;
  11768. DWORD dwMsgEncodingType;
  11769. HCRYPTPROV hCryptProv;
  11770. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  11771. //+-------------------------------------------------------------------------
  11772. // Sign the message.
  11773. //
  11774. // If fDetachedSignature is TRUE, the "to be signed" content isn't included
  11775. // in the encoded signed blob.
  11776. //--------------------------------------------------------------------------
  11777. WINCRYPT32API
  11778. BOOL
  11779. WINAPI
  11780. CryptSignMessage(
  11781. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11782. IN BOOL fDetachedSignature,
  11783. IN DWORD cToBeSigned,
  11784. IN const BYTE *rgpbToBeSigned[],
  11785. IN DWORD rgcbToBeSigned[],
  11786. OUT BYTE *pbSignedBlob,
  11787. IN OUT DWORD *pcbSignedBlob
  11788. );
  11789. //+-------------------------------------------------------------------------
  11790. // Verify a signed message.
  11791. //
  11792. // If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  11793. // For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  11794. // verified.
  11795. //
  11796. // A message might have more than one signer. Set dwSignerIndex to iterate
  11797. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11798. //
  11799. // pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  11800. // certificate.
  11801. //
  11802. // For a verified signer and message, *ppSignerCert is updated
  11803. // with the CertContext of the signer. It must be freed by calling
  11804. // CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  11805. //
  11806. // ppSignerCert can be NULL, indicating the caller isn't interested
  11807. // in getting the CertContext of the signer.
  11808. //
  11809. // pcbDecoded can be NULL, indicating the caller isn't interested in getting
  11810. // the decoded content. Furthermore, if the message doesn't contain any
  11811. // content or signers, then, pcbDecoded must be set to NULL, to allow the
  11812. // pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  11813. // the case when the signed message contains only certficates and CRLs.
  11814. // If pcbDecoded is NULL and the message doesn't have the indicated signer,
  11815. // pfnGetCertificate is called with pSignerId set to NULL.
  11816. //
  11817. // If the message doesn't contain any signers || dwSignerIndex > message's
  11818. // SignerCount, then, an error is returned with LastError set to
  11819. // CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  11820. // is still called with pSignerId set to NULL.
  11821. //
  11822. // Note, an alternative way to get the certificates and CRLs from a
  11823. // signed message is to call CryptGetMessageCertificates.
  11824. //--------------------------------------------------------------------------
  11825. WINCRYPT32API
  11826. BOOL
  11827. WINAPI
  11828. CryptVerifyMessageSignature(
  11829. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11830. IN DWORD dwSignerIndex,
  11831. IN const BYTE *pbSignedBlob,
  11832. IN DWORD cbSignedBlob,
  11833. OUT BYTE OPTIONAL *pbDecoded,
  11834. IN OUT OPTIONAL DWORD *pcbDecoded,
  11835. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11836. );
  11837. //+-------------------------------------------------------------------------
  11838. // Returns the count of signers in the signed message. For no signers, returns
  11839. // 0. For an error returns -1 with LastError updated accordingly.
  11840. //--------------------------------------------------------------------------
  11841. WINCRYPT32API
  11842. LONG
  11843. WINAPI
  11844. CryptGetMessageSignerCount(
  11845. IN DWORD dwMsgEncodingType,
  11846. IN const BYTE *pbSignedBlob,
  11847. IN DWORD cbSignedBlob
  11848. );
  11849. //+-------------------------------------------------------------------------
  11850. // Returns the cert store containing the message's certs and CRLs.
  11851. // For an error, returns NULL with LastError updated.
  11852. //--------------------------------------------------------------------------
  11853. WINCRYPT32API
  11854. HCERTSTORE
  11855. WINAPI
  11856. CryptGetMessageCertificates(
  11857. IN DWORD dwMsgAndCertEncodingType,
  11858. IN HCRYPTPROV hCryptProv, // passed to CertOpenStore
  11859. IN DWORD dwFlags, // passed to CertOpenStore
  11860. IN const BYTE *pbSignedBlob,
  11861. IN DWORD cbSignedBlob
  11862. );
  11863. //+-------------------------------------------------------------------------
  11864. // Verify a signed message containing detached signature(s).
  11865. // The "to be signed" content is passed in separately. No
  11866. // decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  11867. //--------------------------------------------------------------------------
  11868. WINCRYPT32API
  11869. BOOL
  11870. WINAPI
  11871. CryptVerifyDetachedMessageSignature(
  11872. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11873. IN DWORD dwSignerIndex,
  11874. IN const BYTE *pbDetachedSignBlob,
  11875. IN DWORD cbDetachedSignBlob,
  11876. IN DWORD cToBeSigned,
  11877. IN const BYTE *rgpbToBeSigned[],
  11878. IN DWORD rgcbToBeSigned[],
  11879. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11880. );
  11881. //+-------------------------------------------------------------------------
  11882. // Encrypts the message for the recipient(s).
  11883. //--------------------------------------------------------------------------
  11884. WINCRYPT32API
  11885. BOOL
  11886. WINAPI
  11887. CryptEncryptMessage(
  11888. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11889. IN DWORD cRecipientCert,
  11890. IN PCCERT_CONTEXT rgpRecipientCert[],
  11891. IN const BYTE *pbToBeEncrypted,
  11892. IN DWORD cbToBeEncrypted,
  11893. OUT BYTE *pbEncryptedBlob,
  11894. IN OUT DWORD *pcbEncryptedBlob
  11895. );
  11896. //+-------------------------------------------------------------------------
  11897. // Decrypts the message.
  11898. //
  11899. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11900. // For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  11901. // decrypted.
  11902. //
  11903. // For a successfully decrypted message, *ppXchgCert is updated
  11904. // with the CertContext used to decrypt. It must be freed by calling
  11905. // CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  11906. //
  11907. // ppXchgCert can be NULL, indicating the caller isn't interested
  11908. // in getting the CertContext used to decrypt.
  11909. //--------------------------------------------------------------------------
  11910. WINCRYPT32API
  11911. BOOL
  11912. WINAPI
  11913. CryptDecryptMessage(
  11914. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11915. IN const BYTE *pbEncryptedBlob,
  11916. IN DWORD cbEncryptedBlob,
  11917. OUT OPTIONAL BYTE *pbDecrypted,
  11918. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11919. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  11920. );
  11921. //+-------------------------------------------------------------------------
  11922. // Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  11923. // followed with a CryptEncryptMessage.
  11924. //
  11925. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11926. // inside of an CMSG_ENVELOPED.
  11927. //--------------------------------------------------------------------------
  11928. WINCRYPT32API
  11929. BOOL
  11930. WINAPI
  11931. CryptSignAndEncryptMessage(
  11932. IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  11933. IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  11934. IN DWORD cRecipientCert,
  11935. IN PCCERT_CONTEXT rgpRecipientCert[],
  11936. IN const BYTE *pbToBeSignedAndEncrypted,
  11937. IN DWORD cbToBeSignedAndEncrypted,
  11938. OUT BYTE *pbSignedAndEncryptedBlob,
  11939. IN OUT DWORD *pcbSignedAndEncryptedBlob
  11940. );
  11941. //+-------------------------------------------------------------------------
  11942. // Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  11943. // followed with a CryptVerifyMessageSignature.
  11944. //
  11945. // If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  11946. // For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  11947. // verified.
  11948. //
  11949. // A message might have more than one signer. Set dwSignerIndex to iterate
  11950. // through all the signers. dwSignerIndex == 0 selects the first signer.
  11951. //
  11952. // The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  11953. // certificate.
  11954. //
  11955. // For a successfully decrypted and verified message, *ppXchgCert and
  11956. // *ppSignerCert are updated. They must be freed by calling
  11957. // CertStoreFreeCert. Otherwise, they are set to NULL.
  11958. //
  11959. // ppXchgCert and/or ppSignerCert can be NULL, indicating the
  11960. // caller isn't interested in getting the CertContext.
  11961. //
  11962. // Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  11963. // inside of an CMSG_ENVELOPED.
  11964. //
  11965. // The message always needs to be decrypted to allow access to the
  11966. // signed message. Therefore, if ppXchgCert != NULL, its always updated.
  11967. //--------------------------------------------------------------------------
  11968. WINCRYPT32API
  11969. BOOL
  11970. WINAPI
  11971. CryptDecryptAndVerifyMessageSignature(
  11972. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  11973. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  11974. IN DWORD dwSignerIndex,
  11975. IN const BYTE *pbEncryptedBlob,
  11976. IN DWORD cbEncryptedBlob,
  11977. OUT OPTIONAL BYTE *pbDecrypted,
  11978. IN OUT OPTIONAL DWORD *pcbDecrypted,
  11979. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  11980. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  11981. );
  11982. //+-------------------------------------------------------------------------
  11983. // Decodes a cryptographic message which may be one of the following types:
  11984. // CMSG_DATA
  11985. // CMSG_SIGNED
  11986. // CMSG_ENVELOPED
  11987. // CMSG_SIGNED_AND_ENVELOPED
  11988. // CMSG_HASHED
  11989. //
  11990. // dwMsgTypeFlags specifies the set of allowable messages. For example, to
  11991. // decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  11992. // CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  11993. //
  11994. // dwProvInnerContentType is only applicable when processing nested
  11995. // crytographic messages. When processing an outer crytographic message
  11996. // it must be set to 0. When decoding a nested cryptographic message
  11997. // its the dwInnerContentType returned by a previous CryptDecodeMessage
  11998. // of the outer message. The InnerContentType can be any of the CMSG types,
  11999. // for example, CMSG_DATA, CMSG_SIGNED, ...
  12000. //
  12001. // The optional *pdwMsgType is updated with the type of message.
  12002. //
  12003. // The optional *pdwInnerContentType is updated with the type of the inner
  12004. // message. Unless there is cryptographic message nesting, CMSG_DATA
  12005. // is returned.
  12006. //
  12007. // For CMSG_DATA: returns decoded content.
  12008. // For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  12009. // For CMSG_ENVELOPED: same as CryptDecryptMessage.
  12010. // For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  12011. // CryptVerifyMessageSignature.
  12012. // For CMSG_HASHED: verifies the hash and returns decoded content.
  12013. //--------------------------------------------------------------------------
  12014. WINCRYPT32API
  12015. BOOL
  12016. WINAPI
  12017. CryptDecodeMessage(
  12018. IN DWORD dwMsgTypeFlags,
  12019. IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  12020. IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  12021. IN DWORD dwSignerIndex,
  12022. IN const BYTE *pbEncodedBlob,
  12023. IN DWORD cbEncodedBlob,
  12024. IN DWORD dwPrevInnerContentType,
  12025. OUT OPTIONAL DWORD *pdwMsgType,
  12026. OUT OPTIONAL DWORD *pdwInnerContentType,
  12027. OUT OPTIONAL BYTE *pbDecoded,
  12028. IN OUT OPTIONAL DWORD *pcbDecoded,
  12029. OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  12030. OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  12031. );
  12032. //+-------------------------------------------------------------------------
  12033. // Hash the message.
  12034. //
  12035. // If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  12036. // pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  12037. // are encoded.
  12038. //
  12039. // pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  12040. // isn't interested in getting the output.
  12041. //--------------------------------------------------------------------------
  12042. WINCRYPT32API
  12043. BOOL
  12044. WINAPI
  12045. CryptHashMessage(
  12046. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12047. IN BOOL fDetachedHash,
  12048. IN DWORD cToBeHashed,
  12049. IN const BYTE *rgpbToBeHashed[],
  12050. IN DWORD rgcbToBeHashed[],
  12051. OUT OPTIONAL BYTE *pbHashedBlob,
  12052. IN OUT OPTIONAL DWORD *pcbHashedBlob,
  12053. OUT OPTIONAL BYTE *pbComputedHash,
  12054. IN OUT OPTIONAL DWORD *pcbComputedHash
  12055. );
  12056. //+-------------------------------------------------------------------------
  12057. // Verify a hashed message.
  12058. //
  12059. // pcbToBeHashed or pcbComputedHash can be NULL,
  12060. // indicating the caller isn't interested in getting the output.
  12061. //--------------------------------------------------------------------------
  12062. WINCRYPT32API
  12063. BOOL
  12064. WINAPI
  12065. CryptVerifyMessageHash(
  12066. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12067. IN BYTE *pbHashedBlob,
  12068. IN DWORD cbHashedBlob,
  12069. OUT OPTIONAL BYTE *pbToBeHashed,
  12070. IN OUT OPTIONAL DWORD *pcbToBeHashed,
  12071. OUT OPTIONAL BYTE *pbComputedHash,
  12072. IN OUT OPTIONAL DWORD *pcbComputedHash
  12073. );
  12074. //+-------------------------------------------------------------------------
  12075. // Verify a hashed message containing a detached hash.
  12076. // The "to be hashed" content is passed in separately. No
  12077. // decoded output. Otherwise, identical to CryptVerifyMessageHash.
  12078. //
  12079. // pcbComputedHash can be NULL, indicating the caller isn't interested
  12080. // in getting the output.
  12081. //--------------------------------------------------------------------------
  12082. WINCRYPT32API
  12083. BOOL
  12084. WINAPI
  12085. CryptVerifyDetachedMessageHash(
  12086. IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  12087. IN BYTE *pbDetachedHashBlob,
  12088. IN DWORD cbDetachedHashBlob,
  12089. IN DWORD cToBeHashed,
  12090. IN const BYTE *rgpbToBeHashed[],
  12091. IN DWORD rgcbToBeHashed[],
  12092. OUT OPTIONAL BYTE *pbComputedHash,
  12093. IN OUT OPTIONAL DWORD *pcbComputedHash
  12094. );
  12095. //+-------------------------------------------------------------------------
  12096. // Sign the message using the provider's private key specified in the
  12097. // parameters. A dummy SignerId is created and stored in the message.
  12098. //
  12099. // Normally used until a certificate has been created for the key.
  12100. //--------------------------------------------------------------------------
  12101. WINCRYPT32API
  12102. BOOL
  12103. WINAPI
  12104. CryptSignMessageWithKey(
  12105. IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  12106. IN const BYTE *pbToBeSigned,
  12107. IN DWORD cbToBeSigned,
  12108. OUT BYTE *pbSignedBlob,
  12109. IN OUT DWORD *pcbSignedBlob
  12110. );
  12111. //+-------------------------------------------------------------------------
  12112. // Verify a signed message using the specified public key info.
  12113. //
  12114. // Normally called by a CA until it has created a certificate for the
  12115. // key.
  12116. //
  12117. // pPublicKeyInfo contains the public key to use to verify the signed
  12118. // message. If NULL, the signature isn't verified (for instance, the decoded
  12119. // content may contain the PublicKeyInfo).
  12120. //
  12121. // pcbDecoded can be NULL, indicating the caller isn't interested
  12122. // in getting the decoded content.
  12123. //--------------------------------------------------------------------------
  12124. WINCRYPT32API
  12125. BOOL
  12126. WINAPI
  12127. CryptVerifyMessageSignatureWithKey(
  12128. IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  12129. IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  12130. IN const BYTE *pbSignedBlob,
  12131. IN DWORD cbSignedBlob,
  12132. OUT OPTIONAL BYTE *pbDecoded,
  12133. IN OUT OPTIONAL DWORD *pcbDecoded
  12134. );
  12135. //+=========================================================================
  12136. // System Certificate Store Data Structures and APIs
  12137. //==========================================================================
  12138. //+-------------------------------------------------------------------------
  12139. // Get a system certificate store based on a subsystem protocol.
  12140. //
  12141. // Current examples of subsystems protocols are:
  12142. // "MY" Cert Store hold certs with associated Private Keys
  12143. // "CA" Certifying Authority certs
  12144. // "ROOT" Root Certs
  12145. // "SPC" Software publisher certs
  12146. //
  12147. //
  12148. // If hProv is NULL the default provider "1" is opened for you.
  12149. // When the store is closed the provider is release. Otherwise
  12150. // if hProv is not NULL, no provider is created or released.
  12151. //
  12152. // The returned Cert Store can be searched for an appropriate Cert
  12153. // using the Cert Store API's (see certstor.h)
  12154. //
  12155. // When done, the cert store should be closed using CertStoreClose
  12156. //--------------------------------------------------------------------------
  12157. WINCRYPT32API
  12158. HCERTSTORE
  12159. WINAPI
  12160. CertOpenSystemStoreA(
  12161. HCRYPTPROV hProv,
  12162. LPCSTR szSubsystemProtocol
  12163. );
  12164. WINCRYPT32API
  12165. HCERTSTORE
  12166. WINAPI
  12167. CertOpenSystemStoreW(
  12168. HCRYPTPROV hProv,
  12169. LPCWSTR szSubsystemProtocol
  12170. );
  12171. #ifdef UNICODE
  12172. #define CertOpenSystemStore CertOpenSystemStoreW
  12173. #else
  12174. #define CertOpenSystemStore CertOpenSystemStoreA
  12175. #endif // !UNICODE
  12176. WINCRYPT32API
  12177. BOOL
  12178. WINAPI
  12179. CertAddEncodedCertificateToSystemStoreA(
  12180. LPCSTR szCertStoreName,
  12181. const BYTE * pbCertEncoded,
  12182. DWORD cbCertEncoded
  12183. );
  12184. WINCRYPT32API
  12185. BOOL
  12186. WINAPI
  12187. CertAddEncodedCertificateToSystemStoreW(
  12188. LPCWSTR szCertStoreName,
  12189. const BYTE * pbCertEncoded,
  12190. DWORD cbCertEncoded
  12191. );
  12192. #ifdef UNICODE
  12193. #define CertAddEncodedCertificateToSystemStore CertAddEncodedCertificateToSystemStoreW
  12194. #else
  12195. #define CertAddEncodedCertificateToSystemStore CertAddEncodedCertificateToSystemStoreA
  12196. #endif // !UNICODE
  12197. //+-------------------------------------------------------------------------
  12198. // Find all certificate chains tying the given issuer name to any certificate
  12199. // that the current user has a private key for.
  12200. //
  12201. // If no certificate chain is found, FALSE is returned with LastError set
  12202. // to CRYPT_E_NOT_FOUND and the counts zeroed.
  12203. //
  12204. // IE 3.0 ASSUMPTION:
  12205. // The client certificates are in the "My" system store. The issuer
  12206. // cerificates may be in the "Root", "CA" or "My" system stores.
  12207. //--------------------------------------------------------------------------
  12208. typedef struct _CERT_CHAIN {
  12209. DWORD cCerts; // number of certs in chain
  12210. PCERT_BLOB certs; // pointer to array of cert chain blobs
  12211. // representing the certs
  12212. CRYPT_KEY_PROV_INFO keyLocatorInfo; // key locator for cert
  12213. } CERT_CHAIN, *PCERT_CHAIN;
  12214. // WINCRYPT32API This is not exported by crypt32, it is exported by softpub
  12215. HRESULT
  12216. WINAPI
  12217. FindCertsByIssuer(
  12218. OUT PCERT_CHAIN pCertChains,
  12219. IN OUT DWORD *pcbCertChains,
  12220. OUT DWORD *pcCertChains, // count of certificates chains returned
  12221. IN BYTE* pbEncodedIssuerName, // DER encoded issuer name
  12222. IN DWORD cbEncodedIssuerName, // count in bytes of encoded issuer name
  12223. IN LPCWSTR pwszPurpose, // "ClientAuth" or "CodeSigning"
  12224. IN DWORD dwKeySpec // only return signers supporting this
  12225. // keyspec
  12226. );
  12227. //-------------------------------------------------------------------------
  12228. //
  12229. // CryptQueryObject takes a CERT_BLOB or a file name and returns the
  12230. // information about the content in the blob or in the file.
  12231. //
  12232. // Parameters:
  12233. // INPUT dwObjectType:
  12234. // Indicate the type of the object. Should be one of the
  12235. // following:
  12236. // CERT_QUERY_OBJECT_FILE
  12237. // CERT_QUERY_OBJECT_BLOB
  12238. //
  12239. // INPUT pvObject:
  12240. // If dwObjectType == CERT_QUERY_OBJECT_FILE, it is a
  12241. // LPWSTR, that is, the pointer to a wchar file name
  12242. // if dwObjectType == CERT_QUERY_OBJECT_BLOB, it is a
  12243. // PCERT_BLOB, that is, a pointer to a CERT_BLOB
  12244. //
  12245. // INPUT dwExpectedContentTypeFlags:
  12246. // Indicate the expected contenet type.
  12247. // Can be one of the following:
  12248. // CERT_QUERY_CONTENT_FLAG_ALL (the content can be any type)
  12249. // CERT_QUERY_CONTENT_FLAG_CERT
  12250. // CERT_QUERY_CONTENT_FLAG_CTL
  12251. // CERT_QUERY_CONTENT_FLAG_CRL
  12252. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE
  12253. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT
  12254. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL
  12255. // CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL
  12256. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
  12257. // CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
  12258. // CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED
  12259. // CERT_QUERY_CONTENT_FLAG_PKCS10
  12260. // CERT_QUERY_CONTENT_FLAG_PFX
  12261. // CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12262. //
  12263. // INPUT dwExpectedFormatTypeFlags:
  12264. // Indicate the expected format type.
  12265. // Can be one of the following:
  12266. // CERT_QUERY_FORMAT_FLAG_ALL (the content can be any format)
  12267. // CERT_QUERY_FORMAT_FLAG_BINARY
  12268. // CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED
  12269. // CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12270. //
  12271. //
  12272. // INPUT dwFlags
  12273. // Reserved flag. Should always set to 0
  12274. //
  12275. // OUTPUT pdwMsgAndCertEncodingType
  12276. // Optional output. If NULL != pdwMsgAndCertEncodingType,
  12277. // it contains the encoding type of the content as any
  12278. // combination of the following:
  12279. // X509_ASN_ENCODING
  12280. // PKCS_7_ASN_ENCODING
  12281. //
  12282. // OUTPUT pdwContentType
  12283. // Optional output. If NULL!=pdwContentType, it contains
  12284. // the content type as one of the the following:
  12285. // CERT_QUERY_CONTENT_CERT
  12286. // CERT_QUERY_CONTENT_CTL
  12287. // CERT_QUERY_CONTENT_CRL
  12288. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12289. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12290. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12291. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12292. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12293. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12294. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12295. // CERT_QUERY_CONTENT_PKCS10
  12296. // CERT_QUERY_CONTENT_PFX
  12297. // CERT_QUERY_CONTENT_CERT_PAIR
  12298. //
  12299. // OUTPUT pdwFormatType
  12300. // Optional output. If NULL !=pdwFormatType, it
  12301. // contains the format type of the content as one of the
  12302. // following:
  12303. // CERT_QUERY_FORMAT_BINARY
  12304. // CERT_QUERY_FORMAT_BASE64_ENCODED
  12305. // CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED
  12306. //
  12307. //
  12308. // OUTPUT phCertStore
  12309. // Optional output. If NULL !=phStore,
  12310. // it contains a cert store that includes all of certificates,
  12311. // CRL, and CTL in the object if the object content type is
  12312. // one of the following:
  12313. // CERT_QUERY_CONTENT_CERT
  12314. // CERT_QUERY_CONTENT_CTL
  12315. // CERT_QUERY_CONTENT_CRL
  12316. // CERT_QUERY_CONTENT_SERIALIZED_STORE
  12317. // CERT_QUERY_CONTENT_SERIALIZED_CERT
  12318. // CERT_QUERY_CONTENT_SERIALIZED_CTL
  12319. // CERT_QUERY_CONTENT_SERIALIZED_CRL
  12320. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12321. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12322. // CERT_QUERY_CONTENT_CERT_PAIR
  12323. //
  12324. // Caller should free *phCertStore via CertCloseStore.
  12325. //
  12326. //
  12327. // OUTPUT phMsg Optional output. If NULL != phMsg,
  12328. // it contains a handle to a opened message if
  12329. // the content type is one of the following:
  12330. // CERT_QUERY_CONTENT_PKCS7_SIGNED
  12331. // CERT_QUERY_CONTENT_PKCS7_UNSIGNED
  12332. // CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED
  12333. //
  12334. // Caller should free *phMsg via CryptMsgClose.
  12335. //
  12336. // OUTPUT pContext Optional output. If NULL != pContext,
  12337. // it contains either a PCCERT_CONTEXT or PCCRL_CONTEXT,
  12338. // or PCCTL_CONTEXT based on the content type.
  12339. //
  12340. // If the content type is CERT_QUERY_CONTENT_CERT or
  12341. // CERT_QUERY_CONTENT_SERIALIZED_CERT, it is a PCCERT_CONTEXT;
  12342. // Caller should free the pContext via CertFreeCertificateContext.
  12343. //
  12344. // If the content type is CERT_QUERY_CONTENT_CRL or
  12345. // CERT_QUERY_CONTENT_SERIALIZED_CRL, it is a PCCRL_CONTEXT;
  12346. // Caller should free the pContext via CertFreeCRLContext.
  12347. //
  12348. // If the content type is CERT_QUERY_CONTENT_CTL or
  12349. // CERT_QUERY_CONTENT_SERIALIZED_CTL, it is a PCCTL_CONTEXT;
  12350. // Caller should free the pContext via CertFreeCTLContext.
  12351. //
  12352. // If the *pbObject is of type CERT_QUERY_CONTENT_PKCS10 or CERT_QUERY_CONTENT_PFX, CryptQueryObject
  12353. // will not return anything in *phCertstore, *phMsg, or *ppvContext.
  12354. //--------------------------------------------------------------------------
  12355. WINCRYPT32API
  12356. BOOL
  12357. WINAPI
  12358. CryptQueryObject(
  12359. DWORD dwObjectType,
  12360. const void *pvObject,
  12361. DWORD dwExpectedContentTypeFlags,
  12362. DWORD dwExpectedFormatTypeFlags,
  12363. DWORD dwFlags,
  12364. DWORD *pdwMsgAndCertEncodingType,
  12365. DWORD *pdwContentType,
  12366. DWORD *pdwFormatType,
  12367. HCERTSTORE *phCertStore,
  12368. HCRYPTMSG *phMsg,
  12369. const void **ppvContext
  12370. );
  12371. //-------------------------------------------------------------------------
  12372. //dwObjectType for CryptQueryObject
  12373. //-------------------------------------------------------------------------
  12374. #define CERT_QUERY_OBJECT_FILE 0x00000001
  12375. #define CERT_QUERY_OBJECT_BLOB 0x00000002
  12376. //-------------------------------------------------------------------------
  12377. //dwContentType for CryptQueryObject
  12378. //-------------------------------------------------------------------------
  12379. //encoded single certificate
  12380. #define CERT_QUERY_CONTENT_CERT 1
  12381. //encoded single CTL
  12382. #define CERT_QUERY_CONTENT_CTL 2
  12383. //encoded single CRL
  12384. #define CERT_QUERY_CONTENT_CRL 3
  12385. //serialized store
  12386. #define CERT_QUERY_CONTENT_SERIALIZED_STORE 4
  12387. //serialized single certificate
  12388. #define CERT_QUERY_CONTENT_SERIALIZED_CERT 5
  12389. //serialized single CTL
  12390. #define CERT_QUERY_CONTENT_SERIALIZED_CTL 6
  12391. //serialized single CRL
  12392. #define CERT_QUERY_CONTENT_SERIALIZED_CRL 7
  12393. //a PKCS#7 signed message
  12394. #define CERT_QUERY_CONTENT_PKCS7_SIGNED 8
  12395. //a PKCS#7 message, such as enveloped message. But it is not a signed message,
  12396. #define CERT_QUERY_CONTENT_PKCS7_UNSIGNED 9
  12397. //a PKCS7 signed message embedded in a file
  12398. #define CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED 10
  12399. //an encoded PKCS#10
  12400. #define CERT_QUERY_CONTENT_PKCS10 11
  12401. //an encoded PKX BLOB
  12402. #define CERT_QUERY_CONTENT_PFX 12
  12403. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12404. #define CERT_QUERY_CONTENT_CERT_PAIR 13
  12405. //-------------------------------------------------------------------------
  12406. //dwExpectedConentTypeFlags for CryptQueryObject
  12407. //-------------------------------------------------------------------------
  12408. //encoded single certificate
  12409. #define CERT_QUERY_CONTENT_FLAG_CERT \
  12410. ( 1 << CERT_QUERY_CONTENT_CERT)
  12411. //encoded single CTL
  12412. #define CERT_QUERY_CONTENT_FLAG_CTL \
  12413. ( 1 << CERT_QUERY_CONTENT_CTL)
  12414. //encoded single CRL
  12415. #define CERT_QUERY_CONTENT_FLAG_CRL \
  12416. ( 1 << CERT_QUERY_CONTENT_CRL)
  12417. //serialized store
  12418. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE \
  12419. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_STORE)
  12420. //serialized single certificate
  12421. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT \
  12422. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CERT)
  12423. //serialized single CTL
  12424. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL \
  12425. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CTL)
  12426. //serialized single CRL
  12427. #define CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL \
  12428. ( 1 << CERT_QUERY_CONTENT_SERIALIZED_CRL)
  12429. //an encoded PKCS#7 signed message
  12430. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED \
  12431. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED)
  12432. //an encoded PKCS#7 message. But it is not a signed message
  12433. #define CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED \
  12434. ( 1 << CERT_QUERY_CONTENT_PKCS7_UNSIGNED)
  12435. //the content includes an embedded PKCS7 signed message
  12436. #define CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED \
  12437. ( 1 << CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED)
  12438. //an encoded PKCS#10
  12439. #define CERT_QUERY_CONTENT_FLAG_PKCS10 \
  12440. ( 1 << CERT_QUERY_CONTENT_PKCS10)
  12441. //an encoded PFX BLOB
  12442. #define CERT_QUERY_CONTENT_FLAG_PFX \
  12443. ( 1 << CERT_QUERY_CONTENT_PFX)
  12444. //an encoded CertificatePair (contains forward and/or reverse cross certs)
  12445. #define CERT_QUERY_CONTENT_FLAG_CERT_PAIR \
  12446. ( 1 << CERT_QUERY_CONTENT_CERT_PAIR)
  12447. //content can be any type
  12448. #define CERT_QUERY_CONTENT_FLAG_ALL \
  12449. CERT_QUERY_CONTENT_FLAG_CERT | \
  12450. CERT_QUERY_CONTENT_FLAG_CTL | \
  12451. CERT_QUERY_CONTENT_FLAG_CRL | \
  12452. CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE | \
  12453. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | \
  12454. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CTL | \
  12455. CERT_QUERY_CONTENT_FLAG_SERIALIZED_CRL | \
  12456. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | \
  12457. CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | \
  12458. CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | \
  12459. CERT_QUERY_CONTENT_FLAG_PKCS10 | \
  12460. CERT_QUERY_CONTENT_FLAG_PFX | \
  12461. CERT_QUERY_CONTENT_FLAG_CERT_PAIR
  12462. //-------------------------------------------------------------------------
  12463. //dwFormatType for CryptQueryObject
  12464. //-------------------------------------------------------------------------
  12465. //the content is in binary format
  12466. #define CERT_QUERY_FORMAT_BINARY 1
  12467. //the content is base64 encoded
  12468. #define CERT_QUERY_FORMAT_BASE64_ENCODED 2
  12469. //the content is ascii hex encoded with "{ASN}" prefix
  12470. #define CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED 3
  12471. //-------------------------------------------------------------------------
  12472. //dwExpectedFormatTypeFlags for CryptQueryObject
  12473. //-------------------------------------------------------------------------
  12474. //the content is in binary format
  12475. #define CERT_QUERY_FORMAT_FLAG_BINARY \
  12476. ( 1 << CERT_QUERY_FORMAT_BINARY)
  12477. //the content is base64 encoded
  12478. #define CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED \
  12479. ( 1 << CERT_QUERY_FORMAT_BASE64_ENCODED)
  12480. //the content is ascii hex encoded with "{ASN}" prefix
  12481. #define CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED \
  12482. ( 1 << CERT_QUERY_FORMAT_ASN_ASCII_HEX_ENCODED)
  12483. //the content can be of any format
  12484. #define CERT_QUERY_FORMAT_FLAG_ALL \
  12485. CERT_QUERY_FORMAT_FLAG_BINARY | \
  12486. CERT_QUERY_FORMAT_FLAG_BASE64_ENCODED | \
  12487. CERT_QUERY_FORMAT_FLAG_ASN_ASCII_HEX_ENCODED
  12488. //
  12489. // Crypt32 Memory Management Routines. All Crypt32 API which return allocated
  12490. // buffers will do so via CryptMemAlloc, CryptMemRealloc. Clients can free
  12491. // those buffers using CryptMemFree. Also included is CryptMemSize
  12492. //
  12493. WINCRYPT32API
  12494. LPVOID
  12495. WINAPI
  12496. CryptMemAlloc (
  12497. IN ULONG cbSize
  12498. );
  12499. WINCRYPT32API
  12500. LPVOID
  12501. WINAPI
  12502. CryptMemRealloc (
  12503. IN LPVOID pv,
  12504. IN ULONG cbSize
  12505. );
  12506. WINCRYPT32API
  12507. VOID
  12508. WINAPI
  12509. CryptMemFree (
  12510. IN LPVOID pv
  12511. );
  12512. //
  12513. // Crypt32 Asynchronous Parameter Management Routines. All Crypt32 API which
  12514. // expose asynchronous mode operation use a Crypt32 Async Handle to pass
  12515. // around information about the operation e.g. callback routines. The
  12516. // following API are used for manipulation of the async handle
  12517. //
  12518. typedef HANDLE HCRYPTASYNC, *PHCRYPTASYNC;
  12519. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_PARAM_FREE_FUNC) (
  12520. LPSTR pszParamOid,
  12521. LPVOID pvParam
  12522. );
  12523. WINCRYPT32API
  12524. BOOL
  12525. WINAPI
  12526. CryptCreateAsyncHandle (
  12527. IN DWORD dwFlags,
  12528. OUT PHCRYPTASYNC phAsync
  12529. );
  12530. WINCRYPT32API
  12531. BOOL
  12532. WINAPI
  12533. CryptSetAsyncParam (
  12534. IN HCRYPTASYNC hAsync,
  12535. IN LPSTR pszParamOid,
  12536. IN LPVOID pvParam,
  12537. IN OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC pfnFree
  12538. );
  12539. WINCRYPT32API
  12540. BOOL
  12541. WINAPI
  12542. CryptGetAsyncParam (
  12543. IN HCRYPTASYNC hAsync,
  12544. IN LPSTR pszParamOid,
  12545. OUT LPVOID* ppvParam,
  12546. OUT OPTIONAL PFN_CRYPT_ASYNC_PARAM_FREE_FUNC* ppfnFree
  12547. );
  12548. WINCRYPT32API
  12549. BOOL
  12550. WINAPI
  12551. CryptCloseAsyncHandle (
  12552. IN HCRYPTASYNC hAsync
  12553. );
  12554. //
  12555. // Crypt32 Remote Object Retrieval Routines. This API allows retrieval of
  12556. // remote PKI objects where the location is given by an URL. The remote
  12557. // object retrieval manager exposes two provider models. One is the "Scheme
  12558. // Provider" model which allows for installable protocol providers as defined
  12559. // by the URL scheme e.g. ldap, http, ftp. The scheme provider entry point is
  12560. // the same as the CryptRetrieveObjectByUrl however the *ppvObject returned
  12561. // is ALWAYS a counted array of encoded bits (one per object retrieved). The
  12562. // second provider model is the "Context Provider" model which allows for
  12563. // installable creators of CAPI2 context handles (objects) based on the
  12564. // retrieved encoded bits. These are dispatched based on the object OID given
  12565. // in the call to CryptRetrieveObjectByUrl.
  12566. //
  12567. typedef struct _CRYPT_BLOB_ARRAY {
  12568. DWORD cBlob;
  12569. PCRYPT_DATA_BLOB rgBlob;
  12570. } CRYPT_BLOB_ARRAY, *PCRYPT_BLOB_ARRAY;
  12571. typedef struct _CRYPT_CREDENTIALS {
  12572. DWORD cbSize;
  12573. LPCSTR pszCredentialsOid;
  12574. LPVOID pvCredentials;
  12575. } CRYPT_CREDENTIALS, *PCRYPT_CREDENTIALS;
  12576. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_A ((LPCSTR)1)
  12577. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS_W ((LPCSTR)2)
  12578. #ifdef UNICODE
  12579. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_W
  12580. #else
  12581. #define CREDENTIAL_OID_PASSWORD_CREDENTIALS CREDENTIAL_OID_PASSWORD_CREDENTIALS_A
  12582. #endif //UNICODE
  12583. typedef struct _CRYPT_PASSWORD_CREDENTIALSA {
  12584. DWORD cbSize;
  12585. LPSTR pszUsername;
  12586. LPSTR pszPassword;
  12587. } CRYPT_PASSWORD_CREDENTIALSA, *PCRYPT_PASSWORD_CREDENTIALSA;
  12588. typedef struct _CRYPT_PASSWORD_CREDENTIALSW {
  12589. DWORD cbSize;
  12590. LPWSTR pszUsername;
  12591. LPWSTR pszPassword;
  12592. } CRYPT_PASSWORD_CREDENTIALSW, *PCRYPT_PASSWORD_CREDENTIALSW;
  12593. #ifdef UNICODE
  12594. typedef CRYPT_PASSWORD_CREDENTIALSW CRYPT_PASSWORD_CREDENTIALS;
  12595. typedef PCRYPT_PASSWORD_CREDENTIALSW PCRYPT_PASSWORD_CREDENTIALS;
  12596. #else
  12597. typedef CRYPT_PASSWORD_CREDENTIALSA CRYPT_PASSWORD_CREDENTIALS;
  12598. typedef PCRYPT_PASSWORD_CREDENTIALSA PCRYPT_PASSWORD_CREDENTIALS;
  12599. #endif // UNICODE
  12600. //
  12601. // Scheme Provider Signatures
  12602. //
  12603. // The following is obsolete and has been replaced with the following
  12604. // definition
  12605. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECT_FUNC "SchemeDllRetrieveEncodedObject"
  12606. // 2-8-02 .NET Server changed to use UNICODE Url strings instead of multibyte
  12607. #define SCHEME_OID_RETRIEVE_ENCODED_OBJECTW_FUNC "SchemeDllRetrieveEncodedObjectW"
  12608. typedef VOID (WINAPI *PFN_FREE_ENCODED_OBJECT_FUNC) (
  12609. LPCSTR pszObjectOid,
  12610. PCRYPT_BLOB_ARRAY pObject,
  12611. LPVOID pvFreeContext
  12612. );
  12613. //
  12614. // SchemeDllRetrieveEncodedObject was replaced in .NET Server with
  12615. // the following. (Changed to use UNICODE Url Strings.)
  12616. //
  12617. //
  12618. // SchemeDllRetrieveEncodedObjectW has the following signature:
  12619. //
  12620. // BOOL WINAPI SchemeDllRetrieveEncodedObjectW (
  12621. // IN LPCWSTR pwszUrl,
  12622. // IN LPCSTR pszObjectOid,
  12623. // IN DWORD dwRetrievalFlags,
  12624. // IN DWORD dwTimeout, // milliseconds
  12625. // OUT PCRYPT_BLOB_ARRAY pObject,
  12626. // OUT PFN_FREE_ENCODED_OBJECT_FUNC* ppfnFreeObject,
  12627. // OUT LPVOID* ppvFreeContext,
  12628. // IN HCRYPTASYNC hAsyncRetrieve,
  12629. // IN PCRYPT_CREDENTIALS pCredentials,
  12630. // IN PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12631. // )
  12632. //
  12633. //
  12634. // Context Provider Signatures
  12635. //
  12636. #define CONTEXT_OID_CREATE_OBJECT_CONTEXT_FUNC "ContextDllCreateObjectContext"
  12637. #define CONTEXT_OID_CERTIFICATE ((LPCSTR)1)
  12638. #define CONTEXT_OID_CRL ((LPCSTR)2)
  12639. #define CONTEXT_OID_CTL ((LPCSTR)3)
  12640. #define CONTEXT_OID_PKCS7 ((LPCSTR)4)
  12641. #define CONTEXT_OID_CAPI2_ANY ((LPCSTR)5)
  12642. //
  12643. // ContextDllCreateObjectContext has the following signature:
  12644. //
  12645. // BOOL WINAPI ContextDllCreateObjectContext (
  12646. // IN LPCSTR pszObjectOid,
  12647. // IN DWORD dwRetrievalFlags,
  12648. // IN PCRYPT_BLOB_ARRAY pObject,
  12649. // OUT LPVOID* ppvContext
  12650. // )
  12651. //
  12652. //
  12653. // Remote Object Retrieval API
  12654. //
  12655. //
  12656. // Retrieval flags
  12657. //
  12658. #define CRYPT_RETRIEVE_MULTIPLE_OBJECTS 0x00000001
  12659. #define CRYPT_CACHE_ONLY_RETRIEVAL 0x00000002
  12660. #define CRYPT_WIRE_ONLY_RETRIEVAL 0x00000004
  12661. #define CRYPT_DONT_CACHE_RESULT 0x00000008
  12662. #define CRYPT_ASYNC_RETRIEVAL 0x00000010
  12663. #define CRYPT_STICKY_CACHE_RETRIEVAL 0x00001000
  12664. #define CRYPT_LDAP_SCOPE_BASE_ONLY_RETRIEVAL 0x00002000
  12665. #define CRYPT_OFFLINE_CHECK_RETRIEVAL 0x00004000
  12666. // When the following flag is set, the following 2 NULL terminated ascii
  12667. // strings are inserted at the beginning of each returned blob:
  12668. // "%d\0%s\0", dwEntryIndex, pszAttribute
  12669. //
  12670. // The first dwEntryIndex is 0, "0\0".
  12671. //
  12672. // When set, pszObjectOid must be NULL, so that a PCRYPT_BLOB_ARRAY is returned.
  12673. #define CRYPT_LDAP_INSERT_ENTRY_ATTRIBUTE 0x00008000
  12674. // Set this flag to digitally sign all of the ldap traffic to and from a
  12675. // Windows 2000 LDAP server using the Kerberos authentication protocol.
  12676. // This feature provides integrity required by some applications.
  12677. #define CRYPT_LDAP_SIGN_RETRIEVAL 0x00010000
  12678. // Set this flag to inhibit automatic authentication handling. See the
  12679. // wininet flag, INTERNET_FLAG_NO_AUTH, for more details.
  12680. #define CRYPT_NO_AUTH_RETRIEVAL 0x00020000
  12681. // Performs an A-Record only DNS lookup on the supplied host string.
  12682. // This prevents bogus DNS queries from being generated when resolving host
  12683. // names. Use this flag whenever passing a hostname as opposed to a
  12684. // domain name for the hostname parameter.
  12685. //
  12686. // See LDAP_OPT_AREC_EXCLUSIVE defined in winldap.h for more details.
  12687. #define CRYPT_LDAP_AREC_EXCLUSIVE_RETRIEVAL 0x00040000
  12688. // Apply AIA URL restrictions, such as, validate retrieved content before
  12689. // writing to cache.
  12690. #define CRYPT_AIA_RETRIEVAL 0x00080000
  12691. //
  12692. // Data verification retrieval flags
  12693. //
  12694. // CRYPT_VERIFY_CONTEXT_SIGNATURE is used to get signature verification
  12695. // on the context created. In this case pszObjectOid must be non-NULL and
  12696. // pvVerify points to the signer certificate context
  12697. //
  12698. // CRYPT_VERIFY_DATA_HASH is used to get verification of the blob data
  12699. // retrieved by the protocol. The pvVerify points to an URL_DATA_HASH
  12700. // structure (TBD)
  12701. //
  12702. #define CRYPT_VERIFY_CONTEXT_SIGNATURE 0x00000020
  12703. #define CRYPT_VERIFY_DATA_HASH 0x00000040
  12704. //
  12705. // Time Valid Object flags
  12706. //
  12707. #define CRYPT_KEEP_TIME_VALID 0x00000080
  12708. #define CRYPT_DONT_VERIFY_SIGNATURE 0x00000100
  12709. #define CRYPT_DONT_CHECK_TIME_VALIDITY 0x00000200
  12710. // The default checks if ftNextUpdate >= ftValidFor. Set this flag to
  12711. // check if ftThisUpdate >= ftValidFor.
  12712. #define CRYPT_CHECK_FRESHNESS_TIME_VALIDITY 0x00000400
  12713. #define CRYPT_ACCUMULATIVE_TIMEOUT 0x00000800
  12714. typedef struct _CRYPT_RETRIEVE_AUX_INFO {
  12715. DWORD cbSize;
  12716. FILETIME *pLastSyncTime;
  12717. DWORD dwMaxUrlRetrievalByteCount; // 0 => implies no limit
  12718. } CRYPT_RETRIEVE_AUX_INFO, *PCRYPT_RETRIEVE_AUX_INFO;
  12719. WINCRYPT32API
  12720. BOOL
  12721. WINAPI
  12722. CryptRetrieveObjectByUrlA (
  12723. IN LPCSTR pszUrl,
  12724. IN LPCSTR pszObjectOid,
  12725. IN DWORD dwRetrievalFlags,
  12726. IN DWORD dwTimeout, // milliseconds
  12727. OUT LPVOID* ppvObject,
  12728. IN HCRYPTASYNC hAsyncRetrieve,
  12729. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12730. IN OPTIONAL LPVOID pvVerify,
  12731. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12732. );
  12733. WINCRYPT32API
  12734. BOOL
  12735. WINAPI
  12736. CryptRetrieveObjectByUrlW (
  12737. IN LPCWSTR pszUrl,
  12738. IN LPCSTR pszObjectOid,
  12739. IN DWORD dwRetrievalFlags,
  12740. IN DWORD dwTimeout, // milliseconds
  12741. OUT LPVOID* ppvObject,
  12742. IN HCRYPTASYNC hAsyncRetrieve,
  12743. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12744. IN OPTIONAL LPVOID pvVerify,
  12745. IN OPTIONAL PCRYPT_RETRIEVE_AUX_INFO pAuxInfo
  12746. );
  12747. #ifdef UNICODE
  12748. #define CryptRetrieveObjectByUrl CryptRetrieveObjectByUrlW
  12749. #else
  12750. #define CryptRetrieveObjectByUrl CryptRetrieveObjectByUrlA
  12751. #endif // !UNICODE
  12752. //
  12753. // Call back function to cancel object retrieval
  12754. //
  12755. // The function can be installed on a per thread basis.
  12756. // If CryptInstallCancelRetrieval is called for multiple times, only the most recent
  12757. // installation will be kept.
  12758. //
  12759. // This is only effective for http, https, gopher, and ftp protocol.
  12760. // It is ignored by the rest of the protocols.
  12761. typedef BOOL (WINAPI *PFN_CRYPT_CANCEL_RETRIEVAL)(
  12762. IN DWORD dwFlags,
  12763. IN void *pvArg
  12764. );
  12765. //
  12766. // PFN_CRYPT_CANCEL_RETRIEVAL
  12767. //
  12768. // This function should return FALSE when the object retrieval should be continued
  12769. // and return TRUE when the object retrieval should be cancelled.
  12770. //
  12771. WINCRYPT32API
  12772. BOOL
  12773. WINAPI
  12774. CryptInstallCancelRetrieval(
  12775. IN PFN_CRYPT_CANCEL_RETRIEVAL pfnCancel,
  12776. IN const void *pvArg,
  12777. IN DWORD dwFlags,
  12778. IN void *pvReserved
  12779. );
  12780. WINCRYPT32API
  12781. BOOL
  12782. WINAPI
  12783. CryptUninstallCancelRetrieval(
  12784. IN DWORD dwFlags,
  12785. IN void *pvReserved
  12786. );
  12787. WINCRYPT32API
  12788. BOOL
  12789. WINAPI
  12790. CryptCancelAsyncRetrieval (
  12791. HCRYPTASYNC hAsyncRetrieval
  12792. );
  12793. //
  12794. // Remote Object Async Retrieval parameters
  12795. //
  12796. //
  12797. // A client that wants to be notified of asynchronous object retrieval
  12798. // completion sets this parameter on the async handle
  12799. //
  12800. #define CRYPT_PARAM_ASYNC_RETRIEVAL_COMPLETION ((LPCSTR)1)
  12801. typedef VOID (WINAPI *PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC) (
  12802. IN LPVOID pvCompletion,
  12803. IN DWORD dwCompletionCode,
  12804. IN LPCSTR pszUrl,
  12805. IN LPSTR pszObjectOid,
  12806. IN LPVOID pvObject
  12807. );
  12808. typedef struct _CRYPT_ASYNC_RETRIEVAL_COMPLETION {
  12809. PFN_CRYPT_ASYNC_RETRIEVAL_COMPLETION_FUNC pfnCompletion;
  12810. LPVOID pvCompletion;
  12811. } CRYPT_ASYNC_RETRIEVAL_COMPLETION, *PCRYPT_ASYNC_RETRIEVAL_COMPLETION;
  12812. //
  12813. // This function is set on the async handle by a scheme provider that
  12814. // supports asynchronous retrieval
  12815. //
  12816. #define CRYPT_PARAM_CANCEL_ASYNC_RETRIEVAL ((LPCSTR)2)
  12817. typedef BOOL (WINAPI *PFN_CANCEL_ASYNC_RETRIEVAL_FUNC) (
  12818. HCRYPTASYNC hAsyncRetrieve
  12819. );
  12820. //
  12821. // Get the locator for a CAPI object
  12822. //
  12823. #define CRYPT_GET_URL_FROM_PROPERTY 0x00000001
  12824. #define CRYPT_GET_URL_FROM_EXTENSION 0x00000002
  12825. #define CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE 0x00000004
  12826. #define CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE 0x00000008
  12827. typedef struct _CRYPT_URL_ARRAY {
  12828. DWORD cUrl;
  12829. LPWSTR* rgwszUrl;
  12830. } CRYPT_URL_ARRAY, *PCRYPT_URL_ARRAY;
  12831. typedef struct _CRYPT_URL_INFO {
  12832. DWORD cbSize;
  12833. // Seconds between syncs
  12834. DWORD dwSyncDeltaTime;
  12835. // Returned URLs may be grouped. For instance, groups of cross cert
  12836. // distribution points. Each distribution point may have multiple
  12837. // URLs, (LDAP and HTTP scheme).
  12838. DWORD cGroup;
  12839. DWORD *rgcGroupEntry;
  12840. } CRYPT_URL_INFO, *PCRYPT_URL_INFO;
  12841. WINCRYPT32API
  12842. BOOL
  12843. WINAPI
  12844. CryptGetObjectUrl (
  12845. IN LPCSTR pszUrlOid,
  12846. IN LPVOID pvPara,
  12847. IN DWORD dwFlags,
  12848. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  12849. IN OUT DWORD* pcbUrlArray,
  12850. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  12851. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  12852. IN OPTIONAL LPVOID pvReserved
  12853. );
  12854. #define URL_OID_GET_OBJECT_URL_FUNC "UrlDllGetObjectUrl"
  12855. //
  12856. // UrlDllGetObjectUrl has the same signature as CryptGetObjectUrl
  12857. //
  12858. //
  12859. // URL_OID_CERTIFICATE_ISSUER
  12860. //
  12861. // pvPara == PCCERT_CONTEXT, certificate whose issuer's URL is being requested
  12862. //
  12863. // This will be retrieved from the authority info access extension or property
  12864. // on the certificate
  12865. //
  12866. // URL_OID_CERTIFICATE_CRL_DIST_POINT
  12867. //
  12868. // pvPara == PCCERT_CONTEXT, certificate whose CRL distribution point is being
  12869. // requested
  12870. //
  12871. // This will be retrieved from the CRL distribution point extension or property
  12872. // on the certificate
  12873. //
  12874. // URL_OID_CTL_ISSUER
  12875. //
  12876. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose issuer's URL (identified
  12877. // by the signer index) is being requested
  12878. //
  12879. // This will be retrieved from an authority info access attribute method encoded
  12880. // in each signer info in the PKCS7 (CTL)
  12881. //
  12882. // URL_OID_CTL_NEXT_UPDATE
  12883. //
  12884. // pvPara == PCCTL_CONTEXT, Signer Index, CTL whose next update URL is being
  12885. // requested and an optional signer index in case we need to check signer
  12886. // info attributes
  12887. //
  12888. // This will be retrieved from an authority info access CTL extension, property,
  12889. // or signer info attribute method
  12890. //
  12891. // URL_OID_CRL_ISSUER
  12892. //
  12893. // pvPara == PCCRL_CONTEXT, CRL whose issuer's URL is being requested
  12894. //
  12895. // This will be retrieved from a property on the CRL which has been inherited
  12896. // from the subject cert (either from the subject cert issuer or the subject
  12897. // cert distribution point extension). It will be encoded as an authority
  12898. // info access extension method.
  12899. //
  12900. // URL_OID_CERTIFICATE_FRESHEST_CRL
  12901. //
  12902. // pvPara == PCCERT_CONTEXT, certificate whose freshest CRL distribution point
  12903. // is being requested
  12904. //
  12905. // This will be retrieved from the freshest CRL extension or property
  12906. // on the certificate
  12907. //
  12908. // URL_OID_CRL_FRESHEST_CRL
  12909. //
  12910. // pvPara == PCCERT_CRL_CONTEXT_PAIR, certificate's base CRL whose
  12911. // freshest CRL distribution point is being requested
  12912. //
  12913. // This will be retrieved from the freshest CRL extension or property
  12914. // on the CRL
  12915. //
  12916. // URL_OID_CROSS_CERT_DIST_POINT
  12917. //
  12918. // pvPara == PCCERT_CONTEXT, certificate whose cross certificate distribution
  12919. // point is being requested
  12920. //
  12921. // This will be retrieved from the cross certificate distribution point
  12922. // extension or property on the certificate
  12923. //
  12924. #define URL_OID_CERTIFICATE_ISSUER ((LPCSTR)1)
  12925. #define URL_OID_CERTIFICATE_CRL_DIST_POINT ((LPCSTR)2)
  12926. #define URL_OID_CTL_ISSUER ((LPCSTR)3)
  12927. #define URL_OID_CTL_NEXT_UPDATE ((LPCSTR)4)
  12928. #define URL_OID_CRL_ISSUER ((LPCSTR)5)
  12929. #define URL_OID_CERTIFICATE_FRESHEST_CRL ((LPCSTR)6)
  12930. #define URL_OID_CRL_FRESHEST_CRL ((LPCSTR)7)
  12931. #define URL_OID_CROSS_CERT_DIST_POINT ((LPCSTR)8)
  12932. typedef struct _CERT_CRL_CONTEXT_PAIR {
  12933. PCCERT_CONTEXT pCertContext;
  12934. PCCRL_CONTEXT pCrlContext;
  12935. } CERT_CRL_CONTEXT_PAIR, *PCERT_CRL_CONTEXT_PAIR;
  12936. typedef const CERT_CRL_CONTEXT_PAIR *PCCERT_CRL_CONTEXT_PAIR;
  12937. //
  12938. // Get a time valid CAPI2 object
  12939. //
  12940. WINCRYPT32API
  12941. BOOL
  12942. WINAPI
  12943. CryptGetTimeValidObject (
  12944. IN LPCSTR pszTimeValidOid,
  12945. IN LPVOID pvPara,
  12946. IN PCCERT_CONTEXT pIssuer,
  12947. IN OPTIONAL LPFILETIME pftValidFor,
  12948. IN DWORD dwFlags,
  12949. IN DWORD dwTimeout, // milliseconds
  12950. OUT OPTIONAL LPVOID* ppvObject,
  12951. IN OPTIONAL PCRYPT_CREDENTIALS pCredentials,
  12952. IN OPTIONAL LPVOID pvReserved
  12953. );
  12954. #define TIME_VALID_OID_GET_OBJECT_FUNC "TimeValidDllGetObject"
  12955. //
  12956. // TimeValidDllGetObject has the same signature as CryptGetTimeValidObject
  12957. //
  12958. //
  12959. // TIME_VALID_OID_GET_CTL
  12960. //
  12961. // pvPara == PCCTL_CONTEXT, the current CTL
  12962. //
  12963. // TIME_VALID_OID_GET_CRL
  12964. //
  12965. // pvPara == PCCRL_CONTEXT, the current CRL
  12966. //
  12967. // TIME_VALID_OID_GET_CRL_FROM_CERT
  12968. //
  12969. // pvPara == PCCERT_CONTEXT, the subject cert
  12970. //
  12971. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT
  12972. //
  12973. // pvPara == PCCERT_CONTEXT, the subject cert
  12974. //
  12975. // TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL
  12976. //
  12977. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL
  12978. //
  12979. #define TIME_VALID_OID_GET_CTL ((LPCSTR)1)
  12980. #define TIME_VALID_OID_GET_CRL ((LPCSTR)2)
  12981. #define TIME_VALID_OID_GET_CRL_FROM_CERT ((LPCSTR)3)
  12982. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  12983. #define TIME_VALID_OID_GET_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  12984. WINCRYPT32API
  12985. BOOL
  12986. WINAPI
  12987. CryptFlushTimeValidObject (
  12988. IN LPCSTR pszFlushTimeValidOid,
  12989. IN LPVOID pvPara,
  12990. IN PCCERT_CONTEXT pIssuer,
  12991. IN DWORD dwFlags,
  12992. IN LPVOID pvReserved
  12993. );
  12994. #define TIME_VALID_OID_FLUSH_OBJECT_FUNC "TimeValidDllFlushObject"
  12995. //
  12996. // TimeValidDllFlushObject has the same signature as CryptFlushTimeValidObject
  12997. //
  12998. //
  12999. // TIME_VALID_OID_FLUSH_CTL
  13000. //
  13001. // pvPara == PCCTL_CONTEXT, the CTL to flush
  13002. //
  13003. // TIME_VALID_OID_FLUSH_CRL
  13004. //
  13005. // pvPara == PCCRL_CONTEXT, the CRL to flush
  13006. //
  13007. // TIME_VALID_OID_FLUSH_CRL_FROM_CERT
  13008. //
  13009. // pvPara == PCCERT_CONTEXT, the subject cert's CRL to flush
  13010. //
  13011. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT
  13012. //
  13013. // pvPara == PCCERT_CONTEXT, the subject cert's freshest CRL to flush
  13014. //
  13015. // TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL
  13016. //
  13017. // pvPara == PCCERT_CRL_CONTEXT_PAIR, the subject cert and its base CRL's
  13018. // freshest CRL to flush
  13019. //
  13020. #define TIME_VALID_OID_FLUSH_CTL ((LPCSTR)1)
  13021. #define TIME_VALID_OID_FLUSH_CRL ((LPCSTR)2)
  13022. #define TIME_VALID_OID_FLUSH_CRL_FROM_CERT ((LPCSTR)3)
  13023. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CERT ((LPCSTR)4)
  13024. #define TIME_VALID_OID_FLUSH_FRESHEST_CRL_FROM_CRL ((LPCSTR)5)
  13025. //-------------------------------------------------------------------------
  13026. // Data Protection APIs
  13027. //-------------------------------------------------------------------------
  13028. //
  13029. // Data protection APIs enable applications to easily secure data.
  13030. //
  13031. // The base provider provides protection based on the users' logon
  13032. // credentials. The data secured with these APIs follow the same
  13033. // roaming characteristics as HKCU -- if HKCU roams, the data
  13034. // protected by the base provider may roam as well. This makes
  13035. // the API ideal for the munging of data stored in the registry.
  13036. //
  13037. //
  13038. // Prompt struct -- what to tell users about the access
  13039. //
  13040. typedef struct _CRYPTPROTECT_PROMPTSTRUCT
  13041. {
  13042. DWORD cbSize;
  13043. DWORD dwPromptFlags;
  13044. HWND hwndApp;
  13045. LPCWSTR szPrompt;
  13046. } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT;
  13047. //
  13048. // base provider action
  13049. //
  13050. #define CRYPTPROTECT_DEFAULT_PROVIDER { 0xdf9d8cd0, 0x1501, 0x11d1, {0x8c, 0x7a, 0x00, 0xc0, 0x4f, 0xc2, 0x97, 0xeb} }
  13051. //
  13052. // CryptProtect PromptStruct dwPromtFlags
  13053. //
  13054. //
  13055. // prompt on unprotect
  13056. #define CRYPTPROTECT_PROMPT_ON_UNPROTECT 0x1 // 1<<0
  13057. //
  13058. // prompt on protect
  13059. #define CRYPTPROTECT_PROMPT_ON_PROTECT 0x2 // 1<<1
  13060. #define CRYPTPROTECT_PROMPT_RESERVED 0x04 // reserved, do not use.
  13061. //
  13062. // default to strong variant UI protection (user supplied password currently).
  13063. #define CRYPTPROTECT_PROMPT_STRONG 0x08 // 1<<3
  13064. //
  13065. // require strong variant UI protection (user supplied password currently).
  13066. #define CRYPTPROTECT_PROMPT_REQUIRE_STRONG 0x10 // 1<<4
  13067. //
  13068. // CryptProtectData and CryptUnprotectData dwFlags
  13069. //
  13070. // for remote-access situations where ui is not an option
  13071. // if UI was specified on protect or unprotect operation, the call
  13072. // will fail and GetLastError() will indicate ERROR_PASSWORD_RESTRICTION
  13073. #define CRYPTPROTECT_UI_FORBIDDEN 0x1
  13074. //
  13075. // per machine protected data -- any user on machine where CryptProtectData
  13076. // took place may CryptUnprotectData
  13077. #define CRYPTPROTECT_LOCAL_MACHINE 0x4
  13078. //
  13079. // force credential synchronize during CryptProtectData()
  13080. // Synchronize is only operation that occurs during this operation
  13081. #define CRYPTPROTECT_CRED_SYNC 0x8
  13082. //
  13083. // Generate an Audit on protect and unprotect operations
  13084. //
  13085. #define CRYPTPROTECT_AUDIT 0x10
  13086. //
  13087. // Protect data with a non-recoverable key
  13088. //
  13089. #define CRYPTPROTECT_NO_RECOVERY 0x20
  13090. //
  13091. // Verify the protection of a protected blob
  13092. //
  13093. #define CRYPTPROTECT_VERIFY_PROTECTION 0x40
  13094. //
  13095. // Regenerate the local machine protection
  13096. //
  13097. #define CRYPTPROTECT_CRED_REGENERATE 0x80
  13098. // flags reserved for system use
  13099. #define CRYPTPROTECT_FIRST_RESERVED_FLAGVAL 0x0FFFFFFF
  13100. #define CRYPTPROTECT_LAST_RESERVED_FLAGVAL 0xFFFFFFFF
  13101. //
  13102. // flags specific to base provider
  13103. //
  13104. WINCRYPT32API
  13105. BOOL
  13106. WINAPI
  13107. CryptProtectData(
  13108. IN DATA_BLOB* pDataIn,
  13109. IN LPCWSTR szDataDescr,
  13110. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  13111. IN PVOID pvReserved,
  13112. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  13113. IN DWORD dwFlags,
  13114. OUT DATA_BLOB* pDataOut // out encr blob
  13115. );
  13116. WINCRYPT32API
  13117. BOOL
  13118. WINAPI
  13119. CryptUnprotectData(
  13120. IN DATA_BLOB* pDataIn, // in encr blob
  13121. OUT OPTIONAL LPWSTR* ppszDataDescr, // out
  13122. IN OPTIONAL DATA_BLOB* pOptionalEntropy,
  13123. IN PVOID pvReserved,
  13124. IN OPTIONAL CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
  13125. IN DWORD dwFlags,
  13126. OUT DATA_BLOB* pDataOut
  13127. );
  13128. //+=========================================================================
  13129. // Helper functions to build certificates
  13130. //==========================================================================
  13131. //+-------------------------------------------------------------------------
  13132. //
  13133. // Builds a self-signed certificate and returns a PCCERT_CONTEXT representing
  13134. // the certificate. A hProv must be specified to build the cert context.
  13135. //
  13136. // pSubjectIssuerBlob is the DN for the certifcate. If an alternate subject
  13137. // name is desired it must be specified as an extension in the pExtensions
  13138. // parameter. pSubjectIssuerBlob can NOT be NULL, so minimually an empty DN
  13139. // must be specified.
  13140. //
  13141. // By default:
  13142. // pKeyProvInfo - The CSP is queried for the KeyProvInfo parameters. Only the Provider,
  13143. // Provider Type and Container is queried. Many CSPs don't support these
  13144. // queries and will cause a failure. In such cases the pKeyProvInfo
  13145. // must be specified (RSA BASE works fine).
  13146. //
  13147. // pSignatureAlgorithm - will default to SHA1RSA
  13148. // pStartTime will default to the current time
  13149. // pEndTime will default to 1 year
  13150. // pEntensions will be empty.
  13151. //
  13152. // The returned PCCERT_CONTEXT will reference the private keys by setting the
  13153. // CERT_KEY_PROV_INFO_PROP_ID. However, if this property is not desired specify the
  13154. // CERT_CREATE_SELFSIGN_NO_KEY_INFO in dwFlags.
  13155. //
  13156. // If the cert being built is only a dummy placeholder cert for speed it may not
  13157. // need to be signed. Signing of the cert is skipped if CERT_CREATE_SELFSIGN_NO_SIGN
  13158. // is specified in dwFlags.
  13159. //
  13160. //--------------------------------------------------------------------------
  13161. WINCRYPT32API
  13162. PCCERT_CONTEXT
  13163. WINAPI
  13164. CertCreateSelfSignCertificate(
  13165. IN HCRYPTPROV hProv,
  13166. IN PCERT_NAME_BLOB pSubjectIssuerBlob,
  13167. IN DWORD dwFlags,
  13168. OPTIONAL PCRYPT_KEY_PROV_INFO pKeyProvInfo,
  13169. OPTIONAL PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  13170. OPTIONAL PSYSTEMTIME pStartTime,
  13171. OPTIONAL PSYSTEMTIME pEndTime,
  13172. OPTIONAL PCERT_EXTENSIONS pExtensions
  13173. );
  13174. #define CERT_CREATE_SELFSIGN_NO_SIGN 1
  13175. #define CERT_CREATE_SELFSIGN_NO_KEY_INFO 2
  13176. //+=========================================================================
  13177. // Key Identifier Property Data Structures and APIs
  13178. //==========================================================================
  13179. //+-------------------------------------------------------------------------
  13180. // Get the property for the specified Key Identifier.
  13181. //
  13182. // The Key Identifier is the SHA1 hash of the encoded CERT_PUBLIC_KEY_INFO.
  13183. // The Key Identifier for a certificate can be obtained by getting the
  13184. // certificate's CERT_KEY_IDENTIFIER_PROP_ID. The
  13185. // CryptCreateKeyIdentifierFromCSP API can be called to create the Key
  13186. // Identifier from a CSP Public Key Blob.
  13187. //
  13188. // A Key Identifier can have the same properties as a certificate context.
  13189. // CERT_KEY_PROV_INFO_PROP_ID is the property of most interest.
  13190. // For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO
  13191. // structure. Elements pointed to by fields in the pvData structure follow the
  13192. // structure. Therefore, *pcbData will exceed the size of the structure.
  13193. //
  13194. // If CRYPT_KEYID_ALLOC_FLAG is set, then, *pvData is updated with a
  13195. // pointer to allocated memory. LocalFree() must be called to free the
  13196. // allocated memory.
  13197. //
  13198. // By default, searches the CurrentUser's list of Key Identifiers.
  13199. // CRYPT_KEYID_MACHINE_FLAG can be set to search the LocalMachine's list
  13200. // of Key Identifiers. When CRYPT_KEYID_MACHINE_FLAG is set, pwszComputerName
  13201. // can also be set to specify the name of a remote computer to be searched
  13202. // instead of the local machine.
  13203. //--------------------------------------------------------------------------
  13204. WINCRYPT32API
  13205. BOOL
  13206. WINAPI
  13207. CryptGetKeyIdentifierProperty(
  13208. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13209. IN DWORD dwPropId,
  13210. IN DWORD dwFlags,
  13211. IN OPTIONAL LPCWSTR pwszComputerName,
  13212. IN OPTIONAL void *pvReserved,
  13213. OUT void *pvData,
  13214. IN OUT DWORD *pcbData
  13215. );
  13216. // When the following flag is set, searches the LocalMachine instead of the
  13217. // CurrentUser. This flag is applicable to all the KeyIdentifierProperty APIs.
  13218. #define CRYPT_KEYID_MACHINE_FLAG 0x00000020
  13219. // When the following flag is set, *pvData is updated with a pointer to
  13220. // allocated memory. LocalFree() must be called to free the allocated memory.
  13221. #define CRYPT_KEYID_ALLOC_FLAG 0x00008000
  13222. //+-------------------------------------------------------------------------
  13223. // Set the property for the specified Key Identifier.
  13224. //
  13225. // For CERT_KEY_PROV_INFO_PROP_ID pvData points to the
  13226. // CRYPT_KEY_PROV_INFO data structure. For all other properties, pvData
  13227. // points to a CRYPT_DATA_BLOB.
  13228. //
  13229. // Setting pvData == NULL, deletes the property.
  13230. //
  13231. // Set CRYPT_KEYID_MACHINE_FLAG to set the property for a LocalMachine
  13232. // Key Identifier. Set pwszComputerName, to select a remote computer.
  13233. //
  13234. // If CRYPT_KEYID_DELETE_FLAG is set, the Key Identifier and all its
  13235. // properties is deleted.
  13236. //
  13237. // If CRYPT_KEYID_SET_NEW_FLAG is set, the set fails if the property already
  13238. // exists. For an existing property, FALSE is returned with LastError set to
  13239. // CRYPT_E_EXISTS.
  13240. //--------------------------------------------------------------------------
  13241. WINCRYPT32API
  13242. BOOL
  13243. WINAPI
  13244. CryptSetKeyIdentifierProperty(
  13245. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13246. IN DWORD dwPropId,
  13247. IN DWORD dwFlags,
  13248. IN OPTIONAL LPCWSTR pwszComputerName,
  13249. IN OPTIONAL void *pvReserved,
  13250. IN const void *pvData
  13251. );
  13252. // When the following flag is set, the Key Identifier and all its properties
  13253. // are deleted.
  13254. #define CRYPT_KEYID_DELETE_FLAG 0x00000010
  13255. // When the following flag is set, the set fails if the property already
  13256. // exists.
  13257. #define CRYPT_KEYID_SET_NEW_FLAG 0x00002000
  13258. //+-------------------------------------------------------------------------
  13259. // For CERT_KEY_PROV_INFO_PROP_ID, rgppvData[] points to a
  13260. // CRYPT_KEY_PROV_INFO.
  13261. //
  13262. // Return FALSE to stop the enumeration.
  13263. //--------------------------------------------------------------------------
  13264. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_KEYID_PROP)(
  13265. IN const CRYPT_HASH_BLOB *pKeyIdentifier,
  13266. IN DWORD dwFlags,
  13267. IN void *pvReserved,
  13268. IN void *pvArg,
  13269. IN DWORD cProp,
  13270. IN DWORD *rgdwPropId,
  13271. IN void **rgpvData,
  13272. IN DWORD *rgcbData
  13273. );
  13274. //+-------------------------------------------------------------------------
  13275. // Enumerate the Key Identifiers.
  13276. //
  13277. // If pKeyIdentifier is NULL, enumerates all Key Identifers. Otherwise,
  13278. // calls the callback for the specified KeyIdentifier. If dwPropId is
  13279. // 0, calls the callback with all the properties. Otherwise, only calls
  13280. // the callback with the specified property (cProp = 1).
  13281. // Furthermore, when dwPropId is specified, skips KeyIdentifiers not
  13282. // having the property.
  13283. //
  13284. // Set CRYPT_KEYID_MACHINE_FLAG to enumerate the LocalMachine
  13285. // Key Identifiers. Set pwszComputerName, to enumerate Key Identifiers on
  13286. // a remote computer.
  13287. //--------------------------------------------------------------------------
  13288. WINCRYPT32API
  13289. BOOL
  13290. WINAPI
  13291. CryptEnumKeyIdentifierProperties(
  13292. IN OPTIONAL const CRYPT_HASH_BLOB *pKeyIdentifier,
  13293. IN DWORD dwPropId,
  13294. IN DWORD dwFlags,
  13295. IN OPTIONAL LPCWSTR pwszComputerName,
  13296. IN OPTIONAL void *pvReserved,
  13297. IN OPTIONAL void *pvArg,
  13298. IN PFN_CRYPT_ENUM_KEYID_PROP pfnEnum
  13299. );
  13300. //+-------------------------------------------------------------------------
  13301. // Create a KeyIdentifier from the CSP Public Key Blob.
  13302. //
  13303. // Converts the CSP PUBLICKEYSTRUC into a X.509 CERT_PUBLIC_KEY_INFO and
  13304. // encodes. The encoded CERT_PUBLIC_KEY_INFO is SHA1 hashed to obtain
  13305. // the Key Identifier.
  13306. //
  13307. // By default, the pPubKeyStruc->aiKeyAlg is used to find the appropriate
  13308. // public key Object Identifier. pszPubKeyOID can be set to override
  13309. // the default OID obtained from the aiKeyAlg.
  13310. //--------------------------------------------------------------------------
  13311. WINCRYPT32API
  13312. BOOL
  13313. WINAPI
  13314. CryptCreateKeyIdentifierFromCSP(
  13315. IN DWORD dwCertEncodingType,
  13316. IN OPTIONAL LPCSTR pszPubKeyOID,
  13317. IN const PUBLICKEYSTRUC *pPubKeyStruc,
  13318. IN DWORD cbPubKeyStruc,
  13319. IN DWORD dwFlags,
  13320. IN OPTIONAL void *pvReserved,
  13321. OUT BYTE *pbHash,
  13322. IN OUT DWORD *pcbHash
  13323. );
  13324. //+=========================================================================
  13325. // Certificate Chaining Infrastructure
  13326. //==========================================================================
  13327. #define CERT_CHAIN_CONFIG_REGPATH \
  13328. L"Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CertDllCreateCertificateChainEngine\\Config"
  13329. // The following are REG_DWORD's. These configuration parameters are used
  13330. // to restrict Authority Info Access (AIA) URL retrieval.
  13331. #define CERT_CHAIN_DISABLE_AIA_URL_RETRIEVAL_VALUE_NAME \
  13332. L"DisableAIAUrlRetrieval"
  13333. // By default AIA Url Retrieval is enabled. Set this registry value to nonzero
  13334. // to disable
  13335. #define CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_VALUE_NAME \
  13336. L"MaxAIAUrlCountInCert"
  13337. #define CERT_CHAIN_MAX_AIA_URL_COUNT_IN_CERT_DEFAULT 5
  13338. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_VALUE_NAME \
  13339. L"MaxAIAUrlRetrievalCountPerChain"
  13340. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_COUNT_PER_CHAIN_DEFAULT 10
  13341. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_VALUE_NAME \
  13342. L"MaxAIAUrlRetrievalByteCount"
  13343. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_BYTE_COUNT_DEFAULT 100000
  13344. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_VALUE_NAME \
  13345. L"MaxAIAUrlRetrievalCertCount"
  13346. #define CERT_CHAIN_MAX_AIA_URL_RETRIEVAL_CERT_COUNT_DEFAULT 10
  13347. //
  13348. // The chain engine defines the store namespace and cache partitioning for
  13349. // the Certificate Chaining infrastructure. A default chain engine
  13350. // is defined for the process which uses all default system stores e.g.
  13351. // Root, CA, Trust, for chain building and caching. If an application
  13352. // wishes to define its own store namespace or have its own partitioned
  13353. // cache then it can create its own chain engine. It is advisable to create
  13354. // a chain engine at application startup and use it throughout the lifetime
  13355. // of the application in order to get optimal caching behavior
  13356. //
  13357. typedef HANDLE HCERTCHAINENGINE;
  13358. #define HCCE_CURRENT_USER ((HCERTCHAINENGINE)NULL)
  13359. #define HCCE_LOCAL_MACHINE ((HCERTCHAINENGINE)0x1)
  13360. //
  13361. // Create a certificate chain engine.
  13362. //
  13363. //
  13364. // Configuration parameters for the certificate chain engine
  13365. //
  13366. // hRestrictedRoot - restrict the root store (must be a subset of "Root")
  13367. //
  13368. // hRestrictedTrust - restrict the store for CTLs
  13369. //
  13370. // hRestrictedOther - restrict the store for certs and CRLs
  13371. //
  13372. // cAdditionalStore, rghAdditionalStore - additional stores
  13373. //
  13374. // NOTE: The algorithm used to define the stores for the engine is as
  13375. // follows:
  13376. //
  13377. // hRoot = hRestrictedRoot or System Store "Root"
  13378. //
  13379. // hTrust = hRestrictedTrust or hWorld (defined later)
  13380. //
  13381. // hOther = hRestrictedOther or (hRestrictedTrust == NULL) ? hWorld :
  13382. // hRestrictedTrust + hWorld
  13383. //
  13384. // hWorld = hRoot + "CA" + "My" + "Trust" + rghAdditionalStore
  13385. //
  13386. // dwFlags - flags
  13387. //
  13388. // CERT_CHAIN_CACHE_END_CERT - information will be cached on
  13389. // the end cert as well as the other
  13390. // certs in the chain
  13391. //
  13392. // CERT_CHAIN_THREAD_STORE_SYNC - use separate thread for store syncs
  13393. // and related cache updates
  13394. //
  13395. // CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL - don't hit the wire to get
  13396. // URL based objects
  13397. //
  13398. // dwUrlRetrievalTimeout - timeout for wire based URL object retrievals
  13399. // (milliseconds)
  13400. //
  13401. #define CERT_CHAIN_CACHE_END_CERT 0x00000001
  13402. #define CERT_CHAIN_THREAD_STORE_SYNC 0x00000002
  13403. #define CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL 0x00000004
  13404. #define CERT_CHAIN_USE_LOCAL_MACHINE_STORE 0x00000008
  13405. #define CERT_CHAIN_ENABLE_CACHE_AUTO_UPDATE 0x00000010
  13406. #define CERT_CHAIN_ENABLE_SHARE_STORE 0x00000020
  13407. typedef struct _CERT_CHAIN_ENGINE_CONFIG {
  13408. DWORD cbSize;
  13409. HCERTSTORE hRestrictedRoot;
  13410. HCERTSTORE hRestrictedTrust;
  13411. HCERTSTORE hRestrictedOther;
  13412. DWORD cAdditionalStore;
  13413. HCERTSTORE* rghAdditionalStore;
  13414. DWORD dwFlags;
  13415. DWORD dwUrlRetrievalTimeout; // milliseconds
  13416. DWORD MaximumCachedCertificates;
  13417. DWORD CycleDetectionModulus;
  13418. } CERT_CHAIN_ENGINE_CONFIG, *PCERT_CHAIN_ENGINE_CONFIG;
  13419. WINCRYPT32API
  13420. BOOL
  13421. WINAPI
  13422. CertCreateCertificateChainEngine (
  13423. IN PCERT_CHAIN_ENGINE_CONFIG pConfig,
  13424. OUT HCERTCHAINENGINE* phChainEngine
  13425. );
  13426. //
  13427. // Free a certificate trust engine
  13428. //
  13429. WINCRYPT32API
  13430. VOID
  13431. WINAPI
  13432. CertFreeCertificateChainEngine (
  13433. IN HCERTCHAINENGINE hChainEngine
  13434. );
  13435. //
  13436. // Resync the certificate chain engine. This resync's the stores backing
  13437. // the engine and updates the engine caches.
  13438. //
  13439. WINCRYPT32API
  13440. BOOL
  13441. WINAPI
  13442. CertResyncCertificateChainEngine (
  13443. IN HCERTCHAINENGINE hChainEngine
  13444. );
  13445. //
  13446. // When an application requests a certificate chain, the data structure
  13447. // returned is in the form of a CERT_CHAIN_CONTEXT. This contains
  13448. // an array of CERT_SIMPLE_CHAIN where each simple chain goes from
  13449. // an end cert to a self signed cert and the chain context connects simple
  13450. // chains via trust lists. Each simple chain contains the chain of
  13451. // certificates, summary trust information about the chain and trust information
  13452. // about each certificate element in the chain.
  13453. //
  13454. //
  13455. // Trust status bits
  13456. //
  13457. typedef struct _CERT_TRUST_STATUS {
  13458. DWORD dwErrorStatus;
  13459. DWORD dwInfoStatus;
  13460. } CERT_TRUST_STATUS, *PCERT_TRUST_STATUS;
  13461. //
  13462. // The following are error status bits
  13463. //
  13464. // These can be applied to certificates and chains
  13465. #define CERT_TRUST_NO_ERROR 0x00000000
  13466. #define CERT_TRUST_IS_NOT_TIME_VALID 0x00000001
  13467. #define CERT_TRUST_IS_NOT_TIME_NESTED 0x00000002
  13468. #define CERT_TRUST_IS_REVOKED 0x00000004
  13469. #define CERT_TRUST_IS_NOT_SIGNATURE_VALID 0x00000008
  13470. #define CERT_TRUST_IS_NOT_VALID_FOR_USAGE 0x00000010
  13471. #define CERT_TRUST_IS_UNTRUSTED_ROOT 0x00000020
  13472. #define CERT_TRUST_REVOCATION_STATUS_UNKNOWN 0x00000040
  13473. #define CERT_TRUST_IS_CYCLIC 0x00000080
  13474. #define CERT_TRUST_INVALID_EXTENSION 0x00000100
  13475. #define CERT_TRUST_INVALID_POLICY_CONSTRAINTS 0x00000200
  13476. #define CERT_TRUST_INVALID_BASIC_CONSTRAINTS 0x00000400
  13477. #define CERT_TRUST_INVALID_NAME_CONSTRAINTS 0x00000800
  13478. #define CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT 0x00001000
  13479. #define CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT 0x00002000
  13480. #define CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT 0x00004000
  13481. #define CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT 0x00008000
  13482. #define CERT_TRUST_IS_OFFLINE_REVOCATION 0x01000000
  13483. #define CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY 0x02000000
  13484. // These can be applied to chains only
  13485. #define CERT_TRUST_IS_PARTIAL_CHAIN 0x00010000
  13486. #define CERT_TRUST_CTL_IS_NOT_TIME_VALID 0x00020000
  13487. #define CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID 0x00040000
  13488. #define CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE 0x00080000
  13489. //
  13490. // The following are info status bits
  13491. //
  13492. // These can be applied to certificates only
  13493. #define CERT_TRUST_HAS_EXACT_MATCH_ISSUER 0x00000001
  13494. #define CERT_TRUST_HAS_KEY_MATCH_ISSUER 0x00000002
  13495. #define CERT_TRUST_HAS_NAME_MATCH_ISSUER 0x00000004
  13496. #define CERT_TRUST_IS_SELF_SIGNED 0x00000008
  13497. // These can be applied to certificates and chains
  13498. #define CERT_TRUST_HAS_PREFERRED_ISSUER 0x00000100
  13499. #define CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY 0x00000200
  13500. #define CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS 0x00000400
  13501. // These can be applied to chains only
  13502. #define CERT_TRUST_IS_COMPLEX_CHAIN 0x00010000
  13503. //
  13504. // Each certificate context in a simple chain has a corresponding chain element
  13505. // in the simple chain context
  13506. //
  13507. // dwErrorStatus has CERT_TRUST_IS_REVOKED, pRevocationInfo set
  13508. // dwErrorStatus has CERT_TRUST_REVOCATION_STATUS_UNKNOWN, pRevocationInfo set
  13509. //
  13510. // Note that the post processing revocation supported in the first
  13511. // version only sets cbSize and dwRevocationResult. Everything else
  13512. // is NULL
  13513. //
  13514. //
  13515. // Revocation Information
  13516. //
  13517. typedef struct _CERT_REVOCATION_INFO {
  13518. DWORD cbSize;
  13519. DWORD dwRevocationResult;
  13520. LPCSTR pszRevocationOid;
  13521. LPVOID pvOidSpecificInfo;
  13522. // fHasFreshnessTime is only set if we are able to retrieve revocation
  13523. // information. For a CRL its CurrentTime - ThisUpdate.
  13524. BOOL fHasFreshnessTime;
  13525. DWORD dwFreshnessTime; // seconds
  13526. // NonNULL for CRL base revocation checking
  13527. PCERT_REVOCATION_CRL_INFO pCrlInfo;
  13528. } CERT_REVOCATION_INFO, *PCERT_REVOCATION_INFO;
  13529. //
  13530. // Trust List Information
  13531. //
  13532. typedef struct _CERT_TRUST_LIST_INFO {
  13533. DWORD cbSize;
  13534. PCTL_ENTRY pCtlEntry;
  13535. PCCTL_CONTEXT pCtlContext;
  13536. } CERT_TRUST_LIST_INFO, *PCERT_TRUST_LIST_INFO;
  13537. //
  13538. // Chain Element
  13539. //
  13540. typedef struct _CERT_CHAIN_ELEMENT {
  13541. DWORD cbSize;
  13542. PCCERT_CONTEXT pCertContext;
  13543. CERT_TRUST_STATUS TrustStatus;
  13544. PCERT_REVOCATION_INFO pRevocationInfo;
  13545. PCERT_ENHKEY_USAGE pIssuanceUsage; // If NULL, any
  13546. PCERT_ENHKEY_USAGE pApplicationUsage; // If NULL, any
  13547. LPCWSTR pwszExtendedErrorInfo; // If NULL, none
  13548. } CERT_CHAIN_ELEMENT, *PCERT_CHAIN_ELEMENT;
  13549. //
  13550. // The simple chain is an array of chain elements and a summary trust status
  13551. // for the chain
  13552. //
  13553. // rgpElements[0] is the end certificate chain element
  13554. //
  13555. // rgpElements[cElement-1] is the self-signed "root" certificate chain element
  13556. //
  13557. typedef struct _CERT_SIMPLE_CHAIN {
  13558. DWORD cbSize;
  13559. CERT_TRUST_STATUS TrustStatus;
  13560. DWORD cElement;
  13561. PCERT_CHAIN_ELEMENT* rgpElement;
  13562. PCERT_TRUST_LIST_INFO pTrustListInfo;
  13563. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13564. // revocation information for all elements checked for revocation.
  13565. // For a CRL its CurrentTime - ThisUpdate.
  13566. //
  13567. // dwRevocationFreshnessTime is the largest time across all elements
  13568. // checked.
  13569. BOOL fHasRevocationFreshnessTime;
  13570. DWORD dwRevocationFreshnessTime; // seconds
  13571. } CERT_SIMPLE_CHAIN, *PCERT_SIMPLE_CHAIN;
  13572. //
  13573. // And the chain context contains an array of simple chains and summary trust
  13574. // status for all the connected simple chains
  13575. //
  13576. // rgpChains[0] is the end certificate simple chain
  13577. //
  13578. // rgpChains[cChain-1] is the final (possibly trust list signer) chain which
  13579. // ends in a certificate which is contained in the root store
  13580. //
  13581. typedef struct _CERT_CHAIN_CONTEXT CERT_CHAIN_CONTEXT, *PCERT_CHAIN_CONTEXT;
  13582. typedef const CERT_CHAIN_CONTEXT *PCCERT_CHAIN_CONTEXT;
  13583. struct _CERT_CHAIN_CONTEXT {
  13584. DWORD cbSize;
  13585. CERT_TRUST_STATUS TrustStatus;
  13586. DWORD cChain;
  13587. PCERT_SIMPLE_CHAIN* rgpChain;
  13588. // Following is returned when CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS
  13589. // is set in dwFlags
  13590. DWORD cLowerQualityChainContext;
  13591. PCCERT_CHAIN_CONTEXT* rgpLowerQualityChainContext;
  13592. // fHasRevocationFreshnessTime is only set if we are able to retrieve
  13593. // revocation information for all elements checked for revocation.
  13594. // For a CRL its CurrentTime - ThisUpdate.
  13595. //
  13596. // dwRevocationFreshnessTime is the largest time across all elements
  13597. // checked.
  13598. BOOL fHasRevocationFreshnessTime;
  13599. DWORD dwRevocationFreshnessTime; // seconds
  13600. };
  13601. //
  13602. // When building a chain, the there are various parameters used for finding
  13603. // issuing certificates and trust lists. They are identified in the
  13604. // following structure
  13605. //
  13606. // Default usage match type is AND with value zero
  13607. #define USAGE_MATCH_TYPE_AND 0x00000000
  13608. #define USAGE_MATCH_TYPE_OR 0x00000001
  13609. typedef struct _CERT_USAGE_MATCH {
  13610. DWORD dwType;
  13611. CERT_ENHKEY_USAGE Usage;
  13612. } CERT_USAGE_MATCH, *PCERT_USAGE_MATCH;
  13613. typedef struct _CTL_USAGE_MATCH {
  13614. DWORD dwType;
  13615. CTL_USAGE Usage;
  13616. } CTL_USAGE_MATCH, *PCTL_USAGE_MATCH;
  13617. typedef struct _CERT_CHAIN_PARA {
  13618. DWORD cbSize;
  13619. CERT_USAGE_MATCH RequestedUsage;
  13620. #ifdef CERT_CHAIN_PARA_HAS_EXTRA_FIELDS
  13621. // Note, if you #define CERT_CHAIN_PARA_HAS_EXTRA_FIELDS, then, you
  13622. // must zero all unused fields in this data structure.
  13623. // More fields could be added in a future release.
  13624. CERT_USAGE_MATCH RequestedIssuancePolicy;
  13625. DWORD dwUrlRetrievalTimeout; // milliseconds
  13626. BOOL fCheckRevocationFreshnessTime;
  13627. DWORD dwRevocationFreshnessTime; // seconds
  13628. #endif
  13629. } CERT_CHAIN_PARA, *PCERT_CHAIN_PARA;
  13630. //
  13631. // The following API is used for retrieving certificate chains
  13632. //
  13633. // Parameters:
  13634. //
  13635. // hChainEngine - the chain engine (namespace and cache) to use, NULL
  13636. // mean use the default chain engine
  13637. //
  13638. // pCertContext - the context we are retrieving the chain for, it
  13639. // will be the zero index element in the chain
  13640. //
  13641. // pTime - the point in time that we want the chain validated
  13642. // for. Note that the time does not affect trust list,
  13643. // revocation, or root store checking. NULL means use
  13644. // the current system time
  13645. //
  13646. // hAdditionalStore - additional store to use when looking up objects
  13647. //
  13648. // pChainPara - parameters for chain building
  13649. //
  13650. // dwFlags - flags such as should revocation checking be done
  13651. // on the chain?
  13652. //
  13653. // pvReserved - reserved parameter, must be NULL
  13654. //
  13655. // ppChainContext - chain context returned
  13656. //
  13657. // CERT_CHAIN_CACHE_END_CERT can be used here as well
  13658. // Revocation flags are in the high nibble
  13659. #define CERT_CHAIN_REVOCATION_CHECK_END_CERT 0x10000000
  13660. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN 0x20000000
  13661. #define CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT 0x40000000
  13662. #define CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY 0x80000000
  13663. // By default, the dwUrlRetrievalTimeout in pChainPara is the timeout used
  13664. // for each revocation URL wire retrieval. When the following flag is set,
  13665. // dwUrlRetrievalTimeout is the accumulative timeout across all
  13666. // revocation URL wire retrievals.
  13667. #define CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT 0x08000000
  13668. // First pass determines highest quality based upon:
  13669. // - Chain signature valid (higest quality bit of this set)
  13670. // - Complete chain
  13671. // - Trusted root (lowestest quality bit of this set)
  13672. // By default, second pass only considers paths >= highest first pass quality
  13673. #define CERT_CHAIN_DISABLE_PASS1_QUALITY_FILTERING 0x00000040
  13674. #define CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS 0x00000080
  13675. #define CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE 0x00000100
  13676. // When this flag is set, pTime will be used as the timestamp time.
  13677. // pTime will be used to determine if the end certificate was valid at this
  13678. // time. Revocation checking will be relative to pTime.
  13679. // In addition, current time will also be used
  13680. // to determine if the certificate is still time valid. All remaining
  13681. // CA and root certificates will be checked using current time and not pTime.
  13682. //
  13683. // This flag was added 4/5/01 in WXP.
  13684. #define CERT_CHAIN_TIMESTAMP_TIME 0x00000200
  13685. WINCRYPT32API
  13686. BOOL
  13687. WINAPI
  13688. CertGetCertificateChain (
  13689. IN OPTIONAL HCERTCHAINENGINE hChainEngine,
  13690. IN PCCERT_CONTEXT pCertContext,
  13691. IN OPTIONAL LPFILETIME pTime,
  13692. IN OPTIONAL HCERTSTORE hAdditionalStore,
  13693. IN PCERT_CHAIN_PARA pChainPara,
  13694. IN DWORD dwFlags,
  13695. IN LPVOID pvReserved,
  13696. OUT PCCERT_CHAIN_CONTEXT* ppChainContext
  13697. );
  13698. //
  13699. // Free a certificate chain
  13700. //
  13701. WINCRYPT32API
  13702. VOID
  13703. WINAPI
  13704. CertFreeCertificateChain (
  13705. IN PCCERT_CHAIN_CONTEXT pChainContext
  13706. );
  13707. //
  13708. // Duplicate (add a reference to) a certificate chain
  13709. //
  13710. WINCRYPT32API
  13711. PCCERT_CHAIN_CONTEXT
  13712. WINAPI
  13713. CertDuplicateCertificateChain (
  13714. IN PCCERT_CHAIN_CONTEXT pChainContext
  13715. );
  13716. //
  13717. // Specific Revocation Type OID and structure definitions
  13718. //
  13719. //
  13720. // CRL Revocation OID
  13721. //
  13722. #define REVOCATION_OID_CRL_REVOCATION ((LPCSTR)1)
  13723. //
  13724. // For the CRL revocation OID the pvRevocationPara is NULL
  13725. //
  13726. //
  13727. // CRL Revocation Info
  13728. //
  13729. typedef struct _CRL_REVOCATION_INFO {
  13730. PCRL_ENTRY pCrlEntry;
  13731. PCCRL_CONTEXT pCrlContext;
  13732. PCCERT_CHAIN_CONTEXT pCrlIssuerChain;
  13733. } CRL_REVOCATION_INFO, *PCRL_REVOCATION_INFO;
  13734. //+-------------------------------------------------------------------------
  13735. // Find the first or next certificate chain context in the store.
  13736. //
  13737. // The chain context is found according to the dwFindFlags, dwFindType and
  13738. // its pvFindPara. See below for a list of the find types and its parameters.
  13739. //
  13740. // If the first or next chain context isn't found, NULL is returned.
  13741. // Otherwise, a pointer to a read only CERT_CHAIN_CONTEXT is returned.
  13742. // CERT_CHAIN_CONTEXT must be freed by calling CertFreeCertificateChain
  13743. // or is freed when passed as the
  13744. // pPrevChainContext on a subsequent call. CertDuplicateCertificateChain
  13745. // can be called to make a duplicate.
  13746. //
  13747. // pPrevChainContext MUST BE NULL on the first
  13748. // call to find the chain context. To find the next chain context, the
  13749. // pPrevChainContext is set to the CERT_CHAIN_CONTEXT returned by a previous
  13750. // call.
  13751. //
  13752. // NOTE: a NON-NULL pPrevChainContext is always CertFreeCertificateChain'ed by
  13753. // this function, even for an error.
  13754. //--------------------------------------------------------------------------
  13755. WINCRYPT32API
  13756. PCCERT_CHAIN_CONTEXT
  13757. WINAPI
  13758. CertFindChainInStore(
  13759. IN HCERTSTORE hCertStore,
  13760. IN DWORD dwCertEncodingType,
  13761. IN DWORD dwFindFlags,
  13762. IN DWORD dwFindType,
  13763. IN const void *pvFindPara,
  13764. IN PCCERT_CHAIN_CONTEXT pPrevChainContext
  13765. );
  13766. #define CERT_CHAIN_FIND_BY_ISSUER 1
  13767. //+-------------------------------------------------------------------------
  13768. // CERT_CHAIN_FIND_BY_ISSUER
  13769. //
  13770. // Find a certificate chain having a private key for the end certificate and
  13771. // matching one of the given issuer names. A matching dwKeySpec and
  13772. // enhanced key usage can also be specified. Additionally a callback can
  13773. // be provided for even more caller provided filtering before building the
  13774. // chain.
  13775. //
  13776. // By default, only the issuers in the first simple chain are compared
  13777. // for a name match. CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG can
  13778. // be set in dwFindFlags to match issuers in all the simple chains.
  13779. //
  13780. // CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG can be set in dwFindFlags to
  13781. // not check if the end certificate has a private key.
  13782. //
  13783. // CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG can be set in dwFindFlags
  13784. // to compare the public key in the end certificate with the crypto
  13785. // provider's public key. The dwAcquirePrivateKeyFlags can be set
  13786. // in CERT_CHAIN_FIND_BY_ISSUER_PARA to enable caching of the private key's
  13787. // HKEY returned by the CSP.
  13788. //
  13789. // If dwCertEncodingType == 0, defaults to X509_ASN_ENCODING for the
  13790. // array of encoded issuer names.
  13791. //
  13792. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13793. // as an additional store to CertGetCertificateChain.
  13794. // CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG can be set in dwFindFlags
  13795. // to improve performance by only searching the cached system stores
  13796. // (root, my, ca, trust) to find the issuer certificates. If you are doing
  13797. // a find in the "my" system store, than, this flag should be set to
  13798. // improve performance.
  13799. //
  13800. // Setting CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG in dwFindFlags
  13801. // restricts CertGetCertificateChain to search the Local Machine
  13802. // cached system stores instead of the Current User's.
  13803. //
  13804. // Setting CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG in dwFindFlags
  13805. // restricts CertGetCertificateChain to only search the URL cache
  13806. // and not hit the wire.
  13807. //--------------------------------------------------------------------------
  13808. // Returns FALSE to skip this certificate. Otherwise, returns TRUE to
  13809. // build a chain for this certificate.
  13810. typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(
  13811. IN PCCERT_CONTEXT pCert,
  13812. IN void *pvFindArg
  13813. );
  13814. typedef struct _CERT_CHAIN_FIND_BY_ISSUER_PARA {
  13815. DWORD cbSize;
  13816. // If pszUsageIdentifier == NULL, matches any usage.
  13817. LPCSTR pszUsageIdentifier;
  13818. // If dwKeySpec == 0, matches any KeySpec
  13819. DWORD dwKeySpec;
  13820. // When CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG is set in dwFindFlags,
  13821. // CryptAcquireCertificatePrivateKey is called to do the public key
  13822. // comparison. The following flags can be set to enable caching
  13823. // of the acquired private key or suppress CSP UI. See the API for more
  13824. // details on these flags.
  13825. DWORD dwAcquirePrivateKeyFlags;
  13826. // Pointer to an array of X509, ASN.1 encoded issuer name blobs. If
  13827. // cIssuer == 0, matches any issuer
  13828. DWORD cIssuer;
  13829. CERT_NAME_BLOB *rgIssuer;
  13830. // If NULL or Callback returns TRUE, builds the chain for the end
  13831. // certificate having a private key with the specified KeySpec and
  13832. // enhanced key usage.
  13833. PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK pfnFindCallback;
  13834. void *pvFindArg;
  13835. #ifdef CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS
  13836. // Note, if you #define CERT_CHAIN_FIND_BY_ISSUER_PARA_HAS_EXTRA_FIELDS,
  13837. // then, you must zero all unused fields in this data structure.
  13838. // More fields could be added in a future release.
  13839. // If the following pointers are nonNull, returns the index of the
  13840. // matching issuer certificate, which is at:
  13841. // pChainContext->
  13842. // rgpChain[*pdwIssuerChainIndex]->rgpElement[*pdwIssuerElementIndex].
  13843. //
  13844. // The issuer name blob is compared against the Issuer field in the
  13845. // certificate. The *pdwIssuerElementIndex is set to the index of this
  13846. // subject certificate + 1. Therefore, its possible for a partial chain or
  13847. // a self signed certificate matching the name blob, where
  13848. // *pdwIssuerElementIndex points past the last certificate in the chain.
  13849. //
  13850. // Note, not updated if the above cIssuer == 0.
  13851. DWORD *pdwIssuerChainIndex;
  13852. DWORD *pdwIssuerElementIndex;
  13853. #endif
  13854. } CERT_CHAIN_FIND_ISSUER_PARA, *PCERT_CHAIN_FIND_ISSUER_PARA,
  13855. CERT_CHAIN_FIND_BY_ISSUER_PARA, *PCERT_CHAIN_FIND_BY_ISSUER_PARA;
  13856. // The following dwFindFlags can be set for CERT_CHAIN_FIND_BY_ISSUER
  13857. // If set, compares the public key in the end certificate with the crypto
  13858. // provider's public key. This comparison is the last check made on the
  13859. // build chain.
  13860. #define CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG 0x0001
  13861. // If not set, only checks the first simple chain for an issuer name match.
  13862. // When set, also checks second and subsequent simple chains.
  13863. #define CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG 0x0002
  13864. // If set, CertGetCertificateChain only searches the URL cache and
  13865. // doesn't hit the wire.
  13866. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG 0x0004
  13867. // If set, CertGetCertificateChain only opens the Local Machine
  13868. // certificate stores instead of the Current User's.
  13869. #define CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG 0x0008
  13870. // If set, no check is made to see if the end certificate has a private
  13871. // key associated with it.
  13872. #define CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG 0x4000
  13873. // By default, the hCertStore passed to CertFindChainInStore, is passed
  13874. // as the additional store to CertGetCertificateChain. This flag can be
  13875. // set to improve performance by only searching the cached system stores
  13876. // (root, my, ca, trust) to find the issuer certificates. If not set, then,
  13877. // the hCertStore is always searched in addition to the cached system
  13878. // stores.
  13879. #define CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG 0x8000
  13880. //+=========================================================================
  13881. // Certificate Chain Policy Data Structures and APIs
  13882. //==========================================================================
  13883. typedef struct _CERT_CHAIN_POLICY_PARA {
  13884. DWORD cbSize;
  13885. DWORD dwFlags;
  13886. void *pvExtraPolicyPara; // pszPolicyOID specific
  13887. } CERT_CHAIN_POLICY_PARA, *PCERT_CHAIN_POLICY_PARA;
  13888. // If both lChainIndex and lElementIndex are set to -1, the dwError applies
  13889. // to the whole chain context. If only lElementIndex is set to -1, the
  13890. // dwError applies to the lChainIndex'ed chain. Otherwise, the dwError applies
  13891. // to the certificate element at
  13892. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13893. typedef struct _CERT_CHAIN_POLICY_STATUS {
  13894. DWORD cbSize;
  13895. DWORD dwError;
  13896. LONG lChainIndex;
  13897. LONG lElementIndex;
  13898. void *pvExtraPolicyStatus; // pszPolicyOID specific
  13899. } CERT_CHAIN_POLICY_STATUS, *PCERT_CHAIN_POLICY_STATUS;
  13900. // Common chain policy flags
  13901. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG 0x00000001
  13902. #define CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG 0x00000002
  13903. #define CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG 0x00000004
  13904. #define CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG 0x00000008
  13905. #define CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS ( \
  13906. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG | \
  13907. CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG | \
  13908. CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG \
  13909. )
  13910. #define CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG 0x00000010
  13911. #define CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG 0x00000020
  13912. #define CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG 0x00000040
  13913. #define CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG 0x00000080
  13914. #define CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG 0x00000100
  13915. #define CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG 0x00000200
  13916. #define CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG 0x00000400
  13917. #define CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG 0x00000800
  13918. #define CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS ( \
  13919. CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG | \
  13920. CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG | \
  13921. CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG | \
  13922. CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG \
  13923. )
  13924. #define CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG 0x00008000
  13925. #define CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG 0x00004000
  13926. //+-------------------------------------------------------------------------
  13927. // Verify that the certificate chain satisfies the specified policy
  13928. // requirements. If we were able to verify the chain policy, TRUE is returned
  13929. // and the dwError field of the pPolicyStatus is updated. A dwError of 0
  13930. // (ERROR_SUCCESS, S_OK) indicates the chain satisfies the specified policy.
  13931. //
  13932. // If dwError applies to the entire chain context, both lChainIndex and
  13933. // lElementIndex are set to -1. If dwError applies to a simple chain,
  13934. // lElementIndex is set to -1 and lChainIndex is set to the index of the
  13935. // first offending chain having the error. If dwError applies to a
  13936. // certificate element, lChainIndex and lElementIndex are updated to
  13937. // index the first offending certificate having the error, where, the
  13938. // the certificate element is at:
  13939. // pChainContext->rgpChain[lChainIndex]->rgpElement[lElementIndex].
  13940. //
  13941. // The dwFlags in pPolicyPara can be set to change the default policy checking
  13942. // behaviour. In addition, policy specific parameters can be passed in
  13943. // the pvExtraPolicyPara field of pPolicyPara.
  13944. //
  13945. // In addition to returning dwError, in pPolicyStatus, policy OID specific
  13946. // extra status may be returned via pvExtraPolicyStatus.
  13947. //--------------------------------------------------------------------------
  13948. WINCRYPT32API
  13949. BOOL
  13950. WINAPI
  13951. CertVerifyCertificateChainPolicy(
  13952. IN LPCSTR pszPolicyOID,
  13953. IN PCCERT_CHAIN_CONTEXT pChainContext,
  13954. IN PCERT_CHAIN_POLICY_PARA pPolicyPara,
  13955. IN OUT PCERT_CHAIN_POLICY_STATUS pPolicyStatus
  13956. );
  13957. // Predefined OID Function Names
  13958. #define CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC \
  13959. "CertDllVerifyCertificateChainPolicy"
  13960. // CertDllVerifyCertificateChainPolicy has same function signature as
  13961. // CertVerifyCertificateChainPolicy.
  13962. //+-------------------------------------------------------------------------
  13963. // Predefined verify chain policies
  13964. //--------------------------------------------------------------------------
  13965. #define CERT_CHAIN_POLICY_BASE ((LPCSTR) 1)
  13966. #define CERT_CHAIN_POLICY_AUTHENTICODE ((LPCSTR) 2)
  13967. #define CERT_CHAIN_POLICY_AUTHENTICODE_TS ((LPCSTR) 3)
  13968. #define CERT_CHAIN_POLICY_SSL ((LPCSTR) 4)
  13969. #define CERT_CHAIN_POLICY_BASIC_CONSTRAINTS ((LPCSTR) 5)
  13970. #define CERT_CHAIN_POLICY_NT_AUTH ((LPCSTR) 6)
  13971. #define CERT_CHAIN_POLICY_MICROSOFT_ROOT ((LPCSTR) 7)
  13972. //+-------------------------------------------------------------------------
  13973. // CERT_CHAIN_POLICY_BASE
  13974. //
  13975. // Implements the base chain policy verification checks. dwFlags can
  13976. // be set in pPolicyPara to alter the default policy checking behaviour.
  13977. //--------------------------------------------------------------------------
  13978. //+-------------------------------------------------------------------------
  13979. // CERT_CHAIN_POLICY_AUTHENTICODE
  13980. //
  13981. // Implements the Authenticode chain policy verification checks.
  13982. //
  13983. // pvExtraPolicyPara may optionally be set to point to the following
  13984. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA.
  13985. //
  13986. // pvExtraPolicyStatus may optionally be set to point to the following
  13987. // AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS.
  13988. //--------------------------------------------------------------------------
  13989. // dwRegPolicySettings are defined in wintrust.h
  13990. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA {
  13991. DWORD cbSize;
  13992. DWORD dwRegPolicySettings;
  13993. PCMSG_SIGNER_INFO pSignerInfo; // optional
  13994. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA,
  13995. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_PARA;
  13996. typedef struct _AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS {
  13997. DWORD cbSize;
  13998. BOOL fCommercial; // obtained from signer statement
  13999. } AUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS,
  14000. *PAUTHENTICODE_EXTRA_CERT_CHAIN_POLICY_STATUS;
  14001. //+-------------------------------------------------------------------------
  14002. // CERT_CHAIN_POLICY_AUTHENTICODE_TS
  14003. //
  14004. // Implements the Authenticode Time Stamp chain policy verification checks.
  14005. //
  14006. // pvExtraPolicyPara may optionally be set to point to the following
  14007. // AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA.
  14008. //
  14009. // pvExtraPolicyStatus isn't used and must be set to NULL.
  14010. //--------------------------------------------------------------------------
  14011. // dwRegPolicySettings are defined in wintrust.h
  14012. typedef struct _AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA {
  14013. DWORD cbSize;
  14014. DWORD dwRegPolicySettings;
  14015. BOOL fCommercial;
  14016. } AUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA,
  14017. *PAUTHENTICODE_TS_EXTRA_CERT_CHAIN_POLICY_PARA;
  14018. //+-------------------------------------------------------------------------
  14019. // CERT_CHAIN_POLICY_SSL
  14020. //
  14021. // Implements the SSL client/server chain policy verification checks.
  14022. //
  14023. // pvExtraPolicyPara may optionally be set to point to the following
  14024. // SSL_EXTRA_CERT_CHAIN_POLICY_PARA data structure
  14025. //--------------------------------------------------------------------------
  14026. // fdwChecks flags are defined in wininet.h
  14027. typedef struct _HTTPSPolicyCallbackData
  14028. {
  14029. union {
  14030. DWORD cbStruct; // sizeof(HTTPSPolicyCallbackData);
  14031. DWORD cbSize; // sizeof(HTTPSPolicyCallbackData);
  14032. };
  14033. DWORD dwAuthType;
  14034. # define AUTHTYPE_CLIENT 1
  14035. # define AUTHTYPE_SERVER 2
  14036. DWORD fdwChecks;
  14037. WCHAR *pwszServerName; // used to check against CN=xxxx
  14038. } HTTPSPolicyCallbackData, *PHTTPSPolicyCallbackData,
  14039. SSL_EXTRA_CERT_CHAIN_POLICY_PARA, *PSSL_EXTRA_CERT_CHAIN_POLICY_PARA;
  14040. //+-------------------------------------------------------------------------
  14041. // CERT_CHAIN_POLICY_BASIC_CONSTRAINTS
  14042. //
  14043. // Implements the basic constraints chain policy.
  14044. //
  14045. // Iterates through all the certificates in the chain checking for either
  14046. // a szOID_BASIC_CONSTRAINTS or a szOID_BASIC_CONSTRAINTS2 extension. If
  14047. // neither extension is present, the certificate is assumed to have
  14048. // valid policy. Otherwise, for the first certificate element, checks if
  14049. // it matches the expected CA_FLAG or END_ENTITY_FLAG specified in
  14050. // pPolicyPara->dwFlags. If neither or both flags are set, then, the first
  14051. // element can be either a CA or END_ENTITY. All other elements must be
  14052. // a CA. If the PathLenConstraint is present in the extension, its
  14053. // checked.
  14054. //
  14055. // The first elements in the remaining simple chains (ie, the certificate
  14056. // used to sign the CTL) are checked to be an END_ENTITY.
  14057. //
  14058. // If this verification fails, dwError will be set to
  14059. // TRUST_E_BASIC_CONSTRAINTS.
  14060. //--------------------------------------------------------------------------
  14061. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_CA_FLAG 0x80000000
  14062. #define BASIC_CONSTRAINTS_CERT_CHAIN_POLICY_END_ENTITY_FLAG 0x40000000
  14063. //+-------------------------------------------------------------------------
  14064. // CERT_CHAIN_POLICY_NT_AUTH
  14065. //
  14066. // Implements the NT Authentication chain policy.
  14067. //
  14068. // The NT Authentication chain policy consists of 3 distinct chain
  14069. // verifications in the following order:
  14070. // [1] CERT_CHAIN_POLICY_BASE - Implements the base chain policy
  14071. // verification checks. The LOWORD of dwFlags can be set in
  14072. // pPolicyPara to alter the default policy checking behaviour. See
  14073. // CERT_CHAIN_POLICY_BASE for more details.
  14074. //
  14075. // [2] CERT_CHAIN_POLICY_BASIC_CONSTRAINTS - Implements the basic
  14076. // constraints chain policy. The HIWORD of dwFlags can be set
  14077. // to specify if the first element must be either a CA or END_ENTITY.
  14078. // See CERT_CHAIN_POLICY_BASIC_CONSTRAINTS for more details.
  14079. //
  14080. // [3] Checks if the second element in the chain, the CA that issued
  14081. // the end certificate, is a trusted CA for NT
  14082. // Authentication. A CA is considered to be trusted if it exists in
  14083. // the "NTAuth" system registry store found in the
  14084. // CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE store location.
  14085. // If this verification fails, whereby the CA isn't trusted,
  14086. // dwError is set to CERT_E_UNTRUSTEDCA.
  14087. //
  14088. // If CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG is set
  14089. // in the "Flags" value of the HKLM policy "ProtectedRoots" subkey
  14090. // defined by CERT_PROT_ROOT_FLAGS_REGPATH, then,
  14091. // if the above check fails, checks if the chain
  14092. // has CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS set in dwInfoStatus. This
  14093. // will only be set if there was a valid name constraint for all
  14094. // name spaces including UPN. If the chain doesn't have this info
  14095. // status set, dwError is set to CERT_E_UNTRUSTEDCA.
  14096. //--------------------------------------------------------------------------
  14097. //+-------------------------------------------------------------------------
  14098. // CERT_CHAIN_POLICY_MICROSOFT_ROOT
  14099. //
  14100. // Checks if the last element of the first simple chain contains a
  14101. // Microsoft root public key. If it doesn't contain a Microsoft root
  14102. // public key, dwError is set to CERT_E_UNTRUSTEDROOT.
  14103. //
  14104. // pPolicyPara is optional. However,
  14105. // MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG can be set in
  14106. // the dwFlags in pPolicyPara to also check for the Microsoft Test Roots.
  14107. //
  14108. // pvExtraPolicyPara and pvExtraPolicyStatus aren't used and must be set
  14109. // to NULL.
  14110. //--------------------------------------------------------------------------
  14111. #define MICROSOFT_ROOT_CERT_CHAIN_POLICY_ENABLE_TEST_ROOT_FLAG 0x00010000
  14112. //+-------------------------------------------------------------------------
  14113. // convert formatted string to binary
  14114. // If cchString is 0, then pszString is NULL terminated and
  14115. // cchString is obtained via strlen() + 1.
  14116. // dwFlags defines string format
  14117. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  14118. // *pdwSkip returns the character count of skipped strings, optional
  14119. // *pdwFlags returns the actual format used in the conversion, optional
  14120. //--------------------------------------------------------------------------
  14121. WINCRYPT32STRINGAPI
  14122. BOOL
  14123. WINAPI
  14124. CryptStringToBinaryA(
  14125. IN LPCSTR pszString,
  14126. IN DWORD cchString,
  14127. IN DWORD dwFlags,
  14128. IN BYTE *pbBinary,
  14129. IN OUT DWORD *pcbBinary,
  14130. OUT DWORD *pdwSkip, //OPTIONAL
  14131. OUT DWORD *pdwFlags //OPTIONAL
  14132. );
  14133. //+-------------------------------------------------------------------------
  14134. // convert formatted string to binary
  14135. // If cchString is 0, then pszString is NULL terminated and
  14136. // cchString is obtained via strlen() + 1.
  14137. // dwFlags defines string format
  14138. // if pbBinary is NULL, *pcbBinary returns the size of required memory
  14139. // *pdwSkip returns the character count of skipped strings, optional
  14140. // *pdwFlags returns the actual format used in the conversion, optional
  14141. //--------------------------------------------------------------------------
  14142. WINCRYPT32STRINGAPI
  14143. BOOL
  14144. WINAPI
  14145. CryptStringToBinaryW(
  14146. IN LPCWSTR pszString,
  14147. IN DWORD cchString,
  14148. IN DWORD dwFlags,
  14149. IN BYTE *pbBinary,
  14150. IN OUT DWORD *pcbBinary,
  14151. OUT DWORD *pdwSkip, //OPTIONAL
  14152. OUT DWORD *pdwFlags //OPTIONAL
  14153. );
  14154. #ifdef UNICODE
  14155. #define CryptStringToBinary CryptStringToBinaryW
  14156. #else
  14157. #define CryptStringToBinary CryptStringToBinaryA
  14158. #endif // !UNICODE
  14159. //+-------------------------------------------------------------------------
  14160. // convert binary to formatted string
  14161. // dwFlags defines string format
  14162. // if pszString is NULL, *pcchString returns size in characters
  14163. // including null-terminator
  14164. //--------------------------------------------------------------------------
  14165. WINCRYPT32STRINGAPI
  14166. BOOL
  14167. WINAPI
  14168. CryptBinaryToStringA(
  14169. IN CONST BYTE *pbBinary,
  14170. IN DWORD cbBinary,
  14171. IN DWORD dwFlags,
  14172. IN LPSTR pszString,
  14173. IN OUT DWORD *pcchString
  14174. );
  14175. //+-------------------------------------------------------------------------
  14176. // convert binary to formatted string
  14177. // dwFlags defines string format
  14178. // if pszString is NULL, *pcchString returns size in characters
  14179. // including null-terminator
  14180. //--------------------------------------------------------------------------
  14181. WINCRYPT32STRINGAPI
  14182. BOOL
  14183. WINAPI
  14184. CryptBinaryToStringW(
  14185. IN CONST BYTE *pbBinary,
  14186. IN DWORD cbBinary,
  14187. IN DWORD dwFlags,
  14188. IN LPWSTR pszString,
  14189. IN OUT DWORD *pcchString
  14190. );
  14191. #ifdef UNICODE
  14192. #define CryptBinaryToString CryptBinaryToStringW
  14193. #else
  14194. #define CryptBinaryToString CryptBinaryToStringA
  14195. #endif // !UNICODE
  14196. // dwFlags has the following defines
  14197. #define CRYPT_STRING_BASE64HEADER 0x00000000
  14198. #define CRYPT_STRING_BASE64 0x00000001
  14199. #define CRYPT_STRING_BINARY 0x00000002
  14200. #define CRYPT_STRING_BASE64REQUESTHEADER 0x00000003
  14201. #define CRYPT_STRING_HEX 0x00000004
  14202. #define CRYPT_STRING_HEXASCII 0x00000005
  14203. #define CRYPT_STRING_BASE64_ANY 0x00000006
  14204. #define CRYPT_STRING_ANY 0x00000007
  14205. #define CRYPT_STRING_HEX_ANY 0x00000008
  14206. #define CRYPT_STRING_BASE64X509CRLHEADER 0x00000009
  14207. #define CRYPT_STRING_HEXADDR 0x0000000a
  14208. #define CRYPT_STRING_HEXASCIIADDR 0x0000000b
  14209. #define CRYPT_STRING_NOCR 0x80000000
  14210. // CryptBinaryToString uses the following flags
  14211. // CRYPT_STRING_BASE64HEADER - base64 format with certificate begin
  14212. // and end headers
  14213. // CRYPT_STRING_BASE64 - only base64 without headers
  14214. // CRYPT_STRING_BINARY - pure binary copy
  14215. // CRYPT_STRING_BASE64REQUESTHEADER - base64 format with request begin
  14216. // and end headers
  14217. // CRYPT_STRING_BASE64X509CRLHEADER - base64 format with x509 crl begin
  14218. // and end headers
  14219. // CRYPT_STRING_HEX - only hex format
  14220. // CRYPT_STRING_HEXASCII - hex format with ascii char display
  14221. // CRYPT_STRING_HEXADDR - hex format with address display
  14222. // CRYPT_STRING_HEXASCIIADDR - hex format with ascii char and address display
  14223. //
  14224. // CryptBinaryToString accepts CRYPT_STRING_NOCR or'd into one of the above.
  14225. // When set, line breaks contain only LF, instead of CR-LF pairs.
  14226. // CryptStringToBinary uses the following flags
  14227. // CRYPT_STRING_BASE64_ANY tries the following, in order:
  14228. // CRYPT_STRING_BASE64HEADER
  14229. // CRYPT_STRING_BASE64
  14230. // CRYPT_STRING_ANY tries the following, in order:
  14231. // CRYPT_STRING_BASE64_ANY
  14232. // CRYPT_STRING_BINARY -- should always succeed
  14233. // CRYPT_STRING_HEX_ANY tries the following, in order:
  14234. // CRYPT_STRING_HEXADDR
  14235. // CRYPT_STRING_HEXASCIIADDR
  14236. // CRYPT_STRING_HEXASCII
  14237. // CRYPT_STRING_HEX
  14238. //+=========================================================================
  14239. // PFX (PKCS #12) function defintions and types
  14240. //==========================================================================
  14241. //+-------------------------------------------------------------------------
  14242. // PFXImportCertStore
  14243. //
  14244. // Import the PFX blob and return a store containing certificates
  14245. //
  14246. // If the password parameter is incorrect or any other problems decoding
  14247. // the PFX blob are encountered, the function will return NULL and the
  14248. // error code can be found from GetLastError().
  14249. //
  14250. // The dwFlags parameter may be set to the following:
  14251. // CRYPT_EXPORTABLE - specify that any imported keys should be marked as
  14252. // exportable (see documentation on CryptImportKey)
  14253. // CRYPT_USER_PROTECTED - (see documentation on CryptImportKey)
  14254. // CRYPT_MACHINE_KEYSET - used to force the private key to be stored in the
  14255. // the local machine and not the current user.
  14256. // CRYPT_USER_KEYSET - used to force the private key to be stored in the
  14257. // the current user and not the local machine, even if
  14258. // the pfx blob specifies that it should go into local
  14259. // machine.
  14260. //--------------------------------------------------------------------------
  14261. WINCRYPT32API
  14262. HCERTSTORE
  14263. WINAPI
  14264. PFXImportCertStore(
  14265. IN CRYPT_DATA_BLOB* pPFX,
  14266. IN LPCWSTR szPassword,
  14267. IN DWORD dwFlags);
  14268. // dwFlags definitions for PFXImportCertStore
  14269. //#define CRYPT_EXPORTABLE 0x00000001 // CryptImportKey dwFlags
  14270. //#define CRYPT_USER_PROTECTED 0x00000002 // CryptImportKey dwFlags
  14271. //#define CRYPT_MACHINE_KEYSET 0x00000020 // CryptAcquireContext dwFlags
  14272. #define CRYPT_USER_KEYSET 0x00001000
  14273. #define PKCS12_IMPORT_RESERVED_MASK 0xffff0000
  14274. //+-------------------------------------------------------------------------
  14275. // PFXIsPFXBlob
  14276. //
  14277. // This function will try to decode the outer layer of the blob as a pfx
  14278. // blob, and if that works it will return TRUE, it will return FALSE otherwise
  14279. //
  14280. //--------------------------------------------------------------------------
  14281. WINCRYPT32API
  14282. BOOL
  14283. WINAPI
  14284. PFXIsPFXBlob(
  14285. IN CRYPT_DATA_BLOB* pPFX);
  14286. //+-------------------------------------------------------------------------
  14287. // PFXVerifyPassword
  14288. //
  14289. // This function will attempt to decode the outer layer of the blob as a pfx
  14290. // blob and decrypt with the given password. No data from the blob will be
  14291. // imported.
  14292. //
  14293. // Return value is TRUE if password appears correct, FALSE otherwise.
  14294. //
  14295. //--------------------------------------------------------------------------
  14296. WINCRYPT32API
  14297. BOOL
  14298. WINAPI
  14299. PFXVerifyPassword(
  14300. IN CRYPT_DATA_BLOB* pPFX,
  14301. IN LPCWSTR szPassword,
  14302. IN DWORD dwFlags);
  14303. //+-------------------------------------------------------------------------
  14304. // PFXExportCertStoreEx
  14305. //
  14306. // Export the certificates and private keys referenced in the passed-in store
  14307. //
  14308. // This API encodes the blob under a stronger algorithm. The resulting
  14309. // PKCS12 blobs are incompatible with the earlier PFXExportCertStore API.
  14310. //
  14311. // The value passed in the password parameter will be used to encrypt and
  14312. // verify the integrity of the PFX packet. If any problems encoding the store
  14313. // are encountered, the function will return FALSE and the error code can
  14314. // be found from GetLastError().
  14315. //
  14316. // The dwFlags parameter may be set to any combination of
  14317. // EXPORT_PRIVATE_KEYS
  14318. // REPORT_NO_PRIVATE_KEY
  14319. // REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY
  14320. //
  14321. // The encoded PFX blob is returned in *pPFX. If pPFX->pbData is NULL upon
  14322. // input, this is a length only calculation, whereby, pPFX->cbData is updated
  14323. // with the number of bytes required for the encoded blob. Otherwise,
  14324. // the memory pointed to by pPFX->pbData is updated with the encoded bytes
  14325. // and pPFX->cbData is updated with the encoded byte length.
  14326. //--------------------------------------------------------------------------
  14327. WINCRYPT32API
  14328. BOOL
  14329. WINAPI
  14330. PFXExportCertStoreEx(
  14331. IN HCERTSTORE hStore,
  14332. IN OUT CRYPT_DATA_BLOB* pPFX,
  14333. IN LPCWSTR szPassword,
  14334. IN void* pvReserved,
  14335. IN DWORD dwFlags);
  14336. // dwFlags definitions for PFXExportCertStoreEx
  14337. #define REPORT_NO_PRIVATE_KEY 0x0001
  14338. #define REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY 0x0002
  14339. #define EXPORT_PRIVATE_KEYS 0x0004
  14340. #define PKCS12_EXPORT_RESERVED_MASK 0xffff0000
  14341. //+-------------------------------------------------------------------------
  14342. // PFXExportCertStore
  14343. //
  14344. // Export the certificates and private keys referenced in the passed-in store
  14345. //
  14346. // This is an old API kept for compatibility with IE4 clients. New applications
  14347. // should call the above PfxExportCertStoreEx for enhanced security.
  14348. //--------------------------------------------------------------------------
  14349. WINCRYPT32API
  14350. BOOL
  14351. WINAPI
  14352. PFXExportCertStore(
  14353. IN HCERTSTORE hStore,
  14354. IN OUT CRYPT_DATA_BLOB* pPFX,
  14355. IN LPCWSTR szPassword,
  14356. IN DWORD dwFlags);
  14357. #ifdef __cplusplus
  14358. } // Balance extern "C" above
  14359. #endif
  14360. #if defined (_MSC_VER)
  14361. #if ( _MSC_VER >= 800 )
  14362. #if _MSC_VER >= 1200
  14363. #pragma warning(pop)
  14364. #else
  14365. #pragma warning(default:4201)
  14366. #endif
  14367. #endif
  14368. #endif
  14369. #endif // __WINCRYPT_H__