OpenCoverage

pcy_cache.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/x509v3/pcy_cache.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: pcy_cache.c,v 1.5 2014/07/11 08:44:49 jsing Exp $ */-
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL-
3 * project 2004.-
4 */-
5/* ====================================================================-
6 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.-
7 *-
8 * Redistribution and use in source and binary forms, with or without-
9 * modification, are permitted provided that the following conditions-
10 * are met:-
11 *-
12 * 1. Redistributions of source code must retain the above copyright-
13 * notice, this list of conditions and the following disclaimer.-
14 *-
15 * 2. Redistributions in binary form must reproduce the above copyright-
16 * notice, this list of conditions and the following disclaimer in-
17 * the documentation and/or other materials provided with the-
18 * distribution.-
19 *-
20 * 3. All advertising materials mentioning features or use of this-
21 * software must display the following acknowledgment:-
22 * "This product includes software developed by the OpenSSL Project-
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"-
24 *-
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to-
26 * endorse or promote products derived from this software without-
27 * prior written permission. For written permission, please contact-
28 * licensing@OpenSSL.org.-
29 *-
30 * 5. Products derived from this software may not be called "OpenSSL"-
31 * nor may "OpenSSL" appear in their names without prior written-
32 * permission of the OpenSSL Project.-
33 *-
34 * 6. Redistributions of any form whatsoever must retain the following-
35 * acknowledgment:-
36 * "This product includes software developed by the OpenSSL Project-
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"-
38 *-
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY-
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE-
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR-
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR-
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT-
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;-
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,-
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)-
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED-
50 * OF THE POSSIBILITY OF SUCH DAMAGE.-
51 * ====================================================================-
52 *-
53 * This product includes cryptographic software written by Eric Young-
54 * (eay@cryptsoft.com). This product includes software written by Tim-
55 * Hudson (tjh@cryptsoft.com).-
56 *-
57 */-
58-
59#include <openssl/x509.h>-
60#include <openssl/x509v3.h>-
61-
62#include "pcy_int.h"-
63-
64static int policy_data_cmp(const X509_POLICY_DATA * const *a,-
65 const X509_POLICY_DATA * const *b);-
66static int policy_cache_set_int(long *out, ASN1_INTEGER *value);-
67-
68/* Set cache entry according to CertificatePolicies extension.-
69 * Note: this destroys the passed CERTIFICATEPOLICIES structure.-
70 */-
71-
72static int-
73policy_cache_create(X509 *x, CERTIFICATEPOLICIES *policies, int crit)-
74{-
75 int i;-
76 int ret = 0;-
77 X509_POLICY_CACHE *cache = x->policy_cache;-
78 X509_POLICY_DATA *data = NULL;-
79 POLICYINFO *policy;-
80-
81 if (sk_POLICYINFO_num(policies) == 0)
sk_num(((_STAC...NFO*)0))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
82 goto bad_policy;
never executed: goto bad_policy;
0
83 cache->data = sk_X509_POLICY_DATA_new(policy_data_cmp);-
84 if (!cache->data)
!cache->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
85 goto bad_policy;
never executed: goto bad_policy;
0
86 for (i = 0; i < sk_POLICYINFO_num(policies); i++) {
i < sk_num(((_...LICYINFO*)0)))Description
TRUEnever evaluated
FALSEnever evaluated
0
87 policy = sk_POLICYINFO_value(policies, i);-
88 data = policy_data_new(policy, NULL, crit);-
89 if (!data)
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
90 goto bad_policy;
never executed: goto bad_policy;
0
91 /* Duplicate policy OIDs are illegal: reject if matches-
92 * found.-
93 */-
94 if (OBJ_obj2nid(data->valid_policy) == NID_any_policy) {
OBJ_obj2nid(da...policy) == 746Description
TRUEnever evaluated
FALSEnever evaluated
0
95 if (cache->anyPolicy) {
cache->anyPolicyDescription
TRUEnever evaluated
FALSEnever evaluated
0
96 ret = -1;-
97 goto bad_policy;
never executed: goto bad_policy;
0
98 }-
99 cache->anyPolicy = data;-
100 } else if (sk_X509_POLICY_DATA_find(cache->data, data) != -1) {
never executed: end of block
sk_find(((_STA...TA*)0))) != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
101 ret = -1;-
102 goto bad_policy;
never executed: goto bad_policy;
0
103 } else if (!sk_X509_POLICY_DATA_push(cache->data, data))
!sk_push(((_ST...ICY_DATA*)0)))Description
TRUEnever evaluated
FALSEnever evaluated
0
104 goto bad_policy;
never executed: goto bad_policy;
0
105 data = NULL;-
106 }
never executed: end of block
0
107 ret = 1;-
108-
109bad_policy:
code before this statement never executed: bad_policy:
0
110 if (ret == -1)
ret == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
111 x->ex_flags |= EXFLAG_INVALID_POLICY;
never executed: x->ex_flags |= 0x0800;
0
112 if (data)
dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 policy_data_free(data);
never executed: policy_data_free(data);
0
114 sk_POLICYINFO_pop_free(policies, POLICYINFO_free);-
115 if (ret <= 0) {
ret <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
116 sk_X509_POLICY_DATA_pop_free(cache->data, policy_data_free);-
117 cache->data = NULL;-
118 }
never executed: end of block
0
119 return ret;
never executed: return ret;
0
120}-
121-
122static int-
123policy_cache_new(X509 *x)-
124{-
125 X509_POLICY_CACHE *cache;-
126 ASN1_INTEGER *ext_any = NULL;-
127 POLICY_CONSTRAINTS *ext_pcons = NULL;-
128 CERTIFICATEPOLICIES *ext_cpols = NULL;-
129 POLICY_MAPPINGS *ext_pmaps = NULL;-
130 int i;-
131-
132 cache = malloc(sizeof(X509_POLICY_CACHE));-
133 if (!cache)
!cacheDescription
TRUEnever evaluated
FALSEnever evaluated
0
134 return 0;
never executed: return 0;
0
135 cache->anyPolicy = NULL;-
136 cache->data = NULL;-
137 cache->any_skip = -1;-
138 cache->explicit_skip = -1;-
139 cache->map_skip = -1;-
140-
141 x->policy_cache = cache;-
142-
143 /* Handle requireExplicitPolicy *first*. Need to process this-
144 * even if we don't have any policies.-
145 */-
146 ext_pcons = X509_get_ext_d2i(x, NID_policy_constraints, &i, NULL);-
147-
148 if (!ext_pcons) {
!ext_pconsDescription
TRUEnever evaluated
FALSEnever evaluated
0
149 if (i != -1)
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
150 goto bad_cache;
never executed: goto bad_cache;
0
151 } else {
never executed: end of block
0
152 if (!ext_pcons->requireExplicitPolicy &&
!ext_pcons->re...ExplicitPolicyDescription
TRUEnever evaluated
FALSEnever evaluated
0
153 !ext_pcons->inhibitPolicyMapping)
!ext_pcons->in...tPolicyMappingDescription
TRUEnever evaluated
FALSEnever evaluated
0
154 goto bad_cache;
never executed: goto bad_cache;
0
155 if (!policy_cache_set_int(&cache->explicit_skip,
!policy_cache_...xplicitPolicy)Description
TRUEnever evaluated
FALSEnever evaluated
0
156 ext_pcons->requireExplicitPolicy))
!policy_cache_...xplicitPolicy)Description
TRUEnever evaluated
FALSEnever evaluated
0
157 goto bad_cache;
never executed: goto bad_cache;
0
158 if (!policy_cache_set_int(&cache->map_skip,
!policy_cache_...PolicyMapping)Description
TRUEnever evaluated
FALSEnever evaluated
0
159 ext_pcons->inhibitPolicyMapping))
!policy_cache_...PolicyMapping)Description
TRUEnever evaluated
FALSEnever evaluated
0
160 goto bad_cache;
never executed: goto bad_cache;
0
161 }
never executed: end of block
0
162-
163 /* Process CertificatePolicies */-
164-
165 ext_cpols = X509_get_ext_d2i(x, NID_certificate_policies, &i, NULL);-
166 /* If no CertificatePolicies extension or problem decoding then-
167 * there is no point continuing because the valid policies will be-
168 * NULL.-
169 */-
170 if (!ext_cpols) {
!ext_cpolsDescription
TRUEnever evaluated
FALSEnever evaluated
0
171 /* If not absent some problem with extension */-
172 if (i != -1)
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
173 goto bad_cache;
never executed: goto bad_cache;
0
174 return 1;
never executed: return 1;
0
175 }-
176-
177 i = policy_cache_create(x, ext_cpols, i);-
178-
179 /* NB: ext_cpols freed by policy_cache_set_policies */-
180-
181 if (i <= 0)
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
182 return i;
never executed: return i;
0
183-
184 ext_pmaps = X509_get_ext_d2i(x, NID_policy_mappings, &i, NULL);-
185-
186 if (!ext_pmaps) {
!ext_pmapsDescription
TRUEnever evaluated
FALSEnever evaluated
0
187 /* If not absent some problem with extension */-
188 if (i != -1)
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
189 goto bad_cache;
never executed: goto bad_cache;
0
190 } else {
never executed: end of block
0
191 i = policy_cache_set_mapping(x, ext_pmaps);-
192 if (i <= 0)
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
193 goto bad_cache;
never executed: goto bad_cache;
0
194 }
never executed: end of block
0
195-
196 ext_any = X509_get_ext_d2i(x, NID_inhibit_any_policy, &i, NULL);-
197-
198 if (!ext_any) {
!ext_anyDescription
TRUEnever evaluated
FALSEnever evaluated
0
199 if (i != -1)
i != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
200 goto bad_cache;
never executed: goto bad_cache;
0
201 } else if (!policy_cache_set_int(&cache->any_skip, ext_any))
never executed: end of block
!policy_cache_...skip, ext_any)Description
TRUEnever evaluated
FALSEnever evaluated
0
202 goto bad_cache;
never executed: goto bad_cache;
0
203-
204 if (0) {-
205bad_cache:-
206 x->ex_flags |= EXFLAG_INVALID_POLICY;-
207 }
never executed: end of block
0
208-
209 if (ext_pcons)
ext_pconsDescription
TRUEnever evaluated
FALSEnever evaluated
0
210 POLICY_CONSTRAINTS_free(ext_pcons);
never executed: POLICY_CONSTRAINTS_free(ext_pcons);
0
211-
212 if (ext_any)
ext_anyDescription
TRUEnever evaluated
FALSEnever evaluated
0
213 ASN1_INTEGER_free(ext_any);
never executed: ASN1_INTEGER_free(ext_any);
0
214-
215 return 1;
never executed: return 1;
0
216}-
217-
218void-
219policy_cache_free(X509_POLICY_CACHE *cache)-
220{-
221 if (!cache)
!cacheDescription
TRUEevaluated 244 times by 7 tests
Evaluated by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • servertest
  • ssltest
  • tlstest
  • verifytest
FALSEnever evaluated
0-244
222 return;
executed 244 times by 7 tests: return;
Executed by:
  • asn1test
  • keypairtest
  • libcrypto.so.44.0.1
  • servertest
  • ssltest
  • tlstest
  • verifytest
244
223 if (cache->anyPolicy)
cache->anyPolicyDescription
TRUEnever evaluated
FALSEnever evaluated
0
224 policy_data_free(cache->anyPolicy);
never executed: policy_data_free(cache->anyPolicy);
0
225 if (cache->data)
cache->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
226 sk_X509_POLICY_DATA_pop_free(cache->data, policy_data_free);
never executed: sk_pop_free(((_STACK*) (1 ? (cache->data) : (struct stack_st_X509_POLICY_DATA*)0)), ((void (*)(void *)) ((1 ? (policy_data_free) : (void (*)(X509_POLICY_DATA *))0))));
0
227 free(cache);-
228}
never executed: end of block
0
229-
230const X509_POLICY_CACHE *-
231policy_cache_set(X509 *x)-
232{-
233 if (x->policy_cache == NULL) {
x->policy_cache == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
234 CRYPTO_w_lock(CRYPTO_LOCK_X509);-
235 policy_cache_new(x);-
236 CRYPTO_w_unlock(CRYPTO_LOCK_X509);-
237 }
never executed: end of block
0
238-
239 return x->policy_cache;
never executed: return x->policy_cache;
0
240}-
241-
242X509_POLICY_DATA *-
243policy_cache_find_data(const X509_POLICY_CACHE *cache, const ASN1_OBJECT *id)-
244{-
245 int idx;-
246 X509_POLICY_DATA tmp;-
247-
248 tmp.valid_policy = (ASN1_OBJECT *)id;-
249 idx = sk_X509_POLICY_DATA_find(cache->data, &tmp);-
250 if (idx == -1)
idx == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
251 return NULL;
never executed: return ((void *)0) ;
0
252 return sk_X509_POLICY_DATA_value(cache->data, idx);
never executed: return ((X509_POLICY_DATA *)sk_value(((_STACK*) (1 ? (cache->data) : (struct stack_st_X509_POLICY_DATA*)0)), (idx)));
0
253}-
254-
255static int-
256policy_data_cmp(const X509_POLICY_DATA * const *a,-
257 const X509_POLICY_DATA * const *b)-
258{-
259 return OBJ_cmp((*a)->valid_policy, (*b)->valid_policy);
never executed: return OBJ_cmp((*a)->valid_policy, (*b)->valid_policy);
0
260}-
261-
262static int-
263policy_cache_set_int(long *out, ASN1_INTEGER *value)-
264{-
265 if (value == NULL)
value == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
266 return 1;
never executed: return 1;
0
267 if (value->type == V_ASN1_NEG_INTEGER)
value->type == (2 | 0x100)Description
TRUEnever evaluated
FALSEnever evaluated
0
268 return 0;
never executed: return 0;
0
269 *out = ASN1_INTEGER_get(value);-
270 return 1;
never executed: return 1;
0
271}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2