---
product: Chilkat
product_version: 11.7.0
language: sqlserver
language_label: SQL Server
class: CertChain
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/sqlserver_CertChainRef.html
---
# Chilkat CertChain — SQL Server — v11.7.0

> Chilkat 11.7.0 · language=sqlserver · class=CertChain
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/CertChain.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/guide.md`.

## Purpose

**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](https://www.chilkatsoft.com/certchain_class_overview.asp).

## Object creation, unlocking and error handling

**Object Creation**

```sql
DECLARE @hr int
DECLARE @certChain int
EXEC @hr = sp_OACreate 'Chilkat.CertChain', @certChain OUT
IF @hr <> 0
BEGIN
    PRINT 'Failed to create ActiveX component'
    RETURN
END

-- ... use @certChain ...

EXEC @hr = sp_OADestroy @certChain
```

T-SQL uses the Chilkat ActiveX through the OLE Automation stored procedures. They must be enabled once on the server (`EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;`), and the Chilkat ActiveX registered must match the bitness of the SQL Server instance (64-bit for a 64-bit SQL Server). To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `sp_OACreate 'Chilkat.CertChain.11'` for Chilkat v11.\*.\*.

`sp_OACreate` returns an object token (an `int`) that is passed as the first argument of every `sp_OAMethod`, `sp_OAGetProperty` and `sp_OASetProperty` call, and released with `sp_OADestroy`. Objects returned by methods (such as an `HttpResponse` or `JsonObject`) are also tokens received through an `int` OUT parameter; they must likewise be destroyed, and the OUT parameter is `NULL` when the method fails to return an object. Objects passed as arguments are passed by their token. When an OLE Automation procedure itself fails (non-zero `@hr`), `sp_OAGetErrorInfo` describes the error.

Data types: strings are `nvarchar(4000)`; integers, booleans (1 or 0) and object tokens are `int`; dates are `datetime`. In the signatures on this page, `@success`, `@iResult`, `@sResult` and the like are the OUT variables receiving a method's return value, `@iValue` / `@sValue` receive or supply a property value, and the remaining `@` variables are the method's arguments in order.

A string returned through an OUT parameter is limited to 4000 characters. For longer values, retrieve the result as a result set into a table variable instead of an OUT parameter, for example `DECLARE @tmp TABLE (outputLine ntext)` followed by `INSERT INTO @tmp EXEC sp_OAGetProperty @certChain, 'LastErrorText'`. See [string length limitations for strings returned by sp_OAMethod calls](https://www.chilkatsoft.com/sql_server_nvarchar_max_limitation.asp).

Methods that pass or return raw byte arrays are not shown on this page, because `varbinary(max)` values cannot be exchanged through `sp_OAMethod` (see [varbinary(max) limitation](https://www.chilkatsoft.com/sql_server_varbinary_max_limitation.asp)). Use the `BinData`-based alternatives (methods ending in *Bd*) or the base64 / hex string-encoded variants instead. Binary *properties* (such as `LastBinaryResult`) can be retrieved as a result set into a table variable, as shown in their signatures. Asynchronous (*\*Async*) methods and event callbacks are not available from SQL Server.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in SQL Server.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `EXEC sp_OAGetProperty @certChain, 'DebugLogFilePath', @sValue OUT EXEC sp_OASetProperty @certChain, 'DebugLogFilePath', @sValue` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `INSERT INTO @tmp EXEC sp_OAGetProperty @certChain, 'LastBinaryResult'` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `EXEC sp_OAGetProperty @certChain, 'LastErrorHtml', @sValue OUT` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `EXEC sp_OAGetProperty @certChain, 'LastErrorText', @sValue OUT` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `EXEC sp_OAGetProperty @certChain, 'LastErrorXml', @sValue OUT` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `EXEC sp_OAGetProperty @certChain, 'LastMethodSuccess', @iValue OUT EXEC sp_OASetProperty @certChain, 'LastMethodSuccess', @iValue` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `EXEC sp_OAGetProperty @certChain, 'LastStringResult', @sValue OUT` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `EXEC sp_OAGetProperty @certChain, 'LastStringResultLen', @iValue OUT` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `EXEC sp_OAGetProperty @certChain, 'VerboseLogging', @iValue OUT EXEC sp_OASetProperty @certChain, 'VerboseLogging', @iValue` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `EXEC sp_OAGetProperty @certChain, 'Version', @sValue OUT` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `NumCerts` | property, read-only | `EXEC sp_OAGetProperty @certChain, 'NumCerts', @iValue OUT` |
| `NumExpiredCerts` | property, read-only | `EXEC sp_OAGetProperty @certChain, 'NumExpiredCerts', @iValue OUT` |
| `ReachesRoot` | property, read-only | `EXEC sp_OAGetProperty @certChain, 'ReachesRoot', @iValue OUT` |
| `UncommonOptions` | property, read/write | `EXEC sp_OAGetProperty @certChain, 'UncommonOptions', @sValue OUT EXEC sp_OASetProperty @certChain, 'UncommonOptions', @sValue` |
| `CertAt` | method | `EXEC sp_OAMethod @certChain, 'CertAt', @success OUT, @index, @cert` |
| `IsRootTrusted` | method | `EXEC sp_OAMethod @certChain, 'IsRootTrusted', @success OUT, @trustedRoots` |
| `LoadX5C` | method | `EXEC sp_OAMethod @certChain, 'LoadX5C', @success OUT, @jwk` |
| `VerifyCertSignatures` | method | `EXEC sp_OAMethod @certChain, 'VerifyCertSignatures', @success OUT` |
| `X509PKIPathv1` | method | `EXEC sp_OAMethod @certChain, 'X509PKIPathv1', @sResult OUT` |

Deprecated members are listed at the end of this file with their replacements; do not use them in new code.

## Properties

### CertChain.NumCerts

`Chilkat 11.7.0 · sqlserver · CertChain · NumCerts · property · read-only · since 9.5.0.40`

```sql
EXEC sp_OAGetProperty @certChain, 'NumCerts', @iValue OUT
```

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 |

**Do not assume the final certificate is trusted:** If `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.

### CertChain.NumExpiredCerts

`Chilkat 11.7.0 · sqlserver · CertChain · NumExpiredCerts · property · read-only · since 9.5.0.40`

```sql
EXEC sp_OAGetProperty @certChain, 'NumExpiredCerts', @iValue OUT
```

The number of certificates in the chain whose validity period has expired.

**Expiration is only one validation check:** A value of `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.

### CertChain.ReachesRoot

`Chilkat 11.7.0 · sqlserver · CertChain · ReachesRoot · property · read-only · since 9.5.0.44`

```sql
EXEC sp_OAGetProperty @certChain, 'ReachesRoot', @iValue OUT
```

`1` 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 `NumCerts - 1` is 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 `IsRootTrusted` with the application's approved `TrustedRoots` collection to test trust-anchor membership.

A value of `0` means the chain is incomplete at the root end; the final certificate may be an intermediate CA for which no issuer certificate was available.

### CertChain.UncommonOptions

`Chilkat 11.7.0 · sqlserver · CertChain · UncommonOptions · property · read/write · since 9.5.0.98`

```sql
EXEC sp_OAGetProperty @certChain, 'UncommonOptions', @sValue OUT
EXEC sp_OASetProperty @certChain, 'UncommonOptions', @sValue
```

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. |

**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.

## Methods

### CertChain.CertAt

`Chilkat 11.7.0 · sqlserver · CertChain · CertAt · method · since 11.0.0`

```sql
EXEC sp_OAMethod @certChain, 'CertAt', @success OUT, @index, @cert
```

Populates `cert` with the certificate at the specified zero-based `index`. 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 `1` |

Returns `1` on success. Returns `0` if the index is invalid or the certificate cannot be returned; in that case, do not use the contents of `cert` as a successful result.

Returns 1 for success, 0 for failure.

### CertChain.IsRootTrusted

`Chilkat 11.7.0 · sqlserver · CertChain · IsRootTrusted · method · since 9.5.0.40`

```sql
EXEC sp_OAMethod @certChain, 'IsRootTrusted', @success OUT, @trustedRoots
```

Tests whether the certificate at the root end of this chain is present in the `TrustedRoots` collection passed in `trustedRoots`. Returns `1` when a matching trusted-root certificate is found; otherwise returns `0`.

**Trust 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.

### CertChain.LoadX5C

`Chilkat 11.7.0 · sqlserver · CertChain · LoadX5C · method · since 9.5.0.66`

```sql
EXEC sp_OAMethod @certChain, 'LoadX5C', @success OUT, @jwk
```

Loads the certificate chain from the `x5c` member of the JWK contained in `jwk`. Returns `1` if the chain is loaded successfully; otherwise returns `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.

**Security note:** Loading an `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 1 for success, 0 for failure.

### CertChain.VerifyCertSignatures

`Chilkat 11.7.0 · sqlserver · CertChain · VerifyCertSignatures · method · since 9.5.0.40`

```sql
EXEC sp_OAMethod @certChain, 'VerifyCertSignatures', @success OUT
```

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 `1` when the certificate signatures are valid through the root end of the chain; otherwise returns `0`.

**Signature verification is not full path validation:** A `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.

### CertChain.X509PKIPathv1

`Chilkat 11.7.0 · sqlserver · CertChain · X509PKIPathv1 · method · since 9.5.0.88`

```sql
EXEC sp_OAMethod @certChain, 'X509PKIPathv1', @sResult OUT
```

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.

**Return-value note:** This is a string-returning method. Check `LastMethodSuccess` before using the returned text, and inspect `LastErrorText` if the operation fails.

Returns `NULL` on failure

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `GetCert` | method | before 11.6.1 | `CertAt` |

## Related classes

[`Cert`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/Cert.md), [`JsonObject`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/JsonObject.md), [`TrustedRoots`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/TrustedRoots.md)

