x509.h 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446
  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  59. * ECDH support in OpenSSL originally developed by
  60. * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  61. */
  62. #ifndef HEADER_X509_H
  63. #define HEADER_X509_H
  64. #include <openssl/asn1.h>
  65. #include <openssl/base.h>
  66. #include <openssl/bio.h>
  67. #include <openssl/cipher.h>
  68. #include <openssl/dh.h>
  69. #include <openssl/dsa.h>
  70. #include <openssl/ec.h>
  71. #include <openssl/ecdh.h>
  72. #include <openssl/ecdsa.h>
  73. #include <openssl/evp.h>
  74. #include <openssl/obj.h>
  75. #include <openssl/pkcs7.h>
  76. #include <openssl/pool.h>
  77. #include <openssl/rsa.h>
  78. #include <openssl/sha.h>
  79. #include <openssl/stack.h>
  80. #include <openssl/thread.h>
  81. #include <time.h>
  82. #if defined(__cplusplus)
  83. extern "C" {
  84. #endif
  85. // Legacy X.509 library.
  86. //
  87. // This header is part of OpenSSL's X.509 implementation. It is retained for
  88. // compatibility but otherwise underdocumented and not actively maintained. In
  89. // the future, a replacement library will be available. Meanwhile, minimize
  90. // dependencies on this header where possible.
  91. #define X509_FILETYPE_PEM 1
  92. #define X509_FILETYPE_ASN1 2
  93. #define X509_FILETYPE_DEFAULT 3
  94. #define X509v3_KU_DIGITAL_SIGNATURE 0x0080
  95. #define X509v3_KU_NON_REPUDIATION 0x0040
  96. #define X509v3_KU_KEY_ENCIPHERMENT 0x0020
  97. #define X509v3_KU_DATA_ENCIPHERMENT 0x0010
  98. #define X509v3_KU_KEY_AGREEMENT 0x0008
  99. #define X509v3_KU_KEY_CERT_SIGN 0x0004
  100. #define X509v3_KU_CRL_SIGN 0x0002
  101. #define X509v3_KU_ENCIPHER_ONLY 0x0001
  102. #define X509v3_KU_DECIPHER_ONLY 0x8000
  103. #define X509v3_KU_UNDEF 0xffff
  104. struct X509_algor_st {
  105. ASN1_OBJECT *algorithm;
  106. ASN1_TYPE *parameter;
  107. } /* X509_ALGOR */;
  108. DECLARE_ASN1_FUNCTIONS(X509_ALGOR)
  109. DEFINE_STACK_OF(X509_ALGOR)
  110. typedef STACK_OF(X509_ALGOR) X509_ALGORS;
  111. DEFINE_STACK_OF(X509_NAME_ENTRY)
  112. DEFINE_STACK_OF(X509_NAME)
  113. typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS;
  114. DEFINE_STACK_OF(X509_EXTENSION)
  115. DEFINE_STACK_OF(X509_ATTRIBUTE)
  116. // This stuff is certificate "auxiliary info"
  117. // it contains details which are useful in certificate
  118. // stores and databases. When used this is tagged onto
  119. // the end of the certificate itself
  120. DECLARE_STACK_OF(DIST_POINT)
  121. DECLARE_STACK_OF(GENERAL_NAME)
  122. DEFINE_STACK_OF(X509)
  123. // This is used for a table of trust checking functions
  124. struct x509_trust_st {
  125. int trust;
  126. int flags;
  127. int (*check_trust)(struct x509_trust_st *, X509 *, int);
  128. char *name;
  129. int arg1;
  130. void *arg2;
  131. } /* X509_TRUST */;
  132. DEFINE_STACK_OF(X509_TRUST)
  133. // standard trust ids
  134. #define X509_TRUST_DEFAULT (-1) // Only valid in purpose settings
  135. #define X509_TRUST_COMPAT 1
  136. #define X509_TRUST_SSL_CLIENT 2
  137. #define X509_TRUST_SSL_SERVER 3
  138. #define X509_TRUST_EMAIL 4
  139. #define X509_TRUST_OBJECT_SIGN 5
  140. #define X509_TRUST_OCSP_SIGN 6
  141. #define X509_TRUST_OCSP_REQUEST 7
  142. #define X509_TRUST_TSA 8
  143. // Keep these up to date!
  144. #define X509_TRUST_MIN 1
  145. #define X509_TRUST_MAX 8
  146. // trust_flags values
  147. #define X509_TRUST_DYNAMIC 1
  148. #define X509_TRUST_DYNAMIC_NAME 2
  149. // check_trust return codes
  150. #define X509_TRUST_TRUSTED 1
  151. #define X509_TRUST_REJECTED 2
  152. #define X509_TRUST_UNTRUSTED 3
  153. // Flags for X509_print_ex()
  154. #define X509_FLAG_COMPAT 0
  155. #define X509_FLAG_NO_HEADER 1L
  156. #define X509_FLAG_NO_VERSION (1L << 1)
  157. #define X509_FLAG_NO_SERIAL (1L << 2)
  158. #define X509_FLAG_NO_SIGNAME (1L << 3)
  159. #define X509_FLAG_NO_ISSUER (1L << 4)
  160. #define X509_FLAG_NO_VALIDITY (1L << 5)
  161. #define X509_FLAG_NO_SUBJECT (1L << 6)
  162. #define X509_FLAG_NO_PUBKEY (1L << 7)
  163. #define X509_FLAG_NO_EXTENSIONS (1L << 8)
  164. #define X509_FLAG_NO_SIGDUMP (1L << 9)
  165. #define X509_FLAG_NO_AUX (1L << 10)
  166. #define X509_FLAG_NO_ATTRIBUTES (1L << 11)
  167. #define X509_FLAG_NO_IDS (1L << 12)
  168. // Flags specific to X509_NAME_print_ex(). These flags must not collide with
  169. // |ASN1_STRFLGS_*|.
  170. // The field separator information
  171. #define XN_FLAG_SEP_MASK (0xf << 16)
  172. #define XN_FLAG_COMPAT 0 // Traditional SSLeay: use old X509_NAME_print
  173. #define XN_FLAG_SEP_COMMA_PLUS (1 << 16) // RFC 2253 ,+
  174. #define XN_FLAG_SEP_CPLUS_SPC (2 << 16) // ,+ spaced: more readable
  175. #define XN_FLAG_SEP_SPLUS_SPC (3 << 16) // ;+ spaced
  176. #define XN_FLAG_SEP_MULTILINE (4 << 16) // One line per field
  177. #define XN_FLAG_DN_REV (1 << 20) // Reverse DN order
  178. // How the field name is shown
  179. #define XN_FLAG_FN_MASK (0x3 << 21)
  180. #define XN_FLAG_FN_SN 0 // Object short name
  181. #define XN_FLAG_FN_LN (1 << 21) // Object long name
  182. #define XN_FLAG_FN_OID (2 << 21) // Always use OIDs
  183. #define XN_FLAG_FN_NONE (3 << 21) // No field names
  184. #define XN_FLAG_SPC_EQ (1 << 23) // Put spaces round '='
  185. // This determines if we dump fields we don't recognise:
  186. // RFC 2253 requires this.
  187. #define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24)
  188. #define XN_FLAG_FN_ALIGN (1 << 25) // Align field names to 20 characters
  189. // Complete set of RFC 2253 flags
  190. #define XN_FLAG_RFC2253 \
  191. (ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | \
  192. XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS)
  193. // readable oneline form
  194. #define XN_FLAG_ONELINE \
  195. (ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | \
  196. XN_FLAG_SPC_EQ | XN_FLAG_FN_SN)
  197. // readable multiline form
  198. #define XN_FLAG_MULTILINE \
  199. (ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | XN_FLAG_SEP_MULTILINE | \
  200. XN_FLAG_SPC_EQ | XN_FLAG_FN_LN | XN_FLAG_FN_ALIGN)
  201. DEFINE_STACK_OF(X509_REVOKED)
  202. DECLARE_STACK_OF(GENERAL_NAMES)
  203. DEFINE_STACK_OF(X509_CRL)
  204. struct private_key_st {
  205. int version;
  206. // The PKCS#8 data types
  207. X509_ALGOR *enc_algor;
  208. ASN1_OCTET_STRING *enc_pkey; // encrypted pub key
  209. // When decrypted, the following will not be NULL
  210. EVP_PKEY *dec_pkey;
  211. // used to encrypt and decrypt
  212. int key_length;
  213. char *key_data;
  214. int key_free; // true if we should auto free key_data
  215. // expanded version of 'enc_algor'
  216. EVP_CIPHER_INFO cipher;
  217. } /* X509_PKEY */;
  218. struct X509_info_st {
  219. X509 *x509;
  220. X509_CRL *crl;
  221. X509_PKEY *x_pkey;
  222. EVP_CIPHER_INFO enc_cipher;
  223. int enc_len;
  224. char *enc_data;
  225. } /* X509_INFO */;
  226. DEFINE_STACK_OF(X509_INFO)
  227. // The next 2 structures and their 8 routines were sent to me by
  228. // Pat Richard <patr@x509.com> and are used to manipulate
  229. // Netscapes spki structures - useful if you are writing a CA web page
  230. struct Netscape_spkac_st {
  231. X509_PUBKEY *pubkey;
  232. ASN1_IA5STRING *challenge; // challenge sent in atlas >= PR2
  233. } /* NETSCAPE_SPKAC */;
  234. struct Netscape_spki_st {
  235. NETSCAPE_SPKAC *spkac; // signed public key and challenge
  236. X509_ALGOR *sig_algor;
  237. ASN1_BIT_STRING *signature;
  238. } /* NETSCAPE_SPKI */;
  239. // TODO(davidben): Document remaining functions, reorganize them, and define
  240. // supported patterns for using |X509| objects in general. In particular, when
  241. // it is safe to call mutating functions is a little tricky due to various
  242. // internal caches.
  243. // X509_VERSION_* are X.509 version numbers. Note the numerical values of all
  244. // defined X.509 versions are one less than the named version.
  245. #define X509_VERSION_1 0
  246. #define X509_VERSION_2 1
  247. #define X509_VERSION_3 2
  248. // X509_get_version returns the numerical value of |x509|'s version, which will
  249. // be one of the |X509_VERSION_*| constants.
  250. OPENSSL_EXPORT long X509_get_version(const X509 *x509);
  251. // X509_set_version sets |x509|'s version to |version|, which should be one of
  252. // the |X509V_VERSION_*| constants. It returns one on success and zero on error.
  253. //
  254. // If unsure, use |X509_VERSION_3|.
  255. OPENSSL_EXPORT int X509_set_version(X509 *x509, long version);
  256. // X509_get0_serialNumber returns |x509|'s serial number.
  257. OPENSSL_EXPORT const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x509);
  258. // X509_set_serialNumber sets |x509|'s serial number to |serial|. It returns one
  259. // on success and zero on error.
  260. OPENSSL_EXPORT int X509_set_serialNumber(X509 *x509,
  261. const ASN1_INTEGER *serial);
  262. // X509_get0_notBefore returns |x509|'s notBefore time.
  263. OPENSSL_EXPORT const ASN1_TIME *X509_get0_notBefore(const X509 *x509);
  264. // X509_get0_notAfter returns |x509|'s notAfter time.
  265. OPENSSL_EXPORT const ASN1_TIME *X509_get0_notAfter(const X509 *x509);
  266. // X509_set1_notBefore sets |x509|'s notBefore time to |tm|. It returns one on
  267. // success and zero on error.
  268. OPENSSL_EXPORT int X509_set1_notBefore(X509 *x509, const ASN1_TIME *tm);
  269. // X509_set1_notAfter sets |x509|'s notAfter time to |tm|. it returns one on
  270. // success and zero on error.
  271. OPENSSL_EXPORT int X509_set1_notAfter(X509 *x509, const ASN1_TIME *tm);
  272. // X509_getm_notBefore returns a mutable pointer to |x509|'s notBefore time.
  273. OPENSSL_EXPORT ASN1_TIME *X509_getm_notBefore(X509 *x509);
  274. // X509_getm_notAfter returns a mutable pointer to |x509|'s notAfter time.
  275. OPENSSL_EXPORT ASN1_TIME *X509_getm_notAfter(X509 *x);
  276. // X509_get_notBefore returns |x509|'s notBefore time. Note this function is not
  277. // const-correct for legacy reasons. Use |X509_get0_notBefore| or
  278. // |X509_getm_notBefore| instead.
  279. OPENSSL_EXPORT ASN1_TIME *X509_get_notBefore(const X509 *x509);
  280. // X509_get_notAfter returns |x509|'s notAfter time. Note this function is not
  281. // const-correct for legacy reasons. Use |X509_get0_notAfter| or
  282. // |X509_getm_notAfter| instead.
  283. OPENSSL_EXPORT ASN1_TIME *X509_get_notAfter(const X509 *x509);
  284. // X509_set_notBefore calls |X509_set1_notBefore|. Use |X509_set1_notBefore|
  285. // instead.
  286. OPENSSL_EXPORT int X509_set_notBefore(X509 *x509, const ASN1_TIME *tm);
  287. // X509_set_notAfter calls |X509_set1_notAfter|. Use |X509_set1_notAfter|
  288. // instead.
  289. OPENSSL_EXPORT int X509_set_notAfter(X509 *x509, const ASN1_TIME *tm);
  290. // X509_get0_uids sets |*out_issuer_uid| to a non-owning pointer to the
  291. // issuerUID field of |x509|, or NULL if |x509| has no issuerUID. It similarly
  292. // outputs |x509|'s subjectUID field to |*out_subject_uid|.
  293. //
  294. // Callers may pass NULL to either |out_issuer_uid| or |out_subject_uid| to
  295. // ignore the corresponding field.
  296. OPENSSL_EXPORT void X509_get0_uids(const X509 *x509,
  297. const ASN1_BIT_STRING **out_issuer_uid,
  298. const ASN1_BIT_STRING **out_subject_uid);
  299. // X509_extract_key is a legacy alias to |X509_get_pubkey|. Use
  300. // |X509_get_pubkey| instead.
  301. #define X509_extract_key(x) X509_get_pubkey(x)
  302. // X509_get_pathlen returns path length constraint from the basic constraints
  303. // extension in |x509|. (See RFC 5280, section 4.2.1.9.) It returns -1 if the
  304. // constraint is not present, or if some extension in |x509| was invalid.
  305. //
  306. // Note that decoding an |X509| object will not check for invalid extensions. To
  307. // detect the error case, call |X509_get_extensions_flags| and check the
  308. // |EXFLAG_INVALID| bit.
  309. OPENSSL_EXPORT long X509_get_pathlen(X509 *x509);
  310. // X509_REQ_VERSION_1 is the version constant for |X509_REQ| objects. No other
  311. // versions are defined.
  312. #define X509_REQ_VERSION_1 0
  313. // X509_REQ_get_version returns the numerical value of |req|'s version. This
  314. // will always be |X509_REQ_VERSION_1|.
  315. OPENSSL_EXPORT long X509_REQ_get_version(const X509_REQ *req);
  316. // X509_REQ_get_subject_name returns |req|'s subject name. Note this function is
  317. // not const-correct for legacy reasons.
  318. OPENSSL_EXPORT X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req);
  319. // X509_REQ_extract_key is a legacy alias for |X509_REQ_get_pubkey|.
  320. #define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
  321. // X509_name_cmp is a legacy alias for |X509_NAME_cmp|.
  322. #define X509_name_cmp(a, b) X509_NAME_cmp((a), (b))
  323. #define X509_CRL_VERSION_1 0
  324. #define X509_CRL_VERSION_2 1
  325. // X509_CRL_get_version returns the numerical value of |crl|'s version, which
  326. // will be one of the |X509_CRL_VERSION_*| constants.
  327. OPENSSL_EXPORT long X509_CRL_get_version(const X509_CRL *crl);
  328. // X509_CRL_get0_lastUpdate returns |crl|'s lastUpdate time.
  329. OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl);
  330. // X509_CRL_get0_nextUpdate returns |crl|'s nextUpdate time, or NULL if |crl|
  331. // has none.
  332. OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl);
  333. // X509_CRL_set1_lastUpdate sets |crl|'s lastUpdate time to |tm|. It returns one
  334. // on success and zero on error.
  335. OPENSSL_EXPORT int X509_CRL_set1_lastUpdate(X509_CRL *crl, const ASN1_TIME *tm);
  336. // X509_CRL_set1_nextUpdate sets |crl|'s nextUpdate time to |tm|. It returns one
  337. // on success and zero on error.
  338. OPENSSL_EXPORT int X509_CRL_set1_nextUpdate(X509_CRL *crl, const ASN1_TIME *tm);
  339. // The following symbols are deprecated aliases to |X509_CRL_set1_*|.
  340. #define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate
  341. #define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate
  342. // X509_CRL_get_lastUpdate returns a mutable pointer to |crl|'s lastUpdate time.
  343. // Use |X509_CRL_get0_lastUpdate| or |X509_CRL_set1_lastUpdate| instead.
  344. OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl);
  345. // X509_CRL_get_nextUpdate returns a mutable pointer to |crl|'s nextUpdate time,
  346. // or NULL if |crl| has none. Use |X509_CRL_get0_nextUpdate| or
  347. // |X509_CRL_set1_nextUpdate| instead.
  348. OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl);
  349. // X509_CRL_get_issuer returns |crl|'s issuer name. Note this function is not
  350. // const-correct for legacy reasons.
  351. OPENSSL_EXPORT X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl);
  352. // X509_CRL_get_REVOKED returns the list of revoked certificates in |crl|, or
  353. // NULL if |crl| omits it.
  354. //
  355. // TOOD(davidben): This function was originally a macro, without clear const
  356. // semantics. It should take a const input and give const output, but the latter
  357. // would break existing callers. For now, we match upstream.
  358. OPENSSL_EXPORT STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl);
  359. // X509_CRL_get0_extensions returns |crl|'s extension list, or NULL if |crl|
  360. // omits it.
  361. OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(
  362. const X509_CRL *crl);
  363. // X509_SIG_get0 sets |*out_alg| and |*out_digest| to non-owning pointers to
  364. // |sig|'s algorithm and digest fields, respectively. Either |out_alg| and
  365. // |out_digest| may be NULL to skip those fields.
  366. OPENSSL_EXPORT void X509_SIG_get0(const X509_SIG *sig,
  367. const X509_ALGOR **out_alg,
  368. const ASN1_OCTET_STRING **out_digest);
  369. // X509_SIG_getm behaves like |X509_SIG_get0| but returns mutable pointers.
  370. OPENSSL_EXPORT void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **out_alg,
  371. ASN1_OCTET_STRING **out_digest);
  372. // X509_get_X509_PUBKEY returns the public key of |x509|. Note this function is
  373. // not const-correct for legacy reasons. Callers should not modify the returned
  374. // object.
  375. OPENSSL_EXPORT X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x509);
  376. // X509_verify_cert_error_string returns |err| as a human-readable string, where
  377. // |err| should be one of the |X509_V_*| values. If |err| is unknown, it returns
  378. // a default description.
  379. OPENSSL_EXPORT const char *X509_verify_cert_error_string(long err);
  380. // X509_verify checks that |x509| has a valid signature by |pkey|. It returns
  381. // one if the signature is valid and zero otherwise. Note this function only
  382. // checks the signature itself and does not perform a full certificate
  383. // validation.
  384. OPENSSL_EXPORT int X509_verify(X509 *x509, EVP_PKEY *pkey);
  385. // X509_REQ_verify checks that |req| has a valid signature by |pkey|. It returns
  386. // one if the signature is valid and zero otherwise.
  387. OPENSSL_EXPORT int X509_REQ_verify(X509_REQ *req, EVP_PKEY *pkey);
  388. // X509_CRL_verify checks that |crl| has a valid signature by |pkey|. It returns
  389. // one if the signature is valid and zero otherwise.
  390. OPENSSL_EXPORT int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *pkey);
  391. // NETSCAPE_SPKI_verify checks that |spki| has a valid signature by |pkey|. It
  392. // returns one if the signature is valid and zero otherwise.
  393. OPENSSL_EXPORT int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *spki, EVP_PKEY *pkey);
  394. // NETSCAPE_SPKI_b64_decode decodes |len| bytes from |str| as a base64-encoded
  395. // Netscape signed public key and challenge (SPKAC) structure. It returns a
  396. // newly-allocated |NETSCAPE_SPKI| structure with the result, or NULL on error.
  397. // If |len| is 0 or negative, the length is calculated with |strlen| and |str|
  398. // must be a NUL-terminated C string.
  399. OPENSSL_EXPORT NETSCAPE_SPKI *NETSCAPE_SPKI_b64_decode(const char *str,
  400. int len);
  401. // NETSCAPE_SPKI_b64_encode encodes |spki| as a base64-encoded Netscape signed
  402. // public key and challenge (SPKAC) structure. It returns a newly-allocated
  403. // NUL-terminated C string with the result, or NULL on error. The caller must
  404. // release the memory with |OPENSSL_free| when done.
  405. OPENSSL_EXPORT char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki);
  406. // NETSCAPE_SPKI_get_pubkey decodes and returns the public key in |spki| as an
  407. // |EVP_PKEY|, or NULL on error. The caller takes ownership of the resulting
  408. // pointer and must call |EVP_PKEY_free| when done.
  409. OPENSSL_EXPORT EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *spki);
  410. // NETSCAPE_SPKI_set_pubkey sets |spki|'s public key to |pkey|. It returns one
  411. // on success or zero on error. This function does not take ownership of |pkey|,
  412. // so the caller may continue to manage its lifetime independently of |spki|.
  413. OPENSSL_EXPORT int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *spki,
  414. EVP_PKEY *pkey);
  415. // X509_signature_dump writes a human-readable representation of |sig| to |bio|,
  416. // indented with |indent| spaces. It returns one on success and zero on error.
  417. OPENSSL_EXPORT int X509_signature_dump(BIO *bio, const ASN1_STRING *sig,
  418. int indent);
  419. // X509_signature_print writes a human-readable representation of |alg| and
  420. // |sig| to |bio|. It returns one on success and zero on error.
  421. OPENSSL_EXPORT int X509_signature_print(BIO *bio, const X509_ALGOR *alg,
  422. const ASN1_STRING *sig);
  423. // X509_sign signs |x509| with |pkey| and replaces the signature algorithm and
  424. // signature fields. It returns one on success and zero on error. This function
  425. // uses digest algorithm |md|, or |pkey|'s default if NULL. Other signing
  426. // parameters use |pkey|'s defaults. To customize them, use |X509_sign_ctx|.
  427. OPENSSL_EXPORT int X509_sign(X509 *x509, EVP_PKEY *pkey, const EVP_MD *md);
  428. // X509_sign_ctx signs |x509| with |ctx| and replaces the signature algorithm
  429. // and signature fields. It returns one on success and zero on error. The
  430. // signature algorithm and parameters come from |ctx|, which must have been
  431. // initialized with |EVP_DigestSignInit|. The caller should configure the
  432. // corresponding |EVP_PKEY_CTX| before calling this function.
  433. OPENSSL_EXPORT int X509_sign_ctx(X509 *x509, EVP_MD_CTX *ctx);
  434. // X509_REQ_sign signs |req| with |pkey| and replaces the signature algorithm
  435. // and signature fields. It returns one on success and zero on error. This
  436. // function uses digest algorithm |md|, or |pkey|'s default if NULL. Other
  437. // signing parameters use |pkey|'s defaults. To customize them, use
  438. // |X509_REQ_sign_ctx|.
  439. OPENSSL_EXPORT int X509_REQ_sign(X509_REQ *req, EVP_PKEY *pkey,
  440. const EVP_MD *md);
  441. // X509_REQ_sign_ctx signs |req| with |ctx| and replaces the signature algorithm
  442. // and signature fields. It returns one on success and zero on error. The
  443. // signature algorithm and parameters come from |ctx|, which must have been
  444. // initialized with |EVP_DigestSignInit|. The caller should configure the
  445. // corresponding |EVP_PKEY_CTX| before calling this function.
  446. OPENSSL_EXPORT int X509_REQ_sign_ctx(X509_REQ *req, EVP_MD_CTX *ctx);
  447. // X509_CRL_sign signs |crl| with |pkey| and replaces the signature algorithm
  448. // and signature fields. It returns one on success and zero on error. This
  449. // function uses digest algorithm |md|, or |pkey|'s default if NULL. Other
  450. // signing parameters use |pkey|'s defaults. To customize them, use
  451. // |X509_CRL_sign_ctx|.
  452. OPENSSL_EXPORT int X509_CRL_sign(X509_CRL *crl, EVP_PKEY *pkey,
  453. const EVP_MD *md);
  454. // X509_CRL_sign_ctx signs |crl| with |ctx| and replaces the signature algorithm
  455. // and signature fields. It returns one on success and zero on error. The
  456. // signature algorithm and parameters come from |ctx|, which must have been
  457. // initialized with |EVP_DigestSignInit|. The caller should configure the
  458. // corresponding |EVP_PKEY_CTX| before calling this function.
  459. OPENSSL_EXPORT int X509_CRL_sign_ctx(X509_CRL *crl, EVP_MD_CTX *ctx);
  460. // NETSCAPE_SPKI_sign signs |spki| with |pkey| and replaces the signature
  461. // algorithm and signature fields. It returns one on success and zero on error.
  462. // This function uses digest algorithm |md|, or |pkey|'s default if NULL. Other
  463. // signing parameters use |pkey|'s defaults.
  464. OPENSSL_EXPORT int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *spki, EVP_PKEY *pkey,
  465. const EVP_MD *md);
  466. // X509_pubkey_digest hashes the DER encoding of |x509|'s subjectPublicKeyInfo
  467. // field with |md| and writes the result to |out|. |EVP_MD_CTX_size| bytes are
  468. // written, which is at most |EVP_MAX_MD_SIZE|. If |out_len| is not NULL,
  469. // |*out_len| is set to the number of bytes written. This function returns one
  470. // on success and zero on error.
  471. OPENSSL_EXPORT int X509_pubkey_digest(const X509 *x509, const EVP_MD *md,
  472. uint8_t *out, unsigned *out_len);
  473. // X509_digest hashes |x509|'s DER encoding with |md| and writes the result to
  474. // |out|. |EVP_MD_CTX_size| bytes are written, which is at most
  475. // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number
  476. // of bytes written. This function returns one on success and zero on error.
  477. // Note this digest covers the entire certificate, not just the signed portion.
  478. OPENSSL_EXPORT int X509_digest(const X509 *x509, const EVP_MD *md, uint8_t *out,
  479. unsigned *out_len);
  480. // X509_CRL_digest hashes |crl|'s DER encoding with |md| and writes the result
  481. // to |out|. |EVP_MD_CTX_size| bytes are written, which is at most
  482. // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number
  483. // of bytes written. This function returns one on success and zero on error.
  484. // Note this digest covers the entire CRL, not just the signed portion.
  485. OPENSSL_EXPORT int X509_CRL_digest(const X509_CRL *crl, const EVP_MD *md,
  486. uint8_t *out, unsigned *out_len);
  487. // X509_REQ_digest hashes |req|'s DER encoding with |md| and writes the result
  488. // to |out|. |EVP_MD_CTX_size| bytes are written, which is at most
  489. // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number
  490. // of bytes written. This function returns one on success and zero on error.
  491. // Note this digest covers the entire certificate request, not just the signed
  492. // portion.
  493. OPENSSL_EXPORT int X509_REQ_digest(const X509_REQ *req, const EVP_MD *md,
  494. uint8_t *out, unsigned *out_len);
  495. // X509_NAME_digest hashes |name|'s DER encoding with |md| and writes the result
  496. // to |out|. |EVP_MD_CTX_size| bytes are written, which is at most
  497. // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number
  498. // of bytes written. This function returns one on success and zero on error.
  499. OPENSSL_EXPORT int X509_NAME_digest(const X509_NAME *name, const EVP_MD *md,
  500. uint8_t *out, unsigned *out_len);
  501. // X509_parse_from_buffer parses an X.509 structure from |buf| and returns a
  502. // fresh X509 or NULL on error. There must not be any trailing data in |buf|.
  503. // The returned structure (if any) holds a reference to |buf| rather than
  504. // copying parts of it as a normal |d2i_X509| call would do.
  505. OPENSSL_EXPORT X509 *X509_parse_from_buffer(CRYPTO_BUFFER *buf);
  506. OPENSSL_EXPORT X509 *d2i_X509_fp(FILE *fp, X509 **x509);
  507. OPENSSL_EXPORT int i2d_X509_fp(FILE *fp, X509 *x509);
  508. OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl);
  509. OPENSSL_EXPORT int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl);
  510. OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req);
  511. OPENSSL_EXPORT int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req);
  512. OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa);
  513. OPENSSL_EXPORT int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa);
  514. OPENSSL_EXPORT RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa);
  515. OPENSSL_EXPORT int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa);
  516. OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa);
  517. OPENSSL_EXPORT int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa);
  518. #ifndef OPENSSL_NO_DSA
  519. OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
  520. OPENSSL_EXPORT int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
  521. OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
  522. OPENSSL_EXPORT int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
  523. #endif
  524. OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey);
  525. OPENSSL_EXPORT int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey);
  526. OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey);
  527. OPENSSL_EXPORT int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey);
  528. OPENSSL_EXPORT X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8);
  529. OPENSSL_EXPORT int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8);
  530. OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(
  531. FILE *fp, PKCS8_PRIV_KEY_INFO **p8inf);
  532. OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
  533. PKCS8_PRIV_KEY_INFO *p8inf);
  534. OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
  535. OPENSSL_EXPORT int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
  536. OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
  537. OPENSSL_EXPORT int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey);
  538. OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a);
  539. OPENSSL_EXPORT X509 *d2i_X509_bio(BIO *bp, X509 **x509);
  540. OPENSSL_EXPORT int i2d_X509_bio(BIO *bp, X509 *x509);
  541. OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl);
  542. OPENSSL_EXPORT int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl);
  543. OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req);
  544. OPENSSL_EXPORT int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req);
  545. OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa);
  546. OPENSSL_EXPORT int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa);
  547. OPENSSL_EXPORT RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa);
  548. OPENSSL_EXPORT int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa);
  549. OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa);
  550. OPENSSL_EXPORT int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa);
  551. #ifndef OPENSSL_NO_DSA
  552. OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
  553. OPENSSL_EXPORT int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
  554. OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
  555. OPENSSL_EXPORT int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
  556. #endif
  557. OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey);
  558. OPENSSL_EXPORT int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey);
  559. OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey);
  560. OPENSSL_EXPORT int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey);
  561. OPENSSL_EXPORT X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8);
  562. OPENSSL_EXPORT int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8);
  563. OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(
  564. BIO *bp, PKCS8_PRIV_KEY_INFO **p8inf);
  565. OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
  566. PKCS8_PRIV_KEY_INFO *p8inf);
  567. OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
  568. OPENSSL_EXPORT int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
  569. OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
  570. OPENSSL_EXPORT int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);
  571. OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);
  572. OPENSSL_EXPORT DH *d2i_DHparams_bio(BIO *bp, DH **dh);
  573. OPENSSL_EXPORT int i2d_DHparams_bio(BIO *bp, const DH *dh);
  574. OPENSSL_EXPORT X509 *X509_dup(X509 *x509);
  575. OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
  576. OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
  577. OPENSSL_EXPORT X509_CRL *X509_CRL_dup(X509_CRL *crl);
  578. OPENSSL_EXPORT X509_REVOKED *X509_REVOKED_dup(X509_REVOKED *rev);
  579. OPENSSL_EXPORT X509_REQ *X509_REQ_dup(X509_REQ *req);
  580. OPENSSL_EXPORT X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
  581. // X509_ALGOR_set0 sets |alg| to an AlgorithmIdentifier with algorithm |obj| and
  582. // parameter determined by |param_type| and |param_value|. It returns one on
  583. // success and zero on error. This function takes ownership of |obj| and
  584. // |param_value| on success.
  585. //
  586. // If |param_type| is |V_ASN1_UNDEF|, the parameter is omitted. If |param_type|
  587. // is zero, the parameter is left unchanged. Otherwise, |param_type| and
  588. // |param_value| are interpreted as in |ASN1_TYPE_set|.
  589. //
  590. // Note omitting the parameter (|V_ASN1_UNDEF|) and encoding an explicit NULL
  591. // value (|V_ASN1_NULL|) are different. Some algorithms require one and some the
  592. // other. Consult the relevant specification before calling this function. The
  593. // correct parameter for an RSASSA-PKCS1-v1_5 signature is |V_ASN1_NULL|. The
  594. // correct one for an ECDSA or Ed25519 signature is |V_ASN1_UNDEF|.
  595. OPENSSL_EXPORT int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *obj,
  596. int param_type, void *param_value);
  597. // X509_ALGOR_get0 sets |*out_obj| to the |alg|'s algorithm. If |alg|'s
  598. // parameter is omitted, it sets |*out_param_type| and |*out_param_value| to
  599. // |V_ASN1_UNDEF| and NULL. Otherwise, it sets |*out_param_type| and
  600. // |*out_param_value| to the parameter, using the same representation as
  601. // |ASN1_TYPE_set0|. See |ASN1_TYPE_set0| and |ASN1_TYPE| for details.
  602. //
  603. // Callers that require the parameter in serialized form should, after checking
  604. // for |V_ASN1_UNDEF|, use |ASN1_TYPE_set1| and |d2i_ASN1_TYPE|, rather than
  605. // inspecting |*out_param_value|.
  606. //
  607. // Each of |out_obj|, |out_param_type|, and |out_param_value| may be NULL to
  608. // ignore the output. If |out_param_type| is NULL, |out_param_value| is ignored.
  609. //
  610. // WARNING: If |*out_param_type| is set to |V_ASN1_UNDEF|, OpenSSL and older
  611. // revisions of BoringSSL leave |*out_param_value| unset rather than setting it
  612. // to NULL. Callers that support both OpenSSL and BoringSSL should not assume
  613. // |*out_param_value| is uniformly initialized.
  614. OPENSSL_EXPORT void X509_ALGOR_get0(const ASN1_OBJECT **out_obj,
  615. int *out_param_type,
  616. const void **out_param_value,
  617. const X509_ALGOR *alg);
  618. // X509_ALGOR_set_md sets |alg| to the hash function |md|. Note this
  619. // AlgorithmIdentifier represents the hash function itself, not a signature
  620. // algorithm that uses |md|.
  621. OPENSSL_EXPORT void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md);
  622. // X509_ALGOR_cmp returns zero if |a| and |b| are equal, and some non-zero value
  623. // otherwise. Note this function can only be used for equality checks, not an
  624. // ordering.
  625. OPENSSL_EXPORT int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b);
  626. OPENSSL_EXPORT X509_NAME *X509_NAME_dup(X509_NAME *xn);
  627. OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
  628. OPENSSL_EXPORT int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne);
  629. OPENSSL_EXPORT int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder,
  630. size_t *pderlen);
  631. // X509_cmp_time compares |s| against |*t|. On success, it returns a negative
  632. // number if |s| <= |*t| and a positive number if |s| > |*t|. On error, it
  633. // returns zero. If |t| is NULL, it uses the current time instead of |*t|.
  634. //
  635. // WARNING: Unlike most comparison functions, this function returns zero on
  636. // error, not equality.
  637. OPENSSL_EXPORT int X509_cmp_time(const ASN1_TIME *s, time_t *t);
  638. // X509_cmp_current_time behaves like |X509_cmp_time| but compares |s| against
  639. // the current time.
  640. OPENSSL_EXPORT int X509_cmp_current_time(const ASN1_TIME *s);
  641. // X509_time_adj calls |X509_time_adj_ex| with |offset_day| equal to zero.
  642. OPENSSL_EXPORT ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec,
  643. time_t *t);
  644. // X509_time_adj_ex behaves like |ASN1_TIME_adj|, but adds an offset to |*t|. If
  645. // |t| is NULL, it uses the current time instead of |*t|.
  646. OPENSSL_EXPORT ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, int offset_day,
  647. long offset_sec, time_t *t);
  648. // X509_gmtime_adj behaves like |X509_time_adj_ex| but adds |offset_sec| to the
  649. // current time.
  650. OPENSSL_EXPORT ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long offset_sec);
  651. OPENSSL_EXPORT const char *X509_get_default_cert_area(void);
  652. OPENSSL_EXPORT const char *X509_get_default_cert_dir(void);
  653. OPENSSL_EXPORT const char *X509_get_default_cert_file(void);
  654. OPENSSL_EXPORT const char *X509_get_default_cert_dir_env(void);
  655. OPENSSL_EXPORT const char *X509_get_default_cert_file_env(void);
  656. OPENSSL_EXPORT const char *X509_get_default_private_dir(void);
  657. DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS)
  658. DECLARE_ASN1_FUNCTIONS(X509_PUBKEY)
  659. // X509_PUBKEY_set serializes |pkey| into a newly-allocated |X509_PUBKEY|
  660. // structure. On success, it frees |*x|, sets |*x| to the new object, and
  661. // returns one. Otherwise, it returns zero.
  662. OPENSSL_EXPORT int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
  663. // X509_PUBKEY_get decodes the public key in |key| and returns an |EVP_PKEY| on
  664. // success, or NULL on error. The caller must release the result with
  665. // |EVP_PKEY_free| when done. The |EVP_PKEY| is cached in |key|, so callers must
  666. // not mutate the result.
  667. OPENSSL_EXPORT EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key);
  668. DECLARE_ASN1_FUNCTIONS(X509_SIG)
  669. DECLARE_ASN1_FUNCTIONS(X509_REQ)
  670. DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE)
  671. // X509_ATTRIBUTE_create returns a newly-allocated |X509_ATTRIBUTE|, or NULL on
  672. // error. The attribute has type |nid| and contains a single value determined by
  673. // |attrtype| and |value|, which are interpreted as in |ASN1_TYPE_set|. Note
  674. // this function takes ownership of |value|.
  675. OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int attrtype,
  676. void *value);
  677. DECLARE_ASN1_FUNCTIONS(X509_EXTENSION)
  678. DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
  679. DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY)
  680. DECLARE_ASN1_FUNCTIONS(X509_NAME)
  681. // X509_NAME_set makes a copy of |name|. On success, it frees |*xn|, sets |*xn|
  682. // to the copy, and returns one. Otherwise, it returns zero.
  683. OPENSSL_EXPORT int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
  684. DECLARE_ASN1_FUNCTIONS(X509)
  685. // X509_up_ref adds one to the reference count of |x509| and returns one.
  686. OPENSSL_EXPORT int X509_up_ref(X509 *x509);
  687. OPENSSL_EXPORT int X509_get_ex_new_index(long argl, void *argp,
  688. CRYPTO_EX_unused *unused,
  689. CRYPTO_EX_dup *dup_unused,
  690. CRYPTO_EX_free *free_func);
  691. OPENSSL_EXPORT int X509_set_ex_data(X509 *r, int idx, void *arg);
  692. OPENSSL_EXPORT void *X509_get_ex_data(X509 *r, int idx);
  693. // i2d_re_X509_tbs serializes the TBSCertificate portion of |x509|, as described
  694. // in |i2d_SAMPLE|.
  695. //
  696. // This function re-encodes the TBSCertificate and may not reflect |x509|'s
  697. // original encoding. It may be used to manually generate a signature for a new
  698. // certificate. To verify certificates, use |i2d_X509_tbs| instead.
  699. OPENSSL_EXPORT int i2d_re_X509_tbs(X509 *x509, unsigned char **outp);
  700. // i2d_X509_tbs serializes the TBSCertificate portion of |x509|, as described in
  701. // |i2d_SAMPLE|.
  702. //
  703. // This function preserves the original encoding of the TBSCertificate and may
  704. // not reflect modifications made to |x509|. It may be used to manually verify
  705. // the signature of an existing certificate. To generate certificates, use
  706. // |i2d_re_X509_tbs| instead.
  707. OPENSSL_EXPORT int i2d_X509_tbs(X509 *x509, unsigned char **outp);
  708. // X509_set1_signature_algo sets |x509|'s signature algorithm to |algo| and
  709. // returns one on success or zero on error. It updates both the signature field
  710. // of the TBSCertificate structure, and the signatureAlgorithm field of the
  711. // Certificate.
  712. OPENSSL_EXPORT int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo);
  713. // X509_set1_signature_value sets |x509|'s signature to a copy of the |sig_len|
  714. // bytes pointed by |sig|. It returns one on success and zero on error.
  715. //
  716. // Due to a specification error, X.509 certificates store signatures in ASN.1
  717. // BIT STRINGs, but signature algorithms return byte strings rather than bit
  718. // strings. This function creates a BIT STRING containing a whole number of
  719. // bytes, with the bit order matching the DER encoding. This matches the
  720. // encoding used by all X.509 signature algorithms.
  721. OPENSSL_EXPORT int X509_set1_signature_value(X509 *x509, const uint8_t *sig,
  722. size_t sig_len);
  723. // X509_get0_signature sets |*out_sig| and |*out_alg| to the signature and
  724. // signature algorithm of |x509|, respectively. Either output pointer may be
  725. // NULL to ignore the value.
  726. //
  727. // This function outputs the outer signature algorithm. For the one in the
  728. // TBSCertificate, see |X509_get0_tbs_sigalg|. Certificates with mismatched
  729. // signature algorithms will successfully parse, but they will be rejected when
  730. // verifying.
  731. OPENSSL_EXPORT void X509_get0_signature(const ASN1_BIT_STRING **out_sig,
  732. const X509_ALGOR **out_alg,
  733. const X509 *x509);
  734. // X509_get_signature_nid returns the NID corresponding to |x509|'s signature
  735. // algorithm, or |NID_undef| if the signature algorithm does not correspond to
  736. // a known NID.
  737. OPENSSL_EXPORT int X509_get_signature_nid(const X509 *x509);
  738. // Auxiliary properties.
  739. //
  740. // |X509| objects optionally maintain auxiliary properties. These are not part
  741. // of the certificates themselves, and thus are not covered by signatures or
  742. // preserved by the standard serialization. They are used as inputs or outputs
  743. // to other functions in this library.
  744. // i2d_X509_AUX marshals |x509| as a DER-encoded X.509 Certificate (RFC 5280),
  745. // followed optionally by a separate, OpenSSL-specific structure with auxiliary
  746. // properties. It behaves as described in |i2d_SAMPLE|.
  747. //
  748. // Unlike similarly-named functions, this function does not output a single
  749. // ASN.1 element. Directly embedding the output in a larger ASN.1 structure will
  750. // not behave correctly.
  751. OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, unsigned char **outp);
  752. // d2i_X509_AUX parses up to |length| bytes from |*inp| as a DER-encoded X.509
  753. // Certificate (RFC 5280), followed optionally by a separate, OpenSSL-specific
  754. // structure with auxiliary properties. It behaves as described in
  755. // |d2i_SAMPLE_with_reuse|.
  756. //
  757. // Some auxiliary properties affect trust decisions, so this function should not
  758. // be used with untrusted input.
  759. //
  760. // Unlike similarly-named functions, this function does not parse a single
  761. // ASN.1 element. Trying to parse data directly embedded in a larger ASN.1
  762. // structure will not behave correctly.
  763. OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const unsigned char **inp,
  764. long length);
  765. // X509_alias_set1 sets |x509|'s alias to |len| bytes from |name|. If |name| is
  766. // NULL, the alias is cleared instead. Aliases are not part of the certificate
  767. // itself and will not be serialized by |i2d_X509|.
  768. OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const unsigned char *name,
  769. int len);
  770. // X509_keyid_set1 sets |x509|'s key ID to |len| bytes from |id|. If |id| is
  771. // NULL, the key ID is cleared instead. Key IDs are not part of the certificate
  772. // itself and will not be serialized by |i2d_X509|.
  773. OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const unsigned char *id,
  774. int len);
  775. // X509_alias_get0 looks up |x509|'s alias. If found, it sets |*out_len| to the
  776. // alias's length and returns a pointer to a buffer containing the contents. If
  777. // not found, it outputs the empty string by returning NULL and setting
  778. // |*out_len| to zero.
  779. //
  780. // If |x509| was parsed from a PKCS#12 structure (see
  781. // |PKCS12_get_key_and_certs|), the alias will reflect the friendlyName
  782. // attribute (RFC 2985).
  783. //
  784. // WARNING: In OpenSSL, this function did not set |*out_len| when the alias was
  785. // missing. Callers that target both OpenSSL and BoringSSL should set the value
  786. // to zero before calling this function.
  787. OPENSSL_EXPORT unsigned char *X509_alias_get0(X509 *x509, int *out_len);
  788. // X509_keyid_get0 looks up |x509|'s key ID. If found, it sets |*out_len| to the
  789. // key ID's length and returns a pointer to a buffer containing the contents. If
  790. // not found, it outputs the empty string by returning NULL and setting
  791. // |*out_len| to zero.
  792. //
  793. // WARNING: In OpenSSL, this function did not set |*out_len| when the alias was
  794. // missing. Callers that target both OpenSSL and BoringSSL should set the value
  795. // to zero before calling this function.
  796. OPENSSL_EXPORT unsigned char *X509_keyid_get0(X509 *x509, int *out_len);
  797. OPENSSL_EXPORT int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
  798. OPENSSL_EXPORT int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
  799. OPENSSL_EXPORT void X509_trust_clear(X509 *x);
  800. OPENSSL_EXPORT void X509_reject_clear(X509 *x);
  801. OPENSSL_EXPORT int X509_TRUST_set(int *t, int trust);
  802. DECLARE_ASN1_FUNCTIONS(X509_REVOKED)
  803. DECLARE_ASN1_FUNCTIONS(X509_CRL)
  804. OPENSSL_EXPORT int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
  805. OPENSSL_EXPORT int X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **ret,
  806. ASN1_INTEGER *serial);
  807. OPENSSL_EXPORT int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret,
  808. X509 *x);
  809. OPENSSL_EXPORT X509_PKEY *X509_PKEY_new(void);
  810. OPENSSL_EXPORT void X509_PKEY_free(X509_PKEY *a);
  811. DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)
  812. DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
  813. OPENSSL_EXPORT X509_INFO *X509_INFO_new(void);
  814. OPENSSL_EXPORT void X509_INFO_free(X509_INFO *a);
  815. OPENSSL_EXPORT char *X509_NAME_oneline(const X509_NAME *a, char *buf, int size);
  816. OPENSSL_EXPORT int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
  817. unsigned char *md, unsigned int *len);
  818. OPENSSL_EXPORT int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type,
  819. void *data, unsigned char *md,
  820. unsigned int *len);
  821. OPENSSL_EXPORT int ASN1_item_verify(const ASN1_ITEM *it,
  822. const X509_ALGOR *algor1,
  823. const ASN1_BIT_STRING *signature,
  824. void *data, EVP_PKEY *pkey);
  825. OPENSSL_EXPORT int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1,
  826. X509_ALGOR *algor2,
  827. ASN1_BIT_STRING *signature, void *data,
  828. EVP_PKEY *pkey, const EVP_MD *type);
  829. OPENSSL_EXPORT int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1,
  830. X509_ALGOR *algor2,
  831. ASN1_BIT_STRING *signature, void *asn,
  832. EVP_MD_CTX *ctx);
  833. // X509_get_serialNumber returns a mutable pointer to |x509|'s serial number.
  834. // Prefer |X509_get0_serialNumber|.
  835. OPENSSL_EXPORT ASN1_INTEGER *X509_get_serialNumber(X509 *x509);
  836. // X509_set_issuer_name sets |x509|'s issuer to a copy of |name|. It returns one
  837. // on success and zero on error.
  838. OPENSSL_EXPORT int X509_set_issuer_name(X509 *x509, X509_NAME *name);
  839. // X509_get_issuer_name returns |x509|'s issuer.
  840. OPENSSL_EXPORT X509_NAME *X509_get_issuer_name(const X509 *x509);
  841. // X509_set_subject_name sets |x509|'s subject to a copy of |name|. It returns
  842. // one on success and zero on error.
  843. OPENSSL_EXPORT int X509_set_subject_name(X509 *x509, X509_NAME *name);
  844. // X509_get_issuer_name returns |x509|'s subject.
  845. OPENSSL_EXPORT X509_NAME *X509_get_subject_name(const X509 *x509);
  846. // X509_set_pubkey sets |x509|'s public key to |pkey|. It returns one on success
  847. // and zero on error. This function does not take ownership of |pkey| and
  848. // internally copies and updates reference counts as needed.
  849. OPENSSL_EXPORT int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey);
  850. // X509_get_pubkey returns |x509|'s public key as an |EVP_PKEY|, or NULL if the
  851. // public key was unsupported or could not be decoded. This function returns a
  852. // reference to the |EVP_PKEY|. The caller must release the result with
  853. // |EVP_PKEY_free| when done.
  854. OPENSSL_EXPORT EVP_PKEY *X509_get_pubkey(X509 *x509);
  855. // X509_get0_pubkey_bitstr returns the BIT STRING portion of |x509|'s public
  856. // key. Note this does not contain the AlgorithmIdentifier portion.
  857. //
  858. // WARNING: This function returns a non-const pointer for OpenSSL compatibility,
  859. // but the caller must not modify the resulting object. Doing so will break
  860. // internal invariants in |x509|.
  861. OPENSSL_EXPORT ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x509);
  862. // X509_get0_extensions returns |x509|'s extension list, or NULL if |x509| omits
  863. // it.
  864. OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_get0_extensions(
  865. const X509 *x509);
  866. // X509_get0_tbs_sigalg returns the signature algorithm in |x509|'s
  867. // TBSCertificate. For the outer signature algorithm, see |X509_get0_signature|.
  868. //
  869. // Certificates with mismatched signature algorithms will successfully parse,
  870. // but they will be rejected when verifying.
  871. OPENSSL_EXPORT const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x509);
  872. // X509_REQ_set_version sets |req|'s version to |version|, which should be
  873. // |X509_REQ_VERSION_1|. It returns one on success and zero on error.
  874. //
  875. // The only defined CSR version is |X509_REQ_VERSION_1|, so there is no need to
  876. // call this function.
  877. OPENSSL_EXPORT int X509_REQ_set_version(X509_REQ *req, long version);
  878. // X509_REQ_set_subject_name sets |req|'s subject to a copy of |name|. It
  879. // returns one on success and zero on error.
  880. OPENSSL_EXPORT int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name);
  881. // X509_REQ_get0_signature sets |*out_sig| and |*out_alg| to the signature and
  882. // signature algorithm of |req|, respectively. Either output pointer may be NULL
  883. // to ignore the value.
  884. OPENSSL_EXPORT void X509_REQ_get0_signature(const X509_REQ *req,
  885. const ASN1_BIT_STRING **out_sig,
  886. const X509_ALGOR **out_alg);
  887. // X509_REQ_get_signature_nid returns the NID corresponding to |req|'s signature
  888. // algorithm, or |NID_undef| if the signature algorithm does not correspond to
  889. // a known NID.
  890. OPENSSL_EXPORT int X509_REQ_get_signature_nid(const X509_REQ *req);
  891. // i2d_re_X509_REQ_tbs serializes the CertificationRequestInfo (see RFC 2986)
  892. // portion of |req|, as described in |i2d_SAMPLE|.
  893. //
  894. // This function re-encodes the CertificationRequestInfo and may not reflect
  895. // |req|'s original encoding. It may be used to manually generate a signature
  896. // for a new certificate request.
  897. OPENSSL_EXPORT int i2d_re_X509_REQ_tbs(X509_REQ *req, uint8_t **outp);
  898. // X509_REQ_set_pubkey sets |req|'s public key to |pkey|. It returns one on
  899. // success and zero on error. This function does not take ownership of |pkey|
  900. // and internally copies and updates reference counts as needed.
  901. OPENSSL_EXPORT int X509_REQ_set_pubkey(X509_REQ *req, EVP_PKEY *pkey);
  902. // X509_REQ_get_pubkey returns |req|'s public key as an |EVP_PKEY|, or NULL if
  903. // the public key was unsupported or could not be decoded. This function returns
  904. // a reference to the |EVP_PKEY|. The caller must release the result with
  905. // |EVP_PKEY_free| when done.
  906. OPENSSL_EXPORT EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req);
  907. // X509_REQ_extension_nid returns one if |nid| is a supported CSR attribute type
  908. // for carrying extensions and zero otherwise. The supported types are
  909. // |NID_ext_req| (pkcs-9-at-extensionRequest from RFC 2985) and |NID_ms_ext_req|
  910. // (a Microsoft szOID_CERT_EXTENSIONS variant).
  911. OPENSSL_EXPORT int X509_REQ_extension_nid(int nid);
  912. // X509_REQ_get_extensions decodes the list of requested extensions in |req| and
  913. // returns a newly-allocated |STACK_OF(X509_EXTENSION)| containing the result.
  914. // It returns NULL on error, or if |req| did not request extensions.
  915. //
  916. // This function supports both pkcs-9-at-extensionRequest from RFC 2985 and the
  917. // Microsoft szOID_CERT_EXTENSIONS variant.
  918. OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
  919. // X509_REQ_add_extensions_nid adds an attribute to |req| of type |nid|, to
  920. // request the certificate extensions in |exts|. It returns one on success and
  921. // zero on error. |nid| should be |NID_ext_req| or |NID_ms_ext_req|.
  922. OPENSSL_EXPORT int X509_REQ_add_extensions_nid(
  923. X509_REQ *req, const STACK_OF(X509_EXTENSION) *exts, int nid);
  924. // X509_REQ_add_extensions behaves like |X509_REQ_add_extensions_nid|, using the
  925. // standard |NID_ext_req| for the attribute type.
  926. OPENSSL_EXPORT int X509_REQ_add_extensions(
  927. X509_REQ *req, const STACK_OF(X509_EXTENSION) *exts);
  928. // X509_REQ_get_attr_count returns the number of attributes in |req|.
  929. OPENSSL_EXPORT int X509_REQ_get_attr_count(const X509_REQ *req);
  930. // X509_REQ_get_attr_by_NID returns the index of the attribute in |req| of type
  931. // |nid|, or a negative number if not found. If found, callers can use
  932. // |X509_REQ_get_attr| to look up the attribute by index.
  933. //
  934. // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers
  935. // can thus loop over all matching attributes by first passing -1 and then
  936. // passing the previously-returned value until no match is returned.
  937. OPENSSL_EXPORT int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
  938. int lastpos);
  939. // X509_REQ_get_attr_by_OBJ behaves like |X509_REQ_get_attr_by_NID| but looks
  940. // for attributes of type |obj|.
  941. OPENSSL_EXPORT int X509_REQ_get_attr_by_OBJ(const X509_REQ *req,
  942. const ASN1_OBJECT *obj,
  943. int lastpos);
  944. // X509_REQ_get_attr returns the attribute at index |loc| in |req|, or NULL if
  945. // out of bounds.
  946. OPENSSL_EXPORT X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
  947. // X509_REQ_delete_attr removes the attribute at index |loc| in |req|. It
  948. // returns the removed attribute to the caller, or NULL if |loc| was out of
  949. // bounds. If non-NULL, the caller must release the result with
  950. // |X509_ATTRIBUTE_free| when done. It is also safe, but not necessary, to call
  951. // |X509_ATTRIBUTE_free| if the result is NULL.
  952. OPENSSL_EXPORT X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
  953. // X509_REQ_add1_attr appends a copy of |attr| to |req|'s list of attributes. It
  954. // returns one on success and zero on error.
  955. //
  956. // TODO(https://crbug.com/boringssl/407): |attr| should be const.
  957. OPENSSL_EXPORT int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
  958. // X509_REQ_add1_attr_by_OBJ appends a new attribute to |req| with type |obj|.
  959. // It returns one on success and zero on error. The value is determined by
  960. // |X509_ATTRIBUTE_set1_data|.
  961. //
  962. // WARNING: The interpretation of |attrtype|, |data|, and |len| is complex and
  963. // error-prone. See |X509_ATTRIBUTE_set1_data| for details.
  964. OPENSSL_EXPORT int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
  965. const ASN1_OBJECT *obj,
  966. int attrtype,
  967. const unsigned char *data,
  968. int len);
  969. // X509_REQ_add1_attr_by_NID behaves like |X509_REQ_add1_attr_by_OBJ| except the
  970. // attribute type is determined by |nid|.
  971. OPENSSL_EXPORT int X509_REQ_add1_attr_by_NID(X509_REQ *req, int nid,
  972. int attrtype,
  973. const unsigned char *data,
  974. int len);
  975. // X509_REQ_add1_attr_by_txt behaves like |X509_REQ_add1_attr_by_OBJ| except the
  976. // attribute type is determined by calling |OBJ_txt2obj| with |attrname|.
  977. OPENSSL_EXPORT int X509_REQ_add1_attr_by_txt(X509_REQ *req,
  978. const char *attrname, int attrtype,
  979. const unsigned char *data,
  980. int len);
  981. // X509_CRL_set_version sets |crl|'s version to |version|, which should be one
  982. // of the |X509_CRL_VERSION_*| constants. It returns one on success and zero on
  983. // error.
  984. //
  985. // If unsure, use |X509_CRL_VERSION_2|. Note that, unlike certificates, CRL
  986. // versions are only defined up to v2. Callers should not use |X509_VERSION_3|.
  987. OPENSSL_EXPORT int X509_CRL_set_version(X509_CRL *crl, long version);
  988. // X509_CRL_set_issuer_name sets |crl|'s issuer to a copy of |name|. It returns
  989. // one on success and zero on error.
  990. OPENSSL_EXPORT int X509_CRL_set_issuer_name(X509_CRL *crl, X509_NAME *name);
  991. OPENSSL_EXPORT int X509_CRL_sort(X509_CRL *crl);
  992. // X509_CRL_up_ref adds one to the reference count of |crl| and returns one.
  993. OPENSSL_EXPORT int X509_CRL_up_ref(X509_CRL *crl);
  994. // X509_CRL_get0_signature sets |*out_sig| and |*out_alg| to the signature and
  995. // signature algorithm of |crl|, respectively. Either output pointer may be NULL
  996. // to ignore the value.
  997. //
  998. // This function outputs the outer signature algorithm, not the one in the
  999. // TBSCertList. CRLs with mismatched signature algorithms will successfully
  1000. // parse, but they will be rejected when verifying.
  1001. OPENSSL_EXPORT void X509_CRL_get0_signature(const X509_CRL *crl,
  1002. const ASN1_BIT_STRING **out_sig,
  1003. const X509_ALGOR **out_alg);
  1004. // X509_CRL_get_signature_nid returns the NID corresponding to |crl|'s signature
  1005. // algorithm, or |NID_undef| if the signature algorithm does not correspond to
  1006. // a known NID.
  1007. OPENSSL_EXPORT int X509_CRL_get_signature_nid(const X509_CRL *crl);
  1008. // i2d_re_X509_CRL_tbs serializes the TBSCertList portion of |crl|, as described
  1009. // in |i2d_SAMPLE|.
  1010. //
  1011. // This function re-encodes the TBSCertList and may not reflect |crl|'s original
  1012. // encoding. It may be used to manually generate a signature for a new CRL. To
  1013. // verify CRLs, use |i2d_X509_CRL_tbs| instead.
  1014. OPENSSL_EXPORT int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp);
  1015. // i2d_X509_CRL_tbs serializes the TBSCertList portion of |crl|, as described in
  1016. // |i2d_SAMPLE|.
  1017. //
  1018. // This function preserves the original encoding of the TBSCertList and may not
  1019. // reflect modifications made to |crl|. It may be used to manually verify the
  1020. // signature of an existing CRL. To generate CRLs, use |i2d_re_X509_CRL_tbs|
  1021. // instead.
  1022. OPENSSL_EXPORT int i2d_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp);
  1023. // X509_CRL_set1_signature_algo sets |crl|'s signature algorithm to |algo| and
  1024. // returns one on success or zero on error. It updates both the signature field
  1025. // of the TBSCertList structure, and the signatureAlgorithm field of the CRL.
  1026. OPENSSL_EXPORT int X509_CRL_set1_signature_algo(X509_CRL *crl,
  1027. const X509_ALGOR *algo);
  1028. // X509_CRL_set1_signature_value sets |crl|'s signature to a copy of the
  1029. // |sig_len| bytes pointed by |sig|. It returns one on success and zero on
  1030. // error.
  1031. //
  1032. // Due to a specification error, X.509 CRLs store signatures in ASN.1 BIT
  1033. // STRINGs, but signature algorithms return byte strings rather than bit
  1034. // strings. This function creates a BIT STRING containing a whole number of
  1035. // bytes, with the bit order matching the DER encoding. This matches the
  1036. // encoding used by all X.509 signature algorithms.
  1037. OPENSSL_EXPORT int X509_CRL_set1_signature_value(X509_CRL *crl,
  1038. const uint8_t *sig,
  1039. size_t sig_len);
  1040. // X509_REVOKED_get0_serialNumber returns the serial number of the certificate
  1041. // revoked by |revoked|.
  1042. OPENSSL_EXPORT const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(
  1043. const X509_REVOKED *revoked);
  1044. // X509_REVOKED_set_serialNumber sets |revoked|'s serial number to |serial|. It
  1045. // returns one on success or zero on error.
  1046. OPENSSL_EXPORT int X509_REVOKED_set_serialNumber(X509_REVOKED *revoked,
  1047. const ASN1_INTEGER *serial);
  1048. // X509_REVOKED_get0_revocationDate returns the revocation time of the
  1049. // certificate revoked by |revoked|.
  1050. OPENSSL_EXPORT const ASN1_TIME *X509_REVOKED_get0_revocationDate(
  1051. const X509_REVOKED *revoked);
  1052. // X509_REVOKED_set_revocationDate sets |revoked|'s revocation time to |tm|. It
  1053. // returns one on success or zero on error.
  1054. OPENSSL_EXPORT int X509_REVOKED_set_revocationDate(X509_REVOKED *revoked,
  1055. const ASN1_TIME *tm);
  1056. // X509_REVOKED_get0_extensions returns |r|'s extensions list, or NULL if |r|
  1057. // omits it.
  1058. OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(
  1059. const X509_REVOKED *r);
  1060. OPENSSL_EXPORT X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer,
  1061. EVP_PKEY *skey, const EVP_MD *md,
  1062. unsigned int flags);
  1063. OPENSSL_EXPORT int X509_REQ_check_private_key(X509_REQ *x509, EVP_PKEY *pkey);
  1064. OPENSSL_EXPORT int X509_check_private_key(X509 *x509, const EVP_PKEY *pkey);
  1065. OPENSSL_EXPORT int X509_chain_check_suiteb(int *perror_depth, X509 *x,
  1066. STACK_OF(X509) *chain,
  1067. unsigned long flags);
  1068. OPENSSL_EXPORT int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk,
  1069. unsigned long flags);
  1070. // X509_chain_up_ref returns a newly-allocated |STACK_OF(X509)| containing a
  1071. // shallow copy of |chain|, or NULL on error. That is, the return value has the
  1072. // same contents as |chain|, and each |X509|'s reference count is incremented by
  1073. // one.
  1074. OPENSSL_EXPORT STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain);
  1075. OPENSSL_EXPORT int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
  1076. OPENSSL_EXPORT int X509_issuer_name_cmp(const X509 *a, const X509 *b);
  1077. OPENSSL_EXPORT unsigned long X509_issuer_name_hash(X509 *a);
  1078. OPENSSL_EXPORT int X509_subject_name_cmp(const X509 *a, const X509 *b);
  1079. OPENSSL_EXPORT unsigned long X509_subject_name_hash(X509 *x);
  1080. OPENSSL_EXPORT unsigned long X509_issuer_name_hash_old(X509 *a);
  1081. OPENSSL_EXPORT unsigned long X509_subject_name_hash_old(X509 *x);
  1082. OPENSSL_EXPORT int X509_cmp(const X509 *a, const X509 *b);
  1083. OPENSSL_EXPORT int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
  1084. OPENSSL_EXPORT unsigned long X509_NAME_hash(X509_NAME *x);
  1085. OPENSSL_EXPORT unsigned long X509_NAME_hash_old(X509_NAME *x);
  1086. OPENSSL_EXPORT int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
  1087. OPENSSL_EXPORT int X509_CRL_match(const X509_CRL *a, const X509_CRL *b);
  1088. OPENSSL_EXPORT int X509_print_ex_fp(FILE *bp, X509 *x, unsigned long nmflag,
  1089. unsigned long cflag);
  1090. OPENSSL_EXPORT int X509_print_fp(FILE *bp, X509 *x);
  1091. OPENSSL_EXPORT int X509_CRL_print_fp(FILE *bp, X509_CRL *x);
  1092. OPENSSL_EXPORT int X509_REQ_print_fp(FILE *bp, X509_REQ *req);
  1093. OPENSSL_EXPORT int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm,
  1094. int indent, unsigned long flags);
  1095. OPENSSL_EXPORT int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase);
  1096. OPENSSL_EXPORT int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent,
  1097. unsigned long flags);
  1098. OPENSSL_EXPORT int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflag,
  1099. unsigned long cflag);
  1100. OPENSSL_EXPORT int X509_print(BIO *bp, X509 *x);
  1101. OPENSSL_EXPORT int X509_ocspid_print(BIO *bp, X509 *x);
  1102. OPENSSL_EXPORT int X509_CRL_print(BIO *bp, X509_CRL *x);
  1103. OPENSSL_EXPORT int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag,
  1104. unsigned long cflag);
  1105. OPENSSL_EXPORT int X509_REQ_print(BIO *bp, X509_REQ *req);
  1106. OPENSSL_EXPORT int X509_NAME_entry_count(const X509_NAME *name);
  1107. OPENSSL_EXPORT int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid,
  1108. char *buf, int len);
  1109. OPENSSL_EXPORT int X509_NAME_get_text_by_OBJ(const X509_NAME *name,
  1110. const ASN1_OBJECT *obj, char *buf,
  1111. int len);
  1112. // NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
  1113. // lastpos, search after that position on.
  1114. OPENSSL_EXPORT int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid,
  1115. int lastpos);
  1116. OPENSSL_EXPORT int X509_NAME_get_index_by_OBJ(const X509_NAME *name,
  1117. const ASN1_OBJECT *obj,
  1118. int lastpos);
  1119. OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name,
  1120. int loc);
  1121. OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name,
  1122. int loc);
  1123. OPENSSL_EXPORT int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne,
  1124. int loc, int set);
  1125. OPENSSL_EXPORT int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
  1126. int type,
  1127. const unsigned char *bytes,
  1128. int len, int loc, int set);
  1129. OPENSSL_EXPORT int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid,
  1130. int type,
  1131. const unsigned char *bytes,
  1132. int len, int loc, int set);
  1133. OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(
  1134. X509_NAME_ENTRY **ne, const char *field, int type,
  1135. const unsigned char *bytes, int len);
  1136. OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(
  1137. X509_NAME_ENTRY **ne, int nid, int type, const unsigned char *bytes,
  1138. int len);
  1139. OPENSSL_EXPORT int X509_NAME_add_entry_by_txt(X509_NAME *name,
  1140. const char *field, int type,
  1141. const unsigned char *bytes,
  1142. int len, int loc, int set);
  1143. OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(
  1144. X509_NAME_ENTRY **ne, const ASN1_OBJECT *obj, int type,
  1145. const unsigned char *bytes, int len);
  1146. OPENSSL_EXPORT int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
  1147. const ASN1_OBJECT *obj);
  1148. OPENSSL_EXPORT int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
  1149. const unsigned char *bytes,
  1150. int len);
  1151. OPENSSL_EXPORT ASN1_OBJECT *X509_NAME_ENTRY_get_object(
  1152. const X509_NAME_ENTRY *ne);
  1153. OPENSSL_EXPORT ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne);
  1154. // X509v3_get_ext_count returns the number of extensions in |x|.
  1155. OPENSSL_EXPORT int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
  1156. // X509v3_get_ext_by_NID returns the index of the first extension in |x| with
  1157. // type |nid|, or a negative number if not found. If found, callers can use
  1158. // |X509v3_get_ext| to look up the extension by index.
  1159. //
  1160. // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers
  1161. // can thus loop over all matching extensions by first passing -1 and then
  1162. // passing the previously-returned value until no match is returned.
  1163. OPENSSL_EXPORT int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
  1164. int nid, int lastpos);
  1165. // X509v3_get_ext_by_OBJ behaves like |X509v3_get_ext_by_NID| but looks for
  1166. // extensions matching |obj|.
  1167. OPENSSL_EXPORT int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
  1168. const ASN1_OBJECT *obj, int lastpos);
  1169. // X509v3_get_ext_by_critical returns the index of the first extension in |x|
  1170. // whose critical bit matches |crit|, or a negative number if no such extension
  1171. // was found.
  1172. //
  1173. // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers
  1174. // can thus loop over all matching extensions by first passing -1 and then
  1175. // passing the previously-returned value until no match is returned.
  1176. OPENSSL_EXPORT int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
  1177. int crit, int lastpos);
  1178. // X509v3_get_ext returns the extension in |x| at index |loc|, or NULL if |loc|
  1179. // is out of bounds.
  1180. OPENSSL_EXPORT X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x,
  1181. int loc);
  1182. // X509v3_delete_ext removes the extension in |x| at index |loc| and returns the
  1183. // removed extension, or NULL if |loc| was out of bounds. If an extension was
  1184. // returned, the caller must release it with |X509_EXTENSION_free|.
  1185. OPENSSL_EXPORT X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x,
  1186. int loc);
  1187. // X509v3_add_ext adds a copy of |ex| to the extension list in |*x|. If |*x| is
  1188. // NULL, it allocates a new |STACK_OF(X509_EXTENSION)| to hold the copy and sets
  1189. // |*x| to the new list. It returns |*x| on success and NULL on error. The
  1190. // caller retains ownership of |ex| and can release it independently of |*x|.
  1191. //
  1192. // The new extension is inserted at index |loc|, shifting extensions to the
  1193. // right. If |loc| is -1 or out of bounds, the new extension is appended to the
  1194. // list.
  1195. OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509v3_add_ext(
  1196. STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc);
  1197. // X509_get_ext_count returns the number of extensions in |x|.
  1198. OPENSSL_EXPORT int X509_get_ext_count(const X509 *x);
  1199. // X509_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for
  1200. // extensions in |x|.
  1201. OPENSSL_EXPORT int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos);
  1202. // X509_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for
  1203. // extensions in |x|.
  1204. OPENSSL_EXPORT int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj,
  1205. int lastpos);
  1206. // X509_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but
  1207. // searches for extensions in |x|.
  1208. OPENSSL_EXPORT int X509_get_ext_by_critical(const X509 *x, int crit,
  1209. int lastpos);
  1210. // X509_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| is
  1211. // out of bounds.
  1212. OPENSSL_EXPORT X509_EXTENSION *X509_get_ext(const X509 *x, int loc);
  1213. // X509_delete_ext removes the extension in |x| at index |loc| and returns the
  1214. // removed extension, or NULL if |loc| was out of bounds. If non-NULL, the
  1215. // caller must release the result with |X509_EXTENSION_free|. It is also safe,
  1216. // but not necessary, to call |X509_EXTENSION_free| if the result is NULL.
  1217. OPENSSL_EXPORT X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
  1218. // X509_add_ext adds a copy of |ex| to |x|. It returns one on success and zero
  1219. // on failure. The caller retains ownership of |ex| and can release it
  1220. // independently of |x|.
  1221. //
  1222. // The new extension is inserted at index |loc|, shifting extensions to the
  1223. // right. If |loc| is -1 or out of bounds, the new extension is appended to the
  1224. // list.
  1225. OPENSSL_EXPORT int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
  1226. // X509_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the extension in
  1227. // |x509|'s extension list.
  1228. //
  1229. // WARNING: This function is difficult to use correctly. See the documentation
  1230. // for |X509V3_get_d2i| for details.
  1231. OPENSSL_EXPORT void *X509_get_ext_d2i(const X509 *x509, int nid,
  1232. int *out_critical, int *out_idx);
  1233. // X509_add1_ext_i2d behaves like |X509V3_add1_i2d| but adds the extension to
  1234. // |x|'s extension list.
  1235. //
  1236. // WARNING: This function may return zero or -1 on error. The caller must also
  1237. // ensure |value|'s type matches |nid|. See the documentation for
  1238. // |X509V3_add1_i2d| for details.
  1239. OPENSSL_EXPORT int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
  1240. unsigned long flags);
  1241. // X509_CRL_get_ext_count returns the number of extensions in |x|.
  1242. OPENSSL_EXPORT int X509_CRL_get_ext_count(const X509_CRL *x);
  1243. // X509_CRL_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for
  1244. // extensions in |x|.
  1245. OPENSSL_EXPORT int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid,
  1246. int lastpos);
  1247. // X509_CRL_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for
  1248. // extensions in |x|.
  1249. OPENSSL_EXPORT int X509_CRL_get_ext_by_OBJ(const X509_CRL *x,
  1250. const ASN1_OBJECT *obj, int lastpos);
  1251. // X509_CRL_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but
  1252. // searches for extensions in |x|.
  1253. OPENSSL_EXPORT int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit,
  1254. int lastpos);
  1255. // X509_CRL_get_ext returns the extension in |x| at index |loc|, or NULL if
  1256. // |loc| is out of bounds.
  1257. OPENSSL_EXPORT X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc);
  1258. // X509_CRL_delete_ext removes the extension in |x| at index |loc| and returns
  1259. // the removed extension, or NULL if |loc| was out of bounds. If non-NULL, the
  1260. // caller must release the result with |X509_EXTENSION_free|. It is also safe,
  1261. // but not necessary, to call |X509_EXTENSION_free| if the result is NULL.
  1262. OPENSSL_EXPORT X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
  1263. // X509_CRL_add_ext adds a copy of |ex| to |x|. It returns one on success and
  1264. // zero on failure. The caller retains ownership of |ex| and can release it
  1265. // independently of |x|.
  1266. //
  1267. // The new extension is inserted at index |loc|, shifting extensions to the
  1268. // right. If |loc| is -1 or out of bounds, the new extension is appended to the
  1269. // list.
  1270. OPENSSL_EXPORT int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
  1271. // X509_CRL_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the
  1272. // extension in |crl|'s extension list.
  1273. //
  1274. // WARNING: This function is difficult to use correctly. See the documentation
  1275. // for |X509V3_get_d2i| for details.
  1276. OPENSSL_EXPORT void *X509_CRL_get_ext_d2i(const X509_CRL *crl, int nid,
  1277. int *out_critical, int *out_idx);
  1278. // X509_CRL_add1_ext_i2d behaves like |X509V3_add1_i2d| but adds the extension
  1279. // to |x|'s extension list.
  1280. //
  1281. // WARNING: This function may return zero or -1 on error. The caller must also
  1282. // ensure |value|'s type matches |nid|. See the documentation for
  1283. // |X509V3_add1_i2d| for details.
  1284. OPENSSL_EXPORT int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value,
  1285. int crit, unsigned long flags);
  1286. // X509_REVOKED_get_ext_count returns the number of extensions in |x|.
  1287. OPENSSL_EXPORT int X509_REVOKED_get_ext_count(const X509_REVOKED *x);
  1288. // X509_REVOKED_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches
  1289. // for extensions in |x|.
  1290. OPENSSL_EXPORT int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid,
  1291. int lastpos);
  1292. // X509_REVOKED_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches
  1293. // for extensions in |x|.
  1294. OPENSSL_EXPORT int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x,
  1295. const ASN1_OBJECT *obj,
  1296. int lastpos);
  1297. // X509_REVOKED_get_ext_by_critical behaves like |X509v3_get_ext_by_critical|
  1298. // but searches for extensions in |x|.
  1299. OPENSSL_EXPORT int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x,
  1300. int crit, int lastpos);
  1301. // X509_REVOKED_get_ext returns the extension in |x| at index |loc|, or NULL if
  1302. // |loc| is out of bounds.
  1303. OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x,
  1304. int loc);
  1305. // X509_REVOKED_delete_ext removes the extension in |x| at index |loc| and
  1306. // returns the removed extension, or NULL if |loc| was out of bounds. If
  1307. // non-NULL, the caller must release the result with |X509_EXTENSION_free|. It
  1308. // is also safe, but not necessary, to call |X509_EXTENSION_free| if the result
  1309. // is NULL.
  1310. OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x,
  1311. int loc);
  1312. // X509_REVOKED_add_ext adds a copy of |ex| to |x|. It returns one on success
  1313. // and zero on failure. The caller retains ownership of |ex| and can release it
  1314. // independently of |x|.
  1315. //
  1316. // The new extension is inserted at index |loc|, shifting extensions to the
  1317. // right. If |loc| is -1 or out of bounds, the new extension is appended to the
  1318. // list.
  1319. OPENSSL_EXPORT int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex,
  1320. int loc);
  1321. // X509_REVOKED_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the
  1322. // extension in |revoked|'s extension list.
  1323. //
  1324. // WARNING: This function is difficult to use correctly. See the documentation
  1325. // for |X509V3_get_d2i| for details.
  1326. OPENSSL_EXPORT void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *revoked,
  1327. int nid, int *out_critical,
  1328. int *out_idx);
  1329. // X509_REVOKED_add1_ext_i2d behaves like |X509V3_add1_i2d| but adds the
  1330. // extension to |x|'s extension list.
  1331. //
  1332. // WARNING: This function may return zero or -1 on error. The caller must also
  1333. // ensure |value|'s type matches |nid|. See the documentation for
  1334. // |X509V3_add1_i2d| for details.
  1335. OPENSSL_EXPORT int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid,
  1336. void *value, int crit,
  1337. unsigned long flags);
  1338. // X509_EXTENSION_create_by_NID creates a new |X509_EXTENSION| with type |nid|,
  1339. // value |data|, and critical bit |crit|. It returns the newly-allocated
  1340. // |X509_EXTENSION| on success, and false on error. |nid| should be a |NID_*|
  1341. // constant.
  1342. //
  1343. // If |ex| and |*ex| are both non-NULL, it modifies and returns |*ex| instead of
  1344. // creating a new object. If |ex| is non-NULL, but |*ex| is NULL, it sets |*ex|
  1345. // to the new |X509_EXTENSION|, in addition to returning the result.
  1346. OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_NID(
  1347. X509_EXTENSION **ex, int nid, int crit, const ASN1_OCTET_STRING *data);
  1348. // X509_EXTENSION_create_by_OBJ behaves like |X509_EXTENSION_create_by_NID|, but
  1349. // the extension type is determined by an |ASN1_OBJECT|.
  1350. OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_OBJ(
  1351. X509_EXTENSION **ex, const ASN1_OBJECT *obj, int crit,
  1352. const ASN1_OCTET_STRING *data);
  1353. // X509_EXTENSION_set_object sets |ex|'s extension type to |obj|. It returns one
  1354. // on success and zero on error.
  1355. OPENSSL_EXPORT int X509_EXTENSION_set_object(X509_EXTENSION *ex,
  1356. const ASN1_OBJECT *obj);
  1357. // X509_EXTENSION_set_critical sets |ex| to critical if |crit| is non-zero and
  1358. // to non-critical if |crit| is zero.
  1359. OPENSSL_EXPORT int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
  1360. // X509_EXTENSION_set_data set's |ex|'s extension value to a copy of |data|. It
  1361. // returns one on success and zero on error.
  1362. OPENSSL_EXPORT int X509_EXTENSION_set_data(X509_EXTENSION *ex,
  1363. const ASN1_OCTET_STRING *data);
  1364. // X509_EXTENSION_get_object returns |ex|'s extension type.
  1365. OPENSSL_EXPORT ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex);
  1366. // X509_EXTENSION_get_data returns |ne|'s extension value.
  1367. OPENSSL_EXPORT ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
  1368. // X509_EXTENSION_get_critical returns one if |ex| is critical and zero
  1369. // otherwise.
  1370. OPENSSL_EXPORT int X509_EXTENSION_get_critical(const X509_EXTENSION *ex);
  1371. // X509at_get_attr_count returns the number of attributes in |x|.
  1372. OPENSSL_EXPORT int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
  1373. // X509at_get_attr_by_NID returns the index of the attribute in |x| of type
  1374. // |nid|, or a negative number if not found. If found, callers can use
  1375. // |X509at_get_attr| to look up the attribute by index.
  1376. //
  1377. // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers
  1378. // can thus loop over all matching attributes by first passing -1 and then
  1379. // passing the previously-returned value until no match is returned.
  1380. OPENSSL_EXPORT int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x,
  1381. int nid, int lastpos);
  1382. // X509at_get_attr_by_OBJ behaves like |X509at_get_attr_by_NID| but looks for
  1383. // attributes of type |obj|.
  1384. OPENSSL_EXPORT int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk,
  1385. const ASN1_OBJECT *obj, int lastpos);
  1386. // X509at_get_attr returns the attribute at index |loc| in |x|, or NULL if
  1387. // out of bounds.
  1388. OPENSSL_EXPORT X509_ATTRIBUTE *X509at_get_attr(
  1389. const STACK_OF(X509_ATTRIBUTE) *x, int loc);
  1390. // X509at_delete_attr removes the attribute at index |loc| in |x|. It returns
  1391. // the removed attribute to the caller, or NULL if |loc| was out of bounds. If
  1392. // non-NULL, the caller must release the result with |X509_ATTRIBUTE_free| when
  1393. // done. It is also safe, but not necessary, to call |X509_ATTRIBUTE_free| if
  1394. // the result is NULL.
  1395. OPENSSL_EXPORT X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x,
  1396. int loc);
  1397. // X509at_add1_attr appends a copy of |attr| to the attribute list in |*x|. If
  1398. // |*x| is NULL, it allocates a new |STACK_OF(X509_ATTRIBUTE)| to hold the copy
  1399. // and sets |*x| to the new list. It returns |*x| on success and NULL on error.
  1400. // The caller retains ownership of |attr| and can release it independently of
  1401. // |*x|.
  1402. OPENSSL_EXPORT STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(
  1403. STACK_OF(X509_ATTRIBUTE) **x, X509_ATTRIBUTE *attr);
  1404. // X509at_add1_attr_by_OBJ behaves like |X509at_add1_attr|, but adds an
  1405. // attribute created by |X509_ATTRIBUTE_create_by_OBJ|.
  1406. OPENSSL_EXPORT STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(
  1407. STACK_OF(X509_ATTRIBUTE) **x, const ASN1_OBJECT *obj, int type,
  1408. const unsigned char *bytes, int len);
  1409. // X509at_add1_attr_by_NID behaves like |X509at_add1_attr|, but adds an
  1410. // attribute created by |X509_ATTRIBUTE_create_by_NID|.
  1411. OPENSSL_EXPORT STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(
  1412. STACK_OF(X509_ATTRIBUTE) **x, int nid, int type, const unsigned char *bytes,
  1413. int len);
  1414. // X509at_add1_attr_by_txt behaves like |X509at_add1_attr|, but adds an
  1415. // attribute created by |X509_ATTRIBUTE_create_by_txt|.
  1416. OPENSSL_EXPORT STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(
  1417. STACK_OF(X509_ATTRIBUTE) **x, const char *attrname, int type,
  1418. const unsigned char *bytes, int len);
  1419. // X509_ATTRIBUTE_create_by_NID returns a newly-allocated |X509_ATTRIBUTE| of
  1420. // type |nid|, or NULL on error. The value is determined as in
  1421. // |X509_ATTRIBUTE_set1_data|.
  1422. //
  1423. // If |attr| is non-NULL, the resulting |X509_ATTRIBUTE| is also written to
  1424. // |*attr|. If |*attr| was non-NULL when the function was called, |*attr| is
  1425. // reused instead of creating a new object.
  1426. //
  1427. // WARNING: The interpretation of |attrtype|, |data|, and |len| is complex and
  1428. // error-prone. See |X509_ATTRIBUTE_set1_data| for details.
  1429. //
  1430. // WARNING: The object reuse form is deprecated and may be removed in the
  1431. // future. It also currently incorrectly appends to the reused object's value
  1432. // set rather than overwriting it.
  1433. OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(
  1434. X509_ATTRIBUTE **attr, int nid, int attrtype, const void *data, int len);
  1435. // X509_ATTRIBUTE_create_by_OBJ behaves like |X509_ATTRIBUTE_create_by_NID|
  1436. // except the attribute's type is determined by |obj|.
  1437. OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(
  1438. X509_ATTRIBUTE **attr, const ASN1_OBJECT *obj, int attrtype,
  1439. const void *data, int len);
  1440. // X509_ATTRIBUTE_create_by_txt behaves like |X509_ATTRIBUTE_create_by_NID|
  1441. // except the attribute's type is determined by calling |OBJ_txt2obj| with
  1442. // |attrname|.
  1443. OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(
  1444. X509_ATTRIBUTE **attr, const char *attrname, int type,
  1445. const unsigned char *bytes, int len);
  1446. // X509_ATTRIBUTE_set1_object sets |attr|'s type to |obj|. It returns one on
  1447. // success and zero on error.
  1448. OPENSSL_EXPORT int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr,
  1449. const ASN1_OBJECT *obj);
  1450. // X509_ATTRIBUTE_set1_data appends a value to |attr|'s value set and returns
  1451. // one on success or zero on error. The value is determined as follows:
  1452. //
  1453. // If |attrtype| is a |MBSTRING_*| constant, the value is an ASN.1 string. The
  1454. // string is determined by decoding |len| bytes from |data| in the encoding
  1455. // specified by |attrtype|, and then re-encoding it in a form appropriate for
  1456. // |attr|'s type. If |len| is -1, |strlen(data)| is used instead. See
  1457. // |ASN1_STRING_set_by_NID| for details.
  1458. //
  1459. // TODO(davidben): Document |ASN1_STRING_set_by_NID| so the reference is useful.
  1460. //
  1461. // Otherwise, if |len| is not -1, the value is an ASN.1 string. |attrtype| is an
  1462. // |ASN1_STRING| type value and the |len| bytes from |data| are copied as the
  1463. // type-specific representation of |ASN1_STRING|. See |ASN1_STRING| for details.
  1464. //
  1465. // WARNING: If this form is used to construct a negative INTEGER or ENUMERATED,
  1466. // |attrtype| includes the |V_ASN1_NEG| flag for |ASN1_STRING|, but the function
  1467. // forgets to clear the flag for |ASN1_TYPE|. This matches OpenSSL but is
  1468. // probably a bug. For now, do not use this form with negative values.
  1469. //
  1470. // Otherwise, if |len| is -1, the value is constructed by passing |attrtype| and
  1471. // |data| to |ASN1_TYPE_set1|. That is, |attrtype| is an |ASN1_TYPE| type value,
  1472. // and |data| is cast to the corresponding pointer type.
  1473. //
  1474. // WARNING: Despite the name, this function appends to |attr|'s value set,
  1475. // rather than overwriting it. To overwrite the value set, create a new
  1476. // |X509_ATTRIBUTE| with |X509_ATTRIBUTE_new|.
  1477. //
  1478. // WARNING: If using the |MBSTRING_*| form, pass a length rather than relying on
  1479. // |strlen|. In particular, |strlen| will not behave correctly if the input is
  1480. // |MBSTRING_BMP| or |MBSTRING_UNIV|.
  1481. //
  1482. // WARNING: This function currently misinterprets |V_ASN1_OTHER| as an
  1483. // |MBSTRING_*| constant. This matches OpenSSL but means it is impossible to
  1484. // construct a value with a non-universal tag.
  1485. OPENSSL_EXPORT int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
  1486. const void *data, int len);
  1487. // X509_ATTRIBUTE_get0_data returns the |idx|th value of |attr| in a
  1488. // type-specific representation to |attrtype|, or NULL if out of bounds or the
  1489. // type does not match. |attrtype| is one of the type values in |ASN1_TYPE|. On
  1490. // match, the return value uses the same representation as |ASN1_TYPE_set0|. See
  1491. // |ASN1_TYPE| for details.
  1492. OPENSSL_EXPORT void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
  1493. int attrtype, void *unused);
  1494. // X509_ATTRIBUTE_count returns the number of values in |attr|.
  1495. OPENSSL_EXPORT int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr);
  1496. // X509_ATTRIBUTE_get0_object returns the type of |attr|.
  1497. OPENSSL_EXPORT ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
  1498. // X509_ATTRIBUTE_get0_type returns the |idx|th value in |attr|, or NULL if out
  1499. // of bounds. Note this function returns one of |attr|'s values, not the type.
  1500. OPENSSL_EXPORT ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr,
  1501. int idx);
  1502. OPENSSL_EXPORT int X509_verify_cert(X509_STORE_CTX *ctx);
  1503. // lookup a cert from a X509 STACK
  1504. OPENSSL_EXPORT X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,
  1505. X509_NAME *name,
  1506. ASN1_INTEGER *serial);
  1507. OPENSSL_EXPORT X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name);
  1508. // PKCS#8 utilities
  1509. DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
  1510. OPENSSL_EXPORT EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
  1511. OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
  1512. OPENSSL_EXPORT int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,
  1513. int version, int ptype, void *pval,
  1514. unsigned char *penc, int penclen);
  1515. OPENSSL_EXPORT int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg,
  1516. const unsigned char **pk, int *ppklen,
  1517. X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8);
  1518. // X509_PUBKEY_set0_param sets |pub| to a key with AlgorithmIdentifier
  1519. // determined by |obj|, |param_type|, and |param_value|, and an encoded
  1520. // public key of |key|. On success, it takes ownership of all its parameters and
  1521. // returns one. Otherwise, it returns zero. |key| must have been allocated by
  1522. // |OPENSSL_malloc|.
  1523. //
  1524. // |obj|, |param_type|, and |param_value| are interpreted as in
  1525. // |X509_ALGOR_set0|. See |X509_ALGOR_set0| for details.
  1526. OPENSSL_EXPORT int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *obj,
  1527. int param_type, void *param_value,
  1528. uint8_t *key, int key_len);
  1529. // X509_PUBKEY_get0_param outputs fields of |pub| and returns one. If |out_obj|
  1530. // is not NULL, it sets |*out_obj| to AlgorithmIdentifier's OID. If |out_key|
  1531. // is not NULL, it sets |*out_key| and |*out_key_len| to the encoded public key.
  1532. // If |out_alg| is not NULL, it sets |*out_alg| to the AlgorithmIdentifier.
  1533. //
  1534. // Note: X.509 SubjectPublicKeyInfo structures store the encoded public key as a
  1535. // BIT STRING. |*out_key| and |*out_key_len| will silently pad the key with zero
  1536. // bits if |pub| did not contain a whole number of bytes. Use
  1537. // |X509_PUBKEY_get0_public_key| to preserve this information.
  1538. OPENSSL_EXPORT int X509_PUBKEY_get0_param(ASN1_OBJECT **out_obj,
  1539. const uint8_t **out_key,
  1540. int *out_key_len,
  1541. X509_ALGOR **out_alg,
  1542. X509_PUBKEY *pub);
  1543. // X509_PUBKEY_get0_public_key returns |pub|'s encoded public key.
  1544. OPENSSL_EXPORT const ASN1_BIT_STRING *X509_PUBKEY_get0_public_key(
  1545. const X509_PUBKEY *pub);
  1546. OPENSSL_EXPORT int X509_check_trust(X509 *x, int id, int flags);
  1547. OPENSSL_EXPORT int X509_TRUST_get_count(void);
  1548. OPENSSL_EXPORT X509_TRUST *X509_TRUST_get0(int idx);
  1549. OPENSSL_EXPORT int X509_TRUST_get_by_id(int id);
  1550. OPENSSL_EXPORT int X509_TRUST_add(int id, int flags,
  1551. int (*ck)(X509_TRUST *, X509 *, int),
  1552. char *name, int arg1, void *arg2);
  1553. OPENSSL_EXPORT void X509_TRUST_cleanup(void);
  1554. OPENSSL_EXPORT int X509_TRUST_get_flags(const X509_TRUST *xp);
  1555. OPENSSL_EXPORT char *X509_TRUST_get0_name(const X509_TRUST *xp);
  1556. OPENSSL_EXPORT int X509_TRUST_get_trust(const X509_TRUST *xp);
  1557. struct rsa_pss_params_st {
  1558. X509_ALGOR *hashAlgorithm;
  1559. X509_ALGOR *maskGenAlgorithm;
  1560. ASN1_INTEGER *saltLength;
  1561. ASN1_INTEGER *trailerField;
  1562. // OpenSSL caches the MGF hash on |RSA_PSS_PARAMS| in some cases. None of the
  1563. // cases apply to BoringSSL, so this is always NULL, but Node expects the
  1564. // field to be present.
  1565. X509_ALGOR *maskHash;
  1566. } /* RSA_PSS_PARAMS */;
  1567. DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
  1568. /*
  1569. SSL_CTX -> X509_STORE
  1570. -> X509_LOOKUP
  1571. ->X509_LOOKUP_METHOD
  1572. -> X509_LOOKUP
  1573. ->X509_LOOKUP_METHOD
  1574. SSL -> X509_STORE_CTX
  1575. ->X509_STORE
  1576. The X509_STORE holds the tables etc for verification stuff.
  1577. A X509_STORE_CTX is used while validating a single certificate.
  1578. The X509_STORE has X509_LOOKUPs for looking up certs.
  1579. The X509_STORE then calls a function to actually verify the
  1580. certificate chain.
  1581. */
  1582. #define X509_LU_X509 1
  1583. #define X509_LU_CRL 2
  1584. #define X509_LU_PKEY 3
  1585. DEFINE_STACK_OF(X509_LOOKUP)
  1586. DEFINE_STACK_OF(X509_OBJECT)
  1587. DEFINE_STACK_OF(X509_VERIFY_PARAM)
  1588. typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *);
  1589. typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *);
  1590. typedef int (*X509_STORE_CTX_get_issuer_fn)(X509 **issuer, X509_STORE_CTX *ctx,
  1591. X509 *x);
  1592. typedef int (*X509_STORE_CTX_check_issued_fn)(X509_STORE_CTX *ctx, X509 *x,
  1593. X509 *issuer);
  1594. typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx);
  1595. typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, X509_CRL **crl,
  1596. X509 *x);
  1597. typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl);
  1598. typedef int (*X509_STORE_CTX_cert_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl,
  1599. X509 *x);
  1600. typedef int (*X509_STORE_CTX_check_policy_fn)(X509_STORE_CTX *ctx);
  1601. typedef STACK_OF(X509) *(*X509_STORE_CTX_lookup_certs_fn)(X509_STORE_CTX *ctx,
  1602. X509_NAME *nm);
  1603. typedef STACK_OF(X509_CRL) *(*X509_STORE_CTX_lookup_crls_fn)(
  1604. X509_STORE_CTX *ctx, X509_NAME *nm);
  1605. typedef int (*X509_STORE_CTX_cleanup_fn)(X509_STORE_CTX *ctx);
  1606. OPENSSL_EXPORT int X509_STORE_set_depth(X509_STORE *store, int depth);
  1607. OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
  1608. #define X509_STORE_CTX_set_app_data(ctx, data) \
  1609. X509_STORE_CTX_set_ex_data(ctx, 0, data)
  1610. #define X509_STORE_CTX_get_app_data(ctx) X509_STORE_CTX_get_ex_data(ctx, 0)
  1611. #define X509_L_FILE_LOAD 1
  1612. #define X509_L_ADD_DIR 2
  1613. #define X509_LOOKUP_load_file(x, name, type) \
  1614. X509_LOOKUP_ctrl((x), X509_L_FILE_LOAD, (name), (long)(type), NULL)
  1615. #define X509_LOOKUP_add_dir(x, name, type) \
  1616. X509_LOOKUP_ctrl((x), X509_L_ADD_DIR, (name), (long)(type), NULL)
  1617. #define X509_V_OK 0
  1618. #define X509_V_ERR_UNSPECIFIED 1
  1619. #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
  1620. #define X509_V_ERR_UNABLE_TO_GET_CRL 3
  1621. #define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
  1622. #define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
  1623. #define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
  1624. #define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
  1625. #define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
  1626. #define X509_V_ERR_CERT_NOT_YET_VALID 9
  1627. #define X509_V_ERR_CERT_HAS_EXPIRED 10
  1628. #define X509_V_ERR_CRL_NOT_YET_VALID 11
  1629. #define X509_V_ERR_CRL_HAS_EXPIRED 12
  1630. #define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
  1631. #define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
  1632. #define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
  1633. #define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
  1634. #define X509_V_ERR_OUT_OF_MEM 17
  1635. #define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
  1636. #define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
  1637. #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
  1638. #define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
  1639. #define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
  1640. #define X509_V_ERR_CERT_REVOKED 23
  1641. #define X509_V_ERR_INVALID_CA 24
  1642. #define X509_V_ERR_PATH_LENGTH_EXCEEDED 25
  1643. #define X509_V_ERR_INVALID_PURPOSE 26
  1644. #define X509_V_ERR_CERT_UNTRUSTED 27
  1645. #define X509_V_ERR_CERT_REJECTED 28
  1646. // These are 'informational' when looking for issuer cert
  1647. #define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29
  1648. #define X509_V_ERR_AKID_SKID_MISMATCH 30
  1649. #define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31
  1650. #define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32
  1651. #define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33
  1652. #define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34
  1653. #define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35
  1654. #define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36
  1655. #define X509_V_ERR_INVALID_NON_CA 37
  1656. #define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38
  1657. #define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39
  1658. #define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40
  1659. #define X509_V_ERR_INVALID_EXTENSION 41
  1660. #define X509_V_ERR_INVALID_POLICY_EXTENSION 42
  1661. #define X509_V_ERR_NO_EXPLICIT_POLICY 43
  1662. #define X509_V_ERR_DIFFERENT_CRL_SCOPE 44
  1663. #define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45
  1664. #define X509_V_ERR_UNNESTED_RESOURCE 46
  1665. #define X509_V_ERR_PERMITTED_VIOLATION 47
  1666. #define X509_V_ERR_EXCLUDED_VIOLATION 48
  1667. #define X509_V_ERR_SUBTREE_MINMAX 49
  1668. #define X509_V_ERR_APPLICATION_VERIFICATION 50
  1669. #define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51
  1670. #define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52
  1671. #define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53
  1672. #define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54
  1673. // Suite B mode algorithm violation
  1674. #define X509_V_ERR_SUITE_B_INVALID_VERSION 56
  1675. #define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57
  1676. #define X509_V_ERR_SUITE_B_INVALID_CURVE 58
  1677. #define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59
  1678. #define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60
  1679. #define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61
  1680. // Host, email and IP check errors
  1681. #define X509_V_ERR_HOSTNAME_MISMATCH 62
  1682. #define X509_V_ERR_EMAIL_MISMATCH 63
  1683. #define X509_V_ERR_IP_ADDRESS_MISMATCH 64
  1684. // Caller error
  1685. #define X509_V_ERR_INVALID_CALL 65
  1686. // Issuer lookup error
  1687. #define X509_V_ERR_STORE_LOOKUP 66
  1688. #define X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS 67
  1689. // Certificate verify flags
  1690. // Send issuer+subject checks to verify_cb
  1691. #define X509_V_FLAG_CB_ISSUER_CHECK 0x1
  1692. // Use check time instead of current time
  1693. #define X509_V_FLAG_USE_CHECK_TIME 0x2
  1694. // Lookup CRLs
  1695. #define X509_V_FLAG_CRL_CHECK 0x4
  1696. // Lookup CRLs for whole chain
  1697. #define X509_V_FLAG_CRL_CHECK_ALL 0x8
  1698. // Ignore unhandled critical extensions
  1699. #define X509_V_FLAG_IGNORE_CRITICAL 0x10
  1700. // Does nothing as its functionality has been enabled by default.
  1701. #define X509_V_FLAG_X509_STRICT 0x00
  1702. // Enable proxy certificate validation
  1703. #define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40
  1704. // Enable policy checking
  1705. #define X509_V_FLAG_POLICY_CHECK 0x80
  1706. // Policy variable require-explicit-policy
  1707. #define X509_V_FLAG_EXPLICIT_POLICY 0x100
  1708. // Policy variable inhibit-any-policy
  1709. #define X509_V_FLAG_INHIBIT_ANY 0x200
  1710. // Policy variable inhibit-policy-mapping
  1711. #define X509_V_FLAG_INHIBIT_MAP 0x400
  1712. // Notify callback that policy is OK
  1713. #define X509_V_FLAG_NOTIFY_POLICY 0x800
  1714. // Extended CRL features such as indirect CRLs, alternate CRL signing keys
  1715. #define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000
  1716. // Delta CRL support
  1717. #define X509_V_FLAG_USE_DELTAS 0x2000
  1718. // Check selfsigned CA signature
  1719. #define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000
  1720. // Use trusted store first
  1721. #define X509_V_FLAG_TRUSTED_FIRST 0x8000
  1722. // Suite B 128 bit only mode: not normally used
  1723. #define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000
  1724. // Suite B 192 bit only mode
  1725. #define X509_V_FLAG_SUITEB_192_LOS 0x20000
  1726. // Suite B 128 bit mode allowing 192 bit algorithms
  1727. #define X509_V_FLAG_SUITEB_128_LOS 0x30000
  1728. // Allow partial chains if at least one certificate is in trusted store
  1729. #define X509_V_FLAG_PARTIAL_CHAIN 0x80000
  1730. // If the initial chain is not trusted, do not attempt to build an alternative
  1731. // chain. Alternate chain checking was introduced in 1.0.2b. Setting this flag
  1732. // will force the behaviour to match that of previous versions.
  1733. #define X509_V_FLAG_NO_ALT_CHAINS 0x100000
  1734. #define X509_VP_FLAG_DEFAULT 0x1
  1735. #define X509_VP_FLAG_OVERWRITE 0x2
  1736. #define X509_VP_FLAG_RESET_FLAGS 0x4
  1737. #define X509_VP_FLAG_LOCKED 0x8
  1738. #define X509_VP_FLAG_ONCE 0x10
  1739. // Internal use: mask of policy related options
  1740. #define X509_V_FLAG_POLICY_MASK \
  1741. (X509_V_FLAG_POLICY_CHECK | X509_V_FLAG_EXPLICIT_POLICY | \
  1742. X509_V_FLAG_INHIBIT_ANY | X509_V_FLAG_INHIBIT_MAP)
  1743. OPENSSL_EXPORT int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h,
  1744. int type, X509_NAME *name);
  1745. OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_retrieve_by_subject(
  1746. STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name);
  1747. OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h,
  1748. X509_OBJECT *x);
  1749. OPENSSL_EXPORT int X509_OBJECT_up_ref_count(X509_OBJECT *a);
  1750. OPENSSL_EXPORT void X509_OBJECT_free_contents(X509_OBJECT *a);
  1751. OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *a);
  1752. OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a);
  1753. OPENSSL_EXPORT X509_STORE *X509_STORE_new(void);
  1754. OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store);
  1755. OPENSSL_EXPORT void X509_STORE_free(X509_STORE *v);
  1756. OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *st);
  1757. OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_get1_certs(X509_STORE_CTX *st,
  1758. X509_NAME *nm);
  1759. OPENSSL_EXPORT STACK_OF(X509_CRL) *X509_STORE_get1_crls(X509_STORE_CTX *st,
  1760. X509_NAME *nm);
  1761. OPENSSL_EXPORT int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags);
  1762. OPENSSL_EXPORT int X509_STORE_set_purpose(X509_STORE *ctx, int purpose);
  1763. OPENSSL_EXPORT int X509_STORE_set_trust(X509_STORE *ctx, int trust);
  1764. OPENSSL_EXPORT int X509_STORE_set1_param(X509_STORE *ctx,
  1765. X509_VERIFY_PARAM *pm);
  1766. OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx);
  1767. OPENSSL_EXPORT void X509_STORE_set_verify(X509_STORE *ctx,
  1768. X509_STORE_CTX_verify_fn verify);
  1769. #define X509_STORE_set_verify_func(ctx, func) \
  1770. X509_STORE_set_verify((ctx), (func))
  1771. OPENSSL_EXPORT void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx,
  1772. X509_STORE_CTX_verify_fn verify);
  1773. OPENSSL_EXPORT X509_STORE_CTX_verify_fn X509_STORE_get_verify(X509_STORE *ctx);
  1774. OPENSSL_EXPORT void X509_STORE_set_verify_cb(
  1775. X509_STORE *ctx, X509_STORE_CTX_verify_cb verify_cb);
  1776. #define X509_STORE_set_verify_cb_func(ctx, func) \
  1777. X509_STORE_set_verify_cb((ctx), (func))
  1778. OPENSSL_EXPORT X509_STORE_CTX_verify_cb
  1779. X509_STORE_get_verify_cb(X509_STORE *ctx);
  1780. OPENSSL_EXPORT void X509_STORE_set_get_issuer(
  1781. X509_STORE *ctx, X509_STORE_CTX_get_issuer_fn get_issuer);
  1782. OPENSSL_EXPORT X509_STORE_CTX_get_issuer_fn
  1783. X509_STORE_get_get_issuer(X509_STORE *ctx);
  1784. OPENSSL_EXPORT void X509_STORE_set_check_issued(
  1785. X509_STORE *ctx, X509_STORE_CTX_check_issued_fn check_issued);
  1786. OPENSSL_EXPORT X509_STORE_CTX_check_issued_fn
  1787. X509_STORE_get_check_issued(X509_STORE *ctx);
  1788. OPENSSL_EXPORT void X509_STORE_set_check_revocation(
  1789. X509_STORE *ctx, X509_STORE_CTX_check_revocation_fn check_revocation);
  1790. OPENSSL_EXPORT X509_STORE_CTX_check_revocation_fn
  1791. X509_STORE_get_check_revocation(X509_STORE *ctx);
  1792. OPENSSL_EXPORT void X509_STORE_set_get_crl(X509_STORE *ctx,
  1793. X509_STORE_CTX_get_crl_fn get_crl);
  1794. OPENSSL_EXPORT X509_STORE_CTX_get_crl_fn
  1795. X509_STORE_get_get_crl(X509_STORE *ctx);
  1796. OPENSSL_EXPORT void X509_STORE_set_check_crl(
  1797. X509_STORE *ctx, X509_STORE_CTX_check_crl_fn check_crl);
  1798. OPENSSL_EXPORT X509_STORE_CTX_check_crl_fn
  1799. X509_STORE_get_check_crl(X509_STORE *ctx);
  1800. OPENSSL_EXPORT void X509_STORE_set_cert_crl(
  1801. X509_STORE *ctx, X509_STORE_CTX_cert_crl_fn cert_crl);
  1802. OPENSSL_EXPORT X509_STORE_CTX_cert_crl_fn
  1803. X509_STORE_get_cert_crl(X509_STORE *ctx);
  1804. OPENSSL_EXPORT void X509_STORE_set_lookup_certs(
  1805. X509_STORE *ctx, X509_STORE_CTX_lookup_certs_fn lookup_certs);
  1806. OPENSSL_EXPORT X509_STORE_CTX_lookup_certs_fn
  1807. X509_STORE_get_lookup_certs(X509_STORE *ctx);
  1808. OPENSSL_EXPORT void X509_STORE_set_lookup_crls(
  1809. X509_STORE *ctx, X509_STORE_CTX_lookup_crls_fn lookup_crls);
  1810. #define X509_STORE_set_lookup_crls_cb(ctx, func) \
  1811. X509_STORE_set_lookup_crls((ctx), (func))
  1812. OPENSSL_EXPORT X509_STORE_CTX_lookup_crls_fn
  1813. X509_STORE_get_lookup_crls(X509_STORE *ctx);
  1814. OPENSSL_EXPORT void X509_STORE_set_cleanup(X509_STORE *ctx,
  1815. X509_STORE_CTX_cleanup_fn cleanup);
  1816. OPENSSL_EXPORT X509_STORE_CTX_cleanup_fn
  1817. X509_STORE_get_cleanup(X509_STORE *ctx);
  1818. OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void);
  1819. OPENSSL_EXPORT int X509_STORE_CTX_get1_issuer(X509 **issuer,
  1820. X509_STORE_CTX *ctx, X509 *x);
  1821. OPENSSL_EXPORT void X509_STORE_CTX_zero(X509_STORE_CTX *ctx);
  1822. OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx);
  1823. OPENSSL_EXPORT int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
  1824. X509 *x509, STACK_OF(X509) *chain);
  1825. OPENSSL_EXPORT void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx,
  1826. STACK_OF(X509) *sk);
  1827. OPENSSL_EXPORT void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
  1828. OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx);
  1829. OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx);
  1830. OPENSSL_EXPORT X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v,
  1831. X509_LOOKUP_METHOD *m);
  1832. OPENSSL_EXPORT X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
  1833. OPENSSL_EXPORT X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
  1834. OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
  1835. OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
  1836. OPENSSL_EXPORT int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type,
  1837. X509_NAME *name, X509_OBJECT *ret);
  1838. OPENSSL_EXPORT int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
  1839. long argl, char **ret);
  1840. #ifndef OPENSSL_NO_STDIO
  1841. OPENSSL_EXPORT int X509_load_cert_file(X509_LOOKUP *ctx, const char *file,
  1842. int type);
  1843. OPENSSL_EXPORT int X509_load_crl_file(X509_LOOKUP *ctx, const char *file,
  1844. int type);
  1845. OPENSSL_EXPORT int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file,
  1846. int type);
  1847. #endif
  1848. OPENSSL_EXPORT X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
  1849. OPENSSL_EXPORT void X509_LOOKUP_free(X509_LOOKUP *ctx);
  1850. OPENSSL_EXPORT int X509_LOOKUP_init(X509_LOOKUP *ctx);
  1851. OPENSSL_EXPORT int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type,
  1852. X509_NAME *name, X509_OBJECT *ret);
  1853. OPENSSL_EXPORT int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type,
  1854. X509_NAME *name,
  1855. ASN1_INTEGER *serial,
  1856. X509_OBJECT *ret);
  1857. OPENSSL_EXPORT int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
  1858. unsigned char *bytes, int len,
  1859. X509_OBJECT *ret);
  1860. OPENSSL_EXPORT int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
  1861. int len, X509_OBJECT *ret);
  1862. OPENSSL_EXPORT int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
  1863. #ifndef OPENSSL_NO_STDIO
  1864. OPENSSL_EXPORT int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
  1865. const char *dir);
  1866. OPENSSL_EXPORT int X509_STORE_set_default_paths(X509_STORE *ctx);
  1867. #endif
  1868. OPENSSL_EXPORT int X509_STORE_CTX_get_ex_new_index(long argl, void *argp,
  1869. CRYPTO_EX_unused *unused,
  1870. CRYPTO_EX_dup *dup_unused,
  1871. CRYPTO_EX_free *free_func);
  1872. OPENSSL_EXPORT int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx,
  1873. void *data);
  1874. OPENSSL_EXPORT void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx);
  1875. OPENSSL_EXPORT int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
  1876. OPENSSL_EXPORT void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s);
  1877. OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
  1878. OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
  1879. OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx);
  1880. OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx);
  1881. OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(
  1882. X509_STORE_CTX *ctx);
  1883. OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
  1884. OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx);
  1885. OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
  1886. OPENSSL_EXPORT void X509_STORE_CTX_set_cert(X509_STORE_CTX *c, X509 *x);
  1887. OPENSSL_EXPORT void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,
  1888. STACK_OF(X509) *sk);
  1889. OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(
  1890. X509_STORE_CTX *ctx);
  1891. OPENSSL_EXPORT void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c,
  1892. STACK_OF(X509_CRL) *sk);
  1893. OPENSSL_EXPORT int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
  1894. OPENSSL_EXPORT int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
  1895. OPENSSL_EXPORT int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx,
  1896. int def_purpose, int purpose,
  1897. int trust);
  1898. OPENSSL_EXPORT void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx,
  1899. unsigned long flags);
  1900. OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx,
  1901. unsigned long flags, time_t t);
  1902. OPENSSL_EXPORT void X509_STORE_CTX_set_verify_cb(
  1903. X509_STORE_CTX *ctx, int (*verify_cb)(int, X509_STORE_CTX *));
  1904. OPENSSL_EXPORT X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(
  1905. X509_STORE_CTX *ctx);
  1906. OPENSSL_EXPORT int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx);
  1907. OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(
  1908. X509_STORE_CTX *ctx);
  1909. OPENSSL_EXPORT void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx,
  1910. X509_VERIFY_PARAM *param);
  1911. OPENSSL_EXPORT int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx,
  1912. const char *name);
  1913. // X509_VERIFY_PARAM functions
  1914. OPENSSL_EXPORT X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void);
  1915. OPENSSL_EXPORT void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param);
  1916. OPENSSL_EXPORT int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to,
  1917. const X509_VERIFY_PARAM *from);
  1918. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to,
  1919. const X509_VERIFY_PARAM *from);
  1920. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param,
  1921. const char *name);
  1922. OPENSSL_EXPORT int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param,
  1923. unsigned long flags);
  1924. OPENSSL_EXPORT int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,
  1925. unsigned long flags);
  1926. OPENSSL_EXPORT unsigned long X509_VERIFY_PARAM_get_flags(
  1927. X509_VERIFY_PARAM *param);
  1928. OPENSSL_EXPORT int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param,
  1929. int purpose);
  1930. OPENSSL_EXPORT int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param,
  1931. int trust);
  1932. OPENSSL_EXPORT void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param,
  1933. int depth);
  1934. OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param,
  1935. time_t t);
  1936. OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,
  1937. ASN1_OBJECT *policy);
  1938. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_policies(
  1939. X509_VERIFY_PARAM *param, STACK_OF(ASN1_OBJECT) *policies);
  1940. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param,
  1941. const char *name,
  1942. size_t namelen);
  1943. OPENSSL_EXPORT int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param,
  1944. const char *name,
  1945. size_t namelen);
  1946. OPENSSL_EXPORT void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
  1947. unsigned int flags);
  1948. OPENSSL_EXPORT char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *);
  1949. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param,
  1950. const char *email,
  1951. size_t emaillen);
  1952. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param,
  1953. const unsigned char *ip,
  1954. size_t iplen);
  1955. OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param,
  1956. const char *ipasc);
  1957. OPENSSL_EXPORT int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param);
  1958. OPENSSL_EXPORT const char *X509_VERIFY_PARAM_get0_name(
  1959. const X509_VERIFY_PARAM *param);
  1960. OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param);
  1961. OPENSSL_EXPORT int X509_VERIFY_PARAM_get_count(void);
  1962. OPENSSL_EXPORT const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id);
  1963. OPENSSL_EXPORT const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(
  1964. const char *name);
  1965. OPENSSL_EXPORT void X509_VERIFY_PARAM_table_cleanup(void);
  1966. OPENSSL_EXPORT int X509_policy_check(X509_POLICY_TREE **ptree,
  1967. int *pexplicit_policy,
  1968. STACK_OF(X509) *certs,
  1969. STACK_OF(ASN1_OBJECT) *policy_oids,
  1970. unsigned int flags);
  1971. OPENSSL_EXPORT void X509_policy_tree_free(X509_POLICY_TREE *tree);
  1972. OPENSSL_EXPORT int X509_policy_tree_level_count(const X509_POLICY_TREE *tree);
  1973. OPENSSL_EXPORT X509_POLICY_LEVEL *X509_policy_tree_get0_level(
  1974. const X509_POLICY_TREE *tree, int i);
  1975. OPENSSL_EXPORT STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(
  1976. const X509_POLICY_TREE *tree);
  1977. OPENSSL_EXPORT STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(
  1978. const X509_POLICY_TREE *tree);
  1979. OPENSSL_EXPORT int X509_policy_level_node_count(X509_POLICY_LEVEL *level);
  1980. OPENSSL_EXPORT X509_POLICY_NODE *X509_policy_level_get0_node(
  1981. X509_POLICY_LEVEL *level, int i);
  1982. OPENSSL_EXPORT const ASN1_OBJECT *X509_policy_node_get0_policy(
  1983. const X509_POLICY_NODE *node);
  1984. OPENSSL_EXPORT STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(
  1985. const X509_POLICY_NODE *node);
  1986. OPENSSL_EXPORT const X509_POLICY_NODE *X509_policy_node_get0_parent(
  1987. const X509_POLICY_NODE *node);
  1988. #if defined(__cplusplus)
  1989. } // extern C
  1990. #endif
  1991. #if !defined(BORINGSSL_NO_CXX)
  1992. extern "C++" {
  1993. BSSL_NAMESPACE_BEGIN
  1994. BORINGSSL_MAKE_DELETER(NETSCAPE_SPKI, NETSCAPE_SPKI_free)
  1995. BORINGSSL_MAKE_DELETER(RSA_PSS_PARAMS, RSA_PSS_PARAMS_free)
  1996. BORINGSSL_MAKE_DELETER(X509, X509_free)
  1997. BORINGSSL_MAKE_UP_REF(X509, X509_up_ref)
  1998. BORINGSSL_MAKE_DELETER(X509_ALGOR, X509_ALGOR_free)
  1999. BORINGSSL_MAKE_DELETER(X509_ATTRIBUTE, X509_ATTRIBUTE_free)
  2000. BORINGSSL_MAKE_DELETER(X509_CRL, X509_CRL_free)
  2001. BORINGSSL_MAKE_UP_REF(X509_CRL, X509_CRL_up_ref)
  2002. BORINGSSL_MAKE_DELETER(X509_EXTENSION, X509_EXTENSION_free)
  2003. BORINGSSL_MAKE_DELETER(X509_INFO, X509_INFO_free)
  2004. BORINGSSL_MAKE_DELETER(X509_LOOKUP, X509_LOOKUP_free)
  2005. BORINGSSL_MAKE_DELETER(X509_NAME, X509_NAME_free)
  2006. BORINGSSL_MAKE_DELETER(X509_NAME_ENTRY, X509_NAME_ENTRY_free)
  2007. BORINGSSL_MAKE_DELETER(X509_PKEY, X509_PKEY_free)
  2008. BORINGSSL_MAKE_DELETER(X509_POLICY_TREE, X509_policy_tree_free)
  2009. BORINGSSL_MAKE_DELETER(X509_PUBKEY, X509_PUBKEY_free)
  2010. BORINGSSL_MAKE_DELETER(X509_REQ, X509_REQ_free)
  2011. BORINGSSL_MAKE_DELETER(X509_REVOKED, X509_REVOKED_free)
  2012. BORINGSSL_MAKE_DELETER(X509_SIG, X509_SIG_free)
  2013. BORINGSSL_MAKE_DELETER(X509_STORE, X509_STORE_free)
  2014. BORINGSSL_MAKE_UP_REF(X509_STORE, X509_STORE_up_ref)
  2015. BORINGSSL_MAKE_DELETER(X509_STORE_CTX, X509_STORE_CTX_free)
  2016. BORINGSSL_MAKE_DELETER(X509_VERIFY_PARAM, X509_VERIFY_PARAM_free)
  2017. BSSL_NAMESPACE_END
  2018. } // extern C++
  2019. #endif // !BORINGSSL_NO_CXX
  2020. #define X509_R_AKID_MISMATCH 100
  2021. #define X509_R_BAD_PKCS7_VERSION 101
  2022. #define X509_R_BAD_X509_FILETYPE 102
  2023. #define X509_R_BASE64_DECODE_ERROR 103
  2024. #define X509_R_CANT_CHECK_DH_KEY 104
  2025. #define X509_R_CERT_ALREADY_IN_HASH_TABLE 105
  2026. #define X509_R_CRL_ALREADY_DELTA 106
  2027. #define X509_R_CRL_VERIFY_FAILURE 107
  2028. #define X509_R_IDP_MISMATCH 108
  2029. #define X509_R_INVALID_BIT_STRING_BITS_LEFT 109
  2030. #define X509_R_INVALID_DIRECTORY 110
  2031. #define X509_R_INVALID_FIELD_NAME 111
  2032. #define X509_R_INVALID_PSS_PARAMETERS 112
  2033. #define X509_R_INVALID_TRUST 113
  2034. #define X509_R_ISSUER_MISMATCH 114
  2035. #define X509_R_KEY_TYPE_MISMATCH 115
  2036. #define X509_R_KEY_VALUES_MISMATCH 116
  2037. #define X509_R_LOADING_CERT_DIR 117
  2038. #define X509_R_LOADING_DEFAULTS 118
  2039. #define X509_R_NEWER_CRL_NOT_NEWER 119
  2040. #define X509_R_NOT_PKCS7_SIGNED_DATA 120
  2041. #define X509_R_NO_CERTIFICATES_INCLUDED 121
  2042. #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 122
  2043. #define X509_R_NO_CRLS_INCLUDED 123
  2044. #define X509_R_NO_CRL_NUMBER 124
  2045. #define X509_R_PUBLIC_KEY_DECODE_ERROR 125
  2046. #define X509_R_PUBLIC_KEY_ENCODE_ERROR 126
  2047. #define X509_R_SHOULD_RETRY 127
  2048. #define X509_R_UNKNOWN_KEY_TYPE 128
  2049. #define X509_R_UNKNOWN_NID 129
  2050. #define X509_R_UNKNOWN_PURPOSE_ID 130
  2051. #define X509_R_UNKNOWN_TRUST_ID 131
  2052. #define X509_R_UNSUPPORTED_ALGORITHM 132
  2053. #define X509_R_WRONG_LOOKUP_TYPE 133
  2054. #define X509_R_WRONG_TYPE 134
  2055. #define X509_R_NAME_TOO_LONG 135
  2056. #define X509_R_INVALID_PARAMETER 136
  2057. #define X509_R_SIGNATURE_ALGORITHM_MISMATCH 137
  2058. #define X509_R_DELTA_CRL_WITHOUT_CRL_NUMBER 138
  2059. #define X509_R_INVALID_FIELD_FOR_VERSION 139
  2060. #define X509_R_INVALID_VERSION 140
  2061. #define X509_R_NO_CERTIFICATE_FOUND 141
  2062. #define X509_R_NO_CERTIFICATE_OR_CRL_FOUND 142
  2063. #define X509_R_NO_CRL_FOUND 143
  2064. #endif