x509.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /* crypto/x509/x509.h */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. /* ====================================================================
  59. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  60. * ECDH support in OpenSSL originally developed by
  61. * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  62. */
  63. #ifndef HEADER_X509_H
  64. #define HEADER_X509_H
  65. #include <openssl/e_os2.h>
  66. #include <openssl/symhacks.h>
  67. #ifndef OPENSSL_NO_BUFFER
  68. #include <openssl/buffer.h>
  69. #endif
  70. #ifndef OPENSSL_NO_EVP
  71. #include <openssl/evp.h>
  72. #endif
  73. #ifndef OPENSSL_NO_BIO
  74. #include <openssl/bio.h>
  75. #endif
  76. #include <openssl/stack.h>
  77. #include <openssl/asn1.h>
  78. #include <openssl/safestack.h>
  79. #ifndef OPENSSL_NO_EC
  80. #include <openssl/ec.h>
  81. #endif
  82. #ifndef OPENSSL_NO_ECDSA
  83. #include <openssl/ecdsa.h>
  84. #endif
  85. #ifndef OPENSSL_NO_ECDH
  86. #include <openssl/ecdh.h>
  87. #endif
  88. #ifndef OPENSSL_NO_DEPRECATED
  89. #ifndef OPENSSL_NO_RSA
  90. #include <openssl/rsa.h>
  91. #endif
  92. #ifndef OPENSSL_NO_DSA
  93. #include <openssl/dsa.h>
  94. #endif
  95. #ifndef OPENSSL_NO_DH
  96. #include <openssl/dh.h>
  97. #endif
  98. #endif
  99. #ifndef OPENSSL_NO_SHA
  100. #include <openssl/sha.h>
  101. #endif
  102. #include <openssl/ossl_typ.h>
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. #ifdef OPENSSL_SYS_WIN32
  107. /* Under Win32 these are defined in wincrypt.h */
  108. #undef X509_NAME
  109. #undef X509_CERT_PAIR
  110. #endif
  111. #define X509_FILETYPE_PEM 1
  112. #define X509_FILETYPE_ASN1 2
  113. #define X509_FILETYPE_DEFAULT 3
  114. #define X509v3_KU_DIGITAL_SIGNATURE 0x0080
  115. #define X509v3_KU_NON_REPUDIATION 0x0040
  116. #define X509v3_KU_KEY_ENCIPHERMENT 0x0020
  117. #define X509v3_KU_DATA_ENCIPHERMENT 0x0010
  118. #define X509v3_KU_KEY_AGREEMENT 0x0008
  119. #define X509v3_KU_KEY_CERT_SIGN 0x0004
  120. #define X509v3_KU_CRL_SIGN 0x0002
  121. #define X509v3_KU_ENCIPHER_ONLY 0x0001
  122. #define X509v3_KU_DECIPHER_ONLY 0x8000
  123. #define X509v3_KU_UNDEF 0xffff
  124. typedef struct X509_objects_st
  125. {
  126. int nid;
  127. int (*a2i)(void);
  128. int (*i2a)(void);
  129. } X509_OBJECTS;
  130. struct X509_algor_st
  131. {
  132. ASN1_OBJECT *algorithm;
  133. ASN1_TYPE *parameter;
  134. } /* X509_ALGOR */;
  135. DECLARE_ASN1_SET_OF(X509_ALGOR)
  136. typedef STACK_OF(X509_ALGOR) X509_ALGORS;
  137. typedef struct X509_val_st
  138. {
  139. ASN1_TIME *notBefore;
  140. ASN1_TIME *notAfter;
  141. } X509_VAL;
  142. struct X509_pubkey_st
  143. {
  144. X509_ALGOR *algor;
  145. ASN1_BIT_STRING *public_key;
  146. EVP_PKEY *pkey;
  147. };
  148. typedef struct X509_sig_st
  149. {
  150. X509_ALGOR *algor;
  151. ASN1_OCTET_STRING *digest;
  152. } X509_SIG;
  153. typedef struct X509_name_entry_st
  154. {
  155. ASN1_OBJECT *object;
  156. ASN1_STRING *value;
  157. int set;
  158. int size; /* temp variable */
  159. } X509_NAME_ENTRY;
  160. DECLARE_STACK_OF(X509_NAME_ENTRY)
  161. DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
  162. /* we always keep X509_NAMEs in 2 forms. */
  163. struct X509_name_st
  164. {
  165. STACK_OF(X509_NAME_ENTRY) *entries;
  166. int modified; /* true if 'bytes' needs to be built */
  167. #ifndef OPENSSL_NO_BUFFER
  168. BUF_MEM *bytes;
  169. #else
  170. char *bytes;
  171. #endif
  172. /* unsigned long hash; Keep the hash around for lookups */
  173. unsigned char *canon_enc;
  174. int canon_enclen;
  175. } /* X509_NAME */;
  176. DECLARE_STACK_OF(X509_NAME)
  177. #define X509_EX_V_NETSCAPE_HACK 0x8000
  178. #define X509_EX_V_INIT 0x0001
  179. typedef struct X509_extension_st
  180. {
  181. ASN1_OBJECT *object;
  182. ASN1_BOOLEAN critical;
  183. ASN1_OCTET_STRING *value;
  184. } X509_EXTENSION;
  185. typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS;
  186. DECLARE_STACK_OF(X509_EXTENSION)
  187. DECLARE_ASN1_SET_OF(X509_EXTENSION)
  188. /* a sequence of these are used */
  189. typedef struct x509_attributes_st
  190. {
  191. ASN1_OBJECT *object;
  192. int single; /* 0 for a set, 1 for a single item (which is wrong) */
  193. union {
  194. char *ptr;
  195. /* 0 */ STACK_OF(ASN1_TYPE) *set;
  196. /* 1 */ ASN1_TYPE *single;
  197. } value;
  198. } X509_ATTRIBUTE;
  199. DECLARE_STACK_OF(X509_ATTRIBUTE)
  200. DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
  201. typedef struct X509_req_info_st
  202. {
  203. ASN1_ENCODING enc;
  204. ASN1_INTEGER *version;
  205. X509_NAME *subject;
  206. X509_PUBKEY *pubkey;
  207. /* d=2 hl=2 l= 0 cons: cont: 00 */
  208. STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
  209. } X509_REQ_INFO;
  210. typedef struct X509_req_st
  211. {
  212. X509_REQ_INFO *req_info;
  213. X509_ALGOR *sig_alg;
  214. ASN1_BIT_STRING *signature;
  215. int references;
  216. } X509_REQ;
  217. typedef struct x509_cinf_st
  218. {
  219. ASN1_INTEGER *version; /* [ 0 ] default of v1 */
  220. ASN1_INTEGER *serialNumber;
  221. X509_ALGOR *signature;
  222. X509_NAME *issuer;
  223. X509_VAL *validity;
  224. X509_NAME *subject;
  225. X509_PUBKEY *key;
  226. ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
  227. ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
  228. STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
  229. } X509_CINF;
  230. /* This stuff is certificate "auxiliary info"
  231. * it contains details which are useful in certificate
  232. * stores and databases. When used this is tagged onto
  233. * the end of the certificate itself
  234. */
  235. typedef struct x509_cert_aux_st
  236. {
  237. STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
  238. STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
  239. ASN1_UTF8STRING *alias; /* "friendly name" */
  240. ASN1_OCTET_STRING *keyid; /* key id of private key */
  241. STACK_OF(X509_ALGOR) *other; /* other unspecified info */
  242. } X509_CERT_AUX;
  243. struct x509_st
  244. {
  245. X509_CINF *cert_info;
  246. X509_ALGOR *sig_alg;
  247. ASN1_BIT_STRING *signature;
  248. int valid;
  249. int references;
  250. char *name;
  251. CRYPTO_EX_DATA ex_data;
  252. /* These contain copies of various extension values */
  253. long ex_pathlen;
  254. long ex_pcpathlen;
  255. unsigned long ex_flags;
  256. unsigned long ex_kusage;
  257. unsigned long ex_xkusage;
  258. unsigned long ex_nscert;
  259. ASN1_OCTET_STRING *skid;
  260. AUTHORITY_KEYID *akid;
  261. X509_POLICY_CACHE *policy_cache;
  262. STACK_OF(DIST_POINT) *crldp;
  263. #ifndef OPENSSL_NO_RFC3779
  264. STACK_OF(IPAddressFamily) *rfc3779_addr;
  265. struct ASIdentifiers_st *rfc3779_asid;
  266. #endif
  267. #ifndef OPENSSL_NO_SHA
  268. unsigned char sha1_hash[SHA_DIGEST_LENGTH];
  269. #endif
  270. X509_CERT_AUX *aux;
  271. } /* X509 */;
  272. DECLARE_STACK_OF(X509)
  273. DECLARE_ASN1_SET_OF(X509)
  274. /* This is used for a table of trust checking functions */
  275. typedef struct x509_trust_st {
  276. int trust;
  277. int flags;
  278. int (*check_trust)(struct x509_trust_st *, X509 *, int);
  279. char *name;
  280. int arg1;
  281. void *arg2;
  282. } X509_TRUST;
  283. DECLARE_STACK_OF(X509_TRUST)
  284. typedef struct x509_cert_pair_st {
  285. X509 *forward;
  286. X509 *reverse;
  287. } X509_CERT_PAIR;
  288. /* standard trust ids */
  289. #define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */
  290. #define X509_TRUST_COMPAT 1
  291. #define X509_TRUST_SSL_CLIENT 2
  292. #define X509_TRUST_SSL_SERVER 3
  293. #define X509_TRUST_EMAIL 4
  294. #define X509_TRUST_OBJECT_SIGN 5
  295. #define X509_TRUST_OCSP_SIGN 6
  296. #define X509_TRUST_OCSP_REQUEST 7
  297. #define X509_TRUST_TSA 8
  298. /* Keep these up to date! */
  299. #define X509_TRUST_MIN 1
  300. #define X509_TRUST_MAX 8
  301. /* trust_flags values */
  302. #define X509_TRUST_DYNAMIC 1
  303. #define X509_TRUST_DYNAMIC_NAME 2
  304. /* check_trust return codes */
  305. #define X509_TRUST_TRUSTED 1
  306. #define X509_TRUST_REJECTED 2
  307. #define X509_TRUST_UNTRUSTED 3
  308. /* Flags for X509_print_ex() */
  309. #define X509_FLAG_COMPAT 0
  310. #define X509_FLAG_NO_HEADER 1L
  311. #define X509_FLAG_NO_VERSION (1L << 1)
  312. #define X509_FLAG_NO_SERIAL (1L << 2)
  313. #define X509_FLAG_NO_SIGNAME (1L << 3)
  314. #define X509_FLAG_NO_ISSUER (1L << 4)
  315. #define X509_FLAG_NO_VALIDITY (1L << 5)
  316. #define X509_FLAG_NO_SUBJECT (1L << 6)
  317. #define X509_FLAG_NO_PUBKEY (1L << 7)
  318. #define X509_FLAG_NO_EXTENSIONS (1L << 8)
  319. #define X509_FLAG_NO_SIGDUMP (1L << 9)
  320. #define X509_FLAG_NO_AUX (1L << 10)
  321. #define X509_FLAG_NO_ATTRIBUTES (1L << 11)
  322. /* Flags specific to X509_NAME_print_ex() */
  323. /* The field separator information */
  324. #define XN_FLAG_SEP_MASK (0xf << 16)
  325. #define XN_FLAG_COMPAT 0 /* Traditional SSLeay: use old X509_NAME_print */
  326. #define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */
  327. #define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */
  328. #define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */
  329. #define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */
  330. #define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */
  331. /* How the field name is shown */
  332. #define XN_FLAG_FN_MASK (0x3 << 21)
  333. #define XN_FLAG_FN_SN 0 /* Object short name */
  334. #define XN_FLAG_FN_LN (1 << 21) /* Object long name */
  335. #define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */
  336. #define XN_FLAG_FN_NONE (3 << 21) /* No field names */
  337. #define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */
  338. /* This determines if we dump fields we don't recognise:
  339. * RFC2253 requires this.
  340. */
  341. #define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24)
  342. #define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 characters */
  343. /* Complete set of RFC2253 flags */
  344. #define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \
  345. XN_FLAG_SEP_COMMA_PLUS | \
  346. XN_FLAG_DN_REV | \
  347. XN_FLAG_FN_SN | \
  348. XN_FLAG_DUMP_UNKNOWN_FIELDS)
  349. /* readable oneline form */
  350. #define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \
  351. ASN1_STRFLGS_ESC_QUOTE | \
  352. XN_FLAG_SEP_CPLUS_SPC | \
  353. XN_FLAG_SPC_EQ | \
  354. XN_FLAG_FN_SN)
  355. /* readable multiline form */
  356. #define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \
  357. ASN1_STRFLGS_ESC_MSB | \
  358. XN_FLAG_SEP_MULTILINE | \
  359. XN_FLAG_SPC_EQ | \
  360. XN_FLAG_FN_LN | \
  361. XN_FLAG_FN_ALIGN)
  362. struct x509_revoked_st
  363. {
  364. ASN1_INTEGER *serialNumber;
  365. ASN1_TIME *revocationDate;
  366. STACK_OF(X509_EXTENSION) /* optional */ *extensions;
  367. int sequence; /* load sequence */
  368. };
  369. DECLARE_STACK_OF(X509_REVOKED)
  370. DECLARE_ASN1_SET_OF(X509_REVOKED)
  371. typedef struct X509_crl_info_st
  372. {
  373. ASN1_INTEGER *version;
  374. X509_ALGOR *sig_alg;
  375. X509_NAME *issuer;
  376. ASN1_TIME *lastUpdate;
  377. ASN1_TIME *nextUpdate;
  378. STACK_OF(X509_REVOKED) *revoked;
  379. STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
  380. ASN1_ENCODING enc;
  381. } X509_CRL_INFO;
  382. struct X509_crl_st
  383. {
  384. /* actual signature */
  385. X509_CRL_INFO *crl;
  386. X509_ALGOR *sig_alg;
  387. ASN1_BIT_STRING *signature;
  388. int references;
  389. int flags;
  390. /* Copies of various extensions */
  391. AUTHORITY_KEYID *akid;
  392. ISSUING_DIST_POINT *idp;
  393. /* Convenient breakdown of IDP */
  394. int idp_flags;
  395. int idp_reasons;
  396. #ifndef OPENSSL_NO_SHA
  397. unsigned char sha1_hash[SHA_DIGEST_LENGTH];
  398. #endif
  399. const X509_CRL_METHOD *meth;
  400. void *meth_data;
  401. } /* X509_CRL */;
  402. DECLARE_STACK_OF(X509_CRL)
  403. DECLARE_ASN1_SET_OF(X509_CRL)
  404. typedef struct private_key_st
  405. {
  406. int version;
  407. /* The PKCS#8 data types */
  408. X509_ALGOR *enc_algor;
  409. ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */
  410. /* When decrypted, the following will not be NULL */
  411. EVP_PKEY *dec_pkey;
  412. /* used to encrypt and decrypt */
  413. int key_length;
  414. char *key_data;
  415. int key_free; /* true if we should auto free key_data */
  416. /* expanded version of 'enc_algor' */
  417. EVP_CIPHER_INFO cipher;
  418. int references;
  419. } X509_PKEY;
  420. #ifndef OPENSSL_NO_EVP
  421. typedef struct X509_info_st
  422. {
  423. X509 *x509;
  424. X509_CRL *crl;
  425. X509_PKEY *x_pkey;
  426. EVP_CIPHER_INFO enc_cipher;
  427. int enc_len;
  428. char *enc_data;
  429. int references;
  430. } X509_INFO;
  431. DECLARE_STACK_OF(X509_INFO)
  432. #endif
  433. /* The next 2 structures and their 8 routines were sent to me by
  434. * Pat Richard <patr@x509.com> and are used to manipulate
  435. * Netscapes spki structures - useful if you are writing a CA web page
  436. */
  437. typedef struct Netscape_spkac_st
  438. {
  439. X509_PUBKEY *pubkey;
  440. ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */
  441. } NETSCAPE_SPKAC;
  442. typedef struct Netscape_spki_st
  443. {
  444. NETSCAPE_SPKAC *spkac; /* signed public key and challenge */
  445. X509_ALGOR *sig_algor;
  446. ASN1_BIT_STRING *signature;
  447. } NETSCAPE_SPKI;
  448. /* Netscape certificate sequence structure */
  449. typedef struct Netscape_certificate_sequence
  450. {
  451. ASN1_OBJECT *type;
  452. STACK_OF(X509) *certs;
  453. } NETSCAPE_CERT_SEQUENCE;
  454. /* Unused (and iv length is wrong)
  455. typedef struct CBCParameter_st
  456. {
  457. unsigned char iv[8];
  458. } CBC_PARAM;
  459. */
  460. /* Password based encryption structure */
  461. typedef struct PBEPARAM_st {
  462. ASN1_OCTET_STRING *salt;
  463. ASN1_INTEGER *iter;
  464. } PBEPARAM;
  465. /* Password based encryption V2 structures */
  466. typedef struct PBE2PARAM_st {
  467. X509_ALGOR *keyfunc;
  468. X509_ALGOR *encryption;
  469. } PBE2PARAM;
  470. typedef struct PBKDF2PARAM_st {
  471. ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */
  472. ASN1_INTEGER *iter;
  473. ASN1_INTEGER *keylength;
  474. X509_ALGOR *prf;
  475. } PBKDF2PARAM;
  476. /* PKCS#8 private key info structure */
  477. struct pkcs8_priv_key_info_st
  478. {
  479. int broken; /* Flag for various broken formats */
  480. #define PKCS8_OK 0
  481. #define PKCS8_NO_OCTET 1
  482. #define PKCS8_EMBEDDED_PARAM 2
  483. #define PKCS8_NS_DB 3
  484. ASN1_INTEGER *version;
  485. X509_ALGOR *pkeyalg;
  486. ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
  487. STACK_OF(X509_ATTRIBUTE) *attributes;
  488. };
  489. #ifdef __cplusplus
  490. }
  491. #endif
  492. #include <openssl/x509_vfy.h>
  493. #include <openssl/pkcs7.h>
  494. #ifdef __cplusplus
  495. extern "C" {
  496. #endif
  497. #define X509_EXT_PACK_UNKNOWN 1
  498. #define X509_EXT_PACK_STRING 2
  499. #define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
  500. /* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
  501. #define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
  502. #define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
  503. #define X509_extract_key(x) X509_get_pubkey(x) /*****/
  504. #define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
  505. #define X509_REQ_get_subject_name(x) ((x)->req_info->subject)
  506. #define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
  507. #define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
  508. #define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
  509. #define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
  510. #define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
  511. #define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
  512. #define X509_CRL_get_issuer(x) ((x)->crl->issuer)
  513. #define X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
  514. void X509_CRL_set_default_method(const X509_CRL_METHOD *meth);
  515. X509_CRL_METHOD *X509_CRL_METHOD_new(
  516. int (*crl_init)(X509_CRL *crl),
  517. int (*crl_free)(X509_CRL *crl),
  518. int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, ASN1_INTEGER *ser),
  519. int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk));
  520. void X509_CRL_METHOD_free(X509_CRL_METHOD *m);
  521. void X509_CRL_set_meth_data(X509_CRL *crl, void *dat);
  522. void *X509_CRL_get_meth_data(X509_CRL *crl);
  523. /* This one is only used so that a binary form can output, as in
  524. * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
  525. #define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
  526. const char *X509_verify_cert_error_string(long n);
  527. #ifndef OPENSSL_NO_EVP
  528. int X509_verify(X509 *a, EVP_PKEY *r);
  529. int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
  530. int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
  531. int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
  532. NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
  533. char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
  534. EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
  535. int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
  536. int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
  537. int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig);
  538. int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
  539. int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
  540. int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
  541. int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
  542. int X509_pubkey_digest(const X509 *data,const EVP_MD *type,
  543. unsigned char *md, unsigned int *len);
  544. int X509_digest(const X509 *data,const EVP_MD *type,
  545. unsigned char *md, unsigned int *len);
  546. int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type,
  547. unsigned char *md, unsigned int *len);
  548. int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type,
  549. unsigned char *md, unsigned int *len);
  550. int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type,
  551. unsigned char *md, unsigned int *len);
  552. #endif
  553. #ifndef OPENSSL_NO_FP_API
  554. X509 *d2i_X509_fp(FILE *fp, X509 **x509);
  555. int i2d_X509_fp(FILE *fp,X509 *x509);
  556. X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
  557. int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
  558. X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
  559. int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
  560. #ifndef OPENSSL_NO_RSA
  561. RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
  562. int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
  563. RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
  564. int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
  565. RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
  566. int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
  567. #endif
  568. #ifndef OPENSSL_NO_DSA
  569. DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
  570. int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
  571. DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
  572. int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
  573. #endif
  574. #ifndef OPENSSL_NO_EC
  575. EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey);
  576. int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey);
  577. EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey);
  578. int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey);
  579. #endif
  580. X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
  581. int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
  582. PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
  583. PKCS8_PRIV_KEY_INFO **p8inf);
  584. int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
  585. int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
  586. int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
  587. EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
  588. int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey);
  589. EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a);
  590. #endif
  591. #ifndef OPENSSL_NO_BIO
  592. X509 *d2i_X509_bio(BIO *bp,X509 **x509);
  593. int i2d_X509_bio(BIO *bp,X509 *x509);
  594. X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
  595. int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
  596. X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
  597. int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
  598. #ifndef OPENSSL_NO_RSA
  599. RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
  600. int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
  601. RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
  602. int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
  603. RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
  604. int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
  605. #endif
  606. #ifndef OPENSSL_NO_DSA
  607. DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
  608. int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
  609. DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
  610. int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
  611. #endif
  612. #ifndef OPENSSL_NO_EC
  613. EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey);
  614. int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey);
  615. EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey);
  616. int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey);
  617. #endif
  618. X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
  619. int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
  620. PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
  621. PKCS8_PRIV_KEY_INFO **p8inf);
  622. int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
  623. int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
  624. int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
  625. EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
  626. int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);
  627. EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);
  628. #endif
  629. X509 *X509_dup(X509 *x509);
  630. X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
  631. X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
  632. X509_CRL *X509_CRL_dup(X509_CRL *crl);
  633. X509_REQ *X509_REQ_dup(X509_REQ *req);
  634. X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
  635. int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval);
  636. void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
  637. X509_ALGOR *algor);
  638. X509_NAME *X509_NAME_dup(X509_NAME *xn);
  639. X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
  640. int X509_cmp_time(const ASN1_TIME *s, time_t *t);
  641. int X509_cmp_current_time(const ASN1_TIME *s);
  642. ASN1_TIME * X509_time_adj(ASN1_TIME *s, long adj, time_t *t);
  643. ASN1_TIME * X509_gmtime_adj(ASN1_TIME *s, long adj);
  644. const char * X509_get_default_cert_area(void );
  645. const char * X509_get_default_cert_dir(void );
  646. const char * X509_get_default_cert_file(void );
  647. const char * X509_get_default_cert_dir_env(void );
  648. const char * X509_get_default_cert_file_env(void );
  649. const char * X509_get_default_private_dir(void );
  650. X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
  651. X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
  652. DECLARE_ASN1_FUNCTIONS(X509_ALGOR)
  653. DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS)
  654. DECLARE_ASN1_FUNCTIONS(X509_VAL)
  655. DECLARE_ASN1_FUNCTIONS(X509_PUBKEY)
  656. int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
  657. EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
  658. int X509_get_pubkey_parameters(EVP_PKEY *pkey,
  659. STACK_OF(X509) *chain);
  660. int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
  661. EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp,
  662. long length);
  663. #ifndef OPENSSL_NO_RSA
  664. int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
  665. RSA * d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp,
  666. long length);
  667. #endif
  668. #ifndef OPENSSL_NO_DSA
  669. int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
  670. DSA * d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp,
  671. long length);
  672. #endif
  673. #ifndef OPENSSL_NO_EC
  674. int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp);
  675. EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp,
  676. long length);
  677. #endif
  678. DECLARE_ASN1_FUNCTIONS(X509_SIG)
  679. DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO)
  680. DECLARE_ASN1_FUNCTIONS(X509_REQ)
  681. DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE)
  682. X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
  683. DECLARE_ASN1_FUNCTIONS(X509_EXTENSION)
  684. DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
  685. DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY)
  686. DECLARE_ASN1_FUNCTIONS(X509_NAME)
  687. int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
  688. DECLARE_ASN1_FUNCTIONS(X509_CINF)
  689. DECLARE_ASN1_FUNCTIONS(X509)
  690. DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)
  691. DECLARE_ASN1_FUNCTIONS(X509_CERT_PAIR)
  692. int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
  693. CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
  694. int X509_set_ex_data(X509 *r, int idx, void *arg);
  695. void *X509_get_ex_data(X509 *r, int idx);
  696. int i2d_X509_AUX(X509 *a,unsigned char **pp);
  697. X509 * d2i_X509_AUX(X509 **a,const unsigned char **pp,long length);
  698. int X509_alias_set1(X509 *x, unsigned char *name, int len);
  699. int X509_keyid_set1(X509 *x, unsigned char *id, int len);
  700. unsigned char * X509_alias_get0(X509 *x, int *len);
  701. unsigned char * X509_keyid_get0(X509 *x, int *len);
  702. int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
  703. int X509_TRUST_set(int *t, int trust);
  704. int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
  705. int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
  706. void X509_trust_clear(X509 *x);
  707. void X509_reject_clear(X509 *x);
  708. DECLARE_ASN1_FUNCTIONS(X509_REVOKED)
  709. DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO)
  710. DECLARE_ASN1_FUNCTIONS(X509_CRL)
  711. int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
  712. int X509_CRL_get0_by_serial(X509_CRL *crl,
  713. X509_REVOKED **ret, ASN1_INTEGER *serial);
  714. X509_PKEY * X509_PKEY_new(void );
  715. void X509_PKEY_free(X509_PKEY *a);
  716. int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
  717. X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,const unsigned char **pp,long length);
  718. DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)
  719. DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
  720. DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE)
  721. #ifndef OPENSSL_NO_EVP
  722. X509_INFO * X509_INFO_new(void);
  723. void X509_INFO_free(X509_INFO *a);
  724. char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
  725. int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1,
  726. ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
  727. int ASN1_digest(i2d_of_void *i2d,const EVP_MD *type,char *data,
  728. unsigned char *md,unsigned int *len);
  729. int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1,
  730. X509_ALGOR *algor2, ASN1_BIT_STRING *signature,
  731. char *data,EVP_PKEY *pkey, const EVP_MD *type);
  732. int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,
  733. unsigned char *md,unsigned int *len);
  734. int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1,
  735. ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey);
  736. int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
  737. ASN1_BIT_STRING *signature,
  738. void *data, EVP_PKEY *pkey, const EVP_MD *type);
  739. #endif
  740. int X509_set_version(X509 *x,long version);
  741. int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
  742. ASN1_INTEGER * X509_get_serialNumber(X509 *x);
  743. int X509_set_issuer_name(X509 *x, X509_NAME *name);
  744. X509_NAME * X509_get_issuer_name(X509 *a);
  745. int X509_set_subject_name(X509 *x, X509_NAME *name);
  746. X509_NAME * X509_get_subject_name(X509 *a);
  747. int X509_set_notBefore(X509 *x, const ASN1_TIME *tm);
  748. int X509_set_notAfter(X509 *x, const ASN1_TIME *tm);
  749. int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
  750. EVP_PKEY * X509_get_pubkey(X509 *x);
  751. ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x);
  752. int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
  753. int X509_REQ_set_version(X509_REQ *x,long version);
  754. int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
  755. int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
  756. EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
  757. int X509_REQ_extension_nid(int nid);
  758. int * X509_REQ_get_extension_nids(void);
  759. void X509_REQ_set_extension_nids(int *nids);
  760. STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
  761. int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
  762. int nid);
  763. int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
  764. int X509_REQ_get_attr_count(const X509_REQ *req);
  765. int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
  766. int lastpos);
  767. int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
  768. int lastpos);
  769. X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
  770. X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
  771. int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
  772. int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
  773. const ASN1_OBJECT *obj, int type,
  774. const unsigned char *bytes, int len);
  775. int X509_REQ_add1_attr_by_NID(X509_REQ *req,
  776. int nid, int type,
  777. const unsigned char *bytes, int len);
  778. int X509_REQ_add1_attr_by_txt(X509_REQ *req,
  779. const char *attrname, int type,
  780. const unsigned char *bytes, int len);
  781. int X509_CRL_set_version(X509_CRL *x, long version);
  782. int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
  783. int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm);
  784. int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm);
  785. int X509_CRL_sort(X509_CRL *crl);
  786. int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
  787. int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);
  788. int X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey);
  789. int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
  790. int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
  791. unsigned long X509_issuer_and_serial_hash(X509 *a);
  792. int X509_issuer_name_cmp(const X509 *a, const X509 *b);
  793. unsigned long X509_issuer_name_hash(X509 *a);
  794. int X509_subject_name_cmp(const X509 *a, const X509 *b);
  795. unsigned long X509_subject_name_hash(X509 *x);
  796. int X509_cmp(const X509 *a, const X509 *b);
  797. int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
  798. unsigned long X509_NAME_hash(X509_NAME *x);
  799. int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
  800. int X509_CRL_match(const X509_CRL *a, const X509_CRL *b);
  801. #ifndef OPENSSL_NO_FP_API
  802. int X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
  803. int X509_print_fp(FILE *bp,X509 *x);
  804. int X509_CRL_print_fp(FILE *bp,X509_CRL *x);
  805. int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
  806. int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags);
  807. #endif
  808. #ifndef OPENSSL_NO_BIO
  809. int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
  810. int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags);
  811. int X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
  812. int X509_print(BIO *bp,X509 *x);
  813. int X509_ocspid_print(BIO *bp,X509 *x);
  814. int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
  815. int X509_CRL_print(BIO *bp,X509_CRL *x);
  816. int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag);
  817. int X509_REQ_print(BIO *bp,X509_REQ *req);
  818. #endif
  819. int X509_NAME_entry_count(X509_NAME *name);
  820. int X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
  821. char *buf,int len);
  822. int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
  823. char *buf,int len);
  824. /* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
  825. * lastpos, search after that position on. */
  826. int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
  827. int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
  828. int lastpos);
  829. X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
  830. X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
  831. int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
  832. int loc, int set);
  833. int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
  834. unsigned char *bytes, int len, int loc, int set);
  835. int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
  836. unsigned char *bytes, int len, int loc, int set);
  837. X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
  838. const char *field, int type, const unsigned char *bytes, int len);
  839. X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
  840. int type,unsigned char *bytes, int len);
  841. int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
  842. const unsigned char *bytes, int len, int loc, int set);
  843. X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
  844. ASN1_OBJECT *obj, int type,const unsigned char *bytes,
  845. int len);
  846. int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
  847. ASN1_OBJECT *obj);
  848. int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
  849. const unsigned char *bytes, int len);
  850. ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
  851. ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
  852. int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
  853. int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
  854. int nid, int lastpos);
  855. int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
  856. ASN1_OBJECT *obj,int lastpos);
  857. int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
  858. int crit, int lastpos);
  859. X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
  860. X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
  861. STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
  862. X509_EXTENSION *ex, int loc);
  863. int X509_get_ext_count(X509 *x);
  864. int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
  865. int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
  866. int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
  867. X509_EXTENSION *X509_get_ext(X509 *x, int loc);
  868. X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
  869. int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
  870. void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
  871. int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
  872. unsigned long flags);
  873. int X509_CRL_get_ext_count(X509_CRL *x);
  874. int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
  875. int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
  876. int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
  877. X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
  878. X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
  879. int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
  880. void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
  881. int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,
  882. unsigned long flags);
  883. int X509_REVOKED_get_ext_count(X509_REVOKED *x);
  884. int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
  885. int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
  886. int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
  887. X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
  888. X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
  889. int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
  890. void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
  891. int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,
  892. unsigned long flags);
  893. X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
  894. int nid, int crit, ASN1_OCTET_STRING *data);
  895. X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
  896. ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
  897. int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
  898. int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
  899. int X509_EXTENSION_set_data(X509_EXTENSION *ex,
  900. ASN1_OCTET_STRING *data);
  901. ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
  902. ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
  903. int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
  904. int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
  905. int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
  906. int lastpos);
  907. int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
  908. int lastpos);
  909. X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
  910. X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
  911. STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
  912. X509_ATTRIBUTE *attr);
  913. STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
  914. const ASN1_OBJECT *obj, int type,
  915. const unsigned char *bytes, int len);
  916. STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
  917. int nid, int type,
  918. const unsigned char *bytes, int len);
  919. STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
  920. const char *attrname, int type,
  921. const unsigned char *bytes, int len);
  922. void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x,
  923. ASN1_OBJECT *obj, int lastpos, int type);
  924. X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
  925. int atrtype, const void *data, int len);
  926. X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
  927. const ASN1_OBJECT *obj, int atrtype, const void *data, int len);
  928. X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
  929. const char *atrname, int type, const unsigned char *bytes, int len);
  930. int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);
  931. int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len);
  932. void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
  933. int atrtype, void *data);
  934. int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
  935. ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
  936. ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
  937. int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
  938. int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
  939. int lastpos);
  940. int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
  941. int lastpos);
  942. X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
  943. X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
  944. int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
  945. int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
  946. const ASN1_OBJECT *obj, int type,
  947. const unsigned char *bytes, int len);
  948. int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
  949. int nid, int type,
  950. const unsigned char *bytes, int len);
  951. int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
  952. const char *attrname, int type,
  953. const unsigned char *bytes, int len);
  954. int X509_verify_cert(X509_STORE_CTX *ctx);
  955. /* lookup a cert from a X509 STACK */
  956. X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
  957. ASN1_INTEGER *serial);
  958. X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
  959. DECLARE_ASN1_FUNCTIONS(PBEPARAM)
  960. DECLARE_ASN1_FUNCTIONS(PBE2PARAM)
  961. DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM)
  962. int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
  963. const unsigned char *salt, int saltlen);
  964. X509_ALGOR *PKCS5_pbe_set(int alg, int iter,
  965. const unsigned char *salt, int saltlen);
  966. X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
  967. unsigned char *salt, int saltlen);
  968. X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter,
  969. unsigned char *salt, int saltlen,
  970. unsigned char *aiv, int prf_nid);
  971. /* PKCS#8 utilities */
  972. DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
  973. EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
  974. PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
  975. PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
  976. PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
  977. int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,
  978. int version, int ptype, void *pval,
  979. unsigned char *penc, int penclen);
  980. int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg,
  981. const unsigned char **pk, int *ppklen,
  982. X509_ALGOR **pa,
  983. PKCS8_PRIV_KEY_INFO *p8);
  984. int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
  985. int ptype, void *pval,
  986. unsigned char *penc, int penclen);
  987. int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg,
  988. const unsigned char **pk, int *ppklen,
  989. X509_ALGOR **pa,
  990. X509_PUBKEY *pub);
  991. int X509_check_trust(X509 *x, int id, int flags);
  992. int X509_TRUST_get_count(void);
  993. X509_TRUST * X509_TRUST_get0(int idx);
  994. int X509_TRUST_get_by_id(int id);
  995. int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
  996. char *name, int arg1, void *arg2);
  997. void X509_TRUST_cleanup(void);
  998. int X509_TRUST_get_flags(X509_TRUST *xp);
  999. char *X509_TRUST_get0_name(X509_TRUST *xp);
  1000. int X509_TRUST_get_trust(X509_TRUST *xp);
  1001. /* BEGIN ERROR CODES */
  1002. /* The following lines are auto generated by the script mkerr.pl. Any changes
  1003. * made after this point may be overwritten when the script is next run.
  1004. */
  1005. void ERR_load_X509_strings(void);
  1006. /* Error codes for the X509 functions. */
  1007. /* Function codes. */
  1008. #define X509_F_ADD_CERT_DIR 100
  1009. #define X509_F_BY_FILE_CTRL 101
  1010. #define X509_F_CHECK_POLICY 145
  1011. #define X509_F_DIR_CTRL 102
  1012. #define X509_F_GET_CERT_BY_SUBJECT 103
  1013. #define X509_F_NETSCAPE_SPKI_B64_DECODE 129
  1014. #define X509_F_NETSCAPE_SPKI_B64_ENCODE 130
  1015. #define X509_F_X509AT_ADD1_ATTR 135
  1016. #define X509_F_X509V3_ADD_EXT 104
  1017. #define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136
  1018. #define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137
  1019. #define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140
  1020. #define X509_F_X509_ATTRIBUTE_GET0_DATA 139
  1021. #define X509_F_X509_ATTRIBUTE_SET1_DATA 138
  1022. #define X509_F_X509_CHECK_PRIVATE_KEY 128
  1023. #define X509_F_X509_CRL_PRINT_FP 147
  1024. #define X509_F_X509_EXTENSION_CREATE_BY_NID 108
  1025. #define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
  1026. #define X509_F_X509_GET_PUBKEY_PARAMETERS 110
  1027. #define X509_F_X509_LOAD_CERT_CRL_FILE 132
  1028. #define X509_F_X509_LOAD_CERT_FILE 111
  1029. #define X509_F_X509_LOAD_CRL_FILE 112
  1030. #define X509_F_X509_NAME_ADD_ENTRY 113
  1031. #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
  1032. #define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131
  1033. #define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
  1034. #define X509_F_X509_NAME_ONELINE 116
  1035. #define X509_F_X509_NAME_PRINT 117
  1036. #define X509_F_X509_PRINT_EX_FP 118
  1037. #define X509_F_X509_PUBKEY_GET 119
  1038. #define X509_F_X509_PUBKEY_SET 120
  1039. #define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144
  1040. #define X509_F_X509_REQ_PRINT_EX 121
  1041. #define X509_F_X509_REQ_PRINT_FP 122
  1042. #define X509_F_X509_REQ_TO_X509 123
  1043. #define X509_F_X509_STORE_ADD_CERT 124
  1044. #define X509_F_X509_STORE_ADD_CRL 125
  1045. #define X509_F_X509_STORE_CTX_GET1_ISSUER 146
  1046. #define X509_F_X509_STORE_CTX_INIT 143
  1047. #define X509_F_X509_STORE_CTX_NEW 142
  1048. #define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134
  1049. #define X509_F_X509_TO_X509_REQ 126
  1050. #define X509_F_X509_TRUST_ADD 133
  1051. #define X509_F_X509_TRUST_SET 141
  1052. #define X509_F_X509_VERIFY_CERT 127
  1053. /* Reason codes. */
  1054. #define X509_R_BAD_X509_FILETYPE 100
  1055. #define X509_R_BASE64_DECODE_ERROR 118
  1056. #define X509_R_CANT_CHECK_DH_KEY 114
  1057. #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
  1058. #define X509_R_ERR_ASN1_LIB 102
  1059. #define X509_R_INVALID_DIRECTORY 113
  1060. #define X509_R_INVALID_FIELD_NAME 119
  1061. #define X509_R_INVALID_TRUST 123
  1062. #define X509_R_KEY_TYPE_MISMATCH 115
  1063. #define X509_R_KEY_VALUES_MISMATCH 116
  1064. #define X509_R_LOADING_CERT_DIR 103
  1065. #define X509_R_LOADING_DEFAULTS 104
  1066. #define X509_R_METHOD_NOT_SUPPORTED 124
  1067. #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
  1068. #define X509_R_PUBLIC_KEY_DECODE_ERROR 125
  1069. #define X509_R_PUBLIC_KEY_ENCODE_ERROR 126
  1070. #define X509_R_SHOULD_RETRY 106
  1071. #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
  1072. #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
  1073. #define X509_R_UNKNOWN_KEY_TYPE 117
  1074. #define X509_R_UNKNOWN_NID 109
  1075. #define X509_R_UNKNOWN_PURPOSE_ID 121
  1076. #define X509_R_UNKNOWN_TRUST_ID 120
  1077. #define X509_R_UNSUPPORTED_ALGORITHM 111
  1078. #define X509_R_WRONG_LOOKUP_TYPE 112
  1079. #define X509_R_WRONG_TYPE 122
  1080. #ifdef __cplusplus
  1081. }
  1082. #endif
  1083. #endif