Initial addition of new X509 V3 files, tidy of old files.
[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_ctx_struct {
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 #define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
134 ",name:", val->name, ",value:", val->value);
135
136 #define EXT_BITSTRING(nid, table) { nid, 0, \
137                         (X509V3_EXT_NEW)asn1_bit_string_new, ASN1_STRING_free, \
138                         (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \
139                         i2d_ASN1_BIT_STRING, \
140                         NULL, NULL, \
141                         (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
142                         (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
143                         NULL, \
144                         (char *)table}
145
146 #define EXT_IA5STRING(nid) { nid, 0, \
147                         (X509V3_EXT_NEW)ia5string_new, ASN1_STRING_free, \
148                         (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \
149                         i2d_ASN1_IA5STRING, \
150                         (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
151                         (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
152                         NULL, NULL, NULL, \
153                         NULL}
154
155 #define EXT_END { -1, 0, NULL, NULL, NULL, NULL, NULL, NULL, \
156                          NULL, NULL, NULL, \
157                          NULL}
158
159 #ifndef NOPROTO
160 void ERR_load_X509V3_strings(void);
161 void ERR_X509V3_error(int function, int reason, char *file, int line);
162 int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
163 BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
164 BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void);
165 void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a);
166
167 int i2d_ext_ku(STACK *a, unsigned char **pp);
168 STACK *d2i_ext_ku(STACK **a, unsigned char **pp, long length);
169 void ext_ku_free(STACK *a);
170 STACK *ext_ku_new(void);
171
172 #ifdef HEADER_CONF_H
173 void X509V3_conf_free(CONF_VALUE *val);
174 X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
175 X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
176 int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
177 int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
178 int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
179 #endif
180
181 int X509V3_add_value(char *name, char *value, STACK **extlist);
182 int X509V3_add_value_bool(char *name, int asn1_bool, STACK **extlist);
183 int X509V3_add_value_int( char *name, ASN1_INTEGER *aint, STACK **extlist);
184 int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
185 int X509V3_EXT_add_alias(int nid_to, int nid_from);
186 void X509V3_EXT_cleanup(void);
187
188 X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
189 X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
190 int X509V3_add_standard_extensions(void);
191 STACK *X509V3_parse_list(char *line);
192
193 int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag);
194 int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag);
195
196 #else
197
198 void ERR_load_X509V3_strings();
199 void ERR_X509V3_error();
200 int i2d_BASIC_CONSTRAINTS();
201 BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS();
202 BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new();
203 void BASIC_CONSTRAINTS_free();
204
205 int i2d_ext_ku();
206 STACK *d2i_ext_ku();
207 void ext_ku_free();
208 STACK *ext_ku_new();
209
210 #ifdef HEADER_CONF_H
211 void X509V3_conf_free();
212 X509_EXTENSION *X509V3_EXT_conf_nid();
213 X509_EXTENSION *X509V3_EXT_conf();
214 int X509V3_EXT_add_conf();
215 int X509V3_get_value_bool();
216 int X509V3_get_value_int();
217 #endif
218
219 int X509V3_add_value();
220 int X509V3_add_value_bool();
221 int X509V3_add_value_int();
222 int X509V3_EXT_add();
223 int X509V3_EXT_add_alias();
224 void X509V3_EXT_cleanup();
225
226 X509V3_EXT_METHOD *X509V3_EXT_get();
227 X509V3_EXT_METHOD *X509V3_EXT_get_nid();
228 int X509V3_add_standard_extensions();
229 STACK *X509V3_parse_list();
230
231 int X509V3_EXT_print();
232 int X509V3_EXT_print_fp();
233 #endif
234
235 /* BEGIN ERROR CODES */
236 /* Error codes for the X509V3 functions. */
237
238 /* Function codes. */
239 #define X509V3_F_S2I_ASN1_IA5STRING                      100
240 #define X509V3_F_V2I_ASN1_BIT_STRING                     101
241 #define X509V3_F_V2I_BASIC_CONSTRAINTS                   102
242 #define X509V3_F_V2I_EXT_KU                              103
243 #define X509V3_F_X509V3_ADD_EXT                          104
244 #define X509V3_F_X509V3_ADD_VALUE                        105
245 #define X509V3_F_X509V3_EXT_ADD_ALIAS                    106
246 #define X509V3_F_X509V3_EXT_CONF                         107
247 #define X509V3_F_X509V3_GET_VALUE_INT                    108
248 #define X509V3_F_X509V3_PARSE_LIST                       109
249 #define X509V3_F_X509V3_VALUE_GET_BOOL                   110
250
251 /* Reason codes. */
252 #define X509V3_R_BN_DEC2BN_ERROR                         100
253 #define X509V3_R_BN_TO_ASN1_INTEGER_ERROR                101
254 #define X509V3_R_EXTENSION_NOT_FOUND                     102
255 #define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED         103
256 #define X509V3_R_INVALID_BOOLEAN_STRING                  104
257 #define X509V3_R_INVALID_EXTENSION_STRING                105
258 #define X509V3_R_INVALID_NAME                            106
259 #define X509V3_R_INVALID_NULL_ARGUMENT                   107
260 #define X509V3_R_INVALID_NULL_NAME                       108
261 #define X509V3_R_INVALID_NULL_VALUE                      109
262 #define X509V3_R_INVALID_OBJECT_IDENTIFIER               110
263 #define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT             111
264  
265 #ifdef  __cplusplus
266 }
267 #endif
268 #endif
269