xref: /freebsd/crypto/openssl/crypto/x509/v3_conf.c (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
1 /*
2  * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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
8  */
9 
10 /* extension creation utilities */
11 
12 #include <stdio.h>
13 #include "crypto/ctype.h"
14 #include "internal/cryptlib.h"
15 #include <openssl/conf.h>
16 #include <openssl/x509.h>
17 #include "crypto/x509.h"
18 #include <openssl/x509v3.h>
19 
20 static int v3_check_critical(const char **value);
21 static int v3_check_generic(const char **value);
22 static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
23     int crit, const char *value);
24 static X509_EXTENSION *v3_generic_extension(const char *ext, const char *value,
25     int crit, int type,
26     X509V3_CTX *ctx);
27 static char *conf_lhash_get_string(void *db, const char *section, const char *value);
28 static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, const char *section);
29 static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,
30     int ext_nid, int crit, void *ext_struc);
31 static unsigned char *generic_asn1(const char *value, X509V3_CTX *ctx,
32     long *ext_len);
33 
X509V3_EXT_nconf_int(CONF * conf,X509V3_CTX * ctx,const char * section,const char * name,const char * value)34 static X509_EXTENSION *X509V3_EXT_nconf_int(CONF *conf, X509V3_CTX *ctx,
35     const char *section,
36     const char *name, const char *value)
37 {
38     int crit;
39     int ext_type;
40     X509_EXTENSION *ret;
41 
42     crit = v3_check_critical(&value);
43     if ((ext_type = v3_check_generic(&value)))
44         return v3_generic_extension(name, value, crit, ext_type, ctx);
45     ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
46     if (!ret) {
47         if (section != NULL)
48             ERR_raise_data(ERR_LIB_X509V3, X509V3_R_ERROR_IN_EXTENSION,
49                 "section=%s, name=%s, value=%s",
50                 section, name, value);
51         else
52             ERR_raise_data(ERR_LIB_X509V3, X509V3_R_ERROR_IN_EXTENSION,
53                 "name=%s, value=%s", name, value);
54     }
55     return ret;
56 }
57 
X509V3_EXT_nconf(CONF * conf,X509V3_CTX * ctx,const char * name,const char * value)58 X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, const char *name,
59     const char *value)
60 {
61     return X509V3_EXT_nconf_int(conf, ctx, NULL, name, value);
62 }
63 
X509V3_EXT_nconf_nid(CONF * conf,X509V3_CTX * ctx,int ext_nid,const char * value)64 X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
65     const char *value)
66 {
67     int crit;
68     int ext_type;
69 
70     crit = v3_check_critical(&value);
71     if ((ext_type = v3_check_generic(&value)))
72         return v3_generic_extension(OBJ_nid2sn(ext_nid),
73             value, crit, ext_type, ctx);
74     return do_ext_nconf(conf, ctx, ext_nid, crit, value);
75 }
76 
77 /* CONF *conf:  Config file    */
78 /* char *value:  Value    */
do_ext_nconf(CONF * conf,X509V3_CTX * ctx,int ext_nid,int crit,const char * value)79 static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
80     int crit, const char *value)
81 {
82     const X509V3_EXT_METHOD *method;
83     X509_EXTENSION *ext;
84     STACK_OF(CONF_VALUE) *nval;
85     void *ext_struc;
86 
87     if (ext_nid == NID_undef) {
88         ERR_raise(ERR_LIB_X509V3, X509V3_R_UNKNOWN_EXTENSION_NAME);
89         return NULL;
90     }
91     if ((method = X509V3_EXT_get_nid(ext_nid)) == NULL) {
92         ERR_raise(ERR_LIB_X509V3, X509V3_R_UNKNOWN_EXTENSION);
93         return NULL;
94     }
95     /* Now get internal extension representation based on type */
96     if (method->v2i) {
97         if (*value == '@')
98             nval = NCONF_get_section(conf, value + 1);
99         else
100             nval = X509V3_parse_list(value);
101         if (nval == NULL || sk_CONF_VALUE_num(nval) <= 0) {
102             ERR_raise_data(ERR_LIB_X509V3, X509V3_R_INVALID_EXTENSION_STRING,
103                 "name=%s,section=%s", OBJ_nid2sn(ext_nid), value);
104             if (*value != '@')
105                 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
106             return NULL;
107         }
108         ext_struc = method->v2i(method, ctx, nval);
109         if (*value != '@')
110             sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
111         if (!ext_struc)
112             return NULL;
113     } else if (method->s2i) {
114         if ((ext_struc = method->s2i(method, ctx, value)) == NULL)
115             return NULL;
116     } else if (method->r2i) {
117         if (!ctx->db || !ctx->db_meth) {
118             ERR_raise(ERR_LIB_X509V3, X509V3_R_NO_CONFIG_DATABASE);
119             return NULL;
120         }
121         if ((ext_struc = method->r2i(method, ctx, value)) == NULL)
122             return NULL;
123     } else {
124         ERR_raise_data(ERR_LIB_X509V3, X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,
125             "name=%s", OBJ_nid2sn(ext_nid));
126         return NULL;
127     }
128 
129     ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
130     if (method->it)
131         ASN1_item_free(ext_struc, ASN1_ITEM_ptr(method->it));
132     else
133         method->ext_free(ext_struc);
134     return ext;
135 }
136 
do_ext_i2d(const X509V3_EXT_METHOD * method,int ext_nid,int crit,void * ext_struc)137 static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,
138     int ext_nid, int crit, void *ext_struc)
139 {
140     unsigned char *ext_der = NULL;
141     int ext_len;
142     ASN1_OCTET_STRING *ext_oct = NULL;
143     X509_EXTENSION *ext;
144 
145     /* Convert internal representation to DER */
146     if (method->it) {
147         ext_der = NULL;
148         ext_len = ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it));
149         if (ext_len < 0) {
150             ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
151             goto err;
152         }
153     } else {
154         unsigned char *p;
155 
156         ext_len = method->i2d(ext_struc, NULL);
157         if (ext_len <= 0) {
158             ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
159             goto err;
160         }
161         if ((ext_der = OPENSSL_malloc(ext_len)) == NULL)
162             goto err;
163         p = ext_der;
164         method->i2d(ext_struc, &p);
165     }
166     if ((ext_oct = ASN1_OCTET_STRING_new()) == NULL) {
167         ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
168         goto err;
169     }
170     ext_oct->data = ext_der;
171     ext_der = NULL;
172     ext_oct->length = ext_len;
173 
174     ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
175     if (!ext) {
176         ERR_raise(ERR_LIB_X509V3, ERR_R_X509V3_LIB);
177         goto err;
178     }
179     ASN1_OCTET_STRING_free(ext_oct);
180 
181     return ext;
182 
183 err:
184     OPENSSL_free(ext_der);
185     ASN1_OCTET_STRING_free(ext_oct);
186     return NULL;
187 }
188 
189 /* Given an internal structure, nid and critical flag create an extension */
190 
X509V3_EXT_i2d(int ext_nid,int crit,void * ext_struc)191 X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
192 {
193     const X509V3_EXT_METHOD *method;
194 
195     if ((method = X509V3_EXT_get_nid(ext_nid)) == NULL) {
196         ERR_raise(ERR_LIB_X509V3, X509V3_R_UNKNOWN_EXTENSION);
197         return NULL;
198     }
199     return do_ext_i2d(method, ext_nid, crit, ext_struc);
200 }
201 
202 /* Check the extension string for critical flag */
v3_check_critical(const char ** value)203 static int v3_check_critical(const char **value)
204 {
205     const char *p = *value;
206 
207     if (!CHECK_AND_SKIP_PREFIX(p, "critical,"))
208         return 0;
209     while (ossl_isspace(*p))
210         p++;
211     *value = p;
212     return 1;
213 }
214 
215 /* Check extension string for generic extension and return the type */
v3_check_generic(const char ** value)216 static int v3_check_generic(const char **value)
217 {
218     int gen_type = 0;
219     const char *p = *value;
220 
221     if (CHECK_AND_SKIP_PREFIX(p, "DER:")) {
222         gen_type = 1;
223     } else if (CHECK_AND_SKIP_PREFIX(p, "ASN1:")) {
224         gen_type = 2;
225     } else
226         return 0;
227 
228     while (ossl_isspace(*p))
229         p++;
230     *value = p;
231     return gen_type;
232 }
233 
234 /* Create a generic extension: for now just handle DER type */
v3_generic_extension(const char * ext,const char * value,int crit,int gen_type,X509V3_CTX * ctx)235 static X509_EXTENSION *v3_generic_extension(const char *ext, const char *value,
236     int crit, int gen_type,
237     X509V3_CTX *ctx)
238 {
239     unsigned char *ext_der = NULL;
240     long ext_len = 0;
241     ASN1_OBJECT *obj = NULL;
242     ASN1_OCTET_STRING *oct = NULL;
243     X509_EXTENSION *extension = NULL;
244 
245     if ((obj = OBJ_txt2obj(ext, 0)) == NULL) {
246         ERR_raise_data(ERR_LIB_X509V3, X509V3_R_EXTENSION_NAME_ERROR,
247             "name=%s", ext);
248         goto err;
249     }
250 
251     if (gen_type == 1)
252         ext_der = OPENSSL_hexstr2buf(value, &ext_len);
253     else if (gen_type == 2)
254         ext_der = generic_asn1(value, ctx, &ext_len);
255 
256     if (ext_der == NULL) {
257         ERR_raise_data(ERR_LIB_X509V3, X509V3_R_EXTENSION_VALUE_ERROR,
258             "value=%s", value);
259         goto err;
260     }
261 
262     if ((oct = ASN1_OCTET_STRING_new()) == NULL) {
263         ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
264         goto err;
265     }
266 
267     oct->data = ext_der;
268     oct->length = ext_len;
269     ext_der = NULL;
270 
271     extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
272 
273 err:
274     ASN1_OBJECT_free(obj);
275     ASN1_OCTET_STRING_free(oct);
276     OPENSSL_free(ext_der);
277     return extension;
278 }
279 
generic_asn1(const char * value,X509V3_CTX * ctx,long * ext_len)280 static unsigned char *generic_asn1(const char *value, X509V3_CTX *ctx,
281     long *ext_len)
282 {
283     ASN1_TYPE *typ;
284     unsigned char *ext_der = NULL;
285 
286     typ = ASN1_generate_v3(value, ctx);
287     if (typ == NULL)
288         return NULL;
289     *ext_len = i2d_ASN1_TYPE(typ, &ext_der);
290     ASN1_TYPE_free(typ);
291     return ext_der;
292 }
293 
delete_ext(STACK_OF (X509_EXTENSION)* sk,X509_EXTENSION * dext)294 static void delete_ext(STACK_OF(X509_EXTENSION) *sk, X509_EXTENSION *dext)
295 {
296     int idx;
297     ASN1_OBJECT *obj;
298 
299     obj = X509_EXTENSION_get_object(dext);
300     while ((idx = X509v3_get_ext_by_OBJ(sk, obj, -1)) >= 0)
301         X509_EXTENSION_free(X509v3_delete_ext(sk, idx));
302 }
303 
304 /*
305  * This is the main function: add a bunch of extensions based on a config
306  * file section to an extension STACK. Just check in case sk == NULL.
307  * Note that on error new elements may have been added to *sk if sk != NULL.
308  */
X509V3_EXT_add_nconf_sk(CONF * conf,X509V3_CTX * ctx,const char * section,STACK_OF (X509_EXTENSION)** sk)309 int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section,
310     STACK_OF(X509_EXTENSION) **sk)
311 {
312     X509_EXTENSION *ext;
313     STACK_OF(CONF_VALUE) *nval;
314     const CONF_VALUE *val;
315     int i, akid = -1, skid = -1;
316 
317     if ((nval = NCONF_get_section(conf, section)) == NULL)
318         return 0;
319     for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
320         val = sk_CONF_VALUE_value(nval, i);
321         if (strcmp(val->name, "authorityKeyIdentifier") == 0)
322             akid = i;
323         else if (strcmp(val->name, "subjectKeyIdentifier") == 0)
324             skid = i;
325     }
326     for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
327         val = sk_CONF_VALUE_value(nval, i);
328         if (skid > akid && akid >= 0) {
329             /* make sure SKID is handled before AKID */
330             if (i == akid)
331                 val = sk_CONF_VALUE_value(nval, skid);
332             else if (i == skid)
333                 val = sk_CONF_VALUE_value(nval, akid);
334         }
335         if ((ext = X509V3_EXT_nconf_int(conf, ctx, val->section,
336                  val->name, val->value))
337             == NULL)
338             return 0;
339         if (sk != NULL) {
340             if (ctx->flags == X509V3_CTX_REPLACE)
341                 delete_ext(*sk, ext);
342             if (X509v3_add_ext(sk, ext, -1) == NULL) {
343                 X509_EXTENSION_free(ext);
344                 return 0;
345             }
346         }
347         X509_EXTENSION_free(ext);
348     }
349     return 1;
350 }
351 
352 /*
353  * Add extensions to a certificate. Just check in case cert == NULL.
354  * Note that on error new elements may remain added to cert if cert != NULL.
355  */
X509V3_EXT_add_nconf(CONF * conf,X509V3_CTX * ctx,const char * section,X509 * cert)356 int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section,
357     X509 *cert)
358 {
359     STACK_OF(X509_EXTENSION) **sk = NULL;
360     if (cert != NULL)
361         sk = &cert->cert_info.extensions;
362     return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
363 }
364 
365 /*
366  * Add extensions to a CRL. Just check in case crl == NULL.
367  * Note that on error new elements may remain added to crl if crl != NULL.
368  */
X509V3_EXT_CRL_add_nconf(CONF * conf,X509V3_CTX * ctx,const char * section,X509_CRL * crl)369 int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section,
370     X509_CRL *crl)
371 {
372     STACK_OF(X509_EXTENSION) **sk = NULL;
373     if (crl != NULL)
374         sk = &crl->crl.extensions;
375     return X509V3_EXT_add_nconf_sk(conf, ctx, section, sk);
376 }
377 
378 /*
379  * Add extensions to certificate request. Just check in case req is NULL.
380  * Note that on error new elements may remain added to req if req != NULL.
381  */
X509V3_EXT_REQ_add_nconf(CONF * conf,X509V3_CTX * ctx,const char * section,X509_REQ * req)382 int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section,
383     X509_REQ *req)
384 {
385     STACK_OF(X509_EXTENSION) *exts = NULL;
386     int ret = X509V3_EXT_add_nconf_sk(conf, ctx, section, &exts);
387 
388     if (ret && req != NULL && exts != NULL)
389         ret = X509_REQ_add_extensions(req, exts);
390     sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
391     return ret;
392 }
393 
394 /* Config database functions */
395 
X509V3_get_string(X509V3_CTX * ctx,const char * name,const char * section)396 char *X509V3_get_string(X509V3_CTX *ctx, const char *name, const char *section)
397 {
398     if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_string) {
399         ERR_raise(ERR_LIB_X509V3, X509V3_R_OPERATION_NOT_DEFINED);
400         return NULL;
401     }
402     if (ctx->db_meth->get_string)
403         return ctx->db_meth->get_string(ctx->db, name, section);
404     return NULL;
405 }
406 
STACK_OF(CONF_VALUE)407 STACK_OF(CONF_VALUE) *X509V3_get_section(X509V3_CTX *ctx, const char *section)
408 {
409     if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_section) {
410         ERR_raise(ERR_LIB_X509V3, X509V3_R_OPERATION_NOT_DEFINED);
411         return NULL;
412     }
413     if (ctx->db_meth->get_section)
414         return ctx->db_meth->get_section(ctx->db, section);
415     return NULL;
416 }
417 
X509V3_string_free(X509V3_CTX * ctx,char * str)418 void X509V3_string_free(X509V3_CTX *ctx, char *str)
419 {
420     if (!str)
421         return;
422     if (ctx->db_meth->free_string)
423         ctx->db_meth->free_string(ctx->db, str);
424 }
425 
X509V3_section_free(X509V3_CTX * ctx,STACK_OF (CONF_VALUE)* section)426 void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
427 {
428     if (!section)
429         return;
430     if (ctx->db_meth->free_section)
431         ctx->db_meth->free_section(ctx->db, section);
432 }
433 
nconf_get_string(void * db,const char * section,const char * value)434 static char *nconf_get_string(void *db, const char *section, const char *value)
435 {
436     return NCONF_get_string(db, section, value);
437 }
438 
STACK_OF(CONF_VALUE)439 static STACK_OF(CONF_VALUE) *nconf_get_section(void *db, const char *section)
440 {
441     return NCONF_get_section(db, section);
442 }
443 
444 static X509V3_CONF_METHOD nconf_method = {
445     nconf_get_string,
446     nconf_get_section,
447     NULL,
448     NULL
449 };
450 
X509V3_set_nconf(X509V3_CTX * ctx,CONF * conf)451 void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf)
452 {
453     if (ctx == NULL) {
454         ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER);
455         return;
456     }
457     ctx->db_meth = &nconf_method;
458     ctx->db = conf;
459 }
460 
X509V3_set_ctx(X509V3_CTX * ctx,X509 * issuer,X509 * subj,X509_REQ * req,X509_CRL * crl,int flags)461 void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
462     X509_CRL *crl, int flags)
463 {
464     if (ctx == NULL) {
465         ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER);
466         return;
467     }
468     ctx->flags = flags;
469     ctx->issuer_cert = issuer;
470     ctx->subject_cert = subj;
471     ctx->subject_req = req;
472     ctx->crl = crl;
473     ctx->db_meth = NULL;
474     ctx->db = NULL;
475     ctx->issuer_pkey = NULL;
476 }
477 
478 /* For API backward compatibility, this is separate from X509V3_set_ctx() */
X509V3_set_issuer_pkey(X509V3_CTX * ctx,EVP_PKEY * pkey)479 int X509V3_set_issuer_pkey(X509V3_CTX *ctx, EVP_PKEY *pkey)
480 {
481     if (ctx == NULL) {
482         ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER);
483         return 0;
484     }
485     if (ctx->subject_cert == NULL && pkey != NULL) {
486         ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT);
487         return 0;
488     }
489     ctx->issuer_pkey = pkey;
490     return 1;
491 }
492 
493 /* Old conf compatibility functions */
494 
X509V3_EXT_conf(LHASH_OF (CONF_VALUE)* conf,X509V3_CTX * ctx,const char * name,const char * value)495 X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
496     const char *name, const char *value)
497 {
498     CONF *ctmp;
499     X509_EXTENSION *ret;
500 
501     if ((ctmp = NCONF_new(NULL)) == NULL)
502         return NULL;
503     CONF_set_nconf(ctmp, conf);
504     ret = X509V3_EXT_nconf(ctmp, ctx, name, value);
505     CONF_set_nconf(ctmp, NULL);
506     NCONF_free(ctmp);
507     return ret;
508 }
509 
X509V3_EXT_conf_nid(LHASH_OF (CONF_VALUE)* conf,X509V3_CTX * ctx,int ext_nid,const char * value)510 X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf,
511     X509V3_CTX *ctx, int ext_nid, const char *value)
512 {
513     CONF *ctmp;
514     X509_EXTENSION *ret;
515 
516     if ((ctmp = NCONF_new(NULL)) == NULL)
517         return NULL;
518     CONF_set_nconf(ctmp, conf);
519     ret = X509V3_EXT_nconf_nid(ctmp, ctx, ext_nid, value);
520     CONF_set_nconf(ctmp, NULL);
521     NCONF_free(ctmp);
522     return ret;
523 }
524 
conf_lhash_get_string(void * db,const char * section,const char * value)525 static char *conf_lhash_get_string(void *db, const char *section, const char *value)
526 {
527     return CONF_get_string(db, section, value);
528 }
529 
STACK_OF(CONF_VALUE)530 static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, const char *section)
531 {
532     return CONF_get_section(db, section);
533 }
534 
535 static X509V3_CONF_METHOD conf_lhash_method = {
536     conf_lhash_get_string,
537     conf_lhash_get_section,
538     NULL,
539     NULL
540 };
541 
X509V3_set_conf_lhash(X509V3_CTX * ctx,LHASH_OF (CONF_VALUE)* lhash)542 void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash)
543 {
544     if (ctx == NULL) {
545         ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER);
546         return;
547     }
548     ctx->db_meth = &conf_lhash_method;
549     ctx->db = lhash;
550 }
551 
X509V3_EXT_add_conf(LHASH_OF (CONF_VALUE)* conf,X509V3_CTX * ctx,const char * section,X509 * cert)552 int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
553     const char *section, X509 *cert)
554 {
555     CONF *ctmp;
556     int ret;
557 
558     if ((ctmp = NCONF_new(NULL)) == NULL)
559         return 0;
560     CONF_set_nconf(ctmp, conf);
561     ret = X509V3_EXT_add_nconf(ctmp, ctx, section, cert);
562     CONF_set_nconf(ctmp, NULL);
563     NCONF_free(ctmp);
564     return ret;
565 }
566 
567 /* Same as above but for a CRL */
568 
X509V3_EXT_CRL_add_conf(LHASH_OF (CONF_VALUE)* conf,X509V3_CTX * ctx,const char * section,X509_CRL * crl)569 int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
570     const char *section, X509_CRL *crl)
571 {
572     CONF *ctmp;
573     int ret;
574 
575     if ((ctmp = NCONF_new(NULL)) == NULL)
576         return 0;
577     CONF_set_nconf(ctmp, conf);
578     ret = X509V3_EXT_CRL_add_nconf(ctmp, ctx, section, crl);
579     CONF_set_nconf(ctmp, NULL);
580     NCONF_free(ctmp);
581     return ret;
582 }
583 
584 /* Add extensions to certificate request */
585 
X509V3_EXT_REQ_add_conf(LHASH_OF (CONF_VALUE)* conf,X509V3_CTX * ctx,const char * section,X509_REQ * req)586 int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx,
587     const char *section, X509_REQ *req)
588 {
589     CONF *ctmp;
590     int ret;
591 
592     if ((ctmp = NCONF_new(NULL)) == NULL)
593         return 0;
594     CONF_set_nconf(ctmp, conf);
595     ret = X509V3_EXT_REQ_add_nconf(ctmp, ctx, section, req);
596     CONF_set_nconf(ctmp, NULL);
597     NCONF_free(ctmp);
598     return ret;
599 }
600