summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-02-23 13:06:43 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-02-23 13:06:43 +0000
commitf019ba181914c9ddda4efbfc04768c6bab12dead (patch)
tree4739056a479de3ddebca61a244765cd02cc99dcc /usr.sbin
parentb18f8648740f074d3b926e4ab72f008c2b5cf60c (diff)
rpki-client: simplify parse_load_crl_from_mft()
Now that we always inspect both locations if necessary, we can do away with the loop and simply have the only caller call twice. Removes a bunch of clever complexity and streamlines the code quite a bit. ok claudio job
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rpki-client/parser.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c
index 02a1e6f2c69..68f3d920f15 100644
--- a/usr.sbin/rpki-client/parser.c
+++ b/usr.sbin/rpki-client/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.85 2023/02/23 09:50:40 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.86 2023/02/23 13:06:42 tb Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -210,46 +210,47 @@ proc_parser_mft_check(const char *fn, struct mft *p)
}
/*
- * Load the correct CRL using the info from the MFT.
+ * Load the CRL from loc using the info from the MFT.
*/
static struct crl *
-parse_load_crl_from_mft(struct entity *entp, struct mft *mft, char **crlfile)
+parse_load_crl_from_mft(struct entity *entp, struct mft *mft, enum location loc,
+ char **crlfile)
{
struct crl *crl = NULL;
unsigned char *f = NULL;
char *fn = NULL;
size_t flen;
- enum location loc = DIR_TEMP;
- while (1) {
- fn = parse_filepath(entp->repoid, entp->path, mft->crl, loc);
- if (fn == NULL)
- goto next;
+ *crlfile = NULL;
+
+ fn = parse_filepath(entp->repoid, entp->path, mft->crl, loc);
+ if (fn == NULL)
+ goto out;
- f = load_file(fn, &flen);
- if (f == NULL && errno != ENOENT)
+ f = load_file(fn, &flen);
+ if (f == NULL) {
+ if (errno != ENOENT)
warn("parse file %s", fn);
- if (f == NULL)
- goto next;
- if (!valid_hash(f, flen, mft->crlhash, sizeof(mft->crlhash)))
- goto next;
- crl = crl_parse(fn, f, flen);
+ goto out;
+ }
-next:
- free(f);
- f = NULL;
+ if (!valid_hash(f, flen, mft->crlhash, sizeof(mft->crlhash)))
+ goto out;
- if (crl != NULL) {
- *crlfile = fn;
- return crl;
- }
- free(fn);
- fn = NULL;
- if (loc == DIR_TEMP)
- loc = DIR_VALID;
- else
- return NULL;
- }
+ crl = crl_parse(fn, f, flen);
+ if (crl == NULL)
+ goto out;
+
+ *crlfile = fn;
+ free(f);
+
+ return crl;
+
+ out:
+ free(f);
+ free(fn);
+
+ return NULL;
}
/*
@@ -286,7 +287,9 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file,
}
free(der);
- *crl = parse_load_crl_from_mft(entp, mft, crlfile);
+ *crl = parse_load_crl_from_mft(entp, mft, DIR_TEMP, crlfile);
+ if (*crl == NULL)
+ *crl = parse_load_crl_from_mft(entp, mft, DIR_VALID, crlfile);
a = valid_ski_aki(*file, &auths, mft->ski, mft->aki);
if (!valid_x509(*file, ctx, x509, a, *crl, errstr)) {