The client application must access the certificate from the Windows certificate store. Search input is the subject name in the X500 string format, as shown below.
"C=CH, S=Aargau, L=Baden, O=Test, OU=FF, CN= Test Root"
Exact matching is required (non-subscript matching using CERT_FIND_SUBJECT_STR). For this I do the following
CERT_NAME_BLOB subjectname = {0};
bRet = CertStrToNameA(X509_ASN_ENCODING, "C=CH, S=Aargau, L=Baden, O=Test, OU=S1, CN= Test Root", CERT_X500_NAME_STR, NULL, NULL, &size, NULL);
if(TRUE == bRet)
{
subjectname.pbData = (BYTE*)malloc(size);
subjectname.cbData = size;
bRet = CertStrToNameA(X509_ASN_ENCODING , "C=CH, S=Aargau, L=Baden, O=Test, OU=S1, CN=Test Root", CERT_X500_NAME_STR, NULL, subjectname.pbData, &subjectname.cbData, NULL);
if(TRUE == bRet)
{
capiCertificate = CertFindCertificateInStore(hStore, X509_ASN_ENCODING, 0, CERT_FIND_SUBJECT_NAME, &subjectname, NULL);
if (NULL == capiCertificate)
{
errorcode = GetLastError();
ret = CA_CERT_NOT_FOUND;
}
}
}
The problem is that CertFindCertificateInStore always returns a NULL pointer. I debugged, but could not find out what was going on here.
Any suggestions would be very helpful.