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