summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-07-11 11:36:48 +0200
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-07-30 20:14:49 +0200
commitfafa56a14fc4787060818715c151e1ef7b25e72f (patch)
tree56df8de045d1ffd883d39302fa7fb97276fe8b88
parent87d20a96510ecc78068865423e0fa127d17486de (diff)
Export ossl_cmp_msg_load() as OSSL_CMP_MSG_read(), use it in apps/cmp.c
Fixes #12403 Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/12421)
-rw-r--r--apps/cmp.c10
-rw-r--r--crypto/cmp/cmp_local.h1
-rw-r--r--crypto/cmp/cmp_msg.c6
-rw-r--r--doc/internal/man3/ossl_cmp_msg_create.pod5
-rw-r--r--doc/man3/OSSL_CMP_MSG_get0_header.pod7
-rw-r--r--include/openssl/cmp.h1
-rw-r--r--test/cmp_testlib.c2
-rw-r--r--util/libcrypto.num1
8 files changed, 16 insertions, 17 deletions
diff --git a/apps/cmp.c b/apps/cmp.c
index 102146a275..20e7f6ac84 100644
--- a/apps/cmp.c
+++ b/apps/cmp.c
@@ -965,7 +965,6 @@ static int write_PKIMESSAGE(const OSSL_CMP_MSG *msg, char **filenames)
static OSSL_CMP_MSG *read_PKIMESSAGE(char **filenames)
{
char *file;
- BIO *bio;
OSSL_CMP_MSG *ret;
if (filenames == NULL) {
@@ -979,15 +978,10 @@ static OSSL_CMP_MSG *read_PKIMESSAGE(char **filenames)
file = *filenames;
*filenames = next_item(file);
- bio = BIO_new_file(file, "rb");
- if (bio == NULL) {
- CMP_err1("Cannot open file '%s' for reading", file);
- return NULL;
- }
- ret = d2i_OSSL_CMP_MSG_bio(bio, NULL);
+
+ ret = OSSL_CMP_MSG_read(file);
if (ret == NULL)
CMP_err1("Cannot read PKIMessage from file '%s'", file);
- BIO_free(bio);
return ret;
}
diff --git a/crypto/cmp/cmp_local.h b/crypto/cmp/cmp_local.h
index 92f192bb5f..4e33fd339c 100644
--- a/crypto/cmp/cmp_local.h
+++ b/crypto/cmp/cmp_local.h
@@ -896,7 +896,6 @@ ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crm,
int rid);
X509 *ossl_cmp_certresponse_get1_certificate(EVP_PKEY *privkey,
const OSSL_CMP_CERTRESPONSE *crep);
-OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file);
/* from cmp_protect.c */
ASN1_BIT_STRING *ossl_cmp_calc_protection(const OSSL_CMP_MSG *msg,
diff --git a/crypto/cmp/cmp_msg.c b/crypto/cmp/cmp_msg.c
index d45a803677..2e24f49f3c 100644
--- a/crypto/cmp/cmp_msg.c
+++ b/crypto/cmp/cmp_msg.c
@@ -1008,13 +1008,15 @@ int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg)
|| ossl_cmp_msg_protect(ctx, msg);
}
-OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file)
+OSSL_CMP_MSG *OSSL_CMP_MSG_read(const char *file)
{
OSSL_CMP_MSG *msg = NULL;
BIO *bio = NULL;
- if (!ossl_assert(file != NULL))
+ if (file == NULL) {
+ CMPerr(0, CMP_R_NULL_ARGUMENT);
return NULL;
+ }
if ((bio = BIO_new_file(file, "rb")) == NULL)
return NULL;
diff --git a/doc/internal/man3/ossl_cmp_msg_create.pod b/doc/internal/man3/ossl_cmp_msg_create.pod
index 3c236a3b49..0a10a6567e 100644
--- a/doc/internal/man3/ossl_cmp_msg_create.pod
+++ b/doc/internal/man3/ossl_cmp_msg_create.pod
@@ -6,7 +6,6 @@ ossl_cmp_bodytype_to_string,
ossl_cmp_msg_get_bodytype,
ossl_cmp_msg_set_bodytype,
ossl_cmp_msg_create,
-ossl_cmp_msg_load,
ossl_cmp_msg_gen_ITAV_push0,
ossl_cmp_msg_gen_ITAVs_push1
- functions manipulating CMP messages
@@ -19,7 +18,6 @@ ossl_cmp_msg_gen_ITAVs_push1
int ossl_cmp_msg_get_bodytype(const OSSL_CMP_MSG *msg);
int ossl_cmp_msg_set_bodytype( OSSL_CMP_MSG *msg, int type);
OSSL_CMP_MSG *ossl_cmp_msg_create(OSSL_CMP_CTX *ctx, int bodytype);
- OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file);
int ossl_cmp_msg_gen_ITAV_push0(OSSL_CMP_MSG *msg, OSSL_CMP_ITAV *itav);
int ossl_cmp_msg_gen_ITAVs_push1(OSSL_CMP_MSG *msg,
STACK_OF(OSSL_CMP_ITAV) *itavs);
@@ -40,9 +38,6 @@ ossl_cmp_msg_create() creates and initializes a OSSL_CMP_MSG structure,
using B<ctx> for the header and B<bodytype> for the body.
Returns pointer to created OSSL_CMP_MSG on success, NULL on error.
-OSSL_CMP_MSG *ossl_cmp_msg_load() loads a OSSL_CMP_MSG from a B<file>.
-Returns pointer to created OSSL_CMP_MSG on success, NULL on error.
-
ossl_cmp_msg_gen_ITAV_push0() pushes the B<itav> to the body of the
PKIMessage B<msg> of GenMsg or GenRep type. Consumes the B<itavs> pointer.
Returns 1 on success, 0 on error.
diff --git a/doc/man3/OSSL_CMP_MSG_get0_header.pod b/doc/man3/OSSL_CMP_MSG_get0_header.pod
index f1bf8eac32..0670fa31dc 100644
--- a/doc/man3/OSSL_CMP_MSG_get0_header.pod
+++ b/doc/man3/OSSL_CMP_MSG_get0_header.pod
@@ -5,6 +5,7 @@
OSSL_CMP_MSG_get0_header,
OSSL_CMP_MSG_update_transactionID,
OSSL_CMP_CTX_setup_CRM,
+OSSL_CMP_MSG_read,
d2i_OSSL_CMP_MSG_bio,
i2d_OSSL_CMP_MSG_bio
- function(s) manipulating CMP messages
@@ -16,6 +17,7 @@ i2d_OSSL_CMP_MSG_bio
OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg);
int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
OSSL_CRMF_MSG *OSSL_CMP_CTX_setup_CRM(OSSL_CMP_CTX *ctx, int for_KUR, int rid);
+ OSSL_CMP_MSG *OSSL_CMP_MSG_read(const char *file);
OSSL_CMP_MSG *d2i_OSSL_CMP_MSG_bio(BIO *bio, OSSL_CMP_MSG **msg);
int i2d_OSSL_CMP_MSG_bio(BIO *bio, const OSSL_CMP_MSG *msg);
@@ -35,6 +37,8 @@ then it copies the subject DN from there
if I<for_KUR> is set or the I<ctx> does not include a subjectAltName.
The I<rid> defines the request identifier to use, which typically is 0.
+OSSL_CMP_MSG_read() loads a DER-encoded OSSL_CMP_MSG from B<file>.
+
d2i_OSSL_CMP_MSG_bio() parses an ASN.1-encoded OSSL_CMP_MSG from the BIO I<bio>.
It assigns a pointer to the new structure to I<*msg> if I<msg> is not NULL.
@@ -55,6 +59,9 @@ NULL on error.
d2i_OSSL_CMP_MSG_bio() returns the parsed message or NULL on error.
+OSSL_CMP_MSG_read() and d2i_OSSL_CMP_MSG_bio()
+return the parsed CMP message or NULL on error.
+
i2d_OSSL_CMP_MSG_bio() and OSSL_CMP_MSG_update_transactionID()
return 1 on success, 0 on error.
diff --git a/include/openssl/cmp.h b/include/openssl/cmp.h
index 378cda641d..9dc8c95ad0 100644
--- a/include/openssl/cmp.h
+++ b/include/openssl/cmp.h
@@ -355,6 +355,7 @@ ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_recipNonce(const OSSL_CMP_PKIHEADER *hdr);
OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg);
int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg);
OSSL_CRMF_MSG *OSSL_CMP_CTX_setup_CRM(OSSL_CMP_CTX *ctx, int for_KUR, int rid);
+OSSL_CMP_MSG *OSSL_CMP_MSG_read(const char *file);
OSSL_CMP_MSG *d2i_OSSL_CMP_MSG_bio(BIO *bio, OSSL_CMP_MSG **msg);
int i2d_OSSL_CMP_MSG_bio(BIO *bio, const OSSL_CMP_MSG *msg);
diff --git a/test/cmp_testlib.c b/test/cmp_testlib.c
index d25ab7468b..ef33aa8e83 100644
--- a/test/cmp_testlib.c
+++ b/test/cmp_testlib.c
@@ -46,7 +46,7 @@ OSSL_CMP_MSG *load_pkimsg(const char *file)
{
OSSL_CMP_MSG *msg;
- (void)TEST_ptr((msg = ossl_cmp_msg_load(file)));
+ (void)TEST_ptr((msg = OSSL_CMP_MSG_read(file)));
return msg;
}
diff --git a/util/libcrypto.num b/util/libcrypto.num
index d53d04afa6..1668253366 100644
--- a/util/libcrypto.num
+++ b/util/libcrypto.num
@@ -4993,6 +4993,7 @@ OSSL_CMP_certConf_cb ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_RR_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_exec_GENM_ses ? 3_0_0 EXIST::FUNCTION:CMP
OSSL_CMP_MSG_http_perform ? 3_0_0 EXIST::FUNCTION:CMP
+OSSL_CMP_MSG_read ? 3_0_0 EXIST::FUNCTION:CMP
EVP_PKEY_gen ? 3_0_0 EXIST::FUNCTION:
EVP_PKEY_CTX_set_rsa_keygen_bits ? 3_0_0 EXIST::FUNCTION:RSA
EVP_PKEY_CTX_set_rsa_keygen_pubexp ? 3_0_0 EXIST::FUNCTION:RSA