CMS_VERIFY(3ossl)

πŸ’– CMS_VERIFY(3ossl) β€” bestie's guide to verifying a CMS SignedData πŸ’–

okay so. hi. welcome to CMS_VERIFY, an OpenSSL manual page, but make it a group chat. we're gonna talk about CMS_verify(), CMS_SignedData_verify() and CMS_get0_signers() β€” the trio that checks whether a CMS SignedData thing is actually, you know, legit. πŸ”₯


✨ NAME ✨

CMS_verify, CMS_SignedData_verify, CMS_get0_signers β€” verify a CMS SignedData structure. that's the whole vibe. 🫢


🌸 SYNOPSIS 🌸

#include <openssl/cms.h>

int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
               BIO *detached_data, BIO *out, unsigned int flags);
BIO *CMS_SignedData_verify(CMS_SignedData *sd, BIO *detached_data,
                           STACK_OF(X509) *scerts, X509_STORE *store,
                           STACK_OF(X509) *extra, STACK_OF(X509_CRL) *crls,
                           unsigned int flags,
                           OSSL_LIB_CTX *libctx, const char *propq);

STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);

πŸ¦‹ DESCRIPTION πŸ¦‹

CMS_verify() β€” the classic

CMS_verify() is very similar to PKCS7_verify(3), iykyk. what it does is verify a CMS SignedData structure that lives inside a CMS_ContentInfo-typed struct.

  • cms β€” points at the CMS_ContentInfo structure we're verifying. the main character, honestly. πŸ‘‘
  • certs β€” optional, a set of certificates to search for signing certificates in. it also doubles as a source of untrusted intermediate CA certificates for chain building. multitasking icon. πŸ’…
  • cms itself may contain extra untrusted CA certificates that can be used for chain building, plus CRLs that can be used for certificate validation.
  • store β€” may be NULL, or point at the trusted certificate store to use for chain verification.
  • detached_data β€” points at the signed data if the content is detached from cms. otherwise it should be NULL and the signed data must be in cms itself. no cap, pick one.
  • out β€” the content gets written to this BIO unless it's NULL.
  • flags β€” an optional set of flags to modify the operation. we'll get to those, bestie, don't worry. 🌈

CMS_SignedData_verify() β€” the upgraded one

CMS_SignedData_verify() is like CMS_verify() except:

  • it operates on CMS SignedData input in the sd argument,
  • it has some additional parameters (described next πŸ‘‡),
  • and on success it returns the verified content as a memory BIO. slay.

the extra deets:

  • extra β€” optional. provides untrusted CA certificates that might help with chain building in certificate validation. ⚠️ this list of certificates must not contain duplicates. the way that duplicates will ruin you… don't.
  • crls β€” optional. provides extra CRLs. also ⚠️ this list of CRLs must not contain duplicates. same energy.
  • libctx and propq β€” optional library context and property query, used when retrieving algorithms from providers. providers stay provider-ing. ✨

CMS_get0_signers() β€” the reveal

CMS_get0_signers() retrieves the signing certificate(s) from cms. but bestie, listen: it may only be called after a successful CMS_verify() or CMS_SignedData_verify() operation. calling it early is giving chaos. 🫠


πŸ” VERIFY PROCESS πŸ”

the default storyline

normally, the verify process proceeds like this. (put your phone down, this part matters.)

  1. initially, some sanity checks are performed on cms. the type of cms must be SignedData. there must be at least one signature on the data, and if the content is detached then detached_data cannot be NULL. no exceptions, periodt.
  2. an attempt is made to locate all the signing certificate(s), first looking in the certs parameter (if it's not NULL) and then looking in any certificates contained in the cms structure β€” unless CMS_NOINTERN is set. if any signing certificate cannot be located, the operation fails. πŸ’€
  3. each signing certificate is chain verified using the smimesign purpose and using the trusted certificate store store if supplied. any internal certificates in the message β€” which may have been added using CMS_add1_cert(3) β€” are used as untrusted CAs. if CRL checking is enabled in store and CMS_NOCRL is not set, any internal CRLs β€” which may have been added using CMS_add1_crl(3) β€” are used in addition to attempting to look them up in store. if store is not NULL and any chain verify fails, an error code is returned.
  4. finally, the signed content is read (and written to out unless it's NULL) and the signature is checked. ✨

if all signatures verify correctly, the function is successful. that's the win. πŸŽ‰

the flags (ored together, iconic behaviour)

any of the following flags can be passed in the flags parameter to change the default verify behaviour. they get ored together, because of course they do.

  • CMS_NOINTERN β€” the certificates in the message itself are not searched when locating the signing certificate(s). meaning: all the signing certificates must be in the certs parameter. no shortcuts. 🚫
  • CMS_NOCRL β€” if set, and CRL checking is enabled in store, then any CRLs in the message itself and any provided via the crls parameter are ignored. bye. πŸ‘‹
  • CMS_TEXT β€” MIME headers for type "text/plain" are deleted from the content. if the content is not of type "text/plain", an error is returned. picky, but valid. πŸ’…
  • CMS_NO_SIGNER_CERT_VERIFY β€” the signing certificates are not chain verified… unless CMS_CADES is also set. plot twist.
  • CMS_NO_ATTR_VERIFY β€” the signed attributes signature is not verified… unless CMS_CADES is also set. again.
  • CMS_CADES β€” each signer certificate is checked against the ESS signingCertificate or ESS signingCertificateV2 extension that is required in the signed attributes of the signature. mandatory behaviour, no skips. πŸ”₯
  • CMS_NO_CONTENT_VERIFY β€” the content digest is not checked. yeah. we'll talk about that in NOTES. 😭

πŸ“ NOTES πŸ“

one application of CMS_NOINTERN is to only accept messages signed by a small number of certificates. the acceptable certificates would be passed in the certs parameter. in that case, if the signer certificate is not one of the certificates supplied in certs, the verify will fail β€” because the signer cannot be found. that's the whole point, bestie. πŸ’–

in some cases the standard techniques for looking up and validating certificates are just… not appropriate? like, an application may wish to look up certificates in a database, or perform customised verification. you can achieve that by setting and verifying the signer certificates manually, using the signed data utility functions. do it yourself, main character energy. πŸ‘‘

⚠️ care should be taken when modifying the default verify behaviour. for example, setting CMS_NO_CONTENT_VERIFY will totally disable all content verification, and any modified content will be considered valid. that's giving "yikes". this combination is however useful if one merely wishes to write the content to out and its validity is not considered important. know what you're doing, fr fr.

chain verification should arguably be performed using the signing time rather than the current time. however, since the signing time is supplied by the signer, it cannot be trusted without additional evidence (such as a trusted timestamp). shrug. πŸ¦‹


πŸŽ€ RETURN VALUES πŸŽ€

  • CMS_verify() β€” returns 1 for a successful verification, and 0 if an error occurred. binary, simple, we love her.
  • CMS_SignedData_verify() β€” returns a memory BIO containing the verified content, or NULL on error.
  • CMS_get0_signers() β€” returns all signers, or NULL if an error occurred.

the error can be obtained from ERR_get_error(3). go get your error, bestie, it's yours. 🌸


πŸ’€ BUGS πŸ’€

  • the trusted certificate store is not searched for the signing certificate. this is primarily due to the inadequacies of the current X509_STORE functionality. not our fault, we're just reporting. πŸ™ˆ
  • the lack of single pass processing means that the signed content must all be held in memory if it is not detached. all of it. in memory. good luck. 😭

πŸ‘€ SEE ALSO πŸ‘€

PKCS7_verify(3), CMS_add1_cert(3), CMS_add1_crl(3), OSSL_ESS_check_signing_certs(3), ERR_get_error(3), CMS_sign(3)


⭐ HISTORY ⭐

CMS_SignedData_verify() was added in OpenSSL 3.2. newer than you think, but she ate. ✨


Copyright 2008-2024 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, you're officially educated. πŸ’… this was OpenSSL 3.5.9, dated 2026-09-29, and honestly? iconic. go verify something. mwah. πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from