CertChain Chilkat2 Perl Reference Documentation
Chilkat2::CertChain
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.CertChain
Examine the certificates in chain order and retrieve individual
certificates with
Determine whether the chain reaches a root certificate and whether that
root is trusted.
Verify that each certificate in the chain is signed by the next
certificate in the chain.
Detect whether one or more certificates in the chain are expired.
Load certificate chains from JWK
Export the certificate chain in
For an extended overview, see
CertChain Class Overview.
Inspect, verify, export, and work with X.509 certificate chains.
Chilkat.CertChain is a compact helper class for representing
and working with X.509 certificate chains. It lets applications inspect the
ordered certificates in a chain, retrieve individual certificates, determine
whether the chain reaches a root, check for expired certificates, verify
chain signatures, test whether the root is trusted, load certificate chains
from JWK x5c data, and export the chain as
X509PKIPathv1.
Chain inspection
CertAt.
Root and trust checks
Signature verification
Expiration checks
JWK x5c support
x5c arrays used by JWT,
JWS, and other security-token workflows.
Chain export
X509PKIPathv1 format when
that representation is required.
CertChain to reason about the chain as a whole. For
certificate-level details such as subject, issuer, SAN values, key usage,
validity dates, fingerprints, serial numbers, and extensions, retrieve each
certificate with CertAt and inspect it using
Chilkat.Cert.
Object Creation
use Chilkat2;
my $certChain = Chilkat2::CertChain->new;
# or set properties (and RaiseError) at creation:
# my $certChain = Chilkat2::CertChain->new(VerboseLogging => 1, RaiseError => 1);Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/CertChain.pm file holds only this class's documentation (perldoc Chilkat2::CertChain).
Perl frees the object when its last reference goes (undef $certChain, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::CertChain';): an object is a blessed hash reference whose hash is free for the subclass's own fields.
When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.
Errors
A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::CertChain'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.
Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.
Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.
Properties
DebugLogFilePath
my $strVal = $certChain->DebugLogFilePath;
$certChain->DebugLogFilePath($strVal);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastErrorHtml
my $strVal = $certChain->LastErrorHtml;
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
my $strVal = $certChain->LastErrorText;
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
my $strVal = $certChain->LastErrorXml;
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
my $boolVal = $certChain->LastMethodSuccess;
$certChain->LastMethodSuccess($boolVal);
Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
NumCerts
my $intVal = $certChain->NumCerts;
The number of certificates currently contained in the chain.
| Index | Meaning |
|---|---|
0 |
The target or end-entity certificate—the certificate farthest from the root end of the chain |
1 ... NumCerts - 2 |
Intermediate CA certificates, when present |
NumCerts - 1 |
The highest certificate available in the chain |
ReachesRoot is 0, the final certificate may only be the highest intermediate that was available. Even when the chain ends in a self-signed root, trust must be established separately.
NumExpiredCerts
my $intVal = $certChain->NumExpiredCerts;
The number of certificates in the chain whose validity period has expired.
0 does not mean the chain is valid or trusted. It does not by itself establish that certificates are already valid, correctly signed, unrevoked, issued by an accepted trust anchor, or suitable for the intended identity and key usage.
Retrieve individual certificates with CertAt when the application needs to inspect exact validity dates or identify which certificates are expired.
ReachesRoot
my $boolVal = $certChain->ReachesRoot;
if the chain extends to a terminal root certificate rather than stopping at an intermediate certificate. When this property is 1, the certificate at index 1NumCerts - 1 is the root-end certificate of the chain.
IsRootTrusted with the application's approved TrustedRoots collection to test trust-anchor membership.
A value of means the chain is incomplete at the root end; the final certificate may be an intermediate CA for which no issuer certificate was available.0
UncommonOptions
my $strVal = $certChain->UncommonOptions;
$certChain->UncommonOptions($strVal);
Specifies uncommon behavior as a comma-separated list of keywords. The default is the empty string, which enables the standard behavior.
| Keyword | Effect |
|---|---|
PkiPathV1.ExcludeRoot |
Omits the root certificate from the value returned by X509PKIPathv1. This option affects that method only. |
VerboseLogging
my $boolVal = $certChain->VerboseLogging;
$certChain->VerboseLogging($boolVal);
If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
my $strVal = $certChain->Version;
Methods
CertAt
# $cert is a Chilkat2::Cert
# $success is true or false
my $success = $certChain->CertAt($index, $cert);
Populates with the certificate at the specified zero-based $certindex. Valid indices range from 0 through NumCerts - 1.
| Index | Position in the chain |
|---|---|
0 |
Target or end-entity certificate |
1 ... NumCerts - 2 |
Intermediate CA certificates, when present |
NumCerts - 1 |
Highest certificate available in the chain; a root certificate only when ReachesRoot is |
Returns on success. Returns 1 if the index is invalid or the certificate cannot be returned; in that case, do not use the contents of 0 as a successful result.$cert
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
IsRootTrusted
# $flag is true or false
my $flag = $certChain->IsRootTrusted($trustedRoots);
Tests whether the certificate at the root end of this chain is present in the TrustedRoots collection passed in . Returns $trustedRoots when a matching trusted-root certificate is found; otherwise returns 1.0
A complete certificate-validation decision may also require checking signature linkage, certificate validity periods, revocation status, basic constraints, key usage, policies, name constraints, and application-specific identity requirements.
Never dies: false is an answer, not a failure.
topLoadX5C
# $success is true or false
my $success = $certChain->LoadX5C($jwk);
Loads the certificate chain from the x5c member of the JWK contained in . Returns $jwk if the chain is loaded successfully; otherwise returns 1.0
As defined by RFC 7517, x5c is a JSON array of DER-encoded X.509 certificates represented using standard Base64—not Base64URL. The first certificate contains the key associated with the JWK. Each following certificate should certify the certificate immediately before it, so the array order is target certificate first and rootward certificates afterward.
x5c array does not make its certificates trusted. Treat the chain as untrusted input until the required signature, validity, trust-anchor, revocation, and application-policy checks have been completed.
Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.
VerifyCertSignatures
my $flag = $certChain->VerifyCertSignatures();
Verifies the cryptographic signature linkage of the certificates in this chain. Starting with the target certificate at index 0, each certificate's signature is checked using the public key of the next issuer certificate in the chain. Returns when the certificate signatures are valid through the root end of the chain; otherwise returns 1.0
1 result confirms the issuer-signature relationships represented by the chain. It does not by itself prove that the root is trusted, that certificates are within their validity periods, that none are revoked, that CA constraints and policies are acceptable, or that the target certificate is valid for a particular hostname or usage.
Never dies: false is an answer, not a failure.
topX509PKIPathv1
my $str = $certChain->X509PKIPathv1();
Returns the Base64 representation of a DER-encoded ASN.1 PkiPath containing the certificates in this chain. This representation is commonly identified as the X509PKIPathv1 token type in WS-Security and may also be encountered in XML-signature workflows.
A PkiPath is a SEQUENCE OF Certificate ordered from the root or most-trusted end toward the target certificate. This is the reverse of the indexing used by CertAt, where index 0 is the target certificate.
| Representation | Certificate order |
|---|---|
CertChain indexing |
Target/leaf → intermediates → root |
X509PKIPathv1 |
Root → intermediates → target/leaf |
By default, the root certificate is included when it is present in the chain. Set UncommonOptions to PkiPathV1.ExcludeRoot when the receiving protocol expects the trust anchor to be supplied separately.
LastMethodSuccess before using the returned text, and inspect LastErrorText if the operation fails.
Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.