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

Calling CertFindCertificateInStore

181 views
Skip to first unread message

Anastasios Angelidis

unread,
May 28, 2003, 12:25:59 PM5/28/03
to
When I call the function the way shown below my
application works.

pCertContext = CertFindCertificateInStore(hMyStore,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
0, CERT_FIND_SUBJECT_STR,
L"tas...@trustmarque.ca", NULL);

When I try to set the pvFindData to a value retrieved from
the command line arguments it fails. For instance...

void main(int argc, char **argv)
{
char certSubject[257];
strcpy(certSubject, argv[1]);
printf("Cert Subject: %s\n", certSubject); // Print
correct value.
...

pCertContext = CertFindCertificateInStore(hMyStore,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
0, CERT_FIND_SUBJECT_STR,
certSubject, NULL);

...
}

Thanks

Yu Chen [MS]

unread,
May 28, 2003, 3:51:36 PM5/28/03
to
You need to pass in a WCHAR string as pvFindPara - certSubject below is in
ANSI.
BTW, there's a potential buffer overrun in your code:

> char certSubject[257];
> strcpy(certSubject, argv[1]);

--
Yu Chen [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.


"Anastasios Angelidis" <tas...@trustmarque.ca> wrote in message
news:451701c32535$d2776400$a101...@phx.gbl...

Anastasios Angelidis

unread,
May 28, 2003, 4:06:20 PM5/28/03
to
Thanks, though it was purposes...
>.
>

John Banes [MS]

unread,
May 28, 2003, 4:14:18 PM5/28/03
to
Well, in the case that works you're passing in a Unicode string, and in the
case that doesn't you're passing in an ansi string.

Does CERT_FIND_SUBJECT_STR_A work any better?

Regards,

John Banes
[Microsoft Security Developer]

This posting is provided "AS IS" with no warranties, and confers no rights.

Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

"Anastasios Angelidis" <tas...@trustmarque.ca> wrote in message
news:451701c32535$d2776400$a101...@phx.gbl...

Anastasios Angelidis

unread,
May 28, 2003, 4:26:41 PM5/28/03
to
Sorry for the mumbling... :)

I tried WCHAR still no go...

I also used wscopy also, WCHAR will only work if my
application is set for unicode my application is not
unicode ready...

>.
>

Anastasios Angelidis

unread,
May 28, 2003, 4:40:37 PM5/28/03
to
Yes it does work now. Though this is not mentioned in the
MSDN library docs.

Thanks

>.
>

Yu Chen [MS]

unread,
May 28, 2003, 5:57:06 PM5/28/03
to
You will need to convert char string to WCHAR string first. Or you can just
use the CERT_FIND_SUBJECT_STR_A as John mentioned in the other thread.

--
Yu Chen [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.


"Anastasios Angelidis" <tas...@trustmarque.ca> wrote in message

news:482a01c32557$72d1a430$a101...@phx.gbl...

0 new messages