CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    1

    Angry 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: InternetQueryOption retuning empty INTERNET_CERTIFICATE_INFO

    Please read the FAQ's before posting. You need to edit your post to include
    Code:
    CODE TAGS
    so we can read that mess
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured