SMIME_READ_CMS(3ossl)

πŸ’Œ SMIME_read_CMS β€” bestie edition (that's the SMIME_read_CMS(3ossl) girlies, come thru) ✨

okay so welcome to the manual page for SMIME_read_CMS and SMIME_read_CMS_ex, and no cap, these two are the ones you call when you have a whole S/MIME message sitting in a BIO and you just want the actual CMS structure out of it. it's giving "unboxing but for cryptography." πŸŽ€


✨ NAME ✨

SMIME_read_CMS_ex, SMIME_read_CMS β€” parse an S/MIME message, fr fr πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/cms.h>

CMS_ContentInfo *SMIME_read_CMS_ex(BIO *bio, int flags, BIO **bcont,
                                   CMS_ContentInfo **cms);
CMS_ContentInfo *SMIME_read_CMS(BIO *in, BIO **bcont);

πŸ¦‹ DESCRIPTION πŸ¦‹

so SMIME_read_CMS() is the main character here β€” she parses a message that's in S/MIME format. πŸ’–

in is the BIO you're reading that message from. that's it, that's the input, she reads from it.

if cleartext signing is being used, then the content gets saved into a memory bio, and that memory bio gets written to *bcont. otherwise (aka no cleartext signing happening), *bcont is set to NULL. simple as that. 🫢

the parsed CMS_ContentInfo structure is what you get back, or NULL if an error went down. πŸ™ˆ

now, SMIME_read_CMS_ex() is like her slightly more extra sister β€” same vibe, but optionally you can hand her a previously created cms CMS_ContentInfo object, plus some flags. if you need to create a cms object yourself, that's CMS_ContentInfo_new_ex(3), go off. πŸ‘‘

and the flags, bestie, listen:

  • if the flags argument contains CMS_BINARY, then the input is assumed to be in binary format and is not translated to canonical form. okay? not. translated. 😀
  • if in addition SMIME_ASCIICRLF is set, then that binary input is assumed to be followed by CR and LF characters. otherwise it's only followed by an LF character. lowkey a whole distinction, i know. 🌈

and if flags is 0 and cms is NULL, then honestly? she's literally identical to SMIME_read_CMS(). same girl, different fit. πŸ’€


πŸ’œ NOTES πŸ’œ

if *bcont is not NULL, that means the message is clear text signed. πŸŽ‰ and once you've got it, *bcont can then be passed to CMS_verify() with the CMS_DETACHED flag set. periodt.

otherwise (i.e. when *bcont is NULL), the type of the returned structure can be figured out using CMS_get0_type(). mystery solved, sleuth. πŸ”

and here's the little future-proofing moment: to support future functionality, if bcont is not NULL, you should initialize *bcont to NULL. yes, bestie, before. for example:

BIO *cont = NULL;
CMS_ContentInfo *cms;

cms = SMIME_read_CMS(in, &cont);

that's the whole vibe. do that. πŸ™


πŸ’€ BUGS πŸ’€ (yes we're airing it out)

okay so the MIME parser that SMIME_read_CMS() uses is, and i say this with love, somewhat primitive. 😭 she will handle most S/MIME messages, sure, but more complex compound formats may just... not work. it's giving "tried her best."

the parser also assumes that the CMS_ContentInfo structure is always base64 encoded. so if it's in binary format, or it uses quoted printable format? she will not handle that case. nope. not happening. πŸ™ˆ

and β€” big one β€” the use of a memory BIO to hold the signed content limits the size of the message that can be processed, because, y'know, memory restraints. a streaming single pass option should be available. it's not, but it should be. manifesting it. πŸ•―οΈβœ¨


🌟 RETURN VALUES 🌟

SMIME_read_CMS_ex() and SMIME_read_CMS() both return a valid CMS_ContentInfo structure, or NULL if an error occurred. πŸ’– and if you did get an error, you can obtain it from ERR_get_error(3). go get your girl, she'll tell you what happened.


πŸ‘€ SEE ALSO πŸ‘€


⭐ HISTORY ⭐

the function SMIME_read_CMS_ex() was added in OpenSSL 3.0. a legend was born. πŸ‘‘


Copyright 2008-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>.


and that's the whole page, bestie!! 🫢 this was SMIME_read_CMS(3ossl) from the OpenSSL 3.5.9 era, dated 2026-09-29 β€” mwah, slay, go parse something beautiful πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from