CMS_decrypt.pod 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. =pod
  2. =head1 NAME
  3. CMS_decrypt - decrypt content from a CMS envelopedData structure
  4. =head1 SYNOPSIS
  5. #include <openssl/cms.h>
  6. int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, BIO *dcont, BIO *out, unsigned int flags);
  7. =head1 DESCRIPTION
  8. CMS_decrypt() extracts and decrypts the content from a CMS EnvelopedData
  9. structure. B<pkey> is the private key of the recipient, B<cert> is the
  10. recipient's certificate, B<out> is a BIO to write the content to and
  11. B<flags> is an optional set of flags.
  12. The B<dcont> parameter is used in the rare case where the encrypted content
  13. is detached. It will normally be set to NULL.
  14. =head1 NOTES
  15. OpenSSL_add_all_algorithms() (or equivalent) should be called before using this
  16. function or errors about unknown algorithms will occur.
  17. Although the recipients certificate is not needed to decrypt the data it is
  18. needed to locate the appropriate (of possible several) recipients in the CMS
  19. structure.
  20. If B<cert> is set to NULL all possible recipients are tried. This case however
  21. is problematic. To thwart the MMA attack (Bleichenbacher's attack on
  22. PKCS #1 v1.5 RSA padding) all recipients are tried whether they succeed or
  23. not. If no recipient succeeds then a random symmetric key is used to decrypt
  24. the content: this will typically output garbage and may (but is not guaranteed
  25. to) ultimately return a padding error only. If CMS_decrypt() just returned an
  26. error when all recipient encrypted keys failed to decrypt an attacker could
  27. use this in a timing attack. If the special flag B<CMS_DEBUG_DECRYPT> is set
  28. then the above behaviour is modified and an error B<is> returned if no
  29. recipient encrypted key can be decrypted B<without> generating a random
  30. content encryption key. Applications should use this flag with
  31. B<extreme caution> especially in automated gateways as it can leave them
  32. open to attack.
  33. It is possible to determine the correct recipient key by other means (for
  34. example looking them up in a database) and setting them in the CMS structure
  35. in advance using the CMS utility functions such as CMS_set1_pkey(). In this
  36. case both B<cert> and B<pkey> should be set to NULL.
  37. To process KEKRecipientInfo types CMS_set1_key() or CMS_RecipientInfo_set0_key()
  38. and CMS_ReceipientInfo_decrypt() should be called before CMS_decrypt() and
  39. B<cert> and B<pkey> set to NULL.
  40. The following flags can be passed in the B<flags> parameter.
  41. If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted
  42. from the content. If the content is not of type B<text/plain> then an error is
  43. returned.
  44. =head1 RETURN VALUES
  45. CMS_decrypt() returns either 1 for success or 0 for failure.
  46. The error can be obtained from ERR_get_error(3)
  47. =head1 BUGS
  48. The lack of single pass processing and the need to hold all data in memory as
  49. mentioned in CMS_verify() also applies to CMS_decrypt().
  50. =head1 SEE ALSO
  51. L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_encrypt(3)|CMS_encrypt(3)>
  52. =head1 HISTORY
  53. CMS_decrypt() was added to OpenSSL 0.9.8
  54. =cut