SMIME_READ_PKCS7(3SSL)
π SMIME_READ_PKCS7 β bestie, it's literally the S/MIME message parser π
okay so picture this: you've got an S/MIME message and you need someone to actually read it. that's this. this is the β¨ parse S/MIME message β¨ girlies, living in the OpenSSL fam, sitting pretty in manual section 3SSL. come sit, we're doing this together π«Ά
β¨ SYNOPSIS β¨
#include <openssl/pkcs7.h>
PKCS7 *SMIME_read_PKCS7_ex(BIO *bio, BIO **bcont, PKCS7 **p7);
PKCS7 *SMIME_read_PKCS7(BIO *in, BIO **bcont);
two functions. one job. let's go π
πΈ DESCRIPTION πΈ
So SMIME_read_PKCS7() does the thing: it parses a message that's in S/MIME format. iconic behavior, honestly.
in is the BIO you're reading the message from. that's your input girlie, that's where the message lives.
Now β if cleartext signing is being used, the content gets saved into a memory bio, and that bio gets written to *bcont. and if that's not happening? then *bcont is just set to NULL. simple as. no notes. β¨
the parsed PKCS#7 structure is what you get back β or NULL if an error happened, which, tragic, but okay π
then there's SMIME_read_PKCS7_ex(), which is the same vibe as SMIME_read_PKCS7() but β and this is the fun part β it can optionally take a previously created p7 PKCS#7 object. if p7 is NULL, then honestly it's literally identical to SMIME_read_PKCS7(). and to make yourself a p7 object, you go use PKCS7_new_ex(3). periodt π
π NOTES π
If *bcont is not NULL, then bestie, the message is clear text signed. and here's the cute part: *bcont can then be passed straight to PKCS7_verify() with the PKCS7_DETACHED flag set. teamwork! π«Ά
Otherwise β like, if *bcont is NULL β you figure out the type of the returned structure using PKCS7_type_is_enveloped(), etc.
And for future-proofing purposes (to support future functionality!), if bcont is not NULL, you should initialize *bcont to NULL. iykyk. like this:
BIO *cont = NULL;
PKCS7 *p7;
p7 = SMIME_read_PKCS7(in, &cont);
do it this way. the future you is thanking you. β
π BUGS π
okay ngl, we have to talk about the flaws. not every queen is perfect.
- the MIME parser that
SMIME_read_PKCS7()uses is, and I quote, "somewhat primitive." π it will handle most S/MIME messages, but more complex compound formats? may not work. so if your format is doing the absolute most, this parser might ghost you. - the parser assumes the
PKCS7structure is always base64 encoded. it will not handle the case where it's in binary format, and it will not handle quoted printable format either. it said base64 or nothing, we don't make the rules π - and because it uses a memory BIO to hold the signed content, the size of message you can process is limited by memory restraints. the manpage's own words on the fix: a streaming single pass option should be available. meaning: it's not. yet. noted. π
π RETURN VALUES π
SMIME_read_PKCS7_ex() and SMIME_read_PKCS7() both return a valid PKCS7 structure, or NULL if an error occurred. and to get that error? you hit up ERR_get_error(3). she'll tell you what went wrong. π
π SEE ALSO π
ERR_get_error(3), SMIME_read_PKCS7(3), PKCS7_sign(3), PKCS7_verify(3), PKCS7_encrypt(3) PKCS7_decrypt(3)
the whole friend group. go say hi. π¦
π HISTORY π
SMIME_read_PKCS7_ex() was added in OpenSSL 3.0. newer addition, still slaying, no cap. β¨
π COPYRIGHT π
Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page bestie, we ate and left no crumbs π this was OpenSSL 4.0.3, dated 2026-09-29, page SMIME_READ_PKCS7(3SSL) β mwah, go parse something gorgeous π
β¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms