e46a999b29d1c3e5ec9e760cf7e697c2957fd0df
[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 #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 int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
162 BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
163 BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void);
164 void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a);
165
166 int i2d_ext_ku(STACK *a, unsigned char **pp);
167 STACK *d2i_ext_ku(STACK **a, unsigned char **pp, long length);
168 void ext_ku_free(STACK *a);
169 STACK *ext_ku_new(void);
170
171 #ifdef HEADER_CONF_H
172 void X509V3_conf_free(CONF_VALUE *val);
173 X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
174 X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
175 int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
176 int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
177 int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
178 #endif
179
180 int X509V3_add_value(char *name, char *value, STACK **extlist);
181 int X509V3_add_value_bool(char *name, int asn1_bool, STACK **extlist);
182 int X509V3_add_value_int( char *name, ASN1_INTEGER *aint, STACK **extlist);
183 int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
184 int X509V3_EXT_add_alias(int nid_to, int nid_from);
185 void X509V3_EXT_cleanup(void);
186
187 X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
188 X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
189 int X509V3_add_standard_extensions(void);
190 STACK *X509V3_parse_list(char *line);
191
192 int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag);
193 int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag);
194
195 #else
196
197 void ERR_load_X509V3_strings();
198 int i2d_BASIC_CONSTRAINTS();
199 BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS();
200 BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new();
201 void BASIC_CONSTRAINTS_free();
202
203 int i2d_ext_ku();
204 STACK *d2i_ext_ku();
205 void ext_ku_free();
206 STACK *ext_ku_new();
207
208 #ifdef HEADER_CONF_H
209 void X509V3_conf_free();
210 X509_EXTENSION *X509V3_EXT_conf_nid();
211 X509_EXTENSION *X509V3_EXT_conf();
212 int X509V3_EXT_add_conf();
213 int X509V3_get_value_bool();
214 int X509V3_get_value_int();
215 #endif
216
217 int X509V3_add_value();
218 int X509V3_add_value_bool();
219 int X509V3_add_value_int();
220 int X509V3_EXT_add();
221 int X509V3_EXT_add_alias();
222 void X509V3_EXT_cleanup();
223
224 X509V3_EXT_METHOD *X509V3_EXT_get();
225 X509V3_EXT_METHOD *X509V3_EXT_get_nid();
226 int X509V3_add_standard_extensions();
227 STACK *X509V3_parse_list();
228
229 int X509V3_EXT_print();
230 int X509V3_EXT_print_fp();
231 #endif
232
233 /* BEGIN ERROR CODES */
234 /* Error codes for the X509V3 functions. */
235
236 /* Function codes. */
237 #define X509V3_F_S2I_ASN1_IA5STRING                      100
238 #define X509V3_F_V2I_ASN1_BIT_STRING                     101
239 #define X509V3_F_V2I_BASIC_CONSTRAINTS                   102
240 #define X509V3_F_V2I_EXT_KU                              103
241 #define X509V3_F_X509V3_ADD_EXT                          104
242 #define X509V3_F_X509V3_ADD_VALUE                        105
243 #define X509V3_F_X509V3_EXT_ADD_ALIAS                    106
244 #define X509V3_F_X509V3_EXT_CONF                         107
245 #define X509V3_F_X509V3_GET_VALUE_INT                    108
246 #define X509V3_F_X509V3_PARSE_LIST                       109
247 #define X509V3_F_X509V3_VALUE_GET_BOOL                   110
248
249 /* Reason codes. */
250 #define X509V3_R_BN_DEC2BN_ERROR                         100
251 #define X509V3_R_BN_TO_ASN1_INTEGER_ERROR                101
252 #define X509V3_R_EXTENSION_NOT_FOUND                     102
253 #define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED         103
254 #define X509V3_R_INVALID_BOOLEAN_STRING                  104
255 #define X509V3_R_INVALID_EXTENSION_STRING                105
256 #define X509V3_R_INVALID_NAME                            106
257 #define X509V3_R_INVALID_NULL_ARGUMENT                   107
258 #define X509V3_R_INVALID_NULL_NAME                       108
259 #define X509V3_R_INVALID_NULL_VALUE                      109
260 #define X509V3_R_INVALID_OBJECT_IDENTIFIER               110
261 #define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT             111
262  
263 #ifdef  __cplusplus
264 }
265 #endif
266 #endif
267