xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/PKCS7_sign.pod (revision 4170684f22077e3779c5c14826430de0dec964b2)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
5b0d17251SchristosPKCS7_sign_ex, PKCS7_sign
6b0d17251Schristos- create a PKCS#7 signedData structure
713d40330Schristos
813d40330Schristos=head1 SYNOPSIS
913d40330Schristos
1013d40330Schristos #include <openssl/pkcs7.h>
1113d40330Schristos
12b0d17251Schristos PKCS7 *PKCS7_sign_ex(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
13b0d17251Schristos                      BIO *data, int flags, OSSL_LIB_CTX *libctx,
14b0d17251Schristos                      const char *propq);
1513d40330Schristos PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
1613d40330Schristos                   BIO *data, int flags);
1713d40330Schristos
1813d40330Schristos=head1 DESCRIPTION
1913d40330Schristos
20b0d17251SchristosPKCS7_sign_ex() creates and returns a PKCS#7 signedData structure.
216f6db51eSchristosI<signcert> is the certificate to sign with, I<pkey> is the corresponding
226f6db51eSchristosprivate key. I<certs> is an optional set of extra certificates to include
236f6db51eSchristosin the PKCS#7 structure (for example any intermediate CAs in the chain).
24b0d17251SchristosThe library context I<libctx> and property query I<propq> are used when
25b0d17251Schristosretrieving algorithms from providers.
2613d40330Schristos
276f6db51eSchristosThe data to be signed is read from BIO I<data>.
2813d40330Schristos
296f6db51eSchristosI<flags> is an optional set of flags.
3013d40330Schristos
316f6db51eSchristosAny of the following flags (ored together) can be passed in the I<flags>
32b0d17251Schristosparameter.
3313d40330Schristos
3413d40330SchristosMany S/MIME clients expect the signed content to include valid MIME headers. If
356f6db51eSchristosthe B<PKCS7_TEXT> flag is set MIME headers for type C<text/plain> are prepended
3613d40330Schristosto the data.
3713d40330Schristos
386f6db51eSchristosIf B<PKCS7_NOCERTS> is set the signer's certificate and the extra I<certs>
396f6db51eSchristoswill not be included in the PKCS7 structure.
406f6db51eSchristosThe signer's certificate must still be supplied in the I<signcert> parameter
416f6db51eSchristosthough. This can reduce the size of the signatures if the signer's certificates
426f6db51eSchristoscan be obtained by other means: for example a previously signed message.
4313d40330Schristos
4413d40330SchristosThe data being signed is included in the PKCS7 structure, unless
4513d40330SchristosB<PKCS7_DETACHED> is set in which case it is omitted. This is used for PKCS7
4613d40330Schristosdetached signatures which are used in S/MIME plaintext signed messages for
4713d40330Schristosexample.
4813d40330Schristos
4913d40330SchristosNormally the supplied content is translated into MIME canonical format (as
5013d40330Schristosrequired by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
5113d40330Schristosoccurs. This option should be used if the supplied data is in binary format
5213d40330Schristosotherwise the translation will corrupt it.
5313d40330Schristos
5413d40330SchristosThe signedData structure includes several PKCS#7 authenticatedAttributes
5513d40330Schristosincluding the signing time, the PKCS#7 content type and the supported list of
5613d40330Schristosciphers in an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no
5713d40330SchristosauthenticatedAttributes will be used. If B<PKCS7_NOSMIMECAP> is set then just
5813d40330Schristosthe SMIMECapabilities are omitted.
5913d40330Schristos
6013d40330SchristosIf present the SMIMECapabilities attribute indicates support for the following
6113d40330Schristosalgorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any of
6213d40330Schristosthese algorithms is disabled then it will not be included.
6313d40330Schristos
6413d40330SchristosIf the flags B<PKCS7_STREAM> is set then the returned B<PKCS7> structure is
6513d40330Schristosjust initialized ready to perform the signing operation. The signing is however
666f6db51eSchristosB<not> performed and the data to be signed is not read from the I<data>
6713d40330Schristosparameter. Signing is deferred until after the data has been written. In this
6813d40330Schristosway data can be signed in a single pass.
6913d40330Schristos
7013d40330SchristosIf the B<PKCS7_PARTIAL> flag is set a partial B<PKCS7> structure is output to
7113d40330Schristoswhich additional signers and capabilities can be added before finalization.
7213d40330Schristos
7313d40330SchristosIf the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
7413d40330Schristoscomplete and outputting its contents via a function that does not properly
7513d40330Schristosfinalize the B<PKCS7> structure will give unpredictable results.
7613d40330Schristos
7713d40330SchristosSeveral functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
7813d40330SchristosPEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
7913d40330Schristoscan be performed by obtaining the streaming ASN1 B<BIO> directly using
8013d40330SchristosBIO_new_PKCS7().
8113d40330Schristos
8213d40330SchristosIf a signer is specified it will use the default digest for the signing
8313d40330Schristosalgorithm. This is B<SHA1> for both RSA and DSA keys.
8413d40330Schristos
856f6db51eSchristosThe I<certs>, I<signcert> and I<pkey> parameters can all be
866f6db51eSchristosNULL if the B<PKCS7_PARTIAL> flag is set. One or more signers can be added
8713d40330Schristosusing the function PKCS7_sign_add_signer(). PKCS7_final() must also be
8813d40330Schristoscalled to finalize the structure if streaming is not enabled. Alternative
8913d40330Schristossigning digests can also be specified using this method.
9013d40330Schristos
916f6db51eSchristosIf I<signcert> and I<pkey> are NULL then a certificates only
9213d40330SchristosPKCS#7 structure is output.
9313d40330Schristos
946f6db51eSchristosIn versions of OpenSSL before 1.0.0 the I<signcert> and I<pkey> parameters must
956f6db51eSchristosnot be NULL.
9613d40330Schristos
97b0d17251SchristosPKCS7_sign() is like PKCS7_sign_ex() except that it uses default values of
98b0d17251SchristosNULL for the library context I<libctx> and the property query I<propq>.
99*4170684fSchristosThis is retained for API backward compatibility.
100b0d17251Schristos
10113d40330Schristos=head1 BUGS
10213d40330Schristos
10313d40330SchristosSome advanced attributes such as counter signatures are not supported.
10413d40330Schristos
10513d40330Schristos=head1 RETURN VALUES
10613d40330Schristos
107b0d17251SchristosPKCS7_sign_ex() and PKCS7_sign() return either a valid PKCS7 structure
108b0d17251Schristosor NULL if an error occurred.  The error can be obtained from ERR_get_error(3).
10913d40330Schristos
11013d40330Schristos=head1 SEE ALSO
11113d40330Schristos
11213d40330SchristosL<ERR_get_error(3)>, L<PKCS7_verify(3)>
11313d40330Schristos
11413d40330Schristos=head1 HISTORY
11513d40330Schristos
116b0d17251SchristosThe function PKCS7_sign_ex() was added in OpenSSL 3.0.
117b0d17251Schristos
1186f6db51eSchristosThe B<PKCS7_PARTIAL> flag, and the ability for I<certs>, I<signcert>,
1196f6db51eSchristosand I<pkey> parameters to be NULL were added in OpenSSL 1.0.0.
12013d40330Schristos
121b88c74d5SchristosThe B<PKCS7_STREAM> flag was added in OpenSSL 1.0.0.
12213d40330Schristos
12313d40330Schristos=head1 COPYRIGHT
12413d40330Schristos
125*4170684fSchristosCopyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved.
12613d40330Schristos
127b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
12813d40330Schristosthis file except in compliance with the License.  You can obtain a copy
12913d40330Schristosin the file LICENSE in the source distribution or at
13013d40330SchristosL<https://www.openssl.org/source/license.html>.
13113d40330Schristos
13213d40330Schristos=cut
133