-/* $OpenBSD: cert.c,v 1.147 2024/06/12 04:01:20 tb Exp $ */
+/* $OpenBSD: cert.c,v 1.148 2024/06/12 10:03:09 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Job Snijders <job@openbsd.org>
extern ASN1_OBJECT *manifest_oid; /* 1.3.6.1.5.5.7.48.10 (rpkiManifest) */
extern ASN1_OBJECT *notify_oid; /* 1.3.6.1.5.5.7.48.13 (rpkiNotify) */
-static int certid = TALSZ_MAX;
+int certid = TALSZ_MAX;
/*
* Append an IP address structure to our list of results.
cert->certid = cert->talid;
} else {
cert->certid = ++certid;
- if (certid > CERTID_MAX)
- errx(1, "%s: too many certificates in store", fn);
+ if (certid > CERTID_MAX) {
+ if (certid == CERTID_MAX + 1)
+ warnx("%s: too many certificates in store", fn);
+ free(na);
+ return NULL;
+ }
na->depth = issuer->depth + 1;
}
-/* $OpenBSD: parser.c,v 1.140 2024/06/10 11:49:29 tb Exp $ */
+/* $OpenBSD: parser.c,v 1.141 2024/06/12 10:03:09 tb Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
#include "extern.h"
+extern int certid;
+
static X509_STORE_CTX *ctx;
static struct auth_tree auths = RB_INITIALIZER(&auths);
static struct crl_tree crlt = RB_INITIALIZER(&crlt);
a = auth_find(&auths, id);
if (a == NULL) {
- warnx("%s: RFC 6487: unknown cert with SKI %s", fn, aki);
+ if (certid <= CERTID_MAX)
+ warnx("%s: RFC 6487: unknown cert with SKI %s", fn,
+ aki);
return NULL;
}
return NULL;
a = find_issuer(file, entp->certid, roa->aki, entp->mftaki);
+ if (a == NULL) {
+ X509_free(x509);
+ roa_free(roa);
+ return NULL;
+ }
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
return NULL;
a = find_issuer(file, entp->certid, spl->aki, entp->mftaki);
+ if (a == NULL) {
+ X509_free(x509);
+ spl_free(spl);
+ return NULL;
+ }
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
*crl = parse_load_crl_from_mft(entp, mft, DIR_VALID, crlfile);
a = find_issuer(file, entp->certid, mft->aki, NULL);
+ if (a == NULL)
+ goto err;
if (!valid_x509(file, ctx, x509, a, *crl, errstr))
goto err;
X509_free(x509);
err2 = err1;
if (err2 == NULL)
err2 = "no valid manifest available";
- warnx("%s: %s", file2, err2);
+ if (certid <= CERTID_MAX)
+ warnx("%s: %s", file2, err2);
}
mft_free(mft1);
return NULL;
a = find_issuer(file, entp->certid, cert->aki, entp->mftaki);
+ if (a == NULL) {
+ cert_free(cert);
+ return NULL;
+ }
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, cert->x509, a, crl, &errstr) ||
return NULL;
a = find_issuer(file, entp->certid, gbr->aki, entp->mftaki);
+ if (a == NULL) {
+ X509_free(x509);
+ gbr_free(gbr);
+ return NULL;
+ }
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
return NULL;
a = find_issuer(file, entp->certid, aspa->aki, entp->mftaki);
+ if (a == NULL) {
+ X509_free(x509);
+ aspa_free(aspa);
+ return NULL;
+ }
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
return NULL;
a = find_issuer(file, entp->certid, tak->aki, entp->mftaki);
+ if (a == NULL)
+ goto out;
crl = crl_get(&crlt, a);
if (!valid_x509(file, ctx, x509, a, crl, &errstr)) {
ibuf_free(inbuf);
+ if (certid > CERTID_MAX)
+ errx(1, "processing incomplete: too many certificates");
+
exit(0);
}