155714Skris/* crypto/x509/x509_vfy.h */
255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355714Skris * All rights reserved.
455714Skris *
555714Skris * This package is an SSL implementation written
655714Skris * by Eric Young (eay@cryptsoft.com).
755714Skris * The implementation was written so as to conform with Netscapes SSL.
855714Skris *
955714Skris * This library is free for commercial and non-commercial use as long as
1055714Skris * the following conditions are aheared to.  The following conditions
1155714Skris * apply to all code found in this distribution, be it the RC4, RSA,
1255714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355714Skris * included with this distribution is covered by the same copyright terms
1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1555714Skris *
1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1755714Skris * the code are not to be removed.
1855714Skris * If this package is used in a product, Eric Young should be given attribution
1955714Skris * as the author of the parts of the library used.
2055714Skris * This can be in the form of a textual message at program startup or
2155714Skris * in documentation (online or textual) provided with the package.
2255714Skris *
2355714Skris * Redistribution and use in source and binary forms, with or without
2455714Skris * modification, are permitted provided that the following conditions
2555714Skris * are met:
2655714Skris * 1. Redistributions of source code must retain the copyright
2755714Skris *    notice, this list of conditions and the following disclaimer.
2855714Skris * 2. Redistributions in binary form must reproduce the above copyright
2955714Skris *    notice, this list of conditions and the following disclaimer in the
3055714Skris *    documentation and/or other materials provided with the distribution.
3155714Skris * 3. All advertising materials mentioning features or use of this software
3255714Skris *    must display the following acknowledgement:
3355714Skris *    "This product includes cryptographic software written by
3455714Skris *     Eric Young (eay@cryptsoft.com)"
3555714Skris *    The word 'cryptographic' can be left out if the rouines from the library
3655714Skris *    being used are not cryptographic related :-).
3755714Skris * 4. If you include any Windows specific code (or a derivative thereof) from
3855714Skris *    the apps directory (application code) you must include an acknowledgement:
3955714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4055714Skris *
4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5155714Skris * SUCH DAMAGE.
5255714Skris *
5355714Skris * The licence and distribution terms for any publically available version or
5455714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555714Skris * copied and put under another distribution licence
5655714Skris * [including the GNU Public Licence.]
5755714Skris */
5855714Skris
5955714Skris#ifndef HEADER_X509_H
6055714Skris#include <openssl/x509.h>
6155714Skris/* openssl/x509.h ends up #include-ing this file at about the only
6255714Skris * appropriate moment. */
6355714Skris#endif
6455714Skris
6555714Skris#ifndef HEADER_X509_VFY_H
6655714Skris#define HEADER_X509_VFY_H
6755714Skris
68160814Ssimon#include <openssl/opensslconf.h>
69109998Smarkm#ifndef OPENSSL_NO_LHASH
7068651Skris#include <openssl/lhash.h>
7168651Skris#endif
7268651Skris#include <openssl/bio.h>
7368651Skris#include <openssl/crypto.h>
74109998Smarkm#include <openssl/symhacks.h>
7568651Skris
7655714Skris#ifdef  __cplusplus
7755714Skrisextern "C" {
7855714Skris#endif
7955714Skris
80238405Sjkim#if 0
8155714Skris/* Outer object */
8255714Skristypedef struct x509_hash_dir_st
8355714Skris	{
8455714Skris	int num_dirs;
8555714Skris	char **dirs;
8655714Skris	int *dirs_type;
8755714Skris	int num_dirs_alloced;
8855714Skris	} X509_HASH_DIR_CTX;
89238405Sjkim#endif
9055714Skris
9155714Skristypedef struct x509_file_st
9255714Skris	{
9355714Skris	int num_paths;	/* number of paths to files or directories */
9455714Skris	int num_alloced;
9555714Skris	char **paths;	/* the list of paths or directories */
9655714Skris	int *path_type;
9755714Skris	} X509_CERT_FILE_CTX;
9855714Skris
9955714Skris/*******************************/
10055714Skris/*
10155714SkrisSSL_CTX -> X509_STORE
10255714Skris		-> X509_LOOKUP
10355714Skris			->X509_LOOKUP_METHOD
10455714Skris		-> X509_LOOKUP
10555714Skris			->X509_LOOKUP_METHOD
10655714Skris
10755714SkrisSSL	-> X509_STORE_CTX
10855714Skris		->X509_STORE
10955714Skris
11055714SkrisThe X509_STORE holds the tables etc for verification stuff.
11155714SkrisA X509_STORE_CTX is used while validating a single certificate.
11255714SkrisThe X509_STORE has X509_LOOKUPs for looking up certs.
11355714SkrisThe X509_STORE then calls a function to actually verify the
11455714Skriscertificate chain.
11555714Skris*/
11655714Skris
11755714Skris#define X509_LU_RETRY		-1
11855714Skris#define X509_LU_FAIL		0
11955714Skris#define X509_LU_X509		1
12055714Skris#define X509_LU_CRL		2
12155714Skris#define X509_LU_PKEY		3
12255714Skris
12355714Skristypedef struct x509_object_st
12455714Skris	{
12555714Skris	/* one of the above types */
12655714Skris	int type;
12755714Skris	union	{
12855714Skris		char *ptr;
12955714Skris		X509 *x509;
13055714Skris		X509_CRL *crl;
13155714Skris		EVP_PKEY *pkey;
13255714Skris		} data;
13355714Skris	} X509_OBJECT;
13455714Skris
13555714Skristypedef struct x509_lookup_st X509_LOOKUP;
13655714Skris
13755714SkrisDECLARE_STACK_OF(X509_LOOKUP)
13868651SkrisDECLARE_STACK_OF(X509_OBJECT)
13955714Skris
14055714Skris/* This is a static that defines the function interface */
14155714Skristypedef struct x509_lookup_method_st
14255714Skris	{
14355714Skris	const char *name;
14455714Skris	int (*new_item)(X509_LOOKUP *ctx);
14555714Skris	void (*free)(X509_LOOKUP *ctx);
14655714Skris	int (*init)(X509_LOOKUP *ctx);
14755714Skris	int (*shutdown)(X509_LOOKUP *ctx);
14855714Skris	int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl,
14955714Skris			char **ret);
15055714Skris	int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name,
15155714Skris			      X509_OBJECT *ret);
15255714Skris	int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name,
15355714Skris				    ASN1_INTEGER *serial,X509_OBJECT *ret);
15455714Skris	int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type,
15555714Skris				  unsigned char *bytes,int len,
15655714Skris				  X509_OBJECT *ret);
15755714Skris	int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len,
15855714Skris			    X509_OBJECT *ret);
15955714Skris	} X509_LOOKUP_METHOD;
16055714Skris
161160814Ssimon/* This structure hold all parameters associated with a verify operation
162160814Ssimon * by including an X509_VERIFY_PARAM structure in related structures the
163160814Ssimon * parameters used can be customized
164160814Ssimon */
165160814Ssimon
166160814Ssimontypedef struct X509_VERIFY_PARAM_st
167160814Ssimon	{
168160814Ssimon	char *name;
169160814Ssimon	time_t check_time;	/* Time to use */
170160814Ssimon	unsigned long inh_flags; /* Inheritance flags */
171160814Ssimon	unsigned long flags;	/* Various verify flags */
172160814Ssimon	int purpose;		/* purpose to check untrusted certificates */
173160814Ssimon	int trust;		/* trust setting to check */
174160814Ssimon	int depth;		/* Verify depth */
175160814Ssimon	STACK_OF(ASN1_OBJECT) *policies;	/* Permissible policies */
176160814Ssimon	} X509_VERIFY_PARAM;
177160814Ssimon
178160814SsimonDECLARE_STACK_OF(X509_VERIFY_PARAM)
179160814Ssimon
18055714Skris/* This is used to hold everything.  It is used for all certificate
18155714Skris * validation.  Once we have a certificate chain, the 'verify'
18255714Skris * function is then called to actually check the cert chain. */
183109998Smarkmstruct x509_store_st
18455714Skris	{
18555714Skris	/* The following is a cache of trusted certs */
18655714Skris	int cache; 	/* if true, stash any hits */
18768651Skris	STACK_OF(X509_OBJECT) *objs;	/* Cache of all objects */
18855714Skris
18955714Skris	/* These are external lookup methods */
19055714Skris	STACK_OF(X509_LOOKUP) *get_cert_methods;
191109998Smarkm
192160814Ssimon	X509_VERIFY_PARAM *param;
193109998Smarkm
194109998Smarkm	/* Callbacks for various operations */
19555714Skris	int (*verify)(X509_STORE_CTX *ctx);	/* called to verify a certificate */
19655714Skris	int (*verify_cb)(int ok,X509_STORE_CTX *ctx);	/* error callback */
197109998Smarkm	int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);	/* get issuers cert from ctx */
198109998Smarkm	int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
199109998Smarkm	int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
200109998Smarkm	int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
201109998Smarkm	int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
202109998Smarkm	int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
203238405Sjkim	STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
204238405Sjkim	STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
205109998Smarkm	int (*cleanup)(X509_STORE_CTX *ctx);
20655714Skris
20755714Skris	CRYPTO_EX_DATA ex_data;
20855714Skris	int references;
209109998Smarkm	} /* X509_STORE */;
21055714Skris
211160814Ssimonint X509_STORE_set_depth(X509_STORE *store, int depth);
21255714Skris
21355714Skris#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))
21455714Skris#define X509_STORE_set_verify_func(ctx,func)	((ctx)->verify=(func))
21555714Skris
21655714Skris/* This is the functions plus an instance of the local variables. */
21755714Skrisstruct x509_lookup_st
21855714Skris	{
21955714Skris	int init;			/* have we been started */
22055714Skris	int skip;			/* don't use us. */
22155714Skris	X509_LOOKUP_METHOD *method;	/* the functions */
22255714Skris	char *method_data;		/* method data */
22355714Skris
22455714Skris	X509_STORE *store_ctx;	/* who owns us */
225109998Smarkm	} /* X509_LOOKUP */;
22655714Skris
22768651Skris/* This is a used when verifying cert chains.  Since the
22855714Skris * gathering of the cert chain can take some time (and have to be
22955714Skris * 'retried', this needs to be kept and passed around. */
23068651Skrisstruct x509_store_ctx_st      /* X509_STORE_CTX */
23155714Skris	{
23255714Skris	X509_STORE *ctx;
23355714Skris	int current_method;	/* used when looking up certs */
23455714Skris
23555714Skris	/* The following are set by the caller */
23655714Skris	X509 *cert;		/* The cert to check */
23755714Skris	STACK_OF(X509) *untrusted;	/* chain of X509s - untrusted - passed in */
238160814Ssimon	STACK_OF(X509_CRL) *crls;	/* set of CRLs passed in */
239160814Ssimon
240160814Ssimon	X509_VERIFY_PARAM *param;
24168651Skris	void *other_ctx;	/* Other info for use with get_issuer() */
24255714Skris
24368651Skris	/* Callbacks for various operations */
24468651Skris	int (*verify)(X509_STORE_CTX *ctx);	/* called to verify a certificate */
24568651Skris	int (*verify_cb)(int ok,X509_STORE_CTX *ctx);		/* error callback */
24668651Skris	int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);	/* get issuers cert from ctx */
24768651Skris	int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */
248109998Smarkm	int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */
249109998Smarkm	int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
250109998Smarkm	int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
251109998Smarkm	int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
252160814Ssimon	int (*check_policy)(X509_STORE_CTX *ctx);
253238405Sjkim	STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm);
254238405Sjkim	STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm);
25568651Skris	int (*cleanup)(X509_STORE_CTX *ctx);
25668651Skris
25755714Skris	/* The following is built up */
25855714Skris	int valid;		/* if 0, rebuild chain */
25955714Skris	int last_untrusted;	/* index of last untrusted cert */
26055714Skris	STACK_OF(X509) *chain; 		/* chain of X509s - built up and trusted */
261160814Ssimon	X509_POLICY_TREE *tree;	/* Valid policy tree */
26255714Skris
263160814Ssimon	int explicit_policy;	/* Require explicit policy value */
264160814Ssimon
26555714Skris	/* When something goes wrong, this is why */
26655714Skris	int error_depth;
26755714Skris	int error;
26855714Skris	X509 *current_cert;
26968651Skris	X509 *current_issuer;	/* cert currently being tested as valid issuer */
270109998Smarkm	X509_CRL *current_crl;	/* current CRL */
27155714Skris
272238405Sjkim	int current_crl_score;  /* score of current CRL */
273238405Sjkim	unsigned int current_reasons;  /* Reason mask */
274238405Sjkim
275238405Sjkim	X509_STORE_CTX *parent; /* For CRL path validation: parent context */
276238405Sjkim
27755714Skris	CRYPTO_EX_DATA ex_data;
278109998Smarkm	} /* X509_STORE_CTX */;
27955714Skris
280160814Ssimonvoid X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
28155714Skris
28255714Skris#define X509_STORE_CTX_set_app_data(ctx,data) \
28355714Skris	X509_STORE_CTX_set_ex_data(ctx,0,data)
28455714Skris#define X509_STORE_CTX_get_app_data(ctx) \
28555714Skris	X509_STORE_CTX_get_ex_data(ctx,0)
28655714Skris
28755714Skris#define X509_L_FILE_LOAD	1
28855714Skris#define X509_L_ADD_DIR		2
28955714Skris
29055714Skris#define X509_LOOKUP_load_file(x,name,type) \
29155714Skris		X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
29255714Skris
29355714Skris#define X509_LOOKUP_add_dir(x,name,type) \
29455714Skris		X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
29555714Skris
29655714Skris#define		X509_V_OK					0
29759191Skris/* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */
29855714Skris
29955714Skris#define		X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT		2
30055714Skris#define		X509_V_ERR_UNABLE_TO_GET_CRL			3
30155714Skris#define		X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE	4
30255714Skris#define		X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE	5
30355714Skris#define		X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY	6
30455714Skris#define		X509_V_ERR_CERT_SIGNATURE_FAILURE		7
30555714Skris#define		X509_V_ERR_CRL_SIGNATURE_FAILURE		8
306160814Ssimon#define		X509_V_ERR_CERT_NOT_YET_VALID			9
30755714Skris#define		X509_V_ERR_CERT_HAS_EXPIRED			10
30855714Skris#define		X509_V_ERR_CRL_NOT_YET_VALID			11
30955714Skris#define		X509_V_ERR_CRL_HAS_EXPIRED			12
31055714Skris#define		X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD	13
31155714Skris#define		X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD	14
31255714Skris#define		X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD	15
31355714Skris#define		X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD	16
31455714Skris#define		X509_V_ERR_OUT_OF_MEM				17
31555714Skris#define		X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT		18
31655714Skris#define		X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN		19
31755714Skris#define		X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY	20
31855714Skris#define		X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE	21
31955714Skris#define		X509_V_ERR_CERT_CHAIN_TOO_LONG			22
32055714Skris#define		X509_V_ERR_CERT_REVOKED				23
32159191Skris#define		X509_V_ERR_INVALID_CA				24
32259191Skris#define		X509_V_ERR_PATH_LENGTH_EXCEEDED			25
32359191Skris#define		X509_V_ERR_INVALID_PURPOSE			26
32459191Skris#define		X509_V_ERR_CERT_UNTRUSTED			27
32559191Skris#define		X509_V_ERR_CERT_REJECTED			28
32668651Skris/* These are 'informational' when looking for issuer cert */
32768651Skris#define		X509_V_ERR_SUBJECT_ISSUER_MISMATCH		29
32868651Skris#define		X509_V_ERR_AKID_SKID_MISMATCH			30
32968651Skris#define		X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH		31
33068651Skris#define		X509_V_ERR_KEYUSAGE_NO_CERTSIGN			32
33155714Skris
332109998Smarkm#define		X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER		33
333109998Smarkm#define		X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION		34
334127128Snectar#define		X509_V_ERR_KEYUSAGE_NO_CRL_SIGN			35
335127128Snectar#define		X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION	36
336160814Ssimon#define		X509_V_ERR_INVALID_NON_CA			37
337160814Ssimon#define		X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED		38
338160814Ssimon#define		X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE	39
339160814Ssimon#define		X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED	40
340109998Smarkm
341160814Ssimon#define		X509_V_ERR_INVALID_EXTENSION			41
342160814Ssimon#define		X509_V_ERR_INVALID_POLICY_EXTENSION		42
343160814Ssimon#define		X509_V_ERR_NO_EXPLICIT_POLICY			43
344238405Sjkim#define		X509_V_ERR_DIFFERENT_CRL_SCOPE			44
345238405Sjkim#define		X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE	45
346160814Ssimon
347238405Sjkim#define		X509_V_ERR_UNNESTED_RESOURCE			46
348160814Ssimon
349238405Sjkim#define		X509_V_ERR_PERMITTED_VIOLATION			47
350238405Sjkim#define		X509_V_ERR_EXCLUDED_VIOLATION			48
351238405Sjkim#define		X509_V_ERR_SUBTREE_MINMAX			49
352238405Sjkim#define		X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE		51
353238405Sjkim#define		X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX	52
354238405Sjkim#define		X509_V_ERR_UNSUPPORTED_NAME_SYNTAX		53
355238405Sjkim#define		X509_V_ERR_CRL_PATH_VALIDATION_ERROR		54
356238405Sjkim
35755714Skris/* The application is not happy */
35855714Skris#define		X509_V_ERR_APPLICATION_VERIFICATION		50
35955714Skris
36068651Skris/* Certificate verify flags */
36168651Skris
362127128Snectar/* Send issuer+subject checks to verify_cb */
363127128Snectar#define	X509_V_FLAG_CB_ISSUER_CHECK		0x1
364127128Snectar/* Use check time instead of current time */
365127128Snectar#define	X509_V_FLAG_USE_CHECK_TIME		0x2
366127128Snectar/* Lookup CRLs */
367127128Snectar#define	X509_V_FLAG_CRL_CHECK			0x4
368127128Snectar/* Lookup CRLs for whole chain */
369127128Snectar#define	X509_V_FLAG_CRL_CHECK_ALL		0x8
370127128Snectar/* Ignore unhandled critical extensions */
371127128Snectar#define	X509_V_FLAG_IGNORE_CRITICAL		0x10
372127128Snectar/* Disable workarounds for broken certificates */
373127128Snectar#define	X509_V_FLAG_X509_STRICT			0x20
374160814Ssimon/* Enable proxy certificate validation */
375160814Ssimon#define	X509_V_FLAG_ALLOW_PROXY_CERTS		0x40
376160814Ssimon/* Enable policy checking */
377160814Ssimon#define X509_V_FLAG_POLICY_CHECK		0x80
378160814Ssimon/* Policy variable require-explicit-policy */
379160814Ssimon#define X509_V_FLAG_EXPLICIT_POLICY		0x100
380160814Ssimon/* Policy variable inhibit-any-policy */
381160814Ssimon#define	X509_V_FLAG_INHIBIT_ANY			0x200
382160814Ssimon/* Policy variable inhibit-policy-mapping */
383160814Ssimon#define X509_V_FLAG_INHIBIT_MAP			0x400
384160814Ssimon/* Notify callback that policy is OK */
385160814Ssimon#define X509_V_FLAG_NOTIFY_POLICY		0x800
386238405Sjkim/* Extended CRL features such as indirect CRLs, alternate CRL signing keys */
387238405Sjkim#define X509_V_FLAG_EXTENDED_CRL_SUPPORT	0x1000
388238405Sjkim/* Delta CRL support */
389238405Sjkim#define X509_V_FLAG_USE_DELTAS			0x2000
390205128Ssimon/* Check selfsigned CA signature */
391205128Ssimon#define X509_V_FLAG_CHECK_SS_SIGNATURE		0x4000
392205128Ssimon
393238405Sjkim
394160814Ssimon#define X509_VP_FLAG_DEFAULT			0x1
395160814Ssimon#define X509_VP_FLAG_OVERWRITE			0x2
396160814Ssimon#define X509_VP_FLAG_RESET_FLAGS		0x4
397160814Ssimon#define X509_VP_FLAG_LOCKED			0x8
398160814Ssimon#define X509_VP_FLAG_ONCE			0x10
399160814Ssimon
400160814Ssimon/* Internal use: mask of policy related options */
401160814Ssimon#define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \
402160814Ssimon				| X509_V_FLAG_EXPLICIT_POLICY \
403160814Ssimon				| X509_V_FLAG_INHIBIT_ANY \
404160814Ssimon				| X509_V_FLAG_INHIBIT_MAP)
405160814Ssimon
40668651Skrisint X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
40768651Skris	     X509_NAME *name);
40868651SkrisX509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,int type,X509_NAME *name);
40968651SkrisX509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x);
41055714Skrisvoid X509_OBJECT_up_ref_count(X509_OBJECT *a);
41155714Skrisvoid X509_OBJECT_free_contents(X509_OBJECT *a);
41255714SkrisX509_STORE *X509_STORE_new(void );
41355714Skrisvoid X509_STORE_free(X509_STORE *v);
41455714Skris
415238405SjkimSTACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *st, X509_NAME *nm);
416238405SjkimSTACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *st, X509_NAME *nm);
417160814Ssimonint X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags);
418109998Smarkmint X509_STORE_set_purpose(X509_STORE *ctx, int purpose);
419109998Smarkmint X509_STORE_set_trust(X509_STORE *ctx, int trust);
420160814Ssimonint X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm);
421109998Smarkm
422238405Sjkimvoid X509_STORE_set_verify_cb(X509_STORE *ctx,
423238405Sjkim				  int (*verify_cb)(int, X509_STORE_CTX *));
424238405Sjkim
42559191SkrisX509_STORE_CTX *X509_STORE_CTX_new(void);
42668651Skris
42768651Skrisint X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
42868651Skris
42959191Skrisvoid X509_STORE_CTX_free(X509_STORE_CTX *ctx);
430109998Smarkmint X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
43155714Skris			 X509 *x509, STACK_OF(X509) *chain);
43268651Skrisvoid X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk);
43355714Skrisvoid X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
43455714Skris
43555714SkrisX509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
43655714Skris
43755714SkrisX509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
43855714SkrisX509_LOOKUP_METHOD *X509_LOOKUP_file(void);
43955714Skris
44055714Skrisint X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
44155714Skrisint X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
44255714Skris
44355714Skrisint X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
44455714Skris	X509_OBJECT *ret);
44555714Skris
44655714Skrisint X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
44755714Skris	long argl, char **ret);
44855714Skris
449109998Smarkm#ifndef OPENSSL_NO_STDIO
45055714Skrisint X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
45155714Skrisint X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
45259191Skrisint X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type);
45355714Skris#endif
45455714Skris
45555714Skris
45655714SkrisX509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
45755714Skrisvoid X509_LOOKUP_free(X509_LOOKUP *ctx);
45855714Skrisint X509_LOOKUP_init(X509_LOOKUP *ctx);
45955714Skrisint X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
46055714Skris	X509_OBJECT *ret);
46155714Skrisint X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
46255714Skris	ASN1_INTEGER *serial, X509_OBJECT *ret);
46355714Skrisint X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
46455714Skris	unsigned char *bytes, int len, X509_OBJECT *ret);
46555714Skrisint X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
46655714Skris	int len, X509_OBJECT *ret);
46755714Skrisint X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
46855714Skris
469109998Smarkm#ifndef OPENSSL_NO_STDIO
47055714Skrisint	X509_STORE_load_locations (X509_STORE *ctx,
47155714Skris		const char *file, const char *dir);
47255714Skrisint	X509_STORE_set_default_paths(X509_STORE *ctx);
47355714Skris#endif
47455714Skris
47559191Skrisint X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
47659191Skris	CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
47755714Skrisint	X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
47855714Skrisvoid *	X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
47955714Skrisint	X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
48055714Skrisvoid	X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
48155714Skrisint	X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
48255714SkrisX509 *	X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
483238405SjkimX509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx);
484238405SjkimX509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx);
485238405SjkimX509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx);
48655714SkrisSTACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
48759191SkrisSTACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
48855714Skrisvoid	X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
48955714Skrisvoid	X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
490160814Ssimonvoid	X509_STORE_CTX_set0_crls(X509_STORE_CTX *c,STACK_OF(X509_CRL) *sk);
49159191Skrisint X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
49259191Skrisint X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
49359191Skrisint X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
49459191Skris				int purpose, int trust);
495160814Ssimonvoid X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags);
496160814Ssimonvoid X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags,
497160814Ssimon								time_t t);
49889837Skrisvoid X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
49989837Skris				  int (*verify_cb)(int, X509_STORE_CTX *));
500160814Ssimon
501160814SsimonX509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx);
502160814Ssimonint X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx);
50355714Skris
504160814SsimonX509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx);
505160814Ssimonvoid X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
506160814Ssimonint X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
507160814Ssimon
508160814Ssimon/* X509_VERIFY_PARAM functions */
509160814Ssimon
510160814SsimonX509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void);
511160814Ssimonvoid X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param);
512160814Ssimonint X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to,
513160814Ssimon						const X509_VERIFY_PARAM *from);
514160814Ssimonint X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to,
515160814Ssimon						const X509_VERIFY_PARAM *from);
516160814Ssimonint X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name);
517160814Ssimonint X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags);
518160814Ssimonint X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,
519160814Ssimon							unsigned long flags);
520160814Ssimonunsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param);
521160814Ssimonint X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose);
522160814Ssimonint X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust);
523160814Ssimonvoid X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth);
524160814Ssimonvoid X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t);
525160814Ssimonint X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,
526160814Ssimon						ASN1_OBJECT *policy);
527160814Ssimonint X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param,
528160814Ssimon					STACK_OF(ASN1_OBJECT) *policies);
529160814Ssimonint X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param);
530160814Ssimon
531160814Ssimonint X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param);
532160814Ssimonconst X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name);
533160814Ssimonvoid X509_VERIFY_PARAM_table_cleanup(void);
534160814Ssimon
535160814Ssimonint X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,
536160814Ssimon			STACK_OF(X509) *certs,
537160814Ssimon			STACK_OF(ASN1_OBJECT) *policy_oids,
538160814Ssimon			unsigned int flags);
539160814Ssimon
540160814Ssimonvoid X509_policy_tree_free(X509_POLICY_TREE *tree);
541160814Ssimon
542160814Ssimonint X509_policy_tree_level_count(const X509_POLICY_TREE *tree);
543160814SsimonX509_POLICY_LEVEL *
544160814Ssimon	X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, int i);
545160814Ssimon
546160814SsimonSTACK_OF(X509_POLICY_NODE) *
547160814Ssimon	X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree);
548160814Ssimon
549160814SsimonSTACK_OF(X509_POLICY_NODE) *
550160814Ssimon	X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree);
551160814Ssimon
552160814Ssimonint X509_policy_level_node_count(X509_POLICY_LEVEL *level);
553160814Ssimon
554160814SsimonX509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i);
555160814Ssimon
556160814Ssimonconst ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node);
557160814Ssimon
558160814SsimonSTACK_OF(POLICYQUALINFO) *
559160814Ssimon	X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node);
560160814Ssimonconst X509_POLICY_NODE *
561160814Ssimon	X509_policy_node_get0_parent(const X509_POLICY_NODE *node);
562160814Ssimon
56355714Skris#ifdef  __cplusplus
56455714Skris}
56555714Skris#endif
56655714Skris#endif
56755714Skris
568