From aebfeadbe62f7780f4e32b470b973876b1364d4c Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 25 Mar 2021 09:27:38 +0000 Subject: [PATCH] Adjust base64_decode() to just take a base64 string as input instead of a string plus length. Preparation work for RRDP. OK tb@ --- usr.sbin/rpki-client/tal.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/usr.sbin/rpki-client/tal.c b/usr.sbin/rpki-client/tal.c index 94b191a492e..e5a8674774a 100644 --- a/usr.sbin/rpki-client/tal.c +++ b/usr.sbin/rpki-client/tal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tal.c,v 1.28 2021/03/05 17:15:19 claudio Exp $ */ +/* $OpenBSD: tal.c,v 1.29 2021/03/25 09:27:38 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -28,11 +28,11 @@ #include "extern.h" static int -base64_decode(const unsigned char *in, size_t inlen, unsigned char **out, - size_t *outlen) +base64_decode(const unsigned char *in, unsigned char **out, size_t *outlen) { static EVP_ENCODE_CTX *ctx; unsigned char *to; + size_t inlen; int tolen; if (ctx == NULL && (ctx = EVP_ENCODE_CTX_new()) == NULL) @@ -41,6 +41,7 @@ base64_decode(const unsigned char *in, size_t inlen, unsigned char **out, *out = NULL; *outlen = 0; + inlen = strlen(in); if (inlen >= INT_MAX - 3) return -1; tolen = ((inlen + 3) / 4) * 3 + 1; @@ -81,7 +82,7 @@ tal_parse_buffer(const char *fn, char *buf) { char *nl, *line, *f, *file = NULL; unsigned char *der; - size_t sz, dersz; + size_t dersz; int rc = 0; struct tal *tal = NULL; EVP_PKEY *pkey = NULL; @@ -147,17 +148,13 @@ tal_parse_buffer(const char *fn, char *buf) /* sort uri lexicographically so https:// is preferred */ qsort(tal->uri, tal->urisz, sizeof(tal->uri[0]), tal_cmp); - sz = strlen(buf); - if (sz == 0) { + /* Now the Base64-encoded public key. */ + if ((base64_decode(buf, &der, &dersz)) == -1) { warnx("%s: RFC 7730 section 2.1: subjectPublicKeyInfo: " - "zero-length public key", fn); + "bad public key", fn); goto out; } - /* Now the BASE64-encoded public key. */ - if ((base64_decode(buf, sz, &der, &dersz)) == -1) - errx(1, "base64 decode"); - tal->pkey = der; tal->pkeysz = dersz; -- 2.20.1