/src/openssl/crypto/x509/v3_bcons.c
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  | #include <stdio.h>  | 
11  |  | #include "internal/cryptlib.h"  | 
12  |  | #include <openssl/asn1.h>  | 
13  |  | #include <openssl/asn1t.h>  | 
14  |  | #include <openssl/conf.h>  | 
15  |  | #include <openssl/x509v3.h>  | 
16  |  | #include "ext_dat.h"  | 
17  |  | #include "x509_local.h"  | 
18  |  |  | 
19  |  | static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,  | 
20  |  |                                                    BASIC_CONSTRAINTS *bcons,  | 
21  |  |                                                    STACK_OF(CONF_VALUE)  | 
22  |  |                                                    *extlist);  | 
23  |  | static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,  | 
24  |  |                                                 X509V3_CTX *ctx,  | 
25  |  |                                                 STACK_OF(CONF_VALUE) *values);  | 
26  |  |  | 
27  |  | const X509V3_EXT_METHOD ossl_v3_bcons = { | 
28  |  |     NID_basic_constraints, 0,  | 
29  |  |     ASN1_ITEM_ref(BASIC_CONSTRAINTS),  | 
30  |  |     0, 0, 0, 0,  | 
31  |  |     0, 0,  | 
32  |  |     (X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS,  | 
33  |  |     (X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,  | 
34  |  |     NULL, NULL,  | 
35  |  |     NULL  | 
36  |  | };  | 
37  |  |  | 
38  |  | ASN1_SEQUENCE(BASIC_CONSTRAINTS) = { | 
39  |  |         ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),  | 
40  |  |         ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)  | 
41  |  | } ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)  | 
42  |  |  | 
43  |  | IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)  | 
44  |  |  | 
45  |  | static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,  | 
46  |  |                                                    BASIC_CONSTRAINTS *bcons,  | 
47  |  |                                                    STACK_OF(CONF_VALUE)  | 
48  |  |                                                    *extlist)  | 
49  | 260  | { | 
50  | 260  |     X509V3_add_value_bool("CA", bcons->ca, &extlist); | 
51  | 260  |     X509V3_add_value_int("pathlen", bcons->pathlen, &extlist); | 
52  | 260  |     return extlist;  | 
53  | 260  | }  | 
54  |  |  | 
55  |  | static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,  | 
56  |  |                                                 X509V3_CTX *ctx,  | 
57  |  |                                                 STACK_OF(CONF_VALUE) *values)  | 
58  | 0  | { | 
59  | 0  |     BASIC_CONSTRAINTS *bcons = NULL;  | 
60  | 0  |     CONF_VALUE *val;  | 
61  | 0  |     int i;  | 
62  |  | 
  | 
63  | 0  |     if ((bcons = BASIC_CONSTRAINTS_new()) == NULL) { | 
64  | 0  |         ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);  | 
65  | 0  |         return NULL;  | 
66  | 0  |     }  | 
67  | 0  |     for (i = 0; i < sk_CONF_VALUE_num(values); i++) { | 
68  | 0  |         val = sk_CONF_VALUE_value(values, i);  | 
69  | 0  |         if (strcmp(val->name, "CA") == 0) { | 
70  | 0  |             if (!X509V3_get_value_bool(val, &bcons->ca))  | 
71  | 0  |                 goto err;  | 
72  | 0  |         } else if (strcmp(val->name, "pathlen") == 0) { | 
73  | 0  |             if (!X509V3_get_value_int(val, &bcons->pathlen))  | 
74  | 0  |                 goto err;  | 
75  | 0  |         } else { | 
76  | 0  |             ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NAME);  | 
77  | 0  |             X509V3_conf_add_error_name_value(val);  | 
78  | 0  |             goto err;  | 
79  | 0  |         }  | 
80  | 0  |     }  | 
81  | 0  |     return bcons;  | 
82  | 0  |  err:  | 
83  | 0  |     BASIC_CONSTRAINTS_free(bcons);  | 
84  | 0  |     return NULL;  | 
85  | 0  | }  |