Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:02

0001 //
0002 // ssl/host_name_verification.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_SSL_HOST_NAME_VERIFICATION_HPP
0012 #define BOOST_ASIO_SSL_HOST_NAME_VERIFICATION_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #include <string>
0021 #include <boost/asio/ssl/detail/openssl_types.hpp>
0022 #include <boost/asio/ssl/verify_context.hpp>
0023 
0024 #include <boost/asio/detail/push_options.hpp>
0025 
0026 namespace boost {
0027 namespace asio {
0028 namespace ssl {
0029 
0030 /// Verifies a certificate against a host_name according to the rules described
0031 /// in RFC 6125.
0032 /**
0033  * @par Example
0034  * The following example shows how to synchronously open a secure connection to
0035  * a given host name:
0036  * @code
0037  * using boost::asio::ip::tcp;
0038  * namespace ssl = boost::asio::ssl;
0039  * typedef ssl::stream<tcp::socket> ssl_socket;
0040  *
0041  * // Create a context that uses the default paths for finding CA certificates.
0042  * ssl::context ctx(ssl::context::sslv23);
0043  * ctx.set_default_verify_paths();
0044  *
0045  * // Open a socket and connect it to the remote host.
0046  * boost::asio::io_context io_context;
0047  * ssl_socket sock(io_context, ctx);
0048  * tcp::resolver resolver(io_context);
0049  * tcp::resolver::query query("host.name", "https");
0050  * boost::asio::connect(sock.lowest_layer(), resolver.resolve(query));
0051  * sock.lowest_layer().set_option(tcp::no_delay(true));
0052  *
0053  * // Perform SSL handshake and verify the remote host's certificate.
0054  * sock.set_verify_mode(ssl::verify_peer);
0055  * sock.set_verify_callback(ssl::host_name_verification("host.name"));
0056  * sock.handshake(ssl_socket::client);
0057  *
0058  * // ... read and write as normal ...
0059  * @endcode
0060  */
0061 class host_name_verification
0062 {
0063 public:
0064   /// The type of the function object's result.
0065   typedef bool result_type;
0066 
0067   /// Constructor.
0068   explicit host_name_verification(const std::string& host)
0069     : host_(host)
0070   {
0071   }
0072 
0073   /// Perform certificate verification.
0074   BOOST_ASIO_DECL bool operator()(bool preverified, verify_context& ctx) const;
0075 
0076 private:
0077   // Helper function to check a host name against an IPv4 address
0078   // The host name to be checked.
0079   std::string host_;
0080 };
0081 
0082 } // namespace ssl
0083 } // namespace asio
0084 } // namespace boost
0085 
0086 #include <boost/asio/detail/pop_options.hpp>
0087 
0088 #if defined(BOOST_ASIO_HEADER_ONLY)
0089 # include <boost/asio/ssl/impl/host_name_verification.ipp>
0090 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0091 
0092 #endif // BOOST_ASIO_SSL_HOST_NAME_VERIFICATION_HPP