madz
madz

Reputation: 1873

Unhandled exception calling CertCreateCertificateChainEngine function

I'm following this tutorial from Microsoft Example C Program: Creating a Certificate Chain

But I get Unhandled exception calling CertCreateCertificateChainEngine function at the following block

if(CertCreateCertificateChainEngine(
     &ChainConfig,
     &hChainEngine)) {

    printf("A chain engine has been created.\n");
}
else {

    MyHandleError("The engine creation function failed.");
}

Exception message is:

Unhandled exception at 0x7535F61A (crypt32.dll) in capi_verify.exe: 0xC0000005: Access violation writing location 0xCCCCCCD0.

Here is how the variables are defined:

HCERTCHAINENGINE         hChainEngine = NULL;
CERT_CHAIN_ENGINE_CONFIG ChainConfig;

and the ChainConfig struct is initialized as:

ChainConfig.cbSize = sizeof(CERT_CHAIN_ENGINE_CONFIG);
ChainConfig.hRestrictedRoot= NULL ;
ChainConfig.hRestrictedTrust= NULL ;
ChainConfig.hRestrictedOther= NULL ;
ChainConfig.cAdditionalStore=0 ;
ChainConfig.rghAdditionalStore = NULL ;
ChainConfig.dwFlags = CERT_CHAIN_CACHE_END_CERT;
ChainConfig.dwUrlRetrievalTimeout= 0 ;
ChainConfig.MaximumCachedCertificates=0 ;
ChainConfig.CycleDetectionModulus = 0;

CertCreateCertificateChainEngine function has the following signature:

BOOL WINAPI CertCreateCertificateChainEngine(
  _In_  PCERT_CHAIN_ENGINE_CONFIG pConfig,
  _Out_ HCERTCHAINENGINE          *phChainEngine
);

And here is the debug screenshot of ChainConfig:

ChainConfig

hChainEngine is shown as NULL e.g. 0x00000000

Upvotes: 0

Views: 280

Answers (1)

madz
madz

Reputation: 1873

I figured the cause of this exception. The problem was that due to changes have been made after windows 7 we should initialize hExclusivrTrustPeople and hExclusiveRoot members too. So the mentioned article is sort of outdated for newer windows systems

Upvotes: 1

Related Questions