Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Pdf.Signer

Classes, interfaces and records

classePdfSignError

inherits from Exception

(no public members)

recordtPdfSignatureInfo

tPdfSignatureInfo - what ExtractPdfSignature(s) reports about one signature of a signed document; used by verification and the tests.

fByteRange: array [0..3] of Int64; fContents: OctetString;
the CMS DER, trailing padding stripped
fSubFilter: string; fFieldName: OctetString; fSignedBytes: OctetString;
the concatenated /ByteRange spans
fCoversWholeFile: Boolean;
ranges = everything except the /Contents hole
fGapIsContentsString: Boolean;
fGapIsContentsString is the signature-wrapping (SWA) defence: the gap between the two signed spans must be EXACTLY one PDF hex string - '<', hex digits/whitespace, '>' - i.e. the /Contents slot itself and nothing else. A crafted ByteRange that leaves unsigned document bytes in the gap fails this even though it may still "cover the whole file".
fDocMDPLevel: Integer;
fDocMDPLevel is the certification level from a DocMDP transform: 1 = no changes permitted, 2 = form fill-in and signing, 3 = also annotations. -1 when this is an ordinary (approval) signature.

recordtPdfValidationMaterial

tPdfValidationMaterial - the certificates and revocation data that a PAdES B-LT document embeds so the signature stays verifiable after the signer certificate expires or its responder disappears. Every entry is a raw DER blob: a Certificate, an OCSPResponse, or a CertificateList (CRL). Fill it with PdfAddCert / PdfAddOcsp / PdfAddCrl.

fCerts: array of OctetString; fOcsps: array of OctetString; fCrls: array of OctetString;

classTstPdfSigner — component reference

inherits from TComponent

TstPdfSigner

Drop-in signing component (the TstMPSignedData branch of the library). Assign KeysAndCerts, then call SignData/SignFile with the signer certificate (which must be resolvable to a private key by the manager, exactly as for TstMPSignedData.SignData). On True the destination holds the signed document; on False LastError says why.

constructor Create(aOwner: TComponent); override; function SignData(aCert: iCertificate; aSource, aDest: TStream): Boolean;
SignData reads the PDF from aSource, appends the signature increment and writes the complete signed document to aDest. » member page
function SignFile(aCert: iCertificate; const aSourceFile, aDestFile: string): Boolean; property LastError: string read fLastError;
LastError describes the failure when the most recent call returned False; it is empty otherwise. » member page
property KeysAndCerts: TstCertificateManager read fKeysAndCerts write SetKeysAndCerts;
The certificate/private-key store the CMS layer draws the signer key from (see TstMPSignedData.KeysAndCerts). » member page
property ContentDigestAlg: tHashAlgorithm read fContentDigestAlg write fContentDigestAlg default haSHA256;
ContentDigestAlg is the digest over the ByteRange spans and the CMS pre-hash (default haSHA256). » member page
property ContentsSize: Integer read fContentsSize write fContentsSize default 16384;
ContentsSize is the number of BYTES reserved for the CMS in /Contents (the hex hole is twice as many characters). The default 16384 leaves room for certificate chains and an RFC 3161 time-stamp token. » member page
property SubFilter: tPdfSubFilter read fSubFilter write fSubFilter default psfAdbePkcs7Detached;
SubFilter: adbe.pkcs7.detached (default, universally accepted) or ETSI.CAdES.detached (PAdES baseline: adds the ESS signing-certificate-v2 signed attribute and omits signingTime). » member page
property FieldName: string read fFieldName write fFieldName;
FieldName names the signature form field (default 'Signature1'). » member page
property Reason: string read fReason write fReason;
Reason/Location/ContactInfo are copied into the signature dictionary when non-empty. » member page
property Location: string read fLocation write fLocation; property ContactInfo: string read fContactInfo write fContactInfo; property TimeStampURL: string read fTimeStampURL write fTimeStampURL;
TimeStampURL: when set, the CMS layer obtains an RFC 3161 signature time-stamp from this TSA and embeds it as the signatureTimeStampToken unsigned attribute (see StreamSec.DSI.Tsp). » member page
property VisibleLeft: Double read fVisibleLeft write fVisibleLeft;
Visible appearance. With VisibleRect set to a non-empty rectangle the signature widget is placed on the page (page 1) and given a normal appearance stream drawing a border, the signer line and the reason / location / date, in Helvetica. Leave it empty (the default) for an invisible signature. Coordinates are PDF user space, origin bottom-left. » member page
property VisibleBottom: Double read fVisibleBottom write fVisibleBottom; property VisibleRight: Double read fVisibleRight write fVisibleRight; property VisibleTop: Double read fVisibleTop write fVisibleTop; property VisibleText: string read fVisibleText write fVisibleText;
VisibleText overrides the generated appearance text; when empty the appearance is built from the signer common name, Reason and Location. » member page
function ExtendToLT(aSource, aDest: TStream; const aMaterial: tPdfValidationMaterial): Boolean;
ExtendToLT raises an already-signed document to PAdES B-LT: it appends an incremental update carrying a /DSS (Document Security Store) in the catalog with the supplied certificates, OCSP responses and CRLs, so the signature remains verifiable once those are no longer obtainable online. Full description »
function ExtendToLTFile(const aSourceFile, aDestFile: string; const aMaterial: tPdfValidationMaterial): Boolean; function AddDocumentTimestamp(aSource, aDest: TStream): Boolean;
AddDocumentTimestamp appends a DOCUMENT timestamp: a /Type/DocTimeStamp field whose /SubFilter is /ETSI.RFC3161 and whose /Contents is a bare RFC 3161 time-stamp token over the /ByteRange digest (not a CAdES signature). TimeStampURL must name the TSA. This is what turns B-LT into B-LTA, and what later archival timestamps renew. » member page
function AddDocumentTimestampFile(const aSourceFile, aDestFile: string): Boolean; function ExtendToLTA(aSource, aDest: TStream; const aMaterial: tPdfValidationMaterial): Boolean;
ExtendToLTA = ExtendToLT followed by AddDocumentTimestamp, in two separate incremental updates (the timestamp must cover the DSS). » member page
function ExtendToLTAFile(const aSourceFile, aDestFile: string; const aMaterial: tPdfValidationMaterial): Boolean; property Certify: Boolean read fCertify write fCertify default False;
Certify turns this into a CERTIFICATION (DocMDP) signature rather than an ordinary approval signature: the signature dictionary gains a /Reference with TransformMethod /DocMDP and the /P level below, and the catalog gains /Perms /DocMDP. Full description »
property CertifyLevel: Integer read fCertifyLevel write fCertifyLevel default 2; property ExtKeyUsagePolicy: tExtKeyUsagePolicy read fExtKeyUsagePolicy write fExtKeyUsagePolicy default ekupIgnore;
ExtKeyUsagePolicy decides whether the SIGNING certificate is checked for the id_kp_documentSigning key purpose (RFC 9336) before it is used. Full description »

classTstPdfVerifier — component reference

inherits from TComponent

TstPdfVerifier

Basic verification counterpart of TstPdfSigner: locates the first signature, checks the ByteRange geometry (including detection of content appended AFTER signing - the incremental-update surface every PDF validator must report), and verifies the detached CMS over the signed spans through TstCustomMPSignedData with the assigned KeysAndCerts (the manager's configuration decides trust, exactly as for CMS verification; an embedded RFC 3161 signature time-stamp is verified along the way and surfaced through LastTimeStampTime). Deeper PAdES policy - DocMDP, permitted-change analysis of post-signing updates, LTV - is later work.

Certificates embedded in the signature are imported automatically by the CMS layer, but the key manager only STORES a certificate that chains correctly under its filters and indexes, and that requires a trust anchor of the chain to be present in the manager's root store (plus a storage willing to accept it). So configure KeysAndCerts with the trusted root(s) before verifying; a signature whose chain has no anchor there is reported pssInvalid with "signer certificate could not be resolved/trusted", not silently accepted.

function VerifyData(aSource: TStream): tPdfSignatureStatus;
VerifyData/VerifyFile check EVERY signature field in the document and return the WORST per-signature verdict (pssInvalid beats pssValidModified beats pssValid), so a document cannot be passed off as good because its first signature happens to verify. Per-signature detail is in SignatureCount / Signatures / StatusOf / ModificationOf / ErrorOf. » member page
function VerifyFile(const aFile: string): tPdfSignatureStatus; property LastError: string read fLastError; property LastInfo: tPdfSignatureInfo read fLastInfo;
LastInfo carries the FIRST signature's details (compatibility); use Signatures[] for a multi-signature document. » member page
property SignatureCount: Integer read get_SignatureCount; property Signatures[aIndex: Integer]: tPdfSignatureInfo read get_Signatures; property StatusOf[aIndex: Integer]: tPdfSignatureStatus read get_StatusOf; property ModificationOf[aIndex: Integer]: tPdfModificationClass read get_ModificationOf;
ModificationOf says what an incremental update appended after that signature actually did - see tPdfModificationClass. A second signature legitimately appends, so pmcSignatureOnly is NOT a defect; only pmcContentChanged degrades the verdict. » member page
property ErrorOf[aIndex: Integer]: string read get_ErrorOf; property LastModificationClass: tPdfModificationClass read get_LastModificationClass;
LastModificationClass is the worst modification class over all signatures. » member page
property LastTimeStampTime: TDateTime read fLastTimeStampTime;
LastTimeStampTime is the genTime of a verified RFC 3161 signature time-stamp (0 when the signature carries none). » member page
property LastTimeStampError: string read fLastTimeStampError; property KeysAndCerts: TstCertificateManager read fKeysAndCerts write SetKeysAndCerts; property ExtKeyUsagePolicy: tExtKeyUsagePolicy read fExtKeyUsagePolicy write fExtKeyUsagePolicy default ekupIgnore;
ExtKeyUsagePolicy decides whether the SIGNER's certificate is checked for the id_kp_documentSigning key purpose (RFC 9336). Full description »
property OnKeyUsageRejected: tPdfKeyUsageEvent read fOnKeyUsageRejected write fOnKeyUsageRejected;
Raised ONLY when ExtKeyUsagePolicy has rejected a signer certificate. See tPdfKeyUsageEvent. » member page

Types (enumerations, sets, aliases)

enumtPdfSubFilter

tPdfSubFilter - the signature encoding named in /SubFilter.

  tPdfSubFilter = (psfAdbePkcs7Detached,  // adbe.pkcs7.detached (ISO 32000)
                   psfEtsiCadesDetached); // ETSI.CAdES.detached (PAdES B-B)

arraytPdfSignatureInfoArray

  tPdfSignatureInfoArray = array of tPdfSignatureInfo;

enumtPdfModificationClass

tPdfModificationClass - what an incremental update appended AFTER a signature actually did. PDF permits appending (that is how a second signature is added), so "modified" alone is not a verdict; what matters is WHICH objects the later revision superseded.

  tPdfModificationClass = (
    pmcNone,            // nothing was appended after this signature
    pmcSignatureOnly,   // only signature-related growth: new objects, plus at
                        // most the AcroForm/Fields and the page /Annots that
                        // adding a signature field legitimately touches, and
                        // the catalog /DSS + /Extensions that a PAdES B-LT
                        // (LTV) extension adds
    pmcContentChanged,  // an object the signature covered was SUPERSEDED by a
                        // later revision - the shadow / incremental-saving
                        // attack surface
    pmcUnparsable);     // the appended revision could not be analysed

enumtPdfSignatureStatus

tPdfSignatureStatus - the verdict of TstPdfVerifier.

  tPdfSignatureStatus = (
    pssValid,         // the CMS verified and the ranges cover the whole file
    pssValidModified, // the CMS verified, but updates were APPENDED to the
                      // document after signing - the signature only vouches
                      // for the file as it was at signing time
    pssInvalid,       // a signature is present but did not verify
    pssNoSignature,   // the document carries no signature field
    pssError);        // the document could not be assessed (parse failure...)

proctPdfKeyUsageEvent

tPdfKeyUsageEvent - last word on a signer certificate that the verifier's ExtKeyUsagePolicy has REJECTED. It is raised only on that path, so an unassigned handler can never weaken the policy, and the accepting path costs nothing. Set aAccept True to overrule the rejection - the place to honour, say, a legacy CA that marks document signing with its own OID.

  tPdfKeyUsageEvent = procedure (Sender: TObject;
                                 const aCert: iCertificate;
                                 var aAccept: Boolean) of object;

Routines