xref: /freebsd-src/crypto/openssl/doc/man3/CMS_decrypt.pod (revision e71b70530d95c4f34d8bdbd78d1242df1ba4a945)
1*e71b7053SJung-uk Kim=pod
2*e71b7053SJung-uk Kim
3*e71b7053SJung-uk Kim=head1 NAME
4*e71b7053SJung-uk Kim
5*e71b7053SJung-uk KimCMS_decrypt - decrypt content from a CMS envelopedData structure
6*e71b7053SJung-uk Kim
7*e71b7053SJung-uk Kim=head1 SYNOPSIS
8*e71b7053SJung-uk Kim
9*e71b7053SJung-uk Kim #include <openssl/cms.h>
10*e71b7053SJung-uk Kim
11*e71b7053SJung-uk Kim int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
12*e71b7053SJung-uk Kim                 BIO *dcont, BIO *out, unsigned int flags);
13*e71b7053SJung-uk Kim
14*e71b7053SJung-uk Kim=head1 DESCRIPTION
15*e71b7053SJung-uk Kim
16*e71b7053SJung-uk KimCMS_decrypt() extracts and decrypts the content from a CMS EnvelopedData
17*e71b7053SJung-uk Kimstructure. B<pkey> is the private key of the recipient, B<cert> is the
18*e71b7053SJung-uk Kimrecipient's certificate, B<out> is a BIO to write the content to and
19*e71b7053SJung-uk KimB<flags> is an optional set of flags.
20*e71b7053SJung-uk Kim
21*e71b7053SJung-uk KimThe B<dcont> parameter is used in the rare case where the encrypted content
22*e71b7053SJung-uk Kimis detached. It will normally be set to NULL.
23*e71b7053SJung-uk Kim
24*e71b7053SJung-uk Kim=head1 NOTES
25*e71b7053SJung-uk Kim
26*e71b7053SJung-uk KimAlthough the recipients certificate is not needed to decrypt the data it is
27*e71b7053SJung-uk Kimneeded to locate the appropriate (of possible several) recipients in the CMS
28*e71b7053SJung-uk Kimstructure.
29*e71b7053SJung-uk Kim
30*e71b7053SJung-uk KimIf B<cert> is set to NULL all possible recipients are tried. This case however
31*e71b7053SJung-uk Kimis problematic. To thwart the MMA attack (Bleichenbacher's attack on
32*e71b7053SJung-uk KimPKCS #1 v1.5 RSA padding) all recipients are tried whether they succeed or
33*e71b7053SJung-uk Kimnot. If no recipient succeeds then a random symmetric key is used to decrypt
34*e71b7053SJung-uk Kimthe content: this will typically output garbage and may (but is not guaranteed
35*e71b7053SJung-uk Kimto) ultimately return a padding error only. If CMS_decrypt() just returned an
36*e71b7053SJung-uk Kimerror when all recipient encrypted keys failed to decrypt an attacker could
37*e71b7053SJung-uk Kimuse this in a timing attack. If the special flag B<CMS_DEBUG_DECRYPT> is set
38*e71b7053SJung-uk Kimthen the above behaviour is modified and an error B<is> returned if no
39*e71b7053SJung-uk Kimrecipient encrypted key can be decrypted B<without> generating a random
40*e71b7053SJung-uk Kimcontent encryption key. Applications should use this flag with
41*e71b7053SJung-uk KimB<extreme caution> especially in automated gateways as it can leave them
42*e71b7053SJung-uk Kimopen to attack.
43*e71b7053SJung-uk Kim
44*e71b7053SJung-uk KimIt is possible to determine the correct recipient key by other means (for
45*e71b7053SJung-uk Kimexample looking them up in a database) and setting them in the CMS structure
46*e71b7053SJung-uk Kimin advance using the CMS utility functions such as CMS_set1_pkey(). In this
47*e71b7053SJung-uk Kimcase both B<cert> and B<pkey> should be set to NULL.
48*e71b7053SJung-uk Kim
49*e71b7053SJung-uk KimTo process KEKRecipientInfo types CMS_set1_key() or CMS_RecipientInfo_set0_key()
50*e71b7053SJung-uk Kimand CMS_RecipientInfo_decrypt() should be called before CMS_decrypt() and
51*e71b7053SJung-uk KimB<cert> and B<pkey> set to NULL.
52*e71b7053SJung-uk Kim
53*e71b7053SJung-uk KimThe following flags can be passed in the B<flags> parameter.
54*e71b7053SJung-uk Kim
55*e71b7053SJung-uk KimIf the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted
56*e71b7053SJung-uk Kimfrom the content. If the content is not of type B<text/plain> then an error is
57*e71b7053SJung-uk Kimreturned.
58*e71b7053SJung-uk Kim
59*e71b7053SJung-uk Kim=head1 RETURN VALUES
60*e71b7053SJung-uk Kim
61*e71b7053SJung-uk KimCMS_decrypt() returns either 1 for success or 0 for failure.
62*e71b7053SJung-uk KimThe error can be obtained from ERR_get_error(3)
63*e71b7053SJung-uk Kim
64*e71b7053SJung-uk Kim=head1 BUGS
65*e71b7053SJung-uk Kim
66*e71b7053SJung-uk KimThe lack of single pass processing and the need to hold all data in memory as
67*e71b7053SJung-uk Kimmentioned in CMS_verify() also applies to CMS_decrypt().
68*e71b7053SJung-uk Kim
69*e71b7053SJung-uk Kim=head1 SEE ALSO
70*e71b7053SJung-uk Kim
71*e71b7053SJung-uk KimL<ERR_get_error(3)>, L<CMS_encrypt(3)>
72*e71b7053SJung-uk Kim
73*e71b7053SJung-uk Kim=head1 COPYRIGHT
74*e71b7053SJung-uk Kim
75*e71b7053SJung-uk KimCopyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
76*e71b7053SJung-uk Kim
77*e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
78*e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
79*e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
80*e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
81*e71b7053SJung-uk Kim
82*e71b7053SJung-uk Kim=cut
83