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