SetTimeStampToken

Security and signatures

Requires the Enterprise edition — a method of TPDFlibSignatureTimeStampProcess in the Enterprise unit PDFlibEntSignVerify

Description

Validates a DER-encoded RFC 3161 time-stamp token, attaches it to the selected signer of the cached CMS as an unsigned id-aa-signatureTimeStampToken attribute and stores the rebuilt CMS in NewCMSBytes for Apply.

The token is checked before it is used: it has to be an RFC 3161 TimeStampToken whose signature verifies, its message imprint has to be the digest of the signer's signature value under DigestAlgorithm, the signer certificate has to carry time stamping (1.3.6.1.5.5.7.3.8) as the only purpose of a critical extended key usage, and a time-stamp authority name in the token has to match the subject or a subject alternative name of that certificate.

The result code is also stored in ProcessResult. Requires the Enterprise edition; the method belongs to TPDFlibSignatureTimeStampProcess in unit PDFlibEntSignVerify.

Syntax

Delphi

Function TPDFlibSignatureTimeStampProcess.SetTimeStampToken(Const TimeStampTokenDER: AnsiString;
  SignerIndex: Integer): Integer;

Parameters

TimeStampTokenDERThe complete DER-encoded RFC 3161 TimeStampToken returned by the time-stamp authority, as raw bytes
SignerIndexZero-based index of the CMS signer that receives the token. The token is checked against the signature value of this signer

Return values

1The token passed every check; the rebuilt CMS with the new attribute is stored in NewCMSBytes
11SignerIndex is negative, no signature value can be extracted from the CMS for this index, the token failed one of the checks (not an RFC 3161 token, signature not valid, key usage or authority name not matched, hash algorithm or message imprint not matching the signature value), or the attribute could not be inserted into the CMS
OtherOriginalCMS was empty, so PrepareHash ran first with the same SignerIndex and failed. The value is the result code of that call: 2, 3, 12, 14, 15, 16 or 17, as listed for PrepareHash

Remarks

PrepareHash normally runs first, because its hash is what the authority stamps. When OriginalCMS is empty, for example after a failed PrepareHash, this method calls PrepareHash itself with SignerIndex and returns its code when that call fails.

The signature value is hashed again with DigestAlgorithm; SignatureValueHashBytes is not read. A DigestAlgorithm changed between the two calls makes the token fail the imprint check.

An existing signature time-stamp attribute on the signer is replaced; the other unsigned attributes are kept and the attribute set is re-encoded in sorted DER order. The signed attributes and the signature value are not changed.

Nothing is written to the target here; call Apply for that. The class does not contact the time-stamp authority: the request that produces TimeStampTokenDER is the caller's. The conditions in the table are reported as codes and do not raise.

See also

TPDFlibSignatureTimeStampProcess, PrepareHash, Apply, TPDFlibDigestAlgorithm, SetPAdESSignatureTimeStampToken, VerifySignatureTimeStampEx