Class CertChain
- All Implemented Interfaces:
AutoCloseable
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
Examine the certificates in chain order and retrieve individual
certificates with CertAt.
Root and trust checks
Determine whether the chain reaches a root certificate and whether that root is trusted.
Signature verification
Verify that each certificate in the chain is signed by the next certificate in the chain.
Expiration checks
Detect whether one or more certificates in the chain are expired.
JWK x5c support
Load certificate chains from JWK x5c arrays used by JWT,
JWS, and other security-token workflows.
Chain export
Export the certificate chain in X509PKIPathv1 format when
that representation is required.
Common pattern:
Use 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.
For an extended overview, see CertChain Class Overview.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPopulateswith the certificate at the specified zero-basedcertindex.intThe number of certificates currently contained in the chain.intThe number of certificates in the chain whose validity period has expired.booleanif the chain extends to a terminal root certificate rather than stopping at an intermediate certificate.trueSpecifies uncommon behavior as a comma-separated list of keywords.booleanisRootTrusted(TrustedRoots trustedRoots)Tests whether the certificate at the root end of this chain is present in theTrustedRootscollection passed in.trustedRootsvoidloadX5C(JsonObject jwk)Loads the certificate chain from thex5cmember of the JWK contained in.jwkvoidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().booleanVerifies the cryptographic signature linkage of the certificates in this chain.Returns the Base64 representation of a DER-encoded ASN.1PkiPathcontaining the certificates in this chain.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
CertChain
public CertChain()Creates a newCertChainobject.
-
-
Method Details
-
getNumCerts
public int getNumCerts()The number of certificates currently contained in the chain.Index Meaning
0The target or end-entity certificate—the certificate farthest from the root end of the chain1 ... NumCerts - 2Intermediate CA certificates, when presentNumCerts - 1The highest certificate available in the chainDo not assume the final certificate is trusted: If
ReachesRootis, 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.false- Returns:
- the value of the
NumCertsproperty (read-only)
-
getNumExpiredCerts
public int getNumExpiredCerts()The number of certificates in the chain whose validity period has expired.Expiration is only one validation check: A value of
0does 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
CertAtwhen the application needs to inspect exact validity dates or identify which certificates are expired.- Returns:
- the value of the
NumExpiredCertsproperty (read-only)
-
getReachesRoot
public boolean getReachesRoot()if the chain extends to a terminal root certificate rather than stopping at an intermediate certificate. When this property istrue, the certificate at indextrueNumCerts - 1is the root-end certificate of the chain.Root presence is not root trust: An included root is commonly self-signed, but its presence does not make it a trusted anchor. Use
IsRootTrustedwith the application's approvedTrustedRootscollection 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.false- Returns:
- the value of the
ReachesRootproperty (read-only)
-
getUncommonOptions
Specifies uncommon behavior as a comma-separated list of keywords. The default is the empty string, which enables the standard behavior.Keyword Effect
PkiPathV1.ExcludeRootOmits the root certificate from the value returned byX509PKIPathv1. This option affects that method only.Interoperability note: Some protocols transport the trust anchor with the path, while others expect the recipient to obtain or trust it independently. Use this option according to the format required by the receiving system.
- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
certAt
Populateswith the certificate at the specified zero-basedcertindex. Valid indices range from0throughNumCerts - 1.Index Position in the chain
0Target or end-entity certificate1 ... NumCerts - 2Intermediate CA certificates, when presentNumCerts - 1Highest certificate available in the chain; a root certificate only whenReachesRootistrueReturns
on success. Returnstrueif the index is invalid or the certificate cannot be returned; in that case, do not use the contents offalseas a successful result.cert- Parameters:
index- theindexargumentcert- thecertargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
isRootTrusted
Tests whether the certificate at the root end of this chain is present in theTrustedRootscollection passed in. ReturnstrustedRootswhen a matching trusted-root certificate is found; otherwise returnstrue.falseTrust is a local policy decision: A self-signed certificate is not trusted merely because it appears at the end of a chain. This method checks membership in the supplied trust collection; it does not, by itself, establish that the entire chain is valid for a particular application or identity.
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.
- Parameters:
trustedRoots- thetrustedRootsargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
loadX5C
Loads the certificate chain from thex5cmember of the JWK contained in. Returnsjwkif the chain is loaded successfully; otherwise returnstrue.falseAs defined by RFC 7517,
x5cis 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.Security note: Loading an
x5carray 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.- Parameters:
jwk- thejwkargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
verifyCertSignatures
public boolean verifyCertSignatures()Verifies the cryptographic signature linkage of the certificates in this chain. Starting with the target certificate at index0, each certificate's signature is checked using the public key of the next issuer certificate in the chain. Returnswhen the certificate signatures are valid through the root end of the chain; otherwise returnstrue.falseSignature verification is not full path validation: A
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.true- Returns:
- the result; this method never throws
ChilkatException
-
x509PKIPathv1
Returns the Base64 representation of a DER-encoded ASN.1PkiPathcontaining the certificates in this chain. This representation is commonly identified as theX509PKIPathv1token type in WS-Security and may also be encountered in XML-signature workflows.A
PkiPathis aSEQUENCE OF Certificateordered from the root or most-trusted end toward the target certificate. This is the reverse of the indexing used byCertAt, where index0is the target certificate.Representation Certificate order
CertChainindexing Target/leaf → intermediates → rootX509PKIPathv1Root → intermediates → target/leafBy default, the root certificate is included when it is present in the chain. Set
UncommonOptionstoPkiPathV1.ExcludeRootwhen the receiving protocol expects the trust anchor to be supplied separately.Return-value note: This is a string-returning method. Check
LastMethodSuccessbefore using the returned text, and inspectLastErrorTextif the operation fails.- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-