]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/crypto/x509.h
X509: Add d2i_PUBKEY_ex(), which take a libctx and propq
[thirdparty/openssl.git] / include / crypto / x509.h
1 /*
2 * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include "internal/refcount.h"
11
12 /* Internal X509 structures and functions: not for application use */
13
14 /* Note: unless otherwise stated a field pointer is mandatory and should
15 * never be set to NULL: the ASN.1 code and accessors rely on mandatory
16 * fields never being NULL.
17 */
18
19 /*
20 * name entry structure, equivalent to AttributeTypeAndValue defined
21 * in RFC5280 et al.
22 */
23 struct X509_name_entry_st {
24 ASN1_OBJECT *object; /* AttributeType */
25 ASN1_STRING *value; /* AttributeValue */
26 int set; /* index of RDNSequence for this entry */
27 int size; /* temp variable */
28 };
29
30 /* Name from RFC 5280. */
31 struct X509_name_st {
32 STACK_OF(X509_NAME_ENTRY) *entries; /* DN components */
33 int modified; /* true if 'bytes' needs to be built */
34 BUF_MEM *bytes; /* cached encoding: cannot be NULL */
35 /* canonical encoding used for rapid Name comparison */
36 unsigned char *canon_enc;
37 int canon_enclen;
38 } /* X509_NAME */ ;
39
40 /* Signature info structure */
41
42 struct x509_sig_info_st {
43 /* NID of message digest */
44 int mdnid;
45 /* NID of public key algorithm */
46 int pknid;
47 /* Security bits */
48 int secbits;
49 /* Various flags */
50 uint32_t flags;
51 };
52
53 /* PKCS#10 certificate request */
54
55 struct X509_req_info_st {
56 ASN1_ENCODING enc; /* cached encoding of signed part */
57 ASN1_INTEGER *version; /* version, defaults to v1(0) so can be NULL */
58 X509_NAME *subject; /* certificate request DN */
59 X509_PUBKEY *pubkey; /* public key of request */
60 /*
61 * Zero or more attributes.
62 * NB: although attributes is a mandatory field some broken
63 * encodings omit it so this may be NULL in that case.
64 */
65 STACK_OF(X509_ATTRIBUTE) *attributes;
66 };
67
68 struct X509_req_st {
69 X509_REQ_INFO req_info; /* signed certificate request data */
70 X509_ALGOR sig_alg; /* signature algorithm */
71 ASN1_BIT_STRING *signature; /* signature */
72 CRYPTO_REF_COUNT references;
73 CRYPTO_RWLOCK *lock;
74
75 /* Set on live certificates for authentication purposes */
76 ASN1_OCTET_STRING *distinguishing_id;
77 };
78
79 struct X509_crl_info_st {
80 ASN1_INTEGER *version; /* version: defaults to v1(0) so may be NULL */
81 X509_ALGOR sig_alg; /* signature algorithm */
82 X509_NAME *issuer; /* CRL issuer name */
83 ASN1_TIME *lastUpdate; /* lastUpdate field */
84 ASN1_TIME *nextUpdate; /* nextUpdate field: optional */
85 STACK_OF(X509_REVOKED) *revoked; /* revoked entries: optional */
86 STACK_OF(X509_EXTENSION) *extensions; /* extensions: optional */
87 ASN1_ENCODING enc; /* encoding of signed portion of CRL */
88 };
89
90 struct X509_crl_st {
91 X509_CRL_INFO crl; /* signed CRL data */
92 X509_ALGOR sig_alg; /* CRL signature algorithm */
93 ASN1_BIT_STRING signature; /* CRL signature */
94 CRYPTO_REF_COUNT references;
95 int flags;
96 /*
97 * Cached copies of decoded extension values, since extensions
98 * are optional any of these can be NULL.
99 */
100 AUTHORITY_KEYID *akid;
101 ISSUING_DIST_POINT *idp;
102 /* Convenient breakdown of IDP */
103 int idp_flags;
104 int idp_reasons;
105 /* CRL and base CRL numbers for delta processing */
106 ASN1_INTEGER *crl_number;
107 ASN1_INTEGER *base_crl_number;
108 STACK_OF(GENERAL_NAMES) *issuers;
109 /* hash of CRL */
110 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
111 /* alternative method to handle this CRL */
112 const X509_CRL_METHOD *meth;
113 void *meth_data;
114 CRYPTO_RWLOCK *lock;
115 };
116
117 struct x509_revoked_st {
118 ASN1_INTEGER serialNumber; /* revoked entry serial number */
119 ASN1_TIME *revocationDate; /* revocation date */
120 STACK_OF(X509_EXTENSION) *extensions; /* CRL entry extensions: optional */
121 /* decoded value of CRLissuer extension: set if indirect CRL */
122 STACK_OF(GENERAL_NAME) *issuer;
123 /* revocation reason: set to CRL_REASON_NONE if reason extension absent */
124 int reason;
125 /*
126 * CRL entries are reordered for faster lookup of serial numbers. This
127 * field contains the original load sequence for this entry.
128 */
129 int sequence;
130 };
131
132 /*
133 * This stuff is certificate "auxiliary info": it contains details which are
134 * useful in certificate stores and databases. When used this is tagged onto
135 * the end of the certificate itself. OpenSSL specific structure not defined
136 * in any RFC.
137 */
138
139 struct x509_cert_aux_st {
140 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
141 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
142 ASN1_UTF8STRING *alias; /* "friendly name" */
143 ASN1_OCTET_STRING *keyid; /* key id of private key */
144 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
145 };
146
147 struct x509_cinf_st {
148 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
149 ASN1_INTEGER serialNumber;
150 X509_ALGOR signature;
151 X509_NAME *issuer;
152 X509_VAL validity;
153 X509_NAME *subject;
154 X509_PUBKEY *key;
155 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
156 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
157 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
158 ASN1_ENCODING enc;
159 };
160
161 struct x509_st {
162 X509_CINF cert_info;
163 X509_ALGOR sig_alg;
164 ASN1_BIT_STRING signature;
165 X509_SIG_INFO siginf;
166 CRYPTO_REF_COUNT references;
167 CRYPTO_EX_DATA ex_data;
168 /* These contain copies of various extension values */
169 long ex_pathlen;
170 long ex_pcpathlen;
171 uint32_t ex_flags;
172 uint32_t ex_kusage;
173 uint32_t ex_xkusage;
174 uint32_t ex_nscert;
175 ASN1_OCTET_STRING *skid;
176 AUTHORITY_KEYID *akid;
177 X509_POLICY_CACHE *policy_cache;
178 STACK_OF(DIST_POINT) *crldp;
179 STACK_OF(GENERAL_NAME) *altname;
180 NAME_CONSTRAINTS *nc;
181 # ifndef OPENSSL_NO_RFC3779
182 STACK_OF(IPAddressFamily) *rfc3779_addr;
183 struct ASIdentifiers_st *rfc3779_asid;
184 # endif
185 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
186 X509_CERT_AUX *aux;
187 CRYPTO_RWLOCK *lock;
188 volatile int ex_cached;
189
190 /* Set on live certificates for authentication purposes */
191 ASN1_OCTET_STRING *distinguishing_id;
192
193 OPENSSL_CTX *libctx;
194 const char *propq;
195 } /* X509 */ ;
196
197 /*
198 * This is a used when verifying cert chains. Since the gathering of the
199 * cert chain can take some time (and have to be 'retried', this needs to be
200 * kept and passed around.
201 */
202 struct x509_store_ctx_st { /* X509_STORE_CTX */
203 X509_STORE *store;
204 /* The following are set by the caller */
205 /* The cert to check */
206 X509 *cert;
207 /* chain of X509s - untrusted - passed in */
208 STACK_OF(X509) *untrusted;
209 /* set of CRLs passed in */
210 STACK_OF(X509_CRL) *crls;
211 X509_VERIFY_PARAM *param;
212 /* Other info for use with get_issuer() */
213 void *other_ctx;
214 /* Callbacks for various operations */
215 /* called to verify a certificate */
216 int (*verify) (X509_STORE_CTX *ctx);
217 /* error callback */
218 int (*verify_cb) (int ok, X509_STORE_CTX *ctx);
219 /* get issuers cert from ctx */
220 int (*get_issuer) (X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
221 /* check issued */
222 int (*check_issued) (X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
223 /* Check revocation status of chain */
224 int (*check_revocation) (X509_STORE_CTX *ctx);
225 /* retrieve CRL */
226 int (*get_crl) (X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x);
227 /* Check CRL validity */
228 int (*check_crl) (X509_STORE_CTX *ctx, X509_CRL *crl);
229 /* Check certificate against CRL */
230 int (*cert_crl) (X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x);
231 /* Check policy status of the chain */
232 int (*check_policy) (X509_STORE_CTX *ctx);
233 STACK_OF(X509) *(*lookup_certs) (X509_STORE_CTX *ctx,
234 const X509_NAME *nm);
235 /* cannot constify 'ctx' param due to lookup_certs_sk() in x509_vfy.c */
236 STACK_OF(X509_CRL) *(*lookup_crls) (const X509_STORE_CTX *ctx,
237 const X509_NAME *nm);
238 int (*cleanup) (X509_STORE_CTX *ctx);
239 /* The following is built up */
240 /* if 0, rebuild chain */
241 int valid;
242 /* number of untrusted certs */
243 int num_untrusted;
244 /* chain of X509s - built up and trusted */
245 STACK_OF(X509) *chain;
246 /* Valid policy tree */
247 X509_POLICY_TREE *tree;
248 /* Require explicit policy value */
249 int explicit_policy;
250 /* When something goes wrong, this is why */
251 int error_depth;
252 int error;
253 X509 *current_cert;
254 /* cert currently being tested as valid issuer */
255 X509 *current_issuer;
256 /* current CRL */
257 X509_CRL *current_crl;
258 /* score of current CRL */
259 int current_crl_score;
260 /* Reason mask */
261 unsigned int current_reasons;
262 /* For CRL path validation: parent context */
263 X509_STORE_CTX *parent;
264 CRYPTO_EX_DATA ex_data;
265 SSL_DANE *dane;
266 /* signed via bare TA public key, rather than CA certificate */
267 int bare_ta_signed;
268
269 OPENSSL_CTX *libctx;
270 char *propq;
271 };
272
273 /* PKCS#8 private key info structure */
274
275 struct pkcs8_priv_key_info_st {
276 ASN1_INTEGER *version;
277 X509_ALGOR *pkeyalg;
278 ASN1_OCTET_STRING *pkey;
279 STACK_OF(X509_ATTRIBUTE) *attributes;
280 };
281
282 struct X509_sig_st {
283 X509_ALGOR *algor;
284 ASN1_OCTET_STRING *digest;
285 };
286
287 struct x509_object_st {
288 /* one of the above types */
289 X509_LOOKUP_TYPE type;
290 union {
291 char *ptr;
292 X509 *x509;
293 X509_CRL *crl;
294 EVP_PKEY *pkey;
295 } data;
296 };
297
298 int a2i_ipadd(unsigned char *ipout, const char *ipasc);
299 int x509_set1_time(ASN1_TIME **ptm, const ASN1_TIME *tm);
300 int x509_print_ex_brief(BIO *bio, X509 *cert, unsigned long neg_cflags);
301 int x509v3_cache_extensions(X509 *x);
302 int x509_set0_libctx(X509 *x, OPENSSL_CTX *libctx, const char *propq);
303 void x509_init_sig_info(X509 *x);
304 int asn1_item_digest_with_libctx(const ASN1_ITEM *it, const EVP_MD *type,
305 void *data, unsigned char *md,
306 unsigned int *len, OPENSSL_CTX *libctx,
307 const char *propq);
308 int X509_add_cert_new(STACK_OF(X509) **sk, X509 *cert, int flags);
309
310 int X509_PUBKEY_get0_libctx(OPENSSL_CTX **plibctx, const char **ppropq,
311 const X509_PUBKEY *key);