set_verify_callback is not always called for TLS websocket connection

53 views
Skip to first unread message

Deval Gupta

unread,
Oct 14, 2022, 5:11:05 PM10/14/22
to WebSocket++
Hello,

I am running on an embedded platform and have run across a peculiar situation.

Sometimes when my device switches from a Wi-Fi connection to a cellular connection I am unable to establish a TLS socket connection again because my set_verify_callback fucntion is not called. Well, the callback is set to my function pointer but the actual callback function is not called. This callback function is doing the certificate verification so then the socket connection fails on a TLS timeout. 

I have been careful to reopen the socket connection only when it has closed, and I believe all the shared ptrs are reinstantiated. The odd thing is I can kill the process and run it again and it will then work. So it makes me think something with the SSL callback is not happening correctly. Anyone have any idea of anything I need to do specifically to reinit my connection?

context_ptr ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv12_client);

try {

    ctx->set_options(boost::asio::ssl::context::default_workarounds |
                     boost::asio::ssl::context::no_sslv2 |
                     boost::asio::ssl::context::no_sslv3);

   // we will need to enable these methods to get TLS working with client verification
   ctx->set_verify_mode(boost::asio::ssl::verify_peer);
   ctx->set_verify_callback(bind(&ConnectionMetadata::verify_server_cert, this,
                                 websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2));

This is the code snippet of the on_tls_init which is successfully called, but the callback we are setting in set_verify_callback is not called.



Thanks
Reply all
Reply to author
Forward
0 new messages