SMIME_WRITE_CMS(3)
π SMIME_WRITE_CMS π
okay so bestie, welcome to SMIME_write_CMS β the libcrypto girlie whose whole job is converting a CMS structure into S/MIME format. yes that's the NAME, and yes she's iconic for it β¨
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/cms.h>
int
SMIME_write_CMS(BIO *out, CMS_ContentInfo *cms, BIO *data, int flags);
π DESCRIPTION π
So SMIME_write_CMS() generates an S/MIME message on out by writing MIME 1.0 headers, and then β right after, no gap β a BER- and base64-encoded serialization of cms. The BER encoding uses the DER format, except for the cases described down in CMS_STREAM below. And if streaming is enabled, the content has to be supplied in the data argument. no cap, that's the deal π
The flags can be the logical OR of zero or more of the following bits:
π the flags
CMS_DETACHEDβ use cleartext signing and generate a"multipart/signed"S/MIME message. The content gets read fromdata. Ifdatais aNULLpointer, this flag is ignored, like it said nothing and walked away π- This flag is only supported if
cmsis of the typeSignedDataandCMS_DETACHEDwas also set when it was created withCMS_sign(3). - If
CMS_STREAMis not set, the data must be read twice: once to compute the signature inCMS_sign(3)and once to output the S/MIME message. yeah, twice. she's thorough π - If
CMS_DETACHEDis ignored or not specified, thesmime-typeis chosen according toCMS_get0_type(3):NID_pkcs7_envelopedβ"enveloped-data"NID_pkcs7_signed:"signed-receipt"ifCMS_get0_eContentType(3)isNID_id_smime_ct_receipt"signed-data"ifcmsspecifies any digest algorithm"certs-only"otherwise
NID_id_smime_ct_compressedDataβ"compressed-data"
- This flag is only supported if
CMS_REUSE_DIGESTβ skip the calls toCMS_dataInit(3)andCMS_dataFinal(3). This flag has no effect unlessCMS_DETACHEDis also set. fr fr, it does nothing on its own π«ΆCMS_STREAMβ perform streaming by reading the content fromdata. This only works ifCMS_DETACHEDis not specified.- This flag should only be set if
CMS_STREAMwas also passed to the function that createdcms. iykyk π§ - The content is output in BER format using indefinite length constructed encoding, except in the case of
SignedDatawith detached content β where the content is absent and DER format is used.
- This flag should only be set if
CMS_TEXTβ prepend the line"Content-Type: text/plain"to the content. This only makes sense ifCMS_DETACHEDis also set. It is ignored if the flagSMIME_BINARYis also set. conflicting vibes, honestly πSMIME_BINARYβ if specified, this flag is passed through toSMIME_crlf_copy(3). that's it, that's the whole job πΈSMIME_CRLFEOLβ end MIME header lines with pairs of carriage return and newline characters. By default, no carriage return characters are written and header lines are ended with newline characters only. Windows girlies stay winning π
π¦ RETURN VALUES π¦
SMIME_write_CMS() is intended to return 1 on success or 0 on failure. "intended" doing olympic-level heavy lifting there, bestie β see the BUGS section, it's giving foreshadowing π
π₯ SEE ALSO π₯
BIO_f_base64(3), BIO_new(3), CMS_ContentInfo_new(3), CMS_encrypt(3), CMS_sign(3), d2i_CMS_ContentInfo(3), ERR_get_error(3), SMIME_crlf_copy(3), SMIME_read_CMS(3), SMIME_write_PKCS7(3)
the whole friend group, honestly π«Ά
π HISTORY π
SMIME_write_CMS() first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 6.7. a true legacy icon, she's been slaying since forever β
π BUGS π
SMIME_write_CMS()ignores most errors and is likely to return1even after producing corrupt or incomplete output. so likeβ¦ she'll tell you she ate, but did she actually eat? questionable. don't trust the return value blindly πSMIME_write_CMS()always base64 encodes CMS structures. There should be an option to disable this. no option yet, so we wait π
warning bestie: that first bug is real β corrupt or incomplete output can still come back with a 1, so verify your output yourself. not me trusting the honor system π
okay that's the whole page, periodt π this was SMIME_write_CMS from the Debian build of the manual, dated June 11, 2025 β written up with love, butterflies, and a healthy distrust of return values π¦π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021, 2025 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2008 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms