CertGetSubjectCertificateFromStore() problem....
- From: "Wendy Moore" <WenMoore@xxxxxxxxx>
- Date: Fri, 14 Jul 2006 07:27:34 +0200
Hi,
I want to search for a specific certificate in my certificate store
by using this api CertGetSubjectCertificateFromStore(). It uses
the Issuer and serial number for defining the cert in question.\
I always get the cert not found error!
If I get a list of all the certificates in the store and watch to the
certinfo structure (SerialNumber and Issuer)
I get exactly the same values as these that I define for the search...
Here is a part of the code
CERT_INFO tCertInfo;
PCCERT_CONTEXT pSignerCertContext=NULL;
LPSTR pszName;
DWORD cbName = 8192;
DWORD dwStrType =
CERT_OID_NAME_STR|CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG;
PCERT_BLOB pCert_Blob=NULL;
char a_cDN [1024];
strcpy(a_cDN, "c=nl,cn=CA");
if(!(pszName = (char *)malloc(cbName)))
{
printf ("Memory allocation failed.");
}
//--------------------------------------------------------------------
// Get the length needed to convert the string back
// back into the name as it was in the certificate.
if(!(CertStrToName(
PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
a_cDN,
dwStrType,
NULL,
NULL, // NULL to get the number of bytes
// needed for the buffer.
&cbName, // Pointer to a DWORD to hold the
// number of bytes needed for the
// buffer
NULL ))) // Optional address of a pointer to
// old the location for an error in the
// input string.
{
printf("Could not get the lenth of the BLOB.");
}
if ( (pCert_Blob=(CERT_BLOB *)malloc(cbName)) == NULL )
{
printf ("Memory Allocation for the BLOB failed.");
}
if(CertStrToName(
PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
a_cDN,
dwStrType,
NULL,
(BYTE *)pCert_Blob,
&cbName,
NULL))
{
printf("CertStrToName created the BLOB.\n");
}
else
{
printf("Could not create the BLOB.");
}
memset(&tCertInfo, '\0', sizeof(tCertInfo));
tCertInfo.Issuer.cbData = cbName;
tCertInfo.Issuer.pbData = (unsigned char *) pCert_Blob;
tCertInfo.SerialNumber.cbData=2;
tCertInfo.SerialNumber.pbData=(unsigned char
*)malloc(tCertInfo.SerialNumber.cbData);
tCertInfo.SerialNumber.pbData[0]=0x2a;
tCertInfo.SerialNumber.pbData[1]=0x01;
if ( pSignerCertContext =
CertGetSubjectCertificateFromStore(hSysStore,
PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
&tCertInfo))
{
printf ("Cert Found\n");
}
else
{
printf ("Cert NOT Found:[%d]\n", GetLastError());
}
.
- Prev by Date: Re: Domain local groups not in tokens. Was: Confusing Effective Permissions for serviceConnectionPoint objects
- Next by Date: Re: Domain local groups not in tokens. Was: Confusing Effective Permissions for serviceConnectionPoint objects
- Previous by thread: can not grant full control access using EXPLICIT_ACCESS
- Next by thread: Digital signature check on binaries
- Index(es):
Relevant Pages
|