Skip to content

Commit 449b8f5

Browse files
eakralydeanberris
authored andcommitted
Verify hostname matches certificate
1 parent 3229d2a commit 449b8f5

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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/normal_delegate.hpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ 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,
23+
std::string host,
2324
function<void(system::error_code const &)> handler) {
2425
socket_.reset(new asio::ip::tcp::socket(service_));
2526
socket_->async_connect(endpoint, handler);

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ boost::network::http::impl::ssl_delegate::ssl_delegate(
2525

2626
void boost::network::http::impl::ssl_delegate::connect(
2727
asio::ip::tcp::endpoint &endpoint,
28+
std::string host,
2829
function<void(system::error_code const &)> handler) {
2930
context_.reset(
3031
new asio::ssl::context(service_, asio::ssl::context::sslv23_client));
@@ -47,6 +48,7 @@ void boost::network::http::impl::ssl_delegate::connect(
4748
boost::asio::ssl::context::pem);
4849
socket_.reset(
4950
new asio::ssl::stream<asio::ip::tcp::socket>(service_, *context_));
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)