Newsgroups : Microsoft : microsoft.public.inetsdk.programming.wininet : 2008 Apr : InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO

www.cryer.info
Managed Newsgroup Archive

InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO

Subject:InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO
Posted by:"Dream tripper" (f.saut..@gmail.com)
Date:Mon, 28 Apr 2008 15:14:33 -0700 (PDT)

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

Replies:

www.cryer.info
Managed Newsgroup Archive