From: Dr. David von Oheimb Date: Sun, 13 Apr 2025 07:58:06 +0000 (+0200) Subject: apps/cms.c: add missing error messages in various error cases X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc7084a5ee2deaeb8882d4c60cf6e9f1caded632;p=thirdparty%2Fopenssl.git apps/cms.c: add missing error messages in various error cases Reviewed-by: Tomas Mraz Reviewed-by: Dmitry Belyavskiy (Merged from https://github.com/openssl/openssl/pull/27368) --- diff --git a/apps/cms.c b/apps/cms.c index 6f19414880c..346fb7bce4c 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -1093,8 +1093,10 @@ int cms_main(int argc, char **argv) } flags |= CMS_PARTIAL; cms = CMS_sign_ex(NULL, NULL, other, in, flags, libctx, app_get0_propq()); - if (cms == NULL) + if (cms == NULL) { + BIO_puts(bio_err, "CMS SignedData Creation Error\n"); goto end; + } if (econtent_type != NULL) CMS_set1_eContentType(cms, econtent_type); @@ -1132,30 +1134,38 @@ int cms_main(int argc, char **argv) } } si = CMS_add1_signer(cms, signer, key, sign_md, tflags); - if (si == NULL) + if (si == NULL) { + BIO_printf(bio_err, "Error adding SignerInfo with key from %s\n", keyfile); goto end; + } + if (kparam != NULL) { - EVP_PKEY_CTX *pctx; - pctx = CMS_SignerInfo_get0_pkey_ctx(si); + EVP_PKEY_CTX *pctx = CMS_SignerInfo_get0_pkey_ctx(si); + if (!cms_set_pkey_param(pctx, kparam->param)) goto end; } - if (rr != NULL && !CMS_add1_ReceiptRequest(si, rr)) + if (rr != NULL && !CMS_add1_ReceiptRequest(si, rr)) { + BIO_puts(bio_err, "Error adding CMS ReceiptRequest\n"); goto end; + } X509_free(signer); signer = NULL; EVP_PKEY_free(key); key = NULL; } /* If not streaming or resigning finalize structure */ - if (operation == SMIME_SIGN && digestbin != NULL - && (flags & CMS_STREAM) == 0) { - /* Use pre-computed digest instead of content */ - if (!CMS_final_digest(cms, digestbin, digestlen, NULL, flags)) - goto end; - } else if (operation == SMIME_SIGN && (flags & CMS_STREAM) == 0) { - if (!CMS_final(cms, in, NULL, flags)) + if (operation == SMIME_SIGN && (flags & CMS_STREAM) == 0) { + int res; + + if (digestbin != NULL) /* Use pre-computed digest instead of content */ + res = CMS_final_digest(cms, digestbin, digestlen, NULL, flags); + else + res = CMS_final(cms, in, NULL, flags); + if (!res) { + BIO_puts(bio_err, "Error finalizing CMS structure\n"); goto end; + } } }