CMS_sign.pod 4.9 KB

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