Python bindings for the underskrift PDF signing and verification library
Project description
pyunderskrift
Python bindings for the underskrift PDF signing and verification library.
Features
- PDF signing with PKCS#12 software signers (PAdES and PKCS#7 sub-filters)
- Signature verification with configurable trust stores and policies
- Three-phase remote signing for HSM / cloud signing workflows
- Signature extraction without verification
- Trust store management for signature, timestamp, and SVT certificate authorities
- Algorithm registry to control permitted cryptographic algorithms
- Policy evaluation with basic and PKIX-based signature validation policies
- GIL released during all signing, verification, and extraction operations
Installation
python3 -m pip install pyunderskrift
Requires Python >= 3.10.
Quick start
Sign a PDF
from pyunderskrift import PdfSigner, SoftwareSigner, SigningOptions, SubFilter
signer = SoftwareSigner.from_pkcs12_file("signer.p12", "password")
options = SigningOptions(
sub_filter=SubFilter.Pades,
field_name="Signature1",
reason="Approved",
location="Stockholm",
)
pdf_data = open("document.pdf", "rb").read()
pdf_signer = PdfSigner(options)
signed_pdf = pdf_signer.sign(pdf_data, signer)
with open("signed.pdf", "wb") as f:
f.write(signed_pdf)
Verify signatures
from pyunderskrift import (
SignatureVerifier,
TrustStore,
TrustStoreSet,
SignatureStatus,
)
# Build trust stores
sig_store = TrustStore.from_pem_directory("./trust/sig")
tsa_store = TrustStore.from_pem_directory("./trust/tsa")
stores = TrustStoreSet()
stores.set_sig_store(sig_store)
stores.set_tsa_store(tsa_store)
# Verify
verifier = SignatureVerifier(stores)
pdf_data = open("signed.pdf", "rb").read()
report = verifier.verify_pdf(pdf_data)
for sig in report.signatures:
print(f"{sig.field_name}: {sig.status} - {sig.summary}")
print(f"All valid: {report.all_valid()}")
print(f"Document modified: {report.document_modified}")
Extract signatures (no verification)
from pyunderskrift import extract_signatures
pdf_data = open("signed.pdf", "rb").read()
for sig in extract_signatures(pdf_data):
print(f" Field: {sig.field_name}")
print(f" Type: {sig.signature_type.kind}")
print(f" Signer: {sig.signer_name}")
print(f" Time: {sig.signing_time}")
Three-phase remote signing
from pyunderskrift import (
RemoteSignerInfo,
RemoteSigningOptions,
DigestAlgorithm,
SignatureAlgorithm,
SubFilter,
prepare_signature,
finalize_signature,
)
# Phase 1: Prepare (caller provides signer certificate info)
signer_info = RemoteSignerInfo(
certificate_der=cert_der_bytes,
chain_der=[intermediate_der],
digest_algorithm=DigestAlgorithm.Sha256,
signature_algorithm=SignatureAlgorithm.RsaPkcs1v15,
)
options = RemoteSigningOptions(sub_filter=SubFilter.Pades)
prepared = prepare_signature(pdf_data, signer_info, options)
# Phase 2: Sign the hash remotely (e.g. via HSM API)
signature_bytes = remote_hsm_sign(prepared.attrs_hash)
# Phase 3: Finalize
signed_pdf = finalize_signature(prepared, signature_bytes)
Validation policies
from pyunderskrift import (
BasicPdfSignaturePolicy,
PkixPdfSignaturePolicy,
SignatureVerifier,
TrustStoreSet,
PolicyConclusion,
)
# Basic policy: integrity + crypto + trust + no modifications
basic = BasicPdfSignaturePolicy(require_no_modifications=True)
# PKIX policy: adds revocation checks, grace periods, timestamp validation
pkix = PkixPdfSignaturePolicy(
grace_period_secs=86400,
require_revocation_check=True,
require_no_modifications=True,
use_timestamp_time=True,
)
stores = TrustStoreSet()
# ... configure stores ...
verifier = SignatureVerifier(stores)
verifier.set_pkix_policy(pkix)
report = verifier.verify_pdf(pdf_data)
for sig in report.signatures:
if sig.policy_result is not None:
if sig.policy_result.conclusion == PolicyConclusion.Passed:
print(f"{sig.field_name}: policy PASSED")
else:
print(f"{sig.field_name}: {sig.policy_result.message}")
for check in sig.policy_result.checks:
if not check.passed:
print(f" FAIL: {check.check_name} - {check.message}")
API overview
The full API is documented in the type stub. Key types:
Enums
SignatureStatus, DetectedPadesLevel, PadesLevel, SubFilter,
StoreKind, PolicyConclusion, DigestAlgorithm, SignatureAlgorithm,
SigningTimePlacement, RevocationSource, RevocationReason
Struct-based enums
CryptoValidity, CertValidity, SignatureType, ValidationStatus --
each has a .kind string property and optional variant-specific properties.
Trust
TrustStore, TrustStoreSet
Verification
SignatureVerifier, VerificationReport, SignatureVerificationResult
Policy
BasicPdfSignaturePolicy, PkixPdfSignaturePolicy, PolicyResult,
PolicyCheckResult
Signing
PdfSigner, SigningOptions, SoftwareSigner, AlgorithmRegistry
Extraction
ExtractedSignature, extract_signatures()
Remote signing
RemoteSignerInfo, RemoteSigningOptions, PreparedSignature,
prepare_signature(), finalize_signature()
Building from source
Requires Rust (stable) and Python >= 3.10.
git clone https://github.com/kushaldas/pyunderskrift.git
cd pyunderskrift
uv venv
source .venv/bin/activate
uv pip install maturin pytest
maturin develop
pytest tests/ -vvv
To generate test fixtures (requires OpenSSL):
cd tests/fixtures
bash ../../gen-test-fixtures.sh
License
BSD-2-Clause
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyunderskrift-0.1.0.tar.gz.
File metadata
- Download URL: pyunderskrift-0.1.0.tar.gz
- Upload date:
- Size: 44.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57aa348737e3e316ca61eaf27f63823e7d0a1646bd4ce57495066c3f19a406f2
|
|
| MD5 |
a27f4074c7d5f4a9cf5c0cddf5180222
|
|
| BLAKE2b-256 |
bdd420222de91167cec8200f82f2ee710ef14a732844fcebdece1927668e86e7
|
Provenance
The following attestation bundles were made for pyunderskrift-0.1.0.tar.gz:
Publisher:
release.yml on kushaldas/pyunderskrift
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyunderskrift-0.1.0.tar.gz -
Subject digest:
57aa348737e3e316ca61eaf27f63823e7d0a1646bd4ce57495066c3f19a406f2 - Sigstore transparency entry: 1065917947
- Sigstore integration time:
-
Permalink:
kushaldas/pyunderskrift@59597b5ee1f4878c2e8e3547cbdebf45dc543e1b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@59597b5ee1f4878c2e8e3547cbdebf45dc543e1b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyunderskrift-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyunderskrift-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76ce78ca08089e6992150d3f5aace21444af9fdf0de099978f31b6ccc0f86a23
|
|
| MD5 |
3293db385dd393c3fb464a5bd077548f
|
|
| BLAKE2b-256 |
1e10b8821fee50601ff95c047bf54a77dee5ce85524e1e79f4891710c1f0ca8f
|
Provenance
The following attestation bundles were made for pyunderskrift-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on kushaldas/pyunderskrift
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyunderskrift-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
76ce78ca08089e6992150d3f5aace21444af9fdf0de099978f31b6ccc0f86a23 - Sigstore transparency entry: 1065917951
- Sigstore integration time:
-
Permalink:
kushaldas/pyunderskrift@59597b5ee1f4878c2e8e3547cbdebf45dc543e1b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kushaldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@59597b5ee1f4878c2e8e3547cbdebf45dc543e1b -
Trigger Event:
workflow_dispatch
-
Statement type: