diff --git a/README.md b/README.md index 8175ae4..93c131c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - ## As of 3.1.2 May 2024 Update, `--destination-client-type V1` will be a required parameter when connecting with the following: - AWS IoT Device Client - AWS IoT Secure Tunneling Component OR Greengrass V2 Secure Tunneling Component @@ -653,3 +652,25 @@ If you need this limit increased, please reach out to AWS support and ask for a #### Load balancing in multiplexed streams If more than one stream is transferred at the same time, local proxy will not load balance between these streams. If you have one stream that is dominating the bandwidth, the other streams sharing the same tunnel connection may see latency of data packet delivery. + +### Troubleshooting + +#### SSL Handshake Issues + +If you encounter SSL handshake issues, follow these steps to troubleshoot: + +1. **Check SSL Certificates**: Ensure that the SSL certificates are correctly installed and configured on your system. Verify that the certificate chain is complete and trusted. + +2. **Verify Network Configuration**: Check your network configuration to ensure that there are no firewall rules or network policies blocking the SSL handshake. + +3. **Enable Detailed Logging**: Enable detailed logging in the localproxy to capture SSL handshake errors. Use the `-v` option with a higher verbosity level (e.g., `-v 6`) to get more detailed logs. + +4. **Retry Mechanism**: The localproxy includes a retry mechanism for SSL handshake. If the handshake fails, the localproxy will automatically retry the handshake. Ensure that the retry mechanism is enabled in the configuration. + +5. **Disable SSL Verification**: As a last resort, you can disable SSL verification if the handshake continues to fail. Use the `--no-ssl-host-verify` option to disable SSL host verification. Note that this should only be used for troubleshooting purposes and not in production environments. + +6. **Check System Environment**: The issue may be specific to your system environment. Ensure that the localproxy works on other systems to rule out any system-specific issues. + +7. **Update Dependencies**: Ensure that you are using the latest versions of the dependencies (e.g., OpenSSL, Boost) required by the localproxy. Outdated dependencies may cause SSL handshake issues. + +8. **Consult Documentation**: Refer to the official documentation and troubleshooting guides provided by the localproxy project for additional troubleshooting steps and best practices. diff --git a/src/WebSocketStream.cpp b/src/WebSocketStream.cpp index 9f603c5..549dbb6 100644 --- a/src/WebSocketStream.cpp +++ b/src/WebSocketStream.cpp @@ -1,6 +1,3 @@ -// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - #include "WebSocketStream.h" #include @@ -175,35 +172,77 @@ namespace aws { void WebSocketStream::async_ssl_handshake(const ssl::stream_base::handshake_type &type, const std::string &host, const BoostCallbackFunc &handler) { - if (localproxyConfig.is_web_proxy_using_tls) { - BOOST_LOG_SEV(*log, trace) << "Calling next_layer().async_handshake with type: " - << WEB_PROXY_WITH_TLS_TYPE_NAME; - // Set SNI Hostname (many hosts need this to handshake successfully) - if(!SSL_set_tlsext_host_name(boost::get>(wss)->next_layer().native_handle(), host.c_str())) - { - BOOST_LOG_SEV(*log, trace) << "SSL next_layer() failed to set SNI"; - } - else - { - BOOST_LOG_SEV(*log, trace) << "SSL next_layer() SNI is set : " - << host; - } - return boost::get>(wss)->next_layer().async_handshake(type, handler); - } else { - BOOST_LOG_SEV(*log, trace) << "Calling next_layer().async_handshake with type: " - << WEB_PROXY_NO_TLS_TYPE_NAME; - // Set SNI Hostname (many hosts need this to handshake successfully) - if(!SSL_set_tlsext_host_name(boost::get>(wss)->next_layer().native_handle(), host.c_str())) - { - BOOST_LOG_SEV(*log, trace) << "SSL next_layer() failed to set SNI"; - } - else - { - BOOST_LOG_SEV(*log, trace) << "SSL next_layer() SNI is set : " - << host; + auto retry_count = std::make_shared(0); + auto retry_limit = 3; + auto retry_delay = std::chrono::seconds(1); + + auto perform_handshake = [this, type, host, handler, retry_count, retry_limit, retry_delay]() { + if (localproxyConfig.is_web_proxy_using_tls) { + BOOST_LOG_SEV(*log, trace) << "Calling next_layer().async_handshake with type: " + << WEB_PROXY_WITH_TLS_TYPE_NAME; + // Set SNI Hostname (many hosts need this to handshake successfully) + if(!SSL_set_tlsext_host_name(boost::get>(wss)->next_layer().native_handle(), host.c_str())) + { + BOOST_LOG_SEV(*log, trace) << "SSL next_layer() failed to set SNI"; + } + else + { + BOOST_LOG_SEV(*log, trace) << "SSL next_layer() SNI is set : " + << host; + } + boost::get>(wss)->next_layer().async_handshake(type, [this, handler, retry_count, retry_limit, retry_delay](const boost::system::error_code& ec) { + if (ec) { + BOOST_LOG_SEV(*log, error) << "SSL handshake failed: " << ec.message(); + if (*retry_count < retry_limit) { + (*retry_count)++; + BOOST_LOG_SEV(*log, warning) << "Retrying SSL handshake (" << *retry_count << "/" << retry_limit << ")..."; + boost::asio::steady_timer timer(io_context, retry_delay); + timer.async_wait([this, handler](const boost::system::error_code&) { + perform_handshake(); + }); + } else { + BOOST_LOG_SEV(*log, error) << "SSL handshake failed after " << retry_limit << " attempts."; + handler(ec); + } + } else { + handler(ec); + } + }); + } else { + BOOST_LOG_SEV(*log, trace) << "Calling next_layer().async_handshake with type: " + << WEB_PROXY_NO_TLS_TYPE_NAME; + // Set SNI Hostname (many hosts need this to handshake successfully) + if(!SSL_set_tlsext_host_name(boost::get>(wss)->next_layer().native_handle(), host.c_str())) + { + BOOST_LOG_SEV(*log, trace) << "SSL next_layer() failed to set SNI"; + } + else + { + BOOST_LOG_SEV(*log, trace) << "SSL next_layer() SNI is set : " + << host; + } + boost::get>(wss)->next_layer().async_handshake(type, [this, handler, retry_count, retry_limit, retry_delay](const boost::system::error_code& ec) { + if (ec) { + BOOST_LOG_SEV(*log, error) << "SSL handshake failed: " << ec.message(); + if (*retry_count < retry_limit) { + (*retry_count)++; + BOOST_LOG_SEV(*log, warning) << "Retrying SSL handshake (" << *retry_count << "/" << retry_limit << ")..."; + boost::asio::steady_timer timer(io_context, retry_delay); + timer.async_wait([this, handler](const boost::system::error_code&) { + perform_handshake(); + }); + } else { + BOOST_LOG_SEV(*log, error) << "SSL handshake failed after " << retry_limit << " attempts."; + handler(ec); + } + } else { + handler(ec); + } + }); } - return boost::get>(wss)->next_layer().async_handshake(type, handler); - } + }; + + perform_handshake(); } #endif