OpenCoverage

v3_asid.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509v3/v3_asid.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2006-2018 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/*-
11 * Implementation of RFC 3779 section 3.2.-
12 */-
13-
14#include <assert.h>-
15#include <stdio.h>-
16#include <string.h>-
17#include "internal/cryptlib.h"-
18#include <openssl/conf.h>-
19#include <openssl/asn1.h>-
20#include <openssl/asn1t.h>-
21#include <openssl/x509v3.h>-
22#include <openssl/x509.h>-
23#include "internal/x509_int.h"-
24#include <openssl/bn.h>-
25#include "ext_dat.h"-
26-
27#ifndef OPENSSL_NO_RFC3779-
28-
29/*-
30 * OpenSSL ASN.1 template translation of RFC 3779 3.2.3.-
31 */-
32-
33ASN1_SEQUENCE(ASRange) = {-
34 ASN1_SIMPLE(ASRange, min, ASN1_INTEGER),-
35 ASN1_SIMPLE(ASRange, max, ASN1_INTEGER)-
36} ASN1_SEQUENCE_END(ASRange)-
37-
38ASN1_CHOICE(ASIdOrRange) = {-
39 ASN1_SIMPLE(ASIdOrRange, u.id, ASN1_INTEGER),-
40 ASN1_SIMPLE(ASIdOrRange, u.range, ASRange)-
41} ASN1_CHOICE_END(ASIdOrRange)-
42-
43ASN1_CHOICE(ASIdentifierChoice) = {-
44 ASN1_SIMPLE(ASIdentifierChoice, u.inherit, ASN1_NULL),-
45 ASN1_SEQUENCE_OF(ASIdentifierChoice, u.asIdsOrRanges, ASIdOrRange)-
46} ASN1_CHOICE_END(ASIdentifierChoice)-
47-
48ASN1_SEQUENCE(ASIdentifiers) = {-
49 ASN1_EXP_OPT(ASIdentifiers, asnum, ASIdentifierChoice, 0),-
50 ASN1_EXP_OPT(ASIdentifiers, rdi, ASIdentifierChoice, 1)-
51} ASN1_SEQUENCE_END(ASIdentifiers)-
52-
53IMPLEMENT_ASN1_FUNCTIONS(ASRange)
never executed: end of block
never executed: return (ASRange *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ASRange_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ASRange_it)));
never executed: return (ASRange *)ASN1_item_new((&(ASRange_it)));
0
54IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange)
never executed: end of block
never executed: return (ASIdOrRange *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ASIdOrRange_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ASIdOrRange_it)));
never executed: return (ASIdOrRange *)ASN1_item_new((&(ASIdOrRange_it)));
0
55IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice)
never executed: end of block
never executed: return (ASIdentifierChoice *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ASIdentifierChoice_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ASIdentifierChoice_it)));
never executed: return (ASIdentifierChoice *)ASN1_item_new((&(ASIdentifierChoice_it)));
0
56IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers)
executed 39780 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
never executed: return (ASIdentifiers *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ASIdentifiers_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ASIdentifiers_it)));
never executed: return (ASIdentifiers *)ASN1_item_new((&(ASIdentifiers_it)));
0-39780
57-
58/*-
59 * i2r method for an ASIdentifierChoice.-
60 */-
61static int i2r_ASIdentifierChoice(BIO *out,-
62 ASIdentifierChoice *choice,-
63 int indent, const char *msg)-
64{-
65 int i;-
66 char *s;-
67 if (choice == NULL)
choice == ((void *)0)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-10
68 return 1;
executed 10 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
10
69 BIO_printf(out, "%*s%s:\n", indent, "", msg);-
70 switch (choice->type) {-
71 case ASIdentifierChoice_inherit:
never executed: case 0:
0
72 BIO_printf(out, "%*sinherit\n", indent + 2, "");-
73 break;
never executed: break;
0
74 case ASIdentifierChoice_asIdsOrRanges:
never executed: case 1:
0
75 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges); i++) {
i < sk_ASIdOrR...asIdsOrRanges)Description
TRUEnever evaluated
FALSEnever evaluated
0
76 ASIdOrRange *aor =-
77 sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);-
78 switch (aor->type) {-
79 case ASIdOrRange_id:
never executed: case 0:
0
80 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL)
(s = i2s_ASN1_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
81 return 0;
never executed: return 0;
0
82 BIO_printf(out, "%*s%s\n", indent + 2, "", s);-
83 OPENSSL_free(s);-
84 break;
never executed: break;
0
85 case ASIdOrRange_range:
never executed: case 1:
0
86 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL)
(s = i2s_ASN1_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
87 return 0;
never executed: return 0;
0
88 BIO_printf(out, "%*s%s-", indent + 2, "", s);-
89 OPENSSL_free(s);-
90 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL)
(s = i2s_ASN1_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
91 return 0;
never executed: return 0;
0
92 BIO_printf(out, "%s\n", s);-
93 OPENSSL_free(s);-
94 break;
never executed: break;
0
95 default:
never executed: default:
0
96 return 0;
never executed: return 0;
0
97 }-
98 }-
99 break;
never executed: break;
0
100 default:
never executed: default:
0
101 return 0;
never executed: return 0;
0
102 }-
103 return 1;
never executed: return 1;
0
104}-
105-
106/*-
107 * i2r method for an ASIdentifier extension.-
108 */-
109static int i2r_ASIdentifiers(const X509V3_EXT_METHOD *method,-
110 void *ext, BIO *out, int indent)-
111{-
112 ASIdentifiers *asid = ext;-
113 return (i2r_ASIdentifierChoice(out, asid->asnum, indent,
executed 5 times by 1 test: return (i2r_ASIdentifierChoice(out, asid->asnum, indent, "Autonomous System Numbers") && i2r_ASIdentifierChoice(out, asid->rdi, indent, "Routing Domain Identifiers"));
Executed by:
  • libcrypto.so.1.1
i2r_ASIdentifi...stem Numbers")Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-5
114 "Autonomous System Numbers") &&
executed 5 times by 1 test: return (i2r_ASIdentifierChoice(out, asid->asnum, indent, "Autonomous System Numbers") && i2r_ASIdentifierChoice(out, asid->rdi, indent, "Routing Domain Identifiers"));
Executed by:
  • libcrypto.so.1.1
i2r_ASIdentifi...stem Numbers")Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-5
115 i2r_ASIdentifierChoice(out, asid->rdi, indent,
executed 5 times by 1 test: return (i2r_ASIdentifierChoice(out, asid->asnum, indent, "Autonomous System Numbers") && i2r_ASIdentifierChoice(out, asid->rdi, indent, "Routing Domain Identifiers"));
Executed by:
  • libcrypto.so.1.1
i2r_ASIdentifi... Identifiers")Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-5
116 "Routing Domain Identifiers"));
executed 5 times by 1 test: return (i2r_ASIdentifierChoice(out, asid->asnum, indent, "Autonomous System Numbers") && i2r_ASIdentifierChoice(out, asid->rdi, indent, "Routing Domain Identifiers"));
Executed by:
  • libcrypto.so.1.1
i2r_ASIdentifi... Identifiers")Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-5
117}-
118-
119/*-
120 * Sort comparison function for a sequence of ASIdOrRange elements.-
121 */-
122static int ASIdOrRange_cmp(const ASIdOrRange *const *a_,-
123 const ASIdOrRange *const *b_)-
124{-
125 const ASIdOrRange *a = *a_, *b = *b_;-
126-
127 assert((a->type == ASIdOrRange_id && a->u.id != NULL) ||-
128 (a->type == ASIdOrRange_range && a->u.range != NULL &&-
129 a->u.range->min != NULL && a->u.range->max != NULL));-
130-
131 assert((b->type == ASIdOrRange_id && b->u.id != NULL) ||-
132 (b->type == ASIdOrRange_range && b->u.range != NULL &&-
133 b->u.range->min != NULL && b->u.range->max != NULL));-
134-
135 if (a->type == ASIdOrRange_id && b->type == ASIdOrRange_id)
a->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
b->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
136 return ASN1_INTEGER_cmp(a->u.id, b->u.id);
never executed: return ASN1_INTEGER_cmp(a->u.id, b->u.id);
0
137-
138 if (a->type == ASIdOrRange_range && b->type == ASIdOrRange_range) {
a->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
b->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
139 int r = ASN1_INTEGER_cmp(a->u.range->min, b->u.range->min);-
140 return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max,
never executed: return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max, b->u.range->max);
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
141 b->u.range->max);
never executed: return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max, b->u.range->max);
0
142 }-
143-
144 if (a->type == ASIdOrRange_id)
a->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
145 return ASN1_INTEGER_cmp(a->u.id, b->u.range->min);
never executed: return ASN1_INTEGER_cmp(a->u.id, b->u.range->min);
0
146 else-
147 return ASN1_INTEGER_cmp(a->u.range->min, b->u.id);
never executed: return ASN1_INTEGER_cmp(a->u.range->min, b->u.id);
0
148}-
149-
150/*-
151 * Add an inherit element.-
152 */-
153int X509v3_asid_add_inherit(ASIdentifiers *asid, int which)-
154{-
155 ASIdentifierChoice **choice;-
156 if (asid == NULL)
asid == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
157 return 0;
never executed: return 0;
0
158 switch (which) {-
159 case V3_ASID_ASNUM:
never executed: case 0:
0
160 choice = &asid->asnum;-
161 break;
never executed: break;
0
162 case V3_ASID_RDI:
never executed: case 1:
0
163 choice = &asid->rdi;-
164 break;
never executed: break;
0
165 default:
never executed: default:
0
166 return 0;
never executed: return 0;
0
167 }-
168 if (*choice == NULL) {
*choice == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
169 if ((*choice = ASIdentifierChoice_new()) == NULL)
(*choice = ASI...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
170 return 0;
never executed: return 0;
0
171 if (((*choice)->u.inherit = ASN1_NULL_new()) == NULL)
((*choice)->u....== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
172 return 0;
never executed: return 0;
0
173 (*choice)->type = ASIdentifierChoice_inherit;-
174 }
never executed: end of block
0
175 return (*choice)->type == ASIdentifierChoice_inherit;
never executed: return (*choice)->type == 0;
0
176}-
177-
178/*-
179 * Add an ID or range to an ASIdentifierChoice.-
180 */-
181int X509v3_asid_add_id_or_range(ASIdentifiers *asid,-
182 int which, ASN1_INTEGER *min, ASN1_INTEGER *max)-
183{-
184 ASIdentifierChoice **choice;-
185 ASIdOrRange *aor;-
186 if (asid == NULL)
asid == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
187 return 0;
never executed: return 0;
0
188 switch (which) {-
189 case V3_ASID_ASNUM:
never executed: case 0:
0
190 choice = &asid->asnum;-
191 break;
never executed: break;
0
192 case V3_ASID_RDI:
never executed: case 1:
0
193 choice = &asid->rdi;-
194 break;
never executed: break;
0
195 default:
never executed: default:
0
196 return 0;
never executed: return 0;
0
197 }-
198 if (*choice != NULL && (*choice)->type == ASIdentifierChoice_inherit)
*choice != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
(*choice)->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
199 return 0;
never executed: return 0;
0
200 if (*choice == NULL) {
*choice == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
201 if ((*choice = ASIdentifierChoice_new()) == NULL)
(*choice = ASI...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
202 return 0;
never executed: return 0;
0
203 (*choice)->u.asIdsOrRanges = sk_ASIdOrRange_new(ASIdOrRange_cmp);-
204 if ((*choice)->u.asIdsOrRanges == NULL)
(*choice)->u.a...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
205 return 0;
never executed: return 0;
0
206 (*choice)->type = ASIdentifierChoice_asIdsOrRanges;-
207 }
never executed: end of block
0
208 if ((aor = ASIdOrRange_new()) == NULL)
(aor = ASIdOrR...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
209 return 0;
never executed: return 0;
0
210 if (max == NULL) {
max == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
211 aor->type = ASIdOrRange_id;-
212 aor->u.id = min;-
213 } else {
never executed: end of block
0
214 aor->type = ASIdOrRange_range;-
215 if ((aor->u.range = ASRange_new()) == NULL)
(aor->u.range ...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
216 goto err;
never executed: goto err;
0
217 ASN1_INTEGER_free(aor->u.range->min);-
218 aor->u.range->min = min;-
219 ASN1_INTEGER_free(aor->u.range->max);-
220 aor->u.range->max = max;-
221 }
never executed: end of block
0
222 if (!(sk_ASIdOrRange_push((*choice)->u.asIdsOrRanges, aor)))
!(sk_ASIdOrRan...rRanges, aor))Description
TRUEnever evaluated
FALSEnever evaluated
0
223 goto err;
never executed: goto err;
0
224 return 1;
never executed: return 1;
0
225-
226 err:-
227 ASIdOrRange_free(aor);-
228 return 0;
never executed: return 0;
0
229}-
230-
231/*-
232 * Extract min and max values from an ASIdOrRange.-
233 */-
234static int extract_min_max(ASIdOrRange *aor,-
235 ASN1_INTEGER **min, ASN1_INTEGER **max)-
236{-
237 if (!ossl_assert(aor != NULL))
!((aor != ((void *)0) ) != 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
238 return 0;
never executed: return 0;
0
239 switch (aor->type) {-
240 case ASIdOrRange_id:
never executed: case 0:
0
241 *min = aor->u.id;-
242 *max = aor->u.id;-
243 return 1;
never executed: return 1;
0
244 case ASIdOrRange_range:
never executed: case 1:
0
245 *min = aor->u.range->min;-
246 *max = aor->u.range->max;-
247 return 1;
never executed: return 1;
0
248 }-
249-
250 return 0;
never executed: return 0;
0
251}-
252-
253/*-
254 * Check whether an ASIdentifierChoice is in canonical form.-
255 */-
256static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice)-
257{-
258 ASN1_INTEGER *a_max_plus_one = NULL;-
259 BIGNUM *bn = NULL;-
260 int i, ret = 0;-
261-
262 /*-
263 * Empty element or inheritance is canonical.-
264 */-
265 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
choice == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
choice->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
266 return 1;
never executed: return 1;
0
267-
268 /*-
269 * If not a list, or if empty list, it's broken.-
270 */-
271 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
choice->type != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
272 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0)
sk_ASIdOrRange...OrRanges) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
273 return 0;
never executed: return 0;
0
274-
275 /*-
276 * It's a list, check it.-
277 */-
278 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
i < sk_ASIdOrR...sOrRanges) - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
279 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);-
280 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);-
281 ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =-
282 NULL;-
283-
284 if (!extract_min_max(a, &a_min, &a_max)
!extract_min_m...a_min, &a_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
285 || !extract_min_max(b, &b_min, &b_max))
!extract_min_m...b_min, &b_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
286 goto done;
never executed: goto done;
0
287-
288 /*-
289 * Punt misordered list, overlapping start, or inverted range.-
290 */-
291 if (ASN1_INTEGER_cmp(a_min, b_min) >= 0 ||
ASN1_INTEGER_c...n, b_min) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
292 ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
ASN1_INTEGER_c...in, a_max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
293 ASN1_INTEGER_cmp(b_min, b_max) > 0)
ASN1_INTEGER_c...in, b_max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
294 goto done;
never executed: goto done;
0
295-
296 /*-
297 * Calculate a_max + 1 to check for adjacency.-
298 */-
299 if ((bn == NULL && (bn = BN_new()) == NULL) ||
bn == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
(bn = BN_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
300 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
ASN1_INTEGER_t...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
301 !BN_add_word(bn, 1) ||
!BN_add_word(bn, 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
302 (a_max_plus_one =
(a_max_plus_on...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
303 BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
(a_max_plus_on...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
304 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL,-
305 ERR_R_MALLOC_FAILURE);-
306 goto done;
never executed: goto done;
0
307 }-
308-
309 /*-
310 * Punt if adjacent or overlapping.-
311 */-
312 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) >= 0)
ASN1_INTEGER_c...e, b_min) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
313 goto done;
never executed: goto done;
0
314 }
never executed: end of block
0
315-
316 /*-
317 * Check for inverted range.-
318 */-
319 i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;-
320 {-
321 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);-
322 ASN1_INTEGER *a_min, *a_max;-
323 if (a != NULL && a->type == ASIdOrRange_range) {
a != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
a->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
324 if (!extract_min_max(a, &a_min, &a_max)
!extract_min_m...a_min, &a_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
325 || ASN1_INTEGER_cmp(a_min, a_max) > 0)
ASN1_INTEGER_c...in, a_max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
326 goto done;
never executed: goto done;
0
327 }
never executed: end of block
0
328 }-
329-
330 ret = 1;-
331-
332 done:
code before this statement never executed: done:
0
333 ASN1_INTEGER_free(a_max_plus_one);-
334 BN_free(bn);-
335 return ret;
never executed: return ret;
0
336}-
337-
338/*-
339 * Check whether an ASIdentifier extension is in canonical form.-
340 */-
341int X509v3_asid_is_canonical(ASIdentifiers *asid)-
342{-
343 return (asid == NULL ||
never executed: return (asid == ((void *)0) || (ASIdentifierChoice_is_canonical(asid->asnum) && ASIdentifierChoice_is_canonical(asid->rdi)));
asid == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
344 (ASIdentifierChoice_is_canonical(asid->asnum) &&
never executed: return (asid == ((void *)0) || (ASIdentifierChoice_is_canonical(asid->asnum) && ASIdentifierChoice_is_canonical(asid->rdi)));
ASIdentifierCh...l(asid->asnum)Description
TRUEnever evaluated
FALSEnever evaluated
0
345 ASIdentifierChoice_is_canonical(asid->rdi)));
never executed: return (asid == ((void *)0) || (ASIdentifierChoice_is_canonical(asid->asnum) && ASIdentifierChoice_is_canonical(asid->rdi)));
ASIdentifierCh...cal(asid->rdi)Description
TRUEnever evaluated
FALSEnever evaluated
0
346}-
347-
348/*-
349 * Whack an ASIdentifierChoice into canonical form.-
350 */-
351static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)-
352{-
353 ASN1_INTEGER *a_max_plus_one = NULL;-
354 BIGNUM *bn = NULL;-
355 int i, ret = 0;-
356-
357 /*-
358 * Nothing to do for empty element or inheritance.-
359 */-
360 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
choice == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
choice->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
361 return 1;
never executed: return 1;
0
362-
363 /*-
364 * If not a list, or if empty list, it's broken.-
365 */-
366 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
choice->type != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
367 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
sk_ASIdOrRange...OrRanges) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
368 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,-
369 X509V3_R_EXTENSION_VALUE_ERROR);-
370 return 0;
never executed: return 0;
0
371 }-
372-
373 /*-
374 * We have a non-empty list. Sort it.-
375 */-
376 sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);-
377-
378 /*-
379 * Now check for errors and suboptimal encoding, rejecting the-
380 * former and fixing the latter.-
381 */-
382 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
i < sk_ASIdOrR...sOrRanges) - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
383 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);-
384 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);-
385 ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =-
386 NULL;-
387-
388 if (!extract_min_max(a, &a_min, &a_max)
!extract_min_m...a_min, &a_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
389 || !extract_min_max(b, &b_min, &b_max))
!extract_min_m...b_min, &b_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
390 goto done;
never executed: goto done;
0
391-
392 /*-
393 * Make sure we're properly sorted (paranoia).-
394 */-
395 if (!ossl_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0))
!((ASN1_INTEGE...n) <= 0) != 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
396 goto done;
never executed: goto done;
0
397-
398 /*-
399 * Punt inverted ranges.-
400 */-
401 if (ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
ASN1_INTEGER_c...in, a_max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
402 ASN1_INTEGER_cmp(b_min, b_max) > 0)
ASN1_INTEGER_c...in, b_max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
403 goto done;
never executed: goto done;
0
404-
405 /*-
406 * Check for overlaps.-
407 */-
408 if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) {
ASN1_INTEGER_c...x, b_min) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
409 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,-
410 X509V3_R_EXTENSION_VALUE_ERROR);-
411 goto done;
never executed: goto done;
0
412 }-
413-
414 /*-
415 * Calculate a_max + 1 to check for adjacency.-
416 */-
417 if ((bn == NULL && (bn = BN_new()) == NULL) ||
bn == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
(bn = BN_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
418 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
ASN1_INTEGER_t...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
419 !BN_add_word(bn, 1) ||
!BN_add_word(bn, 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
420 (a_max_plus_one =
(a_max_plus_on...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
421 BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
(a_max_plus_on...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
422 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,-
423 ERR_R_MALLOC_FAILURE);-
424 goto done;
never executed: goto done;
0
425 }-
426-
427 /*-
428 * If a and b are adjacent, merge them.-
429 */-
430 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) {
ASN1_INTEGER_c...e, b_min) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
431 ASRange *r;-
432 switch (a->type) {-
433 case ASIdOrRange_id:
never executed: case 0:
0
434 if ((r = OPENSSL_malloc(sizeof(*r))) == NULL) {
(r = CRYPTO_ma...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
435 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,-
436 ERR_R_MALLOC_FAILURE);-
437 goto done;
never executed: goto done;
0
438 }-
439 r->min = a_min;-
440 r->max = b_max;-
441 a->type = ASIdOrRange_range;-
442 a->u.range = r;-
443 break;
never executed: break;
0
444 case ASIdOrRange_range:
never executed: case 1:
0
445 ASN1_INTEGER_free(a->u.range->max);-
446 a->u.range->max = b_max;-
447 break;
never executed: break;
0
448 }-
449 switch (b->type) {-
450 case ASIdOrRange_id:
never executed: case 0:
0
451 b->u.id = NULL;-
452 break;
never executed: break;
0
453 case ASIdOrRange_range:
never executed: case 1:
0
454 b->u.range->max = NULL;-
455 break;
never executed: break;
0
456 }-
457 ASIdOrRange_free(b);-
458 (void)sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);-
459 i--;-
460 continue;
never executed: continue;
0
461 }-
462 }
never executed: end of block
0
463-
464 /*-
465 * Check for final inverted range.-
466 */-
467 i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;-
468 {-
469 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);-
470 ASN1_INTEGER *a_min, *a_max;-
471 if (a != NULL && a->type == ASIdOrRange_range) {
a != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
a->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
472 if (!extract_min_max(a, &a_min, &a_max)
!extract_min_m...a_min, &a_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
473 || ASN1_INTEGER_cmp(a_min, a_max) > 0)
ASN1_INTEGER_c...in, a_max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
474 goto done;
never executed: goto done;
0
475 }
never executed: end of block
0
476 }-
477-
478 /* Paranoia */-
479 if (!ossl_assert(ASIdentifierChoice_is_canonical(choice)))
!((ASIdentifie...choice)) != 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
480 goto done;
never executed: goto done;
0
481-
482 ret = 1;-
483-
484 done:
code before this statement never executed: done:
0
485 ASN1_INTEGER_free(a_max_plus_one);-
486 BN_free(bn);-
487 return ret;
never executed: return ret;
0
488}-
489-
490/*-
491 * Whack an ASIdentifier extension into canonical form.-
492 */-
493int X509v3_asid_canonize(ASIdentifiers *asid)-
494{-
495 return (asid == NULL ||
never executed: return (asid == ((void *)0) || (ASIdentifierChoice_canonize(asid->asnum) && ASIdentifierChoice_canonize(asid->rdi)));
asid == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
496 (ASIdentifierChoice_canonize(asid->asnum) &&
never executed: return (asid == ((void *)0) || (ASIdentifierChoice_canonize(asid->asnum) && ASIdentifierChoice_canonize(asid->rdi)));
ASIdentifierCh...e(asid->asnum)Description
TRUEnever evaluated
FALSEnever evaluated
0
497 ASIdentifierChoice_canonize(asid->rdi)));
never executed: return (asid == ((void *)0) || (ASIdentifierChoice_canonize(asid->asnum) && ASIdentifierChoice_canonize(asid->rdi)));
ASIdentifierCh...ize(asid->rdi)Description
TRUEnever evaluated
FALSEnever evaluated
0
498}-
499-
500/*-
501 * v2i method for an ASIdentifier extension.-
502 */-
503static void *v2i_ASIdentifiers(const struct v3_ext_method *method,-
504 struct v3_ext_ctx *ctx,-
505 STACK_OF(CONF_VALUE) *values)-
506{-
507 ASN1_INTEGER *min = NULL, *max = NULL;-
508 ASIdentifiers *asid = NULL;-
509 int i;-
510-
511 if ((asid = ASIdentifiers_new()) == NULL) {
(asid = ASIden...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
512 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);-
513 return NULL;
never executed: return ((void *)0) ;
0
514 }-
515-
516 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
i < sk_CONF_VALUE_num(values)Description
TRUEnever evaluated
FALSEnever evaluated
0
517 CONF_VALUE *val = sk_CONF_VALUE_value(values, i);-
518 int i1 = 0, i2 = 0, i3 = 0, is_range = 0, which = 0;-
519-
520 /*-
521 * Figure out whether this is an AS or an RDI.-
522 */-
523 if (!name_cmp(val->name, "AS")) {
!name_cmp(val->name, "AS")Description
TRUEnever evaluated
FALSEnever evaluated
0
524 which = V3_ASID_ASNUM;-
525 } else if (!name_cmp(val->name, "RDI")) {
never executed: end of block
!name_cmp(val->name, "RDI")Description
TRUEnever evaluated
FALSEnever evaluated
0
526 which = V3_ASID_RDI;-
527 } else {
never executed: end of block
0
528 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,-
529 X509V3_R_EXTENSION_NAME_ERROR);-
530 X509V3_conf_err(val);-
531 goto err;
never executed: goto err;
0
532 }-
533-
534 /*-
535 * Handle inheritance.-
536 */-
537 if (strcmp(val->value, "inherit") == 0) {
never executed: __result = (((const unsigned char *) (const char *) ( val->value ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "inherit" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
538 if (X509v3_asid_add_inherit(asid, which))
X509v3_asid_ad...t(asid, which)Description
TRUEnever evaluated
FALSEnever evaluated
0
539 continue;
never executed: continue;
0
540 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,-
541 X509V3_R_INVALID_INHERITANCE);-
542 X509V3_conf_err(val);-
543 goto err;
never executed: goto err;
0
544 }-
545-
546 /*-
547 * Number, range, or mistake, pick it apart and figure out which.-
548 */-
549 i1 = strspn(val->value, "0123456789");-
550 if (val->value[i1] == '\0') {
val->value[i1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
551 is_range = 0;-
552 } else {
never executed: end of block
0
553 is_range = 1;-
554 i2 = i1 + strspn(val->value + i1, " \t");-
555 if (val->value[i2] != '-') {
val->value[i2] != '-'Description
TRUEnever evaluated
FALSEnever evaluated
0
556 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,-
557 X509V3_R_INVALID_ASNUMBER);-
558 X509V3_conf_err(val);-
559 goto err;
never executed: goto err;
0
560 }-
561 i2++;-
562 i2 = i2 + strspn(val->value + i2, " \t");-
563 i3 = i2 + strspn(val->value + i2, "0123456789");-
564 if (val->value[i3] != '\0') {
val->value[i3] != '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
565 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,-
566 X509V3_R_INVALID_ASRANGE);-
567 X509V3_conf_err(val);-
568 goto err;
never executed: goto err;
0
569 }-
570 }
never executed: end of block
0
571-
572 /*-
573 * Syntax is ok, read and add it.-
574 */-
575 if (!is_range) {
!is_rangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
576 if (!X509V3_get_value_int(val, &min)) {
!X509V3_get_va...int(val, &min)Description
TRUEnever evaluated
FALSEnever evaluated
0
577 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);-
578 goto err;
never executed: goto err;
0
579 }-
580 } else {
never executed: end of block
0
581 char *s = OPENSSL_strdup(val->value);-
582 if (s == NULL) {
s == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
583 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);-
584 goto err;
never executed: goto err;
0
585 }-
586 s[i1] = '\0';-
587 min = s2i_ASN1_INTEGER(NULL, s);-
588 max = s2i_ASN1_INTEGER(NULL, s + i2);-
589 OPENSSL_free(s);-
590 if (min == NULL || max == NULL) {
min == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
max == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
591 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);-
592 goto err;
never executed: goto err;
0
593 }-
594 if (ASN1_INTEGER_cmp(min, max) > 0) {
ASN1_INTEGER_cmp(min, max) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
595 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,-
596 X509V3_R_EXTENSION_VALUE_ERROR);-
597 goto err;
never executed: goto err;
0
598 }-
599 }
never executed: end of block
0
600 if (!X509v3_asid_add_id_or_range(asid, which, min, max)) {
!X509v3_asid_a...ich, min, max)Description
TRUEnever evaluated
FALSEnever evaluated
0
601 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);-
602 goto err;
never executed: goto err;
0
603 }-
604 min = max = NULL;-
605 }
never executed: end of block
0
606-
607 /*-
608 * Canonize the result, then we're done.-
609 */-
610 if (!X509v3_asid_canonize(asid))
!X509v3_asid_canonize(asid)Description
TRUEnever evaluated
FALSEnever evaluated
0
611 goto err;
never executed: goto err;
0
612 return asid;
never executed: return asid;
0
613-
614 err:-
615 ASIdentifiers_free(asid);-
616 ASN1_INTEGER_free(min);-
617 ASN1_INTEGER_free(max);-
618 return NULL;
never executed: return ((void *)0) ;
0
619}-
620-
621/*-
622 * OpenSSL dispatch.-
623 */-
624const X509V3_EXT_METHOD v3_asid = {-
625 NID_sbgp_autonomousSysNum, /* nid */-
626 0, /* flags */-
627 ASN1_ITEM_ref(ASIdentifiers), /* template */-
628 0, 0, 0, 0, /* old functions, ignored */-
629 0, /* i2s */-
630 0, /* s2i */-
631 0, /* i2v */-
632 v2i_ASIdentifiers, /* v2i */-
633 i2r_ASIdentifiers, /* i2r */-
634 0, /* r2i */-
635 NULL /* extension-specific data */-
636};-
637-
638/*-
639 * Figure out whether extension uses inheritance.-
640 */-
641int X509v3_asid_inherits(ASIdentifiers *asid)-
642{-
643 return (asid != NULL &&
never executed: return (asid != ((void *)0) && ((asid->asnum != ((void *)0) && asid->asnum->type == 0) || (asid->rdi != ((void *)0) && asid->rdi->type == 0)));
asid != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
644 ((asid->asnum != NULL &&
never executed: return (asid != ((void *)0) && ((asid->asnum != ((void *)0) && asid->asnum->type == 0) || (asid->rdi != ((void *)0) && asid->rdi->type == 0)));
asid->asnum != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
645 asid->asnum->type == ASIdentifierChoice_inherit) ||
never executed: return (asid != ((void *)0) && ((asid->asnum != ((void *)0) && asid->asnum->type == 0) || (asid->rdi != ((void *)0) && asid->rdi->type == 0)));
asid->asnum->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
646 (asid->rdi != NULL &&
never executed: return (asid != ((void *)0) && ((asid->asnum != ((void *)0) && asid->asnum->type == 0) || (asid->rdi != ((void *)0) && asid->rdi->type == 0)));
asid->rdi != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
647 asid->rdi->type == ASIdentifierChoice_inherit)));
never executed: return (asid != ((void *)0) && ((asid->asnum != ((void *)0) && asid->asnum->type == 0) || (asid->rdi != ((void *)0) && asid->rdi->type == 0)));
asid->rdi->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
648}-
649-
650/*-
651 * Figure out whether parent contains child.-
652 */-
653static int asid_contains(ASIdOrRanges *parent, ASIdOrRanges *child)-
654{-
655 ASN1_INTEGER *p_min = NULL, *p_max = NULL, *c_min = NULL, *c_max = NULL;-
656 int p, c;-
657-
658 if (child == NULL || parent == child)
child == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
parent == childDescription
TRUEnever evaluated
FALSEnever evaluated
0
659 return 1;
never executed: return 1;
0
660 if (parent == NULL)
parent == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
661 return 0;
never executed: return 0;
0
662-
663 p = 0;-
664 for (c = 0; c < sk_ASIdOrRange_num(child); c++) {
c < sk_ASIdOrRange_num(child)Description
TRUEnever evaluated
FALSEnever evaluated
0
665 if (!extract_min_max(sk_ASIdOrRange_value(child, c), &c_min, &c_max))
!extract_min_m...c_min, &c_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
666 return 0;
never executed: return 0;
0
667 for (;; p++) {-
668 if (p >= sk_ASIdOrRange_num(parent))
p >= sk_ASIdOr...ge_num(parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
669 return 0;
never executed: return 0;
0
670 if (!extract_min_max(sk_ASIdOrRange_value(parent, p), &p_min,
!extract_min_m...p_min, &p_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
671 &p_max))
!extract_min_m...p_min, &p_max)Description
TRUEnever evaluated
FALSEnever evaluated
0
672 return 0;
never executed: return 0;
0
673 if (ASN1_INTEGER_cmp(p_max, c_max) < 0)
ASN1_INTEGER_c...ax, c_max) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
674 continue;
never executed: continue;
0
675 if (ASN1_INTEGER_cmp(p_min, c_min) > 0)
ASN1_INTEGER_c...in, c_min) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
676 return 0;
never executed: return 0;
0
677 break;
never executed: break;
0
678 }-
679 }
never executed: end of block
0
680-
681 return 1;
never executed: return 1;
0
682}-
683-
684/*-
685 * Test whether a is a subset of b.-
686 */-
687int X509v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b)-
688{-
689 return (a == NULL ||
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
a == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
690 a == b ||
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
a == bDescription
TRUEnever evaluated
FALSEnever evaluated
0
691 (b != NULL &&
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
b != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
692 !X509v3_asid_inherits(a) &&
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
!X509v3_asid_inherits(a)Description
TRUEnever evaluated
FALSEnever evaluated
0
693 !X509v3_asid_inherits(b) &&
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
!X509v3_asid_inherits(b)Description
TRUEnever evaluated
FALSEnever evaluated
0
694 asid_contains(b->asnum->u.asIdsOrRanges,
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
asid_contains(...asIdsOrRanges)Description
TRUEnever evaluated
FALSEnever evaluated
0
695 a->asnum->u.asIdsOrRanges) &&
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
asid_contains(...asIdsOrRanges)Description
TRUEnever evaluated
FALSEnever evaluated
0
696 asid_contains(b->rdi->u.asIdsOrRanges,
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
asid_contains(...asIdsOrRanges)Description
TRUEnever evaluated
FALSEnever evaluated
0
697 a->rdi->u.asIdsOrRanges)));
never executed: return (a == ((void *)0) || a == b || (b != ((void *)0) && !X509v3_asid_inherits(a) && !X509v3_asid_inherits(b) && asid_contains(b->asnum->u.asIdsOrRanges, a->asnum->u.asIdsOrRanges) && asid_contains(b->rdi->u.asIdsOrRanges, a->rdi->u.asIdsOrRanges)));
asid_contains(...asIdsOrRanges)Description
TRUEnever evaluated
FALSEnever evaluated
0
698}-
699-
700/*-
701 * Validation error handling via callback.-
702 */-
703#define validation_err(_err_) \-
704 do { \-
705 if (ctx != NULL) { \-
706 ctx->error = _err_; \-
707 ctx->error_depth = i; \-
708 ctx->current_cert = x; \-
709 ret = ctx->verify_cb(0, ctx); \-
710 } else { \-
711 ret = 0; \-
712 } \-
713 if (!ret) \-
714 goto done; \-
715 } while (0)-
716-
717/*-
718 * Core code for RFC 3779 3.3 path validation.-
719 */-
720static int asid_validate_path_internal(X509_STORE_CTX *ctx,-
721 STACK_OF(X509) *chain,-
722 ASIdentifiers *ext)-
723{-
724 ASIdOrRanges *child_as = NULL, *child_rdi = NULL;-
725 int i, ret = 1, inherit_as = 0, inherit_rdi = 0;-
726 X509 *x;-
727-
728 if (!ossl_assert(chain != NULL && sk_X509_num(chain) > 0)
!((chain != ((...in) > 0) != 0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
chain != ((void *)0)Description
TRUEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
sk_X509_num(chain) > 0Description
TRUEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1305
729 || !ossl_assert(ctx != NULL || ext != NULL)
!((ctx != ((vo...d *)0) ) != 0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ctx != ((void *)0)Description
TRUEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
ext != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0-1305
730 || !ossl_assert(ctx == NULL || ctx->verify_cb != NULL)) {
!((ctx == ((vo...d *)0) ) != 0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
ctx->verify_cb != ((void *)0)Description
TRUEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1305
731 if (ctx != NULL)
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
732 ctx->error = X509_V_ERR_UNSPECIFIED;
never executed: ctx->error = 1;
0
733 return 0;
never executed: return 0;
0
734 }-
735-
736-
737 /*-
738 * Figure out where to start. If we don't have an extension to-
739 * check, we're done. Otherwise, check canonical form and-
740 * set up for walking up the chain.-
741 */-
742 if (ext != NULL) {
ext != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1305
743 i = -1;-
744 x = NULL;-
745 } else {
never executed: end of block
0
746 i = 0;-
747 x = sk_X509_value(chain, i);-
748 if ((ext = x->rfc3779_asid) == NULL)
(ext = x->rfc3...== ((void *)0)Description
TRUEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1305
749 goto done;
executed 1305 times by 1 test: goto done;
Executed by:
  • libcrypto.so.1.1
1305
750 }
never executed: end of block
0
751 if (!X509v3_asid_is_canonical(ext))
!X509v3_asid_is_canonical(ext)Description
TRUEnever evaluated
FALSEnever evaluated
0
752 validation_err(X509_V_ERR_INVALID_EXTENSION);
never executed: end of block
never executed: end of block
never executed: goto done;
never executed: end of block
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
753 if (ext->asnum != NULL) {
ext->asnum != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
754 switch (ext->asnum->type) {-
755 case ASIdentifierChoice_inherit:
never executed: case 0:
0
756 inherit_as = 1;-
757 break;
never executed: break;
0
758 case ASIdentifierChoice_asIdsOrRanges:
never executed: case 1:
0
759 child_as = ext->asnum->u.asIdsOrRanges;-
760 break;
never executed: break;
0
761 }-
762 }
never executed: end of block
0
763 if (ext->rdi != NULL) {
ext->rdi != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
764 switch (ext->rdi->type) {-
765 case ASIdentifierChoice_inherit:
never executed: case 0:
0
766 inherit_rdi = 1;-
767 break;
never executed: break;
0
768 case ASIdentifierChoice_asIdsOrRanges:
never executed: case 1:
0
769 child_rdi = ext->rdi->u.asIdsOrRanges;-
770 break;
never executed: break;
0
771 }-
772 }
never executed: end of block
0
773-
774 /*-
775 * Now walk up the chain. Extensions must be in canonical form, no-
776 * cert may list resources that its parent doesn't list.-
777 */-
778 for (i++; i < sk_X509_num(chain); i++) {
i < sk_X509_num(chain)Description
TRUEnever evaluated
FALSEnever evaluated
0
779 x = sk_X509_value(chain, i);-
780 if (!ossl_assert(x != NULL)) {
!((x != ((void *)0) ) != 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
781 if (ctx != NULL)
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
782 ctx->error = X509_V_ERR_UNSPECIFIED;
never executed: ctx->error = 1;
0
783 return 0;
never executed: return 0;
0
784 }-
785 if (x->rfc3779_asid == NULL) {
x->rfc3779_asid == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
786 if (child_as != NULL || child_rdi != NULL)
child_as != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
child_rdi != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
787 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
never executed: end of block
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
788 continue;
never executed: continue;
0
789 }-
790 if (!X509v3_asid_is_canonical(x->rfc3779_asid))
!X509v3_asid_i...>rfc3779_asid)Description
TRUEnever evaluated
FALSEnever evaluated
0
791 validation_err(X509_V_ERR_INVALID_EXTENSION);
never executed: end of block
never executed: end of block
never executed: goto done;
never executed: end of block
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
792 if (x->rfc3779_asid->asnum == NULL && child_as != NULL) {
x->rfc3779_asi...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
child_as != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
793 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
794 child_as = NULL;-
795 inherit_as = 0;-
796 }
never executed: end of block
0
797 if (x->rfc3779_asid->asnum != NULL &&
x->rfc3779_asi...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
798 x->rfc3779_asid->asnum->type ==
x->rfc3779_asi...num->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
799 ASIdentifierChoice_asIdsOrRanges) {
x->rfc3779_asi...num->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
800 if (inherit_as
inherit_asDescription
TRUEnever evaluated
FALSEnever evaluated
0
801 || asid_contains(x->rfc3779_asid->asnum->u.asIdsOrRanges,
asid_contains(...ges, child_as)Description
TRUEnever evaluated
FALSEnever evaluated
0
802 child_as)) {
asid_contains(...ges, child_as)Description
TRUEnever evaluated
FALSEnever evaluated
0
803 child_as = x->rfc3779_asid->asnum->u.asIdsOrRanges;-
804 inherit_as = 0;-
805 } else {
never executed: end of block
0
806 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
807 }
never executed: end of block
0
808 }-
809 if (x->rfc3779_asid->rdi == NULL && child_rdi != NULL) {
x->rfc3779_asi...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
child_rdi != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
810 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
811 child_rdi = NULL;-
812 inherit_rdi = 0;-
813 }
never executed: end of block
0
814 if (x->rfc3779_asid->rdi != NULL &&
x->rfc3779_asi...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
815 x->rfc3779_asid->rdi->type == ASIdentifierChoice_asIdsOrRanges) {
x->rfc3779_asi...rdi->type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
816 if (inherit_rdi ||
inherit_rdiDescription
TRUEnever evaluated
FALSEnever evaluated
0
817 asid_contains(x->rfc3779_asid->rdi->u.asIdsOrRanges,
asid_contains(...es, child_rdi)Description
TRUEnever evaluated
FALSEnever evaluated
0
818 child_rdi)) {
asid_contains(...es, child_rdi)Description
TRUEnever evaluated
FALSEnever evaluated
0
819 child_rdi = x->rfc3779_asid->rdi->u.asIdsOrRanges;-
820 inherit_rdi = 0;-
821 } else {
never executed: end of block
0
822 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
823 }
never executed: end of block
0
824 }-
825 }
never executed: end of block
0
826-
827 /*-
828 * Trust anchor can't inherit.-
829 */-
830 if (!ossl_assert(x != NULL)) {
!((x != ((void *)0) ) != 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
831 if (ctx != NULL)
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
832 ctx->error = X509_V_ERR_UNSPECIFIED;
never executed: ctx->error = 1;
0
833 return 0;
never executed: return 0;
0
834 }-
835 if (x->rfc3779_asid != NULL) {
x->rfc3779_asid != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
836 if (x->rfc3779_asid->asnum != NULL &&
x->rfc3779_asi...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
837 x->rfc3779_asid->asnum->type == ASIdentifierChoice_inherit)
x->rfc3779_asi...num->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
838 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
never executed: end of block
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
839 if (x->rfc3779_asid->rdi != NULL &&
x->rfc3779_asi...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
840 x->rfc3779_asid->rdi->type == ASIdentifierChoice_inherit)
x->rfc3779_asi...rdi->type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
841 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
never executed: end of block
never executed: end of block
never executed: goto done;
never executed: end of block
!retDescription
TRUEnever evaluated
FALSEnever evaluated
ctx != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
842 }
never executed: end of block
0
843-
844 done:
code before this statement never executed: done:
0
845 return ret;
executed 1305 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1305
846}-
847-
848#undef validation_err-
849-
850/*-
851 * RFC 3779 3.3 path validation -- called from X509_verify_cert().-
852 */-
853int X509v3_asid_validate_path(X509_STORE_CTX *ctx)-
854{-
855 if (ctx->chain == NULL
ctx->chain == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1305
856 || sk_X509_num(ctx->chain) == 0
sk_X509_num(ctx->chain) == 0Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1305
857 || ctx->verify_cb == NULL) {
ctx->verify_cb == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1305 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1305
858 ctx->error = X509_V_ERR_UNSPECIFIED;-
859 return 0;
never executed: return 0;
0
860 }-
861 return asid_validate_path_internal(ctx, ctx->chain, NULL);
executed 1305 times by 1 test: return asid_validate_path_internal(ctx, ctx->chain, ((void *)0) );
Executed by:
  • libcrypto.so.1.1
1305
862}-
863-
864/*-
865 * RFC 3779 3.3 path validation of an extension.-
866 * Test whether chain covers extension.-
867 */-
868int X509v3_asid_validate_resource_set(STACK_OF(X509) *chain,-
869 ASIdentifiers *ext, int allow_inheritance)-
870{-
871 if (ext == NULL)
ext == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
872 return 1;
never executed: return 1;
0
873 if (chain == NULL || sk_X509_num(chain) == 0)
chain == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
sk_X509_num(chain) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
874 return 0;
never executed: return 0;
0
875 if (!allow_inheritance && X509v3_asid_inherits(ext))
!allow_inheritanceDescription
TRUEnever evaluated
FALSEnever evaluated
X509v3_asid_inherits(ext)Description
TRUEnever evaluated
FALSEnever evaluated
0
876 return 0;
never executed: return 0;
0
877 return asid_validate_path_internal(NULL, chain, ext);
never executed: return asid_validate_path_internal( ((void *)0) , chain, ext);
0
878}-
879-
880#endif /* OPENSSL_NO_RFC3779 */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2