2 * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
11 * Implementation of RFC 3779 section 3.2.
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 "crypto/x509.h"
24 #include <openssl/bn.h>
26 #include "x509_local.h"
28 #ifndef OPENSSL_NO_RFC3779
31 * OpenSSL ASN.1 template translation of RFC 3779 3.2.3.
34 ASN1_SEQUENCE(ASRange
) = {
35 ASN1_SIMPLE(ASRange
, min
, ASN1_INTEGER
),
36 ASN1_SIMPLE(ASRange
, max
, ASN1_INTEGER
)
37 } ASN1_SEQUENCE_END(ASRange
)
39 ASN1_CHOICE(ASIdOrRange
) = {
40 ASN1_SIMPLE(ASIdOrRange
, u
.id
, ASN1_INTEGER
),
41 ASN1_SIMPLE(ASIdOrRange
, u
.range
, ASRange
)
42 } ASN1_CHOICE_END(ASIdOrRange
)
44 ASN1_CHOICE(ASIdentifierChoice
) = {
45 ASN1_SIMPLE(ASIdentifierChoice
, u
.inherit
, ASN1_NULL
),
46 ASN1_SEQUENCE_OF(ASIdentifierChoice
, u
.asIdsOrRanges
, ASIdOrRange
)
47 } ASN1_CHOICE_END(ASIdentifierChoice
)
49 ASN1_SEQUENCE(ASIdentifiers
) = {
50 ASN1_EXP_OPT(ASIdentifiers
, asnum
, ASIdentifierChoice
, 0),
51 ASN1_EXP_OPT(ASIdentifiers
, rdi
, ASIdentifierChoice
, 1)
52 } ASN1_SEQUENCE_END(ASIdentifiers
)
54 IMPLEMENT_ASN1_FUNCTIONS(ASRange
)
55 IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange
)
56 IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice
)
57 IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers
)
60 * i2r method for an ASIdentifierChoice.
62 static int i2r_ASIdentifierChoice(BIO
*out
,
63 ASIdentifierChoice
*choice
,
64 int indent
, const char *msg
)
70 BIO_printf(out
, "%*s%s:\n", indent
, "", msg
);
71 switch (choice
->type
) {
72 case ASIdentifierChoice_inherit
:
73 BIO_printf(out
, "%*sinherit\n", indent
+ 2, "");
75 case ASIdentifierChoice_asIdsOrRanges
:
76 for (i
= 0; i
< sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
); i
++) {
78 sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
);
81 if ((s
= i2s_ASN1_INTEGER(NULL
, aor
->u
.id
)) == NULL
)
83 BIO_printf(out
, "%*s%s\n", indent
+ 2, "", s
);
86 case ASIdOrRange_range
:
87 if ((s
= i2s_ASN1_INTEGER(NULL
, aor
->u
.range
->min
)) == NULL
)
89 BIO_printf(out
, "%*s%s-", indent
+ 2, "", s
);
91 if ((s
= i2s_ASN1_INTEGER(NULL
, aor
->u
.range
->max
)) == NULL
)
93 BIO_printf(out
, "%s\n", s
);
108 * i2r method for an ASIdentifier extension.
110 static int i2r_ASIdentifiers(const X509V3_EXT_METHOD
*method
,
111 void *ext
, BIO
*out
, int indent
)
113 ASIdentifiers
*asid
= ext
;
114 return (i2r_ASIdentifierChoice(out
, asid
->asnum
, indent
,
115 "Autonomous System Numbers") &&
116 i2r_ASIdentifierChoice(out
, asid
->rdi
, indent
,
117 "Routing Domain Identifiers"));
121 * Sort comparison function for a sequence of ASIdOrRange elements.
123 static int ASIdOrRange_cmp(const ASIdOrRange
*const *a_
,
124 const ASIdOrRange
*const *b_
)
126 const ASIdOrRange
*a
= *a_
, *b
= *b_
;
128 assert((a
->type
== ASIdOrRange_id
&& a
->u
.id
!= NULL
) ||
129 (a
->type
== ASIdOrRange_range
&& a
->u
.range
!= NULL
&&
130 a
->u
.range
->min
!= NULL
&& a
->u
.range
->max
!= NULL
));
132 assert((b
->type
== ASIdOrRange_id
&& b
->u
.id
!= NULL
) ||
133 (b
->type
== ASIdOrRange_range
&& b
->u
.range
!= NULL
&&
134 b
->u
.range
->min
!= NULL
&& b
->u
.range
->max
!= NULL
));
136 if (a
->type
== ASIdOrRange_id
&& b
->type
== ASIdOrRange_id
)
137 return ASN1_INTEGER_cmp(a
->u
.id
, b
->u
.id
);
139 if (a
->type
== ASIdOrRange_range
&& b
->type
== ASIdOrRange_range
) {
140 int r
= ASN1_INTEGER_cmp(a
->u
.range
->min
, b
->u
.range
->min
);
141 return r
!= 0 ? r
: ASN1_INTEGER_cmp(a
->u
.range
->max
,
145 if (a
->type
== ASIdOrRange_id
)
146 return ASN1_INTEGER_cmp(a
->u
.id
, b
->u
.range
->min
);
148 return ASN1_INTEGER_cmp(a
->u
.range
->min
, b
->u
.id
);
152 * Add an inherit element.
154 int X509v3_asid_add_inherit(ASIdentifiers
*asid
, int which
)
156 ASIdentifierChoice
**choice
;
161 choice
= &asid
->asnum
;
169 if (*choice
== NULL
) {
170 if ((*choice
= ASIdentifierChoice_new()) == NULL
)
172 if (((*choice
)->u
.inherit
= ASN1_NULL_new()) == NULL
)
174 (*choice
)->type
= ASIdentifierChoice_inherit
;
176 return (*choice
)->type
== ASIdentifierChoice_inherit
;
180 * Add an ID or range to an ASIdentifierChoice.
182 int X509v3_asid_add_id_or_range(ASIdentifiers
*asid
,
183 int which
, ASN1_INTEGER
*min
, ASN1_INTEGER
*max
)
185 ASIdentifierChoice
**choice
;
191 choice
= &asid
->asnum
;
199 if (*choice
!= NULL
&& (*choice
)->type
== ASIdentifierChoice_inherit
)
201 if (*choice
== NULL
) {
202 if ((*choice
= ASIdentifierChoice_new()) == NULL
)
204 (*choice
)->u
.asIdsOrRanges
= sk_ASIdOrRange_new(ASIdOrRange_cmp
);
205 if ((*choice
)->u
.asIdsOrRanges
== NULL
)
207 (*choice
)->type
= ASIdentifierChoice_asIdsOrRanges
;
209 if ((aor
= ASIdOrRange_new()) == NULL
)
212 aor
->type
= ASIdOrRange_id
;
215 aor
->type
= ASIdOrRange_range
;
216 if ((aor
->u
.range
= ASRange_new()) == NULL
)
218 ASN1_INTEGER_free(aor
->u
.range
->min
);
219 aor
->u
.range
->min
= min
;
220 ASN1_INTEGER_free(aor
->u
.range
->max
);
221 aor
->u
.range
->max
= max
;
223 if (!(sk_ASIdOrRange_push((*choice
)->u
.asIdsOrRanges
, aor
)))
228 ASIdOrRange_free(aor
);
233 * Extract min and max values from an ASIdOrRange.
235 static int extract_min_max(ASIdOrRange
*aor
,
236 ASN1_INTEGER
**min
, ASN1_INTEGER
**max
)
238 if (!ossl_assert(aor
!= NULL
))
245 case ASIdOrRange_range
:
246 *min
= aor
->u
.range
->min
;
247 *max
= aor
->u
.range
->max
;
255 * Check whether an ASIdentifierChoice is in canonical form.
257 static int ASIdentifierChoice_is_canonical(ASIdentifierChoice
*choice
)
259 ASN1_INTEGER
*a_max_plus_one
= NULL
;
265 * Empty element or inheritance is canonical.
267 if (choice
== NULL
|| choice
->type
== ASIdentifierChoice_inherit
)
271 * If not a list, or if empty list, it's broken.
273 if (choice
->type
!= ASIdentifierChoice_asIdsOrRanges
||
274 sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
) == 0)
278 * It's a list, check it.
280 for (i
= 0; i
< sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
) - 1; i
++) {
281 ASIdOrRange
*a
= sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
);
282 ASIdOrRange
*b
= sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
+ 1);
283 ASN1_INTEGER
*a_min
= NULL
, *a_max
= NULL
, *b_min
= NULL
, *b_max
=
286 if (!extract_min_max(a
, &a_min
, &a_max
)
287 || !extract_min_max(b
, &b_min
, &b_max
))
291 * Punt misordered list, overlapping start, or inverted range.
293 if (ASN1_INTEGER_cmp(a_min
, b_min
) >= 0 ||
294 ASN1_INTEGER_cmp(a_min
, a_max
) > 0 ||
295 ASN1_INTEGER_cmp(b_min
, b_max
) > 0)
299 * Calculate a_max + 1 to check for adjacency.
301 if ((bn
== NULL
&& (bn
= BN_new()) == NULL
) ||
302 ASN1_INTEGER_to_BN(a_max
, bn
) == NULL
||
303 !BN_add_word(bn
, 1)) {
304 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
308 if ((a_max_plus_one
=
309 BN_to_ASN1_INTEGER(bn
, orig
= a_max_plus_one
)) == NULL
) {
310 a_max_plus_one
= orig
;
311 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
316 * Punt if adjacent or overlapping.
318 if (ASN1_INTEGER_cmp(a_max_plus_one
, b_min
) >= 0)
323 * Check for inverted range.
325 i
= sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
) - 1;
327 ASIdOrRange
*a
= sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
);
328 ASN1_INTEGER
*a_min
, *a_max
;
329 if (a
!= NULL
&& a
->type
== ASIdOrRange_range
) {
330 if (!extract_min_max(a
, &a_min
, &a_max
)
331 || ASN1_INTEGER_cmp(a_min
, a_max
) > 0)
339 ASN1_INTEGER_free(a_max_plus_one
);
345 * Check whether an ASIdentifier extension is in canonical form.
347 int X509v3_asid_is_canonical(ASIdentifiers
*asid
)
349 return (asid
== NULL
||
350 (ASIdentifierChoice_is_canonical(asid
->asnum
) &&
351 ASIdentifierChoice_is_canonical(asid
->rdi
)));
355 * Whack an ASIdentifierChoice into canonical form.
357 static int ASIdentifierChoice_canonize(ASIdentifierChoice
*choice
)
359 ASN1_INTEGER
*a_max_plus_one
= NULL
;
365 * Nothing to do for empty element or inheritance.
367 if (choice
== NULL
|| choice
->type
== ASIdentifierChoice_inherit
)
371 * If not a list, or if empty list, it's broken.
373 if (choice
->type
!= ASIdentifierChoice_asIdsOrRanges
||
374 sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
) == 0) {
375 ERR_raise(ERR_LIB_X509V3
, X509V3_R_EXTENSION_VALUE_ERROR
);
380 * We have a non-empty list. Sort it.
382 sk_ASIdOrRange_sort(choice
->u
.asIdsOrRanges
);
385 * Now check for errors and suboptimal encoding, rejecting the
386 * former and fixing the latter.
388 for (i
= 0; i
< sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
) - 1; i
++) {
389 ASIdOrRange
*a
= sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
);
390 ASIdOrRange
*b
= sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
+ 1);
391 ASN1_INTEGER
*a_min
= NULL
, *a_max
= NULL
, *b_min
= NULL
, *b_max
=
394 if (!extract_min_max(a
, &a_min
, &a_max
)
395 || !extract_min_max(b
, &b_min
, &b_max
))
399 * Make sure we're properly sorted (paranoia).
401 if (!ossl_assert(ASN1_INTEGER_cmp(a_min
, b_min
) <= 0))
405 * Punt inverted ranges.
407 if (ASN1_INTEGER_cmp(a_min
, a_max
) > 0 ||
408 ASN1_INTEGER_cmp(b_min
, b_max
) > 0)
412 * Check for overlaps.
414 if (ASN1_INTEGER_cmp(a_max
, b_min
) >= 0) {
415 ERR_raise(ERR_LIB_X509V3
, X509V3_R_EXTENSION_VALUE_ERROR
);
420 * Calculate a_max + 1 to check for adjacency.
422 if ((bn
== NULL
&& (bn
= BN_new()) == NULL
) ||
423 ASN1_INTEGER_to_BN(a_max
, bn
) == NULL
||
424 !BN_add_word(bn
, 1)) {
425 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
429 if ((a_max_plus_one
=
430 BN_to_ASN1_INTEGER(bn
, orig
= a_max_plus_one
)) == NULL
) {
431 a_max_plus_one
= orig
;
432 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
437 * If a and b are adjacent, merge them.
439 if (ASN1_INTEGER_cmp(a_max_plus_one
, b_min
) == 0) {
443 if ((r
= OPENSSL_malloc(sizeof(*r
))) == NULL
) {
444 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
449 a
->type
= ASIdOrRange_range
;
452 case ASIdOrRange_range
:
453 ASN1_INTEGER_free(a
->u
.range
->max
);
454 a
->u
.range
->max
= b_max
;
461 case ASIdOrRange_range
:
462 b
->u
.range
->max
= NULL
;
466 (void)sk_ASIdOrRange_delete(choice
->u
.asIdsOrRanges
, i
+ 1);
473 * Check for final inverted range.
475 i
= sk_ASIdOrRange_num(choice
->u
.asIdsOrRanges
) - 1;
477 ASIdOrRange
*a
= sk_ASIdOrRange_value(choice
->u
.asIdsOrRanges
, i
);
478 ASN1_INTEGER
*a_min
, *a_max
;
479 if (a
!= NULL
&& a
->type
== ASIdOrRange_range
) {
480 if (!extract_min_max(a
, &a_min
, &a_max
)
481 || ASN1_INTEGER_cmp(a_min
, a_max
) > 0)
487 if (!ossl_assert(ASIdentifierChoice_is_canonical(choice
)))
493 ASN1_INTEGER_free(a_max_plus_one
);
499 * Whack an ASIdentifier extension into canonical form.
501 int X509v3_asid_canonize(ASIdentifiers
*asid
)
503 return (asid
== NULL
||
504 (ASIdentifierChoice_canonize(asid
->asnum
) &&
505 ASIdentifierChoice_canonize(asid
->rdi
)));
509 * v2i method for an ASIdentifier extension.
511 static void *v2i_ASIdentifiers(const struct v3_ext_method
*method
,
512 struct v3_ext_ctx
*ctx
,
513 STACK_OF(CONF_VALUE
) *values
)
515 ASN1_INTEGER
*min
= NULL
, *max
= NULL
;
516 ASIdentifiers
*asid
= NULL
;
519 if ((asid
= ASIdentifiers_new()) == NULL
) {
520 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
524 for (i
= 0; i
< sk_CONF_VALUE_num(values
); i
++) {
525 CONF_VALUE
*val
= sk_CONF_VALUE_value(values
, i
);
526 int i1
= 0, i2
= 0, i3
= 0, is_range
= 0, which
= 0;
529 * Figure out whether this is an AS or an RDI.
531 if (!v3_name_cmp(val
->name
, "AS")) {
532 which
= V3_ASID_ASNUM
;
533 } else if (!v3_name_cmp(val
->name
, "RDI")) {
536 ERR_raise(ERR_LIB_X509V3
, X509V3_R_EXTENSION_NAME_ERROR
);
537 X509V3_conf_add_error_name_value(val
);
542 * Handle inheritance.
544 if (strcmp(val
->value
, "inherit") == 0) {
545 if (X509v3_asid_add_inherit(asid
, which
))
547 ERR_raise(ERR_LIB_X509V3
, X509V3_R_INVALID_INHERITANCE
);
548 X509V3_conf_add_error_name_value(val
);
553 * Number, range, or mistake, pick it apart and figure out which.
555 i1
= strspn(val
->value
, "0123456789");
556 if (val
->value
[i1
] == '\0') {
560 i2
= i1
+ strspn(val
->value
+ i1
, " \t");
561 if (val
->value
[i2
] != '-') {
562 ERR_raise(ERR_LIB_X509V3
, X509V3_R_INVALID_ASNUMBER
);
563 X509V3_conf_add_error_name_value(val
);
567 i2
= i2
+ strspn(val
->value
+ i2
, " \t");
568 i3
= i2
+ strspn(val
->value
+ i2
, "0123456789");
569 if (val
->value
[i3
] != '\0') {
570 ERR_raise(ERR_LIB_X509V3
, X509V3_R_INVALID_ASRANGE
);
571 X509V3_conf_add_error_name_value(val
);
577 * Syntax is ok, read and add it.
580 if (!X509V3_get_value_int(val
, &min
)) {
581 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
585 char *s
= OPENSSL_strdup(val
->value
);
587 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
591 min
= s2i_ASN1_INTEGER(NULL
, s
);
592 max
= s2i_ASN1_INTEGER(NULL
, s
+ i2
);
594 if (min
== NULL
|| max
== NULL
) {
595 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
598 if (ASN1_INTEGER_cmp(min
, max
) > 0) {
599 ERR_raise(ERR_LIB_X509V3
, X509V3_R_EXTENSION_VALUE_ERROR
);
603 if (!X509v3_asid_add_id_or_range(asid
, which
, min
, max
)) {
604 ERR_raise(ERR_LIB_X509V3
, ERR_R_MALLOC_FAILURE
);
611 * Canonize the result, then we're done.
613 if (!X509v3_asid_canonize(asid
))
618 ASIdentifiers_free(asid
);
619 ASN1_INTEGER_free(min
);
620 ASN1_INTEGER_free(max
);
627 const X509V3_EXT_METHOD v3_asid
= {
628 NID_sbgp_autonomousSysNum
, /* nid */
630 ASN1_ITEM_ref(ASIdentifiers
), /* template */
631 0, 0, 0, 0, /* old functions, ignored */
635 v2i_ASIdentifiers
, /* v2i */
636 i2r_ASIdentifiers
, /* i2r */
638 NULL
/* extension-specific data */
642 * Figure out whether extension uses inheritance.
644 int X509v3_asid_inherits(ASIdentifiers
*asid
)
646 return (asid
!= NULL
&&
647 ((asid
->asnum
!= NULL
&&
648 asid
->asnum
->type
== ASIdentifierChoice_inherit
) ||
649 (asid
->rdi
!= NULL
&&
650 asid
->rdi
->type
== ASIdentifierChoice_inherit
)));
654 * Figure out whether parent contains child.
656 static int asid_contains(ASIdOrRanges
*parent
, ASIdOrRanges
*child
)
658 ASN1_INTEGER
*p_min
= NULL
, *p_max
= NULL
, *c_min
= NULL
, *c_max
= NULL
;
661 if (child
== NULL
|| parent
== child
)
667 for (c
= 0; c
< sk_ASIdOrRange_num(child
); c
++) {
668 if (!extract_min_max(sk_ASIdOrRange_value(child
, c
), &c_min
, &c_max
))
671 if (p
>= sk_ASIdOrRange_num(parent
))
673 if (!extract_min_max(sk_ASIdOrRange_value(parent
, p
), &p_min
,
676 if (ASN1_INTEGER_cmp(p_max
, c_max
) < 0)
678 if (ASN1_INTEGER_cmp(p_min
, c_min
) > 0)
688 * Test whether a is a subset of b.
690 int X509v3_asid_subset(ASIdentifiers
*a
, ASIdentifiers
*b
)
695 !X509v3_asid_inherits(a
) &&
696 !X509v3_asid_inherits(b
) &&
697 asid_contains(b
->asnum
->u
.asIdsOrRanges
,
698 a
->asnum
->u
.asIdsOrRanges
) &&
699 asid_contains(b
->rdi
->u
.asIdsOrRanges
,
700 a
->rdi
->u
.asIdsOrRanges
)));
704 * Validation error handling via callback.
706 #define validation_err(_err_) \
709 ctx->error = _err_; \
710 ctx->error_depth = i; \
711 ctx->current_cert = x; \
712 ret = ctx->verify_cb(0, ctx); \
721 * Core code for RFC 3779 3.3 path validation.
723 static int asid_validate_path_internal(X509_STORE_CTX
*ctx
,
724 STACK_OF(X509
) *chain
,
727 ASIdOrRanges
*child_as
= NULL
, *child_rdi
= NULL
;
728 int i
, ret
= 1, inherit_as
= 0, inherit_rdi
= 0;
731 if (!ossl_assert(chain
!= NULL
&& sk_X509_num(chain
) > 0)
732 || !ossl_assert(ctx
!= NULL
|| ext
!= NULL
)
733 || !ossl_assert(ctx
== NULL
|| ctx
->verify_cb
!= NULL
)) {
735 ctx
->error
= X509_V_ERR_UNSPECIFIED
;
741 * Figure out where to start. If we don't have an extension to
742 * check, we're done. Otherwise, check canonical form and
743 * set up for walking up the chain.
750 x
= sk_X509_value(chain
, i
);
751 if ((ext
= x
->rfc3779_asid
) == NULL
)
754 if (!X509v3_asid_is_canonical(ext
))
755 validation_err(X509_V_ERR_INVALID_EXTENSION
);
756 if (ext
->asnum
!= NULL
) {
757 switch (ext
->asnum
->type
) {
758 case ASIdentifierChoice_inherit
:
761 case ASIdentifierChoice_asIdsOrRanges
:
762 child_as
= ext
->asnum
->u
.asIdsOrRanges
;
766 if (ext
->rdi
!= NULL
) {
767 switch (ext
->rdi
->type
) {
768 case ASIdentifierChoice_inherit
:
771 case ASIdentifierChoice_asIdsOrRanges
:
772 child_rdi
= ext
->rdi
->u
.asIdsOrRanges
;
778 * Now walk up the chain. Extensions must be in canonical form, no
779 * cert may list resources that its parent doesn't list.
781 for (i
++; i
< sk_X509_num(chain
); i
++) {
782 x
= sk_X509_value(chain
, i
);
783 if (!ossl_assert(x
!= NULL
)) {
785 ctx
->error
= X509_V_ERR_UNSPECIFIED
;
788 if (x
->rfc3779_asid
== NULL
) {
789 if (child_as
!= NULL
|| child_rdi
!= NULL
)
790 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
793 if (!X509v3_asid_is_canonical(x
->rfc3779_asid
))
794 validation_err(X509_V_ERR_INVALID_EXTENSION
);
795 if (x
->rfc3779_asid
->asnum
== NULL
&& child_as
!= NULL
) {
796 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
800 if (x
->rfc3779_asid
->asnum
!= NULL
&&
801 x
->rfc3779_asid
->asnum
->type
==
802 ASIdentifierChoice_asIdsOrRanges
) {
804 || asid_contains(x
->rfc3779_asid
->asnum
->u
.asIdsOrRanges
,
806 child_as
= x
->rfc3779_asid
->asnum
->u
.asIdsOrRanges
;
809 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
812 if (x
->rfc3779_asid
->rdi
== NULL
&& child_rdi
!= NULL
) {
813 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
817 if (x
->rfc3779_asid
->rdi
!= NULL
&&
818 x
->rfc3779_asid
->rdi
->type
== ASIdentifierChoice_asIdsOrRanges
) {
820 asid_contains(x
->rfc3779_asid
->rdi
->u
.asIdsOrRanges
,
822 child_rdi
= x
->rfc3779_asid
->rdi
->u
.asIdsOrRanges
;
825 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
831 * Trust anchor can't inherit.
833 if (!ossl_assert(x
!= NULL
)) {
835 ctx
->error
= X509_V_ERR_UNSPECIFIED
;
838 if (x
->rfc3779_asid
!= NULL
) {
839 if (x
->rfc3779_asid
->asnum
!= NULL
&&
840 x
->rfc3779_asid
->asnum
->type
== ASIdentifierChoice_inherit
)
841 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
842 if (x
->rfc3779_asid
->rdi
!= NULL
&&
843 x
->rfc3779_asid
->rdi
->type
== ASIdentifierChoice_inherit
)
844 validation_err(X509_V_ERR_UNNESTED_RESOURCE
);
851 #undef validation_err
854 * RFC 3779 3.3 path validation -- called from X509_verify_cert().
856 int X509v3_asid_validate_path(X509_STORE_CTX
*ctx
)
858 if (ctx
->chain
== NULL
859 || sk_X509_num(ctx
->chain
) == 0
860 || ctx
->verify_cb
== NULL
) {
861 ctx
->error
= X509_V_ERR_UNSPECIFIED
;
864 return asid_validate_path_internal(ctx
, ctx
->chain
, NULL
);
868 * RFC 3779 3.3 path validation of an extension.
869 * Test whether chain covers extension.
871 int X509v3_asid_validate_resource_set(STACK_OF(X509
) *chain
,
872 ASIdentifiers
*ext
, int allow_inheritance
)
876 if (chain
== NULL
|| sk_X509_num(chain
) == 0)
878 if (!allow_inheritance
&& X509v3_asid_inherits(ext
))
880 return asid_validate_path_internal(NULL
, chain
, ext
);
883 #endif /* OPENSSL_NO_RFC3779 */