【问题标题】:Unhandled exception calling CertCreateCertificateChainEngine function调用 CertCreateCertificateChainEngine 函数的未处理异常
【发布时间】:2017-01-20 16:45:01
【问题描述】:

我正在关注微软Example C Program: Creating a Certificate Chain的本教程

但我在以下块调用 CertCreateCertificateChainEngine 函数得到未处理的异常

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

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

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

异常信息是:

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

以下是变量的定义方式:

HCERTCHAINENGINE         hChainEngine = NULL;
CERT_CHAIN_ENGINE_CONFIG ChainConfig;

ChainConfig 结构初始化为:

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 函数具有以下签名:

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

这是ChainConfig的调试截图:

hChainEngine 显示为 NULL,例如0x00000000

【问题讨论】:

    标签: c visual-c++ cryptoapi


    【解决方案1】:

    我想出了这个异常的原因。问题是由于在 Windows 7 之后进行了更改,我们也应该初始化 hExclusivrTrustPeople 和 hExclusiveRoot 成员。因此,对于较新的 Windows 系统,上述文章有点过时了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 2023-01-25
      • 2011-11-19
      相关资源
      最近更新 更多