PDFium Delphi Component Docs

FPdfCryptoWin unit

Unit: FPdfCryptoWin
Windows Cryptography API backend for PAdES signing, detached CMS verification, and cache-only system certificate trust evaluation

Syntax

function WinCryptoAvailable: Boolean;
function WinCmsVerificationAvailable: Boolean;
function VerifyWinDetachedCms(const CmsDer: TBytes; Segment1: Pointer; Segment1Length: Cardinal; Segment2: Pointer; Segment2Length: Cardinal): TWinCmsVerifyResult;
function VerifyWinDetachedCmsEx(const CmsDer: TBytes; Segment1: Pointer; Segment1Length: Cardinal; Segment2: Pointer; Segment2Length: Cardinal; const Options: TWinCmsVerifyOptions): TWinCmsVerifyResult;
function VerifyWinAttachedCmsEx(const CmsDer: TBytes; const Options: TWinCmsVerifyOptions): TWinCmsVerifyResult;
function ResolveWinSigner(const Options: TPadesSignerOptions): TPadesResolvedSigner;
function TestBuildWinCmsTrust(SignerCert: Pointer;
  const Options: TWinCmsVerifyOptions; GetChain, VerifyPolicy,
  FreeChain: Pointer): TWinCmsVerifyResult; // PDFIUMPAS_CRYPTO_TESTS only

Description

FPdfCryptoWin is the Windows-specific crypto backend consumed by FPdfCrypto. It opens the current-user and local-machine certificate stores via CryptoAPI, locates the certificate matching the requested thumbprint, acquires the associated NCRYPT private key handle, and returns a TPadesResolvedSigner whose ICmsSigner signs through CNG

WinCryptoAvailable performs the lightweight check that the Crypt32 / ncrypt bindings resolve, so callers can decide at startup whether PAdES signing will be possible on this machine

VerifyWinDetachedCms validates a detached CMS value against two caller-owned byte segments, returns the signer certificate, and evaluates its chain with the cache-only Windows base policy without performing network retrieval

The extended verification functions accept TWinCmsVerifyOptions so callers can enable online certificate retrieval, request revocation checking, set a retrieval timeout, and observe verification checkpoints

Signature validity and certificate trust are independent results so an authentic signature from an untrusted or self-signed certificate remains distinguishable from tampered content

Functions

FunctionDescription
WinCryptoAvailableReturns True when the Windows Crypt32 and ncrypt bindings can be resolved at runtime
WinCmsVerificationAvailableReturns True when detached CMS verification and certificate chain-policy APIs are available
VerifyWinDetachedCmsVerifies the CMS signed attributes and signature over two detached content segments and reports current cache-only system trust separately
VerifyWinDetachedCmsExVerifies detached CMS content with explicit online retrieval, revocation, timeout, and checkpoint options
VerifyWinAttachedCmsExVerifies an attached CMS value and evaluates its signer certificate using the supplied options
ResolveWinSignerResolves a thumbprint into a signer, certificate DER, and chain using the Windows certificate store and CNG private key
TestBuildWinCmsTrustTest-conditional hook compiled only under PDFIUMPAS_CRYPTO_TESTS: swaps the CNG chain-policy function pointers for caller-supplied stubs, runs trust building with the signature status preset to valid, and restores the pointers, so crypto unit tests can exercise BuildWinCmsTrust without a real certificate chain

Verification Types

TypeMembers and purpose
TWinCmsVerifyStatuswcvsUnavailable, wcvsValid, wcvsInvalid, wcvsUnsupported, or wcvsIndeterminate
TWinCmsVerifyStagewcvstCryptographicSignature, wcvstChainBuild, wcvstOnlineRetrieval, or wcvstRevocationCheck
TWinCmsVerifyCheckpointObject-method callback receiving each TWinCmsVerifyStage
TWinCmsVerifyOptionsOnlineRetrieval, CheckRevocation, CollectChainCertificates, UrlRetrievalTimeoutMs, OnCheckpoint, and the static Default factory
TWinCmsVerifyResultAlias of TPdfCmsVerifyResult, containing SignatureStatus, TrustStatus, RevocationStatus, SignatureError, TrustError, SignerCertificate, ChainCertificates, RevocationReason, and RevocationError

Revocation results

With CheckRevocation enabled, the backend builds a separate revocation chain and fills RevocationStatus, RevocationReason, and RevocationError. Revocation failures do not overwrite the signature result or the independently evaluated TrustStatus and TrustError

For a well-formed native chain, confirmed revocation produces wcvsInvalid with pcrrCertificateRevoked. Without confirmed revocation, an untrusted chain produces wcvsIndeterminate with pcrrChainUntrusted; incomplete native structures and other unresolved revocation checks remain wcvsIndeterminate with pcrrUnknown

A valid result requires a trusted chain, no chain errors, at least one certificate that requires revocation checking, and a successful native revocation result for every such certificate. Only a terminal certificate explicitly marked as self-signed or a trusted CA anchor is excluded from that coverage requirement; a root-only chain or missing per-certificate evidence remains indeterminate

RevocationError preserves a raw DWORD from CERT_REVOCATION_INFO.dwRevocationResult, or the immediate GetLastError value when the revocation chain call fails. Zero means no native diagnostic is available, including when a chain status establishes revocation without a corresponding provider code. Aggregate CERT_TRUST_STATUS.dwErrorStatus bits are used for classification and are not copied into this field as an invented native error

Interpret the raw value in its Windows provider or API context; it is not guaranteed to be an HRESULT. Offline, stale, or unknown revocation evidence does not identify CRL expiration, malformed CRLs, or bad CRL signatures, so this backend does not infer those detailed reasons

With OnlineRetrieval = False, both chain building and revocation checking use cached retrieval only. Enabling online retrieval permits the Windows chain engine to obtain the supporting evidence within the configured retrieval timeout

Remarks

See Also

FPdfCrypto, FPdfCms