Validate PDF signatures
Signature validation tells you whether a signed PDF is trustworthy: whether the signed content is unchanged since signing, and whether the signer’s certificate chains to a certificate you trust and wasn’t revoked when the document was signed. Nutrient Python SDK validates each signature as defined by ETSI EN 319 102-1, the European standard for signature validation, and reports one of its three results: passed, failed, or indeterminate. This guide shows how to validate the signatures of a PDF against a trusted root certificate and how to read the results.
Common use cases include:
- Checking signed contracts and invoices before processing them
- Rejecting documents that changed after they were signed
- Accepting only signatures from certification authorities your organization trusts
How Nutrient helps
Nutrient Python SDK validates every signature of a document with one method call. For each signature, the SDK:
- Checks that the signed bytes match the signature
- Builds the signer’s certificate chain to one of the certificates you trust
- Checks the revocation status of each certificate in the chain, from the certificate revocation lists (CRLs) and Online Certificate Status Protocol (OCSP) responses the document embeds, or from the network
- Validates the signature timestamp, when the signature has one
- Validates document timestamps (PAdES B-LTA)
Preparing the project
Import Nutrient Python SDK:
from nutrient_sdk import Document, Signature, NutrientExceptionfrom nutrient_sdk import DigitalSignatureOptionsfrom nutrient_sdk import SignatureValidationOptions, SignatureRevocationModefrom nutrient_sdk import SignatureValidationIndication, SignatureValidationSubIndicationSigning a sample PDF
The sample signs input.pdf first, so it has a signed document to validate. The sample certificate, certificate.pfx, is issued by the sample root certificate authority, root_ca_cert.pem. For more information on signing, refer to the PAdES baseline levels guide:
def main(): try: with Signature() as signer: with Document.open("input.pdf") as document: options = DigitalSignatureOptions() options.certificate_path = "certificate.pfx" options.certificate_password = "Nutrient answers all your document needs" options.signer_name = "Legal Department" options.reason = "Contract approval" signer.sign(document, "signed.pdf", options)Configuring the validation
A signature passes validation only when the signer’s certificate chains to a certificate you trust. No certificate is trusted by default. Add the root certificates of the certification authorities you accept with add_trusted_certificate, which takes the certificate as bytes: a DER-encoded certificate, a PKCS#7 certificate bundle, or PEM text with one or more certificates:
validation_options = SignatureValidationOptions() with open("root_ca_cert.pem", "rb") as root_file: validation_options.add_trusted_certificate(root_file.read())
# The sample certificate authority publishes no revocation data. validation_options.revocation_mode = SignatureRevocationMode.NONEThe revocation_mode property sets where the revocation status of the certificates comes from:
EMBEDDED_ONLY— Only the CRLs and OCSP responses the document embeds. No network access. This is the default.ONLINE_IF_MISSING— The embedded data first, then the certificate’s OCSP responder or CRL distribution points for each certificate the embedded data doesn’t cover.ALWAYS_ONLINE— The certificate’s OCSP responder or CRL distribution points for every certificate, together with the embedded data.NONE— Revocation isn’t checked.
The sample uses NONE because its certificate authority publishes no revocation data: with any other mode, its signature is reported as INDETERMINATE with CERTIFICATE_CHAIN_GENERAL_FAILURE. For certificates from a public certification authority, keep the default for documents signed at PAdES B-LT or higher, which embed their revocation data. Use ONLINE_IF_MISSING for other documents.
The options also include the following settings:
validation_time— The time to validate the signatures at, as an ISO 8601 string such as"2026-01-31T12:00:00Z". The default is the current time.network_timeout— The time one network request takes at most, in milliseconds. The default is 30000.add_intermediate_certificate— Adds certificates that complete a chain between the signer and a trusted certificate when neither the document nor the signature includes them.
Validating the signatures
Open the signed document and pass it to validate, which returns one result per signed signature field. The sample prints each result and writes a short report:
with Document.open("signed.pdf") as signed_document: results = signer.validate(signed_document, validation_options)
report = [] for result in results: indication = SignatureValidationIndication(result.indication) sub_indication = SignatureValidationSubIndication(result.sub_indication) print(f"{result.field_name}: {indication.name} {sub_indication.name}") print(f" Unchanged since signing: {result.is_integrity_valid}") print(f" Certificate chain: {len(result.certificate_chain)} certificates") print(f" Signer certificate: {len(result.signer_certificate)} bytes") if indication != SignatureValidationIndication.TOTAL_PASSED: print(f" Reason: {result.message}") report.append(f"{result.field_name}: {indication.name} {sub_indication.name}")
with open("validation-report.txt", "w", encoding="utf-8") as report_file: report_file.write("\n".join(report) + "\n") except NutrientException as e: print(f"Error: {e}")
if __name__ == "__main__": main()The sample signature chains to the trusted root, so the sample prints TOTAL_PASSED NONE. The indication and sub_indication properties return the enumeration values as integers; the sample converts them to SignatureValidationIndication and SignatureValidationSubIndication members.
Each result has the following properties:
field_name— The name of the signature field.indicationandsub_indication— The result of the validation, and the reason when it didn’t pass.message— A description of the problem found. Empty when the validation passed.is_integrity_valid— Whether the signed bytes match the signature.covers_whole_document— Whether the signature covers the whole document. It’sFalsewhen content was added after signing, for example a later signature or the validation data of a PAdES B-LT signature.signer_certificate— The DER-encoded certificate of the signer, asbytes.certificate_chain— The signer’s certificate, its issuers, and the trusted certificate, each with itscertificate,is_trust_anchor,revocation_status,revocation_source, andrevocation_time.timestamp— The validation of the signature timestamp, orNonewhen the signature has no timestamp.best_signature_time— The earliest time the signature is proven to exist, as an ISO 8601 string in UTC: the time of a valid signature timestamp, otherwise the validation time.is_document_timestamp— Whether the result is for a document timestamp rather than a signature.
Reading the results
The indication property reports one of three results:
| Indication | Meaning |
|---|---|
TOTAL_PASSED | The signature is intact, and the signer’s certificate chains to a trusted certificate and wasn’t revoked at the time the signature is proven to exist. |
TOTAL_FAILED | The signature is invalid. For example, HASH_FAILURE means the document changed after signing. |
INDETERMINATE | The available data doesn’t establish whether the signature is valid. The sub-indication tells you what’s missing. |
The most common sub-indications for an INDETERMINATE result are:
NO_CERTIFICATE_CHAIN_FOUND— No chain leads from the signer’s certificate to a trusted certificate. Add the root certificate of the signer’s certification authority.CERTIFICATE_CHAIN_GENERAL_FAILURE— No usable revocation data covers a certificate of the chain. UseONLINE_IF_MISSING, or ask the signer for a PAdES B-LT signature.OUT_OF_BOUNDS_NO_POE— The signer’s certificate expired, and no signature timestamp proves the signature existed before then.REVOKED_NO_POE— The signer’s certificate was revoked, and no signature timestamp proves the signature existed before the revocation.
Error handling
Nutrient Python SDK handles errors with exception handling. validate reports an invalid signature in its result, not as an exception. It raises a NutrientException when the validation fails to run — for example, when the document isn’t a PDF or when an option is invalid. add_trusted_certificate raises a NutrientException when the data holds no certificate.
Limitations
- Only the certificates you add are trusted. The system certificate store and the European Union Trusted List (EUTL) aren’t used.
- A document timestamp is validated, but it isn’t used as proof that the signatures it covers existed before it.
- The validation reads the bytes the document was opened from. Edits made to the document in memory aren’t validated.
Conclusion
Use this workflow to validate the signatures of a PDF:
- Create
SignatureValidationOptionsand add the root certificates you trust withadd_trusted_certificate. - Set
revocation_modeto match where the revocation data of your documents comes from. - Open the document using a context manager(opens in a new tab) and call
validateon aSignatureinstance. - Accept a signature only when its
indicationisTOTAL_PASSED, and use the sub-indication and message to diagnose the others.
For related signing workflows, refer to the Python SDK guides.