Discussion:
How to get the certificate for an SSL server (HTTPS)???
(too old to reply)
Emil
2006-05-19 08:18:02 UTC
Permalink
Hi all,

I do not belive it!! I tried to obtain the certificate for an SSL server
(http connectio) but I cannot. I use "INTERNET_OPTION_SECURITY_CERTIFICATE"
or "INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT", calling with
InternetQueryOption (or CInternetSession::QueryOption). Dosen't matter what
option I have the function fails and the result is allways
ERROR_WINHTTP_INCORRECT_HANDLE_TYPE (The type of handle supplied is incorrect
for this operation.).
Knows anybody how can I do this? Knows someone a piece of code where
InternetQueryOption realy runs? Or is there another way to do this. I'm
desparate...
Thanks in advance.

Regards,
Emil
pengfei ding
2006-06-19 08:33:03 UTC
Permalink
pServer = session.GetHttpConnection( szServerName,
INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_SECURE,
INTERNET_DEFAULT_HTTPS_PORT, L"", L"" );

pFile = pServer->OpenRequest( CHttpConnection::HTTP_VERB_POST, szObject,
NULL, 1, NULL, NULL,
INTERNET_FLAG_EXISTING_CONNECT |
INTERNET_FLAG_NO_AUTO_REDIRECT |
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID );

DWORD dwFlags;
pFile->QueryOption( INTERNET_OPTION_SECURITY_FLAGS, dwFlags );
// Set the new security flags
pFile->SetOption( INTERNET_OPTION_SECURITY_FLAGS, dwFlags |
SECURITY_FLAG_IGNORE_UNKNOWN_CA );
pFile->SendRequest();//note:firewall will block this step if run firewall.

INTERNET_CERTIFICATE_INFO info;
memset( &info, 0, sizeof(INTERNET_CERTIFICATE_INFO) );
DWORD length = sizeof(INTERNET_CERTIFICATE_INFO);

if ( !pFile->QueryOption( INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info,
&length ) )
{
dwError = ::GetLastError();
}

length = 4096;
BYTE *buf = new BYTE[length];
if ( !pFile->QueryOption( INTERNET_OPTION_SECURITY_CERTIFICATE, buf,
&length ) )
{
dwError = ::GetLastError();
}
delete [] buf;
Emil
2006-07-11 09:55:02 UTC
Permalink
Did it work for you. I resolved it with WinHttp, in WinInet seams to be a
bug, look in Q251347.
Thanks a lot anyway!

Emil
Post by pengfei ding
pServer = session.GetHttpConnection( szServerName,
INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_SECURE,
INTERNET_DEFAULT_HTTPS_PORT, L"", L"" );
pFile = pServer->OpenRequest( CHttpConnection::HTTP_VERB_POST, szObject,
NULL, 1, NULL, NULL,
INTERNET_FLAG_EXISTING_CONNECT |
INTERNET_FLAG_NO_AUTO_REDIRECT |
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID );
DWORD dwFlags;
pFile->QueryOption( INTERNET_OPTION_SECURITY_FLAGS, dwFlags );
// Set the new security flags
pFile->SetOption( INTERNET_OPTION_SECURITY_FLAGS, dwFlags |
SECURITY_FLAG_IGNORE_UNKNOWN_CA );
pFile->SendRequest();//note:firewall will block this step if run firewall.
INTERNET_CERTIFICATE_INFO info;
memset( &info, 0, sizeof(INTERNET_CERTIFICATE_INFO) );
DWORD length = sizeof(INTERNET_CERTIFICATE_INFO);
if ( !pFile->QueryOption( INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info,
&length ) )
{
dwError = ::GetLastError();
}
length = 4096;
BYTE *buf = new BYTE[length];
if ( !pFile->QueryOption( INTERNET_OPTION_SECURITY_CERTIFICATE, buf,
&length ) )
{
dwError = ::GetLastError();
}
delete [] buf;
Loading...