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