Debian Codegraph @

upstream/debian-unstable/man3/CMS_sign.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
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 3SSL"
58 .TH CMS_SIGN 3SSL 2026-04-07 3.6.2 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 at all. If \fBCMS_NOSMIMECAP\fR is set then the SMIMECapabilities
122 will be omitted. If \fBCMS_NO_SIGNING_TIME\fR is set then the signing time will be
123 omitted.
124 .PP
125 If present the SMIMECapabilities attribute indicates support for the following
126 algorithms in preference order: 256 bit AES, Gost R3411\-94, Gost 28147\-89, 192
127 bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
128 If any of these algorithms is not available then it will not be included:
129 for example the GOST algorithms will not be included if the GOST ENGINE is
130 not loaded.
131 .PP
132 OpenSSL will by default identify signing certificates using issuer name
133 and serial number. If \fBCMS_USE_KEYID\fR is set it will use the subject key
134 identifier value instead. An error occurs if the signing certificate does not
135 have a subject key identifier extension.
136 .PP
137 If the flags \fBCMS_STREAM\fR is set then the returned \fBCMS_ContentInfo\fR
138 structure is just initialized ready to perform the signing operation. The
139 signing is however \fBnot\fR performed and the data to be signed is not read from
140 the \fBdata\fR parameter. Signing is deferred until after the data has been
141 written. In this way data can be signed in a single pass.
142 .PP
143 If the \fBCMS_PARTIAL\fR flag is set a partial \fBCMS_ContentInfo\fR structure is
144 output to which additional signers and capabilities can be added before
145 finalization.
146 .PP
147 If the flag \fBCMS_STREAM\fR is set the returned \fBCMS_ContentInfo\fR structure is
148 \&\fBnot\fR complete and outputting its contents via a function that does not
149 properly finalize the \fBCMS_ContentInfo\fR structure will give unpredictable
150 results.
151 .PP
152 Several functions including \fBSMIME_write_CMS()\fR, \fBi2d_CMS_bio_stream()\fR,
153 \&\fBPEM_write_bio_CMS_stream()\fR finalize the structure. Alternatively finalization
154 can be performed by obtaining the streaming ASN1 \fBBIO\fR directly using
155 \&\fBBIO_new_CMS()\fR.
156 .PP
157 If a signer is specified it will use the default digest for the signing
158 algorithm. This is \fBSHA256\fR for both RSA and DSA keys.
159 .PP
160 If \fBsigncert\fR and \fBpkey\fR are NULL then a certificates only CMS structure is
161 output.
162 .PP
163 The function \fBCMS_sign()\fR is a basic CMS signing function whose output will be
164 suitable for many purposes. For finer control of the output format the
165 \&\fBcerts\fR, \fBsigncert\fR and \fBpkey\fR parameters can all be \fBNULL\fR and the
166 \&\fBCMS_PARTIAL\fR flag set. Then one or more signers can be added using the
167 function \fBCMS_add1_signer()\fR, non default digests can be used and custom
168 attributes added. \fBCMS_final()\fR must then be called to finalize the
169 structure if streaming is not enabled.
170 .SH BUGS
171 .IX Header "BUGS"
172 Some attributes such as counter signatures are not supported.
173 .SH "RETURN VALUES"
174 .IX Header "RETURN VALUES"
175 \&\fBCMS_sign_ex()\fR and \fBCMS_sign()\fR return either a valid CMS_ContentInfo
176 structure or NULL if an error occurred. The error can be obtained from
177 \&\fBERR_get_error\fR\|(3).
178 .SH "SEE ALSO"
179 .IX Header "SEE ALSO"
180 \&\fBERR_get_error\fR\|(3), \fBCMS_verify\fR\|(3)
181 .SH HISTORY
182 .IX Header "HISTORY"
183 The \fBCMS_STREAM\fR flag is only supported for detached data in OpenSSL 0.9.8,
184 it is supported for embedded data in OpenSSL 1.0.0 and later.
185 .PP
186 The \fBCMS_sign_ex()\fR method was added in OpenSSL 3.0.
187 .PP
188 Since OpenSSL 3.2, \fBCMS_sign_ex()\fR and \fBCMS_sign()\fR ignore any duplicate
189 certificates in their \fIcerts\fR argument and no longer throw an error for them.
190 .SH COPYRIGHT
191 .IX Header "COPYRIGHT"
192 Copyright 2008\-2025 The OpenSSL Project Authors. All Rights Reserved.
193 .PP
194 Licensed under the Apache License 2.0 (the "License"). You may not use
195 this file except in compliance with the License. You can obtain a copy
196 in the file LICENSE in the source distribution or at
197 <https://www.openssl.org/source/license.html>.