xref: /freebsd/crypto/openssl/doc/man3/CMS_encrypt.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5*b077aed3SPierre ProncheryCMS_encrypt_ex, CMS_encrypt - create a CMS envelopedData structure
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim #include <openssl/cms.h>
10e71b7053SJung-uk Kim
11*b077aed3SPierre Pronchery CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
12*b077aed3SPierre Pronchery                                 const EVP_CIPHER *cipher, unsigned int flags,
13*b077aed3SPierre Pronchery                                 OSSL_LIB_CTX *libctx, const char *propq);
14e71b7053SJung-uk Kim CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
15e71b7053SJung-uk Kim                              const EVP_CIPHER *cipher, unsigned int flags);
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim=head1 DESCRIPTION
18e71b7053SJung-uk Kim
19*b077aed3SPierre ProncheryCMS_encrypt_ex() creates and returns a CMS EnvelopedData or
20*b077aed3SPierre ProncheryAuthEnvelopedData structure. I<certs> is a list of recipient certificates.
21*b077aed3SPierre ProncheryI<in> is the content to be encrypted. I<cipher> is the symmetric cipher to use.
22*b077aed3SPierre ProncheryI<flags> is an optional set of flags. The library context I<libctx> and the
23*b077aed3SPierre Proncheryproperty query I<propq> are used internally when retrieving algorithms from
24*b077aed3SPierre Proncheryproviders.
25e71b7053SJung-uk Kim
26e71b7053SJung-uk KimOnly certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
27e71b7053SJung-uk Kimfunction.
28e71b7053SJung-uk Kim
29e71b7053SJung-uk KimEVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
30e71b7053SJung-uk Kimbecause most clients will support it.
31e71b7053SJung-uk Kim
32e71b7053SJung-uk KimThe algorithm passed in the B<cipher> parameter must support ASN1 encoding of
33*b077aed3SPierre Proncheryits parameters. If the cipher mode is GCM, then an AuthEnvelopedData structure
34*b077aed3SPierre Proncherycontaining MAC is used. Otherwise an EnvelopedData structure is used. Currently
35*b077aed3SPierre Proncherythe AES variants with GCM mode are the only supported AEAD algorithms.
36e71b7053SJung-uk Kim
37e71b7053SJung-uk KimMany browsers implement a "sign and encrypt" option which is simply an S/MIME
38e71b7053SJung-uk KimenvelopedData containing an S/MIME signed message. This can be readily produced
39e71b7053SJung-uk Kimby storing the S/MIME signed message in a memory BIO and passing it to
40e71b7053SJung-uk KimCMS_encrypt().
41e71b7053SJung-uk Kim
42e71b7053SJung-uk KimThe following flags can be passed in the B<flags> parameter.
43e71b7053SJung-uk Kim
44e71b7053SJung-uk KimIf the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are
45e71b7053SJung-uk Kimprepended to the data.
46e71b7053SJung-uk Kim
47e71b7053SJung-uk KimNormally the supplied content is translated into MIME canonical format (as
48e71b7053SJung-uk Kimrequired by the S/MIME specifications) if B<CMS_BINARY> is set no translation
49e71b7053SJung-uk Kimoccurs. This option should be used if the supplied data is in binary format
50e71b7053SJung-uk Kimotherwise the translation will corrupt it. If B<CMS_BINARY> is set then
51e71b7053SJung-uk KimB<CMS_TEXT> is ignored.
52e71b7053SJung-uk Kim
53e71b7053SJung-uk KimOpenSSL will by default identify recipient certificates using issuer name
54e71b7053SJung-uk Kimand serial number. If B<CMS_USE_KEYID> is set it will use the subject key
55e71b7053SJung-uk Kimidentifier value instead. An error occurs if all recipient certificates do not
56e71b7053SJung-uk Kimhave a subject key identifier extension.
57e71b7053SJung-uk Kim
58e71b7053SJung-uk KimIf the B<CMS_STREAM> flag is set a partial B<CMS_ContentInfo> structure is
59e71b7053SJung-uk Kimreturned suitable for streaming I/O: no data is read from the BIO B<in>.
60e71b7053SJung-uk Kim
61e71b7053SJung-uk KimIf the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
62e71b7053SJung-uk Kimreturned to which additional recipients and attributes can be added before
63e71b7053SJung-uk Kimfinalization.
64e71b7053SJung-uk Kim
65e71b7053SJung-uk KimThe data being encrypted is included in the CMS_ContentInfo structure, unless
66e71b7053SJung-uk KimB<CMS_DETACHED> is set in which case it is omitted. This is rarely used in
67e71b7053SJung-uk Kimpractice and is not supported by SMIME_write_CMS().
68e71b7053SJung-uk Kim
69e71b7053SJung-uk KimIf the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
70e71b7053SJung-uk KimB<not> complete and outputting its contents via a function that does not
71e71b7053SJung-uk Kimproperly finalize the B<CMS_ContentInfo> structure will give unpredictable
72e71b7053SJung-uk Kimresults.
73e71b7053SJung-uk Kim
74e71b7053SJung-uk KimSeveral functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
75e71b7053SJung-uk KimPEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
76e71b7053SJung-uk Kimcan be performed by obtaining the streaming ASN1 B<BIO> directly using
77e71b7053SJung-uk KimBIO_new_CMS().
78e71b7053SJung-uk Kim
79e71b7053SJung-uk KimThe recipients specified in B<certs> use a CMS KeyTransRecipientInfo info
80e71b7053SJung-uk Kimstructure. KEKRecipientInfo is also supported using the flag B<CMS_PARTIAL>
81e71b7053SJung-uk Kimand CMS_add0_recipient_key().
82e71b7053SJung-uk Kim
83e71b7053SJung-uk KimThe parameter B<certs> may be NULL if B<CMS_PARTIAL> is set and recipients
84e71b7053SJung-uk Kimadded later using CMS_add1_recipient_cert() or CMS_add0_recipient_key().
85e71b7053SJung-uk Kim
86*b077aed3SPierre ProncheryCMS_encrypt() is similar to CMS_encrypt_ex() but uses default values
87*b077aed3SPierre Proncheryof NULL for the library context I<libctx> and the property query I<propq>.
88*b077aed3SPierre Pronchery
89e71b7053SJung-uk Kim=head1 RETURN VALUES
90e71b7053SJung-uk Kim
91*b077aed3SPierre ProncheryCMS_encrypt_ex() and CMS_encrypt() return either a CMS_ContentInfo
92*b077aed3SPierre Proncherystructure or NULL if an error occurred. The error can be obtained from
93*b077aed3SPierre ProncheryERR_get_error(3).
94e71b7053SJung-uk Kim
95e71b7053SJung-uk Kim=head1 SEE ALSO
96e71b7053SJung-uk Kim
97e71b7053SJung-uk KimL<ERR_get_error(3)>, L<CMS_decrypt(3)>
98e71b7053SJung-uk Kim
99e71b7053SJung-uk Kim=head1 HISTORY
100e71b7053SJung-uk Kim
101*b077aed3SPierre ProncheryThe function CMS_encrypt_ex() was added in OpenSSL 3.0.
102*b077aed3SPierre Pronchery
103e71b7053SJung-uk KimThe B<CMS_STREAM> flag was first supported in OpenSSL 1.0.0.
104e71b7053SJung-uk Kim
105e71b7053SJung-uk Kim=head1 COPYRIGHT
106e71b7053SJung-uk Kim
107*b077aed3SPierre ProncheryCopyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.
108e71b7053SJung-uk Kim
109*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
110e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
111e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
112e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
113e71b7053SJung-uk Kim
114e71b7053SJung-uk Kim=cut
115