| 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 "PKCS7_SIGN 3SSL" |
| 58 |
.TH PKCS7_SIGN 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 |
PKCS7_sign_ex, PKCS7_sign |
| 65 |
\&\- create a PKCS#7 signedData structure |
| 66 |
.SH SYNOPSIS |
| 67 |
.IX Header "SYNOPSIS" |
| 68 |
.Vb 1 |
| 69 |
\& #include <openssl/pkcs7.h> |
| 70 |
\& |
| 71 |
\& PKCS7 *PKCS7_sign_ex(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, |
| 72 |
\& BIO *data, int flags, OSSL_LIB_CTX *libctx, |
| 73 |
\& const char *propq); |
| 74 |
\& PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, |
| 75 |
\& BIO *data, int flags); |
| 76 |
.Ve |
| 77 |
.SH DESCRIPTION |
| 78 |
.IX Header "DESCRIPTION" |
| 79 |
\&\fBPKCS7_sign_ex()\fR creates and returns a PKCS#7 signedData structure. |
| 80 |
\&\fIsigncert\fR is the certificate to sign with, \fIpkey\fR is the corresponding |
| 81 |
private key. \fIcerts\fR is an optional set of extra certificates to include |
| 82 |
in the PKCS#7 structure (for example any intermediate CAs in the chain). |
| 83 |
The library context \fIlibctx\fR and property query \fIpropq\fR are used when |
| 84 |
retrieving algorithms from providers. |
| 85 |
.PP |
| 86 |
The data to be signed is read from BIO \fIdata\fR. |
| 87 |
.PP |
| 88 |
\&\fIflags\fR is an optional set of flags. |
| 89 |
.PP |
| 90 |
Any of the following flags (ored together) can be passed in the \fIflags\fR |
| 91 |
parameter. |
| 92 |
.PP |
| 93 |
Many S/MIME clients expect the signed content to include valid MIME headers. If |
| 94 |
the \fBPKCS7_TEXT\fR flag is set MIME headers for type \f(CW\*(C`text/plain\*(C'\fR are prepended |
| 95 |
to the data. |
| 96 |
.PP |
| 97 |
If \fBPKCS7_NOCERTS\fR is set the signer's certificate and the extra \fIcerts\fR |
| 98 |
will not be included in the PKCS7 structure. |
| 99 |
The signer's certificate must still be supplied in the \fIsigncert\fR parameter |
| 100 |
though. This can reduce the size of the signatures if the signer's certificates |
| 101 |
can be obtained by other means: for example a previously signed message. |
| 102 |
.PP |
| 103 |
The data being signed is included in the PKCS7 structure, unless |
| 104 |
\&\fBPKCS7_DETACHED\fR is set in which case it is omitted. This is used for PKCS7 |
| 105 |
detached signatures which are used in S/MIME plaintext signed messages for |
| 106 |
example. |
| 107 |
.PP |
| 108 |
Normally the supplied content is translated into MIME canonical format (as |
| 109 |
required by the S/MIME specifications) if \fBPKCS7_BINARY\fR is set no translation |
| 110 |
occurs. This option should be used if the supplied data is in binary format |
| 111 |
otherwise the translation will corrupt it. |
| 112 |
.PP |
| 113 |
The signedData structure includes several PKCS#7 authenticatedAttributes |
| 114 |
including the signing time, the PKCS#7 content type and the supported list of |
| 115 |
ciphers in an SMIMECapabilities attribute. If \fBPKCS7_NOATTR\fR is set then no |
| 116 |
authenticatedAttributes will be used. If \fBPKCS7_NOSMIMECAP\fR is set then just |
| 117 |
the SMIMECapabilities are omitted. |
| 118 |
.PP |
| 119 |
If present the SMIMECapabilities attribute indicates support for the following |
| 120 |
algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any of |
| 121 |
these algorithms is disabled then it will not be included. |
| 122 |
.PP |
| 123 |
If the flags \fBPKCS7_STREAM\fR is set then the returned \fBPKCS7\fR structure is |
| 124 |
just initialized ready to perform the signing operation. The signing is however |
| 125 |
\&\fBnot\fR performed and the data to be signed is not read from the \fIdata\fR |
| 126 |
parameter. Signing is deferred until after the data has been written. In this |
| 127 |
way data can be signed in a single pass. |
| 128 |
.PP |
| 129 |
If the \fBPKCS7_PARTIAL\fR flag is set a partial \fBPKCS7\fR structure is output to |
| 130 |
which additional signers and capabilities can be added before finalization. |
| 131 |
.PP |
| 132 |
If the flag \fBPKCS7_STREAM\fR is set the returned \fBPKCS7\fR structure is \fBnot\fR |
| 133 |
complete and outputting its contents via a function that does not properly |
| 134 |
finalize the \fBPKCS7\fR structure will give unpredictable results. |
| 135 |
.PP |
| 136 |
Several functions including \fBSMIME_write_PKCS7()\fR, \fBi2d_PKCS7_bio_stream()\fR, |
| 137 |
\&\fBPEM_write_bio_PKCS7_stream()\fR finalize the structure. Alternatively finalization |
| 138 |
can be performed by obtaining the streaming ASN1 \fBBIO\fR directly using |
| 139 |
\&\fBBIO_new_PKCS7()\fR. |
| 140 |
.PP |
| 141 |
If a signer is specified it will use the default digest for the signing |
| 142 |
algorithm. This is \fBSHA256\fR for both RSA and DSA keys. |
| 143 |
.PP |
| 144 |
The \fIcerts\fR, \fIsigncert\fR and \fIpkey\fR parameters can all be |
| 145 |
NULL if the \fBPKCS7_PARTIAL\fR flag is set. One or more signers can be added |
| 146 |
using the function \fBPKCS7_sign_add_signer()\fR. \fBPKCS7_final()\fR must also be |
| 147 |
called to finalize the structure if streaming is not enabled. Alternative |
| 148 |
signing digests can also be specified using this method. |
| 149 |
.PP |
| 150 |
If \fIsigncert\fR and \fIpkey\fR are NULL then a certificates only |
| 151 |
PKCS#7 structure is output. |
| 152 |
.PP |
| 153 |
In versions of OpenSSL before 1.0.0 the \fIsigncert\fR and \fIpkey\fR parameters must |
| 154 |
not be NULL. |
| 155 |
.PP |
| 156 |
\&\fBPKCS7_sign()\fR is like \fBPKCS7_sign_ex()\fR except that it uses default values of |
| 157 |
NULL for the library context \fIlibctx\fR and the property query \fIpropq\fR. |
| 158 |
This is retained for API backward compatibility. |
| 159 |
.SH BUGS |
| 160 |
.IX Header "BUGS" |
| 161 |
Some advanced attributes such as counter signatures are not supported. |
| 162 |
.SH "RETURN VALUES" |
| 163 |
.IX Header "RETURN VALUES" |
| 164 |
\&\fBPKCS7_sign_ex()\fR and \fBPKCS7_sign()\fR return either a valid PKCS7 structure |
| 165 |
or NULL if an error occurred. The error can be obtained from \fBERR_get_error\fR\|(3). |
| 166 |
.SH "SEE ALSO" |
| 167 |
.IX Header "SEE ALSO" |
| 168 |
\&\fBERR_get_error\fR\|(3), \fBPKCS7_verify\fR\|(3) |
| 169 |
.SH HISTORY |
| 170 |
.IX Header "HISTORY" |
| 171 |
The function \fBPKCS7_sign_ex()\fR was added in OpenSSL 3.0. |
| 172 |
.PP |
| 173 |
The \fBPKCS7_PARTIAL\fR flag, and the ability for \fIcerts\fR, \fIsigncert\fR, |
| 174 |
and \fIpkey\fR parameters to be NULL were added in OpenSSL 1.0.0. |
| 175 |
.PP |
| 176 |
The \fBPKCS7_STREAM\fR flag was added in OpenSSL 1.0.0. |
| 177 |
.SH COPYRIGHT |
| 178 |
.IX Header "COPYRIGHT" |
| 179 |
Copyright 2002\-2025 The OpenSSL Project Authors. All Rights Reserved. |
| 180 |
.PP |
| 181 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 182 |
this file except in compliance with the License. You can obtain a copy |
| 183 |
in the file LICENSE in the source distribution or at |
| 184 |
<https://www.openssl.org/source/license.html>. |