|
||||
File indexing completed on 2025-01-18 09:29:02
0001 // 0002 // ssl/rfc2818_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_RFC2818_VERIFICATION_HPP 0012 #define BOOST_ASIO_SSL_RFC2818_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 #if !defined(BOOST_ASIO_NO_DEPRECATED) 0021 0022 #include <string> 0023 #include <boost/asio/ssl/detail/openssl_types.hpp> 0024 #include <boost/asio/ssl/verify_context.hpp> 0025 0026 #include <boost/asio/detail/push_options.hpp> 0027 0028 namespace boost { 0029 namespace asio { 0030 namespace ssl { 0031 0032 /// (Deprecated. Use ssl::host_name_verification.) Verifies a certificate 0033 /// against a hostname according to the rules described in RFC 2818. 0034 /** 0035 * @par Example 0036 * The following example shows how to synchronously open a secure connection to 0037 * a given host name: 0038 * @code 0039 * using boost::asio::ip::tcp; 0040 * namespace ssl = boost::asio::ssl; 0041 * typedef ssl::stream<tcp::socket> ssl_socket; 0042 * 0043 * // Create a context that uses the default paths for finding CA certificates. 0044 * ssl::context ctx(ssl::context::sslv23); 0045 * ctx.set_default_verify_paths(); 0046 * 0047 * // Open a socket and connect it to the remote host. 0048 * boost::asio::io_context io_context; 0049 * ssl_socket sock(io_context, ctx); 0050 * tcp::resolver resolver(io_context); 0051 * tcp::resolver::query query("host.name", "https"); 0052 * boost::asio::connect(sock.lowest_layer(), resolver.resolve(query)); 0053 * sock.lowest_layer().set_option(tcp::no_delay(true)); 0054 * 0055 * // Perform SSL handshake and verify the remote host's certificate. 0056 * sock.set_verify_mode(ssl::verify_peer); 0057 * sock.set_verify_callback(ssl::rfc2818_verification("host.name")); 0058 * sock.handshake(ssl_socket::client); 0059 * 0060 * // ... read and write as normal ... 0061 * @endcode 0062 */ 0063 class rfc2818_verification 0064 { 0065 public: 0066 /// The type of the function object's result. 0067 typedef bool result_type; 0068 0069 /// Constructor. 0070 explicit rfc2818_verification(const std::string& host) 0071 : host_(host) 0072 { 0073 } 0074 0075 /// Perform certificate verification. 0076 BOOST_ASIO_DECL bool operator()(bool preverified, verify_context& ctx) const; 0077 0078 private: 0079 // Helper function to check a host name against a pattern. 0080 BOOST_ASIO_DECL static bool match_pattern(const char* pattern, 0081 std::size_t pattern_length, const char* host); 0082 0083 // Helper function to check a host name against an IPv4 address 0084 // The host name to be checked. 0085 std::string host_; 0086 }; 0087 0088 } // namespace ssl 0089 } // namespace asio 0090 } // namespace boost 0091 0092 #include <boost/asio/detail/pop_options.hpp> 0093 0094 #if defined(BOOST_ASIO_HEADER_ONLY) 0095 # include <boost/asio/ssl/impl/rfc2818_verification.ipp> 0096 #endif // defined(BOOST_ASIO_HEADER_ONLY) 0097 0098 #endif // !defined(BOOST_ASIO_NO_DEPRECATED) 0099 0100 #endif // BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |