Download raw body.
rpki-client: reimplement and fix cert inheritance checks
On Thu, Nov 12, 2026 at 09:07:50PM +0100, Theo Buehler wrote:
> This was supposed to be a very straightforward diff...
>
> The current implementations of x509_inherits() and x509_any_inherits()
> are a bit dumb because they re-parse the RFC 3779 extensions to figure
> out if all (or any of) the resources inherit. That's quite expensive.
>
> We have all this information already in struct cert, so let's use that.
>
> In cert.c we already have the strangely named cert_as_inherit() which
> requires the presence of AS resources and checks that the ASIdentifiers
> are marked inherit. (It should probably be called cert_ases_inherit())
>
> A similar approach works for IPAddrBlocks. The main observation is that
> inheritance applies to the entire address family. Since the IPAddrBlocks
> are sorted by AF of which there are two, we know that an inherit element
> comes at the start or the end of the cert->ips[] array. This leads to
> cheap and easy cert_all_ips_inherit() and cert_any_ip_inherits()
> implementations.
>
> So far, so good. RFC 9286, section 5.1, has this requirement (point 2):
>
> This EE certificate MUST describe its Internet Number Resources
> (INRs) using the "inherit" attribute, rather than an explicit
> description of a resource set (see [RFC3779]). (RPs are required
> to verify this.)
>
> x509_inherits() took this (or its predecessor in RFC 6486) to mean that
> both types of RFC 3779 resources must be present and use the inherit
> attribute.
>
> 1. This has worked fine so far and to our knowledge nobody has issued a
> manifest EE cert with only one type of resources.
>
> 2. There are over 25k CAs (most of them of course issuing manifests)
> that only have one type of resources.
>
> 3. In order to validate a resource certificate per RFC 6487, the entire
> validating chain must have the relevant RFC 3779 resources.
>
> Point 3 means that none of CAs in point 2 could possibly issue a valid
> manifest EE cert with both types of resources. This remained hidden
> because both the path validation in libcrypto and the path validation
> we have in rpki-client (and all the other RFC 3779 validators out there)
> used to accept this due to bugs and now keep accepting it for backward
> compatibility.
>
> The below implementation relaxes the implementation of cert_inherit()
> to require the inheritance of all resources that are present, without
> requiring that both IPAddrBlocks and ASIdentifiers are present.
> That one of cert->num_ips > 0 and cert->num_ases > 0 is true is enforced
> by cert_parse_extensions() but I preferred to make this explicit.
>
> Also add a check that IPv4 precedes IPv6 if both are present. A check
> which somehow was forgotten.
The description is more complex then the code :)
OK claudio@
> Index: cert.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/cert.c,v
> diff -u -p -r1.255 cert.c
> --- cert.c 10 Nov 2026 11:04:01 -0000 1.255
> +++ cert.c 12 Nov 2026 18:38:15 -0000
> @@ -1090,6 +1090,38 @@ cert_policies(const char *fn, struct cer
> }
>
> /*
> + * The inherit element applies to an entire AF. We have IPv4 and/or IPv6,
> + * so inherit elements are at the start of cert->ips[] and/or at the end.
> + */
> +
> +static int
> +cert_all_ips_inherit(const struct cert *cert)
> +{
> + if (cert->num_ips == 1)
> + return cert->ips[0].type == CERT_IP_INHERIT;
> +
> + if (cert->num_ips == 2)
> + return cert->ips[0].type == CERT_IP_INHERIT &&
> + cert->ips[1].type == CERT_IP_INHERIT;
> +
> + return 0;
> +}
> +
> +static int
> +cert_any_ip_inherits(const struct cert *cert)
> +{
> + if (cert->num_ips == 0)
> + return 0;
> +
> + if (cert->ips[0].type == CERT_IP_INHERIT)
> + return 1;
> + if (cert->ips[cert->num_ips - 1].type == CERT_IP_INHERIT)
> + return 1;
> +
> + return 0;
> +}
> +
> +/*
> * Parse an IP Resources X.509v3 extension, RFC 6487 4.8.10, with
> * syntax documented in RFC 3779 starting in section 2.2.
> * Returns zero on failure, non-zero on success.
> @@ -1145,6 +1177,25 @@ cert_has_one_as(const struct cert *cert)
> return cert->ases[0].type == CERT_AS_ID;
> }
>
> +int
> +cert_inherits(const struct cert *cert)
> +{
> + /* Need one type of resources */
> + if (cert->num_ips == 0 && cert->num_ases == 0)
> + return 0;
> + if (cert->num_ips > 0 && !cert_all_ips_inherit(cert))
> + return 0;
> + if (cert->num_ases > 0 && !cert_as_inherit(cert))
> + return 0;
> + return 1;
> +}
> +
> +int
> +cert_any_inherits(const struct cert *cert)
> +{
> + return cert_any_ip_inherits(cert) || cert_as_inherit(cert);
> +}
> +
> /*
> * Parse an AS Resources X.509v3 extension, RFC 6487 4.8.11, with
> * syntax documented in RFC 3779 starting in section 3.2.
> @@ -1433,7 +1484,7 @@ cert_parse_extensions(const char *fn, st
> }
>
> if (cert->purpose == CERT_PURPOSE_TA) {
> - if (x509_any_inherits(cert->x509)) {
> + if (cert_any_inherits(cert)) {
> warnx("%s: RFC 8630, 2.3: Trust Anchor INRs "
> "must not inherit", fn);
> goto out;
> @@ -2015,7 +2066,7 @@ auth_insert(const char *fn, struct auth_
>
> na->issuer = issuer;
> na->cert = cert;
> - na->any_inherits = x509_any_inherits(cert->x509);
> + na->any_inherits = cert_any_inherits(cert);
>
> if (RB_INSERT(auth_tree, auths, na) != NULL)
> errx(1, "auth tree corrupted");
> Index: extern.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v
> diff -u -p -r1.325 extern.h
> --- extern.h 12 Nov 2026 16:15:29 -0000 1.325
> +++ extern.h 12 Nov 2026 17:30:32 -0000
> @@ -779,6 +779,8 @@ struct cert *cert_parse_filemode(const c
> struct cert *ta_validate(const char *, struct cert *, const unsigned char *,
> size_t);
> struct cert *cert_read(struct ibuf *);
> +int cert_any_inherits(const struct cert *);
> +int cert_inherits(const struct cert *);
> int cert_has_one_as(const struct cert *);
> void cert_insert_brks(struct brk_tree *, struct cert *);
>
> @@ -1025,8 +1027,6 @@ int x509_valid_serial(const char *, co
> int x509_check_tbs_sigalg(const char *, const X509_ALGOR *);
> int x509_location(const char *, const char *, GENERAL_NAME *,
> char **);
> -int x509_inherits(X509 *);
> -int x509_any_inherits(X509 *);
> int x509_valid_subject_name(const char *, const X509_NAME *);
> int x509_valid_issuer_name(const char *, const X509_NAME *);
> time_t x509_find_expires(time_t, struct auth *, struct crl *);
> Index: ip.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/ip.c,v
> diff -u -p -r1.40 ip.c
> --- ip.c 9 May 2026 01:42:30 -0000 1.40
> +++ ip.c 12 Nov 2026 17:26:28 -0000
> @@ -521,6 +521,11 @@ sbgp_parse_ipaddrblocks(const char *fn,
>
> switch (afi) {
> case AFI_IPV4:
> + if (ipv6_seen) {
> + warnx("%s: RFC 3779 section 2.2.3.3: "
> + "IPv6 must not precede IPv4", fn);
> + goto out;
> + }
> if (ipv4_seen++ > 0) {
> warnx("%s: RFC 6487 section 4.8.10: "
> "IPv4 appears twice", fn);
> Index: mft.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/mft.c,v
> diff -u -p -r1.150 mft.c
> --- mft.c 11 Nov 2026 12:27:56 -0000 1.150
> +++ mft.c 12 Nov 2026 17:26:28 -0000
> @@ -381,7 +381,7 @@ mft_cert_info(const char *fn, void *obj,
> struct mft *mft = obj;
> char *crlfile;
>
> - if (!x509_inherits(cert->x509)) {
> + if (!cert_inherits(cert)) {
> warnx("%s: RFC 3779 extensions not set to inherit", fn);
> return 0;
> }
> Index: roa.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/roa.c,v
> diff -u -p -r1.97 roa.c
> --- roa.c 12 Nov 2026 16:14:32 -0000 1.97
> +++ roa.c 12 Nov 2026 17:26:28 -0000
> @@ -269,7 +269,7 @@ roa_parse_econtent(const char *fn, void
> static int
> roa_cert_info(const char *fn, void *obj, const struct cert *cert)
> {
> - if (x509_any_inherits(cert->x509)) {
> + if (cert_any_inherits(cert)) {
> warnx("%s: inherit elements not allowed in EE cert", fn);
> return 0;
> }
> Index: rsc.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/rsc.c,v
> diff -u -p -r1.51 rsc.c
> --- rsc.c 12 Nov 2026 16:14:32 -0000 1.51
> +++ rsc.c 12 Nov 2026 17:26:28 -0000
> @@ -343,7 +343,7 @@ rsc_parse_econtent(const char *fn, void
> static int
> rsc_cert_info(const char *fn, void *obj, const struct cert *cert)
> {
> - if (x509_any_inherits(cert->x509)) {
> + if (cert_any_inherits(cert)) {
> warnx("%s: inherit elements not allowed in EE cert", fn);
> return 0;
> }
> Index: spl.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/spl.c,v
> diff -u -p -r1.23 spl.c
> --- spl.c 12 Nov 2026 16:14:32 -0000 1.23
> +++ spl.c 12 Nov 2026 17:26:28 -0000
> @@ -213,7 +213,7 @@ spl_parse_econtent(const char *fn, void
> static int
> spl_cert_info(const char *fn, void *obj, const struct cert *cert)
> {
> - if (x509_any_inherits(cert->x509)) {
> + if (cert_any_inherits(cert)) {
> warnx("%s: inherit elements not allowed in EE cert", fn);
> return 0;
> }
> Index: tak.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/tak.c,v
> diff -u -p -r1.35 tak.c
> --- tak.c 15 Oct 2026 20:54:00 -0000 1.35
> +++ tak.c 12 Nov 2026 17:26:28 -0000
> @@ -187,7 +187,7 @@ tak_parse_econtent(const char *fn, void
> static int
> tak_cert_info(const char *fn, void *obj, const struct cert *cert)
> {
> - if (!x509_inherits(cert->x509)) {
> + if (!cert_inherits(cert)) {
> warnx("%s: RFC 3779 extension not set to inherit", fn);
> return 0;
> }
> Index: x509.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/x509.c,v
> diff -u -p -r1.139 x509.c
> --- x509.c 3 Nov 2026 14:58:42 -0000 1.139
> +++ x509.c 12 Nov 2026 17:26:28 -0000
> @@ -202,87 +202,6 @@ x509_pubkey_get_ski(X509_PUBKEY *pubkey,
> }
>
> /*
> - * Check whether all RFC 3779 extensions are set to inherit.
> - * Return 1 if both AS & IP are set to inherit.
> - * Return 0 on failure (such as missing extensions or no inheritance).
> - */
> -int
> -x509_inherits(X509 *x)
> -{
> - STACK_OF(IPAddressFamily) *addrblk = NULL;
> - ASIdentifiers *asidentifiers = NULL;
> - const IPAddressFamily *af;
> - int crit, i, rc = 0;
> -
> - addrblk = X509_get_ext_d2i(x, NID_sbgp_ipAddrBlock, &crit, NULL);
> - if (addrblk == NULL) {
> - if (crit != -1)
> - warnx("error parsing ipAddrBlocks");
> - goto out;
> - }
> -
> - /*
> - * Check by hand, since X509v3_addr_inherits() success only means that
> - * at least one address family inherits, not all of them.
> - */
> - for (i = 0; i < sk_IPAddressFamily_num(addrblk); i++) {
> - af = sk_IPAddressFamily_value(addrblk, i);
> - if (af->ipAddressChoice->type != IPAddressChoice_inherit)
> - goto out;
> - }
> -
> - asidentifiers = X509_get_ext_d2i(x, NID_sbgp_autonomousSysNum, NULL,
> - NULL);
> - if (asidentifiers == NULL) {
> - if (crit != -1)
> - warnx("error parsing asIdentifiers");
> - goto out;
> - }
> -
> - /* We need to have AS numbers and don't want RDIs. */
> - if (asidentifiers->asnum == NULL || asidentifiers->rdi != NULL)
> - goto out;
> - if (!X509v3_asid_inherits(asidentifiers))
> - goto out;
> -
> - rc = 1;
> - out:
> - ASIdentifiers_free(asidentifiers);
> - sk_IPAddressFamily_pop_free(addrblk, IPAddressFamily_free);
> - return rc;
> -}
> -
> -/*
> - * Check whether at least one RFC 3779 extension is set to inherit.
> - * Return 1 if an inherit element is encountered in AS or IP.
> - * Return 0 otherwise.
> - */
> -int
> -x509_any_inherits(X509 *x)
> -{
> - STACK_OF(IPAddressFamily) *addrblk = NULL;
> - ASIdentifiers *asidentifiers = NULL;
> - int crit, rc = 0;
> -
> - addrblk = X509_get_ext_d2i(x, NID_sbgp_ipAddrBlock, &crit, NULL);
> - if (addrblk == NULL && crit != -1)
> - warnx("error parsing ipAddrBlocks");
> - if (X509v3_addr_inherits(addrblk))
> - rc = 1;
> -
> - asidentifiers = X509_get_ext_d2i(x, NID_sbgp_autonomousSysNum, &crit,
> - NULL);
> - if (asidentifiers == NULL && crit != -1)
> - warnx("error parsing asIdentifiers");
> - if (X509v3_asid_inherits(asidentifiers))
> - rc = 1;
> -
> - ASIdentifiers_free(asidentifiers);
> - sk_IPAddressFamily_pop_free(addrblk, IPAddressFamily_free);
> - return rc;
> -}
> -
> -/*
> * Convert passed ASN1_TIME to time_t *t.
> * Returns 1 on success and 0 on failure.
> */
>
--
:wq Claudio
rpki-client: reimplement and fix cert inheritance checks