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)
This commit is contained in:
Dr. David von Oheimb 2020-07-11 11:36:48 +02:00
parent 87d20a9651
commit fafa56a14f
8 changed files with 16 additions and 17 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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;

View File

@ -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.

View File

@ -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.

View File

@ -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);

View File

@ -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;
}

View File

@ -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