Skip to content

Commit 2028c55

Browse files
committed
Merge pull request cpp-netlib#455 from eakraly/0.11-devel
Verify hostname according to rfc2818
2 parents 3229d2a + b1f305b commit 2028c55

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

boost/network/protocol/http/client/connection/async_normal.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct http_async_connection
9797
resolve_(
9898
resolver_, host(request), port_,
9999
request_strand_.wrap(boost::bind(
100-
&this_type::handle_resolved, this_type::shared_from_this(), port_,
100+
&this_type::handle_resolved, this_type::shared_from_this(), host(request), port_,
101101
get_body, callback, generator, boost::arg<1>(), boost::arg<2>())));
102102
if (timeout_ > 0) {
103103
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
@@ -128,7 +128,7 @@ struct http_async_connection
128128
is_timedout_ = true;
129129
}
130130

131-
void handle_resolved(boost::uint16_t port, bool get_body,
131+
void handle_resolved(string_type host, boost::uint16_t port, bool get_body,
132132
body_callback_function_type callback,
133133
body_generator_function_type generator,
134134
boost::system::error_code const& ec,
@@ -140,9 +140,9 @@ struct http_async_connection
140140
resolver_iterator iter = boost::begin(endpoint_range);
141141
asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port);
142142
delegate_->connect(
143-
endpoint, request_strand_.wrap(boost::bind(
143+
endpoint, host, request_strand_.wrap(boost::bind(
144144
&this_type::handle_connected,
145-
this_type::shared_from_this(), port, get_body, callback,
145+
this_type::shared_from_this(), host, port, get_body, callback,
146146
generator, std::make_pair(++iter, resolver_iterator()),
147147
placeholders::error)));
148148
} else {
@@ -152,7 +152,7 @@ struct http_async_connection
152152
}
153153
}
154154

155-
void handle_connected(boost::uint16_t port, bool get_body,
155+
void handle_connected(string_type host, boost::uint16_t port, bool get_body,
156156
body_callback_function_type callback,
157157
body_generator_function_type generator,
158158
resolver_iterator_pair endpoint_range,
@@ -173,9 +173,10 @@ struct http_async_connection
173173
asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port);
174174
delegate_->connect(
175175
endpoint,
176+
host,
176177
request_strand_.wrap(boost::bind(
177178
&this_type::handle_connected, this_type::shared_from_this(),
178-
port, get_body, callback, generator,
179+
host, port, get_body, callback, generator,
179180
std::make_pair(++iter, resolver_iterator()),
180181
placeholders::error)));
181182
} else {

boost/network/protocol/http/client/connection/connection_delegate.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace http {
1313
namespace impl {
1414

1515
struct connection_delegate {
16-
virtual void connect(asio::ip::tcp::endpoint &endpoint,
16+
virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host,
1717
function<void(system::error_code const &)> handler) = 0;
1818
virtual void write(
1919
asio::streambuf &command_streambuf,

boost/network/protocol/http/client/connection/normal_delegate.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace impl {
1919
struct normal_delegate : connection_delegate {
2020
normal_delegate(asio::io_service &service);
2121

22-
virtual void connect(asio::ip::tcp::endpoint &endpoint,
22+
virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host,
2323
function<void(system::error_code const &)> handler);
2424
virtual void write(
2525
asio::streambuf &command_streambuf,

boost/network/protocol/http/client/connection/normal_delegate.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ boost::network::http::impl::normal_delegate::normal_delegate(
1919
: service_(service) {}
2020

2121
void boost::network::http::impl::normal_delegate::connect(
22-
asio::ip::tcp::endpoint &endpoint,
22+
asio::ip::tcp::endpoint &endpoint, std::string host,
2323
function<void(system::error_code const &)> handler) {
2424
socket_.reset(new asio::ip::tcp::socket(service_));
2525
socket_->async_connect(endpoint, handler);

boost/network/protocol/http/client/connection/ssl_delegate.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct ssl_delegate : connection_delegate,
2828
optional<std::string> certificate_file,
2929
optional<std::string> private_key_file);
3030

31-
virtual void connect(asio::ip::tcp::endpoint &endpoint,
31+
virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host,
3232
function<void(system::error_code const &)> handler);
3333
virtual void write(
3434
asio::streambuf &command_streambuf,

boost/network/protocol/http/client/connection/ssl_delegate.ipp

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ boost::network::http::impl::ssl_delegate::ssl_delegate(
2424
always_verify_peer_(always_verify_peer) {}
2525

2626
void boost::network::http::impl::ssl_delegate::connect(
27-
asio::ip::tcp::endpoint &endpoint,
27+
asio::ip::tcp::endpoint &endpoint, std::string host,
2828
function<void(system::error_code const &)> handler) {
2929
context_.reset(
3030
new asio::ssl::context(service_, asio::ssl::context::sslv23_client));
@@ -47,6 +47,8 @@ void boost::network::http::impl::ssl_delegate::connect(
4747
boost::asio::ssl::context::pem);
4848
socket_.reset(
4949
new asio::ssl::stream<asio::ip::tcp::socket>(service_, *context_));
50+
if (always_verify_peer_)
51+
socket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host));
5052
socket_->lowest_layer().async_connect(
5153
endpoint,
5254
::boost::bind(

0 commit comments

Comments
 (0)