]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/include/internal/x509_int.h
Support public key and param check in EVP interface
[thirdparty/openssl.git] / crypto / include / internal / x509_int.h
CommitLineData
2743e38c 1/*
aa6bb135 2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
2743e38c 3 *
aa6bb135
RS
4 * Licensed under the OpenSSL license (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
2743e38c
DSH
8 */
9
2f545ae4
KR
10#include "internal/refcount.h"
11
2743e38c
DSH
12/* Internal X509 structures and functions: not for application use */
13
40ffdc9c
DSH
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 */
2743e38c 23struct X509_name_entry_st {
40ffdc9c
DSH
24 ASN1_OBJECT *object; /* AttributeType */
25 ASN1_STRING *value; /* AttributeValue */
26 int set; /* index of RDNSequence for this entry */
2743e38c
DSH
27 int size; /* temp variable */
28};
29
40ffdc9c 30/* Name from RFC 5280. */
2743e38c 31struct X509_name_st {
40ffdc9c 32 STACK_OF(X509_NAME_ENTRY) *entries; /* DN components */
2743e38c 33 int modified; /* true if 'bytes' needs to be built */
40ffdc9c
DSH
34 BUF_MEM *bytes; /* cached encoding: cannot be NULL */
35 /* canonical encoding used for rapid Name comparison */
2743e38c
DSH
36 unsigned char *canon_enc;
37 int canon_enclen;
38} /* X509_NAME */ ;
bc3686df 39
786dd2c2
DSH
40/* Signature info structure */
41
42struct 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
40ffdc9c 53/* PKCS#10 certificate request */
124055a9
DSH
54
55struct X509_req_info_st {
40ffdc9c
DSH
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;
124055a9
DSH
66};
67
68struct X509_req_st {
40ffdc9c
DSH
69 X509_REQ_INFO req_info; /* signed certificate request data */
70 X509_ALGOR sig_alg; /* signature algorithm */
71 ASN1_BIT_STRING *signature; /* signature */
2f545ae4 72 CRYPTO_REF_COUNT references;
c001ce33 73 CRYPTO_RWLOCK *lock;
124055a9 74};
e3e57192
DSH
75
76struct X509_crl_info_st {
40ffdc9c 77 ASN1_INTEGER *version; /* version: defaults to v1(0) so may be NULL */
8483a003 78 X509_ALGOR sig_alg; /* signature algorithm */
40ffdc9c
DSH
79 X509_NAME *issuer; /* CRL issuer name */
80 ASN1_TIME *lastUpdate; /* lastUpdate field */
81 ASN1_TIME *nextUpdate; /* nextUpdate field: optional */
687b4868 82 STACK_OF(X509_REVOKED) *revoked; /* revoked entries: optional */
40ffdc9c 83 STACK_OF(X509_EXTENSION) *extensions; /* extensions: optional */
687b4868 84 ASN1_ENCODING enc; /* encoding of signed portion of CRL */
e3e57192
DSH
85};
86
87struct X509_crl_st {
40ffdc9c
DSH
88 X509_CRL_INFO crl; /* signed CRL data */
89 X509_ALGOR sig_alg; /* CRL signature algorithm */
687b4868 90 ASN1_BIT_STRING signature; /* CRL signature */
2f545ae4 91 CRYPTO_REF_COUNT references;
e3e57192 92 int flags;
40ffdc9c
DSH
93 /*
94 * Cached copies of decoded extension values, since extensions
95 * are optional any of these can be NULL.
96 */
e3e57192
DSH
97 AUTHORITY_KEYID *akid;
98 ISSUING_DIST_POINT *idp;
99 /* Convenient breakdown of IDP */
100 int idp_flags;
101 int idp_reasons;
102 /* CRL and base CRL numbers for delta processing */
103 ASN1_INTEGER *crl_number;
104 ASN1_INTEGER *base_crl_number;
e3e57192 105 STACK_OF(GENERAL_NAMES) *issuers;
40ffdc9c
DSH
106 /* hash of CRL */
107 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
108 /* alternative method to handle this CRL */
e3e57192
DSH
109 const X509_CRL_METHOD *meth;
110 void *meth_data;
c001ce33 111 CRYPTO_RWLOCK *lock;
e3e57192 112};
44748efc
DSH
113
114struct x509_revoked_st {
34a42e14 115 ASN1_INTEGER serialNumber; /* revoked entry serial number */
40ffdc9c
DSH
116 ASN1_TIME *revocationDate; /* revocation date */
117 STACK_OF(X509_EXTENSION) *extensions; /* CRL entry extensions: optional */
118 /* decoded value of CRLissuer extension: set if indirect CRL */
44748efc 119 STACK_OF(GENERAL_NAME) *issuer;
40ffdc9c 120 /* revocation reason: set to CRL_REASON_NONE if reason extension absent */
44748efc 121 int reason;
40ffdc9c
DSH
122 /*
123 * CRL entries are reordered for faster lookup of serial numbers. This
124 * field contains the original load sequence for this entry.
125 */
126 int sequence;
127};
128
129/*
130 * This stuff is certificate "auxiliary info": it contains details which are
131 * useful in certificate stores and databases. When used this is tagged onto
132 * the end of the certificate itself. OpenSSL specific structure not defined
133 * in any RFC.
134 */
135
136struct x509_cert_aux_st {
137 STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */
138 STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */
139 ASN1_UTF8STRING *alias; /* "friendly name" */
140 ASN1_OCTET_STRING *keyid; /* key id of private key */
141 STACK_OF(X509_ALGOR) *other; /* other unspecified info */
44748efc 142};
2c81e476
DSH
143
144struct x509_cinf_st {
145 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
81e49438 146 ASN1_INTEGER serialNumber;
2c81e476
DSH
147 X509_ALGOR signature;
148 X509_NAME *issuer;
149 X509_VAL validity;
150 X509_NAME *subject;
151 X509_PUBKEY *key;
152 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
153 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
154 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
155 ASN1_ENCODING enc;
156};
157
158struct x509_st {
159 X509_CINF cert_info;
160 X509_ALGOR sig_alg;
81e49438 161 ASN1_BIT_STRING signature;
786dd2c2 162 X509_SIG_INFO siginf;
2f545ae4 163 CRYPTO_REF_COUNT references;
2c81e476
DSH
164 CRYPTO_EX_DATA ex_data;
165 /* These contain copies of various extension values */
166 long ex_pathlen;
167 long ex_pcpathlen;
168 uint32_t ex_flags;
169 uint32_t ex_kusage;
170 uint32_t ex_xkusage;
171 uint32_t ex_nscert;
172 ASN1_OCTET_STRING *skid;
173 AUTHORITY_KEYID *akid;
174 X509_POLICY_CACHE *policy_cache;
175 STACK_OF(DIST_POINT) *crldp;
176 STACK_OF(GENERAL_NAME) *altname;
177 NAME_CONSTRAINTS *nc;
178#ifndef OPENSSL_NO_RFC3779
179 STACK_OF(IPAddressFamily) *rfc3779_addr;
180 struct ASIdentifiers_st *rfc3779_asid;
181# endif
182 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
183 X509_CERT_AUX *aux;
c001ce33 184 CRYPTO_RWLOCK *lock;
2c81e476 185} /* X509 */ ;
54dbf423 186
f0e0fd51
RS
187/*
188 * This is a used when verifying cert chains. Since the gathering of the
189 * cert chain can take some time (and have to be 'retried', this needs to be
190 * kept and passed around.
191 */
192struct x509_store_ctx_st { /* X509_STORE_CTX */
193 X509_STORE *ctx;
f0e0fd51
RS
194 /* The following are set by the caller */
195 /* The cert to check */
196 X509 *cert;
197 /* chain of X509s - untrusted - passed in */
198 STACK_OF(X509) *untrusted;
199 /* set of CRLs passed in */
200 STACK_OF(X509_CRL) *crls;
201 X509_VERIFY_PARAM *param;
202 /* Other info for use with get_issuer() */
203 void *other_ctx;
204 /* Callbacks for various operations */
205 /* called to verify a certificate */
206 int (*verify) (X509_STORE_CTX *ctx);
207 /* error callback */
208 int (*verify_cb) (int ok, X509_STORE_CTX *ctx);
209 /* get issuers cert from ctx */
210 int (*get_issuer) (X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
211 /* check issued */
212 int (*check_issued) (X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
213 /* Check revocation status of chain */
214 int (*check_revocation) (X509_STORE_CTX *ctx);
215 /* retrieve CRL */
216 int (*get_crl) (X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x);
217 /* Check CRL validity */
218 int (*check_crl) (X509_STORE_CTX *ctx, X509_CRL *crl);
219 /* Check certificate against CRL */
220 int (*cert_crl) (X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x);
0a5fe2eb 221 /* Check policy status of the chain */
f0e0fd51
RS
222 int (*check_policy) (X509_STORE_CTX *ctx);
223 STACK_OF(X509) *(*lookup_certs) (X509_STORE_CTX *ctx, X509_NAME *nm);
224 STACK_OF(X509_CRL) *(*lookup_crls) (X509_STORE_CTX *ctx, X509_NAME *nm);
225 int (*cleanup) (X509_STORE_CTX *ctx);
226 /* The following is built up */
227 /* if 0, rebuild chain */
228 int valid;
229 /* number of untrusted certs */
230 int num_untrusted;
231 /* chain of X509s - built up and trusted */
232 STACK_OF(X509) *chain;
233 /* Valid policy tree */
234 X509_POLICY_TREE *tree;
235 /* Require explicit policy value */
236 int explicit_policy;
237 /* When something goes wrong, this is why */
238 int error_depth;
239 int error;
240 X509 *current_cert;
241 /* cert currently being tested as valid issuer */
242 X509 *current_issuer;
243 /* current CRL */
244 X509_CRL *current_crl;
245 /* score of current CRL */
246 int current_crl_score;
247 /* Reason mask */
248 unsigned int current_reasons;
249 /* For CRL path validation: parent context */
250 X509_STORE_CTX *parent;
251 CRYPTO_EX_DATA ex_data;
252 SSL_DANE *dane;
253 /* signed via bare TA public key, rather than CA certificate */
254 int bare_ta_signed;
255};
256
54dbf423
DSH
257/* PKCS#8 private key info structure */
258
259struct pkcs8_priv_key_info_st {
260 ASN1_INTEGER *version;
261 X509_ALGOR *pkeyalg;
262 ASN1_OCTET_STRING *pkey;
263 STACK_OF(X509_ATTRIBUTE) *attributes;
264};
a6eb1ce6
DSH
265
266struct X509_sig_st {
267 X509_ALGOR *algor;
268 ASN1_OCTET_STRING *digest;
269};
f0e0fd51
RS
270
271struct x509_object_st {
272 /* one of the above types */
273 X509_LOOKUP_TYPE type;
274 union {
275 char *ptr;
276 X509 *x509;
277 X509_CRL *crl;
278 EVP_PKEY *pkey;
279 } data;
280};
6670d55a
RS
281
282int a2i_ipadd(unsigned char *ipout, const char *ipasc);
3a60d6fa 283int x509_set1_time(ASN1_TIME **ptm, const ASN1_TIME *tm);
786dd2c2
DSH
284
285void x509_init_sig_info(X509 *x);