Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d9538f

Browse files
committed
Fixes#346 - add an option to always verify peer
1 parent947269e commit8d9538f

File tree

16 files changed

+524
-542
lines changed

16 files changed

+524
-542
lines changed

‎boost/network/protocol/http/client/async_impl.hpp‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ struct async_client
3636

3737
typedef function<bool(string_type&)> body_generator_function_type;
3838

39-
async_client(bool cache_resolved,
40-
boolfollow_redirect,
39+
async_client(bool cache_resolved,bool follow_redirect,
40+
boolalways_verify_peer,
4141
boost::shared_ptr<boost::asio::io_service> service,
4242
optional<string_type>const& certificate_filename,
4343
optional<string_type>const& verify_path)
@@ -49,7 +49,8 @@ struct async_client
4949
resolver_(service_),
5050
sentinel_(new boost::asio::io_service::work(service_)),
5151
certificate_filename_(certificate_filename),
52-
verify_path_(verify_path) {
52+
verify_path_(verify_path),
53+
always_verify_peer_(always_verify_peer) {
5354
connection_base::resolver_strand_.reset(
5455
newboost::asio::io_service::strand(service_));
5556
lifetime_thread_.reset(newboost::thread(
@@ -65,16 +66,15 @@ struct async_client
6566
}
6667

6768
basic_response<Tag>constrequest_skeleton(
68-
basic_request<Tag>const& request_,
69-
string_typeconst& method,
70-
bool get_body,
71-
body_callback_function_type callback,
69+
basic_request<Tag>const& request_, string_typeconst& method,
70+
bool get_body, body_callback_function_type callback,
7271
body_generator_function_type generator) {
7372
typename connection_base::connection_ptr connection_;
7473
connection_ =connection_base::get_connection(
75-
resolver_, request_, certificate_filename_, verify_path_);
76-
return connection_->send_request(
77-
method, request_, get_body, callback, generator);
74+
resolver_, request_, always_verify_peer_, certificate_filename_,
75+
verify_path_);
76+
return connection_->send_request(method, request_, get_body, callback,
77+
generator);
7878
}
7979

8080
boost::shared_ptr<boost::asio::io_service> service_ptr;
@@ -83,6 +83,7 @@ struct async_client
8383
boost::shared_ptr<boost::asio::io_service::work> sentinel_;
8484
boost::shared_ptr<boost::thread> lifetime_thread_;
8585
optional<string_type> certificate_filename_, verify_path_;
86+
bool always_verify_peer_;
8687
};
8788
}// namespace impl
8889
}// namespace http

‎boost/network/protocol/http/client/connection/async_base.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace boost { namespace network { namespace http { namespace impl {
3737
resolve_function resolve,
3838
resolver_type & resolver,
3939
bool follow_redirect,
40+
bool always_verify_peer,
4041
bool https,
4142
optional<string_type> certificate_filename=optional<string_type>(),
4243
optional<string_type>const & verify_path=optional<string_type>()) {
@@ -52,6 +53,7 @@ namespace boost { namespace network { namespace http { namespace impl {
5253
delegate_factory_type::new_connection_delegate(
5354
resolver.get_io_service(),
5455
https,
56+
always_verify_peer,
5557
certificate_filename,
5658
verify_path)));
5759
BOOST_ASSERT(temp.get() !=0);

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

Lines changed: 111 additions & 182 deletions
Large diffs are not rendered by default.

‎boost/network/protocol/http/client/connection/connection_delegate_factory.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ struct connection_delegate_factory {
3030
static connection_delegate_ptrnew_connection_delegate(
3131
asio::io_service & service,
3232
bool https,
33+
bool always_verify_peer,
3334
optional<string_type> certificate_filename,
3435
optional<string_type> verify_path) {
3536
connection_delegate_ptr delegate;
3637
if (https) {
3738
#ifdef BOOST_NETWORK_ENABLE_HTTPS
3839
delegate.reset(newssl_delegate(service,
40+
always_verify_peer,
3941
certificate_filename,
4042
verify_path));
4143
#else

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,38 @@
1515
#include<boost/network/support/is_default_string.hpp>
1616
#include<boost/network/support/is_default_wstring.hpp>
1717

18-
namespaceboost {namespacenetwork {namespacehttp {namespaceimpl {
18+
namespaceboost {
19+
namespacenetwork {
20+
namespacehttp {
21+
namespaceimpl {
1922

20-
structssl_delegate : connection_delegate, enable_shared_from_this<ssl_delegate> {
21-
ssl_delegate(asio::io_service & service,
22-
optional<std::string> certificate_filename,
23-
optional<std::string> verify_path);
23+
structssl_delegate : connection_delegate,
24+
enable_shared_from_this<ssl_delegate> {
25+
ssl_delegate(asio::io_service &service,bool always_verify_peer,
26+
optional<std::string> certificate_filename,
27+
optional<std::string> verify_path);
2428

25-
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint,
29+
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint,
2630
function<void(system::error_codeconst &)> handler);
27-
virtualvoidwrite(asio::streambuf & command_streambuf,
28-
function<void(system::error_codeconst &,size_t)> handler);
29-
virtualvoidread_some(asio::mutable_buffers_1const & read_buffer,
30-
function<void(system::error_codeconst &,size_t)> handler);
31+
virtualvoidwrite(
32+
asio::streambuf &command_streambuf,
33+
function<void(system::error_codeconst &,size_t)> handler);
34+
virtualvoidread_some(
35+
asio::mutable_buffers_1const &read_buffer,
36+
function<void(system::error_codeconst &,size_t)> handler);
3137
~ssl_delegate();
3238

3339
private:
34-
asio::io_service &service_;
40+
asio::io_service &service_;
3541
optional<std::string> certificate_filename_, verify_path_;
3642
scoped_ptr<asio::ssl::context> context_;
3743
scoped_ptr<asio::ssl::stream<asio::ip::tcp::socket> > socket_;
44+
bool always_verify_peer_;
3845

39-
ssl_delegate(ssl_delegateconst &);// = delete
40-
ssl_delegate&operator=(ssl_delegate);// = delete
46+
ssl_delegate(ssl_delegateconst &);// = delete
47+
ssl_delegate &operator=(ssl_delegate);// = delete
4148

42-
voidhandle_connected(system::error_codeconst &ec,
49+
voidhandle_connected(system::error_codeconst &ec,
4350
function<void(system::error_codeconst &)> handler);
4451
};
4552

@@ -55,4 +62,5 @@ struct ssl_delegate : connection_delegate, enable_shared_from_this<ssl_delegate>
5562
#include<boost/network/protocol/http/client/connection/ssl_delegate.ipp>
5663
#endif/* BOOST_NETWORK_NO_LIB*/
5764

58-
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_SSL_DELEGATE_20110819*/
65+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_SSL_DELEGATE_20110819 \
66+
*/

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,47 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/protocol/http/client/connection/ssl_delegate.hpp>
11+
#include<boost/asio/ssl.hpp>
1112
#include<boost/bind.hpp>
1213

13-
boost::network::http::impl::ssl_delegate::ssl_delegate(asio::io_service & service,
14-
optional<std::string> certificate_filename,
15-
optional<std::string> verify_path) :
16-
service_(service),
17-
certificate_filename_(certificate_filename),
18-
verify_path_(verify_path) {}
14+
boost::network::http::impl::ssl_delegate::ssl_delegate(
15+
asio::io_service &service,bool always_verify_peer,
16+
optional<std::string> certificate_filename,
17+
optional<std::string> verify_path)
18+
: service_(service),
19+
certificate_filename_(certificate_filename),
20+
verify_path_(verify_path),
21+
always_verify_peer_(always_verify_peer) {}
1922

2023
voidboost::network::http::impl::ssl_delegate::connect(
21-
asio::ip::tcp::endpoint &endpoint,
24+
asio::ip::tcp::endpoint &endpoint,
2225
function<void(system::error_codeconst &)> handler) {
23-
context_.reset(newasio::ssl::context(
24-
service_,
25-
asio::ssl::context::sslv23_client));
26+
context_.reset(
27+
newasio::ssl::context(service_, asio::ssl::context::sslv23_client));
2628
if (certificate_filename_ || verify_path_) {
2729
context_->set_verify_mode(asio::ssl::context::verify_peer);
28-
if (certificate_filename_) context_->load_verify_file(*certificate_filename_);
30+
if (certificate_filename_)
31+
context_->load_verify_file(*certificate_filename_);
2932
if (verify_path_) context_->add_verify_path(*verify_path_);
3033
}else {
31-
context_->set_verify_mode(asio::ssl::context::verify_none);
34+
if (always_verify_peer_)
35+
context_->set_verify_mode(asio::ssl::context::verify_peer);
36+
else
37+
context_->set_verify_mode(asio::ssl::context::verify_none);
3238
}
33-
socket_.reset(new asio::ssl::stream<asio::ip::tcp::socket>(service_, *context_));
39+
socket_.reset(
40+
new asio::ssl::stream<asio::ip::tcp::socket>(service_, *context_));
3441
socket_->lowest_layer().async_connect(
3542
endpoint,
36-
::boost::bind(&boost::network::http::impl::ssl_delegate::handle_connected,
37-
boost::network::http::impl::ssl_delegate::shared_from_this(),
38-
asio::placeholders::error,
39-
handler));
43+
::boost::bind(
44+
&boost::network::http::impl::ssl_delegate::handle_connected,
45+
boost::network::http::impl::ssl_delegate::shared_from_this(),
46+
asio::placeholders::error, handler));
4047
}
4148

42-
voidboost::network::http::impl::ssl_delegate::handle_connected(system::error_codeconst & ec,
43-
function<void(system::error_codeconst &)> handler) {
49+
voidboost::network::http::impl::ssl_delegate::handle_connected(
50+
system::error_codeconst &ec,
51+
function<void(system::error_codeconst &)> handler) {
4452
if (!ec) {
4553
socket_->async_handshake(asio::ssl::stream_base::client, handler);
4654
}else {
@@ -49,17 +57,18 @@ void boost::network::http::impl::ssl_delegate::handle_connected(system::error_co
4957
}
5058

5159
voidboost::network::http::impl::ssl_delegate::write(
52-
asio::streambuf &command_streambuf,
60+
asio::streambuf &command_streambuf,
5361
function<void(system::error_codeconst &,size_t)> handler) {
5462
asio::async_write(*socket_, command_streambuf, handler);
5563
}
5664

5765
voidboost::network::http::impl::ssl_delegate::read_some(
58-
asio::mutable_buffers_1const &read_buffer,
66+
asio::mutable_buffers_1const &read_buffer,
5967
function<void(system::error_codeconst &,size_t)> handler) {
6068
socket_->async_read_some(read_buffer, handler);
6169
}
6270

6371
boost::network::http::impl::ssl_delegate::~ssl_delegate() {}
6472

65-
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_SSL_DELEGATE_IPP_20110819*/
73+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_SSL_DELEGATE_IPP_20110819 \
74+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp