SMIME_READ_ASN1(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’Œ 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 πŸ’–

  • in is a BIO to read the message from. your input stream, your vibe source, ykyk.
  • if the flags argument contains CMS_BINARY then 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_ASCIICRLF is set, then the binary input is assumed to be followed by CR and LF characters β€” else only by an LF character. details details, but the details are the whole point, lowkey πŸ‘‘
  • x can be used to optionally supply a previously created it ASN1_VALUE object (such as CMS_ContentInfo or PKCS7) β€” it can be set to NULL. your choice, no pressure 🫢
  • valid values that can be used by ASN.1 structure it are ASN1_ITEM_rptr(PKCS7) or ASN1_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_CTX supplied in the libctx parameter, and use the property query string propq. see "ALGORITHM FETCHING" in crypto(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 🌈

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 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