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