Download the PHP package tecnickcom/tc-lib-pdf-sign without Composer

On this page you can find all versions of the php package tecnickcom/tc-lib-pdf-sign. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tc-lib-pdf-sign

tc-lib-pdf-sign

Digital signature primitives for PDF documents (PKCS#7, CAdES, PAdES).

Latest Stable Version Build Coverage License Downloads

Sponsor on GitHub

💖 Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance →


Overview

tc-lib-pdf-sign provides the cryptographic building blocks and PDF signature objects used by tc-lib-pdf to produce signed PDF documents. The crypto and the PDF object generation live here, while the host library keeps the ByteRange placement, the incremental update writer, and the public facade.

The package assembles CMS/CAdES signatures natively in pure PHP (via a small DER ASN.1 codec), so it can embed the ESS signing-certificate-v2 attribute that openssl_pkcs7_sign() cannot add. This is what lifts a plain PKCS#7 signature to a PAdES baseline signature.

Namespace \Com\Tecnick\Pdf\Sign
Author Nicola Asuni [email protected]
License GNU LGPL v3 - see LICENSE
API docs https://tcpdf.org/docs/srcdoc/tc-lib-pdf-sign
Packagist https://packagist.org/packages/tecnickcom/tc-lib-pdf-sign

Features

Signature profiles (each level builds on the previous one):

Profile /SubFilter What it provides
Legacy adbe.pkcs7.detached ISO 32000-1 detached CMS, carrying the ESS signing-certificate-v2 attribute.
PAdES B-B ETSI.CAdES.detached CAdES-based CMS with content-type, message-digest, and signing-certificate-v2 signed attributes.
PAdES B-T ETSI.CAdES.detached B-B plus an RFC 3161 signature timestamp embedded as the id-aa-signatureTimeStampToken unsigned attribute.
PAdES B-LT ETSI.CAdES.detached B-T plus a Document Security Store (/DSS, /VRI) with certificate, OCSP, and CRL validation material.
PAdES B-LTA ETSI.CAdES.detached + ETSI.RFC3161 B-LT plus a /Type /DocTimeStamp archive timestamp for long-term archival.

Components

Component Responsibility
Config Immutable signature configuration (profile, digest algorithm, certification level) with /SubFilter derivation.
SignatureProfile Backed enum of the supported profiles, the closed set Config validates against.
DigestAlgorithm Backed enum of the supported digests, with their lengths and NIST OIDs.
Signer Orchestration entry point: builds the detached CAdES CMS and collects the LTV material, tying the pieces below together.
Cms\Builder Native detached CAdES-BES SignedData builder (signs the DER signed attributes with openssl_sign()), in one call or in two.
Cms\SigningRequest Validated, immutable inputs for the signed attributes; the state that crosses a two-phase signature.
Cms\SignatureEncoding Encoding of an externally produced signature: DER, or the fixed-width ECDSA form (IEEE P1363).
Cms\Asn1 Minimal DER ASN.1 encoder/decoder for CMS, RFC 3161, and OCSP structures.
Cms\Oid The CMS content type and signed attribute type OIDs this library emits and reads.
Cms\Certificate X.509 field reader for the issuer, subject, serial, and public key that CMS and OCSP quote verbatim.
Cms\SignatureVerifier Verifies a signature over a signed body against the certificate that produced it.
Cms\SignedDataVerifier Verifies a CMS SignedData, whether it carries its own content, as a timestamp token does, or is detached over content the caller supplies.
Timestamp\Client / Timestamp\Config RFC 3161 timestamp codec; the returned token is verified and matched against the request.
Ocsp\Client RFC 6960 OCSP request builder and response validator.
Ltv\ValidationMaterial DSS material collection: certificate dedup, AIA/CRL-DP URL extraction, OCSP/CRL retrieval.
Ltv\Crl RFC 5280 CRL reader: issuer match, scope, validity interval, revocation entries, and signature.
Ltv\SkipReason Why a revocation URL was discarded: revoked, invalid, unreachable, duplicate, not attempted.
Output\Signature The /Sig value dictionary, including the /ByteRange and /Contents placeholders.
Output\Widget Signature and empty-field widget annotations.
Output\Dss DSS/VRI object emitter.
Output\DocTimeStamp The /Type /DocTimeStamp value object (B-LTA).
Output\PdfString Shared PDF string-token encoder.
Exception Library exception type.
RevokedException Raised when a responder or a CRL states that a certificate is revoked.

Design

The codecs are pure and perform no file or network access. HTTP transports (TSA, OCSP, CRL) and key loading are injected by the host as callables, so the consuming application owns networking and SSRF protection.

Nothing a TSA, an OCSP responder, or a CRL distribution point returns becomes validation material until its signature has been checked:

Anything that fails is rejected here rather than embedded in the document. The number of URLs taken from one certificate extension is bounded at Ltv\ValidationMaterial::MAX_URLS, each one being a call to the host's transport; the excess is reported rather than dropped. Revocation collection is best-effort, so a rejection is a skip rather than an error: Signer::collectValidationMaterial() takes an $onSkip observer that receives every discarded URL with the reason and an Ltv\SkipReason, which separates a revoked verdict from a timeout:

The digest and signature algorithms accepted for validation material are SHA-256 and above. SHA-1 is refused; a host that has to accept one from a legacy responder passes allowSha1: true to Cms\SignatureVerifier or Cms\SignedDataVerifier and injects it.

RSA signatures are PKCS#1 v1.5 throughout, identified by rsaEncryption as RFC 3370 section 3.2 defines it for CMS and read back under either that identifier or the sha*WithRSAEncryption form. RSASSA-PSS is not supported, in either direction: openssl_sign() cannot produce it and openssl_verify() cannot express its parameters, so a PSS-signing key cannot sign through this library, and a PSS-signed timestamp token, OCSP response, or CRL is refused as an unsupported signature algorithm.

Some checks stay with the host. The library does not decide whether a certificate is trusted, and by default it does not refuse to sign with one that has expired or whose key usage forbids signing, since a host may deliberately re-sign historical content. Cms\Certificate::assertValidAt() and Cms\Certificate::assertUsableForSigning() run those checks on demand, and new Signer(checkSignerCertificate: true) runs both on every sign() and prepare().

Timestamp\Config carries host, timeout, verifyPeer, username, password, and cert for the host to apply to its own HTTP client. This library never reads them, opening no connection.


Requirements


Installation

This package is normally pulled in transitively by tc-lib-pdf; install it directly only when you need the low-level primitives on their own.


Usage

For signing PDF documents, use the tc-lib-pdf fluent signature() facade, which drives this package end to end:

See the full guide in tc-lib-pdf/doc/DIGITAL_SIGNATURES.md and the runnable E007/E008/E009/E081 signature examples in tc-lib-pdf.

Low-level: building a detached CMS

Cms\Builder produces a detached CAdES-BES CMS over arbitrary bytes (the host supplies the ByteRange-covered content). It is the core of PAdES B-B:

Low-level: two-phase signing

sign() needs the private key and the content in this process. When either is unavailable, the same call is available in two halves. signaturePayload() returns the DER SET OF signed attributes that the signature has to cover, and buildFromSignature() turns those plus the signature into the CMS.

This covers a key held in a hardware token, a smart card, or a remote signing service, and a document too large to hold as a string, since the request carries the message digest rather than the content:

Signer exposes the same three steps (prepare(), signaturePayload(), buildFromSignature()), so a host driving a remote signer can complete the flow through that class alone while getting the profile rules applied.

buildFromSignature() verifies the signature against the signing certificate before it emits anything, so a signature over the wrong bytes, from the wrong key, or in the wrong encoding fails at the call. Cms\SignedDataVerifier::verify() reads a finished CMS back, given the content a detached signature covers:

Omit the content and the message has to carry its own, which is the shape of an RFC 3161 timestamp token; supply it and the message must carry none, because a message with content of its own is not the message being checked. An ECDSA signature returned as the fixed-width r || s concatenation is accepted by passing SignatureEncoding::P1363 as the last argument.

The request is immutable and validated on construction. When the two phases are separate HTTP requests, carry it across with toArray() and fromArray(), which validate again on the way back in.

Validation is not authentication. Re-running the constructor rejects a payload that is not a valid request, but not one edited into a different valid request. Pass a secret to both calls and the state carries an HMAC that is checked before anything else, or carry it over a channel the host already protects.

Signer::prepare() and Signer::buildFromSignature() are the same pair one level up, applying the profile rules: the signing-time attribute is omitted for PAdES, and a B-T or higher profile requires the timestamp client and transport.

Signer::collectValidationMaterial() takes the signer chain leaf-first, one certificate per entry as PEM or DER, and verifies that ordering by signature rather than by name. Taking the signature as the link is what lets an authority that re-issued its own certificate with a Name of the same value in another string type still be recognised as the issuer of the leaves it signed. A PEM entry holding more than one certificate, such as a fullchain.pem, is refused rather than decoded as a chain of one. Each entry is parsed as a certificate, and the armour has to say CERTIFICATE, since nearly everything a PEM file holds is a DER SEQUENCE.

The certificates a timestamp token embeds are ordered into a path starting at the certificate the token was verified against, not at a leaf picked out of the bag: the certificates field sits outside signedAttrs and is covered by no signature. A bag member outside the path is still collected, since a validator may need it, but nothing can be looked up for it, so its URLs are reported through $onSkip with SkipReason::NotAttempted.

Signer::signatureTimestampTokens() reads the tokens back out of a CMS. The token is produced inside sign(), by the provider the profile requires, and the host's transport sees the TimeStampResp rather than the token inside it, so this is how the output of sign() or buildFromSignature() feeds the collector:

Pass the signature timestamp tokens as the fourth argument: the certificates they embed are ordered into a path, by signature for the same reason, and run through the same OCSP and CRL lookups as the signer's own chain, which is what ETSI EN 319 142-1 requires of a B-LT Document Security Store. Members of the token's certificate bag that do not chain are collected as certificates but not looked up, there being no issuer to build a lookup against. Ordering the bag costs a signature check per pair of members, so one larger than Signer::MAX_PATH_CERTIFICATES is refused rather than ordered.

Pass the signing time as the fifth argument so a retried or queued signature collects against the same instant it signs for. It is separate from the $timestampNow argument of sign() and buildFromSignature(), which is the moment the timestamp request is made and what the token's genTime is checked against.

Output\Dss::emit() returns a state entry alongside the objects. A DSS written by an incremental update replaces the one before it, so pass that state back on the next update (a second signature, or the B-LTA archive timestamp) and the earlier VRI entries are carried into the new dictionary instead of being dropped. Material an earlier revision already wrote is referenced again rather than written a second time.

A signed attribute a profile requires, such as the CAdES signature-policy-identifier, is passed to the request as an OID-keyed map. The attribute types the builder controls are reserved and cannot be overridden.


Standards


Development


Packaging

For system packages, bootstrap with:


Contributing

Contributions are welcome. Please review SECURITY.md.


All versions of tc-lib-pdf-sign with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-hash Version *
ext-json Version *
ext-openssl Version *
ext-pcre Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tecnickcom/tc-lib-pdf-sign contains the following files

Loading the files please wait ...