RenewPAdESArchiveVerified

Security and signatures

Requires the Enterprise edition — a method of TPDFlibEntSignLTV (unit PDFlibEntSignLTV); create the library as TPDFlibEnterprise to call it

Description

Renews the archive time stamp of a signed PDF and publishes the result only when the renewed document verifies under the trust anchors passed in. The method promotes the document to PAdES B-LTA in memory, reopens the exact candidate, runs the historical validation of the selected signature and writes the output file as the last step.

TPDFlibEntSignLTV is an ancestor of TPDFlibEnterprise, so applications call the method on that class (unit PDFlibEnterprise); the declaring unit is PDFlibEntSignLTV. The method requires the Enterprise edition.

Syntax

Delphi

Function TPDFlibEntSignLTV.RenewPAdESArchiveVerified(Const InputFile, Password, OutputFile,
  FieldName: WideString; Const TrustAnchorsDER: Array Of AnsiString;
  ValidationTimeUTC: TDateTime; LTVOptions: Integer;
  Out Report: TPDFlibAdESHistoricalValidationReport): Integer;

Parameters

InputFileThe signed PDF to renew. It is opened read-only, never modified, and must hold at least one byte and at most 64 MiB (67,108,864 bytes)
PasswordPassword that opens InputFile; empty for a document that is not encrypted
OutputFilePath of the renewed document. It must not exist yet: an existing destination is refused and the file is created only after the verification passed
FieldNameName of the signature field that is processed and validated. It has to carry an intact signature with exactly one signer and the ETSI.CAdES.detached subfilter
TrustAnchorsDEROne to 32 DER-encoded certificates. They are the only trust anchors of the verification; each must be at most 65536 bytes and parse as a certificate
ValidationTimeUTCUTC time at which the historical validation runs, as a TDateTime. 0 selects the current UTC time; a negative value, NaN, an infinite value or a value of 2958466 or later is rejected
LTVOptionsBit mask of PADES_LTV_* options for the validation-material stage, as for ApplyPAdESLongTermValidation. 0 selects PADES_LTV_SKIP_EXISTING; any bit outside PADES_LTV_DEFAULT is rejected
ReportReceives the TPDFlibAdESHistoricalValidationReport of the reopened candidate. It is cleared at the start of the call and filled only when the historical validation ran

Return values

1The renewed document passed every check and was written to OutputFile; GetPAdESLTVError returns an empty string
0No file was published and GetPAdESLTVError returns the reason: an argument failed its check, the time-stamp server is not configured or does not use SHA-256, SHA-384 or SHA-512, OutputFile already exists, the B-LTA stage failed, or the reopened candidate did not satisfy the trust policy

Remarks

The checks run in a fixed order. Arguments first: InputFile, OutputFile and FieldName must not be empty or contain a #0 character, TrustAnchorsDER must hold 1 to 32 items, ValidationTimeUTC must be a finite value from 0 up to but not including 2958466, and LTVOptions must not have a bit outside PADES_LTV_DEFAULT. Then a time-stamp server must be configured with SetTimeStampServer and its digest algorithm, set with SetTimeStampOptions, must be 2, 3 or 4. OutputFile must not exist. Each anchor must be a bounded DER certificate, and the input must hold 1 byte to 64 MiB.

The signature itself must open with Password, verify as intact for signer 0, use the ETSI.CAdES.detached subfilter and have exactly one signer.

The B-LTA stage does the work of ApplyPAdESLongTermArchiveValidation in memory: validation material is collected as LTVOptions requests and a document time stamp is obtained from the configured server. The candidate must be longer than the source, at most 64 MiB, and start with the unchanged source bytes.

The candidate is reopened and must have exactly one signature more than the source. VerifyAdESHistoricalByName then runs for FieldName with srmCacheOnly at ValidationTimeUTC and must return vsValid, with baseline profile 4 (B-LTA), an archive time greater than 0, no time-consistency issue and every document time stamp of the document valid.

Only then is the candidate written to OutputFile as a new file. InputFile is never modified and an existing OutputFile is never replaced.

A verifier is created for the call and gets TrustAnchorsDER as its only trust anchors; no trust source is attached to it. Any exception raised during the work is caught: its message becomes the text returned by GetPAdESLTVError and the result is 0, so the method itself does not raise.

Report holds the historical validation report only when the reopened candidate was verified. GetPAdESLTVError carries the reason of a failed stage, and GetTimeStampError the detail of a failed time-stamp request.

LTVOptions passed as 0 becomes PADES_LTV_SKIP_EXISTING: the stage then writes no /VRI entry and performs no OCSP, CRL or issuer retrieval, so no network request is made for validation material. PADES_LTV_WRITE_VRI, PADES_LTV_FETCH_OCSP, PADES_LTV_FETCH_CRL and PADES_LTV_FOLLOW_AIA switch these steps on, and PADES_LTV_SKIP_ROOT_REVOCATION leaves the self-issued top certificate of a chain without a status request.

Example

Uses PDFlibEnterprise, PDFlibEntSignVerify;

Var
  PDF: TPDFlibEnterprise;
  RootCertDER: AnsiString; // DER bytes of the trust anchor certificate
  History: TPDFlibAdESHistoricalValidationReport;
begin
  PDF:= TPDFlibEnterprise.Create;
  try
    PDF.SetTimeStampServer('https://tsa.example.com/tsa', '', '');
    PDF.SetTimeStampOptions(2, 1, 1, 15000, '');
    if PDF.RenewPAdESArchiveVerified('signed.pdf', '', 'renewed.pdf',
      'Signature1', [RootCertDER], 0, PADES_LTV_DEFAULT, History)<> 1 then
      raise Exception.Create(string(PDF.GetPAdESLTVError));
  finally
    PDF.Free;
  end;
end;

See also

ApplyPAdESLongTermArchiveValidation, GetPAdESLTVError, TPDFlibAdESHistoricalValidationReport, VerifyAdESHistoricalByName, SetTimeStampServer, SetTimeStampOptions, GetTimeStampError, TPDFlibEnterprise