1

I should send text messages to messaging platform like Slacks using incoming webhook. But my network as developing is different from public one, so I decided to use our company's proxy server which can connect to public one. Briefly,

Client - HTTP PROXY - SERVER (messaging platform)

1. Firstly, establish C-P connection using normal TCP socket.

boost::asio::ssl::stream<boost::asio::ip::tcp::socket> m_socket;

boost::asio::ip::tcp::resolver resolver(m_io);
boost::asio::ip::tcp::resolver::query query("www.proxy.dev", "8080");
boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);

boost::asio::async_connect(m_socket.lowest_layer(), iterator,
    boost::bind(&ClientSocket::HandleHandShake, this,
        boost::asio::placeholders::error, shared_from_this()));

After connecting, send connection string to proxy.

m_stringStream << "CONNECT";
m_stringStream << " " << m_domain << ":443";
m_stringStream << " HTTP/1.1\r\n";
m_stringStream << "HOST: " << m_domain << ":443\r\n";
m_stringStream << "Proxy-Connection: keep-alive\r\n";
m_stringStream << "Connection: keep-alive\r\n";

2. Receive status code from proxy.

200 OK

3. Handshake

m_socket.set_verify_mode(boost::asio::ssl::verify_none);
m_socket.set_verify_callback([](auto&& preverified, auto&& ctx)
{
    char subject_name[256];
    X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
    X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256);
    return preverified;
});

m_socket.async_handshake(boost::asio::ssl::stream_base::client,
        boost::bind(&ClientSocket::HandleHandShake, this,
            boost::asio::placeholders::error, shared_from_this()));

4. Write HTTP POST, Read status code.

At 3 step, the error code informs me "short read" so i can't go next step.

I have searched many questions, but everything is not worked for me.

If I skip the handshake process, can receive "uninitialized" error.

If I also skip 'CONNECT' with proxy and send 'POST' directly to server, can receive "403 badrequest" error.

It's OK to connect server and send text message not through proxy server.

Thank you for reading.

  • Why do you want to write raw https handshake? Why not use libs like `curl`? – Mine Jul 06 '17 at 08:10
  • @Mine Boost library I used from building program at first support https handshake function, so i just use that. Thank you for your advice. I will try raw https handshake process. – user2780583 Jul 06 '17 at 08:48
  • Could you add a some more source code snippets? Please see my related question https://stackoverflow.com/questions/69713739/how-to-connect-with-boostasio-to-a-https-server-using-a-proxy – RED SOFT ADAIR Oct 25 '21 at 19:31

0 Answers0