-/* $OpenBSD: extern.h,v 1.75 2021/10/23 20:01:16 claudio Exp $ */
+/* $OpenBSD: extern.h,v 1.76 2021/10/24 12:06:16 job Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
int valid_cert(const char *, struct auth_tree *,
const struct cert *);
int valid_roa(const char *, struct auth_tree *, struct roa *);
+int valid_filename(const char *);
int valid_filehash(const char *, const char *, size_t);
int valid_uri(const char *, size_t, const char *);
-/* $OpenBSD: mft.c,v 1.39 2021/10/23 16:06:04 claudio Exp $ */
+/* $OpenBSD: mft.c,v 1.40 2021/10/24 12:06:16 job Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
{
size_t i;
int rc = 1;
- char *cp, *path = NULL;
+ char *cp, *h, *path = NULL;
/* Check hash of file now, but first build path for it */
cp = strrchr(fn, '/');
for (i = 0; i < p->filesz; i++) {
const struct mftfile *m = &p->files[i];
+ if (!valid_filename(m->file)) {
+ if (base64_encode(m->hash, sizeof(m->hash), &h) == -1)
+ errx(1, "base64_encode failed in %s", __func__);
+ warnx("%s: unsupported filename for %s", fn, h);
+ free(h);
+ continue;
+ }
if (asprintf(&path, "%.*s/%s", (int)(cp - fn), fn,
m->file) == -1)
err(1, NULL);
-/* $OpenBSD: validate.c,v 1.16 2021/10/11 16:50:03 job Exp $ */
+/* $OpenBSD: validate.c,v 1.17 2021/10/24 12:06:16 job Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
return 1;
}
+/*
+ * Validate a filename listed on a Manifest.
+ * draft-ietf-sidrops-6486bis section 4.2.2
+ * Returns 1 if filename is valid, otherwise 0.
+ */
+int
+valid_filename(const char *fn)
+{
+ size_t sz;
+ const unsigned char *c;
+
+ sz = strlen(fn);
+ if (sz < 5)
+ return 0;
+
+ for (c = fn; *c != '\0'; ++c)
+ if (!isalnum(*c) && *c != '-' && *c != '_' && *c != '.')
+ return 0;
+
+ if (strchr(fn, '.') != strrchr(fn, '.'))
+ return 0;
+
+ if (strcasecmp(fn + sz - 4, ".cer") == 0)
+ return 1;
+ if (strcasecmp(fn + sz - 4, ".crl") == 0)
+ return 1;
+ if (strcasecmp(fn + sz - 4, ".gbr") == 0)
+ return 1;
+ if (strcasecmp(fn + sz - 4, ".roa") == 0)
+ return 1;
+
+ return 0;
+}
+
/*
* Validate a file by verifying the SHA256 hash of that file.
* Returns 1 if valid, 0 otherwise.