| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2020-04-23 20:55:52 +08:00
										 |  |  |  * Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2013-12-11 22:28:57 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 21:00:36 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2013-12-11 22:28:57 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-27 22:01:08 +08:00
										 |  |  | #include "internal/refcount.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-02 20:21:34 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This structure holds all parameters associated with a verify operation by | 
					
						
							|  |  |  |  * including an X509_VERIFY_PARAM structure in related structures the | 
					
						
							|  |  |  |  * parameters used can be customized | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct X509_VERIFY_PARAM_st { | 
					
						
							|  |  |  |     char *name; | 
					
						
							|  |  |  |     time_t check_time;          /* Time to use */ | 
					
						
							| 
									
										
										
										
											2016-12-14 00:52:22 +08:00
										 |  |  |     uint32_t inh_flags;         /* Inheritance flags */ | 
					
						
							| 
									
										
										
										
											2015-05-02 20:21:34 +08:00
										 |  |  |     unsigned long flags;        /* Various verify flags */ | 
					
						
							|  |  |  |     int purpose;                /* purpose to check untrusted certificates */ | 
					
						
							|  |  |  |     int trust;                  /* trust setting to check */ | 
					
						
							|  |  |  |     int depth;                  /* Verify depth */ | 
					
						
							| 
									
										
										
										
											2016-03-19 10:09:41 +08:00
										 |  |  |     int auth_level;             /* Security level for chain verification */ | 
					
						
							| 
									
										
										
										
											2015-05-02 20:21:34 +08:00
										 |  |  |     STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */ | 
					
						
							| 
									
										
										
										
											2015-05-03 00:44:08 +08:00
										 |  |  |     /* Peer identity details */ | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     STACK_OF(OPENSSL_STRING) *hosts; /* Set of acceptable names */ | 
					
						
							|  |  |  |     unsigned int hostflags;     /* Flags to control matching features */ | 
					
						
							|  |  |  |     char *peername;             /* Matching hostname in peer certificate */ | 
					
						
							|  |  |  |     char *email;                /* If not NULL email address to match */ | 
					
						
							|  |  |  |     size_t emaillen; | 
					
						
							|  |  |  |     unsigned char *ip;          /* If not NULL IP address to match */ | 
					
						
							|  |  |  |     size_t iplen;               /* Length of IP address */ | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-05-25 06:55:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-28 03:17:28 +08:00
										 |  |  | /* No error callback if depth < 0 */ | 
					
						
							|  |  |  | int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int depth); | 
					
						
							| 
									
										
										
										
											2015-03-15 07:48:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* a sequence of these are used */ | 
					
						
							|  |  |  | struct x509_attributes_st { | 
					
						
							|  |  |  |     ASN1_OBJECT *object; | 
					
						
							| 
									
										
										
										
											2015-03-25 23:08:55 +08:00
										 |  |  |     STACK_OF(ASN1_TYPE) *set; | 
					
						
							| 
									
										
										
										
											2015-03-15 07:48:47 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-03-15 21:43:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct X509_extension_st { | 
					
						
							|  |  |  |     ASN1_OBJECT *object; | 
					
						
							|  |  |  |     ASN1_BOOLEAN critical; | 
					
						
							| 
									
										
										
										
											2015-10-12 03:44:07 +08:00
										 |  |  |     ASN1_OCTET_STRING value; | 
					
						
							| 
									
										
										
										
											2015-03-15 21:43:56 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-09-22 23:20:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Method to handle CRL access. In general a CRL could be very large (several | 
					
						
							|  |  |  |  * Mb) and can consume large amounts of resources if stored in memory by | 
					
						
							|  |  |  |  * multiple processes. This method allows general CRL operations to be | 
					
						
							|  |  |  |  * redirected to more efficient callbacks: for example a CRL entry database. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define X509_CRL_METHOD_DYNAMIC         1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct x509_crl_method_st { | 
					
						
							|  |  |  |     int flags; | 
					
						
							|  |  |  |     int (*crl_init) (X509_CRL *crl); | 
					
						
							|  |  |  |     int (*crl_free) (X509_CRL *crl); | 
					
						
							|  |  |  |     int (*crl_lookup) (X509_CRL *crl, X509_REVOKED **ret, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                        const ASN1_INTEGER *ser, const X509_NAME *issuer); | 
					
						
							| 
									
										
										
										
											2015-09-22 23:20:09 +08:00
										 |  |  |     int (*crl_verify) (X509_CRL *crl, EVP_PKEY *pk); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-01-06 10:54:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  | struct x509_lookup_method_st { | 
					
						
							| 
									
										
										
										
											2018-02-10 02:23:18 +08:00
										 |  |  |     char *name; | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     int (*new_item) (X509_LOOKUP *ctx); | 
					
						
							|  |  |  |     void (*free) (X509_LOOKUP *ctx); | 
					
						
							|  |  |  |     int (*init) (X509_LOOKUP *ctx); | 
					
						
							|  |  |  |     int (*shutdown) (X509_LOOKUP *ctx); | 
					
						
							|  |  |  |     int (*ctrl) (X509_LOOKUP *ctx, int cmd, const char *argc, long argl, | 
					
						
							|  |  |  |                  char **ret); | 
					
						
							| 
									
										
										
										
											2016-07-25 23:46:05 +08:00
										 |  |  |     int (*get_by_subject) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                            const X509_NAME *name, X509_OBJECT *ret); | 
					
						
							| 
									
										
										
										
											2016-07-25 23:46:05 +08:00
										 |  |  |     int (*get_by_issuer_serial) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |                                  const X509_NAME *name, | 
					
						
							|  |  |  |                                  const ASN1_INTEGER *serial, | 
					
						
							| 
									
										
										
										
											2016-07-25 23:46:05 +08:00
										 |  |  |                                  X509_OBJECT *ret); | 
					
						
							|  |  |  |     int (*get_by_fingerprint) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, | 
					
						
							| 
									
										
										
										
											2016-08-01 01:19:49 +08:00
										 |  |  |                                const unsigned char *bytes, int len, | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |                                X509_OBJECT *ret); | 
					
						
							| 
									
										
										
										
											2016-07-25 23:46:05 +08:00
										 |  |  |     int (*get_by_alias) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, | 
					
						
							| 
									
										
										
										
											2016-08-01 01:19:49 +08:00
										 |  |  |                          const char *str, int len, X509_OBJECT *ret); | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* This is the functions plus an instance of the local variables. */ | 
					
						
							|  |  |  | struct x509_lookup_st { | 
					
						
							|  |  |  |     int init;                   /* have we been started */ | 
					
						
							|  |  |  |     int skip;                   /* don't use us. */ | 
					
						
							|  |  |  |     X509_LOOKUP_METHOD *method; /* the functions */ | 
					
						
							| 
									
										
										
										
											2018-02-10 02:23:18 +08:00
										 |  |  |     void *method_data;          /* method data */ | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     X509_STORE *store_ctx;      /* who owns us */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * This is used to hold everything.  It is used for all certificate | 
					
						
							|  |  |  |  * validation.  Once we have a certificate chain, the 'verify' function is | 
					
						
							|  |  |  |  * then called to actually check the cert chain. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct x509_store_st { | 
					
						
							|  |  |  |     /* The following is a cache of trusted certs */ | 
					
						
							|  |  |  |     int cache;                  /* if true, stash any hits */ | 
					
						
							|  |  |  |     STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */ | 
					
						
							|  |  |  |     /* These are external lookup methods */ | 
					
						
							|  |  |  |     STACK_OF(X509_LOOKUP) *get_cert_methods; | 
					
						
							|  |  |  |     X509_VERIFY_PARAM *param; | 
					
						
							|  |  |  |     /* Callbacks for various operations */ | 
					
						
							|  |  |  |     /* called to verify a certificate */ | 
					
						
							|  |  |  |     int (*verify) (X509_STORE_CTX *ctx); | 
					
						
							|  |  |  |     /* error callback */ | 
					
						
							|  |  |  |     int (*verify_cb) (int ok, X509_STORE_CTX *ctx); | 
					
						
							|  |  |  |     /* get issuers cert from ctx */ | 
					
						
							|  |  |  |     int (*get_issuer) (X509 **issuer, X509_STORE_CTX *ctx, X509 *x); | 
					
						
							|  |  |  |     /* check issued */ | 
					
						
							|  |  |  |     int (*check_issued) (X509_STORE_CTX *ctx, X509 *x, X509 *issuer); | 
					
						
							|  |  |  |     /* Check revocation status of chain */ | 
					
						
							|  |  |  |     int (*check_revocation) (X509_STORE_CTX *ctx); | 
					
						
							|  |  |  |     /* retrieve CRL */ | 
					
						
							|  |  |  |     int (*get_crl) (X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); | 
					
						
							|  |  |  |     /* Check CRL validity */ | 
					
						
							|  |  |  |     int (*check_crl) (X509_STORE_CTX *ctx, X509_CRL *crl); | 
					
						
							|  |  |  |     /* Check certificate against CRL */ | 
					
						
							|  |  |  |     int (*cert_crl) (X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); | 
					
						
							| 
									
										
										
										
											2016-07-20 22:23:34 +08:00
										 |  |  |     /* Check policy status of the chain */ | 
					
						
							|  |  |  |     int (*check_policy) (X509_STORE_CTX *ctx); | 
					
						
							| 
									
										
										
										
											2020-03-23 15:30:37 +08:00
										 |  |  |     STACK_OF(X509) *(*lookup_certs) (X509_STORE_CTX *ctx, | 
					
						
							|  |  |  |                                      const X509_NAME *nm); | 
					
						
							|  |  |  |     /* cannot constify 'ctx' param due to lookup_certs_sk() in x509_vfy.c */ | 
					
						
							|  |  |  |     STACK_OF(X509_CRL) *(*lookup_crls) (const X509_STORE_CTX *ctx, | 
					
						
							|  |  |  |                                         const X509_NAME *nm); | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     int (*cleanup) (X509_STORE_CTX *ctx); | 
					
						
							|  |  |  |     CRYPTO_EX_DATA ex_data; | 
					
						
							| 
									
										
										
										
											2016-08-27 22:01:08 +08:00
										 |  |  |     CRYPTO_REF_COUNT references; | 
					
						
							| 
									
										
										
										
											2016-04-15 11:59:26 +08:00
										 |  |  |     CRYPTO_RWLOCK *lock; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 10:54:18 +08:00
										 |  |  | typedef struct lookup_dir_hashes_st BY_DIR_HASH; | 
					
						
							|  |  |  | typedef struct lookup_dir_entry_st BY_DIR_ENTRY; | 
					
						
							|  |  |  | DEFINE_STACK_OF(BY_DIR_HASH) | 
					
						
							|  |  |  | DEFINE_STACK_OF(BY_DIR_ENTRY) | 
					
						
							|  |  |  | typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; | 
					
						
							|  |  |  | DEFINE_STACK_OF(STACK_OF_X509_NAME_ENTRY) | 
					
						
							| 
									
										
										
										
											2017-04-21 22:56:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void x509_set_signature_info(X509_SIG_INFO *siginf, const X509_ALGOR *alg, | 
					
						
							|  |  |  |                              const ASN1_STRING *sig); | 
					
						
							| 
									
										
										
										
											2019-12-24 00:37:17 +08:00
										 |  |  | int x509_likely_issued(X509 *issuer, X509 *subject, | 
					
						
							|  |  |  |                        OPENSSL_CTX *libctx, const char *propq); | 
					
						
							|  |  |  | int x509_signing_allowed(const X509 *issuer, const X509 *subject); |