Discussion:
InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO
(too old to reply)
Dream tripper
2008-04-28 22:14:33 UTC
Permalink
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.

Here's the 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
Volodymyr M. Shcherbyna
2008-05-02 10:00:22 UTC
Permalink
What error number do you get?
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Dream tripper
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.
------------------------------------------------------------------------------------------
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
Loading...