| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "CMS_DECRYPT 3SSL" |
| 58 |
.TH CMS_DECRYPT 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
CMS_decrypt, CMS_decrypt_set1_pkey_and_peer, |
| 65 |
CMS_decrypt_set1_pkey, CMS_decrypt_set1_password |
| 66 |
\&\- decrypt content from a CMS envelopedData structure |
| 67 |
.SH SYNOPSIS |
| 68 |
.IX Header "SYNOPSIS" |
| 69 |
.Vb 1 |
| 70 |
\& #include <openssl/cms.h> |
| 71 |
\& |
| 72 |
\& int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, |
| 73 |
\& BIO *dcont, BIO *out, unsigned int flags); |
| 74 |
\& int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, |
| 75 |
\& EVP_PKEY *pk, X509 *cert, X509 *peer); |
| 76 |
\& int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert); |
| 77 |
\& int CMS_decrypt_set1_password(CMS_ContentInfo *cms, |
| 78 |
\& unsigned char *pass, ossl_ssize_t passlen); |
| 79 |
.Ve |
| 80 |
.SH DESCRIPTION |
| 81 |
.IX Header "DESCRIPTION" |
| 82 |
\&\fBCMS_decrypt()\fR extracts the decrypted content from a CMS EnvelopedData |
| 83 |
or AuthEnvelopedData structure. |
| 84 |
It uses \fBCMS_decrypt_set1_pkey()\fR to decrypt the content |
| 85 |
with the recipient private key \fIpkey\fR if \fIpkey\fR is not NULL. |
| 86 |
In this case, the associated certificate is recommended to provide in \fIcert\fR \- |
| 87 |
see the NOTES below. |
| 88 |
\&\fIout\fR is a BIO to write the content to and |
| 89 |
\&\fIflags\fR is an optional set of flags. |
| 90 |
If \fIpkey\fR is NULL the function assumes that decryption was already done |
| 91 |
(e.g., using \fBCMS_decrypt_set1_pkey()\fR or \fBCMS_decrypt_set1_password()\fR) and just |
| 92 |
provides the content unless \fIcert\fR, \fIdcont\fR, and \fIout\fR are NULL as well. |
| 93 |
The \fIdcont\fR parameter is used in the rare case where the encrypted content |
| 94 |
is detached. It will normally be set to NULL. |
| 95 |
.PP |
| 96 |
\&\fBCMS_decrypt_set1_pkey_and_peer()\fR decrypts the CMS_ContentInfo structure \fIcms\fR |
| 97 |
using the private key \fIpkey\fR, the corresponding certificate \fIcert\fR, which is |
| 98 |
recommended but may be NULL, and the (optional) originator certificate \fIpeer\fR. |
| 99 |
On success, it also records in \fIcms\fR the decryption key \fIpkey\fR, and then |
| 100 |
should be followed by \f(CW\*(C`CMS_decrypt(cms, NULL, NULL, dcont, out, flags)\*(C'\fR. |
| 101 |
This call deallocates any decryption key stored in \fIcms\fR. |
| 102 |
.PP |
| 103 |
\&\fBCMS_decrypt_set1_pkey()\fR is the same as |
| 104 |
\&\fBCMS_decrypt_set1_pkey_and_peer()\fR with \fIpeer\fR being NULL. |
| 105 |
.PP |
| 106 |
\&\fBCMS_decrypt_set1_password()\fR decrypts the CMS_ContentInfo structure \fIcms\fR |
| 107 |
using the secret \fIpass\fR of length \fIpasslen\fR. |
| 108 |
On success, it also records in \fIcms\fR the decryption key used, and then |
| 109 |
should be followed by \f(CW\*(C`CMS_decrypt(cms, NULL, NULL, dcont, out, flags)\*(C'\fR. |
| 110 |
This call deallocates any decryption key stored in \fIcms\fR. |
| 111 |
.SH NOTES |
| 112 |
.IX Header "NOTES" |
| 113 |
Although the recipients certificate is not needed to decrypt the data it is |
| 114 |
needed to locate the appropriate (of possible several) recipients in the CMS |
| 115 |
structure. |
| 116 |
.PP |
| 117 |
If \fIcert\fR is set to NULL all possible recipients are tried. This case however |
| 118 |
is problematic. To thwart the MMA attack (Bleichenbacher's attack on |
| 119 |
PKCS #1 v1.5 RSA padding) all recipients are tried whether they succeed or |
| 120 |
not. If no recipient succeeds then a random symmetric key is used to decrypt |
| 121 |
the content: this will typically output garbage and may (but is not guaranteed |
| 122 |
to) ultimately return a padding error only. If \fBCMS_decrypt()\fR just returned an |
| 123 |
error when all recipient encrypted keys failed to decrypt an attacker could |
| 124 |
use this in a timing attack. If the special flag \fBCMS_DEBUG_DECRYPT\fR is set |
| 125 |
then the above behaviour is modified and an error \fBis\fR returned if no |
| 126 |
recipient encrypted key can be decrypted \fBwithout\fR generating a random |
| 127 |
content encryption key. Applications should use this flag with |
| 128 |
\&\fBextreme caution\fR especially in automated gateways as it can leave them |
| 129 |
open to attack. |
| 130 |
.PP |
| 131 |
It is possible to determine the correct recipient key by other means (for |
| 132 |
example looking them up in a database) and setting them in the CMS structure |
| 133 |
in advance using the CMS utility functions such as \fBCMS_set1_pkey()\fR, |
| 134 |
or use \fBCMS_decrypt_set1_password()\fR if the recipient has a symmetric key. |
| 135 |
In these cases both \fIcert\fR and \fIpkey\fR should be set to NULL. |
| 136 |
.PP |
| 137 |
To process KEKRecipientInfo types \fBCMS_set1_key()\fR or \fBCMS_RecipientInfo_set0_key()\fR |
| 138 |
and \fBCMS_RecipientInfo_decrypt()\fR should be called before \fBCMS_decrypt()\fR and |
| 139 |
\&\fIcert\fR and \fIpkey\fR set to NULL. |
| 140 |
.PP |
| 141 |
The following flags can be passed in the \fIflags\fR parameter. |
| 142 |
.PP |
| 143 |
If the \fBCMS_TEXT\fR flag is set MIME headers for type \f(CW\*(C`text/plain\*(C'\fR are deleted |
| 144 |
from the content. If the content is not of type \f(CW\*(C`text/plain\*(C'\fR then an error is |
| 145 |
returned. |
| 146 |
.SH "RETURN VALUES" |
| 147 |
.IX Header "RETURN VALUES" |
| 148 |
\&\fBCMS_decrypt()\fR, \fBCMS_decrypt_set1_pkey_and_peer()\fR, |
| 149 |
\&\fBCMS_decrypt_set1_pkey()\fR, and \fBCMS_decrypt_set1_password()\fR |
| 150 |
return either 1 for success or 0 for failure. |
| 151 |
The error can be obtained from \fBERR_get_error\fR\|(3). |
| 152 |
.SH BUGS |
| 153 |
.IX Header "BUGS" |
| 154 |
The \fBset1_\fR part of these function names is misleading |
| 155 |
and should better read: \fBwith_\fR. |
| 156 |
.PP |
| 157 |
The lack of single pass processing and the need to hold all data in memory as |
| 158 |
mentioned in \fBCMS_verify()\fR also applies to \fBCMS_decrypt()\fR. |
| 159 |
.SH "SEE ALSO" |
| 160 |
.IX Header "SEE ALSO" |
| 161 |
\&\fBERR_get_error\fR\|(3), \fBCMS_encrypt\fR\|(3) |
| 162 |
.SH HISTORY |
| 163 |
.IX Header "HISTORY" |
| 164 |
\&\fBCMS_decrypt_set1_pkey_and_peer()\fR and \fBCMS_decrypt_set1_password()\fR |
| 165 |
were added in OpenSSL 3.0. |
| 166 |
.SH COPYRIGHT |
| 167 |
.IX Header "COPYRIGHT" |
| 168 |
Copyright 2008\-2020 The OpenSSL Project Authors. All Rights Reserved. |
| 169 |
.PP |
| 170 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 171 |
this file except in compliance with the License. You can obtain a copy |
| 172 |
in the file LICENSE in the source distribution or at |
| 173 |
<https://www.openssl.org/source/license.html>. |