]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Export ossl_cmp_msg_load() as OSSL_CMP_MSG_read(), use it in apps/cmp.c
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Sat, 11 Jul 2020 09:36:48 +0000 (11:36 +0200)
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>
Thu, 30 Jul 2020 18:14:49 +0000 (20:14 +0200)
Fixes #12403

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12421)

apps/cmp.c
crypto/cmp/cmp_local.h
crypto/cmp/cmp_msg.c
doc/internal/man3/ossl_cmp_msg_create.pod
doc/man3/OSSL_CMP_MSG_get0_header.pod
include/openssl/cmp.h
test/cmp_testlib.c
util/libcrypto.num

index 102146a2755736871e330236e40a37eeec8707cb..20e7f6ac843d7fe0501862213e41f90162e28710 100644 (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;
 }
 
index 92f192bb5f9191aa4cd971974f2f5a735b59d135..4e33fd339c951a30603356278e9f69c2308dcb8e 100644 (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,
index d45a803677e8cc9cd8775af65d37ba86ede2a5c4..2e24f49f3c12b50ee047f49586fa258fd27e8d6e 100644 (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;
index 3c236a3b4948a9aa6a7dd913f6212051a98cfd92..0a10a6567edab0855ac8ad9652c92c4e27310c50 100644 (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.
index f1bf8eac32c1a5eaee45b76d327952e0e93e2dbf..0670fa31dc5bbf754b95e7861262c500653059e7 100644 (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.
 
index 378cda641d55b6043d3b8d18ac8ac39e0ca10e44..9dc8c95ad02de1e994b4a3cca55def1f71f9267d 100644 (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);
 
index d25ab7468b592dac92125c9ff5fdf6787dc5ea7e..ef33aa8e83805d3aa75d536efe4d5dad297c0c85 100644 (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;
 }
 
index d53d04afa626750baa7120db3ee5e6d888a9349d..16682533663af2ce950a64a2b8487ab6f6cdcaf8 100644 (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