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