/src/boringssl/crypto/x509/v3_bcons.cc
Line | Count | Source |
1 | | // Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <stdio.h> |
16 | | #include <string.h> |
17 | | |
18 | | #include <openssl/asn1.h> |
19 | | #include <openssl/asn1t.h> |
20 | | #include <openssl/conf.h> |
21 | | #include <openssl/err.h> |
22 | | #include <openssl/obj.h> |
23 | | #include <openssl/x509.h> |
24 | | |
25 | | #include "internal.h" |
26 | | |
27 | | |
28 | | using namespace bssl; |
29 | | |
30 | | static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS( |
31 | | const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *extlist); |
32 | | static void *v2i_BASIC_CONSTRAINTS(const X509V3_EXT_METHOD *method, |
33 | | const X509V3_CTX *ctx, |
34 | | const STACK_OF(CONF_VALUE) *values); |
35 | | |
36 | | const X509V3_EXT_METHOD bssl::v3_bcons = { |
37 | | NID_basic_constraints, |
38 | | 0, |
39 | | ASN1_ITEM_ref(BASIC_CONSTRAINTS), |
40 | | nullptr, |
41 | | nullptr, |
42 | | nullptr, |
43 | | nullptr, |
44 | | nullptr, |
45 | | nullptr, |
46 | | i2v_BASIC_CONSTRAINTS, |
47 | | v2i_BASIC_CONSTRAINTS, |
48 | | nullptr, |
49 | | nullptr, |
50 | | nullptr, |
51 | | }; |
52 | | |
53 | | ASN1_SEQUENCE(BASIC_CONSTRAINTS) = { |
54 | | ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN), |
55 | | ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER), |
56 | | } ASN1_SEQUENCE_END(BASIC_CONSTRAINTS) |
57 | | |
58 | | IMPLEMENT_ASN1_FUNCTIONS_const(BASIC_CONSTRAINTS) |
59 | | |
60 | | static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS( |
61 | 190 | const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *extlist) { |
62 | 190 | const BASIC_CONSTRAINTS *bcons = |
63 | 190 | reinterpret_cast<const BASIC_CONSTRAINTS *>(ext); |
64 | 190 | X509V3_add_value_bool("CA", bcons->ca, &extlist); |
65 | 190 | X509V3_add_value_int("pathlen", bcons->pathlen, &extlist); |
66 | 190 | return extlist; |
67 | 190 | } |
68 | | |
69 | | static void *v2i_BASIC_CONSTRAINTS(const X509V3_EXT_METHOD *method, |
70 | | const X509V3_CTX *ctx, |
71 | 186 | const STACK_OF(CONF_VALUE) *values) { |
72 | 186 | BASIC_CONSTRAINTS *bcons = nullptr; |
73 | 186 | if (!(bcons = BASIC_CONSTRAINTS_new())) { |
74 | 0 | return nullptr; |
75 | 0 | } |
76 | 589 | for (size_t i = 0; i < sk_CONF_VALUE_num(values); i++) { |
77 | 540 | const CONF_VALUE *val = sk_CONF_VALUE_value(values, i); |
78 | 540 | if (!strcmp(val->name, "CA")) { |
79 | 195 | if (!X509V3_get_value_bool(val, &bcons->ca)) { |
80 | 20 | goto err; |
81 | 20 | } |
82 | 345 | } else if (!strcmp(val->name, "pathlen")) { |
83 | 238 | if (!X509V3_get_value_int(val, &bcons->pathlen)) { |
84 | 10 | goto err; |
85 | 10 | } |
86 | 238 | } else { |
87 | 107 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NAME); |
88 | 107 | X509V3_conf_err(val); |
89 | 107 | goto err; |
90 | 107 | } |
91 | 540 | } |
92 | 49 | return bcons; |
93 | 137 | err: |
94 | 137 | BASIC_CONSTRAINTS_free(bcons); |
95 | 137 | return nullptr; |
96 | 186 | } |