检索证书吊销列表
证书颁发机构 (CA) 负责将其 证书吊销列表 (CRL) 发布。 可以使用 ICertAdmin2::GetCRL 方法检索当前 CRL。 如果 CA 的证书已续订,可能需要检索以前的 CA 证书的 CRL。 有关 CA 续订的信息,请参阅 证书颁发机构续订。 此外,CA 可能会发布增量 CRL。 若要检索续订的 CA 证书或增量 CRL 的 CRL,请使用 ICertAdmin2::GetCAProperty 或 ICertRequest2::GetCAProperty 方法。
以下示例演示如何检索当前 CRL。
ICertAdmin2 * pCertAdmin2 = NULL; // pointer to interface object
BSTR bstrCA = NULL; // variable for computer\CAname
BSTR bstrCRL = NULL; // variable to contain the retrieved CRL
HRESULT hr;
// Initialize COM.
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
printf("Failed CoInitializeEx [%x]\n", hr);
goto error;
}
// Create the CertAdmin object,
// and get a pointer to its ICertAdmin interface.
hr = CoCreateInstance( CLSID_CCertAdmin,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICertAdmin2,
(void **)&pCertAdmin2);
if (FAILED(hr))
{
printf("Failed CoCreateInstance pCertAdmin2 [%x]\n", hr);
goto error;
}
// Note the use of two '\' in C++ to produce one '\'.
bstrCA = SysAllocString(L"<COMPUTERNAMEHERE>\\<CANAMEHERE>");
if (bstrCA == NULL)
{
printf("Failed to allocate memory for bstrCA\n");
goto error;
}
// Retrieve the CRL.
hr = pCertAdmin2->GetCRL( bstrCA, CR_OUT_BINARY, &bstrCRL );
if (FAILED(hr))
{
printf("Failed GetCRL [%x]\n", hr);
goto error;
}
else
printf("CRL retrieved successfully\n");
// Use the CRL as needed...
// Processing is finished.
error:
// Free BSTR values.
if (NULL != bstrCA)
SysFreeString(bstrCA);
if (NULL != bstrCRL)
SysFreeString(bstrCRL);
// Clean up object resources.
if (NULL != pCertAdmin2)
pCertAdmin2->Release();
// Free COM resources.
CoUninitialize();
以下示例演示如何检索基本 CRL 和增量 CRL,包括已续订的 CA 证书的 CRL。 此示例使用 ICertAdmin2::GetCAProperty,尽管 ICertRequest2::GetCAProperty 提供类似的功能。
LONG nCACertCount, nIndex, nCRLState;
VARIANT variant;
VariantInit(&variant);
// Determine the number of CA certificates.
hr = pCertAdmin2->GetCAProperty(bstrCA,
CR_PROP_CASIGCERTCOUNT,
0,
PROPTYPE_LONG,
CR_OUT_BINARY,
&variant);
if (FAILED(hr))
{
printf("Failed call to GetCAProperty - "
"CR_PROP_CASIGCERTCOUNT\n");
goto error;
}
nCACertCount = variant.lVal;
VariantClear(&variant);
for (nIndex = 0; nIndex < nCACertCount; nIndex++)
{
// Determine the CRL state for each certificate index.
hr = pCertAdmin2->GetCAProperty(bstrCA,
CR_PROP_CRLSTATE,
nIndex,
PROPTYPE_LONG,
CR_OUT_BINARY,
&variant);
if (FAILED(hr))
{
printf("Failed call to GetCAProperty - "
"CR_PROP_CRLSTATE\n");
goto error;
}
nCRLState = variant.lVal;
VariantClear(&variant);
// Process certificate indices only when
// the CRL state is valid.
if (CA_DISP_VALID == nCRLState)
{
// Retrieve the base CRL.
hr = pCertAdmin2->GetCAProperty(bstrCA,
CR_PROP_BASECRL,
nIndex,
PROPTYPE_BINARY,
CR_OUT_BINARY,
&variant);
if (FAILED(hr))
{
printf("Failed call to GetCAProperty - "
"CR_PROP_BASECRL\n");
goto error;
}
// Use the base CRL as needed (not shown).
// ...
VariantClear(&variant);
// Retrieve the delta CRL.
hr = pCertAdmin2->GetCAProperty(bstrCA,
CR_PROP_DELTACRL,
nIndex,
PROPTYPE_BINARY,
CR_OUT_BINARY,
&variant);
if (FAILED(hr))
{
printf("Failed call to GetCAProperty - "
"CR_PROP_DELTACRL\n");
goto error;
}
// Use the delta CRL as needed (not shown).
// ...
VariantClear(&variant);
}
}
// Processing is finished.
error:
// Clean up object resources.
if ( NULL != pCertAdmin2 )
pCertAdmin2->Release();
// Free BSTR variables.
if ( NULL != bstrCA )
SysFreeString ( bstrCA );
// Clear the variant.
VariantClear(&variant);
```