PKCS7_VERIFY(3ossl)
okay bestie π before we even start: this is the PKCS7_VERIFY page from the OpenSSL manual (3ossl), and it's literally all about verifying a PKCS#7 signedData structure. she's giving crypto-bureaucracy but she's also lowkey iconic. let's get into it π«Ά
πΈ NAME πΈ
PKCS7_verify, PKCS7_get0_signers β verify a PKCS#7 signedData structure. that's the whole vibe β¨
π SYNOPSIS π
#include <openssl/pkcs7.h>
int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
BIO *indata, BIO *out, int flags);
STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
π DESCRIPTION π
PKCS7_verify() is basically the twin sister of CMS_verify(3), fr fr. she verifies a PKCS#7 signedData structure, and that structure comes in through p7 π
the optional certs parameter is a set of certificates where she goes looking for the signer's certificates. it doubles as a source of untrusted intermediate CA certificates for chain building, because she's versatile like that πββοΈ. and p7 itself may contain extra untrusted CA certificates used for chain building, plus CRLs that may be used for certificate validation. multitasking queen.
store may be NULL, or it can point to the trusted certificate store you wanna use for chain verification. indata is where you put the signed data if the content is detached from p7. if the content is not detached, then indata should be NULL, and the signed data must live inside p7. the content gets written to the BIO out unless it's NULL. and flags is an optional set of flags you can use to modify the operation ποΈ
PKCS7_get0_signers() retrieves the signer's certificates from p7, and bestie, hear me: it does not check their validity, and it does not check whether any signatures are valid. it's strictly a getter, no vibes-checking included π. the certs and flags parameters mean the same thing as they do in PKCS7_verify().
π¦ VERIFY PROCESS π¦
normally the whole verify process goes like this:
first up, some sanity checks get 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, indata cannot be NULL β no exceptions π₯.
if the content is not detached and indata is not NULL, then the structure has both embedded and external content. to treat that as an error, use the flag PKCS7_NO_DUAL_CONTENT. the default behavior allows it, for compatibility with older versions of OpenSSL. so yeah, she's being lenient for the elders π
then she tries to locate all the signer's certificates β first looking in the certs parameter (if it's not NULL), and then looking them up in any certificates contained in the p7 structure, unless PKCS7_NOINTERN is set. if any signer's certificates can't be located, the operation fails. no certificate, no entry, periodt π
each signer's certificate gets chain verified using the smimesign purpose, and using the trusted certificate store store if one was 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, then 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, 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. only the flag PKCS7_NOINTERN is meaningful to PKCS7_get0_signers() btw:
PKCS7_NOINTERNβ the certificates inside the message itself are not searched when locating the signer's certificates. this means all the signer's certificates must be in thecertsparameter.PKCS7_NOCRLβ if CRL checking is enabled instore, then any CRLs in the message itself are ignored.PKCS7_TEXTβ MIME headers for type"text/plain"get deleted from the content. and if the content is not of type"text/plain"then an error is returned.PKCS7_NOVERIFYβ the signer's certificates are not chain verified.PKCS7_NOCHAINβ 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.PKCS7_NOSIGSβ the signatures on the data are not checked.
π 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 π΅οΈββοΈ
care should be taken when modifying the default verify behaviour, bestie. for example, setting"PKCS7_NOVERIFY|PKCS7_NOSIGS"will totally disable all verification and any signed message will be considered valid. like, literally any message. that combination is however useful if you merely wish to write the content tooutand its validity is not considered important. just 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). so it's a whole trust exercise situation π
π RETURN VALUES π
PKCS7_verify() returns 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. she's flawed, she knows π
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. no streaming, no shortcuts π§
π SEE ALSO π
CMS_verify(3), PKCS7_add_certificate(3), PKCS7_add_crl(3), ERR_get_error(3), PKCS7_sign(3) β go read these, iykyk π«Ά
β COPYRIGHT β
Copyright 2002-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>.
and that's the page, bestie π sign-off time: this is OpenSSL version 3.5.0, dated 2026-09-25, and she ate. go verify something and stay safe out there π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms