8
8
// http://www.boost.org/LICENSE_1_0.txt)
9
9
10
10
#include < boost/network/protocol/http/client/connection/ssl_delegate.hpp>
11
+ #include < boost/asio/ssl.hpp>
11
12
#include < boost/bind.hpp>
12
13
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) {}
19
22
20
23
void boost::network::http::impl::ssl_delegate::connect (
21
- asio::ip::tcp::endpoint & endpoint,
24
+ asio::ip::tcp::endpoint &endpoint,
22
25
function<void (system::error_code const &)> handler) {
23
- context_.reset (new asio::ssl::context (
24
- service_,
25
- asio::ssl::context::sslv23_client));
26
+ context_.reset (
27
+ new asio::ssl::context (service_, asio::ssl::context::sslv23_client));
26
28
if (certificate_filename_ || verify_path_) {
27
29
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_);
29
32
if (verify_path_) context_->add_verify_path (*verify_path_);
30
33
} 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);
32
38
}
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_));
34
41
socket_->lowest_layer ().async_connect (
35
42
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));
40
47
}
41
48
42
- void boost::network::http::impl::ssl_delegate::handle_connected (system::error_code const & ec,
43
- function<void (system::error_code const &)> handler) {
49
+ void boost::network::http::impl::ssl_delegate::handle_connected (
50
+ system::error_code const &ec,
51
+ function<void (system::error_code const &)> handler) {
44
52
if (!ec) {
45
53
socket_->async_handshake (asio::ssl::stream_base::client, handler);
46
54
} else {
@@ -49,17 +57,18 @@ void boost::network::http::impl::ssl_delegate::handle_connected(system::error_co
49
57
}
50
58
51
59
void boost::network::http::impl::ssl_delegate::write (
52
- asio::streambuf & command_streambuf,
60
+ asio::streambuf &command_streambuf,
53
61
function<void (system::error_code const &, size_t )> handler) {
54
62
asio::async_write (*socket_, command_streambuf, handler);
55
63
}
56
64
57
65
void boost::network::http::impl::ssl_delegate::read_some (
58
- asio::mutable_buffers_1 const & read_buffer,
66
+ asio::mutable_buffers_1 const &read_buffer,
59
67
function<void (system::error_code const &, size_t )> handler) {
60
68
socket_->async_read_some (read_buffer, handler);
61
69
}
62
70
63
71
boost::network::http::impl::ssl_delegate::~ssl_delegate () {}
64
72
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