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 <openssl/bn.h>
73 #ifndef OPENSSL_NO_RFC3779
76 * OpenSSL ASN.1 template translation of RFC 3779 3.2.3.
79 ASN1_SEQUENCE(ASRange) = {
80 ASN1_SIMPLE(ASRange, min, ASN1_INTEGER),
81 ASN1_SIMPLE(ASRange, max, ASN1_INTEGER)
82 } ASN1_SEQUENCE_END(ASRange)
84 ASN1_CHOICE(ASIdOrRange) = {
85 ASN1_SIMPLE(ASIdOrRange, u.id, ASN1_INTEGER),
86 ASN1_SIMPLE(ASIdOrRange, u.range, ASRange)
87 } ASN1_CHOICE_END(ASIdOrRange)
89 ASN1_CHOICE(ASIdentifierChoice) = {
90 ASN1_SIMPLE(ASIdentifierChoice, u.inherit, ASN1_NULL),
91 ASN1_SEQUENCE_OF(ASIdentifierChoice, u.asIdsOrRanges, ASIdOrRange)
92 } ASN1_CHOICE_END(ASIdentifierChoice)
94 ASN1_SEQUENCE(ASIdentifiers) = {
95 ASN1_EXP_OPT(ASIdentifiers, asnum, ASIdentifierChoice, 0),
96 ASN1_EXP_OPT(ASIdentifiers, rdi, ASIdentifierChoice, 1)
97 } ASN1_SEQUENCE_END(ASIdentifiers)
99 IMPLEMENT_ASN1_FUNCTIONS(ASRange)
100 IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange)
101 IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice)
102 IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers)
105 * i2r method for an ASIdentifierChoice.
107 static int i2r_ASIdentifierChoice(BIO *out,
108 ASIdentifierChoice *choice,
109 int indent, const char *msg)
115 BIO_printf(out, "%*s%s:\n", indent, "", msg);
116 switch (choice->type) {
117 case ASIdentifierChoice_inherit:
118 BIO_printf(out, "%*sinherit\n", indent + 2, "");
120 case ASIdentifierChoice_asIdsOrRanges:
121 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges); i++) {
123 sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
126 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL)
128 BIO_printf(out, "%*s%s\n", indent + 2, "", s);
131 case ASIdOrRange_range:
132 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL)
134 BIO_printf(out, "%*s%s-", indent + 2, "", s);
136 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL)
138 BIO_printf(out, "%s\n", s);
153 * i2r method for an ASIdentifier extension.
155 static int i2r_ASIdentifiers(const X509V3_EXT_METHOD *method,
156 void *ext, BIO *out, int indent)
158 ASIdentifiers *asid = ext;
159 return (i2r_ASIdentifierChoice(out, asid->asnum, indent,
160 "Autonomous System Numbers") &&
161 i2r_ASIdentifierChoice(out, asid->rdi, indent,
162 "Routing Domain Identifiers"));
166 * Sort comparision function for a sequence of ASIdOrRange elements.
168 static int ASIdOrRange_cmp(const ASIdOrRange *const *a_,
169 const ASIdOrRange *const *b_)
171 const ASIdOrRange *a = *a_, *b = *b_;
173 OPENSSL_assert((a->type == ASIdOrRange_id && a->u.id != NULL) ||
174 (a->type == ASIdOrRange_range && a->u.range != NULL &&
175 a->u.range->min != NULL && a->u.range->max != NULL));
177 OPENSSL_assert((b->type == ASIdOrRange_id && b->u.id != NULL) ||
178 (b->type == ASIdOrRange_range && b->u.range != NULL &&
179 b->u.range->min != NULL && b->u.range->max != NULL));
181 if (a->type == ASIdOrRange_id && b->type == ASIdOrRange_id)
182 return ASN1_INTEGER_cmp(a->u.id, b->u.id);
184 if (a->type == ASIdOrRange_range && b->type == ASIdOrRange_range) {
185 int r = ASN1_INTEGER_cmp(a->u.range->min, b->u.range->min);
186 return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max,
190 if (a->type == ASIdOrRange_id)
191 return ASN1_INTEGER_cmp(a->u.id, b->u.range->min);
193 return ASN1_INTEGER_cmp(a->u.range->min, b->u.id);
197 * Add an inherit element.
199 int v3_asid_add_inherit(ASIdentifiers *asid, int which)
201 ASIdentifierChoice **choice;
206 choice = &asid->asnum;
214 if (*choice == NULL) {
215 if ((*choice = ASIdentifierChoice_new()) == NULL)
217 OPENSSL_assert((*choice)->u.inherit == NULL);
218 if (((*choice)->u.inherit = ASN1_NULL_new()) == NULL)
220 (*choice)->type = ASIdentifierChoice_inherit;
222 return (*choice)->type == ASIdentifierChoice_inherit;
226 * Add an ID or range to an ASIdentifierChoice.
228 int v3_asid_add_id_or_range(ASIdentifiers *asid,
229 int which, ASN1_INTEGER *min, ASN1_INTEGER *max)
231 ASIdentifierChoice **choice;
237 choice = &asid->asnum;
245 if (*choice != NULL && (*choice)->type == ASIdentifierChoice_inherit)
247 if (*choice == NULL) {
248 if ((*choice = ASIdentifierChoice_new()) == NULL)
250 OPENSSL_assert((*choice)->u.asIdsOrRanges == NULL);
251 (*choice)->u.asIdsOrRanges = sk_ASIdOrRange_new(ASIdOrRange_cmp);
252 if ((*choice)->u.asIdsOrRanges == NULL)
254 (*choice)->type = ASIdentifierChoice_asIdsOrRanges;
256 if ((aor = ASIdOrRange_new()) == NULL)
259 aor->type = ASIdOrRange_id;
262 aor->type = ASIdOrRange_range;
263 if ((aor->u.range = ASRange_new()) == NULL)
265 ASN1_INTEGER_free(aor->u.range->min);
266 aor->u.range->min = min;
267 ASN1_INTEGER_free(aor->u.range->max);
268 aor->u.range->max = max;
270 if (!(sk_ASIdOrRange_push((*choice)->u.asIdsOrRanges, aor)))
275 ASIdOrRange_free(aor);
280 * Extract min and max values from an ASIdOrRange.
282 static void extract_min_max(ASIdOrRange *aor,
283 ASN1_INTEGER **min, ASN1_INTEGER **max)
285 OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
291 case ASIdOrRange_range:
292 *min = aor->u.range->min;
293 *max = aor->u.range->max;
299 * Check whether an ASIdentifierChoice is in canonical form.
301 static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice)
303 ASN1_INTEGER *a_max_plus_one = NULL;
308 * Empty element or inheritance is canonical.
310 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
314 * If not a list, or if empty list, it's broken.
316 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
317 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0)
321 * It's a list, check it.
323 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
324 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
325 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
326 ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
329 extract_min_max(a, &a_min, &a_max);
330 extract_min_max(b, &b_min, &b_max);
333 * Punt misordered list, overlapping start, or inverted range.
335 if (ASN1_INTEGER_cmp(a_min, b_min) >= 0 ||
336 ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
337 ASN1_INTEGER_cmp(b_min, b_max) > 0)
341 * Calculate a_max + 1 to check for adjacency.
343 if ((bn == NULL && (bn = BN_new()) == NULL) ||
344 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
345 !BN_add_word(bn, 1) ||
347 BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
348 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL,
349 ERR_R_MALLOC_FAILURE);
354 * Punt if adjacent or overlapping.
356 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) >= 0)
361 * Check for inverted range.
363 i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;
365 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
366 ASN1_INTEGER *a_min, *a_max;
367 if (a != NULL && a->type == ASIdOrRange_range) {
368 extract_min_max(a, &a_min, &a_max);
369 if (ASN1_INTEGER_cmp(a_min, a_max) > 0)
377 ASN1_INTEGER_free(a_max_plus_one);
383 * Check whether an ASIdentifier extension is in canonical form.
385 int v3_asid_is_canonical(ASIdentifiers *asid)
387 return (asid == NULL ||
388 (ASIdentifierChoice_is_canonical(asid->asnum) &&
389 ASIdentifierChoice_is_canonical(asid->rdi)));
393 * Whack an ASIdentifierChoice into canonical form.
395 static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
397 ASN1_INTEGER *a_max_plus_one = NULL;
402 * Nothing to do for empty element or inheritance.
404 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
408 * If not a list, or if empty list, it's broken.
410 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
411 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
412 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
413 X509V3_R_EXTENSION_VALUE_ERROR);
418 * We have a non-empty list. Sort it.
420 sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);
423 * Now check for errors and suboptimal encoding, rejecting the
424 * former and fixing the latter.
426 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
427 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
428 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
429 ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
432 extract_min_max(a, &a_min, &a_max);
433 extract_min_max(b, &b_min, &b_max);
436 * Make sure we're properly sorted (paranoia).
438 OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0);
441 * Punt inverted ranges.
443 if (ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
444 ASN1_INTEGER_cmp(b_min, b_max) > 0)
448 * Check for overlaps.
450 if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) {
451 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
452 X509V3_R_EXTENSION_VALUE_ERROR);
457 * Calculate a_max + 1 to check for adjacency.
459 if ((bn == NULL && (bn = BN_new()) == NULL) ||
460 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
461 !BN_add_word(bn, 1) ||
463 BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
464 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
465 ERR_R_MALLOC_FAILURE);
470 * If a and b are adjacent, merge them.
472 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) {
476 if ((r = OPENSSL_malloc(sizeof(*r))) == NULL) {
477 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
478 ERR_R_MALLOC_FAILURE);
483 a->type = ASIdOrRange_range;
486 case ASIdOrRange_range:
487 ASN1_INTEGER_free(a->u.range->max);
488 a->u.range->max = b_max;
495 case ASIdOrRange_range:
496 b->u.range->max = NULL;
500 (void)sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);
507 * Check for final inverted range.
509 i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;
511 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
512 ASN1_INTEGER *a_min, *a_max;
513 if (a != NULL && a->type == ASIdOrRange_range) {
514 extract_min_max(a, &a_min, &a_max);
515 if (ASN1_INTEGER_cmp(a_min, a_max) > 0)
520 OPENSSL_assert(ASIdentifierChoice_is_canonical(choice)); /* Paranoia */
525 ASN1_INTEGER_free(a_max_plus_one);
531 * Whack an ASIdentifier extension into canonical form.
533 int v3_asid_canonize(ASIdentifiers *asid)
535 return (asid == NULL ||
536 (ASIdentifierChoice_canonize(asid->asnum) &&
537 ASIdentifierChoice_canonize(asid->rdi)));
541 * v2i method for an ASIdentifier extension.
543 static void *v2i_ASIdentifiers(const struct v3_ext_method *method,
544 struct v3_ext_ctx *ctx,
545 STACK_OF(CONF_VALUE) *values)
547 ASN1_INTEGER *min = NULL, *max = NULL;
548 ASIdentifiers *asid = NULL;
551 if ((asid = ASIdentifiers_new()) == NULL) {
552 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
556 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
557 CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
558 int i1 = 0, i2 = 0, i3 = 0, is_range = 0, which = 0;
561 * Figure out whether this is an AS or an RDI.
563 if (!name_cmp(val->name, "AS")) {
564 which = V3_ASID_ASNUM;
565 } else if (!name_cmp(val->name, "RDI")) {
568 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
569 X509V3_R_EXTENSION_NAME_ERROR);
570 X509V3_conf_err(val);
575 * Handle inheritance.
577 if (strcmp(val->value, "inherit") == 0) {
578 if (v3_asid_add_inherit(asid, which))
580 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
581 X509V3_R_INVALID_INHERITANCE);
582 X509V3_conf_err(val);
587 * Number, range, or mistake, pick it apart and figure out which.
589 i1 = strspn(val->value, "0123456789");
590 if (val->value[i1] == '\0') {
594 i2 = i1 + strspn(val->value + i1, " \t");
595 if (val->value[i2] != '-') {
596 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
597 X509V3_R_INVALID_ASNUMBER);
598 X509V3_conf_err(val);
602 i2 = i2 + strspn(val->value + i2, " \t");
603 i3 = i2 + strspn(val->value + i2, "0123456789");
604 if (val->value[i3] != '\0') {
605 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
606 X509V3_R_INVALID_ASRANGE);
607 X509V3_conf_err(val);
613 * Syntax is ok, read and add it.
616 if (!X509V3_get_value_int(val, &min)) {
617 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
621 char *s = BUF_strdup(val->value);
623 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
627 min = s2i_ASN1_INTEGER(NULL, s);
628 max = s2i_ASN1_INTEGER(NULL, s + i2);
630 if (min == NULL || max == NULL) {
631 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
634 if (ASN1_INTEGER_cmp(min, max) > 0) {
635 X509V3err(X509V3_F_V2I_ASIDENTIFIERS,
636 X509V3_R_EXTENSION_VALUE_ERROR);
640 if (!v3_asid_add_id_or_range(asid, which, min, max)) {
641 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
648 * Canonize the result, then we're done.
650 if (!v3_asid_canonize(asid))
655 ASIdentifiers_free(asid);
656 ASN1_INTEGER_free(min);
657 ASN1_INTEGER_free(max);
664 const X509V3_EXT_METHOD v3_asid = {
665 NID_sbgp_autonomousSysNum, /* nid */
667 ASN1_ITEM_ref(ASIdentifiers), /* template */
668 0, 0, 0, 0, /* old functions, ignored */
672 v2i_ASIdentifiers, /* v2i */
673 i2r_ASIdentifiers, /* i2r */
675 NULL /* extension-specific data */
679 * Figure out whether extension uses inheritance.
681 int v3_asid_inherits(ASIdentifiers *asid)
683 return (asid != NULL &&
684 ((asid->asnum != NULL &&
685 asid->asnum->type == ASIdentifierChoice_inherit) ||
686 (asid->rdi != NULL &&
687 asid->rdi->type == ASIdentifierChoice_inherit)));
691 * Figure out whether parent contains child.
693 static int asid_contains(ASIdOrRanges *parent, ASIdOrRanges *child)
695 ASN1_INTEGER *p_min = NULL, *p_max = NULL, *c_min = NULL, *c_max = NULL;
698 if (child == NULL || parent == child)
704 for (c = 0; c < sk_ASIdOrRange_num(child); c++) {
705 extract_min_max(sk_ASIdOrRange_value(child, c), &c_min, &c_max);
707 if (p >= sk_ASIdOrRange_num(parent))
709 extract_min_max(sk_ASIdOrRange_value(parent, p), &p_min, &p_max);
710 if (ASN1_INTEGER_cmp(p_max, c_max) < 0)
712 if (ASN1_INTEGER_cmp(p_min, c_min) > 0)
722 * Test whether a is a subet of b.
724 int v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b)
729 !v3_asid_inherits(a) &&
730 !v3_asid_inherits(b) &&
731 asid_contains(b->asnum->u.asIdsOrRanges,
732 a->asnum->u.asIdsOrRanges) &&
733 asid_contains(b->rdi->u.asIdsOrRanges,
734 a->rdi->u.asIdsOrRanges)));
738 * Validation error handling via callback.
740 #define validation_err(_err_) \
743 ctx->error = _err_; \
744 ctx->error_depth = i; \
745 ctx->current_cert = x; \
746 ret = ctx->verify_cb(0, ctx); \
755 * Core code for RFC 3779 3.3 path validation.
757 static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx,
758 STACK_OF(X509) *chain,
761 ASIdOrRanges *child_as = NULL, *child_rdi = NULL;
762 int i, ret = 1, inherit_as = 0, inherit_rdi = 0;
765 OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0);
766 OPENSSL_assert(ctx != NULL || ext != NULL);
767 OPENSSL_assert(ctx == NULL || ctx->verify_cb != NULL);
770 * Figure out where to start. If we don't have an extension to
771 * check, we're done. Otherwise, check canonical form and
772 * set up for walking up the chain.
779 x = sk_X509_value(chain, i);
780 OPENSSL_assert(x != NULL);
781 if ((ext = x->rfc3779_asid) == NULL)
784 if (!v3_asid_is_canonical(ext))
785 validation_err(X509_V_ERR_INVALID_EXTENSION);
786 if (ext->asnum != NULL) {
787 switch (ext->asnum->type) {
788 case ASIdentifierChoice_inherit:
791 case ASIdentifierChoice_asIdsOrRanges:
792 child_as = ext->asnum->u.asIdsOrRanges;
796 if (ext->rdi != NULL) {
797 switch (ext->rdi->type) {
798 case ASIdentifierChoice_inherit:
801 case ASIdentifierChoice_asIdsOrRanges:
802 child_rdi = ext->rdi->u.asIdsOrRanges;
808 * Now walk up the chain. Extensions must be in canonical form, no
809 * cert may list resources that its parent doesn't list.
811 for (i++; i < sk_X509_num(chain); i++) {
812 x = sk_X509_value(chain, i);
813 OPENSSL_assert(x != NULL);
814 if (x->rfc3779_asid == NULL) {
815 if (child_as != NULL || child_rdi != NULL)
816 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
819 if (!v3_asid_is_canonical(x->rfc3779_asid))
820 validation_err(X509_V_ERR_INVALID_EXTENSION);
821 if (x->rfc3779_asid->asnum == NULL && child_as != NULL) {
822 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
826 if (x->rfc3779_asid->asnum != NULL &&
827 x->rfc3779_asid->asnum->type ==
828 ASIdentifierChoice_asIdsOrRanges) {
830 || asid_contains(x->rfc3779_asid->asnum->u.asIdsOrRanges,
832 child_as = x->rfc3779_asid->asnum->u.asIdsOrRanges;
835 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
838 if (x->rfc3779_asid->rdi == NULL && child_rdi != NULL) {
839 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
843 if (x->rfc3779_asid->rdi != NULL &&
844 x->rfc3779_asid->rdi->type == ASIdentifierChoice_asIdsOrRanges) {
846 asid_contains(x->rfc3779_asid->rdi->u.asIdsOrRanges,
848 child_rdi = x->rfc3779_asid->rdi->u.asIdsOrRanges;
851 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
857 * Trust anchor can't inherit.
859 OPENSSL_assert(x != NULL);
860 if (x->rfc3779_asid != NULL) {
861 if (x->rfc3779_asid->asnum != NULL &&
862 x->rfc3779_asid->asnum->type == ASIdentifierChoice_inherit)
863 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
864 if (x->rfc3779_asid->rdi != NULL &&
865 x->rfc3779_asid->rdi->type == ASIdentifierChoice_inherit)
866 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
873 #undef validation_err
876 * RFC 3779 3.3 path validation -- called from X509_verify_cert().
878 int v3_asid_validate_path(X509_STORE_CTX *ctx)
880 return v3_asid_validate_path_internal(ctx, ctx->chain, NULL);
884 * RFC 3779 3.3 path validation of an extension.
885 * Test whether chain covers extension.
887 int v3_asid_validate_resource_set(STACK_OF(X509) *chain,
888 ASIdentifiers *ext, int allow_inheritance)
892 if (chain == NULL || sk_X509_num(chain) == 0)
894 if (!allow_inheritance && v3_asid_inherits(ext))
896 return v3_asid_validate_path_internal(NULL, chain, ext);
899 #endif /* OPENSSL_NO_RFC3779 */