I'm trying to retrieve certificates from the local store by subject alternate name. Currently, the only option I see if to retrieve it by subject name. This is my code:
PCCERT_CONTEXT GetCertFromSubject(const std::wstring& subjectName)
{
PCCERT_CONTEXT cert = nullptr;
HCERTSTORE hStoreHandle = CertOpenStore(
CERT_STORE_PROV_SYSTEM,
0,
nullptr,
CERT_SYSTEM_STORE_CURRENT_USER,
L"MY");
if (hStoreHandle == nullptr)
{
// throw
}
cert = CertFindCertificateInStore(
hStoreHandle,
X509_ASN_ENCODING,
0,
CERT_FIND_SUBJECT_STR,
subjectName.c_str(),
nullptr);
CertCloseStore(hStoreHandle, CERT_CLOSE_STORE_CHECK_FLAG);
return cert;
}
This works great if I pass in the subject name to the function. I would like to look up by SAN, but don't see any options. Appreciate any help here!