PLExtractCMSCertificates

signature utilities

Description

Returns every X.509 certificate in the certificates set of a CMS SignedData blob, in encoding order, as raw DER blobs. The walk starts at the outer ContentInfo, descends to the SignedData content and reads the optional [0] IMPLICIT certificates set.

Only the plain Certificate alternative of CertificateChoices is collected; attribute certificates and the other alternatives are skipped because they are not X.509 certificates and nothing downstream can use them. An element whose declared length overruns the set is not treated as a member of it.

The function reads structure only and verifies nothing; it uses the read-only PDFlibCMSRead unit available in every edition.

Syntax

Delphi

Function PLExtractCMSCertificates(Const CMSBytes: AnsiString;
  Out Certs: TPLDERArray): Integer;

Parameters

CMSBytesOne complete binary DER ContentInfo containing SignedData, without PDF hexadecimal encoding or reservation padding; pass the output of PLTrimCMSPadding when starting from a PDF signature
CertsReceives the certificate DER blobs; binary DER is returned in an AnsiString array because a round trip through TStrings would mangle the bytes

Return values

countThe number of certificates found and copied into Certs
0The blob is not a SignedData, carries no certificates set, or the set is empty; Certs is left empty

Remarks

Successful extraction is not a verdict on the signature or the certificates; signature verification stays with the verifier that owns it.

This Pascal unit function has no separate DLL or ActiveX forwarding entry point.

See also

PLCheckCMSSignedDataStructure, GetSignatureEmbeddedCertificateDER, GetSignatureEmbeddedCertificateCount, PLCheckSignatureByteRange