tls: 未协商应用协议

huangapple go评论93阅读模式
英文:

tls: no application protocol negotiated

问题

第一次使用libnghttp2-asio库,尽管它已经不推荐使用。

我正在尝试如何获取reddit网页,如下所示:

boost::system::error_code ec;
namespace net = nghttp2::asio_http2;
namespace ssl = boost::asio::ssl;
using boost::asio::ip::tcp;
boost::asio::io_context ioc;
ssl::context tls(ssl::context::tlsv12_client);
tls.set_options(ssl::context::default_workarounds);
// tls.set_verify_mode(boost::asio::ssl::verify_peer);
tls.set_verify_mode(ssl::verify_none);
tls.set_default_verify_paths();
net::client::session session(ioc, tls, "www.reddit.com", "443");
session.on_connect([&session](tcp::resolver::iterator endpoint_it) {
    std::cout << "Connected" << std::endl;
});
session.on_error([](const boost::system::error_code &ec) {
    std::cout << "error: " << ec.message() << std::endl;
});
ioc.run();

输出:

error: tls: no application protocol negotiated

我想知道如何成功连接,也许我错过了握手过程?如果是这样,应该如何操作?

英文:

First time to using the libnghttp2-asio library despite it being deprecated.

I'm experimenting how I think would give the reddit webpage as follows:

boost::system::error_code ec;
namespace net = nghttp2::asio_http2;
namespace ssl = boost::asio::ssl;
using boost::asio::ip::tcp;
boost::asio::io_context ioc;
ssl::context tls(ssl::context::tlsv12_client);
tls.set_options(ssl::context::default_workarounds);
// tls.set_verify_mode(boost::asio::ssl::verify_peer);
tls.set_verify_mode(ssl::verify_none);
tls.set_default_verify_paths();
net::client::session session(ioc, tls, &quot;www.reddit.com&quot;, &quot;443&quot;);
session.on_connect([&amp;session](tcp::resolver::iterator endpoint_it) {
	std::cout &lt;&lt; &quot;Connected&quot; &lt;&lt; std::endl;
});
session.on_error([](const boost::system::error_code &amp;ec) {
	std::cout &lt;&lt; &quot;error: &quot; &lt;&lt; ec.message() &lt;&lt; std::endl;
});
ioc.run();

Output:

error: tls: no application protocol negotiated

I would like to know how I can connect successfully, perhaps I'm missing the handshake procedure? If so, how should I do it?

答案1

得分: 2

nghttp2默认不支持ALPN。
通过以下方法解决:

SSL_CTX_set_alpn_protos(tls.native_handle(), (const unsigned char *)"\x02h2", 3);
英文:

nghttp2 doesn't do ALPN by default.
Solved by

SSL_CTX_set_alpn_protos(tls.native_handle(), (const unsigned char *)&quot;\x02h2&quot;, 3);

huangapple
  • 本文由 发表于 2023年7月27日 21:38:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780341.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定