Update dependencies.
[openssl.git] / crypto / x509v3 / x509v3.h
1 /* x509v3.h */
2 /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3  * project 1999.
4  */
5 /* ====================================================================
6  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer. 
14  *
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
18  *    distribution.
19  *
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/)"
24  *
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.
29  *
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.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
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  * ====================================================================
52  *
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).
56  *
57  */
58 #ifndef HEADER_X509V3_H
59 #define HEADER_X509V3_H
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 #include "bio.h"
66 #include "x509.h"
67
68 /* Forward reference */
69 struct v3_ext_method;
70 struct v3_ext_ctx;
71
72 /* Useful typedefs */
73
74 typedef char * (*X509V3_EXT_NEW)();
75 typedef void (*X509V3_EXT_FREE)();
76 typedef char * (*X509V3_EXT_D2I)();
77 typedef int (*X509V3_EXT_I2D)();
78 typedef STACK * (*X509V3_EXT_I2V)(struct v3_ext_method *method, char *ext);
79 typedef char * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK *values);
80 typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, char *ext);
81 typedef char * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
82 typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, char *ext, BIO *out);
83
84 /* V3 extension structure */
85
86 struct v3_ext_method {
87 int ext_nid;
88 int ext_flags;
89 X509V3_EXT_NEW ext_new;
90 X509V3_EXT_FREE ext_free;
91 X509V3_EXT_D2I d2i;
92 X509V3_EXT_I2D i2d;
93
94 /* The following pair is used for string extensions */
95 X509V3_EXT_I2S i2s;
96 X509V3_EXT_S2I s2i;
97
98 /* The following pair is used for multi-valued extensions */
99 X509V3_EXT_I2V i2v;
100 X509V3_EXT_V2I v2i;
101
102 /* The following is used for raw extensions */
103 X509V3_EXT_I2R i2r;
104
105 char *usr_data; /* Any extension specific data */
106 };
107
108 /* Context specific info */
109 struct v3_ext_ctx {
110 X509 *issuer_cert;
111 X509 *subject_cert;
112 X509_REQ *subject_req;
113 /* Maybe more here */
114 };
115
116 typedef struct v3_ext_method X509V3_EXT_METHOD;
117 typedef struct v3_ext_ctx X509V3_CTX;
118
119 /* ext_flags values */
120 #define X509V3_EXT_DYNAMIC 0x1
121
122 typedef struct {
123 int bitnum;
124 char *lname;
125 char *sname;
126 } BIT_STRING_BITNAME;
127
128 typedef struct {
129 int ca;
130 ASN1_INTEGER *pathlen;
131 } BASIC_CONSTRAINTS;
132
133 typedef struct {
134
135 #define GEN_OTHERNAME   (0|V_ASN1_CONTEXT_SPECIFIC)
136 #define GEN_EMAIL       (1|V_ASN1_CONTEXT_SPECIFIC)
137 #define GEN_DNS         (2|V_ASN1_CONTEXT_SPECIFIC)
138 #define GEN_X400        (3|V_ASN1_CONTEXT_SPECIFIC)
139 #define GEN_DIRNAME     (4|V_ASN1_CONTEXT_SPECIFIC)
140 #define GEN_EDIPARTY    (5|V_ASN1_CONTEXT_SPECIFIC)
141 #define GEN_URI         (6|V_ASN1_CONTEXT_SPECIFIC)
142 #define GEN_IPADD       (7|V_ASN1_CONTEXT_SPECIFIC)
143 #define GEN_RID         (8|V_ASN1_CONTEXT_SPECIFIC)
144
145 int type;
146 union {
147         char *ptr;
148         ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */
149         ASN1_OCTET_STRING *ip; /* iPAddress */
150         X509_NAME *dirn;                /* dirn */
151         ASN1_OBJECT *rid; /* registeredID */
152         ASN1_TYPE *other; /* otherName, ediPartyName, x400Address */
153 } d;
154 } GENERAL_NAME;
155
156
157
158
159 #define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
160 ",name:", val->name, ",value:", val->value);
161
162 #define EXT_BITSTRING(nid, table) { nid, 0, \
163                         (X509V3_EXT_NEW)asn1_bit_string_new, ASN1_STRING_free, \
164                         (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \
165                         i2d_ASN1_BIT_STRING, \
166                         NULL, NULL, \
167                         (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
168                         (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
169                         NULL, \
170                         (char *)table}
171
172 #define EXT_IA5STRING(nid) { nid, 0, \
173                         (X509V3_EXT_NEW)ia5string_new, ASN1_STRING_free, \
174                         (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \
175                         i2d_ASN1_IA5STRING, \
176                         (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
177                         (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
178                         NULL, NULL, NULL, \
179                         NULL}
180
181 #define EXT_END { -1, 0, NULL, NULL, NULL, NULL, NULL, NULL, \
182                          NULL, NULL, NULL, \
183                          NULL}
184
185 #ifndef NOPROTO
186 void ERR_load_X509V3_strings(void);
187 int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
188 BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
189 BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void);
190 void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a);
191
192 int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp);
193 GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp, long length);
194 GENERAL_NAME *GENERAL_NAME_new(void);
195 void GENERAL_NAME_free(GENERAL_NAME *a);
196
197 STACK *GENERAL_NAMES_new(void);
198 void GENERAL_NAMES_free(STACK *a);
199 STACK *d2i_GENERAL_NAMES(STACK **a, unsigned char **pp, long length);
200 int i2d_GENERAL_NAMES(STACK *a, unsigned char **pp);
201
202
203
204 int i2d_ext_ku(STACK *a, unsigned char **pp);
205 STACK *d2i_ext_ku(STACK **a, unsigned char **pp, long length);
206 void ext_ku_free(STACK *a);
207 STACK *ext_ku_new(void);
208
209 #ifdef HEADER_CONF_H
210 void X509V3_conf_free(CONF_VALUE *val);
211 X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
212 X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
213 int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
214 int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
215 int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
216 #endif
217
218 int X509V3_add_value(char *name, char *value, STACK **extlist);
219 int X509V3_add_value_bool(char *name, int asn1_bool, STACK **extlist);
220 int X509V3_add_value_int( char *name, ASN1_INTEGER *aint, STACK **extlist);
221 int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
222 int X509V3_EXT_add_alias(int nid_to, int nid_from);
223 void X509V3_EXT_cleanup(void);
224
225 X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
226 X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
227 int X509V3_add_standard_extensions(void);
228 STACK *X509V3_parse_list(char *line);
229
230 int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag);
231 int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag);
232
233 #else
234
235 void ERR_load_X509V3_strings();
236 int i2d_BASIC_CONSTRAINTS();
237 BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS();
238 BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new();
239 void BASIC_CONSTRAINTS_free();
240
241 int i2d_GENERAL_NAME();
242 GENERAL_NAME *d2i_GENERAL_NAME();
243 GENERAL_NAME *GENERAL_NAME_new();
244 void GENERAL_NAME_free();
245
246 STACK *GENERAL_NAMES_new():
247 void GENERAL_NAMES_free():
248 STACK *d2i_GENERAL_NAMES();
249 int i2d_GENERAL_NAMES();
250
251 int i2d_ext_ku();
252 STACK *d2i_ext_ku();
253 void ext_ku_free();
254 STACK *ext_ku_new();
255
256 #ifdef HEADER_CONF_H
257 void X509V3_conf_free();
258 X509_EXTENSION *X509V3_EXT_conf_nid();
259 X509_EXTENSION *X509V3_EXT_conf();
260 int X509V3_EXT_add_conf();
261 int X509V3_get_value_bool();
262 int X509V3_get_value_int();
263 #endif
264
265 int X509V3_add_value();
266 int X509V3_add_value_bool();
267 int X509V3_add_value_int();
268 int X509V3_EXT_add();
269 int X509V3_EXT_add_alias();
270 void X509V3_EXT_cleanup();
271
272 X509V3_EXT_METHOD *X509V3_EXT_get();
273 X509V3_EXT_METHOD *X509V3_EXT_get_nid();
274 int X509V3_add_standard_extensions();
275 STACK *X509V3_parse_list();
276
277 int X509V3_EXT_print();
278 int X509V3_EXT_print_fp();
279 #endif
280
281 /* BEGIN ERROR CODES */
282 /* Error codes for the X509V3 functions. */
283
284 /* Function codes. */
285 #define X509V3_F_S2I_ASN1_IA5STRING                      100
286 #define X509V3_F_V2I_ASN1_BIT_STRING                     101
287 #define X509V3_F_V2I_BASIC_CONSTRAINTS                   102
288 #define X509V3_F_V2I_EXT_KU                              103
289 #define X509V3_F_X509V3_ADD_EXT                          104
290 #define X509V3_F_X509V3_ADD_VALUE                        105
291 #define X509V3_F_X509V3_EXT_ADD_ALIAS                    106
292 #define X509V3_F_X509V3_EXT_CONF                         107
293 #define X509V3_F_X509V3_GET_VALUE_INT                    108
294 #define X509V3_F_X509V3_PARSE_LIST                       109
295 #define X509V3_F_X509V3_VALUE_GET_BOOL                   110
296
297 /* Reason codes. */
298 #define X509V3_R_BN_DEC2BN_ERROR                         100
299 #define X509V3_R_BN_TO_ASN1_INTEGER_ERROR                101
300 #define X509V3_R_EXTENSION_NOT_FOUND                     102
301 #define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED         103
302 #define X509V3_R_INVALID_BOOLEAN_STRING                  104
303 #define X509V3_R_INVALID_EXTENSION_STRING                105
304 #define X509V3_R_INVALID_NAME                            106
305 #define X509V3_R_INVALID_NULL_ARGUMENT                   107
306 #define X509V3_R_INVALID_NULL_NAME                       108
307 #define X509V3_R_INVALID_NULL_VALUE                      109
308 #define X509V3_R_INVALID_OBJECT_IDENTIFIER               110
309 #define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT             111
310  
311 #ifdef  __cplusplus
312 }
313 #endif
314 #endif
315