CertStore C Library Reference

CertStore

* This is a freeware class/C library/library.

Represents a collection of certificates. The certificates may be loaded from a PFX (PKCS#12) or from a Windows-based certificate store.

Many of the methods of this class are only applicable when running on a MS Windows operating system. The methods for opening, creating, and modifying Windows-based certificate stores (registry-based, file-based, and memory-based) are (of course) Windows-only. However, the methods for loading certs from PFX (PKCS#12), are valid on all supported operating systems, including Linux, MAC OS X, Windows, etc.

Create/Dispose

HCkCertStore CkCertStore_Create(void);

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

void CkCertStore_Dispose(HCkCertStore handle);

Objects created by calling CkCertStore_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

C "Properties"

BOOL CkCertStore_getAvoidWindowsPkAccess(HCkCertStore cHandle);
void CkCertStore_putAvoidWindowsPkAccess(HCkCertStore cHandle, BOOL newVal);

Applies only when running on a Microsoft Windows operating system. If true, then any method that returns a certificate will not try to also access the associated private key, assuming one exists. This is useful if the certificate was installed with high-security such that a private key access would trigger the Windows OS to display a security warning dialog. The default value of this property is false.

void CkCertStore_getLastErrorHtml(HCkCertStore cHandle, HCkString retval);

Error information in HTML format for the last method called.

void CkCertStore_getLastErrorText(HCkCertStore cHandle, HCkString retval);

Error information in plain-text format for the last method called.

void CkCertStore_getLastErrorXml(HCkCertStore cHandle, HCkString retval);

Error information in XML format for the last method called.

long CkCertStore_getNumCertificates(HCkCertStore cHandle);

The number of certificates held in the certificate store.

BOOL CkCertStore_getUtf8(HCkCertStore cHandle);
void CkCertStore_putUtf8(HCkCertStore cHandle, BOOL newVal);

When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.

BOOL CkCertStore_getVerboseLogging(HCkCertStore cHandle);
void CkCertStore_putVerboseLogging(HCkCertStore cHandle, BOOL newVal);

If set to true, then the LastErrorText may contain more verbose logging.

void CkCertStore_getVersion(HCkCertStore cHandle, HCkString retval);

The version of this component, such as "1.0"

C "Methods"

HCkCert CkCertStore_FindCertByRfc822Name(HCkCertStore cHandle, const char *name);

Locates a certificate by its RFC 822 name and returns it if found.

Returns NULL on failure.

HCkCert CkCertStore_FindCertBySerial(HCkCertStore cHandle, const char *serialNumber);

Finds and returns the certificate that has the matching serial number.

Returns NULL on failure.

HCkCert CkCertStore_FindCertBySha1Thumbprint(HCkCertStore cHandle, const char *str);

Finds a certificate by it's SHA-1 thumbprint. The thumbprint is a hexidecimal string.

Returns NULL on failure.

HCkCert CkCertStore_FindCertBySubject(HCkCertStore cHandle, const char *subject);

Finds a certificate where one of the Subject properties (SubjectCN, SubjectE, SubjectO, SubjectOU, SubjectL, SubjectST, SubjectC) matches exactly (but case insensitive) with the passed string. A match in SubjectCN will be tried first, followed by SubjectE, and SubjectO. After that, the first match found in SubjectOU, SubjectL, SubjectST, or SubjectC, but in no guaranteed order, is returned. All matches are case insensitive.

Returns NULL on failure.

HCkCert CkCertStore_FindCertBySubjectCN(HCkCertStore cHandle, const char *commonName);

Finds a certificate where the SubjectCN property (common name) matches exactly (but case insensitive) with the passed string

Returns NULL on failure.

HCkCert CkCertStore_FindCertBySubjectE(HCkCertStore cHandle, const char *emailAddress);

Finds a certificate where the SubjectE property (email address) matches exactly (but case insensitive) with the passed string. This function differs from FindCertForEmail in that the certificate does not need to match the ForSecureEmail property.

Returns NULL on failure.

HCkCert CkCertStore_FindCertBySubjectO(HCkCertStore cHandle, const char *organization);

Finds a certificate where the SubjectO property (organization) matches exactly (but case insensitive) with the passed string.

Returns NULL on failure.

HCkCert CkCertStore_GetCertificate(HCkCertStore cHandle, long index);

Returns the Nth certificate in the store. The first certificate is at index 0.

Returns NULL on failure.

BOOL CkCertStore_LoadPfxData(HCkCertStore cHandle, HCkByteData pfxData, const char *password);

Loads a PFX from an in-memory image of a PFX file. Once loaded, the certificates within the PFX may be searched via the Find* methods. It is also possible to iterate from 0 to NumCertficates-1, calling GetCertificate for each index, to retrieve each certificate within the PFX.

Returns TRUE for success, FALSE for failure.

BOOL CkCertStore_LoadPfxData2(HCkCertStore cHandle, const unsigned char *buf, unsigned long bufLen, const char *password);

Loads a PFX from an in-memory image of a PFX file. Once loaded, the certificates within the PFX may be searched via the Find* methods. It is also possible to iterate from 0 to NumCertficates-1, calling GetCertificate for each index, to retrieve each certificate within the PFX.

Returns TRUE for success, FALSE for failure.

BOOL CkCertStore_LoadPfxFile(HCkCertStore cHandle, const char *filename, const char *password);

Loads a PFX file. Once loaded, the certificates within the PFX may be searched via the Find* methods. It is also possible to iterate from 0 to NumCertficates-1, calling GetCertificate for each index, to retrieve each certificate within the PFX.

Returns TRUE for success, FALSE for failure.

BOOL CkCertStore_SaveLastError(HCkCertStore cHandle, const char *filename);

Saves the last error information to an XML formatted file.

const char *CkCertStore_lastErrorHtml(HCkCertStore cHandle);

Error information in HTML format for the last method called.

Returns a null on failure

const char *CkCertStore_lastErrorText(HCkCertStore cHandle);

Error information in plain-text format for the last method called.

Returns a null on failure

const char *CkCertStore_lastErrorXml(HCkCertStore cHandle);

Error information in XML format for the last method called.

Returns a null on failure

const char *CkCertStore_version(HCkCertStore cHandle);

The version of this component, such as "1.0"

Returns a null on failure