OLD | NEW |
(Empty) | |
| 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 corresponding 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 in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192 |
| 58 bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. |
| 59 If any of these algorithms is not available then it will not be included: for ex
ample the GOST algorithms will not be included if the GOST ENGINE is |
| 60 not loaded. |
| 61 |
| 62 OpenSSL will by default identify signing certificates using issuer name |
| 63 and serial number. If B<CMS_USE_KEYID> is set it will use the subject key |
| 64 identifier value instead. An error occurs if the signing certificate does not |
| 65 have a subject key identifier extension. |
| 66 |
| 67 If the flags B<CMS_STREAM> is set then the returned B<CMS_ContentInfo> |
| 68 structure is just initialized ready to perform the signing operation. The |
| 69 signing is however B<not> performed and the data to be signed is not read from |
| 70 the B<data> parameter. Signing is deferred until after the data has been |
| 71 written. In this way data can be signed in a single pass. |
| 72 |
| 73 If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is |
| 74 output to which additional signers and capabilities can be added before |
| 75 finalization. |
| 76 |
| 77 If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is |
| 78 B<not> complete and outputting its contents via a function that does not |
| 79 properly finalize the B<CMS_ContentInfo> structure will give unpredictable |
| 80 results. |
| 81 |
| 82 Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(), |
| 83 PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization |
| 84 can be performed by obtaining the streaming ASN1 B<BIO> directly using |
| 85 BIO_new_CMS(). |
| 86 |
| 87 If a signer is specified it will use the default digest for the signing |
| 88 algorithm. This is B<SHA1> for both RSA and DSA keys. |
| 89 |
| 90 If B<signcert> and B<pkey> are NULL then a certificates only CMS structure is |
| 91 output. |
| 92 |
| 93 The function CMS_sign() is a basic CMS signing function whose output will be |
| 94 suitable for many purposes. For finer control of the output format the |
| 95 B<certs>, B<signcert> and B<pkey> parameters can all be B<NULL> and the |
| 96 B<CMS_PARTIAL> flag set. Then one or more signers can be added using the |
| 97 function CMS_sign_add1_signer(), non default digests can be used and custom |
| 98 attributes added. B<CMS_final()> must then be called to finalize the |
| 99 structure if streaming is not enabled. |
| 100 |
| 101 =head1 BUGS |
| 102 |
| 103 Some attributes such as counter signatures are not supported. |
| 104 |
| 105 =head1 RETURN VALUES |
| 106 |
| 107 CMS_sign() returns either a valid CMS_ContentInfo structure or NULL if an error |
| 108 occurred. The error can be obtained from ERR_get_error(3). |
| 109 |
| 110 =head1 SEE ALSO |
| 111 |
| 112 L<ERR_get_error(3)|ERR_get_error(3)>, L<CMS_verify(3)|CMS_verify(3)> |
| 113 |
| 114 =head1 HISTORY |
| 115 |
| 116 CMS_sign() was added to OpenSSL 0.9.8 |
| 117 |
| 118 The B<CMS_STREAM> flag is only supported for detached data in OpenSSL 0.9.8, |
| 119 it is supported for embedded data in OpenSSL 1.0.0 and later. |
| 120 |
| 121 =cut |
OLD | NEW |