Upgrade to OpenSSL-0.9.8k.
[dragonfly.git] / crypto / openssl / crypto / x509v3 / v3_addr.c
CommitLineData
e40c9513
PA
1/*
2 * Contributed to the OpenSSL Project by the American Registry for
3 * Internet Numbers ("ARIN").
4 */
5/* ====================================================================
6 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 */
57
58/*
59 * Implementation of RFC 3779 section 2.2.
60 */
61
62#include <stdio.h>
63#include <stdlib.h>
75607dda 64
e40c9513
PA
65#include "cryptlib.h"
66#include <openssl/conf.h>
67#include <openssl/asn1.h>
68#include <openssl/asn1t.h>
69#include <openssl/buffer.h>
70#include <openssl/x509v3.h>
71
72#ifndef OPENSSL_NO_RFC3779
73
74/*
75 * OpenSSL ASN.1 template translation of RFC 3779 2.2.3.
76 */
77
78ASN1_SEQUENCE(IPAddressRange) = {
79 ASN1_SIMPLE(IPAddressRange, min, ASN1_BIT_STRING),
80 ASN1_SIMPLE(IPAddressRange, max, ASN1_BIT_STRING)
81} ASN1_SEQUENCE_END(IPAddressRange)
82
83ASN1_CHOICE(IPAddressOrRange) = {
84 ASN1_SIMPLE(IPAddressOrRange, u.addressPrefix, ASN1_BIT_STRING),
85 ASN1_SIMPLE(IPAddressOrRange, u.addressRange, IPAddressRange)
86} ASN1_CHOICE_END(IPAddressOrRange)
87
88ASN1_CHOICE(IPAddressChoice) = {
89 ASN1_SIMPLE(IPAddressChoice, u.inherit, ASN1_NULL),
90 ASN1_SEQUENCE_OF(IPAddressChoice, u.addressesOrRanges, IPAddressOrRange)
91} ASN1_CHOICE_END(IPAddressChoice)
92
93ASN1_SEQUENCE(IPAddressFamily) = {
94 ASN1_SIMPLE(IPAddressFamily, addressFamily, ASN1_OCTET_STRING),
95 ASN1_SIMPLE(IPAddressFamily, ipAddressChoice, IPAddressChoice)
96} ASN1_SEQUENCE_END(IPAddressFamily)
97
98ASN1_ITEM_TEMPLATE(IPAddrBlocks) =
99 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
100 IPAddrBlocks, IPAddressFamily)
101ASN1_ITEM_TEMPLATE_END(IPAddrBlocks)
102
103IMPLEMENT_ASN1_FUNCTIONS(IPAddressRange)
104IMPLEMENT_ASN1_FUNCTIONS(IPAddressOrRange)
105IMPLEMENT_ASN1_FUNCTIONS(IPAddressChoice)
106IMPLEMENT_ASN1_FUNCTIONS(IPAddressFamily)
107
108/*
109 * How much buffer space do we need for a raw address?
110 */
111#define ADDR_RAW_BUF_LEN 16
112
113/*
114 * What's the address length associated with this AFI?
115 */
116static int length_from_afi(const unsigned afi)
117{
118 switch (afi) {
119 case IANA_AFI_IPV4:
120 return 4;
121 case IANA_AFI_IPV6:
122 return 16;
123 default:
124 return 0;
125 }
126}
127
128/*
129 * Extract the AFI from an IPAddressFamily.
130 */
75607dda 131unsigned int v3_addr_get_afi(const IPAddressFamily *f)
e40c9513
PA
132{
133 return ((f != NULL &&
134 f->addressFamily != NULL &&
135 f->addressFamily->data != NULL)
136 ? ((f->addressFamily->data[0] << 8) |
137 (f->addressFamily->data[1]))
138 : 0);
139}
140
141/*
142 * Expand the bitstring form of an address into a raw byte array.
143 * At the moment this is coded for simplicity, not speed.
144 */
145static void addr_expand(unsigned char *addr,
146 const ASN1_BIT_STRING *bs,
147 const int length,
148 const unsigned char fill)
149{
75607dda 150 OPENSSL_assert(bs->length >= 0 && bs->length <= length);
e40c9513
PA
151 if (bs->length > 0) {
152 memcpy(addr, bs->data, bs->length);
153 if ((bs->flags & 7) != 0) {
154 unsigned char mask = 0xFF >> (8 - (bs->flags & 7));
155 if (fill == 0)
156 addr[bs->length - 1] &= ~mask;
157 else
158 addr[bs->length - 1] |= mask;
159 }
160 }
161 memset(addr + bs->length, fill, length - bs->length);
162}
163
164/*
165 * Extract the prefix length from a bitstring.
166 */
167#define addr_prefixlen(bs) ((int) ((bs)->length * 8 - ((bs)->flags & 7)))
168
169/*
170 * i2r handler for one address bitstring.
171 */
172static int i2r_address(BIO *out,
173 const unsigned afi,
174 const unsigned char fill,
175 const ASN1_BIT_STRING *bs)
176{
177 unsigned char addr[ADDR_RAW_BUF_LEN];
178 int i, n;
179
180 switch (afi) {
181 case IANA_AFI_IPV4:
182 addr_expand(addr, bs, 4, fill);
183 BIO_printf(out, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
184 break;
185 case IANA_AFI_IPV6:
186 addr_expand(addr, bs, 16, fill);
187 for (n = 16; n > 1 && addr[n-1] == 0x00 && addr[n-2] == 0x00; n -= 2)
188 ;
189 for (i = 0; i < n; i += 2)
190 BIO_printf(out, "%x%s", (addr[i] << 8) | addr[i+1], (i < 14 ? ":" : ""));
191 if (i < 16)
192 BIO_puts(out, ":");
75607dda
PA
193 if (i == 0)
194 BIO_puts(out, ":");
e40c9513
PA
195 break;
196 default:
197 for (i = 0; i < bs->length; i++)
198 BIO_printf(out, "%s%02x", (i > 0 ? ":" : ""), bs->data[i]);
199 BIO_printf(out, "[%d]", (int) (bs->flags & 7));
200 break;
201 }
202 return 1;
203}
204
205/*
206 * i2r handler for a sequence of addresses and ranges.
207 */
208static int i2r_IPAddressOrRanges(BIO *out,
209 const int indent,
210 const IPAddressOrRanges *aors,
211 const unsigned afi)
212{
213 int i;
214 for (i = 0; i < sk_IPAddressOrRange_num(aors); i++) {
215 const IPAddressOrRange *aor = sk_IPAddressOrRange_value(aors, i);
216 BIO_printf(out, "%*s", indent, "");
217 switch (aor->type) {
218 case IPAddressOrRange_addressPrefix:
219 if (!i2r_address(out, afi, 0x00, aor->u.addressPrefix))
220 return 0;
221 BIO_printf(out, "/%d\n", addr_prefixlen(aor->u.addressPrefix));
222 continue;
223 case IPAddressOrRange_addressRange:
224 if (!i2r_address(out, afi, 0x00, aor->u.addressRange->min))
225 return 0;
226 BIO_puts(out, "-");
227 if (!i2r_address(out, afi, 0xFF, aor->u.addressRange->max))
228 return 0;
229 BIO_puts(out, "\n");
230 continue;
231 }
232 }
233 return 1;
234}
235
236/*
237 * i2r handler for an IPAddrBlocks extension.
238 */
239static int i2r_IPAddrBlocks(X509V3_EXT_METHOD *method,
240 void *ext,
241 BIO *out,
242 int indent)
243{
244 const IPAddrBlocks *addr = ext;
245 int i;
246 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
247 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
75607dda 248 const unsigned int afi = v3_addr_get_afi(f);
e40c9513
PA
249 switch (afi) {
250 case IANA_AFI_IPV4:
251 BIO_printf(out, "%*sIPv4", indent, "");
252 break;
253 case IANA_AFI_IPV6:
254 BIO_printf(out, "%*sIPv6", indent, "");
255 break;
256 default:
257 BIO_printf(out, "%*sUnknown AFI %u", indent, "", afi);
258 break;
259 }
260 if (f->addressFamily->length > 2) {
261 switch (f->addressFamily->data[2]) {
262 case 1:
263 BIO_puts(out, " (Unicast)");
264 break;
265 case 2:
266 BIO_puts(out, " (Multicast)");
267 break;
268 case 3:
269 BIO_puts(out, " (Unicast/Multicast)");
270 break;
271 case 4:
272 BIO_puts(out, " (MPLS)");
273 break;
274 case 64:
275 BIO_puts(out, " (Tunnel)");
276 break;
277 case 65:
278 BIO_puts(out, " (VPLS)");
279 break;
280 case 66:
281 BIO_puts(out, " (BGP MDT)");
282 break;
283 case 128:
284 BIO_puts(out, " (MPLS-labeled VPN)");
285 break;
286 default:
287 BIO_printf(out, " (Unknown SAFI %u)",
288 (unsigned) f->addressFamily->data[2]);
289 break;
290 }
291 }
292 switch (f->ipAddressChoice->type) {
293 case IPAddressChoice_inherit:
294 BIO_puts(out, ": inherit\n");
295 break;
296 case IPAddressChoice_addressesOrRanges:
297 BIO_puts(out, ":\n");
298 if (!i2r_IPAddressOrRanges(out,
299 indent + 2,
300 f->ipAddressChoice->u.addressesOrRanges,
301 afi))
302 return 0;
303 break;
304 }
305 }
306 return 1;
307}
308
309/*
310 * Sort comparison function for a sequence of IPAddressOrRange
311 * elements.
312 */
313static int IPAddressOrRange_cmp(const IPAddressOrRange *a,
314 const IPAddressOrRange *b,
315 const int length)
316{
317 unsigned char addr_a[ADDR_RAW_BUF_LEN], addr_b[ADDR_RAW_BUF_LEN];
318 int prefixlen_a = 0;
319 int prefixlen_b = 0;
320 int r;
321
322 switch (a->type) {
323 case IPAddressOrRange_addressPrefix:
324 addr_expand(addr_a, a->u.addressPrefix, length, 0x00);
325 prefixlen_a = addr_prefixlen(a->u.addressPrefix);
326 break;
327 case IPAddressOrRange_addressRange:
328 addr_expand(addr_a, a->u.addressRange->min, length, 0x00);
329 prefixlen_a = length * 8;
330 break;
331 }
332
333 switch (b->type) {
334 case IPAddressOrRange_addressPrefix:
335 addr_expand(addr_b, b->u.addressPrefix, length, 0x00);
336 prefixlen_b = addr_prefixlen(b->u.addressPrefix);
337 break;
338 case IPAddressOrRange_addressRange:
339 addr_expand(addr_b, b->u.addressRange->min, length, 0x00);
340 prefixlen_b = length * 8;
341 break;
342 }
343
344 if ((r = memcmp(addr_a, addr_b, length)) != 0)
345 return r;
346 else
347 return prefixlen_a - prefixlen_b;
348}
349
350/*
351 * IPv4-specific closure over IPAddressOrRange_cmp, since sk_sort()
352 * comparision routines are only allowed two arguments.
353 */
354static int v4IPAddressOrRange_cmp(const IPAddressOrRange * const *a,
355 const IPAddressOrRange * const *b)
356{
357 return IPAddressOrRange_cmp(*a, *b, 4);
358}
359
360/*
361 * IPv6-specific closure over IPAddressOrRange_cmp, since sk_sort()
362 * comparision routines are only allowed two arguments.
363 */
364static int v6IPAddressOrRange_cmp(const IPAddressOrRange * const *a,
365 const IPAddressOrRange * const *b)
366{
367 return IPAddressOrRange_cmp(*a, *b, 16);
368}
369
370/*
371 * Calculate whether a range collapses to a prefix.
372 * See last paragraph of RFC 3779 2.2.3.7.
373 */
374static int range_should_be_prefix(const unsigned char *min,
375 const unsigned char *max,
376 const int length)
377{
378 unsigned char mask;
379 int i, j;
380
381 for (i = 0; i < length && min[i] == max[i]; i++)
382 ;
383 for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xFF; j--)
384 ;
385 if (i < j)
386 return -1;
387 if (i > j)
388 return i * 8;
389 mask = min[i] ^ max[i];
390 switch (mask) {
391 case 0x01: j = 7; break;
392 case 0x03: j = 6; break;
393 case 0x07: j = 5; break;
394 case 0x0F: j = 4; break;
395 case 0x1F: j = 3; break;
396 case 0x3F: j = 2; break;
397 case 0x7F: j = 1; break;
398 default: return -1;
399 }
400 if ((min[i] & mask) != 0 || (max[i] & mask) != mask)
401 return -1;
402 else
403 return i * 8 + j;
404}
405
406/*
407 * Construct a prefix.
408 */
409static int make_addressPrefix(IPAddressOrRange **result,
410 unsigned char *addr,
411 const int prefixlen)
412{
413 int bytelen = (prefixlen + 7) / 8, bitlen = prefixlen % 8;
414 IPAddressOrRange *aor = IPAddressOrRange_new();
415
416 if (aor == NULL)
417 return 0;
418 aor->type = IPAddressOrRange_addressPrefix;
419 if (aor->u.addressPrefix == NULL &&
420 (aor->u.addressPrefix = ASN1_BIT_STRING_new()) == NULL)
421 goto err;
422 if (!ASN1_BIT_STRING_set(aor->u.addressPrefix, addr, bytelen))
423 goto err;
424 aor->u.addressPrefix->flags &= ~7;
425 aor->u.addressPrefix->flags |= ASN1_STRING_FLAG_BITS_LEFT;
426 if (bitlen > 0) {
427 aor->u.addressPrefix->data[bytelen - 1] &= ~(0xFF >> bitlen);
428 aor->u.addressPrefix->flags |= 8 - bitlen;
429 }
430
431 *result = aor;
432 return 1;
433
434 err:
435 IPAddressOrRange_free(aor);
436 return 0;
437}
438
439/*
440 * Construct a range. If it can be expressed as a prefix,
441 * return a prefix instead. Doing this here simplifies
442 * the rest of the code considerably.
443 */
444static int make_addressRange(IPAddressOrRange **result,
445 unsigned char *min,
446 unsigned char *max,
447 const int length)
448{
449 IPAddressOrRange *aor;
450 int i, prefixlen;
451
452 if ((prefixlen = range_should_be_prefix(min, max, length)) >= 0)
453 return make_addressPrefix(result, min, prefixlen);
454
455 if ((aor = IPAddressOrRange_new()) == NULL)
456 return 0;
457 aor->type = IPAddressOrRange_addressRange;
75607dda 458 OPENSSL_assert(aor->u.addressRange == NULL);
e40c9513
PA
459 if ((aor->u.addressRange = IPAddressRange_new()) == NULL)
460 goto err;
461 if (aor->u.addressRange->min == NULL &&
462 (aor->u.addressRange->min = ASN1_BIT_STRING_new()) == NULL)
463 goto err;
464 if (aor->u.addressRange->max == NULL &&
465 (aor->u.addressRange->max = ASN1_BIT_STRING_new()) == NULL)
466 goto err;
467
468 for (i = length; i > 0 && min[i - 1] == 0x00; --i)
469 ;
470 if (!ASN1_BIT_STRING_set(aor->u.addressRange->min, min, i))
471 goto err;
472 aor->u.addressRange->min->flags &= ~7;
473 aor->u.addressRange->min->flags |= ASN1_STRING_FLAG_BITS_LEFT;
474 if (i > 0) {
475 unsigned char b = min[i - 1];
476 int j = 1;
477 while ((b & (0xFFU >> j)) != 0)
478 ++j;
479 aor->u.addressRange->min->flags |= 8 - j;
480 }
481
482 for (i = length; i > 0 && max[i - 1] == 0xFF; --i)
483 ;
484 if (!ASN1_BIT_STRING_set(aor->u.addressRange->max, max, i))
485 goto err;
486 aor->u.addressRange->max->flags &= ~7;
487 aor->u.addressRange->max->flags |= ASN1_STRING_FLAG_BITS_LEFT;
488 if (i > 0) {
489 unsigned char b = max[i - 1];
490 int j = 1;
491 while ((b & (0xFFU >> j)) != (0xFFU >> j))
492 ++j;
493 aor->u.addressRange->max->flags |= 8 - j;
494 }
495
496 *result = aor;
497 return 1;
498
499 err:
500 IPAddressOrRange_free(aor);
501 return 0;
502}
503
504/*
505 * Construct a new address family or find an existing one.
506 */
507static IPAddressFamily *make_IPAddressFamily(IPAddrBlocks *addr,
508 const unsigned afi,
509 const unsigned *safi)
510{
511 IPAddressFamily *f;
512 unsigned char key[3];
513 unsigned keylen;
514 int i;
515
516 key[0] = (afi >> 8) & 0xFF;
517 key[1] = afi & 0xFF;
518 if (safi != NULL) {
519 key[2] = *safi & 0xFF;
520 keylen = 3;
521 } else {
522 keylen = 2;
523 }
524
525 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
526 f = sk_IPAddressFamily_value(addr, i);
75607dda 527 OPENSSL_assert(f->addressFamily->data != NULL);
e40c9513
PA
528 if (f->addressFamily->length == keylen &&
529 !memcmp(f->addressFamily->data, key, keylen))
530 return f;
531 }
532
533 if ((f = IPAddressFamily_new()) == NULL)
534 goto err;
535 if (f->ipAddressChoice == NULL &&
536 (f->ipAddressChoice = IPAddressChoice_new()) == NULL)
537 goto err;
538 if (f->addressFamily == NULL &&
539 (f->addressFamily = ASN1_OCTET_STRING_new()) == NULL)
540 goto err;
541 if (!ASN1_OCTET_STRING_set(f->addressFamily, key, keylen))
542 goto err;
543 if (!sk_IPAddressFamily_push(addr, f))
544 goto err;
545
546 return f;
547
548 err:
549 IPAddressFamily_free(f);
550 return NULL;
551}
552
553/*
554 * Add an inheritance element.
555 */
556int v3_addr_add_inherit(IPAddrBlocks *addr,
557 const unsigned afi,
558 const unsigned *safi)
559{
560 IPAddressFamily *f = make_IPAddressFamily(addr, afi, safi);
561 if (f == NULL ||
562 f->ipAddressChoice == NULL ||
563 (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges &&
564 f->ipAddressChoice->u.addressesOrRanges != NULL))
565 return 0;
566 if (f->ipAddressChoice->type == IPAddressChoice_inherit &&
567 f->ipAddressChoice->u.inherit != NULL)
568 return 1;
569 if (f->ipAddressChoice->u.inherit == NULL &&
570 (f->ipAddressChoice->u.inherit = ASN1_NULL_new()) == NULL)
571 return 0;
572 f->ipAddressChoice->type = IPAddressChoice_inherit;
573 return 1;
574}
575
576/*
577 * Construct an IPAddressOrRange sequence, or return an existing one.
578 */
579static IPAddressOrRanges *make_prefix_or_range(IPAddrBlocks *addr,
580 const unsigned afi,
581 const unsigned *safi)
582{
583 IPAddressFamily *f = make_IPAddressFamily(addr, afi, safi);
584 IPAddressOrRanges *aors = NULL;
585
586 if (f == NULL ||
587 f->ipAddressChoice == NULL ||
588 (f->ipAddressChoice->type == IPAddressChoice_inherit &&
589 f->ipAddressChoice->u.inherit != NULL))
590 return NULL;
591 if (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges)
592 aors = f->ipAddressChoice->u.addressesOrRanges;
593 if (aors != NULL)
594 return aors;
595 if ((aors = sk_IPAddressOrRange_new_null()) == NULL)
596 return NULL;
597 switch (afi) {
598 case IANA_AFI_IPV4:
683caddb 599 (void)sk_IPAddressOrRange_set_cmp_func(aors, v4IPAddressOrRange_cmp);
e40c9513
PA
600 break;
601 case IANA_AFI_IPV6:
683caddb 602 (void)sk_IPAddressOrRange_set_cmp_func(aors, v6IPAddressOrRange_cmp);
e40c9513
PA
603 break;
604 }
605 f->ipAddressChoice->type = IPAddressChoice_addressesOrRanges;
606 f->ipAddressChoice->u.addressesOrRanges = aors;
607 return aors;
608}
609
610/*
611 * Add a prefix.
612 */
613int v3_addr_add_prefix(IPAddrBlocks *addr,
614 const unsigned afi,
615 const unsigned *safi,
616 unsigned char *a,
617 const int prefixlen)
618{
619 IPAddressOrRanges *aors = make_prefix_or_range(addr, afi, safi);
620 IPAddressOrRange *aor;
621 if (aors == NULL || !make_addressPrefix(&aor, a, prefixlen))
622 return 0;
623 if (sk_IPAddressOrRange_push(aors, aor))
624 return 1;
625 IPAddressOrRange_free(aor);
626 return 0;
627}
628
629/*
630 * Add a range.
631 */
632int v3_addr_add_range(IPAddrBlocks *addr,
633 const unsigned afi,
634 const unsigned *safi,
635 unsigned char *min,
636 unsigned char *max)
637{
638 IPAddressOrRanges *aors = make_prefix_or_range(addr, afi, safi);
639 IPAddressOrRange *aor;
640 int length = length_from_afi(afi);
641 if (aors == NULL)
642 return 0;
643 if (!make_addressRange(&aor, min, max, length))
644 return 0;
645 if (sk_IPAddressOrRange_push(aors, aor))
646 return 1;
647 IPAddressOrRange_free(aor);
648 return 0;
649}
650
651/*
652 * Extract min and max values from an IPAddressOrRange.
653 */
654static void extract_min_max(IPAddressOrRange *aor,
655 unsigned char *min,
656 unsigned char *max,
657 int length)
658{
75607dda 659 OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
e40c9513
PA
660 switch (aor->type) {
661 case IPAddressOrRange_addressPrefix:
662 addr_expand(min, aor->u.addressPrefix, length, 0x00);
663 addr_expand(max, aor->u.addressPrefix, length, 0xFF);
664 return;
665 case IPAddressOrRange_addressRange:
666 addr_expand(min, aor->u.addressRange->min, length, 0x00);
667 addr_expand(max, aor->u.addressRange->max, length, 0xFF);
668 return;
669 }
670}
671
672/*
673 * Public wrapper for extract_min_max().
674 */
675int v3_addr_get_range(IPAddressOrRange *aor,
676 const unsigned afi,
677 unsigned char *min,
678 unsigned char *max,
679 const int length)
680{
681 int afi_length = length_from_afi(afi);
682 if (aor == NULL || min == NULL || max == NULL ||
683 afi_length == 0 || length < afi_length ||
684 (aor->type != IPAddressOrRange_addressPrefix &&
685 aor->type != IPAddressOrRange_addressRange))
686 return 0;
687 extract_min_max(aor, min, max, afi_length);
688 return afi_length;
689}
690
691/*
692 * Sort comparision function for a sequence of IPAddressFamily.
693 *
694 * The last paragraph of RFC 3779 2.2.3.3 is slightly ambiguous about
695 * the ordering: I can read it as meaning that IPv6 without a SAFI
696 * comes before IPv4 with a SAFI, which seems pretty weird. The
697 * examples in appendix B suggest that the author intended the
698 * null-SAFI rule to apply only within a single AFI, which is what I
699 * would have expected and is what the following code implements.
700 */
701static int IPAddressFamily_cmp(const IPAddressFamily * const *a_,
702 const IPAddressFamily * const *b_)
703{
704 const ASN1_OCTET_STRING *a = (*a_)->addressFamily;
705 const ASN1_OCTET_STRING *b = (*b_)->addressFamily;
706 int len = ((a->length <= b->length) ? a->length : b->length);
707 int cmp = memcmp(a->data, b->data, len);
708 return cmp ? cmp : a->length - b->length;
709}
710
711/*
712 * Check whether an IPAddrBLocks is in canonical form.
713 */
714int v3_addr_is_canonical(IPAddrBlocks *addr)
715{
716 unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN];
717 unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN];
718 IPAddressOrRanges *aors;
719 int i, j, k;
720
721 /*
722 * Empty extension is cannonical.
723 */
724 if (addr == NULL)
725 return 1;
726
727 /*
728 * Check whether the top-level list is in order.
729 */
730 for (i = 0; i < sk_IPAddressFamily_num(addr) - 1; i++) {
731 const IPAddressFamily *a = sk_IPAddressFamily_value(addr, i);
732 const IPAddressFamily *b = sk_IPAddressFamily_value(addr, i + 1);
733 if (IPAddressFamily_cmp(&a, &b) >= 0)
734 return 0;
735 }
736
737 /*
738 * Top level's ok, now check each address family.
739 */
740 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
741 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
742 int length = length_from_afi(v3_addr_get_afi(f));
743
744 /*
745 * Inheritance is canonical. Anything other than inheritance or
746 * a SEQUENCE OF IPAddressOrRange is an ASN.1 error or something.
747 */
748 if (f == NULL || f->ipAddressChoice == NULL)
749 return 0;
750 switch (f->ipAddressChoice->type) {
751 case IPAddressChoice_inherit:
752 continue;
753 case IPAddressChoice_addressesOrRanges:
754 break;
755 default:
756 return 0;
757 }
758
759 /*
760 * It's an IPAddressOrRanges sequence, check it.
761 */
762 aors = f->ipAddressChoice->u.addressesOrRanges;
763 if (sk_IPAddressOrRange_num(aors) == 0)
764 return 0;
765 for (j = 0; j < sk_IPAddressOrRange_num(aors) - 1; j++) {
766 IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
767 IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, j + 1);
768
769 extract_min_max(a, a_min, a_max, length);
770 extract_min_max(b, b_min, b_max, length);
771
772 /*
773 * Punt misordered list, overlapping start, or inverted range.
774 */
775 if (memcmp(a_min, b_min, length) >= 0 ||
776 memcmp(a_min, a_max, length) > 0 ||
777 memcmp(b_min, b_max, length) > 0)
778 return 0;
779
780 /*
781 * Punt if adjacent or overlapping. Check for adjacency by
782 * subtracting one from b_min first.
783 */
784 for (k = length - 1; k >= 0 && b_min[k]-- == 0x00; k--)
785 ;
786 if (memcmp(a_max, b_min, length) >= 0)
787 return 0;
788
789 /*
790 * Check for range that should be expressed as a prefix.
791 */
792 if (a->type == IPAddressOrRange_addressRange &&
793 range_should_be_prefix(a_min, a_max, length) >= 0)
794 return 0;
795 }
796
797 /*
798 * Check final range to see if it should be a prefix.
799 */
800 j = sk_IPAddressOrRange_num(aors) - 1;
801 {
802 IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
803 if (a->type == IPAddressOrRange_addressRange) {
804 extract_min_max(a, a_min, a_max, length);
805 if (range_should_be_prefix(a_min, a_max, length) >= 0)
806 return 0;
807 }
808 }
809 }
810
811 /*
812 * If we made it through all that, we're happy.
813 */
814 return 1;
815}
816
817/*
818 * Whack an IPAddressOrRanges into canonical form.
819 */
820static int IPAddressOrRanges_canonize(IPAddressOrRanges *aors,
821 const unsigned afi)
822{
823 int i, j, length = length_from_afi(afi);
824
825 /*
826 * Sort the IPAddressOrRanges sequence.
827 */
828 sk_IPAddressOrRange_sort(aors);
829
830 /*
831 * Clean up representation issues, punt on duplicates or overlaps.
832 */
833 for (i = 0; i < sk_IPAddressOrRange_num(aors) - 1; i++) {
834 IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, i);
835 IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, i + 1);
836 unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN];
837 unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN];
838
839 extract_min_max(a, a_min, a_max, length);
840 extract_min_max(b, b_min, b_max, length);
841
842 /*
843 * Punt overlaps.
844 */
845 if (memcmp(a_max, b_min, length) >= 0)
846 return 0;
847
848 /*
849 * Merge if a and b are adjacent. We check for
850 * adjacency by subtracting one from b_min first.
851 */
852 for (j = length - 1; j >= 0 && b_min[j]-- == 0x00; j--)
853 ;
854 if (memcmp(a_max, b_min, length) == 0) {
855 IPAddressOrRange *merged;
856 if (!make_addressRange(&merged, a_min, b_max, length))
857 return 0;
858 sk_IPAddressOrRange_set(aors, i, merged);
683caddb 859 (void)sk_IPAddressOrRange_delete(aors, i + 1);
e40c9513
PA
860 IPAddressOrRange_free(a);
861 IPAddressOrRange_free(b);
862 --i;
863 continue;
864 }
865 }
866
867 return 1;
868}
869
870/*
871 * Whack an IPAddrBlocks extension into canonical form.
872 */
873int v3_addr_canonize(IPAddrBlocks *addr)
874{
875 int i;
876 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
877 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
878 if (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges &&
879 !IPAddressOrRanges_canonize(f->ipAddressChoice->u.addressesOrRanges,
880 v3_addr_get_afi(f)))
881 return 0;
882 }
730b1645 883 (void)sk_IPAddressFamily_set_cmp_func(addr, IPAddressFamily_cmp);
e40c9513 884 sk_IPAddressFamily_sort(addr);
75607dda 885 OPENSSL_assert(v3_addr_is_canonical(addr));
e40c9513
PA
886 return 1;
887}
888
889/*
890 * v2i handler for the IPAddrBlocks extension.
891 */
892static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
893 struct v3_ext_ctx *ctx,
894 STACK_OF(CONF_VALUE) *values)
895{
896 static const char v4addr_chars[] = "0123456789.";
897 static const char v6addr_chars[] = "0123456789.:abcdefABCDEF";
898 IPAddrBlocks *addr = NULL;
899 char *s = NULL, *t;
900 int i;
901
902 if ((addr = sk_IPAddressFamily_new(IPAddressFamily_cmp)) == NULL) {
903 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
904 return NULL;
905 }
906
907 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
908 CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
909 unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN];
910 unsigned afi, *safi = NULL, safi_;
911 const char *addr_chars;
912 int prefixlen, i1, i2, delim, length;
913
914 if ( !name_cmp(val->name, "IPv4")) {
915 afi = IANA_AFI_IPV4;
916 } else if (!name_cmp(val->name, "IPv6")) {
917 afi = IANA_AFI_IPV6;
918 } else if (!name_cmp(val->name, "IPv4-SAFI")) {
919 afi = IANA_AFI_IPV4;
920 safi = &safi_;
921 } else if (!name_cmp(val->name, "IPv6-SAFI")) {
922 afi = IANA_AFI_IPV6;
923 safi = &safi_;
924 } else {
925 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_NAME_ERROR);
926 X509V3_conf_err(val);
927 goto err;
928 }
929
930 switch (afi) {
931 case IANA_AFI_IPV4:
932 addr_chars = v4addr_chars;
933 break;
934 case IANA_AFI_IPV6:
935 addr_chars = v6addr_chars;
936 break;
937 }
938
939 length = length_from_afi(afi);
940
941 /*
942 * Handle SAFI, if any, and BUF_strdup() so we can null-terminate
943 * the other input values.
944 */
945 if (safi != NULL) {
946 *safi = strtoul(val->value, &t, 0);
947 t += strspn(t, " \t");
948 if (*safi > 0xFF || *t++ != ':') {
949 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_SAFI);
950 X509V3_conf_err(val);
951 goto err;
952 }
953 t += strspn(t, " \t");
954 s = BUF_strdup(t);
955 } else {
956 s = BUF_strdup(val->value);
957 }
958 if (s == NULL) {
959 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
960 goto err;
961 }
962
963 /*
964 * Check for inheritance. Not worth additional complexity to
965 * optimize this (seldom-used) case.
966 */
967 if (!strcmp(s, "inherit")) {
968 if (!v3_addr_add_inherit(addr, afi, safi)) {
969 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_INHERITANCE);
970 X509V3_conf_err(val);
971 goto err;
972 }
973 OPENSSL_free(s);
974 s = NULL;
975 continue;
976 }
977
978 i1 = strspn(s, addr_chars);
979 i2 = i1 + strspn(s + i1, " \t");
980 delim = s[i2++];
981 s[i1] = '\0';
982
983 if (a2i_ipadd(min, s) != length) {
984 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
985 X509V3_conf_err(val);
986 goto err;
987 }
988
989 switch (delim) {
990 case '/':
991 prefixlen = (int) strtoul(s + i2, &t, 10);
992 if (t == s + i2 || *t != '\0') {
993 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
994 X509V3_conf_err(val);
995 goto err;
996 }
997 if (!v3_addr_add_prefix(addr, afi, safi, min, prefixlen)) {
998 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
999 goto err;
1000 }
1001 break;
1002 case '-':
1003 i1 = i2 + strspn(s + i2, " \t");
1004 i2 = i1 + strspn(s + i1, addr_chars);
1005 if (i1 == i2 || s[i2] != '\0') {
1006 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
1007 X509V3_conf_err(val);
1008 goto err;
1009 }
1010 if (a2i_ipadd(max, s + i1) != length) {
1011 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
1012 X509V3_conf_err(val);
1013 goto err;
1014 }
1015 if (!v3_addr_add_range(addr, afi, safi, min, max)) {
1016 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
1017 goto err;
1018 }
1019 break;
1020 case '\0':
1021 if (!v3_addr_add_prefix(addr, afi, safi, min, length * 8)) {
1022 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
1023 goto err;
1024 }
1025 break;
1026 default:
1027 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
1028 X509V3_conf_err(val);
1029 goto err;
1030 }
1031
1032 OPENSSL_free(s);
1033 s = NULL;
1034 }
1035
1036 /*
1037 * Canonize the result, then we're done.
1038 */
1039 if (!v3_addr_canonize(addr))
1040 goto err;
1041 return addr;
1042
1043 err:
1044 OPENSSL_free(s);
1045 sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
1046 return NULL;
1047}
1048
1049/*
1050 * OpenSSL dispatch
1051 */
1052const X509V3_EXT_METHOD v3_addr = {
1053 NID_sbgp_ipAddrBlock, /* nid */
1054 0, /* flags */
1055 ASN1_ITEM_ref(IPAddrBlocks), /* template */
1056 0, 0, 0, 0, /* old functions, ignored */
1057 0, /* i2s */
1058 0, /* s2i */
1059 0, /* i2v */
1060 v2i_IPAddrBlocks, /* v2i */
1061 i2r_IPAddrBlocks, /* i2r */
1062 0, /* r2i */
1063 NULL /* extension-specific data */
1064};
1065
1066/*
1067 * Figure out whether extension sues inheritance.
1068 */
1069int v3_addr_inherits(IPAddrBlocks *addr)
1070{
1071 int i;
1072 if (addr == NULL)
1073 return 0;
1074 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
1075 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
1076 if (f->ipAddressChoice->type == IPAddressChoice_inherit)
1077 return 1;
1078 }
1079 return 0;
1080}
1081
1082/*
1083 * Figure out whether parent contains child.
1084 */
1085static int addr_contains(IPAddressOrRanges *parent,
1086 IPAddressOrRanges *child,
1087 int length)
1088{
1089 unsigned char p_min[ADDR_RAW_BUF_LEN], p_max[ADDR_RAW_BUF_LEN];
1090 unsigned char c_min[ADDR_RAW_BUF_LEN], c_max[ADDR_RAW_BUF_LEN];
1091 int p, c;
1092
1093 if (child == NULL || parent == child)
1094 return 1;
1095 if (parent == NULL)
1096 return 0;
1097
1098 p = 0;
1099 for (c = 0; c < sk_IPAddressOrRange_num(child); c++) {
1100 extract_min_max(sk_IPAddressOrRange_value(child, c),
1101 c_min, c_max, length);
1102 for (;; p++) {
1103 if (p >= sk_IPAddressOrRange_num(parent))
1104 return 0;
1105 extract_min_max(sk_IPAddressOrRange_value(parent, p),
1106 p_min, p_max, length);
1107 if (memcmp(p_max, c_max, length) < 0)
1108 continue;
1109 if (memcmp(p_min, c_min, length) > 0)
1110 return 0;
1111 break;
1112 }
1113 }
1114
1115 return 1;
1116}
1117
1118/*
1119 * Test whether a is a subset of b.
1120 */
1121int v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b)
1122{
1123 int i;
1124 if (a == NULL || a == b)
1125 return 1;
1126 if (b == NULL || v3_addr_inherits(a) || v3_addr_inherits(b))
1127 return 0;
683caddb 1128 (void)sk_IPAddressFamily_set_cmp_func(b, IPAddressFamily_cmp);
e40c9513
PA
1129 for (i = 0; i < sk_IPAddressFamily_num(a); i++) {
1130 IPAddressFamily *fa = sk_IPAddressFamily_value(a, i);
1131 int j = sk_IPAddressFamily_find(b, fa);
75607dda
PA
1132 IPAddressFamily *fb;
1133 fb = sk_IPAddressFamily_value(b, j);
1134 if (fb == NULL)
1135 return 0;
e40c9513
PA
1136 if (!addr_contains(fb->ipAddressChoice->u.addressesOrRanges,
1137 fa->ipAddressChoice->u.addressesOrRanges,
1138 length_from_afi(v3_addr_get_afi(fb))))
1139 return 0;
1140 }
1141 return 1;
1142}
1143
1144/*
1145 * Validation error handling via callback.
1146 */
1147#define validation_err(_err_) \
1148 do { \
1149 if (ctx != NULL) { \
1150 ctx->error = _err_; \
1151 ctx->error_depth = i; \
1152 ctx->current_cert = x; \
1153 ret = ctx->verify_cb(0, ctx); \
1154 } else { \
1155 ret = 0; \
1156 } \
1157 if (!ret) \
1158 goto done; \
1159 } while (0)
1160
1161/*
1162 * Core code for RFC 3779 2.3 path validation.
1163 */
1164static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
1165 STACK_OF(X509) *chain,
1166 IPAddrBlocks *ext)
1167{
1168 IPAddrBlocks *child = NULL;
1169 int i, j, ret = 1;
1170 X509 *x = NULL;
1171
75607dda
PA
1172 OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0);
1173 OPENSSL_assert(ctx != NULL || ext != NULL);
1174 OPENSSL_assert(ctx == NULL || ctx->verify_cb != NULL);
e40c9513
PA
1175
1176 /*
1177 * Figure out where to start. If we don't have an extension to
1178 * check, we're done. Otherwise, check canonical form and
1179 * set up for walking up the chain.
1180 */
1181 if (ext != NULL) {
1182 i = -1;
1183 } else {
1184 i = 0;
1185 x = sk_X509_value(chain, i);
75607dda 1186 OPENSSL_assert(x != NULL);
e40c9513
PA
1187 if ((ext = x->rfc3779_addr) == NULL)
1188 goto done;
1189 }
1190 if (!v3_addr_is_canonical(ext))
1191 validation_err(X509_V_ERR_INVALID_EXTENSION);
683caddb 1192 (void)sk_IPAddressFamily_set_cmp_func(ext, IPAddressFamily_cmp);
e40c9513
PA
1193 if ((child = sk_IPAddressFamily_dup(ext)) == NULL) {
1194 X509V3err(X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL, ERR_R_MALLOC_FAILURE);
1195 ret = 0;
1196 goto done;
1197 }
1198
1199 /*
1200 * Now walk up the chain. No cert may list resources that its
1201 * parent doesn't list.
1202 */
1203 for (i++; i < sk_X509_num(chain); i++) {
1204 x = sk_X509_value(chain, i);
75607dda 1205 OPENSSL_assert(x != NULL);
e40c9513
PA
1206 if (!v3_addr_is_canonical(x->rfc3779_addr))
1207 validation_err(X509_V_ERR_INVALID_EXTENSION);
1208 if (x->rfc3779_addr == NULL) {
1209 for (j = 0; j < sk_IPAddressFamily_num(child); j++) {
1210 IPAddressFamily *fc = sk_IPAddressFamily_value(child, j);
1211 if (fc->ipAddressChoice->type != IPAddressChoice_inherit) {
1212 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1213 break;
1214 }
1215 }
1216 continue;
1217 }
683caddb 1218 (void)sk_IPAddressFamily_set_cmp_func(x->rfc3779_addr, IPAddressFamily_cmp);
e40c9513
PA
1219 for (j = 0; j < sk_IPAddressFamily_num(child); j++) {
1220 IPAddressFamily *fc = sk_IPAddressFamily_value(child, j);
1221 int k = sk_IPAddressFamily_find(x->rfc3779_addr, fc);
1222 IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, k);
1223 if (fp == NULL) {
1224 if (fc->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) {
1225 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1226 break;
1227 }
1228 continue;
1229 }
1230 if (fp->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) {
1231 if (fc->ipAddressChoice->type == IPAddressChoice_inherit ||
1232 addr_contains(fp->ipAddressChoice->u.addressesOrRanges,
1233 fc->ipAddressChoice->u.addressesOrRanges,
1234 length_from_afi(v3_addr_get_afi(fc))))
1235 sk_IPAddressFamily_set(child, j, fp);
1236 else
1237 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1238 }
1239 }
1240 }
1241
1242 /*
1243 * Trust anchor can't inherit.
1244 */
1245 if (x->rfc3779_addr != NULL) {
1246 for (j = 0; j < sk_IPAddressFamily_num(x->rfc3779_addr); j++) {
1247 IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, j);
1248 if (fp->ipAddressChoice->type == IPAddressChoice_inherit &&
1249 sk_IPAddressFamily_find(child, fp) >= 0)
1250 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1251 }
1252 }
1253
1254 done:
1255 sk_IPAddressFamily_free(child);
1256 return ret;
1257}
1258
1259#undef validation_err
1260
1261/*
1262 * RFC 3779 2.3 path validation -- called from X509_verify_cert().
1263 */
1264int v3_addr_validate_path(X509_STORE_CTX *ctx)
1265{
1266 return v3_addr_validate_path_internal(ctx, ctx->chain, NULL);
1267}
1268
1269/*
1270 * RFC 3779 2.3 path validation of an extension.
1271 * Test whether chain covers extension.
1272 */
1273int v3_addr_validate_resource_set(STACK_OF(X509) *chain,
1274 IPAddrBlocks *ext,
1275 int allow_inheritance)
1276{
1277 if (ext == NULL)
1278 return 1;
1279 if (chain == NULL || sk_X509_num(chain) == 0)
1280 return 0;
1281 if (!allow_inheritance && v3_addr_inherits(ext))
1282 return 0;
1283 return v3_addr_validate_path_internal(NULL, chain, ext);
1284}
1285
1286#endif /* OPENSSL_NO_RFC3779 */