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.2  christos CMS_sign, CMS_sign_ex - create a CMS SignedData structure
      6      1.1  christos 
      7      1.1  christos =head1 SYNOPSIS
      8      1.1  christos 
      9      1.1  christos  #include <openssl/cms.h>
     10      1.1  christos 
     11  1.1.1.2  christos  CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey,
     12  1.1.1.2  christos                               STACK_OF(X509) *certs, BIO *data,
     13  1.1.1.2  christos                               unsigned int flags, OSSL_LIB_CTX *ctx,
     14  1.1.1.2  christos                               const char *propq);
     15      1.1  christos  CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
     16      1.1  christos                            BIO *data, unsigned int flags);
     17      1.1  christos 
     18      1.1  christos =head1 DESCRIPTION
     19      1.1  christos 
     20  1.1.1.2  christos CMS_sign_ex() creates and returns a CMS SignedData structure.
     21  1.1.1.2  christos I<signcert> is the certificate to sign with, I<pkey> is the corresponding
     22  1.1.1.2  christos private key. I<certs> is an optional additional set of certificates to include
     23  1.1.1.2  christos in the CMS structure (for example any intermediate CAs in the chain). The
     24  1.1.1.2  christos library context I<libctx> and the property query I<propq> are used when
     25  1.1.1.2  christos retrieving algorithms from providers. Any or all of these parameters can be
     26  1.1.1.2  christos B<NULL>, see B<NOTES> below.
     27      1.1  christos 
     28      1.1  christos The data to be signed is read from BIO B<data>.
     29      1.1  christos 
     30      1.1  christos B<flags> is an optional set of flags.
     31      1.1  christos 
     32  1.1.1.2  christos CMS_sign() is similar to CMS_sign_ex() but uses default values of NULL
     33  1.1.1.2  christos for the library context I<libctx> and the property query I<propq>.
     34  1.1.1.2  christos 
     35      1.1  christos =head1 NOTES
     36      1.1  christos 
     37      1.1  christos Any of the following flags (ored together) can be passed in the B<flags>
     38      1.1  christos parameter.
     39      1.1  christos 
     40      1.1  christos Many S/MIME clients expect the signed content to include valid MIME headers. If
     41      1.1  christos the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are prepended
     42      1.1  christos to the data.
     43      1.1  christos 
     44      1.1  christos If B<CMS_NOCERTS> is set the signer's certificate will not be included in the
     45      1.1  christos CMS_ContentInfo structure, the signer's certificate must still be supplied in
     46      1.1  christos the B<signcert> parameter though. This can reduce the size of the signature if
     47      1.1  christos the signers certificate can be obtained by other means: for example a
     48      1.1  christos previously signed message.
     49      1.1  christos 
     50      1.1  christos The data being signed is included in the CMS_ContentInfo structure, unless
     51      1.1  christos B<CMS_DETACHED> is set in which case it is omitted. This is used for
     52      1.1  christos CMS_ContentInfo detached signatures which are used in S/MIME plaintext signed
     53      1.1  christos messages for example.
     54      1.1  christos 
     55      1.1  christos Normally the supplied content is translated into MIME canonical format (as
     56      1.1  christos required by the S/MIME specifications) if B<CMS_BINARY> is set no translation
     57      1.1  christos occurs. This option should be used if the supplied data is in binary format
     58      1.1  christos otherwise the translation will corrupt it.
     59      1.1  christos 
     60      1.1  christos The SignedData structure includes several CMS signedAttributes including the
     61      1.1  christos signing time, the CMS content type and the supported list of ciphers in an
     62      1.1  christos SMIMECapabilities attribute. If B<CMS_NOATTR> is set then no signedAttributes
     63      1.1  christos will be used. If B<CMS_NOSMIMECAP> is set then just the SMIMECapabilities are
     64      1.1  christos omitted.
     65      1.1  christos 
     66      1.1  christos If present the SMIMECapabilities attribute indicates support for the following
     67      1.1  christos algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192
     68      1.1  christos bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2.
     69  1.1.1.2  christos If any of these algorithms is not available then it will not be included:
     70  1.1.1.2  christos for example the GOST algorithms will not be included if the GOST ENGINE is
     71      1.1  christos not loaded.
     72      1.1  christos 
     73      1.1  christos OpenSSL will by default identify signing certificates using issuer name
     74      1.1  christos and serial number. If B<CMS_USE_KEYID> is set it will use the subject key
     75      1.1  christos identifier value instead. An error occurs if the signing certificate does not
     76      1.1  christos have a subject key identifier extension.
     77      1.1  christos 
     78      1.1  christos If the flags B<CMS_STREAM> is set then the returned B<CMS_ContentInfo>
     79      1.1  christos structure is just initialized ready to perform the signing operation. The
     80      1.1  christos signing is however B<not> performed and the data to be signed is not read from
     81      1.1  christos the B<data> parameter. Signing is deferred until after the data has been
     82      1.1  christos written. In this way data can be signed in a single pass.
     83      1.1  christos 
     84      1.1  christos If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
     85      1.1  christos output to which additional signers and capabilities can be added before
     86      1.1  christos finalization.
     87      1.1  christos 
     88      1.1  christos If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
     89      1.1  christos B<not> complete and outputting its contents via a function that does not
     90      1.1  christos properly finalize the B<CMS_ContentInfo> structure will give unpredictable
     91      1.1  christos results.
     92      1.1  christos 
     93      1.1  christos Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
     94      1.1  christos PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
     95      1.1  christos can be performed by obtaining the streaming ASN1 B<BIO> directly using
     96      1.1  christos BIO_new_CMS().
     97      1.1  christos 
     98      1.1  christos If a signer is specified it will use the default digest for the signing
     99      1.1  christos algorithm. This is B<SHA1> for both RSA and DSA keys.
    100      1.1  christos 
    101      1.1  christos If B<signcert> and B<pkey> are NULL then a certificates only CMS structure is
    102      1.1  christos output.
    103      1.1  christos 
    104      1.1  christos The function CMS_sign() is a basic CMS signing function whose output will be
    105      1.1  christos suitable for many purposes. For finer control of the output format the
    106      1.1  christos B<certs>, B<signcert> and B<pkey> parameters can all be B<NULL> and the
    107      1.1  christos B<CMS_PARTIAL> flag set. Then one or more signers can be added using the
    108  1.1.1.3  christos function CMS_add1_signer(), non default digests can be used and custom
    109      1.1  christos attributes added. CMS_final() must then be called to finalize the
    110      1.1  christos structure if streaming is not enabled.
    111      1.1  christos 
    112      1.1  christos =head1 BUGS
    113      1.1  christos 
    114      1.1  christos Some attributes such as counter signatures are not supported.
    115      1.1  christos 
    116      1.1  christos =head1 RETURN VALUES
    117      1.1  christos 
    118  1.1.1.2  christos CMS_sign_ex() and CMS_sign() return either a valid CMS_ContentInfo
    119  1.1.1.2  christos structure or NULL if an error occurred. The error can be obtained from
    120  1.1.1.2  christos ERR_get_error(3).
    121      1.1  christos 
    122      1.1  christos =head1 SEE ALSO
    123      1.1  christos 
    124      1.1  christos L<ERR_get_error(3)>, L<CMS_verify(3)>
    125      1.1  christos 
    126      1.1  christos =head1 HISTORY
    127      1.1  christos 
    128      1.1  christos The B<CMS_STREAM> flag is only supported for detached data in OpenSSL 0.9.8,
    129      1.1  christos it is supported for embedded data in OpenSSL 1.0.0 and later.
    130      1.1  christos 
    131  1.1.1.2  christos The CMS_sign_ex() method was added in OpenSSL 3.0.
    132  1.1.1.2  christos 
    133      1.1  christos =head1 COPYRIGHT
    134      1.1  christos 
    135  1.1.1.3  christos Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.
    136      1.1  christos 
    137  1.1.1.2  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    138      1.1  christos this file except in compliance with the License.  You can obtain a copy
    139      1.1  christos in the file LICENSE in the source distribution or at
    140      1.1  christos L<https://www.openssl.org/source/license.html>.
    141      1.1  christos 
    142      1.1  christos =cut
    143