Home > other >  Fetch SCT list from x509 certificate
Fetch SCT list from x509 certificate

Time:02-18

enter image description here

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();
}
  • Related