-/* $OpenBSD: main.c,v 1.232 2023/02/23 09:50:40 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.233 2023/04/13 17:04:02 job Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
free(ent->path);
free(ent->file);
+ free(ent->mftaki);
free(ent->data);
free(ent);
}
io_read_buf(b, &ent->talid, sizeof(ent->talid));
io_read_str(b, &ent->path);
io_read_str(b, &ent->file);
+ io_read_str(b, &ent->mftaki);
io_read_buf_alloc(b, (void **)&ent->data, &ent->datasz);
}
io_simple_buffer(b, &ent->talid, sizeof(ent->talid));
io_str_buffer(b, ent->path);
io_str_buffer(b, ent->file);
+ io_str_buffer(b, ent->mftaki);
io_buf_buffer(b, ent->data, ent->datasz);
io_close_buffer(&procq, b);
}
io_simple_buffer(b, &talid, sizeof(talid));
io_str_buffer(b, path);
io_str_buffer(b, altpath);
- io_buf_buffer(b, NULL, 0);
+ io_buf_buffer(b, NULL, 0); /* ent->mftaki */
+ io_buf_buffer(b, NULL, 0); /* ent->data */
io_close_buffer(&procq, b);
free(path);
free(altpath);
*/
static void
entityq_add(char *path, char *file, enum rtype type, enum location loc,
- struct repo *rp, unsigned char *data, size_t datasz, int talid)
+ struct repo *rp, unsigned char *data, size_t datasz, int talid,
+ char *mftaki)
{
struct entity *p;
p->type = type;
p->location = loc;
p->talid = talid;
+ p->mftaki = mftaki;
p->path = path;
if (rp != NULL)
p->repoid = repo_id(rp);
size_t i;
struct repo *rp;
const struct mftfile *f;
- char *nfile, *npath = NULL;
+ char *mftaki, *nfile, *npath = NULL;
rp = repo_byid(mft->repoid);
for (i = 0; i < mft->filesz; i++) {
err(1, NULL);
if ((nfile = strdup(f->file)) == NULL)
err(1, NULL);
+ if ((mftaki = strdup(mft->aki)) == NULL)
+ err(1, NULL);
entityq_add(npath, nfile, f->type, f->location, rp, NULL, 0,
- -1);
+ -1, mftaki);
}
}
if ((nfile = strdup(file)) == NULL)
err(1, NULL);
/* Not in a repository, so directly add to queue. */
- entityq_add(NULL, nfile, type, DIR_UNKNOWN, NULL, buf, len, talid);
+ entityq_add(NULL, nfile, type, DIR_UNKNOWN, NULL, buf, len, talid,
+ NULL);
}
/*
data = tal->pkey;
tal->pkey = NULL;
entityq_add(NULL, nfile, RTYPE_CER, DIR_VALID, repo, data,
- tal->pkeysz, tal->id);
+ tal->pkeysz, tal->id, NULL);
}
/*
err(1, NULL);
}
- entityq_add(npath, nfile, RTYPE_MFT, DIR_UNKNOWN, repo, NULL, 0, -1);
+ entityq_add(npath, nfile, RTYPE_MFT, DIR_UNKNOWN, repo, NULL, 0, -1,
+ NULL);
}
/*
-/* $OpenBSD: parser.c,v 1.89 2023/03/13 09:24:37 job Exp $ */
+/* $OpenBSD: parser.c,v 1.90 2023/04/13 17:04:02 job Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* Returns the roa on success, NULL on failure.
*/
static struct roa *
-proc_parser_roa(char *file, const unsigned char *der, size_t len)
+proc_parser_roa(char *file, const unsigned char *der, size_t len,
+ const char *mftaki)
{
struct roa *roa;
struct auth *a;
if ((roa = roa_parse(&x509, file, der, len)) == NULL)
return NULL;
- a = valid_ski_aki(file, &auths, roa->ski, roa->aki);
+ a = valid_ski_aki(file, &auths, roa->ski, roa->aki, mftaki);
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
if (crl == NULL)
goto out;
+ if (strcmp(crl->aki, mft->aki) != 0) {
+ warnx("%s: AKI doesn't match Manifest AKI", fn);
+ goto out;
+ }
+
*crlfile = fn;
free(f);
return crl;
out:
+ crl_free(crl);
free(f);
free(fn);
if (*crl == NULL)
*crl = parse_load_crl_from_mft(entp, mft, DIR_VALID, crlfile);
- a = valid_ski_aki(*file, &auths, mft->ski, mft->aki);
+ a = valid_ski_aki(*file, &auths, mft->ski, mft->aki, NULL);
if (!valid_x509(*file, ctx, x509, a, *crl, errstr)) {
X509_free(x509);
mft_free(mft);
* parse failure.
*/
static struct cert *
-proc_parser_cert(char *file, const unsigned char *der, size_t len)
+proc_parser_cert(char *file, const unsigned char *der, size_t len,
+ const char *mftaki)
{
struct cert *cert;
struct crl *crl;
if (cert == NULL)
return NULL;
- a = valid_ski_aki(file, &auths, cert->ski, cert->aki);
+ a = valid_ski_aki(file, &auths, cert->ski, cert->aki, mftaki);
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, cert->x509, a, crl, &errstr) ||
* Parse a ghostbuster record
*/
static void
-proc_parser_gbr(char *file, const unsigned char *der, size_t len)
+proc_parser_gbr(char *file, const unsigned char *der, size_t len,
+ const char *mftaki)
{
struct gbr *gbr;
X509 *x509;
if ((gbr = gbr_parse(&x509, file, der, len)) == NULL)
return;
- a = valid_ski_aki(file, &auths, gbr->ski, gbr->aki);
+ a = valid_ski_aki(file, &auths, gbr->ski, gbr->aki, mftaki);
crl = crl_get(&crlt, a);
/* return value can be ignored since nothing happens here */
* Parse an ASPA object
*/
static struct aspa *
-proc_parser_aspa(char *file, const unsigned char *der, size_t len)
+proc_parser_aspa(char *file, const unsigned char *der, size_t len,
+ const char *mftaki)
{
struct aspa *aspa;
struct auth *a;
if ((aspa = aspa_parse(&x509, file, der, len)) == NULL)
return NULL;
- a = valid_ski_aki(file, &auths, aspa->ski, aspa->aki);
+ a = valid_ski_aki(file, &auths, aspa->ski, aspa->aki, mftaki);
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
* Parse a TAK object.
*/
static struct tak *
-proc_parser_tak(char *file, const unsigned char *der, size_t len)
+proc_parser_tak(char *file, const unsigned char *der, size_t len,
+ const char *mftaki)
{
struct tak *tak;
X509 *x509;
if ((tak = tak_parse(&x509, file, der, len)) == NULL)
return NULL;
- a = valid_ski_aki(file, &auths, tak->ski, tak->aki);
+ a = valid_ski_aki(file, &auths, tak->ski, tak->aki, mftaki);
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
f, flen, entp->data, entp->datasz,
entp->talid);
else
- cert = proc_parser_cert(file, f, flen);
+ cert = proc_parser_cert(file, f, flen,
+ entp->mftaki);
c = (cert != NULL);
io_simple_buffer(b, &c, sizeof(int));
if (cert != NULL) {
case RTYPE_ROA:
file = parse_load_file(entp, &f, &flen);
io_str_buffer(b, file);
- roa = proc_parser_roa(file, f, flen);
+ roa = proc_parser_roa(file, f, flen, entp->mftaki);
c = (roa != NULL);
io_simple_buffer(b, &c, sizeof(int));
if (roa != NULL)
case RTYPE_GBR:
file = parse_load_file(entp, &f, &flen);
io_str_buffer(b, file);
- proc_parser_gbr(file, f, flen);
+ proc_parser_gbr(file, f, flen, entp->mftaki);
break;
case RTYPE_ASPA:
file = parse_load_file(entp, &f, &flen);
io_str_buffer(b, file);
- aspa = proc_parser_aspa(file, f, flen);
+ aspa = proc_parser_aspa(file, f, flen, entp->mftaki);
c = (aspa != NULL);
io_simple_buffer(b, &c, sizeof(int));
if (aspa != NULL)
case RTYPE_TAK:
file = parse_load_file(entp, &f, &flen);
io_str_buffer(b, file);
- proc_parser_tak(file, f, flen);
+ proc_parser_tak(file, f, flen, entp->mftaki);
break;
case RTYPE_CRL:
default: