Blame doc/man3/CMS_sign.pod

Packit Service 084de1
=pod
Packit Service 084de1
Packit Service 084de1
=head1 NAME
Packit Service 084de1
Packit Service 084de1
CMS_sign - create a CMS SignedData structure
Packit Service 084de1
Packit Service 084de1
=head1 SYNOPSIS
Packit Service 084de1
Packit Service 084de1
 #include <openssl/cms.h>
Packit Service 084de1
Packit Service 084de1
 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
Packit Service 084de1
                           BIO *data, unsigned int flags);
Packit Service 084de1
Packit Service 084de1
=head1 DESCRIPTION
Packit Service 084de1
Packit Service 084de1
CMS_sign() creates and returns a CMS SignedData structure. B<signcert> is
Packit Service 084de1
the certificate to sign with, B<pkey> is the corresponding private key.
Packit Service 084de1
B<certs> is an optional additional set of certificates to include in the CMS
Packit Service 084de1
structure (for example any intermediate CAs in the chain). Any or all of
Packit Service 084de1
these parameters can be B<NULL>, see B<NOTES> below.
Packit Service 084de1
Packit Service 084de1
The data to be signed is read from BIO B<data>.
Packit Service 084de1
Packit Service 084de1
B<flags> is an optional set of flags.
Packit Service 084de1
Packit Service 084de1
=head1 NOTES
Packit Service 084de1
Packit Service 084de1
Any of the following flags (ored together) can be passed in the B<flags>
Packit Service 084de1
parameter.
Packit Service 084de1
Packit Service 084de1
Many S/MIME clients expect the signed content to include valid MIME headers. If
Packit Service 084de1
the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are prepended
Packit Service 084de1
to the data.
Packit Service 084de1
Packit Service 084de1
If B<CMS_NOCERTS> is set the signer's certificate will not be included in the
Packit Service 084de1
CMS_ContentInfo structure, the signer's certificate must still be supplied in
Packit Service 084de1
the B<signcert> parameter though. This can reduce the size of the signature if
Packit Service 084de1
the signers certificate can be obtained by other means: for example a
Packit Service 084de1
previously signed message.
Packit Service 084de1
Packit Service 084de1
The data being signed is included in the CMS_ContentInfo structure, unless
Packit Service 084de1
B<CMS_DETACHED> is set in which case it is omitted. This is used for
Packit Service 084de1
CMS_ContentInfo detached signatures which are used in S/MIME plaintext signed
Packit Service 084de1
messages for example.
Packit Service 084de1
Packit Service 084de1
Normally the supplied content is translated into MIME canonical format (as
Packit Service 084de1
required by the S/MIME specifications) if B<CMS_BINARY> is set no translation
Packit Service 084de1
occurs. This option should be used if the supplied data is in binary format
Packit Service 084de1
otherwise the translation will corrupt it.
Packit Service 084de1
Packit Service 084de1
The SignedData structure includes several CMS signedAttributes including the
Packit Service 084de1
signing time, the CMS content type and the supported list of ciphers in an
Packit Service 084de1
SMIMECapabilities attribute. If B<CMS_NOATTR> is set then no signedAttributes
Packit Service 084de1
will be used. If B<CMS_NOSMIMECAP> is set then just the SMIMECapabilities are
Packit Service 084de1
omitted.
Packit Service 084de1
Packit Service 084de1
If present the SMIMECapabilities attribute indicates support for the following
Packit Service 084de1
algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192
Packit Service 084de1
bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
Packit Service 084de1
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
Packit Service 084de1
not loaded.
Packit Service 084de1
Packit Service 084de1
OpenSSL will by default identify signing certificates using issuer name
Packit Service 084de1
and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
Packit Service 084de1
identifier value instead. An error occurs if the signing certificate does not
Packit Service 084de1
have a subject key identifier extension.
Packit Service 084de1
Packit Service 084de1
If the flags B<CMS_STREAM> is set then the returned B<CMS_ContentInfo>
Packit Service 084de1
structure is just initialized ready to perform the signing operation. The
Packit Service 084de1
signing is however B<not> performed and the data to be signed is not read from
Packit Service 084de1
the B<data> parameter. Signing is deferred until after the data has been
Packit Service 084de1
written. In this way data can be signed in a single pass.
Packit Service 084de1
Packit Service 084de1
If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
Packit Service 084de1
output to which additional signers and capabilities can be added before
Packit Service 084de1
finalization.
Packit Service 084de1
Packit Service 084de1
If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
Packit Service 084de1
B<not> complete and outputting its contents via a function that does not
Packit Service 084de1
properly finalize the B<CMS_ContentInfo> structure will give unpredictable
Packit Service 084de1
results.
Packit Service 084de1
Packit Service 084de1
Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
Packit Service 084de1
PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
Packit Service 084de1
can be performed by obtaining the streaming ASN1 B<BIO> directly using
Packit Service 084de1
BIO_new_CMS().
Packit Service 084de1
Packit Service 084de1
If a signer is specified it will use the default digest for the signing
Packit Service 084de1
algorithm. This is B<SHA1> for both RSA and DSA keys.
Packit Service 084de1
Packit Service 084de1
If B<signcert> and B<pkey> are NULL then a certificates only CMS structure is
Packit Service 084de1
output.
Packit Service 084de1
Packit Service 084de1
The function CMS_sign() is a basic CMS signing function whose output will be
Packit Service 084de1
suitable for many purposes. For finer control of the output format the
Packit Service 084de1
B<certs>, B<signcert> and B<pkey> parameters can all be B<NULL> and the
Packit Service 084de1
B<CMS_PARTIAL> flag set. Then one or more signers can be added using the
Packit Service 084de1
function CMS_sign_add1_signer(), non default digests can be used and custom
Packit Service 084de1
attributes added. CMS_final() must then be called to finalize the
Packit Service 084de1
structure if streaming is not enabled.
Packit Service 084de1
Packit Service 084de1
=head1 BUGS
Packit Service 084de1
Packit Service 084de1
Some attributes such as counter signatures are not supported.
Packit Service 084de1
Packit Service 084de1
=head1 RETURN VALUES
Packit Service 084de1
Packit Service 084de1
CMS_sign() returns either a valid CMS_ContentInfo structure or NULL if an error
Packit Service 084de1
occurred. The error can be obtained from ERR_get_error(3).
Packit Service 084de1
Packit Service 084de1
=head1 SEE ALSO
Packit Service 084de1
Packit Service 084de1
L<ERR_get_error(3)>, L<CMS_verify(3)>
Packit Service 084de1
Packit Service 084de1
=head1 HISTORY
Packit Service 084de1
Packit Service 084de1
The B<CMS_STREAM> flag is only supported for detached data in OpenSSL 0.9.8,
Packit Service 084de1
it is supported for embedded data in OpenSSL 1.0.0 and later.
Packit Service 084de1
Packit Service 084de1
=head1 COPYRIGHT
Packit Service 084de1
Packit Service 084de1
Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
Packit Service 084de1
Packit Service 084de1
Licensed under the OpenSSL license (the "License").  You may not use
Packit Service 084de1
this file except in compliance with the License.  You can obtain a copy
Packit Service 084de1
in the file LICENSE in the source distribution or at
Packit Service 084de1
L<https://www.openssl.org/source/license.html>.
Packit Service 084de1
Packit Service 084de1
=cut