1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5b077aed3SPierre ProncheryCMS_sign, CMS_sign_ex - create a CMS SignedData structure 6e71b7053SJung-uk Kim 7e71b7053SJung-uk Kim=head1 SYNOPSIS 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim #include <openssl/cms.h> 10e71b7053SJung-uk Kim 11b077aed3SPierre Pronchery CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey, 12b077aed3SPierre Pronchery STACK_OF(X509) *certs, BIO *data, 13b077aed3SPierre Pronchery unsigned int flags, OSSL_LIB_CTX *ctx, 14b077aed3SPierre Pronchery const char *propq); 15e71b7053SJung-uk Kim CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, 16e71b7053SJung-uk Kim BIO *data, unsigned int flags); 17e71b7053SJung-uk Kim 18e71b7053SJung-uk Kim=head1 DESCRIPTION 19e71b7053SJung-uk Kim 20b077aed3SPierre ProncheryCMS_sign_ex() creates and returns a CMS SignedData structure. 21b077aed3SPierre ProncheryI<signcert> is the certificate to sign with, I<pkey> is the corresponding 22b077aed3SPierre Proncheryprivate key. I<certs> is an optional additional set of certificates to include 23b077aed3SPierre Proncheryin the CMS structure (for example any intermediate CAs in the chain). The 24b077aed3SPierre Proncherylibrary context I<libctx> and the property query I<propq> are used when 25b077aed3SPierre Proncheryretrieving algorithms from providers. Any or all of these parameters can be 26b077aed3SPierre ProncheryB<NULL>, see B<NOTES> below. 27e71b7053SJung-uk Kim 28e71b7053SJung-uk KimThe data to be signed is read from BIO B<data>. 29e71b7053SJung-uk Kim 30e71b7053SJung-uk KimB<flags> is an optional set of flags. 31e71b7053SJung-uk Kim 32b077aed3SPierre ProncheryCMS_sign() is similar to CMS_sign_ex() but uses default values of NULL 33b077aed3SPierre Proncheryfor the library context I<libctx> and the property query I<propq>. 34b077aed3SPierre Pronchery 35e71b7053SJung-uk Kim=head1 NOTES 36e71b7053SJung-uk Kim 37e71b7053SJung-uk KimAny of the following flags (ored together) can be passed in the B<flags> 38e71b7053SJung-uk Kimparameter. 39e71b7053SJung-uk Kim 40e71b7053SJung-uk KimMany S/MIME clients expect the signed content to include valid MIME headers. If 41e71b7053SJung-uk Kimthe B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are prepended 42e71b7053SJung-uk Kimto the data. 43e71b7053SJung-uk Kim 44e71b7053SJung-uk KimIf B<CMS_NOCERTS> is set the signer's certificate will not be included in the 45e71b7053SJung-uk KimCMS_ContentInfo structure, the signer's certificate must still be supplied in 46e71b7053SJung-uk Kimthe B<signcert> parameter though. This can reduce the size of the signature if 47e71b7053SJung-uk Kimthe signers certificate can be obtained by other means: for example a 48e71b7053SJung-uk Kimpreviously signed message. 49e71b7053SJung-uk Kim 50e71b7053SJung-uk KimThe data being signed is included in the CMS_ContentInfo structure, unless 51e71b7053SJung-uk KimB<CMS_DETACHED> is set in which case it is omitted. This is used for 52e71b7053SJung-uk KimCMS_ContentInfo detached signatures which are used in S/MIME plaintext signed 53e71b7053SJung-uk Kimmessages for example. 54e71b7053SJung-uk Kim 55e71b7053SJung-uk KimNormally the supplied content is translated into MIME canonical format (as 56e71b7053SJung-uk Kimrequired by the S/MIME specifications) if B<CMS_BINARY> is set no translation 57e71b7053SJung-uk Kimoccurs. This option should be used if the supplied data is in binary format 58e71b7053SJung-uk Kimotherwise the translation will corrupt it. 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimThe SignedData structure includes several CMS signedAttributes including the 61e71b7053SJung-uk Kimsigning time, the CMS content type and the supported list of ciphers in an 62e71b7053SJung-uk KimSMIMECapabilities attribute. If B<CMS_NOATTR> is set then no signedAttributes 63e71b7053SJung-uk Kimwill be used. If B<CMS_NOSMIMECAP> is set then just the SMIMECapabilities are 64e71b7053SJung-uk Kimomitted. 65e71b7053SJung-uk Kim 66e71b7053SJung-uk KimIf present the SMIMECapabilities attribute indicates support for the following 67e71b7053SJung-uk Kimalgorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192 68e71b7053SJung-uk Kimbit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. 69b077aed3SPierre ProncheryIf any of these algorithms is not available then it will not be included: 70b077aed3SPierre Proncheryfor example the GOST algorithms will not be included if the GOST ENGINE is 71e71b7053SJung-uk Kimnot loaded. 72e71b7053SJung-uk Kim 73e71b7053SJung-uk KimOpenSSL will by default identify signing certificates using issuer name 74e71b7053SJung-uk Kimand serial number. If B<CMS_USE_KEYID> is set it will use the subject key 75e71b7053SJung-uk Kimidentifier value instead. An error occurs if the signing certificate does not 76e71b7053SJung-uk Kimhave a subject key identifier extension. 77e71b7053SJung-uk Kim 78e71b7053SJung-uk KimIf the flags B<CMS_STREAM> is set then the returned B<CMS_ContentInfo> 79e71b7053SJung-uk Kimstructure is just initialized ready to perform the signing operation. The 80e71b7053SJung-uk Kimsigning is however B<not> performed and the data to be signed is not read from 81e71b7053SJung-uk Kimthe B<data> parameter. Signing is deferred until after the data has been 82e71b7053SJung-uk Kimwritten. In this way data can be signed in a single pass. 83e71b7053SJung-uk Kim 84e71b7053SJung-uk KimIf the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is 85e71b7053SJung-uk Kimoutput to which additional signers and capabilities can be added before 86e71b7053SJung-uk Kimfinalization. 87e71b7053SJung-uk Kim 88e71b7053SJung-uk KimIf the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is 89e71b7053SJung-uk KimB<not> complete and outputting its contents via a function that does not 90e71b7053SJung-uk Kimproperly finalize the B<CMS_ContentInfo> structure will give unpredictable 91e71b7053SJung-uk Kimresults. 92e71b7053SJung-uk Kim 93e71b7053SJung-uk KimSeveral functions including SMIME_write_CMS(), i2d_CMS_bio_stream(), 94e71b7053SJung-uk KimPEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization 95e71b7053SJung-uk Kimcan be performed by obtaining the streaming ASN1 B<BIO> directly using 96e71b7053SJung-uk KimBIO_new_CMS(). 97e71b7053SJung-uk Kim 98e71b7053SJung-uk KimIf a signer is specified it will use the default digest for the signing 99e71b7053SJung-uk Kimalgorithm. This is B<SHA1> for both RSA and DSA keys. 100e71b7053SJung-uk Kim 101e71b7053SJung-uk KimIf B<signcert> and B<pkey> are NULL then a certificates only CMS structure is 102e71b7053SJung-uk Kimoutput. 103e71b7053SJung-uk Kim 104e71b7053SJung-uk KimThe function CMS_sign() is a basic CMS signing function whose output will be 105e71b7053SJung-uk Kimsuitable for many purposes. For finer control of the output format the 106e71b7053SJung-uk KimB<certs>, B<signcert> and B<pkey> parameters can all be B<NULL> and the 107e71b7053SJung-uk KimB<CMS_PARTIAL> flag set. Then one or more signers can be added using the 108*6f1af0d7SPierre Proncheryfunction CMS_add1_signer(), non default digests can be used and custom 109e71b7053SJung-uk Kimattributes added. CMS_final() must then be called to finalize the 110e71b7053SJung-uk Kimstructure if streaming is not enabled. 111e71b7053SJung-uk Kim 112e71b7053SJung-uk Kim=head1 BUGS 113e71b7053SJung-uk Kim 114e71b7053SJung-uk KimSome attributes such as counter signatures are not supported. 115e71b7053SJung-uk Kim 116e71b7053SJung-uk Kim=head1 RETURN VALUES 117e71b7053SJung-uk Kim 118b077aed3SPierre ProncheryCMS_sign_ex() and CMS_sign() return either a valid CMS_ContentInfo 119b077aed3SPierre Proncherystructure or NULL if an error occurred. The error can be obtained from 120b077aed3SPierre ProncheryERR_get_error(3). 121e71b7053SJung-uk Kim 122e71b7053SJung-uk Kim=head1 SEE ALSO 123e71b7053SJung-uk Kim 124e71b7053SJung-uk KimL<ERR_get_error(3)>, L<CMS_verify(3)> 125e71b7053SJung-uk Kim 126e71b7053SJung-uk Kim=head1 HISTORY 127e71b7053SJung-uk Kim 128e71b7053SJung-uk KimThe B<CMS_STREAM> flag is only supported for detached data in OpenSSL 0.9.8, 129e71b7053SJung-uk Kimit is supported for embedded data in OpenSSL 1.0.0 and later. 130e71b7053SJung-uk Kim 131b077aed3SPierre ProncheryThe CMS_sign_ex() method was added in OpenSSL 3.0. 132b077aed3SPierre Pronchery 133e71b7053SJung-uk Kim=head1 COPYRIGHT 134e71b7053SJung-uk Kim 135*6f1af0d7SPierre ProncheryCopyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved. 136e71b7053SJung-uk Kim 137b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 138e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 139e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 140e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 141e71b7053SJung-uk Kim 142e71b7053SJung-uk Kim=cut 143