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
Metadata
Release files for pyunderskrift 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyunderskrift-0.1.4.tar.gz | 50.1 kB | With provenance | Details for pyunderskrift-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyunderskrift-0.1.4-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for pyunderskrift-0.1.4-cp310-abi3-manylinux_2_28_x86_64.whl |
Total release size: 4.1 MB
Release files / pyunderskrift-0.1.4.tar.gz
| Download URL | pyunderskrift-0.1.4.tar.gz |
|---|---|
| Size | 50.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ef7d04dfcdbe9342c176208411b840e7ac433e50ac8e04d378689bbe27e88ae
|
|
BLAKE2b-256 checksum How to use checksums |
49e5d23a5d3c1f9e7c161127fa67a2ad01e24802e79a7ce6a8e35c2c17c28159
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.
Transparency logRelease files / pyunderskrift-0.1.4-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | pyunderskrift-0.1.4-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5ee188989d1be38784c62b00d5f928629a6257510012217092511c403ede1927
|
|
BLAKE2b-256 checksum How to use checksums |
76cbe140b47040626313bdd493eee153a3cfb482038789d1b4dc3ef47ebd428b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.
Transparency logSecurity for pyunderskrift 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyunderskrift-0.1.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.