CMS_SIGN(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’– 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 it
  • certs β€” an optional extra set of certificates to include in the CMS structure (think: any intermediate CAs in the chain, iykyk)
  • libctx β€” the library context, and propq β€” the property query; these two get used when retrieving algorithms from providers
  • data β€” the actual data to be signed, read from this BIO
  • flags β€” 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_TEXT flag is set, MIME headers for type text/plain get prepended to the data. periodt. πŸ’…
  • if CMS_NOCERTS is set, the signer's certificate will not be included in the CMS_ContentInfo structure β€” but the signer's certificate must still be supplied in the signcert parameter 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_ContentInfo structure, unless CMS_DETACHED is set, in which case it is omitted. this is used for CMS_ContentInfo detached 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_BINARY is 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 SignedData structure includes several CMS signedAttributes, including the signing time, the CMS content type, and the supported list of ciphers in an SMIMECapabilities attribute. and then:
    • if CMS_NOATTR is set β†’ no signedAttributes will be used at all
    • if CMS_NOSMIMECAP is set β†’ the SMIMECapabilities will be omitted
    • if CMS_NO_SIGNING_TIME is set β†’ the signing time will be omitted
  • 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. 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_KEYID is 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_STREAM is set, then the returned CMS_ContentInfo structure 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 the data parameter. 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_PARTIAL flag is set, a partial CMS_ContentInfo structure is output, to which additional signers and capabilities can be added before finalization. build-a-bear but make it cryptography. 🧸
  • > 😭 if the flag CMS_STREAM is set, the returned CMS_ContentInfo structure is not complete, and outputting its contents via a function that does not properly finalize the CMS_ContentInfo structure will give unpredictable results. don't do that. please.
  • several functions β€” including SMIME_write_CMS(), i2d_CMS_bio_stream(), and PEM_write_bio_CMS_stream() β€” finalize the structure. alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly using BIO_new_CMS().
  • if a signer is specified, it will use the default digest for the signing algorithm. this is SHA256 for both RSA and DSA keys. queen behavior.
  • if signcert and pkey are NULL, 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, 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. πŸŽ€

πŸ’€ 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_STREAM flag is only supported for detached data in OpenSSL 0.9.8 β€” it is supported for embedded data in OpenSSL 1.0.0 and later. glow up. ✨
  • the CMS_sign_ex() method was added in OpenSSL 3.0.
  • since OpenSSL 3.2, CMS_sign_ex() and CMS_sign() ignore any duplicate certificates in their certs argument and no longer throw an error for them. we simply do not perceive them. πŸ’…

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