SMIME_READ_CMS(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’Œ SMIME_READ_CMS(3ossl) β€” like, the whole vibe

okay so bestie, welcome to the 3ossl corner of the OpenSSL man-verse πŸŽ€ this one's all about SMIME_read_CMS_ex and SMIME_read_CMS, which is literally "parse S/MIME message" energy. yes. that's the name section. we ate. πŸ’…


✨ 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);

no cap, that's the whole signature situation 🫢


πŸ’– DESCRIPTION πŸ’–

So SMIME_read_CMS() parses a message in S/MIME format. iconic behaviour honestly.

in is a BIO to read the message from. that's your source, your main character, your input stream ✨

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. lowkey important detail, remember it 🌸

The parsed CMS_ContentInfo structure is returned, or NULL if an error occurred 😭 (sad but honest).

Now for SMIME_read_CMS_ex() β€” she's similar to SMIME_read_CMS() but optionally a previously created cms CMS_ContentInfo object can be supplied as well as some flags. To create a cms object use CMS_ContentInfo_new_ex(3). iykyk πŸ‘‘

  • If the flags argument contains CMS_BINARY then the input is assumed to be in binary format and is not translated to canonical form. 🧚
  • 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. πŸ’…

And if flags is 0 and cms is NULL then it is identical to SMIME_read_CMS(). literally the same function, just wearing a different outfit πŸ’€


πŸ“ NOTES πŸ“

If *bcont is not NULL then the message is clear text signed. *bcont can then be passed to CMS_verify() with the CMS_DETACHED flag set. periodt. πŸ”₯

Otherwise the type of the returned structure can be determined using CMS_get0_type(). πŸ¦‹

To support future functionality, if bcont is not NULL, *bcont should be initialized to NULL. bestie please do this, it's giving future-proofing πŸ’–

For example:

BIO *cont = NULL;
CMS_ContentInfo *cms;

cms = SMIME_read_CMS(in, &cont);

that's it, that's the whole setup 🌈


πŸ’€ BUGS πŸ’€

okay so we gotta be honest, the MIME parser used by SMIME_read_CMS() is somewhat primitive. While it will handle most S/MIME messages, more complex compound formats may not work. it's trying its best πŸ™ˆ

The parser assumes that the CMS_ContentInfo structure is always base64 encoded, and will not handle the case where it is in binary format or uses quoted printable format. no cap, that's a real limitation ⚠️

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. (future feature energy, we're manifesting it ✨)


πŸŽ€ RETURN VALUES πŸŽ€

SMIME_read_CMS_ex() and SMIME_read_CMS() return a valid CMS_ContentInfo structure or NULL if an error occurred. The error can be obtained from ERR_get_error(3). so if it flops, that's where the receipts are 🧾


πŸ‘€ SEE ALSO πŸ‘€

the whole crew, fr fr πŸ’œ


🌸 HISTORY 🌸

The function SMIME_read_CMS_ex() was added in OpenSSL 3.0. new-ish but already iconic ⭐


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>. (yes, read the license bestie, it's not optional πŸ’…)


and that's the page!! mwah πŸ’‹ this whole thing shipped with OpenSSL 3.5.0 and the date on it is 2026-09-25 β€” SMIME_read_CMS(3ossl), signing off 🫢✨ πŸ“

πŸ“¦ where this page comes from