How can I fetch this SCT list from PCCERT_CONTEXT? Is there any straightforward win API?
CodePudding user response:
With the following code snippet, I could able to fetch the SCT list as a string from X509 certificate
std::wstring GetSCTString(PCCERT_CONTEXT certInfo)
{
PCERT_EXTENSION ext;
ext = CertFindExtension(szOID_CT_CERT_SCTLIST, certInfo->pCertInfo->cExtension, certInfo->pCertInfo->rgExtension);
if (NULL != ext)
{
DWORD strSz(0);
if (CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, szOID_CT_CERT_SCTLIST, ext->Value.pbData, ext->Value.cbData, NULL, &strSz))
{
std::wstring Buff;
Buff.resize((strSz / sizeof(wchar_t)) 1);
if (CryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, szOID_CT_CERT_SCTLIST, ext->Value.pbData, ext->Value.cbData, (void*)Buff.data(), &strSz))
{
return Buff;
}
}
}
return std::wstring();
}