-/* $OpenBSD: cert.c,v 1.101 2022/11/30 09:12:34 job Exp $ */
+/* $OpenBSD: cert.c,v 1.102 2023/02/21 10:18:47 tb Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Job Snijders <job@openbsd.org>
struct cert *
cert_parse_pre(const char *fn, const unsigned char *der, size_t len)
{
- int extsz;
- int sia_present = 0;
- size_t i;
- X509 *x = NULL;
- X509_EXTENSION *ext = NULL;
- ASN1_OBJECT *obj;
- struct parse p;
+ const unsigned char *oder;
+ int extsz;
+ int sia_present = 0;
+ size_t i;
+ X509 *x = NULL;
+ X509_EXTENSION *ext = NULL;
+ ASN1_OBJECT *obj;
+ struct parse p;
/* just fail for empty buffers, the warning was printed elsewhere */
if (der == NULL)
if ((p.res = calloc(1, sizeof(struct cert))) == NULL)
err(1, NULL);
+ oder = der;
if ((x = d2i_X509(NULL, &der, len)) == NULL) {
cryptowarnx("%s: d2i_X509", p.fn);
goto out;
}
+ if (der != oder + len) {
+ warnx("%s: %td bytes trailing garbage", fn, oder + len - der);
+ goto out;
+ }
/* Cache X509v3 extensions, see X509_check_ca(3). */
if (X509_check_purpose(x, -1, -1) <= 0) {
-/* $OpenBSD: cms.c,v 1.26 2022/12/28 21:30:18 jmc Exp $ */
+/* $OpenBSD: cms.c,v 1.27 2023/02/21 10:18:47 tb Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
static int
cms_parse_validate_internal(X509 **xp, const char *fn, const unsigned char *der,
- size_t derlen, const ASN1_OBJECT *oid, BIO *bio, unsigned char **res,
+ size_t len, const ASN1_OBJECT *oid, BIO *bio, unsigned char **res,
size_t *rsz)
{
+ const unsigned char *oder;
char buf[128], obuf[128];
const ASN1_OBJECT *obj, *octype;
ASN1_OCTET_STRING *kid = NULL;
if (der == NULL)
return 0;
- if ((cms = d2i_CMS_ContentInfo(NULL, &der, derlen)) == NULL) {
+ oder = der;
+ if ((cms = d2i_CMS_ContentInfo(NULL, &der, len)) == NULL) {
cryptowarnx("%s: RFC 6488: failed CMS parse", fn);
goto out;
}
+ if (der != oder + len) {
+ warnx("%s: %td bytes trailing garbage", fn, oder + len - der);
+ goto out;
+ }
/*
* The CMS is self-signed with a signing certificate.
-/* $OpenBSD: crl.c,v 1.21 2022/11/30 09:03:44 job Exp $ */
+/* $OpenBSD: crl.c,v 1.22 2023/02/21 10:18:47 tb Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct crl *
crl_parse(const char *fn, const unsigned char *der, size_t len)
{
- struct crl *crl;
- const ASN1_TIME *at;
- int rc = 0;
+ const unsigned char *oder;
+ struct crl *crl;
+ const ASN1_TIME *at;
+ int rc = 0;
/* just fail for empty buffers, the warning was printed elsewhere */
if (der == NULL)
if ((crl = calloc(1, sizeof(*crl))) == NULL)
err(1, NULL);
+ oder = der;
if ((crl->x509_crl = d2i_X509_CRL(NULL, &der, len)) == NULL) {
cryptowarnx("%s: d2i_X509_CRL", fn);
goto out;
}
+ if (der != oder + len) {
+ warnx("%s: %td bytes trailing garbage", fn, oder + len - der);
+ goto out;
+ }
if ((crl->aki = x509_crl_get_aki(crl->x509_crl, fn)) == NULL) {
warnx("x509_crl_get_aki failed");