CMS_sign.pod 5.2 KB

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