diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2022-05-09 21:00:03 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2022-06-28 17:51:21 +0200 |
commit | e2f6960fc5fe1d6eb2178adf51db1ed206ff9e90 (patch) | |
tree | bc336323cf198db2c004e7490bbf47e24fe23740 /crypto/cms | |
parent | 61f510600e2c7cdee6e61f8b7075fb0e939eb179 (diff) |
CMS: Export CMS_EnvelopedData and add CMS_EnvelopedData_decrypt()
Also document CMS_decrypt_set1_password() and fix CMS_EnvelopedData_create.pod.
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18301)
Diffstat (limited to 'crypto/cms')
-rw-r--r-- | crypto/cms/cms_env.c | 37 | ||||
-rw-r--r-- | crypto/cms/cms_local.h | 1 |
2 files changed, 37 insertions, 1 deletions
diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c index 24632fa9c1..471676d2f5 100644 --- a/crypto/cms/cms_env.c +++ b/crypto/cms/cms_env.c @@ -242,6 +242,43 @@ CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher) return CMS_EnvelopedData_create_ex(cipher, NULL, NULL); } +BIO *CMS_EnvelopedData_decrypt(CMS_EnvelopedData *env, BIO *detached_data, + EVP_PKEY *pkey, X509 *cert, + ASN1_OCTET_STRING *secret, unsigned int flags, + OSSL_LIB_CTX *libctx, const char *propq) +{ + CMS_ContentInfo *ci; + BIO *bio = NULL; + int res = 0; + + if (env == NULL) { + ERR_raise(ERR_LIB_CMS, ERR_R_PASSED_NULL_PARAMETER); + return NULL; + } + + if ((ci = CMS_ContentInfo_new_ex(libctx, propq)) == NULL + || (bio = BIO_new(BIO_s_mem())) == NULL) + goto end; + ci->contentType = OBJ_nid2obj(NID_pkcs7_enveloped); + ci->d.envelopedData = env; + if (secret != NULL + && CMS_decrypt_set1_password(ci, (unsigned char *) + ASN1_STRING_get0_data(secret), + ASN1_STRING_length(secret)) != 1) + goto end; + res = CMS_decrypt(ci, pkey, cert, detached_data, bio, flags); + + end: + if (ci != NULL) + ci->d.envelopedData = NULL; + CMS_ContentInfo_free(ci); + if (!res) { + BIO_free(bio); + bio = NULL; + } + return bio; +} + CMS_ContentInfo * CMS_AuthEnvelopedData_create_ex(const EVP_CIPHER *cipher, OSSL_LIB_CTX *libctx, const char *propq) diff --git a/crypto/cms/cms_local.h b/crypto/cms/cms_local.h index 096235c0fa..d16ca95176 100644 --- a/crypto/cms/cms_local.h +++ b/crypto/cms/cms_local.h @@ -25,7 +25,6 @@ typedef struct CMS_SignedData_st CMS_SignedData; typedef struct CMS_OtherRevocationInfoFormat_st CMS_OtherRevocationInfoFormat; typedef struct CMS_OriginatorInfo_st CMS_OriginatorInfo; typedef struct CMS_EncryptedContentInfo_st CMS_EncryptedContentInfo; -typedef struct CMS_EnvelopedData_st CMS_EnvelopedData; typedef struct CMS_DigestedData_st CMS_DigestedData; typedef struct CMS_EncryptedData_st CMS_EncryptedData; typedef struct CMS_AuthenticatedData_st CMS_AuthenticatedData; |