Re: [Boost-users] boost::asio SSL connection thru proxy server
Hi All, Considering that nobody replied my question I am wondering if anybody who has knowledge of this kind of problem has seen my previous message/question. I really need help on this issue if anybody has any thought on this pls. reply. Thanks, Akhilesh Kumar From: Kumar, Akhilesh Sent: Monday, August 23, 2010 5:10 PM To: 'boost-users@lists.boost.org' Subject: boost::asio SSL connection thru proxy server Hi, I am writing a boost socket client using boost::asio to do secure HTTP (HTTPS) communication. I Implemented my client based on the code sample based on (http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/ssl/client....) with little changes as I am using sync socket. My client woks fine, when I am connecting to server directly, but I am not sure what changes I need to make when my communication going thru proxy. The unsecure connection(HTTP) work fine thru proxy, and here is what I do for unsecure connection, 1. Initialize boost socket(IO service and other stuff). 2. Resolve and Connect to Proxy server. 3. Start writing to actual server(HTTP send request). 4. Start uploading/downloading. 5. Close Socket. But I can't use this above procedure for (SSL) secure connection as I need to do handshaking with the server before I can write anything if my understanding is correct. Can somebody give me some pointer or code sample or step I need to do when I am doing secure connection thru proxy server. Just to clarify Microsoft WinInet does do (secure) HTTPS connection thru same proxy fine. If providing my code sample I am using for SSL might help understand the problem I can provide that. Thanks in advance for any help. Akhilesh Kumar
Akilesh, Your question is not clear to me, what exactly does not work when using your proxy? Does the SSL handshake fail? Sam |------------> | From: | |------------>
--------------------------------------------------------------------------------------------------------------------------------------------------| |"Kumar, Akhilesh"
| --------------------------------------------------------------------------------------------------------------------------------------------------| |------------> | To: | |------------> --------------------------------------------------------------------------------------------------------------------------------------------------| |"boost-users@lists.boost.org" | --------------------------------------------------------------------------------------------------------------------------------------------------| |------------> | Date: | |------------> --------------------------------------------------------------------------------------------------------------------------------------------------| |08/30/2010 02:34 PM | --------------------------------------------------------------------------------------------------------------------------------------------------| |------------> | Subject: | |------------> --------------------------------------------------------------------------------------------------------------------------------------------------| |Re: [Boost-users] boost::asio SSL connection thru proxy server | --------------------------------------------------------------------------------------------------------------------------------------------------| |------------> | Sent by: | |------------> --------------------------------------------------------------------------------------------------------------------------------------------------| |boost-users-bounces@lists.boost.org | --------------------------------------------------------------------------------------------------------------------------------------------------|
Hi All, Considering that nobody replied my question I am wondering if anybody who has knowledge of this kind of problem has seen my previous message/question. I really need help on this issue if anybody has any thought on this pls. reply. Thanks, Akhilesh Kumar From: Kumar, Akhilesh Sent: Monday, August 23, 2010 5:10 PM To: 'boost-users@lists.boost.org' Subject: boost::asio SSL connection thru proxy server Hi, I am writing a boost socket client using boost::asio to do secure HTTP (HTTPS) communication. I Implemented my client based on the code sample based on ( http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/example/ssl/client.... ) with little changes as I am using sync socket. My client woks fine, when I am connecting to server directly, but I am not sure what changes I need to make when my communication going thru proxy. The unsecure connection(HTTP) work fine thru proxy, and here is what I do for unsecure connection, 1. Initialize boost socket(IO service and other stuff). 2. Resolve and Connect to Proxy server. 3. Start writing to actual server(HTTP send request). 4. Start uploading/downloading. 5. Close Socket. But I can’t use this above procedure for (SSL) secure connection as I need to do handshaking with the server before I can write anything if my understanding is correct. Can somebody give me some pointer or code sample or step I need to do when I am doing secure connection thru proxy server. Just to clarify Microsoft WinInet does do (secure) HTTPS connection thru same proxy fine. If providing my code sample I am using for SSL might help understand the problem I can provide that. Thanks in advance for any help. Akhilesh Kumar _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Sam,
Here is my code snippet to connect to a server without proxy, This code works fine I have tested it, my question is what changes I need to make if I have to go thru proxy to connect to server.
Thanks,
using boost::asio::ip::tcp;
using namespace std;
using namespace boost;
CBoostSocket::Connect()
{
try
{
tcp::resolver *m_pResolver;
tcp::socket *m_pSocket;
boost::asio::streambuf request_;
boost::asio::streambuf response_;
boost::asio::io_service *m_pIOservice;
boost::asio::ssl::context *m_pSSLContext;
boost::asio::ssl::streamboost::asio::ip::tcp::socket *m_pSecureSocket;
string m_host;//host url
m_pIOservice = new boost::asio::io_service();
tcp::resolver resolver(*m_pIOservice);
m_pSSLContext = new boost::asio::ssl::context(*m_pIOservice, boost::asio::ssl::context::sslv23_client);
m_pSSLContext->set_verify_mode(boost::asio::ssl::context::verify_none);
//by default connect directly
string proxyOrHost(m_host);
//CInternetSettings netSetting;
boost::system::error_code error = boost::asio::error::host_not_found;
tcp::resolver::iterator end;
tcp::resolver::query query(proxyOrHost , "https");
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
// Try each endpoint until we successfully establish a connection.
//boost::system::error_code error;
m_pSecureSocket = new boost::asio::ssl::streamboost::asio::ip::tcp::socket(*m_pIOservice, *m_pSSLContext) ;
//try to connect it directly first even though proxy is set, if fail try with proxy
while (error && endpoint_iterator != end)
{
m_pSecureSocket->lowest_layer().close();
m_pSecureSocket->lowest_layer().connect(*endpoint_iterator++, error);
if (!error)
{
m_pSecureSocket->handshake(boost::asio::ssl::stream_base::client, error);
if(!error)
{
}
else{
boost::system::error_code code = error;
boost::system::system_error e(error);
long lastResult = code.value();
string errorString = e.what();
m_pSecureSocket->lowest_layer().close();
ASSERT(!"Handshake failed: ");
std::cout << "Handshake failed: " << error << "\n";
return ;
}
}
else
{
boost::system::error_code code = error;
boost::system::system_error e(error);
long lastResult = code.value();
string errorString = e.what();
ASSERT(!"Connect failed: ");
std::cout << "Connect failed: " << error << "\n";
m_pSecureSocket->lowest_layer().close();
return ;
}
}
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << "POST" << " " << urlPath << " HTTP/1.0\r\n";
request_stream << "Host: " << m_host << "\r\n";
request_stream << "Accept: */*\r\n";
long contentLength = 0;
const wchar_t *pPostParam;
long paramLen;
if(pPostParam && paramLen)
{
request_stream << "Content-Length: ";
request_stream << boost::lexical_cast<string>(contentLength);
request_stream << "\r\n";
}
else
{
}
request_stream << "Cache-Control: no-cache\r\n";
request_stream << "Connection: Close\r\n\r\n";
// Send the request.
boost::system::error_code error;
boost::asio::write(*m_pSecureSocket, request );
//Write post param
if (error)
throw boost::system::system_error(error);
}
catch(...) {
}
catch (boost::system::system_error &e){
//Handle Error
}
return S_OK;
}
Akhilesh Kumar
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sam Miller
Sent: Monday, August 30, 2010 12:43 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] boost::asio SSL connection thru proxy server
Akilesh,
Your question is not clear to me, what exactly does not work when using your proxy? Does the SSL handshake fail?
Sam
[cid:image001.gif@01CB4845.C28A2DD0]"Kumar, Akhilesh" ---08/30/2010 02:34:00 PM---Hi All, Considering that nobody replied my question I am wondering if anybody who has knowledge of t
From:
"Kumar, Akhilesh"
"Kumar, Akhilesh"
Here is my code snippet to connect to a server without proxy, This code works fine I have tested it, my question is what changes I need to make if I have to go thru proxy to connect to server.
Why do you assume changes are required? Have you tried connecting to a proxy? Does it work using your existing code? Sam
Since I need to connect to secure server before I can do handshake, If I connect to proxy 1st (I will have to do this if I am going thru proxy) how do I connect to secure server for Handshake. If I connect to proxy and do handshake it does not make sense logically and it does fails("asio.ssl error") if I try doing this. So the question is If I connect to Proxy 1st how do I create another secure socket and connect it to secure server which know that it has to go thru proxy? This is the connection I want to established. SecureSocket -> Proxy ->SecureServer. Thanks, Akhilesh Kumar From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sam Miller Sent: Monday, August 30, 2010 3:26 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::asio SSL connection thru proxy server
"Kumar, Akhilesh"
Here is my code snippet to connect to a server without proxy, This code works fine I have tested it, my question is what changes I need to make if I have to go thru proxy to connect to server.
Why do you assume changes are required? Have you tried connecting to a proxy? Does it work using your existing code? Sam
You appear to need to use the CONNECT method. All information found by
googling "SSL via proxy" or similar. References below are out of date,
but appear to still be the latest.
http://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_Tunneling
http://tools.ietf.org/html/draft-luotonen-ssl-tunneling-03
Regards,
Brodie
On Tue, Aug 31, 2010 at 8:25 AM, Kumar, Akhilesh
Since I need to connect to secure server before I can do handshake, If I connect to proxy 1st (I will have to do this if I am going thru proxy) how do I connect to secure server for Handshake. If I connect to proxy and do handshake it does not make sense logically and it does fails(“asio.ssl error”) if I try doing this. So the question is If I connect to Proxy 1st how do I create another secure socket and connect it to secure server which know that it has to go thru proxy?
This is the connection I want to established.
SecureSocket -> Proxy ->SecureServer.
Thanks,
Akhilesh Kumar
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sam Miller Sent: Monday, August 30, 2010 3:26 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::asio SSL connection thru proxy server
"Kumar, Akhilesh"
Here is my code snippet to connect to a server without proxy, This code works fine I have tested it, my question is what changes I need to make if I have to go thru proxy to connect to server.
Why do you assume changes are required? Have you tried connecting to a proxy? Does it work using your existing code?
Sam
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Brodie Thiesfield
-
Kumar, Akhilesh
-
Sam Miller