|
-
April 28th, 2008, 06:11 PM
#1
InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO
Greetings,
I am trying to get the server certificate information (specially the
certificate subjet) from an Internet handle in WinInet. The
communication to the server works fine, and the secure connection is
established; I am also able to send requests. The problem arises when
calling InternetQueryOption to get the certificate: it always returns
an empty structure.
Code:
bool verifyCertSubject(HINTERNET internetHandle)
{
bool isCA = false;
INTERNET_CERTIFICATE_INFO certificateInfo;
DWORD certInfoLength =
sizeof(INTERNET_CERTIFICATE_INFO);
if ( TRUE ==
InternetQueryOption(internetHandle, // Internet handle
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, // Internet option to
query
&certificateInfo, // Buffer
&certInfoLength) ) // Buffer length
{
// ERROR: call is successfull but certificateInfo is always
empty
// free up memory with GlobalFree()
}
else
{
// If trying the wrong handle or if any param is wrong, I have
read the appropriate error code here.
DWORD error = GetLastError();
}
return isCA;
}
void testHttpConnection()
{
HINTERNET mhInternet =
InternetOpen(_T("My connection"), INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if (NULL != mhInternet)
{
HINTERNET mhConnect = InternetConnect(mhInternet,
_T("secureServer.com"),
INTERNET_DEFAULT_HTTPS_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
INTERNET_FLAG_SECURE,
NULL);
if (NULL != mhConnect)
{
HINTERNET mhRequest =
HttpOpenRequest(mhConnect,
_T("POST"),
HTTPS_SERVICE_ENDPOINT,
NULL,
NULL,
NULL,
INTERNET_FLAG_SECURE,
NULL);
if (NULL != mhRequest)
{
if (verifyCertSubject(mhRequest))
{
std::cout << "Certificate is valid and issued by
CA" << std::endl;
}
}
}
}
}
Any help or ideas will be greatly appreciated. I have tried about
everything that I could and have not been able to get any better
results from this call.
Thanks and regards,
Fred
PS: x-posting at http://groups.google.com/group/micro...3433ec9e?fwc=1
Last edited by Dreamtripper; April 28th, 2008 at 06:55 PM.
Reason: Did not include correct formatting for code.
-
April 28th, 2008, 06:26 PM
#2
Re: InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO
Please read the FAQ's before posting. You need to edit your post to include
so we can read that mess
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|