xref: /freebsd/crypto/openssl/doc/man3/CMS_sign.pod (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1=pod
2
3=head1 NAME
4
5CMS_sign - create a CMS SignedData structure
6
7=head1 SYNOPSIS
8
9 #include <openssl/cms.h>
10
11 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
12                           BIO *data, unsigned int flags);
13
14=head1 DESCRIPTION
15
16CMS_sign() creates and returns a CMS SignedData structure. B<signcert> is
17the certificate to sign with, B<pkey> is the corresponding private key.
18B<certs> is an optional additional set of certificates to include in the CMS
19structure (for example any intermediate CAs in the chain). Any or all of
20these parameters can be B<NULL>, see B<NOTES> below.
21
22The data to be signed is read from BIO B<data>.
23
24B<flags> is an optional set of flags.
25
26=head1 NOTES
27
28Any of the following flags (ored together) can be passed in the B<flags>
29parameter.
30
31Many S/MIME clients expect the signed content to include valid MIME headers. If
32the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are prepended
33to the data.
34
35If B<CMS_NOCERTS> is set the signer's certificate will not be included in the
36CMS_ContentInfo structure, the signer's certificate must still be supplied in
37the B<signcert> parameter though. This can reduce the size of the signature if
38the signers certificate can be obtained by other means: for example a
39previously signed message.
40
41The data being signed is included in the CMS_ContentInfo structure, unless
42B<CMS_DETACHED> is set in which case it is omitted. This is used for
43CMS_ContentInfo detached signatures which are used in S/MIME plaintext signed
44messages for example.
45
46Normally the supplied content is translated into MIME canonical format (as
47required by the S/MIME specifications) if B<CMS_BINARY> is set no translation
48occurs. This option should be used if the supplied data is in binary format
49otherwise the translation will corrupt it.
50
51The SignedData structure includes several CMS signedAttributes including the
52signing time, the CMS content type and the supported list of ciphers in an
53SMIMECapabilities attribute. If B<CMS_NOATTR> is set then no signedAttributes
54will be used. If B<CMS_NOSMIMECAP> is set then just the SMIMECapabilities are
55omitted.
56
57If present the SMIMECapabilities attribute indicates support for the following
58algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192
59bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
60If any of these algorithms is not available then it will not be included: for example the GOST algorithms will not be included if the GOST ENGINE is
61not loaded.
62
63OpenSSL will by default identify signing certificates using issuer name
64and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
65identifier value instead. An error occurs if the signing certificate does not
66have a subject key identifier extension.
67
68If the flags B<CMS_STREAM> is set then the returned B<CMS_ContentInfo>
69structure is just initialized ready to perform the signing operation. The
70signing is however B<not> performed and the data to be signed is not read from
71the B<data> parameter. Signing is deferred until after the data has been
72written. In this way data can be signed in a single pass.
73
74If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
75output to which additional signers and capabilities can be added before
76finalization.
77
78If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
79B<not> complete and outputting its contents via a function that does not
80properly finalize the B<CMS_ContentInfo> structure will give unpredictable
81results.
82
83Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
84PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
85can be performed by obtaining the streaming ASN1 B<BIO> directly using
86BIO_new_CMS().
87
88If a signer is specified it will use the default digest for the signing
89algorithm. This is B<SHA1> for both RSA and DSA keys.
90
91If B<signcert> and B<pkey> are NULL then a certificates only CMS structure is
92output.
93
94The function CMS_sign() is a basic CMS signing function whose output will be
95suitable for many purposes. For finer control of the output format the
96B<certs>, B<signcert> and B<pkey> parameters can all be B<NULL> and the
97B<CMS_PARTIAL> flag set. Then one or more signers can be added using the
98function CMS_sign_add1_signer(), non default digests can be used and custom
99attributes added. CMS_final() must then be called to finalize the
100structure if streaming is not enabled.
101
102=head1 BUGS
103
104Some attributes such as counter signatures are not supported.
105
106=head1 RETURN VALUES
107
108CMS_sign() returns either a valid CMS_ContentInfo structure or NULL if an error
109occurred. The error can be obtained from ERR_get_error(3).
110
111=head1 SEE ALSO
112
113L<ERR_get_error(3)>, L<CMS_verify(3)>
114
115=head1 HISTORY
116
117The B<CMS_STREAM> flag is only supported for detached data in OpenSSL 0.9.8,
118it is supported for embedded data in OpenSSL 1.0.0 and later.
119
120=head1 COPYRIGHT
121
122Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
123
124Licensed under the OpenSSL license (the "License").  You may not use
125this file except in compliance with the License.  You can obtain a copy
126in the file LICENSE in the source distribution or at
127L<https://www.openssl.org/source/license.html>.
128
129=cut
130