xref: /openssl/doc/man3/CMS_decrypt.pod (revision e2f6960f)
1=pod
2
3=head1 NAME
4
5CMS_decrypt, CMS_decrypt_set1_pkey_and_peer,
6CMS_decrypt_set1_pkey, CMS_decrypt_set1_password
7- decrypt content from a CMS envelopedData structure
8
9=head1 SYNOPSIS
10
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
21=head1 DESCRIPTION
22
23CMS_decrypt() extracts and decrypts the content from a CMS EnvelopedData
24or AuthEnvelopedData structure. I<pkey> is the private key of the recipient,
25I<cert> is the recipient's certificate, I<out> is a BIO to write the content to
26and I<flags> is an optional set of flags.
27
28The I<dcont> parameter is used in the rare case where the encrypted content
29is detached. It will normally be set to NULL.
30
31CMS_decrypt_set1_pkey_and_peer() associates the private key I<pkey>, the
32corresponding certificate I<cert> and the originator certificate I<peer> with
33the CMS_ContentInfo structure I<cms>.
34
35CMS_decrypt_set1_pkey() associates the private key I<pkey> and the corresponding
36certificate I<cert> with the CMS_ContentInfo structure I<cms>.
37
38CMS_decrypt_set1_password() associates the secret I<pass> of length I<passlen>
39with the CMS_ContentInfo structure I<cms>.
40
41=head1 NOTES
42
43Although the recipients certificate is not needed to decrypt the data it is
44needed to locate the appropriate (of possible several) recipients in the CMS
45structure.
46
47If I<cert> is set to NULL all possible recipients are tried. This case however
48is problematic. To thwart the MMA attack (Bleichenbacher's attack on
49PKCS #1 v1.5 RSA padding) all recipients are tried whether they succeed or
50not. If no recipient succeeds then a random symmetric key is used to decrypt
51the content: this will typically output garbage and may (but is not guaranteed
52to) ultimately return a padding error only. If CMS_decrypt() just returned an
53error when all recipient encrypted keys failed to decrypt an attacker could
54use this in a timing attack. If the special flag B<CMS_DEBUG_DECRYPT> is set
55then the above behaviour is modified and an error B<is> returned if no
56recipient encrypted key can be decrypted B<without> generating a random
57content encryption key. Applications should use this flag with
58B<extreme caution> especially in automated gateways as it can leave them
59open to attack.
60
61It is possible to determine the correct recipient key by other means (for
62example looking them up in a database) and setting them in the CMS structure
63in advance using the CMS utility functions such as CMS_set1_pkey(). In this
64case both I<cert> and I<pkey> should be set to NULL.
65
66To process KEKRecipientInfo types CMS_set1_key() or CMS_RecipientInfo_set0_key()
67and CMS_RecipientInfo_decrypt() should be called before CMS_decrypt() and
68I<cert> and I<pkey> set to NULL.
69
70The following flags can be passed in the I<flags> parameter.
71
72If the B<CMS_TEXT> flag is set MIME headers for type C<text/plain> are deleted
73from the content. If the content is not of type C<text/plain> then an error is
74returned.
75
76=head1 RETURN VALUES
77
78CMS_decrypt(), CMS_decrypt_set1_pkey_and_peer(),
79CMS_decrypt_set1_pkey(), and CMS_decrypt_set1_password()
80return either 1 for success or 0 for failure.
81The error can be obtained from ERR_get_error(3).
82
83=head1 BUGS
84
85The lack of single pass processing and the need to hold all data in memory as
86mentioned in CMS_verify() also applies to CMS_decrypt().
87
88=head1 SEE ALSO
89
90L<ERR_get_error(3)>, L<CMS_encrypt(3)>
91
92=head1 HISTORY
93
94CMS_decrypt_set1_pkey_and_peer() and CMS_decrypt_set1_password()
95were added in OpenSSL 3.0.
96
97=head1 COPYRIGHT
98
99Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.
100
101Licensed under the Apache License 2.0 (the "License").  You may not use
102this file except in compliance with the License.  You can obtain a copy
103in the file LICENSE in the source distribution or at
104L<https://www.openssl.org/source/license.html>.
105
106=cut
107