1CMS_DECRYPT(3ossl)                  OpenSSL                 CMS_DECRYPT(3ossl)
2
3
4

NAME

6       CMS_decrypt, CMS_decrypt_set1_pkey_and_peer, CMS_decrypt_set1_pkey,
7       CMS_decrypt_set1_password - decrypt content from a CMS envelopedData
8       structure
9

SYNOPSIS

11        #include <openssl/cms.h>
12
13        int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
14                        BIO *dcont, BIO *out, unsigned int flags);
15        int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms,
16                        EVP_PKEY *pk, X509 *cert, X509 *peer);
17        int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert);
18        int CMS_decrypt_set1_password(CMS_ContentInfo *cms,
19                                      unsigned char *pass, ossl_ssize_t passlen);
20

DESCRIPTION

22       CMS_decrypt() extracts the decrypted content from a CMS EnvelopedData
23       or AuthEnvelopedData structure.  It uses CMS_decrypt_set1_pkey() to
24       decrypt the content with the recipient private key pkey if pkey is not
25       NULL.  In this case, it is recommended to provide the associated
26       certificate in cert - see the NOTES below.  out is a BIO to write the
27       content to and flags is an optional set of flags.  If pkey is NULL the
28       function assumes that decryption was already done (e.g., using
29       CMS_decrypt_set1_pkey() or CMS_decrypt_set1_password()) and just
30       provides the content unless cert, dcont, and out are NULL as well.  The
31       dcont parameter is used in the rare case where the encrypted content is
32       detached. It will normally be set to NULL.
33
34       CMS_decrypt_set1_pkey_and_peer() decrypts the CMS_ContentInfo structure
35       cms using the private key pkey, the corresponding certificate cert,
36       which is recommended to be supplied but may be NULL, and the (optional)
37       originator certificate peer.  On success, it also records in cms the
38       decryption key pkey, and this should be followed by "CMS_decrypt(cms,
39       NULL, NULL, dcont, out, flags)".  This call deallocates any decryption
40       key stored in cms.
41
42       CMS_decrypt_set1_pkey() is the same as CMS_decrypt_set1_pkey_and_peer()
43       with peer being NULL.
44
45       CMS_decrypt_set1_password() decrypts the CMS_ContentInfo structure cms
46       using the secret pass of length passlen.  On success, it also records
47       in cms the decryption key used, and this should be followed by
48       "CMS_decrypt(cms, NULL, NULL, dcont, out, flags)".  This call
49       deallocates any decryption key stored in cms.
50

NOTES

52       Although the recipients certificate is not needed to decrypt the data
53       it is needed to locate the appropriate (of possible several) recipients
54       in the CMS structure.
55
56       If cert is set to NULL all possible recipients are tried. This case
57       however is problematic. To thwart the MMA attack (Bleichenbacher's
58       attack on PKCS #1 v1.5 RSA padding) all recipients are tried whether
59       they succeed or not. If no recipient succeeds then a random symmetric
60       key is used to decrypt the content: this will typically output garbage
61       and may (but is not guaranteed to) ultimately return a padding error
62       only. If CMS_decrypt() just returned an error when all recipient
63       encrypted keys failed to decrypt an attacker could use this in a timing
64       attack. If the special flag CMS_DEBUG_DECRYPT is set then the above
65       behaviour is modified and an error is returned if no recipient
66       encrypted key can be decrypted without generating a random content
67       encryption key. Applications should use this flag with extreme caution
68       especially in automated gateways as it can leave them open to attack.
69
70       It is possible to determine the correct recipient key by other means
71       (for example looking them up in a database) and setting them in the CMS
72       structure in advance using the CMS utility functions such as
73       CMS_set1_pkey(), or use CMS_decrypt_set1_password() if the recipient
74       has a symmetric key.  In these cases both cert and pkey should be set
75       to NULL.
76
77       To process KEKRecipientInfo types CMS_set1_key() or
78       CMS_RecipientInfo_set0_key() and CMS_RecipientInfo_decrypt() should be
79       called before CMS_decrypt() and cert and pkey set to NULL.
80
81       The following flags can be passed in the flags parameter.
82
83       If the CMS_TEXT flag is set MIME headers for type "text/plain" are
84       deleted from the content. If the content is not of type "text/plain"
85       then an error is returned.
86

RETURN VALUES

88       CMS_decrypt(), CMS_decrypt_set1_pkey_and_peer(),
89       CMS_decrypt_set1_pkey(), and CMS_decrypt_set1_password() return either
90       1 for success or 0 for failure.  The error can be obtained from
91       ERR_get_error(3).
92

BUGS

94       The set1_ part of these function names is misleading and should better
95       read: with_.
96
97       The lack of single pass processing and the need to hold all data in
98       memory as mentioned in CMS_verify() also applies to CMS_decrypt().
99

SEE ALSO

101       ERR_get_error(3), CMS_encrypt(3)
102

HISTORY

104       CMS_decrypt_set1_pkey_and_peer() and CMS_decrypt_set1_password() were
105       added in OpenSSL 3.0.
106
108       Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.
109
110       Licensed under the Apache License 2.0 (the "License").  You may not use
111       this file except in compliance with the License.  You can obtain a copy
112       in the file LICENSE in the source distribution or at
113       <https://www.openssl.org/source/license.html>.
114
115
116
1173.1.1                             2023-08-31                CMS_DECRYPT(3ossl)
Impressum