SMIME_READ_ASN1(3ossl)
π SMIME_READ_ASN1(3ossl) β bestie's guide to parsing S/MIME messages
okay so welcome to the SMIME_read_ASN1(3ossl) page, part of OpenSSL's 3ossl manual fam π
this one is literally all about pulling an S/MIME message apart, and ngl it's giving "small function, big lore." stay with me, we're gonna slay it β¨
πΈ NAME πΈ
SMIME_read_ASN1_ex, SMIME_read_ASN1 β parse S/MIME message π
yes bestie, that's the whole job. two functions, one mission: take an S/MIME message and turn it into something you can actually use. iconic behaviour honestly.
β¨ 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);
look at that signature on the _ex one, she's LONG, she's got six... okay seven... arguments, she's a main character fr fr π but every single one of them matters, so don't skip a single arg, bestie.
π¦ DESCRIPTION π¦
SMIME_read_ASN1_ex() parses a message in S/MIME format. that's it, that's her whole personality π
inis aBIOto read the message from. your input stream, your vibe source, ykyk.- if the
flagsargument containsCMS_BINARYthen the input is assumed to be in binary format and is not translated to canonical form. so no glow-up into canonical form for this one, she stays raw π - if in addition
SMIME_ASCIICRLFis set, then the binary input is assumed to be followed byCRandLFcharacters β else only by anLFcharacter. details details, but the details are the whole point, lowkey π xcan be used to optionally supply a previously createditASN1_VALUEobject (such asCMS_ContentInfoorPKCS7) β it can be set toNULL. your choice, no pressure π«Ά- valid values that can be used by ASN.1 structure
itareASN1_ITEM_rptr(PKCS7)orASN1_ITEM_rptr(CMS_ContentInfo). those two, that's the list, don't try to be creative π - any algorithm fetches that occur during the operation will use the
OSSL_LIB_CTXsupplied in thelibctxparameter, and use the property query stringpropq. see"ALGORITHM FETCHING"incrypto(7)for further details about algorithm fetching. go read it, it's tea β
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. so either you get the goods, or you get NULL, no in-between π
the parsed ASN1_VALUE structure is returned, or NULL if an error occurred. π
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. she's the low-effort version of her sister and honestly? same energy πΈ
π§ NOTES π§
bestie PLEASE read this part, it's important π
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, this one works, but those are the upgrade, the glow-up, the "she's not like other functions." use those β¨
to support future functionality, if bcont is not NULL then *bcont should be initialized to NULL. future-proofing is self-care, periodt π
π BUGS π
the MIME parser used by SMIME_read_ASN1_ex() is somewhat primitive. not me calling out the parser like this but okay, the manpage said it first π while it will handle most S/MIME messages, more complex compound formats may not work. so if something weird fails, it's not you, it's the parser π
the use of a memory BIO to hold the signed content limits the size of message which can be processed due to memory restraints β and a streaming single pass option should be available. note the "should," bestie, meaning it is NOT available yet, so plan accordingly π
π 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). always check, bestie, always check π₯
π 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)
the whole friend group honestly, go say hi π«Ά
π HISTORY π
the function SMIME_read_ASN1_ex() was added in OpenSSL 3.0. a queen was born, history was made, we were all there π
π 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 that's the page!! π this was SMIME_read_ASN1(3ossl) from OpenSSL version 3.5.6, dated 2026-04-07 β write that down, cite it in your essay, print it out and put it on your wall, whatever you need bestie. mwah, go parse responsibly πβ¨π¦
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms