Class TrustedRoots

java.lang.Object
com.chilkatsoft.chilkat2.ChilkatObject
com.chilkatsoft.chilkat2.TrustedRoots
All Implemented Interfaces:
AutoCloseable

public class TrustedRoots extends ChilkatObject
<section class="trustedroots-summary">

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 Details

    • TrustedRoots

      public TrustedRoots()
      Creates a new TrustedRoots object.
  • Method Details

    • getNumCerts

      public int getNumCerts()
      The number of certificates explicitly contained in this object. The count includes certificates added by AddCert, AddJavaKeyStore, and LoadCaCertsPem.

      Use indexes from 0 through NumCerts - 1 with CertAt.

      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 NumCerts property (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 false.

      Value Behavior

      false Do not reject a one-certificate TLS chain solely because the certificate is self-signed.

      true Reject TLS server chains consisting of one self-signed certificate.

      This 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 RejectSelfSignedCerts property
    • setRejectSelfSignedCerts

      public void setRejectSelfSignedCerts​(boolean value)
      Sets the RejectSelfSignedCerts property; see getRejectSelfSignedCerts().
      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 true.

      Value Behavior

      true Trust explicitly added certificates and the system-provided CA roots available to Chilkat.

      false Do not automatically trust system-provided CA roots; use the explicitly configured collection and the selected self-signed-certificate policy.

      On 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.crt when available.

      System roots are not added to this object's explicit collection and therefore are not included in NumCerts or returned by CertAt.

      Returns:
      the value of the TrustSystemCaRoots property
    • setTrustSystemCaRoots

      public void setTrustSystemCaRoots​(boolean value)
      Sets the TrustSystemCaRoots property; see getTrustSystemCaRoots().
      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, or LoadCaCertsPem.
      • Operating-system CA roots when TrustSystemCaRoots is 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 true if the configuration was activated successfully; otherwise returns false.

      Trust-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
    • addCert

      public void addCert​(Cert cert)
      Adds the certificate in cert to this object's explicit trusted-certificate collection. The certificate is subsequently treated as a trust anchor when this configuration is activated.

      Returns true if the certificate was added successfully; otherwise returns false.

      Security-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 - the cert argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addJavaKeyStore

      public void addJavaKeyStore​(JavaKeyStore keystore)
      Adds the certificates designated as trusted entries in the keystore JavaKeyStore to this object's explicit trusted-certificate collection.

      Private keys and secret keys are not imported. Returns true if the trusted certificates were added successfully; otherwise returns false.

      Java 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 - the keystore argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • certAt

      public void certAt​(int index, Cert cert)
      Copies the certificate at zero-based index into the caller-supplied Cert object in cert.

      Valid indexes are from 0 through NumCerts - 1. Returns true if the certificate was retrieved successfully; otherwise returns false, such as when the index is outside the valid range.

      This method enumerates only certificates explicitly contained in this TrustedRoots object. Operating-system roots enabled through TrustSystemCaRoots are not included.

      Parameters:
      index - the index argument
      cert - the cert argument (not null)
      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 true if the active configuration was deactivated successfully; otherwise returns false.

      Security warning: This is a permissive mode. It does not merely restore a conventional “trust the operating-system CA store” policy. Use Deactivate only 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

      public void loadCaCertsPem​(String path)
      Loads one or more PEM-encoded certificates from the file at path and 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.crt when that file exists. Returns true if the bundle was loaded successfully; otherwise returns false.

      Trust 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 - the path argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • setProgressListener

      public void setProgressListener​(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; null removes it.
      Parameters:
      listener - the listener, or null
      Throws:
      IllegalStateException - if called from inside one of this object's own callbacks
    • getProgressListener

      public ProgressListener getProgressListener()
      Returns the installed listener, or null.
      Returns:
      the listener installed with setProgressListener(ProgressListener) or one of the on... methods
    • onAbortCheck

      public void onAbortCheck​(BooleanSupplier callback)
      Installs a listener whose only callback is abortCheck: called every HeartbeatMs milliseconds during a long-running method; return true to abort it. Replaces any listener installed before.
      Parameters:
      callback - the callback, or null to remove the listener
    • onPercentDone

      public void onPercentDone​(IntPredicate callback)
      Installs a listener whose only callback is percentDone: called with the completion percentage (0..100) as a long-running method progresses; return true to abort it. Replaces any listener installed before.
      Parameters:
      callback - the callback, or null to remove the listener
    • onProgressInfo

      public void onProgressInfo​(BiConsumer<String,​String> callback)
      Installs a listener whose only callback is progressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.
      Parameters:
      callback - the callback, or null to remove the listener