PKCS7_VERIFY(3SSL)

πŸ“¦
version 4.0.3 Β· 2 versions
, in ubuntu stonking

πŸ’– PKCS7_VERIFY πŸ’–

okay bestie, gather round, because today we're talking about PKCS7_verify β€” that's the manual page from the OpenSSL fam, section 3SSL, and it's literally the girlboss of PKCS#7 signedData verification. no cap.


✨ NAME ✨

PKCS7_verify, PKCS7_dataVerify, PKCS7_get0_signers β€” verify a PKCS#7 signedData structure. that's the whole vibe check 🫢


🌸 SYNOPSIS 🌸

#include <openssl/pkcs7.h>

int PKCS7_verify(PKCS7 *p7, const STACK_OF(X509) *certs, X509_STORE *store,
                 BIO *indata, BIO *out, int flags);

int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
                 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);

STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, const STACK_OF(X509) *certs,
                                   int flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so PKCS7_verify() is very similar to CMS_verify(3) β€” like, sisters, same energy. it verifies a PKCS#7 signedData structure handed to it in p7. πŸ“¬

the optional certs parameter? it's a set of certificates where we go looking for the signer's certificates. it also doubles as a source of untrusted intermediate CA certificates for chain building. iconic multi-purpose behavior, we love her. πŸ’…

so p7 itself may contain extra untrusted CA certificates that can be used for chain building, plus CRLs that may be used for certificate validation. store can be NULL, or it can point to the trusted certificate store you wanna use for chain verification. indata refers to the signed data if the content is detached from p7. if it's not detached, then indata should be NULL, because then the signed data must just be chillin' inside p7 itself. the content gets written to the BIO out β€” unless out is NULL, in which case, no writing, we simply do not. and flags is an optional set of flags that modifies the operation. πŸŽ€

PKCS7_get0_signers() retrieves the signer certificates from p7. she does not check their validity, and she does not check whether any signatures are valid β€” she's just here to grab the signers, bestie. the certs and flags parameters mean the same thing as they do in PKCS7_verify(). πŸ’–

PKCS7_dataVerify() operates in a similar fashion to PKCS7_verify, but with a few notable exceptions, and we're gonna be so real about them:

  • PKCS7_dataVerify does not support the passing of the flags parameter. no flags for her, she said no. πŸ™…
  • PKCS7_dataVerify obtains its signer info from the passed-in signer data via the si parameter, rather than parsing the signers from the PKCS7 object directly. different pathway, same destination.

PKCS7_dataVerify() is available for backwards compatibility with older versions of OpenSSL, but ngl, it's generally recommended that users use the PKCS7_verify() API instead, because it offers greater flexibility in the verification process. PKCS7_verify is the main character here fr fr. πŸ‘‘


πŸ”₯ VERIFY PROCESS πŸ”₯

normally, the verify process proceeds like this. buckle up, it's a whole journey. ✨

first, some sanity checks are performed on p7. the type of p7 must be SignedData. there must be at least one signature on the data, and if the content is detached, then indata cannot be NULL. πŸ“Œ

now if the content is not detached and indata is not NULL, then the structure has both embedded and external content. if you wanna treat that as an error, use the flag PKCS7_NO_DUAL_CONTENT. the default behavior allows this though, for compatibility with older versions of OpenSSL. (the messy old days, we don't judge. much. πŸ’€)

an attempt is made to locate all the signer's certificates β€” first looking in the certs parameter (if it's not NULL). then they're looked up in any certificates contained in the p7 structure, unless PKCS7_NOINTERN is set. if any signer's certificates cannot be located, the operation fails. periodt.

each signer's 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 PKCS7_add_certificate(3) β€” are used as untrusted CAs unless PKCS7_NOCHAIN is set. if CRL checking is enabled in store and PKCS7_NOCRL is not set, any internal CRLs β€” which may have been added using PKCS7_add_crl(3) β€” are used in addition to attempting to look them up in store. and if store is not NULL and any chain verify fails, an error code is returned. 🚨

finally, the signed content is read (and written to out unless it's NULL) and the signature is checked. πŸ•΅οΈ

if all signatures verify correctly, then the function is successful. slay. πŸ’…


any of the following flags (ored together) can be passed in the flags parameter to change the default verify behaviour. heads up: only the flag PKCS7_NOINTERN is meaningful to PKCS7_get0_signers(). everyone else, sit down. πŸ™ˆ

  • PKCS7_NOINTERN β€” if set, the certificates in the message itself are not searched when locating the signer's certificates. meaning all the signer's certificates must be in the certs parameter. no backup plan, no searching the couch cushions.
  • PKCS7_NOCRL β€” if set, and CRL checking is enabled in store, then any CRLs in the message itself are ignored. bye bestie πŸ‘‹
  • PKCS7_TEXT β€” if set, MIME headers for type "text/plain" are deleted from the content. but if the content is not of type "text/plain", then an error is returned. read the room, content.
  • PKCS7_NOVERIFY β€” if set, the signer's certificates are not chain verified. zero verification energy.
  • PKCS7_NOCHAIN β€” if set, then the certificates contained in the message are not used as untrusted CAs. this means the whole verify chain (apart from the signer's certificates) must be contained in the trusted store. no shortcuts, no vibes-based trust.
  • PKCS7_NOSIGS β€” if set, then the signatures on the data are not checked. we simply look away. 🫣

πŸ’œ NOTES πŸ’œ

one application of PKCS7_NOINTERN is to only accept messages signed by a small number of certificates. the acceptable certificates would be passed in the certs parameter. in this case, if the signer's certificate is not one of the certificates supplied in certs, then the verify will fail, because the signer cannot be found. it's giving ✨ exclusive guest list ✨.

care should be taken when modifying the default verify behaviour, bestie, seriously. for example, setting "PKCS7_NOVERIFY|PKCS7_NOSIGS" will totally disable all verification and any signed message will be considered valid. like, ANY of them. that combination is however useful if one merely wishes to write the content to out and its validity is not considered important. so like, you do you, but know what you're doing πŸ’€.

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). sad but true, the signer is not a reliable narrator. 😭


🌈 RETURN VALUES 🌈

  • PKCS7_verify() and PKCS7_dataVerify() return 1 for a successful verification and 0 if an error occurs.
  • PKCS7_get0_signers() returns all signers, or NULL if an error occurred.
  • the error can be obtained from ERR_get_error(3). πŸ•΅οΈ

πŸŽ€ BUGS πŸŽ€

  • the trusted certificate store is not searched for the signer's certificates. this is primarily due to the inadequacies of the current X509_STORE functionality. we said what we said. πŸ™ˆ
  • the lack of single pass processing means that the signed content must all be held in memory if it is not detached. every last byte. in RAM. yeah. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

CMS_verify(3), PKCS7_add_certificate(3), PKCS7_add_crl(3), ERR_get_error(3), PKCS7_sign(3)


Copyright 2002-2026 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>.


and that's the whole page, bestie!! πŸ¦‹ version 4.0.3, dated 2026-09-29, and it's the PKCS7_VERIFY(3SSL) page from the OpenSSL crew. go forth and verify responsibly, and do NOT set PKCS7_NOVERIFY|PKCS7_NOSIGS unless you truly mean it πŸ’…βœ¨

πŸ“¦ where this page comes from