CMS_sign.3ossl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "CMS_SIGN 3ossl"
  58. .TH CMS_SIGN 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. CMS_sign, CMS_sign_ex \- create a CMS SignedData structure
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 1
  68. \& #include <openssl/cms.h>
  69. \&
  70. \& CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey,
  71. \& STACK_OF(X509) *certs, BIO *data,
  72. \& unsigned int flags, OSSL_LIB_CTX *ctx,
  73. \& const char *propq);
  74. \& CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
  75. \& BIO *data, unsigned int flags);
  76. .Ve
  77. .SH DESCRIPTION
  78. .IX Header "DESCRIPTION"
  79. \&\fBCMS_sign_ex()\fR creates and returns a CMS SignedData structure.
  80. \&\fIsigncert\fR is the certificate to sign with, \fIpkey\fR is the corresponding
  81. private key. \fIcerts\fR is an optional additional set of certificates to include
  82. in the CMS structure (for example any intermediate CAs in the chain). The
  83. library context \fIlibctx\fR and the property query \fIpropq\fR are used when
  84. retrieving algorithms from providers. Any or all of these parameters can be
  85. \&\fBNULL\fR, see \fBNOTES\fR below.
  86. .PP
  87. The data to be signed is read from BIO \fBdata\fR.
  88. .PP
  89. \&\fBflags\fR is an optional set of flags.
  90. .PP
  91. \&\fBCMS_sign()\fR is similar to \fBCMS_sign_ex()\fR but uses default values of NULL
  92. for the library context \fIlibctx\fR and the property query \fIpropq\fR.
  93. .SH NOTES
  94. .IX Header "NOTES"
  95. Any of the following flags (ored together) can be passed in the \fBflags\fR
  96. parameter.
  97. .PP
  98. Many S/MIME clients expect the signed content to include valid MIME headers. If
  99. the \fBCMS_TEXT\fR flag is set MIME headers for type \fBtext/plain\fR are prepended
  100. to the data.
  101. .PP
  102. If \fBCMS_NOCERTS\fR is set the signer's certificate will not be included in the
  103. CMS_ContentInfo structure, the signer's certificate must still be supplied in
  104. the \fBsigncert\fR parameter though. This can reduce the size of the signature if
  105. the signers certificate can be obtained by other means: for example a
  106. previously signed message.
  107. .PP
  108. The data being signed is included in the CMS_ContentInfo structure, unless
  109. \&\fBCMS_DETACHED\fR is set in which case it is omitted. This is used for
  110. CMS_ContentInfo detached signatures which are used in S/MIME plaintext signed
  111. messages for example.
  112. .PP
  113. Normally the supplied content is translated into MIME canonical format (as
  114. required by the S/MIME specifications) if \fBCMS_BINARY\fR is set no translation
  115. occurs. This option should be used if the supplied data is in binary format
  116. otherwise the translation will corrupt it.
  117. .PP
  118. The SignedData structure includes several CMS signedAttributes including the
  119. signing time, the CMS content type and the supported list of ciphers in an
  120. SMIMECapabilities attribute. If \fBCMS_NOATTR\fR is set then no signedAttributes
  121. will be used. If \fBCMS_NOSMIMECAP\fR is set then just the SMIMECapabilities are
  122. omitted.
  123. .PP
  124. If present the SMIMECapabilities attribute indicates support for the following
  125. algorithms in preference order: 256 bit AES, Gost R3411\-94, Gost 28147\-89, 192
  126. bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
  127. If any of these algorithms is not available then it will not be included:
  128. for example the GOST algorithms will not be included if the GOST ENGINE is
  129. not loaded.
  130. .PP
  131. OpenSSL will by default identify signing certificates using issuer name
  132. and serial number. If \fBCMS_USE_KEYID\fR is set it will use the subject key
  133. identifier value instead. An error occurs if the signing certificate does not
  134. have a subject key identifier extension.
  135. .PP
  136. If the flags \fBCMS_STREAM\fR is set then the returned \fBCMS_ContentInfo\fR
  137. structure is just initialized ready to perform the signing operation. The
  138. signing is however \fBnot\fR performed and the data to be signed is not read from
  139. the \fBdata\fR parameter. Signing is deferred until after the data has been
  140. written. In this way data can be signed in a single pass.
  141. .PP
  142. If the \fBCMS_PARTIAL\fR flag is set a partial \fBCMS_ContentInfo\fR structure is
  143. output to which additional signers and capabilities can be added before
  144. finalization.
  145. .PP
  146. If the flag \fBCMS_STREAM\fR is set the returned \fBCMS_ContentInfo\fR structure is
  147. \&\fBnot\fR complete and outputting its contents via a function that does not
  148. properly finalize the \fBCMS_ContentInfo\fR structure will give unpredictable
  149. results.
  150. .PP
  151. Several functions including \fBSMIME_write_CMS()\fR, \fBi2d_CMS_bio_stream()\fR,
  152. \&\fBPEM_write_bio_CMS_stream()\fR finalize the structure. Alternatively finalization
  153. can be performed by obtaining the streaming ASN1 \fBBIO\fR directly using
  154. \&\fBBIO_new_CMS()\fR.
  155. .PP
  156. If a signer is specified it will use the default digest for the signing
  157. algorithm. This is \fBSHA1\fR for both RSA and DSA keys.
  158. .PP
  159. If \fBsigncert\fR and \fBpkey\fR are NULL then a certificates only CMS structure is
  160. output.
  161. .PP
  162. The function \fBCMS_sign()\fR is a basic CMS signing function whose output will be
  163. suitable for many purposes. For finer control of the output format the
  164. \&\fBcerts\fR, \fBsigncert\fR and \fBpkey\fR parameters can all be \fBNULL\fR and the
  165. \&\fBCMS_PARTIAL\fR flag set. Then one or more signers can be added using the
  166. function \fBCMS_add1_signer()\fR, non default digests can be used and custom
  167. attributes added. \fBCMS_final()\fR must then be called to finalize the
  168. structure if streaming is not enabled.
  169. .SH BUGS
  170. .IX Header "BUGS"
  171. Some attributes such as counter signatures are not supported.
  172. .SH "RETURN VALUES"
  173. .IX Header "RETURN VALUES"
  174. \&\fBCMS_sign_ex()\fR and \fBCMS_sign()\fR return either a valid CMS_ContentInfo
  175. structure or NULL if an error occurred. The error can be obtained from
  176. \&\fBERR_get_error\fR\|(3).
  177. .SH "SEE ALSO"
  178. .IX Header "SEE ALSO"
  179. \&\fBERR_get_error\fR\|(3), \fBCMS_verify\fR\|(3)
  180. .SH HISTORY
  181. .IX Header "HISTORY"
  182. The \fBCMS_STREAM\fR flag is only supported for detached data in OpenSSL 0.9.8,
  183. it is supported for embedded data in OpenSSL 1.0.0 and later.
  184. .PP
  185. The \fBCMS_sign_ex()\fR method was added in OpenSSL 3.0.
  186. .PP
  187. Since OpenSSL 3.2, \fBCMS_sign_ex()\fR and \fBCMS_sign()\fR ignore any duplicate
  188. certificates in their \fIcerts\fR argument and no longer throw an error for them.
  189. .SH COPYRIGHT
  190. .IX Header "COPYRIGHT"
  191. Copyright 2008\-2023 The OpenSSL Project Authors. All Rights Reserved.
  192. .PP
  193. Licensed under the Apache License 2.0 (the "License"). You may not use
  194. this file except in compliance with the License. You can obtain a copy
  195. in the file LICENSE in the source distribution or at
  196. <https://www.openssl.org/source/license.html>.