CertEnumCertificateContextProperties

The CertEnumCertificateContextProperties function enumerates the properties for the specified certificate context.

#include <wincrypt.h>
DWORD WINAPI CertEnumCertificateContextProperties(
  PCCERT_CONTEXT pCertContext,  // in
  DWORD dwPropId                // in
);
 

Parameters

pCertContext
Pointer to the specified certificate context.
dwPropId
To get the first property, set dwPropId to 0. The ID of the first property is returned. To get the next property, set dwPropId to the ID returned by the last call. To enumerate all the properties, continue enumerating them until 0 is returned.

For any given dwPropId returned, an application may call CertGetCertificateContextProperty to get that property's data.

Return Values

The return value is described under dwPropId in the preceding text.

Call GetLastError to see the reason for any failures.

Remarks

Since the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID property, they aren't enumerated individually.

Example

// 
// Enumerate (List) the property id numbers of a certificate context
// using CertEnumCertificateContextProperties.  
//
// handle_error() is a function defined in a separate file.
//
HANDLE           hCertStore;        
PCCERT_CONTEXT   pCertContext;      
void*            pvData;
DWORD            cbData;
DWORD            dwPropId = 0;   // 0 must be used on the first
                                 // call to the function. After that,
                                 // the last returned property id is passed.

// Open a file based certificate store. 
// For details, see CertOpenStore.
if (hCertStore = CertOpenStore(
CERT_STORE_PROV_FILENAME,0,NULL,0,L"TESTSTOR.STO"))
printf("The file store is open. Continue.\n");
else
handle_error("The file based store did not open.");
// Get a certificate from the open store.
if(pCertContext= CertEnumCertificatesInStore(
hCertStore,NULL))
printf("A certificate has been retrieved. Continue. \n");
else
handle_error("No certificate retrieved. The store may be empty.");
// In a loop, find all of the property IDs for the given certificate.
// The loop continues until the function returns a 0.
while(dwPropId = CertEnumCertificateContextProperties(
pCertContext, // the context whose properties are to be listed.
       dwPropId))    // number of the last property found. Must be
                     // 0 to find the first property id.
{
   //
// When the loop is executed, a property id has been found.
// Retrieve information on that property by first getting its size 
// For details, see CertGetCertificateContextProperty.
   //
if(CertGetCertificateContextProperty   
(pCertContext, dwPropId , NULL, &cbData))
printf("Call #1 succeeded. Continue. \n");
else
handle_error("Call #1 to the function failed.");
// Allocate memory.
if(pvData = (void*)malloc(cbData))
printf("Allocation succeeded. Retrieve the property data.\n");
else
handle_error("Memory allocation failed.");\
if(CertGetCertificateContextProperty(
pCertContext,dwPropId,pvData, &cbData))
printf("The function succeeded. Continue.\n");
else
handle_error("Call #2 to the function failed.\n");
// Show the results
printf("Length %d  \n",cbData);
printf("The Content of pbData is %d \n", pvData);
// Free the certificate context property memory when finished with it.
free(pvData);
} // end while

// Free the certificate context. 
CertFreeCertificateContext(pCertContext);
CertCloseStore(hCertStore,0);
printf("The function completed successfully. \n"); 
 

QuickInfo

  Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
  Windows: Requires Windows 95 OSR2 or later.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.