PKCS7_DATAINIT(3)
π
PKCS7_dataInit π
okay bestie, this little icon lives in the Library Functions Manual, and itβs giving βbuild me a BIO chain so I can put content into p7 or pull content out of p7β energy. no cap. π«Ά
πΈ NAME πΈ
PKCS7_dataInit β construct a BIO chain for adding or retrieving content, periodt.
β¨ SYNOPSIS β¨
#include <openssl/pkcs7.h>
BIO *
PKCS7_dataInit(PKCS7 *p7, BIO *indata);
π DESCRIPTION π
PKCS7_dataInit() constructs a BIO chain in preparation for putting data into p7 or retrieving data out of p7. Depending on the contentType of p7, the created chain starts with:
- for
SignedData: one or moreBIO_f_md(3)message digest filters - for
EnvelopedData: oneBIO_f_cipher(3)encryption filter - for
SignedAndEnvelopedData: one or moreBIO_f_md(3)message digest filters followed by oneBIO_f_cipher(3)encryption filter - for
DigestedData: oneBIO_f_md(3)message digest filter - for arbitrary data: no filter
BIO
Then one extra BIO gets appended to the end of the chain β and itβs the first condition that holds in this list that wins:
indataβ if theindataargument is notNULL. This only makes sense while verifying a detached signature, in which caseindatais expected to supply the content associated with the detached signature.BIO_s_null(3)β if thecontentTypeofp7isSignedDataand it is configured to contain a detached signature. This only makes sense while creating the detached signature.BIO_new_mem_buf(3)β when reading from aSignedDataorDigestedDataobject.PKCS7_dataInit()attaches the end of the chain to the nested content ofp7.BIO_s_mem(3)β otherwise. This is the most common case while writing data top7.PKCS7_dataFinal(3)can later be used to transfer the data from the memoryBIOintop7.
π Adding content π
Before calling PKCS7_dataInit() in order to add content, PKCS7_new(3), PKCS7_set_type(3), and PKCS7_content_new(3) are typically required to create p7, to choose its desired type, and to allocate the nested ContentInfo structure. Alternatively, for SignedData, PKCS7_sign(3) can be used with the PKCS7_PARTIAL or PKCS7_STREAM flags β or for EnvelopedData, PKCS7_encrypt(3) with the PKCS7_STREAM flag. slay. β¨
After calling PKCS7_dataInit(), the desired data can be written into the returned BIO, BIO_flush(3) can be called on it, PKCS7_dataFinal(3) can be used to transfer the processed data from the returned memory BIO to the p7 structure, and the chain can finally be destroyed with BIO_free_all(3). cute, clean, done. π
While PKCS7_dataInit() does support the EnvelopedData and SignedAndEnvelopedData types, using it for these types is awkward and error prone except when using PKCS7_encrypt(3) for the setup because PKCS7_content_new(3) does not support these two types. So in addition to creating p7 itself and setting its type, the nested ContentInfo structure also needs to be constructed with PKCS7_new(3) and PKCS7_set_type(3) and manually inserted into the correct field of the respective sub-structure of p7. yes, itβs giving manual-labour era. π
π¦ Retrieving content π¦
PKCS7_dataInit() can also be called on a fully populated object of type SignedData or DigestedData. After that, BIO_read(3) can be used to retrieve data from it. In this use case, do not call PKCS7_dataFinal(3); simply proceed directly to BIO_free_all(3) after reading the data. thatβs the whole vibe. π«Ά
π₯ RETURN VALUES π₯
PKCS7_dataInit() returns a BIO chain on success or NULL on failure. It fails if p7 is NULL, if the content field of p7 is empty, if the contentType of p7 is unsupported, if a cipher is required but none is configured, or if any required operation fails β for example due to lack of memory or for various other reasons. so yeah, it can absolutely fold. π
π SEE ALSO π
BIO_new(3), BIO_read(3), PKCS7_content_new(3), PKCS7_dataFinal(3), PKCS7_encrypt(3), PKCS7_final(3), PKCS7_new(3), PKCS7_set_type(3), PKCS7_sign(3)
β HISTORY β
PKCS7_dataInit() first appeared in SSLeay 0.8.1 and has been available since OpenBSD 2.4. vintage but make it useful. π
π CAVEATS π
π¨ this function does not support EncryptedData. not me finding out the hard way. π
π BUGS π
π ifp7is a fully populated structure containingEnvelopedData,SignedAndEnvelopedData, or arbitrary data,PKCS7_dataInit()returns aBIOchain that ultimately reads from an empty memoryBIO, so reading from it will instantly return an end-of-file indication rather than reading the actual data contained inp7.
source/version: Debian π β date: June 3, 2020 π β and thatβs the cute little sign-off, bestie. periodt. β¨
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms