TrustedRoots C Reference Documentation

TrustedRoots

Current Version: 11.5.0

Chilkat.TrustedRoots

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.

Create/Dispose

HCkTrustedRoots instance = CkTrustedRoots_Create();
// ...
CkTrustedRoots_Dispose(instance);
HCkTrustedRoots CkTrustedRoots_Create(void);

Creates an instance of the HCkTrustedRoots object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkTrustedRoots_Dispose(HCkTrustedRoots handle);

Objects created by calling CkTrustedRoots_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkTrustedRoots_Dispose.

Callback Functions

void CkTrustedRoots_setAbortCheck(HCkTrustedRoots cHandle, BOOL (*fnAbortCheck)(void));

Provides the opportunity for a method call to be aborted. If TRUE is returned, the operation in progress is aborted. Return FALSE to allow the current method call to continue. This callback function is called periodically based on the value of the HeartbeatMs property. (If HeartbeatMs is 0, then no callbacks are made.) As an example, to make 5 AbortCheck callbacks per second, set the HeartbeatMs property equal to 200.

void CkTrustedRoots_setPercentDone(HCkTrustedRoots cHandle, BOOL (*fnPercentDone)(int pctDone));

Provides the percentage completed for any method that involves network communications or time-consuming processing (assuming it is a method where a percentage completion can be measured). This callback is only called when it is possible to know a percentage completion, and when it makes sense to express the operation as a percentage completed. The pctDone argument will have a value from 1 to 100. For methods that complete very quickly, the number of PercentDone callbacks will vary, but the final callback should have a value of 100. For long running operations, no more than one callback per percentage point will occur (for example: 1, 2, 3, ... 98, 99, 100).

This callback counts as an AbortCheck callback, and takes the place of the AbortCheck event when it fires.

The return value indicates whether the method call should be aborted, or whether it should proceed. Return TRUE to abort, and FALSE to proceed.

void CkTrustedRoots_setProgressInfo(HCkTrustedRoots cHandle, void (*fnProgressInfo)(const char *name, const char *value));

This is a general callback that provides name/value information about what is happening at certain points during a method call. To see the information provided in ProgressInfo callbacks, if any, write code to handle this event and log the name/value pairs. Most are self-explanatory.

void CkTrustedRoots_setTaskCompleted(HCkTrustedRoots cHandle, void (*fnTaskCompleted)(HCkTask hTask));

Called in the background thread when an asynchronous task completes. (Note: When an async method is running, all callbacks are in the background thread.)

Properties

DebugLogFilePath
void CkTrustedRoots_getDebugLogFilePath(HCkTrustedRoots cHandle, HCkString retval);
void CkTrustedRoots_putDebugLogFilePath(HCkTrustedRoots cHandle, const char *newVal);
const char *CkTrustedRoots_debugLogFilePath(HCkTrustedRoots cHandle);

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.

More Information and Examples
top
LastErrorHtml
void CkTrustedRoots_getLastErrorHtml(HCkTrustedRoots cHandle, HCkString retval);
const char *CkTrustedRoots_lastErrorHtml(HCkTrustedRoots cHandle);

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.

top
LastErrorText
void CkTrustedRoots_getLastErrorText(HCkTrustedRoots cHandle, HCkString retval);
const char *CkTrustedRoots_lastErrorText(HCkTrustedRoots cHandle);

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.

top
LastErrorXml
void CkTrustedRoots_getLastErrorXml(HCkTrustedRoots cHandle, HCkString retval);
const char *CkTrustedRoots_lastErrorXml(HCkTrustedRoots cHandle);

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.

top
LastMethodSuccess
BOOL CkTrustedRoots_getLastMethodSuccess(HCkTrustedRoots cHandle);
void CkTrustedRoots_putLastMethodSuccess(HCkTrustedRoots cHandle, BOOL newVal);

Indicates the success or failure of the most recent method call: TRUE means success, FALSE 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.

top
NumCerts
int CkTrustedRoots_getNumCerts(HCkTrustedRoots cHandle);
Introduced in version 9.5.0.38

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.

top
RejectSelfSignedCerts
BOOL CkTrustedRoots_getRejectSelfSignedCerts(HCkTrustedRoots cHandle);
void CkTrustedRoots_putRejectSelfSignedCerts(HCkTrustedRoots cHandle, BOOL newVal);
Introduced in version 9.5.0.80

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.

ValueBehavior
FALSEDo not reject a one-certificate TLS chain solely because the certificate is self-signed.
TRUEReject 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.

top
TrustSystemCaRoots
BOOL CkTrustedRoots_getTrustSystemCaRoots(HCkTrustedRoots cHandle);
void CkTrustedRoots_putTrustSystemCaRoots(HCkTrustedRoots cHandle, BOOL newVal);
Introduced in version 9.5.0.41

Controls whether operating-system CA roots are included when this object's trust configuration is activated. The default value is TRUE.

ValueBehavior
TRUETrust explicitly added certificates and the system-provided CA roots available to Chilkat.
FALSEDo 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.

More Information and Examples
top
Utf8
BOOL CkTrustedRoots_getUtf8(HCkTrustedRoots cHandle);
void CkTrustedRoots_putUtf8(HCkTrustedRoots cHandle, BOOL newVal);

When set to TRUE, all const char * arguments and return values are interpreted as UTF-8 strings. When set to FALSE, they are interpreted as ANSI strings.

In Chilkat v11.0.0 and later, the default value is TRUE. Before v11.0.0, it was FALSE.

top
VerboseLogging
BOOL CkTrustedRoots_getVerboseLogging(HCkTrustedRoots cHandle);
void CkTrustedRoots_putVerboseLogging(HCkTrustedRoots cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
void CkTrustedRoots_getVersion(HCkTrustedRoots cHandle, HCkString retval);
const char *CkTrustedRoots_version(HCkTrustedRoots cHandle);

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

Activate
BOOL CkTrustedRoots_Activate(HCkTrustedRoots cHandle);
Introduced in version 9.5.0.38

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.

More Information and Examples
top
AddCert
BOOL CkTrustedRoots_AddCert(HCkTrustedRoots cHandle, HCkCert cert);
Introduced in version 9.5.0.41

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.

top
AddJavaKeyStore
BOOL CkTrustedRoots_AddJavaKeyStore(HCkTrustedRoots cHandle, HCkJavaKeyStore keystore);
Introduced in version 9.5.0.44

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.

Returns TRUE for success, FALSE for failure.

top
AddJavaKeyStoreAsync (1)
HCkTask CkTrustedRoots_AddJavaKeyStoreAsync(HCkTrustedRoots cHandle, HCkJavaKeyStore keystore);
Introduced in version 9.5.0.44

Creates an asynchronous task to call the AddJavaKeyStore method with the arguments provided.

Returns NULL on failure

top
CertAt
BOOL CkTrustedRoots_CertAt(HCkTrustedRoots cHandle, int index, HCkCert cert);
Introduced in version 11.0.0

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.

Returns TRUE for success, FALSE for failure.

top
Deactivate
BOOL CkTrustedRoots_Deactivate(HCkTrustedRoots cHandle);
Introduced in version 9.5.0.40

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.

Returns TRUE for success, FALSE for failure.

top
LoadCaCertsPem
BOOL CkTrustedRoots_LoadCaCertsPem(HCkTrustedRoots cHandle, const char *path);
Introduced in version 9.5.0.38

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.

More Information and Examples
top
LoadCaCertsPemAsync (1)
HCkTask CkTrustedRoots_LoadCaCertsPemAsync(HCkTrustedRoots cHandle, const char *path);
Introduced in version 9.5.0.38

Creates an asynchronous task to call the LoadCaCertsPem method with the arguments provided.

Returns NULL on failure

top
LoadTaskCaller
BOOL CkTrustedRoots_LoadTaskCaller(HCkTrustedRoots cHandle, HCkTask task);
Introduced in version 9.5.0.80

Associates task with the object that initiated the task's asynchronous method call. This supports Chilkat's asynchronous task infrastructure and is not normally called directly by application code.

Returns TRUE if the task caller was loaded successfully; otherwise returns FALSE.

Returns TRUE for success, FALSE for failure.

top

Deprecated

GetCert
HCkCert CkTrustedRoots_GetCert(HCkTrustedRoots cHandle, int index);
Introduced in version 9.5.0.38
This method is deprecated and replaced by CertAt

Returns the certificate at zero-based index in this object's explicitly added certificate collection.

This method is deprecated. New applications should call CertAt, which returns an explicit success/failure result and stores the certificate in a caller-supplied Cert object.

Valid indexes are from 0 through NumCerts - 1. Operating-system roots enabled by TrustSystemCaRoots are not part of this indexed collection.

Returns NULL on failure

More Information and Examples
top