示例#1
0
 http_sync_connection(resolver_type& resolver, resolver_function_type resolve,
                      int timeout)
     : connection_base(),
       timeout_(timeout),
       timer_(resolver.get_io_service()),
       resolver_(resolver),
       resolve_(resolve),
       socket_(resolver.get_io_service()) {}
示例#2
0
 // FIXME make the certificate filename and verify path parameters be
 // optional ranges
 https_sync_connection(
     resolver_type& resolver, resolver_function_type resolve,
     bool always_verify_peer, int timeout,
     optional<string_type>  /*unused*/const& certificate_filename =
         optional<string_type>(),
     optional<string_type> const& verify_path = optional<string_type>(),
     optional<string_type> const& certificate_file = optional<string_type>(),
     optional<string_type> const& private_key_file = optional<string_type>(),
     optional<string_type> const& ciphers = optional<string_type>(),
     long ssl_options = 0)
     : connection_base(),
       timeout_(timeout),
       timer_(resolver.get_io_service()),
       resolver_(resolver),
       resolve_(std::move(resolve)),
       context_(resolver.get_io_service(),
                boost::asio::ssl::context::sslv23_client),
       socket_(resolver.get_io_service(), context_) {
   if (ciphers) {
     ::SSL_CTX_set_cipher_list(context_.native_handle(), ciphers->c_str());
   }
   if (ssl_options != 0) {
     context_.set_options(ssl_options);
   }
   if (certificate_filename || verify_path) {
     context_.set_verify_mode(boost::asio::ssl::context::verify_peer);
     // FIXME make the certificate filename and verify path parameters
     // be
     // optional ranges
     if (certificate_filename)
       context_.load_verify_file(*certificate_filename);
     if (verify_path) context_.add_verify_path(*verify_path);
   } else {
     if (always_verify_peer)
       context_.set_verify_mode(boost::asio::ssl::context_base::verify_peer);
     else
       context_.set_verify_mode(boost::asio::ssl::context_base::verify_none);
   }
   if (certificate_file)
     context_.use_certificate_file(*certificate_file,
                                   boost::asio::ssl::context::pem);
   if (private_key_file)
     context_.use_private_key_file(*private_key_file,
                                   boost::asio::ssl::context::pem);
 }
示例#3
0
        resolver_iterator_pair resolve(resolver_type & resolver_, string_type const & hostname, string_type const & port) {
            if (cache_resolved_) {
                typename resolved_cache::iterator cached_iterator =
                    endpoint_cache_.find(hostname);
                if (cached_iterator == endpoint_cache_.end()) {
                    bool inserted = false;
                    boost::fusion::tie(cached_iterator, inserted) =
                        endpoint_cache_.insert(
                                std::make_pair(
                                        boost::to_lower_copy(hostname),
                                        std::make_pair(
                                                resolver_.resolve(
                                                        resolver_query(
                                                                hostname,
                                                                port,
                                                                resolver_query::numeric_service
                                                                )
                                                        )
                                                        , resolver_iterator()
                                                )
                                        )
                                );
                };
                return cached_iterator->second;
            };

            return std::make_pair(
                    resolver_.resolve(
                            resolver_query(
                                    hostname,
                                    port,
                                    resolver_query::numeric_service
                                    )
                            )
                            ,
                            resolver_iterator()
                    );
        };
示例#4
0
 // FIXME make the certificate filename and verify path parameters be
 // optional ranges
 https_sync_connection(resolver_type& resolver, resolver_function_type resolve,
                       bool always_verify_peer,
                       optional<string_type> const& certificate_filename =
                           optional<string_type>(),
                       optional<string_type> const& verify_path =
                           optional<string_type>(),
                       optional<string_type> const& certificate_file =
                           optional<string_type>(),
                       optional<string_type> const& private_key_file =
                           optional<string_type>())
     : connection_base(),
       resolver_(resolver),
       resolve_(resolve),
       context_(resolver.get_io_service(),
                boost::asio::ssl::context::sslv23_client),
       socket_(resolver.get_io_service(), context_) {
     if (certificate_filename || verify_path) {
         context_.set_verify_mode(boost::asio::ssl::context::verify_peer);
         // FIXME make the certificate filename and verify path parameters be
         // optional ranges
         if (certificate_filename)
             context_.load_verify_file(*certificate_filename);
         if (verify_path) context_.add_verify_path(*verify_path);
     } else {
         if (always_verify_peer)
             context_.set_verify_mode(boost::asio::ssl::context_base::verify_peer);
         else
             context_.set_verify_mode(boost::asio::ssl::context_base::verify_none);
     }
     if (certificate_file)
         context_.use_certificate_file(
             *certificate_file, boost::asio::ssl::context::pem);
     if (private_key_file)
         context_.use_private_key_file(
             *private_key_file, boost::asio::ssl::context::pem);
 }
示例#5
0
 // This is the factory function which constructs the appropriate async
 // connection implementation with the correct delegate chosen based on the
 // tag.
 static connection_ptr new_connection(
     resolve_function resolve, resolver_type &resolver, bool follow_redirect,
     bool always_verify_peer, bool https, int timeout,
     optional<string_type> certificate_filename = optional<string_type>(),
     optional<string_type> const &verify_path = optional<string_type>(),
     optional<string_type> certificate_file = optional<string_type>(),
     optional<string_type> private_key_file = optional<string_type>(),
     optional<string_type> ciphers = optional<string_type>(),
     long ssl_options = 0) {
   typedef http_async_connection<Tag, version_major, version_minor>
       async_connection;
   typedef typename delegate_factory<Tag>::type delegate_factory_type;
   connection_ptr temp;
   temp.reset(new async_connection(
       resolver, resolve, follow_redirect, timeout,
       delegate_factory_type::new_connection_delegate(
           resolver.get_io_service(), https, always_verify_peer,
           certificate_filename, verify_path, certificate_file,
           private_key_file, ciphers, ssl_options)));
   BOOST_ASSERT(temp.get() != 0);
   return temp;
 }
示例#6
0
 // This is the factory function which constructs the appropriate async
 // connection implementation with the correct delegate chosen based on the
 // tag.
 static connection_ptr new_connection(
     resolve_function resolve, resolver_type &resolver, bool follow_redirect,
     bool always_verify_peer, bool https, int timeout,
     optional<string_type> certificate_filename = optional<string_type>(),
     optional<string_type> const &verify_path = optional<string_type>(),
     optional<string_type> certificate_file = optional<string_type>(),
     optional<string_type> private_key_file = optional<string_type>(),
     optional<string_type> ciphers = optional<string_type>(),
     optional<string_type> sni_hostname = optional<string_type>(),
     long ssl_options = 0) {
   typedef http_async_connection<Tag, version_major, version_minor>
       async_connection;
   typedef typename delegate_factory<Tag>::type delegate_factory_type;
   auto delegate = delegate_factory_type::new_connection_delegate(
       resolver.get_io_service(), https, always_verify_peer,
       certificate_filename, verify_path, certificate_file, private_key_file,
       ciphers, sni_hostname, ssl_options);
   auto temp = std::make_shared<async_connection>(
       resolver, resolve, follow_redirect, timeout, std::move(delegate));
   BOOST_ASSERT(temp != nullptr);
   return temp;
 }