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