CMS_SIGN(3)
π CMS_SIGN(3) β create a CMS SignedData structure π
okay bestie, welcome to the Library Functions Manual page for CMS_sign β yes, the CMS signing function, and yes, sheβs giving main-character crypto energy π
πΈ NAME πΈ
CMS_sign β create a CMS SignedData structure
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/cms.h>
CMS_ContentInfo *
CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
BIO *data, unsigned int flags);
π DESCRIPTION π
CMS_sign() creates and returns a CMS SignedData structure. signcert is the certificate to sign with, and pkey is the corresponding private key. certs is an optional additional set of certificates to include in the CMS structure β think any intermediate CAs in the chain, bestie. Any or all of these parameters can be NULL.
The data to be signed is read from data. no cap, thatβs the tea β
π© flags (inside DESCRIPTION) π©
Any of the following flags (OR'ed together) can be passed in the flags argument:
CMS_TEXTβ Prepend MIME headers for the typetext/plainto the data. Many S/MIME clients expect the signed content to include valid MIME headers.CMS_NOCERTSβ Do not include the signerβs certificate in theCMS_ContentInfostructure. 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 from a previously signed message.CMS_DETACHEDβ Omit the data being signed from theCMS_ContentInfostructure. This is used forCMS_ContentInfodetached signatures which are used in S/MIME plaintext signed messages for example.CMS_BINARYβ Do not translate the supplied content into MIME canonical format even though that is required by the S/MIME specifications. This option should be used if the supplied data is in binary format. Otherwise the translation will corrupt it. πCMS_NOATTRβ Do not add any SignedAttributes. By default, thesignerInfosfield includes several CMS SignedAttributes including the signing time, the CMS content type, and the supported list of ciphers in an SMIMECapabilities attribute.CMS_NOSMIMECAPβ Omit just the SMIMECapabilities. If present, the SMIMECapabilities attribute indicates support for the following algorithms in preference order: 256-bit AES, 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.CMS_USE_KEYIDβ Use the subject key identifier value to identify signing certificates. An error occurs if the signing certificate does not have a subject key identifier extension. By default, issuer name and serial number are used instead.CMS_STREAMβ Only initialize the returnedCMS_ContentInfostructure to prepare it for performing 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. β οΈ warning, bestie: the returnedCMS_ContentInfostructure is not complete and outputting its contents via a function that does not properly finalize theCMS_ContentInfostructure will give unpredictable results. Several functions includingSMIME_write_CMS(3),i2d_CMS_bio_stream(3), orPEM_write_bio_CMS_stream(3)finalize the structure. Alternatively, finalization can be performed by obtaining the streaming ASN1 BIO directly usingBIO_new_CMS(3).CMS_PARTIALβ Output a partialCMS_ContentInfostructure to which additional signers and capabilities can be added before finalization.
If a signer is specified, it will use the default digest for the signing algorithm. This is SHA-1 for both RSA and DSA keys. iykyk π«
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(3), non default digests can be used and custom attributes added. CMS_final(3) must then be called to finalize the structure if streaming is not enabled. slay the customization arc β¨
π«Ά RETURN VALUES π«Ά
CMS_sign() returns either a valid CMS_ContentInfo structure or NULL if an error occurred. The error can be obtained from ERR_get_error(3).
π₯ SEE ALSO π₯
CMS_add0_cert(3)CMS_add1_signer(3)CMS_ContentInfo_new(3)CMS_final(3)CMS_sign_receipt(3)CMS_verify(3)
π STANDARDS π
RFC 5652: Cryptographic Message Syntax (CMS)- section 5.1: SignedData Type
- section 5.3: SignerInfo Type
RFC 8419: Use of Edwards-Curve Digital Signature Algorithm (EdDSA) Signatures in the Cryptographic Message Syntax (CMS)RFC 8551: Secure/Multipurpose Internet Mail Extensions (S/MIME) Version 4.0 Message Specification, section 2.5.2: SMIMECapabilities Attribute
π HISTORY π
CMS_sign() first appeared in OpenSSL 0.9.8h and has been available since OpenBSD 6.7. vintage but still iconic π
π BUGS π
Some attributes such as counter signatures are not supported. not me pointing at the missing counter signatures π
mwah π β footer sign-off: source/version Debian, date June 8, 2025, manual CMS_SIGN(3). bye bestie, go sign something safely π«Ά
π¦ 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) 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