Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CertFindCertificateInStore() and CERT_FIND_SUBJECT_NAME flag

550 views
Skip to first unread message

Petar Popara

unread,
Jan 11, 2005, 5:08:26 AM1/11/05
to

I can't make it to work. It never finds certificate. :(

I get subject name from cert like this:

CertNameToStr(MY_ENCODING_TYPE,
&pCertContext->pCertInfo->Subject,
CERT_X500_NAME_STR,
pszNameString,
255);

then store it, and then try to find cert in the store:

CERT_NAME_BLOB subBlob;
subBlob.pbData = (BYTE*)subject; //unicode
subBlob.cbData = SysStringLen(subject);

PCCERT_CONTEXT pCert = CertFindCertificateInStore(hMYStoreHandle,
MY_ENCODING_TYPE,
0,
CERT_FIND_SUBJECT_NAME,
&subBlob,
NULL);

it allways fails (pCert == 0). I'm using WinXP Pro SP 2 with IE6.


Sergio Dutra [MS]

unread,
Jan 11, 2005, 10:14:49 AM1/11/05
to
The name blob is encoded in a specific way. It's not just a string/size of
string structure, as you have below.

Some code that should work:

// Get the name blob
CERT_NAME_BLOB suBlob;
suBlob.cbData = pCertContext->pCertInfo->Subject.cbData;
suBlob.pbData = new BYTE[suBlob.cbData];
if (NULL != suBlob.pbData) {
CopyMemory(suBlob.pbData, pCertContext->pCertInfo->Subject.pbData,
suBlob.cbData);
}

// Now persist the blob somewhere, and later find the cert using this blob
as you have below

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Petar Popara" <my....@mail.net> wrote in message
news:OR6hGU89...@TK2MSFTNGP15.phx.gbl...

Petar Popara

unread,
Jan 12, 2005, 3:30:11 AM1/12/05
to

I have to store subject name as a string:

CN=Badb, O=Baltimore Technologies, ST=Dublin, C=IE

and then to read it and find corresponding cert. I've tried this:

CERT_NAME_BLOB * subBlob;
DWORD subBlobLen = 0;

if (!CertStrToName(MY_ENCODING_TYPE,
"CN=Badb, O=Baltimore Technologies, ST=Dublin, C=IE",
CERT_X500_NAME_STR,
NULL,
NULL,
&subBlobLen,
NULL))
{
//error
}

subBlob = new CERT_NAME_BLOB[subBlobLen];

if (!CertStrToName(MY_ENCODING_TYPE,
"CN=Badb, O=Baltimore Technologies, ST=Dublin, C=IE",
CERT_X500_NAME_STR,
NULL,
(BYTE*)subBlob,
&subBlobLen,
NULL))
{
//error
}

if (!(pCert = CertFindCertificateInStore(hMYStoreHandle,
MY_ENCODING_TYPE,
0,
CERT_FIND_SUBJECT_NAME,
&subBlob,
NULL)))
{
//error
}

but it fails to find cert. :(


0 new messages