/src/openssl111/crypto/x509v3/v3_bcons.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the OpenSSL license (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 |  |  | 
| 18 |  | static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, | 
| 19 |  |                                                    BASIC_CONSTRAINTS *bcons, | 
| 20 |  |                                                    STACK_OF(CONF_VALUE) | 
| 21 |  |                                                    *extlist); | 
| 22 |  | static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, | 
| 23 |  |                                                 X509V3_CTX *ctx, | 
| 24 |  |                                                 STACK_OF(CONF_VALUE) *values); | 
| 25 |  |  | 
| 26 |  | const X509V3_EXT_METHOD v3_bcons = { | 
| 27 |  |     NID_basic_constraints, 0, | 
| 28 |  |     ASN1_ITEM_ref(BASIC_CONSTRAINTS), | 
| 29 |  |     0, 0, 0, 0, | 
| 30 |  |     0, 0, | 
| 31 |  |     (X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS, | 
| 32 |  |     (X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS, | 
| 33 |  |     NULL, NULL, | 
| 34 |  |     NULL | 
| 35 |  | }; | 
| 36 |  |  | 
| 37 |  | ASN1_SEQUENCE(BASIC_CONSTRAINTS) = { | 
| 38 |  |         ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN), | 
| 39 |  |         ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER) | 
| 40 |  | } ASN1_SEQUENCE_END(BASIC_CONSTRAINTS) | 
| 41 |  |  | 
| 42 |  | IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) | 
| 43 |  |  | 
| 44 |  | static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, | 
| 45 |  |                                                    BASIC_CONSTRAINTS *bcons, | 
| 46 |  |                                                    STACK_OF(CONF_VALUE) | 
| 47 |  |                                                    *extlist) | 
| 48 | 0 | { | 
| 49 | 0 |     X509V3_add_value_bool("CA", bcons->ca, &extlist); | 
| 50 | 0 |     X509V3_add_value_int("pathlen", bcons->pathlen, &extlist); | 
| 51 | 0 |     return extlist; | 
| 52 | 0 | } | 
| 53 |  |  | 
| 54 |  | static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, | 
| 55 |  |                                                 X509V3_CTX *ctx, | 
| 56 |  |                                                 STACK_OF(CONF_VALUE) *values) | 
| 57 | 0 | { | 
| 58 | 0 |     BASIC_CONSTRAINTS *bcons = NULL; | 
| 59 | 0 |     CONF_VALUE *val; | 
| 60 | 0 |     int i; | 
| 61 |  | 
 | 
| 62 | 0 |     if ((bcons = BASIC_CONSTRAINTS_new()) == NULL) { | 
| 63 | 0 |         X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE); | 
| 64 | 0 |         return NULL; | 
| 65 | 0 |     } | 
| 66 | 0 |     for (i = 0; i < sk_CONF_VALUE_num(values); i++) { | 
| 67 | 0 |         val = sk_CONF_VALUE_value(values, i); | 
| 68 | 0 |         if (strcmp(val->name, "CA") == 0) { | 
| 69 | 0 |             if (!X509V3_get_value_bool(val, &bcons->ca)) | 
| 70 | 0 |                 goto err; | 
| 71 | 0 |         } else if (strcmp(val->name, "pathlen") == 0) { | 
| 72 | 0 |             if (!X509V3_get_value_int(val, &bcons->pathlen)) | 
| 73 | 0 |                 goto err; | 
| 74 | 0 |         } else { | 
| 75 | 0 |             X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME); | 
| 76 | 0 |             X509V3_conf_err(val); | 
| 77 | 0 |             goto err; | 
| 78 | 0 |         } | 
| 79 | 0 |     } | 
| 80 | 0 |     return bcons; | 
| 81 | 0 |  err: | 
| 82 | 0 |     BASIC_CONSTRAINTS_free(bcons); | 
| 83 | 0 |     return NULL; | 
| 84 | 0 | } |