srctree

Robin Linden parent a3de5603 44d524a0
net: Fix ssl handshake failure when SNI is required

inlinesplit
net/BUILD added: 11, removed: 3, total 8
@@ -16,5 +16,8 @@ cc_library(
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
deps = ["@asio"],
deps = [
"@asio",
"@boringssl//:ssl",
],
)
 
net/socket.cpp added: 11, removed: 3, total 8
@@ -7,7 +7,9 @@
 
#include <asio.hpp>
#include <asio/ssl.hpp>
#include <openssl/ssl.h>
 
#include <string>
#include <utility>
 
namespace net {
@@ -98,6 +100,9 @@ struct SecureSocket::Impl : public BaseSocketImpl {
bool connect(std::string_view host, std::string_view service) {
if (BaseSocketImpl::connect(resolver, socket.next_layer(), host, service)) {
asio::error_code ec;
// Set SNI hostname. Many hosts reject the handshake if this isn't done.
std::string null_terminated_host{host};
SSL_set_tlsext_host_name(socket.native_handle(), null_terminated_host.c_str());
socket.handshake(asio::ssl::stream_base::handshake_type::client, ec);
return !ec;
}