/src/boringssl/crypto/x509/v3_pmaps.cc
Line | Count | Source |
1 | | // Copyright 2003-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 | | |
17 | | #include <openssl/asn1t.h> |
18 | | #include <openssl/conf.h> |
19 | | #include <openssl/err.h> |
20 | | #include <openssl/obj.h> |
21 | | #include <openssl/x509.h> |
22 | | |
23 | | #include "internal.h" |
24 | | |
25 | | |
26 | | using namespace bssl; |
27 | | |
28 | | static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, |
29 | | const X509V3_CTX *ctx, |
30 | | const STACK_OF(CONF_VALUE) *nval); |
31 | | static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS( |
32 | | const X509V3_EXT_METHOD *method, void *pmps, STACK_OF(CONF_VALUE) *extlist); |
33 | | |
34 | | const X509V3_EXT_METHOD bssl::v3_policy_mappings = { |
35 | | NID_policy_mappings, |
36 | | 0, |
37 | | ASN1_ITEM_ref(POLICY_MAPPINGS), |
38 | | nullptr, |
39 | | nullptr, |
40 | | nullptr, |
41 | | nullptr, |
42 | | nullptr, |
43 | | nullptr, |
44 | | i2v_POLICY_MAPPINGS, |
45 | | v2i_POLICY_MAPPINGS, |
46 | | nullptr, |
47 | | nullptr, |
48 | | nullptr, |
49 | | }; |
50 | | |
51 | | ASN1_SEQUENCE(POLICY_MAPPING) = { |
52 | | ASN1_SIMPLE(POLICY_MAPPING, issuerDomainPolicy, ASN1_OBJECT), |
53 | | ASN1_SIMPLE(POLICY_MAPPING, subjectDomainPolicy, ASN1_OBJECT), |
54 | | } ASN1_SEQUENCE_END(POLICY_MAPPING) |
55 | | |
56 | | ASN1_ITEM_TEMPLATE(POLICY_MAPPINGS) = ASN1_EX_TEMPLATE_TYPE( |
57 | | ASN1_TFLG_SEQUENCE_OF, 0, POLICY_MAPPINGS, POLICY_MAPPING) |
58 | | ASN1_ITEM_TEMPLATE_END(POLICY_MAPPINGS) |
59 | | |
60 | | IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) |
61 | | |
62 | | static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS( |
63 | 71 | const X509V3_EXT_METHOD *method, void *a, STACK_OF(CONF_VALUE) *ext_list) { |
64 | 71 | const POLICY_MAPPINGS *pmaps = reinterpret_cast<POLICY_MAPPINGS *>(a); |
65 | 140 | for (size_t i = 0; i < sk_POLICY_MAPPING_num(pmaps); i++) { |
66 | 69 | const POLICY_MAPPING *pmap = sk_POLICY_MAPPING_value(pmaps, i); |
67 | 69 | char obj_tmp1[80], obj_tmp2[80]; |
68 | 69 | i2t_ASN1_OBJECT(obj_tmp1, 80, pmap->issuerDomainPolicy); |
69 | 69 | i2t_ASN1_OBJECT(obj_tmp2, 80, pmap->subjectDomainPolicy); |
70 | 69 | X509V3_add_value(obj_tmp1, obj_tmp2, &ext_list); |
71 | 69 | } |
72 | 71 | return ext_list; |
73 | 71 | } |
74 | | |
75 | | static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, |
76 | | const X509V3_CTX *ctx, |
77 | 78 | const STACK_OF(CONF_VALUE) *nval) { |
78 | 78 | POLICY_MAPPINGS *pmaps = sk_POLICY_MAPPING_new_null(); |
79 | 78 | if (pmaps == nullptr) { |
80 | 0 | return nullptr; |
81 | 0 | } |
82 | | |
83 | 361 | for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
84 | 346 | const CONF_VALUE *val = sk_CONF_VALUE_value(nval, i); |
85 | 346 | if (!val->value || !val->name) { |
86 | 16 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER); |
87 | 16 | X509V3_conf_err(val); |
88 | 16 | goto err; |
89 | 16 | } |
90 | | |
91 | 330 | POLICY_MAPPING *pmap = POLICY_MAPPING_new(); |
92 | 330 | if (pmap == nullptr || !sk_POLICY_MAPPING_push(pmaps, pmap)) { |
93 | 0 | POLICY_MAPPING_free(pmap); |
94 | 0 | goto err; |
95 | 0 | } |
96 | | |
97 | 330 | pmap->issuerDomainPolicy = OBJ_txt2obj(val->name, 0); |
98 | 330 | pmap->subjectDomainPolicy = OBJ_txt2obj(val->value, 0); |
99 | 330 | if (!pmap->issuerDomainPolicy || !pmap->subjectDomainPolicy) { |
100 | 47 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER); |
101 | 47 | X509V3_conf_err(val); |
102 | 47 | goto err; |
103 | 47 | } |
104 | 330 | } |
105 | 15 | return pmaps; |
106 | | |
107 | 63 | err: |
108 | 63 | sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free); |
109 | 63 | return nullptr; |
110 | 78 | } |