2 * Contributed to the OpenSSL Project by the American Registry for
3 * Internet Numbers ("ARIN").
5 /* ====================================================================
6 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
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 * ====================================================================
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).
59 * Implementation of RFC 3779 section 3.2.
64 #include "internal/cryptlib.h"
65 #include <openssl/conf.h>
66 #include <openssl/asn1.h>
67 #include <openssl/asn1t.h>
68 #include <openssl/x509v3.h>
69 #include <openssl/x509.h>
70 #include "internal/x509_int.h"
71 #include <openssl/bn.h>
74 #ifndef OPENSSL_NO_RFC3779
77 * OpenSSL ASN.1 template translation of RFC 3779 3.2.3.
80 ASN1_SEQUENCE(ASRange) = {
81 ASN1_SIMPLE(ASRange, min, ASN1_INTEGER),
82 ASN1_SIMPLE(ASRange, max, ASN1_INTEGER)
83 } ASN1_SEQUENCE_END(ASRange)
85 ASN1_CHOICE(ASIdOrRange) = {
86 ASN1_SIMPLE(ASIdOrRange, u.id, ASN1_INTEGER),
87 ASN1_SIMPLE(ASIdOrRange, u.range, ASRange)
88 } ASN1_CHOICE_END(ASIdOrRange)
90 ASN1_CHOICE(ASIdentifierChoice) = {
91 ASN1_SIMPLE(ASIdentifierChoice, u.inherit, ASN1_NULL),
92 ASN1_SEQUENCE_OF(ASIdentifierChoice, u.asIdsOrRanges, ASIdOrRange)
93 } ASN1_CHOICE_END(ASIdentifierChoice)
95 ASN1_SEQUENCE(ASIdentifiers) = {
96 ASN1_EXP_OPT(ASIdentifiers, asnum, ASIdentifierChoice, 0),
97 ASN1_EXP_OPT(ASIdentifiers, rdi, ASIdentifierChoice, 1)
98 } ASN1_SEQUENCE_END(ASIdentifiers)
100 IMPLEMENT_ASN1_FUNCTIONS(ASRange)
101 IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange)
102 IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice)
103 IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers)
106 * i2r method for an ASIdentifierChoice.
108 static int i2r_ASIdentifierChoice(BIO *out,
109 ASIdentifierChoice *choice,
110 int indent, const char *msg)
116 BIO_printf(out, "%*s%s:\n", indent, "", msg);
117 switch (choice->type) {
118 case ASIdentifierChoice_inherit:
119 BIO_printf(out, "%*sinherit\n", indent + 2, "");
121 case ASIdentifierChoice_asIdsOrRanges:
122 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges); i++) {
124 sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
127 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL)
129 BIO_printf(out, "%*s%s\n", indent + 2, "", s);
132 case ASIdOrRange_range:
133 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL)
135 BIO_printf(out, "%*s%s-", indent + 2, "", s);
137 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL)
139 BIO_printf(out, "%s\n", s);
154 * i2r method for an ASIdentifier extension.
156 static int i2r_ASIdentifiers(const X509V3_EXT_METHOD *method,
157 void *ext, BIO *out, int indent)
159 ASIdentifiers *asid = ext;
160 return (i2r_ASIdentifierChoice(out, asid->asnum, indent,
161 "Autonomous System Numbers") &&
162 i2r_ASIdentifierChoice(out, asid->rdi, indent,
163 "Routing Domain Identifiers"));
167 * Sort comparision function for a sequence of ASIdOrRange elements.
169 static int ASIdOrRange_cmp(const ASIdOrRange *const *a_,
170 const ASIdOrRange *const *b_)
172 const ASIdOrRange *a = *a_, *b = *b_;
174 OPENSSL_assert((a->type == ASIdOrRange_id && a->u.id != NULL) ||
175 (a->type == ASIdOrRange_range && a->u.range != NULL &&
176 a->u.range->min != NULL && a->u.range->max != NULL));
178 OPENSSL_assert((b->type == ASIdOrRange_id && b->u.id != NULL) ||
179 (b->type == ASIdOrRange_range && b->u.range != NULL &&
180 b->u.range->min != NULL && b->u.range->max != NULL));
182 if (a->type == ASIdOrRange_id && b->type == ASIdOrRange_id)
183 return ASN1_INTEGER_cmp(a->u.id, b->u.id);
185 if (a->type == ASIdOrRange_range && b->type == ASIdOrRange_range) {
186 int r = ASN1_INTEGER_cmp(a->u.range->min, b->u.range->min);
187 return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max,
191 if (a->type == ASIdOrRange_id)
192 return ASN1_INTEGER_cmp(a->u.id, b->u.range->min);
194 return ASN1_INTEGER_cmp(a->u.range->min, b->u.id);
198 * Add an inherit element.
200 int v3_asid_add_inherit(ASIdentifiers *asid, int which)
202 ASIdentifierChoice **choice;
207 choice = &asid->asnum;
215 if (*choice == NULL) {
216 if ((*choice = ASIdentifierChoice_new()) == NULL)
218 OPENSSL_assert((*choice)->u.inherit == NULL);
219 if (((*choice)->u.inherit = ASN1_NULL_new()) == NULL)
221 (*choice)->type = ASIdentifierChoice_inherit;
223 return (*choice)->type == ASIdentifierChoice_inherit;
227 * Add an ID or range to an ASIdentifierChoice.
229 int v3_asid_add_id_or_range(ASIdentifiers *asid,
230 int which, ASN1_INTEGER *min, ASN1_INTEGER *max)
232 ASIdentifierChoice **choice;
238 choice = &asid->asnum;
246 if (*choice != NULL && (*choice)->type == ASIdentifierChoice_inherit)
248 if (*choice == NULL) {
249 if ((*choice = ASIdentifierChoice_new()) == NULL)
251 OPENSSL_assert((*choice)->u.asIdsOrRanges == NULL);
252 (*choice)->u.asIdsOrRanges = sk_ASIdOrRange_new(ASIdOrRange_cmp);
253 if ((*choice)->u.asIdsOrRanges == NULL)
255 (*choice)->type = ASIdentifierChoice_asIdsOrRanges;
257 if ((aor = ASIdOrRange_new()) == NULL)
260 aor->type = ASIdOrRange_id;
263 aor->type = ASIdOrRange_range;
264 if ((aor->u.range = ASRange_new()) == NULL)
266 ASN1_INTEGER_free(aor->u.range->min);
267 aor->u.range->min = min;
268 ASN1_INTEGER_free(aor->u.range->max);
269 aor->u.range->max = max;
271 if (!(sk_ASIdOrRange_push((*choice)->u.asIdsOrRanges, aor)))
276 ASIdOrRange_free(aor);
281 * Extract min and max values from an ASIdOrRange.
283 static void extract_min_max(ASIdOrRange *aor,
284 ASN1_INTEGER **min, ASN1_INTEGER **max)
286 OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
292 case ASIdOrRange_range:
293 *min = aor->u.range->min;
294 *max = aor->u.range->max;
300 * Check whether an ASIdentifierChoice is in canonical form.
302 static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice)
304 ASN1_INTEGER *a_max_plus_one = NULL;
309 * Empty element or inheritance is canonical.
311 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
315 * If not a list, or if empty list, it's broken.
317 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
318 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0)
322 * It's a list, check it.
324 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
325 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
326 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
327 ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
330 extract_min_max(a, &a_min, &a_max);
331 extract_min_max(b, &b_min, &b_max);
334 * Punt misordered list, overlapping start, or inverted range.
336 if (ASN1_INTEGER_cmp(a_min, b_min) >= 0 ||
337 ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
338 ASN1_INTEGER_cmp(b_min, b_max) > 0)
342 * Calculate a_max + 1 to check for adjacency.
344 if ((bn == NULL && (bn = BN_new()) == NULL) ||
345 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
346 !BN_add_word(bn, 1) ||
348 BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
349 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL,
350 ERR_R_MALLOC_FAILURE);
355 * Punt if adjacent or overlapping.
357 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) >= 0)
362 * Check for inverted range.
364 i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;
366 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
367 ASN1_INTEGER *a_min, *a_max;
368 if (a != NULL && a->type == ASIdOrRange_range) {
369 extract_min_max(a, &a_min, &a_max);
370 if (ASN1_INTEGER_cmp(a_min, a_max) > 0)
378 ASN1_INTEGER_free(a_max_plus_one);
384 * Check whether an ASIdentifier extension is in canonical form.
386 int v3_asid_is_canonical(ASIdentifiers *asid)
388 return (asid == NULL ||
389 (ASIdentifierChoice_is_canonical(asid->asnum) &&
390 ASIdentifierChoice_is_canonical(asid->rdi)));
394 * Whack an ASIdentifierChoice into canonical form.
396 static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
398 ASN1_INTEGER *a_max_plus_one = NULL;
403 * Nothing to do for empty element or inheritance.
405 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
409 * If not a list, or if empty list, it's broken.
411 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
412 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
413 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
414 X509V3_R_EXTENSION_VALUE_ERROR);
419 * We have a non-empty list. Sort it.
421 sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);
424 * Now check for errors and suboptimal encoding, rejecting the
425 * former and fixing the latter.
427 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
428 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
429 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
430 ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
433 extract_min_max(a, &a_min, &a_max);
434 extract_min_max(b, &b_min, &b_max);
437 * Make sure we're properly sorted (paranoia).
439 OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0);
442 * Punt inverted ranges.
444 if (ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
445 ASN1_INTEGER_cmp(b_min, b_max) > 0)
449 * Check for overlaps.
451 if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) {
452 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
453 X509V3_R_EXTENSION_VALUE_ERROR);
458 * Calculate a_max + 1 to check for adjacency.
460 if ((bn == NULL && (bn = BN_new()) == NULL) ||
461 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
462 !BN_add_word(bn, 1) ||
464 BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
465 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
466 ERR_R_MALLOC_FAILURE);
471 * If a and b are adjacent, merge them.
473 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) {
477 if ((r = OPENSSL_malloc(sizeof(*r))) == NULL) {
478 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
479 ERR_R_MALLOC_FAILURE);
484 a->type = ASIdOrRange_range;
487 case ASIdOrRange_range:
488 ASN1_INTEGER_free(a->u.range->max);
489 a->u.range->max = b_max;
496 case ASIdOrRange_range:
497 b->u.range->max = NULL;
501 (void)sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);
508 * Check for final inverted range.
510 i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;
512 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
513 ASN1_INTEGER *a_min, *a_max;
514 if (a != NULL && a->type == ASIdOrRange_range) {
515 extract_min_max(a, &a_min, &a_max);
516 if (ASN1_INTEGER_cmp(a_min, a_max) > 0)
521 OPENSSL_assert(ASIdentifierChoice_is_canonical(choice)); /* Paranoia */
526 ASN1_INTEGER_free(a_max_plus_one);
532 * Whack an ASIdentifier extension into canonical form.
534 int v3_asid_canonize(ASIdentifiers *asid)
536 return (asid == NULL ||
537 (ASIdentifierChoice_canonize(asid->asnum) &&
538 ASIdentifierChoice_canonize(asid->rdi)));
542 * v2i method for an ASIdentifier extension.
544 static void *v2i_ASIdentifiers(const struct v3_ext_method *method,
545 struct v3_ext_ctx *ctx,
546 STACK_OF(CONF_VALUE) *values)
548 ASN1_INTEGER *min = NULL, *max = NULL;
549 ASIdentifiers *asid = NULL;
552 if ((asid = ASIdentifiers_new()) == NULL) {
553 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
557 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
558 CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
559 int i1 = 0, i2 = 0, i3 = 0, is_range = 0, which = 0;
562 * Figure out whether this is an AS or an RDI.
564 if (!name_cmp(val->name, "AS")) {
565 which = V3_ASID_ASNUM;
566 } else if (!name_cmp(val->name, "RDI")) {
569 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
570 X509V3_R_EXTENSION_NAME_ERROR);
571 X509V3_conf_err(val);
576 * Handle inheritance.
578 if (strcmp(val->value, "inherit") == 0) {
579 if (v3_asid_add_inherit(asid, which))
581 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
582 X509V3_R_INVALID_INHERITANCE);
583 X509V3_conf_err(val);
588 * Number, range, or mistake, pick it apart and figure out which.
590 i1 = strspn(val->value, "0123456789");
591 if (val->value[i1] == '\0') {
595 i2 = i1 + strspn(val->value + i1, " \t");
596 if (val->value[i2] != '-') {
597 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
598 X509V3_R_INVALID_ASNUMBER);
599 X509V3_conf_err(val);
603 i2 = i2 + strspn(val->value + i2, " \t");
604 i3 = i2 + strspn(val->value + i2, "0123456789");
605 if (val->value[i3] != '\0') {
606 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
607 X509V3_R_INVALID_ASRANGE);
608 X509V3_conf_err(val);
614 * Syntax is ok, read and add it.
617 if (!X509V3_get_value_int(val, &min)) {
618 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
622 char *s = BUF_strdup(val->value);
624 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
628 min = s2i_ASN1_INTEGER(NULL, s);
629 max = s2i_ASN1_INTEGER(NULL, s + i2);
631 if (min == NULL || max == NULL) {
632 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
635 if (ASN1_INTEGER_cmp(min, max) > 0) {
636 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
637 X509V3_R_EXTENSION_VALUE_ERROR);
641 if (!v3_asid_add_id_or_range(asid, which, min, max)) {
642 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
649 * Canonize the result, then we're done.
651 if (!v3_asid_canonize(asid))
656 ASIdentifiers_free(asid);
657 ASN1_INTEGER_free(min);
658 ASN1_INTEGER_free(max);
665 const X509V3_EXT_METHOD v3_asid = {
666 NID_sbgp_autonomousSysNum, /* nid */
668 ASN1_ITEM_ref(ASIdentifiers), /* template */
669 0, 0, 0, 0, /* old functions, ignored */
673 v2i_ASIdentifiers, /* v2i */
674 i2r_ASIdentifiers, /* i2r */
676 NULL /* extension-specific data */
680 * Figure out whether extension uses inheritance.
682 int v3_asid_inherits(ASIdentifiers *asid)
684 return (asid != NULL &&
685 ((asid->asnum != NULL &&
686 asid->asnum->type == ASIdentifierChoice_inherit) ||
687 (asid->rdi != NULL &&
688 asid->rdi->type == ASIdentifierChoice_inherit)));
692 * Figure out whether parent contains child.
694 static int asid_contains(ASIdOrRanges *parent, ASIdOrRanges *child)
696 ASN1_INTEGER *p_min = NULL, *p_max = NULL, *c_min = NULL, *c_max = NULL;
699 if (child == NULL || parent == child)
705 for (c = 0; c < sk_ASIdOrRange_num(child); c++) {
706 extract_min_max(sk_ASIdOrRange_value(child, c), &c_min, &c_max);
708 if (p >= sk_ASIdOrRange_num(parent))
710 extract_min_max(sk_ASIdOrRange_value(parent, p), &p_min, &p_max);
711 if (ASN1_INTEGER_cmp(p_max, c_max) < 0)
713 if (ASN1_INTEGER_cmp(p_min, c_min) > 0)
723 * Test whether a is a subet of b.
725 int v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b)
730 !v3_asid_inherits(a) &&
731 !v3_asid_inherits(b) &&
732 asid_contains(b->asnum->u.asIdsOrRanges,
733 a->asnum->u.asIdsOrRanges) &&
734 asid_contains(b->rdi->u.asIdsOrRanges,
735 a->rdi->u.asIdsOrRanges)));
739 * Validation error handling via callback.
741 #define validation_err(_err_) \
744 ctx->error = _err_; \
745 ctx->error_depth = i; \
746 ctx->current_cert = x; \
747 ret = ctx->verify_cb(0, ctx); \
756 * Core code for RFC 3779 3.3 path validation.
758 static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx,
759 STACK_OF(X509) *chain,
762 ASIdOrRanges *child_as = NULL, *child_rdi = NULL;
763 int i, ret = 1, inherit_as = 0, inherit_rdi = 0;
766 OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0);
767 OPENSSL_assert(ctx != NULL || ext != NULL);
768 OPENSSL_assert(ctx == NULL || ctx->verify_cb != NULL);
771 * Figure out where to start. If we don't have an extension to
772 * check, we're done. Otherwise, check canonical form and
773 * set up for walking up the chain.
780 x = sk_X509_value(chain, i);
781 OPENSSL_assert(x != NULL);
782 if ((ext = x->rfc3779_asid) == NULL)
785 if (!v3_asid_is_canonical(ext))
786 validation_err(X509_V_ERR_INVALID_EXTENSION);
787 if (ext->asnum != NULL) {
788 switch (ext->asnum->type) {
789 case ASIdentifierChoice_inherit:
792 case ASIdentifierChoice_asIdsOrRanges:
793 child_as = ext->asnum->u.asIdsOrRanges;
797 if (ext->rdi != NULL) {
798 switch (ext->rdi->type) {
799 case ASIdentifierChoice_inherit:
802 case ASIdentifierChoice_asIdsOrRanges:
803 child_rdi = ext->rdi->u.asIdsOrRanges;
809 * Now walk up the chain. Extensions must be in canonical form, no
810 * cert may list resources that its parent doesn't list.
812 for (i++; i < sk_X509_num(chain); i++) {
813 x = sk_X509_value(chain, i);
814 OPENSSL_assert(x != NULL);
815 if (x->rfc3779_asid == NULL) {
816 if (child_as != NULL || child_rdi != NULL)
817 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
820 if (!v3_asid_is_canonical(x->rfc3779_asid))
821 validation_err(X509_V_ERR_INVALID_EXTENSION);
822 if (x->rfc3779_asid->asnum == NULL && child_as != NULL) {
823 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
827 if (x->rfc3779_asid->asnum != NULL &&
828 x->rfc3779_asid->asnum->type ==
829 ASIdentifierChoice_asIdsOrRanges) {
831 || asid_contains(x->rfc3779_asid->asnum->u.asIdsOrRanges,
833 child_as = x->rfc3779_asid->asnum->u.asIdsOrRanges;
836 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
839 if (x->rfc3779_asid->rdi == NULL && child_rdi != NULL) {
840 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
844 if (x->rfc3779_asid->rdi != NULL &&
845 x->rfc3779_asid->rdi->type == ASIdentifierChoice_asIdsOrRanges) {
847 asid_contains(x->rfc3779_asid->rdi->u.asIdsOrRanges,
849 child_rdi = x->rfc3779_asid->rdi->u.asIdsOrRanges;
852 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
858 * Trust anchor can't inherit.
860 OPENSSL_assert(x != NULL);
861 if (x->rfc3779_asid != NULL) {
862 if (x->rfc3779_asid->asnum != NULL &&
863 x->rfc3779_asid->asnum->type == ASIdentifierChoice_inherit)
864 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
865 if (x->rfc3779_asid->rdi != NULL &&
866 x->rfc3779_asid->rdi->type == ASIdentifierChoice_inherit)
867 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
874 #undef validation_err
877 * RFC 3779 3.3 path validation -- called from X509_verify_cert().
879 int v3_asid_validate_path(X509_STORE_CTX *ctx)
881 return v3_asid_validate_path_internal(ctx, ctx->chain, NULL);
885 * RFC 3779 3.3 path validation of an extension.
886 * Test whether chain covers extension.
888 int v3_asid_validate_resource_set(STACK_OF(X509) *chain,
889 ASIdentifiers *ext, int allow_inheritance)
893 if (chain == NULL || sk_X509_num(chain) == 0)
895 if (!allow_inheritance && v3_asid_inherits(ext))
897 return v3_asid_validate_path_internal(NULL, chain, ext);
900 #endif /* OPENSSL_NO_RFC3779 */