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
flagsargument containsCMS_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_ASCIICRLFis 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 π
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
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms