2 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
5 /* ====================================================================
6 * Copyright (c) 2015 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
59 /* Internal X509 structures and functions: not for application use */
61 /* Note: unless otherwise stated a field pointer is mandatory and should
62 * never be set to NULL: the ASN.1 code and accessors rely on mandatory
63 * fields never being NULL.
67 * name entry structure, equivalent to AttributeTypeAndValue defined
70 struct X509_name_entry_st {
71 ASN1_OBJECT *object; /* AttributeType */
72 ASN1_STRING *value; /* AttributeValue */
73 int set; /* index of RDNSequence for this entry */
74 int size; /* temp variable */
77 /* Name from RFC 5280. */
79 STACK_OF(X509_NAME_ENTRY) *entries; /* DN components */
80 int modified; /* true if 'bytes' needs to be built */
81 BUF_MEM *bytes; /* cached encoding: cannot be NULL */
82 /* canonical encoding used for rapid Name comparison */
83 unsigned char *canon_enc;
87 /* PKCS#10 certificate request */
89 struct X509_req_info_st {
90 ASN1_ENCODING enc; /* cached encoding of signed part */
91 ASN1_INTEGER *version; /* version, defaults to v1(0) so can be NULL */
92 X509_NAME *subject; /* certificate request DN */
93 X509_PUBKEY *pubkey; /* public key of request */
95 * Zero or more attributes.
96 * NB: although attributes is a mandatory field some broken
97 * encodings omit it so this may be NULL in that case.
99 STACK_OF(X509_ATTRIBUTE) *attributes;
103 X509_REQ_INFO req_info; /* signed certificate request data */
104 X509_ALGOR sig_alg; /* signature algorithm */
105 ASN1_BIT_STRING *signature; /* signature */
110 struct X509_crl_info_st {
111 ASN1_INTEGER *version; /* version: defaults to v1(0) so may be NULL */
112 X509_ALGOR sig_alg; /* signature algorithm */
113 X509_NAME *issuer; /* CRL issuer name */
114 ASN1_TIME *lastUpdate; /* lastUpdate field */
115 ASN1_TIME *nextUpdate; /* nextUpdate field: optional */
116 STACK_OF(X509_REVOKED) *revoked; /* revoked entries: optional */
117 STACK_OF(X509_EXTENSION) *extensions; /* extensions: optional */
118 ASN1_ENCODING enc; /* encoding of signed portion of CRL */
122 X509_CRL_INFO crl; /* signed CRL data */
123 X509_ALGOR sig_alg; /* CRL signature algorithm */
124 ASN1_BIT_STRING signature; /* CRL signature */
128 * Cached copies of decoded extension values, since extensions
129 * are optional any of these can be NULL.
131 AUTHORITY_KEYID *akid;
132 ISSUING_DIST_POINT *idp;
133 /* Convenient breakdown of IDP */
136 /* CRL and base CRL numbers for delta processing */
137 ASN1_INTEGER *crl_number;
138 ASN1_INTEGER *base_crl_number;
139 STACK_OF(GENERAL_NAMES) *issuers;
141 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
142 /* alternative method to handle this CRL */
143 const X509_CRL_METHOD *meth;
148 struct x509_revoked_st {
149 ASN1_INTEGER serialNumber; /* revoked entry serial number */
150 ASN1_TIME *revocationDate; /* revocation date */
151 STACK_OF(X509_EXTENSION) *extensions; /* CRL entry extensions: optional */
152 /* decoded value of CRLissuer extension: set if indirect CRL */
153 STACK_OF(GENERAL_NAME) *issuer;
154 /* revocation reason: set to CRL_REASON_NONE if reason extension absent */
157 * CRL entries are reordered for faster lookup of serial numbers. This
158 * field contains the original load sequence for this entry.
164 * This stuff is certificate "auxiliary info": it contains details which are
165 * useful in certificate stores and databases. When used this is tagged onto
166 * the end of the certificate itself. OpenSSL specific structure not defined
170 struct x509_cert_aux_st {
171 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
172 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
173 ASN1_UTF8STRING *alias; /* "friendly name" */
174 ASN1_OCTET_STRING *keyid; /* key id of private key */
175 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
178 struct x509_cinf_st {
179 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
180 ASN1_INTEGER serialNumber;
181 X509_ALGOR signature;
186 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
187 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
188 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
195 ASN1_BIT_STRING signature;
197 CRYPTO_EX_DATA ex_data;
198 /* These contain copies of various extension values */
205 ASN1_OCTET_STRING *skid;
206 AUTHORITY_KEYID *akid;
207 X509_POLICY_CACHE *policy_cache;
208 STACK_OF(DIST_POINT) *crldp;
209 STACK_OF(GENERAL_NAME) *altname;
210 NAME_CONSTRAINTS *nc;
211 #ifndef OPENSSL_NO_RFC3779
212 STACK_OF(IPAddressFamily) *rfc3779_addr;
213 struct ASIdentifiers_st *rfc3779_asid;
215 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
221 * This is a used when verifying cert chains. Since the gathering of the
222 * cert chain can take some time (and have to be 'retried', this needs to be
223 * kept and passed around.
225 struct x509_store_ctx_st { /* X509_STORE_CTX */
227 /* used when looking up certs */
229 /* The following are set by the caller */
230 /* The cert to check */
232 /* chain of X509s - untrusted - passed in */
233 STACK_OF(X509) *untrusted;
234 /* set of CRLs passed in */
235 STACK_OF(X509_CRL) *crls;
236 X509_VERIFY_PARAM *param;
237 /* Other info for use with get_issuer() */
239 /* Callbacks for various operations */
240 /* called to verify a certificate */
241 int (*verify) (X509_STORE_CTX *ctx);
243 int (*verify_cb) (int ok, X509_STORE_CTX *ctx);
244 /* get issuers cert from ctx */
245 int (*get_issuer) (X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
247 int (*check_issued) (X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
248 /* Check revocation status of chain */
249 int (*check_revocation) (X509_STORE_CTX *ctx);
251 int (*get_crl) (X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x);
252 /* Check CRL validity */
253 int (*check_crl) (X509_STORE_CTX *ctx, X509_CRL *crl);
254 /* Check certificate against CRL */
255 int (*cert_crl) (X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x);
256 int (*check_policy) (X509_STORE_CTX *ctx);
257 STACK_OF(X509) *(*lookup_certs) (X509_STORE_CTX *ctx, X509_NAME *nm);
258 STACK_OF(X509_CRL) *(*lookup_crls) (X509_STORE_CTX *ctx, X509_NAME *nm);
259 int (*cleanup) (X509_STORE_CTX *ctx);
260 /* The following is built up */
261 /* if 0, rebuild chain */
263 /* number of untrusted certs */
265 /* chain of X509s - built up and trusted */
266 STACK_OF(X509) *chain;
267 /* Valid policy tree */
268 X509_POLICY_TREE *tree;
269 /* Require explicit policy value */
271 /* When something goes wrong, this is why */
275 /* cert currently being tested as valid issuer */
276 X509 *current_issuer;
278 X509_CRL *current_crl;
279 /* score of current CRL */
280 int current_crl_score;
282 unsigned int current_reasons;
283 /* For CRL path validation: parent context */
284 X509_STORE_CTX *parent;
285 CRYPTO_EX_DATA ex_data;
287 /* signed via bare TA public key, rather than CA certificate */
291 /* PKCS#8 private key info structure */
293 struct pkcs8_priv_key_info_st {
294 ASN1_INTEGER *version;
296 ASN1_OCTET_STRING *pkey;
297 STACK_OF(X509_ATTRIBUTE) *attributes;
302 ASN1_OCTET_STRING *digest;
305 struct x509_object_st {
306 /* one of the above types */
307 X509_LOOKUP_TYPE type;