SMIME_READ_ASN1(3SSL)
π SMIME_read_ASN1_ex, SMIME_read_ASN1 β parse S/MIME message π
okay bestie so this is the OpenSSL 3SSL girlies' guide to pulling an S/MIME message apart. yes it's giving β¨parsingβ¨, and yes it's lowkey iconic. let's get into it π«Ά
β¨ SYNOPSIS β¨
#include <openssl/asn1.h>
ASN1_VALUE *SMIME_read_ASN1_ex(BIO *in, int flags, BIO **bcont,
const ASN1_ITEM *it, ASN1_VALUE **x,
OSSL_LIB_CTX *libctx, const char *propq);
ASN1_VALUE *SMIME_read_ASN1(BIO *in, BIO **bcont, const ASN1_ITEM *it);
not me giving you the exact signatures character for character π copy them, don't freestyle them.
πΈ DESCRIPTION πΈ
SMIME_read_ASN1_ex() parses a message in S/MIME format. that's the whole job. that's the gig. π
in is a BIO to read the message from.
if the flags argument contains CMS_BINARY then the input is assumed to be in binary format and is not translated to canonical form. and if SMIME_ASCIICRLF is set in addition to that, then the binary input is assumed to be followed by CR and LF characters β otherwise it's assumed to be followed only by an LF character. (yes, they're being that specific. respect it. π)
x can be used to optionally supply a previously created it ASN1_VALUE object (things like CMS_ContentInfo or PKCS7) β and it can also just be set to NULL, no pressure. π¦ valid values that can be used by the ASN.1 structure it are ASN1_ITEM_rptr(PKCS7) or ASN1_ITEM_rptr(CMS_ContentInfo).
any algorithm fetches that happen during the operation will use the OSSL_LIB_CTX supplied in the libctx parameter, and will use the property query string propq. see "ALGORITHM FETCHING" in crypto(7) for further details about algorithm fetching β go read it, it's giving homework but make it cute. π
if cleartext signing is used then the content is saved in a memory bio which is written to *bcont, otherwise *bcont is set to NULL. slay, noted. β¨
the parsed ASN1_VALUE structure is returned β or NULL if an error occurred. no in between, bestie, it's giving binary. π
SMIME_read_ASN1() is similar to SMIME_read_ASN1_ex() but sets the value of x to NULL and the value of flags to 0. it's the low-effort version and honestly? valid. π§
π NOTES π
the higher level functions SMIME_read_CMS_ex(3) and SMIME_read_PKCS7_ex(3) should be used instead of SMIME_read_ASN1_ex(). like. they're the main characters here. this one's the understudy. π
to support future functionality, if bcont is not NULL then *bcont should be initialized to NULL. don't skip this, it's one line and the future will thank you. π«Ά
π BUGS π
the MIME parser used by SMIME_read_ASN1_ex() is somewhat primitive. while it will handle most S/MIME messages, more complex compound formats may not work. it's doing its best okay π
also! the use of a memory BIO to hold the signed content limits the size of message which can be processed due to memory restraints: a streaming single pass option should be available. (it isn't. we're manifesting. π―οΈ)
β RETURN VALUES β
SMIME_read_ASN1_ex() and SMIME_read_ASN1() return a valid ASN1_VALUE structure, or NULL if an error occurred. the error can be obtained from ERR_get_error(3). so when you get a NULL, don't spiral β go ask ERR_get_error(3) what happened. communication is key. π
π SEE ALSO π
ERR_get_error(3)SMIME_read_CMS_ex(3)SMIME_read_PKCS7_ex(3)SMIME_write_ASN1(3)SMIME_write_ASN1_ex(3)
π HISTORY π
the function SMIME_read_ASN1_ex() was added in OpenSSL 3.0. baby girl is not that old, she just acts like it. π
π COPYRIGHT π
Copyright 2020-2021 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.
okay and that's the whole page, bestie π this was OpenSSL 4.0.3, dated 2026-09-29, and it's the SMIME_READ_ASN1(3SSL) manual β go forth and parse responsibly, mwah ππΈβ¨
π¦ 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