sl@0
|
1 |
/* v3_conf.c */
|
sl@0
|
2 |
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
|
sl@0
|
3 |
* project 1999.
|
sl@0
|
4 |
*/
|
sl@0
|
5 |
/* ====================================================================
|
sl@0
|
6 |
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
9 |
* modification, are permitted provided that the following conditions
|
sl@0
|
10 |
* are met:
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
13 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
16 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
17 |
* the documentation and/or other materials provided with the
|
sl@0
|
18 |
* distribution.
|
sl@0
|
19 |
*
|
sl@0
|
20 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
21 |
* software must display the following acknowledgment:
|
sl@0
|
22 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
23 |
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
sl@0
|
24 |
*
|
sl@0
|
25 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
26 |
* endorse or promote products derived from this software without
|
sl@0
|
27 |
* prior written permission. For written permission, please contact
|
sl@0
|
28 |
* licensing@OpenSSL.org.
|
sl@0
|
29 |
*
|
sl@0
|
30 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
31 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
32 |
* permission of the OpenSSL Project.
|
sl@0
|
33 |
*
|
sl@0
|
34 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
35 |
* acknowledgment:
|
sl@0
|
36 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
37 |
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
sl@0
|
38 |
*
|
sl@0
|
39 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
40 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
41 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
42 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
43 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
44 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
45 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
46 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
47 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
48 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
49 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
50 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
51 |
* ====================================================================
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
54 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
55 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
56 |
*
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
/*
|
sl@0
|
59 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
/* extension creation utilities */
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
|
sl@0
|
65 |
#include <stdio.h>
|
sl@0
|
66 |
#include <ctype.h>
|
sl@0
|
67 |
#include "cryptlib.h"
|
sl@0
|
68 |
#include <openssl/conf.h>
|
sl@0
|
69 |
#include <openssl/x509.h>
|
sl@0
|
70 |
#include <openssl/x509v3.h>
|
sl@0
|
71 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
72 |
#include "libcrypto_wsd_macros.h"
|
sl@0
|
73 |
#include "libcrypto_wsd.h"
|
sl@0
|
74 |
#endif
|
sl@0
|
75 |
|
sl@0
|
76 |
static int v3_check_critical(char **value);
|
sl@0
|
77 |
static int v3_check_generic(char **value);
|
sl@0
|
78 |
static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value);
|
sl@0
|
79 |
static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type, X509V3_CTX *ctx);
|
sl@0
|
80 |
static char *conf_lhash_get_string(void *db, char *section, char *value);
|
sl@0
|
81 |
static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section);
|
sl@0
|
82 |
static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
|
sl@0
|
83 |
int crit, void *ext_struc);
|
sl@0
|
84 |
static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len);
|
sl@0
|
85 |
/* CONF *conf: Config file */
|
sl@0
|
86 |
/* char *name: Name */
|
sl@0
|
87 |
/* char *value: Value */
|
sl@0
|
88 |
EXPORT_C X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name,
|
sl@0
|
89 |
char *value)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
int crit;
|
sl@0
|
92 |
int ext_type;
|
sl@0
|
93 |
X509_EXTENSION *ret;
|
sl@0
|
94 |
crit = v3_check_critical(&value);
|
sl@0
|
95 |
if ((ext_type = v3_check_generic(&value)))
|
sl@0
|
96 |
return v3_generic_extension(name, value, crit, ext_type, ctx);
|
sl@0
|
97 |
ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
|
sl@0
|
98 |
if (!ret)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
X509V3err(X509V3_F_X509V3_EXT_NCONF,X509V3_R_ERROR_IN_EXTENSION);
|
sl@0
|
101 |
ERR_add_error_data(4,"name=", name, ", value=", value);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
return ret;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
/* CONF *conf: Config file */
|
sl@0
|
107 |
/* char *value: Value */
|
sl@0
|
108 |
EXPORT_C X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
|
sl@0
|
109 |
char *value)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
int crit;
|
sl@0
|
112 |
int ext_type;
|
sl@0
|
113 |
crit = v3_check_critical(&value);
|
sl@0
|
114 |
if ((ext_type = v3_check_generic(&value)))
|
sl@0
|
115 |
return v3_generic_extension(OBJ_nid2sn(ext_nid),
|
sl@0
|
116 |
value, crit, ext_type, ctx);
|
sl@0
|
117 |
return do_ext_nconf(conf, ctx, ext_nid, crit, value);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
/* CONF *conf: Config file */
|
sl@0
|
121 |
/* char *value: Value */
|
sl@0
|
122 |
static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
|
sl@0
|
123 |
int crit, char *value)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
X509V3_EXT_METHOD *method;
|
sl@0
|
126 |
X509_EXTENSION *ext;
|
sl@0
|
127 |
STACK_OF(CONF_VALUE) *nval;
|
sl@0
|
128 |
void *ext_struc;
|
sl@0
|
129 |
if (ext_nid == NID_undef)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
|
sl@0
|
132 |
return NULL;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
if (!(method = X509V3_EXT_get_nid(ext_nid)))
|
sl@0
|
135 |
{
|
sl@0
|
136 |
X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_UNKNOWN_EXTENSION);
|
sl@0
|
137 |
return NULL;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
/* Now get internal extension representation based on type */
|
sl@0
|
140 |
if (method->v2i)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
if(*value == '@') nval = NCONF_get_section(conf, value + 1);
|
sl@0
|
143 |
else nval = X509V3_parse_list(value);
|
sl@0
|
144 |
if(sk_CONF_VALUE_num(nval) <= 0)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_INVALID_EXTENSION_STRING);
|
sl@0
|
147 |
ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
|
sl@0
|
148 |
return NULL;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
ext_struc = method->v2i(method, ctx, nval);
|
sl@0
|
151 |
if(*value != '@') sk_CONF_VALUE_pop_free(nval,
|
sl@0
|
152 |
X509V3_conf_free);
|
sl@0
|
153 |
if(!ext_struc) return NULL;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
else if(method->s2i)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
if(!(ext_struc = method->s2i(method, ctx, value))) return NULL;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else if(method->r2i)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
if(!ctx->db || !ctx->db_meth)
|
sl@0
|
162 |
{
|
sl@0
|
163 |
X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_NO_CONFIG_DATABASE);
|
sl@0
|
164 |
return NULL;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
else
|
sl@0
|
169 |
{
|
sl@0
|
170 |
X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
|
sl@0
|
171 |
ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
|
sl@0
|
172 |
return NULL;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
|
sl@0
|
176 |
if(method->it) ASN1_item_free(ext_struc, ASN1_ITEM_ptr(method->it));
|
sl@0
|
177 |
else method->ext_free(ext_struc);
|
sl@0
|
178 |
return ext;
|
sl@0
|
179 |
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
|
sl@0
|
183 |
int crit, void *ext_struc)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
unsigned char *ext_der;
|
sl@0
|
186 |
int ext_len;
|
sl@0
|
187 |
ASN1_OCTET_STRING *ext_oct;
|
sl@0
|
188 |
X509_EXTENSION *ext;
|
sl@0
|
189 |
/* Convert internal representation to DER */
|
sl@0
|
190 |
if (method->it)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
ext_der = NULL;
|
sl@0
|
193 |
ext_len = ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it));
|
sl@0
|
194 |
if (ext_len < 0) goto merr;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
else
|
sl@0
|
197 |
{
|
sl@0
|
198 |
unsigned char *p;
|
sl@0
|
199 |
ext_len = method->i2d(ext_struc, NULL);
|
sl@0
|
200 |
if(!(ext_der = OPENSSL_malloc(ext_len))) goto merr;
|
sl@0
|
201 |
p = ext_der;
|
sl@0
|
202 |
method->i2d(ext_struc, &p);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
if (!(ext_oct = M_ASN1_OCTET_STRING_new())) goto merr;
|
sl@0
|
205 |
ext_oct->data = ext_der;
|
sl@0
|
206 |
ext_oct->length = ext_len;
|
sl@0
|
207 |
|
sl@0
|
208 |
ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
|
sl@0
|
209 |
if (!ext) goto merr;
|
sl@0
|
210 |
M_ASN1_OCTET_STRING_free(ext_oct);
|
sl@0
|
211 |
|
sl@0
|
212 |
return ext;
|
sl@0
|
213 |
|
sl@0
|
214 |
merr:
|
sl@0
|
215 |
X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE);
|
sl@0
|
216 |
return NULL;
|
sl@0
|
217 |
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
/* Given an internal structure, nid and critical flag create an extension */
|
sl@0
|
221 |
|
sl@0
|
222 |
EXPORT_C X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
X509V3_EXT_METHOD *method;
|
sl@0
|
225 |
if (!(method = X509V3_EXT_get_nid(ext_nid))) {
|
sl@0
|
226 |
X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
|
sl@0
|
227 |
return NULL;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
return do_ext_i2d(method, ext_nid, crit, ext_struc);
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
/* Check the extension string for critical flag */
|
sl@0
|
233 |
static int v3_check_critical(char **value)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
char *p = *value;
|
sl@0
|
236 |
if ((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0;
|
sl@0
|
237 |
p+=9;
|
sl@0
|
238 |
while(isspace((unsigned char)*p)) p++;
|
sl@0
|
239 |
*value = p;
|
sl@0
|
240 |
return 1;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
/* Check extension string for generic extension and return the type */
|
sl@0
|
244 |
static int v3_check_generic(char **value)
|
sl@0
|
245 |
{
|
sl@0
|
246 |
int gen_type = 0;
|
sl@0
|
247 |
char *p = *value;
|
sl@0
|
248 |
if ((strlen(p) >= 4) && !strncmp(p, "DER:", 4))
|
sl@0
|
249 |
{
|
sl@0
|
250 |
p+=4;
|
sl@0
|
251 |
gen_type = 1;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
else if ((strlen(p) >= 5) && !strncmp(p, "ASN1:", 5))
|
sl@0
|
254 |
{
|
sl@0
|
255 |
p+=5;
|
sl@0
|
256 |
gen_type = 2;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
else
|
sl@0
|
259 |
return 0;
|
sl@0
|
260 |
|
sl@0
|
261 |
while (isspace((unsigned char)*p)) p++;
|
sl@0
|
262 |
*value = p;
|
sl@0
|
263 |
return gen_type;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
/* Create a generic extension: for now just handle DER type */
|
sl@0
|
267 |
static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
|
sl@0
|
268 |
int crit, int gen_type, X509V3_CTX *ctx)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
unsigned char *ext_der=NULL;
|
sl@0
|
271 |
long ext_len;
|
sl@0
|
272 |
ASN1_OBJECT *obj=NULL;
|
sl@0
|
273 |
ASN1_OCTET_STRING *oct=NULL;
|
sl@0
|
274 |
X509_EXTENSION *extension=NULL;
|
sl@0
|
275 |
if (!(obj = OBJ_txt2obj(ext, 0)))
|
sl@0
|
276 |
{
|
sl@0
|
277 |
X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
|
sl@0
|
278 |
ERR_add_error_data(2, "name=", ext);
|
sl@0
|
279 |
goto err;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
if (gen_type == 1)
|
sl@0
|
283 |
ext_der = string_to_hex(value, &ext_len);
|
sl@0
|
284 |
else if (gen_type == 2)
|
sl@0
|
285 |
ext_der = generic_asn1(value, ctx, &ext_len);
|
sl@0
|
286 |
|
sl@0
|
287 |
if (ext_der == NULL)
|
sl@0
|
288 |
{
|
sl@0
|
289 |
X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
|
sl@0
|
290 |
ERR_add_error_data(2, "value=", value);
|
sl@0
|
291 |
goto err;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
if (!(oct = M_ASN1_OCTET_STRING_new()))
|
sl@0
|
295 |
{
|
sl@0
|
296 |
X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
|
sl@0
|
297 |
goto err;
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
oct->data = ext_der;
|
sl@0
|
301 |
oct->length = ext_len;
|
sl@0
|
302 |
ext_der = NULL;
|
sl@0
|
303 |
|
sl@0
|
304 |
extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
|
sl@0
|
305 |
|
sl@0
|
306 |
err:
|
sl@0
|
307 |
ASN1_OBJECT_free(obj);
|
sl@0
|
308 |
M_ASN1_OCTET_STRING_free(oct);
|
sl@0
|
309 |
if(ext_der) OPENSSL_free(ext_der);
|
sl@0
|
310 |
return extension;
|
sl@0
|
311 |
|
sl@0
|
312 |
}
|
sl@0
|
313 |
|
sl@0
|
314 |
static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
ASN1_TYPE *typ;
|
sl@0
|
317 |
unsigned char *ext_der = NULL;
|
sl@0
|
318 |
typ = ASN1_generate_v3(value, ctx);
|
sl@0
|
319 |
if (typ == NULL)
|
sl@0
|
320 |
return NULL;
|
sl@0
|
321 |
*ext_len = i2d_ASN1_TYPE(typ, &ext_der);
|
sl@0
|
322 |
ASN1_TYPE_free(typ);
|
sl@0
|
323 |
return ext_der;
|
sl@0
|
324 |
}
|
sl@0
|
325 |
|
sl@0
|
326 |
/* This is the main function: add a bunch of extensions based on a config file
|
sl@0
|
327 |
* section to an extension STACK.
|
sl@0
|
328 |
*/
|
sl@0
|
329 |
|
sl@0
|
330 |
|
sl@0
|
331 |
EXPORT_C int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
332 |
STACK_OF(X509_EXTENSION) **sk)
|
sl@0
|
333 |
{
|
sl@0
|
334 |
X509_EXTENSION *ext;
|
sl@0
|
335 |
STACK_OF(CONF_VALUE) *nval;
|
sl@0
|
336 |
CONF_VALUE *val;
|
sl@0
|
337 |
int i;
|
sl@0
|
338 |
if (!(nval = NCONF_get_section(conf, section))) return 0;
|
sl@0
|
339 |
for (i = 0; i < sk_CONF_VALUE_num(nval); i++)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
val = sk_CONF_VALUE_value(nval, i);
|
sl@0
|
342 |
if (!(ext = X509V3_EXT_nconf(conf, ctx, val->name, val->value)))
|
sl@0
|
343 |
return 0;
|
sl@0
|
344 |
if (sk) X509v3_add_ext(sk, ext, -1);
|
sl@0
|
345 |
X509_EXTENSION_free(ext);
|
sl@0
|
346 |
}
|
sl@0
|
347 |
return 1;
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
/* Convenience functions to add extensions to a certificate, CRL and request */
|
sl@0
|
351 |
|
sl@0
|
352 |
EXPORT_C int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
353 |
X509 *cert)
|
sl@0
|
354 |
{
|
sl@0
|
355 |
STACK_OF(X509_EXTENSION) **sk = NULL;
|
sl@0
|
356 |
if (cert)
|
sl@0
|
357 |
sk = &cert->cert_info->extensions;
|
sl@0
|
358 |
return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
/* Same as above but for a CRL */
|
sl@0
|
362 |
|
sl@0
|
363 |
EXPORT_C int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
364 |
X509_CRL *crl)
|
sl@0
|
365 |
{
|
sl@0
|
366 |
STACK_OF(X509_EXTENSION) **sk = NULL;
|
sl@0
|
367 |
if (crl)
|
sl@0
|
368 |
sk = &crl->crl->extensions;
|
sl@0
|
369 |
return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
|
sl@0
|
370 |
}
|
sl@0
|
371 |
|
sl@0
|
372 |
/* Add extensions to certificate request */
|
sl@0
|
373 |
|
sl@0
|
374 |
EXPORT_C int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
375 |
X509_REQ *req)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
STACK_OF(X509_EXTENSION) *extlist = NULL, **sk = NULL;
|
sl@0
|
378 |
int i;
|
sl@0
|
379 |
if (req)
|
sl@0
|
380 |
sk = &extlist;
|
sl@0
|
381 |
i = X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
|
sl@0
|
382 |
if (!i || !sk)
|
sl@0
|
383 |
return i;
|
sl@0
|
384 |
i = X509_REQ_add_extensions(req, extlist);
|
sl@0
|
385 |
sk_X509_EXTENSION_pop_free(extlist, X509_EXTENSION_free);
|
sl@0
|
386 |
return i;
|
sl@0
|
387 |
}
|
sl@0
|
388 |
|
sl@0
|
389 |
/* Config database functions */
|
sl@0
|
390 |
|
sl@0
|
391 |
EXPORT_C char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
|
sl@0
|
392 |
{
|
sl@0
|
393 |
if(!ctx->db || !ctx->db_meth || !ctx->db_meth->get_string)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
X509V3err(X509V3_F_X509V3_GET_STRING,X509V3_R_OPERATION_NOT_DEFINED);
|
sl@0
|
396 |
return NULL;
|
sl@0
|
397 |
}
|
sl@0
|
398 |
if (ctx->db_meth->get_string)
|
sl@0
|
399 |
return ctx->db_meth->get_string(ctx->db, name, section);
|
sl@0
|
400 |
return NULL;
|
sl@0
|
401 |
}
|
sl@0
|
402 |
|
sl@0
|
403 |
EXPORT_C STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
|
sl@0
|
404 |
{
|
sl@0
|
405 |
if(!ctx->db || !ctx->db_meth || !ctx->db_meth->get_section)
|
sl@0
|
406 |
{
|
sl@0
|
407 |
X509V3err(X509V3_F_X509V3_GET_SECTION,X509V3_R_OPERATION_NOT_DEFINED);
|
sl@0
|
408 |
return NULL;
|
sl@0
|
409 |
}
|
sl@0
|
410 |
if (ctx->db_meth->get_section)
|
sl@0
|
411 |
return ctx->db_meth->get_section(ctx->db, section);
|
sl@0
|
412 |
return NULL;
|
sl@0
|
413 |
}
|
sl@0
|
414 |
|
sl@0
|
415 |
EXPORT_C void X509V3_string_free(X509V3_CTX *ctx, char *str)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
if (!str) return;
|
sl@0
|
418 |
if (ctx->db_meth->free_string)
|
sl@0
|
419 |
ctx->db_meth->free_string(ctx->db, str);
|
sl@0
|
420 |
}
|
sl@0
|
421 |
|
sl@0
|
422 |
EXPORT_C void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
|
sl@0
|
423 |
{
|
sl@0
|
424 |
if (!section) return;
|
sl@0
|
425 |
if (ctx->db_meth->free_section)
|
sl@0
|
426 |
ctx->db_meth->free_section(ctx->db, section);
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
static char *nconf_get_string(void *db, char *section, char *value)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
return NCONF_get_string(db, section, value);
|
sl@0
|
432 |
}
|
sl@0
|
433 |
|
sl@0
|
434 |
static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, char *section)
|
sl@0
|
435 |
{
|
sl@0
|
436 |
return NCONF_get_section(db, section);
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
#ifndef EMULATOR
|
sl@0
|
440 |
static X509V3_CONF_METHOD nconf_method = {
|
sl@0
|
441 |
nconf_get_string,
|
sl@0
|
442 |
nconf_get_section,
|
sl@0
|
443 |
NULL,
|
sl@0
|
444 |
NULL
|
sl@0
|
445 |
};
|
sl@0
|
446 |
#else
|
sl@0
|
447 |
GET_STATIC_VAR_FROM_TLS(nconf_method,v3_conf,X509V3_CONF_METHOD)
|
sl@0
|
448 |
#define nconf_method (*GET_WSD_VAR_NAME(nconf_method,v3_conf, s)())
|
sl@0
|
449 |
const X509V3_CONF_METHOD temp_s_nconf_method = {
|
sl@0
|
450 |
nconf_get_string,
|
sl@0
|
451 |
nconf_get_section,
|
sl@0
|
452 |
NULL,
|
sl@0
|
453 |
NULL
|
sl@0
|
454 |
};
|
sl@0
|
455 |
#endif
|
sl@0
|
456 |
|
sl@0
|
457 |
EXPORT_C void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
ctx->db_meth = &nconf_method;
|
sl@0
|
460 |
ctx->db = conf;
|
sl@0
|
461 |
}
|
sl@0
|
462 |
|
sl@0
|
463 |
EXPORT_C void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
|
sl@0
|
464 |
X509_CRL *crl, int flags)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
ctx->issuer_cert = issuer;
|
sl@0
|
467 |
ctx->subject_cert = subj;
|
sl@0
|
468 |
ctx->crl = crl;
|
sl@0
|
469 |
ctx->subject_req = req;
|
sl@0
|
470 |
ctx->flags = flags;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
|
sl@0
|
473 |
/* Old conf compatibility functions */
|
sl@0
|
474 |
|
sl@0
|
475 |
EXPORT_C X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
|
sl@0
|
476 |
char *value)
|
sl@0
|
477 |
{
|
sl@0
|
478 |
CONF ctmp;
|
sl@0
|
479 |
CONF_set_nconf(&ctmp, conf);
|
sl@0
|
480 |
return X509V3_EXT_nconf(&ctmp, ctx, name, value);
|
sl@0
|
481 |
}
|
sl@0
|
482 |
|
sl@0
|
483 |
/* LHASH *conf: Config file */
|
sl@0
|
484 |
/* char *value: Value */
|
sl@0
|
485 |
EXPORT_C X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
|
sl@0
|
486 |
char *value)
|
sl@0
|
487 |
{
|
sl@0
|
488 |
CONF ctmp;
|
sl@0
|
489 |
CONF_set_nconf(&ctmp, conf);
|
sl@0
|
490 |
return X509V3_EXT_nconf_nid(&ctmp, ctx, ext_nid, value);
|
sl@0
|
491 |
}
|
sl@0
|
492 |
|
sl@0
|
493 |
static char *conf_lhash_get_string(void *db, char *section, char *value)
|
sl@0
|
494 |
{
|
sl@0
|
495 |
return CONF_get_string(db, section, value);
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
|
sl@0
|
499 |
{
|
sl@0
|
500 |
return CONF_get_section(db, section);
|
sl@0
|
501 |
}
|
sl@0
|
502 |
|
sl@0
|
503 |
#ifndef EMULATOR
|
sl@0
|
504 |
static X509V3_CONF_METHOD conf_lhash_method = {
|
sl@0
|
505 |
conf_lhash_get_string,
|
sl@0
|
506 |
conf_lhash_get_section,
|
sl@0
|
507 |
NULL,
|
sl@0
|
508 |
NULL
|
sl@0
|
509 |
};
|
sl@0
|
510 |
#else
|
sl@0
|
511 |
GET_STATIC_VAR_FROM_TLS(conf_lhash_method,v3_conf,X509V3_CONF_METHOD)
|
sl@0
|
512 |
#define conf_lhash_method (*GET_WSD_VAR_NAME(conf_lhash_method,v3_conf, s)())
|
sl@0
|
513 |
const X509V3_CONF_METHOD temp_s_conf_lhash_method = {
|
sl@0
|
514 |
conf_lhash_get_string,
|
sl@0
|
515 |
conf_lhash_get_section,
|
sl@0
|
516 |
NULL,
|
sl@0
|
517 |
NULL
|
sl@0
|
518 |
};
|
sl@0
|
519 |
#endif
|
sl@0
|
520 |
|
sl@0
|
521 |
EXPORT_C void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
|
sl@0
|
522 |
{
|
sl@0
|
523 |
ctx->db_meth = &conf_lhash_method;
|
sl@0
|
524 |
ctx->db = lhash;
|
sl@0
|
525 |
}
|
sl@0
|
526 |
|
sl@0
|
527 |
EXPORT_C int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
528 |
X509 *cert)
|
sl@0
|
529 |
{
|
sl@0
|
530 |
CONF ctmp;
|
sl@0
|
531 |
CONF_set_nconf(&ctmp, conf);
|
sl@0
|
532 |
return X509V3_EXT_add_nconf(&ctmp, ctx, section, cert);
|
sl@0
|
533 |
}
|
sl@0
|
534 |
|
sl@0
|
535 |
/* Same as above but for a CRL */
|
sl@0
|
536 |
|
sl@0
|
537 |
EXPORT_C int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
538 |
X509_CRL *crl)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
CONF ctmp;
|
sl@0
|
541 |
CONF_set_nconf(&ctmp, conf);
|
sl@0
|
542 |
return X509V3_EXT_CRL_add_nconf(&ctmp, ctx, section, crl);
|
sl@0
|
543 |
}
|
sl@0
|
544 |
|
sl@0
|
545 |
/* Add extensions to certificate request */
|
sl@0
|
546 |
|
sl@0
|
547 |
EXPORT_C int X509V3_EXT_REQ_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
|
sl@0
|
548 |
X509_REQ *req)
|
sl@0
|
549 |
{
|
sl@0
|
550 |
CONF ctmp;
|
sl@0
|
551 |
CONF_set_nconf(&ctmp, conf);
|
sl@0
|
552 |
return X509V3_EXT_REQ_add_nconf(&ctmp, ctx, section, req);
|
sl@0
|
553 |
}
|