Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I am using CInternetSession class of MFC to send HTTP queries and get results. Things work fine with bith HTTP and HTTPS.Objects of CInternetSession cal also return details of session by QueryOption which brings options. Now I am trying to extract certificate, using one of two options:
ASM
BYTE lpBuffer[2048];
DWORD lpdwBufferLength = sizeof(lpBuffer);
//CInternetSession session created before and valid and working
//attempt 1
BOOL resQueryOption = session.QueryOption((DWORD)INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,  lpBuffer,&lpdwBufferLength);
DWORD erro1r = GetLastError(); //ERROR_INTERNET_INCORRECT_HANDLE_TYPE

//attempt 2
HINTERNET hInternet = (HINTERNET )session; //provides handle OK
BOOL resInternetQueryOption = InternetQueryOption(  hInternet,  INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,   lpBuffer,   &lpdwBufferLength);
DWORD error2 = GetLastError(); //ERROR_INTERNET_INCORRECT_HANDLE_TYPE


However the result is FALSE, and the error is ERROR_INTERNET_INCORRECT_HANDLE_TYPE (12018) even if I try to do like samples one can find in Internet. What can be wrong, please?
Levi
Posted

1 solution

I found the problem. I sent query too early, the correct way it not send after GetHttpConnection and not after OpenRequest, but only after SendRequest.
So the correct order is

CInternetSession session(_T("something"));
CHttpConnection *pConnection = session.GetHttpConnection(strHost,flags, ipUsedPort,_T(""),_T(""));
CHttpFile *pFile = pConnection->OpenRequest(mode,"url", NULL,1,NULL, NULL, INTERNET_FLAG_SECURE);
res = res && pFile->SendRequest(strHeaders, (LPVOID) (LPCTSTR) sbody.c_str(), sbody.length());
INTERNET_CERTIFICATE_INFO certificateInfo;
DWORD certInfoLength = sizeof(INTERNET_CERTIFICATE_INFO);
BOOL resQueryResult = pFile->QueryOption((DWORD)INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &certificateInfo,&certInfoLength);
DWORD erro1r = GetLastError();

Sorry to bother, Levi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900