Fixes #168.
}
static int
-handle_ip_extension(X509_EXTENSION *ext, struct resources *resources,
- bool allow_inherit)
+handle_ip_extension(X509_EXTENSION *ext, struct resources *resources, int flags)
{
ASN1_OCTET_STRING *string;
struct IPAddrBlocks *blocks;
}
for (i = 0; i < blocks->list.count && !error; i++)
- error = resources_add_ip(resources, blocks->list.array[i],
- allow_inherit);
+ error = resources_add_ip(resources, blocks->list.array[i], flags);
end:
ASN_STRUCT_FREE(asn_DEF_IPAddrBlocks, blocks);
static int
handle_asn_extension(X509_EXTENSION *ext, struct resources *resources,
- bool allow_inherit)
+ int flags)
{
ASN1_OCTET_STRING *string;
struct ASIdentifiers *ids;
if (error)
return error;
- error = resources_add_asn(resources, ids, allow_inherit);
+ error = resources_add_asn(resources, ids, flags);
ASN_STRUCT_FREE(asn_DEF_ASIdentifiers, ids);
return error;
{
int allowed_ip_nid = NID_undef;
int allowed_as_nid = NID_undef;
- bool allow_inherit = true;
+ int flags = RF_ALLOW_ALL;
int nid_ip1 = NID_sbgp_ipAddrBlock;
int nid_ip2 = nid_ipAddrBlocksv2();
case RPKI_POLICY_RFC8360:
allowed_ip_nid = nid_ip2;
}
- allow_inherit = false;
+ flags &= ~RF_ALLOW_INHERIT;
break;
case EET_ASPA:
switch (resources_get_policy(resources)) {
case RPKI_POLICY_RFC8360:
allowed_as_nid = nid_as2;
}
- allow_inherit = false;
+ flags = 0;
break;
case EET_MFT:
case EET_GBR:
if (extnid != allowed_ip_nid)
return pr_val_err("Found an unexpected IP Resources extension.");
- error = handle_ip_extension(ext, resources, allow_inherit);
+ error = handle_ip_extension(ext, resources, flags);
if (error)
return error;
allowed_ip_nid = NID_undef;
if (extnid != allowed_as_nid)
return pr_val_err("Found an unexpected AS Resources extension.");
- error = handle_asn_extension(ext, resources, allow_inherit);
+ error = handle_asn_extension(ext, resources, flags);
if (error)
return error;
allowed_as_nid = NID_undef;
int
resources_add_ip(struct resources *resources, struct IPAddressFamily *obj,
- bool allow_inherit)
+ int flags)
{
int family;
case IPAddressChoice_PR_NOTHING:
break;
case IPAddressChoice_PR_inherit:
- return allow_inherit
+ return (flags & RF_ALLOW_INHERIT)
? inherit_aors(resources, family)
: pr_val_err("IP extension is not allowed to contain 'inherit' elements.");
case IPAddressChoice_PR_addressesOrRanges:
}
static int
-add_asior(struct resources *resources, struct ASIdOrRange *obj)
+add_asior(struct resources *resources, struct ASIdOrRange *obj, int flags)
{
struct resources *parent;
struct asn_range asns;
return add_asn(resources, &asns, parent);
case ASIdOrRange_PR_range:
+ if ((flags & RF_ALLOW_RANGES) == 0)
+ return pr_val_err("ASN extension is not allowed to contain 'range' elements.");
error = ASId2u32(&obj->choice.range.min, &asns.min);
if (error)
return error;
}
static int
-add_asiors(struct resources *resources, struct ASIdentifiers *ids)
+add_asiors(struct resources *resources, struct ASIdentifiers *ids, int flags)
{
struct ASIdentifierChoice__asIdsOrRanges *iors;
int i;
if (iors->list.count == 0)
return pr_val_err("AS extension's set of AS number records is empty.");
+ if ((flags & RF_ALLOW_MULTIPLE) == 0 && iors->list.count != 1)
+ return pr_val_err("AS resources list more than one ASIdOrRange.");
+
for (i = 0; i < iors->list.count; i++) {
- error = add_asior(resources, iors->list.array[i]);
+ error = add_asior(resources, iors->list.array[i], flags);
if (error)
return error;
}
int
resources_add_asn(struct resources *resources, struct ASIdentifiers *ids,
- bool allow_inherit)
+ int flags)
{
if (ids->asnum == NULL)
return pr_val_err("ASN extension lacks 'asnum' element.");
switch (ids->asnum->present) {
case ASIdentifierChoice_PR_inherit:
- if (!allow_inherit)
+ if ((flags & RF_ALLOW_INHERIT) == 0)
return pr_val_err("ASN extension is not allowed to contain 'inherit' elements.");
return inherit_asiors(resources);
case ASIdentifierChoice_PR_asIdsOrRanges:
- return add_asiors(resources, ids);
+ return add_asiors(resources, ids, flags);
case ASIdentifierChoice_PR_NOTHING:
break;
}
struct resources *resources_create(enum rpki_policy, bool);
void resources_destroy(struct resources *);
-int resources_add_ip(struct resources *, struct IPAddressFamily *, bool);
-int resources_add_asn(struct resources *, struct ASIdentifiers *, bool);
+#define RF_ALLOW_INHERIT (1 << 0)
+#define RF_ALLOW_MULTIPLE (1 << 1)
+#define RF_ALLOW_RANGES (1 << 2)
+#define RF_ALLOW_ALL (RF_ALLOW_INHERIT | RF_ALLOW_MULTIPLE | RF_ALLOW_RANGES)
+
+int resources_add_ip(struct resources *, struct IPAddressFamily *, int);
+int resources_add_asn(struct resources *, struct ASIdentifiers *, int);
bool resources_empty(struct resources *);
bool resources_contains_asns(struct resources *, struct asn_range const *);