【问题标题】:Boost Asio SSL through proxy, "handshake: wrong version number"通过代理提升 Asio SSL,“握手:版本号错误”
【发布时间】:2019-12-03 12:34:25
【问题描述】:

我正在尝试使用 Boost.Asio(和 Boost.Beast)通过我的代理服务器建立 TLS 连接。

使用 HTTP CONNECT 设置隧道按预期工作。我用作演示的代码是:

net::io_context ioc{};

std::thread([&] {
    ioc.run();
 }).detach();

ssl::context ssl_context_{ssl::context::tls};
ssl_context_.set_default_verify_paths();
ssl_context_.add_verify_path("/opt/misc/certificates");

auto websocket_secure_ = std::make_shared<websocket::stream<ssl::stream<tcp::socket>>>(ioc, ssl_context_);

tcp::resolver resolver_{ioc};
auto const resolve_results = resolver_.resolve("www-my.proxy.int", "8080");
net::connect(websocket_secure_->next_layer().next_layer(), resolve_results.begin(), resolve_results.end());

const std::string HOST_TO_CONNECT_TO = "my.host.com:443";

http::request<http::string_body> request_connect{http::verb::connect, HOST_TO_CONNECT_TO, 11};
request_connect.insert(http::field::proxy_authorization, "Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
request_connect.insert(http::field::host, HOST_TO_CONNECT_TO);
boost::beast::http::write(websocket_secure_->next_layer().next_layer(), request_connect);

正如预期的那样,Wireshark 会显示一个 HTTP CONNECT,然后是 200 响应。

但是,之后尝试进行 SSL 握手会导致抛出错误:“handshake: wrong version number”。

try {
    websocket_secure_->next_layer().handshake(ssl::stream_base::client);
  } catch (boost::system::system_error& error) {
    std::cout << error.what();
    throw error;
  }

Wireshark 显示客户端问候,然后是服务器问候、证书、服务器密钥交换、证书请求、服务器问候完成。跟踪对我来说看起来不错,并且与我的浏览器对同一网站的请求没有什么不同。

如果我不必通过代理传输请求,SSL 握手就可以正常工作。

为什么在我的应用程序中出现抛出的错误?提前感谢您的帮助!

【问题讨论】:

    标签: ssl boost proxy boost-asio boost-beast


    【解决方案1】:

    对于任何有类似问题的人:

    Vinnie Falco 在 Github 上发布了有效回复(再次感谢!):

    https://github.com/boostorg/beast/issues/1776

    【讨论】:

    猜你喜欢
    • 2011-03-06
    • 2013-01-01
    • 2018-05-16
    • 2014-05-22
    • 2023-01-26
    • 2017-02-11
    • 1970-01-01
    • 2019-03-30
    • 2015-02-03
    相关资源
    最近更新 更多