Home | History | Annotate | Line # | Download | only in man3
      1      1.1  christos =pod
      2      1.1  christos 
      3      1.1  christos =head1 NAME
      4      1.1  christos 
      5  1.1.1.4  christos PKCS7_sign_ex, PKCS7_sign
      6  1.1.1.4  christos - create a PKCS#7 signedData structure
      7      1.1  christos 
      8      1.1  christos =head1 SYNOPSIS
      9      1.1  christos 
     10      1.1  christos  #include <openssl/pkcs7.h>
     11      1.1  christos 
     12  1.1.1.4  christos  PKCS7 *PKCS7_sign_ex(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
     13  1.1.1.4  christos                       BIO *data, int flags, OSSL_LIB_CTX *libctx,
     14  1.1.1.4  christos                       const char *propq);
     15      1.1  christos  PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
     16      1.1  christos                    BIO *data, int flags);
     17      1.1  christos 
     18      1.1  christos =head1 DESCRIPTION
     19      1.1  christos 
     20  1.1.1.4  christos PKCS7_sign_ex() creates and returns a PKCS#7 signedData structure.
     21  1.1.1.3  christos I<signcert> is the certificate to sign with, I<pkey> is the corresponding
     22  1.1.1.3  christos private key. I<certs> is an optional set of extra certificates to include
     23  1.1.1.3  christos in the PKCS#7 structure (for example any intermediate CAs in the chain).
     24  1.1.1.4  christos The library context I<libctx> and property query I<propq> are used when
     25  1.1.1.4  christos retrieving algorithms from providers.
     26      1.1  christos 
     27  1.1.1.3  christos The data to be signed is read from BIO I<data>.
     28      1.1  christos 
     29  1.1.1.3  christos I<flags> is an optional set of flags.
     30      1.1  christos 
     31  1.1.1.3  christos Any of the following flags (ored together) can be passed in the I<flags>
     32  1.1.1.4  christos parameter.
     33      1.1  christos 
     34      1.1  christos Many S/MIME clients expect the signed content to include valid MIME headers. If
     35  1.1.1.3  christos the B<PKCS7_TEXT> flag is set MIME headers for type C<text/plain> are prepended
     36      1.1  christos to the data.
     37      1.1  christos 
     38  1.1.1.3  christos If B<PKCS7_NOCERTS> is set the signer's certificate and the extra I<certs>
     39  1.1.1.3  christos will not be included in the PKCS7 structure.
     40  1.1.1.3  christos The signer's certificate must still be supplied in the I<signcert> parameter
     41  1.1.1.3  christos though. This can reduce the size of the signatures if the signer's certificates
     42  1.1.1.3  christos can be obtained by other means: for example a previously signed message.
     43      1.1  christos 
     44      1.1  christos The data being signed is included in the PKCS7 structure, unless
     45      1.1  christos B<PKCS7_DETACHED> is set in which case it is omitted. This is used for PKCS7
     46      1.1  christos detached signatures which are used in S/MIME plaintext signed messages for
     47      1.1  christos example.
     48      1.1  christos 
     49      1.1  christos Normally the supplied content is translated into MIME canonical format (as
     50      1.1  christos required by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation
     51      1.1  christos occurs. This option should be used if the supplied data is in binary format
     52      1.1  christos otherwise the translation will corrupt it.
     53      1.1  christos 
     54      1.1  christos The signedData structure includes several PKCS#7 authenticatedAttributes
     55      1.1  christos including the signing time, the PKCS#7 content type and the supported list of
     56      1.1  christos ciphers in an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no
     57      1.1  christos authenticatedAttributes will be used. If B<PKCS7_NOSMIMECAP> is set then just
     58      1.1  christos the SMIMECapabilities are omitted.
     59      1.1  christos 
     60      1.1  christos If present the SMIMECapabilities attribute indicates support for the following
     61      1.1  christos algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any of
     62      1.1  christos these algorithms is disabled then it will not be included.
     63      1.1  christos 
     64      1.1  christos If the flags B<PKCS7_STREAM> is set then the returned B<PKCS7> structure is
     65      1.1  christos just initialized ready to perform the signing operation. The signing is however
     66  1.1.1.3  christos B<not> performed and the data to be signed is not read from the I<data>
     67      1.1  christos parameter. Signing is deferred until after the data has been written. In this
     68      1.1  christos way data can be signed in a single pass.
     69      1.1  christos 
     70      1.1  christos If the B<PKCS7_PARTIAL> flag is set a partial B<PKCS7> structure is output to
     71      1.1  christos which additional signers and capabilities can be added before finalization.
     72      1.1  christos 
     73      1.1  christos If the flag B<PKCS7_STREAM> is set the returned B<PKCS7> structure is B<not>
     74      1.1  christos complete and outputting its contents via a function that does not properly
     75      1.1  christos finalize the B<PKCS7> structure will give unpredictable results.
     76      1.1  christos 
     77      1.1  christos Several functions including SMIME_write_PKCS7(), i2d_PKCS7_bio_stream(),
     78      1.1  christos PEM_write_bio_PKCS7_stream() finalize the structure. Alternatively finalization
     79      1.1  christos can be performed by obtaining the streaming ASN1 B<BIO> directly using
     80      1.1  christos BIO_new_PKCS7().
     81      1.1  christos 
     82      1.1  christos If a signer is specified it will use the default digest for the signing
     83      1.1  christos algorithm. This is B<SHA1> for both RSA and DSA keys.
     84      1.1  christos 
     85  1.1.1.3  christos The I<certs>, I<signcert> and I<pkey> parameters can all be
     86  1.1.1.3  christos NULL if the B<PKCS7_PARTIAL> flag is set. One or more signers can be added
     87      1.1  christos using the function PKCS7_sign_add_signer(). PKCS7_final() must also be
     88      1.1  christos called to finalize the structure if streaming is not enabled. Alternative
     89      1.1  christos signing digests can also be specified using this method.
     90      1.1  christos 
     91  1.1.1.3  christos If I<signcert> and I<pkey> are NULL then a certificates only
     92      1.1  christos PKCS#7 structure is output.
     93      1.1  christos 
     94  1.1.1.3  christos In versions of OpenSSL before 1.0.0 the I<signcert> and I<pkey> parameters must
     95  1.1.1.3  christos not be NULL.
     96      1.1  christos 
     97  1.1.1.4  christos PKCS7_sign() is like PKCS7_sign_ex() except that it uses default values of
     98  1.1.1.4  christos NULL for the library context I<libctx> and the property query I<propq>.
     99  1.1.1.5  christos This is retained for API backward compatibility.
    100  1.1.1.4  christos 
    101      1.1  christos =head1 BUGS
    102      1.1  christos 
    103      1.1  christos Some advanced attributes such as counter signatures are not supported.
    104      1.1  christos 
    105      1.1  christos =head1 RETURN VALUES
    106      1.1  christos 
    107  1.1.1.4  christos PKCS7_sign_ex() and PKCS7_sign() return either a valid PKCS7 structure
    108  1.1.1.4  christos or NULL if an error occurred.  The error can be obtained from ERR_get_error(3).
    109      1.1  christos 
    110      1.1  christos =head1 SEE ALSO
    111      1.1  christos 
    112      1.1  christos L<ERR_get_error(3)>, L<PKCS7_verify(3)>
    113      1.1  christos 
    114      1.1  christos =head1 HISTORY
    115      1.1  christos 
    116  1.1.1.4  christos The function PKCS7_sign_ex() was added in OpenSSL 3.0.
    117  1.1.1.4  christos 
    118  1.1.1.3  christos The B<PKCS7_PARTIAL> flag, and the ability for I<certs>, I<signcert>,
    119  1.1.1.3  christos and I<pkey> parameters to be NULL were added in OpenSSL 1.0.0.
    120      1.1  christos 
    121  1.1.1.2  christos The B<PKCS7_STREAM> flag was added in OpenSSL 1.0.0.
    122      1.1  christos 
    123      1.1  christos =head1 COPYRIGHT
    124      1.1  christos 
    125  1.1.1.5  christos Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved.
    126      1.1  christos 
    127  1.1.1.4  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    128      1.1  christos this file except in compliance with the License.  You can obtain a copy
    129      1.1  christos in the file LICENSE in the source distribution or at
    130      1.1  christos L<https://www.openssl.org/source/license.html>.
    131      1.1  christos 
    132      1.1  christos =cut
    133