[ssl] SSL handshake takes forever sometimes
Hi, I have an application written in boost with SSL. I noticed that when the client network is down for a while and come back again. The SSL handshake sometimes take forever. I tried to kill the client application and run it again, the problem still there. The only way to make it work again was to reboot my client device. I'm using boost 1.60 on the client side and 1.58 on the server side. The SSL handshake code was copied from Boost SSL server and client example I modified a bit to suit my application needs. Does anyone experience the similar issue? If so, can you please let me know how do you fix it? It would be much appropriated if you could help me out on this issue. Below is the SSL handshake code. chat_client(boost::asio::io_service& io_service, boost::asio::ssl::context& context, tcp::resolver::iterator endpoint_iterator) : io_service_(io_service), socket_(io_service, context) { filesize_=0; isfileopen_=false; socket_.set_verify_mode(boost::asio::ssl::verify_peer); socket_.set_verify_callback( boost::bind(&chat_client::verify_certificate, this, _1, _2)); boost::asio::async_connect(socket_.lowest_layer(), endpoint_iterator, boost::bind(&chat_client::handle_connect, this, boost::asio::placeholders::error)); } bool verify_certificate(bool preverified, boost::asio::ssl::verify_context& 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); log_time(); fprintf(logfile,"%s: Verifying %s\n",logtime.c_str(), subject_name); return preverified; } void handle_connect(const boost::system::error_code& error) { if (!error) { socket_.async_handshake(boost::asio::ssl::stream_base::client, boost::bind(&chat_client::handle_handshake, this, boost::asio::placeholders::error)); } else { log_time(); fprintf(logfile, " %s Connect to server failed: %s\n ",logtime.c_str(), error.message().c_str()); fflush(logfile); delete this; } } void handle_handshake(const boost::system::error_code& error) { if (!error) { ssl_handshake_ok=1; do_read_header(); } else { log_time(); fprintf(logfile,"%s: Handshake failed:%s\n ",logtime.c_str(), error.message().c_str()); } }
participants (1)
-
Shuchen He