xref: /openbsd/lib/libcrypto/man/PKCS7_sign.3 (revision 09467b48)
1.\" $OpenBSD: PKCS7_sign.3,v 1.13 2020/06/10 11:43:08 schwarze Exp $
2.\" full merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2002, 2003, 2006-2009, 2015 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in
17.\"    the documentation and/or other materials provided with the
18.\"    distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\"    software must display the following acknowledgment:
22.\"    "This product includes software developed by the OpenSSL Project
23.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\"    endorse or promote products derived from this software without
27.\"    prior written permission. For written permission, please contact
28.\"    openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\"    nor may "OpenSSL" appear in their names without prior written
32.\"    permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\"    acknowledgment:
36.\"    "This product includes software developed by the OpenSSL Project
37.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 10 2020 $
53.Dt PKCS7_SIGN 3
54.Os
55.Sh NAME
56.Nm PKCS7_sign
57.Nd create a PKCS#7 signedData structure
58.Sh SYNOPSIS
59.In openssl/pkcs7.h
60.Ft PKCS7 *
61.Fo PKCS7_sign
62.Fa "X509 *signcert"
63.Fa "EVP_PKEY *pkey"
64.Fa "STACK_OF(X509) *certs"
65.Fa "BIO *data"
66.Fa "int flags"
67.Fc
68.Sh DESCRIPTION
69.Fn PKCS7_sign
70creates and returns a PKCS#7 signedData structure.
71.Fa signcert
72is the certificate to sign with,
73.Fa pkey
74is the corresponding private key.
75.Fa certs
76is an optional additional set of certificates to include in the PKCS#7
77structure (for example any intermediate CAs in the chain).
78.Pp
79The data to be signed is read from
80.Vt BIO
81.Fa data .
82.Pp
83.Fa flags
84is an optional set of flags.
85.Pp
86Any of the following flags (OR'ed together) can be passed in the
87.Fa flags
88parameter.
89.Pp
90Many S/MIME clients expect the signed content to include valid MIME
91headers.
92If the
93.Dv PKCS7_TEXT
94flag is set, MIME headers for type
95.Sy text/plain
96are prepended to the data.
97.Pp
98If
99.Dv PKCS7_NOCERTS
100is set, the signer's certificate will not be included in the PKCS7
101structure, though the signer's certificate must still be supplied in the
102.Fa signcert
103parameter.
104This can reduce the size of the signature if the signer's certificate can
105be obtained by other means: for example a previously signed message.
106.Pp
107The data being signed is included in the
108.Vt PKCS7
109structure, unless
110.Dv PKCS7_DETACHED
111is set, in which case it is omitted.
112This is used for PKCS7 detached signatures which are used in S/MIME
113plaintext signed messages for example.
114.Pp
115Normally the supplied content is translated into MIME canonical format
116(as required by the S/MIME specifications).
117If
118.Dv PKCS7_BINARY
119is set, no translation occurs.
120This option should be used if the supplied data is in binary format;
121otherwise, the translation will corrupt it.
122.Pp
123The signedData structure includes several PKCS#7 authenticatedAttributes
124including the signing time, the PKCS#7 content type and the supported
125list of ciphers in an SMIMECapabilities attribute.
126If
127.Dv PKCS7_NOATTR
128is set, then no authenticatedAttributes will be used.
129If
130.Dv PKCS7_NOSMIMECAP
131is set, then just the SMIMECapabilities are omitted.
132.Pp
133If present, the SMIMECapabilities attribute indicates support for the
134following algorithms: triple DES, 128-bit RC2, 64-bit RC2, DES
135and 40-bit RC2.
136If any of these algorithms is disabled then it will not be included.
137.Pp
138If the flags
139.Dv PKCS7_STREAM
140is set, then the returned
141.Vt PKCS7
142structure is just initialized ready to perform the signing operation.
143The signing is however
144.Sy not
145performed and the data to be signed is not read from the
146.Fa data
147parameter.
148Signing is deferred until after the data has been written.
149In this way data can be signed in a single pass.
150.Pp
151If the
152.Dv PKCS7_PARTIAL
153flag is set, a partial
154.Vt PKCS7
155structure is output to which additional signers and capabilities can be
156added before finalization.
157.Pp
158If the flag
159.Dv PKCS7_STREAM
160is set, the returned
161.Vt PKCS7
162structure is
163.Sy not
164complete and outputting its contents via a function that does not
165properly finalize the
166.Vt PKCS7
167structure will give unpredictable results.
168.Pp
169Several functions including
170.Xr PKCS7_final 3 ,
171.Xr SMIME_write_PKCS7 3 ,
172.Xr PEM_write_bio_PKCS7_stream 3 ,
173and
174.Xr i2d_PKCS7_bio_stream 3
175finalize the structure.
176Alternatively finalization can be performed by obtaining the streaming
177ASN.1
178.Vt BIO
179directly using
180.Fn BIO_new_PKCS7 .
181.Pp
182If a signer is specified, it will use the default digest for the
183signing algorithm.
184This is
185.Sy SHA1
186for both RSA and DSA keys.
187.Pp
188In OpenSSL 1.0.0, the
189.Fa certs ,
190.Fa signcert ,
191and
192.Fa pkey
193parameters can all be
194.Dv NULL
195if the
196.Dv PKCS7_PARTIAL
197flag is set.
198One or more signers can be added using the function
199.Xr PKCS7_sign_add_signer 3
200and attributes can be added using the functions described in
201.Xr PKCS7_add_attribute 3 .
202.Xr PKCS7_final 3
203must also be called to finalize the structure if streaming is not
204enabled.
205Alternative signing digests can also be specified using this method.
206.Pp
207In OpenSSL 1.0.0, if
208.Fa signcert
209and
210.Fa pkey
211are
212.Dv NULL ,
213then a certificate-only PKCS#7 structure is output.
214.Pp
215In versions of OpenSSL before 1.0.0 the
216.Fa signcert
217and
218.Fa pkey
219parameters must
220.Sy NOT
221be
222.Dv NULL .
223.Sh RETURN VALUES
224.Fn PKCS7_sign
225returns either a valid
226.Vt PKCS7
227structure or
228.Dv NULL
229if an error occurred.
230The error can be obtained from
231.Xr ERR_get_error 3 .
232.Sh SEE ALSO
233.Xr PKCS7_add_attribute 3 ,
234.Xr PKCS7_encrypt 3 ,
235.Xr PKCS7_final 3 ,
236.Xr PKCS7_get_signer_info 3 ,
237.Xr PKCS7_new 3 ,
238.Xr PKCS7_sign_add_signer 3 ,
239.Xr PKCS7_verify 3
240.Sh HISTORY
241.Fn PKCS7_sign
242first appeared in OpenSSL 0.9.5 and have been available since
243.Ox 2.7 .
244.Pp
245The
246.Dv PKCS7_PARTIAL
247and
248.Dv PKCS7_STREAM
249flags were added in OpenSSL 1.0.0.
250.Sh BUGS
251Some advanced attributes such as counter signatures are not supported.
252