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_encrypt_ex, CMS_encrypt - create a CMS envelopedData 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_encrypt_ex(STACK_OF(X509) *certs, BIO *in, 12 1.1.1.2 christos const EVP_CIPHER *cipher, unsigned int flags, 13 1.1.1.2 christos OSSL_LIB_CTX *libctx, const char *propq); 14 1.1 christos CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, 15 1.1 christos const EVP_CIPHER *cipher, unsigned int flags); 16 1.1 christos 17 1.1 christos =head1 DESCRIPTION 18 1.1 christos 19 1.1.1.2 christos CMS_encrypt_ex() creates and returns a CMS EnvelopedData or 20 1.1.1.2 christos AuthEnvelopedData structure. I<certs> is a list of recipient certificates. 21 1.1.1.2 christos I<in> is the content to be encrypted. I<cipher> is the symmetric cipher to use. 22 1.1.1.2 christos I<flags> is an optional set of flags. The library context I<libctx> and the 23 1.1.1.2 christos property query I<propq> are used internally when retrieving algorithms from 24 1.1.1.2 christos providers. 25 1.1 christos 26 1.1 christos Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this 27 1.1 christos function. 28 1.1 christos 29 1.1 christos EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use 30 1.1 christos because most clients will support it. 31 1.1 christos 32 1.1 christos The algorithm passed in the B<cipher> parameter must support ASN1 encoding of 33 1.1.1.2 christos its parameters. If the cipher mode is GCM, then an AuthEnvelopedData structure 34 1.1.1.2 christos containing MAC is used. Otherwise an EnvelopedData structure is used. Currently 35 1.1.1.2 christos the AES variants with GCM mode are the only supported AEAD algorithms. 36 1.1 christos 37 1.1 christos Many browsers implement a "sign and encrypt" option which is simply an S/MIME 38 1.1 christos envelopedData containing an S/MIME signed message. This can be readily produced 39 1.1 christos by storing the S/MIME signed message in a memory BIO and passing it to 40 1.1 christos CMS_encrypt(). 41 1.1 christos 42 1.1 christos The following flags can be passed in the B<flags> parameter. 43 1.1 christos 44 1.1 christos If the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are 45 1.1 christos prepended to the data. 46 1.1 christos 47 1.1 christos Normally the supplied content is translated into MIME canonical format (as 48 1.1 christos required by the S/MIME specifications) if B<CMS_BINARY> is set no translation 49 1.1 christos occurs. This option should be used if the supplied data is in binary format 50 1.1 christos otherwise the translation will corrupt it. If B<CMS_BINARY> is set then 51 1.1 christos B<CMS_TEXT> is ignored. 52 1.1 christos 53 1.1 christos OpenSSL will by default identify recipient certificates using issuer name 54 1.1 christos and serial number. If B<CMS_USE_KEYID> is set it will use the subject key 55 1.1 christos identifier value instead. An error occurs if all recipient certificates do not 56 1.1 christos have a subject key identifier extension. 57 1.1 christos 58 1.1 christos If the B<CMS_STREAM> flag is set a partial B<CMS_ContentInfo> structure is 59 1.1 christos returned suitable for streaming I/O: no data is read from the BIO B<in>. 60 1.1 christos 61 1.1 christos If the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is 62 1.1 christos returned to which additional recipients and attributes can be added before 63 1.1 christos finalization. 64 1.1 christos 65 1.1 christos The data being encrypted is included in the CMS_ContentInfo structure, unless 66 1.1 christos B<CMS_DETACHED> is set in which case it is omitted. This is rarely used in 67 1.1 christos practice and is not supported by SMIME_write_CMS(). 68 1.1 christos 69 1.1 christos If the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is 70 1.1 christos B<not> complete and outputting its contents via a function that does not 71 1.1 christos properly finalize the B<CMS_ContentInfo> structure will give unpredictable 72 1.1 christos results. 73 1.1 christos 74 1.1 christos Several functions including SMIME_write_CMS(), i2d_CMS_bio_stream(), 75 1.1 christos PEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization 76 1.1 christos can be performed by obtaining the streaming ASN1 B<BIO> directly using 77 1.1 christos BIO_new_CMS(). 78 1.1 christos 79 1.1 christos The recipients specified in B<certs> use a CMS KeyTransRecipientInfo info 80 1.1 christos structure. KEKRecipientInfo is also supported using the flag B<CMS_PARTIAL> 81 1.1 christos and CMS_add0_recipient_key(). 82 1.1 christos 83 1.1 christos The parameter B<certs> may be NULL if B<CMS_PARTIAL> is set and recipients 84 1.1 christos added later using CMS_add1_recipient_cert() or CMS_add0_recipient_key(). 85 1.1 christos 86 1.1.1.2 christos CMS_encrypt() is similar to CMS_encrypt_ex() but uses default values 87 1.1.1.2 christos of NULL for the library context I<libctx> and the property query I<propq>. 88 1.1.1.2 christos 89 1.1 christos =head1 RETURN VALUES 90 1.1 christos 91 1.1.1.2 christos CMS_encrypt_ex() and CMS_encrypt() return either a CMS_ContentInfo 92 1.1.1.2 christos structure or NULL if an error occurred. The error can be obtained from 93 1.1.1.2 christos ERR_get_error(3). 94 1.1 christos 95 1.1 christos =head1 SEE ALSO 96 1.1 christos 97 1.1 christos L<ERR_get_error(3)>, L<CMS_decrypt(3)> 98 1.1 christos 99 1.1 christos =head1 HISTORY 100 1.1 christos 101 1.1.1.2 christos The function CMS_encrypt_ex() was added in OpenSSL 3.0. 102 1.1.1.2 christos 103 1.1 christos The B<CMS_STREAM> flag was first supported in OpenSSL 1.0.0. 104 1.1 christos 105 1.1 christos =head1 COPYRIGHT 106 1.1 christos 107 1.1.1.2 christos Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved. 108 1.1 christos 109 1.1.1.2 christos Licensed under the Apache License 2.0 (the "License"). You may not use 110 1.1 christos this file except in compliance with the License. You can obtain a copy 111 1.1 christos in the file LICENSE in the source distribution or at 112 1.1 christos L<https://www.openssl.org/source/license.html>. 113 1.1 christos 114 1.1 christos =cut 115