CMS_SIGN(3ossl)
π CMS_SIGN(3ossl) β like, the whole entire manual page, bestie π
okay so this is CMS_sign, CMS_sign_ex β yes that's the manual name, we're not doing the boring header line, we're doing vibes instead. Buckle up, this one's actually kind of iconic. π
β¨ NAME β¨
CMS_sign, CMS_sign_ex β literally just creating a CMS SignedData structure. that's the whole job. that's the assignment. π
πΈ SYNOPSIS πΈ
#include <openssl/cms.h>
CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey,
STACK_OF(X509) *certs, BIO *data,
unsigned int flags, OSSL_LIB_CTX *ctx,
const char *propq);
CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
BIO *data, unsigned int flags);
look at those signatures. gorgeous. no notes. π«Ά
π¦ DESCRIPTION π¦
okay so CMS_sign_ex() creates and returns a CMS SignedData structure. that's the main character move here.
signcertβ the certificate you're signing with πpkeyβ the corresponding private key, you literally cannot do this without itcertsβ an optional extra set of certificates to include in the CMS structure (think: any intermediate CAs in the chain, iykyk)libctxβ the library context, andpropqβ the property query; these two get used when retrieving algorithms from providersdataβ the actual data to be signed, read from thisBIOflagsβ an optional set of flags (we'll get to those, there are so many, stay with me)
and get this β any or all of these parameters can be NULL, but like, go read NOTES below before you get cute with that. π
CMS_sign() is basically CMS_sign_ex()'s lowkey sibling β same energy, but it uses default values of NULL for the library context libctx and the property query propq. slay.
π₯ NOTES π₯
okay bestie, here's where it gets juicy. any of the following flags (ored together, obvs) can be passed in the flags parameter:
- many S/MIME clients expect the signed content to include valid MIME headers. so if the
CMS_TEXTflag is set, MIME headers for typetext/plainget prepended to the data. periodt. π - if
CMS_NOCERTSis set, the signer's certificate will not be included in theCMS_ContentInfostructure β but the signer's certificate must still be supplied in thesigncertparameter though, don't get it twisted. this can reduce the size of the signature if the signer's certificate can be obtained by other means: for example, a previously signed message. π - the data being signed is included in the
CMS_ContentInfostructure, unlessCMS_DETACHEDis set, in which case it is omitted. this is used forCMS_ContentInfodetached signatures, which are used in S/MIME plaintext signed messages for example. - normally the supplied content is translated into MIME canonical format (as required by the S/MIME specifications). if
CMS_BINARYis set, no translation occurs. > β οΈ use this if the supplied data is in binary format β otherwise the translation will corrupt it. like, actually ruin it. not a vibe. - the
SignedDatastructure includes several CMSsignedAttributes, including the signing time, the CMS content type, and the supported list of ciphers in anSMIMECapabilitiesattribute. and then:- if
CMS_NOATTRis set β nosignedAttributeswill be used at all - if
CMS_NOSMIMECAPis set β theSMIMECapabilitieswill be omitted - if
CMS_NO_SIGNING_TIMEis set β the signing time will be omitted
- if
- if present, the
SMIMECapabilitiesattribute indicates support for the following algorithms in preference order: 256 bit AES, Gost R3411-94, Gost 28147-89, 192 bit AES, 128 bit AES, triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. if any of these algorithms is not available then it will not be included: for example, the GOST algorithms will not be included if the GOST ENGINE is not loaded. π - OpenSSL will by default identify signing certificates using issuer name and serial number. if
CMS_USE_KEYIDis set, it will use the subject key identifier value instead. > π¨ an error occurs if the signing certificate does not have a subject key identifier extension. no extension, no entry. - if the flags
CMS_STREAMis set, then the returnedCMS_ContentInfostructure is just initialized, ready to perform the signing operation. the signing is however not performed, and the data to be signed is not read from thedataparameter. signing is deferred until after the data has been written. in this way, data can be signed in a single pass. efficiency queen. β - if the
CMS_PARTIALflag is set, a partialCMS_ContentInfostructure is output, to which additional signers and capabilities can be added before finalization. build-a-bear but make it cryptography. π§Έ - > π if the flag
CMS_STREAMis set, the returnedCMS_ContentInfostructure is not complete, and outputting its contents via a function that does not properly finalize theCMS_ContentInfostructure will give unpredictable results. don't do that. please. - several functions β including
SMIME_write_CMS(),i2d_CMS_bio_stream(), andPEM_write_bio_CMS_stream()β finalize the structure. alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly usingBIO_new_CMS(). - if a signer is specified, it will use the default digest for the signing algorithm. this is
SHA256for both RSA and DSA keys. queen behavior. - if
signcertandpkeyareNULL, then a certificates only CMS structure is output. - the function
CMS_sign()is a basic CMS signing function whose output will be suitable for many purposes. for finer control of the output format, thecerts,signcertandpkeyparameters can all beNULLand theCMS_PARTIALflag set. then one or more signers can be added using the functionCMS_add1_signer(), non default digests can be used, and custom attributes added.CMS_final()must then be called to finalize the structure if streaming is not enabled. π
π BUGS π
some attributes, such as counter signatures, are not supported. yeah. that's it. that's the bug section. we move. π
π RETURN VALUES π
CMS_sign_ex() and CMS_sign() return either a valid CMS_ContentInfo structure, or NULL if an error occurred. the error can be obtained from ERR_get_error(3). go get your receipts, bestie.
π SEE ALSO π
β HISTORY β
- the
CMS_STREAMflag is only supported for detached data in OpenSSL0.9.8β it is supported for embedded data in OpenSSL1.0.0and later. glow up. β¨ - the
CMS_sign_ex()method was added in OpenSSL3.0. - since OpenSSL
3.2,CMS_sign_ex()andCMS_sign()ignore any duplicate certificates in theircertsargument and no longer throw an error for them. we simply do not perceive them. π
π COPYRIGHT π
Copyright 2008-2025 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 thing, you're officially smarter than you were 5 minutes ago π«Ά this little beauty dropped as version 3.5.6, dated 2026-04-07 β and that's the actual footer, bestie, we just made it cute. mwah. π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms