SMIME_READ_CMS(3SSL)
π SMIME_READ_CMS(3SSL) β the OpenSSL girlies' guide π
okay so bestie, welcome to SMIME_read_CMS_ex and SMIME_read_CMS π this is the OpenSSL manual, and today we're parsing S/MIME messages. yes really. it's giving crypto pen-pal energy. let's go π¦
β¨ NAME β¨
SMIME_read_CMS_ex, SMIME_read_CMS β parse S/MIME message π
πΈ 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() parses a message in S/MIME format. that's the whole vibe. π
in is a BIO you read the message from. that's your little pipe, your lil stream, your main character entrance. π«Ά
If cleartext signing is being used, then the content gets saved into a memory bio, and that bio is written to *bcont. otherwise *bcont is set to NULL. no content, no drama. πΈ
Then you get back the parsed CMS_ContentInfo structure β or NULL if an error happened. π (we'll get to that)
SMIME_read_CMS_ex() is literally the same energy as SMIME_read_CMS() except you optionally get to hand it a previously created cms CMS_ContentInfo object, plus some flags. β¨ If you wanna make a cms object, use CMS_ContentInfo_new_ex(3) β she's iconic, she's the blueprint.
Now the flags, bestie, listen up π
- if
flagscontainsCMS_BINARY, then the input is assumed to be in binary format and is not translated to canonical form. - if in addition
SMIME_ASCIICRLFis set, then the binary input is assumed to be followed by CR and LF characters; otherwise it's only followed by an LF character.
And the cute little shortcut: if flags is 0 and cms is NULL, then SMIME_read_CMS_ex() is identical to SMIME_read_CMS(). same girl, different name. π
π NOTES π
If *bcont is not NULL, then the message is clear text signed π₯ and you can then pass *bcont to CMS_verify() with the CMS_DETACHED flag set. slay.
Otherwise, you can figure out the type of the returned structure using CMS_get0_type(). know your type, know your worth. β¨
And for future functionality support β like, the devs are thinking ahead, we love that β if bcont is not NULL, then bcont should be initialized to NULL. for example:
BIO *cont = NULL;
CMS_ContentInfo *cms;
cms = SMIME_read_CMS(in, &cont);
initialize your pointers, protect your peace π
π BUGS π
ngl, the MIME parser used by SMIME_read_CMS() is somewhat primitive. π it will handle most S/MIME messages, but more complex compound formats may justβ¦ not work. she's doing her best.
The parser also assumes that the CMS_ContentInfo structure is always base64 encoded π« and it will not handle the case where it's in binary format, or where it uses quoted printable format. so if your message is built different, she's not gonna recognize it. π
And okay, the tea: using a memory BIO to hold the signed content limits the size of the message you can process, because, well, memory restraints. a streaming single-pass option should be available. it is not. periodt. π
π₯ RETURN VALUES π₯
SMIME_read_CMS_ex() and SMIME_read_CMS() return a valid CMS_ContentInfo structure β or NULL if an error occurred. π
You can get the error from ERR_get_error(3). go check her, she'll tell you what went wrong. π
π SEE ALSO π
ERR_get_error(3), CMS_sign(3), CMS_verify(3), CMS_encrypt(3), CMS_decrypt(3)
(the whole squad, fr fr π«Ά)
β HISTORY β
The function SMIME_read_CMS_ex() was added in OpenSSL 3.0. she's new-ish, she's fresh, she's the upgrade. β¨
π 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>.
okay that's the whole page bestie, you ate π
β¨ this was OpenSSL 4.0.3, dated 2026-09-29, and yes it's still SMIME_READ_CMS(3SSL) β go forth and parse those messages, you absolute icon πππ¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms