1.\" $OpenBSD: SMIME_write_PKCS7.3,v 1.7 2020/06/03 13:41:27 schwarze Exp $ 2.\" full merge up to: OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2002, 2003, 2006, 2007, 2015 The OpenSSL Project. 6.\" All rights reserved. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in 17.\" the documentation and/or other materials provided with the 18.\" distribution. 19.\" 20.\" 3. All advertising materials mentioning features or use of this 21.\" software must display the following acknowledgment: 22.\" "This product includes software developed by the OpenSSL Project 23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24.\" 25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26.\" endorse or promote products derived from this software without 27.\" prior written permission. For written permission, please contact 28.\" openssl-core@openssl.org. 29.\" 30.\" 5. Products derived from this software may not be called "OpenSSL" 31.\" nor may "OpenSSL" appear in their names without prior written 32.\" permission of the OpenSSL Project. 33.\" 34.\" 6. Redistributions of any form whatsoever must retain the following 35.\" acknowledgment: 36.\" "This product includes software developed by the OpenSSL Project 37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38.\" 39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51.\" 52.Dd $Mdocdate: June 3 2020 $ 53.Dt SMIME_WRITE_PKCS7 3 54.Os 55.Sh NAME 56.Nm SMIME_write_PKCS7 57.Nd convert PKCS#7 structure to S/MIME format 58.Sh SYNOPSIS 59.In openssl/pkcs7.h 60.Ft int 61.Fo SMIME_write_PKCS7 62.Fa "BIO *out" 63.Fa "PKCS7 *p7" 64.Fa "BIO *data" 65.Fa "int flags" 66.Fc 67.Sh DESCRIPTION 68.Fn SMIME_write_PKCS7 69adds the appropriate MIME headers to a PKCS#7 structure to produce an 70S/MIME message. 71.Pp 72.Fa out 73is the 74.Vt BIO 75to write the data to. 76.Fa p7 77is the appropriate 78.Vt PKCS7 79structure. 80If streaming is enabled, then the content must be supplied in the 81.Fa data 82argument. 83.Fa flags 84is an optional set of flags. 85.Pp 86The following flags can be passed in the 87.Fa flags 88parameter. 89.Pp 90If 91.Dv PKCS7_DETACHED 92is set, then cleartext signing will be used. 93This option only makes sense for signedData where 94.Dv PKCS7_DETACHED 95is also set when 96.Xr PKCS7_sign 3 97is also called. 98.Pp 99If the 100.Dv PKCS7_TEXT 101flag is set, MIME headers for type 102.Sy text/plain 103are added to the content. 104This only makes sense if 105.Dv PKCS7_DETACHED 106is also set. 107.Pp 108If the 109.Dv PKCS7_STREAM 110flag is set, streaming is performed. 111This flag should only be set if 112.Dv PKCS7_STREAM 113was also set in the previous call to 114.Xr PKCS7_sign 3 115or 116.Xr PKCS7_encrypt 3 . 117.Pp 118If cleartext signing is being used and 119.Dv PKCS7_STREAM 120is not set, then the data must be read twice: once to compute the 121signature in 122.Xr PKCS7_sign 3 123and once to output the S/MIME message. 124.Pp 125If streaming is performed, the content is output in BER format using 126indefinite length constructed encoding except in the case of signed 127data with detached content where the content is absent and DER 128format is used. 129.Sh RETURN VALUES 130Upon successful completion, 1 is returned; 131otherwise 0 is returned and an error code can be retrieved with 132.Xr ERR_get_error 3 . 133.Sh SEE ALSO 134.Xr i2d_PKCS7_bio_stream 3 , 135.Xr PEM_write_bio_PKCS7_stream 3 , 136.Xr PEM_write_PKCS7 3 , 137.Xr PKCS7_final 3 , 138.Xr PKCS7_new 3 , 139.Xr SMIME_read_PKCS7 3 140.Sh HISTORY 141.Fn SMIME_write_PKCS7 142first appeared in OpenSSL 0.9.5 and has been available since 143.Ox 2.7 . 144.Sh BUGS 145.Fn SMIME_write_PKCS7 146always base64 encodes PKCS#7 structures. 147There should be an option to disable this. 148