: false;
}
+static bool
+is_rsync_uri(GENERAL_NAME *name)
+{
+ return name->type == GEN_URI && is_rsync(name->d.GN_URI);
+}
+
static int
handle_rpkiManifest(ACCESS_DESCRIPTION *ad, struct rpki_uri *mft)
{
names = dp->distpoint->name.fullname;
for (i = 0; i < sk_GENERAL_NAME_num(names); i++) {
name = sk_GENERAL_NAME_value(names, i);
- if (name->type == GEN_URI && is_rsync(name->d.GN_URI)) {
+ if (is_rsync_uri(name)) {
/*
* Since we're parsing and validating the manifest's CRL
* at some point, I think that all we need to do now is
* later.
*/
error = ia5s2string(name->d.GN_URI, &refs->crldp);
- pr_debug("Certificate CRL: %s", refs->crldp);
goto end;
}
}
AUTHORITY_INFO_ACCESS *aia;
ACCESS_DESCRIPTION *ad;
int i;
+ int error;
aia = X509V3_EXT_d2i(ext);
if (aia == NULL)
return cannot_decode(&AIA);
+ /*
+ * RFC 6487:
+ * an rsync URI [RFC5781] MUST be specified with an accessMethod
+ * value of id-ad-caIssuers. (...) Other accessMethod URIs
+ * referencing the same object MAY also be included in the value
+ * sequence of this extension.
+ *
+ * It doesn't technically say that id-ad-caIssuers is reserved for RSYNC
+ * URIs, but it sure feels like it's the actual intention.
+ *
+ * But let's commit to the literal wording, which I think equals "there
+ * must be a caIssuers RSYNC URI, which must be correct (ie. equal the
+ * manifest's), and there can also be anything else."
+ */
for (i = 0; i < sk_ACCESS_DESCRIPTION_num(aia); i++) {
ad = sk_ACCESS_DESCRIPTION_value(aia, i);
- if (OBJ_obj2nid(ad->method) == NID_ad_ca_issuers) {
- if (ad->location->type != GEN_URI) {
- return pr_err("The AIA caIssuers is not an URI. (type: %d)",
- ad->location->type);
- }
-
+ /*
+ * TODO open the call hierarchy of location.
+ * All GEN_URIs should probably be handled the same.
+ */
+ if (OBJ_obj2nid(ad->method) == NID_ad_ca_issuers
+ && is_rsync_uri(ad->location)) {
/*
* Bringing the parent certificate's URI all the way
* over here is too much trouble, so do the handle_cdp()
* hack.
*/
-
- return ia5s2string(ad->location->d.GN_URI,
+ error = ia5s2string(ad->location->d.GN_URI,
&refs->caIssuers);
+ goto end;
}
}
+ error = pr_err("The certificate lacks a caIssuers RSYNC URI.");
+
+end:
AUTHORITY_INFO_ACCESS_free(aia);
- return 0;
+ return error;
}
static int
--- /dev/null
+#include "address.c"
+
+#include <check.h>
+#include <errno.h>
+#include <stdlib.h>
+
+static void
+test_range4(uint32_t min, uint32_t max, bool valid)
+{
+ struct ipv4_range range = {
+ .min.s_addr = htonl(min),
+ .max.s_addr = htonl(max),
+ };
+ ck_assert_int_eq(valid ? 0 : -EINVAL, check_encoding4(&range));
+}
+
+START_TEST(check_encoding4_test)
+{
+ test_range4(0x00000000, 0x00000000, false);
+ test_range4(0x12345678, 0x12345678, false);
+ test_range4(0xFFFFFFFF, 0xFFFFFFFF, false);
+ test_range4(0x00000000, 0xFFFFFFFF, false);
+ test_range4(0x00000000, 0x00000001, false);
+ test_range4(0x11000000, 0x11001000, true);
+ test_range4(0x11000000, 0x1100FFFF, false);
+ test_range4(0x11000000, 0x1100F1FF, true);
+
+}
+END_TEST
+
+static void
+test_range6(uint32_t a1a, uint32_t a1b, uint32_t a1c, uint32_t a1d,
+ uint32_t a2a, uint32_t a2b, uint32_t a2c, uint32_t a2d,
+ bool valid)
+{
+ struct ipv6_range range;
+
+ range.min.s6_addr32[0] = htonl(a1a);
+ range.min.s6_addr32[1] = htonl(a1b);
+ range.min.s6_addr32[2] = htonl(a1c);
+ range.min.s6_addr32[3] = htonl(a1d);
+ range.max.s6_addr32[0] = htonl(a2a);
+ range.max.s6_addr32[1] = htonl(a2b);
+ range.max.s6_addr32[2] = htonl(a2c);
+ range.max.s6_addr32[3] = htonl(a2d);
+
+ ck_assert_int_eq(valid ? 0 : -EINVAL, check_encoding6(&range));
+}
+
+START_TEST(check_encoding6_test)
+{
+ test_range6(0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ false);
+ test_range6(0x12345678, 0x12345678, 0x12345678, 0x12345678,
+ 0x12345678, 0x12345678, 0x12345678, 0x12345678,
+ false);
+ test_range6(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ false);
+
+ test_range6(0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ false);
+ test_range6(0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000001,
+ false);
+
+ /* Matching most significant bits stop on the first quadrant */
+ test_range6(0x00001000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ false);
+
+ test_range6(0x00001010, 0x00000000, 0x00000000, 0x00000000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00000000, 0x00000000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00000000, 0x00001000, 0x00000000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00000000, 0x00000000, 0x00001000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+
+ test_range6(0x00001000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00001F0F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00001FFF, 0xFF0FFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFF0FF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF0FF,
+ true);
+
+ /* Matching most significant bits stop on the second quadrant */
+ test_range6(0x00001000, 0x00001000, 0x00000000, 0x00000000,
+ 0x00001000, 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ false);
+
+ test_range6(0x00001000, 0x00001010, 0x00000000, 0x00000000,
+ 0x00001000, 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00000000,
+ 0x00001000, 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00000000, 0x00001000,
+ 0x00001000, 0x00001FFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+
+ test_range6(0x00001000, 0x00001000, 0x00000000, 0x00000000,
+ 0x00001000, 0x00001F0F, 0xFFFFFFFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00000000, 0x00000000,
+ 0x00001000, 0x00001FFF, 0xFFFFF0FF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00000000, 0x00000000,
+ 0x00001000, 0x00001FFF, 0xFFFFFFFF, 0xFFFFF0FF,
+ true);
+
+ /* Matching most significant bits stop on the third quadrant */
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00000000,
+ 0x00001000, 0x00001000, 0x00001FFF, 0xFFFFFFFF,
+ false);
+
+ test_range6(0x00001000, 0x00001000, 0x00001010, 0x00000000,
+ 0x00001000, 0x00001000, 0x00001FFF, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00001000,
+ 0x00001000, 0x00001000, 0x00001FFF, 0xFFFFFFFF,
+ true);
+
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00000000,
+ 0x00001000, 0x00001000, 0x00001F0F, 0xFFFFFFFF,
+ true);
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00000000,
+ 0x00001000, 0x00001000, 0x00001FFF, 0xFFFFF0FF,
+ true);
+
+ /* Matching most significant bits stop on the fourth quadrant */
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00001000,
+ 0x00001000, 0x00001000, 0x00001000, 0x00001FFF,
+ false);
+
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00001010,
+ 0x00001000, 0x00001000, 0x00001000, 0x00001FFF,
+ true);
+
+ test_range6(0x00001000, 0x00001000, 0x00001000, 0x00001000,
+ 0x00001000, 0x00001000, 0x00001000, 0x00001F0F,
+ true);
+}
+END_TEST
+
+Suite *address_load_suite(void)
+{
+ Suite *suite;
+ TCase *core;
+
+ core = tcase_create("Core");
+ tcase_add_test(core, check_encoding4_test);
+ tcase_add_test(core, check_encoding6_test);
+
+ suite = suite_create("Encoding checking");
+ suite_add_tcase(suite, core);
+ return suite;
+}
+
+int main(void)
+{
+ Suite *suite;
+ SRunner *runner;
+ int tests_failed;
+
+ suite = address_load_suite();
+
+ runner = srunner_create(suite);
+ srunner_run_all(runner, CK_NORMAL);
+ tests_failed = srunner_ntests_failed(runner);
+ srunner_free(runner);
+
+ return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}