1.\" $OpenBSD: BIO_new_CMS.3,v 1.9 2023/05/01 07:28:11 tb Exp $ 2.\" full merge up to: OpenSSL df75c2bfc Dec 9 01:02:36 2018 +0100 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2008 The OpenSSL Project. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in 16.\" the documentation and/or other materials provided with the 17.\" distribution. 18.\" 19.\" 3. All advertising materials mentioning features or use of this 20.\" software must display the following acknowledgment: 21.\" "This product includes software developed by the OpenSSL Project 22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 23.\" 24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 25.\" endorse or promote products derived from this software without 26.\" prior written permission. For written permission, please contact 27.\" openssl-core@openssl.org. 28.\" 29.\" 5. Products derived from this software may not be called "OpenSSL" 30.\" nor may "OpenSSL" appear in their names without prior written 31.\" permission of the OpenSSL Project. 32.\" 33.\" 6. Redistributions of any form whatsoever must retain the following 34.\" acknowledgment: 35.\" "This product includes software developed by the OpenSSL Project 36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 37.\" 38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" 51.Dd $Mdocdate: May 1 2023 $ 52.Dt BIO_NEW_CMS 3 53.Os 54.Sh NAME 55.Nm BIO_new_CMS 56.Nd CMS streaming filter BIO 57.Sh SYNOPSIS 58.In openssl/cms.h 59.Ft BIO * 60.Fo BIO_new_CMS 61.Fa "BIO *out" 62.Fa "CMS_ContentInfo *cms" 63.Fc 64.Sh DESCRIPTION 65.Fn BIO_new_CMS 66returns a streaming filter 67.Vt BIO 68chain based on 69.Fa cms . 70The output of the filter is written to 71.Fa out . 72Any data written to the chain is automatically translated 73to a BER format CMS structure of the appropriate type. 74.Pp 75The chain returned by this function behaves like a standard filter 76.Vt BIO . 77It supports non blocking I/O. 78Content is processed and streamed on the fly and not all held in memory 79at once: so it is possible to encode very large structures. 80After all content has been written through the chain, 81.Xr BIO_flush 3 82must be called to finalise the structure. 83.Pp 84The 85.Dv CMS_STREAM 86flag must be included in the corresponding 87.Fa flags 88parameter of the 89.Fa cms 90creation function. 91.Pp 92If an application wishes to write additional data to 93.Fa out , 94BIOs should be removed from the chain using 95.Xr BIO_pop 3 96and freed with 97.Xr BIO_free 3 98until 99.Fa out 100is reached. 101If no additional data needs to be written, 102.Xr BIO_free_all 3 103can be called to free up the whole chain. 104.Pp 105Any content written through the filter is used verbatim: 106no canonical translation is performed. 107.Pp 108It is possible to chain multiple BIOs to, for example, 109create a triple wrapped signed, enveloped, signed structure. 110In this case it is the application's responsibility 111to set the inner content type of any outer 112.Vt CMS_ContentInfo 113structures. 114.Pp 115Large numbers of small writes through the chain should be avoided as this 116will produce an output consisting of lots of OCTET STRING structures. 117Prepending a 118.Xr BIO_f_buffer 3 119buffering BIO will prevent this. 120.Sh RETURN VALUES 121.Fn BIO_new_CMS 122returns a 123.Vt BIO 124chain when successful or 125.Dv NULL 126if an error occurred. 127The error can be obtained from 128.Xr ERR_get_error 3 . 129.Sh SEE ALSO 130.Xr BIO_new 3 , 131.Xr CMS_ContentInfo_new 3 , 132.Xr CMS_encrypt 3 , 133.Xr CMS_sign 3 134.Sh HISTORY 135.Fn BIO_new_CMS 136first appeared in OpenSSL 1.0.0 137and has been available since 138.Ox 6.7 . 139.Sh BUGS 140There is currently no corresponding inverse BIO 141which can decode a CMS structure on the fly. 142