Class TrustedRoots
- All Implemented Interfaces:
AutoCloseable
Configure the trusted root certificates used by Chilkat certificate validation.
Chilkat.TrustedRoots manages a collection of trusted CA and
self-signed root certificates used Chilkat-wide for PKCS7/CMS signature
validation and SSL/TLS server certificate validation. It can add individual
certificates, import trusted certificates from a Java keystore, load PEM CA
bundles, activate or deactivate the trusted-root set, and control whether
system CA roots and self-signed server certificates are trusted.
Custom trusted roots
Add root or CA certificates that should be trusted by Chilkat validation operations.
PEM CA bundles
Load one or more trusted CA certificates from PEM bundle files used by many TLS and certificate-validation workflows.
Java keystore import
Import trusted certificates from a JavaKeyStore when trust
anchors are maintained in JKS-style storage.
System CA root control
Choose whether Chilkat should also trust the operating system's CA root certificates.
Self-signed certificate policy
Control whether self-signed server certificates are rejected or accepted during certificate validation.
Activate Chilkat-wide trust
Activate the configured trusted-root set so it is used by Chilkat classes that perform TLS or signature certificate validation.
Common pattern:
Create a TrustedRoots object, add trusted certificates or load a
PEM CA bundle, configure whether system roots and self-signed certificates
should be trusted, then call Activate. Treat trusted roots as
Chilkat-wide validation configuration, not as private state for a single
object.
For an extended overview, see TrustedRoots Class Overview.
</section>
Event-capable: long-running methods report progress through a ProgressListener installed
with setProgressListener(ProgressListener), onAbortCheck(BooleanSupplier),
onPercentDone(IntPredicate) or onProgressInfo(BiConsumer).
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 TypeMethodDescriptionvoidactivate()Activates this object's trust configuration for Chilkat-wide certificate validation.voidAdds the certificate incertto this object's explicit trusted-certificate collection.voidaddJavaKeyStore(JavaKeyStore keystore)Adds the certificates designated as trusted entries in thekeystoreJavaKeyStoreto this object's explicit trusted-certificate collection.voidCopies the certificate at zero-basedindexinto the caller-suppliedCertobject incert.voidDeactivates the previously activated Chilkat-wide trusted-root configuration.intThe number of certificates explicitly contained in this object.Returns the installed listener, ornull.booleanControls the special case in which an SSL/TLS server presents a certificate chain containing exactly one certificate and that certificate is self-signed.booleanControls whether operating-system CA roots are included when this object's trust configuration is activated.voidloadCaCertsPem(String path)Loads one or more PEM-encoded certificates from the file atpathand adds them to this object's explicit trusted-certificate collection.voidonAbortCheck(BooleanSupplier callback)Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it.voidonPercentDone(IntPredicate callback)Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it.voidonProgressInfo(BiConsumer<String,String> callback)Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds.voidsetProgressListener(ProgressListener listener)Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.voidsetRejectSelfSignedCerts(boolean value)Sets theRejectSelfSignedCertsproperty; seegetRejectSelfSignedCerts().voidsetTrustSystemCaRoots(boolean value)Sets theTrustSystemCaRootsproperty; seegetTrustSystemCaRoots().Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
TrustedRoots
public TrustedRoots()Creates a newTrustedRootsobject.
-
-
Method Details
-
getNumCerts
public int getNumCerts()The number of certificates explicitly contained in this object. The count includes certificates added byAddCert,AddJavaKeyStore, andLoadCaCertsPem.Use indexes from
0throughNumCerts - 1withCertAt.Scope of the count: This property does not include operating-system CA roots made available by
TrustSystemCaRoots. It reports only the certificates stored in this object.- Returns:
- the value of the
NumCertsproperty (read-only)
-
getRejectSelfSignedCerts
public boolean getRejectSelfSignedCerts()Controls the special case in which an SSL/TLS server presents a certificate chain containing exactly one certificate and that certificate is self-signed. The default value is.falseValue Behavior
Do not reject a one-certificate TLS chain solely because the certificate is self-signed.falseReject TLS server chains consisting of one self-signed certificate.trueThis property applies to the TLS server-certificate case described above. It does not reject a self-signed CA certificate merely because that certificate appears as the trust anchor above a longer chain.
Security guidance: A self-signed certificate has no external issuer establishing trust. Accept it only when the certificate or its public-key fingerprint has been authenticated through a separate trusted channel.
- Returns:
- the value of the
RejectSelfSignedCertsproperty
-
setRejectSelfSignedCerts
public void setRejectSelfSignedCerts(boolean value)Sets theRejectSelfSignedCertsproperty; seegetRejectSelfSignedCerts().- Parameters:
value- the new value
-
getTrustSystemCaRoots
public boolean getTrustSystemCaRoots()Controls whether operating-system CA roots are included when this object's trust configuration is activated. The default value is.trueValue Behavior
Trust explicitly added certificates and the system-provided CA roots available to Chilkat.trueDo not automatically trust system-provided CA roots; use the explicitly configured collection and the selected self-signed-certificate policy.falseOn Windows, system roots come from registry-based certificate stores. On Linux, Chilkat may use a system CA bundle such as
/etc/ssl/certs/ca-certificates.crtwhen available.System roots are not added to this object's explicit collection and therefore are not included in
NumCertsor returned byCertAt.- Returns:
- the value of the
TrustSystemCaRootsproperty
-
setTrustSystemCaRoots
public void setTrustSystemCaRoots(boolean value)Sets theTrustSystemCaRootsproperty; seegetTrustSystemCaRoots().- Parameters:
value- the new value
-
activate
public void activate()Activates this object's trust configuration for Chilkat-wide certificate validation. The active configuration includes:- Certificates explicitly added to this object by
AddCert,AddJavaKeyStore, orLoadCaCertsPem. - Operating-system CA roots when
TrustSystemCaRootsis.true - The self-signed TLS certificate policy selected by
RejectSelfSignedCerts.
After activation, Chilkat classes that validate PKCS7/CMS signatures or SSL/TLS server certificate chains use this trust configuration. Returns
if the configuration was activated successfully; otherwise returnstrue.falseTrust-anchor note: Activating a certificate as trusted supplies a starting point for certificate-path validation. It does not, by itself, prove that every certificate issued beneath that anchor is valid for every purpose; the applicable validation operation may also evaluate signatures, validity periods, identity, key usage, constraints, and other policy requirements.
- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
- Certificates explicitly added to this object by
-
addCert
Adds the certificate incertto this object's explicit trusted-certificate collection. The certificate is subsequently treated as a trust anchor when this configuration is activated.Returns
if the certificate was added successfully; otherwise returnstrue.falseSecurity-sensitive operation: Calling this method is an explicit trust decision. It does not first determine whether the certificate is self-signed, belongs to a public CA, is currently valid, or is appropriate for the intended application. Add only certificates obtained and verified through a trustworthy process.
- Parameters:
cert- thecertargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addJavaKeyStore
Adds the certificates designated as trusted entries in thekeystoreJavaKeyStoreto this object's explicit trusted-certificate collection.Private keys and secret keys are not imported. Returns
if the trusted certificates were added successfully; otherwise returnstrue.falseJava keystore terminology: A trusted-certificate entry represents a certificate that the keystore owner has chosen to trust. Importing it preserves that trust decision; it does not independently validate the certificate or build a certification path for it.
- Parameters:
keystore- thekeystoreargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
certAt
Copies the certificate at zero-basedindexinto the caller-suppliedCertobject incert.Valid indexes are from
0throughNumCerts - 1. Returnsif the certificate was retrieved successfully; otherwise returnstrue, such as when the index is outside the valid range.falseThis method enumerates only certificates explicitly contained in this
TrustedRootsobject. Operating-system roots enabled throughTrustSystemCaRootsare not included.- Parameters:
index- theindexargumentcert- thecertargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
deactivate
public void deactivate()Deactivates the previously activated Chilkat-wide trusted-root configuration. After deactivation, roots and single-certificate self-signed certificates are implicitly trusted.Returns
if the active configuration was deactivated successfully; otherwise returnstrue.falseSecurity warning: This is a permissive mode. It does not merely restore a conventional “trust the operating-system CA store” policy. Use
Deactivateonly when implicitly trusting arbitrary roots and self-signed certificates is intentional and acceptable for the application.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadCaCertsPem
Loads one or more PEM-encoded certificates from the file atpathand adds them to this object's explicit trusted-certificate collection. A CA bundle normally contains consecutive-----BEGIN CERTIFICATE-----/-----END CERTIFICATE-----blocks.This method can load a curated application bundle, a Mozilla-derived CA bundle, or a platform bundle such as
/etc/ssl/certs/ca-certificates.crtwhen that file exists. Returnsif the bundle was loaded successfully; otherwise returnstrue.falseTrust implication: Certificates loaded by this method are treated as trusted anchors after activation. The file is not merely a source of intermediate certificates. Review and protect the bundle as security-sensitive configuration.
- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setProgressListener
Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.- Parameters:
listener- the listener, ornull- Throws:
IllegalStateException- if called from inside one of this object's own callbacks
-
getProgressListener
Returns the installed listener, ornull.- Returns:
- the listener installed with
setProgressListener(ProgressListener)or one of theon...methods
-
onAbortCheck
Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onPercentDone
Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onProgressInfo
Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-