SetPAdESSignatureTimeStampToken

Requires the Enterprise edition — in Delphi, C++Builder and Lazarus code create the library as TPDFlibEnterprise (unit PDFlibEnterprise); the Enterprise DLL and ActiveX builds provide it unchanged; other editions keep the method, which returns 0, an empty string or False and sets LastErrorCode to 900 (PDFLIB_ERROR_ENTERPRISE_REQUIRED)

Security and Signatures

Description

Validates a DER-encoded RFC 3161 TimeStampToken and injects it as an id-aa-signatureTimeStampToken unsigned attribute on the selected CMS SignerInfo

The method verifies the token signature, requires the sole critical extended key usage to be timeStamping, checks an encoded TSA name when present, and compares the token message imprint with the configured digest of the signer signatureValue

Existing signature timestamp attributes on the selected signer are replaced, unrelated unsigned attributes are preserved, and the rebuilt attribute set is DER sorted

Syntax

Delphi

Function TPDFlib.SetPAdESSignatureTimeStampToken(STSProcessID: Integer;
  Const TimeStampTokenDER: AnsiString; SignerIndex: Integer= 0): Integer; Virtual;

ActiveX

Function PDFlib::SetPAdESSignatureTimeStampToken(STSProcessID As Long, TimeStampTokenDER As Variant, SignerIndex As Long) As Long

DLL

int DLSetPAdESSignatureTimeStampToken(int InstanceID, int STSProcessID, const char* TimeStampTokenDER, int TimeStampTokenDERLength, int SignerIndex);

Parameters

STSProcessIDValue returned by one of the NewPAdESSignatureTimeStampProcessFrom* functions
TimeStampTokenDERComplete DER-encoded RFC 3161 TimeStampToken returned by the TSA
SignerIndexZero-based CMS signer index, defaulting to the first signer

Return values

0The process identifier is invalid
1The token was validated and injected
11The token, CMS, selected signer, TSA constraints, or message imprint is invalid
17A later signature or document time stamp covers the target signature value; attaching the token would invalidate it (see GetPAdESSignatureTimeStampProcessResult)
OtherThe source PDF or selected signature could not be prepared, as reported by GetPAdESSignatureTimeStampProcessResult

Workflow

  1. Reserve enough signature contents space with SetSignProcessReserveContentsBytes before creating the original signature
  2. Create a timestamp process and select the signature field and digest algorithm
  3. Call GetPAdESSignatureValueHashHex and send that message imprint to the TSA
  4. Pass the returned TimeStampToken to this method
  5. Finish with an EndPAdESSignatureTimeStampProcessTo* method

The library validates and rewrites CMS but does not perform the TSA HTTP request

See also

GetPAdESSignatureValueHashHex, SetPAdESSignatureTimeStampDigestAlgorithm, SetSignProcessReserveContentsBytes, TPDFlibSignatureVerifier