Boost ASIO: SSL handshake() never finishes

后端 未结 1 1099
时光取名叫无心
时光取名叫无心 2021-02-13 05:20

I have a C++ client app that uses Boost ASIO to make SSL connections to various servers. But against 2 specific servers, the SSL connection cannot be established. It hangs in t

1条回答
  •  逝去的感伤
    2021-02-13 06:03

    I figured it out. This SSL tutorial (http://h71000.www7.hp.com/doc/83final/ba554_90007/ch04s03.html) contained the key that finally got this working for me. Quote:

    You can reuse the information from an already established SSL session to create a new SSL connection. Because the new SSL connection is reusing the same master secret, the SSL handshake can be performed more quickly. As a result, SSL session resumption can reduce the load of a server that is accepting many SSL connections.

    So here is how I got this working with Boost ASIO:

    • setup the normal SSL control socket (lots of examples, including this question)
    • when you need to setup the 2nd SSL data socket, do this:
    
        sslSocket2.lowest_layer().connect( tcpEndpoint, ec );
        SSLSocket::impl_type impl1 = sslSocket1.impl();
        SSLSocket::impl_type impl2 = sslSocket2.impl();
        SSL_SESSION *savedSession = SSL_get1_session( impl1->ssl );
        SSL_set_session( impl2->ssl, savedSession );
        SSL_connect( impl2->ssl );
    

    That's it. At this point, no need to call sslSocket2.handshake(). Just read and write to the socket knowing the connection has been established.

    0 讨论(0)
提交回复
热议问题