CMS_SIGN(3SSL)
β¨ CMS_SIGN π
okay bestie, pull up a chair because we're talking about CMS_sign and CMS_sign_ex from the OpenSSL family β yes, that OpenSSL, the 3SSL girlies, the manual section three girlies π
πΈ NAME πΈ
CMS_sign, CMS_sign_ex β the way these two literally just create a CMS SignedData structure. that's it. that's the job. iconic behavior honestly π
β¨ 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. so clean. so demure. π
π¦ DESCRIPTION π¦
so CMS_sign_ex() is the main character here β she creates and returns a CMS SignedData structure. slay.
signcertis the certificate you're signing with ποΈpkeyis the corresponding private key πcertsis an optional additional set of certificates that get included in the CMS structure (thinking like, any intermediate CAs hanging out in the chain, yk?) π- the library context
libctxand the property querypropqare what get used when retrieving algorithms from providers π
and here's the tea: any or all of these parameters can be NULL β scroll down to NOTES, bestie, we get into it π
The data to be signed is read from the BIO data. π
flags is an optional set of flags β we're gonna go through ALL of them, don't worry, I would never leave you hanging.
And CMS_sign()? She's basically CMS_sign_ex()'s chill little sister β same energy, but she uses default values of NULL for the library context libctx and the property query propq. no cap. π«Ά
π NOTES π
okay so, any of the following flags (ored together, obviously) can be passed in the flags parameter. let's go one by one, bestie, because I love you π
- Many S/MIME clients expect the signed content to include valid MIME headers. If the
CMS_TEXTflag is set, MIME headers for typetext/plainare prepended to the data. cute, right? π CMS_NOCERTSβ if this is set, the signer's certificate will not be included in theCMS_ContentInfostructure. but plot twist: the signer's certificate must still be supplied in thesigncertparameter though π« . 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. recycling! we love sustainability πCMS_DETACHEDβ the data being signed is included in theCMS_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. βοΈCMS_BINARYβ normally the supplied content is translated into MIME canonical format (as required by the S/MIME specifications). IfCMS_BINARYis set, no translation occurs. This option should be used if the supplied data is in binary format, otherwise the translation will corrupt it. π¨ not a drill, bestie, this one's serious.- signedAttributes talk π β the SignedData structure includes several CMS signedAttributes, including the signing time, the CMS content type, and the supported list of ciphers in an SMIMECapabilities attribute. So:
- if
CMS_NOATTRis set β no signedAttributes will be used at all. none. zero. bye. - if
CMS_NOSMIMECAPis set β the SMIMECapabilities will be omitted. - if
CMS_NO_SIGNING_TIMEis set β the signing time will be omitted. β°
- if
- SMIMECapabilities deets β if present, the SMIMECapabilities attribute 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. And if any of these algorithms is not available, then it will not be included. simple as that πββοΈ
CMS_USE_KEYIDβ OpenSSL will by default identify signing certificates using issuer name and serial number. IfCMS_USE_KEYIDis set, it will use the subject key identifier value instead. And heads up: an error occurs if the signing certificate does not have a subject key identifier extension. β οΈCMS_STREAMβ if this flag is set, the returnedCMS_ContentInfostructure is just initialized, ready to perform the signing operation. But β and this is the important part β 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 πCMS_PARTIALβ if this flag is set, a partialCMS_ContentInfostructure is output, to which additional signers and capabilities can be added before finalization. build-a-bear energy π§Έ
β οΈ BIG WARNING BESTIE β if the flagCMS_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. π do not do this. do not be that girl.
Several functions β including SMIME_write_CMS(), i2d_CMS_bio_stream(), PEM_write_bio_CMS_stream() β finalize the structure. β
Alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly using BIO_new_CMS(). your call, diva β¨
If a signer is specified, it will use the default digest for the signing algorithm. This is SHA256 for both RSA and DSA keys. π
If signcert and pkey are NULL, then a certificates only CMS structure is output. just certs, no signing, vibing π
The function CMS_sign() is a basic CMS signing function whose output will be suitable for many purposes. But for finer control of the output format, the certs, signcert and pkey parameters can all be NULL and the CMS_PARTIAL flag set. Then one or more signers can be added using the function CMS_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. see? the girlies who want options get options π
π BUGS π
Some attributes β such as counter signatures β are not supported. we don't talk about it. π
β RETURN VALUES β
CMS_sign_ex() and CMS_sign() return either a valid CMS_ContentInfo structure, or NULL if an error occurred. And the error can be obtained from ERR_get_error(3). go get your girl, she'll tell you what happened π
π¦ SEE ALSO π¦
(the besties tag along, as always π«Ά)
π HISTORY π
- The
CMS_STREAMflag is only supported for detached data in OpenSSL 0.9.8. It's supported for embedded data in OpenSSL 1.0.0 and later. glow up timeline β¨ - The
CMS_sign_ex()method was added in OpenSSL 3.0. welcome to the world, baby πΌ - Since OpenSSL 3.2,
CMS_sign_ex()andCMS_sign()ignore any duplicate certificates in theircertsargument and no longer throw an error for them. character development, honestly π
π 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 page bestie, you ate that π this was CMS_SIGN(3SSL) from OpenSSL 4.0.3, dated 2026-09-29 β go forth and sign something slay β¨ππ¦
π¦ 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