xref: /openbsd/lib/libcrypto/x509/x509.h (revision 9fcb5aca)
1 /* $OpenBSD: x509.h,v 1.112 2024/06/12 03:55:46 tb Exp $ */
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 
64 #ifndef HEADER_X509_H
65 #define HEADER_X509_H
66 
67 #include <openssl/opensslconf.h>
68 
69 #include <openssl/asn1.h>
70 #ifndef OPENSSL_NO_BIO
71 #include <openssl/bio.h>
72 #endif
73 #ifndef OPENSSL_NO_BUFFER
74 #include <openssl/buffer.h>
75 #endif
76 #ifndef OPENSSL_NO_DH
77 #include <openssl/dh.h>
78 #endif
79 #ifndef OPENSSL_NO_DSA
80 #include <openssl/dsa.h>
81 #endif
82 #ifndef OPENSSL_NO_EC
83 #include <openssl/ec.h>
84 #endif
85 #ifndef OPENSSL_NO_EVP
86 #include <openssl/evp.h>
87 #endif
88 #ifndef OPENSSL_NO_RSA
89 #include <openssl/rsa.h>
90 #endif
91 #ifndef OPENSSL_NO_SHA
92 #include <openssl/sha.h>
93 #endif
94 #include <openssl/stack.h>
95 #include <openssl/safestack.h>
96 
97 #include <openssl/ossl_typ.h>
98 
99 #ifdef  __cplusplus
100 extern "C" {
101 #endif
102 
103 #define X509_FILETYPE_PEM	1
104 #define X509_FILETYPE_ASN1	2
105 #define X509_FILETYPE_DEFAULT	3
106 
107 #define X509v3_KU_DIGITAL_SIGNATURE	0x0080
108 #define X509v3_KU_NON_REPUDIATION	0x0040
109 #define X509v3_KU_KEY_ENCIPHERMENT	0x0020
110 #define X509v3_KU_DATA_ENCIPHERMENT	0x0010
111 #define X509v3_KU_KEY_AGREEMENT		0x0008
112 #define X509v3_KU_KEY_CERT_SIGN		0x0004
113 #define X509v3_KU_CRL_SIGN		0x0002
114 #define X509v3_KU_ENCIPHER_ONLY		0x0001
115 #define X509v3_KU_DECIPHER_ONLY		0x8000
116 #define X509v3_KU_UNDEF			0xffff
117 
118 struct X509_algor_st {
119 	ASN1_OBJECT *algorithm;
120 	ASN1_TYPE *parameter;
121 } /* X509_ALGOR */;
122 
123 typedef STACK_OF(X509_ALGOR) X509_ALGORS;
124 
125 typedef struct X509_val_st {
126 	ASN1_TIME *notBefore;
127 	ASN1_TIME *notAfter;
128 } X509_VAL;
129 
130 typedef struct X509_sig_st X509_SIG;
131 
132 typedef struct X509_name_entry_st X509_NAME_ENTRY;
133 
134 DECLARE_STACK_OF(X509_NAME_ENTRY)
135 
136 DECLARE_STACK_OF(X509_NAME)
137 
138 typedef struct X509_extension_st X509_EXTENSION;
139 
140 typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS;
141 
142 DECLARE_STACK_OF(X509_EXTENSION)
143 
144 typedef struct x509_attributes_st X509_ATTRIBUTE;
145 
146 DECLARE_STACK_OF(X509_ATTRIBUTE)
147 
148 typedef struct X509_req_info_st X509_REQ_INFO;
149 
150 typedef struct X509_req_st X509_REQ;
151 
152 typedef struct x509_cinf_st X509_CINF;
153 
154 DECLARE_STACK_OF(X509)
155 
156 /* standard trust ids */
157 
158 /* OpenSSL changed this to 0 */
159 #define X509_TRUST_DEFAULT	-1	/* Only valid in purpose settings */
160 
161 #define X509_TRUST_COMPAT	1
162 #define X509_TRUST_SSL_CLIENT	2
163 #define X509_TRUST_SSL_SERVER	3
164 #define X509_TRUST_EMAIL	4
165 #define X509_TRUST_OBJECT_SIGN	5
166 #define X509_TRUST_OCSP_SIGN	6
167 #define X509_TRUST_OCSP_REQUEST	7
168 #define X509_TRUST_TSA		8
169 
170 /* Keep these up to date! */
171 #define X509_TRUST_MIN		1
172 #define X509_TRUST_MAX		8
173 
174 
175 /* trust_flags values */
176 #define	X509_TRUST_DYNAMIC 	1
177 #define	X509_TRUST_DYNAMIC_NAME	2
178 
179 /* check_trust return codes */
180 
181 #define X509_TRUST_TRUSTED	1
182 #define X509_TRUST_REJECTED	2
183 #define X509_TRUST_UNTRUSTED	3
184 
185 /* Flags for X509_print_ex() */
186 
187 #define	X509_FLAG_COMPAT		0
188 #define	X509_FLAG_NO_HEADER		1L
189 #define	X509_FLAG_NO_VERSION		(1L << 1)
190 #define	X509_FLAG_NO_SERIAL		(1L << 2)
191 #define	X509_FLAG_NO_SIGNAME		(1L << 3)
192 #define	X509_FLAG_NO_ISSUER		(1L << 4)
193 #define	X509_FLAG_NO_VALIDITY		(1L << 5)
194 #define	X509_FLAG_NO_SUBJECT		(1L << 6)
195 #define	X509_FLAG_NO_PUBKEY		(1L << 7)
196 #define	X509_FLAG_NO_EXTENSIONS		(1L << 8)
197 #define	X509_FLAG_NO_SIGDUMP		(1L << 9)
198 #define	X509_FLAG_NO_AUX		(1L << 10)
199 #define	X509_FLAG_NO_ATTRIBUTES		(1L << 11)
200 
201 /* Flags specific to X509_NAME_print_ex() */
202 
203 /* The field separator information */
204 
205 #define XN_FLAG_SEP_MASK	(0xf << 16)
206 
207 #define XN_FLAG_COMPAT		0		/* Traditional SSLeay: use old X509_NAME_print */
208 #define XN_FLAG_SEP_COMMA_PLUS	(1 << 16)	/* RFC2253 ,+ */
209 #define XN_FLAG_SEP_CPLUS_SPC	(2 << 16)	/* ,+ spaced: more readable */
210 #define XN_FLAG_SEP_SPLUS_SPC	(3 << 16)	/* ;+ spaced */
211 #define XN_FLAG_SEP_MULTILINE	(4 << 16)	/* One line per field */
212 
213 #define XN_FLAG_DN_REV		(1 << 20)	/* Reverse DN order */
214 
215 /* How the field name is shown */
216 
217 #define XN_FLAG_FN_MASK		(0x3 << 21)
218 
219 #define XN_FLAG_FN_SN		0		/* Object short name */
220 #define XN_FLAG_FN_LN		(1 << 21)	/* Object long name */
221 #define XN_FLAG_FN_OID		(2 << 21)	/* Always use OIDs */
222 #define XN_FLAG_FN_NONE		(3 << 21)	/* No field names */
223 
224 #define XN_FLAG_SPC_EQ		(1 << 23)	/* Put spaces round '=' */
225 
226 /* This determines if we dump fields we don't recognise:
227  * RFC2253 requires this.
228  */
229 
230 #define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24)
231 
232 #define XN_FLAG_FN_ALIGN	(1 << 25)	/* Align field names to 20 characters */
233 
234 /* Complete set of RFC2253 flags */
235 
236 #define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \
237 			XN_FLAG_SEP_COMMA_PLUS | \
238 			XN_FLAG_DN_REV | \
239 			XN_FLAG_FN_SN | \
240 			XN_FLAG_DUMP_UNKNOWN_FIELDS)
241 
242 /* readable oneline form */
243 
244 #define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \
245 			ASN1_STRFLGS_ESC_QUOTE | \
246 			XN_FLAG_SEP_CPLUS_SPC | \
247 			XN_FLAG_SPC_EQ | \
248 			XN_FLAG_FN_SN)
249 
250 /* readable multiline form */
251 
252 #define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \
253 			ASN1_STRFLGS_ESC_MSB | \
254 			XN_FLAG_SEP_MULTILINE | \
255 			XN_FLAG_SPC_EQ | \
256 			XN_FLAG_FN_LN | \
257 			XN_FLAG_FN_ALIGN)
258 
259 DECLARE_STACK_OF(X509_REVOKED)
260 
261 typedef struct X509_crl_info_st X509_CRL_INFO;
262 
263 DECLARE_STACK_OF(X509_CRL)
264 
265 typedef struct private_key_st {
266 	int version;
267 	/* The PKCS#8 data types */
268 	X509_ALGOR *enc_algor;
269 	ASN1_OCTET_STRING *enc_pkey;	/* encrypted pub key */
270 
271 	/* When decrypted, the following will not be NULL */
272 	EVP_PKEY *dec_pkey;
273 
274 	/* used to encrypt and decrypt */
275 	int key_length;
276 	char *key_data;
277 	int key_free;	/* true if we should auto free key_data */
278 
279 	/* expanded version of 'enc_algor' */
280 	EVP_CIPHER_INFO cipher;
281 
282 	int references;
283 } X509_PKEY;
284 
285 #ifndef OPENSSL_NO_EVP
286 typedef struct X509_info_st {
287 	X509 *x509;
288 	X509_CRL *crl;
289 	X509_PKEY *x_pkey;
290 
291 	EVP_CIPHER_INFO enc_cipher;
292 	int enc_len;
293 	char *enc_data;
294 
295 	int references;
296 } X509_INFO;
297 
298 DECLARE_STACK_OF(X509_INFO)
299 #endif
300 
301 /* The next 2 structures and their 8 routines were sent to me by
302  * Pat Richard <patr@x509.com> and are used to manipulate
303  * Netscapes spki structures - useful if you are writing a CA web page
304  */
305 typedef struct Netscape_spkac_st {
306 	X509_PUBKEY *pubkey;
307 	ASN1_IA5STRING *challenge;	/* challenge sent in atlas >= PR2 */
308 } NETSCAPE_SPKAC;
309 
310 typedef struct Netscape_spki_st {
311 	NETSCAPE_SPKAC *spkac;	/* signed public key and challenge */
312 	X509_ALGOR *sig_algor;
313 	ASN1_BIT_STRING *signature;
314 } NETSCAPE_SPKI;
315 
316 typedef struct PBEPARAM_st {
317 	ASN1_OCTET_STRING *salt;
318 	ASN1_INTEGER *iter;
319 } PBEPARAM;
320 
321 #ifdef  __cplusplus
322 }
323 #endif
324 
325 #include <openssl/x509_vfy.h>
326 #include <openssl/pkcs7.h>
327 
328 #ifdef  __cplusplus
329 extern "C" {
330 #endif
331 
332 #define		X509_extract_key(x)	X509_get_pubkey(x) /*****/
333 #define		X509_REQ_extract_key(a)	X509_REQ_get_pubkey(a)
334 #define		X509_name_cmp(a,b)	X509_NAME_cmp((a),(b))
335 
336 int X509_CRL_up_ref(X509_CRL *x);
337 int X509_CRL_get_signature_nid(const X509_CRL *crl);
338 
339 int i2d_re_X509_CRL_tbs(X509_CRL *req, unsigned char **pp);
340 
341 const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl);
342 long X509_CRL_get_version(const X509_CRL *crl);
343 const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl);
344 const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl);
345 ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl);
346 ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl);
347 X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl);
348 STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl);
349 void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
350     const X509_ALGOR **palg);
351 
352 const X509_ALGOR *X509_CRL_get0_tbs_sigalg(const X509_CRL *crl);
353 
354 int X509_REQ_get_signature_nid(const X509_REQ *req);
355 
356 void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig,
357     const X509_ALGOR **palg);
358 
359 X509_PUBKEY	*X509_get_X509_PUBKEY(const X509 *x);
360 
361 const char *X509_verify_cert_error_string(long n);
362 
363 #ifndef OPENSSL_NO_EVP
364 int X509_verify(X509 *a, EVP_PKEY *r);
365 
366 int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
367 int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
368 int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
369 
370 NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
371 char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
372 EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
373 int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
374 
375 int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
376 
377 int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent);
378 int X509_signature_print(BIO *bp, const X509_ALGOR *alg,
379     const ASN1_STRING *sig);
380 
381 int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
382 int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx);
383 int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
384 int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx);
385 int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
386 int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx);
387 int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
388 
389 int X509_pubkey_digest(const X509 *data,const EVP_MD *type,
390 		unsigned char *md, unsigned int *len);
391 int X509_digest(const X509 *data,const EVP_MD *type,
392 		unsigned char *md, unsigned int *len);
393 int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type,
394 		unsigned char *md, unsigned int *len);
395 int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type,
396 		unsigned char *md, unsigned int *len);
397 int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type,
398 		unsigned char *md, unsigned int *len);
399 #endif
400 
401 X509 *d2i_X509_fp(FILE *fp, X509 **x509);
402 int i2d_X509_fp(FILE *fp,X509 *x509);
403 X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
404 int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
405 X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
406 int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
407 #ifndef OPENSSL_NO_RSA
408 RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
409 int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
410 RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
411 int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
412 RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
413 int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
414 #endif
415 #ifndef OPENSSL_NO_DSA
416 DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
417 int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
418 DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
419 int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
420 #endif
421 #ifndef OPENSSL_NO_EC
422 EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey);
423 int   i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey);
424 EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey);
425 int   i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey);
426 #endif
427 X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
428 int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
429 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
430 						PKCS8_PRIV_KEY_INFO **p8inf);
431 int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
432 int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
433 int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
434 EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
435 int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey);
436 EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a);
437 
438 #ifndef OPENSSL_NO_BIO
439 X509 *d2i_X509_bio(BIO *bp,X509 **x509);
440 int i2d_X509_bio(BIO *bp,X509 *x509);
441 X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
442 int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
443 X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
444 int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
445 #ifndef OPENSSL_NO_RSA
446 RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
447 int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
448 RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
449 int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
450 RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
451 int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
452 #endif
453 #ifndef OPENSSL_NO_DSA
454 DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
455 int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
456 DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
457 int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
458 #endif
459 #ifndef OPENSSL_NO_EC
460 EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey);
461 int   i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey);
462 EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey);
463 int   i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey);
464 #endif
465 X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
466 int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
467 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
468 						PKCS8_PRIV_KEY_INFO **p8inf);
469 int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
470 int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
471 int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
472 EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
473 int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey);
474 EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a);
475 #endif
476 
477 X509 *X509_dup(X509 *x509);
478 X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
479 X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
480 X509_CRL *X509_CRL_dup(X509_CRL *crl);
481 X509_REQ *X509_REQ_dup(X509_REQ *req);
482 X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
483 int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval);
484 void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, const void **ppval,
485     const X509_ALGOR *algor);
486 int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b);
487 
488 X509_NAME *X509_NAME_dup(X509_NAME *xn);
489 int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, size_t *pderlen);
490 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
491 
492 int		X509_cmp_time(const ASN1_TIME *s, time_t *t);
493 int		X509_cmp_current_time(const ASN1_TIME *s);
494 ASN1_TIME *	X509_time_adj(ASN1_TIME *s, long adj, time_t *t);
495 ASN1_TIME *	X509_time_adj_ex(ASN1_TIME *s,
496 				int offset_day, long offset_sec, time_t *t);
497 ASN1_TIME *	X509_gmtime_adj(ASN1_TIME *s, long adj);
498 
499 const char *	X509_get_default_cert_area(void );
500 const char *	X509_get_default_cert_dir(void );
501 const char *	X509_get_default_cert_file(void );
502 const char *	X509_get_default_cert_dir_env(void );
503 const char *	X509_get_default_cert_file_env(void );
504 const char *	X509_get_default_private_dir(void );
505 
506 X509_REQ *	X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
507 X509 *		X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
508 
509 X509_ALGOR *X509_ALGOR_new(void);
510 void X509_ALGOR_free(X509_ALGOR *a);
511 X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, const unsigned char **in, long len);
512 int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **out);
513 extern const ASN1_ITEM X509_ALGOR_it;
514 X509_ALGORS *d2i_X509_ALGORS(X509_ALGORS **a, const unsigned char **in, long len);
515 int i2d_X509_ALGORS(X509_ALGORS *a, unsigned char **out);
516 extern const ASN1_ITEM X509_ALGORS_it;
517 X509_VAL *X509_VAL_new(void);
518 void X509_VAL_free(X509_VAL *a);
519 X509_VAL *d2i_X509_VAL(X509_VAL **a, const unsigned char **in, long len);
520 int i2d_X509_VAL(X509_VAL *a, unsigned char **out);
521 extern const ASN1_ITEM X509_VAL_it;
522 
523 X509_PUBKEY *X509_PUBKEY_new(void);
524 void X509_PUBKEY_free(X509_PUBKEY *a);
525 X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, const unsigned char **in, long len);
526 int i2d_X509_PUBKEY(X509_PUBKEY *a, unsigned char **out);
527 extern const ASN1_ITEM X509_PUBKEY_it;
528 
529 int		X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
530 EVP_PKEY *	X509_PUBKEY_get(X509_PUBKEY *key);
531 EVP_PKEY *	X509_PUBKEY_get0(X509_PUBKEY *key);
532 int		X509_get_pubkey_parameters(EVP_PKEY *pkey,
533 					   STACK_OF(X509) *chain);
534 int		i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
535 EVP_PKEY *	d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp,
536 			long length);
537 #ifndef OPENSSL_NO_RSA
538 int		i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
539 RSA *		d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp,
540 			long length);
541 #endif
542 #ifndef OPENSSL_NO_DSA
543 int		i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
544 DSA *		d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp,
545 			long length);
546 #endif
547 #ifndef OPENSSL_NO_EC
548 int		i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp);
549 EC_KEY 		*d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp,
550 			long length);
551 #endif
552 
553 X509_SIG *X509_SIG_new(void);
554 void X509_SIG_free(X509_SIG *a);
555 X509_SIG *d2i_X509_SIG(X509_SIG **a, const unsigned char **in, long len);
556 int i2d_X509_SIG(X509_SIG *a, unsigned char **out);
557 extern const ASN1_ITEM X509_SIG_it;
558 void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg,
559     const ASN1_OCTET_STRING **pdigest);
560 void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **palg,
561     ASN1_OCTET_STRING **pdigest);
562 
563 X509_REQ_INFO *X509_REQ_INFO_new(void);
564 void X509_REQ_INFO_free(X509_REQ_INFO *a);
565 X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, const unsigned char **in, long len);
566 int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **out);
567 extern const ASN1_ITEM X509_REQ_INFO_it;
568 X509_REQ *X509_REQ_new(void);
569 void X509_REQ_free(X509_REQ *a);
570 X509_REQ *d2i_X509_REQ(X509_REQ **a, const unsigned char **in, long len);
571 int i2d_X509_REQ(X509_REQ *a, unsigned char **out);
572 extern const ASN1_ITEM X509_REQ_it;
573 
574 X509_ATTRIBUTE *X509_ATTRIBUTE_new(void);
575 void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
576 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, const unsigned char **in, long len);
577 int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **out);
578 extern const ASN1_ITEM X509_ATTRIBUTE_it;
579 X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
580 
581 X509_EXTENSION *X509_EXTENSION_new(void);
582 void X509_EXTENSION_free(X509_EXTENSION *a);
583 X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, const unsigned char **in, long len);
584 int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **out);
585 extern const ASN1_ITEM X509_EXTENSION_it;
586 X509_EXTENSIONS *d2i_X509_EXTENSIONS(X509_EXTENSIONS **a, const unsigned char **in, long len);
587 int i2d_X509_EXTENSIONS(X509_EXTENSIONS *a, unsigned char **out);
588 extern const ASN1_ITEM X509_EXTENSIONS_it;
589 
590 X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
591 void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
592 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, const unsigned char **in, long len);
593 int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **out);
594 extern const ASN1_ITEM X509_NAME_ENTRY_it;
595 
596 X509_NAME *X509_NAME_new(void);
597 void X509_NAME_free(X509_NAME *a);
598 X509_NAME *d2i_X509_NAME(X509_NAME **a, const unsigned char **in, long len);
599 int i2d_X509_NAME(X509_NAME *a, unsigned char **out);
600 extern const ASN1_ITEM X509_NAME_it;
601 
602 int		X509_NAME_set(X509_NAME **xn, X509_NAME *name);
603 
604 X509_CINF *X509_CINF_new(void);
605 void X509_CINF_free(X509_CINF *a);
606 X509_CINF *d2i_X509_CINF(X509_CINF **a, const unsigned char **in, long len);
607 int i2d_X509_CINF(X509_CINF *a, unsigned char **out);
608 extern const ASN1_ITEM X509_CINF_it;
609 
610 X509 *X509_new(void);
611 void X509_free(X509 *a);
612 X509 *d2i_X509(X509 **a, const unsigned char **in, long len);
613 int i2d_X509(X509 *a, unsigned char **out);
614 extern const ASN1_ITEM X509_it;
615 
616 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
617 	     CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
618 int X509_set_ex_data(X509 *r, int idx, void *arg);
619 void *X509_get_ex_data(X509 *r, int idx);
620 int		i2d_X509_AUX(X509 *a,unsigned char **pp);
621 X509 *		d2i_X509_AUX(X509 **a,const unsigned char **pp,long length);
622 
623 int i2d_re_X509_tbs(X509 *x, unsigned char **pp);
624 
625 void X509_get0_signature(const ASN1_BIT_STRING **psig,
626     const X509_ALGOR **palg, const X509 *x);
627 int X509_get_signature_nid(const X509 *x);
628 
629 int X509_alias_set1(X509 *x, const unsigned char *name, int len);
630 int X509_keyid_set1(X509 *x, const unsigned char *id, int len);
631 unsigned char *X509_alias_get0(X509 *x, int *len);
632 unsigned char *X509_keyid_get0(X509 *x, int *len);
633 int X509_add1_trust_object(X509 *x, const ASN1_OBJECT *obj);
634 int X509_add1_reject_object(X509 *x, const ASN1_OBJECT *obj);
635 void X509_trust_clear(X509 *x);
636 void X509_reject_clear(X509 *x);
637 
638 X509_REVOKED *X509_REVOKED_new(void);
639 void X509_REVOKED_free(X509_REVOKED *a);
640 X509_REVOKED *X509_REVOKED_dup(X509_REVOKED *a);
641 X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, const unsigned char **in, long len);
642 int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **out);
643 extern const ASN1_ITEM X509_REVOKED_it;
644 
645 X509_CRL_INFO *X509_CRL_INFO_new(void);
646 void X509_CRL_INFO_free(X509_CRL_INFO *a);
647 X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, const unsigned char **in, long len);
648 int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **out);
649 extern const ASN1_ITEM X509_CRL_INFO_it;
650 
651 X509_CRL *X509_CRL_new(void);
652 void X509_CRL_free(X509_CRL *a);
653 X509_CRL *d2i_X509_CRL(X509_CRL **a, const unsigned char **in, long len);
654 int i2d_X509_CRL(X509_CRL *a, unsigned char **out);
655 extern const ASN1_ITEM X509_CRL_it;
656 
657 int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
658 int X509_CRL_get0_by_serial(X509_CRL *crl,
659 		X509_REVOKED **ret, ASN1_INTEGER *serial);
660 int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x);
661 
662 X509_PKEY *	X509_PKEY_new(void );
663 void		X509_PKEY_free(X509_PKEY *a);
664 
665 NETSCAPE_SPKI *NETSCAPE_SPKI_new(void);
666 void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
667 NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a, const unsigned char **in, long len);
668 int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **out);
669 extern const ASN1_ITEM NETSCAPE_SPKI_it;
670 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void);
671 void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
672 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a, const unsigned char **in, long len);
673 int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a, unsigned char **out);
674 extern const ASN1_ITEM NETSCAPE_SPKAC_it;
675 
676 #ifndef OPENSSL_NO_EVP
677 X509_INFO *	X509_INFO_new(void);
678 void		X509_INFO_free(X509_INFO *a);
679 char *		X509_NAME_oneline(const X509_NAME *a, char *buf, int size);
680 
681 int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,
682 	unsigned char *md,unsigned int *len);
683 
684 int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1,
685 	ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey);
686 
687 int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
688 	ASN1_BIT_STRING *signature,
689 	void *data, EVP_PKEY *pkey, const EVP_MD *type);
690 int ASN1_item_sign_ctx(const ASN1_ITEM *it,
691 		X509_ALGOR *algor1, X509_ALGOR *algor2,
692 	     	ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx);
693 #endif
694 
695 const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x);
696 void		X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **issuerUID,
697 		    const ASN1_BIT_STRING **subjectUID);
698 const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x);
699 int 		X509_set_version(X509 *x, long version);
700 long		X509_get_version(const X509 *x);
701 int 		X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
702 ASN1_INTEGER *	X509_get_serialNumber(X509 *x);
703 const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x);
704 int 		X509_set_issuer_name(X509 *x, X509_NAME *name);
705 X509_NAME *	X509_get_issuer_name(const X509 *a);
706 int 		X509_set_subject_name(X509 *x, X509_NAME *name);
707 X509_NAME *	X509_get_subject_name(const X509 *a);
708 int 		X509_set_notBefore(X509 *x, const ASN1_TIME *tm);
709 int 		X509_set1_notBefore(X509 *x, const ASN1_TIME *tm);
710 int 		X509_set_notAfter(X509 *x, const ASN1_TIME *tm);
711 int 		X509_set1_notAfter(X509 *x, const ASN1_TIME *tm);
712 const ASN1_TIME *X509_get0_notBefore(const X509 *x);
713 ASN1_TIME *X509_getm_notBefore(const X509 *x);
714 const ASN1_TIME *X509_get0_notAfter(const X509 *x);
715 ASN1_TIME *X509_getm_notAfter(const X509 *x);
716 int 		X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
717 EVP_PKEY *	X509_get_pubkey(X509 *x);
718 EVP_PKEY *	X509_get0_pubkey(const X509 *x);
719 ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x);
720 int		X509_certificate_type(const X509 *x, const EVP_PKEY *pubkey);
721 int		X509_get_signature_type(const X509 *x);
722 
723 #define X509_get_notBefore	X509_getm_notBefore
724 #define X509_get_notAfter	X509_getm_notAfter
725 
726 int		X509_REQ_set_version(X509_REQ *x,long version);
727 long		X509_REQ_get_version(const X509_REQ *x);
728 int		X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name);
729 X509_NAME	*X509_REQ_get_subject_name(const X509_REQ *x);
730 int		X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
731 EVP_PKEY *	X509_REQ_get_pubkey(X509_REQ *req);
732 int		i2d_re_X509_REQ_tbs(X509_REQ *req, unsigned char **pp);
733 EVP_PKEY *	X509_REQ_get0_pubkey(X509_REQ *req);
734 int		X509_REQ_extension_nid(int nid);
735 int *		X509_REQ_get_extension_nids(void);
736 void		X509_REQ_set_extension_nids(int *nids);
737 STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
738 int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
739 				int nid);
740 int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
741 int X509_REQ_get_attr_count(const X509_REQ *req);
742 int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
743 			  int lastpos);
744 int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, const ASN1_OBJECT *obj,
745 			  int lastpos);
746 X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
747 X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
748 int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
749 int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
750 			const ASN1_OBJECT *obj, int type,
751 			const unsigned char *bytes, int len);
752 int X509_REQ_add1_attr_by_NID(X509_REQ *req,
753 			int nid, int type,
754 			const unsigned char *bytes, int len);
755 int X509_REQ_add1_attr_by_txt(X509_REQ *req,
756 			const char *attrname, int type,
757 			const unsigned char *bytes, int len);
758 
759 int X509_CRL_set_version(X509_CRL *x, long version);
760 int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
761 int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm);
762 int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm);
763 int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm);
764 int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm);
765 int X509_CRL_sort(X509_CRL *crl);
766 
767 const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const X509_REVOKED *x);
768 const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x);
769 const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x);
770 int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);
771 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
772 
773 int		X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey);
774 
775 int		X509_check_private_key(const X509 *x509, const EVP_PKEY *pkey);
776 
777 int		X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
778 unsigned long	X509_issuer_and_serial_hash(X509 *a);
779 
780 int		X509_issuer_name_cmp(const X509 *a, const X509 *b);
781 unsigned long	X509_issuer_name_hash(X509 *a);
782 
783 int		X509_subject_name_cmp(const X509 *a, const X509 *b);
784 unsigned long	X509_subject_name_hash(X509 *x);
785 
786 #ifndef OPENSSL_NO_MD5
787 unsigned long	X509_issuer_name_hash_old(X509 *a);
788 unsigned long	X509_subject_name_hash_old(X509 *x);
789 #endif
790 
791 int		X509_cmp(const X509 *a, const X509 *b);
792 int		X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
793 unsigned long	X509_NAME_hash(X509_NAME *x);
794 unsigned long	X509_NAME_hash_old(X509_NAME *x);
795 
796 int		X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
797 int		X509_CRL_match(const X509_CRL *a, const X509_CRL *b);
798 int		X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
799 int		X509_print_fp(FILE *bp,X509 *x);
800 int		X509_CRL_print_fp(FILE *bp,X509_CRL *x);
801 int		X509_REQ_print_fp(FILE *bp,X509_REQ *req);
802 int		X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent,
803 		    unsigned long flags);
804 
805 #ifndef OPENSSL_NO_BIO
806 int		X509_NAME_print(BIO *bp, const X509_NAME *name, int obase);
807 int		X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent,
808 		    unsigned long flags);
809 int		X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag);
810 int		X509_print(BIO *bp,X509 *x);
811 int		X509_ocspid_print(BIO *bp,X509 *x);
812 int		X509_CRL_print(BIO *bp,X509_CRL *x);
813 int		X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag);
814 int		X509_REQ_print(BIO *bp,X509_REQ *req);
815 #endif
816 
817 int 		X509_NAME_entry_count(const X509_NAME *name);
818 int 		X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
819 			char *buf,int len);
820 int		X509_NAME_get_text_by_OBJ(X509_NAME *name,
821 			const ASN1_OBJECT *obj, char *buf,int len);
822 
823 /* NOTE: you should be passing -1, not 0 as lastpos.  The functions that use
824  * lastpos, search after that position on. */
825 int 		X509_NAME_get_index_by_NID(const X509_NAME *name, int nid,
826 			int lastpos);
827 int 		X509_NAME_get_index_by_OBJ(const X509_NAME *name,
828 			const ASN1_OBJECT *obj, int lastpos);
829 X509_NAME_ENTRY *X509_NAME_get_entry(const 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, const X509_NAME_ENTRY *ne,
832 			int loc, int set);
833 int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj,
834     int type, const 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 			const 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, const 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 			const ASN1_OBJECT *obj, int type,
845 			const unsigned char *bytes, int len);
846 int 		X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
847 			const 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(const X509_NAME_ENTRY *ne);
851 ASN1_STRING *	X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne);
852 int		X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne);
853 
854 int		X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
855 int		X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
856 				      int nid, int lastpos);
857 int		X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
858 				      const ASN1_OBJECT *obj, int lastpos);
859 int		X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
860 					   int crit, int lastpos);
861 X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
862 X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
863 STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
864 					 X509_EXTENSION *ex, int loc);
865 
866 int		X509_get_ext_count(const X509 *x);
867 int		X509_get_ext_by_NID(const X509 *x, int nid, int lastpos);
868 int		X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj,
869 		    int lastpos);
870 int		X509_get_ext_by_critical(const X509 *x, int crit, int lastpos);
871 X509_EXTENSION *X509_get_ext(const X509 *x, int loc);
872 X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
873 int		X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
874 void	*	X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx);
875 int		X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
876 							unsigned long flags);
877 
878 int		X509_CRL_get_ext_count(const X509_CRL *x);
879 int		X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid,
880 		    int lastpos);
881 int		X509_CRL_get_ext_by_OBJ(const X509_CRL *x,
882 		    const ASN1_OBJECT *obj, int lastpos);
883 int		X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit,
884 		    int lastpos);
885 X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc);
886 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
887 int		X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
888 void	*	X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit,
889 		    int *idx);
890 int		X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value,
891 		    int crit, unsigned long flags);
892 
893 int		X509_REVOKED_get_ext_count(const X509_REVOKED *x);
894 int		X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid,
895 		    int lastpos);
896 int		X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x,
897 		    const ASN1_OBJECT *obj, int lastpos);
898 int		X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x,
899 		    int crit, int lastpos);
900 X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc);
901 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
902 int		X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex,
903 		    int loc);
904 void	*	X509_REVOKED_get_ext_d2i(const X509_REVOKED *x, int nid,
905 		    int *crit, int *idx);
906 int		X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value,
907 		    int crit, unsigned long flags);
908 
909 X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
910 			int nid, int crit, ASN1_OCTET_STRING *data);
911 X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
912     const ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data);
913 int		X509_EXTENSION_set_object(X509_EXTENSION *ex,
914 		    const ASN1_OBJECT *obj);
915 int		X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
916 int		X509_EXTENSION_set_data(X509_EXTENSION *ex,
917 			ASN1_OCTET_STRING *data);
918 ASN1_OBJECT *	X509_EXTENSION_get_object(X509_EXTENSION *ex);
919 ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
920 int		X509_EXTENSION_get_critical(const X509_EXTENSION *ex);
921 
922 int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
923 int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
924 			  int lastpos);
925 int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk,
926     const ASN1_OBJECT *obj, int lastpos);
927 X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
928 X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
929 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
930 					 X509_ATTRIBUTE *attr);
931 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
932 			const ASN1_OBJECT *obj, int type,
933 			const unsigned char *bytes, int len);
934 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
935 			int nid, int type,
936 			const unsigned char *bytes, int len);
937 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
938 			const char *attrname, int type,
939 			const unsigned char *bytes, int len);
940 void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x,
941     const ASN1_OBJECT *obj, int lastpos, int type);
942 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
943 	     int atrtype, const void *data, int len);
944 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
945 	     const ASN1_OBJECT *obj, int atrtype, const void *data, int len);
946 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
947 		const char *atrname, int type, const unsigned char *bytes, int len);
948 int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);
949 int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len);
950 void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
951 					int atrtype, void *data);
952 int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr);
953 ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
954 ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
955 
956 int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
957 int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
958 			  int lastpos);
959 int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj,
960 			  int lastpos);
961 X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
962 X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
963 int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
964 int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
965 			const ASN1_OBJECT *obj, int type,
966 			const unsigned char *bytes, int len);
967 int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
968 			int nid, int type,
969 			const unsigned char *bytes, int len);
970 int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
971 			const char *attrname, int type,
972 			const unsigned char *bytes, int len);
973 
974 int		X509_verify_cert(X509_STORE_CTX *ctx);
975 
976 /* lookup a cert from a X509 STACK */
977 X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
978 				     ASN1_INTEGER *serial);
979 X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
980 
981 extern const ASN1_ITEM PBEPARAM_it;
982 
983 /* PKCS#8 utilities */
984 
985 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
986 void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
987 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a, const unsigned char **in, long len);
988 int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **out);
989 extern const ASN1_ITEM PKCS8_PRIV_KEY_INFO_it;
990 
991 EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8);
992 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
993 
994 int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version,
995     int ptype, void *pval, unsigned char *penc, int penclen);
996 int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk,
997     int *ppklen, const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8);
998 
999 const STACK_OF(X509_ATTRIBUTE) *PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8);
1000 int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type,
1001     const unsigned char *bytes, int len);
1002 
1003 int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, int ptype,
1004     void *pval, unsigned char *penc, int penclen);
1005 int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, const unsigned char **pk,
1006     int *ppklen, X509_ALGOR **pa, X509_PUBKEY *pub);
1007 
1008 int X509_check_trust(X509 *x, int id, int flags);
1009 
1010 int X509_up_ref(X509 *x);
1011 STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain);
1012 
1013 void ERR_load_X509_strings(void);
1014 
1015 /* Error codes for the X509 functions. */
1016 
1017 /* Function codes. */
1018 #define X509_F_ADD_CERT_DIR				 100
1019 #define X509_F_BY_FILE_CTRL				 101
1020 #define X509_F_CHECK_POLICY				 145
1021 #define X509_F_DIR_CTRL					 102
1022 #define X509_F_GET_CERT_BY_SUBJECT			 103
1023 #define X509_F_NETSCAPE_SPKI_B64_DECODE			 129
1024 #define X509_F_NETSCAPE_SPKI_B64_ENCODE			 130
1025 #define X509_F_X509AT_ADD1_ATTR				 135
1026 #define X509_F_X509V3_ADD_EXT				 104
1027 #define X509_F_X509_ATTRIBUTE_CREATE_BY_NID		 136
1028 #define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ		 137
1029 #define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT		 140
1030 #define X509_F_X509_ATTRIBUTE_GET0_DATA			 139
1031 #define X509_F_X509_ATTRIBUTE_SET1_DATA			 138
1032 #define X509_F_X509_CHECK_PRIVATE_KEY			 128
1033 #define X509_F_X509_CRL_PRINT_FP			 147
1034 #define X509_F_X509_EXTENSION_CREATE_BY_NID		 108
1035 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ		 109
1036 #define X509_F_X509_GET_PUBKEY_PARAMETERS		 110
1037 #define X509_F_X509_LOAD_CERT_CRL_FILE			 132
1038 #define X509_F_X509_LOAD_CERT_FILE			 111
1039 #define X509_F_X509_LOAD_CRL_FILE			 112
1040 #define X509_F_X509_NAME_ADD_ENTRY			 113
1041 #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID		 114
1042 #define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT		 131
1043 #define X509_F_X509_NAME_ENTRY_SET_OBJECT		 115
1044 #define X509_F_X509_NAME_ONELINE			 116
1045 #define X509_F_X509_NAME_PRINT				 117
1046 #define X509_F_X509_PRINT_EX_FP				 118
1047 #define X509_F_X509_PUBKEY_GET				 119
1048 #define X509_F_X509_PUBKEY_SET				 120
1049 #define X509_F_X509_REQ_CHECK_PRIVATE_KEY		 144
1050 #define X509_F_X509_REQ_PRINT_EX			 121
1051 #define X509_F_X509_REQ_PRINT_FP			 122
1052 #define X509_F_X509_REQ_TO_X509				 123
1053 #define X509_F_X509_STORE_ADD_CERT			 124
1054 #define X509_F_X509_STORE_ADD_CRL			 125
1055 #define X509_F_X509_STORE_CTX_GET1_ISSUER		 146
1056 #define X509_F_X509_STORE_CTX_INIT			 143
1057 #define X509_F_X509_STORE_CTX_NEW			 142
1058 #define X509_F_X509_STORE_CTX_PURPOSE_INHERIT		 134
1059 #define X509_F_X509_TO_X509_REQ				 126
1060 #define X509_F_X509_TRUST_ADD				 133
1061 #define X509_F_X509_TRUST_SET				 141
1062 #define X509_F_X509_VERIFY_CERT				 127
1063 
1064 /* Reason codes. */
1065 #define X509_R_BAD_X509_FILETYPE			 100
1066 #define X509_R_BASE64_DECODE_ERROR			 118
1067 #define X509_R_CANT_CHECK_DH_KEY			 114
1068 #define X509_R_CERT_ALREADY_IN_HASH_TABLE		 101
1069 #define X509_R_ERR_ASN1_LIB				 102
1070 #define X509_R_INVALID_DIRECTORY			 113
1071 #define X509_R_INVALID_FIELD_NAME			 119
1072 #define X509_R_INVALID_TRUST				 123
1073 #define X509_R_INVALID_VERSION				 137
1074 #define X509_R_KEY_TYPE_MISMATCH			 115
1075 #define X509_R_KEY_VALUES_MISMATCH			 116
1076 #define X509_R_LOADING_CERT_DIR				 103
1077 #define X509_R_LOADING_DEFAULTS				 104
1078 #define X509_R_METHOD_NOT_SUPPORTED			 124
1079 #define X509_R_NO_CERTIFICATE_OR_CRL_FOUND		 136
1080 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY		 105
1081 #define X509_R_PUBLIC_KEY_DECODE_ERROR			 125
1082 #define X509_R_PUBLIC_KEY_ENCODE_ERROR			 126
1083 #define X509_R_SHOULD_RETRY				 106
1084 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN	 107
1085 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY		 108
1086 #define X509_R_UNKNOWN_KEY_TYPE				 117
1087 #define X509_R_UNKNOWN_NID				 109
1088 #define X509_R_UNKNOWN_PURPOSE_ID			 121
1089 #define X509_R_UNKNOWN_TRUST_ID				 120
1090 #define X509_R_UNSUPPORTED_ALGORITHM			 111
1091 #define X509_R_WRONG_LOOKUP_TYPE			 112
1092 #define X509_R_WRONG_TYPE				 122
1093 
1094 #ifdef  __cplusplus
1095 }
1096 #endif
1097 #endif
1098