Discussion:
WinInet & untrusted certificates
(too old to reply)
Seshadri
2004-10-12 18:11:10 UTC
Permalink
Dear All,
I have a problem with my code that refuses to work on a SSL which has
untrusted certificates, while trying to read a page. I think I have put in
the necessary flags for the code to ignore untrusted certificates, but still,
I get a null string every time. If I try the HTTP on the same server, it
works fine but HTTPS with an untrusted certificate, I get null string. I am
pasting the code below. If you could help me where I could be going wrong, it
will be great.

Thank you in advance.
- Sesahdri.

Code follows:
<<
CRegistrationDlg::CallInternet(void)
{
HINTERNET hSession =
InternetOpen("MembaGenesisInternetRequest",INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,NULL,NULL,NULL);
HINTERNET hConnect =
InternetConnect(hSession,"pw-sesh-sdi",INTERNET_DEFAULT_HTTPS_PORT,"","",INTERNET_SERVICE_HTTP,0,0) ;
HINTERNET hHttpFile =
HttpOpenRequest(hConnect,"GET","/a.htm",HTTP_VERSION,NULL,0,INTERNET_FLAG_IGNORE_CERT_CN_INVALID
|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |INTERNET_FLAG_NO_COOKIES
|INTERNET_FLAG_RELOAD |INTERNET_FLAG_SECURE |INTERNET_FLAG_DONT_CACHE,0);
BOOL bSendRequest = HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery =
HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,bufQuery,&dwLengthBufQuery,0) ;
DWORD dwFileSize = (DWORD)atol(bufQuery) ;
char* buffer = new char[dwFileSize+1] ;
DWORD dwBytesRead ;
BOOL bRead = InternetReadFile(hHttpFile,buffer,dwFileSize+1,
&dwBytesRead);
buffer[dwBytesRead] = 0 ;
InternetCloseHandle(hHttpFile);
InternetCloseHandle(hConnect) ;
InternetCloseHandle(hSession) ;
AfxMessageBox(buffer);
}
Seshadri
2004-10-14 10:41:04 UTC
Permalink
Additional information:
Development environment:
Windows XP professional.
SSL enabled by using the IIS SelfSSL utility found at :
http://www.somacon.com/iis_ssl/page14.php

Thanks in advance.

- Seshadri.
Post by Seshadri
Dear All,
I have a problem with my code that refuses to work on a SSL which has
untrusted certificates, while trying to read a page. I think I have put in
the necessary flags for the code to ignore untrusted certificates, but still,
I get a null string every time. If I try the HTTP on the same server, it
works fine but HTTPS with an untrusted certificate, I get null string. I am
pasting the code below. If you could help me where I could be going wrong, it
will be great.
Thank you in advance.
- Sesahdri.
<<
CRegistrationDlg::CallInternet(void)
{
HINTERNET hSession =
InternetOpen("MembaGenesisInternetRequest",INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,NULL,NULL,NULL);
HINTERNET hConnect =
InternetConnect(hSession,"pw-sesh-sdi",INTERNET_DEFAULT_HTTPS_PORT,"","",INTERNET_SERVICE_HTTP,0,0) ;
HINTERNET hHttpFile =
HttpOpenRequest(hConnect,"GET","/a.htm",HTTP_VERSION,NULL,0,INTERNET_FLAG_IGNORE_CERT_CN_INVALID
|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |INTERNET_FLAG_NO_COOKIES
|INTERNET_FLAG_RELOAD |INTERNET_FLAG_SECURE |INTERNET_FLAG_DONT_CACHE,0);
BOOL bSendRequest = HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery =
HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,bufQuery,&dwLengthBufQuery,0) ;
DWORD dwFileSize = (DWORD)atol(bufQuery) ;
char* buffer = new char[dwFileSize+1] ;
DWORD dwBytesRead ;
BOOL bRead = InternetReadFile(hHttpFile,buffer,dwFileSize+1,
&dwBytesRead);
buffer[dwBytesRead] = 0 ;
InternetCloseHandle(hHttpFile);
InternetCloseHandle(hConnect) ;
InternetCloseHandle(hSession) ;
AfxMessageBox(buffer);
}
Brian Combs
2004-10-14 17:44:30 UTC
Permalink
Hello
Please take a look at the following article: 182888 How To Handle Invalid
Certificate Authority Error with WinInet
http://support.microsoft.com/?id=182888

Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Thread-Topic: WinInet & untrusted certificates
| thread-index: AcSx2k5CziIET9fFRum/w/DGuPAh4w==
| X-WBNR-Posting-Host: 217.204.241.58
| From: "=?Utf-8?B?U2VzaGFkcmk=?=" <***@discussions.microsoft.com>
| References: <34A58AE5-0831-4D7A-A5B6-***@microsoft.com>
| Subject: RE: WinInet & untrusted certificates
| Date: Thu, 14 Oct 2004 03:41:04 -0700
| Lines: 54
| Message-ID: <946730FE-6F5D-44E2-881A-***@microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11774
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| Additional information:
| Development environment:
| Windows XP professional.
| SSL enabled by using the IIS SelfSSL utility found at :
| http://www.somacon.com/iis_ssl/page14.php
|
| Thanks in advance.
|
| - Seshadri.
|
|
| "Seshadri" wrote:
|
| > Dear All,
| > I have a problem with my code that refuses to work on a SSL which
has
| > untrusted certificates, while trying to read a page. I think I have put
in
| > the necessary flags for the code to ignore untrusted certificates, but
still,
| > I get a null string every time. If I try the HTTP on the same server,
it
| > works fine but HTTPS with an untrusted certificate, I get null string.
I am
| > pasting the code below. If you could help me where I could be going
wrong, it
| > will be great.
| >
| > Thank you in advance.
| > - Sesahdri.
| >
| > Code follows:
| > <<
| > CRegistrationDlg::CallInternet(void)
| > {
| > HINTERNET hSession =
| >
InternetOpen("MembaGenesisInternetRequest",INTERNET_OPEN_TYPE_PRECONFIG_WITH
_NO_AUTOPROXY,NULL,NULL,NULL);
| > HINTERNET hConnect =
| >
InternetConnect(hSession,"pw-sesh-sdi",INTERNET_DEFAULT_HTTPS_PORT,"","",INT
ERNET_SERVICE_HTTP,0,0) ;
| > HINTERNET hHttpFile =
| >
HttpOpenRequest(hConnect,"GET","/a.htm",HTTP_VERSION,NULL,0,INTERNET_FLAG_IG
NORE_CERT_CN_INVALID
| > |INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |INTERNET_FLAG_NO_COOKIES
| > |INTERNET_FLAG_RELOAD |INTERNET_FLAG_SECURE
|INTERNET_FLAG_DONT_CACHE,0);
| > BOOL bSendRequest = HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
| > char bufQuery[32] ;
| > DWORD dwLengthBufQuery = sizeof(bufQuery);
| > BOOL bQuery =
| >
HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,bufQuery,&dwLengthBufQuery
,0) ;
| > DWORD dwFileSize = (DWORD)atol(bufQuery) ;
| > char* buffer = new char[dwFileSize+1] ;
| > DWORD dwBytesRead ;
| > BOOL bRead = InternetReadFile(hHttpFile,buffer,dwFileSize+1,
| > &dwBytesRead);
| > buffer[dwBytesRead] = 0 ;
| > InternetCloseHandle(hHttpFile);
| > InternetCloseHandle(hConnect) ;
| > InternetCloseHandle(hSession) ;
| > AfxMessageBox(buffer);
| > }
| > >>
|

Loading...