1
0
mirror of https://github.com/openbsd/src.git synced 2026-06-18 07:13:36 +02:00

Use fopen() and BIO_new_fd() instead of BIO_new_file so that a possible

open error can be better logged to the operator. The cryptowarnx function
logs warnings is a less optimal way (mainly because of OpenSSL error stacks).
OK benno@ deraadt@
This commit is contained in:
claudio
2020-04-02 09:16:43 +00:00
parent 2699785b2d
commit 5ff8d7be0a
3 changed files with 24 additions and 8 deletions
+8 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: cert.c,v 1.14 2020/02/26 02:35:08 deraadt Exp $ */
/* $OpenBSD: cert.c,v 1.15 2020/04/02 09:16:43 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -930,12 +930,18 @@ cert_parse_inner(X509 **xp, const char *fn, const unsigned char *dgst, int ta)
ASN1_OBJECT *obj;
struct parse p;
BIO *bio = NULL, *shamd;
FILE *f;
EVP_MD *md;
char mdbuf[EVP_MAX_MD_SIZE];
*xp = NULL;
if ((bio = BIO_new_file(fn, "rb")) == NULL) {
if ((f = fopen(fn, "rb")) == NULL) {
warn("%s", fn);
return NULL;
}
if ((bio = BIO_new_fp(f, BIO_CLOSE)) == NULL) {
if (verbose > 0)
cryptowarnx("%s: BIO_new_file", fn);
return NULL;
+8 -4
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: cms.c,v 1.6 2019/11/29 05:14:11 benno Exp $ */
/* $OpenBSD: cms.c,v 1.7 2020/04/02 09:16:43 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -42,6 +42,7 @@ cms_parse_validate(X509 **xp, const char *fn,
ASN1_OCTET_STRING **os = NULL;
BIO *bio = NULL, *shamd;
CMS_ContentInfo *cms;
FILE *f;
char buf[128], mdbuf[EVP_MAX_MD_SIZE];
int rc = 0, sz;
STACK_OF(X509) *certs = NULL;
@@ -55,10 +56,13 @@ cms_parse_validate(X509 **xp, const char *fn,
* This is usually fopen() failure, so let it pass through to
* the handler, which will in turn ignore the entity.
*/
if ((f = fopen(fn, "rb")) == NULL) {
warn("%s", fn);
return NULL;
}
if ((bio = BIO_new_file(fn, "rb")) == NULL) {
if (verbose > 0)
cryptowarnx("%s: BIO_new_file", fn);
if ((bio = BIO_new_fp(f, BIO_CLOSE)) == NULL) {
cryptowarnx("%s: BIO_new_fp", fn);
return NULL;
}
+8 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: crl.c,v 1.7 2019/11/29 04:40:04 claudio Exp $ */
/* $OpenBSD: crl.c,v 1.8 2020/04/02 09:16:43 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -36,10 +36,16 @@ crl_parse(const char *fn, const unsigned char *dgst)
int rc = 0, sz;
X509_CRL *x = NULL;
BIO *bio = NULL, *shamd;
FILE *f;
EVP_MD *md;
char mdbuf[EVP_MAX_MD_SIZE];
if ((bio = BIO_new_file(fn, "rb")) == NULL) {
if ((f = fopen(fn, "rb")) == NULL) {
warn("%s", fn);
return NULL;
}
if ((bio = BIO_new_fp(f, BIO_CLOSE)) == NULL) {
if (verbose > 0)
cryptowarnx("%s: BIO_new_file", fn);
return NULL;